]>
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(__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
->SetScroll( 0, 0, 400, 600 );
59 canvas
->SetMappingScroll( 0, 0, 400, 600, FALSE
);
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
);
80 for (i
= 10; i
< 300; i
+=10)
82 wxCanvasRect
*r
= new wxCanvasRect( i
,50,3,140 );
83 r
->SetBrush( *wxRED_BRUSH
);
87 m_smile2
= new wxCanvasImage( image
, 0,110,32,32 );
88 root
->Append( m_smile2
);
90 for (i
= 15; i
< 300; i
+=10)
92 wxCanvasRect
*r
= new wxCanvasRect( i
,50,3,140 );
93 r
->SetBrush( *wxRED_BRUSH
);
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
);
101 // One object group is the root object.
102 canvas
->SetRoot( root
);
105 void MyFrame::CreateMyMenuBar()
107 wxMenu
*file_menu
= new wxMenu
;
108 file_menu
->Append( ID_QUIT
, "Quit...", "Quit program" );
110 wxMenuBar
*menu_bar
= new wxMenuBar();
111 menu_bar
->Append( file_menu
, "File" );
113 SetMenuBar( menu_bar
);
116 // WDR: handler implementations for MyFrame
118 void MyFrame::OnQuit( wxCommandEvent
&event
)
123 void MyFrame::OnCloseWindow( wxCloseEvent
&event
)
125 // if ! saved changes -> return
130 //------------------------------------------------------------------------------
132 //------------------------------------------------------------------------------
142 MyFrame
*frame
= new MyFrame( NULL
, -1, "SuperApp", wxPoint(20,20), wxSize(500,340) );