Promote mouse drag settings to full enums.

This commit is contained in:
Jeff Young 2021-01-11 15:46:41 +00:00
parent e4c77f3a47
commit 50889a9ed6
10 changed files with 86 additions and 102 deletions

View File

@ -22,11 +22,8 @@
#include <dialogs/panel_mouse_settings.h>
#include <pgm_base.h>
#include <settings/common_settings.h>
#include <view/view_controls.h>
#include <wx/defs.h>
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<int>( MOUSE_DRAG_ACTION::SELECT ); break;
case 1: cfg->m_Input.drag_left = static_cast<int>( MOUSE_DRAG_ACTION::DRAG_SELECTED ); break;
case 2: cfg->m_Input.drag_left = static_cast<int>( 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<int>( MOUSE_DRAG_ACTION::PAN ); break;
case 1: cfg->m_Input.drag_middle = static_cast<int>( MOUSE_DRAG_ACTION::ZOOM ); break;
case 2: cfg->m_Input.drag_middle = static_cast<int>( 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<int>( MOUSE_DRAG_ACTION::PAN ); break;
case 1: cfg->m_Input.drag_right = static_cast<int>( MOUSE_DRAG_ACTION::ZOOM ); break;
case 2: cfg->m_Input.drag_right = static_cast<int>( 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<MOUSE_DRAG_ACTION>( 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<MOUSE_DRAG_ACTION>( aSettings.m_Input.drag_middle ),
m_choiceMiddleButtonDrag );
set_mouse_buttons( static_cast<MOUSE_DRAG_ACTION>( 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;

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2020 Jon Evans <jon@craftyjon.com>
* 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 <set>
#include <settings/common_settings.h>
#include <settings/parameters.h>
#include <view/view_controls.h>
#include <view/zoom_controller.h>
#include <wx/config.h>
#include <wx/log.h>
using KIGFX::MOUSE_DRAG_ACTION;
///! The following environment variables will never be migrated from a previous version
const std::set<wxString> envVarBlacklist =
@ -127,41 +123,38 @@ COMMON_SETTINGS::COMMON_SETTINGS() :
int default_zoom_speed = 1;
#endif
m_params.emplace_back(
new PARAM<int>( "input.zoom_speed", &m_Input.zoom_speed, default_zoom_speed ) );
m_params.emplace_back( new PARAM<int>( "input.zoom_speed",
&m_Input.zoom_speed, default_zoom_speed ) );
m_params.emplace_back(
new PARAM<bool>( "input.zoom_speed_auto", &m_Input.zoom_speed_auto, true ) );
m_params.emplace_back( new PARAM<bool>( "input.zoom_speed_auto",
&m_Input.zoom_speed_auto, true ) );
m_params.emplace_back(
new PARAM<int>( "input.scroll_modifier_zoom", &m_Input.scroll_modifier_zoom, 0 ) );
m_params.emplace_back( new PARAM<int>( "input.scroll_modifier_zoom",
&m_Input.scroll_modifier_zoom, 0 ) );
m_params.emplace_back( new PARAM<int>(
"input.scroll_modifier_pan_h", &m_Input.scroll_modifier_pan_h, WXK_CONTROL ) );
m_params.emplace_back( new PARAM<int>( "input.scroll_modifier_pan_h",
&m_Input.scroll_modifier_pan_h, WXK_CONTROL ) );
m_params.emplace_back( new PARAM<int>(
"input.scroll_modifier_pan_v", &m_Input.scroll_modifier_pan_v, WXK_SHIFT ) );
m_params.emplace_back( new PARAM<int>( "input.scroll_modifier_pan_v",
&m_Input.scroll_modifier_pan_v, WXK_SHIFT ) );
m_params.emplace_back( new PARAM<int>( "input.mouse_left", &m_Input.drag_left,
static_cast<int>( MOUSE_DRAG_ACTION::DRAG_SELECTED ),
static_cast<int>( MOUSE_DRAG_ACTION::DRAG_ANY ),
static_cast<int>( MOUSE_DRAG_ACTION::SELECT ) ) );
m_params.emplace_back( new PARAM_ENUM<MOUSE_DRAG_ACTION>( "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<int>( "input.mouse_middle", &m_Input.drag_middle,
static_cast<int>( MOUSE_DRAG_ACTION::PAN ),
static_cast<int>( MOUSE_DRAG_ACTION::SELECT ),
static_cast<int>( MOUSE_DRAG_ACTION::NONE ) ) );
m_params.emplace_back( new PARAM_ENUM<MOUSE_DRAG_ACTION>( "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<int>( "input.mouse_right", &m_Input.drag_right,
static_cast<int>( MOUSE_DRAG_ACTION::PAN ),
static_cast<int>( MOUSE_DRAG_ACTION::SELECT ),
static_cast<int>( MOUSE_DRAG_ACTION::NONE ) ) );
m_params.emplace_back( new PARAM_ENUM<MOUSE_DRAG_ACTION>( "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<int>( "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<int>( "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<int>( "system.autosave_interval",
&m_System.autosave_interval, 600 ) );

View File

@ -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<KIGFX::MOUSE_DRAG_ACTION>( settings->m_Input.drag_left );
m_dragAction = settings->m_Input.drag_left;
m_immediateActions = settings->m_Input.immediate_actions;
}

View File

@ -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<MOUSE_DRAG_ACTION>( cfg->m_Input.drag_left );
m_settings.m_dragMiddle = static_cast<MOUSE_DRAG_ACTION>( cfg->m_Input.drag_middle );
m_settings.m_dragRight = static_cast<MOUSE_DRAG_ACTION>( 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();

View File

@ -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<SCH_EDIT_FRAME*>( 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
{

View File

@ -24,6 +24,18 @@
#include <settings/json_settings.h>
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

View File

@ -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
};

View File

@ -3,7 +3,7 @@
*
* Copyright (C) 2012 Torsten Hueter, torstenhtr <at> 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 <tomasz.wlostowski@cern.ch>
*
@ -26,34 +26,17 @@
*
*/
/**
* @file view_controls.h
* @brief VIEW_CONTROLS class definition.
*/
#ifndef __VIEW_CONTROLS_H
#define __VIEW_CONTROLS_H
#include <math/box2.h>
#include <settings/common_settings.h>
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
{

View File

@ -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() ) )
{

View File

@ -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() ) )