diff --git a/common/legacy_gal/eda_draw_frame.cpp b/common/legacy_gal/eda_draw_frame.cpp index 75fd45c7ee..9d8718c52c 100644 --- a/common/legacy_gal/eda_draw_frame.cpp +++ b/common/legacy_gal/eda_draw_frame.cpp @@ -237,7 +237,7 @@ EDA_DRAW_FRAME::~EDA_DRAW_FRAME() socket->Destroy(); } - if( m_canvasTypeDirty ) + if( m_canvasTypeDirty ) // the canvas type has changed: save the new type saveCanvasTypeSetting( m_canvasType ); delete m_actions; @@ -1076,7 +1076,7 @@ EDA_DRAW_PANEL_GAL::GAL_TYPE EDA_DRAW_FRAME::LoadCanvasTypeSetting() if( canvasType < EDA_DRAW_PANEL_GAL::GAL_TYPE_NONE || canvasType >= EDA_DRAW_PANEL_GAL::GAL_TYPE_LAST ) { - assert( false ); + wxASSERT( false ); canvasType = EDA_DRAW_PANEL_GAL::GAL_TYPE_NONE; } @@ -1089,7 +1089,7 @@ bool EDA_DRAW_FRAME::saveCanvasTypeSetting( EDA_DRAW_PANEL_GAL::GAL_TYPE aCanvas if( aCanvasType < EDA_DRAW_PANEL_GAL::GAL_TYPE_NONE || aCanvasType >= EDA_DRAW_PANEL_GAL::GAL_TYPE_LAST ) { - assert( false ); + wxASSERT( false ); return false; } @@ -1364,9 +1364,9 @@ void EDA_DRAW_FRAME::OnZoom( wxCommandEvent& event ) return; int id = event.GetId(); - bool zoom_at_cursor = false; - BASE_SCREEN* screen = GetScreen(); - wxPoint center = GetScrollCenterPosition(); + bool warp_cursor = false; + VECTOR2D cpos = GetCrossHairPosition();//GetGalCanvas()->GetViewControls()->GetCursorPosition(); + wxPoint zoom_center( (int)cpos.x, (int)cpos.y ); if ( id == ID_KEY_ZOOM_IN ) { @@ -1382,39 +1382,27 @@ void EDA_DRAW_FRAME::OnZoom( wxCommandEvent& event ) switch( id ) { case ID_OFFCENTER_ZOOM_IN: - center = m_canvas->ToDeviceXY( GetCrossHairPosition() ); - - if( screen->SetPreviousZoom() ) - RedrawScreen2( center ); + SetPreviousZoomAndRedraw( zoom_center,warp_cursor ); break; case ID_POPUP_ZOOM_IN: - zoom_at_cursor = true; - center = GetCrossHairPosition(); - - // fall thru + warp_cursor = true; + // fall thru case ID_VIEWER_ZOOM_IN: case ID_ZOOM_IN: - if( screen->SetPreviousZoom() ) - RedrawScreen( center, zoom_at_cursor ); + SetPreviousZoomAndRedraw( zoom_center,warp_cursor ); break; case ID_OFFCENTER_ZOOM_OUT: - center = m_canvas->ToDeviceXY( GetCrossHairPosition() ); - - if( screen->SetNextZoom() ) - RedrawScreen2( center ); + SetNextZoomAndRedraw( zoom_center, warp_cursor ); break; case ID_POPUP_ZOOM_OUT: - zoom_at_cursor = true; - center = GetCrossHairPosition(); - - // fall thru + warp_cursor = true; + // fall thru case ID_VIEWER_ZOOM_OUT: case ID_ZOOM_OUT: - if( screen->SetNextZoom() ) - RedrawScreen( center, zoom_at_cursor ); + SetNextZoomAndRedraw( zoom_center, warp_cursor ); break; case ID_VIEWER_ZOOM_REDRAW: @@ -1425,8 +1413,8 @@ void EDA_DRAW_FRAME::OnZoom( wxCommandEvent& event ) break; case ID_POPUP_ZOOM_CENTER: - center = GetCrossHairPosition(); - RedrawScreen( center, true ); + GetGalCanvas()->GetView()->SetScale( GetGalCanvas()->GetView()->GetScale(), zoom_center ); + GetGalCanvas()->GetViewControls()->CenterOnCursor(); break; case ID_POPUP_ZOOM_PAGE: @@ -1462,6 +1450,64 @@ void EDA_DRAW_FRAME::SetPrevZoom() } +void EDA_DRAW_FRAME::SetNextZoomAndRedraw( const wxPoint& aCenterPoint, bool aWarpPointer ) +{ + double zoom = GetGalCanvas()->GetLegacyZoom(); + zoom *= 1.3; + + // Now look for the next closest menu step + std::vector& zoomList = GetScreen()->m_ZoomList; + int idx; + + for( idx = 0; idx < (int)zoomList.size(); ++idx ) + { + if( zoomList[idx] > zoom ) + break; + } + + if( idx >= (int)zoomList.size() ) + return; + + VECTOR2D cpos = GetGalCanvas()->GetViewControls()->GetCursorPosition(); + wxPoint center( (int)cpos.x, (int)cpos.y ); + + if( m_zoomSelectBox ) + m_zoomSelectBox->SetSelection( idx ); + + if( GetScreen()->SetZoom( GetScreen()->m_ZoomList[idx] ) ) + RedrawScreen( aCenterPoint, true ); +} + + +void EDA_DRAW_FRAME::SetPreviousZoomAndRedraw( const wxPoint& aCenterPoint, bool aWarpPointer ) +{ + double zoom = GetGalCanvas()->GetLegacyZoom(); + zoom /= 1.3; + + // Now look for the next closest menu step + std::vector& zoomList = GetScreen()->m_ZoomList; + int idx; + + for( idx = zoomList.size() - 1; idx >= 0; --idx ) + { + if( zoomList[idx] < zoom ) + break; + } + + if( idx < 0 ) + return; + + VECTOR2D cpos = GetGalCanvas()->GetViewControls()->GetCursorPosition(); + wxPoint center( (int)cpos.x, (int)cpos.y ); + + if( m_zoomSelectBox ) + m_zoomSelectBox->SetSelection( idx ); + + if( GetScreen()->SetZoom( GetScreen()->m_ZoomList[idx] ) ) + RedrawScreen( aCenterPoint, aWarpPointer ); +} + + void EDA_DRAW_FRAME::SetPresetZoom( int aIndex ) { BASE_SCREEN* screen = GetScreen(); diff --git a/eeschema/sch_base_frame.cpp b/eeschema/sch_base_frame.cpp index b355eea693..3a71df32b7 100644 --- a/eeschema/sch_base_frame.cpp +++ b/eeschema/sch_base_frame.cpp @@ -143,6 +143,8 @@ void SCH_BASE_FRAME::OnSwitchCanvas( wxCommandEvent& aEvent ) return; GetGalCanvas()->SwitchBackend( new_type ); + m_canvasTypeDirty = true; // force saving new canvas type in config + m_canvasType = new_type; } @@ -461,7 +463,7 @@ void SCH_BASE_FRAME::RedrawScreen( const wxPoint& aCenterPoint, bool aWarpPointe GetCanvas()->GetView()->SetScale( scale ); if( aWarpPointer ) - GetCanvas()->GetViewControls()->WarpCursor( aCenterPoint ); + GetCanvas()->GetViewControls()->CenterOnCursor(); GetCanvas()->Refresh(); } diff --git a/eeschema/sch_draw_panel.cpp b/eeschema/sch_draw_panel.cpp index 4aa36700e2..95d593664e 100644 --- a/eeschema/sch_draw_panel.cpp +++ b/eeschema/sch_draw_panel.cpp @@ -40,10 +40,9 @@ using namespace std::placeholders; - // Events used by EDA_DRAW_PANEL // GAL TODO: some (most?) of these need to be implemented... -BEGIN_EVENT_TABLE( SCH_DRAW_PANEL, wxScrolledWindow ) +BEGIN_EVENT_TABLE( SCH_DRAW_PANEL, wxScrolledCanvas ) // EVT_LEAVE_WINDOW( EDA_DRAW_PANEL::OnMouseLeaving ) // EVT_ENTER_WINDOW( EDA_DRAW_PANEL::OnMouseEntering ) // EVT_MOUSEWHEEL( EDA_DRAW_PANEL::OnMouseWheel ) @@ -381,17 +380,7 @@ void SCH_DRAW_PANEL::OnMouseEvent( wxMouseEvent& event ) if( event.MiddleIsDown() ) { -/* Not used in GAL canvas - wxPoint currentPosition = event.GetPosition(); - - double scale = GetParent()->GetScreen()->GetScalingFactor(); - int x = m_PanStartCenter.x + - KiROUND( (double) ( m_PanStartEventPosition.x - currentPosition.x ) / scale ); - int y = m_PanStartCenter.y + - KiROUND( (double) ( m_PanStartEventPosition.y - currentPosition.y ) / scale ); - - GetParent()->RedrawScreen( wxPoint( x, y ), false ); -*/ + // already managed by EDA_DRAW_PANEL_GAL mouse event handler. return; } diff --git a/include/draw_frame.h b/include/draw_frame.h index c9948761ec..ae54b260cb 100644 --- a/include/draw_frame.h +++ b/include/draw_frame.h @@ -72,7 +72,6 @@ class EDA_DRAW_FRAME : public KIWAY_PLAYER BASE_SCREEN* m_currentScreen; ///< current used SCREEN bool m_snapToGrid; ///< Indicates if cursor should be snapped to grid. - bool m_galCanvasActive; ///< whether to use new GAL engine EDA_DRAW_PANEL_GAL* m_galCanvas; @@ -80,6 +79,7 @@ class EDA_DRAW_FRAME : public KIWAY_PLAYER KIGFX::GAL_DISPLAY_OPTIONS m_galDisplayOptions; protected: + bool m_galCanvasActive; ///< whether to use new GAL engine bool m_useSingleCanvasPane; wxSocketServer* m_socketServer; @@ -648,12 +648,28 @@ public: */ void SetNextZoom(); + /** + * changes the zoom to the next one available redraws the screen + * and warp the mouse pointer on request. + * @param aCenterPoint is the reference point for zooming + * @param aWarpPointer = true to move the pointer to the aCenterPoint + */ + void SetNextZoomAndRedraw( const wxPoint& aCenterPoint, bool aWarpPointer ); + /** * Function SetPrevZoom() * changes the zoom to the previous one available. */ void SetPrevZoom(); + /** + * changes the zoom to the previous one available redraws the screen + * and warp the mouse pointer on request. + * @param aCenterPoint is the reference point for zooming + * @param aWarpPointer = true to move the pointer to the aCenterPoint + */ + void SetPreviousZoomAndRedraw( const wxPoint& aCenterPoint, bool aWarpPointer ); + /** * Function SetPresetZoom() * changes zoom to one of the preset values. diff --git a/include/legacy_gal/class_drawpanel.h b/include/legacy_gal/class_drawpanel.h index 0f2ef13d59..c0564d04a5 100644 --- a/include/legacy_gal/class_drawpanel.h +++ b/include/legacy_gal/class_drawpanel.h @@ -94,7 +94,7 @@ public: * A way to pass info to draw functions. * this is just an accessor to the GetDisplayOptions() parent frame function. */ - virtual void* GetDisplayOptions() { printf("Unimplemented\n"); assert(false); return nullptr; }; + virtual void* GetDisplayOptions() { printf("EDA_DRAW_PANEL:Unimplemented\n"); wxASSERT(false); return nullptr; }; virtual BASE_SCREEN* GetScreen() = 0; @@ -143,7 +143,7 @@ public: * X and Y axis * X and Y auxiliary axis */ - virtual void DrawBackGround( wxDC* DC ) { printf("Unimplemented\n"); }; + virtual void DrawBackGround( wxDC* DC ) { printf("EDA_DRAW_PANEL:Unimplemented1\n"); }; /** * Function DrawGrid @@ -153,7 +153,7 @@ public: * @see EDA_DRAW_FRAME::GetGridColor() for the color of the grid. * @param aDC The device context to draw the grid. */ - virtual void DrawGrid( wxDC* aDC ) { printf("Unimplemented\n"); }; + virtual void DrawGrid( wxDC* aDC ) { printf("EDA_DRAW_PANEL:Unimplemented2\n"); }; /** * Function DrawAuxiliaryAxis @@ -162,7 +162,7 @@ public: * @param aDC = current Device Context * @param aDrawMode = draw mode (GR_COPY, GR_OR ..) */ - virtual void DrawAuxiliaryAxis( wxDC* aDC, GR_DRAWMODE aDrawMode ) { printf("Unimplemented\n");}; + virtual void DrawAuxiliaryAxis( wxDC* aDC, GR_DRAWMODE aDrawMode ) { printf("EDA_DRAW_PANEL:Unimplemented2\n");}; /** * Function DrawGridAxis @@ -172,7 +172,7 @@ public: * @param aDrawMode = draw mode (GR_COPY, GR_OR ..) * @param aGridOrigin = the absolute coordinate of grid origin for snap. */ - virtual void DrawGridAxis( wxDC* aDC, GR_DRAWMODE aDrawMode, const wxPoint& aGridOrigin ) { printf("Unimplemented\n"); }; + virtual void DrawGridAxis( wxDC* aDC, GR_DRAWMODE aDrawMode, const wxPoint& aGridOrigin ) { printf("EDA_DRAW_PANEL:Unimplemented4\n"); }; /** * Function DeviceToLogical @@ -184,7 +184,7 @@ public: * @param aDC The device context used for the conversion. * @return A rectangle converted to drawing units. */ - virtual wxRect DeviceToLogical( const wxRect& aRect, wxDC& aDC ) { printf("Unimplemented\n");assert(false); return wxRect(); }; + virtual wxRect DeviceToLogical( const wxRect& aRect, wxDC& aDC ) { printf("EDA_DRAW_PANEL:Unimplemented5\n");wxASSERT(false); return wxRect(); }; /* Mouse and keys events */ @@ -198,13 +198,13 @@ public: *

*/ - virtual void EraseScreen( wxDC* DC ) { printf("Unimplemented\n"); };; + virtual void EraseScreen( wxDC* DC ) { printf("EDA_DRAW_PANEL:Unimplemented6\n"); };; - virtual void SetZoom( double mode ) { printf("Unimplemented\n"); };; - virtual double GetZoom() { printf("Unimplemented\n"); return 1.0; };; + virtual void SetZoom( double mode ) { printf("EDA_DRAW_PANEL:Unimplemented7\n"); };; + virtual double GetZoom() { printf("EDA_DRAW_PANEL:Unimplemented8\n"); return 1.0; };; - //virtual void SetGrid( const wxRealPoint& size ) { printf("Unimplemented\n"); };; - //virtual wxRealPoint GetGrid() { printf("Unimplemented\n"); return wxRealPoint(1.0, 1.0); };; + //virtual void SetGrid( const wxRealPoint& size ) { printf("EDA_DRAW_PANEL:Unimplemented\n"); };; + //virtual wxRealPoint GetGrid() { printf("EDA_DRAW_PANEL:Unimplemented\n"); return wxRealPoint(1.0, 1.0); };; /** @@ -213,7 +213,7 @@ public: * @return true if \a aPosition is visible on the screen. * false if \a aPosition is not visible on the screen. */ - virtual bool IsPointOnDisplay( const wxPoint& aPosition ) { printf("Unimplemented\n"); return false; };; + virtual bool IsPointOnDisplay( const wxPoint& aPosition ) { printf("EDA_DRAW_PANEL:Unimplemented9\n"); return false; };; /** * Function SetClipBox @@ -231,9 +231,9 @@ public: * @param aRect The clip rectangle in device units or NULL for the entire visible area * of the screen. */ - virtual void SetClipBox( wxDC& aDC, const wxRect* aRect = NULL ) { printf("Unimplemented\n"); };; + virtual void SetClipBox( wxDC& aDC, const wxRect* aRect = NULL ) { printf("EDA_DRAW_PANEL:Unimplemented10\n"); };; - virtual void ReDraw( wxDC* aDC, bool aEraseBackground = true ) { printf("Unimplemented\n"); };; + virtual void ReDraw( wxDC* aDC, bool aEraseBackground = true ) { printf("EDA_DRAW_PANEL:Unimplemented11\n"); };; /** * Function RefreshDrawingRect @@ -242,7 +242,7 @@ public: * @param aRect The rectangle to repaint. * @param aEraseBackground Erases the background if true. */ - virtual void RefreshDrawingRect( const EDA_RECT& aRect, bool aEraseBackground = true ) { printf("Unimplemented\n"); };; + virtual void RefreshDrawingRect( const EDA_RECT& aRect, bool aEraseBackground = true ) { printf("EDA_DRAW_PANEL:Unimplemented12\n"); };; /// @copydoc wxWindow::Refresh() //virtual void Refresh( bool eraseBackground = true, const wxRect* rect = NULL ); @@ -251,32 +251,32 @@ public: * Function GetScreenCenterLogicalPosition * @return The current screen center position in logical (drawing) units. */ - virtual wxPoint GetScreenCenterLogicalPosition() { printf("Unimplemented\n"); return wxPoint(0, 0); };; + virtual wxPoint GetScreenCenterLogicalPosition() { printf("EDA_DRAW_PANEL:Unimplemented13\n"); return wxPoint(0, 0); };; /** * Function MoveCursorToCrossHair * warps the cursor to the current cross hair position. */ - virtual void MoveCursorToCrossHair() { printf("Unimplemented\n"); };; + virtual void MoveCursorToCrossHair() { printf("EDA_DRAW_PANEL:Unimplemented14\n"); };; /** * Function ToDeviceXY * transforms logical to device coordinates */ - virtual wxPoint ToDeviceXY( const wxPoint& pos ) { printf("Unimplemented\n"); return wxPoint(0, 0); };; + virtual wxPoint ToDeviceXY( const wxPoint& pos ) { printf("EDA_DRAW_PANEL:Unimplemented15\n"); return wxPoint(0, 0); };; /** * Function ToLogicalXY * transforms device to logical coordinates */ - virtual wxPoint ToLogicalXY( const wxPoint& pos ) { printf("Unimplemented\n"); return wxPoint(0, 0); };; + virtual wxPoint ToLogicalXY( const wxPoint& pos ) { printf("EDA_DRAW_PANEL:Unimplemented16\n"); return wxPoint(0, 0); };; /** * Function MoveCursor * moves the mouse pointer to \a aPosition in logical (drawing) units. * @param aPosition The position in logical units to move the cursor. */ - virtual void MoveCursor( const wxPoint& aPosition ) { printf("Unimplemented\n"); };; + virtual void MoveCursor( const wxPoint& aPosition ) { printf("EDA_DRAW_PANEL:Unimplemented17\n"); };; /* Cursor functions */ /** @@ -291,13 +291,13 @@ public: * @param aDC - the device context to draw the cursor * @param aColor - the color to draw the cursor */ - virtual void DrawCrossHair( wxDC* aDC=nullptr, COLOR4D aColor = COLOR4D::WHITE ) { printf("Unimplemented\n"); };; + virtual void DrawCrossHair( wxDC* aDC=nullptr, COLOR4D aColor = COLOR4D::WHITE ) { printf("EDA_DRAW_PANEL:Unimplemented18\n"); };; // Hide the cross hair. - virtual void CrossHairOff( wxDC* DC=nullptr ) { printf("Unimplemented\n"); };; + virtual void CrossHairOff( wxDC* DC=nullptr ) { printf("EDA_DRAW_PANEL:Unimplemented19\n"); };; // Show the cross hair. - virtual void CrossHairOn( wxDC* DC=nullptr ) { printf("Unimplemented\n"); };; + virtual void CrossHairOn( wxDC* DC=nullptr ) { printf("EDA_DRAW_PANEL:Unimplemented20\n"); };; /** * Function SetMouseCapture @@ -332,7 +332,7 @@ public: */ virtual void EndMouseCapture( int aId = -1, int aCursorId = -1, const wxString& aTitle = wxEmptyString, - bool aCallEndFunc = true ) { printf("Unimplemented\n"); assert(false); };; + bool aCallEndFunc = true ) { printf("EDA_DRAW_PANEL:Unimplemented21\n"); wxASSERT(false); };; inline bool IsMouseCaptured() const { return m_mouseCaptureCallback != NULL; } @@ -346,7 +346,7 @@ public: * @param aErase True indicates the item being drawn should be erase before drawing * it a \a aPosition. */ - virtual void CallMouseCapture( wxDC* aDC, const wxPoint& aPosition, bool aErase ) { printf("Unimplemented\n"); assert(false); };; + virtual void CallMouseCapture( wxDC* aDC, const wxPoint& aPosition, bool aErase ) { printf("EDA_DRAW_PANEL:Unimplemented22\n"); wxASSERT(false); };; /** * Function CallEndMouseCapture @@ -354,7 +354,7 @@ public: * * @param aDC A point to a wxDC object to perform any drawing upon. */ - virtual void CallEndMouseCapture( wxDC* aDC ) { printf("Unimplemented\n"); assert(false); };; + virtual void CallEndMouseCapture( wxDC* aDC ) { printf("EDA_DRAW_PANEL:Unimplemented23\n"); wxASSERT(false); };; virtual void Refresh( bool eraseBackground = true, const wxRect* rect = NULL ) {}