20 #include <vstgui4/vstgui/uidescription/iviewcreator.h> 21 #include <vstgui4/vstgui/uidescription/uiviewcreator.h> 22 #include <vstgui4/vstgui/uidescription/uiviewfactory.h> 23 #include <vstgui4/vstgui/uidescription/uiattributes.h> 24 #include <vstgui4/vstgui/uidescription/detail/uiviewcreatorattributes.h> 25 #include <vstgui4/vstgui/lib/crect.h> 26 #include <vstgui4/vstgui/lib/ccolor.h> 27 #include <vstgui4/vstgui/lib/cbitmap.h> 30 #include <pongasoft/logging/logging.h> 50 fName(std::move(iName))
56 virtual IViewCreator::AttrType getType() = 0;
73 virtual bool apply(CView *iView,
const UIAttributes &iAttributes,
const IUIDescription *iDescription) = 0;
81 virtual bool getAttributeValue(CView *iView,
const IUIDescription *iDescription, std::string &oStringValue)
const = 0;
91 template<
typename TView>
120 template<
typename TView>
129 template<
typename T,
typename TGetter,
typename TSetter>
143 return IViewCreator::kUnknownType;
150 virtual bool fromString(IUIDescription
const *iDescription, std::string
const &iAttributeValue, T &oValue)
const 159 virtual bool toString(IUIDescription
const *iDescription, T
const &iValue, std::string &oStringValue)
const 165 bool apply(CView *iView,
const UIAttributes &iAttributes,
const IUIDescription *iDescription)
override 167 auto *tv = dynamic_cast<TView *>(iView);
170 auto attributeValue = iAttributes.getAttributeValue(getName());
174 if(fromString(iDescription, *attributeValue, value))
176 (tv->*fSetter)(value);
185 bool getAttributeValue(CView *iView,
const IUIDescription *iDescription, std::string &oStringValue)
const override 187 auto *tv = dynamic_cast<TView *>(iView);
190 auto value = (tv->*fGetter)();
191 return toString(iDescription, value, oStringValue);
211 using ByRefAttribute = TAttribute<T, T
const &(TView::*)() const,
void (TView::*)(T const &)>;
228 return IViewCreator::kTagType;
232 bool fromString(IUIDescription
const *iDescription, std::string
const &iAttributeValue, int32_t &oValue)
const override 234 if(iAttributeValue.length() != 0)
236 auto tag = iDescription->getTagForName(iAttributeValue.c_str());
239 char *endPtr =
nullptr;
240 tag = (int32_t) strtol(iAttributeValue.c_str(), &endPtr, 10);
241 if(endPtr == iAttributeValue.c_str())
253 bool toString(IUIDescription
const *iDescription,
const int32_t &iValue, std::string &oStringValue)
const override 257 UTF8StringPtr controlTag = iDescription->lookupControlTagName(iValue);
260 oStringValue = controlTag;
273 template<
typename TInt>
287 return IViewCreator::kIntegerType;
291 bool fromString(IUIDescription
const *iDescription, std::string
const &iAttributeValue, TInt &oValue)
const override 293 char *endPtr =
nullptr;
294 auto value = static_cast<TInt>(strtol(iAttributeValue.c_str(), &endPtr, 10));
295 if(endPtr == iAttributeValue.c_str())
297 DLOG_F(WARNING,
"could not convert <%s> to an integer", iAttributeValue.c_str());
305 bool toString(IUIDescription
const *iDescription,
const TInt &iValue, std::string &oStringValue)
const override 307 std::stringstream str;
309 oStringValue = str.str();
318 template<
typename TFloat>
332 return IViewCreator::kFloatType;
336 bool fromString(IUIDescription
const *iDescription, std::string
const &iAttributeValue, TFloat &oValue)
const override 339 if(Utils::stringToFloat<TFloat>(iAttributeValue, value))
344 DLOG_F(WARNING,
"could not convert <%s> to a float", iAttributeValue.c_str());
349 bool toString(IUIDescription
const *iDescription,
const TFloat &iValue, std::string &oStringValue)
const override 351 std::stringstream str;
353 oStringValue = str.str();
375 return IViewCreator::kColorType;
379 bool fromString(IUIDescription
const *iDescription, std::string
const &iAttributeValue, CColor &oValue)
const override 382 if(UIViewCreator::stringToColor(&iAttributeValue, color, iDescription))
391 bool toString(IUIDescription
const *iDescription,
const CColor &iValue, std::string &oStringValue)
const override 393 return UIViewCreator::colorToString(iValue, oStringValue, iDescription);
414 return IViewCreator::kGradientType;
418 bool fromString(IUIDescription
const *iDescription, std::string
const &iAttributeValue,
GradientPtr &oValue)
const override 420 auto gradient = iDescription->getGradient(iAttributeValue.c_str());
430 bool toString(IUIDescription
const *iDescription,
GradientPtr const &iValue, std::string &oStringValue)
const override 434 auto name = iDescription->lookupGradientName(iValue);
462 return IViewCreator::kBooleanType;
466 bool fromString(IUIDescription
const *iDescription, std::string
const &iAttributeValue,
bool &oValue)
const override 468 if(iAttributeValue ==
"true")
474 if(iAttributeValue ==
"false")
484 bool toString(IUIDescription
const *iDescription,
const bool &iValue, std::string &oStringValue)
const override 486 oStringValue = iValue ?
"true" :
"false";
507 return IViewCreator::kBitmapType;
511 bool fromString(IUIDescription
const *iDescription, std::string
const &iAttributeValue,
BitmapPtr &oValue)
const override 514 if(UIViewCreator::stringToBitmap(&iAttributeValue, bitmap, iDescription))
523 bool toString(IUIDescription
const *iDescription,
BitmapPtr const &iValue, std::string &oStringValue)
const override 526 return UIViewCreator::bitmapToString(iValue, oStringValue, iDescription);
548 return IViewCreator::kFontType;
552 bool fromString(IUIDescription
const *iDescription, std::string
const &iAttributeValue,
FontPtr &oValue)
const override 554 auto font = iDescription->getFont(iAttributeValue.c_str());
564 bool toString(IUIDescription
const *iDescription,
FontPtr const &iValue, std::string &oStringValue)
const override 568 auto fontName = iDescription->lookupFontName(iValue);
571 oStringValue = fontName;
592 bool fromString(IUIDescription
const *iDescription, std::string
const &iAttributeValue,
Margin &oValue)
const override 594 auto parts = Utils::splitFloats<CCoord>(iAttributeValue,
',');
600 if(std::find_if(parts.cbegin(), parts.cend(), [] (
auto f) {
return std::isnan(f);}) != parts.cend())
603 if(parts.size() == 1)
605 oValue =
Margin{parts[0]};
612 oValue =
Margin{parts[0], parts[1], parts[2], parts[3]};
619 bool toString(IUIDescription
const *iDescription,
const Margin &iValue, std::string &oStringValue)
const override 621 std::stringstream str;
634 oStringValue = str.str();
652 bool fromString(IUIDescription
const *iDescription, std::string
const &iAttributeValue,
Range &oValue)
const override 654 auto parts = Utils::splitFloats<CCoord>(iAttributeValue,
',');
660 if(std::find_if(parts.cbegin(), parts.cend(), [] (
auto f) {
return std::isnan(f);}) != parts.cend())
663 if(parts.size() == 1)
664 oValue =
Range{parts[0]};
666 oValue =
Range{parts[0], parts[1]};
672 bool toString(IUIDescription
const *iDescription,
const Range &iValue, std::string &oStringValue)
const override 674 std::stringstream str;
683 oStringValue = str.str();
691 char const *iDisplayName =
nullptr,
692 char const *iBaseViewName = VSTGUI::UIViewCreator::kCView) :
693 fViewName{iViewName},
694 fDisplayName{iDisplayName},
695 fBaseViewName{iBaseViewName},
699 if(iViewName !=
nullptr && iDisplayName !=
nullptr)
700 VSTGUI::UIViewFactory::registerViewCreator(*
this);
726 return fBaseViewName;
732 template<
typename XView>
737 registerAttribute(attribute.second);
740 if(std::string(fBaseViewName) == std::string(VSTGUI::UIViewCreator::kCView))
748 typename ColorAttribute::Getter iGetter,
749 typename ColorAttribute::Setter iSetter)
751 registerAttribute<ColorAttribute>(iName, iGetter, iSetter);
758 typename GradientAttribute::Getter iGetter,
759 typename GradientAttribute::Setter iSetter)
761 registerAttribute<GradientAttribute>(iName, iGetter, iSetter);
768 typename BitmapAttribute::Getter iGetter,
769 typename BitmapAttribute::Setter iSetter)
771 registerAttribute<BitmapAttribute>(iName, iGetter, iSetter);
778 typename FontAttribute::Getter iGetter,
779 typename FontAttribute::Setter iSetter)
781 registerAttribute<FontAttribute>(iName, iGetter, iSetter);
788 typename MarginAttribute::Getter iGetter,
789 typename MarginAttribute::Setter iSetter)
791 registerAttribute<MarginAttribute>(iName, iGetter, iSetter);
798 typename RangeAttribute::Getter iGetter,
799 typename RangeAttribute::Setter iSetter)
801 registerAttribute<RangeAttribute>(iName, iGetter, iSetter);
808 typename TagAttribute::Getter iGetter,
809 typename TagAttribute::Setter iSetter)
811 registerAttribute<TagAttribute>(iName, iGetter, iSetter);
817 template<
typename TInt>
819 typename IntegerAttribute<TInt>::Getter iGetter,
820 typename IntegerAttribute<TInt>::Setter iSetter)
822 registerAttribute<IntegerAttribute<TInt>>(iName, iGetter, iSetter);
829 typename IntegerAttribute<int32_t>::Getter iGetter,
830 typename IntegerAttribute<int32_t>::Setter iSetter)
832 registerIntegerAttribute<int32_t>(iName, iGetter, iSetter);
839 typename FloatAttribute<float>::Getter iGetter,
840 typename FloatAttribute<float>::Setter iSetter)
842 registerAttribute<FloatAttribute<float>>(iName, iGetter, iSetter);
849 typename FloatAttribute<double>::Getter iGetter,
850 typename FloatAttribute<double>::Setter iSetter)
852 registerAttribute<FloatAttribute<double>>(iName, iGetter, iSetter);
859 typename BooleanAttribute::Getter iGetter,
860 typename BooleanAttribute::Setter iSetter)
862 registerAttribute<BooleanAttribute>(iName, iGetter, iSetter);
868 CView *
create(
const UIAttributes &attributes,
const IUIDescription *description)
const override 870 #ifdef JAMBA_DEBUG_LOGGING 871 DLOG_F(INFO,
"CustomViewCreator<%s>::create()", getViewName());
874 return createCustomView<TView>(CRect(0, 0, 0, 0));
881 bool apply(CView *view,
const UIAttributes &attributes,
const IUIDescription *description)
const override 883 auto *tv = dynamic_cast<TView *>(view);
888 for(
auto attribute : fAttributes)
890 attribute.second->apply(tv, attributes, description);
899 for(
auto attribute : fAttributes)
901 attributeNames.emplace_back(attribute.first);
909 auto iter = fAttributes.find(attributeName);
910 if(iter != fAttributes.cend())
912 return iter->second->getType();
921 const std::string &iAttributeName,
922 std::string &oStringValue,
923 const IUIDescription *iDescription)
const override 925 auto *cdv = dynamic_cast<TView *>(iView);
930 auto iter = fAttributes.find(iAttributeName);
931 if(iter != fAttributes.cend())
933 return iter->second->getAttributeValue(cdv, iDescription, oStringValue);
942 template<
typename XView>
951 assert(fAttributes.find(iAttribute->getName()) == fAttributes.cend());
952 fAttributes[iAttribute->getName()] = iAttribute;
958 template<
typename TViewAttribute>
960 typename TViewAttribute::Getter iGetter,
961 typename TViewAttribute::Setter iSetter)
963 std::shared_ptr<ViewAttribute> cva;
964 cva.reset(
new TViewAttribute(iName, iGetter, iSetter));
965 registerAttribute(cva);
974 std::map<std::string, std::shared_ptr<ViewAttribute>>
fAttributes;
980 template<
typename TView,
typename TBaseView>
985 char const *iDisplayName =
nullptr,
986 char const *iBaseViewName = VSTGUI::UIViewCreator::kCView) :
TSetter Setter
Definition: CustomViewCreator.h:134
void registerAttribute(std::string const &iName, typename TViewAttribute::Getter iGetter, typename TViewAttribute::Setter iSetter)
Definition: CustomViewCreator.h:959
Definition: CustomViewCreator.h:981
Definition: CustomViewCreator.h:130
void registerFloatAttribute(std::string const &iName, typename FloatAttribute< float >::Getter iGetter, typename FloatAttribute< float >::Setter iSetter)
Definition: CustomViewCreator.h:838
T fTo
Definition: Lerp.h:332
bool toString(IUIDescription const *iDescription, const CColor &iValue, std::string &oStringValue) const override
Definition: CustomViewCreator.h:391
Definition: CustomViewCreator.h:319
IntegerAttribute(std::string const &iName, Getter iGetter, Setter iSetter)
Definition: CustomViewCreator.h:281
virtual bool fromString(IUIDescription const *iDescription, std::string const &iAttributeValue, T &oValue) const
Definition: CustomViewCreator.h:150
IdStringPtr getBaseViewName() const override
Definition: CustomViewCreator.h:724
bool fromString(IUIDescription const *iDescription, std::string const &iAttributeValue, GradientPtr &oValue) const override
Definition: CustomViewCreator.h:418
Definition: CustomViewCreator.h:583
void registerIntegerAttribute(std::string const &iName, typename IntegerAttribute< TInt >::Getter iGetter, typename IntegerAttribute< TInt >::Setter iSetter)
Definition: CustomViewCreator.h:818
bool apply(CView *view, const UIAttributes &attributes, const IUIDescription *description) const override
Definition: CustomViewCreator.h:881
void registerTagAttribute(std::string const &iName, typename TagAttribute::Getter iGetter, typename TagAttribute::Setter iSetter)
Definition: CustomViewCreator.h:807
void registerBooleanAttribute(std::string const &iName, typename BooleanAttribute::Getter iGetter, typename BooleanAttribute::Setter iSetter)
Definition: CustomViewCreator.h:858
bool getAttributeNames(std::list< std::string > &attributeNames) const override
Definition: CustomViewCreator.h:897
IViewCreator::AttrType getType() override
Definition: CustomViewCreator.h:330
CBitmap * BitmapPtr
Definition: Types.h:49
IViewCreator::AttrType getType() override
Definition: CustomViewCreator.h:285
bool toString(IUIDescription const *iDescription, const Range &iValue, std::string &oStringValue) const override
Definition: CustomViewCreator.h:672
bool getAttributeValue(CView *iView, const IUIDescription *iDescription, std::string &oStringValue) const override
Definition: CustomViewCreator.h:185
void registerBitmapAttribute(std::string const &iName, typename BitmapAttribute::Getter iGetter, typename BitmapAttribute::Setter iSetter)
Definition: CustomViewCreator.h:767
bool fromString(IUIDescription const *iDescription, std::string const &iAttributeValue, Range &oValue) const override
Definition: CustomViewCreator.h:652
Definition: CustomViewCreator.h:643
Definition: CustomViewCreator.h:495
Definition: CustomViewCreator.h:274
void registerGradientAttribute(std::string const &iName, typename GradientAttribute::Getter iGetter, typename GradientAttribute::Setter iSetter)
Definition: CustomViewCreator.h:757
Definition: CustomViewCreator.h:362
CustomViewCreator(char const *iViewName=nullptr, char const *iDisplayName=nullptr, char const *iBaseViewName=VSTGUI::UIViewCreator::kCView)
Definition: CustomViewCreator.h:984
bool toString(IUIDescription const *iDescription, const int32_t &iValue, std::string &oStringValue) const override
Definition: CustomViewCreator.h:253
bool toString(IUIDescription const *iDescription, const bool &iValue, std::string &oStringValue) const override
Definition: CustomViewCreator.h:484
bool fromString(IUIDescription const *iDescription, std::string const &iAttributeValue, CColor &oValue) const override
Definition: CustomViewCreator.h:379
ViewAttribute(std::string iName)
Definition: CustomViewCreator.h:49
bool toString(IUIDescription const *iDescription, const TInt &iValue, std::string &oStringValue) const override
Definition: CustomViewCreator.h:305
bool fromString(IUIDescription const *iDescription, std::string const &iAttributeValue, FontPtr &oValue) const override
Definition: CustomViewCreator.h:552
IViewCreator::AttrType getType() override
Definition: CustomViewCreator.h:373
FloatAttribute(std::string const &iName, Getter iGetter, Setter iSetter)
Definition: CustomViewCreator.h:326
TView * createCustomView(CRect const &iSize)
Definition: CustomViewCreator.h:92
TAttribute< T, T const &(StepButtonView ::*)() const, void(StepButtonView ::*)(T const &)> ByRefAttribute
Definition: CustomViewCreator.h:211
bool fromString(IUIDescription const *iDescription, std::string const &iAttributeValue, int32_t &oValue) const override
Definition: CustomViewCreator.h:232
virtual bool toString(IUIDescription const *iDescription, T const &iValue, std::string &oStringValue) const
Definition: CustomViewCreator.h:159
CView * create(const UIAttributes &attributes, const IUIDescription *description) const override
Definition: CustomViewCreator.h:868
MarginAttribute(std::string const &iName, typename ByRefAttribute< Margin >::Getter iGetter, typename ByRefAttribute< Margin >::Setter iSetter)
Definition: CustomViewCreator.h:586
Definition: CustomViewCreator.h:217
TCustomViewCreator(char const *iViewName=nullptr, char const *iDisplayName=nullptr, char const *iBaseViewName=VSTGUI::UIViewCreator::kCView)
Definition: CustomViewCreator.h:690
std::string getName() const
Definition: CustomViewCreator.h:62
IViewCreator::AttrType getType() override
Definition: CustomViewCreator.h:546
char const * fBaseViewName
Definition: CustomViewCreator.h:971
void registerAttribute(std::shared_ptr< ViewAttribute > iAttribute)
Definition: CustomViewCreator.h:948
bool toString(IUIDescription const *iDescription, const Margin &iValue, std::string &oStringValue) const override
Definition: CustomViewCreator.h:619
IdStringPtr getViewName() const override
Definition: CustomViewCreator.h:712
Definition: LookAndFeel.h:32
GradientAttribute(std::string const &iName, typename ByValAttribute< GradientPtr >::Getter iGetter, typename ByValAttribute< GradientPtr >::Setter iSetter)
Definition: CustomViewCreator.h:406
TAttribute< T, T(StepButtonView ::*)() const, void(StepButtonView ::*)(T)> ByValAttribute
Definition: CustomViewCreator.h:205
Definition: CustomViewCreator.h:401
Definition: CustomViewCreator.h:536
std::string fName
Definition: CustomViewCreator.h:84
bool fromString(IUIDescription const *iDescription, std::string const &iAttributeValue, TFloat &oValue) const override
Definition: CustomViewCreator.h:336
char const * fDisplayName
Definition: CustomViewCreator.h:970
CCoord fLeft
Definition: LookAndFeel.h:61
void registerRangeAttribute(std::string const &iName, typename RangeAttribute::Getter iGetter, typename RangeAttribute::Setter iSetter)
Definition: CustomViewCreator.h:797
ColorAttribute(std::string const &iName, typename ByRefAttribute< CColor >::Getter iGetter, typename ByRefAttribute< CColor >::Setter iSetter)
Definition: CustomViewCreator.h:367
void registerFontAttribute(std::string const &iName, typename FontAttribute::Getter iGetter, typename FontAttribute::Setter iSetter)
Definition: CustomViewCreator.h:777
IViewCreator::AttrType getType() override
Definition: CustomViewCreator.h:141
bool fromString(IUIDescription const *iDescription, std::string const &iAttributeValue, BitmapPtr &oValue) const override
Definition: CustomViewCreator.h:511
bool toString(IUIDescription const *iDescription, const TFloat &iValue, std::string &oStringValue) const override
Definition: CustomViewCreator.h:349
IViewCreator::AttrType getType() override
Definition: CustomViewCreator.h:226
bool toString(IUIDescription const *iDescription, GradientPtr const &iValue, std::string &oStringValue) const override
Definition: CustomViewCreator.h:430
BitmapAttribute(std::string const &iName, typename ByValAttribute< BitmapPtr >::Getter iGetter, typename ByValAttribute< BitmapPtr >::Setter iSetter)
Definition: CustomViewCreator.h:499
void registerMarginAttribute(std::string const &iName, typename MarginAttribute::Getter iGetter, typename MarginAttribute::Setter iSetter)
Definition: CustomViewCreator.h:787
bool fromString(IUIDescription const *iDescription, std::string const &iAttributeValue, TInt &oValue) const override
Definition: CustomViewCreator.h:291
bool fromString(IUIDescription const *iDescription, std::string const &iAttributeValue, Margin &oValue) const override
Definition: CustomViewCreator.h:592
std::map< std::string, std::shared_ptr< ViewAttribute > > fAttributes
Definition: CustomViewCreator.h:974
bool getAttributeValue(CView *iView, const std::string &iAttributeName, std::string &oStringValue, const IUIDescription *iDescription) const override
Definition: CustomViewCreator.h:920
IViewCreator::AttrType getType() override
Definition: CustomViewCreator.h:460
FontAttribute(std::string const &iName, typename ByValAttribute< FontPtr >::Getter iGetter, typename ByValAttribute< FontPtr >::Setter iSetter)
Definition: CustomViewCreator.h:540
T fFrom
Definition: Lerp.h:331
bool fromString(IUIDescription const *iDescription, std::string const &iAttributeValue, bool &oValue) const override
Definition: CustomViewCreator.h:466
void registerIntAttribute(std::string const &iName, typename IntegerAttribute< int32_t >::Getter iGetter, typename IntegerAttribute< int32_t >::Setter iSetter)
Definition: CustomViewCreator.h:828
RangeAttribute(std::string const &iName, typename ByRefAttribute< Range >::Getter iGetter, typename ByRefAttribute< Range >::Setter iSetter)
Definition: CustomViewCreator.h:646
bool apply(CView *iView, const UIAttributes &iAttributes, const IUIDescription *iDescription) override
Definition: CustomViewCreator.h:165
void registerAttributes(TCustomViewCreator< XView > const &iOther)
Definition: CustomViewCreator.h:733
TAttribute(std::string const &iName, Getter iGetter, Setter iSetter)
Definition: CustomViewCreator.h:137
BooleanAttribute(std::string const &iName, typename ByValAttribute< bool >::Getter iGetter, typename ByValAttribute< bool >::Setter iSetter)
Definition: CustomViewCreator.h:454
CCoord fTop
Definition: LookAndFeel.h:58
IViewCreator::AttrType getType() override
Definition: CustomViewCreator.h:412
UTF8StringPtr getDisplayName() const override
Definition: CustomViewCreator.h:718
char const * fViewName
Definition: CustomViewCreator.h:969
IViewCreator::AttrType getType() override
Definition: CustomViewCreator.h:505
~TCustomViewCreator() override
Definition: CustomViewCreator.h:704
bool toString(IUIDescription const *iDescription, BitmapPtr const &iValue, std::string &oStringValue) const override
Definition: CustomViewCreator.h:523
CCoord fRight
Definition: LookAndFeel.h:59
Definition: CustomViewCreator.h:121
void registerColorAttribute(std::string const &iName, typename ColorAttribute::Getter iGetter, typename ColorAttribute::Setter iSetter)
Definition: CustomViewCreator.h:747
void registerDoubleAttribute(std::string const &iName, typename FloatAttribute< double >::Getter iGetter, typename FloatAttribute< double >::Setter iSetter)
Definition: CustomViewCreator.h:848
Definition: CustomViewCreator.h:450
AttrType getAttributeType(const std::string &attributeName) const override
Definition: CustomViewCreator.h:907
TGetter Getter
Definition: CustomViewCreator.h:133
bool toString(IUIDescription const *iDescription, FontPtr const &iValue, std::string &oStringValue) const override
Definition: CustomViewCreator.h:564
CFontDesc * FontPtr
Definition: Types.h:53
Getter fGetter
Definition: CustomViewCreator.h:197
Definition: CustomViewCreator.h:45
CCoord fBottom
Definition: LookAndFeel.h:60
Setter fSetter
Definition: CustomViewCreator.h:198
TagAttribute(std::string const &iName, typename ByValAttribute< int32_t >::Getter iGetter, typename ByValAttribute< int32_t >::Setter iSetter)
Definition: CustomViewCreator.h:220
CGradient * GradientPtr
Definition: Types.h:57