]> git.saurik.com Git - wxWidgets.git/blame - contrib/samples/canvas/test/test.cpp
Corrected typo
[wxWidgets.git] / contrib / samples / canvas / test / test.cpp
CommitLineData
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
30class MyFrame;
31class MyApp;
32
33// MyFrame
34
35class MyFrame: public wxFrame
36{
37public:
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
50private:
51 DECLARE_DYNAMIC_CLASS(MyFrame)
52 DECLARE_EVENT_TABLE()
53};
54
55// MyApp
56
57class MyApp: public wxApp
58{
59public:
60 virtual bool OnInit();
61};
62
63// main program
64
65IMPLEMENT_APP(MyApp)
66
67// MyFrame
68
69const int ID_QUIT = 108;
70const int ID_ABOUT = 109;
71
72IMPLEMENT_DYNAMIC_CLASS( MyFrame, wxFrame )
73
74BEGIN_EVENT_TABLE(MyFrame,wxFrame)
75 EVT_MENU (ID_ABOUT, MyFrame::OnAbout)
76 EVT_MENU (ID_QUIT, MyFrame::OnQuit)
77 EVT_TIMER (-1, MyFrame::OnTimer)
78END_EVENT_TABLE()
79
80MyFrame::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 );
cb281cfc 101 m_canvas->SetColour( 255, 255, 255 );
6a2c1874
RR
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
cb281cfc 108 m_canvas->Append( new wxCanvasImage( image, 40, 50 ) );
6a2c1874 109
cb281cfc 110 wxButton *button = new wxButton( m_canvas, -1, "Hello", wxPoint(80,50) );
3b111dbe 111 m_canvas->Append( new wxCanvasControl( button ) );
d1f9b206 112
cb281cfc 113 m_canvas->Append( new wxCanvasText( "Hello", 180, 50, "/home/robert/TrueType/times.ttf", 20 ) );
3b111dbe 114
6a2c1874 115 m_timer = new wxTimer( this );
d1f9b206 116 m_timer->Start( 100, FALSE );
6a2c1874
RR
117}
118
119MyFrame::~MyFrame()
120{
121 delete m_timer;
122}
123
124void MyFrame::OnQuit( wxCommandEvent &WXUNUSED(event) )
125{
126 Close( TRUE );
127}
128
129void MyFrame::OnTimer( wxTimerEvent &WXUNUSED(event) )
130{
131 m_co->Move( m_co->GetX()+1, m_co->GetY() );
132 wxWakeUpIdle();
133}
134
135void 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
146bool 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