]>
git.saurik.com Git - wxWidgets.git/blob - contrib/samples/canvas/test/test.cpp
4 * Author: Robert Roebling
6 * Copyright: (C) 1998, Robert Roebling
9 // For compilers that support precompilation, includes "wx/wx.h".
10 #include "wx/wxprec.h"
29 #include "wx/canvas/canvas.h"
34 class MywxCanvasImage
: public wxCanvasImage
37 MywxCanvasImage( const wxImage
&image
, double x
, double y
, double w
, double h
);
39 void MywxCanvasImage::OnMouse(wxMouseEvent
&event
);
44 BEGIN_EVENT_TABLE(MywxCanvasImage
,wxCanvasImage
)
45 EVT_MOUSE_EVENTS( MywxCanvasImage::OnMouse
)
48 MywxCanvasImage::MywxCanvasImage( const wxImage
&image
, double x
, double y
, double w
, double h
)
49 :wxCanvasImage( image
, x
, y
, w
, h
)
53 void MywxCanvasImage::OnMouse(wxMouseEvent
&event
)
55 static bool first
=false;
68 Move(m_area
.x
+x
-dx
,m_area
.y
+y
-dy
);
71 else if (IsCapturedMouse())
84 class MyFrame
: public wxFrame
90 void OnAbout( wxCommandEvent
&event
);
91 void OnNewFrame( wxCommandEvent
&event
);
92 void OnQuit( wxCommandEvent
&event
);
93 void OnTimer( wxTimerEvent
&event
);
96 wxCanvasObject
*m_sm1
;
97 wxCanvasObject
*m_sm2
;
98 wxCanvasObject
*m_sm3
;
99 wxCanvasObject
*m_sm4
;
104 DECLARE_DYNAMIC_CLASS(MyFrame
)
105 DECLARE_EVENT_TABLE()
110 class MyApp
: public wxApp
113 virtual bool OnInit();
115 const wxString
& GetFontPath() const { return m_fontpath
; }
127 const int ID_QUIT
= 108;
128 const int ID_ABOUT
= 109;
130 IMPLEMENT_DYNAMIC_CLASS( MyFrame
, wxFrame
)
132 BEGIN_EVENT_TABLE(MyFrame
,wxFrame
)
133 EVT_MENU (ID_ABOUT
, MyFrame::OnAbout
)
134 EVT_MENU (ID_QUIT
, MyFrame::OnQuit
)
135 EVT_TIMER (-1, MyFrame::OnTimer
)
139 : wxFrame( (wxFrame
*)NULL
, -1, "wxCanvas sample",
140 wxPoint(20,20), wxSize(470,460) )
142 wxMenu
*file_menu
= new wxMenu();
143 file_menu
->Append( ID_ABOUT
, "&About...");
144 file_menu
->AppendSeparator();
145 file_menu
->Append( ID_QUIT
, "E&xit");
147 wxMenuBar
*menu_bar
= new wxMenuBar();
148 menu_bar
->Append(file_menu
, "&File");
150 SetMenuBar( menu_bar
);
153 int widths
[] = { -1, 100 };
154 SetStatusWidths( 2, widths
);
156 m_canvas
= new wxCanvas( this, -1, wxPoint(0,0), wxSize(10,10) );
160 m_canvas
->SetArea( 400, 600 );
161 m_canvas
->SetColour( 255, 255, 255 );
163 wxBitmap
bitmap( smile_xpm
);
164 wxImage
image( bitmap
);
166 m_sm1
= new wxCanvasImage( image
, 0,70,16,16 );
167 m_canvas
->Append( m_sm1
);
170 for (i
= 10; i
< 300; i
+=10)
171 m_canvas
->Append( new wxCanvasRect( i
,50,3,140, 255,0,0 ) );
173 m_sm2
= new wxCanvasImage( image
, 0,140,24,24 );
174 m_canvas
->Append( m_sm2
);
176 for (i
= 15; i
< 300; i
+=10)
177 m_canvas
->Append( new wxCanvasRect( i
,50,3,140, 255,0,0 ) );
179 wxButton
*button
= new wxButton( m_canvas
, -1, "Hello", wxPoint(80,50) );
180 m_canvas
->Append( new wxCanvasControl( button
) );
182 m_canvas
->Append( new wxCanvasText( "Hello", 180, 50,
183 wxGetApp().GetFontPath() + "/times.ttf", 20 ) );
185 m_sm3
= new wxCanvasImage( image
, 0,210,32,32 );
186 m_canvas
->Append( m_sm3
);
188 for (i
= 10; i
< 300; i
+=10)
189 m_canvas
->Append( new wxCanvasLine( 10,-15,i
,300, 0,255,0 ) );
191 // m_canvas->Append( new wxCanvasLine( 10,-1500e6,50,300000e6, 0,255,0 ) );
192 // m_canvas->Append( new wxCanvasLine( 10,-150000,50,300000, 0,255,0 ) );
194 m_sm4
= new MywxCanvasImage( image
, 0,270,64,32 );
195 m_canvas
->Append( m_sm4
);
199 m_log
= new wxTextCtrl( this, -1, "", wxPoint(0,0), wxSize(100,100), wxTE_MULTILINE
);
200 wxLog
*old_log
= wxLog::SetActiveTarget( new wxLogTextCtrl( m_log
) );
203 wxBoxSizer
*topsizer
= new wxBoxSizer( wxVERTICAL
);
205 topsizer
->Add( m_canvas
, 1, wxEXPAND
);
206 topsizer
->Add( m_log
, 0, wxEXPAND
);
208 SetAutoLayout( TRUE
);
209 SetSizer( topsizer
);
211 m_timer
= new wxTimer( this );
212 m_timer
->Start( 100, FALSE
);
220 void MyFrame::OnQuit( wxCommandEvent
&WXUNUSED(event
) )
225 void MyFrame::OnTimer( wxTimerEvent
&WXUNUSED(event
) )
227 m_sm1
->Move( m_sm1
->GetX()+1, m_sm1
->GetY() );
228 m_sm2
->Move( m_sm2
->GetX()+1, m_sm2
->GetY() );
229 m_sm3
->Move( m_sm3
->GetX()+1, m_sm3
->GetY() );
230 m_sm4
->Move( m_sm4
->GetX()+1, m_sm4
->GetY() );
234 void MyFrame::OnAbout( wxCommandEvent
&WXUNUSED(event
) )
236 (void)wxMessageBox( "wxCanvas demo\n"
237 "Robert Roebling (c) 1998,2000",
238 "About wxCanvas Demo", wxICON_INFORMATION
| wxOK
);
241 //-----------------------------------------------------------------------------
243 //-----------------------------------------------------------------------------
247 m_fontpath
= getenv("TRUETYPE");
250 wxLogError("Please set env var TRUETYPE to the path where times.ttf lives.");
257 wxImage::AddHandler( new wxPNGHandler
);
260 wxFrame
*frame
= new MyFrame();