1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
|
#include "wx/wx.h"
class MyApp : public wxApp
{
public:
virtual bool OnInit();
};
class MyFrame : public wxFrame
{
public:
MyFrame(const wxString& title);
private:
DECLARE_EVENT_TABLE()
};
class CMonItemRender : public wxEvtHandler
{
public:
virtual ~CMonItemRender()
{
if(mp_container){
mp_container->RemoveEventHandler(this);
}
}
CMonItemRender(wxWindow * container_,wxPoint const & top_left_, wxSize const & size_)
:mp_container(container_),m_top_left(top_left_),m_size(size_)
{
mp_container->PushEventHandler(this);
}
void OnPaint(wxPaintEvent&evt_)
{
wxPaintDC dc(mp_container);
dc.SetBrush(*wxBLUE_BRUSH);
dc.SetPen(wxPen(*wxBLUE));
dc.DrawRectangle(m_top_left.x,m_top_left.y,m_size.x,m_size.y);
evt_.Skip();
}
private:
wxWindow *mp_container;
wxPoint m_top_left;
wxSize m_size;
DECLARE_EVENT_TABLE()
};
BEGIN_EVENT_TABLE(CMonItemRender,wxEvtHandler)
EVT_PAINT(CMonItemRender::OnPaint)
END_EVENT_TABLE()
class CMonControle :public wxControl
{
public:
static const wxChar CMonControleNameStr[];
CMonControle():m_renderer(this,wxPoint(5,5),wxSize(20,20)){}
CMonControle(wxWindow *parent,
wxWindowID id,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize, long style = 0,
const wxValidator& validator = wxDefaultValidator,
const wxString& name = CMonControleNameStr)
:m_renderer(this,wxPoint(5,5),wxSize(20,20))
{
Create(parent, id, pos, size, style, validator, name);
}
private:
void OnPaint(wxPaintEvent&)
{
wxPaintDC dc(this);
wxSize ma_taille = GetClientSize();
dc.SetBrush(*wxGREEN_BRUSH);
dc.SetPen(*wxGREEN_PEN);
dc.DrawRectangle(0,0,ma_taille.x,ma_taille.y);
}
void OnSize(wxSizeEvent&)
{
Refresh();
}
private:
CMonItemRender m_renderer;
DECLARE_DYNAMIC_CLASS(CMonControle)
DECLARE_EVENT_TABLE()
};
IMPLEMENT_DYNAMIC_CLASS(CMonControle,wxControl);
BEGIN_EVENT_TABLE(CMonControle,wxControl)
EVT_PAINT(CMonControle::OnPaint)
EVT_SIZE(CMonControle::OnSize)
END_EVENT_TABLE()
const wxChar CMonControle::CMonControleNameStr[]="monControle";
IMPLEMENT_APP(MyApp)
// 'Main program' equivalent: the program execution "starts" here
bool MyApp::OnInit()
{
if ( !wxApp::OnInit() )
return false;
MyFrame *frame = new MyFrame(_T("Minimal wxWidgets App"));
frame->Show(true);
new CMonControle(frame,wxID_ANY,wxPoint(10,10),wxSize(100,100));
return true;
}
BEGIN_EVENT_TABLE(MyFrame, wxFrame)
END_EVENT_TABLE()
MyFrame::MyFrame(const wxString& title)
: wxFrame(NULL, wxID_ANY, title)
{} |
Partager