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();
}
}
void MywxCanvasObjectGroupRef::OnMouse(wxMouseEvent &event)
{
- static bool first=FALSE;
static int dx=0;
static int dy=0;
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();
}
}
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...");
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 );
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
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;
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();
}
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
{
child_event.SetEventType( wxEVT_MOTION );
child_event.SetEventObject( obj );
}
+
obj->ProcessEvent( child_event );
return;
}
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();
}