]>
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) );
158 m_canvas
->SetArea( 400, 600 );
159 m_canvas
->SetColour( 255, 255, 255 );
161 wxBitmap
bitmap( smile_xpm
);
162 wxImage
image( bitmap
);
164 m_sm1
= new wxCanvasImage( image
, 0,70,16,16 );
165 m_canvas
->Append( m_sm1
);
168 for (i
= 10; i
< 300; i
+=10)
169 m_canvas
->Append( new wxCanvasRect( i
,50,3,140, 255,0,0 ) );
171 m_sm2
= new wxCanvasImage( image
, 0,140,24,24 );
172 m_canvas
->Append( m_sm2
);
174 for (i
= 15; i
< 300; i
+=10)
175 m_canvas
->Append( new wxCanvasRect( i
,50,3,140, 255,0,0 ) );
177 wxButton
*button
= new wxButton( m_canvas
, -1, "Hello", wxPoint(80,50) );
178 m_canvas
->Append( new wxCanvasControl( button
) );
180 m_canvas
->Append( new wxCanvasText( "Hello", 180, 50,
181 wxGetApp().GetFontPath() + "/times.ttf", 20 ) );
183 m_sm3
= new wxCanvasImage( image
, 0,210,32,32 );
184 m_canvas
->Append( m_sm3
);
186 for (i
= 10; i
< 300; i
+=10)
187 m_canvas
->Append( new wxCanvasLine( 10,-15,i
,300, 0,255,0 ) );
189 // m_canvas->Append( new wxCanvasLine( 10,-1500e6,50,300000e6, 0,255,0 ) );
190 // m_canvas->Append( new wxCanvasLine( 10,-150000,50,300000, 0,255,0 ) );
192 m_sm4
= new MywxCanvasImage( image
, 0,270,64,32 );
193 m_canvas
->Append( m_sm4
);
195 m_log
= new wxTextCtrl( this, -1, "", wxPoint(0,0), wxSize(100,100), wxTE_MULTILINE
);
196 wxLog
*old_log
= wxLog::SetActiveTarget( new wxLogTextCtrl( m_log
) );
199 wxBoxSizer
*topsizer
= new wxBoxSizer( wxVERTICAL
);
201 topsizer
->Add( m_canvas
, 1, wxEXPAND
);
202 topsizer
->Add( m_log
, 0, wxEXPAND
);
204 SetAutoLayout( TRUE
);
205 SetSizer( topsizer
);
207 m_timer
= new wxTimer( this );
208 m_timer
->Start( 100, FALSE
);
216 void MyFrame::OnQuit( wxCommandEvent
&WXUNUSED(event
) )
221 void MyFrame::OnTimer( wxTimerEvent
&WXUNUSED(event
) )
223 m_sm1
->Move( m_sm1
->GetX()+1, m_sm1
->GetY() );
224 m_sm2
->Move( m_sm2
->GetX()+1, m_sm2
->GetY() );
225 m_sm3
->Move( m_sm3
->GetX()+1, m_sm3
->GetY() );
226 m_sm4
->Move( m_sm4
->GetX()+1, m_sm4
->GetY() );
231 void MyFrame::OnAbout( wxCommandEvent
&WXUNUSED(event
) )
233 (void)wxMessageBox( "wxCanvas demo\n"
234 "Robert Roebling (c) 1998,2000",
235 "About wxCanvas Demo", wxICON_INFORMATION
| wxOK
);
238 //-----------------------------------------------------------------------------
240 //-----------------------------------------------------------------------------
244 m_fontpath
= getenv("TRUETYPE");
247 wxLogError("Please set env var TRUETYPE to the path where times.ttf lives.");
254 wxImage::AddHandler( new wxPNGHandler
);
257 wxFrame
*frame
= new MyFrame();