]> git.saurik.com Git - wxWidgets.git/blame - contrib/samples/canvas/simple/simple.cpp
fix for uninit vars
[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
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
38BEGIN_EVENT_TABLE(MyFrame,wxFrame)
39 EVT_MENU(ID_QUIT, MyFrame::OnQuit)
40 EVT_CLOSE(MyFrame::OnCloseWindow)
41END_EVENT_TABLE()
42
43MyFrame::MyFrame( wxWindow *parent, wxWindowID id, const wxString &title,
44 const wxPoint &position, const wxSize& size, long style ) :
45 wxFrame( parent, id, title, position, size, style )
46{
47 CreateMyMenuBar();
48
49 CreateStatusBar(1);
f03b31e8 50 SetStatusText( "Welcome to wxCanvas sample!" );
f9032263
RR
51
52 SetIcon(wxICON(mondrian));
53
f03b31e8 54 // Create wxCanvasAdmin and wxCanvas.
f9032263
RR
55 m_admin = new wxCanvasAdmin;
56 wxCanvas *canvas = new wxCanvas( m_admin, this, -1 );
f03b31e8
RR
57
58 canvas->SetScroll( 0, 0, 400, 600 );
59 canvas->SetMappingScroll( 0, 0, 400, 600, FALSE );
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
RR
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 int i;
80 for (i = 10; i < 300; i+=10)
81 {
82 wxCanvasRect *r = new wxCanvasRect( i,50,3,140 );
83 r->SetBrush( *wxRED_BRUSH );
84 root->Append( r );
85 }
86
87 m_smile2 = new wxCanvasImage( image, 0,110,32,32 );
88 root->Append( m_smile2 );
89
90 for (i = 15; i < 300; i+=10)
91 {
92 wxCanvasRect *r = new wxCanvasRect( i,50,3,140 );
93 r->SetBrush( *wxRED_BRUSH );
94 root->Append( r );
95 }
f9032263 96
f03b31e8
RR
97 // This will call all object and children recursivly so
98 // all know what their wxCanvasAdmin is. Call at the end.
99 root->SetAdmin( m_admin );
100
101 // One object group is the root object.
f9032263
RR
102 canvas->SetRoot( root );
103}
104
105void MyFrame::CreateMyMenuBar()
106{
107 wxMenu *file_menu = new wxMenu;
108 file_menu->Append( ID_QUIT, "Quit...", "Quit program" );
109
110 wxMenuBar *menu_bar = new wxMenuBar();
111 menu_bar->Append( file_menu, "File" );
112
113 SetMenuBar( menu_bar );
114}
115
116// WDR: handler implementations for MyFrame
117
118void MyFrame::OnQuit( wxCommandEvent &event )
119{
120 Close( TRUE );
121}
122
123void MyFrame::OnCloseWindow( wxCloseEvent &event )
124{
125 // if ! saved changes -> return
126
127 Destroy();
128}
129
130//------------------------------------------------------------------------------
131// MyApp
132//------------------------------------------------------------------------------
133
134IMPLEMENT_APP(MyApp)
135
136MyApp::MyApp()
137{
138}
139
140bool MyApp::OnInit()
141{
142 MyFrame *frame = new MyFrame( NULL, -1, "SuperApp", wxPoint(20,20), wxSize(500,340) );
143 frame->Show( TRUE );
144
145 return TRUE;
146}
147
148int MyApp::OnExit()
149{
150 return 0;
151}
152