From a10d1d632890bc7a5fafbac3fef0ab30ce7ea42b Mon Sep 17 00:00:00 2001 From: Vadym Hrynchyshyn Date: Thu, 9 May 2024 15:31:58 +0300 Subject: [PATCH 1/4] Add 'Load From SVG Resource' for bitmap property Signed-off-by: Vadym Hrynchyshyn --- src/codegen/cppcg.cpp | 3 +++ src/rad/inspector/wxfbadvprops.cpp | 36 ++++++++++++++++++++++-------- src/rad/inspector/wxfbadvprops.h | 1 + 3 files changed, 31 insertions(+), 9 deletions(-) diff --git a/src/codegen/cppcg.cpp b/src/codegen/cppcg.cpp index 25aa60b8b..b0d593af6 100644 --- a/src/codegen/cppcg.cpp +++ b/src/codegen/cppcg.cpp @@ -256,6 +256,9 @@ wxString CppTemplateParser::ValueToCode(PropertyType type, wxString value) rid = wxT("wxT(\"") + rid + wxT("\")"); result = wxT("wxArtProvider::GetBitmap( wxASCII_STR(") + rid + wxT("), wxASCII_STR(") + path.AfterFirst(wxT(':')) + wxT(") )"); + } else if (source == _("Load From SVG Resource")) { + result.Printf( wxT("wxBitmapBundle::FromSVGResource( wxT(\"%s\"), {%i, %i} )"), + path, icoSize.GetWidth(), icoSize.GetHeight()); } break; } diff --git a/src/rad/inspector/wxfbadvprops.cpp b/src/rad/inspector/wxfbadvprops.cpp index d67c00d21..c1d21d28a 100644 --- a/src/rad/inspector/wxfbadvprops.cpp +++ b/src/rad/inspector/wxfbadvprops.cpp @@ -209,6 +209,8 @@ void wxFBBitmapProperty::CreateChildren() childIndex = 4; } else if (source == wxString(_("Load From Art Provider"))) { childIndex = 5; + } else if (source == wxString(_("Load From SVG Resource"))) { + childIndex = 6; } childValue = WXVARIANT(childIndex); @@ -229,6 +231,7 @@ wxPGProperty* wxFBBitmapProperty::CreatePropertySource(int sourceIndex) sourceChoices.Add(_("Load From Icon Resource")); sourceChoices.Add(_("Load From XRC")); sourceChoices.Add(_("Load From Art Provider")); + sourceChoices.Add(_("Load From SVG Resource")); wxPGProperty* srcProp = new wxEnumProperty(wxT("source"), wxPG_LABEL, sourceChoices, sourceIndex); srcProp->SetHelpString( @@ -244,9 +247,13 @@ wxPGProperty* wxFBBitmapProperty::CreatePropertySource(int sourceIndex) wxString( _("Load the image from XRC resources. The XRC resources must be initialized by the application code.\n\n")) + wxString(_("Load From Art Provider:\n")) + - wxString(_("Query registered providers for bitmap with given ID.\n\n"))); - AppendChild(srcProp); + wxString(_("Query registered providers for bitmap with given ID.\n\n")) + + wxString(_("Load From SVG Resource:\n")) + + wxString(_("On Windows, resource name must be a resource with RT_RCDATA type.\n")) + + wxString(_("On MacOS, resource name must be a file with an extension 'svg' placed in the " + "'Resources' subdirectory of the application bundle.\n\n"))); + AppendChild(srcProp); return srcProp; } @@ -266,7 +273,7 @@ wxPGProperty* wxFBBitmapProperty::CreatePropertyFilePath() wxPGProperty* wxFBBitmapProperty::CreatePropertyResourceName() { - // Create 'resource_name' property (common for 'Load From Resource' and 'Load From Icon Resource' choices) + // Create 'resource_name' property (common for 'Load From Resource', 'Load From Icon Resource', 'Load From SVG Resource' choices) wxPGProperty* propResName = new wxStringProperty(wxT("resource_name"), wxPG_LABEL); propResName->SetHelpString(_("Windows Only. Name of the resource in the .rc file.")); @@ -282,6 +289,15 @@ wxPGProperty* wxFBBitmapProperty::CreatePropertyIconSize() return propIcoSize; } +wxPGProperty* wxFBBitmapProperty::CreatePropertyDefSize() +{ + // Create 'def_size' property ('Load From SVG Resource' only) + wxPGProperty* propDefSize = new wxFBSizeProperty(wxT("def_size"), wxPG_LABEL, {16, 16}); + propDefSize->SetHelpString(_("The default size to return from GetDefaultSize() for this wxBitmapBundle.")); + + return propDefSize; +} + wxPGProperty* wxFBBitmapProperty::CreatePropertyXrcName() { // Create 'xrc_name' property ('Load From XRC' only) @@ -502,7 +518,7 @@ wxVariant wxFBBitmapProperty::ChildChanged(wxVariant& thisValue, const int child const auto count = GetChildCount(); // childValue.GetInteger() returns the chosen item index - switch (childValue.GetInteger()) { + switch (auto child_val = childValue.GetInteger()) { // 'Load From File' and 'Load From Embedded File' case 0: case 1: { @@ -542,9 +558,10 @@ wxVariant wxFBBitmapProperty::ChildChanged(wxVariant& thisValue, const int child } break; } - // 'Load From Icon Resource' - case 3: { - if (prevSrc != 3) { + // 'Load From Icon Resource' and 'Load From SVG Resource' + case 3: + case 6: { + if (prevSrc != 3 && prevSrc != 6) { for (unsigned int i = 1; i < count; ++i) { if (auto* p = Item(i)) { wxLogDebug(wxT("wxFBBP::ChildChanged: Removing:%s"), p->GetLabel()); @@ -552,7 +569,8 @@ wxVariant wxFBBitmapProperty::ChildChanged(wxVariant& thisValue, const int child } } bp->AppendChild(bp->CreatePropertyResourceName()); - bp->AppendChild(bp->CreatePropertyIconSize()); + auto prop = child_val == 3 ? bp->CreatePropertyIconSize() : bp->CreatePropertyDefSize(); + bp->AppendChild(prop); } if (childVals.GetCount() == 3) { @@ -663,7 +681,7 @@ void wxFBBitmapProperty::UpdateChildValues(const wxString& value) if (childVals.Count() > 1) { Item(1)->SetValue(childVals[1]); } - } else if (childVals[0].Contains(_("Load From Icon Resource"))) { + } else if (childVals[0].Contains(_("Load From Icon Resource")) || childVals[0].Contains(_("Load From SVG Resource"))) { if (childVals.Count() > 1) { Item(1)->SetValue(childVals[1]); } diff --git a/src/rad/inspector/wxfbadvprops.h b/src/rad/inspector/wxfbadvprops.h index f0e3721f7..a1b7cccfe 100644 --- a/src/rad/inspector/wxfbadvprops.h +++ b/src/rad/inspector/wxfbadvprops.h @@ -96,6 +96,7 @@ class wxFBBitmapProperty : public wxPGProperty wxPGProperty* CreatePropertyFilePath(); wxPGProperty* CreatePropertyResourceName(); wxPGProperty* CreatePropertyIconSize(); + wxPGProperty* CreatePropertyDefSize(); wxPGProperty* CreatePropertyXrcName(); wxPGProperty* CreatePropertyArtId(); wxPGProperty* CreatePropertyArtClient(); From 71b0ebeeb40f5f88eec33c233f2133bc20a36100 Mon Sep 17 00:00:00 2001 From: Vadym Hrynchyshyn Date: Thu, 16 May 2024 10:45:39 +0300 Subject: [PATCH 2/4] Add code generation for other languages Signed-off-by: Vadym Hrynchyshyn --- src/codegen/luacg.cpp | 3 +++ src/codegen/phpcg.cpp | 5 +++-- src/codegen/pythoncg.cpp | 4 ++++ src/rad/inspector/wxfbadvprops.cpp | 7 +++---- src/rad/inspector/wxfbadvprops.h | 2 +- 5 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/codegen/luacg.cpp b/src/codegen/luacg.cpp index 0f7227e16..f3402e9ca 100644 --- a/src/codegen/luacg.cpp +++ b/src/codegen/luacg.cpp @@ -297,6 +297,9 @@ wxString LuaTemplateParser::ValueToCode(PropertyType type, wxString value) cid.Replace(wxT("wx"), wxT("wx.wx")); result = wxT("wx.wxArtProvider.GetBitmap( ") + rid + wxT(", ") + cid + wxT(" )"); + } else if (source == _("Load From SVG Resource")) { + wxLogWarning(wxT("Lua code generation does not support using SVG resources for bitmap properties:\n%s"), path); + result = wxT("wx.wxNullBitmap"); } break; } diff --git a/src/codegen/phpcg.cpp b/src/codegen/phpcg.cpp index dc97cf143..ef8dc8d28 100644 --- a/src/codegen/phpcg.cpp +++ b/src/codegen/phpcg.cpp @@ -241,10 +241,11 @@ wxString PHPTemplateParser::ValueToCode(PropertyType type, wxString value) rid = wxT("wxT(\"") + rid + wxT("\")"); result = wxT("wxArtProvider::GetBitmap( ") + rid + wxT(", ") + path.AfterFirst(wxT(':')) + wxT(" )"); + } else if (source == _("Load From SVG Resource")) { + wxLogWarning(wxT("PHP code generation does not support using SVG resources for bitmap properties:\n%s"), path); + result = wxT("wxNullBitmap"); } break; - - break; } case PT_STRINGLIST: { // Stringlists are generated like a sequence of wxString separated by ', '. diff --git a/src/codegen/pythoncg.cpp b/src/codegen/pythoncg.cpp index a4655e85e..414dda9ac 100644 --- a/src/codegen/pythoncg.cpp +++ b/src/codegen/pythoncg.cpp @@ -290,6 +290,10 @@ wxString PythonTemplateParser::ValueToCode(PropertyType type, wxString value) cid.Replace(wxT("wx"), wxT("wx.")); result = wxT("wx.ArtProvider.GetBitmap( ") + rid + wxT(", ") + cid + wxT(" )"); + } else if (source == _("Load From SVG Resource")) { + wxLogWarning( + wxT("Python code generation does not support using SVG resources for bitmap properties:\n%s"), path); + result = wxT("wx.NullBitmap"); } break; } diff --git a/src/rad/inspector/wxfbadvprops.cpp b/src/rad/inspector/wxfbadvprops.cpp index c1d21d28a..bb303f10e 100644 --- a/src/rad/inspector/wxfbadvprops.cpp +++ b/src/rad/inspector/wxfbadvprops.cpp @@ -289,7 +289,7 @@ wxPGProperty* wxFBBitmapProperty::CreatePropertyIconSize() return propIcoSize; } -wxPGProperty* wxFBBitmapProperty::CreatePropertyDefSize() +wxPGProperty* wxFBBitmapProperty::CreatePropertyDefaultSize() { // Create 'def_size' property ('Load From SVG Resource' only) wxPGProperty* propDefSize = new wxFBSizeProperty(wxT("def_size"), wxPG_LABEL, {16, 16}); @@ -518,7 +518,7 @@ wxVariant wxFBBitmapProperty::ChildChanged(wxVariant& thisValue, const int child const auto count = GetChildCount(); // childValue.GetInteger() returns the chosen item index - switch (auto child_val = childValue.GetInteger()) { + switch (auto childVal = childValue.GetInteger()) { // 'Load From File' and 'Load From Embedded File' case 0: case 1: { @@ -569,8 +569,7 @@ wxVariant wxFBBitmapProperty::ChildChanged(wxVariant& thisValue, const int child } } bp->AppendChild(bp->CreatePropertyResourceName()); - auto prop = child_val == 3 ? bp->CreatePropertyIconSize() : bp->CreatePropertyDefSize(); - bp->AppendChild(prop); + bp->AppendChild(childVal == 3 ? bp->CreatePropertyIconSize() : bp->CreatePropertyDefaultSize()); } if (childVals.GetCount() == 3) { diff --git a/src/rad/inspector/wxfbadvprops.h b/src/rad/inspector/wxfbadvprops.h index a1b7cccfe..67eec78f1 100644 --- a/src/rad/inspector/wxfbadvprops.h +++ b/src/rad/inspector/wxfbadvprops.h @@ -96,7 +96,7 @@ class wxFBBitmapProperty : public wxPGProperty wxPGProperty* CreatePropertyFilePath(); wxPGProperty* CreatePropertyResourceName(); wxPGProperty* CreatePropertyIconSize(); - wxPGProperty* CreatePropertyDefSize(); + wxPGProperty* CreatePropertyDefaultSize(); wxPGProperty* CreatePropertyXrcName(); wxPGProperty* CreatePropertyArtId(); wxPGProperty* CreatePropertyArtClient(); From efaa122655523b96ad6fdfcff3998d030afe8447 Mon Sep 17 00:00:00 2001 From: Steffen Olszewski Date: Thu, 16 May 2024 22:00:38 +0200 Subject: [PATCH 3/4] Move `Load From SVG Resource` behind `Load From Icon Resource` In this order all resource based options are grouped together. --- src/rad/inspector/wxfbadvprops.cpp | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/rad/inspector/wxfbadvprops.cpp b/src/rad/inspector/wxfbadvprops.cpp index bb303f10e..8b0e2ce78 100644 --- a/src/rad/inspector/wxfbadvprops.cpp +++ b/src/rad/inspector/wxfbadvprops.cpp @@ -205,11 +205,11 @@ void wxFBBitmapProperty::CreateChildren() childIndex = 2; } else if (source == wxString(_("Load From Icon Resource"))) { childIndex = 3; - } else if (source == wxString(_("Load From XRC"))) { + } else if (source == wxString(_("Load From SVG Resource"))) { childIndex = 4; - } else if (source == wxString(_("Load From Art Provider"))) { + } else if (source == wxString(_("Load From XRC"))) { childIndex = 5; - } else if (source == wxString(_("Load From SVG Resource"))) { + } else if (source == wxString(_("Load From Art Provider"))) { childIndex = 6; } @@ -229,9 +229,9 @@ wxPGProperty* wxFBBitmapProperty::CreatePropertySource(int sourceIndex) sourceChoices.Add(_("Load From Embedded File")); sourceChoices.Add(_("Load From Resource")); sourceChoices.Add(_("Load From Icon Resource")); + sourceChoices.Add(_("Load From SVG Resource")); sourceChoices.Add(_("Load From XRC")); sourceChoices.Add(_("Load From Art Provider")); - sourceChoices.Add(_("Load From SVG Resource")); wxPGProperty* srcProp = new wxEnumProperty(wxT("source"), wxPG_LABEL, sourceChoices, sourceIndex); srcProp->SetHelpString( @@ -243,15 +243,15 @@ wxPGProperty* wxFBBitmapProperty::CreatePropertySource(int sourceIndex) wxString(_("Windows Only. Load the image from a BITMAP resource in a .rc file\n\n")) + wxString(_("Load From Icon Resource:\n")) + wxString(_("Windows Only. Load the image from a ICON resource in a .rc file\n\n")) + + wxString(_("Load From SVG Resource:\n")) + + wxString(_("On Windows, resource name must be a resource with RT_RCDATA type.\n")) + + wxString(_("On MacOS, resource name must be a file with an extension 'svg' placed in the " + "'Resources' subdirectory of the application bundle.\n\n")) + wxString(_("Load From XRC:\n")) + wxString( _("Load the image from XRC resources. The XRC resources must be initialized by the application code.\n\n")) + wxString(_("Load From Art Provider:\n")) + - wxString(_("Query registered providers for bitmap with given ID.\n\n")) + - wxString(_("Load From SVG Resource:\n")) + - wxString(_("On Windows, resource name must be a resource with RT_RCDATA type.\n")) + - wxString(_("On MacOS, resource name must be a file with an extension 'svg' placed in the " - "'Resources' subdirectory of the application bundle.\n\n"))); + wxString(_("Query registered providers for bitmap with given ID.\n\n"))); AppendChild(srcProp); return srcProp; @@ -560,8 +560,8 @@ wxVariant wxFBBitmapProperty::ChildChanged(wxVariant& thisValue, const int child } // 'Load From Icon Resource' and 'Load From SVG Resource' case 3: - case 6: { - if (prevSrc != 3 && prevSrc != 6) { + case 4: { + if (prevSrc != 3 && prevSrc != 4) { for (unsigned int i = 1; i < count; ++i) { if (auto* p = Item(i)) { wxLogDebug(wxT("wxFBBP::ChildChanged: Removing:%s"), p->GetLabel()); @@ -581,8 +581,8 @@ wxVariant wxFBBitmapProperty::ChildChanged(wxVariant& thisValue, const int child break; } // 'Load From XRC' - case 4: { - if (prevSrc != 4) { + case 5: { + if (prevSrc != 5) { for (unsigned int i = 1; i < count; ++i) { if (auto* p = Item(i)) { wxLogDebug(wxT("wxFBBP::ChildChanged: Removing:%s"), p->GetLabel()); @@ -600,8 +600,8 @@ wxVariant wxFBBitmapProperty::ChildChanged(wxVariant& thisValue, const int child break; } // 'Load From Art Provider' - case 5: { - if (prevSrc != 5) { + case 6: { + if (prevSrc != 6) { for (unsigned int i = 1; i < count; ++i) { if (auto* p = Item(i)) { wxLogDebug(wxT("wxFBBP::ChildChanged: Removing:%s"), p->GetLabel()); From 59e8b6d3927c6f48a70bd6099615cef24ef1c7b5 Mon Sep 17 00:00:00 2001 From: Steffen Olszewski Date: Thu, 16 May 2024 22:05:23 +0200 Subject: [PATCH 4/4] Fix child update of `Load From Icon/SVG Resource` Although both types have a common child, they have a different child for their size property, so a child update is necessary on type change. --- src/rad/inspector/wxfbadvprops.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rad/inspector/wxfbadvprops.cpp b/src/rad/inspector/wxfbadvprops.cpp index 8b0e2ce78..008c77b05 100644 --- a/src/rad/inspector/wxfbadvprops.cpp +++ b/src/rad/inspector/wxfbadvprops.cpp @@ -561,7 +561,7 @@ wxVariant wxFBBitmapProperty::ChildChanged(wxVariant& thisValue, const int child // 'Load From Icon Resource' and 'Load From SVG Resource' case 3: case 4: { - if (prevSrc != 3 && prevSrc != 4) { + if (prevSrc != childVal) { for (unsigned int i = 1; i < count; ++i) { if (auto* p = Item(i)) { wxLogDebug(wxT("wxFBBP::ChildChanged: Removing:%s"), p->GetLabel());