Commit c4888afb authored by Maciej Suminski's avatar Maciej Suminski
Browse files

Refactored the way GAL handles zoom settings.

parent 74a902da
Loading
Loading
Loading
Loading
+20 −38
Original line number Diff line number Diff line
@@ -424,8 +424,7 @@ void EDA_DRAW_FRAME::OnSelectGrid( wxCommandEvent& event )

    if( IsGalCanvasActive() )
    {
        GetGalCanvas()->GetGAL()->SetGridSize( VECTOR2D( screen->GetGrid().m_Size.x,
                                                         screen->GetGrid().m_Size.y ) );
        GetGalCanvas()->GetGAL()->SetGridSize( VECTOR2D( screen->GetGrid().m_Size ) );
        GetGalCanvas()->GetView()->MarkTargetDirty( KIGFX::TARGET_NONCACHED );
    }

@@ -456,22 +455,14 @@ void EDA_DRAW_FRAME::OnSelectZoom( wxCommandEvent& event )
            return;

        GetScreen()->SetZoom( selectedZoom );

        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();

    double zoomFactor = gal->GetWorldScale() / gal->GetZoomFactor();

    // Display the same view after canvas switching
    if( aEnable )
    {
    BASE_SCREEN* screen = GetScreen();

        // Switch to GAL rendering
        if( !IsGalCanvasActive() )
    // Display the same view after canvas switching
    if( aEnable )       // Switch to GAL rendering
    {
        // Set up viewport
        double zoom = 1.0 / ( zoomFactor * m_canvas->GetZoom() );
        view->SetScale( zoom );
        view->SetCenter( VECTOR2D( m_canvas->GetScreenCenterLogicalPosition() ) );
        }

        // Set up grid settings
        gal->SetGridVisibility( IsGridVisible() );
        gal->SetGridSize( VECTOR2D( screen->GetGridSize().x, screen->GetGridSize().y ) );
        gal->SetGridSize( VECTOR2D( screen->GetGridSize() ) );
        gal->SetGridOrigin( VECTOR2D( GetGridOrigin() ) );
    }
    else
    {
        // Switch to standard rendering
        if( IsGalCanvasActive() )
    else                // Switch to standard rendering
    {
        // Change view settings only if GAL was active previously
        double zoom = 1.0 / ( zoomFactor * view->GetScale() );
        m_canvas->SetZoom( zoom );

        VECTOR2D center = view->GetCenter();
            RedrawScreen( wxPoint( center.x, center.y ), false );
        }
        AdjustScrollBars( wxPoint( center.x, center.y ) );
    }

    m_canvas->SetEvtHandlerEnabled( !aEnable );
+27 −14
Original line number Diff line number Diff line
@@ -33,8 +33,6 @@
#include <fctsys.h>
#include <id.h>
#include <class_drawpanel.h>
#include <class_draw_panel_gal.h>
#include <gal/graphics_abstraction_layer.h>
#include <view/view.h>
#include <class_base_screen.h>
#include <draw_frame.h>
@@ -46,6 +44,9 @@

void EDA_DRAW_FRAME::RedrawScreen( const wxPoint& aCenterPoint, bool aWarpPointer )
{
    if( IsGalCanvasActive() )
        return;

    AdjustScrollBars( aCenterPoint );

    // 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 )
{
    if( IsGalCanvasActive() )
        return;

    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 newCenter = m_canvas->ToLogicalXY( newScreenPos - dPos );
@@ -186,18 +190,7 @@ void EDA_DRAW_FRAME::OnZoom( wxCommandEvent& event )
        break;

    default:
        unsigned i;

        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 );
        SetPresetZoom( id - ID_POPUP_ZOOM_LEVEL_START );
    }

    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.
 *  used in OnRightClick(wxMouseEvent& event)
 */
+1 −1
Original line number Diff line number Diff line
@@ -215,7 +215,7 @@ public:
    int                 m_ScreenNumber;
    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;

public:
+13 −0
Original line number Diff line number Diff line
@@ -346,6 +346,12 @@ public:
     */
    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 Process_PageSettings( wxCommandEvent& event );

@@ -505,6 +511,13 @@ public:
     */
    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
     * redraws the entire screen area by updating the scroll bars and mouse pointer in
+10 −6
Original line number Diff line number Diff line
@@ -181,30 +181,34 @@ TOOL_ACTION COMMON_ACTIONS::arcPosture( "pcbnew.InteractiveDrawing.arcPosture",


// View Controls
TOOL_ACTION COMMON_ACTIONS::zoomIn( "pcbnew.Control.zoomIn",
TOOL_ACTION COMMON_ACTIONS::zoomIn( "common.Control.zoomIn",
        AS_GLOBAL, WXK_F1,
        "", "" );

TOOL_ACTION COMMON_ACTIONS::zoomOut( "pcbnew.Control.zoomOut",
TOOL_ACTION COMMON_ACTIONS::zoomOut( "common.Control.zoomOut",
        AS_GLOBAL, WXK_F2,
        "", "" );

TOOL_ACTION COMMON_ACTIONS::zoomInCenter( "pcbnew.Control.zoomInCenter",
TOOL_ACTION COMMON_ACTIONS::zoomInCenter( "common.Control.zoomInCenter",
        AS_GLOBAL, 0,
        "", "" );

TOOL_ACTION COMMON_ACTIONS::zoomOutCenter( "pcbnew.Control.zoomOutCenter",
TOOL_ACTION COMMON_ACTIONS::zoomOutCenter( "common.Control.zoomOutCenter",
        AS_GLOBAL, 0,
        "", "" );

TOOL_ACTION COMMON_ACTIONS::zoomCenter( "pcbnew.Control.zoomCenter",
TOOL_ACTION COMMON_ACTIONS::zoomCenter( "common.Control.zoomCenter",
        AS_GLOBAL, WXK_F4,
        "", "" );

TOOL_ACTION COMMON_ACTIONS::zoomFitScreen( "pcbnew.Control.zoomFitScreen",
TOOL_ACTION COMMON_ACTIONS::zoomFitScreen( "common.Control.zoomFitScreen",
        AS_GLOBAL, WXK_HOME,
        "", "" );

TOOL_ACTION COMMON_ACTIONS::zoomPreset( "common.Control.zoomPreset",
        AS_GLOBAL, 0,
        "", "" );


// Display modes
TOOL_ACTION COMMON_ACTIONS::trackDisplayMode( "pcbnew.Control.trackDisplayMode",
Loading