I'm trying to make a program that will contain many panels. All of them must have a background image.
To ease my job I decided to create a base class that will be responsible for drawing this image (and for other stuff common to all derived screens).
So far, so good. The problem I'm facing is that the image that should be drawn in background is being draw on top of components in the derived class.
Shouldn't the images/components of derived class be draw on top of components from base class?
I'm struggling with this for a couple of days but I couldn't find a solution.
You can see both an image showing the problem and the source code I made.
Could someone point me what I am doing wrong?
Thanks in advance.
Code: Select all
// BaseScreen.h
#ifndef _BASE_SCREEN_H
#define _BASE_SCREEN_H
#include <wx/wx.h>
#include "global_settings.h"
class BaseScreen : public wxPanel
{
private:
protected:
wxStaticBitmap* m_bgImage;
public:
BaseScreen( wxWindow* parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition, const wxSize& size = g_AppSize, long style = wxTAB_TRAVERSAL );
virtual ~BaseScreen();
};
#endif //_BASE_SCREEN_H
Code: Select all
// BaseScreen.cpp
#include "BaseScreen.h"
BaseScreen::BaseScreen( wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style ) :
wxPanel( parent, id, pos, size, style )
{
wxImage::AddHandler( new wxPNGHandler );
wxBoxSizer* bSizer1;
bSizer1 = new wxBoxSizer( wxVERTICAL );
bSizer1->Add( 0, 0, 1, wxEXPAND, 5 );
m_bgImage = new wxStaticBitmap( this, wxID_ANY, wxBitmap( g_pathToBgImage, wxBITMAP_TYPE_PNG ), wxDefaultPosition, wxDefaultSize, 0 );
m_bgImage->SetMinSize( g_bgImageSize );
m_bgImage->SetMaxSize( g_bgImageSize );
bSizer1->Add( m_bgImage, 0, wxALIGN_CENTER, 5 );
bSizer1->Add( 0, 0, 1, wxEXPAND, 5 );
this->SetSizer( bSizer1 );
this->Layout();
}
BaseScreen::~BaseScreen()
{
}
Code: Select all
// MainScreen.h
#ifndef _MAIN_SCREEN_H
#define _MAIN_SCREEN_H
#include <wx/wx.h>
#include "BaseScreen.h"
class MainScreen : public BaseScreen
{
private:
protected:
wxStaticText *m_txtTitle;
wxButton *m_btnFile;
wxButton *m_btnImport;
wxButton *m_btnExport;
wxButton *m_btnAbout;
public:
MainScreen( wxWindow* parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition, const wxSize& size = g_AppSize, long style = wxTAB_TRAVERSAL );
virtual ~MainScreen();
};
#endif // _MAIN_SCREEN_H
Code: Select all
// MainScreen.cpp
#include <wx/wx.h>
#include "MainScreen.h"
MainScreen::MainScreen( wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style ) :
BaseScreen( parent, id, pos, size, style )
{
this->SetForegroundColour( g_PanelForegroundColor );
this->SetBackgroundColour( g_PanelBackroundColor );
this->SetMinSize( wxSize( g_AppSize ) );
this->SetMaxSize( wxSize( g_AppSize ) );
wxBoxSizer* bSizer1;
bSizer1 = new wxBoxSizer( wxVERTICAL );
// Title - Start
m_txtTitle = new wxStaticText( this, wxID_ANY, g_MainMenuTitle, wxDefaultPosition, wxDefaultSize, 0 );
m_txtTitle->Wrap( -1 );
m_txtTitle->SetFont( wxFont( 24, 74, 90, 92, false, wxT("Arial Black") ) );
m_txtTitle->SetForegroundColour( g_TitleColor );
bSizer1->Add( m_txtTitle, 0, wxALIGN_CENTER|wxALL, 5 );
// Title - End
// File button - Start
wxBoxSizer* bSizer2;
bSizer2 = new wxBoxSizer( wxHORIZONTAL );
m_btnFile = new wxButton( this, wxID_ANY, m_btnFile, wxDefaultPosition, wxDefaultSize, 0 );
bSizer2->Add( m_btnFile, 1, wxALL, 5 );
bSizer1->Add( bSizer2, 0, wxEXPAND, 5 );
// Import button - Start
wxBoxSizer* bSizer3;
bSizer3 = new wxBoxSizer( wxHORIZONTAL );
m_btnImport = new wxButton( this, wxID_ANY, m_btnImport, wxDefaultPosition, wxDefaultSize, 0 );
bSizer3->Add( m_btnImport, 1, wxALL, 5 );
bSizer1->Add( bSizer3, 0, wxEXPAND, 5 );
// Export button - Start
wxBoxSizer* bSizer4;
bSizer4 = new wxBoxSizer( wxHORIZONTAL );
m_btnExport = new wxButton( this, wxID_ANY, m_btnExport, wxDefaultPosition, wxDefaultSize, 0 );
bSizer4->Add( m_btnExport, 1, wxALL, 5 );
bSizer1->Add( bSizer4, 0, wxEXPAND, 5 );
// About button - Start
wxBoxSizer* bSizer5;
bSizer5 = new wxBoxSizer( wxHORIZONTAL );
m_btnAbout = new wxButton( this, wxID_ANY, g_About, wxDefaultPosition, wxDefaultSize, 0 );
bSizer5->Add( m_btnAbout, 1, wxALL, 5 );
bSizer1->Add( bSizer5, 0, wxEXPAND, 5 );
// About button - End
this->SetSizer( bSizer1 );
this->Layout();
}
MainScreen::~MainScreen()
{
}