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