]>
git.saurik.com Git - wxWidgets.git/blob - contrib/samples/canvas/test/test.cpp
4 * Author: Robert Roebling
6 * Copyright: (C) 1998, Robert Roebling
11 #pragma implementation "test.cpp"
14 // For compilers that support precompilation
15 #include "wx/wxprec.h"
24 //-----------------------------------------------------
25 // class MywxCanvasObjectRef
26 //-----------------------------------------------------
28 BEGIN_EVENT_TABLE(MywxCanvasObjectRef
,wxCanvasObjectRef
)
29 EVT_MOUSE_EVENTS( MywxCanvasObjectRef::OnMouseEvent
)
32 IMPLEMENT_DYNAMIC_CLASS(MywxCanvasObjectRef
, wxCanvasObjectRef
)
34 MywxCanvasObjectRef::MywxCanvasObjectRef(double x
, double y
,wxCanvasObjectGroup
* group
)
35 :wxCanvasObjectRef(x
,y
,group
)
39 MywxCanvasObjectRef::MywxCanvasObjectRef()
40 :wxCanvasObjectRef(0,0,NULL
)
44 MywxCanvasObjectRef::~MywxCanvasObjectRef()
48 void MywxCanvasObjectRef::OnMouseEvent(wxMouseEvent
&event
)
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());
66 if (m_dragmode
!= DRAG_REDRAW
)
69 else if (event
.LeftUp())
72 if (m_dragmode
!= DRAG_REDRAW
)
75 else if (IsCapturedMouse())
77 if (m_dragmode
!= DRAG_REDRAW
)
78 DragRelative(x
-xprev
,y
-yprev
);
80 MoveRelative(x
-xprev
,y
-yprev
);
85 //well do something extra
86 if (IsCapturedMouse())
87 m_admin
->GetActive()->SetCursor(*wxHOURGLASS_CURSOR
);
89 m_admin
->GetActive()->SetCursor(*wxSTANDARD_CURSOR
);
92 //---------------------------------------------------
93 // class MyEventHandler
94 //---------------------------------------------------
96 BEGIN_EVENT_TABLE(MyEventHandler
,wxEvtHandler
)
97 EVT_MOUSE_EVENTS( MyEventHandler::OnMouseEvent
)
100 MyEventHandler::MyEventHandler()
104 void MyEventHandler::OnMouseEvent(wxMouseEvent
&event
)
106 wxCanvasObject
* obj
=(wxCanvasObject
*)event
.GetEventObject();
108 if (!obj
->GetDraggable())
114 wxCanvasAdmin
* adm
=obj
->GetAdmin();
116 //new position of the mouse relative within the object
117 double x
= adm
->DeviceToLogicalX(event
.GetX());
118 double y
= adm
->DeviceToLogicalY(event
.GetY());
120 if (event
.LeftDown())
123 if (obj
->GetDragMode() != DRAG_REDRAW
)
126 else if (event
.LeftUp())
129 if (obj
->GetDragMode() != DRAG_REDRAW
)
132 else if (obj
->IsCapturedMouse())
134 if (obj
->GetDragMode() != DRAG_REDRAW
)
135 obj
->DragRelative(x
-xprev
,y
-yprev
);
137 obj
->MoveRelative(x
-xprev
,y
-yprev
);
142 //well do something extra
143 if (obj
->IsCapturedMouse())
144 obj
->GetAdmin()->GetActive()->SetCursor(*wxHOURGLASS_CURSOR
);
146 obj
->GetAdmin()->GetActive()->SetCursor(*wxSTANDARD_CURSOR
);
149 //------------------------------------------------
151 //------------------------------------------------
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
)
163 EVT_UPDATE_UI(SPLIT_VERTICAL
, MyFrame::UpdateUIVertical
)
164 EVT_UPDATE_UI(SPLIT_HORIZONTAL
, MyFrame::UpdateUIHorizontal
)
165 EVT_UPDATE_UI(SPLIT_UNSPLIT
, MyFrame::UpdateUIUnsplit
)
167 EVT_MENU (ID_ABOUT
, MyFrame::OnAbout
)
168 EVT_TIMER (-1, MyFrame::OnTimer
)
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
)
175 m_eventhandler
=new MyEventHandler();
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
);
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...");
202 menuBar
= new wxMenuBar
;
203 menuBar
->Append(fileMenu
, "&File");
207 m_splitter
= new MySplitterWindow(this, SPLITTER_WINDOW
);
209 m_canvas1
= new MyCanvas(&m_canvasadmin
, m_splitter
, CANVAS1
, wxPoint(0, 0), wxSize(400, 400),wxHSCROLL
|wxVSCROLL
);
210 m_canvas1
->SetYaxis(TRUE
);
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
));
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
);
222 m_canvasadmin
.Append(m_canvas1
);
223 m_canvasadmin
.Append(m_canvas2
);
224 m_canvasadmin
.SetActive(m_canvas1
);
226 m_splitter
->Initialize(m_canvas1
);
227 SetStatusText("Min pane size = 0", 1);
229 int widths
[] = { -1, 100 };
230 SetStatusWidths( 2, widths
);
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
);
237 wxBitmap
bitmap( smile_xpm
);
238 wxImage
image( bitmap
);
240 // m_sm1 = new wxCanvasImage( image, 0,70,32,32 );
241 // m_datatree->Append( m_sm1 );
244 for (i
= 10; i
< 300; i
+=10)
246 wxCanvasRect
*r
= new wxCanvasRect( i
,50,3,140 );
247 r
->SetBrush( *wxRED_BRUSH
);
248 m_datatree
->Append( r
);
252 // m_sm2 = new wxCanvasImage( image, 0,140,24,24 );
253 // m_datatree->Append( m_sm2 );
255 for (i
= 15; i
< 300; i
+=10)
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
);
264 wxButton *button = new wxButton( m_canvas1, -1, "Hello", wxPoint(80,50) );
265 m_datatree->Append( new wxCanvasControl( button ) );
267 m_datatree->Append( new wxCanvasText( "Hello", 180, 50,
268 wxGetApp().GetFontPath() + "/times.ttf", 20 ) );
270 m_datatree->Append( new wxCanvasText( "How are you?", 180, 10,
271 wxGetApp().GetFontPath() + "/times.ttf", 8 ) );
273 m_datatree->Append( new wxCanvasText( "How are you?", 180, 20,
274 wxGetApp().GetFontPath() + "/times.ttf", 10 ) );
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 );
281 for (i
= 10; i
< 300; i
+=10)
282 m_datatree
->Append( new wxCanvasLine( 10,-15,i
,300 ) );
284 m_sm4 = new wxCanvasImage( image, 0,270,64,32 );
285 m_sm4->SetDragMode(DRAG_RECTANGLE);
286 m_datatree->Append( m_sm4 );
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 ) );
293 //make a group of wxCanvasObjects
294 wxCanvasObjectGroup
* group1
= new wxCanvasObjectGroup(0,0);
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
);
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
);
312 wxPoint2DDouble
* todraw2
= new wxPoint2DDouble
[3];
319 wxCanvasPolyline
* poly2
= new wxCanvasPolyline(3,todraw2
);
320 poly2
->SetPen(wxPen(wxColour(200,0,64 ),4,wxDOT
));
321 m_datatree
->Prepend( poly2
);
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
);
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
);
341 wxPoint2DDouble
* todraw
= new wxPoint2DDouble
[5];
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
);
358 wxPoint2DDouble
* todraw4
= new wxPoint2DDouble
[4];
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
);
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
);
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
);
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
);
409 wxCanvasPolylineL
* poly16
= new wxCanvasPolylineL(pointlist2
,TRUE
);
410 poly16
->SetPen(wxPen(wxColour(9,115,64 ),4,wxSOLID
));
411 m_datatree
->Prepend( poly16
);
414 wxPoint2DDouble
* todraw6
= new wxPoint2DDouble
[5];
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
);
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
);
446 group3
->Prepend( m_ref
);
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
);
455 m_ref2
= new MywxCanvasObjectRef(80,450, group1
);
456 m_ref2
->SetRotation(-35);
457 m_ref2
->SetDragMode(DRAG_RECTANGLE
);
458 m_datatree
->Prepend( m_ref2
);
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(DRAG_REDRAW
);
464 m_datatree
->Prepend( cir
);
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
);
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
);
476 //HOW BAD DO THINGS GET
478 for (kk
=0;kk
<100;kk
++)
480 // MywxCanvasObjectRef* m_refx = new MywxCanvasObjectRef(180,50+kk*30, group1);
481 // m_refx->SetRotation(-35);
482 // m_datatree->Prepend( m_refx );
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 ) );
490 wxBoxSizer *topsizer = new wxBoxSizer( wxVERTICAL );
492 topsizer->Add( m_canvas, 1, wxEXPAND );
493 topsizer->Add( m_log, 0, wxEXPAND );
495 SetAutoLayout( TRUE );
496 SetSizer( topsizer );
500 wxPoint2DDouble
* todraw8
= new wxPoint2DDouble
[4];
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);
516 wxCanvasObjectRef
* m_refb
= new wxCanvasObjectRef(200,0, poly18
);
517 m_refb
->SetRotation(90);
519 m_datatree
->Prepend( m_refb
);
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 );
527 m_datatree
->SetAdmin(&m_canvasadmin
);
528 m_datatree
->AppendEventHandler( m_eventhandler
);
529 m_canvas1
->SetRoot(m_datatree
);
531 //wxCanvasObjectGroup* group3 = new wxCanvasObjectGroup(0,0);
532 // group3->Prepend( cir );
534 group3
->SetAdmin(&m_canvasadmin
);
535 m_canvas2
->SetRoot(group3
);
537 m_timer
= new wxTimer( this );
538 //m_timer->Start( 100, FALSE );
543 m_datatree
->RemoveLastEventHandler( FALSE
);
544 delete m_eventhandler
;
548 void MyFrame::Quit(wxCommandEvent
& WXUNUSED(event
) )
553 void MyFrame::SplitHorizontal(wxCommandEvent
& WXUNUSED(event
) )
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
);
563 void MyFrame::SplitVertical(wxCommandEvent
& WXUNUSED(event
) )
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
);
573 void MyFrame::Unsplit(wxCommandEvent
& WXUNUSED(event
) )
575 if ( m_splitter
->IsSplit() )
576 m_splitter
->Unsplit();
577 SetStatusText("No splitter");
580 void MyFrame::SetMinSize(wxCommandEvent
& WXUNUSED(event
) )
583 str
.Printf( _T("%d"), m_splitter
->GetMinimumPaneSize());
584 str
= wxGetTextFromUser("Enter minimal size for panes:", "", str
, this);
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);
594 void MyFrame::UpdateUIHorizontal(wxUpdateUIEvent
& event
)
596 event
.Enable( ( (!m_splitter
->IsSplit()) || (m_splitter
->GetSplitMode() != wxSPLIT_HORIZONTAL
) ) );
599 void MyFrame::UpdateUIVertical(wxUpdateUIEvent
& event
)
601 event
.Enable( ( (!m_splitter
->IsSplit()) || (m_splitter
->GetSplitMode() != wxSPLIT_VERTICAL
) ) );
604 void MyFrame::UpdateUIUnsplit(wxUpdateUIEvent
& event
)
606 event
.Enable( m_splitter
->IsSplit() );
609 void MyFrame::UpdatePosition()
612 str
.Printf( "Sash position = %d", m_splitter
->GetSashPosition());
616 void MyFrame::OnQuit( wxCommandEvent
&WXUNUSED(event
) )
621 void MyFrame::OnTimer( wxTimerEvent
&WXUNUSED(event
) )
623 m_sm1
->MoveRelative( 1, 0);
624 m_sm2
->MoveRelative( 1, 0);
625 m_sm3
->MoveRelative( 1, 0);
626 m_sm4
->MoveRelative( 2, 0);
628 // m_ref->MoveRelative( 1, 0 );
629 m_ref2
->MoveRelative( 2, 0 );
630 m_canvas1
->UpdateNow();
636 void MyFrame::OnAbout( wxCommandEvent
&WXUNUSED(event
) )
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
);
644 //------------------------------------------------
646 //------------------------------------------------
648 // the event tables connect the wxWindows events with the functions (event
649 // handlers) which process them.
650 BEGIN_EVENT_TABLE(MyCanvas
,wxCanvas
)
651 EVT_MOUSE_EVENTS (MyCanvas::OnMouseEvent
)
654 MyCanvas::MyCanvas(wxCanvasAdmin
* admin
, MySplitterWindow
*parent
, wxWindowID id
,
655 const wxPoint
&position
, const wxSize
& size
, long style
) :
656 wxCanvas( admin
, parent
, id
, position
, size
, style
)
661 void MyCanvas::OnMouseEvent(wxMouseEvent
& event
)
666 wxPoint pos
= event
.GetPosition();
668 m_mouse_worldx
= DeviceToLogicalX( pos
.x
);
669 m_mouse_worldy
= DeviceToLogicalY( pos
.y
);
672 str
.Printf( "Current mouse position: %f,%f", m_mouse_worldx
, m_mouse_worldy
);
673 m_parent
->SetStatusText( str
);
675 if (!event
.m_controlDown
&& !GetCaptured())
677 if (event
.LeftDown())
679 m_zoom_x1
=m_zoom_x2
=pos
.x
;
680 m_zoom_y1
=m_zoom_y2
=pos
.y
;
682 if (event
.RightDown())
684 SetMappingScroll(m_virtm_minX
,m_virtm_minY
,m_virtm_maxX
,m_virtm_maxY
,0);
685 Update( 0,0, GetBufferWidth(), GetBufferHeight(), TRUE
);
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
);
700 if (event
.Dragging()&& event
.m_leftDown
)
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
);
706 dc
.DrawRectangle(m_zoom_x1
,m_zoom_y1
,m_zoom_x2
-m_zoom_x1
,m_zoom_y2
-m_zoom_y1
);
711 wxCanvas::OnMouse(event
);
716 //-----------------------------------------------------------------------------
718 //-----------------------------------------------------------------------------
726 m_fontpath
= getenv("TRUETYPE");
727 m_fontpath
= "c:/WINNT/Fonts/times.ttf";
730 wxLogError("Please set env var TRUETYPE to the path where times.ttf lives.");
737 wxImage::AddHandler( new wxPNGHandler
);
740 wxFrame
*frame
= new MyFrame((wxFrame
*) NULL
, "wxCanvas Example", wxPoint(0,0), wxSize(400,500));