From 51c0ae3480d62a8f713c1e87935a0734c20d58a3 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Wed, 1 Jul 2015 03:46:42 +0200 Subject: [PATCH] Fixed cursor offset in GAL. --- common/gal/cairo/cairo_gal.cpp | 8 ++++++-- common/gal/opengl/opengl_gal.cpp | 6 +++++- pcbnew/tools/pcbnew_control.cpp | 26 +++++++++++--------------- 3 files changed, 22 insertions(+), 18 deletions(-) diff --git a/common/gal/cairo/cairo_gal.cpp b/common/gal/cairo/cairo_gal.cpp index 3ce89e7ea5..07714ec775 100644 --- a/common/gal/cairo/cairo_gal.cpp +++ b/common/gal/cairo/cairo_gal.cpp @@ -73,6 +73,9 @@ CAIRO_GAL::CAIRO_GAL( wxWindow* aParent, wxEvtHandler* aMouseListener, Connect( wxEVT_ENTER_WINDOW, wxMouseEventHandler( CAIRO_GAL::skipMouseEvent ) ); #endif + SetSize( aParent->GetSize() ); + screenSize = VECTOR2I( aParent->GetSize() ); + cursorPixels = NULL; cursorPixelsSaved = NULL; initCursor(); @@ -300,8 +303,7 @@ void CAIRO_GAL::DrawCurve( const VECTOR2D& aStartPoint, const VECTOR2D& aControl void CAIRO_GAL::ResizeScreen( int aWidth, int aHeight ) { - SetSize( wxSize( aWidth, aHeight ) ); - screenSize = m_parent->GetClientSize(); // use client size to subtract scrollbars size + screenSize = VECTOR2I( aWidth, aHeight ); // Recreate the bitmaps deleteBitmaps(); @@ -311,6 +313,8 @@ void CAIRO_GAL::ResizeScreen( int aWidth, int aHeight ) compositor->Resize( aWidth, aHeight ); validCompositor = false; + + SetSize( wxSize( aWidth, aHeight ) ); } diff --git a/common/gal/opengl/opengl_gal.cpp b/common/gal/opengl/opengl_gal.cpp index 0ecb3f2453..73b164a868 100644 --- a/common/gal/opengl/opengl_gal.cpp +++ b/common/gal/opengl/opengl_gal.cpp @@ -96,6 +96,9 @@ OPENGL_GAL::OPENGL_GAL( wxWindow* aParent, wxEvtHandler* aMouseListener, Connect( wxEVT_ENTER_WINDOW, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) ); #endif + SetSize( aParent->GetSize() ); + screenSize = VECTOR2I( aParent->GetSize() ); + // Grid color settings are different in Cairo and OpenGL SetGridColor( COLOR4D( 0.8, 0.8, 0.8, 0.1 ) ); @@ -536,6 +539,8 @@ void OPENGL_GAL::DrawCurve( const VECTOR2D& aStartPoint, const VECTOR2D& aContro void OPENGL_GAL::ResizeScreen( int aWidth, int aHeight ) { + screenSize = VECTOR2I( aWidth, aHeight ); + #ifdef RETINA_OPENGL_PATCH const float scaleFactor = GetBackingScaleFactor(); #else @@ -547,7 +552,6 @@ void OPENGL_GAL::ResizeScreen( int aWidth, int aHeight ) isFramebufferInitialized = false; wxGLCanvas::SetSize( aWidth, aHeight ); - screenSize = m_parent->GetClientSize(); // use client size to subtract scrollbars size } diff --git a/pcbnew/tools/pcbnew_control.cpp b/pcbnew/tools/pcbnew_control.cpp index fd8b509883..fc789302a1 100644 --- a/pcbnew/tools/pcbnew_control.cpp +++ b/pcbnew/tools/pcbnew_control.cpp @@ -117,31 +117,27 @@ int PCBNEW_CONTROL::ZoomCenter( const TOOL_EVENT& aEvent ) int PCBNEW_CONTROL::ZoomFitScreen( const TOOL_EVENT& aEvent ) { - KIGFX::VIEW* view = m_frame->GetGalCanvas()->GetView(); - KIGFX::GAL* gal = m_frame->GetGalCanvas()->GetGAL(); + KIGFX::VIEW* view = getView(); + EDA_DRAW_PANEL_GAL* galCanvas = m_frame->GetGalCanvas(); BOARD* board = getModel(); board->ComputeBoundingBox(); - BOX2I boardBBox = board->ViewBBox(); - const VECTOR2I& screenSize = gal->GetScreenPixelSize(); - if( boardBBox.GetSize().x == 0 || boardBBox.GetSize().y == 0 ) + BOX2I boardBBox = board->ViewBBox(); + VECTOR2I screenSize = galCanvas->GetClientSize(); + VECTOR2I scrollbarSize = VECTOR2I( galCanvas->GetSize() ) - screenSize; + VECTOR2D worldScrollbarSize = view->ToWorld( scrollbarSize, false ); + + if( boardBBox.GetWidth() == 0 || boardBBox.GetHeight() == 0 ) { // Empty view - view->SetCenter( view->ToWorld( VECTOR2D( screenSize.x / 2, screenSize.y / 2 ) ) ); view->SetScale( 17.0 ); + view->SetCenter( view->ToWorld( VECTOR2D( screenSize + scrollbarSize ) / 2, false ) ); } 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 ); + view->SetViewport( BOX2D( boardBBox.GetOrigin(), + boardBBox.GetSize() + worldScrollbarSize ) ); } return 0;