]> git.saurik.com Git - wxWidgets.git/commitdiff
Some more tests and mouse events for wxCanvas.
authorRobert Roebling <robert@roebling.de>
Mon, 11 Sep 2000 12:52:39 +0000 (12:52 +0000)
committerRobert Roebling <robert@roebling.de>
Mon, 11 Sep 2000 12:52:39 +0000 (12:52 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@8327 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

contrib/samples/canvas/test/test.cpp
contrib/src/canvas/canvas.cpp

index 93392729724bee3056f5af18ab8ca8785512bfe3..230cbb774a45d61c065478826f3483c60b23885d 100644 (file)
@@ -52,29 +52,25 @@ MywxCanvasImage::MywxCanvasImage( const wxImage &image, double x, double y, doub
 
 void MywxCanvasImage::OnMouse(wxMouseEvent &event)
 {
-    static bool first=FALSE;
     static int dx=0;
     static int dy=0;
 
     int x = event.GetX();
     int y = event.GetY();
-    if (event.m_leftDown)
+    if (event.LeftDown())
     {   
-        if (!first)
-        {
-           first=TRUE;
-           dx=x;
-           dy=y;
-        }
-        Move(m_area.x+x-dx,m_area.y+y-dy);
+        dx=x;
+        dy=y;
         CaptureMouse();
+    } 
+    else if (event.LeftUp())
+    {
+        ReleaseMouse();
     }
     else if (IsCapturedMouse())
     {
-        ReleaseMouse();
-        first=FALSE;
-        dx=0;
-        dy=0;
+        Move(m_area.x+x-dx,m_area.y+y-dy);
+        m_owner->UpdateNow();
     }
 }
 
@@ -99,7 +95,6 @@ MywxCanvasObjectGroupRef::MywxCanvasObjectGroupRef(double x, double y,wxCanvasOb
 
 void MywxCanvasObjectGroupRef::OnMouse(wxMouseEvent &event)
 {
-    static bool first=FALSE;
     static int dx=0;
     static int dy=0;
 
@@ -107,23 +102,20 @@ void MywxCanvasObjectGroupRef::OnMouse(wxMouseEvent &event)
     int x = m_owner->GetDeviceX( event.GetX());
     int y = m_owner->GetDeviceY( event.GetY());
 
-    if (event.m_leftDown)
+    if (event.LeftDown())
     {   
-        if (!first)
-        {
-           first=FALSE;
-           dx=x;
-           dy=y;
-        }
-        Move(m_x+x-dx,m_y+y-dy);
+        dx=x;
+        dy=y;
         CaptureMouse();
+    } 
+    else if (event.LeftUp())
+    {
+        ReleaseMouse();
     }
     else if (IsCapturedMouse())
     {
-        ReleaseMouse();
-        first=FALSE;
-        dx=0;
-        dy=0;
+        Move(m_x+x-dx,m_y+y-dy);
+        m_owner->UpdateNow();
     }
 }
 
@@ -192,7 +184,7 @@ END_EVENT_TABLE()
 
 MyFrame::MyFrame()
        : wxFrame( (wxFrame *)NULL, -1, "wxCanvas sample",
-                  wxPoint(20,20), wxSize(470,860) )
+                  wxPoint(20,20), wxSize(470,460) )
 {
     wxMenu *file_menu = new wxMenu();
     file_menu->Append( ID_ABOUT, "&About...");
@@ -210,7 +202,7 @@ MyFrame::MyFrame()
 
     m_canvas = new wxCanvas( this, -1, wxPoint(0,0), wxSize(10,10) );
 
-    m_canvas->SetArea( 1400, 600 );
+    m_canvas->SetArea( 1000,1000 );
     m_canvas->SetColour( 255, 255, 255 );
 
 
@@ -254,7 +246,6 @@ MyFrame::MyFrame()
     group1->Prepend( new wxCanvasLine( 10,-35,50,190,100,255,0 ) );
     group1->Prepend( new wxCanvasImage( image, 4,38,32,32 ) );
     group1->Prepend( new wxCanvasRect(20,-20,50,170,0,20,240 ) );
-    group1->Prepend( new wxCanvasRect(10,20,104,52,0,240,240 ) );
 
 
     //make another group of wxCanvasObjects
@@ -267,13 +258,14 @@ MyFrame::MyFrame()
     group1->Prepend( m_subref );
 
     //now make two refrences to group1 into root group of the canvas
+/*
     m_ref = new MywxCanvasObjectGroupRef(40,200, group1);
     m_canvas->Prepend( m_ref );
+*/
 
     m_ref2 = new MywxCanvasObjectGroupRef(80,350, group1);
     m_canvas->Prepend( m_ref2 );
 
-
     m_log = new wxTextCtrl( this, -1, "", wxPoint(0,0), wxSize(100,100), wxTE_MULTILINE );
     wxLog *old_log = wxLog::SetActiveTarget( new wxLogTextCtrl( m_log ) );
     delete old_log;
@@ -306,9 +298,11 @@ void MyFrame::OnTimer( wxTimerEvent &WXUNUSED(event) )
     m_sm2->Move( m_sm2->GetX()+1, m_sm2->GetY() );
     m_sm3->Move( m_sm3->GetX()+1, m_sm3->GetY() );
     m_sm4->Move( m_sm4->GetX()+2, m_sm4->GetY() );
+/*
     m_ref->Move( m_ref->GetPosX()+1, m_ref->GetPosY() );
     m_ref2->Move( m_ref2->GetPosX()+2, m_ref2->GetPosY() );
-
+*/
+    
     wxWakeUpIdle();
 }
 
index 300d87c568ef8c01ea4f675cd2f42b9d962165d1..f2284c9ed751818e489a982eaeb651f8c14b9999 100644 (file)
@@ -1296,7 +1296,9 @@ void wxCanvas::OnMouse(wxMouseEvent &event)
             child_event.m_shiftDown = event.m_shiftDown;
             child_event.m_altDown = event.m_altDown;
             child_event.m_metaDown = event.m_metaDown;
+            
             m_captureMouse->ProcessEvent( child_event );
+            return;
         }
         else
         {
@@ -1334,6 +1336,7 @@ void wxCanvas::OnMouse(wxMouseEvent &event)
                     child_event.SetEventType( wxEVT_MOTION );
                     child_event.SetEventObject( obj );
                 }
+                
                 obj->ProcessEvent( child_event );
                 return;
             }
@@ -1357,6 +1360,46 @@ void wxCanvas::OnMouse(wxMouseEvent &event)
             return;
         }
     }
+    else
+    {
+        if (m_captureMouse) //no matter what go to this one
+        {
+            wxMouseEvent child_event( event.GetEventType() );
+            child_event.SetEventObject(m_captureMouse);
+            child_event.m_x = x - m_captureMouse->GetX();
+            child_event.m_y = y - m_captureMouse->GetY();
+            child_event.m_leftDown = event.m_leftDown;
+            child_event.m_rightDown = event.m_rightDown;
+            child_event.m_middleDown = event.m_middleDown;
+            child_event.m_controlDown = event.m_controlDown;
+            child_event.m_shiftDown = event.m_shiftDown;
+            child_event.m_altDown = event.m_altDown;
+            child_event.m_metaDown = event.m_metaDown;
+            m_captureMouse->ProcessEvent( child_event );
+        }
+        else
+        {
+            wxCanvasObject *obj = m_root->IsHitObject(x,y,0);
+
+            if (obj && !obj->IsControl())
+            {
+                wxMouseEvent child_event( event.GetEventType() );
+                child_event.SetEventObject( obj );
+                child_event.m_x = x - obj->GetX();
+                child_event.m_y = y - obj->GetY();
+                child_event.m_leftDown = event.m_leftDown;
+                child_event.m_rightDown = event.m_rightDown;
+                child_event.m_middleDown = event.m_middleDown;
+                child_event.m_controlDown = event.m_controlDown;
+                child_event.m_shiftDown = event.m_shiftDown;
+                child_event.m_altDown = event.m_altDown;
+                child_event.m_metaDown = event.m_metaDown;
+                
+                obj->ProcessEvent( child_event );
+                return;
+            }
+        }
+    }
 
     event.Skip();
 }