]>
git.saurik.com Git - wxWidgets.git/blob - contrib/samples/canvas/simple/simple.cpp
26390ed9cb4cb996e710b4a3bcaf964e3c8522f8
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(__WXMOTIF__)
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
)
43 MyFrame::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
)
50 SetStatusText( "Welcome to wxCanvas sample!" );
52 SetIcon(wxICON(mondrian
));
54 // Create wxCanvasAdmin and wxCanvas.
55 m_admin
= new wxCanvasAdmin
;
56 wxCanvas
*canvas
= new wxCanvas( m_admin
, this, -1 );
58 canvas
->SetScrollbars( 10, 10, 40, 40 );
60 // The wxCanvasAdmin need to know about all Admin wxCanvas objects.
61 m_admin
->Append( canvas
);
63 // One wxCanvas is the active one (current rendering and current
64 // world coordinates).
65 m_admin
->SetActive( canvas
);
67 // One object group is the root in every canvas.
68 wxCanvasObjectGroup
*root
= new wxCanvasObjectGroup(0,0);
69 root
->DeleteContents( TRUE
);
71 // Bunch of rects and images.
72 wxBitmap
bitmap( smile_xpm
);
73 wxImage
image( bitmap
);
75 m_smile1
= new wxCanvasImage( image
, 0,70,32,32 );
76 root
->Append( m_smile1
);
78 wxCanvasRect
*rect
= new wxCanvasRect( 20,20,100,100 );
79 rect
->SetBrush( *wxRED_BRUSH
);
84 for (i = 10; i < 300; i+=10)
86 wxCanvasRect *r = new wxCanvasRect( i,50,3,140 );
87 r->SetBrush( *wxRED_BRUSH );
92 m_smile2
= new wxCanvasImage( image
, 0,110,32,32 );
93 root
->Append( m_smile2
);
96 for (i = 15; i < 300; i+=10)
98 wxCanvasRect *r = new wxCanvasRect( i,50,3,140 );
99 r->SetBrush( *wxRED_BRUSH );
104 // This will call all object and children recursivly so
105 // all know what their wxCanvasAdmin is. Call at the end.
106 root
->SetAdmin( m_admin
);
108 // One object group is the root object.
109 canvas
->SetRoot( root
);
112 void MyFrame::CreateMyMenuBar()
114 wxMenu
*file_menu
= new wxMenu
;
115 file_menu
->Append( ID_QUIT
, "Quit...", "Quit program" );
117 wxMenuBar
*menu_bar
= new wxMenuBar();
118 menu_bar
->Append( file_menu
, "File" );
120 SetMenuBar( menu_bar
);
123 // WDR: handler implementations for MyFrame
125 void MyFrame::OnQuit( wxCommandEvent
&event
)
130 void MyFrame::OnCloseWindow( wxCloseEvent
&event
)
132 // if ! saved changes -> return
137 //------------------------------------------------------------------------------
139 //------------------------------------------------------------------------------
149 MyFrame
*frame
= new MyFrame( NULL
, -1, "SuperApp", wxPoint(20,20), wxSize(500,340) );