Commit afc56d3f authored by Maciej Suminski's avatar Maciej Suminski

Moved panning boundaries and scale limits from VIEW to VIEW_CONTROL.

parent c7fa57fa
...@@ -45,10 +45,8 @@ VIEW::VIEW( bool aIsDynamic ) : ...@@ -45,10 +45,8 @@ VIEW::VIEW( bool aIsDynamic ) :
m_scale( 1.0 ), m_scale( 1.0 ),
m_painter( NULL ), m_painter( NULL ),
m_gal( NULL ), m_gal( NULL ),
m_dynamic( aIsDynamic ), m_dynamic( aIsDynamic )
m_scaleLimits( 15000.0, 1.0 )
{ {
m_panBoundary.SetMaximum();
m_needsUpdate.reserve( 32768 ); m_needsUpdate.reserve( 32768 );
// Redraw everything at the beginning // Redraw everything at the beginning
...@@ -295,11 +293,6 @@ void VIEW::SetMirror( bool aMirrorX, bool aMirrorY ) ...@@ -295,11 +293,6 @@ void VIEW::SetMirror( bool aMirrorX, bool aMirrorY )
void VIEW::SetScale( double aScale, const VECTOR2D& aAnchor ) 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 ); VECTOR2D a = ToScreen( aAnchor );
m_gal->SetZoomFactor( aScale ); m_gal->SetZoomFactor( aScale );
...@@ -319,19 +312,6 @@ void VIEW::SetCenter( const VECTOR2D& aCenter ) ...@@ -319,19 +312,6 @@ void VIEW::SetCenter( const VECTOR2D& aCenter )
{ {
m_center = 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->SetLookAtPoint( m_center );
m_gal->ComputeWorldScreenMatrix(); m_gal->ComputeWorldScreenMatrix();
......
...@@ -66,6 +66,42 @@ void VIEW_CONTROLS::ShowCursor( bool aEnabled ) ...@@ -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 ) void WX_VIEW_CONTROLS::onMotion( wxMouseEvent& aEvent )
{ {
bool isAutoPanning = false; bool isAutoPanning = false;
...@@ -80,7 +116,7 @@ void WX_VIEW_CONTROLS::onMotion( wxMouseEvent& aEvent ) ...@@ -80,7 +116,7 @@ void WX_VIEW_CONTROLS::onMotion( wxMouseEvent& aEvent )
VECTOR2D d = m_dragStartPoint - VECTOR2D( aEvent.GetX(), aEvent.GetY() ); VECTOR2D d = m_dragStartPoint - VECTOR2D( aEvent.GetX(), aEvent.GetY() );
VECTOR2D delta = m_view->ToWorld( d, false ); VECTOR2D delta = m_view->ToWorld( d, false );
m_view->SetCenter( m_lookStartPoint + delta ); setCenter( m_lookStartPoint + delta );
aEvent.StopPropagation(); aEvent.StopPropagation();
} }
else else
...@@ -110,7 +146,7 @@ void WX_VIEW_CONTROLS::onWheel( wxMouseEvent& aEvent ) ...@@ -110,7 +146,7 @@ void WX_VIEW_CONTROLS::onWheel( wxMouseEvent& aEvent )
VECTOR2D delta( aEvent.ControlDown() ? -scrollSpeed : 0.0, VECTOR2D delta( aEvent.ControlDown() ? -scrollSpeed : 0.0,
aEvent.ShiftDown() ? -scrollSpeed : 0.0 ); aEvent.ShiftDown() ? -scrollSpeed : 0.0 );
m_view->SetCenter( m_view->GetCenter() + delta ); setCenter( m_view->GetCenter() + delta );
} }
else else
{ {
...@@ -133,7 +169,7 @@ void WX_VIEW_CONTROLS::onWheel( wxMouseEvent& aEvent ) ...@@ -133,7 +169,7 @@ void WX_VIEW_CONTROLS::onWheel( wxMouseEvent& aEvent )
} }
VECTOR2D anchor = m_view->ToWorld( VECTOR2D( aEvent.GetX(), aEvent.GetY() ) ); 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(); aEvent.Skip();
...@@ -190,7 +226,7 @@ void WX_VIEW_CONTROLS::onTimer( wxTimerEvent& aEvent ) ...@@ -190,7 +226,7 @@ void WX_VIEW_CONTROLS::onTimer( wxTimerEvent& aEvent )
dir = dir.Resize( borderSize ); dir = dir.Resize( borderSize );
dir = m_view->ToWorld( dir, false ); 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 // Notify tools that the cursor position has changed in the world coordinates
wxMouseEvent moveEvent( EVT_REFRESH_MOUSE ); wxMouseEvent moveEvent( EVT_REFRESH_MOUSE );
......
...@@ -507,29 +507,6 @@ public: ...@@ -507,29 +507,6 @@ public:
*/ */
void UpdateItems(); 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 static const int VIEW_MAX_LAYERS = 128; ///< maximum number of layers that may be shown
private: private:
...@@ -670,12 +647,6 @@ private: ...@@ -670,12 +647,6 @@ private:
/// Rendering order modifier for layers that are marked as top layers /// Rendering order modifier for layers that are marked as top layers
static const int TOP_LAYER_MODIFIER = -VIEW_MAX_LAYERS; static const int TOP_LAYER_MODIFIER = -VIEW_MAX_LAYERS;
/// Panning boundaries
BOX2I m_panBoundary;
/// Zoom limits
VECTOR2D m_scaleLimits;
/// Items to be updated /// Items to be updated
std::vector<VIEW_ITEM*> m_needsUpdate; std::vector<VIEW_ITEM*> m_needsUpdate;
}; };
......
...@@ -46,14 +46,40 @@ class VIEW; ...@@ -46,14 +46,40 @@ class VIEW;
class VIEW_CONTROLS class VIEW_CONTROLS
{ {
public: public:
VIEW_CONTROLS( VIEW* aView ) : m_view( aView ), m_forceCursorPosition( false ), VIEW_CONTROLS( VIEW* aView ) : m_view( aView ), m_minScale( 4.0 ), m_maxScale( 15000 ),
m_snappingEnabled( false ), m_grabMouse( false ), m_autoPanEnabled( false ), m_forceCursorPosition( false ), m_snappingEnabled( false ), m_grabMouse( false ),
m_autoPanMargin( 0.1 ), m_autoPanSpeed( 0.15 ) m_autoPanEnabled( false ), m_autoPanMargin( 0.1 ), m_autoPanSpeed( 0.15 )
{} {
m_panBoundary.SetMaximum();
}
virtual ~VIEW_CONTROLS() 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() * Function SetSnapping()
* Enables/disables snapping cursor to grid. * Enables/disables snapping cursor to grid.
...@@ -146,11 +172,23 @@ public: ...@@ -146,11 +172,23 @@ public:
virtual void ShowCursor( bool aEnabled ); virtual void ShowCursor( bool aEnabled );
protected: 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. /// Pointer to controlled VIEW.
VIEW* m_view; VIEW* m_view;
/// Current mouse position /// Panning boundaries.
VECTOR2D m_mousePosition; BOX2I m_panBoundary;
/// Scale lower limit.
double m_minScale;
/// Scale upper limit.
double m_maxScale;
/// Current cursor position /// Current cursor position
VECTOR2D m_cursorPosition; VECTOR2D m_cursorPosition;
......
...@@ -56,6 +56,7 @@ ...@@ -56,6 +56,7 @@
#include <dialog_plot.h> #include <dialog_plot.h>
#include <convert_from_iu.h> #include <convert_from_iu.h>
#include <view/view.h> #include <view/view.h>
#include <view/view_controls.h>
#include <painter.h> #include <painter.h>
#include <class_track.h> #include <class_track.h>
...@@ -583,7 +584,7 @@ void PCB_EDIT_FRAME::ViewReloadBoard( const BOARD* aBoard ) const ...@@ -583,7 +584,7 @@ void PCB_EDIT_FRAME::ViewReloadBoard( const BOARD* aBoard ) const
view->Add( aBoard->GetRatsnestViewItem() ); view->Add( aBoard->GetRatsnestViewItem() );
// Limit panning to the size of worksheet frame // Limit panning to the size of worksheet frame
view->SetPanBoundary( aBoard->GetWorksheetViewItem()->ViewBBox() ); GetGalCanvas()->GetViewControls()->SetPanBoundary( aBoard->GetWorksheetViewItem()->ViewBBox() );
view->RecacheAllItems( true ); view->RecacheAllItems( true );
if( IsGalCanvasActive() ) if( IsGalCanvasActive() )
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment