Refactored the way GAL handles zoom settings.
This commit is contained in:
parent
74a902da20
commit
c4888afbcc
|
@ -424,8 +424,7 @@ void EDA_DRAW_FRAME::OnSelectGrid( wxCommandEvent& event )
|
||||||
|
|
||||||
if( IsGalCanvasActive() )
|
if( IsGalCanvasActive() )
|
||||||
{
|
{
|
||||||
GetGalCanvas()->GetGAL()->SetGridSize( VECTOR2D( screen->GetGrid().m_Size.x,
|
GetGalCanvas()->GetGAL()->SetGridSize( VECTOR2D( screen->GetGrid().m_Size ) );
|
||||||
screen->GetGrid().m_Size.y ) );
|
|
||||||
GetGalCanvas()->GetView()->MarkTargetDirty( KIGFX::TARGET_NONCACHED );
|
GetGalCanvas()->GetView()->MarkTargetDirty( KIGFX::TARGET_NONCACHED );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -456,22 +455,14 @@ void EDA_DRAW_FRAME::OnSelectZoom( wxCommandEvent& event )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
GetScreen()->SetZoom( selectedZoom );
|
GetScreen()->SetZoom( selectedZoom );
|
||||||
|
RedrawScreen( GetScrollCenterPosition(), false );
|
||||||
if( IsGalCanvasActive() )
|
|
||||||
{
|
|
||||||
// Apply computed view settings to GAL
|
|
||||||
KIGFX::VIEW* view = GetGalCanvas()->GetView();
|
|
||||||
KIGFX::GAL* gal = GetGalCanvas()->GetGAL();
|
|
||||||
|
|
||||||
double zoomFactor = gal->GetWorldScale() / gal->GetZoomFactor();
|
|
||||||
double zoom = 1.0 / ( zoomFactor * GetZoom() );
|
|
||||||
|
|
||||||
view->SetScale( zoom );
|
|
||||||
GetGalCanvas()->Refresh();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
RedrawScreen( GetScrollCenterPosition(), false );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Notify GAL
|
||||||
|
TOOL_MANAGER* mgr = GetToolManager();
|
||||||
|
|
||||||
|
if( mgr && IsGalCanvasActive() )
|
||||||
|
mgr->RunAction( "common.Control.zoomPreset", true, id );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1026,38 +1017,29 @@ void EDA_DRAW_FRAME::UseGalCanvas( bool aEnable )
|
||||||
KIGFX::GAL* gal = GetGalCanvas()->GetGAL();
|
KIGFX::GAL* gal = GetGalCanvas()->GetGAL();
|
||||||
|
|
||||||
double zoomFactor = gal->GetWorldScale() / gal->GetZoomFactor();
|
double zoomFactor = gal->GetWorldScale() / gal->GetZoomFactor();
|
||||||
|
BASE_SCREEN* screen = GetScreen();
|
||||||
|
|
||||||
// Display the same view after canvas switching
|
// Display the same view after canvas switching
|
||||||
if( aEnable )
|
if( aEnable ) // Switch to GAL rendering
|
||||||
{
|
{
|
||||||
BASE_SCREEN* screen = GetScreen();
|
// Set up viewport
|
||||||
|
double zoom = 1.0 / ( zoomFactor * m_canvas->GetZoom() );
|
||||||
// Switch to GAL rendering
|
view->SetScale( zoom );
|
||||||
if( !IsGalCanvasActive() )
|
view->SetCenter( VECTOR2D( m_canvas->GetScreenCenterLogicalPosition() ) );
|
||||||
{
|
|
||||||
// Set up viewport
|
|
||||||
double zoom = 1.0 / ( zoomFactor * m_canvas->GetZoom() );
|
|
||||||
view->SetScale( zoom );
|
|
||||||
view->SetCenter( VECTOR2D( m_canvas->GetScreenCenterLogicalPosition() ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set up grid settings
|
// Set up grid settings
|
||||||
gal->SetGridVisibility( IsGridVisible() );
|
gal->SetGridVisibility( IsGridVisible() );
|
||||||
gal->SetGridSize( VECTOR2D( screen->GetGridSize().x, screen->GetGridSize().y ) );
|
gal->SetGridSize( VECTOR2D( screen->GetGridSize() ) );
|
||||||
gal->SetGridOrigin( VECTOR2D( GetGridOrigin() ) );
|
gal->SetGridOrigin( VECTOR2D( GetGridOrigin() ) );
|
||||||
}
|
}
|
||||||
else
|
else // Switch to standard rendering
|
||||||
{
|
{
|
||||||
// Switch to standard rendering
|
// Change view settings only if GAL was active previously
|
||||||
if( IsGalCanvasActive() )
|
double zoom = 1.0 / ( zoomFactor * view->GetScale() );
|
||||||
{
|
m_canvas->SetZoom( zoom );
|
||||||
// Change view settings only if GAL was active previously
|
|
||||||
double zoom = 1.0 / ( zoomFactor * view->GetScale() );
|
|
||||||
m_canvas->SetZoom( zoom );
|
|
||||||
|
|
||||||
VECTOR2D center = view->GetCenter();
|
VECTOR2D center = view->GetCenter();
|
||||||
RedrawScreen( wxPoint( center.x, center.y ), false );
|
AdjustScrollBars( wxPoint( center.x, center.y ) );
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
m_canvas->SetEvtHandlerEnabled( !aEnable );
|
m_canvas->SetEvtHandlerEnabled( !aEnable );
|
||||||
|
|
|
@ -33,8 +33,6 @@
|
||||||
#include <fctsys.h>
|
#include <fctsys.h>
|
||||||
#include <id.h>
|
#include <id.h>
|
||||||
#include <class_drawpanel.h>
|
#include <class_drawpanel.h>
|
||||||
#include <class_draw_panel_gal.h>
|
|
||||||
#include <gal/graphics_abstraction_layer.h>
|
|
||||||
#include <view/view.h>
|
#include <view/view.h>
|
||||||
#include <class_base_screen.h>
|
#include <class_base_screen.h>
|
||||||
#include <draw_frame.h>
|
#include <draw_frame.h>
|
||||||
|
@ -46,6 +44,9 @@
|
||||||
|
|
||||||
void EDA_DRAW_FRAME::RedrawScreen( const wxPoint& aCenterPoint, bool aWarpPointer )
|
void EDA_DRAW_FRAME::RedrawScreen( const wxPoint& aCenterPoint, bool aWarpPointer )
|
||||||
{
|
{
|
||||||
|
if( IsGalCanvasActive() )
|
||||||
|
return;
|
||||||
|
|
||||||
AdjustScrollBars( aCenterPoint );
|
AdjustScrollBars( aCenterPoint );
|
||||||
|
|
||||||
// Move the mouse cursor to the on grid graphic cursor position
|
// Move the mouse cursor to the on grid graphic cursor position
|
||||||
|
@ -58,6 +59,9 @@ void EDA_DRAW_FRAME::RedrawScreen( const wxPoint& aCenterPoint, bool aWarpPointe
|
||||||
|
|
||||||
void EDA_DRAW_FRAME::RedrawScreen2( const wxPoint& posBefore )
|
void EDA_DRAW_FRAME::RedrawScreen2( const wxPoint& posBefore )
|
||||||
{
|
{
|
||||||
|
if( IsGalCanvasActive() )
|
||||||
|
return;
|
||||||
|
|
||||||
wxPoint dPos = posBefore - m_canvas->GetClientSize() / 2; // relative screen position to center before zoom
|
wxPoint dPos = posBefore - m_canvas->GetClientSize() / 2; // relative screen position to center before zoom
|
||||||
wxPoint newScreenPos = m_canvas->ToDeviceXY( GetCrossHairPosition() ); // screen position of crosshair after zoom
|
wxPoint newScreenPos = m_canvas->ToDeviceXY( GetCrossHairPosition() ); // screen position of crosshair after zoom
|
||||||
wxPoint newCenter = m_canvas->ToLogicalXY( newScreenPos - dPos );
|
wxPoint newCenter = m_canvas->ToLogicalXY( newScreenPos - dPos );
|
||||||
|
@ -186,18 +190,7 @@ void EDA_DRAW_FRAME::OnZoom( wxCommandEvent& event )
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
unsigned i;
|
SetPresetZoom( id - ID_POPUP_ZOOM_LEVEL_START );
|
||||||
|
|
||||||
i = id - ID_POPUP_ZOOM_LEVEL_START;
|
|
||||||
|
|
||||||
if( i >= screen->m_ZoomList.size() )
|
|
||||||
{
|
|
||||||
wxLogDebug( wxT( "%s %d: index %d is outside the bounds of the zoom list." ),
|
|
||||||
__TFILE__, __LINE__, i );
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if( screen->SetZoom( screen->m_ZoomList[i] ) )
|
|
||||||
RedrawScreen( center, true );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
UpdateStatusBar();
|
UpdateStatusBar();
|
||||||
|
@ -216,6 +209,26 @@ void EDA_DRAW_FRAME::SetPrevZoom()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void EDA_DRAW_FRAME::SetPresetZoom( int aIndex )
|
||||||
|
{
|
||||||
|
BASE_SCREEN* screen = GetScreen();
|
||||||
|
|
||||||
|
if( aIndex >= (int) screen->m_ZoomList.size() )
|
||||||
|
{
|
||||||
|
wxLogDebug( wxT( "%s %d: index %d is outside the bounds of the zoom list." ),
|
||||||
|
__TFILE__, __LINE__, aIndex );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_zoomSelectBox->SetSelection( aIndex );
|
||||||
|
|
||||||
|
if( screen->SetZoom( screen->m_ZoomList[aIndex] ) )
|
||||||
|
RedrawScreen( GetScrollCenterPosition(), true );
|
||||||
|
|
||||||
|
UpdateStatusBar();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* add the zoom list menu the the MasterMenu.
|
/* add the zoom list menu the the MasterMenu.
|
||||||
* used in OnRightClick(wxMouseEvent& event)
|
* used in OnRightClick(wxMouseEvent& event)
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -215,7 +215,7 @@ public:
|
||||||
int m_ScreenNumber;
|
int m_ScreenNumber;
|
||||||
int m_NumberOfScreens;
|
int m_NumberOfScreens;
|
||||||
|
|
||||||
std::vector<double> m_ZoomList; ///< standard zoom (i.e. scale) coefficients.
|
std::vector<int> m_ZoomList; ///< standard zoom (i.e. scale) coefficients.
|
||||||
bool m_IsPrinting;
|
bool m_IsPrinting;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
|
@ -346,6 +346,12 @@ public:
|
||||||
*/
|
*/
|
||||||
virtual const wxString GetZoomLevelIndicator() const;
|
virtual const wxString GetZoomLevelIndicator() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Function GetZoomLevelCoeff
|
||||||
|
* returns the coefficient to convert internal display scale factor to zoom level.
|
||||||
|
*/
|
||||||
|
inline double GetZoomLevelCoeff() const { return m_zoomLevelCoeff; }
|
||||||
|
|
||||||
void EraseMsgBox();
|
void EraseMsgBox();
|
||||||
void Process_PageSettings( wxCommandEvent& event );
|
void Process_PageSettings( wxCommandEvent& event );
|
||||||
|
|
||||||
|
@ -505,6 +511,13 @@ public:
|
||||||
*/
|
*/
|
||||||
void SetPrevZoom();
|
void SetPrevZoom();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Function SetPresetZoom()
|
||||||
|
* changes zoom to one of the preset values.
|
||||||
|
* @param aIndex is the zoom index from the list.
|
||||||
|
*/
|
||||||
|
void SetPresetZoom( int aIndex );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function RedrawScreen
|
* Function RedrawScreen
|
||||||
* redraws the entire screen area by updating the scroll bars and mouse pointer in
|
* redraws the entire screen area by updating the scroll bars and mouse pointer in
|
||||||
|
|
|
@ -181,30 +181,34 @@ TOOL_ACTION COMMON_ACTIONS::arcPosture( "pcbnew.InteractiveDrawing.arcPosture",
|
||||||
|
|
||||||
|
|
||||||
// View Controls
|
// View Controls
|
||||||
TOOL_ACTION COMMON_ACTIONS::zoomIn( "pcbnew.Control.zoomIn",
|
TOOL_ACTION COMMON_ACTIONS::zoomIn( "common.Control.zoomIn",
|
||||||
AS_GLOBAL, WXK_F1,
|
AS_GLOBAL, WXK_F1,
|
||||||
"", "" );
|
"", "" );
|
||||||
|
|
||||||
TOOL_ACTION COMMON_ACTIONS::zoomOut( "pcbnew.Control.zoomOut",
|
TOOL_ACTION COMMON_ACTIONS::zoomOut( "common.Control.zoomOut",
|
||||||
AS_GLOBAL, WXK_F2,
|
AS_GLOBAL, WXK_F2,
|
||||||
"", "" );
|
"", "" );
|
||||||
|
|
||||||
TOOL_ACTION COMMON_ACTIONS::zoomInCenter( "pcbnew.Control.zoomInCenter",
|
TOOL_ACTION COMMON_ACTIONS::zoomInCenter( "common.Control.zoomInCenter",
|
||||||
AS_GLOBAL, 0,
|
AS_GLOBAL, 0,
|
||||||
"", "" );
|
"", "" );
|
||||||
|
|
||||||
TOOL_ACTION COMMON_ACTIONS::zoomOutCenter( "pcbnew.Control.zoomOutCenter",
|
TOOL_ACTION COMMON_ACTIONS::zoomOutCenter( "common.Control.zoomOutCenter",
|
||||||
AS_GLOBAL, 0,
|
AS_GLOBAL, 0,
|
||||||
"", "" );
|
"", "" );
|
||||||
|
|
||||||
TOOL_ACTION COMMON_ACTIONS::zoomCenter( "pcbnew.Control.zoomCenter",
|
TOOL_ACTION COMMON_ACTIONS::zoomCenter( "common.Control.zoomCenter",
|
||||||
AS_GLOBAL, WXK_F4,
|
AS_GLOBAL, WXK_F4,
|
||||||
"", "" );
|
"", "" );
|
||||||
|
|
||||||
TOOL_ACTION COMMON_ACTIONS::zoomFitScreen( "pcbnew.Control.zoomFitScreen",
|
TOOL_ACTION COMMON_ACTIONS::zoomFitScreen( "common.Control.zoomFitScreen",
|
||||||
AS_GLOBAL, WXK_HOME,
|
AS_GLOBAL, WXK_HOME,
|
||||||
"", "" );
|
"", "" );
|
||||||
|
|
||||||
|
TOOL_ACTION COMMON_ACTIONS::zoomPreset( "common.Control.zoomPreset",
|
||||||
|
AS_GLOBAL, 0,
|
||||||
|
"", "" );
|
||||||
|
|
||||||
|
|
||||||
// Display modes
|
// Display modes
|
||||||
TOOL_ACTION COMMON_ACTIONS::trackDisplayMode( "pcbnew.Control.trackDisplayMode",
|
TOOL_ACTION COMMON_ACTIONS::trackDisplayMode( "pcbnew.Control.trackDisplayMode",
|
||||||
|
|
|
@ -188,6 +188,7 @@ public:
|
||||||
static TOOL_ACTION zoomOutCenter;
|
static TOOL_ACTION zoomOutCenter;
|
||||||
static TOOL_ACTION zoomCenter;
|
static TOOL_ACTION zoomCenter;
|
||||||
static TOOL_ACTION zoomFitScreen;
|
static TOOL_ACTION zoomFitScreen;
|
||||||
|
static TOOL_ACTION zoomPreset;
|
||||||
|
|
||||||
// Display modes
|
// Display modes
|
||||||
static TOOL_ACTION trackDisplayMode;
|
static TOOL_ACTION trackDisplayMode;
|
||||||
|
|
|
@ -140,6 +140,35 @@ int PCBNEW_CONTROL::ZoomFitScreen( const TOOL_EVENT& aEvent )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int PCBNEW_CONTROL::ZoomPreset( const TOOL_EVENT& aEvent )
|
||||||
|
{
|
||||||
|
unsigned int idx = aEvent.Parameter<long>();
|
||||||
|
std::vector<int>& zoomList = m_frame->GetScreen()->m_ZoomList;
|
||||||
|
KIGFX::VIEW* view = m_frame->GetGalCanvas()->GetView();
|
||||||
|
KIGFX::GAL* gal = m_frame->GetGalCanvas()->GetGAL();
|
||||||
|
|
||||||
|
m_frame->SetPresetZoom( idx );
|
||||||
|
|
||||||
|
if( idx == 0 )
|
||||||
|
{
|
||||||
|
return ZoomFitScreen( aEvent );
|
||||||
|
}
|
||||||
|
else if( idx < 0 || idx >= zoomList.size() )
|
||||||
|
{
|
||||||
|
setTransitions();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
double selectedZoom = zoomList[idx];
|
||||||
|
double zoomFactor = gal->GetWorldScale() / gal->GetZoomFactor();
|
||||||
|
view->SetScale( 1.0 / ( zoomFactor * selectedZoom ) );
|
||||||
|
|
||||||
|
setTransitions();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int PCBNEW_CONTROL::TrackDisplayMode( const TOOL_EVENT& aEvent )
|
int PCBNEW_CONTROL::TrackDisplayMode( const TOOL_EVENT& aEvent )
|
||||||
{
|
{
|
||||||
KIGFX::PCB_PAINTER* painter =
|
KIGFX::PCB_PAINTER* painter =
|
||||||
|
@ -539,6 +568,7 @@ void PCBNEW_CONTROL::setTransitions()
|
||||||
Go( &PCBNEW_CONTROL::ZoomInOutCenter, COMMON_ACTIONS::zoomOutCenter.MakeEvent() );
|
Go( &PCBNEW_CONTROL::ZoomInOutCenter, COMMON_ACTIONS::zoomOutCenter.MakeEvent() );
|
||||||
Go( &PCBNEW_CONTROL::ZoomCenter, COMMON_ACTIONS::zoomCenter.MakeEvent() );
|
Go( &PCBNEW_CONTROL::ZoomCenter, COMMON_ACTIONS::zoomCenter.MakeEvent() );
|
||||||
Go( &PCBNEW_CONTROL::ZoomFitScreen, COMMON_ACTIONS::zoomFitScreen.MakeEvent() );
|
Go( &PCBNEW_CONTROL::ZoomFitScreen, COMMON_ACTIONS::zoomFitScreen.MakeEvent() );
|
||||||
|
Go( &PCBNEW_CONTROL::ZoomPreset, COMMON_ACTIONS::zoomPreset.MakeEvent() );
|
||||||
|
|
||||||
// Display modes
|
// Display modes
|
||||||
Go( &PCBNEW_CONTROL::TrackDisplayMode, COMMON_ACTIONS::trackDisplayMode.MakeEvent() );
|
Go( &PCBNEW_CONTROL::TrackDisplayMode, COMMON_ACTIONS::trackDisplayMode.MakeEvent() );
|
||||||
|
|
|
@ -51,6 +51,7 @@ public:
|
||||||
int ZoomInOutCenter( const TOOL_EVENT& aEvent );
|
int ZoomInOutCenter( const TOOL_EVENT& aEvent );
|
||||||
int ZoomCenter( const TOOL_EVENT& aEvent );
|
int ZoomCenter( const TOOL_EVENT& aEvent );
|
||||||
int ZoomFitScreen( const TOOL_EVENT& aEvent );
|
int ZoomFitScreen( const TOOL_EVENT& aEvent );
|
||||||
|
int ZoomPreset( const TOOL_EVENT& aEvent );
|
||||||
|
|
||||||
// Display modes
|
// Display modes
|
||||||
int TrackDisplayMode( const TOOL_EVENT& aEvent );
|
int TrackDisplayMode( const TOOL_EVENT& aEvent );
|
||||||
|
|
Loading…
Reference in New Issue