diff --git a/common/view/view.cpp b/common/view/view.cpp index 3cf57a210b..b28b0a1c32 100644 --- a/common/view/view.cpp +++ b/common/view/view.cpp @@ -45,10 +45,8 @@ VIEW::VIEW( bool aIsDynamic ) : m_scale( 1.0 ), m_painter( NULL ), m_gal( NULL ), - m_dynamic( aIsDynamic ), - m_scaleLimits( 15000.0, 1.0 ) + m_dynamic( aIsDynamic ) { - m_panBoundary.SetMaximum(); m_needsUpdate.reserve( 32768 ); // Redraw everything at the beginning @@ -295,11 +293,6 @@ void VIEW::SetMirror( bool aMirrorX, bool aMirrorY ) void VIEW::SetScale( double aScale, const VECTOR2D& aAnchor ) { - if( aScale > m_scaleLimits.x ) - aScale = m_scaleLimits.x; - else if( aScale < m_scaleLimits.y ) - aScale = m_scaleLimits.y; - VECTOR2D a = ToScreen( aAnchor ); m_gal->SetZoomFactor( aScale ); @@ -319,19 +312,6 @@ void VIEW::SetCenter( const VECTOR2D& aCenter ) { m_center = aCenter; - if( !m_panBoundary.Contains( aCenter ) ) - { - if( aCenter.x < m_panBoundary.GetLeft() ) - m_center.x = m_panBoundary.GetLeft(); - else if( aCenter.x > m_panBoundary.GetRight() ) - m_center.x = m_panBoundary.GetRight(); - - if( aCenter.y < m_panBoundary.GetTop() ) - m_center.y = m_panBoundary.GetTop(); - else if( aCenter.y > m_panBoundary.GetBottom() ) - m_center.y = m_panBoundary.GetBottom(); - } - m_gal->SetLookAtPoint( m_center ); m_gal->ComputeWorldScreenMatrix(); diff --git a/common/view/wx_view_controls.cpp b/common/view/wx_view_controls.cpp index 4ecfa953fd..22eb3ee47e 100644 --- a/common/view/wx_view_controls.cpp +++ b/common/view/wx_view_controls.cpp @@ -66,6 +66,42 @@ void VIEW_CONTROLS::ShowCursor( bool aEnabled ) } +void VIEW_CONTROLS::setCenter( const VECTOR2D& aCenter ) +{ + if( !m_panBoundary.Contains( aCenter ) ) + { + VECTOR2D newCenter( aCenter ); + + if( aCenter.x < m_panBoundary.GetLeft() ) + newCenter.x = m_panBoundary.GetLeft(); + else if( aCenter.x > m_panBoundary.GetRight() ) + newCenter.x = m_panBoundary.GetRight(); + + if( aCenter.y < m_panBoundary.GetTop() ) + newCenter.y = m_panBoundary.GetTop(); + else if( aCenter.y > m_panBoundary.GetBottom() ) + newCenter.y = m_panBoundary.GetBottom(); + + m_view->SetCenter( newCenter ); + } + else + { + m_view->SetCenter( aCenter ); + } +} + + +void VIEW_CONTROLS::setScale( double aScale, const VECTOR2D& aAnchor ) +{ + if( aScale < m_minScale ) + aScale = m_minScale; + else if( aScale > m_maxScale ) + aScale = m_maxScale; + + m_view->SetScale( aScale, aAnchor ); +} + + void WX_VIEW_CONTROLS::onMotion( wxMouseEvent& aEvent ) { bool isAutoPanning = false; @@ -80,7 +116,7 @@ void WX_VIEW_CONTROLS::onMotion( wxMouseEvent& aEvent ) VECTOR2D d = m_dragStartPoint - VECTOR2D( aEvent.GetX(), aEvent.GetY() ); VECTOR2D delta = m_view->ToWorld( d, false ); - m_view->SetCenter( m_lookStartPoint + delta ); + setCenter( m_lookStartPoint + delta ); aEvent.StopPropagation(); } else @@ -110,7 +146,7 @@ void WX_VIEW_CONTROLS::onWheel( wxMouseEvent& aEvent ) VECTOR2D delta( aEvent.ControlDown() ? -scrollSpeed : 0.0, aEvent.ShiftDown() ? -scrollSpeed : 0.0 ); - m_view->SetCenter( m_view->GetCenter() + delta ); + setCenter( m_view->GetCenter() + delta ); } else { @@ -133,7 +169,7 @@ void WX_VIEW_CONTROLS::onWheel( wxMouseEvent& aEvent ) } VECTOR2D anchor = m_view->ToWorld( VECTOR2D( aEvent.GetX(), aEvent.GetY() ) ); - m_view->SetScale( m_view->GetScale() * zoomScale, anchor ); + setScale( m_view->GetScale() * zoomScale, anchor ); } aEvent.Skip(); @@ -190,7 +226,7 @@ void WX_VIEW_CONTROLS::onTimer( wxTimerEvent& aEvent ) dir = dir.Resize( borderSize ); dir = m_view->ToWorld( dir, false ); - m_view->SetCenter( m_view->GetCenter() + dir * m_autoPanSpeed ); + setCenter( m_view->GetCenter() + dir * m_autoPanSpeed ); // Notify tools that the cursor position has changed in the world coordinates wxMouseEvent moveEvent( EVT_REFRESH_MOUSE ); diff --git a/include/view/view.h b/include/view/view.h index 63d6769254..e103089ae0 100644 --- a/include/view/view.h +++ b/include/view/view.h @@ -507,29 +507,6 @@ public: */ void UpdateItems(); - /** - * Function SetPanBoundary() - * Sets limits for panning area. - * @param aBoundary is the box that limits panning area. - */ - void SetPanBoundary( const BOX2I& aBoundary ) - { - m_panBoundary = aBoundary; - } - - /** - * Function SetScaleLimits() - * Sets minimum and maximum values for scale. - * @param aMaximum is the maximum value for scale.. - * @param aMinimum is the minimum value for scale. - */ - void SetScaleLimits( double aMaximum, double aMinimum ) - { - wxASSERT_MSG( aMaximum > aMinimum, wxT( "I guess you passed parameters in wrong order" ) ); - - m_scaleLimits = VECTOR2D( aMaximum, aMinimum ); - } - static const int VIEW_MAX_LAYERS = 128; ///< maximum number of layers that may be shown private: @@ -670,12 +647,6 @@ private: /// Rendering order modifier for layers that are marked as top layers static const int TOP_LAYER_MODIFIER = -VIEW_MAX_LAYERS; - /// Panning boundaries - BOX2I m_panBoundary; - - /// Zoom limits - VECTOR2D m_scaleLimits; - /// Items to be updated std::vector m_needsUpdate; }; diff --git a/include/view/view_controls.h b/include/view/view_controls.h index 35e6709f18..90fecd9ef9 100644 --- a/include/view/view_controls.h +++ b/include/view/view_controls.h @@ -46,14 +46,40 @@ class VIEW; class VIEW_CONTROLS { public: - VIEW_CONTROLS( VIEW* aView ) : m_view( aView ), m_forceCursorPosition( false ), - m_snappingEnabled( false ), m_grabMouse( false ), m_autoPanEnabled( false ), - m_autoPanMargin( 0.1 ), m_autoPanSpeed( 0.15 ) - {} + VIEW_CONTROLS( VIEW* aView ) : m_view( aView ), m_minScale( 4.0 ), m_maxScale( 15000 ), + m_forceCursorPosition( false ), m_snappingEnabled( false ), m_grabMouse( false ), + m_autoPanEnabled( false ), m_autoPanMargin( 0.1 ), m_autoPanSpeed( 0.15 ) + { + m_panBoundary.SetMaximum(); + } virtual ~VIEW_CONTROLS() {} + /** + * Function SetPanBoundary() + * Sets limits for panning area. + * @param aBoundary is the box that limits panning area. + */ + void SetPanBoundary( const BOX2I& aBoundary ) + { + m_panBoundary = aBoundary; + } + + /** + * Function SetScaleLimits() + * Sets minimum and maximum values for scale. + * @param aMaximum is the maximum value for scale. + * @param aMinimum is the minimum value for scale. + */ + void SetScaleLimits( double aMaximum, double aMinimum ) + { + wxASSERT_MSG( aMaximum > aMinimum, wxT( "I guess you passed parameters in wrong order" ) ); + + m_minScale = aMinimum; + m_maxScale = aMaximum; + } + /** * Function SetSnapping() * Enables/disables snapping cursor to grid. @@ -146,11 +172,23 @@ public: virtual void ShowCursor( bool aEnabled ); protected: + /// Sets center for VIEW, takes into account panning boundaries. + void setCenter( const VECTOR2D& aCenter ); + + /// Sets scale for VIEW, takes into account scale limits. + void setScale( double aScale, const VECTOR2D& aAnchor ); + /// Pointer to controlled VIEW. VIEW* m_view; - /// Current mouse position - VECTOR2D m_mousePosition; + /// Panning boundaries. + BOX2I m_panBoundary; + + /// Scale lower limit. + double m_minScale; + + /// Scale upper limit. + double m_maxScale; /// Current cursor position VECTOR2D m_cursorPosition; diff --git a/pcbnew/pcbframe.cpp b/pcbnew/pcbframe.cpp index 0d56f1a634..1b5c4c5c20 100644 --- a/pcbnew/pcbframe.cpp +++ b/pcbnew/pcbframe.cpp @@ -56,6 +56,7 @@ #include #include #include +#include #include #include @@ -583,7 +584,7 @@ void PCB_EDIT_FRAME::ViewReloadBoard( const BOARD* aBoard ) const view->Add( aBoard->GetRatsnestViewItem() ); // Limit panning to the size of worksheet frame - view->SetPanBoundary( aBoard->GetWorksheetViewItem()->ViewBBox() ); + GetGalCanvas()->GetViewControls()->SetPanBoundary( aBoard->GetWorksheetViewItem()->ViewBBox() ); view->RecacheAllItems( true ); if( IsGalCanvasActive() )