Fixed cursor offset in GAL.

This commit is contained in:
Maciej Suminski 2015-07-01 03:46:42 +02:00
parent 6ad6f0bde2
commit 51c0ae3480
3 changed files with 22 additions and 18 deletions

View File

@ -73,6 +73,9 @@ CAIRO_GAL::CAIRO_GAL( wxWindow* aParent, wxEvtHandler* aMouseListener,
Connect( wxEVT_ENTER_WINDOW, wxMouseEventHandler( CAIRO_GAL::skipMouseEvent ) ); Connect( wxEVT_ENTER_WINDOW, wxMouseEventHandler( CAIRO_GAL::skipMouseEvent ) );
#endif #endif
SetSize( aParent->GetSize() );
screenSize = VECTOR2I( aParent->GetSize() );
cursorPixels = NULL; cursorPixels = NULL;
cursorPixelsSaved = NULL; cursorPixelsSaved = NULL;
initCursor(); initCursor();
@ -300,8 +303,7 @@ void CAIRO_GAL::DrawCurve( const VECTOR2D& aStartPoint, const VECTOR2D& aControl
void CAIRO_GAL::ResizeScreen( int aWidth, int aHeight ) void CAIRO_GAL::ResizeScreen( int aWidth, int aHeight )
{ {
SetSize( wxSize( aWidth, aHeight ) ); screenSize = VECTOR2I( aWidth, aHeight );
screenSize = m_parent->GetClientSize(); // use client size to subtract scrollbars size
// Recreate the bitmaps // Recreate the bitmaps
deleteBitmaps(); deleteBitmaps();
@ -311,6 +313,8 @@ void CAIRO_GAL::ResizeScreen( int aWidth, int aHeight )
compositor->Resize( aWidth, aHeight ); compositor->Resize( aWidth, aHeight );
validCompositor = false; validCompositor = false;
SetSize( wxSize( aWidth, aHeight ) );
} }

View File

@ -96,6 +96,9 @@ OPENGL_GAL::OPENGL_GAL( wxWindow* aParent, wxEvtHandler* aMouseListener,
Connect( wxEVT_ENTER_WINDOW, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) ); Connect( wxEVT_ENTER_WINDOW, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) );
#endif #endif
SetSize( aParent->GetSize() );
screenSize = VECTOR2I( aParent->GetSize() );
// Grid color settings are different in Cairo and OpenGL // Grid color settings are different in Cairo and OpenGL
SetGridColor( COLOR4D( 0.8, 0.8, 0.8, 0.1 ) ); 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 ) void OPENGL_GAL::ResizeScreen( int aWidth, int aHeight )
{ {
screenSize = VECTOR2I( aWidth, aHeight );
#ifdef RETINA_OPENGL_PATCH #ifdef RETINA_OPENGL_PATCH
const float scaleFactor = GetBackingScaleFactor(); const float scaleFactor = GetBackingScaleFactor();
#else #else
@ -547,7 +552,6 @@ void OPENGL_GAL::ResizeScreen( int aWidth, int aHeight )
isFramebufferInitialized = false; isFramebufferInitialized = false;
wxGLCanvas::SetSize( aWidth, aHeight ); wxGLCanvas::SetSize( aWidth, aHeight );
screenSize = m_parent->GetClientSize(); // use client size to subtract scrollbars size
} }

View File

@ -117,31 +117,27 @@ int PCBNEW_CONTROL::ZoomCenter( const TOOL_EVENT& aEvent )
int PCBNEW_CONTROL::ZoomFitScreen( const TOOL_EVENT& aEvent ) int PCBNEW_CONTROL::ZoomFitScreen( const TOOL_EVENT& aEvent )
{ {
KIGFX::VIEW* view = m_frame->GetGalCanvas()->GetView(); KIGFX::VIEW* view = getView();
KIGFX::GAL* gal = m_frame->GetGalCanvas()->GetGAL(); EDA_DRAW_PANEL_GAL* galCanvas = m_frame->GetGalCanvas();
BOARD* board = getModel<BOARD>(); BOARD* board = getModel<BOARD>();
board->ComputeBoundingBox(); 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 // Empty view
view->SetCenter( view->ToWorld( VECTOR2D( screenSize.x / 2, screenSize.y / 2 ) ) );
view->SetScale( 17.0 ); view->SetScale( 17.0 );
view->SetCenter( view->ToWorld( VECTOR2D( screenSize + scrollbarSize ) / 2, false ) );
} }
else else
{ {
// Autozoom to board // Autozoom to board
double iuPerX = screenSize.x ? boardBBox.GetWidth() / screenSize.x : 1.0; view->SetViewport( BOX2D( boardBBox.GetOrigin(),
double iuPerY = screenSize.y ? boardBBox.GetHeight() / screenSize.y : 1.0; boardBBox.GetSize() + worldScrollbarSize ) );
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; return 0;