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  const double zoomLevelScale = 1.2; // The minimal step value when changing the current zoom level
118 
119  // mousewheelpan disabled:
120  // wheel + ctrl -> horizontal scrolling;
121  // wheel + shift -> vertical scrolling;
122  // wheel -> zooming;
123  // mousewheelpan enabled:
124  // wheel -> pan;
125  // wheel + ctrl -> zooming;
126  // wheel + shift -> horizontal scrolling.
127 
128  if( ( !m_settings.m_enableMousewheelPan && ( aEvent.ControlDown() || aEvent.ShiftDown() ) ) ||
129  ( m_settings.m_enableMousewheelPan && !aEvent.ControlDown() ) )
130  {
131  // Scrolling
132  VECTOR2D scrollVec = m_view->ToWorld( m_view->GetScreenPixelSize(), false ) *
133  ( (double) aEvent.GetWheelRotation() * wheelPanSpeed );
134  int axis = aEvent.GetWheelAxis();
135  double scrollX = 0.0;
136  double scrollY = 0.0;
137 
139  {
140  if ( axis == wxMOUSE_WHEEL_HORIZONTAL || aEvent.ShiftDown() )
141  scrollX = scrollVec.x;
142  else
143  scrollY = -scrollVec.y;
144  }
145  else
146  {
147  if( aEvent.ControlDown() )
148  scrollX = -scrollVec.x;
149  else
150  scrollY = -scrollVec.y;
151  }
152 
153  VECTOR2D delta( scrollX, scrollY );
154 
156  refreshMouse();
157  }
158  else
159  {
160  // Zooming
161  wxLongLong timeStamp = wxGetLocalTimeMillis();
162  double timeDiff = timeStamp.ToDouble() - m_timeStamp.ToDouble();
163  int rotation = aEvent.GetWheelRotation();
164  double zoomScale = 1.0;
165 
166 #ifdef __WXMAC__
167  // On Apple pointer devices, wheel events occur frequently and with
168  // smaller rotation values. For those devices, let's handle zoom
169  // based on the rotation amount rather than the time difference.
170 
171  // Unused
172  ( void )timeDiff;
173 
174  rotation = ( rotation > 0 ) ? std::min( rotation , 100 )
175  : std::max( rotation , -100 );
176 
177  double dscale = rotation * 0.01;
178  zoomScale = ( rotation > 0 ) ? (1 + dscale) : 1/(1 - dscale);
179 
180 #else
181 
182  m_timeStamp = timeStamp;
183 
184  // Set scaling speed depending on scroll wheel event interval
185  if( timeDiff < 500 && timeDiff > 0 )
186  {
187  zoomScale = 2.05 - timeDiff / 500;
188 
189  // be sure zoomScale value is significant
190  zoomScale = std::max( zoomScale, zoomLevelScale );
191 
192  if( rotation < 0 )
193  zoomScale = 1.0 / zoomScale;
194  }
195  else
196  {
197  zoomScale = ( rotation > 0 ) ? zoomLevelScale : 1/zoomLevelScale;
198  }
199 #endif
200 
201  if( IsCursorWarpingEnabled() )
202  {
203  CenterOnCursor();
204  m_view->SetScale( m_view->GetScale() * zoomScale );
205  }
206  else
207  {
208  VECTOR2D anchor = m_view->ToWorld( VECTOR2D( aEvent.GetX(), aEvent.GetY() ) );
209  m_view->SetScale( m_view->GetScale() * zoomScale, anchor );
210  }
211  }
212 
213  aEvent.Skip();
214 }
215 
216 
217 #if wxCHECK_VERSION( 3, 1, 0 ) || defined( USE_OSX_MAGNIFY_EVENT )
218 void WX_VIEW_CONTROLS::onMagnify( wxMouseEvent& aEvent )
219 {
220  // Scale based on the magnification from our underlying magnification event.
221  VECTOR2D anchor = m_view->ToWorld( VECTOR2D( aEvent.GetX(), aEvent.GetY() ) );
222  m_view->SetScale( m_view->GetScale() * ( aEvent.GetMagnification() + 1.0f ), anchor );
223 
224  aEvent.Skip();
225 }
226 #endif
227 
228 
229 void WX_VIEW_CONTROLS::onButton( wxMouseEvent& aEvent )
230 {
231  switch( m_state )
232  {
233  case IDLE:
234  case AUTO_PANNING:
235  if( aEvent.MiddleDown() ||
236  ( aEvent.LeftDown() && m_settings.m_panWithLeftButton ) ||
237  ( aEvent.RightDown() && m_settings.m_panWithRightButton ) )
238  {
239  m_dragStartPoint = VECTOR2D( aEvent.GetX(), aEvent.GetY() );
242  }
243 
244  if( aEvent.LeftUp() )
245  m_state = IDLE; // Stop autopanning when user release left mouse button
246 
247  break;
248 
249  case DRAG_PANNING:
250  if( aEvent.MiddleUp() || aEvent.LeftUp() || aEvent.RightUp() )
251  m_state = IDLE;
252 
253  break;
254  }
255 
256  aEvent.Skip();
257 }
258 
259 
260 void WX_VIEW_CONTROLS::onEnter( wxMouseEvent& aEvent )
261 {
262  m_parentPanel->SetFocus();
263 }
264 
265 
266 void WX_VIEW_CONTROLS::onLeave( wxMouseEvent& aEvent )
267 {
269  {
270  bool warp = false;
271  int x = aEvent.GetX();
272  int y = aEvent.GetY();
273  wxSize parentSize = m_parentPanel->GetClientSize();
274 
275  if( x < 0 )
276  {
277  x = 0;
278  warp = true;
279  }
280  else if( x >= parentSize.x )
281  {
282  x = parentSize.x - 1;
283  warp = true;
284  }
285 
286  if( y < 0 )
287  {
288  y = 0;
289  warp = true;
290  }
291  else if( y >= parentSize.y )
292  {
293  y = parentSize.y - 1;
294  warp = true;
295  }
296 
297  if( warp )
298  m_parentPanel->WarpPointer( x, y );
299  }
300 }
301 
302 
303 void WX_VIEW_CONTROLS::onTimer( wxTimerEvent& aEvent )
304 {
305  switch( m_state )
306  {
307  case AUTO_PANNING:
308  {
310  {
311  m_state = IDLE;
312  return;
313  }
314 
315 #if wxCHECK_VERSION( 3, 0, 0 )
316  if( !m_parentPanel->HasFocus() )
317  break;
318 #endif
319 
320  double borderSize = std::min( m_settings.m_autoPanMargin * m_view->GetScreenPixelSize().x,
322 
323  VECTOR2D dir( m_panDirection );
324 
325  if( dir.EuclideanNorm() > borderSize )
326  dir = dir.Resize( borderSize );
327 
328  dir = m_view->ToWorld( dir, false );
330 
331  refreshMouse();
332  }
333  break;
334 
335  case IDLE: // Just remove unnecessary warnings
336  case DRAG_PANNING:
337  break;
338  }
339 }
340 
341 
342 void WX_VIEW_CONTROLS::onScroll( wxScrollWinEvent& aEvent )
343 {
344  const double linePanDelta = 0.05;
345  const double pagePanDelta = 0.5;
346 
347  int type = aEvent.GetEventType();
348  int dir = aEvent.GetOrientation();
349 
350  if( type == wxEVT_SCROLLWIN_THUMBTRACK )
351  {
352  VECTOR2D center = m_view->GetCenter();
353  const BOX2I& boundary = m_view->GetBoundary();
354 
355  // Flip scroll direction in flipped view
356  const double xstart = ( m_view->IsMirroredX() ?
357  boundary.GetRight() : boundary.GetLeft() );
358  const double xdelta = ( m_view->IsMirroredX() ? -1 : 1 );
359 
360  if( dir == wxHORIZONTAL )
361  center.x = xstart + xdelta * ( aEvent.GetPosition() / m_scrollScale.x );
362  else
363  center.y = boundary.GetTop() + aEvent.GetPosition() / m_scrollScale.y;
364 
365  m_view->SetCenter( center );
366  }
367  else
368  {
369  double dist = 0;
370 
371  if( type == wxEVT_SCROLLWIN_PAGEUP )
372  dist = pagePanDelta;
373  else if( type == wxEVT_SCROLLWIN_PAGEDOWN )
374  dist = -pagePanDelta;
375  else if( type == wxEVT_SCROLLWIN_LINEUP )
376  dist = linePanDelta;
377  else if( type == wxEVT_SCROLLWIN_LINEDOWN )
378  dist = -linePanDelta;
379  else
380  {
381  wxASSERT( "Unhandled event type" );
382  return;
383  }
384 
385  VECTOR2D scroll = m_view->ToWorld( m_view->GetScreenPixelSize(), false ) * dist;
386 
387  double scrollX = 0.0;
388  double scrollY = 0.0;
389 
390  if ( dir == wxHORIZONTAL )
391  scrollX = -scroll.x;
392  else
393  scrollY = -scroll.y;
394 
395  VECTOR2D delta( scrollX, scrollY );
396 
398  }
399 
400  m_parentPanel->Refresh();
401 }
402 
403 
404 void WX_VIEW_CONTROLS::SetGrabMouse( bool aEnabled )
405 {
406  if( aEnabled && !m_settings.m_grabMouse )
407  m_parentPanel->CaptureMouse();
408  else if( !aEnabled && m_settings.m_grabMouse )
409  m_parentPanel->ReleaseMouse();
410 
411  VIEW_CONTROLS::SetGrabMouse( aEnabled );
412 }
413 
414 
415 VECTOR2D WX_VIEW_CONTROLS::GetMousePosition( bool aWorldCoordinates ) const
416 {
418  VECTOR2D screenPos( msp.x, msp.y );
419 
420  return aWorldCoordinates ? m_view->ToWorld( screenPos ) : screenPos;
421 }
422 
423 
425 {
426  if( aEnableSnapping )
427  {
428  return m_view->GetGAL()->GetGridPoint( m_cursorPos );
429  }
430  else
431  {
432  return m_cursorPos;
433  }
434 }
435 
436 
437 VECTOR2D WX_VIEW_CONTROLS::GetCursorPosition( bool aEnableSnapping ) const
438 {
440  {
442  }
443  else
444  {
445  return GetRawCursorPosition( aEnableSnapping );
446  }
447 }
448 
449 
450 void WX_VIEW_CONTROLS::SetCursorPosition( const VECTOR2D& aPosition, bool aWarpView )
451 {
452  m_updateCursor = false;
453  WarpCursor( aPosition, true, aWarpView );
454  m_cursorPos = aPosition;
455 }
456 
457 
458 void WX_VIEW_CONTROLS::SetCrossHairCursorPosition( const VECTOR2D& aPosition, bool aWarpView = true )
459 {
460  m_updateCursor = false;
461 
462  const VECTOR2I& screenSize = m_view->GetGAL()->GetScreenPixelSize();
463  BOX2I screen( VECTOR2I( 0, 0 ), screenSize );
464  VECTOR2D screenPos = m_view->ToScreen( aPosition );
465 
466  if( !screen.Contains( screenPos ) )
467  {
468  m_view->SetCenter( aPosition );
469  }
470 
471  m_cursorPos = aPosition;
472 }
473 
474 
475 void WX_VIEW_CONTROLS::WarpCursor( const VECTOR2D& aPosition, bool aWorldCoordinates,
476  bool aWarpView )
477 {
478  if( aWorldCoordinates )
479  {
480  const VECTOR2I& screenSize = m_view->GetGAL()->GetScreenPixelSize();
481  BOX2I screen( VECTOR2I( 0, 0 ), screenSize );
482  VECTOR2D screenPos = m_view->ToScreen( aPosition );
483 
484  if( !screen.Contains( screenPos ) )
485  {
486  if( aWarpView )
487  {
488  m_view->SetCenter( aPosition );
489  m_parentPanel->WarpPointer( screenSize.x / 2, screenSize.y / 2 );
490  }
491  }
492  else
493  {
494  m_parentPanel->WarpPointer( screenPos.x, screenPos.y );
495  }
496  }
497  else
498  {
499  m_parentPanel->WarpPointer( aPosition.x, aPosition.y );
500  }
501 
502  refreshMouse();
503 }
504 
505 
507 {
508  const VECTOR2I& screenSize = m_view->GetGAL()->GetScreenPixelSize();
509  VECTOR2I screenCenter( screenSize / 2 );
510 
511  if( GetMousePosition( false ) != screenCenter )
512  {
514  m_parentPanel->WarpPointer( KiROUND( screenSize.x / 2 ), KiROUND( screenSize.y / 2 ) );
515  }
516 }
517 
518 
519 bool WX_VIEW_CONTROLS::handleAutoPanning( const wxMouseEvent& aEvent )
520 {
521  VECTOR2D p( aEvent.GetX(), aEvent.GetY() );
522 
523  // Compute areas where autopanning is active
524  double borderStart = std::min( m_settings.m_autoPanMargin * m_view->GetScreenPixelSize().x,
526  double borderEndX = m_view->GetScreenPixelSize().x - borderStart;
527  double borderEndY = m_view->GetScreenPixelSize().y - borderStart;
528 
529  if( p.x < borderStart )
530  m_panDirection.x = -( borderStart - p.x );
531  else if( p.x > borderEndX )
532  m_panDirection.x = ( p.x - borderEndX );
533  else
534  m_panDirection.x = 0;
535 
536  if( p.y < borderStart )
537  m_panDirection.y = -( borderStart - p.y );
538  else if( p.y > borderEndY )
539  m_panDirection.y = ( p.y - borderEndY );
540  else
541  m_panDirection.y = 0;
542 
543  bool borderHit = ( m_panDirection.x != 0 || m_panDirection.y != 0 );
544 
545  switch( m_state )
546  {
547  case AUTO_PANNING:
548  if( !borderHit )
549  {
550  m_panTimer.Stop();
551  m_state = IDLE;
552 
553  return false;
554  }
555 
556  return true;
557  break;
558 
559  case IDLE:
560  if( borderHit )
561  {
563  m_panTimer.Start( (int) ( 250.0 / 60.0 ) );
564 
565  return true;
566  }
567 
568  return false;
569  break;
570 
571  case DRAG_PANNING:
572  return false;
573  }
574 
575  wxASSERT_MSG( false, wxT( "This line should never be reached" ) );
576  return false; // Should not be reached, just avoid the compiler warnings..
577 }
578 
579 
581 {
582  // Notify tools that the cursor position has changed in the world coordinates
583  wxMouseEvent moveEvent( EVT_REFRESH_MOUSE );
585  moveEvent.SetX( msp.x );
586  moveEvent.SetY( msp.y );
587 
588  // Set the modifiers state
589 #if wxCHECK_VERSION( 3, 0, 0 )
590  moveEvent.SetControlDown( wxGetKeyState( WXK_CONTROL ) );
591  moveEvent.SetShiftDown( wxGetKeyState( WXK_SHIFT ) );
592  moveEvent.SetAltDown( wxGetKeyState( WXK_ALT ) );
593 #else
594  // wx <3.0 do not have accessors, but the fields are exposed
595  moveEvent.m_controlDown = wxGetKeyState( WXK_CONTROL );
596  moveEvent.m_shiftDown = wxGetKeyState( WXK_SHIFT );
597  moveEvent.m_altDown = wxGetKeyState( WXK_ALT );
598 #endif
599 
600  m_cursorPos = m_view->ToWorld( VECTOR2D( msp.x, msp.y ) );
601  wxPostEvent( m_parentPanel, moveEvent );
602 }
603 
604 
606 {
607  wxPoint msp = wxGetMousePosition();
608  m_parentPanel->ScreenToClient( &msp.x, &msp.y );
609  return msp;
610 }
611 
612 
614 {
615  const BOX2D viewport = m_view->GetViewport();
616  const BOX2I& boundary = m_view->GetBoundary();
617 
618  m_scrollScale.x = 2e3 / viewport.GetWidth(); // TODO it does not have to be updated so often
619  m_scrollScale.y = 2e3 / viewport.GetHeight();
620  VECTOR2I newScroll( ( viewport.Centre().x - boundary.GetLeft() ) * m_scrollScale.x,
621  ( viewport.Centre().y - boundary.GetTop() ) * m_scrollScale.y );
622 
623  // Flip scroll direction in flipped view
624  if( m_view->IsMirroredX() )
625  newScroll.x = ( boundary.GetRight() - viewport.Centre().x ) * m_scrollScale.x;
626 
627  // Adjust scrollbars only if it is needed. Otherwise there are cases when canvas is continuosly
628  // refreshed (Windows)
629  if( m_scrollPos != newScroll )
630  {
631  // Another example of wxWidgets being broken by design: scroll position is determined by the
632  // left (or top, if vertical) edge of the slider. Fortunately, slider size seems to be constant
633  // (at least for wxGTK and wxMSW), so we have to add its size to allow user to scroll the workspace
634  // till the end.
635 
636  m_parentPanel->SetScrollbars( 1, 1,
637 #if defined(__LINUX__)
638  m_scrollScale.x * boundary.GetWidth() + 1623, m_scrollScale.y * boundary.GetHeight() + 1623,
639 #elif defined(__WIN32__) || defined(__WIN64__)
640  m_scrollScale.x * boundary.GetWidth() + 1377, m_scrollScale.y * boundary.GetHeight() + 741,
641 #else
642  m_scrollScale.x * boundary.GetWidth(), m_scrollScale.y * boundary.GetHeight(),
643 #endif
644  newScroll.x, newScroll.y, false );
645 
646  m_scrollPos = newScroll;
647  }
648 }
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: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:82
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)
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.
bool IsMirroredX() const
Function IsMirroredX() Returns true if view is flipped across the X axis.
Definition: view.h:227
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:463
void onButton(wxMouseEvent &aEvent)
static const int dist[10][10]
Definition: dist.cpp:57
VC_SETTINGS m_settings
Current VIEW_CONTROLS settings
coord_type GetRight() const
Definition: box2.h:187
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:589
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
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:587
Panning with mouse button pressed.
BOX2D GetViewport() const
Function GetViewport() Returns the current viewport visible area rectangle.
Definition: view.cpp:524
bool m_forceCursorPosition
Is the forced cursor position enabled
Definition: view_controls.h:61
VECTOR2< double > VECTOR2D
Definition: vector2d.h:588
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.
void SetCrossHairCursorPosition(const VECTOR2D &aPosition, bool aWarpView) override
Moves the graphic crosshair cursor to the requested position expressed 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: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:67
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: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:482
bool IsCursorWarpingEnabled() const
Function IsCursorWarpingEnabled()
const VECTOR2I & GetScreenPixelSize() const
Function GetScreenPixelSize() Returns the size of the our rendering area, in pixels.
Definition: view.cpp:1110
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: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:94