]> git.saurik.com Git - wxWidgets.git/blob - contrib/samples/canvas/test/test.cpp
toplevel code transferred to wxTopLevelWindow
[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
10 #ifdef __GNUG__
11 #pragma implementation "test.cpp"
12 #endif
13
14 // For compilers that support precompilation
15 #include "wx/wxprec.h"
16
17 #ifdef __BORLANDC__
18 #pragma hdrstop
19 #endif
20
21 #include "test.h"
22 #include "smile.xpm"
23
24 //-----------------------------------------------------
25 // class MywxCanvasObjectRef
26 //-----------------------------------------------------
27
28 BEGIN_EVENT_TABLE(MywxCanvasObjectRef,wxCanvasObjectRef)
29 EVT_MOUSE_EVENTS( MywxCanvasObjectRef::OnMouseEvent )
30 END_EVENT_TABLE()
31
32 IMPLEMENT_DYNAMIC_CLASS(MywxCanvasObjectRef, wxCanvasObjectRef)
33
34 MywxCanvasObjectRef::MywxCanvasObjectRef(double x, double y,wxCanvasObjectGroup* group)
35 :wxCanvasObjectRef(x,y,group)
36 {
37 }
38
39 MywxCanvasObjectRef::MywxCanvasObjectRef()
40 :wxCanvasObjectRef(0,0,NULL)
41 {
42 }
43
44 MywxCanvasObjectRef::~MywxCanvasObjectRef()
45 {
46 }
47
48 void MywxCanvasObjectRef::OnMouseEvent(wxMouseEvent &event)
49 {
50 if (!m_dragable)
51 {
52 event.Skip();
53 return;
54 }
55
56 static double xprev;
57 static double yprev;
58
59 //new position of the mouse relative within the object
60 double x = m_admin->DeviceToLogicalX(event.GetX());
61 double y = m_admin->DeviceToLogicalY(event.GetY());
62
63 if (event.LeftDown())
64 {
65 CaptureMouse();
66 if (m_dragmode != wxDRAG_REDRAW)
67 DragStart();
68 }
69 else if (event.LeftUp())
70 {
71 ReleaseMouse();
72 if (m_dragmode != wxDRAG_REDRAW)
73 DragEnd();
74 }
75 else if (IsCapturedMouse())
76 {
77 if (m_dragmode != wxDRAG_REDRAW)
78 DragRelative(x-xprev,y-yprev);
79 else
80 MoveRelative(x-xprev,y-yprev);
81 m_admin->UpdateNow();
82 }
83 xprev=x;
84 yprev=y;
85 //well do something extra
86 if (IsCapturedMouse())
87 m_admin->GetActive()->SetCursor(*wxHOURGLASS_CURSOR);
88 else
89 m_admin->GetActive()->SetCursor(*wxSTANDARD_CURSOR);
90 }
91
92 //---------------------------------------------------
93 // class MyEventHandler
94 //---------------------------------------------------
95
96 BEGIN_EVENT_TABLE(MyEventHandler,wxEvtHandler)
97 EVT_MOUSE_EVENTS( MyEventHandler::OnMouseEvent )
98 END_EVENT_TABLE()
99
100 MyEventHandler::MyEventHandler()
101 {
102 }
103
104 void MyEventHandler::OnMouseEvent(wxMouseEvent &event)
105 {
106 wxCanvasObject* obj=(wxCanvasObject*)event.GetEventObject();
107
108 if (!obj->GetDraggable())
109 return;
110
111 static double xprev;
112 static double yprev;
113
114 wxCanvasAdmin* adm=obj->GetAdmin();
115
116 //new position of the mouse relative within the object
117 double x = adm->DeviceToLogicalX(event.GetX());
118 double y = adm->DeviceToLogicalY(event.GetY());
119
120 if (event.LeftDown())
121 {
122 obj->CaptureMouse();
123 if (obj->GetDragMode() != wxDRAG_REDRAW)
124 obj->DragStart();
125 }
126 else if (event.LeftUp())
127 {
128 obj->ReleaseMouse();
129 if (obj->GetDragMode() != wxDRAG_REDRAW)
130 obj->DragEnd();
131 }
132 else if (obj->IsCapturedMouse())
133 {
134 if (obj->GetDragMode() != wxDRAG_REDRAW)
135 obj->DragRelative(x-xprev,y-yprev);
136 else
137 obj->MoveRelative(x-xprev,y-yprev);
138 adm->UpdateNow();
139 }
140 xprev=x;
141 yprev=y;
142 //well do something extra
143 if (obj->IsCapturedMouse())
144 obj->GetAdmin()->GetActive()->SetCursor(*wxHOURGLASS_CURSOR);
145 else
146 obj->GetAdmin()->GetActive()->SetCursor(*wxSTANDARD_CURSOR);
147 }
148
149 //------------------------------------------------
150 // class MyFrame
151 //------------------------------------------------
152
153 class MyApp;
154 class MyCanvas;
155
156 BEGIN_EVENT_TABLE(MyFrame, wxFrame)
157 EVT_MENU(SPLIT_VERTICAL, MyFrame::SplitVertical)
158 EVT_MENU(SPLIT_HORIZONTAL, MyFrame::SplitHorizontal)
159 EVT_MENU(SPLIT_UNSPLIT, MyFrame::Unsplit)
160 EVT_MENU(SPLIT_QUIT, MyFrame::Quit)
161 EVT_MENU(SPLIT_SETMINSIZE, MyFrame::SetMinSize)
162
163 EVT_UPDATE_UI(SPLIT_VERTICAL, MyFrame::UpdateUIVertical)
164 EVT_UPDATE_UI(SPLIT_HORIZONTAL, MyFrame::UpdateUIHorizontal)
165 EVT_UPDATE_UI(SPLIT_UNSPLIT, MyFrame::UpdateUIUnsplit)
166
167 EVT_MENU (ID_ABOUT, MyFrame::OnAbout)
168 EVT_TIMER (-1, MyFrame::OnTimer)
169 END_EVENT_TABLE()
170
171 // My frame constructor
172 MyFrame::MyFrame(wxFrame* frame, const wxString& title, const wxPoint& pos, const wxSize& size):
173 wxFrame(frame, SPLITTER_FRAME, title, pos, size)
174 {
175 m_eventhandler =new MyEventHandler();
176
177 wxPathList pathList;
178 pathList.Add(".");
179 pathList.Add("..");
180
181 wxString path = pathList.FindValidPath("pat36.bmp");
182 gs_bmp36_mono.LoadFile(path, wxBITMAP_TYPE_BMP);
183 wxMask* mask36 = new wxMask(gs_bmp36_mono, *wxBLACK);
184 /* associate a monochrome mask with this bitmap */
185 gs_bmp36_mono.SetMask(mask36);
186
187 CreateStatusBar(2);
188
189 // Make a menubar
190 fileMenu = new wxMenu;
191 fileMenu->Append(SPLIT_VERTICAL, "Split &Vertically\tCtrl-V", "Split vertically");
192 fileMenu->Append(SPLIT_HORIZONTAL, "Split &Horizontally\tCtrl-H", "Split horizontally");
193 fileMenu->Append(SPLIT_UNSPLIT, "&Unsplit", "Unsplit");
194 // fileMenu->Append(SPLIT_UNSPLIT, "&Unsplit\tCtrl-U", "Unsplit");
195 fileMenu->AppendSeparator();
196 fileMenu->Append(SPLIT_SETMINSIZE, "Set &min size", "Set minimum pane size");
197 fileMenu->AppendSeparator();
198 fileMenu->Append(SPLIT_QUIT, "E&xit\tAlt-X", "Exit");
199 fileMenu->Append( ID_ABOUT, "&About...");
200
201
202 menuBar = new wxMenuBar;
203 menuBar->Append(fileMenu, "&File");
204
205 SetMenuBar(menuBar);
206
207 m_splitter = new MySplitterWindow(this, SPLITTER_WINDOW);
208
209 m_canvas1 = new MyCanvas(&m_canvasadmin, m_splitter, CANVAS1, wxPoint(0, 0), wxSize(400, 400),wxHSCROLL|wxVSCROLL);
210 m_canvas1->SetYaxis(FALSE);
211 m_canvas1->SetMappingScroll(-300,-300,500,500,false);
212 m_canvas1->SetScroll(-400,-400,600,600);
213 m_canvas1->SetColour(wxColour(255, 255, 255) );
214 m_canvas1->SetCursor(wxCursor(wxCURSOR_MAGNIFIER));
215
216 m_canvas2 = new MyCanvas(&m_canvasadmin, m_splitter, CANVAS2, wxPoint(0, 0), wxSize(400, 400),wxHSCROLL|wxVSCROLL);
217 m_canvas2->SetMappingScroll(-100,-100,500,500,false);
218 m_canvas2->SetScroll(-400,-400,600,600);
219 m_canvas2->SetColour( wxColour(187, 215, 243) );
220 m_canvas2->Show(FALSE);
221
222 m_canvasadmin.Append(m_canvas1);
223 m_canvasadmin.Append(m_canvas2);
224 m_canvasadmin.SetActive(m_canvas1);
225
226 m_splitter->Initialize(m_canvas1);
227 SetStatusText("Min pane size = 0", 1);
228
229 int widths[] = { -1, 100 };
230 SetStatusWidths( 2, widths );
231
232 //root group always at 0,0
233 m_datatree = new wxCanvasObjectGroup(0,0);
234 m_datatree->DeleteContents( TRUE );
235 m_datatree->SetAdmin(&m_canvasadmin);
236
237 wxBitmap bitmap( smile_xpm );
238 wxImage image( bitmap );
239
240 // m_sm1 = new wxCanvasImage( image, 0,70,32,32 );
241 // m_datatree->Append( m_sm1 );
242
243 int i;
244 for (i = 10; i < 300; i+=10)
245 {
246 wxCanvasRect *r = new wxCanvasRect( i,50,3,140 );
247 r->SetBrush( *wxRED_BRUSH );
248 m_datatree->Append( r );
249 }
250
251
252 // m_sm2 = new wxCanvasImage( image, 0,140,24,24 );
253 // m_datatree->Append( m_sm2 );
254
255 for (i = 15; i < 300; i+=10)
256 {
257 wxCanvasRect* rec= new wxCanvasRect( i,50,3,140 );
258 rec->SetBrush(wxBrush(wxColour(0,10+i,2+i),wxSOLID));
259 rec->SetDraggable(FALSE);
260 m_datatree->Append( rec );
261 }
262
263 /*
264 wxButton *button = new wxButton( m_canvas1, -1, "Hello", wxPoint(80,50) );
265 m_datatree->Append( new wxCanvasControl( button ) );
266
267 m_datatree->Append( new wxCanvasText( "Hello", 180, 50,
268 wxGetApp().GetFontPath() + "/times.ttf", 20 ) );
269
270 m_datatree->Append( new wxCanvasText( "How are you?", 180, 10,
271 wxGetApp().GetFontPath() + "/times.ttf", 8 ) );
272
273 m_datatree->Append( new wxCanvasText( "How are you?", 180, 20,
274 wxGetApp().GetFontPath() + "/times.ttf", 10 ) );
275
276 m_datatree->Append( new wxCanvasText( "How are you?", 180, 30,
277 wxGetApp().GetFontPath() + "/times.ttf", 12 ) );
278 m_sm3 = new wxCanvasImage( image, 0,210,32,32 );
279 m_datatree->Append( m_sm3 );
280 */
281 for (i = 10; i < 300; i+=10)
282 m_datatree->Append( new wxCanvasLine( 10,-15,i,300 ) );
283 /*
284 m_sm4 = new wxCanvasImage( image, 0,270,64,32 );
285 m_sm4->SetDragMode(wxDRAG_RECTANGLE);
286 m_datatree->Append( m_sm4 );
287 */
288
289 // m_canvas->Append( new wxCanvasLine( 10,-1500e6,50,300000e6, 0,255,0 ) );
290 // m_canvas->Append( new wxCanvasLine( 10,-150000,50,300000, 0,255,0 ) );
291
292
293 //make a group of wxCanvasObjects
294 wxCanvasObjectGroup* group1 = new wxCanvasObjectGroup(0,0);
295
296 wxCanvasLine* line = new wxCanvasLine( 10,-35,50,190);
297 line->SetPen(wxPen(wxColour(255,161,5),5,wxDOT_DASH ));
298 group1->Prepend( line );
299 group1->Prepend( new wxCanvasImage( image, 4,38,32,32 ) );
300 wxCanvasRect* rec3 = new wxCanvasRect(20,-20,50,170);
301 rec3->SetBrush(wxBrush(wxColour(0,120,240),wxSOLID));
302 rec3->SetPen(wxPen(wxColour(252,54,252 ),3,wxSOLID));
303 group1->Prepend( rec3 );
304
305 wxCanvasRect* rec2 = new wxCanvasRect(10,20,104,52);
306 rec2->SetBrush(wxBrush(wxColour(0,240,240),wxSOLID));
307 rec2->SetPen(wxPen(wxColour(210,40,50 ),1,wxSOLID));
308 group1->Prepend( rec2 );
309
310
311
312 wxPoint2DDouble* todraw2 = new wxPoint2DDouble[3];
313 todraw2[0].m_x=230;
314 todraw2[0].m_y=220;
315 todraw2[1].m_x=300;
316 todraw2[1].m_y=200;
317 todraw2[2].m_x=300;
318 todraw2[2].m_y=300;
319 wxCanvasPolyline* poly2= new wxCanvasPolyline(3,todraw2);
320 poly2->SetPen(wxPen(wxColour(200,0,64 ),4,wxDOT));
321 m_datatree->Prepend( poly2 );
322
323
324
325 //make another group of wxCanvasObjects
326 wxCanvasObjectGroup* group2 = new wxCanvasObjectGroup(0,0);
327 group2->Prepend( new wxCanvasImage( image, 60,38,52,32 ) );
328 wxCanvasRect* rr = new wxCanvasRect(10,20,104,52,30);
329 rr->SetBrush(wxBrush(wxColour(10,17,255),wxHORIZONTAL_HATCH ));
330 rr->SetPen(wxPen(wxColour(9,115,64 ),4,wxSOLID));
331 group2->Prepend( rr );
332
333
334 //this a reference to group2 put into group1
335 MywxCanvasObjectRef* m_subref = new MywxCanvasObjectRef(60,50, group2);
336 m_subref->SetRotation(35);
337 m_subref->SetRotation(0);
338 group1->Prepend( m_subref );
339
340
341 wxPoint2DDouble* todraw = new wxPoint2DDouble[5];
342 todraw[0].m_x=-30;
343 todraw[0].m_y=-20;
344 todraw[1].m_x=100;
345 todraw[1].m_y=0;
346 todraw[2].m_x=100;
347 todraw[2].m_y=100;
348 todraw[3].m_x=50;
349 todraw[3].m_y=150;
350 todraw[4].m_x=0;
351 todraw[4].m_y=100;
352
353 wxCanvasPolygon* poly= new wxCanvasPolygon(5,todraw);
354 poly->SetBrush(wxBrush(wxColour(100,17,255),wxCROSSDIAG_HATCH ));
355 poly->SetPen(wxPen(wxColour(9,115,64 ),4,wxSOLID));
356 group1->Prepend( poly );
357
358 wxPoint2DDouble* todraw4 = new wxPoint2DDouble[4];
359
360 todraw4[0].m_x=-50;
361 todraw4[0].m_y=-30;
362 todraw4[1].m_x=-50;
363 todraw4[1].m_y=70;
364 todraw4[2].m_x=150;
365 todraw4[2].m_y=70;
366 todraw4[3].m_x=150;
367 todraw4[3].m_y=-30;
368
369 wxCanvasPolygon* poly5= new wxCanvasPolygon(4,todraw4);
370 poly5->SetBrush(wxBrush(wxColour(100,17,255),wxCROSSDIAG_HATCH ));
371 // poly5->SetBrush(wxBrush(wxColour(100,17,255),wxSOLID ));
372 // poly5->SetPen(wxPen(wxColour(9,115,64 ),1,wxSOLID));
373 poly5->SetPen(wxPen(wxColour(9,115,64 ),4,wxSOLID));
374 wxCanvasObjectGroup* group3 = new wxCanvasObjectGroup(0,0);
375 group3->Prepend( poly5 );
376
377 wxList* pointlist = new wxList();
378 wxPoint2DDouble* point = new wxPoint2DDouble(0,0);
379 pointlist->Append((wxObject*)point);
380 point = new wxPoint2DDouble(-300,100);
381 pointlist->Append((wxObject*)point);
382 point = new wxPoint2DDouble(-100,100);
383 pointlist->Append((wxObject*)point);
384 point = new wxPoint2DDouble(-100,0);
385 pointlist->Append((wxObject*)point);
386 point = new wxPoint2DDouble(-200,50);
387 pointlist->Append((wxObject*)point);
388
389 wxCanvasPolygonL* poly15= new wxCanvasPolygonL(pointlist,TRUE);
390 poly15->SetColour1(wxColour(250,78,216 ));
391 poly15->SetColour2(*wxRED);
392 poly15->SetBrush(wxBrush(gs_bmp36_mono));
393 poly15->SetTransParent(TRUE);
394 poly15->SetPen(wxPen(*wxRED,4,wxSOLID));
395 group1->Prepend( poly15 );
396
397 wxList* pointlist2 = new wxList();
398 wxPoint2DDouble* point2 = new wxPoint2DDouble(-400,100);
399 pointlist2->Append((wxObject*)point2);
400 point2 = new wxPoint2DDouble(-400,200);
401 pointlist2->Append((wxObject*)point2);
402 point2 = new wxPoint2DDouble(0,200);
403 pointlist2->Append((wxObject*)point2);
404 point2 = new wxPoint2DDouble(0,100);
405 pointlist2->Append((wxObject*)point2);
406 point2 = new wxPoint2DDouble(-200,175);
407 pointlist2->Append((wxObject*)point2);
408
409 wxCanvasPolylineL* poly16= new wxCanvasPolylineL(pointlist2,TRUE);
410 poly16->SetPen(wxPen(wxColour(9,115,64 ),4,wxSOLID));
411 m_datatree->Prepend( poly16 );
412
413
414 wxPoint2DDouble* todraw6 = new wxPoint2DDouble[5];
415 todraw6[0].m_x=50;
416 todraw6[0].m_y=305;
417 todraw6[1].m_x=-200;
418 todraw6[1].m_y=200;
419 todraw6[2].m_x=0;
420 todraw6[2].m_y=500;
421 todraw6[3].m_x=300;
422 todraw6[3].m_y=200;
423 todraw6[4].m_x=-300;
424 todraw6[4].m_y=-300;
425
426 wxCanvasPolygon* poly17= new wxCanvasPolygon(5,todraw6,TRUE);
427 poly17->SetBrush(wxBrush(wxColour(100,17,255),wxSOLID));
428 poly17->SetPen(wxPen(wxColour(10,17,25),16,wxLONG_DASH ));
429 poly17->SetColour1(*wxGREEN);
430 poly17->SetColour2(*wxRED);
431 poly17->SetGradient(TRUE,wxPen(wxColour(0,0,0),0,wxSOLID),0);
432 wxCanvasObjectRef* m_refc = new wxCanvasObjectRef(0,-200, poly17);
433 m_refc->SetRotation(90);
434 m_datatree->Prepend( m_refc );
435 wxCanvasObjectRef* m_refd = new wxCanvasObjectRef(200,-50, poly17);
436 m_refd->SetRotation(0);
437 m_datatree->Append( m_refd );
438
439 //now make two references to group1 into root group of the canvas
440 m_ref = new MywxCanvasObjectRef(350,-200, group1);
441 m_ref->SetRotation(25);
442 //TODO if rotation is 0 scaling is weird
443 // m_ref->SetScale(2,3.2);
444 m_datatree->Append( m_ref );
445
446 group3->Prepend( m_ref );
447
448
449 //this a reference to group2 put into group1
450 MywxCanvasObjectRef* subref2 = new MywxCanvasObjectRef(20,130, group2);
451 subref2->SetRotation(15);
452 group3->Prepend( subref2 );
453 m_datatree->Prepend( subref2 );
454
455 m_ref2 = new MywxCanvasObjectRef(80,450, group1);
456 m_ref2->SetRotation(-35);
457 m_ref2->SetDragMode(wxDRAG_RECTANGLE);
458 m_datatree->Prepend( m_ref2 );
459
460 wxCanvasCircle* cir = new wxCanvasCircle( -100, -150, 100 );
461 cir->SetBrush(wxBrush(wxColour(19,215,6),wxHORIZONTAL_HATCH ));
462 cir->SetPen(wxPen(wxColour(198,3,105 ),30,wxSOLID));
463 cir->SetDragMode(wxDRAG_REDRAW);
464 m_datatree->Prepend( cir );
465
466 wxCanvasEllipse* elp = new wxCanvasEllipse( -100, 250, 100,300 );
467 elp->SetBrush(wxBrush(wxColour(100,17,55),wxVERTICAL_HATCH ));
468 elp->SetPen(wxPen(wxColour(2,255,6 ),10,wxDOT));
469 m_datatree->Prepend( elp );
470
471 wxCanvasEllipticArc* aelp = new wxCanvasEllipticArc( -230, 250, 100,300, 30,270 );
472 aelp->SetBrush(wxBrush(wxColour(100,17,155),wxSOLID ));
473 aelp->SetPen(wxPen(wxColour(1,215,6 ),10,wxSOLID));
474 m_datatree->Prepend( aelp );
475
476 //HOW BAD DO THINGS GET
477 int kk;
478 for (kk=0;kk<100;kk++)
479 {
480 // MywxCanvasObjectRef* m_refx = new MywxCanvasObjectRef(180,50+kk*30, group1);
481 // m_refx->SetRotation(-35);
482 // m_datatree->Prepend( m_refx );
483 }
484
485 /*
486 m_log = new wxTextCtrl( this, -1, "", wxPoint(0,0), wxSize(100,100), wxTE_MULTILINE );
487 wxLog *old_log = wxLog::SetActiveTarget( new wxLogTextCtrl( m_log ) );
488 delete old_log;
489
490 wxBoxSizer *topsizer = new wxBoxSizer( wxVERTICAL );
491
492 topsizer->Add( m_canvas, 1, wxEXPAND );
493 topsizer->Add( m_log, 0, wxEXPAND );
494
495 SetAutoLayout( TRUE );
496 SetSizer( topsizer );
497 */
498
499 //fancy background
500 wxPoint2DDouble* todraw8 = new wxPoint2DDouble[4];
501 todraw8[0].m_x=-350;
502 todraw8[0].m_y=-350;
503 todraw8[1].m_x=-350;
504 todraw8[1].m_y=550;
505 todraw8[2].m_x=550;
506 todraw8[2].m_y=550;
507 todraw8[3].m_x=550;
508 todraw8[3].m_y=-350;
509
510 wxCanvasPolygon* poly18= new wxCanvasPolygon(4,todraw8);
511 poly18->SetPen(wxPen(wxColour(10,17,25),16,wxTRANSPARENT ));
512 poly18->SetColour1(wxColour(0,0,0));
513 poly18->SetColour2(wxColour(0,255,255));
514 poly18->SetGradient(TRUE,wxPen(wxColour(0,0,0),0,wxSOLID),0);
515
516 wxCanvasObjectRef* m_refb = new wxCanvasObjectRef(200,0, poly18);
517 m_refb->SetRotation(90);
518
519 m_datatree->Prepend( m_refb );
520
521 /*
522 wxCanvasCircle* cir = new wxCanvasCircle( -100, -150, 100 );
523 cir->SetBrush(wxBrush(wxColour(19,215,6),wxHORIZONTAL_HATCH ));
524 cir->SetPen(wxPen(wxColour(198,3,105 ),30,wxSOLID));
525 m_datatree->Prepend( cir );
526 */
527 m_datatree->SetAdmin(&m_canvasadmin);
528 m_datatree->AppendEventHandler( m_eventhandler );
529 m_canvas1->SetRoot(m_datatree);
530
531 //wxCanvasObjectGroup* group3 = new wxCanvasObjectGroup(0,0);
532 // group3->Prepend( cir );
533
534 group3->SetAdmin(&m_canvasadmin);
535 m_canvas2->SetRoot(group3);
536
537 m_timer = new wxTimer( this );
538 //m_timer->Start( 100, FALSE );
539 }
540
541 MyFrame::~MyFrame()
542 {
543 m_datatree->RemoveLastEventHandler( FALSE );
544 delete m_eventhandler;
545 delete m_timer;
546 }
547
548 void MyFrame::Quit(wxCommandEvent& WXUNUSED(event) )
549 {
550 Close(TRUE);
551 }
552
553 void MyFrame::SplitHorizontal(wxCommandEvent& WXUNUSED(event) )
554 {
555 if ( m_splitter->IsSplit() )
556 m_splitter->Unsplit();
557 m_canvas1->Show(TRUE);
558 m_canvas2->Show(TRUE);
559 m_splitter->SplitHorizontally( m_canvas1, m_canvas2 );
560 UpdatePosition();
561 }
562
563 void MyFrame::SplitVertical(wxCommandEvent& WXUNUSED(event) )
564 {
565 if ( m_splitter->IsSplit() )
566 m_splitter->Unsplit();
567 m_canvas1->Show(TRUE);
568 m_canvas2->Show(TRUE);
569 m_splitter->SplitVertically( m_canvas1, m_canvas2 );
570 UpdatePosition();
571 }
572
573 void MyFrame::Unsplit(wxCommandEvent& WXUNUSED(event) )
574 {
575 if ( m_splitter->IsSplit() )
576 m_splitter->Unsplit();
577 SetStatusText("No splitter");
578 }
579
580 void MyFrame::SetMinSize(wxCommandEvent& WXUNUSED(event) )
581 {
582 wxString str;
583 str.Printf( _T("%d"), m_splitter->GetMinimumPaneSize());
584 str = wxGetTextFromUser("Enter minimal size for panes:", "", str, this);
585 if ( str.IsEmpty() )
586 return;
587
588 int minsize = wxStrtol( str, (wxChar**)NULL, 10 );
589 m_splitter->SetMinimumPaneSize(minsize);
590 str.Printf( _T("Min pane size = %d"), minsize);
591 SetStatusText(str, 1);
592 }
593
594 void MyFrame::UpdateUIHorizontal(wxUpdateUIEvent& event)
595 {
596 event.Enable( ( (!m_splitter->IsSplit()) || (m_splitter->GetSplitMode() != wxSPLIT_HORIZONTAL) ) );
597 }
598
599 void MyFrame::UpdateUIVertical(wxUpdateUIEvent& event)
600 {
601 event.Enable( ( (!m_splitter->IsSplit()) || (m_splitter->GetSplitMode() != wxSPLIT_VERTICAL) ) );
602 }
603
604 void MyFrame::UpdateUIUnsplit(wxUpdateUIEvent& event)
605 {
606 event.Enable( m_splitter->IsSplit() );
607 }
608
609 void MyFrame::UpdatePosition()
610 {
611 wxString str;
612 str.Printf( "Sash position = %d", m_splitter->GetSashPosition());
613 SetStatusText(str);
614 }
615
616 void MyFrame::OnQuit( wxCommandEvent &WXUNUSED(event) )
617 {
618 Close( TRUE );
619 }
620
621 void MyFrame::OnTimer( wxTimerEvent &WXUNUSED(event) )
622 {
623 m_sm1->MoveRelative( 1, 0);
624 m_sm2->MoveRelative( 1, 0);
625 m_sm3->MoveRelative( 1, 0);
626 m_sm4->MoveRelative( 2, 0);
627
628 // m_ref->MoveRelative( 1, 0 );
629 m_ref2->MoveRelative( 2, 0 );
630 m_canvas1->UpdateNow();
631
632
633 wxWakeUpIdle();
634 }
635
636 void MyFrame::OnAbout( wxCommandEvent &WXUNUSED(event) )
637 {
638 (void)wxMessageBox( "wxCanvas demo\n"
639 "Robert Roebling (c) 1998,2000 \n Modified by Klaas Holwerda 2000",
640 "About wxCanvas Demo", wxICON_INFORMATION | wxOK );
641 }
642
643
644 //------------------------------------------------
645 // class MyCanvas
646 //------------------------------------------------
647
648 // the event tables connect the wxWindows events with the functions (event
649 // handlers) which process them.
650 BEGIN_EVENT_TABLE(MyCanvas,wxVectorCanvas)
651 EVT_MOUSE_EVENTS (MyCanvas::OnMouseEvent)
652 END_EVENT_TABLE()
653
654 MyCanvas::MyCanvas(wxCanvasAdmin* admin, MySplitterWindow *parent, wxWindowID id,
655 const wxPoint &position, const wxSize& size, long style ) :
656 wxVectorCanvas( admin, parent, id, position, size, style )
657 {
658 m_parent=parent;
659 }
660
661 void MyCanvas::OnMouseEvent(wxMouseEvent& event)
662 {
663 wxClientDC dc(this);
664 PrepareDC(dc);
665
666 wxPoint pos = event.GetPosition();
667
668 m_mouse_worldx = DeviceToLogicalX( pos.x );
669 m_mouse_worldy = DeviceToLogicalY( pos.y );
670
671 wxString str;
672 str.Printf( "Current mouse position: %f,%f", m_mouse_worldx, m_mouse_worldy );
673 m_parent->SetStatusText( str );
674
675 if (!event.m_controlDown && !GetCaptured())
676 {
677 if (event.LeftDown())
678 {
679 m_zoom_x1=m_zoom_x2=pos.x;
680 m_zoom_y1=m_zoom_y2=pos.y;
681 }
682 if (event.RightDown())
683 {
684 SetMappingScroll(m_virtm_minX,m_virtm_minY,m_virtm_maxX,m_virtm_maxY,0);
685 Update( 0,0, GetBufferWidth(), GetBufferHeight(), TRUE );
686 UpdateNow();
687 }
688 if (event.LeftUp())
689 {
690 m_zoom_x2=pos.x;
691 m_zoom_y2=pos.y;
692 double x_virt_min=DeviceToLogicalX(m_zoom_x1);
693 double y_virt_min=DeviceToLogicalY(m_zoom_y2);
694 double x_virt_max=DeviceToLogicalX(m_zoom_x2);
695 double y_virt_max=DeviceToLogicalY(m_zoom_y1);
696 SetMappingScroll(x_virt_min,y_virt_min,x_virt_max,y_virt_max,0);
697 Update( 0,0, GetBufferWidth(), GetBufferHeight(), TRUE );
698 UpdateNow();
699 }
700 if (event.Dragging()&& event.m_leftDown)
701 {
702 dc.SetLogicalFunction(wxINVERT);
703 dc.DrawRectangle(m_zoom_x1,m_zoom_y1,m_zoom_x2-m_zoom_x1,m_zoom_y2-m_zoom_y1 );
704 m_zoom_x2=pos.x;
705 m_zoom_y2=pos.y;
706 dc.DrawRectangle(m_zoom_x1,m_zoom_y1,m_zoom_x2-m_zoom_x1,m_zoom_y2-m_zoom_y1 );
707 }
708 }
709 else
710 {
711 wxVectorCanvas::OnMouse(event);
712 }
713 }
714
715
716 //-----------------------------------------------------------------------------
717 // MyApp
718 //-----------------------------------------------------------------------------
719
720 // main program
721
722 IMPLEMENT_APP(MyApp)
723
724 bool MyApp::OnInit()
725 {
726 m_fontpath = getenv("TRUETYPE");
727 m_fontpath = "c:/WINNT/Fonts/times.ttf";
728 if ( !m_fontpath )
729 {
730 wxLogError("Please set env var TRUETYPE to the path where times.ttf lives.");
731
732 return FALSE;
733
734 }
735
736 #if wxUSE_LIBPNG
737 wxImage::AddHandler( new wxPNGHandler );
738 #endif
739
740 wxFrame *frame = new MyFrame((wxFrame *) NULL, "wxCanvas Example", wxPoint(0,0), wxSize(400,500));
741 frame->Show( TRUE );
742
743 SetTopWindow(frame);
744
745 return TRUE;
746 }
747