Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add 'Load From SVG Resource' for bitmap property #817

Merged
merged 4 commits into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/codegen/cppcg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
3 changes: 3 additions & 0 deletions src/codegen/luacg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
5 changes: 3 additions & 2 deletions src/codegen/phpcg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 ', '.
Expand Down
4 changes: 4 additions & 0 deletions src/codegen/pythoncg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
35 changes: 26 additions & 9 deletions src/rad/inspector/wxfbadvprops.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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(
Expand All @@ -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;
}

Expand All @@ -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."));

Expand All @@ -282,6 +289,15 @@ wxPGProperty* wxFBBitmapProperty::CreatePropertyIconSize()
return propIcoSize;
}

wxPGProperty* wxFBBitmapProperty::CreatePropertyDefaultSize()
{
// Create 'def_size' property ('Load From SVG Resource' only)
wxPGProperty* propDefSize = new wxFBSizeProperty(wxT("def_size"), wxPG_LABEL, {16, 16});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is 16 used as default value? Pretty much in every other place of wxFB a defined default value like wxDefaultSize (-1, -1) is used, can't this be used here as well?

Copy link
Author

@vadimgrn vadimgrn May 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wxDefaultSize(-1, -1) crashes the app. wxBitmapBundle::FromSVGResource expects real WxH because SVG doesn't have size, it will be rasterized to BMP with passed size. 16x16 is used for menu items, 24x24 for toolbars, etc.

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)
Expand Down Expand Up @@ -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 childVal = childValue.GetInteger()) {
// 'Load From File' and 'Load From Embedded File'
case 0:
case 1: {
Expand Down Expand Up @@ -542,17 +558,18 @@ 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());
GetGrid()->DeleteProperty(p);
}
}
bp->AppendChild(bp->CreatePropertyResourceName());
bp->AppendChild(bp->CreatePropertyIconSize());
bp->AppendChild(childVal == 3 ? bp->CreatePropertyIconSize() : bp->CreatePropertyDefaultSize());
}

if (childVals.GetCount() == 3) {
Expand Down Expand Up @@ -663,7 +680,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]);
}
Expand Down
1 change: 1 addition & 0 deletions src/rad/inspector/wxfbadvprops.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ class wxFBBitmapProperty : public wxPGProperty
wxPGProperty* CreatePropertyFilePath();
wxPGProperty* CreatePropertyResourceName();
wxPGProperty* CreatePropertyIconSize();
wxPGProperty* CreatePropertyDefaultSize();
wxPGProperty* CreatePropertyXrcName();
wxPGProperty* CreatePropertyArtId();
wxPGProperty* CreatePropertyArtClient();
Expand Down