In my mainwindow, I am setting the background Image and added few buttons using the wxBoxSizer in CreateWidgets. Now on clicking one of the buttons, it should replace the background Image and hide the old wxBoxSizer and create a new one.
After setting the new image it is always calling child OnPaint function not the parent OnPaint function.
MainFrame::MainFrame(const wxString& title)
: wxFrame(NULL, wxID_ANY, title)
{
// set the frame icon
SetIcon(wxICON(sample));
wxString fileName = wxT("./images/image1.png");
LoadBitmap(fileName);
SetSize(size);
CreateWidgets();
}
void MainFrame::LoadBitmaps(wxString filename) {
if (!wxFile::Exists(filename))
wxLogWarning("Can't find image files");
wxImage::AddHandler(new wxPNGHandler);
image.LoadFile(filename);
size.SetHeight(image.GetHeight() + 60);
size.SetWidth(image.GetWidth() + 25);
}
void MainFrame::OnPaint(wxPaintEvent& WXUNUSED(evt))
{
wxPaintDC dc(this);
wxBitmap bitmap(image);
dc.DrawBitmap(bitmap, 5, 5, false);
}
void MainFrame::CreateWidgets() {
wxBoxSizer *main_sizer = new wxBoxSizer(wxVERTICAL);
wxBoxSizer *button_sizer = new wxBoxSizer(wxHORIZONTAL);
std::vector<wxString> fileNames;
fileNames.push_back(wxT("./images/img.png"));
std::vector<wxString> rollover_files;
rollover_files.push_back(wxT("./images/rollover_img.png"));
std::vector<wxImage> images;
wxImage image1(fileNames[0]);
wxImage rollover_image1(rollover_files[0]);
wxBitmap bitmap1(image1);
wxBitmap rollover_bitmap1(rollover_image1);
const long id = 6000;
MWCustomBitmap *bitmapCtrl1 = new MWCustomBitmap(this, bitmap1, TetraMeshingBitMapBtn, rollover_bitmap1, NULL, wxDefaultPosition, wxDefaultSize);
button_sizer->Add(bitmapCtrl1, 0, wxALL, 10);
main_sizer->AddSpacer(350);
main_sizer->Add(button_sizer, wxSizerFlags().Center());
this->SetSizer(main_sizer);
}
Here on clicking button Loadfile(filename) is not working.
void MWCustomBitmap::OnBtnClicked(wxCommandEvent &evt) {
wxString filename = wxT("./images/img3.png");
if (!wxFile::Exists(filename))
wxLogWarning("Can't find image files");
wxImage::AddHandler(new wxPNGHandler);
((MainFrame*)(m_pParentwindow))->GetImage().LoadFile(filename);
}
PS: I am learning wxWidgets.