]>
git.saurik.com Git - wxWidgets.git/blob - contrib/samples/canvas/simple/simple.cpp
1 /////////////////////////////////////////////////////////////////////////////
6 /////////////////////////////////////////////////////////////////////////////
9 #pragma implementation "simple.cpp"
12 // For compilers that support precompilation
13 #include "wx/wxprec.h"
19 // Include private headers
22 // Include icon header
23 #if defined(__WXGTK__) || defined(__WXX11__) || defined(__WXMOTIF__) || defined(__WXMAC__)
24 #include "mondrian.xpm"
30 // WDR: class implementations
32 //------------------------------------------------------------------------------
34 //------------------------------------------------------------------------------
36 // WDR: event table for MyFrame
38 BEGIN_EVENT_TABLE(MyFrame
,wxFrame
)
39 EVT_MENU(ID_QUIT
, MyFrame::OnQuit
)
40 EVT_CLOSE(MyFrame::OnCloseWindow
)
41 EVT_TIMER(-1, MyFrame::OnTimer
)
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
)
51 SetStatusText( "Welcome to wxCanvas sample!" );
53 SetIcon(wxICON(mondrian
));
55 // Create wxCanvasAdmin and wxCanvas.
56 m_admin
= new wxCanvasAdmin
;
57 wxCanvas
*canvas
= new wxCanvas( m_admin
, this, -1 );
59 canvas
->SetScrollbars( 10, 10, 40, 40 );
61 // The wxCanvasAdmin need to know about all Admin wxCanvas objects.
62 m_admin
->Append( canvas
);
64 // One wxCanvas is the active one (current rendering and current
65 // world coordinates).
66 m_admin
->SetActive( canvas
);
68 // One object group is the root in every canvas.
69 wxCanvasObjectGroup
*root
= new wxCanvasObjectGroup(0,0);
70 root
->DeleteContents( TRUE
);
72 // Bunch of rects and images.
73 wxBitmap
bitmap( smile_xpm
);
74 wxImage
image( bitmap
);
76 m_smile1
= new wxCanvasImage( image
, 0,70,32,32 );
77 root
->Append( m_smile1
);
79 wxCanvasCircle
*circ
= new wxCanvasCircle( 170,70,50 );
80 circ
->SetBrush( *wxBLUE_BRUSH
);
84 for (i
= 10; i
< 300; i
+=10)
86 wxCanvasRect
*r
= new wxCanvasRect( i
,50,3,140 );
87 r
->SetBrush( *wxRED_BRUSH
);
91 m_smile2
= new wxCanvasImage( image
, 0,110,32,32 );
92 root
->Append( m_smile2
);
94 for (i
= 15; i
< 300; i
+=10)
96 wxCanvasRect
*r
= new wxCanvasRect( i
,50,3,140 );
97 r
->SetBrush( *wxRED_BRUSH
);
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
);
105 // One object group is the root object.
106 canvas
->SetRoot( root
);
108 m_timer
= new wxTimer( this );
109 m_timer
->Start( 80, FALSE
);
117 void MyFrame::CreateMyMenuBar()
119 wxMenu
*file_menu
= new wxMenu
;
120 file_menu
->Append( ID_QUIT
, "Quit...", "Quit program" );
122 wxMenuBar
*menu_bar
= new wxMenuBar();
123 menu_bar
->Append( file_menu
, "File" );
125 SetMenuBar( menu_bar
);
128 // WDR: handler implementations for MyFrame
130 void MyFrame::OnQuit( wxCommandEvent
&event
)
135 void MyFrame::OnCloseWindow( wxCloseEvent
&event
)
137 // if ! saved changes -> return
142 void MyFrame::OnTimer( wxTimerEvent
&event
)
144 m_smile1
->MoveRelative( 1, 0);
145 m_smile2
->MoveRelative( 1, 0);
150 //------------------------------------------------------------------------------
152 //------------------------------------------------------------------------------
162 MyFrame
*frame
= new MyFrame( NULL
, -1, "SuperApp", wxPoint(20,20), wxSize(500,340) );