]> git.saurik.com Git - wxWidgets.git/blame - contrib/samples/canvas/test/test.cpp
Commented out palette code for wxGTK
[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>
239c1f50
RR
23#include <wx/log.h>
24
6a2c1874
RR
25
26#include "smile.xpm"
27
28#include "wx/canvas/canvas.h"
29
30// derived classes
31
32class MyFrame;
33class MyApp;
34
35// MyFrame
36
37class MyFrame: public wxFrame
38{
39public:
40 MyFrame();
41 ~MyFrame();
42
43 void OnAbout( wxCommandEvent &event );
44 void OnNewFrame( wxCommandEvent &event );
45 void OnQuit( wxCommandEvent &event );
46 void OnTimer( wxTimerEvent &event );
47
239c1f50
RR
48 wxCanvas *m_canvas;
49 wxCanvasObject *m_sm1;
50 wxCanvasObject *m_sm2;
51 wxCanvasObject *m_sm3;
52 wxCanvasObject *m_sm4;
53 wxTimer *m_timer;
54 wxTextCtrl *m_log;
6a2c1874
RR
55
56private:
57 DECLARE_DYNAMIC_CLASS(MyFrame)
58 DECLARE_EVENT_TABLE()
59};
60
61// MyApp
62
63class MyApp: public wxApp
64{
65public:
66 virtual bool OnInit();
cba349dc
VZ
67
68 const wxString& GetFontPath() const { return m_fontpath; }
69
70private:
71 wxString m_fontpath;
6a2c1874
RR
72};
73
74// main program
75
76IMPLEMENT_APP(MyApp)
77
78// MyFrame
79
80const int ID_QUIT = 108;
81const int ID_ABOUT = 109;
82
83IMPLEMENT_DYNAMIC_CLASS( MyFrame, wxFrame )
84
85BEGIN_EVENT_TABLE(MyFrame,wxFrame)
86 EVT_MENU (ID_ABOUT, MyFrame::OnAbout)
87 EVT_MENU (ID_QUIT, MyFrame::OnQuit)
88 EVT_TIMER (-1, MyFrame::OnTimer)
89END_EVENT_TABLE()
90
91MyFrame::MyFrame()
92 : wxFrame( (wxFrame *)NULL, -1, "wxCanvas sample",
239c1f50 93 wxPoint(20,20), wxSize(470,460) )
6a2c1874 94{
239c1f50
RR
95 wxMenu *file_menu = new wxMenu();
96 file_menu->Append( ID_ABOUT, "&About...");
97 file_menu->AppendSeparator();
98 file_menu->Append( ID_QUIT, "E&xit");
99
100 wxMenuBar *menu_bar = new wxMenuBar();
101 menu_bar->Append(file_menu, "&File");
102
103 SetMenuBar( menu_bar );
104
105 CreateStatusBar(2);
106 int widths[] = { -1, 100 };
107 SetStatusWidths( 2, widths );
108
109 m_canvas = new wxCanvas( this, -1, wxPoint(0,0), wxSize(10,10) );
110
111 m_canvas->Freeze();
112
113 m_canvas->SetArea( 400, 600 );
114 m_canvas->SetColour( 255, 255, 255 );
6a2c1874 115
239c1f50
RR
116 wxBitmap bitmap( smile_xpm );
117 wxImage image( bitmap );
6a2c1874 118
239c1f50
RR
119 m_sm1 = new wxCanvasImage( image, 0, 70 );
120 m_canvas->Append( m_sm1 );
6a2c1874 121
239c1f50
RR
122 int i;
123 for (i = 10; i < 300; i+=10)
124 m_canvas->Append( new wxCanvasRect( i,50,3,140, 255,0,0 ) );
6a2c1874 125
239c1f50
RR
126 m_sm2 = new wxCanvasImage( image, 0, 140 );
127 m_canvas->Append( m_sm2 );
6a2c1874 128
239c1f50
RR
129 for (i = 15; i < 300; i+=10)
130 m_canvas->Append( new wxCanvasRect( i,50,3,140, 255,0,0 ) );
cba349dc 131
239c1f50
RR
132 wxButton *button = new wxButton( m_canvas, -1, "Hello", wxPoint(80,50) );
133 m_canvas->Append( new wxCanvasControl( button ) );
cba349dc 134
239c1f50
RR
135 m_canvas->Append( new wxCanvasText( "Hello", 180, 50,
136 wxGetApp().GetFontPath() + "/times.ttf", 20 ) );
cba349dc 137
239c1f50
RR
138 m_sm3 = new wxCanvasImage( image, 0, 210 );
139 m_canvas->Append( m_sm3 );
cba349dc 140
239c1f50
RR
141 for (i = 10; i < 300; i+=10)
142 m_canvas->Append( new wxCanvasLine( 10,150,i,200, 0,255,0 ) );
143
144 m_sm4 = new wxCanvasImage( image, 0, 270 );
145 m_canvas->Append( m_sm4 );
cba349dc 146
239c1f50 147 m_canvas->Thaw();
cba349dc 148
239c1f50
RR
149 m_log = new wxTextCtrl( this, -1, "", wxPoint(0,0), wxSize(100,100), wxTE_MULTILINE );
150 wxLog *old_log = wxLog::SetActiveTarget( new wxLogTextCtrl( m_log ) );
151 delete old_log;
152
153 wxBoxSizer *topsizer = new wxBoxSizer( wxVERTICAL );
154
155 topsizer->Add( m_canvas, 1, wxEXPAND );
156 topsizer->Add( m_log, 0, wxEXPAND );
d1f9b206 157
239c1f50
RR
158 SetAutoLayout( TRUE );
159 SetSizer( topsizer );
cba349dc 160
239c1f50
RR
161 m_timer = new wxTimer( this );
162 m_timer->Start( 100, FALSE );
6a2c1874
RR
163}
164
165MyFrame::~MyFrame()
166{
167 delete m_timer;
168}
169
170void MyFrame::OnQuit( wxCommandEvent &WXUNUSED(event) )
171{
172 Close( TRUE );
173}
174
175void MyFrame::OnTimer( wxTimerEvent &WXUNUSED(event) )
176{
21544859
RR
177 m_sm1->Move( m_sm1->GetX()+1, m_sm1->GetY() );
178 m_sm2->Move( m_sm2->GetX()+1, m_sm2->GetY() );
239c1f50
RR
179 m_sm3->Move( m_sm3->GetX()+1, m_sm3->GetY() );
180 m_sm4->Move( m_sm4->GetX()+1, m_sm4->GetY() );
6a2c1874
RR
181 wxWakeUpIdle();
182}
183
184void MyFrame::OnAbout( wxCommandEvent &WXUNUSED(event) )
185{
186 (void)wxMessageBox( "wxCanvas demo\n"
187 "Robert Roebling (c) 1998,2000",
188 "About wxCanvas Demo", wxICON_INFORMATION | wxOK );
189}
190
191//-----------------------------------------------------------------------------
192// MyApp
193//-----------------------------------------------------------------------------
194
195bool MyApp::OnInit()
196{
cba349dc
VZ
197 m_fontpath = getenv("TRUETYPE");
198 if ( !m_fontpath )
199 {
200 wxLogError("Please set env var TRUETYPE to the path where times.ttf lives.");
201
202 return FALSE;
203
204 }
205
6a2c1874
RR
206#if wxUSE_LIBPNG
207 wxImage::AddHandler( new wxPNGHandler );
208#endif
209
210 wxFrame *frame = new MyFrame();
211 frame->Show( TRUE );
212
213 return TRUE;
214}
215
216