From dbc4a8f29261ce2739a64455447609b692989b2c Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Thu, 20 Mar 2014 08:47:31 +0100 Subject: [PATCH] GAL zooms in and out using the default hot keys (F1/F2). Screen size is saved in VECTOR2I instead of VECTOR2D. --- common/gal/cairo/cairo_gal.cpp | 6 +++--- common/gal/graphics_abstraction_layer.cpp | 4 ++-- common/gal/opengl/opengl_gal.cpp | 4 ++-- common/view/view.cpp | 2 +- common/zoom.cpp | 5 +++-- include/gal/graphics_abstraction_layer.h | 4 ++-- include/view/view.h | 2 +- pcbnew/menubar_pcbframe.cpp | 20 ++++++++++---------- 8 files changed, 24 insertions(+), 23 deletions(-) diff --git a/common/gal/cairo/cairo_gal.cpp b/common/gal/cairo/cairo_gal.cpp index 393e851235..13055c7aed 100644 --- a/common/gal/cairo/cairo_gal.cpp +++ b/common/gal/cairo/cairo_gal.cpp @@ -70,7 +70,7 @@ CAIRO_GAL::CAIRO_GAL( wxWindow* aParent, wxEvtHandler* aMouseListener, #endif SetSize( aParent->GetSize() ); - screenSize = VECTOR2D( aParent->GetSize() ); + screenSize = VECTOR2I( aParent->GetSize() ); initCursor(); // Grid color settings are different in Cairo and OpenGL @@ -138,7 +138,7 @@ void CAIRO_GAL::EndDrawing() *wxOutputPtr++ = value & 0xff; // Blue pixel } - wxImage img( (int) screenSize.x, (int) screenSize.y, (unsigned char*) wxOutput, true ); + wxImage img( screenSize.x, screenSize.y, (unsigned char*) wxOutput, true ); wxBitmap bmp( img ); wxClientDC client_dc( this ); wxBufferedDC dc; @@ -283,7 +283,7 @@ void CAIRO_GAL::DrawCurve( const VECTOR2D& aStartPoint, const VECTOR2D& aControl void CAIRO_GAL::ResizeScreen( int aWidth, int aHeight ) { - screenSize = VECTOR2D( aWidth, aHeight ); + screenSize = VECTOR2I( aWidth, aHeight ); // Recreate the bitmaps deleteBitmaps(); diff --git a/common/gal/graphics_abstraction_layer.cpp b/common/gal/graphics_abstraction_layer.cpp index 7f57d652c4..724d14ac9e 100644 --- a/common/gal/graphics_abstraction_layer.cpp +++ b/common/gal/graphics_abstraction_layer.cpp @@ -88,7 +88,7 @@ void GAL::ComputeWorldScreenMatrix() MATRIX3x3D translation; translation.SetIdentity(); - translation.SetTranslation( 0.5 * screenSize ); + translation.SetTranslation( 0.5 * VECTOR2D( screenSize ) ); MATRIX3x3D scale; scale.SetIdentity(); @@ -131,7 +131,7 @@ void GAL::DrawGrid() // For the drawing the start points, end points and increments have // to be calculated in world coordinates VECTOR2D worldStartPoint = screenWorldMatrix * VECTOR2D( 0.0, 0.0 ); - VECTOR2D worldEndPoint = screenWorldMatrix * screenSize; + VECTOR2D worldEndPoint = screenWorldMatrix * VECTOR2D( screenSize ); int gridScreenSizeDense = round( gridSize.x * worldScale ); int gridScreenSizeCoarse = round( gridSize.x * static_cast( gridTick ) * worldScale ); diff --git a/common/gal/opengl/opengl_gal.cpp b/common/gal/opengl/opengl_gal.cpp index 81028d6eea..fb8a0fcf4d 100644 --- a/common/gal/opengl/opengl_gal.cpp +++ b/common/gal/opengl/opengl_gal.cpp @@ -86,7 +86,7 @@ OPENGL_GAL::OPENGL_GAL( wxWindow* aParent, wxEvtHandler* aMouseListener, #endif SetSize( aParent->GetSize() ); - screenSize = VECTOR2D( 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 ) ); @@ -562,7 +562,7 @@ void OPENGL_GAL::DrawCurve( const VECTOR2D& aStartPoint, const VECTOR2D& aContro void OPENGL_GAL::ResizeScreen( int aWidth, int aHeight ) { - screenSize = VECTOR2D( aWidth, aHeight ); + screenSize = VECTOR2I( aWidth, aHeight ); // Resize framebuffers compositor.Resize( aWidth, aHeight ); diff --git a/common/view/view.cpp b/common/view/view.cpp index ba070b2786..5cfe071d9f 100644 --- a/common/view/view.cpp +++ b/common/view/view.cpp @@ -771,7 +771,7 @@ void VIEW::Redraw() } -const VECTOR2D& VIEW::GetScreenPixelSize() const +const VECTOR2I& VIEW::GetScreenPixelSize() const { return m_gal->GetScreenPixelSize(); } diff --git a/common/zoom.cpp b/common/zoom.cpp index 6add6bc2f6..859d5a4872 100644 --- a/common/zoom.cpp +++ b/common/zoom.cpp @@ -203,8 +203,9 @@ void EDA_DRAW_FRAME::OnZoom( wxCommandEvent& event ) double zoomFactor = gal->GetWorldScale() / gal->GetZoomFactor(); double zoom = 1.0 / ( zoomFactor * GetZoom() ); - view->SetScale( zoom ); - view->SetCenter( VECTOR2D( center ) ); + VECTOR2D cursorWorld( GetCrossHairPosition() ); + view->SetScale( zoom, cursorWorld ); + GetGalCanvas()->Refresh(); } diff --git a/include/gal/graphics_abstraction_layer.h b/include/gal/graphics_abstraction_layer.h index d49e5e2fad..50b5c355c7 100644 --- a/include/gal/graphics_abstraction_layer.h +++ b/include/gal/graphics_abstraction_layer.h @@ -160,7 +160,7 @@ public: virtual bool Show( bool aShow ) = 0; /// @brief Returns GAL canvas size in pixels - const VECTOR2D& GetScreenPixelSize() const + const VECTOR2I& GetScreenPixelSize() const { return screenSize; } @@ -831,7 +831,7 @@ public: protected: std::stack depthStack; ///< Stored depth values - VECTOR2D screenSize; ///< Screen size in screen coordinates + VECTOR2I screenSize; ///< Screen size in screen coordinates double worldUnitLength; ///< The unit length of the world coordinates [inch] double screenDPI; ///< The dots per inch of the screen diff --git a/include/view/view.h b/include/view/view.h index e103089ae0..694042724f 100644 --- a/include/view/view.h +++ b/include/view/view.h @@ -261,7 +261,7 @@ public: * Returns the size of the our rendering area, in pixels. * @return viewport screen size */ - const VECTOR2D& GetScreenPixelSize() const; + const VECTOR2I& GetScreenPixelSize() const; /** * Function AddLayer() diff --git a/pcbnew/menubar_pcbframe.cpp b/pcbnew/menubar_pcbframe.cpp index 3a340b0c47..f75bd16aaf 100644 --- a/pcbnew/menubar_pcbframe.cpp +++ b/pcbnew/menubar_pcbframe.cpp @@ -328,12 +328,12 @@ void PCB_EDIT_FRAME::ReCreateMenuBar() */ // Zoom In text = AddHotkeyName( _( "Zoom &In" ), g_Pcbnew_Editor_Hokeys_Descr, - HK_ZOOM_IN, IS_ACCELERATOR ); + HK_ZOOM_IN ); AddMenuItem( viewMenu, ID_ZOOM_IN, text, HELP_ZOOM_IN, KiBitmap( zoom_in_xpm ) ); // Zoom Out text = AddHotkeyName( _( "Zoom &Out" ), g_Pcbnew_Editor_Hokeys_Descr, - HK_ZOOM_OUT, IS_ACCELERATOR ); + HK_ZOOM_OUT ); AddMenuItem( viewMenu, ID_ZOOM_OUT, text, HELP_ZOOM_OUT, KiBitmap( zoom_out_xpm ) ); // Fit on Screen @@ -366,38 +366,38 @@ void PCB_EDIT_FRAME::ReCreateMenuBar() viewMenu->AppendSeparator(); text = AddHotkeyName( _( "&Switch canvas to default" ), g_Pcbnew_Editor_Hokeys_Descr, - HK_CANVAS_DEFAULT, IS_ACCELERATOR ); + HK_CANVAS_DEFAULT ); AddMenuItem( viewMenu, ID_MENU_CANVAS_DEFAULT, text, _( "Switch the canvas implementation to default" ), - KiBitmap( tools_xpm ) ); + KiBitmap( tools_xpm ) ); text = AddHotkeyName( _( "&Switch canvas to OpenGL" ), g_Pcbnew_Editor_Hokeys_Descr, - HK_CANVAS_OPENGL, IS_ACCELERATOR ); + HK_CANVAS_OPENGL ); AddMenuItem( viewMenu, ID_MENU_CANVAS_OPENGL, text, _( "Switch the canvas implementation to OpenGL" ), - KiBitmap( tools_xpm ) ); + KiBitmap( tools_xpm ) ); text = AddHotkeyName( _( "&Switch canvas to Cairo" ), g_Pcbnew_Editor_Hokeys_Descr, - HK_CANVAS_CAIRO, IS_ACCELERATOR ); + HK_CANVAS_CAIRO ); AddMenuItem( viewMenu, ID_MENU_CANVAS_CAIRO, text, _( "Switch the canvas implementation to Cairo" ), - KiBitmap( tools_xpm ) ); + KiBitmap( tools_xpm ) ); /** Create Place Menu **/ wxMenu* placeMenu = new wxMenu; // Module text = AddHotkeyName( _( "&Module" ), g_Pcbnew_Editor_Hokeys_Descr, - HK_ADD_MODULE, IS_ACCELERATOR ); + HK_ADD_MODULE ); AddMenuItem( placeMenu, ID_PCB_MODULE_BUTT, text, _( "Add modules" ), KiBitmap( module_xpm ) ); // Track text = AddHotkeyName( _( "&Track" ), g_Pcbnew_Editor_Hokeys_Descr, - HK_ADD_NEW_TRACK, IS_ACCELERATOR ); + HK_ADD_NEW_TRACK ); AddMenuItem( placeMenu, ID_TRACK_BUTT, text, _( "Add tracks and vias" ), KiBitmap( add_tracks_xpm ) );