]> git.saurik.com Git - wxWidgets.git/blob - contrib/samples/canvas/simple/simple.cpp
Project file corrections, doc corrections
[wxWidgets.git] / contrib / samples / canvas / simple / simple.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: simple.cpp
3 // Author: XX
4 // Created: XX/XX/XX
5 // Copyright:
6 /////////////////////////////////////////////////////////////////////////////
7
8 #ifdef __GNUG__
9 #pragma implementation "simple.cpp"
10 #endif
11
12 // For compilers that support precompilation
13 #include "wx/wxprec.h"
14
15 #ifdef __BORLANDC__
16 #pragma hdrstop
17 #endif
18
19 // Include private headers
20 #include "simple.h"
21
22 // Include icon header
23 #if defined(__WXGTK__) || defined(__WXMOTIF__)
24 #include "mondrian.xpm"
25 #endif
26
27 // Include image
28 #include "smile.xpm"
29
30 // WDR: class implementations
31
32 //------------------------------------------------------------------------------
33 // MyFrame
34 //------------------------------------------------------------------------------
35
36 // WDR: event table for MyFrame
37
38 BEGIN_EVENT_TABLE(MyFrame,wxFrame)
39 EVT_MENU(ID_QUIT, MyFrame::OnQuit)
40 EVT_CLOSE(MyFrame::OnCloseWindow)
41 EVT_TIMER(-1, MyFrame::OnTimer)
42 END_EVENT_TABLE()
43
44 MyFrame::MyFrame( wxWindow *parent, wxWindowID id, const wxString &title,
45 const wxPoint &position, const wxSize& size, long style ) :
46 wxFrame( parent, id, title, position, size, style )
47 {
48 CreateMyMenuBar();
49
50 CreateStatusBar(1);
51 SetStatusText( "Welcome to wxCanvas sample!" );
52
53 SetIcon(wxICON(mondrian));
54
55 // Create wxCanvasAdmin and wxCanvas.
56 m_admin = new wxCanvasAdmin;
57 wxCanvas *canvas = new wxCanvas( m_admin, this, -1 );
58
59 canvas->SetScrollbars( 10, 10, 40, 40 );
60
61 // The wxCanvasAdmin need to know about all Admin wxCanvas objects.
62 m_admin->Append( canvas );
63
64 // One wxCanvas is the active one (current rendering and current
65 // world coordinates).
66 m_admin->SetActive( canvas );
67
68 // One object group is the root in every canvas.
69 wxCanvasObjectGroup *root = new wxCanvasObjectGroup(0,0);
70 root->DeleteContents( TRUE );
71
72 // Bunch of rects and images.
73 wxBitmap bitmap( smile_xpm );
74 wxImage image( bitmap );
75
76 m_smile1 = new wxCanvasImage( image, 0,70,32,32 );
77 root->Append( m_smile1 );
78
79 wxCanvasCircle *circ = new wxCanvasCircle( 170,70,50 );
80 circ->SetBrush( *wxBLUE_BRUSH );
81 root->Append( circ );
82
83 int i;
84 for (i = 10; i < 300; i+=10)
85 {
86 wxCanvasRect *r = new wxCanvasRect( i,50,3,140 );
87 r->SetBrush( *wxRED_BRUSH );
88 root->Append( r );
89 }
90
91 m_smile2 = new wxCanvasImage( image, 0,110,32,32 );
92 root->Append( m_smile2 );
93
94 for (i = 15; i < 300; i+=10)
95 {
96 wxCanvasRect *r = new wxCanvasRect( i,50,3,140 );
97 r->SetBrush( *wxRED_BRUSH );
98 root->Append( r );
99 }
100
101 // This will call all object and children recursivly so
102 // all know what their wxCanvasAdmin is. Call at the end.
103 root->SetAdmin( m_admin );
104
105 // One object group is the root object.
106 canvas->SetRoot( root );
107
108 m_timer = new wxTimer( this );
109 m_timer->Start( 80, FALSE );
110 }
111
112 MyFrame::~MyFrame()
113 {
114 delete m_timer;
115 }
116
117 void MyFrame::CreateMyMenuBar()
118 {
119 wxMenu *file_menu = new wxMenu;
120 file_menu->Append( ID_QUIT, "Quit...", "Quit program" );
121
122 wxMenuBar *menu_bar = new wxMenuBar();
123 menu_bar->Append( file_menu, "File" );
124
125 SetMenuBar( menu_bar );
126 }
127
128 // WDR: handler implementations for MyFrame
129
130 void MyFrame::OnQuit( wxCommandEvent &event )
131 {
132 Close( TRUE );
133 }
134
135 void MyFrame::OnCloseWindow( wxCloseEvent &event )
136 {
137 // if ! saved changes -> return
138
139 Destroy();
140 }
141
142 void MyFrame::OnTimer( wxTimerEvent &event )
143 {
144 m_smile1->MoveRelative( 1, 0);
145 m_smile2->MoveRelative( 1, 0);
146
147 wxWakeUpIdle();
148 }
149
150 //------------------------------------------------------------------------------
151 // MyApp
152 //------------------------------------------------------------------------------
153
154 IMPLEMENT_APP(MyApp)
155
156 MyApp::MyApp()
157 {
158 }
159
160 bool MyApp::OnInit()
161 {
162 MyFrame *frame = new MyFrame( NULL, -1, "SuperApp", wxPoint(20,20), wxSize(500,340) );
163 frame->Show( TRUE );
164
165 return TRUE;
166 }
167
168 int MyApp::OnExit()
169 {
170 return 0;
171 }
172