]> git.saurik.com Git - wxWidgets.git/blob - contrib/samples/canvas/test/test.cpp
TrueType support for Canvas.
[wxWidgets.git] / contrib / samples / canvas / test / test.cpp
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;
47 wxCanvasObject *m_co;
48 wxTimer *m_timer;
49
50 private:
51 DECLARE_DYNAMIC_CLASS(MyFrame)
52 DECLARE_EVENT_TABLE()
53 };
54
55 // MyApp
56
57 class MyApp: public wxApp
58 {
59 public:
60 virtual bool OnInit();
61 };
62
63 // main program
64
65 IMPLEMENT_APP(MyApp)
66
67 // MyFrame
68
69 const int ID_QUIT = 108;
70 const int ID_ABOUT = 109;
71
72 IMPLEMENT_DYNAMIC_CLASS( MyFrame, wxFrame )
73
74 BEGIN_EVENT_TABLE(MyFrame,wxFrame)
75 EVT_MENU (ID_ABOUT, MyFrame::OnAbout)
76 EVT_MENU (ID_QUIT, MyFrame::OnQuit)
77 EVT_TIMER (-1, MyFrame::OnTimer)
78 END_EVENT_TABLE()
79
80 MyFrame::MyFrame()
81 : wxFrame( (wxFrame *)NULL, -1, "wxCanvas sample",
82 wxPoint(20,20), wxSize(470,360) )
83 {
84 wxMenu *file_menu = new wxMenu();
85 file_menu->Append( ID_ABOUT, "&About...");
86 file_menu->AppendSeparator();
87 file_menu->Append( ID_QUIT, "E&xit");
88
89 wxMenuBar *menu_bar = new wxMenuBar();
90 menu_bar->Append(file_menu, "&File");
91
92 SetMenuBar( menu_bar );
93
94 CreateStatusBar(2);
95 int widths[] = { -1, 100 };
96 SetStatusWidths( 2, widths );
97
98 m_canvas = new wxCanvas( this, -1, wxPoint(0,0), wxSize(10,10) );
99
100 m_canvas->SetArea( 400, 600 );
101 m_canvas->SetColour( 255, 255, 255 );
102
103 wxBitmap bitmap( smile_xpm );
104 wxImage image( bitmap );
105 m_co = new wxCanvasImage( image, 10, 50 );
106 m_canvas->Append( m_co );
107
108 m_canvas->Append( new wxCanvasImage( image, 40, 50 ) );
109
110 wxButton *button = new wxButton( m_canvas, -1, "Hello", wxPoint(80,50) );
111 m_canvas->Append( new wxCanvasControl( button ) );
112
113 m_canvas->Append( new wxCanvasText( "Hello", 180, 50, "/home/robert/TrueType/times.ttf", 20 ) );
114
115 m_timer = new wxTimer( this );
116 m_timer->Start( 100, FALSE );
117 }
118
119 MyFrame::~MyFrame()
120 {
121 delete m_timer;
122 }
123
124 void MyFrame::OnQuit( wxCommandEvent &WXUNUSED(event) )
125 {
126 Close( TRUE );
127 }
128
129 void MyFrame::OnTimer( wxTimerEvent &WXUNUSED(event) )
130 {
131 m_co->Move( m_co->GetX()+1, m_co->GetY() );
132 wxWakeUpIdle();
133 }
134
135 void MyFrame::OnAbout( wxCommandEvent &WXUNUSED(event) )
136 {
137 (void)wxMessageBox( "wxCanvas demo\n"
138 "Robert Roebling (c) 1998,2000",
139 "About wxCanvas Demo", wxICON_INFORMATION | wxOK );
140 }
141
142 //-----------------------------------------------------------------------------
143 // MyApp
144 //-----------------------------------------------------------------------------
145
146 bool MyApp::OnInit()
147 {
148 #if wxUSE_LIBPNG
149 wxImage::AddHandler( new wxPNGHandler );
150 #endif
151
152 wxFrame *frame = new MyFrame();
153 frame->Show( TRUE );
154
155 return TRUE;
156 }
157
158