Commit 89a138c0 authored by Maciej Suminski's avatar Maciej Suminski

Added handling keyboard events for the Tool framework.

parent 5adba827
...@@ -1017,5 +1017,6 @@ void EDA_DRAW_FRAME::UseGalCanvas( bool aEnable ) ...@@ -1017,5 +1017,6 @@ void EDA_DRAW_FRAME::UseGalCanvas( bool aEnable )
m_auimgr.GetPane( wxT( "DrawFrameGal" ) ).Show( aEnable ); m_auimgr.GetPane( wxT( "DrawFrameGal" ) ).Show( aEnable );
m_auimgr.Update(); m_auimgr.Update();
m_galCanvas->SetFocus();
m_galCanvasActive = aEnable; m_galCanvasActive = aEnable;
} }
...@@ -1334,7 +1334,6 @@ void EDA_DRAW_PANEL::OnKeyEvent( wxKeyEvent& event ) ...@@ -1334,7 +1334,6 @@ void EDA_DRAW_PANEL::OnKeyEvent( wxKeyEvent& event )
Screen->SetMousePosition( pos ); Screen->SetMousePosition( pos );
GetParent()->GeneralControl( &DC, pos, localkey ); GetParent()->GeneralControl( &DC, pos, localkey );
} }
......
...@@ -84,20 +84,21 @@ EDA_DRAW_PANEL_GAL::EDA_DRAW_PANEL_GAL( wxWindow* aParentWindow, wxWindowID aWin ...@@ -84,20 +84,21 @@ EDA_DRAW_PANEL_GAL::EDA_DRAW_PANEL_GAL( wxWindow* aParentWindow, wxWindowID aWin
m_viewControls = new KiGfx::WX_VIEW_CONTROLS( m_view, this ); m_viewControls = new KiGfx::WX_VIEW_CONTROLS( m_view, this );
Connect( wxEVT_PAINT, wxPaintEventHandler( EDA_DRAW_PANEL_GAL::onPaint ), NULL, this ); Connect( wxEVT_PAINT, wxPaintEventHandler( EDA_DRAW_PANEL_GAL::onPaint ), NULL, this );
Connect( wxEVT_SIZE, wxSizeEventHandler( EDA_DRAW_PANEL_GAL::onSize ), NULL, this ); Connect( wxEVT_SIZE, wxSizeEventHandler( EDA_DRAW_PANEL_GAL::onSize ), NULL, this );
/* Generic events for the Tool Dispatcher */ /* Generic events for the Tool Dispatcher */
Connect( wxEVT_MOTION, wxEventHandler( EDA_DRAW_PANEL_GAL::onEvent ), NULL, this ); Connect( wxEVT_MOTION, wxEventHandler( EDA_DRAW_PANEL_GAL::onEvent ), NULL, this );
Connect( wxEVT_LEFT_UP, wxEventHandler( EDA_DRAW_PANEL_GAL::onEvent ), NULL, this ); Connect( wxEVT_LEFT_UP, wxEventHandler( EDA_DRAW_PANEL_GAL::onEvent ), NULL, this );
Connect( wxEVT_LEFT_DOWN, wxEventHandler( EDA_DRAW_PANEL_GAL::onEvent ), NULL, this ); Connect( wxEVT_LEFT_DOWN, wxEventHandler( EDA_DRAW_PANEL_GAL::onEvent ), NULL, this );
Connect( wxEVT_RIGHT_UP, wxEventHandler( EDA_DRAW_PANEL_GAL::onEvent ), NULL, this ); Connect( wxEVT_RIGHT_UP, wxEventHandler( EDA_DRAW_PANEL_GAL::onEvent ), NULL, this );
Connect( wxEVT_RIGHT_DOWN, wxEventHandler( EDA_DRAW_PANEL_GAL::onEvent ), NULL, this ); Connect( wxEVT_RIGHT_DOWN, wxEventHandler( EDA_DRAW_PANEL_GAL::onEvent ), NULL, this );
Connect( wxEVT_MIDDLE_UP, wxEventHandler( EDA_DRAW_PANEL_GAL::onEvent ), NULL, this ); Connect( wxEVT_MIDDLE_UP, wxEventHandler( EDA_DRAW_PANEL_GAL::onEvent ), NULL, this );
Connect( wxEVT_MIDDLE_DOWN, wxEventHandler( EDA_DRAW_PANEL_GAL::onEvent ), NULL, this ); Connect( wxEVT_MIDDLE_DOWN, wxEventHandler( EDA_DRAW_PANEL_GAL::onEvent ), NULL, this );
Connect( wxEVT_MOUSEWHEEL, wxEventHandler( EDA_DRAW_PANEL_GAL::onEvent ), NULL, this ); Connect( wxEVT_MOUSEWHEEL, wxEventHandler( EDA_DRAW_PANEL_GAL::onEvent ), NULL, this );
Connect( wxEVT_KEY_UP, wxEventHandler( EDA_DRAW_PANEL_GAL::onEvent ), NULL, this ); Connect( wxEVT_CHAR_HOOK, wxEventHandler( EDA_DRAW_PANEL_GAL::skipEvent ), NULL, this );
Connect( wxEVT_KEY_DOWN, wxEventHandler( EDA_DRAW_PANEL_GAL::onEvent ), NULL, this ); Connect( wxEVT_KEY_UP, wxEventHandler( EDA_DRAW_PANEL_GAL::onEvent ), NULL, this );
Connect( wxEVT_KEY_DOWN, wxEventHandler( EDA_DRAW_PANEL_GAL::onEvent ), NULL, this );
} }
...@@ -209,3 +210,10 @@ void EDA_DRAW_PANEL_GAL::onEvent( wxEvent& aEvent ) ...@@ -209,3 +210,10 @@ void EDA_DRAW_PANEL_GAL::onEvent( wxEvent& aEvent )
m_eventDispatcher->DispatchWxEvent( aEvent ); m_eventDispatcher->DispatchWxEvent( aEvent );
} }
} }
void EDA_DRAW_PANEL_GAL::skipEvent( wxEvent& aEvent )
{
// This is necessary for CHAR_HOOK event to generate KEY_UP and KEY_DOWN events
aEvent.Skip();
}
...@@ -52,17 +52,16 @@ CAIRO_GAL::CAIRO_GAL( wxWindow* aParent, wxEvtHandler* aMouseListener, ...@@ -52,17 +52,16 @@ CAIRO_GAL::CAIRO_GAL( wxWindow* aParent, wxEvtHandler* aMouseListener,
groupCounter = 0; groupCounter = 0;
// Connecting the event handlers // Connecting the event handlers
Connect( wxEVT_PAINT, wxPaintEventHandler( CAIRO_GAL::onPaint ) ); Connect( wxEVT_PAINT, wxPaintEventHandler( CAIRO_GAL::onPaint ) );
// Mouse events are skipped to the parent // Mouse events are skipped to the parent
Connect( wxEVT_MOTION, wxMouseEventHandler( CAIRO_GAL::skipMouseEvent ) ); Connect( wxEVT_MOTION, wxMouseEventHandler( CAIRO_GAL::skipMouseEvent ) );
Connect( wxEVT_MOUSEWHEEL, wxMouseEventHandler( CAIRO_GAL::skipMouseEvent ) ); Connect( wxEVT_LEFT_DOWN, wxMouseEventHandler( CAIRO_GAL::skipMouseEvent ) );
Connect( wxEVT_RIGHT_DOWN, wxMouseEventHandler( CAIRO_GAL::skipMouseEvent ) ); Connect( wxEVT_LEFT_UP, wxMouseEventHandler( CAIRO_GAL::skipMouseEvent ) );
Connect( wxEVT_RIGHT_UP, wxMouseEventHandler( CAIRO_GAL::skipMouseEvent ) );
Connect( wxEVT_LEFT_DOWN, wxMouseEventHandler( CAIRO_GAL::skipMouseEvent ) );
Connect( wxEVT_LEFT_UP, wxMouseEventHandler( CAIRO_GAL::skipMouseEvent ) );
Connect( wxEVT_MIDDLE_DOWN, wxMouseEventHandler( CAIRO_GAL::skipMouseEvent ) ); Connect( wxEVT_MIDDLE_DOWN, wxMouseEventHandler( CAIRO_GAL::skipMouseEvent ) );
Connect( wxEVT_MIDDLE_UP, wxMouseEventHandler( CAIRO_GAL::skipMouseEvent ) ); Connect( wxEVT_MIDDLE_UP, wxMouseEventHandler( CAIRO_GAL::skipMouseEvent ) );
Connect( wxEVT_RIGHT_DOWN, wxMouseEventHandler( CAIRO_GAL::skipMouseEvent ) );
Connect( wxEVT_RIGHT_UP, wxMouseEventHandler( CAIRO_GAL::skipMouseEvent ) );
#if defined _WIN32 || defined _WIN64 #if defined _WIN32 || defined _WIN64
Connect( wxEVT_ENTER_WINDOW, wxMouseEventHandler( CAIRO_GAL::skipMouseEvent ) ); Connect( wxEVT_ENTER_WINDOW, wxMouseEventHandler( CAIRO_GAL::skipMouseEvent ) );
#endif #endif
......
...@@ -66,17 +66,16 @@ OPENGL_GAL::OPENGL_GAL( wxWindow* aParent, wxEvtHandler* aMouseListener, ...@@ -66,17 +66,16 @@ OPENGL_GAL::OPENGL_GAL( wxWindow* aParent, wxEvtHandler* aMouseListener,
groupCounter = 0; groupCounter = 0;
// Connecting the event handlers // Connecting the event handlers
Connect( wxEVT_PAINT, wxPaintEventHandler( OPENGL_GAL::onPaint ) ); Connect( wxEVT_PAINT, wxPaintEventHandler( OPENGL_GAL::onPaint ) );
// Mouse events are skipped to the parent // Mouse events are skipped to the parent
Connect( wxEVT_MOTION, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) ); Connect( wxEVT_MOTION, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) );
Connect( wxEVT_MOUSEWHEEL, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) ); Connect( wxEVT_LEFT_DOWN, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) );
Connect( wxEVT_RIGHT_DOWN, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) ); Connect( wxEVT_LEFT_UP, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) );
Connect( wxEVT_RIGHT_UP, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) );
Connect( wxEVT_LEFT_DOWN, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) );
Connect( wxEVT_LEFT_UP, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) );
Connect( wxEVT_MIDDLE_DOWN, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) ); Connect( wxEVT_MIDDLE_DOWN, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) );
Connect( wxEVT_MIDDLE_UP, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) ); Connect( wxEVT_MIDDLE_UP, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) );
Connect( wxEVT_RIGHT_DOWN, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) );
Connect( wxEVT_RIGHT_UP, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) );
#if defined _WIN32 || defined _WIN64 #if defined _WIN32 || defined _WIN64
Connect( wxEVT_ENTER_WINDOW, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) ); Connect( wxEVT_ENTER_WINDOW, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) );
#endif #endif
......
...@@ -44,7 +44,7 @@ using boost::optional; ...@@ -44,7 +44,7 @@ using boost::optional;
struct TOOL_DISPATCHER::ButtonState struct TOOL_DISPATCHER::ButtonState
{ {
ButtonState( TOOL_MouseButtons aButton, const wxEventType& aDownEvent, ButtonState( TOOL_MouseButtons aButton, const wxEventType& aDownEvent,
const wxEventType & aUpEvent, bool aTriggerMenu = false) : const wxEventType& aUpEvent, bool aTriggerMenu = false ) :
button( aButton ), button( aButton ),
downEvent( aDownEvent ), downEvent( aDownEvent ),
upEvent( aUpEvent ), upEvent( aUpEvent ),
...@@ -63,7 +63,7 @@ struct TOOL_DISPATCHER::ButtonState ...@@ -63,7 +63,7 @@ struct TOOL_DISPATCHER::ButtonState
bool triggerContextMenu; bool triggerContextMenu;
wxLongLong downTimestamp; wxLongLong downTimestamp;
void Reset() void Reset()
{ {
dragging = false; dragging = false;
...@@ -72,8 +72,8 @@ struct TOOL_DISPATCHER::ButtonState ...@@ -72,8 +72,8 @@ struct TOOL_DISPATCHER::ButtonState
}; };
TOOL_DISPATCHER::TOOL_DISPATCHER( TOOL_MANAGER *aToolMgr, PCB_BASE_FRAME *aEditFrame ) : TOOL_DISPATCHER::TOOL_DISPATCHER( TOOL_MANAGER* aToolMgr, PCB_BASE_FRAME* aEditFrame ) :
m_toolMgr(aToolMgr), m_editFrame(aEditFrame) m_toolMgr( aToolMgr ), m_editFrame( aEditFrame )
{ {
m_buttons.push_back( new ButtonState( MB_Left, wxEVT_LEFT_DOWN, wxEVT_LEFT_UP ) ); m_buttons.push_back( new ButtonState( MB_Left, wxEVT_LEFT_DOWN, wxEVT_LEFT_UP ) );
m_buttons.push_back( new ButtonState( MB_Right, wxEVT_RIGHT_DOWN, wxEVT_RIGHT_UP, true ) ); m_buttons.push_back( new ButtonState( MB_Right, wxEVT_RIGHT_DOWN, wxEVT_RIGHT_UP, true ) );
...@@ -103,23 +103,22 @@ KiGfx::VIEW* TOOL_DISPATCHER::getView() ...@@ -103,23 +103,22 @@ KiGfx::VIEW* TOOL_DISPATCHER::getView()
} }
int TOOL_DISPATCHER::decodeModifiers( wxEvent& aEvent ) int TOOL_DISPATCHER::decodeModifiers( const wxKeyboardState* aState ) const
{ {
wxMouseEvent* me = static_cast<wxMouseEvent*>( &aEvent );
int mods = 0; int mods = 0;
if( me->ControlDown() ) if( aState->ControlDown() )
mods |= MB_ModCtrl; mods |= MD_ModCtrl;
if( me->AltDown() ) if( aState->AltDown() )
mods |= MB_ModAlt; mods |= MD_ModAlt;
if( me->ShiftDown() ) if( aState->ShiftDown() )
mods |= MB_ModShift; mods |= MD_ModShift;
return mods; return mods;
} }
bool TOOL_DISPATCHER::handleMouseButton ( wxEvent& aEvent, int aIndex, bool aMotion ) bool TOOL_DISPATCHER::handleMouseButton( wxEvent& aEvent, int aIndex, bool aMotion )
{ {
ButtonState* st = m_buttons[aIndex]; ButtonState* st = m_buttons[aIndex];
wxEventType type = aEvent.GetEventType(); wxEventType type = aEvent.GetEventType();
...@@ -128,7 +127,7 @@ bool TOOL_DISPATCHER::handleMouseButton ( wxEvent& aEvent, int aIndex, bool aMot ...@@ -128,7 +127,7 @@ bool TOOL_DISPATCHER::handleMouseButton ( wxEvent& aEvent, int aIndex, bool aMot
bool up = type == st->upEvent; bool up = type == st->upEvent;
bool down = type == st->downEvent; bool down = type == st->downEvent;
int mods = decodeModifiers( aEvent ); int mods = decodeModifiers( static_cast<wxMouseEvent*>( &aEvent ) );
int args = st->button | mods; int args = st->button | mods;
if( down ) if( down )
...@@ -139,7 +138,7 @@ bool TOOL_DISPATCHER::handleMouseButton ( wxEvent& aEvent, int aIndex, bool aMot ...@@ -139,7 +138,7 @@ bool TOOL_DISPATCHER::handleMouseButton ( wxEvent& aEvent, int aIndex, bool aMot
st->pressed = true; st->pressed = true;
evt = TOOL_EVENT( TC_Mouse, TA_MouseDown, args ); evt = TOOL_EVENT( TC_Mouse, TA_MouseDown, args );
} }
else if ( up ) else if( up )
{ {
bool isClick = false; bool isClick = false;
st->pressed = false; st->pressed = false;
...@@ -148,7 +147,8 @@ bool TOOL_DISPATCHER::handleMouseButton ( wxEvent& aEvent, int aIndex, bool aMot ...@@ -148,7 +147,8 @@ bool TOOL_DISPATCHER::handleMouseButton ( wxEvent& aEvent, int aIndex, bool aMot
{ {
wxLongLong t = wxGetLocalTimeMillis(); wxLongLong t = wxGetLocalTimeMillis();
if( t - st->downTimestamp < DragTimeThreshold && st->dragMaxDelta < DragDistanceThreshold ) if( t - st->downTimestamp < DragTimeThreshold &&
st->dragMaxDelta < DragDistanceThreshold )
isClick = true; isClick = true;
else else
evt = TOOL_EVENT( TC_Mouse, TA_MouseUp, args ); evt = TOOL_EVENT( TC_Mouse, TA_MouseUp, args );
...@@ -159,7 +159,7 @@ bool TOOL_DISPATCHER::handleMouseButton ( wxEvent& aEvent, int aIndex, bool aMot ...@@ -159,7 +159,7 @@ bool TOOL_DISPATCHER::handleMouseButton ( wxEvent& aEvent, int aIndex, bool aMot
if( isClick ) if( isClick )
{ {
if( st -> triggerContextMenu && !mods ) if( st->triggerContextMenu && !mods )
{} {}
// evt = TOOL_EVENT( TC_Command, TA_ContextMenu ); // evt = TOOL_EVENT( TC_Command, TA_ContextMenu );
else else
...@@ -197,7 +197,7 @@ bool TOOL_DISPATCHER::handleMouseButton ( wxEvent& aEvent, int aIndex, bool aMot ...@@ -197,7 +197,7 @@ bool TOOL_DISPATCHER::handleMouseButton ( wxEvent& aEvent, int aIndex, bool aMot
} }
void TOOL_DISPATCHER::DispatchWxEvent( wxEvent &aEvent ) void TOOL_DISPATCHER::DispatchWxEvent( wxEvent& aEvent )
{ {
bool motion = false, buttonEvents = false; bool motion = false, buttonEvents = false;
VECTOR2D pos; VECTOR2D pos;
...@@ -205,26 +205,43 @@ void TOOL_DISPATCHER::DispatchWxEvent( wxEvent &aEvent ) ...@@ -205,26 +205,43 @@ void TOOL_DISPATCHER::DispatchWxEvent( wxEvent &aEvent )
int type = aEvent.GetEventType(); int type = aEvent.GetEventType();
if( type == wxEVT_MOTION ) // Mouse handling
if( type == wxEVT_MOTION || type == wxEVT_MOUSEWHEEL ||
type == wxEVT_LEFT_DOWN || type == wxEVT_LEFT_UP ||
type == wxEVT_MIDDLE_DOWN || type == wxEVT_MIDDLE_UP ||
type == wxEVT_RIGHT_DOWN || type == wxEVT_RIGHT_UP )
{ {
wxMouseEvent *me = static_cast<wxMouseEvent*>( &aEvent ); wxMouseEvent* me = static_cast<wxMouseEvent*>( &aEvent );
pos = getView()->ToWorld( VECTOR2D( me->GetX(), me->GetY() ) ); pos = getView()->ToWorld( VECTOR2D( me->GetX(), me->GetY() ) );
if( pos != m_lastMousePos ) if( pos != m_lastMousePos )
{ {
motion = true; motion = true;
m_lastMousePos = pos; m_lastMousePos = pos;
} }
}
for( unsigned int i = 0; i < m_buttons.size(); i++ ) for( unsigned int i = 0; i < m_buttons.size(); i++ )
buttonEvents |= handleMouseButton( aEvent, i, motion ); buttonEvents |= handleMouseButton( aEvent, i, motion );
if( !buttonEvents && motion ) if( !buttonEvents && motion )
{ {
evt = TOOL_EVENT (TC_Mouse, TA_MouseMotion ); evt = TOOL_EVENT( TC_Mouse, TA_MouseMotion );
evt->SetMousePosition( pos ); evt->SetMousePosition( pos );
}
} }
// Keyboard handling
else if( type == wxEVT_KEY_UP || type == wxEVT_KEY_DOWN )
{
wxKeyEvent* ke = static_cast<wxKeyEvent*>( &aEvent );
int key = ke->GetKeyCode();
int mods = decodeModifiers( ke );
if( type == wxEVT_KEY_UP )
evt = TOOL_EVENT( TC_Keyboard, TA_KeyUp, key | mods );
else
evt = TOOL_EVENT( TC_Keyboard, TA_KeyDown, key | mods );
}
if( evt ) if( evt )
m_toolMgr->ProcessEvent( *evt ); m_toolMgr->ProcessEvent( *evt );
...@@ -237,7 +254,7 @@ void TOOL_DISPATCHER::DispatchWxCommand( wxCommandEvent &aEvent ) ...@@ -237,7 +254,7 @@ void TOOL_DISPATCHER::DispatchWxCommand( wxCommandEvent &aEvent )
bool activateTool = false; bool activateTool = false;
std::string toolName; std::string toolName;
switch ( aEvent.GetId() ) switch( aEvent.GetId() )
{ {
case ID_SELECTION_TOOL: case ID_SELECTION_TOOL:
toolName = "pcbnew.InteractiveSelection"; toolName = "pcbnew.InteractiveSelection";
...@@ -247,7 +264,7 @@ void TOOL_DISPATCHER::DispatchWxCommand( wxCommandEvent &aEvent ) ...@@ -247,7 +264,7 @@ void TOOL_DISPATCHER::DispatchWxCommand( wxCommandEvent &aEvent )
if( activateTool ) if( activateTool )
{ {
TOOL_EVENT evt ( TC_Command, TA_ActivateTool, toolName ); TOOL_EVENT evt( TC_Command, TA_ActivateTool, toolName );
m_toolMgr->ProcessEvent( evt ); m_toolMgr->ProcessEvent( evt );
} }
} }
...@@ -44,9 +44,13 @@ struct FlagString ...@@ -44,9 +44,13 @@ struct FlagString
static const std::string flag2string( int flag, const FlagString* exps ) static const std::string flag2string( int flag, const FlagString* exps )
{ {
std::string rv; std::string rv;
for(int i = 0; exps[i].str.length(); i++)
if(exps[i].flag & flag) for( int i = 0; exps[i].str.length(); i++ )
rv+=exps[i].str+" "; {
if( exps[i].flag & flag )
rv += exps[i].str + " ";
}
return rv; return rv;
} }
...@@ -57,6 +61,7 @@ const std::string TOOL_EVENT::Format() const ...@@ -57,6 +61,7 @@ const std::string TOOL_EVENT::Format() const
const FlagString categories[] = { const FlagString categories[] = {
{ TC_Mouse, "mouse" }, { TC_Mouse, "mouse" },
{ TC_Keyboard, "keyboard" },
{ TC_Command, "command" }, { TC_Command, "command" },
{ TC_Message, "message" }, { TC_Message, "message" },
{ TC_View, "view" }, { TC_View, "view" },
...@@ -70,6 +75,8 @@ const std::string TOOL_EVENT::Format() const ...@@ -70,6 +75,8 @@ const std::string TOOL_EVENT::Format() const
{ TA_MouseDrag, "drag" }, { TA_MouseDrag, "drag" },
{ TA_MouseMotion, "motion" }, { TA_MouseMotion, "motion" },
{ TA_MouseWheel, "wheel" }, { TA_MouseWheel, "wheel" },
{ TA_KeyUp, "key-up" },
{ TA_KeyDown, "key-down" },
{ TA_ViewRefresh, "view-refresh" }, { TA_ViewRefresh, "view-refresh" },
{ TA_ViewZoom, "view-zoom" }, { TA_ViewZoom, "view-zoom" },
{ TA_ViewPan, "view-pan" }, { TA_ViewPan, "view-pan" },
...@@ -87,23 +94,40 @@ const std::string TOOL_EVENT::Format() const ...@@ -87,23 +94,40 @@ const std::string TOOL_EVENT::Format() const
{ MB_Left, "left" }, { MB_Left, "left" },
{ MB_Right, "right" }, { MB_Right, "right" },
{ MB_Middle, "middle" }, { MB_Middle, "middle" },
{ MB_ModShift, "shift" },
{ MB_ModCtrl, "ctrl" },
{ MB_ModAlt, "alt" },
{ 0, "" } { 0, "" }
}; };
const FlagString modifiers[] = {
{ MD_ModShift, "shift" },
{ MD_ModCtrl, "ctrl" },
{ MD_ModAlt, "alt" },
{ 0, "" }
};
ev = "category: "; ev = "category: ";
ev += flag2string( m_category, categories ); ev += flag2string( m_category, categories );
ev +=" action: "; ev += " action: ";
ev += flag2string( m_actions, actions ); ev += flag2string( m_actions, actions );
if( m_actions & TA_Mouse ) if( m_actions & TA_Mouse )
{ {
ev +=" btns: "; ev += " btns: ";
ev += flag2string( m_mouseButtons, buttons ); ev += flag2string( m_mouseButtons, buttons );
}; }
if( m_actions & TA_Keyboard )
{
char tmp[128];
sprintf( tmp, "key: %d", m_keyCode );
ev += tmp;
}
if( m_actions & ( TA_Mouse | TA_Keyboard ) )
{
ev += " mods: ";
ev += flag2string( m_modifiers, modifiers );
}
if( m_commandId ) if( m_commandId )
{ {
char tmp[128]; char tmp[128];
......
...@@ -53,11 +53,11 @@ WX_VIEW_CONTROLS::WX_VIEW_CONTROLS( VIEW* aView, wxWindow* aParentPanel ) : ...@@ -53,11 +53,11 @@ WX_VIEW_CONTROLS::WX_VIEW_CONTROLS( VIEW* aView, wxWindow* aParentPanel ) :
} }
void WX_VIEW_CONTROLS::onMotion( wxMouseEvent& event ) void WX_VIEW_CONTROLS::onMotion( wxMouseEvent& aEvent )
{ {
if( event.Dragging() && m_isDragPanning ) if( aEvent.Dragging() && m_isDragPanning )
{ {
VECTOR2D mousePoint( event.GetX(), event.GetY() ); VECTOR2D mousePoint( aEvent.GetX(), aEvent.GetY() );
VECTOR2D d = m_dragStartPoint - mousePoint; VECTOR2D d = m_dragStartPoint - mousePoint;
VECTOR2D delta = m_view->ToWorld( d, false ); VECTOR2D delta = m_view->ToWorld( d, false );
...@@ -65,19 +65,19 @@ void WX_VIEW_CONTROLS::onMotion( wxMouseEvent& event ) ...@@ -65,19 +65,19 @@ void WX_VIEW_CONTROLS::onMotion( wxMouseEvent& event )
m_parentPanel->Refresh(); m_parentPanel->Refresh();
} }
event.Skip(); aEvent.Skip();
} }
void WX_VIEW_CONTROLS::onWheel( wxMouseEvent& event ) void WX_VIEW_CONTROLS::onWheel( wxMouseEvent& aEvent )
{ {
const double wheelPanSpeed = 0.001; const double wheelPanSpeed = 0.001;
if( event.ControlDown() || event.ShiftDown() ) if( aEvent.ControlDown() || aEvent.ShiftDown() )
{ {
// Scrolling // Scrolling
VECTOR2D scrollVec = m_view->ToWorld( m_view->GetScreenPixelSize() * VECTOR2D scrollVec = m_view->ToWorld( m_view->GetScreenPixelSize() *
( (double) event.GetWheelRotation() * wheelPanSpeed ), false ); ( (double) aEvent.GetWheelRotation() * wheelPanSpeed ), false );
double scrollSpeed; double scrollSpeed;
if( abs( scrollVec.x ) > abs( scrollVec.y ) ) if( abs( scrollVec.x ) > abs( scrollVec.y ) )
...@@ -85,8 +85,8 @@ void WX_VIEW_CONTROLS::onWheel( wxMouseEvent& event ) ...@@ -85,8 +85,8 @@ void WX_VIEW_CONTROLS::onWheel( wxMouseEvent& event )
else else
scrollSpeed = scrollVec.y; scrollSpeed = scrollVec.y;
VECTOR2D delta( event.ControlDown() ? -scrollSpeed : 0.0, VECTOR2D delta( aEvent.ControlDown() ? -scrollSpeed : 0.0,
event.ShiftDown() ? -scrollSpeed : 0.0 ); aEvent.ShiftDown() ? -scrollSpeed : 0.0 );
m_view->SetCenter( m_view->GetCenter() + delta ); m_view->SetCenter( m_view->GetCenter() + delta );
m_parentPanel->Refresh(); m_parentPanel->Refresh();
...@@ -103,41 +103,41 @@ void WX_VIEW_CONTROLS::onWheel( wxMouseEvent& event ) ...@@ -103,41 +103,41 @@ void WX_VIEW_CONTROLS::onWheel( wxMouseEvent& event )
// Set scaling speed depending on scroll wheel event interval // Set scaling speed depending on scroll wheel event interval
if( timeDiff < 500 && timeDiff > 0 ) if( timeDiff < 500 && timeDiff > 0 )
{ {
zoomScale = ( event.GetWheelRotation() > 0.0 ) ? 2.05 - timeDiff / 500 : zoomScale = ( aEvent.GetWheelRotation() > 0.0 ) ? 2.05 - timeDiff / 500 :
1.0 / ( 2.05 - timeDiff / 500 ); 1.0 / ( 2.05 - timeDiff / 500 );
} }
else else
{ {
zoomScale = ( event.GetWheelRotation() > 0.0 ) ? 1.05 : 0.95; zoomScale = ( aEvent.GetWheelRotation() > 0.0 ) ? 1.05 : 0.95;
} }
VECTOR2D anchor = m_view->ToWorld( VECTOR2D( event.GetX(), event.GetY() ) ); VECTOR2D anchor = m_view->ToWorld( VECTOR2D( aEvent.GetX(), aEvent.GetY() ) );
m_view->SetScale( m_view->GetScale() * zoomScale, anchor ); m_view->SetScale( m_view->GetScale() * zoomScale, anchor );
m_parentPanel->Refresh(); m_parentPanel->Refresh();
} }
event.Skip(); aEvent.Skip();
} }
void WX_VIEW_CONTROLS::onButton( wxMouseEvent& event ) void WX_VIEW_CONTROLS::onButton( wxMouseEvent& aEvent )
{ {
if( event.MiddleDown() ) if( aEvent.MiddleDown() )
{ {
m_isDragPanning = true; m_isDragPanning = true;
m_dragStartPoint = VECTOR2D( event.GetX(), event.GetY() ); m_dragStartPoint = VECTOR2D( aEvent.GetX(), aEvent.GetY() );
m_lookStartPoint = m_view->GetCenter(); m_lookStartPoint = m_view->GetCenter();
} }
else if( event.MiddleUp() ) else if( aEvent.MiddleUp() )
{ {
m_isDragPanning = false; m_isDragPanning = false;
} }
event.Skip(); aEvent.Skip();
} }
void WX_VIEW_CONTROLS::onEnter( wxMouseEvent& event ) void WX_VIEW_CONTROLS::onEnter( wxMouseEvent& aEvent )
{ {
m_parentPanel->SetFocus(); m_parentPanel->SetFocus();
} }
...@@ -115,6 +115,7 @@ protected: ...@@ -115,6 +115,7 @@ protected:
void onPaint( wxPaintEvent& WXUNUSED( aEvent ) ); void onPaint( wxPaintEvent& WXUNUSED( aEvent ) );
void onSize( wxSizeEvent& aEvent ); void onSize( wxSizeEvent& aEvent );
void onEvent( wxEvent& aEvent ); void onEvent( wxEvent& aEvent );
void skipEvent( wxEvent& aEvent );
KiGfx::GAL* m_gal; ///< Interface for drawing objects on a 2D-surface KiGfx::GAL* m_gal; ///< Interface for drawing objects on a 2D-surface
KiGfx::VIEW* m_view; ///< Stores view settings (scale, center, etc.) KiGfx::VIEW* m_view; ///< Stores view settings (scale, center, etc.)
......
...@@ -285,7 +285,7 @@ private: ...@@ -285,7 +285,7 @@ private:
wxPoint savedCursorPosition; ///< The last cursor position wxPoint savedCursorPosition; ///< The last cursor position
wxBitmap* cursorPixels; ///< Cursor pixels wxBitmap* cursorPixels; ///< Cursor pixels
wxBitmap* cursorPixelsSaved; ///< Saved cursor pixels wxBitmap* cursorPixelsSaved; ///< Saved cursor pixels
int cursorSize; ///< Cursor size int cursorSize; ///< Cursor size
/// Maximum number of arguments for one command /// Maximum number of arguments for one command
static const int MAX_CAIRO_ARGUMENTS = 6; static const int MAX_CAIRO_ARGUMENTS = 6;
......
...@@ -30,6 +30,7 @@ ...@@ -30,6 +30,7 @@
#include <tool/tool_event.h> #include <tool/tool_event.h>
#include <wx/event.h> #include <wx/event.h>
#include <wx/kbdstate.h>
class TOOL_MANAGER; class TOOL_MANAGER;
class PCB_BASE_FRAME; class PCB_BASE_FRAME;
...@@ -69,21 +70,18 @@ private: ...@@ -69,21 +70,18 @@ private:
static const int DragTimeThreshold = 300; static const int DragTimeThreshold = 300;
static const int DragDistanceThreshold = 8; static const int DragDistanceThreshold = 8;
bool handleMouseButton ( wxEvent& aEvent, int aIndex, bool aMotion ); bool handleMouseButton( wxEvent& aEvent, int aIndex, bool aMotion );
bool handleKeys ( wxEvent& aEvent ); bool handlePopupMenu( wxEvent& aEvent );
bool handlePopupMenu ( wxEvent& aEvent );
int decodeModifiers( wxEvent& aEvent ); int decodeModifiers( const wxKeyboardState* aState ) const;
KiGfx::VIEW* getView();
struct ButtonState; struct ButtonState;
TOOL_MANAGER* m_toolMgr;
PCB_BASE_FRAME* m_editFrame;
VECTOR2D m_lastMousePos; VECTOR2D m_lastMousePos;
std::vector<ButtonState*> m_buttons; std::vector<ButtonState*> m_buttons;
KiGfx::VIEW* getView();
TOOL_MANAGER* m_toolMgr;
PCB_BASE_FRAME* m_editFrame;
}; };
#endif #endif
...@@ -40,32 +40,39 @@ class TOOL_MANAGER; ...@@ -40,32 +40,39 @@ class TOOL_MANAGER;
*/ */
enum TOOL_EventCategory enum TOOL_EventCategory
{ {
TC_None = 0x0, TC_None = 0x00,
TC_Mouse = 0x1, TC_Mouse = 0x01,
TC_Command = 0x2, TC_Keyboard = 0x02,
TC_Message = 0x4, TC_Command = 0x04,
TC_View = 0x8, TC_Message = 0x08,
TC_Any = 0xffffffff TC_View = 0x10,
TC_Any = 0xffffffff
}; };
enum TOOL_Actions enum TOOL_Actions
{ {
TA_None = 0x0, // UI input events
TA_MouseClick = 0x1, TA_None = 0x0000,
TA_MouseUp = 0x2, TA_MouseClick = 0x0001,
TA_MouseDown = 0x4, TA_MouseUp = 0x0002,
TA_MouseDrag = 0x8, TA_MouseDown = 0x0004,
TA_MouseMotion = 0x10, TA_MouseDrag = 0x0008,
TA_MouseWheel = 0x20, TA_MouseMotion = 0x0010,
TA_Mouse = 0x3f, TA_MouseWheel = 0x0020,
TA_ViewRefresh = 0x40, TA_Mouse = 0x003f,
TA_ViewZoom = 0x80, TA_KeyUp = 0x0040,
TA_ViewPan = 0x100, TA_KeyDown = 0x0080,
TA_ViewDirty = 0x200, TA_Keyboard = TA_KeyUp | TA_KeyDown,
TA_ChangeLayer = 0x1000,
// View related events
TA_ViewRefresh = 0x0100,
TA_ViewZoom = 0x0200,
TA_ViewPan = 0x0400,
TA_ViewDirty = 0x0800,
TA_ChangeLayer = 0x1000,
// Tool cancel event. Issued automagically when the user hits escape or selects End Tool from the context menu. // Tool cancel event. Issued automagically when the user hits escape or selects End Tool from the context menu.
TA_CancelTool = 0x2000, TA_CancelTool = 0x2000,
// Tool activation event. Issued by the GUI upon pressing a button/menu selection. // Tool activation event. Issued by the GUI upon pressing a button/menu selection.
TA_ActivateTool = 0x4000, TA_ActivateTool = 0x4000,
...@@ -81,25 +88,28 @@ enum TOOL_Actions ...@@ -81,25 +88,28 @@ enum TOOL_Actions
enum TOOL_MouseButtons enum TOOL_MouseButtons
{ {
MB_None = 0x0, MB_None = 0x0,
MB_Left = 0x1, MB_Left = 0x1,
MB_Right = 0x2, MB_Right = 0x2,
MB_Middle = 0x4, MB_Middle = 0x4,
MB_ButtonMask = MB_Left | MB_Right | MB_Middle, MB_ButtonMask = MB_Left | MB_Right | MB_Middle,
MB_ModShift = 0x8, MB_Any = 0xffffffff
MB_ModCtrl = 0x10,
MB_ModAlt = 0x20,
MB_ModifierMask = MB_ModShift | MB_ModCtrl | MB_ModAlt,
MB_Any = 0xffffffff
}; };
enum TOOL_Modifiers
{
MD_ModShift = 0x1000,
MD_ModCtrl = 0x2000,
MD_ModAlt = 0x4000,
MD_ModifierMask = MD_ModShift | MD_ModCtrl | MD_ModAlt,
};
// Defines when a context menu is opened. // Defines when a context menu is opened.
enum TOOL_ContextMenuTrigger enum TOOL_ContextMenuTrigger
{ {
CMENU_BUTTON = 0, // On the right button CMENU_BUTTON = 0, // On the right button
CMENU_NOW, // Right now (after TOOL_INTERACTIVE::SetContextMenu) CMENU_NOW, // Right now (after TOOL_INTERACTIVE::SetContextMenu)
CMENU_OFF // Never CMENU_OFF // Never
}; };
/** /**
...@@ -112,22 +122,38 @@ class TOOL_EVENT ...@@ -112,22 +122,38 @@ class TOOL_EVENT
public: public:
const std::string Format() const; const std::string Format() const;
TOOL_EVENT( TOOL_EventCategory aCategory = TC_None, TOOL_Actions aAction = TA_None ): TOOL_EVENT( TOOL_EventCategory aCategory = TC_None, TOOL_Actions aAction = TA_None ) :
m_category( aCategory ), m_category( aCategory ),
m_actions( aAction ), m_actions( aAction ),
m_mouseButtons( 0 ) {} m_mouseButtons( 0 ),
m_keyCode( 0 ),
m_modifiers( 0 ) {}
TOOL_EVENT( TOOL_EventCategory aCategory, TOOL_Actions aAction, int aExtraParam ): TOOL_EVENT( TOOL_EventCategory aCategory, TOOL_Actions aAction, int aExtraParam ) :
m_category( aCategory ), m_category( aCategory ),
m_actions( aAction ) m_actions( aAction )
{ {
if( aCategory == TC_Mouse ) if( aCategory == TC_Mouse )
m_mouseButtons = aExtraParam; {
m_mouseButtons = aExtraParam & MB_ButtonMask;
}
else if( aCategory == TC_Keyboard )
{
m_keyCode = aExtraParam & ~MD_ModifierMask; // Filter out modifiers
}
else if ( aCategory == TC_Command ) else if ( aCategory == TC_Command )
{
m_commandId = aExtraParam; m_commandId = aExtraParam;
}
if( aCategory & ( TC_Mouse | TC_Keyboard ) )
{
m_modifiers = aExtraParam & MD_ModifierMask;
}
} }
TOOL_EVENT( TOOL_EventCategory aCategory, TOOL_Actions aAction, const std::string& aExtraParam ): TOOL_EVENT( TOOL_EventCategory aCategory, TOOL_Actions aAction,
const std::string& aExtraParam ) :
m_category( aCategory ), m_category( aCategory ),
m_actions( aAction ), m_actions( aAction ),
m_mouseButtons( 0 ) m_mouseButtons( 0 )
...@@ -193,9 +219,14 @@ public: ...@@ -193,9 +219,14 @@ public:
return m_actions == TA_CancelTool; return m_actions == TA_CancelTool;
} }
bool Modifier( int aMask = MB_ModifierMask ) const bool Modifier( int aMask = MD_ModifierMask ) const
{
return ( m_modifiers & aMask );
}
int KeyCode() const
{ {
return ( m_mouseButtons & aMask ); return m_keyCode;
} }
void Ignore(); void Ignore();
...@@ -250,6 +281,8 @@ private: ...@@ -250,6 +281,8 @@ private:
VECTOR2D m_mouseDragOrigin; VECTOR2D m_mouseDragOrigin;
int m_mouseButtons; int m_mouseButtons;
int m_keyCode;
int m_modifiers;
boost::optional<int> m_commandId; boost::optional<int> m_commandId;
boost::optional<std::string> m_commandStr; boost::optional<std::string> m_commandStr;
}; };
...@@ -299,12 +332,12 @@ public: ...@@ -299,12 +332,12 @@ public:
return m_events.end(); return m_events.end();
} }
const_iterator cbegin() const const_iterator cbegin() const
{ {
return m_events.begin(); return m_events.begin();
} }
const_iterator cend() const const_iterator cend() const
{ {
return m_events.end(); return m_events.end();
} }
...@@ -354,7 +387,7 @@ private: ...@@ -354,7 +387,7 @@ private:
std::deque<TOOL_EVENT> m_events; std::deque<TOOL_EVENT> m_events;
}; };
inline const TOOL_EVENT_LIST operator||( const TOOL_EVENT& a, const TOOL_EVENT &b ) inline const TOOL_EVENT_LIST operator||( const TOOL_EVENT& a, const TOOL_EVENT& b )
{ {
TOOL_EVENT_LIST l; TOOL_EVENT_LIST l;
...@@ -364,7 +397,7 @@ inline const TOOL_EVENT_LIST operator||( const TOOL_EVENT& a, const TOOL_EVENT & ...@@ -364,7 +397,7 @@ inline const TOOL_EVENT_LIST operator||( const TOOL_EVENT& a, const TOOL_EVENT &
return l; return l;
} }
inline const TOOL_EVENT_LIST operator||( const TOOL_EVENT & a, const TOOL_EVENT_LIST &b ) inline const TOOL_EVENT_LIST operator||( const TOOL_EVENT& a, const TOOL_EVENT_LIST& b )
{ {
TOOL_EVENT_LIST l( b ); TOOL_EVENT_LIST l( b );
......
...@@ -52,10 +52,10 @@ public: ...@@ -52,10 +52,10 @@ public:
WX_VIEW_CONTROLS( VIEW* aView, wxWindow* aParentPanel ); WX_VIEW_CONTROLS( VIEW* aView, wxWindow* aParentPanel );
~WX_VIEW_CONTROLS() {}; ~WX_VIEW_CONTROLS() {};
void onWheel( wxMouseEvent& event ); void onWheel( wxMouseEvent& aEvent );
void onMotion( wxMouseEvent& event ); void onMotion( wxMouseEvent& aEvent );
void onButton( wxMouseEvent& event ); void onButton( wxMouseEvent& aEvent );
void onEnter( wxMouseEvent& event ); void onEnter( wxMouseEvent& aEvent );
void SetEventDispatcher( TOOL_DISPATCHER *aEventDispatcher ); void SetEventDispatcher( TOOL_DISPATCHER *aEventDispatcher );
......
...@@ -69,7 +69,7 @@ int SELECTION_TOOL::Main( TOOL_EVENT& aEvent ) ...@@ -69,7 +69,7 @@ int SELECTION_TOOL::Main( TOOL_EVENT& aEvent )
// Main loop: keep receiving events // Main loop: keep receiving events
while( OPT_TOOL_EVENT evt = Wait() ) while( OPT_TOOL_EVENT evt = Wait() )
{ {
m_additive = evt->Modifier( MB_ModShift ); m_additive = evt->Modifier( MD_ModShift );
if( evt->IsCancel() ) if( evt->IsCancel() )
return 0; return 0;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment