uketernity wrote:I looked through your class and managed to work out what its doing, however, I need to know how to create my image in the first place, how do you do that?
Could you give me an example of how to do this?
You mean how to use the class I posted? Have to warn you it's just an untested suggestion
First, since you're going to need a lot of images, add a default constructor and an initializer method. If you didn't have these, everything would have to be set up in the initialization section of the frame's ctor, and (1) I think loading bitmaps is too complex to put in there, and (2) MSVC thinks that using
this in initialization section is evil. ('f course you could allocate the PositionedBitmaps dynamically, but I always try to avoid too much news and deletes).
Code: Select all
class PositionedBitmap
{
public:
// a default constructor, initialize must be called before use!
PositionedBitmap()
: m_parent(NULL), m_pos(wxDefaultPosition), m_shown(false)
{ }
void initialize(wxWindow* parent, const wxPoint& pos, wxBitmap bmp)
{
m_parent = parent;
m_pos = pos;
m_bmp = bmp;
}
// and leave the rest as it was; perhaps you could add some checking
// as for (m_parent != NULL) and m_bmp.Ok() at the right places
// ...
};
Now you'll have a bunch of these in your frame.
Code: Select all
class MyFrame : public wxFrame
{
// ...
PositionedBitmap m_imgVolume;
PositionedBitmap m_imgSub;
PositionedBitmap m_imgFader;
PositionedBitmap m_imgCenter;
// and so on
std::vector<PositionedBitmap*> m_images; // will explain later
};
// in the frame's ctor, you'll initialize them
MyFrame::MyFrame(...)
{
// ...
m_imgVolume.initialize(this, wxPoint(30, 150), wxBitmap(wxT("volume.png"), wxBITMAP_TYPE_PNG));
m_images.push_back(&m_imgVolume);
m_imgSub.initialize(this, wxPoint(50, 150), wxBitmap(wxT("sub.png"), wxBITMAP_TYPE_PNG));
m_images.push_back(&m_imgSub);
// etc.
}
You will then want to draw some/all of them in MyFrame::OnPaint. This is why I created the m_images vector. It's not absolutely necessary -- without it, you would just draw m_imgVolume, then m_imgSub, and so on. But adding a new button would require changes to OnPaint(); with the vector, you only put one more line after initialize() in the ctor. Now we can draw them all in a loop. I don't know how your OnPaint() is implemented, guess it can't be far from this:
Code: Select all
void MyFrame::OnPaint(wxPaintEvent& event)
{
wxBufferedPaintDC dc(this);
// draw background and other stuff
// ...
// now draw the hideable images
for (size_t i = 0; i < m_images.size(); ++i) {
if (m_images[i]->isShown())
m_images[i]->drawOnto(dc);
}
}