]>
Commit | Line | Data |
---|---|---|
6a2c1874 RR |
1 | /* |
2 | * Program: canvas | |
3 | * | |
4 | * Author: Robert Roebling | |
5 | * | |
6 | * Copyright: (C) 1998, Robert Roebling | |
7 | * | |
8 | */ | |
9 | // For compilers that support precompilation, includes "wx/wx.h". | |
10 | #include "wx/wxprec.h" | |
11 | ||
12 | #ifdef __BORLANDC__ | |
13 | #pragma hdrstop | |
14 | #endif | |
15 | ||
16 | #ifndef WX_PRECOMP | |
17 | #include "wx/wx.h" | |
18 | #endif | |
19 | ||
20 | #include <wx/image.h> | |
21 | #include <wx/file.h> | |
22 | #include <wx/timer.h> | |
23 | ||
24 | #include "smile.xpm" | |
25 | ||
26 | #include "wx/canvas/canvas.h" | |
27 | ||
28 | // derived classes | |
29 | ||
30 | class MyFrame; | |
31 | class MyApp; | |
32 | ||
33 | // MyFrame | |
34 | ||
35 | class MyFrame: public wxFrame | |
36 | { | |
37 | public: | |
38 | MyFrame(); | |
39 | ~MyFrame(); | |
40 | ||
41 | void OnAbout( wxCommandEvent &event ); | |
42 | void OnNewFrame( wxCommandEvent &event ); | |
43 | void OnQuit( wxCommandEvent &event ); | |
44 | void OnTimer( wxTimerEvent &event ); | |
45 | ||
46 | wxCanvas *m_canvas; | |
21544859 RR |
47 | wxCanvasObject *m_sm1; |
48 | wxCanvasObject *m_sm2; | |
6a2c1874 RR |
49 | wxTimer *m_timer; |
50 | ||
51 | private: | |
52 | DECLARE_DYNAMIC_CLASS(MyFrame) | |
53 | DECLARE_EVENT_TABLE() | |
54 | }; | |
55 | ||
56 | // MyApp | |
57 | ||
58 | class MyApp: public wxApp | |
59 | { | |
60 | public: | |
61 | virtual bool OnInit(); | |
62 | }; | |
63 | ||
64 | // main program | |
65 | ||
66 | IMPLEMENT_APP(MyApp) | |
67 | ||
68 | // MyFrame | |
69 | ||
70 | const int ID_QUIT = 108; | |
71 | const int ID_ABOUT = 109; | |
72 | ||
73 | IMPLEMENT_DYNAMIC_CLASS( MyFrame, wxFrame ) | |
74 | ||
75 | BEGIN_EVENT_TABLE(MyFrame,wxFrame) | |
76 | EVT_MENU (ID_ABOUT, MyFrame::OnAbout) | |
77 | EVT_MENU (ID_QUIT, MyFrame::OnQuit) | |
78 | EVT_TIMER (-1, MyFrame::OnTimer) | |
79 | END_EVENT_TABLE() | |
80 | ||
81 | MyFrame::MyFrame() | |
82 | : wxFrame( (wxFrame *)NULL, -1, "wxCanvas sample", | |
83 | wxPoint(20,20), wxSize(470,360) ) | |
84 | { | |
85 | wxMenu *file_menu = new wxMenu(); | |
86 | file_menu->Append( ID_ABOUT, "&About..."); | |
87 | file_menu->AppendSeparator(); | |
88 | file_menu->Append( ID_QUIT, "E&xit"); | |
89 | ||
90 | wxMenuBar *menu_bar = new wxMenuBar(); | |
91 | menu_bar->Append(file_menu, "&File"); | |
92 | ||
93 | SetMenuBar( menu_bar ); | |
94 | ||
95 | CreateStatusBar(2); | |
96 | int widths[] = { -1, 100 }; | |
97 | SetStatusWidths( 2, widths ); | |
98 | ||
99 | m_canvas = new wxCanvas( this, -1, wxPoint(0,0), wxSize(10,10) ); | |
100 | ||
101 | m_canvas->SetArea( 400, 600 ); | |
cb281cfc | 102 | m_canvas->SetColour( 255, 255, 255 ); |
6a2c1874 RR |
103 | |
104 | wxBitmap bitmap( smile_xpm ); | |
105 | wxImage image( bitmap ); | |
6a2c1874 | 106 | |
21544859 RR |
107 | m_sm1 = new wxCanvasImage( image, 0, 70 ); |
108 | m_canvas->Append( m_sm1 ); | |
6a2c1874 | 109 | |
21544859 RR |
110 | int i; |
111 | for (i = 10; i < 300; i+=10) | |
112 | m_canvas->Append( new wxCanvasRect( i,50,3,140, 255,0,0 ) ); | |
113 | ||
114 | m_sm2 = new wxCanvasImage( image, 0, 140 ); | |
115 | m_canvas->Append( m_sm2 ); | |
116 | ||
117 | for (i = 15; i < 300; i+=10) | |
118 | m_canvas->Append( new wxCanvasRect( i,50,3,140, 255,0,0 ) ); | |
119 | ||
cb281cfc | 120 | wxButton *button = new wxButton( m_canvas, -1, "Hello", wxPoint(80,50) ); |
3b111dbe | 121 | m_canvas->Append( new wxCanvasControl( button ) ); |
d1f9b206 | 122 | |
cb281cfc | 123 | m_canvas->Append( new wxCanvasText( "Hello", 180, 50, "/home/robert/TrueType/times.ttf", 20 ) ); |
3b111dbe | 124 | |
6a2c1874 | 125 | m_timer = new wxTimer( this ); |
d1f9b206 | 126 | m_timer->Start( 100, FALSE ); |
6a2c1874 RR |
127 | } |
128 | ||
129 | MyFrame::~MyFrame() | |
130 | { | |
131 | delete m_timer; | |
132 | } | |
133 | ||
134 | void MyFrame::OnQuit( wxCommandEvent &WXUNUSED(event) ) | |
135 | { | |
136 | Close( TRUE ); | |
137 | } | |
138 | ||
139 | void MyFrame::OnTimer( wxTimerEvent &WXUNUSED(event) ) | |
140 | { | |
21544859 RR |
141 | m_sm1->Move( m_sm1->GetX()+1, m_sm1->GetY() ); |
142 | m_sm2->Move( m_sm2->GetX()+1, m_sm2->GetY() ); | |
6a2c1874 RR |
143 | wxWakeUpIdle(); |
144 | } | |
145 | ||
146 | void MyFrame::OnAbout( wxCommandEvent &WXUNUSED(event) ) | |
147 | { | |
148 | (void)wxMessageBox( "wxCanvas demo\n" | |
149 | "Robert Roebling (c) 1998,2000", | |
150 | "About wxCanvas Demo", wxICON_INFORMATION | wxOK ); | |
151 | } | |
152 | ||
153 | //----------------------------------------------------------------------------- | |
154 | // MyApp | |
155 | //----------------------------------------------------------------------------- | |
156 | ||
157 | bool MyApp::OnInit() | |
158 | { | |
159 | #if wxUSE_LIBPNG | |
160 | wxImage::AddHandler( new wxPNGHandler ); | |
161 | #endif | |
162 | ||
163 | wxFrame *frame = new MyFrame(); | |
164 | frame->Show( TRUE ); | |
165 | ||
166 | return TRUE; | |
167 | } | |
168 | ||
169 |