Added limits for VIEW scale values & panning area.

This commit is contained in:
Maciej Suminski 2013-09-18 17:36:54 +02:00
parent 56c78d44bf
commit 9b16651607
3 changed files with 53 additions and 1 deletions

View File

@ -45,8 +45,11 @@ 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();
// Redraw everything at the beginning // Redraw everything at the beginning
for( int i = 0; i < TARGETS_NUMBER; ++i ) for( int i = 0; i < TARGETS_NUMBER; ++i )
MarkTargetDirty( i ); MarkTargetDirty( i );
@ -290,6 +293,11 @@ void VIEW::SetScale( double aScale )
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 );
@ -308,6 +316,20 @@ void VIEW::SetScale( double aScale, const VECTOR2D& aAnchor )
void VIEW::SetCenter( const VECTOR2D& aCenter ) 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();

View File

@ -455,6 +455,29 @@ public:
m_dirtyTargets[i] = true; m_dirtyTargets[i] = true;
} }
/**
* 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:
@ -588,6 +611,12 @@ 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;
}; };
} // namespace KiGfx } // namespace KiGfx

View File

@ -217,6 +217,7 @@ void PCB_BASE_FRAME::ViewReloadBoard( const BOARD* aBoard ) const
view->Add( worksheet ); view->Add( worksheet );
view->SetPanBoundary( worksheet->ViewBBox() );
view->RecacheAllItems( true ); view->RecacheAllItems( true );
if( m_galCanvasActive ) if( m_galCanvasActive )