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 ) );
#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 ) );
}

View File

@ -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
}

View File

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