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>
32 #include <tool/tool_dispatcher.h>
33 
34 using namespace KIGFX;
35 
36 const wxEventType WX_VIEW_CONTROLS::EVT_REFRESH_MOUSE = wxNewEventType();
37 
38 WX_VIEW_CONTROLS::WX_VIEW_CONTROLS( VIEW* aView, wxScrolledCanvas* aParentPanel ) :
39  VIEW_CONTROLS( aView ), m_state( IDLE ), m_parentPanel( aParentPanel ),
40  m_scrollScale( 1.0, 1.0 ), m_cursorPos( 0, 0 ), m_updateCursor( true )
41 {
42  m_parentPanel->Connect( wxEVT_MOTION,
43  wxMouseEventHandler( WX_VIEW_CONTROLS::onMotion ), NULL, this );
44 #if wxCHECK_VERSION( 3, 1, 0 ) || defined( USE_OSX_MAGNIFY_EVENT )
45  m_parentPanel->Connect( wxEVT_MAGNIFY,
46  wxMouseEventHandler( WX_VIEW_CONTROLS::onMagnify ), NULL, this );
47 #endif
48  m_parentPanel->Connect( wxEVT_MOUSEWHEEL,
49  wxMouseEventHandler( WX_VIEW_CONTROLS::onWheel ), NULL, this );
50  m_parentPanel->Connect( wxEVT_MIDDLE_UP,
51  wxMouseEventHandler( WX_VIEW_CONTROLS::onButton ), NULL, this );
52  m_parentPanel->Connect( wxEVT_MIDDLE_DOWN,
53  wxMouseEventHandler( WX_VIEW_CONTROLS::onButton ), NULL, this );
54  m_parentPanel->Connect( wxEVT_LEFT_UP,
55  wxMouseEventHandler( WX_VIEW_CONTROLS::onButton ), NULL, this );
56  m_parentPanel->Connect( wxEVT_LEFT_DOWN,
57  wxMouseEventHandler( WX_VIEW_CONTROLS::onButton ), NULL, this );
58  m_parentPanel->Connect( wxEVT_RIGHT_UP,
59  wxMouseEventHandler( WX_VIEW_CONTROLS::onButton ), NULL, this );
60  m_parentPanel->Connect( wxEVT_RIGHT_DOWN,
61  wxMouseEventHandler( WX_VIEW_CONTROLS::onButton ), NULL, this );
62 #if defined _WIN32 || defined _WIN64
63  m_parentPanel->Connect( wxEVT_ENTER_WINDOW,
64  wxMouseEventHandler( WX_VIEW_CONTROLS::onEnter ), NULL, this );
65 #endif
66  m_parentPanel->Connect( wxEVT_LEAVE_WINDOW,
67  wxMouseEventHandler( WX_VIEW_CONTROLS::onLeave ), NULL, this );
68  m_parentPanel->Connect( wxEVT_SCROLLWIN_THUMBTRACK,
69  wxScrollWinEventHandler( WX_VIEW_CONTROLS::onScroll ), NULL, this );
70  m_parentPanel->Connect( wxEVT_SCROLLWIN_PAGEUP,
71  wxScrollWinEventHandler( WX_VIEW_CONTROLS::onScroll ), NULL, this );
72  m_parentPanel->Connect( wxEVT_SCROLLWIN_PAGEDOWN,
73  wxScrollWinEventHandler( WX_VIEW_CONTROLS::onScroll ), NULL, this );
74 
75  m_panTimer.SetOwner( this );
76  this->Connect( wxEVT_TIMER,
77  wxTimerEventHandler( WX_VIEW_CONTROLS::onTimer ), NULL, this );
78 }
79 
80 
81 void WX_VIEW_CONTROLS::onMotion( wxMouseEvent& aEvent )
82 {
83  bool isAutoPanning = false;
84  VECTOR2D mousePos( aEvent.GetX(), aEvent.GetY() );
85 
87  isAutoPanning = handleAutoPanning( aEvent );
88 
89  if( !isAutoPanning && aEvent.Dragging() )
90  {
91  if( m_state == DRAG_PANNING )
92  {
93  VECTOR2D d = m_dragStartPoint - mousePos;
94  VECTOR2D delta = m_view->ToWorld( d, false );
95 
96  m_view->SetCenter( m_lookStartPoint + delta );
97  aEvent.StopPropagation();
98  }
99  }
100 
101  if( m_updateCursor ) // do not update the cursor position if it was explicitly set
102  m_cursorPos = m_view->ToWorld( mousePos );
103  else
104  m_updateCursor = true;
105 
106  aEvent.Skip();
107 }
108 
109 
110 void WX_VIEW_CONTROLS::onWheel( wxMouseEvent& aEvent )
111 {
112  const double wheelPanSpeed = 0.001;
113  const double zoomLevelScale = 1.2; // The minimal step value when changing the current zoom level
114 
115  // mousewheelpan disabled:
116  // wheel + ctrl -> horizontal scrolling;
117  // wheel + shift -> vertical scrolling;
118  // wheel -> zooming;
119  // mousewheelpan enabled:
120  // wheel -> pan;
121  // wheel + ctrl -> zooming;
122  // wheel + shift -> horizontal scrolling.
123 
124  if( ( !m_settings.m_enableMousewheelPan && ( aEvent.ControlDown() || aEvent.ShiftDown() ) ) ||
125  ( m_settings.m_enableMousewheelPan && !aEvent.ControlDown() ) )
126  {
127  // Scrolling
128  VECTOR2D scrollVec = m_view->ToWorld( m_view->GetScreenPixelSize(), false ) *
129  ( (double) aEvent.GetWheelRotation() * wheelPanSpeed );
130  int axis = aEvent.GetWheelAxis();
131  double scrollX = 0.0;
132  double scrollY = 0.0;
133 
135  {
136  if ( axis == wxMOUSE_WHEEL_HORIZONTAL || aEvent.ShiftDown() )
137  scrollX = scrollVec.x;
138  else
139  scrollY = -scrollVec.y;
140  }
141  else
142  {
143  if( aEvent.ControlDown() )
144  scrollX = -scrollVec.x;
145  else
146  scrollY = -scrollVec.y;
147  }
148 
149  VECTOR2D delta( scrollX, scrollY );
150 
152  refreshMouse();
153  }
154  else
155  {
156  // Zooming
157  wxLongLong timeStamp = wxGetLocalTimeMillis();
158  double timeDiff = timeStamp.ToDouble() - m_timeStamp.ToDouble();
159  int rotation = aEvent.GetWheelRotation();
160  double zoomScale = 1.0;
161 
162 #ifdef __WXMAC__
163  // On Apple pointer devices, wheel events occur frequently and with
164  // smaller rotation values. For those devices, let's handle zoom
165  // based on the rotation amount rather than the time difference.
166 
167  // Unused
168  ( void )timeDiff;
169 
170  rotation = ( rotation > 0 ) ? std::min( rotation , 100 )
171  : std::max( rotation , -100 );
172 
173  double dscale = rotation * 0.01;
174  zoomScale = ( rotation > 0 ) ? (1 + dscale) : 1/(1 - dscale);
175 
176 #else
177 
178  m_timeStamp = timeStamp;
179 
180  // Set scaling speed depending on scroll wheel event interval
181  if( timeDiff < 500 && timeDiff > 0 )
182  {
183  zoomScale = 2.05 - timeDiff / 500;
184 
185  // be sure zoomScale value is significant
186  zoomScale = std::max( zoomScale, zoomLevelScale );
187 
188  if( rotation < 0 )
189  zoomScale = 1.0 / zoomScale;
190  }
191  else
192  {
193  zoomScale = ( rotation > 0 ) ? zoomLevelScale : 1/zoomLevelScale;
194  }
195 #endif
196 
197  if( IsCursorWarpingEnabled() )
198  {
199  CenterOnCursor();
200  m_view->SetScale( m_view->GetScale() * zoomScale );
201  }
202  else
203  {
204  VECTOR2D anchor = m_view->ToWorld( VECTOR2D( aEvent.GetX(), aEvent.GetY() ) );
205  m_view->SetScale( m_view->GetScale() * zoomScale, anchor );
206  }
207  }
208 
209  aEvent.Skip();
210 }
211 
212 
213 #if wxCHECK_VERSION( 3, 1, 0 ) || defined( USE_OSX_MAGNIFY_EVENT )
214 void WX_VIEW_CONTROLS::onMagnify( wxMouseEvent& aEvent )
215 {
216  // Scale based on the magnification from our underlying magnification event.
217  VECTOR2D anchor = m_view->ToWorld( VECTOR2D( aEvent.GetX(), aEvent.GetY() ) );
218  m_view->SetScale( m_view->GetScale() * ( aEvent.GetMagnification() + 1.0f ), anchor );
219 
220  aEvent.Skip();
221 }
222 #endif
223 
224 
225 void WX_VIEW_CONTROLS::onButton( wxMouseEvent& aEvent )
226 {
227  switch( m_state )
228  {
229  case IDLE:
230  case AUTO_PANNING:
231  if( aEvent.MiddleDown() ||
232  ( aEvent.LeftDown() && m_settings.m_panWithLeftButton ) ||
233  ( aEvent.RightDown() && m_settings.m_panWithRightButton ) )
234  {
235  m_dragStartPoint = VECTOR2D( aEvent.GetX(), aEvent.GetY() );
238  }
239 
240  if( aEvent.LeftUp() )
241  m_state = IDLE; // Stop autopanning when user release left mouse button
242 
243  break;
244 
245  case DRAG_PANNING:
246  if( aEvent.MiddleUp() || aEvent.LeftUp() || aEvent.RightUp() )
247  m_state = IDLE;
248 
249  break;
250  }
251 
252  aEvent.Skip();
253 }
254 
255 
256 void WX_VIEW_CONTROLS::onEnter( wxMouseEvent& aEvent )
257 {
258  m_parentPanel->SetFocus();
259 }
260 
261 
262 void WX_VIEW_CONTROLS::onLeave( wxMouseEvent& aEvent )
263 {
265  {
266  bool warp = false;
267  int x = aEvent.GetX();
268  int y = aEvent.GetY();
269  wxSize parentSize = m_parentPanel->GetClientSize();
270 
271  if( x < 0 )
272  {
273  x = 0;
274  warp = true;
275  }
276  else if( x >= parentSize.x )
277  {
278  x = parentSize.x - 1;
279  warp = true;
280  }
281 
282  if( y < 0 )
283  {
284  y = 0;
285  warp = true;
286  }
287  else if( y >= parentSize.y )
288  {
289  y = parentSize.y - 1;
290  warp = true;
291  }
292 
293  if( warp )
294  m_parentPanel->WarpPointer( x, y );
295  }
296 }
297 
298 
299 void WX_VIEW_CONTROLS::onTimer( wxTimerEvent& aEvent )
300 {
301  switch( m_state )
302  {
303  case AUTO_PANNING:
304  {
306  {
307  m_state = IDLE;
308  return;
309  }
310 
311 #if wxCHECK_VERSION( 3, 0, 0 )
312  if( !m_parentPanel->HasFocus() )
313  break;
314 #endif
315 
316  double borderSize = std::min( m_settings.m_autoPanMargin * m_view->GetScreenPixelSize().x,
318 
319  VECTOR2D dir( m_panDirection );
320 
321  if( dir.EuclideanNorm() > borderSize )
322  dir = dir.Resize( borderSize );
323 
324  dir = m_view->ToWorld( dir, false );
326 
327  refreshMouse();
328  }
329  break;
330 
331  case IDLE: // Just remove unnecessary warnings
332  case DRAG_PANNING:
333  break;
334  }
335 }
336 
337 
338 void WX_VIEW_CONTROLS::onScroll( wxScrollWinEvent& aEvent )
339 {
340  const double linePanDelta = 0.05;
341  const double pagePanDelta = 0.5;
342 
343  int type = aEvent.GetEventType();
344  int dir = aEvent.GetOrientation();
345 
346  if( type == wxEVT_SCROLLWIN_THUMBTRACK )
347  {
348  auto center = m_view->GetCenter();
349  const auto& boundary = m_view->GetBoundary();
350 
351  // Flip scroll direction in flipped view
352  const double xstart = ( m_view->IsMirroredX() ?
353  boundary.GetRight() : boundary.GetLeft() );
354  const double xdelta = ( m_view->IsMirroredX() ? -1 : 1 );
355 
356  if( dir == wxHORIZONTAL )
357  center.x = xstart + xdelta * ( aEvent.GetPosition() / m_scrollScale.x );
358  else
359  center.y = boundary.GetTop() + aEvent.GetPosition() / m_scrollScale.y;
360 
361  m_view->SetCenter( center );
362  }
363  else
364  {
365  double dist = 0;
366 
367  if( type == wxEVT_SCROLLWIN_PAGEUP )
368  dist = pagePanDelta;
369  else if( type == wxEVT_SCROLLWIN_PAGEDOWN )
370  dist = -pagePanDelta;
371  else if( type == wxEVT_SCROLLWIN_LINEUP )
372  dist = linePanDelta;
373  else if( type == wxEVT_SCROLLWIN_LINEDOWN )
374  dist = -linePanDelta;
375  else
376  {
377  wxASSERT( "Unhandled event type" );
378  return;
379  }
380 
381  VECTOR2D scroll = m_view->ToWorld( m_view->GetScreenPixelSize(), false ) * dist;
382 
383  double scrollX = 0.0;
384  double scrollY = 0.0;
385 
386  if ( dir == wxHORIZONTAL )
387  scrollX = -scroll.x;
388  else
389  scrollY = -scroll.y;
390 
391  VECTOR2D delta( scrollX, scrollY );
392 
394  }
395 
396  m_parentPanel->Refresh();
397 }
398 
399 
400 void WX_VIEW_CONTROLS::SetGrabMouse( bool aEnabled )
401 {
402  if( aEnabled && !m_settings.m_grabMouse )
403  m_parentPanel->CaptureMouse();
404  else if( !aEnabled && m_settings.m_grabMouse )
405  m_parentPanel->ReleaseMouse();
406 
407  VIEW_CONTROLS::SetGrabMouse( aEnabled );
408 }
409 
410 
411 VECTOR2D WX_VIEW_CONTROLS::GetMousePosition( bool aWorldCoordinates ) const
412 {
414  VECTOR2D screenPos( msp.x, msp.y );
415 
416  return aWorldCoordinates ? m_view->ToWorld( screenPos ) : screenPos;
417 }
418 
419 
421 {
422  if( aEnableSnapping )
423  {
424  return m_view->GetGAL()->GetGridPoint( m_cursorPos );
425  }
426  else
427  {
428  return m_cursorPos;
429  }
430 }
431 
432 
433 VECTOR2D WX_VIEW_CONTROLS::GetCursorPosition( bool aEnableSnapping ) const
434 {
436  {
438  }
439  else
440  {
441  return GetRawCursorPosition( aEnableSnapping );
442  }
443 }
444 
445 
446 void WX_VIEW_CONTROLS::SetCursorPosition( const VECTOR2D& aPosition, bool aWarpView )
447 {
448  m_updateCursor = false;
449  WarpCursor( aPosition, true, aWarpView );
450  m_cursorPos = aPosition;
451 }
452 
453 
454 void WX_VIEW_CONTROLS::SetCrossHairCursorPosition( const VECTOR2D& aPosition, bool aWarpView = true )
455 {
456  m_updateCursor = false;
457 
458  const VECTOR2I& screenSize = m_view->GetGAL()->GetScreenPixelSize();
459  BOX2I screen( VECTOR2I( 0, 0 ), screenSize );
460  VECTOR2D screenPos = m_view->ToScreen( aPosition );
461 
462  if( aWarpView && !screen.Contains( screenPos ) )
463  m_view->SetCenter( aPosition );
464 
465  m_cursorPos = aPosition;
466 }
467 
468 
469 void WX_VIEW_CONTROLS::WarpCursor( const VECTOR2D& aPosition, bool aWorldCoordinates,
470  bool aWarpView )
471 {
472  if( aWorldCoordinates )
473  {
474  const VECTOR2I& screenSize = m_view->GetGAL()->GetScreenPixelSize();
475  BOX2I screen( VECTOR2I( 0, 0 ), screenSize );
476  VECTOR2D screenPos = m_view->ToScreen( aPosition );
477 
478  if( !screen.Contains( screenPos ) )
479  {
480  if( aWarpView )
481  {
482  m_view->SetCenter( aPosition );
483  m_parentPanel->WarpPointer( screenSize.x / 2, screenSize.y / 2 );
484  }
485  }
486  else
487  {
488  m_parentPanel->WarpPointer( screenPos.x, screenPos.y );
489  }
490  }
491  else
492  {
493  m_parentPanel->WarpPointer( aPosition.x, aPosition.y );
494  }
495 
496  refreshMouse();
497 }
498 
499 
501 {
502  const VECTOR2I& screenSize = m_view->GetGAL()->GetScreenPixelSize();
503  VECTOR2I screenCenter( screenSize / 2 );
504 
505  if( GetMousePosition( false ) != screenCenter )
506  {
508  m_parentPanel->WarpPointer( KiROUND( screenSize.x / 2 ), KiROUND( screenSize.y / 2 ) );
509  }
510 }
511 
512 
513 bool WX_VIEW_CONTROLS::handleAutoPanning( const wxMouseEvent& aEvent )
514 {
515  VECTOR2D p( aEvent.GetX(), aEvent.GetY() );
516 
517  // Compute areas where autopanning is active
518  double borderStart = std::min( m_settings.m_autoPanMargin * m_view->GetScreenPixelSize().x,
520  double borderEndX = m_view->GetScreenPixelSize().x - borderStart;
521  double borderEndY = m_view->GetScreenPixelSize().y - borderStart;
522 
523  if( p.x < borderStart )
524  m_panDirection.x = -( borderStart - p.x );
525  else if( p.x > borderEndX )
526  m_panDirection.x = ( p.x - borderEndX );
527  else
528  m_panDirection.x = 0;
529 
530  if( p.y < borderStart )
531  m_panDirection.y = -( borderStart - p.y );
532  else if( p.y > borderEndY )
533  m_panDirection.y = ( p.y - borderEndY );
534  else
535  m_panDirection.y = 0;
536 
537  bool borderHit = ( m_panDirection.x != 0 || m_panDirection.y != 0 );
538 
539  switch( m_state )
540  {
541  case AUTO_PANNING:
542  if( !borderHit )
543  {
544  m_panTimer.Stop();
545  m_state = IDLE;
546 
547  return false;
548  }
549 
550  return true;
551  break;
552 
553  case IDLE:
554  if( borderHit )
555  {
557  m_panTimer.Start( (int) ( 250.0 / 60.0 ) );
558 
559  return true;
560  }
561 
562  return false;
563  break;
564 
565  case DRAG_PANNING:
566  return false;
567  }
568 
569  wxASSERT_MSG( false, wxT( "This line should never be reached" ) );
570  return false; // Should not be reached, just avoid the compiler warnings..
571 }
572 
573 
575 {
576  // Notify tools that the cursor position has changed in the world coordinates
577  wxMouseEvent moveEvent( EVT_REFRESH_MOUSE );
579  moveEvent.SetX( msp.x );
580  moveEvent.SetY( msp.y );
581 
582  // Set the modifiers state
583 #if wxCHECK_VERSION( 3, 0, 0 )
584  moveEvent.SetControlDown( wxGetKeyState( WXK_CONTROL ) );
585  moveEvent.SetShiftDown( wxGetKeyState( WXK_SHIFT ) );
586  moveEvent.SetAltDown( wxGetKeyState( WXK_ALT ) );
587 #else
588  // wx <3.0 do not have accessors, but the fields are exposed
589  moveEvent.m_controlDown = wxGetKeyState( WXK_CONTROL );
590  moveEvent.m_shiftDown = wxGetKeyState( WXK_SHIFT );
591  moveEvent.m_altDown = wxGetKeyState( WXK_ALT );
592 #endif
593 
594  m_cursorPos = m_view->ToWorld( VECTOR2D( msp.x, msp.y ) );
595  wxPostEvent( m_parentPanel, moveEvent );
596 }
597 
598 
600 {
601  wxPoint msp = wxGetMousePosition();
602  m_parentPanel->ScreenToClient( &msp.x, &msp.y );
603  return msp;
604 }
605 
606 
608 {
609  const BOX2D viewport = m_view->GetViewport();
610  const BOX2D& boundary = m_view->GetBoundary();
611 
612  m_scrollScale.x = 2e3 / viewport.GetWidth(); // TODO it does not have to be updated so often
613  m_scrollScale.y = 2e3 / viewport.GetHeight();
614  VECTOR2I newScroll( ( viewport.Centre().x - boundary.GetLeft() ) * m_scrollScale.x,
615  ( viewport.Centre().y - boundary.GetTop() ) * m_scrollScale.y );
616 
617  // Flip scroll direction in flipped view
618  if( m_view->IsMirroredX() )
619  newScroll.x = ( boundary.GetRight() - viewport.Centre().x ) * m_scrollScale.x;
620 
621  // Adjust scrollbars only if it is needed. Otherwise there are cases when canvas is continuosly
622  // refreshed (Windows)
623  if( m_scrollPos != newScroll )
624  {
625  // Another example of wxWidgets being broken by design: scroll position is determined by the
626  // left (or top, if vertical) edge of the slider. Fortunately, slider size seems to be constant
627  // (at least for wxGTK and wxMSW), so we have to add its size to allow user to scroll the workspace
628  // till the end.
629 
630  m_parentPanel->SetScrollbars( 1, 1,
631 #if defined(__LINUX__)
632  m_scrollScale.x * boundary.GetWidth() + 1623, m_scrollScale.y * boundary.GetHeight() + 1623,
633 #elif defined(__WIN32__) || defined(__WIN64__)
634  m_scrollScale.x * boundary.GetWidth() + 1377, m_scrollScale.y * boundary.GetHeight() + 741,
635 #else
636  m_scrollScale.x * boundary.GetWidth(), m_scrollScale.y * boundary.GetHeight(),
637 #endif
638  newScroll.x, newScroll.y, false );
639 
640  m_scrollPos = newScroll;
641  }
642 }
bool m_enableMousewheelPan
Mousewheel (2-finger touchpad) panning
Definition: view_controls.h:88
const VECTOR2D & GetCenter() const
Function GetCenter() Returns the center point of this VIEW (in world space coordinates) ...
Definition: view.h:339
VECTOR2D m_lookStartPoint
Stores information about the center of viewport when dragging has started.
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
void SetCursorPosition(const VECTOR2D &aPosition, bool warpView) override
Moves cursor to the requested position expressed in world coordinates.
Class CAIRO_GAL is the cairo implementation of the graphics abstraction layer.
Definition: class_module.h:58
static int KiROUND(double v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: common.h:120
static const wxEventType EVT_REFRESH_MOUSE
Event that forces mouse move event in the dispatcher (eg.
bool IsMirroredX() const
Function IsMirroredX() Returns true if view is flipped across the X axis.
Definition: view.h:230
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.
bool Contains(const Vec &aPoint) const
Function Contains.
Definition: box2.h:149
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:473
void onButton(wxMouseEvent &aEvent)
VC_SETTINGS m_settings
Current VIEW_CONTROLS settings
coord_type GetRight() const
Definition: box2.h:197
VECTOR2D m_forcedPosition
Forced cursor position (world coordinates)
Definition: view_controls.h:58
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.
coord_type GetTop() const
Definition: box2.h:202
static const int delta[8][2]
Definition: solve.cpp:112
WX_VIEW_CONTROLS class definition.
void UpdateScrollbars()
Adjusts the scrollbars position to match the current viewport.
coord_type GetWidth() const
Definition: box2.h:195
wxPoint getMouseScreenPosition() const
Gets the cursor position in the screen coordinates.
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:599
Panning with mouse button pressed.
BOX2D GetViewport() const
Function GetViewport() Returns the current viewport visible area rectangle.
Definition: view.cpp:536
bool m_forceCursorPosition
Is the forced cursor position enabled
Definition: view_controls.h:61
VECTOR2< double > VECTOR2D
Definition: vector2d.h:586
GAL * GetGAL() const
Function GetGAL() Returns the GAL this view is using to draw graphical primitives.
Definition: view.h:180
VECTOR2D GetCursorPosition() const
Returns the current cursor position in world coordinates.
void SetCrossHairCursorPosition(const VECTOR2D &aPosition, bool aWarpView) override
Moves the graphic crosshair cursor to the requested position expressed in world coordinates.
const BOX2D & GetBoundary() const
Function GetBoundary()
Definition: view.h:298
Class VIEW_CONTROLS is an interface for classes handling user events controlling the view behaviour (...
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...
void refreshMouse()
Sends an event to refresh mouse position.
bool m_autoPanEnabled
Flag for turning on autopanning
Definition: view_controls.h:73
Vec Centre() const
Definition: box2.h:77
void onMotion(wxMouseEvent &aEvent)
void WarpCursor(const VECTOR2D &aPosition, bool aWorldCoordinates=false, bool aWarpView=false) override
const VECTOR2I & GetScreenPixelSize() const
Returns GAL canvas size in pixels.
coord_type GetHeight() const
Definition: box2.h:196
VECTOR2D GetGridPoint(const VECTOR2D &aPoint) const
Function GetGridPoint() For a given point it returns the nearest point belonging to the grid in world...
wxScrolledCanvas * m_parentPanel
Panel that is affected by VIEW_CONTROLS.
void onTimer(wxTimerEvent &WXUNUSED(aEvent))
#define max(a, b)
Definition: auxiliary.h:86
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.
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:492
bool IsCursorWarpingEnabled() const
Function IsCursorWarpingEnabled()
const VECTOR2I & GetScreenPixelSize() const
Function GetScreenPixelSize() Returns the size of the our rendering area, in pixels.
Definition: view.cpp:1167
virtual void SetGrabMouse(bool aEnabled)
Function SetGrabMouse Turns on/off mouse grabbing.
VECTOR2I m_scrollPos
Current scrollbar position.
WX_VIEW_CONTROLS(VIEW *aView, wxScrolledCanvas *aParentPanel)
bool handleAutoPanning(const wxMouseEvent &aEvent)
Function handleAutoPanning() Computes new viewport settings while in autopanning mode.
double GetScale() const
Function GetScale()
Definition: view.h:268
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
wxLongLong m_timeStamp
Used for determining time intervals between scroll & zoom events.
Class VIEW.
Definition: view.h:61
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)
#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