Author Topic: Feature request? - xpm images  (Read 3667 times)

Offline kencamargo

  • Multiple posting newcomer
  • *
  • Posts: 110
Feature request? - xpm images
« on: October 16, 2009, 01:37:05 am »
Hello,

I tend to prefer using embedded .xpm images in my programs. This means going back to the code generated by wxSmith, replacing the file name with the char * array in the .xpm file and adding it as an include file, as below:

wxImage(_T("/files/whatever/directory/images/xyz.xpm")) ;

becomes

#include "xyz.xpm"
wxImage(xyz);

(I generated the .xpm files and adopted as a convention naming the char array with the name of the file minus the extension)

If for any reason I reedit the GUI file with wxSmith, these changes are lost (not the #include directives, though), and I have to redo everything by hand. Yesterday I forgot to do that, and got a desperate user e-mailing me repeatedly today... :)

Is there a way to either (a) force the code generator in wxSmith to ignore the edited initialization code or (b) automatically replace the name of the .xpm file with the corresponding array name?

Thanks in advance,
Ken

Offline mandrav

  • Project Leader
  • Administrator
  • Lives here!
  • *****
  • Posts: 4315
    • Code::Blocks IDE
Re: Feature request? - xpm images
« Reply #1 on: October 16, 2009, 07:40:18 am »
wxSmith uses/supports the wxWidgets' standard ways of including images in your programs. I 'll describe the way to achieve your goal without hand editing anything. It's the way I do it so feel free to take it or leave it :).

If you have noticed, in the wxSmith image dialog (for toolbars, bitmap buttons, etc), there's an option named "Image from wxArtProvider". Also note that the "Art Id" field is editable (i.e. you can type whatever you want in there). That's the key to what you want to achieve.

Now, I could give you the link to wxArtProvider's documentation and let you figure it out from there but I 'll go on and describe what you can do.

Create a file (or break it up in header/source) like this:

Code
#ifndef MY_ARTPROVIDER_H
#define MY_ARTPROVIDER_H

#include <wx/artprov.h>

// include *your* xpm icons here:
#include "icons/xxx.xpm"
#include "icons/yyy.xpm"
#include "icons/zzz.xpm"

class MyArtProvider : public wxArtProvider
{
public:
MyArtProvider() {}
virtual ~MyArtProvider() {}

protected:
wxBitmap CreateBitmap(const wxArtID& id,
  const wxArtClient& client,
  const wxSize& size)
{
if (id == _T("MY_ART_ID_XXX"))
{
return wxBitmap(xxx_xpm);
}
else if (id == _T("MY_ART_ID_YYY"))
{
return wxBitmap(yyy_xpm);
}
else if (id == _T("MY_ART_ID_ZZZ"))
{
return wxBitmap(zzz_xpm);
}
// possibly more Art Ids follow
}
};

#endif // MY_ARTPROVIDER_H

I hope it's clear enough and you can already see where this is going ;).

Anyway, there's only one thing still missing. Somewhere in your app's initialization (wxApp or your main frame/dialog constructor) just add this line:

Code
    wxArtProvider::Push(new MyArtProvider);

That's it. Now you can use your own Art Ids (e.g. MY_ART_ID_ZZZ) with wxSmith. The only down side is that you won't be able to actually see your bitmaps in the wxSmith editor but that's a small price to pay :).

Hope this helps.
Be patient!
This bug will be fixed soon...

Offline kencamargo

  • Multiple posting newcomer
  • *
  • Posts: 110
Re: Feature request? - xpm images
« Reply #2 on: October 17, 2009, 02:35:10 am »
Thanks mandrav, it sure helps. I actually used wxArtProvider before, I didn't know that new IDs can be added to it.

There's still the problem of me not seeing the pretty pics, though. :)

Ken