mirror of
https://gitlab.com/kicad/code/kicad.git
synced 2025-04-20 00:21:31 +00:00
Bind multiply-modified scroll events to the increment action
Implemented as handling un-consumed scroll events that the WX_VIEW_CONTROLS doesn't want because it has too many mods set. Then dispatch these as TA_MOUSE_WHEEL events. The default action from the selection tools is to run the 'increment' ACTION, which is implemented differently in the various tools: eeschema can increment labels, symedit does pin names and numbers, and fpedit does pad numbers.
This commit is contained in:
parent
3f602f8177
commit
9c9542deea
common
eeschema/tools
pcbnew/tools
@ -497,6 +497,14 @@ void TOOL_DISPATCHER::DispatchWxEvent( wxEvent& aEvent )
|
||||
evt->SetMousePosition( pos );
|
||||
}
|
||||
}
|
||||
|
||||
// We only get wheel events that aren't consumed by the view controls
|
||||
// (probably, mods has 2 or more bits set)
|
||||
if( !evt && me->GetWheelRotation() != 0 )
|
||||
{
|
||||
evt = TOOL_EVENT( TC_MOUSE, TA_MOUSE_WHEEL, mods );
|
||||
evt->SetParameter<int>( me->GetWheelRotation() );
|
||||
}
|
||||
}
|
||||
else if( type == wxEVT_CHAR_HOOK || type == wxEVT_CHAR )
|
||||
{
|
||||
|
@ -377,66 +377,90 @@ void WX_VIEW_CONTROLS::onWheel( wxMouseEvent& aEvent )
|
||||
return;
|
||||
|
||||
// Pick the modifier, if any. Shift beats control beats alt, we don't support more than one.
|
||||
int modifiers =
|
||||
aEvent.ShiftDown() ? WXK_SHIFT :
|
||||
( aEvent.ControlDown() ? WXK_CONTROL : ( aEvent.AltDown() ? WXK_ALT : 0 ) );
|
||||
|
||||
// Restrict zoom handling to the vertical axis, otherwise horizontal
|
||||
// scrolling events (e.g. touchpads and some mice) end up interpreted
|
||||
// as vertical scroll events and confuse the user.
|
||||
if( modifiers == m_settings.m_scrollModifierZoom && axis == wxMOUSE_WHEEL_VERTICAL )
|
||||
int nMods = 0;
|
||||
int modifiers = 0;
|
||||
if( aEvent.ShiftDown() )
|
||||
{
|
||||
const int rotation = aEvent.GetWheelRotation() * ( m_settings.m_scrollReverseZoom ? -1 : 1 );
|
||||
const double zoomScale = m_zoomController->GetScaleForRotation( rotation );
|
||||
nMods += 1;
|
||||
modifiers = WXK_SHIFT;
|
||||
}
|
||||
if( aEvent.ControlDown() )
|
||||
{
|
||||
nMods += 1;
|
||||
modifiers = modifiers == 0 ? WXK_CONTROL : modifiers;
|
||||
}
|
||||
if( aEvent.AltDown() )
|
||||
{
|
||||
nMods += 1;
|
||||
modifiers = modifiers == 0 ? WXK_ALT : modifiers;
|
||||
}
|
||||
|
||||
if( IsCursorWarpingEnabled() )
|
||||
// Zero or one modifier is view control
|
||||
if( nMods <= 1 )
|
||||
{
|
||||
// Restrict zoom handling to the vertical axis, otherwise horizontal
|
||||
// scrolling events (e.g. touchpads and some mice) end up interpreted
|
||||
// as vertical scroll events and confuse the user.
|
||||
if( modifiers == m_settings.m_scrollModifierZoom && axis == wxMOUSE_WHEEL_VERTICAL )
|
||||
{
|
||||
CenterOnCursor();
|
||||
m_view->SetScale( m_view->GetScale() * zoomScale );
|
||||
const int rotation =
|
||||
aEvent.GetWheelRotation() * ( m_settings.m_scrollReverseZoom ? -1 : 1 );
|
||||
const double zoomScale = m_zoomController->GetScaleForRotation( rotation );
|
||||
|
||||
if( IsCursorWarpingEnabled() )
|
||||
{
|
||||
CenterOnCursor();
|
||||
m_view->SetScale( m_view->GetScale() * zoomScale );
|
||||
}
|
||||
else
|
||||
{
|
||||
const VECTOR2D anchor = m_view->ToWorld( VECTOR2D( aEvent.GetX(), aEvent.GetY() ) );
|
||||
m_view->SetScale( m_view->GetScale() * zoomScale, anchor );
|
||||
}
|
||||
|
||||
// Refresh the zoom level and mouse position on message panel
|
||||
// (mouse position has not changed, only the zoom level has changed):
|
||||
refreshMouse( true );
|
||||
}
|
||||
else
|
||||
{
|
||||
const VECTOR2D anchor = m_view->ToWorld( VECTOR2D( aEvent.GetX(), aEvent.GetY() ) );
|
||||
m_view->SetScale( m_view->GetScale() * zoomScale, anchor );
|
||||
// Scrolling
|
||||
VECTOR2D scrollVec = m_view->ToWorld( m_view->GetScreenPixelSize(), false )
|
||||
* ( (double) aEvent.GetWheelRotation() * wheelPanSpeed );
|
||||
double scrollX = 0.0;
|
||||
double scrollY = 0.0;
|
||||
bool hReverse = false;
|
||||
|
||||
if( axis != wxMOUSE_WHEEL_HORIZONTAL )
|
||||
hReverse = m_settings.m_scrollReversePanH;
|
||||
|
||||
if( axis == wxMOUSE_WHEEL_HORIZONTAL || modifiers == m_settings.m_scrollModifierPanH )
|
||||
{
|
||||
if( hReverse )
|
||||
scrollX = scrollVec.x;
|
||||
else
|
||||
scrollX = ( axis == wxMOUSE_WHEEL_HORIZONTAL ) ? scrollVec.x : -scrollVec.x;
|
||||
}
|
||||
else
|
||||
{
|
||||
scrollY = -scrollVec.y;
|
||||
}
|
||||
|
||||
VECTOR2D delta( scrollX, scrollY );
|
||||
|
||||
m_view->SetCenter( m_view->GetCenter() + delta );
|
||||
refreshMouse( true );
|
||||
}
|
||||
|
||||
// Refresh the zoom level and mouse position on message panel
|
||||
// (mouse position has not changed, only the zoom level has changed):
|
||||
refreshMouse( true );
|
||||
// Do not skip this event, otherwise wxWidgets will fire
|
||||
// 3 wxEVT_SCROLLWIN_LINEUP or wxEVT_SCROLLWIN_LINEDOWN (normal wxWidgets behavior)
|
||||
// and we do not want that.
|
||||
}
|
||||
else
|
||||
{
|
||||
// Scrolling
|
||||
VECTOR2D scrollVec = m_view->ToWorld( m_view->GetScreenPixelSize(), false ) *
|
||||
( (double) aEvent.GetWheelRotation() * wheelPanSpeed );
|
||||
double scrollX = 0.0;
|
||||
double scrollY = 0.0;
|
||||
bool hReverse = false;
|
||||
|
||||
if( axis != wxMOUSE_WHEEL_HORIZONTAL )
|
||||
hReverse = m_settings.m_scrollReversePanH;
|
||||
|
||||
if( axis == wxMOUSE_WHEEL_HORIZONTAL || modifiers == m_settings.m_scrollModifierPanH )
|
||||
{
|
||||
if( hReverse )
|
||||
scrollX = scrollVec.x;
|
||||
else
|
||||
scrollX = ( axis == wxMOUSE_WHEEL_HORIZONTAL ) ? scrollVec.x : -scrollVec.x;
|
||||
}
|
||||
else
|
||||
{
|
||||
scrollY = -scrollVec.y;
|
||||
}
|
||||
|
||||
VECTOR2D delta( scrollX, scrollY );
|
||||
|
||||
m_view->SetCenter( m_view->GetCenter() + delta );
|
||||
refreshMouse( true );
|
||||
// When we have muliple mods, forward it for tool handling
|
||||
aEvent.Skip();
|
||||
}
|
||||
|
||||
// Do not skip this event, otherwise wxWidgets will fire
|
||||
// 3 wxEVT_SCROLLWIN_LINEUP or wxEVT_SCROLLWIN_LINEDOWN (normal wxWidgets behavior)
|
||||
// and we do not want that.
|
||||
}
|
||||
|
||||
|
||||
|
@ -665,6 +665,27 @@ int EE_SELECTION_TOOL::Main( const TOOL_EVENT& aEvent )
|
||||
{
|
||||
m_toolMgr->RunAction( EE_ACTIONS::navigateForward );
|
||||
}
|
||||
else if( evt->Action() == TA_MOUSE_WHEEL )
|
||||
{
|
||||
int field = -1;
|
||||
|
||||
if( evt->Modifier() == ( MD_SHIFT | MD_ALT ) )
|
||||
field = 0;
|
||||
else if( evt->Modifier() == ( MD_CTRL | MD_ALT ) )
|
||||
field = 1;
|
||||
// any more?
|
||||
|
||||
if( field >= 0 )
|
||||
{
|
||||
const int delta = evt->Parameter<int>();
|
||||
ACTIONS::INCREMENT incParams{
|
||||
delta > 0 ? 1 : -1,
|
||||
field,
|
||||
};
|
||||
|
||||
m_toolMgr->RunAction( ACTIONS::increment, incParams );
|
||||
}
|
||||
}
|
||||
else if( evt->Category() == TC_COMMAND && evt->Action() == TA_CHOICE_MENU_CHOICE )
|
||||
{
|
||||
m_disambiguateTimer.Stop();
|
||||
|
@ -2990,6 +2990,10 @@ int EDIT_TOOL::Increment( const TOOL_EVENT& aEvent )
|
||||
{
|
||||
case PCB_PAD_T:
|
||||
{
|
||||
// Only increment pad numbers in the footprint editor
|
||||
if( !m_isFootprintEditor )
|
||||
break;
|
||||
|
||||
PAD& pad = static_cast<PAD&>( *item );
|
||||
|
||||
if( !pad.CanHaveNumber() )
|
||||
|
@ -396,6 +396,27 @@ int PCB_SELECTION_TOOL::Main( const TOOL_EVENT& aEvent )
|
||||
else
|
||||
m_toolMgr->RunAction( ACTIONS::zoomFitScreen );
|
||||
}
|
||||
else if( evt->Action() == TA_MOUSE_WHEEL )
|
||||
{
|
||||
int field = -1;
|
||||
|
||||
if( evt->Modifier() == ( MD_SHIFT | MD_ALT ) )
|
||||
field = 0;
|
||||
else if( evt->Modifier() == ( MD_CTRL | MD_ALT ) )
|
||||
field = 1;
|
||||
// any more?
|
||||
|
||||
if( field >= 0 )
|
||||
{
|
||||
const int delta = evt->Parameter<int>();
|
||||
ACTIONS::INCREMENT incParams{
|
||||
delta > 0 ? 1 : -1,
|
||||
field,
|
||||
};
|
||||
|
||||
m_toolMgr->RunAction( ACTIONS::increment, incParams );
|
||||
}
|
||||
}
|
||||
else if( evt->IsDrag( BUT_LEFT ) )
|
||||
{
|
||||
m_disambiguateTimer.Stop();
|
||||
|
Loading…
Reference in New Issue
Block a user