From 50889a9ed6dbc1e0ac1dd5b307c90f3826966394 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Mon, 11 Jan 2021 15:46:41 +0000 Subject: [PATCH] Promote mouse drag settings to full enums. --- common/dialogs/panel_mouse_settings.cpp | 62 +++++++++---------- common/settings/common_settings.cpp | 51 +++++++-------- common/tool/tools_holder.cpp | 4 +- common/view/wx_view_controls.cpp | 6 +- eeschema/tools/ee_selection_tool.cpp | 10 +-- include/settings/common_settings.h | 18 +++++- include/tool/tools_holder.h | 4 +- include/view/view_controls.h | 21 +------ pagelayout_editor/tools/pl_selection_tool.cpp | 2 +- pcbnew/tools/pcb_selection_tool.cpp | 10 +-- 10 files changed, 86 insertions(+), 102 deletions(-) diff --git a/common/dialogs/panel_mouse_settings.cpp b/common/dialogs/panel_mouse_settings.cpp index 400207fd71..d14e5e1d36 100644 --- a/common/dialogs/panel_mouse_settings.cpp +++ b/common/dialogs/panel_mouse_settings.cpp @@ -22,11 +22,8 @@ #include #include #include -#include #include -using KIGFX::MOUSE_DRAG_ACTION; - PANEL_MOUSE_SETTINGS::PANEL_MOUSE_SETTINGS( DIALOG_SHIM* aDialog, wxWindow* aParent ) : PANEL_MOUSE_SETTINGS_BASE( aParent ), @@ -83,26 +80,26 @@ bool PANEL_MOUSE_SETTINGS::TransferDataFromWindow() switch( m_choiceLeftButtonDrag->GetSelection() ) { - case 0: cfg->m_Input.drag_left = static_cast( MOUSE_DRAG_ACTION::SELECT ); break; - case 1: cfg->m_Input.drag_left = static_cast( MOUSE_DRAG_ACTION::DRAG_SELECTED ); break; - case 2: cfg->m_Input.drag_left = static_cast( MOUSE_DRAG_ACTION::DRAG_ANY ); break; - default: break; + case 0: cfg->m_Input.drag_left = MOUSE_DRAG_ACTION::SELECT; break; + case 1: cfg->m_Input.drag_left = MOUSE_DRAG_ACTION::DRAG_SELECTED; break; + case 2: cfg->m_Input.drag_left = MOUSE_DRAG_ACTION::DRAG_ANY; break; + default: break; } switch( m_choiceMiddleButtonDrag->GetSelection() ) { - case 0: cfg->m_Input.drag_middle = static_cast( MOUSE_DRAG_ACTION::PAN ); break; - case 1: cfg->m_Input.drag_middle = static_cast( MOUSE_DRAG_ACTION::ZOOM ); break; - case 2: cfg->m_Input.drag_middle = static_cast( MOUSE_DRAG_ACTION::NONE ); break; - default: break; + case 0: cfg->m_Input.drag_middle = MOUSE_DRAG_ACTION::PAN; break; + case 1: cfg->m_Input.drag_middle = MOUSE_DRAG_ACTION::ZOOM; break; + case 2: cfg->m_Input.drag_middle = MOUSE_DRAG_ACTION::NONE; break; + default: break; } switch( m_choiceRightButtonDrag->GetSelection() ) { - case 0: cfg->m_Input.drag_right = static_cast( MOUSE_DRAG_ACTION::PAN ); break; - case 1: cfg->m_Input.drag_right = static_cast( MOUSE_DRAG_ACTION::ZOOM ); break; - case 2: cfg->m_Input.drag_right = static_cast( MOUSE_DRAG_ACTION::NONE ); break; - default: break; + case 0: cfg->m_Input.drag_right = MOUSE_DRAG_ACTION::PAN; break; + case 1: cfg->m_Input.drag_right = MOUSE_DRAG_ACTION::ZOOM; break; + case 2: cfg->m_Input.drag_right = MOUSE_DRAG_ACTION::NONE; break; + default: break; } cfg->m_Input.center_on_zoom = m_checkZoomCenter->GetValue(); @@ -143,7 +140,7 @@ void PANEL_MOUSE_SETTINGS::applySettingsToPanel( const COMMON_SETTINGS& aSetting m_zoomSpeed->Enable( !aSettings.m_Input.zoom_speed_auto ); - switch( static_cast( aSettings.m_Input.drag_left ) ) + switch( aSettings.m_Input.drag_left ) { case MOUSE_DRAG_ACTION::SELECT: m_choiceLeftButtonDrag->SetSelection( 0 ); break; case MOUSE_DRAG_ACTION::DRAG_SELECTED: m_choiceLeftButtonDrag->SetSelection( 1 ); break; @@ -151,24 +148,23 @@ void PANEL_MOUSE_SETTINGS::applySettingsToPanel( const COMMON_SETTINGS& aSetting default: break; } - auto set_mouse_buttons = - []( const MOUSE_DRAG_ACTION& aVal, wxChoice* aChoice ) - { - switch( aVal ) - { - case MOUSE_DRAG_ACTION::PAN: aChoice->SetSelection( 0 ); break; - case MOUSE_DRAG_ACTION::ZOOM: aChoice->SetSelection( 1 ); break; - case MOUSE_DRAG_ACTION::NONE: aChoice->SetSelection( 2 ); break; - case MOUSE_DRAG_ACTION::SELECT: break; - default: break; - } - }; + switch( aSettings.m_Input.drag_middle ) + { + case MOUSE_DRAG_ACTION::PAN: m_choiceMiddleButtonDrag->SetSelection( 0 ); break; + case MOUSE_DRAG_ACTION::ZOOM: m_choiceMiddleButtonDrag->SetSelection( 1 ); break; + case MOUSE_DRAG_ACTION::NONE: m_choiceMiddleButtonDrag->SetSelection( 2 ); break; + case MOUSE_DRAG_ACTION::SELECT: break; + default: break; + } - set_mouse_buttons( static_cast( aSettings.m_Input.drag_middle ), - m_choiceMiddleButtonDrag ); - - set_mouse_buttons( static_cast( aSettings.m_Input.drag_right ), - m_choiceRightButtonDrag ); + switch( aSettings.m_Input.drag_right ) + { + case MOUSE_DRAG_ACTION::PAN: m_choiceRightButtonDrag->SetSelection( 0 ); break; + case MOUSE_DRAG_ACTION::ZOOM: m_choiceRightButtonDrag->SetSelection( 1 ); break; + case MOUSE_DRAG_ACTION::NONE: m_choiceRightButtonDrag->SetSelection( 2 ); break; + case MOUSE_DRAG_ACTION::SELECT: break; + default: break; + } m_currentScrollMod.zoom = aSettings.m_Input.scroll_modifier_zoom; m_currentScrollMod.panh = aSettings.m_Input.scroll_modifier_pan_h; diff --git a/common/settings/common_settings.cpp b/common/settings/common_settings.cpp index ec7163253e..c67f1e6ba6 100644 --- a/common/settings/common_settings.cpp +++ b/common/settings/common_settings.cpp @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2020 Jon Evans - * Copyright (C) 2020 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2020-2021 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the @@ -21,13 +21,9 @@ #include #include #include -#include -#include #include #include -using KIGFX::MOUSE_DRAG_ACTION; - ///! The following environment variables will never be migrated from a previous version const std::set envVarBlacklist = @@ -127,41 +123,38 @@ COMMON_SETTINGS::COMMON_SETTINGS() : int default_zoom_speed = 1; #endif - m_params.emplace_back( - new PARAM( "input.zoom_speed", &m_Input.zoom_speed, default_zoom_speed ) ); + m_params.emplace_back( new PARAM( "input.zoom_speed", + &m_Input.zoom_speed, default_zoom_speed ) ); - m_params.emplace_back( - new PARAM( "input.zoom_speed_auto", &m_Input.zoom_speed_auto, true ) ); + m_params.emplace_back( new PARAM( "input.zoom_speed_auto", + &m_Input.zoom_speed_auto, true ) ); - m_params.emplace_back( - new PARAM( "input.scroll_modifier_zoom", &m_Input.scroll_modifier_zoom, 0 ) ); + m_params.emplace_back( new PARAM( "input.scroll_modifier_zoom", + &m_Input.scroll_modifier_zoom, 0 ) ); - m_params.emplace_back( new PARAM( - "input.scroll_modifier_pan_h", &m_Input.scroll_modifier_pan_h, WXK_CONTROL ) ); + m_params.emplace_back( new PARAM( "input.scroll_modifier_pan_h", + &m_Input.scroll_modifier_pan_h, WXK_CONTROL ) ); - m_params.emplace_back( new PARAM( - "input.scroll_modifier_pan_v", &m_Input.scroll_modifier_pan_v, WXK_SHIFT ) ); + m_params.emplace_back( new PARAM( "input.scroll_modifier_pan_v", + &m_Input.scroll_modifier_pan_v, WXK_SHIFT ) ); - m_params.emplace_back( new PARAM( "input.mouse_left", &m_Input.drag_left, - static_cast( MOUSE_DRAG_ACTION::DRAG_SELECTED ), - static_cast( MOUSE_DRAG_ACTION::DRAG_ANY ), - static_cast( MOUSE_DRAG_ACTION::SELECT ) ) ); + m_params.emplace_back( new PARAM_ENUM( "input.mouse_left", + &m_Input.drag_left, MOUSE_DRAG_ACTION::DRAG_SELECTED, MOUSE_DRAG_ACTION::DRAG_ANY, + MOUSE_DRAG_ACTION::SELECT ) ); - m_params.emplace_back( new PARAM( "input.mouse_middle", &m_Input.drag_middle, - static_cast( MOUSE_DRAG_ACTION::PAN ), - static_cast( MOUSE_DRAG_ACTION::SELECT ), - static_cast( MOUSE_DRAG_ACTION::NONE ) ) ); + m_params.emplace_back( new PARAM_ENUM( "input.mouse_middle", + &m_Input.drag_middle, MOUSE_DRAG_ACTION::PAN, MOUSE_DRAG_ACTION::SELECT, + MOUSE_DRAG_ACTION::NONE ) ); - m_params.emplace_back( new PARAM( "input.mouse_right", &m_Input.drag_right, - static_cast( MOUSE_DRAG_ACTION::PAN ), - static_cast( MOUSE_DRAG_ACTION::SELECT ), - static_cast( MOUSE_DRAG_ACTION::NONE ) ) ); + m_params.emplace_back( new PARAM_ENUM( "input.mouse_right", + &m_Input.drag_right, MOUSE_DRAG_ACTION::PAN, MOUSE_DRAG_ACTION::SELECT, + MOUSE_DRAG_ACTION::NONE ) ); m_params.emplace_back( new PARAM( "graphics.opengl_antialiasing_mode", - &m_Graphics.opengl_aa_mode, 0, 0, 4 ) ); + &m_Graphics.opengl_aa_mode, 0, 0, 4 ) ); m_params.emplace_back( new PARAM( "graphics.cairo_antialiasing_mode", - &m_Graphics.cairo_aa_mode, 0, 0, 3 ) ); + &m_Graphics.cairo_aa_mode, 0, 0, 3 ) ); m_params.emplace_back( new PARAM( "system.autosave_interval", &m_System.autosave_interval, 600 ) ); diff --git a/common/tool/tools_holder.cpp b/common/tool/tools_holder.cpp index 414dca36c2..d37aaaa7a9 100644 --- a/common/tool/tools_holder.cpp +++ b/common/tool/tools_holder.cpp @@ -35,7 +35,7 @@ TOOLS_HOLDER::TOOLS_HOLDER() : m_actions( nullptr ), m_toolDispatcher( nullptr ), m_immediateActions( true ), - m_dragAction( KIGFX::MOUSE_DRAG_ACTION::SELECT ), + m_dragAction( MOUSE_DRAG_ACTION::SELECT ), m_moveWarpsCursor( true ) { } @@ -122,7 +122,7 @@ void TOOLS_HOLDER::CommonSettingsChanged( bool aEnvVarsChanged, bool aTextVarsCh COMMON_SETTINGS* settings = Pgm().GetCommonSettings(); m_moveWarpsCursor = settings->m_Input.warp_mouse_on_move; - m_dragAction = static_cast( settings->m_Input.drag_left ); + m_dragAction = settings->m_Input.drag_left; m_immediateActions = settings->m_Input.immediate_actions; } diff --git a/common/view/wx_view_controls.cpp b/common/view/wx_view_controls.cpp index 9a5fa871b8..7427cef764 100644 --- a/common/view/wx_view_controls.cpp +++ b/common/view/wx_view_controls.cpp @@ -145,9 +145,9 @@ void WX_VIEW_CONTROLS::LoadSettings() m_settings.m_scrollModifierZoom = cfg->m_Input.scroll_modifier_zoom; m_settings.m_scrollModifierPanH = cfg->m_Input.scroll_modifier_pan_h; m_settings.m_scrollModifierPanV = cfg->m_Input.scroll_modifier_pan_v; - m_settings.m_dragLeft = static_cast( cfg->m_Input.drag_left ); - m_settings.m_dragMiddle = static_cast( cfg->m_Input.drag_middle ); - m_settings.m_dragRight = static_cast( cfg->m_Input.drag_right ); + m_settings.m_dragLeft = cfg->m_Input.drag_left; + m_settings.m_dragMiddle = cfg->m_Input.drag_middle; + m_settings.m_dragRight = cfg->m_Input.drag_right; m_zoomController.reset(); diff --git a/eeschema/tools/ee_selection_tool.cpp b/eeschema/tools/ee_selection_tool.cpp index dd5d314d7e..9d19bcdb21 100644 --- a/eeschema/tools/ee_selection_tool.cpp +++ b/eeschema/tools/ee_selection_tool.cpp @@ -324,8 +324,8 @@ int EE_SELECTION_TOOL::Main( const TOOL_EVENT& aEvent ) else if( evt->Modifier( MD_CTRL ) ) m_exclusive_or = true; - bool modifier_enabled = m_subtractive || m_additive || m_exclusive_or; - KIGFX::MOUSE_DRAG_ACTION drag_action = m_frame->GetDragAction(); + bool modifier_enabled = m_subtractive || m_additive || m_exclusive_or; + MOUSE_DRAG_ACTION drag_action = m_frame->GetDragAction(); // Is the user requesting that the selection list include all possible // items without removing less likely selection candidates @@ -432,11 +432,11 @@ int EE_SELECTION_TOOL::Main( const TOOL_EVENT& aEvent ) if( SCH_EDIT_FRAME* schframe = dynamic_cast( m_frame ) ) schframe->FocusOnItem( nullptr ); - if( modifier_enabled || drag_action == KIGFX::MOUSE_DRAG_ACTION::SELECT ) + if( modifier_enabled || drag_action == MOUSE_DRAG_ACTION::SELECT ) { selectMultiple(); } - else if( m_selection.Empty() && drag_action != KIGFX::MOUSE_DRAG_ACTION::DRAG_ANY ) + else if( m_selection.Empty() && drag_action != MOUSE_DRAG_ACTION::DRAG_ANY ) { selectMultiple(); } @@ -582,7 +582,7 @@ int EE_SELECTION_TOOL::Main( const TOOL_EVENT& aEvent ) m_nonModifiedCursor = KICURSOR::HAND; } else if( !m_selection.Empty() - && drag_action == KIGFX::MOUSE_DRAG_ACTION::DRAG_SELECTED + && drag_action == MOUSE_DRAG_ACTION::DRAG_SELECTED && evt->HasPosition() && selectionContains( evt->Position() ) ) //move/drag option prediction { diff --git a/include/settings/common_settings.h b/include/settings/common_settings.h index 60cab5d796..03dc91163c 100644 --- a/include/settings/common_settings.h +++ b/include/settings/common_settings.h @@ -24,6 +24,18 @@ #include +enum class MOUSE_DRAG_ACTION +{ + // WARNING: these are encoded as integers in the file, so don't change their values. + DRAG_ANY = -2, + DRAG_SELECTED, + SELECT, + ZOOM, + PAN, + NONE +}; + + class COMMON_SETTINGS : public JSON_SETTINGS { public: @@ -69,9 +81,9 @@ public: int scroll_modifier_pan_h; int scroll_modifier_pan_v; - int drag_left; - int drag_middle; - int drag_right; + MOUSE_DRAG_ACTION drag_left; + MOUSE_DRAG_ACTION drag_middle; + MOUSE_DRAG_ACTION drag_right; }; struct GRAPHICS diff --git a/include/tool/tools_holder.h b/include/tool/tools_holder.h index f8c258e4a6..72d8a6eea5 100644 --- a/include/tool/tools_holder.h +++ b/include/tool/tools_holder.h @@ -131,7 +131,7 @@ public: * Indicates whether a drag should draw a selection rectangle or drag selected (or unselected) * objects. */ - KIGFX::MOUSE_DRAG_ACTION GetDragAction() const { return m_dragAction; } + MOUSE_DRAG_ACTION GetDragAction() const { return m_dragAction; } /** * Indicate that a move operation should warp the mouse pointer to the origin of the @@ -171,7 +171,7 @@ protected: // the first invocation of a hotkey will just // select the relevant tool rather than executing // the tool's action. - KIGFX::MOUSE_DRAG_ACTION m_dragAction; // DRAG_ANY/DRAG_SELECTED/SELECT. + MOUSE_DRAG_ACTION m_dragAction; // DRAG_ANY/DRAG_SELECTED/SELECT. bool m_moveWarpsCursor; // cursor is warped to move/drag origin }; diff --git a/include/view/view_controls.h b/include/view/view_controls.h index 86250c36a7..fd229aa40d 100644 --- a/include/view/view_controls.h +++ b/include/view/view_controls.h @@ -3,7 +3,7 @@ * * Copyright (C) 2012 Torsten Hueter, torstenhtr gmx.de * Copyright (C) 2013 CERN - * Copyright (C) 2013-2020 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2013-2021 KiCad Developers, see AUTHORS.txt for contributors. * * @author Tomasz Wlostowski * @@ -26,34 +26,17 @@ * */ -/** - * @file view_controls.h - * @brief VIEW_CONTROLS class definition. - */ - #ifndef __VIEW_CONTROLS_H #define __VIEW_CONTROLS_H #include +#include namespace KIGFX { class VIEW; -///< Action to perform when the mouse is dragged -// Warning: these are encoded as integers in the file, so don't change their values -enum class MOUSE_DRAG_ACTION -{ - DRAG_ANY = -2, - DRAG_SELECTED, - SELECT, - ZOOM, - PAN, - NONE -}; - - ///< Structure to keep VIEW_CONTROLS settings for easy store/restore operations struct VC_SETTINGS { diff --git a/pagelayout_editor/tools/pl_selection_tool.cpp b/pagelayout_editor/tools/pl_selection_tool.cpp index c49089bae3..cbdcf52a12 100644 --- a/pagelayout_editor/tools/pl_selection_tool.cpp +++ b/pagelayout_editor/tools/pl_selection_tool.cpp @@ -204,7 +204,7 @@ int PL_SELECTION_TOOL::Main( const TOOL_EVENT& aEvent ) { if( !modifier_enabled && !m_selection.Empty() - && m_frame->GetDragAction() == KIGFX::MOUSE_DRAG_ACTION::DRAG_SELECTED + && m_frame->GetDragAction() == MOUSE_DRAG_ACTION::DRAG_SELECTED && evt->HasPosition() && selectionContains( evt->Position() ) ) { diff --git a/pcbnew/tools/pcb_selection_tool.cpp b/pcbnew/tools/pcb_selection_tool.cpp index 1b05180ade..a5dc1171ea 100644 --- a/pcbnew/tools/pcb_selection_tool.cpp +++ b/pcbnew/tools/pcb_selection_tool.cpp @@ -208,8 +208,8 @@ int PCB_SELECTION_TOOL::Main( const TOOL_EVENT& aEvent ) // Main loop: keep receiving events while( TOOL_EVENT* evt = Wait() ) { - KIGFX::MOUSE_DRAG_ACTION dragAction = m_frame->GetDragAction(); - TRACK_DRAG_ACTION trackDragAction = m_frame->Settings().m_TrackDragAction; + MOUSE_DRAG_ACTION dragAction = m_frame->GetDragAction(); + TRACK_DRAG_ACTION trackDragAction = m_frame->Settings().m_TrackDragAction; // on left click, a selection is made, depending on modifiers ALT, SHIFT, CTRL: // Due to the fact ALT key modifier cannot be useed freely on Winows and Linux, @@ -340,11 +340,11 @@ int PCB_SELECTION_TOOL::Main( const TOOL_EVENT& aEvent ) m_frame->FocusOnItem( nullptr ); m_toolMgr->ProcessEvent( EVENTS::InhibitSelectionEditing ); - if( modifier_enabled || dragAction == KIGFX::MOUSE_DRAG_ACTION::SELECT ) + if( modifier_enabled || dragAction == MOUSE_DRAG_ACTION::SELECT ) { selectMultiple(); } - else if( m_selection.Empty() && dragAction != KIGFX::MOUSE_DRAG_ACTION::DRAG_ANY ) + else if( m_selection.Empty() && dragAction != MOUSE_DRAG_ACTION::DRAG_ANY ) { selectMultiple(); } @@ -424,7 +424,7 @@ int PCB_SELECTION_TOOL::Main( const TOOL_EVENT& aEvent ) { //move cursor prediction if( !modifier_enabled - && dragAction == KIGFX::MOUSE_DRAG_ACTION::DRAG_SELECTED + && dragAction == MOUSE_DRAG_ACTION::DRAG_SELECTED && !m_selection.Empty() && evt->HasPosition() && selectionContains( evt->Position() ) )