KiCad PCB EDA Suite
wx_view_controls.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) 2012 Torsten Hueter, torstenhtr <at> gmx.de
5  * Copyright (C) 2013-2015 CERN
6  * Copyright (C) 2012-2016 KiCad Developers, see AUTHORS.txt for contributors.
7  *
8  * @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
9  * @author Maciej Suminski <maciej.suminski@cern.ch>
10  *
11  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU General Public License
13  * as published by the Free Software Foundation; either version 2
14  * of the License, or (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, you may find one here:
23  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
24  * or you may search the http://www.gnu.org website for the version 2 license,
25  * or you may write to the Free Software Foundation, Inc.,
26  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
27  */
28 
29 #include <view/view.h>
30 #include <view/wx_view_controls.h>
31 #include <view/zoom_controller.h>
33 #include <tool/tool_dispatcher.h>
34 
35 using namespace KIGFX;
36 
37 const wxEventType WX_VIEW_CONTROLS::EVT_REFRESH_MOUSE = wxNewEventType();
38 
39 
40 static std::unique_ptr<ZOOM_CONTROLLER> GetZoomControllerForPlatform()
41 {
42 #ifdef __WXMAC__
43  // On Apple pointer devices, wheel events occur frequently and with
44  // smaller rotation values. For those devices, let's handle zoom
45  // based on the rotation amount rather than the time difference.
46  return std::make_unique<CONSTANT_ZOOM_CONTROLLER>( CONSTANT_ZOOM_CONTROLLER::MAC_SCALE );
47 #elif __WXGTK3__
48  // GTK3 is similar, but the scale constant is smaller
49  return std::make_unique<CONSTANT_ZOOM_CONTROLLER>( CONSTANT_ZOOM_CONTROLLER::GTK3_SCALE );
50 #else
51  return std::make_unique<ACCELERATING_ZOOM_CONTROLLER>();
52 #endif
53 }
54 
55 
56 WX_VIEW_CONTROLS::WX_VIEW_CONTROLS( VIEW* aView, wxScrolledCanvas* aParentPanel ) :
57  VIEW_CONTROLS( aView ), m_state( IDLE ), m_parentPanel( aParentPanel ),
58  m_scrollScale( 1.0, 1.0 ), m_lastTimestamp( 0 ), m_cursorPos( 0, 0 ), m_updateCursor( true )
59 {
60  m_parentPanel->Connect( wxEVT_MOTION,
61  wxMouseEventHandler( WX_VIEW_CONTROLS::onMotion ), NULL, this );
62 #if wxCHECK_VERSION( 3, 1, 0 ) || defined( USE_OSX_MAGNIFY_EVENT )
63  m_parentPanel->Connect( wxEVT_MAGNIFY,
64  wxMouseEventHandler( WX_VIEW_CONTROLS::onMagnify ), NULL, this );
65 #endif
66  m_parentPanel->Connect( wxEVT_MOUSEWHEEL,
67  wxMouseEventHandler( WX_VIEW_CONTROLS::onWheel ), NULL, this );
68  m_parentPanel->Connect( wxEVT_MIDDLE_UP,
69  wxMouseEventHandler( WX_VIEW_CONTROLS::onButton ), NULL, this );
70  m_parentPanel->Connect( wxEVT_MIDDLE_DOWN,
71  wxMouseEventHandler( WX_VIEW_CONTROLS::onButton ), NULL, this );
72  m_parentPanel->Connect( wxEVT_LEFT_UP,
73  wxMouseEventHandler( WX_VIEW_CONTROLS::onButton ), NULL, this );
74  m_parentPanel->Connect( wxEVT_LEFT_DOWN,
75  wxMouseEventHandler( WX_VIEW_CONTROLS::onButton ), NULL, this );
76  m_parentPanel->Connect( wxEVT_RIGHT_UP,
77  wxMouseEventHandler( WX_VIEW_CONTROLS::onButton ), NULL, this );
78  m_parentPanel->Connect( wxEVT_RIGHT_DOWN,
79  wxMouseEventHandler( WX_VIEW_CONTROLS::onButton ), NULL, this );
80 #if defined _WIN32 || defined _WIN64
81  m_parentPanel->Connect( wxEVT_ENTER_WINDOW,
82  wxMouseEventHandler( WX_VIEW_CONTROLS::onEnter ), NULL, this );
83 #endif
84  m_parentPanel->Connect( wxEVT_LEAVE_WINDOW,
85  wxMouseEventHandler( WX_VIEW_CONTROLS::onLeave ), NULL, this );
86  m_parentPanel->Connect( wxEVT_SCROLLWIN_THUMBTRACK,
87  wxScrollWinEventHandler( WX_VIEW_CONTROLS::onScroll ), NULL, this );
88  m_parentPanel->Connect( wxEVT_SCROLLWIN_PAGEUP,
89  wxScrollWinEventHandler( WX_VIEW_CONTROLS::onScroll ), NULL, this );
90  m_parentPanel->Connect( wxEVT_SCROLLWIN_PAGEDOWN,
91  wxScrollWinEventHandler( WX_VIEW_CONTROLS::onScroll ), NULL, this );
92 
93  m_parentPanel->Connect( wxEVT_SCROLLWIN_BOTTOM,
94  wxScrollWinEventHandler( WX_VIEW_CONTROLS::onScroll ), NULL, this );
95  m_parentPanel->Connect( wxEVT_SCROLLWIN_TOP,
96  wxScrollWinEventHandler( WX_VIEW_CONTROLS::onScroll ), NULL, this );
97  m_parentPanel->Connect( wxEVT_SCROLLWIN_LINEUP,
98  wxScrollWinEventHandler( WX_VIEW_CONTROLS::onScroll ), NULL, this );
99  m_parentPanel->Connect( wxEVT_SCROLLWIN_LINEDOWN,
100  wxScrollWinEventHandler( WX_VIEW_CONTROLS::onScroll ), NULL, this );
101 
103 
104  m_cursorWarped = false;
105 
106  m_panTimer.SetOwner( this );
107  this->Connect( wxEVT_TIMER,
108  wxTimerEventHandler( WX_VIEW_CONTROLS::onTimer ), NULL, this );
109 
111 }
112 
113 
115 {
116 }
117 
118 
119 void WX_VIEW_CONTROLS::onMotion( wxMouseEvent& aEvent )
120 {
121  bool isAutoPanning = false;
122  VECTOR2D mousePos( aEvent.GetX(), aEvent.GetY() );
123 
125  isAutoPanning = handleAutoPanning( aEvent );
126 
127  if( !isAutoPanning && aEvent.Dragging() )
128  {
129  if( m_state == DRAG_PANNING )
130  {
131  VECTOR2D d = m_dragStartPoint - mousePos;
132  VECTOR2D delta = m_view->ToWorld( d, false );
133 
135  aEvent.StopPropagation();
136  }
137  }
138 
139  if( m_updateCursor ) // do not update the cursor position if it was explicitly set
140  m_cursorPos = m_view->ToWorld( mousePos );
141  else
142  m_updateCursor = true;
143 
144  aEvent.Skip();
145 }
146 
147 
148 void WX_VIEW_CONTROLS::onWheel( wxMouseEvent& aEvent )
149 {
150  const double wheelPanSpeed = 0.001;
151 
152 #ifdef __WXGTK3__
153  if( aEvent.GetTimestamp() == m_lastTimestamp )
154  {
155  aEvent.Skip( false );
156  return;
157  }
158 
159  m_lastTimestamp = aEvent.GetTimestamp();
160 #endif
161 
162  // mousewheelpan disabled:
163  // wheel + ctrl -> horizontal scrolling;
164  // wheel + shift -> vertical scrolling;
165  // wheel -> zooming;
166  // mousewheelpan enabled:
167  // wheel -> pan;
168  // wheel + ctrl -> zooming;
169  // wheel + shift -> horizontal scrolling.
170 
171  if( ( !m_settings.m_enableMousewheelPan && ( aEvent.ControlDown() || aEvent.ShiftDown() ) ) ||
172  ( m_settings.m_enableMousewheelPan && !aEvent.ControlDown() ) )
173  {
174  // Scrolling
175  VECTOR2D scrollVec = m_view->ToWorld( m_view->GetScreenPixelSize(), false ) *
176  ( (double) aEvent.GetWheelRotation() * wheelPanSpeed );
177  int axis = aEvent.GetWheelAxis();
178  double scrollX = 0.0;
179  double scrollY = 0.0;
180 
182  {
183  if ( axis == wxMOUSE_WHEEL_HORIZONTAL || aEvent.ShiftDown() )
184  scrollX = scrollVec.x;
185  else
186  scrollY = -scrollVec.y;
187  }
188  else
189  {
190  if( aEvent.ControlDown() )
191  scrollX = -scrollVec.x;
192  else
193  scrollY = -scrollVec.y;
194  }
195 
196  VECTOR2D delta( scrollX, scrollY );
197 
199  refreshMouse();
200  }
201  else
202  {
203  int rotation = aEvent.GetWheelRotation();
204  double zoomScale = m_zoomController->GetScaleForRotation( rotation );
205 
206  if( IsCursorWarpingEnabled() )
207  {
208  CenterOnCursor();
209  m_view->SetScale( m_view->GetScale() * zoomScale );
210  }
211  else
212  {
213  VECTOR2D anchor = m_view->ToWorld( VECTOR2D( aEvent.GetX(), aEvent.GetY() ) );
214  m_view->SetScale( m_view->GetScale() * zoomScale, anchor );
215  }
216  }
217 
218  // Do not skip this event, otherwise wxWidgets will fire
219  // 3 wxEVT_SCROLLWIN_LINEUP or wxEVT_SCROLLWIN_LINEDOWN (normal wxWidgets behavior)
220  // and we do not want that.
221  m_parentPanel->Refresh();
222 }
223 
224 
225 #if wxCHECK_VERSION( 3, 1, 0 ) || defined( USE_OSX_MAGNIFY_EVENT )
226 void WX_VIEW_CONTROLS::onMagnify( wxMouseEvent& aEvent )
227 {
228  // Scale based on the magnification from our underlying magnification event.
229  VECTOR2D anchor = m_view->ToWorld( VECTOR2D( aEvent.GetX(), aEvent.GetY() ) );
230  m_view->SetScale( m_view->GetScale() * ( aEvent.GetMagnification() + 1.0f ), anchor );
231 
232  aEvent.Skip();
233 }
234 #endif
235 
236 
237 void WX_VIEW_CONTROLS::onButton( wxMouseEvent& aEvent )
238 {
239  switch( m_state )
240  {
241  case IDLE:
242  case AUTO_PANNING:
243  if( aEvent.MiddleDown() ||
244  ( aEvent.LeftDown() && m_settings.m_panWithLeftButton ) ||
245  ( aEvent.RightDown() && m_settings.m_panWithRightButton ) )
246  {
247  m_dragStartPoint = VECTOR2D( aEvent.GetX(), aEvent.GetY() );
250  }
251 
252  if( aEvent.LeftUp() )
253  m_state = IDLE; // Stop autopanning when user release left mouse button
254 
255  break;
256 
257  case DRAG_PANNING:
258  if( aEvent.MiddleUp() || aEvent.LeftUp() || aEvent.RightUp() )
259  m_state = IDLE;
260 
261  break;
262  }
263 
264  aEvent.Skip();
265 }
266 
267 
268 void WX_VIEW_CONTROLS::onEnter( wxMouseEvent& aEvent )
269 {
270  m_parentPanel->SetFocus();
271 }
272 
273 
274 void WX_VIEW_CONTROLS::onLeave( wxMouseEvent& aEvent )
275 {
277  {
278  bool warp = false;
279  int x = aEvent.GetX();
280  int y = aEvent.GetY();
281  wxSize parentSize = m_parentPanel->GetClientSize();
282 
283  if( x < 0 )
284  {
285  x = 0;
286  warp = true;
287  }
288  else if( x >= parentSize.x )
289  {
290  x = parentSize.x - 1;
291  warp = true;
292  }
293 
294  if( y < 0 )
295  {
296  y = 0;
297  warp = true;
298  }
299  else if( y >= parentSize.y )
300  {
301  y = parentSize.y - 1;
302  warp = true;
303  }
304 
305  if( warp )
306  m_parentPanel->WarpPointer( x, y );
307  }
308 }
309 
310 
311 void WX_VIEW_CONTROLS::onTimer( wxTimerEvent& aEvent )
312 {
313  switch( m_state )
314  {
315  case AUTO_PANNING:
316  {
318  {
319  m_state = IDLE;
320  return;
321  }
322 
323 #if wxCHECK_VERSION( 3, 0, 0 )
324  if( !m_parentPanel->HasFocus() )
325  break;
326 #endif
327 
328  double borderSize = std::min( m_settings.m_autoPanMargin * m_view->GetScreenPixelSize().x,
330 
331  VECTOR2D dir( m_panDirection );
332 
333  if( dir.EuclideanNorm() > borderSize )
334  dir = dir.Resize( borderSize );
335 
336  dir = m_view->ToWorld( dir, false );
338 
339  refreshMouse();
340  }
341  break;
342 
343  case IDLE: // Just remove unnecessary warnings
344  case DRAG_PANNING:
345  break;
346  }
347 }
348 
349 
350 void WX_VIEW_CONTROLS::onScroll( wxScrollWinEvent& aEvent )
351 {
352  const double linePanDelta = 0.05;
353  const double pagePanDelta = 0.5;
354 
355  int type = aEvent.GetEventType();
356  int dir = aEvent.GetOrientation();
357 
358  if( type == wxEVT_SCROLLWIN_THUMBTRACK )
359  {
360  auto center = m_view->GetCenter();
361  const auto& boundary = m_view->GetBoundary();
362 
363  // Flip scroll direction in flipped view
364  const double xstart = ( m_view->IsMirroredX() ?
365  boundary.GetRight() : boundary.GetLeft() );
366  const double xdelta = ( m_view->IsMirroredX() ? -1 : 1 );
367 
368  if( dir == wxHORIZONTAL )
369  center.x = xstart + xdelta * ( aEvent.GetPosition() / m_scrollScale.x );
370  else
371  center.y = boundary.GetTop() + aEvent.GetPosition() / m_scrollScale.y;
372 
373  m_view->SetCenter( center );
374  }
375  else
376  {
377  double dist = 0;
378 
379  if( type == wxEVT_SCROLLWIN_PAGEUP )
380  dist = pagePanDelta;
381  else if( type == wxEVT_SCROLLWIN_PAGEDOWN )
382  dist = -pagePanDelta;
383  else if( type == wxEVT_SCROLLWIN_LINEUP )
384  dist = linePanDelta;
385  else if( type == wxEVT_SCROLLWIN_LINEDOWN )
386  dist = -linePanDelta;
387  else
388  {
389  wxASSERT( "Unhandled event type" );
390  return;
391  }
392 
393  VECTOR2D scroll = m_view->ToWorld( m_view->GetScreenPixelSize(), false ) * dist;
394 
395  double scrollX = 0.0;
396  double scrollY = 0.0;
397 
398  if ( dir == wxHORIZONTAL )
399  scrollX = -scroll.x;
400  else
401  scrollY = -scroll.y;
402 
403  VECTOR2D delta( scrollX, scrollY );
404 
406  }
407 
408  m_parentPanel->Refresh();
409 }
410 
411 
412 void WX_VIEW_CONTROLS::SetGrabMouse( bool aEnabled )
413 {
414  if( aEnabled && !m_settings.m_grabMouse )
415  m_parentPanel->CaptureMouse();
416  else if( !aEnabled && m_settings.m_grabMouse )
417  m_parentPanel->ReleaseMouse();
418 
419  VIEW_CONTROLS::SetGrabMouse( aEnabled );
420 }
421 
422 
423 VECTOR2D WX_VIEW_CONTROLS::GetMousePosition( bool aWorldCoordinates ) const
424 {
425  wxPoint msp = getMouseScreenPosition();
426  VECTOR2D screenPos( msp.x, msp.y );
427 
428  return aWorldCoordinates ? m_view->ToWorld( screenPos ) : screenPos;
429 }
430 
431 
433 {
434  if( aEnableSnapping )
435  {
436  return m_view->GetGAL()->GetGridPoint( m_cursorPos );
437  }
438  else
439  {
440  return m_cursorPos;
441  }
442 }
443 
444 
445 VECTOR2D WX_VIEW_CONTROLS::GetCursorPosition( bool aEnableSnapping ) const
446 {
448  {
450  }
451  else
452  {
453  return GetRawCursorPosition( aEnableSnapping );
454  }
455 }
456 
457 
458 void WX_VIEW_CONTROLS::SetCursorPosition( const VECTOR2D& aPosition, bool aWarpView,
459  bool aTriggeredByArrows )
460 {
461  m_updateCursor = false;
462 
463  if( aTriggeredByArrows )
464  {
467  m_cursorWarped = false;
468  }
469  else
470  {
472  m_cursorWarped = true;
473  }
474 
475  WarpCursor( aPosition, true, aWarpView );
476  m_cursorPos = aPosition;
477 }
478 
479 
480 void WX_VIEW_CONTROLS::SetCrossHairCursorPosition( const VECTOR2D& aPosition, bool aWarpView = true )
481 {
482  m_updateCursor = false;
483 
484  const VECTOR2I& screenSize = m_view->GetGAL()->GetScreenPixelSize();
485  BOX2I screen( VECTOR2I( 0, 0 ), screenSize );
486  VECTOR2D screenPos = m_view->ToScreen( aPosition );
487 
488  if( aWarpView && !screen.Contains( screenPos ) )
489  m_view->SetCenter( aPosition );
490 
491  m_cursorPos = aPosition;
492 }
493 
494 
495 void WX_VIEW_CONTROLS::WarpCursor( const VECTOR2D& aPosition, bool aWorldCoordinates,
496  bool aWarpView )
497 {
498  if( aWorldCoordinates )
499  {
500  const VECTOR2I& screenSize = m_view->GetGAL()->GetScreenPixelSize();
501  BOX2I screen( VECTOR2I( 0, 0 ), screenSize );
502  VECTOR2D screenPos = m_view->ToScreen( aPosition );
503 
504  if( !screen.Contains( screenPos ) )
505  {
506  if( aWarpView )
507  {
508  m_view->SetCenter( aPosition );
509  m_parentPanel->WarpPointer( screenSize.x / 2, screenSize.y / 2 );
510  }
511  }
512  else
513  {
514  m_parentPanel->WarpPointer( screenPos.x, screenPos.y );
515  }
516  }
517  else
518  {
519  m_parentPanel->WarpPointer( aPosition.x, aPosition.y );
520  }
521 
522  refreshMouse();
523 }
524 
525 
527 {
528  const VECTOR2I& screenSize = m_view->GetGAL()->GetScreenPixelSize();
529  VECTOR2I screenCenter( screenSize / 2 );
530 
531  if( GetMousePosition( false ) != screenCenter )
532  {
534  m_parentPanel->WarpPointer( KiROUND( screenSize.x / 2 ), KiROUND( screenSize.y / 2 ) );
535  }
536 }
537 
538 
539 bool WX_VIEW_CONTROLS::handleAutoPanning( const wxMouseEvent& aEvent )
540 {
541  VECTOR2I p( aEvent.GetX(), aEvent.GetY() );
543 
545  {
546  // last cursor move event came from keyboard cursor control. If auto-panning is enabled and
547  // the next position is inside the autopan zone, check if it really came from a mouse event, otherwise
548  // disable autopan temporarily. Also temporaly disable autopan if the cursor is in the autopan zone
549  // because the application warped the cursor.
550 
551  m_cursorWarped = false;
552  return true;
553  }
554 
555  m_cursorWarped = false;
556 
557  // Compute areas where autopanning is active
560  int borderEndX = m_view->GetScreenPixelSize().x - borderStart;
561  int borderEndY = m_view->GetScreenPixelSize().y - borderStart;
562 
563  if( p.x < borderStart )
564  m_panDirection.x = -( borderStart - p.x );
565  else if( p.x > borderEndX )
566  m_panDirection.x = ( p.x - borderEndX );
567  else
568  m_panDirection.x = 0;
569 
570  if( p.y < borderStart )
571  m_panDirection.y = -( borderStart - p.y );
572  else if( p.y > borderEndY )
573  m_panDirection.y = ( p.y - borderEndY );
574  else
575  m_panDirection.y = 0;
576 
577  bool borderHit = ( m_panDirection.x != 0 || m_panDirection.y != 0 );
578 
579  switch( m_state )
580  {
581  case AUTO_PANNING:
582  if( !borderHit )
583  {
584  m_panTimer.Stop();
585  m_state = IDLE;
586 
587  return false;
588  }
589 
590  return true;
591  break;
592 
593  case IDLE:
594  if( borderHit )
595  {
597  m_panTimer.Start( (int) ( 250.0 / 60.0 ) );
598 
599  return true;
600  }
601 
602  return false;
603  break;
604 
605  case DRAG_PANNING:
606  return false;
607  }
608 
609  wxASSERT_MSG( false, wxT( "This line should never be reached" ) );
610  return false; // Should not be reached, just avoid the compiler warnings..
611 }
612 
613 
615 {
616  // Notify tools that the cursor position has changed in the world coordinates
617  wxMouseEvent moveEvent( EVT_REFRESH_MOUSE );
618  wxPoint msp = getMouseScreenPosition();
619  moveEvent.SetX( msp.x );
620  moveEvent.SetY( msp.y );
621 
622  // Set the modifiers state
623 #if wxCHECK_VERSION( 3, 0, 0 )
624  moveEvent.SetControlDown( wxGetKeyState( WXK_CONTROL ) );
625  moveEvent.SetShiftDown( wxGetKeyState( WXK_SHIFT ) );
626  moveEvent.SetAltDown( wxGetKeyState( WXK_ALT ) );
627 #else
628  // wx <3.0 do not have accessors, but the fields are exposed
629  moveEvent.m_controlDown = wxGetKeyState( WXK_CONTROL );
630  moveEvent.m_shiftDown = wxGetKeyState( WXK_SHIFT );
631  moveEvent.m_altDown = wxGetKeyState( WXK_ALT );
632 #endif
633 
634  m_cursorPos = m_view->ToWorld( VECTOR2D( msp.x, msp.y ) );
635  wxPostEvent( m_parentPanel, moveEvent );
636 }
637 
638 
640 {
641  wxPoint msp = wxGetMousePosition();
642  m_parentPanel->ScreenToClient( &msp.x, &msp.y );
643  return msp;
644 }
645 
646 
648 {
649  const BOX2D viewport = m_view->GetViewport();
650  const BOX2D& boundary = m_view->GetBoundary();
651 
652  m_scrollScale.x = 2e3 / viewport.GetWidth(); // TODO it does not have to be updated so often
653  m_scrollScale.y = 2e3 / viewport.GetHeight();
654  VECTOR2I newScroll( ( viewport.Centre().x - boundary.GetLeft() ) * m_scrollScale.x,
655  ( viewport.Centre().y - boundary.GetTop() ) * m_scrollScale.y );
656 
657  // Flip scroll direction in flipped view
658  if( m_view->IsMirroredX() )
659  newScroll.x = ( boundary.GetRight() - viewport.Centre().x ) * m_scrollScale.x;
660 
661  // Adjust scrollbars only if it is needed. Otherwise there are cases when canvas is continuosly
662  // refreshed (Windows)
663  if( m_scrollPos != newScroll )
664  {
665  // Another example of wxWidgets being broken by design: scroll position is determined by the
666  // left (or top, if vertical) edge of the slider. Fortunately, slider size seems to be constant
667  // (at least for wxGTK and wxMSW), so we have to add its size to allow user to scroll the workspace
668  // till the end.
669 
670  m_parentPanel->SetScrollbars( 1, 1,
671 #if defined(__LINUX__)
672  m_scrollScale.x * boundary.GetWidth() + 1623, m_scrollScale.y * boundary.GetHeight() + 1623,
673 #elif defined(__WIN32__) || defined(__WIN64__)
674  m_scrollScale.x * boundary.GetWidth() + 1377, m_scrollScale.y * boundary.GetHeight() + 741,
675 #else
676  m_scrollScale.x * boundary.GetWidth(), m_scrollScale.y * boundary.GetHeight(),
677 #endif
678  newScroll.x, newScroll.y, false );
679 
680  m_scrollPos = newScroll;
681  }
682 }
683 
684 void WX_VIEW_CONTROLS::ForceCursorPosition( bool aEnabled, const VECTOR2D& aPosition )
685 {
687  m_settings.m_forcedPosition = aPosition;
688 }
bool m_enableMousewheelPan
Mousewheel (2-finger touchpad) panning
Definition: view_controls.h:88
VECTOR2D m_lookStartPoint
Stores information about the center of viewport when dragging has started.
BOX2D GetViewport() const
Function GetViewport() Returns the current viewport visible area rectangle.
Definition: view.cpp:538
float m_autoPanSpeed
How fast is panning when in auto mode
Definition: view_controls.h:82
static const int dist[10][10]
Definition: ar_matrix.cpp:320
Class CAIRO_GAL is the cairo implementation of the graphics abstraction layer.
Definition: class_module.h:57
static int KiROUND(double v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: common.h:121
const BOX2D & GetBoundary() const
Function GetBoundary()
Definition: view.h:298
static std::unique_ptr< ZOOM_CONTROLLER > GetZoomControllerForPlatform()
static const wxEventType EVT_REFRESH_MOUSE
Event that forces mouse move event in the dispatcher (eg.
VECTOR2D ToWorld(const VECTOR2D &aCoord, bool aAbsolute=true) const
Function ToWorld() Converts a screen space point/vector to a point/vector in world space coordinates.
Definition: view.cpp:475
coord_type GetTop() const
Definition: box2.h:202
const VECTOR2D & GetCenter() const
Function GetCenter() Returns the center point of this VIEW (in world space coordinates)
Definition: view.h:339
wxPoint getMouseScreenPosition() const
Gets the cursor position in the screen coordinates.
bool m_grabMouse
Flag for grabbing the mouse cursor
Definition: view_controls.h:70
VECTOR2D GetMousePosition(bool aWorldCoordinates=true) const override
Function GetMousePosition() Returns the current mouse pointer position.
std::unique_ptr< ZOOM_CONTROLLER > m_zoomController
a ZOOM_CONTROLLER that determines zoom steps. This is platform-specific.
void onButton(wxMouseEvent &aEvent)
long int m_lastTimestamp
Last event timestamp to remove duplicates.
VC_SETTINGS m_settings
Current VIEW_CONTROLS settings
VECTOR2D m_forcedPosition
Forced cursor position (world coordinates)
Definition: view_controls.h:58
coord_type GetRight() const
Definition: box2.h:197
GAL * GetGAL() const
Function GetGAL() Returns the GAL this view is using to draw graphical primitives.
Definition: view.h:180
bool m_panWithRightButton
Allow panning with the right button in addition to middle
Definition: view_controls.h:91
VIEW * m_view
Pointer to controlled VIEW.
VECTOR2< int > VECTOR2I
Definition: vector2d.h:587
void SetScale(double aScale)
Function SetScale() Sets the scaling factor.
Definition: view.h:250
VECTOR2D m_scrollScale
Ratio used for scaling world coordinates to scrollbar position.
static const int delta[8][2]
Definition: solve.cpp:112
WX_VIEW_CONTROLS class definition.
static constexpr double GTK3_SCALE
A suitable (magic) scale factor for GTK3 systems.
void UpdateScrollbars()
Adjusts the scrollbars position to match the current viewport.
VECTOR2D GetGridPoint(const VECTOR2D &aPoint) const
Function GetGridPoint() For a given point it returns the nearest point belonging to the grid in world...
const VECTOR2I & GetScreenPixelSize() const
Returns GAL canvas size in pixels.
VECTOR2D m_lastKeyboardCursorPosition
Position of the above event
VECTOR2D GetRawCursorPosition(bool aSnappingEnabled=true) const override
Returns the current cursor position in world coordinates - ingoring the cursorUp position force mode.
bool m_autoPanSettingEnabled
Flag for turning on autopanning
Definition: view_controls.h:76
void onWheel(wxMouseEvent &aEvent)
Handler functions.
void SetCenter(const VECTOR2D &aCenter)
Function SetCenter() Sets the center point of the VIEW (i.e.
Definition: view.cpp:601
Panning with mouse button pressed.
bool m_forceCursorPosition
Is the forced cursor position enabled
Definition: view_controls.h:61
VECTOR2< double > VECTOR2D
Definition: vector2d.h:586
coord_type GetWidth() const
Definition: box2.h:195
bool Contains(const Vec &aPoint) const
Function Contains.
Definition: box2.h:149
void SetCrossHairCursorPosition(const VECTOR2D &aPosition, bool aWarpView) override
Moves the graphic crosshair cursor to the requested position expressed in world coordinates.
const VECTOR2I & GetScreenPixelSize() const
Function GetScreenPixelSize() Returns the size of the our rendering area, in pixels.
Definition: view.cpp:1176
bool IsCursorWarpingEnabled() const
Function IsCursorWarpingEnabled()
Class VIEW_CONTROLS is an interface for classes handling user events controlling the view behaviour (...
static constexpr double MAC_SCALE
A suitable (magic) scale factor for Mac systems.
float m_autoPanMargin
Distance from cursor to VIEW edge when panning is active
Definition: view_controls.h:79
void SetGrabMouse(bool aEnabled) override
Function SetGrabMouse() Enables/disables mouse cursor grabbing (limits the movement field only to the...
bool m_cursorWarped
Application warped the cursor, not the user (keyboard)
void refreshMouse()
Sends an event to refresh mouse position.
VECTOR2D ToScreen(const VECTOR2D &aCoord, bool aAbsolute=true) const
Function ToScreen() Converts a world space point/vector to a point/vector in screen space coordinates...
Definition: view.cpp:494
bool m_autoPanEnabled
Flag for turning on autopanning
Definition: view_controls.h:73
void onMotion(wxMouseEvent &aEvent)
void WarpCursor(const VECTOR2D &aPosition, bool aWorldCoordinates=false, bool aWarpView=false) override
bool IsMirroredX() const
Function IsMirroredX() Returns true if view is flipped across the X axis.
Definition: view.h:230
void ForceCursorPosition(bool aEnabled, const VECTOR2D &aPosition=VECTOR2D(0, 0)) override
Function ForceCursorPosition() Places the cursor immediately at a given point.
wxScrolledCanvas * m_parentPanel
Panel that is affected by VIEW_CONTROLS.
void onTimer(wxTimerEvent &WXUNUSED(aEvent))
Vec Centre() const
Definition: box2.h:77
VECTOR2D m_panDirection
Current direction of panning (only autopanning mode)
bool m_updateCursor
Flag deciding whether the cursor position should be calculated using the mouse position.
bool m_lastKeyboardCursorPositionValid
Is last cursor motion event coming from keyboard arrow cursor motion action
Definition: view_controls.h:97
virtual void SetGrabMouse(bool aEnabled)
Function SetGrabMouse Turns on/off mouse grabbing.
VECTOR2I m_scrollPos
Current scrollbar position.
coord_type GetHeight() const
Definition: box2.h:196
WX_VIEW_CONTROLS(VIEW *aView, wxScrolledCanvas *aParentPanel)
bool handleAutoPanning(const wxMouseEvent &aEvent)
Function handleAutoPanning() Computes new viewport settings while in autopanning mode.
void onEnter(wxMouseEvent &WXUNUSED(aEvent))
VECTOR2D m_dragStartPoint
Stores information about point where dragging has started.
STATE m_state
Current state of VIEW_CONTROLS.
coord_type GetLeft() const
Definition: box2.h:201
Class VIEW.
Definition: view.h:61
double GetScale() const
Function GetScale()
Definition: view.h:268
void CenterOnCursor() const override
Function CenterOnCursor() Sets the viewport center to the current cursor position and warps the curso...
bool m_cursorCaptured
Should the cursor be locked within the parent window area
Definition: view_controls.h:64
void onScroll(wxScrollWinEvent &aEvent)
void SetCursorPosition(const VECTOR2D &aPosition, bool warpView, bool aTriggeredByArrows) override
Moves cursor to the requested position expressed in world coordinates.
VECTOR2D GetCursorPosition() const
Returns the current cursor position in world coordinates.
#define min(a, b)
Definition: auxiliary.h:85
void onLeave(wxMouseEvent &WXUNUSED(aEvent))
VECTOR2D m_cursorPos
Current cursor position (world coordinates)
wxTimer m_panTimer
Timer repsonsible for handling autopanning.
bool m_panWithLeftButton
Allow panning with the left button in addition to middle
Definition: view_controls.h:94