01: #include <wx/wx.h> 02: 03: /** 04: A window onto which an ellipse is painted. 05: */ 06: class EllipseWindow : public wxWindow 07: { 08: public: 09: /** 10: Initializes the base class. 11: @param parent the parent window 12: */ 13: EllipseWindow(wxWindow* parent); 14: /** 15: Draws an ellipse on the window. 16: @param event the event descriptor 17: */ 18: void OnPaint(wxPaintEvent& event); 19: private: 20: DECLARE_EVENT_TABLE() 21: }; 22: 23: /** 24: A frame with a window that shows an ellipse. 25: */ 26: class PaintFrame : public wxFrame 27: { 28: public: 29: /** 30: Constructs the window. 31: */ 32: PaintFrame(); 33: private: 34: EllipseWindow* window; 35: }; 36: 37: /** 38: An application to demonstrate painting. 39: */ 40: class PaintApp : public wxApp 41: { 42: public: 43: /** 44: Constructs the frame. 45: */ 46: PaintApp(); 47: /** 48: Shows the frame. 49: @return true 50: */ 51: virtual bool OnInit(); 52: private: 53: PaintFrame* frame; 54: }; 55: 56: DECLARE_APP(PaintApp) 57: 58: IMPLEMENT_APP(PaintApp) 59: 60: BEGIN_EVENT_TABLE(EllipseWindow, wxWindow) 61: EVT_PAINT(EllipseWindow::OnPaint) 62: END_EVENT_TABLE() 63: 64: EllipseWindow::EllipseWindow(wxWindow* parent) 65: : wxWindow(parent, -1) 66: { 67: } 68: 69: void EllipseWindow::OnPaint(wxPaintEvent& event) 70: { 71: wxPaintDC dc(this); 72: dc.SetBrush(*wxTRANSPARENT_BRUSH); 73: wxSize size = GetSize(); 74: int x = 0; 75: int y = 0; 76: int width = size.GetWidth(); 77: int height = size.GetHeight(); 78: dc.DrawEllipse(x, y, width, height); 79: } 80: 81: PaintFrame::PaintFrame() 82: : wxFrame(NULL, -1, "PaintFrame") 83: { 84: window = new EllipseWindow(this); 85: } 86: 87: PaintApp::PaintApp() 88: { 89: frame = new PaintFrame(); 90: } 91: 92: bool PaintApp::OnInit() 93: { 94: frame->Show(true); 95: return true; 96: } 97: