KiCad PCB EDA Suite
panel_mouse_settings.cpp
Go to the documentation of this file.
1 /*
2  * This program source code file is part of KiCad, a free EDA CAD application.
3  *
4  * Copyright (C) 2020 Jon Evans <jon@craftyjon.com>
5  * Copyright (C) 2020 KiCad Developers, see AUTHORS.txt for contributors.
6  *
7  * This program is free software: you can redistribute it and/or modify it
8  * under the terms of the GNU General Public License as published by the
9  * Free Software Foundation, either version 3 of the License, or (at your
10  * option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License along
18  * with this program. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
21 #include <dialog_shim.h>
23 #include <pgm_base.h>
25 #include <view/view_controls.h>
26 #include <wx/defs.h>
27 
29 
30 
32  PANEL_MOUSE_SETTINGS_BASE( aParent ),
33  m_dialog( aDialog ),
34  m_currentScrollMod( {} )
35 {
36 #ifdef __WXOSX_MAC__
37  for( wxSizerItem* child : m_zoomSizer->GetChildren() )
38  {
39  if( child->GetWindow() == m_zoomSpeed )
40  child->SetBorder( 14 );
41  }
42 
43  for( wxSizerItem* child : m_panSizer->GetChildren() )
44  {
45  if( child->GetWindow() == m_autoPanSpeed )
46  child->SetBorder( 14 );
47  }
48 #endif
49 
50  m_checkAutoZoomSpeed->Bind( wxEVT_COMMAND_CHECKBOX_CLICKED,
51  [&]( wxCommandEvent& aEvt )
52  {
53  m_zoomSpeed->Enable( !m_checkAutoZoomSpeed->GetValue() );
54  } );
55 }
56 
57 
59 {
60 }
61 
62 
64 {
65  const COMMON_SETTINGS* cfg = Pgm().GetCommonSettings();
66 
67  applySettingsToPanel( *cfg );
68 
69  return true;
70 }
71 
72 
74 {
75  COMMON_SETTINGS* cfg = Pgm().GetCommonSettings();
76 
78 
80  return false;
81 
82  int drag_middle = static_cast<int>( MOUSE_DRAG_ACTION::NONE );
83  int drag_right = static_cast<int>( MOUSE_DRAG_ACTION::NONE );
84 
85  switch( m_choiceMiddleButtonDrag->GetSelection() )
86  {
87  case 0:
88  drag_middle = static_cast<int>( MOUSE_DRAG_ACTION::PAN );
89  break;
90 
91  case 1:
92  drag_middle = static_cast<int>( MOUSE_DRAG_ACTION::ZOOM );
93  break;
94 
95  default:
96  case 2:
97  break;
98  }
99 
100  switch( m_choiceRightButtonDrag->GetSelection() )
101  {
102  case 0:
103  drag_right = static_cast<int>( MOUSE_DRAG_ACTION::PAN );
104  break;
105 
106  case 1:
107  drag_right = static_cast<int>( MOUSE_DRAG_ACTION::ZOOM );
108  break;
109 
110  default:
111  case 2:
112  break;
113  }
114 
115  cfg->m_Input.center_on_zoom = m_checkZoomCenter->GetValue();
116  cfg->m_Input.auto_pan = m_checkAutoPan->GetValue();
117  cfg->m_Input.auto_pan_acceleration = m_autoPanSpeed->GetValue();
119  cfg->m_Input.zoom_speed = m_zoomSpeed->GetValue();
120  cfg->m_Input.zoom_speed_auto = m_checkAutoZoomSpeed->GetValue();
121  cfg->m_Input.horizontal_pan = m_checkEnablePanH->GetValue();
122 
126 
127  cfg->m_Input.drag_middle = drag_middle;
128  cfg->m_Input.drag_right = drag_right;
129 
130  return true;
131 }
132 
133 
135 {
136  COMMON_SETTINGS defaultSettings;
137 
138  defaultSettings.ResetToDefaults();
139 
140  applySettingsToPanel( defaultSettings );
141 }
142 
143 
145 {
146  m_checkZoomCenter->SetValue( aSettings.m_Input.center_on_zoom );
147  m_checkAutoPan->SetValue( aSettings.m_Input.auto_pan );
148  m_checkZoomAcceleration->SetValue( aSettings.m_Input.zoom_acceleration );
149  m_zoomSpeed->SetValue( aSettings.m_Input.zoom_speed );
150  m_checkAutoZoomSpeed->SetValue( aSettings.m_Input.zoom_speed_auto );
151  m_checkEnablePanH->SetValue( aSettings.m_Input.horizontal_pan );
152  m_autoPanSpeed->SetValue( aSettings.m_Input.auto_pan_acceleration );
153 
154  m_zoomSpeed->Enable( !aSettings.m_Input.zoom_speed_auto );
155 
156  auto set_mouse_buttons =
157  []( const MOUSE_DRAG_ACTION& aVal, wxChoice* aChoice )
158  {
159  switch( aVal )
160  {
161  case MOUSE_DRAG_ACTION::PAN:
162  aChoice->SetSelection( 0 );
163  break;
164 
165  case MOUSE_DRAG_ACTION::ZOOM:
166  aChoice->SetSelection( 1 );
167  break;
168 
170  aChoice->SetSelection( 2 );
171  break;
172 
173  case MOUSE_DRAG_ACTION::SELECT:
174  default:
175  break;
176  }
177  };
178 
179  set_mouse_buttons(
180  static_cast<MOUSE_DRAG_ACTION>( aSettings.m_Input.drag_middle ), m_choiceMiddleButtonDrag );
181 
182  set_mouse_buttons(
183  static_cast<MOUSE_DRAG_ACTION>( aSettings.m_Input.drag_right ), m_choiceRightButtonDrag );
184 
188 
190 }
191 
192 
193 void PANEL_MOUSE_SETTINGS::OnScrollRadioButton( wxCommandEvent& event )
194 {
195  wxRadioButton* btn = dynamic_cast<wxRadioButton*>( event.GetEventObject() );
196 
197  if( !btn )
198  return;
199 
200  SCROLL_MOD_SET newSet = getScrollModSet();
201 
202  if( isScrollModSetValid( newSet ) )
203  m_currentScrollMod = newSet;
204  else
206 }
207 
208 
210 {
211  SCROLL_MOD_SET ret = {};
212 
213  if( m_rbZoomShift->GetValue() )
214  ret.zoom = WXK_SHIFT;
215  else if( m_rbZoomCtrl->GetValue() )
216  ret.zoom = WXK_CONTROL;
217  else if( m_rbZoomAlt->GetValue() )
218  ret.zoom = WXK_ALT;
219 
220  if( m_rbPanHShift->GetValue() )
221  ret.panh = WXK_SHIFT;
222  else if( m_rbPanHCtrl->GetValue() )
223  ret.panh = WXK_CONTROL;
224  else if( m_rbPanHAlt->GetValue() )
225  ret.panh = WXK_ALT;
226 
227  if( m_rbPanVShift->GetValue() )
228  ret.panv = WXK_SHIFT;
229  else if( m_rbPanVCtrl->GetValue() )
230  ret.panv = WXK_CONTROL;
231  else if( m_rbPanVAlt->GetValue() )
232  ret.panv = WXK_ALT;
233 
234  return ret;
235 }
236 
237 
239 {
240  return ( aSet.zoom != aSet.panh && aSet.panh != aSet.panv && aSet.panv != aSet.zoom );
241 }
242 
243 
245 {
246  auto set_wheel_buttons =
247  []( int aModifier, wxRadioButton* aNoneBtn, wxRadioButton* aCtrlBtn,
248  wxRadioButton* aShiftBtn, wxRadioButton* aAltBtn )
249  {
250  switch( aModifier )
251  {
252  case 0:
253  aNoneBtn->SetValue( true );
254  break;
255 
256  case WXK_CONTROL:
257  aCtrlBtn->SetValue( true );
258  break;
259 
260  case WXK_SHIFT:
261  aShiftBtn->SetValue( true );
262  break;
263 
264  case WXK_ALT:
265  aAltBtn->SetValue( true );
266  break;
267  }
268  };
269 
270  set_wheel_buttons(
272 
273  set_wheel_buttons(
275 
276  set_wheel_buttons(
278 }
void ResetToDefaults()
Resets all parameters to default values.
MOUSE_DRAG_ACTION
Action to perform when the mouse is dragged
Definition: view_controls.h:45
VIEW_CONTROLS class definition.
void applySettingsToPanel(const COMMON_SETTINGS &aSettings)
Dialog helper object to sit in the inheritance tree between wxDialog and any class written by wxFormB...
Definition: dialog_shim.h:83
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:102
SCROLL_MOD_SET m_currentScrollMod
PANEL_MOUSE_SETTINGS(DIALOG_SHIM *aDialog, wxWindow *aParent)
bool TransferDataFromWindow() override
void ResetPanel() override
Reset the contents of this panel.
bool isScrollModSetValid(const SCROLL_MOD_SET &aSet)
see class PGM_BASE
SCROLL_MOD_SET getScrollModSet()
void OnScrollRadioButton(wxCommandEvent &event) override
bool TransferDataToWindow() override
Class PANEL_MOUSE_SETTINGS_BASE.