Skip to content

Commit

Permalink
Merge pull request #432 from sodevel/feature_xrcresource
Browse files Browse the repository at this point in the history
Adds the feature to load bitmap resources from XRC
  • Loading branch information
jhasse committed Sep 5, 2018
2 parents ad55cbc + f1c561b commit 7d9d60e
Show file tree
Hide file tree
Showing 7 changed files with 167 additions and 82 deletions.
2 changes: 1 addition & 1 deletion sdk/plugin_interface/xrcconv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ void ObjectToXrcFilter::AddProperty( const wxString &objPropName,
break;
}

if ( bitmapProp.StartsWith( _("Load From File") ) || bitmapProp.StartsWith( _("Load From Embedded File") ) )
if (bitmapProp.StartsWith(_("Load From File")) || bitmapProp.StartsWith(_("Load From Embedded File")) || bitmapProp.StartsWith(_("Load From XRC")))
{
LinkText( filename.Trim().Trim(false), &propElement );
}
Expand Down
10 changes: 10 additions & 0 deletions src/codegen/cppcg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,10 @@ wxString CppTemplateParser::ValueToCode( PropertyType type, wxString value )
result.Printf( wxT( "wxIcon( wxT(\"%s\"), wxBITMAP_TYPE_ICO_RESOURCE, %i, %i )" ), path.c_str(), icoSize.GetWidth(), icoSize.GetHeight() );
}
}
else if (source == _("Load From XRC"))
{
result << wxT("wxXmlResource::Get()->LoadBitmap( wxT(\"") << path << wxT("\") )");
}
else if ( source == _("Load From Art Provider") )
{
wxString rid = path.BeforeFirst( wxT(':') );
Expand Down Expand Up @@ -2020,6 +2024,12 @@ void CppCodeGenerator::FindEmbeddedBitmapProperties( PObjectBase obj, std::set<w
inc << wxT( "#include \"" ) << includePath << wxT( "\"" );
embedset.insert( inc );
}
// NOTE: This is currently not necessary because the default code already contains this header.
// Because the unique include filtering is not global this cannot be enabled without creating a duplicate entry.
//else if (source == _("Load From XRC"))
//{
// embedset.insert(wxT("#include <wx/xrc/xmlres.h>"));
//}
}
}

Expand Down
5 changes: 5 additions & 0 deletions src/codegen/luacg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,11 @@ wxString LuaTemplateParser::ValueToCode( PropertyType type, wxString value )
result.Printf( wxT("wx.Icon( u\"%s\", wx.wxBITMAP_TYPE_ICO_RESOURCE, %i, %i )"), path.c_str(), icoSize.GetWidth(), icoSize.GetHeight() );
}*/
}
else if (source == _("Load From XRC"))
{
// This requires that the global wxXmlResource object is set
result << wxT("wx.wxXmlResource.Get():LoadBitmap( \"") << path << wxT("\" )");
}
else if ( source == _("Load From Art Provider") )
{
wxString rid = path.BeforeFirst( wxT(':') );
Expand Down
5 changes: 5 additions & 0 deletions src/codegen/phpcg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,11 @@ wxString PHPTemplateParser::ValueToCode( PropertyType type, wxString value )
result.Printf( wxT("new wxIcon( \"%s\", wxBITMAP_TYPE_ICO_RESOURCE, %i, %i )"), path.c_str(), icoSize.GetWidth(), icoSize.GetHeight() );
}
}
else if (source == _("Load From XRC"))
{
// This requires that the global wxXmlResource object is set
result << wxT("wxXmlResource::Get()->LoadBitmap( \"") << path << wxT("\" )");
}
else if ( source == _("Load From Art Provider") )
{
wxString rid = path.BeforeFirst( wxT(':') );
Expand Down
5 changes: 5 additions & 0 deletions src/codegen/pythoncg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,11 @@ wxString PythonTemplateParser::ValueToCode( PropertyType type, wxString value )
result.Printf( wxT("wx.Icon( u\"%s\", wx.BITMAP_TYPE_ICO_RESOURCE, %i, %i )"), path.c_str(), icoSize.GetWidth(), icoSize.GetHeight() );
}
}
else if (source == _("Load From XRC"))
{
// NOTE: The module wx.xrc is part of the default code template
result << wxT("wx.xrc.XmlResource.Get().LoadBitmap( u\"") << path << wxT("\" )");
}
else if ( source == _("Load From Art Provider") )
{
wxString rid = path.BeforeFirst( wxT(':') );
Expand Down
221 changes: 140 additions & 81 deletions src/rad/inspector/wxfbadvprops.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,10 +219,14 @@ void wxFBBitmapProperty::CreateChildren()
{
childIndex = 3;
}
else if ( source == wxString(_("Load From Art Provider") ) )
else if (source == wxString(_("Load From XRC")))
{
childIndex = 4;
}
else if (source == wxString(_("Load From Art Provider")))
{
childIndex = 5;
}

childValue = WXVARIANT( childIndex );

Expand All @@ -240,6 +244,7 @@ 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 XRC"));
sourceChoices.Add(_("Load From Art Provider") );

wxPGProperty *srcProp = new wxEnumProperty( wxT("source"), wxPG_LABEL, sourceChoices, sourceIndex );
Expand All @@ -251,6 +256,8 @@ 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 XRC:\n")) +
wxString(_("Load the image from XRC ressources. The XRC ressources 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 );
Expand Down Expand Up @@ -291,6 +298,15 @@ wxPGProperty *wxFBBitmapProperty::CreatePropertyIconSize()
return propIcoSize;
}

wxPGProperty* wxFBBitmapProperty::CreatePropertyXrcName()
{
// Create 'xrc_name' property ('Load From XRC' only)
auto* propXRCName = new wxStringProperty(wxT("xrc_name"), wxPG_LABEL);
propXRCName->SetHelpString(_("Name of the item in the XRC ressources."));

return propXRCName;
}

wxPGProperty *wxFBBitmapProperty::CreatePropertyArtId()
{
wxPGChoices artIdChoices;
Expand Down Expand Up @@ -483,128 +499,164 @@ wxFBBitmapProperty::~wxFBBitmapProperty()
}

wxVariant wxFBBitmapProperty::ChildChanged(wxVariant& thisValue, const int childIndex,
wxVariant& childValue) const {
wxFBBitmapProperty* bp = (wxFBBitmapProperty*)this;
wxVariant& childValue) const
{
auto* bp = const_cast<wxFBBitmapProperty*>(this);

wxString val = thisValue.GetString();
const auto val = thisValue.GetString();
wxArrayString childVals;
GetChildValues( val, childVals );
wxString newVal = val;
GetChildValues(val, childVals);
auto newVal = val;

// Find the appropriate new state
switch ( childIndex )
{
// source
case 0:
{
unsigned int count = GetChildCount();
// Find the appropriate new state
switch (childIndex)
{
// source
case 0:
{
const auto count = GetChildCount();

// childValue.GetInteger() returns the chosen item index
switch ( childValue.GetInteger() )
{
// 'Load From File' and 'Load From Embedded File'
case 0:
case 1:
{
if( prevSrc != 0 && prevSrc!= 1 )
// childValue.GetInteger() returns the chosen item index
switch (childValue.GetInteger())
{
// 'Load From File' and 'Load From Embedded File'
case 0:
case 1:
{
if (prevSrc != 0 && prevSrc!= 1)
{
for ( unsigned int i = 1; i<count ;i++ )
for (unsigned int i = 1; i < count ; ++i)
{
wxPGProperty *p = Item(i) ;
if ( p )
if (auto* p = Item(i))
{
wxLogDebug( wxT("wxFBBP::ChildChanged: Removing:%s"), p->GetLabel().c_str() );
GetGrid()->DeleteProperty( p );
wxLogDebug(wxT("wxFBBP::ChildChanged: Removing:%s"), p->GetLabel().c_str());
GetGrid()->DeleteProperty(p);
}
}
bp->AppendChild( bp->CreatePropertyFilePath() );
bp->AppendChild(bp->CreatePropertyFilePath());
}

if( childVals.GetCount() == 2 )
if (childVals.GetCount() == 2)
{
newVal = childVals.Item(0) + wxT("; ") + childVals.Item(1);
else if( childVals.GetCount() > 1 )
}
else if (childVals.GetCount() > 0)
{
newVal = childVals.Item(0) + wxT("; ");

break;
}
// 'Load From Resource'
case 2:
{
if( prevSrc != 2 )
}
break;
}
// 'Load From Resource'
case 2:
{
if (prevSrc != 2)
{
for ( unsigned int i = 1; i<count ;i++ )
for (unsigned int i = 1; i < count ; ++i)
{
wxPGProperty *p = Item(i) ;
if ( p )
if (auto* p = Item(i))
{
wxLogDebug( wxT("wxFBBP::ChildChanged: Removing:%s"), p->GetLabel().c_str() );
GetGrid()->DeleteProperty( p );
wxLogDebug(wxT("wxFBBP::ChildChanged: Removing:%s"), p->GetLabel().c_str());
GetGrid()->DeleteProperty(p);
}
}
bp->AppendChild( bp->CreatePropertyResourceName() );
bp->AppendChild(bp->CreatePropertyResourceName());
}

if( childVals.GetCount() == 2)
if (childVals.GetCount() == 2)
{
newVal = childVals.Item(0) + wxT("; ") + childVals.Item(1);
else if( childVals.GetCount() > 1 )
}
else if (childVals.GetCount() > 0)
{
newVal = childVals.Item(0) + wxT("; ");

break;
}
// 'Load From Icon Resource'
case 3:
{
if( prevSrc != 3 )
}
break;
}
// 'Load From Icon Resource'
case 3:
{
if (prevSrc != 3)
{
for ( unsigned int i = 1; i<count ;i++ )
for (unsigned int i = 1; i < count ; ++i)
{
wxPGProperty *p = Item(i) ;
if ( p )
if (auto* p = Item(i))
{
wxLogDebug( wxT("wxFBBP::ChildChanged: Removing:%s"), p->GetLabel().c_str() );
GetGrid()->DeleteProperty( p );
wxLogDebug(wxT("wxFBBP::ChildChanged: Removing:%s"), p->GetLabel().c_str());
GetGrid()->DeleteProperty(p);
}
}
bp->AppendChild( bp->CreatePropertyResourceName() );
bp->AppendChild( bp->CreatePropertyIconSize() );
bp->AppendChild(bp->CreatePropertyResourceName());
bp->AppendChild(bp->CreatePropertyIconSize());
}

if( childVals.GetCount() == 3)
if (childVals.GetCount() == 3)
{
newVal = childVals.Item(0) + wxT("; ") + childVals.Item(1) + wxT("; [") + childVals.Item(2) + wxT("]");
else if( childVals.GetCount() > 1 )
}
else if (childVals.GetCount() > 0)
{
newVal = childVals.Item(0) + wxT("; ; []");
}
break;
}
// 'Load From XRC'
case 4:
{
if (prevSrc != 4)
{
for (unsigned int i = 1; i < count; ++i)
{
if (auto* p = Item(i))
{
wxLogDebug(wxT("wxFBBP::ChildChanged: Removing:%s"), p->GetLabel().c_str());
GetGrid()->DeleteProperty(p);
}
}
bp->AppendChild(bp->CreatePropertyXrcName());
}

break;
}
// 'Load From Art Provider'
case 4:
{
if( prevSrc != 4 )
if (childVals.GetCount() == 2)
{
newVal = childVals.Item(0) + wxT("; ") + childVals.Item(1);
}
else if (childVals.GetCount() > 0)
{
newVal = childVals.Item(0) + wxT("; ");
}
break;
}
// 'Load From Art Provider'
case 5:
{
if (prevSrc != 5)
{
for ( unsigned int i = 1; i<count ;i++ )
for (unsigned int i = 1; i < count ; ++i)
{
wxPGProperty *p = Item(i) ;
if ( p )
if (auto* p = Item(i))
{
wxLogDebug( wxT("wxFBBP::ChildChanged: Removing:%s"), p->GetLabel().c_str() );
GetGrid()->DeleteProperty( p );
wxLogDebug(wxT("wxFBBP::ChildChanged: Removing:%s"), p->GetLabel().c_str());
GetGrid()->DeleteProperty(p);
}
}
bp->AppendChild( bp->CreatePropertyArtId() );
bp->AppendChild( bp->CreatePropertyArtClient() );
bp->AppendChild(bp->CreatePropertyArtId());
bp->AppendChild(bp->CreatePropertyArtClient());
}

if( childVals.GetCount() == 3)
if (childVals.GetCount() == 3)
{
newVal = childVals.Item(0) + wxT("; ") + childVals.Item(1) + wxT("; ") + childVals.Item(2);
else if( childVals.GetCount() > 1 )
}
else if (childVals.GetCount() > 0)
{
newVal = childVals.Item(0) + wxT("; ; ");
break;
}
}
break;
}
}
break;
}
}
break;
}

// file_path || id || resource_name
// file_path || id || resource_name || xrc_name
case 1:
{
if ( (Item(0)->GetValueAsString() == _("Load From File")) || (Item(0)->GetValueAsString() == _("Load From Embedded File")) )
Expand Down Expand Up @@ -692,6 +744,13 @@ void wxFBBitmapProperty::UpdateChildValues(const wxString& value)
Item(2)->SetValue(WXVARIANT(TypeConv::StringToSize(aux)));
}
}
else if (childVals[0].Contains(_("Load From XRC")))
{
if (childVals.Count() > 1)
{
Item(1)->SetValue(childVals[1]);
}
}
else if( childVals[0].Contains( _("Load From Art Provider") ) )
{
if(childVals.Count() > 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 *CreatePropertyXrcName();
wxPGProperty *CreatePropertyArtId();
wxPGProperty *CreatePropertyArtClient();

Expand Down

0 comments on commit 7d9d60e

Please sign in to comment.