KiCad PCB EDA Suite
KIGFX::WX_VIEW_CONTROLS Class Reference

Class WX_VIEW_CONTROLS is a specific implementation of class VIEW_CONTROLS for wxWidgets library. More...

#include <wx_view_controls.h>

Inheritance diagram for KIGFX::WX_VIEW_CONTROLS:
KIGFX::VIEW_CONTROLS

Public Member Functions

 WX_VIEW_CONTROLS (VIEW *aView, wxScrolledCanvas *aParentPanel)
 
 ~WX_VIEW_CONTROLS ()
 
void onWheel (wxMouseEvent &aEvent)
 Handler functions. More...
 
void onMotion (wxMouseEvent &aEvent)
 
void onButton (wxMouseEvent &aEvent)
 
void onEnter (wxMouseEvent &WXUNUSED(aEvent))
 
void onLeave (wxMouseEvent &WXUNUSED(aEvent))
 
void onTimer (wxTimerEvent &WXUNUSED(aEvent))
 
void onScroll (wxScrollWinEvent &aEvent)
 
void SetGrabMouse (bool aEnabled) override
 Function SetGrabMouse() Enables/disables mouse cursor grabbing (limits the movement field only to the panel area). More...
 
VECTOR2I GetMousePosition () const override
 Function SetAutoPan() Enables/disables autopanning (panning when mouse cursor reaches the panel border). More...
 
VECTOR2D GetCursorPosition () const override
 Function GetCursorPosition() Returns the current cursor position in world coordinates. More...
 
void WarpCursor (const VECTOR2D &aPosition, bool aWorldCoordinates=false, bool aWarpView=false) const override
 
void CenterOnCursor () const override
 Function CenterOnCursor() Sets the viewport center to the current cursor position and warps the cursor to the screen center. More...
 
void UpdateScrollbars ()
 Adjusts the scrollbars position to match the current viewport. More...
 
virtual void SetSnapping (bool aEnabled)
 Function SetSnapping() Enables/disables snapping cursor to grid. More...
 
virtual void SetAutoPan (bool aEnabled)
 Function SetAutoPan Turns on/off auto panning (this feature is used when there is a tool active (eg. More...
 
virtual void SetAutoPanSpeed (float aSpeed)
 Function SetAutoPanSpeed() Sets speed of autopanning. More...
 
virtual void SetAutoPanMargin (float aMargin)
 Function SetAutoPanMArgin() Sets margin for autopanning (ie. More...
 
virtual void ForceCursorPosition (bool aEnabled, const VECTOR2D &aPosition=VECTOR2D(0, 0))
 Function ForceCursorPosition() Places the cursor immediately at a given point. More...
 
bool ForcedCursorPosition () const
 Function ForcedCursorPosition() Returns true if the current cursor position is forced to a specific location, ignoring the mouse cursor position. More...
 
virtual void ShowCursor (bool aEnabled)
 Function ShowCursor() Enables or disables display of cursor. More...
 
bool IsCursorShown () const
 Function IsCursorShown() Returns true when cursor is visible. More...
 
virtual void CaptureCursor (bool aEnabled)
 Function CaptureCursor() Forces the cursor to stay within the drawing panel area. More...
 
bool IsCursorPositionForced () const
 Function IsCursorPositionForced() Returns true if the cursor position is set by one of the tools. More...
 
void EnableCursorWarping (bool aEnable)
 Function EnableCursorWarping() Enables or disables warping the cursor. More...
 
bool IsCursorWarpingEnabled () const
 Function IsCursorWarpingEnabled() Returns the current setting for cursor warping. More...
 
virtual void EnableMousewheelPan (bool aEnable)
 Function EnableMousewheelPan() Enables or disables mousewheel panning. More...
 
virtual bool IsMousewheelPanEnabled () const
 Function IsMousewheelPanEnabled() Returns the current setting for mousewheel panning. More...
 
virtual void Reset ()
 Function Reset() Restores the default VIEW_CONTROLS settings. More...
 
const VC_SETTINGSGetSettings () const
 

Returns the current VIEW_CONTROLS settings

More...
 
void ApplySettings (const VC_SETTINGS &aSettings)
 

Applies VIEW_CONTROLS settings from an object

More...
 

Static Public Attributes

static const wxEventType EVT_REFRESH_MOUSE = wxNewEventType()
 Event that forces mouse move event in the dispatcher (eg. More...
 

Protected Attributes

VIEWm_view
 

Pointer to controlled VIEW.

More...
 
VC_SETTINGS m_settings
 

Current VIEW_CONTROLS settings

More...
 

Private Types

enum  STATE { IDLE = 1, DRAG_PANNING, AUTO_PANNING }
 Possible states for WX_VIEW_CONTROLS. More...
 

Private Member Functions

bool handleAutoPanning (const wxMouseEvent &aEvent)
 Function handleAutoPanning() Computes new viewport settings while in autopanning mode. More...
 

Private Attributes

STATE m_state
 Current state of VIEW_CONTROLS. More...
 
wxScrolledCanvas * m_parentPanel
 Panel that is affected by VIEW_CONTROLS. More...
 
VECTOR2D m_dragStartPoint
 Stores information about point where dragging has started. More...
 
VECTOR2D m_lookStartPoint
 Stores information about the center of viewport when dragging has started. More...
 
VECTOR2D m_panDirection
 Current direction of panning (only autopanning mode) More...
 
wxLongLong m_timeStamp
 Used for determining time intervals between scroll & zoom events. More...
 
wxTimer m_panTimer
 Timer repsonsible for handling autopanning. More...
 
VECTOR2D m_scrollScale
 Ratio used for scaling world coordinates to scrollbar position. More...
 
VECTOR2I m_scrollPos
 Current scrollbar position. More...
 

Detailed Description

Class WX_VIEW_CONTROLS is a specific implementation of class VIEW_CONTROLS for wxWidgets library.

Definition at line 46 of file wx_view_controls.h.

Member Enumeration Documentation

Possible states for WX_VIEW_CONTROLS.

Enumerator
IDLE 
DRAG_PANNING 

Nothing is happening.

AUTO_PANNING 

Panning with mouse button pressed.

Definition at line 102 of file wx_view_controls.h.

103  {
104  IDLE = 1,
105  DRAG_PANNING,
106  AUTO_PANNING,
107  };
Panning with mouse button pressed.

Constructor & Destructor Documentation

WX_VIEW_CONTROLS::WX_VIEW_CONTROLS ( VIEW aView,
wxScrolledCanvas *  aParentPanel 
)

Definition at line 38 of file wx_view_controls.cpp.

References m_panTimer, m_parentPanel, onButton(), onEnter(), onLeave(), onMotion(), onScroll(), onTimer(), and onWheel().

38  :
39  VIEW_CONTROLS( aView ), m_state( IDLE ), m_parentPanel( aParentPanel ), m_scrollScale( 1.0, 1.0 )
40 {
41  m_parentPanel->Connect( wxEVT_MOTION,
42  wxMouseEventHandler( WX_VIEW_CONTROLS::onMotion ), NULL, this );
43 #if wxCHECK_VERSION( 3, 1, 0 ) || defined( USE_OSX_MAGNIFY_EVENT )
44  m_parentPanel->Connect( wxEVT_MAGNIFY,
45  wxMouseEventHandler( WX_VIEW_CONTROLS::onMagnify ), NULL, this );
46 #endif
47  m_parentPanel->Connect( wxEVT_MOUSEWHEEL,
48  wxMouseEventHandler( WX_VIEW_CONTROLS::onWheel ), NULL, this );
49  m_parentPanel->Connect( wxEVT_MIDDLE_UP,
50  wxMouseEventHandler( WX_VIEW_CONTROLS::onButton ), NULL, this );
51  m_parentPanel->Connect( wxEVT_MIDDLE_DOWN,
52  wxMouseEventHandler( WX_VIEW_CONTROLS::onButton ), NULL, this );
53  m_parentPanel->Connect( wxEVT_LEFT_UP,
54  wxMouseEventHandler( WX_VIEW_CONTROLS::onButton ), NULL, this );
55  m_parentPanel->Connect( wxEVT_LEFT_DOWN,
56  wxMouseEventHandler( WX_VIEW_CONTROLS::onButton ), NULL, this );
57 #if defined _WIN32 || defined _WIN64
58  m_parentPanel->Connect( wxEVT_ENTER_WINDOW,
59  wxMouseEventHandler( WX_VIEW_CONTROLS::onEnter ), NULL, this );
60 #endif
61  m_parentPanel->Connect( wxEVT_LEAVE_WINDOW,
62  wxMouseEventHandler( WX_VIEW_CONTROLS::onLeave ), NULL, this );
63  m_parentPanel->Connect( wxEVT_SCROLLWIN_THUMBTRACK,
64  wxScrollWinEventHandler( WX_VIEW_CONTROLS::onScroll ), NULL, this );
65 
66  m_panTimer.SetOwner( this );
67  this->Connect( wxEVT_TIMER,
68  wxTimerEventHandler( WX_VIEW_CONTROLS::onTimer ), NULL, this );
69 }
VIEW_CONTROLS(VIEW *aView)
Definition: view_controls.h:97
void onButton(wxMouseEvent &aEvent)
VECTOR2D m_scrollScale
Ratio used for scaling world coordinates to scrollbar position.
void onWheel(wxMouseEvent &aEvent)
Handler functions.
void onMotion(wxMouseEvent &aEvent)
wxScrolledCanvas * m_parentPanel
Panel that is affected by VIEW_CONTROLS.
void onTimer(wxTimerEvent &WXUNUSED(aEvent))
void onEnter(wxMouseEvent &WXUNUSED(aEvent))
STATE m_state
Current state of VIEW_CONTROLS.
void onScroll(wxScrollWinEvent &aEvent)
void onLeave(wxMouseEvent &WXUNUSED(aEvent))
wxTimer m_panTimer
Timer repsonsible for handling autopanning.
KIGFX::WX_VIEW_CONTROLS::~WX_VIEW_CONTROLS ( )
inline

Definition at line 50 of file wx_view_controls.h.

51  {}

Member Function Documentation

void VIEW_CONTROLS::ApplySettings ( const VC_SETTINGS aSettings)
inherited

Applies VIEW_CONTROLS settings from an object

Definition at line 72 of file view_controls.cpp.

References KIGFX::VIEW_CONTROLS::CaptureCursor(), KIGFX::VC_SETTINGS::m_autoPanEnabled, KIGFX::VC_SETTINGS::m_autoPanMargin, KIGFX::VC_SETTINGS::m_autoPanSpeed, KIGFX::VC_SETTINGS::m_cursorCaptured, KIGFX::VC_SETTINGS::m_grabMouse, KIGFX::VC_SETTINGS::m_showCursor, KIGFX::VC_SETTINGS::m_snappingEnabled, KIGFX::VIEW_CONTROLS::SetAutoPan(), KIGFX::VIEW_CONTROLS::SetAutoPanMargin(), KIGFX::VIEW_CONTROLS::SetAutoPanSpeed(), KIGFX::VIEW_CONTROLS::SetGrabMouse(), KIGFX::VIEW_CONTROLS::SetSnapping(), and KIGFX::VIEW_CONTROLS::ShowCursor().

Referenced by TOOL_MANAGER::applyViewControls(), TOOL_MANAGER::popViewControls(), and KIGFX::VIEW_CONTROLS::Reset().

73 {
74  ShowCursor( aSettings.m_showCursor );
75  CaptureCursor( aSettings.m_cursorCaptured );
76  SetSnapping( aSettings.m_snappingEnabled );
77  SetGrabMouse( aSettings.m_grabMouse );
78  SetAutoPan( aSettings.m_autoPanEnabled );
79  SetAutoPanMargin( aSettings.m_autoPanMargin );
80  SetAutoPanSpeed( aSettings.m_autoPanSpeed );
81  // storing 'force cursor position' causes more harm than advantage
82  // let the tools control this setting
83  //ForceCursorPosition( aSettings.m_forceCursorPosition, aSettings.m_forcedPosition );
84 }
virtual void ShowCursor(bool aEnabled)
Function ShowCursor() Enables or disables display of cursor.
virtual void SetAutoPanSpeed(float aSpeed)
Function SetAutoPanSpeed() Sets speed of autopanning.
float m_autoPanSpeed
How fast is panning when in auto mode
Definition: view_controls.h:79
bool m_snappingEnabled
Should the cursor snap to grid or move freely
Definition: view_controls.h:67
bool m_grabMouse
Flag for grabbing the mouse cursor
Definition: view_controls.h:70
virtual void SetSnapping(bool aEnabled)
Function SetSnapping() Enables/disables snapping cursor to grid.
virtual void SetAutoPanMargin(float aMargin)
Function SetAutoPanMArgin() Sets margin for autopanning (ie.
virtual void CaptureCursor(bool aEnabled)
Function CaptureCursor() Forces the cursor to stay within the drawing panel area. ...
float m_autoPanMargin
Distance from cursor to VIEW edge when panning is active
Definition: view_controls.h:76
bool m_autoPanEnabled
Flag for turning on autopanning
Definition: view_controls.h:73
virtual void SetAutoPan(bool aEnabled)
Function SetAutoPan Turns on/off auto panning (this feature is used when there is a tool active (eg...
bool m_showCursor
Flag determining the cursor visibility
Definition: view_controls.h:55
virtual void SetGrabMouse(bool aEnabled)
Function SetGrabMouse Turns on/off mouse grabbing.
bool m_cursorCaptured
Should the cursor be locked within the parent window area
Definition: view_controls.h:64
virtual void KIGFX::VIEW_CONTROLS::CaptureCursor ( bool  aEnabled)
inlinevirtualinherited

Function CaptureCursor() Forces the cursor to stay within the drawing panel area.

Parameters
aEnableddetermines if the cursor should be captured.

Definition at line 217 of file view_controls.h.

References KIGFX::VC_SETTINGS::m_cursorCaptured, and KIGFX::VIEW_CONTROLS::m_settings.

Referenced by KIGFX::VIEW_CONTROLS::ApplySettings(), PCB_TOOL::doInteractiveItemPlacement(), DRAWING_TOOL::drawArc(), DRAWING_TOOL::DrawDimension(), MICROWAVE_TOOL::drawMicrowaveInductor(), DRAWING_TOOL::drawSegment(), PCB_EDITOR_CONTROL::PlaceModule(), DRAWING_TOOL::PlaceText(), DRAWING_TOOL::SetAnchor(), and PICKER_TOOL::setControls().

218  {
219  m_settings.m_cursorCaptured = aEnabled;
220  }
VC_SETTINGS m_settings
Current VIEW_CONTROLS settings
bool m_cursorCaptured
Should the cursor be locked within the parent window area
Definition: view_controls.h:64
void WX_VIEW_CONTROLS::CenterOnCursor ( ) const
overridevirtual

Function CenterOnCursor() Sets the viewport center to the current cursor position and warps the cursor to the screen center.

Implements KIGFX::VIEW_CONTROLS.

Definition at line 411 of file wx_view_controls.cpp.

References GetCursorPosition(), KIGFX::VIEW::GetGAL(), GetMousePosition(), KIGFX::GAL::GetScreenPixelSize(), KiROUND(), m_parentPanel, KIGFX::VIEW_CONTROLS::m_view, KIGFX::VIEW::SetCenter(), VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by onWheel().

412 {
413  const VECTOR2I& screenSize = m_view->GetGAL()->GetScreenPixelSize();
414  VECTOR2I screenCenter( screenSize / 2 );
415 
416  if( GetMousePosition() != screenCenter )
417  {
419  m_parentPanel->WarpPointer( KiROUND( screenSize.x / 2 ), KiROUND( screenSize.y / 2 ) );
420  }
421 }
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
Class VECTOR2 defines a general 2D-vector/point.
Definition: vector2d.h:65
VECTOR2I GetMousePosition() const override
Function SetAutoPan() Enables/disables autopanning (panning when mouse cursor reaches the panel borde...
VECTOR2D GetCursorPosition() const override
Function GetCursorPosition() Returns the current cursor position in world coordinates.
VIEW * m_view
Pointer to controlled VIEW.
void SetCenter(const VECTOR2D &aCenter)
Function SetCenter() Sets the center point of the VIEW (i.e.
Definition: view.cpp:564
GAL * GetGAL() const
Function GetGAL() Returns the GAL this view is using to draw graphical primitives.
Definition: view.h:177
const VECTOR2I & GetScreenPixelSize() const
Returns GAL canvas size in pixels.
wxScrolledCanvas * m_parentPanel
Panel that is affected by VIEW_CONTROLS.
void KIGFX::VIEW_CONTROLS::EnableCursorWarping ( bool  aEnable)
inlineinherited

Function EnableCursorWarping() Enables or disables warping the cursor.

Parameters
aEnabledis true if the cursor is allowed to be warped.

Definition at line 250 of file view_controls.h.

References KIGFX::VIEW_CONTROLS::m_settings, and KIGFX::VC_SETTINGS::m_warpCursor.

Referenced by EDA_DRAW_PANEL::SetEnableZoomNoCenter(), and EDA_DRAW_FRAME::UseGalCanvas().

251  {
252  m_settings.m_warpCursor = aEnable;
253  }
VC_SETTINGS m_settings
Current VIEW_CONTROLS settings
bool m_warpCursor
If the cursor is allowed to be warped
Definition: view_controls.h:82
virtual void KIGFX::VIEW_CONTROLS::EnableMousewheelPan ( bool  aEnable)
inlinevirtualinherited

Function EnableMousewheelPan() Enables or disables mousewheel panning.

Parameters
aEnabledis true if mouse-wheel panning is enabled.

Definition at line 269 of file view_controls.h.

References KIGFX::VC_SETTINGS::m_enableMousewheelPan, and KIGFX::VIEW_CONTROLS::m_settings.

Referenced by EDA_DRAW_PANEL::SetEnableMousewheelPan(), and EDA_DRAW_FRAME::UseGalCanvas().

270  {
272  }
bool m_enableMousewheelPan
Mousewheel (2-finger touchpad) panning
Definition: view_controls.h:85
VC_SETTINGS m_settings
Current VIEW_CONTROLS settings
virtual void KIGFX::VIEW_CONTROLS::ForceCursorPosition ( bool  aEnabled,
const VECTOR2D aPosition = VECTOR2D( 0, 0 ) 
)
inlinevirtualinherited

Function ForceCursorPosition() Places the cursor immediately at a given point.

Mouse movement is ignored.

Parameters
aEnabledenable forced cursor position
aPositionthe position (world coordinates).

Definition at line 182 of file view_controls.h.

References KIGFX::VC_SETTINGS::m_forceCursorPosition, KIGFX::VC_SETTINGS::m_forcedPosition, and KIGFX::VIEW_CONTROLS::m_settings.

Referenced by TOOL_MANAGER::dispatchContextMenu(), SELECTION_TOOL::findMove(), ROUTER_TOOL::finishInteractive(), TOOL_MANAGER::finishTool(), ROUTER_TOOL::InlineDrag(), EDIT_TOOL::Main(), POINT_EDITOR::OnSelectionChange(), ROUTER_TOOL::performDragging(), LENGTH_TUNER_TOOL::performTuning(), ROUTER_TOOL::prepareInteractive(), POINT_EDITOR::setEditedPoint(), PNS::TOOL_BASE::updateEndItem(), and PNS::TOOL_BASE::updateStartItem().

183  {
185  m_settings.m_forcedPosition = aPosition;
186  }
VC_SETTINGS m_settings
Current VIEW_CONTROLS settings
VECTOR2D m_forcedPosition
Forced cursor position (world coordinates)
Definition: view_controls.h:58
bool m_forceCursorPosition
Is the forced cursor position enabled
Definition: view_controls.h:61
bool KIGFX::VIEW_CONTROLS::ForcedCursorPosition ( ) const
inlineinherited

Function ForcedCursorPosition() Returns true if the current cursor position is forced to a specific location, ignoring the mouse cursor position.

Definition at line 193 of file view_controls.h.

References KIGFX::VC_SETTINGS::m_forceCursorPosition, and KIGFX::VIEW_CONTROLS::m_settings.

Referenced by TOOL_MANAGER::dispatchContextMenu().

194  {
196  }
VC_SETTINGS m_settings
Current VIEW_CONTROLS settings
bool m_forceCursorPosition
Is the forced cursor position enabled
Definition: view_controls.h:61
VECTOR2D WX_VIEW_CONTROLS::GetCursorPosition ( ) const
overridevirtual

Function GetCursorPosition() Returns the current cursor position in world coordinates.

Note, that it may be different from the mouse pointer position if snapping is enabled or cursor position is forced to specific point.

Returns
The current cursor position in world coordinates.

Implements KIGFX::VIEW_CONTROLS.

Definition at line 364 of file wx_view_controls.cpp.

References KIGFX::VIEW::GetGAL(), KIGFX::GAL::GetGridPoint(), GetMousePosition(), KIGFX::VC_SETTINGS::m_forceCursorPosition, KIGFX::VC_SETTINGS::m_forcedPosition, KIGFX::VIEW_CONTROLS::m_settings, KIGFX::VC_SETTINGS::m_snappingEnabled, KIGFX::VIEW_CONTROLS::m_view, and KIGFX::VIEW::ToWorld().

Referenced by CenterOnCursor(), and EDA_DRAW_PANEL_GAL::onPaint().

365 {
367  {
369  }
370  else
371  {
372  VECTOR2D mousePosition = GetMousePosition();
373 
375  return m_view->GetGAL()->GetGridPoint( m_view->ToWorld( mousePosition ) );
376  else
377  return m_view->ToWorld( mousePosition );
378  }
379 }
bool m_snappingEnabled
Should the cursor snap to grid or move freely
Definition: view_controls.h:67
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
VC_SETTINGS m_settings
Current VIEW_CONTROLS settings
VECTOR2I GetMousePosition() const override
Function SetAutoPan() Enables/disables autopanning (panning when mouse cursor reaches the panel borde...
VECTOR2D m_forcedPosition
Forced cursor position (world coordinates)
Definition: view_controls.h:58
VIEW * m_view
Pointer to controlled VIEW.
bool m_forceCursorPosition
Is the forced cursor position enabled
Definition: view_controls.h:61
GAL * GetGAL() const
Function GetGAL() Returns the GAL this view is using to draw graphical primitives.
Definition: view.h:177
VECTOR2D GetGridPoint(const VECTOR2D &aPoint) const
Function GetGridPoint() For a given point it returns the nearest point belonging to the grid in world...
VECTOR2I WX_VIEW_CONTROLS::GetMousePosition ( ) const
overridevirtual

Function SetAutoPan() Enables/disables autopanning (panning when mouse cursor reaches the panel border).

Parameters
aEnabledsays whether the option should enabled or disabled.Function GetMousePosition() Returns the current mouse pointer position in screen coordinates. Note, that it may be different from the cursor position if snapping is enabled (
See also
GetCursorPosition()).
Returns
The current mouse pointer position in the screen coordinates.

Implements KIGFX::VIEW_CONTROLS.

Definition at line 355 of file wx_view_controls.cpp.

References m_parentPanel, wxPoint::x, and wxPoint::y.

Referenced by CenterOnCursor(), and GetCursorPosition().

356 {
357  wxPoint msp = wxGetMousePosition();
358  wxPoint winp = m_parentPanel->GetScreenPosition();
359 
360  return VECTOR2I( msp.x - winp.x, msp.y - winp.y );
361 }
VECTOR2< int > VECTOR2I
Definition: vector2d.h:590
wxScrolledCanvas * m_parentPanel
Panel that is affected by VIEW_CONTROLS.
const VC_SETTINGS& KIGFX::VIEW_CONTROLS::GetSettings ( ) const
inlineinherited

Returns the current VIEW_CONTROLS settings

Definition at line 297 of file view_controls.h.

References KIGFX::VIEW_CONTROLS::m_settings.

Referenced by TOOL_MANAGER::pushViewControls(), and TOOL_MANAGER::saveViewControls().

298  {
299  return m_settings;
300  }
VC_SETTINGS m_settings
Current VIEW_CONTROLS settings
bool WX_VIEW_CONTROLS::handleAutoPanning ( const wxMouseEvent &  aEvent)
private

Function handleAutoPanning() Computes new viewport settings while in autopanning mode.

Parameters
aEventis an event to be processed and decide if autopanning should happen.
Returns
true if it is currently autopanning (ie. autopanning is active and mouse cursor is in the area that causes autopanning to happen).

Definition at line 424 of file wx_view_controls.cpp.

References AUTO_PANNING, DRAG_PANNING, KIGFX::VIEW::GetScreenPixelSize(), IDLE, KIGFX::VC_SETTINGS::m_autoPanMargin, m_panDirection, m_panTimer, KIGFX::VIEW_CONTROLS::m_settings, m_state, KIGFX::VIEW_CONTROLS::m_view, min, VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by onMotion().

425 {
426  VECTOR2D p( aEvent.GetX(), aEvent.GetY() );
427 
428  // Compute areas where autopanning is active
429  double borderStart = std::min( m_settings.m_autoPanMargin * m_view->GetScreenPixelSize().x,
431  double borderEndX = m_view->GetScreenPixelSize().x - borderStart;
432  double borderEndY = m_view->GetScreenPixelSize().y - borderStart;
433 
434  if( p.x < borderStart )
435  m_panDirection.x = -( borderStart - p.x );
436  else if( p.x > borderEndX )
437  m_panDirection.x = ( p.x - borderEndX );
438  else
439  m_panDirection.x = 0;
440 
441  if( p.y < borderStart )
442  m_panDirection.y = -( borderStart - p.y );
443  else if( p.y > borderEndY )
444  m_panDirection.y = ( p.y - borderEndY );
445  else
446  m_panDirection.y = 0;
447 
448  bool borderHit = ( m_panDirection.x != 0 || m_panDirection.y != 0 );
449 
450  switch( m_state )
451  {
452  case AUTO_PANNING:
453  if( !borderHit )
454  {
455  m_panTimer.Stop();
456  m_state = IDLE;
457 
458  return false;
459  }
460 
461  return true;
462  break;
463 
464  case IDLE:
465  if( borderHit )
466  {
468  m_panTimer.Start( (int) ( 250.0 / 60.0 ) );
469 
470  return true;
471  }
472 
473  return false;
474  break;
475 
476  case DRAG_PANNING:
477  return false;
478  }
479 
480  wxASSERT_MSG( false, wxT( "This line should never be reached" ) );
481  return false; // Should not be reached, just avoid the compiler warnings..
482 }
VC_SETTINGS m_settings
Current VIEW_CONTROLS settings
VIEW * m_view
Pointer to controlled VIEW.
Panning with mouse button pressed.
float m_autoPanMargin
Distance from cursor to VIEW edge when panning is active
Definition: view_controls.h:76
VECTOR2D m_panDirection
Current direction of panning (only autopanning mode)
const VECTOR2I & GetScreenPixelSize() const
Function GetScreenPixelSize() Returns the size of the our rendering area, in pixels.
Definition: view.cpp:1041
STATE m_state
Current state of VIEW_CONTROLS.
#define min(a, b)
Definition: auxiliary.h:85
wxTimer m_panTimer
Timer repsonsible for handling autopanning.
bool KIGFX::VIEW_CONTROLS::IsCursorPositionForced ( ) const
inlineinherited

Function IsCursorPositionForced() Returns true if the cursor position is set by one of the tools.

Forced cursor position means it does not react to mouse movement.

Definition at line 227 of file view_controls.h.

References KIGFX::VC_SETTINGS::m_forceCursorPosition, and KIGFX::VIEW_CONTROLS::m_settings.

228  {
230  }
VC_SETTINGS m_settings
Current VIEW_CONTROLS settings
bool m_forceCursorPosition
Is the forced cursor position enabled
Definition: view_controls.h:61
bool VIEW_CONTROLS::IsCursorShown ( ) const
inherited

Function IsCursorShown() Returns true when cursor is visible.

Returns
True if cursor is visible.

Definition at line 40 of file view_controls.cpp.

References KIGFX::VIEW_CONTROLS::m_settings, and KIGFX::VC_SETTINGS::m_showCursor.

41 {
42  // this only says if the VIEW_CONTROLS say the cursor should be
43  // shown: m_view->GetGAL()->IsCursorEnabled() will say if the GAL is
44  // actually going to do show the cursor or not
45  return m_settings.m_showCursor;
46 }
VC_SETTINGS m_settings
Current VIEW_CONTROLS settings
bool m_showCursor
Flag determining the cursor visibility
Definition: view_controls.h:55
bool KIGFX::VIEW_CONTROLS::IsCursorWarpingEnabled ( ) const
inlineinherited

Function IsCursorWarpingEnabled() Returns the current setting for cursor warping.

Definition at line 259 of file view_controls.h.

References KIGFX::VIEW_CONTROLS::m_settings, and KIGFX::VC_SETTINGS::m_warpCursor.

Referenced by onWheel(), and COMMON_TOOLS::ZoomInOut().

260  {
261  return m_settings.m_warpCursor;
262  }
VC_SETTINGS m_settings
Current VIEW_CONTROLS settings
bool m_warpCursor
If the cursor is allowed to be warped
Definition: view_controls.h:82
virtual bool KIGFX::VIEW_CONTROLS::IsMousewheelPanEnabled ( ) const
inlinevirtualinherited

Function IsMousewheelPanEnabled() Returns the current setting for mousewheel panning.

Definition at line 278 of file view_controls.h.

References KIGFX::VC_SETTINGS::m_enableMousewheelPan, and KIGFX::VIEW_CONTROLS::m_settings.

279  {
281  }
bool m_enableMousewheelPan
Mousewheel (2-finger touchpad) panning
Definition: view_controls.h:85
VC_SETTINGS m_settings
Current VIEW_CONTROLS settings
void WX_VIEW_CONTROLS::onButton ( wxMouseEvent &  aEvent)

Definition at line 203 of file wx_view_controls.cpp.

References AUTO_PANNING, DRAG_PANNING, KIGFX::VIEW::GetCenter(), IDLE, m_dragStartPoint, m_lookStartPoint, m_state, and KIGFX::VIEW_CONTROLS::m_view.

Referenced by WX_VIEW_CONTROLS().

204 {
205  switch( m_state )
206  {
207  case IDLE:
208  case AUTO_PANNING:
209  if( aEvent.MiddleDown() )
210  {
211  m_dragStartPoint = VECTOR2D( aEvent.GetX(), aEvent.GetY() );
214  }
215 
216  if( aEvent.LeftUp() )
217  m_state = IDLE; // Stop autopanning when user release left mouse button
218 
219  break;
220 
221  case DRAG_PANNING:
222  if( aEvent.MiddleUp() )
223  m_state = IDLE;
224 
225  break;
226  }
227 
228  aEvent.Skip();
229 }
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.
VIEW * m_view
Pointer to controlled VIEW.
Panning with mouse button pressed.
VECTOR2< double > VECTOR2D
Definition: vector2d.h:589
VECTOR2D m_dragStartPoint
Stores information about point where dragging has started.
STATE m_state
Current state of VIEW_CONTROLS.
void WX_VIEW_CONTROLS::onEnter ( wxMouseEvent &  WXUNUSEDaEvent)

Definition at line 232 of file wx_view_controls.cpp.

References m_parentPanel.

Referenced by WX_VIEW_CONTROLS().

233 {
234  m_parentPanel->SetFocus();
235 }
wxScrolledCanvas * m_parentPanel
Panel that is affected by VIEW_CONTROLS.
void WX_VIEW_CONTROLS::onLeave ( wxMouseEvent &  WXUNUSEDaEvent)

Definition at line 238 of file wx_view_controls.cpp.

References KIGFX::VC_SETTINGS::m_cursorCaptured, m_parentPanel, and KIGFX::VIEW_CONTROLS::m_settings.

Referenced by WX_VIEW_CONTROLS().

239 {
241  {
242  bool warp = false;
243  int x = aEvent.GetX();
244  int y = aEvent.GetY();
245  wxSize parentSize = m_parentPanel->GetClientSize();
246 
247  if( x < 0 )
248  {
249  x = 0;
250  warp = true;
251  }
252  else if( x >= parentSize.x )
253  {
254  x = parentSize.x - 1;
255  warp = true;
256  }
257 
258  if( y < 0 )
259  {
260  y = 0;
261  warp = true;
262  }
263  else if( y >= parentSize.y )
264  {
265  y = parentSize.y - 1;
266  warp = true;
267  }
268 
269  if( warp )
270  m_parentPanel->WarpPointer( x, y );
271  }
272 }
VC_SETTINGS m_settings
Current VIEW_CONTROLS settings
wxScrolledCanvas * m_parentPanel
Panel that is affected by VIEW_CONTROLS.
bool m_cursorCaptured
Should the cursor be locked within the parent window area
Definition: view_controls.h:64
void WX_VIEW_CONTROLS::onMotion ( wxMouseEvent &  aEvent)

Definition at line 72 of file wx_view_controls.cpp.

References delta, DRAG_PANNING, handleAutoPanning(), KIGFX::VC_SETTINGS::m_autoPanEnabled, m_dragStartPoint, m_lookStartPoint, KIGFX::VIEW_CONTROLS::m_settings, m_state, KIGFX::VIEW_CONTROLS::m_view, KIGFX::VIEW::SetCenter(), and KIGFX::VIEW::ToWorld().

Referenced by WX_VIEW_CONTROLS().

73 {
74  bool isAutoPanning = false;
75 
77  isAutoPanning = handleAutoPanning( aEvent );
78 
79  if( !isAutoPanning && aEvent.Dragging() )
80  {
81  if( m_state == DRAG_PANNING )
82  {
83  VECTOR2D d = m_dragStartPoint - VECTOR2D( aEvent.GetX(), aEvent.GetY() );
84  VECTOR2D delta = m_view->ToWorld( d, false );
85 
86  m_view->SetCenter( m_lookStartPoint + delta );
87  aEvent.StopPropagation();
88  }
89  }
90 
91  aEvent.Skip();
92 }
VECTOR2D m_lookStartPoint
Stores information about the center of viewport when dragging has started.
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
VC_SETTINGS m_settings
Current VIEW_CONTROLS settings
VIEW * m_view
Pointer to controlled VIEW.
static const int delta[8][2]
Definition: solve.cpp:112
void SetCenter(const VECTOR2D &aCenter)
Function SetCenter() Sets the center point of the VIEW (i.e.
Definition: view.cpp:564
VECTOR2< double > VECTOR2D
Definition: vector2d.h:589
bool m_autoPanEnabled
Flag for turning on autopanning
Definition: view_controls.h:73
bool handleAutoPanning(const wxMouseEvent &aEvent)
Function handleAutoPanning() Computes new viewport settings while in autopanning mode.
VECTOR2D m_dragStartPoint
Stores information about point where dragging has started.
STATE m_state
Current state of VIEW_CONTROLS.
void WX_VIEW_CONTROLS::onScroll ( wxScrollWinEvent &  aEvent)

Definition at line 329 of file wx_view_controls.cpp.

References KIGFX::VIEW::GetBoundary(), KIGFX::VIEW::GetCenter(), BOX2< Vec >::GetLeft(), BOX2< Vec >::GetTop(), m_parentPanel, m_scrollScale, KIGFX::VIEW_CONTROLS::m_view, KIGFX::VIEW::SetCenter(), VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by WX_VIEW_CONTROLS().

330 {
331  VECTOR2D center = m_view->GetCenter();
332  const BOX2I& boundary = m_view->GetBoundary();
333 
334  if( aEvent.GetOrientation() == wxHORIZONTAL )
335  center.x = boundary.GetLeft() + aEvent.GetPosition() / m_scrollScale.x;
336  else if( aEvent.GetOrientation() == wxVERTICAL )
337  center.y = boundary.GetTop() + aEvent.GetPosition() / m_scrollScale.y;
338 
339  m_view->SetCenter( center );
340  m_parentPanel->Refresh();
341 }
const VECTOR2D & GetCenter() const
Function GetCenter() Returns the center point of this VIEW (in world space coordinates) ...
Definition: view.h:316
const BOX2I & GetBoundary() const
Function GetBoundary()
Definition: view.h:284
VIEW * m_view
Pointer to controlled VIEW.
VECTOR2D m_scrollScale
Ratio used for scaling world coordinates to scrollbar position.
coord_type GetTop() const
Definition: box2.h:192
void SetCenter(const VECTOR2D &aCenter)
Function SetCenter() Sets the center point of the VIEW (i.e.
Definition: view.cpp:564
wxScrolledCanvas * m_parentPanel
Panel that is affected by VIEW_CONTROLS.
coord_type GetLeft() const
Definition: box2.h:191
void WX_VIEW_CONTROLS::onTimer ( wxTimerEvent &  WXUNUSEDaEvent)

Definition at line 275 of file wx_view_controls.cpp.

References AUTO_PANNING, DRAG_PANNING, EVT_REFRESH_MOUSE, KIGFX::VIEW::GetCenter(), KIGFX::VIEW::GetScreenPixelSize(), IDLE, KIGFX::VC_SETTINGS::m_autoPanEnabled, KIGFX::VC_SETTINGS::m_autoPanMargin, KIGFX::VC_SETTINGS::m_autoPanSpeed, m_panDirection, m_parentPanel, KIGFX::VIEW_CONTROLS::m_settings, m_state, KIGFX::VIEW_CONTROLS::m_view, min, KIGFX::VIEW::SetCenter(), KIGFX::VIEW::ToWorld(), VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by WX_VIEW_CONTROLS().

276 {
277  switch( m_state )
278  {
279  case AUTO_PANNING:
280  {
282  {
283  m_state = IDLE;
284  return;
285  }
286 
287 #if wxCHECK_VERSION( 3, 0, 0 )
288  if( !m_parentPanel->HasFocus() )
289  break;
290 #endif
291 
292  double borderSize = std::min( m_settings.m_autoPanMargin * m_view->GetScreenPixelSize().x,
294 
295  VECTOR2D dir( m_panDirection );
296 
297  if( dir.EuclideanNorm() > borderSize )
298  dir = dir.Resize( borderSize );
299 
300  dir = m_view->ToWorld( dir, false );
302 
303  // Notify tools that the cursor position has changed in the world coordinates
304  wxMouseEvent moveEvent( EVT_REFRESH_MOUSE );
305 
306  // Set the modifiers state
307 #if wxCHECK_VERSION( 3, 0, 0 )
308  moveEvent.SetControlDown( wxGetKeyState( WXK_CONTROL ) );
309  moveEvent.SetShiftDown( wxGetKeyState( WXK_SHIFT ) );
310  moveEvent.SetAltDown( wxGetKeyState( WXK_ALT ) );
311 #else
312  // wx <3.0 do not have accessors, but the fields are exposed
313  moveEvent.m_controlDown = wxGetKeyState( WXK_CONTROL );
314  moveEvent.m_shiftDown = wxGetKeyState( WXK_SHIFT );
315  moveEvent.m_altDown = wxGetKeyState( WXK_ALT );
316 #endif
317 
318  wxPostEvent( m_parentPanel, moveEvent );
319  }
320  break;
321 
322  case IDLE: // Just remove unnecessary warnings
323  case DRAG_PANNING:
324  break;
325  }
326 }
const VECTOR2D & GetCenter() const
Function GetCenter() Returns the center point of this VIEW (in world space coordinates) ...
Definition: view.h:316
float m_autoPanSpeed
How fast is panning when in auto mode
Definition: view_controls.h:79
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:440
VC_SETTINGS m_settings
Current VIEW_CONTROLS settings
VIEW * m_view
Pointer to controlled VIEW.
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.
float m_autoPanMargin
Distance from cursor to VIEW edge when panning is active
Definition: view_controls.h:76
bool m_autoPanEnabled
Flag for turning on autopanning
Definition: view_controls.h:73
wxScrolledCanvas * m_parentPanel
Panel that is affected by VIEW_CONTROLS.
VECTOR2D m_panDirection
Current direction of panning (only autopanning mode)
const VECTOR2I & GetScreenPixelSize() const
Function GetScreenPixelSize() Returns the size of the our rendering area, in pixels.
Definition: view.cpp:1041
STATE m_state
Current state of VIEW_CONTROLS.
#define min(a, b)
Definition: auxiliary.h:85
void WX_VIEW_CONTROLS::onWheel ( wxMouseEvent &  aEvent)

Handler functions.

Definition at line 95 of file wx_view_controls.cpp.

References abs, CenterOnCursor(), delta, KIGFX::VIEW::GetCenter(), KIGFX::VIEW::GetScale(), KIGFX::VIEW::GetScreenPixelSize(), KIGFX::VIEW_CONTROLS::IsCursorWarpingEnabled(), KIGFX::VC_SETTINGS::m_enableMousewheelPan, KIGFX::VIEW_CONTROLS::m_settings, m_timeStamp, KIGFX::VIEW_CONTROLS::m_view, KIGFX::VIEW::SetCenter(), KIGFX::VIEW::SetScale(), timeStamp(), KIGFX::VIEW::ToWorld(), VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by WX_VIEW_CONTROLS().

96 {
97  const double wheelPanSpeed = 0.001;
98 
99  // mousewheelpan disabled:
100  // wheel + ctrl -> horizontal scrolling;
101  // wheel + shift -> vertical scrolling;
102  // wheel -> zooming;
103  // mousewheelpan enabled:
104  // wheel -> pan;
105  // wheel + ctrl -> zooming;
106  // wheel + shift -> horizontal scrolling.
107 
108  if( ( !m_settings.m_enableMousewheelPan && ( aEvent.ControlDown() || aEvent.ShiftDown() ) ) ||
109  ( m_settings.m_enableMousewheelPan && !aEvent.ControlDown() ) )
110  {
111  // Scrolling
112  VECTOR2D scrollVec = m_view->ToWorld( m_view->GetScreenPixelSize(), false ) *
113  ( (double) aEvent.GetWheelRotation() * wheelPanSpeed );
114  int axis = aEvent.GetWheelAxis();
115  double scrollX = 0.0;
116  double scrollY = 0.0;
117 
119  {
120  if ( axis == wxMOUSE_WHEEL_HORIZONTAL || aEvent.ShiftDown() )
121  scrollX = scrollVec.x;
122  else
123  scrollY = -scrollVec.y;
124  }
125  else
126  {
127  if( aEvent.ControlDown() )
128  scrollX = -scrollVec.x;
129  else
130  scrollY = -scrollVec.y;
131  }
132 
133  VECTOR2D delta( scrollX, scrollY );
134 
136  }
137  else
138  {
139  // Zooming
140  wxLongLong timeStamp = wxGetLocalTimeMillis();
141  double timeDiff = timeStamp.ToDouble() - m_timeStamp.ToDouble();
142  int rotation = aEvent.GetWheelRotation();
143  double zoomScale;
144 
145 #ifdef __WXMAC__
146  // The following is to support Apple pointer devices (MagicMouse &
147  // Macbook touchpad), which send events more frequently, but with smaller
148  // wheel rotation.
149  //
150  // It should not break other platforms, but I prefer to be safe than
151  // sorry. If you find a device that behaves in the same way on another
152  // platform, feel free to remove #ifdef directives.
153  if( timeDiff > 0 && timeDiff < 100 && std::abs( rotation ) < 20 )
154  {
155  aEvent.Skip();
156  return;
157  }
158 #endif
159 
161 
162  // Set scaling speed depending on scroll wheel event interval
163  if( timeDiff < 500 && timeDiff > 0 )
164  {
165  zoomScale = 2.05 - timeDiff / 500;
166 
167  if( rotation < 0 )
168  zoomScale = 1.0 / zoomScale;
169  }
170  else
171  {
172  zoomScale = ( rotation > 0 ) ? 1.05 : 1/1.05;
173  }
174 
175  if( IsCursorWarpingEnabled() )
176  {
177  CenterOnCursor();
178  m_view->SetScale( m_view->GetScale() * zoomScale );
179  }
180  else
181  {
182  VECTOR2D anchor = m_view->ToWorld( VECTOR2D( aEvent.GetX(), aEvent.GetY() ) );
183  m_view->SetScale( m_view->GetScale() * zoomScale, anchor );
184  }
185  }
186 
187  aEvent.Skip();
188 }
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 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
VC_SETTINGS m_settings
Current VIEW_CONTROLS settings
VIEW * m_view
Pointer to controlled VIEW.
#define abs(a)
Definition: auxiliary.h:84
void SetScale(double aScale)
Function SetScale() Sets the scaling factor.
Definition: view.h:247
static const int delta[8][2]
Definition: solve.cpp:112
void SetCenter(const VECTOR2D &aCenter)
Function SetCenter() Sets the center point of the VIEW (i.e.
Definition: view.cpp:564
VECTOR2< double > VECTOR2D
Definition: vector2d.h:589
bool IsCursorWarpingEnabled() const
Function IsCursorWarpingEnabled() Returns the current setting for cursor warping. ...
const VECTOR2I & GetScreenPixelSize() const
Function GetScreenPixelSize() Returns the size of the our rendering area, in pixels.
Definition: view.cpp:1041
double GetScale() const
Function GetScale()
Definition: view.h:265
wxLongLong m_timeStamp
Used for determining time intervals between scroll & zoom events.
void CenterOnCursor() const override
Function CenterOnCursor() Sets the viewport center to the current cursor position and warps the curso...
static unsigned long timeStamp(CPTREE &aTree)
Make a unique time stamp.
void VIEW_CONTROLS::Reset ( )
virtualinherited

Function Reset() Restores the default VIEW_CONTROLS settings.

Definition at line 49 of file view_controls.cpp.

References KIGFX::VIEW_CONTROLS::ApplySettings(), and dummy().

50 {
51  // Get the default settings from the default constructor
53  ApplySettings( dummy );
54 }
void ApplySettings(const VC_SETTINGS &aSettings)
Applies VIEW_CONTROLS settings from an object
Structure to keep VIEW_CONTROLS settings for easy store/restore operations
Definition: view_controls.h:44
static LIB_PART * dummy()
Used when a LIB_PART is not found in library to draw a dummy shape This component is a 400 mils squar...
virtual void KIGFX::VIEW_CONTROLS::SetAutoPan ( bool  aEnabled)
inlinevirtualinherited
virtual void KIGFX::VIEW_CONTROLS::SetAutoPanMargin ( float  aMargin)
inlinevirtualinherited

Function SetAutoPanMArgin() Sets margin for autopanning (ie.

the area when autopanning becomes active).

Parameters
aMarginis a new margin for autopanning.

Definition at line 152 of file view_controls.h.

References KIGFX::VC_SETTINGS::m_autoPanMargin, and KIGFX::VIEW_CONTROLS::m_settings.

Referenced by KIGFX::VIEW_CONTROLS::ApplySettings().

153  {
154  m_settings.m_autoPanMargin = aMargin;
155  }
VC_SETTINGS m_settings
Current VIEW_CONTROLS settings
float m_autoPanMargin
Distance from cursor to VIEW edge when panning is active
Definition: view_controls.h:76
virtual void KIGFX::VIEW_CONTROLS::SetAutoPanSpeed ( float  aSpeed)
inlinevirtualinherited

Function SetAutoPanSpeed() Sets speed of autopanning.

Parameters
aSpeedis a new speed for autopanning.

Definition at line 142 of file view_controls.h.

References KIGFX::VC_SETTINGS::m_autoPanSpeed, and KIGFX::VIEW_CONTROLS::m_settings.

Referenced by KIGFX::VIEW_CONTROLS::ApplySettings().

143  {
144  m_settings.m_autoPanSpeed = aSpeed;
145  }
float m_autoPanSpeed
How fast is panning when in auto mode
Definition: view_controls.h:79
VC_SETTINGS m_settings
Current VIEW_CONTROLS settings
void WX_VIEW_CONTROLS::SetGrabMouse ( bool  aEnabled)
overridevirtual

Function SetGrabMouse() Enables/disables mouse cursor grabbing (limits the movement field only to the panel area).

Parameters
aEnabledsays whether the option should be enabled or disabled.

Reimplemented from KIGFX::VIEW_CONTROLS.

Definition at line 344 of file wx_view_controls.cpp.

References KIGFX::VC_SETTINGS::m_grabMouse, m_parentPanel, KIGFX::VIEW_CONTROLS::m_settings, and KIGFX::VIEW_CONTROLS::SetGrabMouse().

345 {
346  if( aEnabled && !m_settings.m_grabMouse )
347  m_parentPanel->CaptureMouse();
348  else if( !aEnabled && m_settings.m_grabMouse )
349  m_parentPanel->ReleaseMouse();
350 
351  VIEW_CONTROLS::SetGrabMouse( aEnabled );
352 }
bool m_grabMouse
Flag for grabbing the mouse cursor
Definition: view_controls.h:70
VC_SETTINGS m_settings
Current VIEW_CONTROLS settings
wxScrolledCanvas * m_parentPanel
Panel that is affected by VIEW_CONTROLS.
virtual void SetGrabMouse(bool aEnabled)
Function SetGrabMouse Turns on/off mouse grabbing.
void VIEW_CONTROLS::ShowCursor ( bool  aEnabled)
virtualinherited

Function ShowCursor() Enables or disables display of cursor.

Parameters
aEnableddecides if the cursor should be shown.

Definition at line 33 of file view_controls.cpp.

References KIGFX::VIEW::GetGAL(), KIGFX::VIEW_CONTROLS::m_settings, KIGFX::VC_SETTINGS::m_showCursor, KIGFX::VIEW_CONTROLS::m_view, and KIGFX::GAL::SetCursorEnabled().

Referenced by KIGFX::VIEW_CONTROLS::ApplySettings(), MODULE_EDITOR_TOOLS::CopyItems(), PCB_TOOL::doInteractiveItemPlacement(), DRAWING_TOOL::drawArc(), DRAWING_TOOL::DrawDimension(), MICROWAVE_TOOL::drawMicrowaveInductor(), DRAWING_TOOL::drawSegment(), MODULE_EDITOR_TOOLS::EnumeratePads(), ROUTER_TOOL::InlineDrag(), EDIT_TOOL::Main(), LENGTH_TUNER_TOOL::mainLoop(), ROUTER_TOOL::mainLoop(), MODULE_EDITOR_TOOLS::PasteItems(), DRAWING_TOOL::PlaceDXF(), PCB_EDITOR_CONTROL::PlaceModule(), MODULE_EDITOR_TOOLS::PlacePad(), DRAWING_TOOL::PlaceText(), DRAWING_TOOL::SetAnchor(), PICKER_TOOL::setControls(), and POINT_EDITOR::setEditedPoint().

34 {
35  m_settings.m_showCursor = aEnabled;
36  m_view->GetGAL()->SetCursorEnabled( aEnabled );
37 }
void SetCursorEnabled(bool aCursorEnabled)
Enable/disable cursor.
VC_SETTINGS m_settings
Current VIEW_CONTROLS settings
VIEW * m_view
Pointer to controlled VIEW.
GAL * GetGAL() const
Function GetGAL() Returns the GAL this view is using to draw graphical primitives.
Definition: view.h:177
bool m_showCursor
Flag determining the cursor visibility
Definition: view_controls.h:55
void WX_VIEW_CONTROLS::UpdateScrollbars ( )

Adjusts the scrollbars position to match the current viewport.

Definition at line 485 of file wx_view_controls.cpp.

References BOX2< Vec >::Centre(), KIGFX::VIEW::GetBoundary(), BOX2< Vec >::GetHeight(), BOX2< Vec >::GetLeft(), BOX2< Vec >::GetTop(), KIGFX::VIEW::GetViewport(), BOX2< Vec >::GetWidth(), m_parentPanel, m_scrollPos, m_scrollScale, KIGFX::VIEW_CONTROLS::m_view, VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by EDA_DRAW_PANEL_GAL::onPaint().

486 {
487  const BOX2D viewport = m_view->GetViewport();
488  const BOX2I& boundary = m_view->GetBoundary();
489 
490  m_scrollScale.x = 2e3 / viewport.GetWidth(); // TODO it does not have to be updated so often
491  m_scrollScale.y = 2e3 / viewport.GetHeight();
492  VECTOR2I newScroll( ( viewport.Centre().x - boundary.GetLeft() ) * m_scrollScale.x,
493  ( viewport.Centre().y - boundary.GetTop() ) * m_scrollScale.y );
494 
495  // Adjust scrollbars only if it is needed. Otherwise there are cases when canvas is continuosly
496  // refreshed (Windows)
497  if( m_scrollPos != newScroll )
498  {
499  // Another example of wxWidgets being broken by design: scroll position is determined by the
500  // left (or top, if vertical) edge of the slider. Fortunately, slider size seems to be constant
501  // (at least for wxGTK and wxMSW), so we have to add its size to allow user to scroll the workspace
502  // till the end.
503 
504  m_parentPanel->SetScrollbars( 1, 1,
505 #if defined(__LINUX__)
506  m_scrollScale.x * boundary.GetWidth() + 1623, m_scrollScale.y * boundary.GetHeight() + 1623,
507 #elif defined(__WIN32__) || defined(__WIN64__)
508  m_scrollScale.x * boundary.GetWidth() + 1377, m_scrollScale.y * boundary.GetHeight() + 741,
509 #else
510  m_scrollScale.x * boundary.GetWidth(), m_scrollScale.y * boundary.GetHeight(),
511 #endif
512  newScroll.x, newScroll.y, false );
513 
514  m_scrollPos = newScroll;
515  }
516 }
const BOX2I & GetBoundary() const
Function GetBoundary()
Definition: view.h:284
Class VECTOR2 defines a general 2D-vector/point.
Definition: vector2d.h:65
VIEW * m_view
Pointer to controlled VIEW.
Class BOX2 handles a 2-D bounding box, built on top of an origin point and size vector, both of templated class Vec.
Definition: box2.h:41
VECTOR2D m_scrollScale
Ratio used for scaling world coordinates to scrollbar position.
coord_type GetTop() const
Definition: box2.h:192
coord_type GetWidth() const
Definition: box2.h:185
BOX2D GetViewport() const
Function GetViewport() Returns the current viewport visible area rectangle.
Definition: view.cpp:501
Vec Centre() const
Definition: box2.h:67
coord_type GetHeight() const
Definition: box2.h:186
wxScrolledCanvas * m_parentPanel
Panel that is affected by VIEW_CONTROLS.
VECTOR2I m_scrollPos
Current scrollbar position.
coord_type GetLeft() const
Definition: box2.h:191
void WX_VIEW_CONTROLS::WarpCursor ( const VECTOR2D aPosition,
bool  aWorldCoordinates = false,
bool  aWarpView = false 
) const
overridevirtual

Implements KIGFX::VIEW_CONTROLS.

Definition at line 382 of file wx_view_controls.cpp.

References BOX2< Vec >::Contains(), KIGFX::VIEW::GetGAL(), KIGFX::GAL::GetScreenPixelSize(), m_parentPanel, KIGFX::VIEW_CONTROLS::m_view, KIGFX::VIEW::SetCenter(), KIGFX::VIEW::ToScreen(), VECTOR2< T >::x, and VECTOR2< T >::y.

384 {
385  if( aWorldCoordinates )
386  {
387  const VECTOR2I& screenSize = m_view->GetGAL()->GetScreenPixelSize();
388  BOX2I screen( VECTOR2I( 0, 0 ), screenSize );
389  VECTOR2D screenPos = m_view->ToScreen( aPosition );
390 
391  if( !screen.Contains( screenPos ) )
392  {
393  if( aWarpView )
394  {
395  m_view->SetCenter( aPosition );
396  m_parentPanel->WarpPointer( screenSize.x / 2, screenSize.y / 2 );
397  }
398  }
399  else
400  {
401  m_parentPanel->WarpPointer( screenPos.x, screenPos.y );
402  }
403  }
404  else
405  {
406  m_parentPanel->WarpPointer( aPosition.x, aPosition.y );
407  }
408 }
Class VECTOR2 defines a general 2D-vector/point.
Definition: vector2d.h:65
VIEW * m_view
Pointer to controlled VIEW.
VECTOR2< int > VECTOR2I
Definition: vector2d.h:590
void SetCenter(const VECTOR2D &aCenter)
Function SetCenter() Sets the center point of the VIEW (i.e.
Definition: view.cpp:564
GAL * GetGAL() const
Function GetGAL() Returns the GAL this view is using to draw graphical primitives.
Definition: view.h:177
const VECTOR2I & GetScreenPixelSize() const
Returns GAL canvas size in pixels.
wxScrolledCanvas * m_parentPanel
Panel that is affected by VIEW_CONTROLS.
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

Member Data Documentation

const wxEventType WX_VIEW_CONTROLS::EVT_REFRESH_MOUSE = wxNewEventType()
static

Event that forces mouse move event in the dispatcher (eg.

used in autopanning, when mouse cursor does not move in screen coordinates, but does in world coordinates)

Definition at line 98 of file wx_view_controls.h.

Referenced by TOOL_DISPATCHER::DispatchWxEvent(), EDA_DRAW_PANEL_GAL::EDA_DRAW_PANEL_GAL(), and onTimer().

VECTOR2D KIGFX::WX_VIEW_CONTROLS::m_dragStartPoint
private

Stores information about point where dragging has started.

Definition at line 126 of file wx_view_controls.h.

Referenced by onButton(), and onMotion().

VECTOR2D KIGFX::WX_VIEW_CONTROLS::m_lookStartPoint
private

Stores information about the center of viewport when dragging has started.

Definition at line 129 of file wx_view_controls.h.

Referenced by onButton(), and onMotion().

VECTOR2D KIGFX::WX_VIEW_CONTROLS::m_panDirection
private

Current direction of panning (only autopanning mode)

Definition at line 132 of file wx_view_controls.h.

Referenced by handleAutoPanning(), and onTimer().

wxTimer KIGFX::WX_VIEW_CONTROLS::m_panTimer
private

Timer repsonsible for handling autopanning.

Definition at line 138 of file wx_view_controls.h.

Referenced by handleAutoPanning(), and WX_VIEW_CONTROLS().

wxScrolledCanvas* KIGFX::WX_VIEW_CONTROLS::m_parentPanel
private
VECTOR2I KIGFX::WX_VIEW_CONTROLS::m_scrollPos
private

Current scrollbar position.

Definition at line 144 of file wx_view_controls.h.

Referenced by UpdateScrollbars().

VECTOR2D KIGFX::WX_VIEW_CONTROLS::m_scrollScale
private

Ratio used for scaling world coordinates to scrollbar position.

Definition at line 141 of file wx_view_controls.h.

Referenced by onScroll(), and UpdateScrollbars().

STATE KIGFX::WX_VIEW_CONTROLS::m_state
private

Current state of VIEW_CONTROLS.

Definition at line 120 of file wx_view_controls.h.

Referenced by handleAutoPanning(), onButton(), onMotion(), and onTimer().

wxLongLong KIGFX::WX_VIEW_CONTROLS::m_timeStamp
private

Used for determining time intervals between scroll & zoom events.

Definition at line 135 of file wx_view_controls.h.

Referenced by onWheel().

VIEW* KIGFX::VIEW_CONTROLS::m_view
protectedinherited

The documentation for this class was generated from the following files: