]> git.saurik.com Git - wxWidgets.git/blame - contrib/samples/canvas/simple/simple.cpp
wxHtmlHistoryItem needs not be wxObject
[wxWidgets.git] / contrib / samples / canvas / simple / simple.cpp
CommitLineData
f9032263
RR
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
618f2efa 23#if defined(__WXGTK__) || defined(__WXX11__) || defined(__WXMOTIF__) || defined(__WXMAC__)
f9032263
RR
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
38BEGIN_EVENT_TABLE(MyFrame,wxFrame)
39 EVT_MENU(ID_QUIT, MyFrame::OnQuit)
40 EVT_CLOSE(MyFrame::OnCloseWindow)
880d870e 41 EVT_TIMER(-1, MyFrame::OnTimer)
f9032263
RR
42END_EVENT_TABLE()
43
44MyFrame::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);
f03b31e8 51 SetStatusText( "Welcome to wxCanvas sample!" );
f9032263
RR
52
53 SetIcon(wxICON(mondrian));
54
f03b31e8 55 // Create wxCanvasAdmin and wxCanvas.
f9032263
RR
56 m_admin = new wxCanvasAdmin;
57 wxCanvas *canvas = new wxCanvas( m_admin, this, -1 );
f03b31e8 58
8636c073 59 canvas->SetScrollbars( 10, 10, 40, 40 );
f03b31e8
RR
60
61 // The wxCanvasAdmin need to know about all Admin wxCanvas objects.
f9032263 62 m_admin->Append( canvas );
f03b31e8
RR
63
64 // One wxCanvas is the active one (current rendering and current
65 // world coordinates).
f9032263
RR
66 m_admin->SetActive( canvas );
67
f03b31e8 68 // One object group is the root in every canvas.
f9032263
RR
69 wxCanvasObjectGroup *root = new wxCanvasObjectGroup(0,0);
70 root->DeleteContents( TRUE );
71
f03b31e8 72 // Bunch of rects and images.
f9032263 73 wxBitmap bitmap( smile_xpm );
a977709b 74 wxImage image( bitmap.ConvertToImage() );
f9032263
RR
75
76 m_smile1 = new wxCanvasImage( image, 0,70,32,32 );
77 root->Append( m_smile1 );
78
880d870e
RR
79 wxCanvasCircle *circ = new wxCanvasCircle( 170,70,50 );
80 circ->SetBrush( *wxBLUE_BRUSH );
81 root->Append( circ );
8636c073 82
f9032263
RR
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 }
f9032263 100
f03b31e8
RR
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.
f9032263 106 canvas->SetRoot( root );
880d870e
RR
107
108 m_timer = new wxTimer( this );
109 m_timer->Start( 80, FALSE );
110}
111
112MyFrame::~MyFrame()
113{
114 delete m_timer;
f9032263
RR
115}
116
117void 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
130void MyFrame::OnQuit( wxCommandEvent &event )
131{
132 Close( TRUE );
133}
134
135void MyFrame::OnCloseWindow( wxCloseEvent &event )
136{
137 // if ! saved changes -> return
138
139 Destroy();
140}
141
880d870e
RR
142void MyFrame::OnTimer( wxTimerEvent &event )
143{
144 m_smile1->MoveRelative( 1, 0);
145 m_smile2->MoveRelative( 1, 0);
146
147 wxWakeUpIdle();
148}
149
f9032263
RR
150//------------------------------------------------------------------------------
151// MyApp
152//------------------------------------------------------------------------------
153
154IMPLEMENT_APP(MyApp)
155
156MyApp::MyApp()
157{
158}
159
160bool 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
168int MyApp::OnExit()
169{
170 return 0;
171}
172