コード例 #1
0
int PCBNEW_CONTROL::ZoomFitScreen( const TOOL_EVENT& aEvent )
{
    KIGFX::VIEW* view = m_frame->GetGalCanvas()->GetView();
    KIGFX::GAL* gal = m_frame->GetGalCanvas()->GetGAL();
    BOARD* board = getModel<BOARD>();
    board->ComputeBoundingBox();
    BOX2I boardBBox = board->ViewBBox();
    VECTOR2I screenSize = gal->GetScreenPixelSize();

    if( boardBBox.GetSize().x == 0 || boardBBox.GetSize().y == 0 )
    {
        // Empty view
        view->SetCenter( view->ToWorld( VECTOR2D( screenSize.x / 2, screenSize.y / 2 ) ) );
        view->SetScale( 17.0 );
    }
    else
    {
        // Autozoom to board
        double iuPerX = screenSize.x ? boardBBox.GetWidth() / screenSize.x : 1.0;
        double iuPerY = screenSize.y ? boardBBox.GetHeight() / screenSize.y : 1.0;

        double bestZoom = std::max( iuPerX, iuPerY );
        double zoomFactor = gal->GetWorldScale() / gal->GetZoomFactor();
        double zoom = 1.0 / ( zoomFactor * bestZoom );

        view->SetCenter( boardBBox.Centre() );
        view->SetScale( zoom );
    }

    return 0;
}
コード例 #2
0
int PCBNEW_CONTROL::ZoomFitScreen( TOOL_EVENT& aEvent )
{
    KIGFX::VIEW* view = m_frame->GetGalCanvas()->GetView();
    KIGFX::GAL* gal = m_frame->GetGalCanvas()->GetGAL();
    BOX2I boardBBox  = getModel<BOARD>( PCB_T )->ViewBBox();
    VECTOR2I screenSize = gal->GetScreenPixelSize();

    double iuPerX = screenSize.x ? boardBBox.GetWidth() / screenSize.x : 1.0;
    double iuPerY = screenSize.y ? boardBBox.GetHeight() / screenSize.y : 1.0;

    double bestZoom = std::max( iuPerX, iuPerY );
    // This is needed to avoid "jumpy" zooms if first hot key was used and then mouse scroll
    // (or other way round).
    m_frame->GetScreen()->SetZoom( bestZoom );

    double zoomFactor = gal->GetWorldScale() / gal->GetZoomFactor();
    double zoom = 1.0 / ( zoomFactor * bestZoom );

    view->SetScale( zoom );
    view->SetCenter( boardBBox.Centre() );
    setTransitions();

    return 0;
}