You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1156 lines
37 KiB

Introduction of Graphics Abstraction Layer based rendering for pcbnew. New classes: - VIEW - represents view that is seen by user, takes care of layer ordering & visibility and how it is displayed (which location, how much zoomed, etc.) - VIEW_ITEM - Base class for every item that can be displayed on VIEW (the biggest change is that now it may be necessary to override ViewBBox & ViewGetLayers method for derived classes). - EDA_DRAW_PANEL_GAL - Inherits after EDA_DRAW_PANEL, displays VIEW output, right now it is not editable (in opposite to usual EDA_DRAW_PANEL). - GAL/OPENGL_GAL/CAIRO_GAL - Base Graphics Abstraction Layer class + two different flavours (Cairo is not fully supported yet), that offers methods to draw primitives using different libraries. - WX_VIEW_CONTROLS - Controller for VIEW, handles user events, allows zooming, panning, etc. - PAINTER/PCB_PAINTER - Classes that uses GAL interface to draw items (as you may have already guessed - PCB_PAINTER is a class for drawing PCB specific object, PAINTER is an abstract class). Its methods are invoked by VIEW, when an item has to be drawn. To display a new type of item - you need to implement draw(ITEM_TYPE*) method that draws it using GAL methods. - STROKE_FONT - Implements stroke font drawing using GAL methods. Most important changes to Kicad original code: * EDA_ITEM now inherits from VIEW_ITEM, which is a base class for all drawable objects. * EDA_DRAW_FRAME contains both usual EDA_DRAW_PANEL and new EDA_DRAW_PANEL_GAL, that can be switched anytime. * There are some new layers for displaying multilayer pads, vias & pads holes (these are not shown yet on the right sidebar in pcbnew) * Display order of layers is different than in previous versions (if you are curious - you may check m_galLayerOrder@pcbnew/basepcbframe.cpp). Preserving usual order would result in not very natural display, such as showing silkscreen texts on the bottom. * Introduced new hotkey (Alt+F12) and new menu option (View->Switch canvas) for switching canvas during runtime. * Some of classes (mostly derived from BOARD_ITEM) now includes ViewBBox & ViewGetLayers methods. * Removed tools/class_painter.h, as now it is extended and included in source code. Build changes: * GAL-based rendering option is turned on by a new compilation CMake option KICAD_GAL. * When compiling with CMake option KICAD_GAL=ON, GLEW and Cairo libraries are required. * GAL-related code is compiled into a static library (common/libgal). * Build with KICAD_GAL=OFF should not need any new libraries and should come out as a standard version of Kicad Currently most of items in pcbnew can be displayed using OpenGL (to be done are DIMENSIONS and MARKERS). More details about GAL can be found in: http://www.ohwr.org/attachments/1884/view-spec.pdf
13 years ago
11 years ago
Introduction of Graphics Abstraction Layer based rendering for pcbnew. New classes: - VIEW - represents view that is seen by user, takes care of layer ordering & visibility and how it is displayed (which location, how much zoomed, etc.) - VIEW_ITEM - Base class for every item that can be displayed on VIEW (the biggest change is that now it may be necessary to override ViewBBox & ViewGetLayers method for derived classes). - EDA_DRAW_PANEL_GAL - Inherits after EDA_DRAW_PANEL, displays VIEW output, right now it is not editable (in opposite to usual EDA_DRAW_PANEL). - GAL/OPENGL_GAL/CAIRO_GAL - Base Graphics Abstraction Layer class + two different flavours (Cairo is not fully supported yet), that offers methods to draw primitives using different libraries. - WX_VIEW_CONTROLS - Controller for VIEW, handles user events, allows zooming, panning, etc. - PAINTER/PCB_PAINTER - Classes that uses GAL interface to draw items (as you may have already guessed - PCB_PAINTER is a class for drawing PCB specific object, PAINTER is an abstract class). Its methods are invoked by VIEW, when an item has to be drawn. To display a new type of item - you need to implement draw(ITEM_TYPE*) method that draws it using GAL methods. - STROKE_FONT - Implements stroke font drawing using GAL methods. Most important changes to Kicad original code: * EDA_ITEM now inherits from VIEW_ITEM, which is a base class for all drawable objects. * EDA_DRAW_FRAME contains both usual EDA_DRAW_PANEL and new EDA_DRAW_PANEL_GAL, that can be switched anytime. * There are some new layers for displaying multilayer pads, vias & pads holes (these are not shown yet on the right sidebar in pcbnew) * Display order of layers is different than in previous versions (if you are curious - you may check m_galLayerOrder@pcbnew/basepcbframe.cpp). Preserving usual order would result in not very natural display, such as showing silkscreen texts on the bottom. * Introduced new hotkey (Alt+F12) and new menu option (View->Switch canvas) for switching canvas during runtime. * Some of classes (mostly derived from BOARD_ITEM) now includes ViewBBox & ViewGetLayers methods. * Removed tools/class_painter.h, as now it is extended and included in source code. Build changes: * GAL-based rendering option is turned on by a new compilation CMake option KICAD_GAL. * When compiling with CMake option KICAD_GAL=ON, GLEW and Cairo libraries are required. * GAL-related code is compiled into a static library (common/libgal). * Build with KICAD_GAL=OFF should not need any new libraries and should come out as a standard version of Kicad Currently most of items in pcbnew can be displayed using OpenGL (to be done are DIMENSIONS and MARKERS). More details about GAL can be found in: http://www.ohwr.org/attachments/1884/view-spec.pdf
13 years ago
11 years ago
Introduction of Graphics Abstraction Layer based rendering for pcbnew. New classes: - VIEW - represents view that is seen by user, takes care of layer ordering & visibility and how it is displayed (which location, how much zoomed, etc.) - VIEW_ITEM - Base class for every item that can be displayed on VIEW (the biggest change is that now it may be necessary to override ViewBBox & ViewGetLayers method for derived classes). - EDA_DRAW_PANEL_GAL - Inherits after EDA_DRAW_PANEL, displays VIEW output, right now it is not editable (in opposite to usual EDA_DRAW_PANEL). - GAL/OPENGL_GAL/CAIRO_GAL - Base Graphics Abstraction Layer class + two different flavours (Cairo is not fully supported yet), that offers methods to draw primitives using different libraries. - WX_VIEW_CONTROLS - Controller for VIEW, handles user events, allows zooming, panning, etc. - PAINTER/PCB_PAINTER - Classes that uses GAL interface to draw items (as you may have already guessed - PCB_PAINTER is a class for drawing PCB specific object, PAINTER is an abstract class). Its methods are invoked by VIEW, when an item has to be drawn. To display a new type of item - you need to implement draw(ITEM_TYPE*) method that draws it using GAL methods. - STROKE_FONT - Implements stroke font drawing using GAL methods. Most important changes to Kicad original code: * EDA_ITEM now inherits from VIEW_ITEM, which is a base class for all drawable objects. * EDA_DRAW_FRAME contains both usual EDA_DRAW_PANEL and new EDA_DRAW_PANEL_GAL, that can be switched anytime. * There are some new layers for displaying multilayer pads, vias & pads holes (these are not shown yet on the right sidebar in pcbnew) * Display order of layers is different than in previous versions (if you are curious - you may check m_galLayerOrder@pcbnew/basepcbframe.cpp). Preserving usual order would result in not very natural display, such as showing silkscreen texts on the bottom. * Introduced new hotkey (Alt+F12) and new menu option (View->Switch canvas) for switching canvas during runtime. * Some of classes (mostly derived from BOARD_ITEM) now includes ViewBBox & ViewGetLayers methods. * Removed tools/class_painter.h, as now it is extended and included in source code. Build changes: * GAL-based rendering option is turned on by a new compilation CMake option KICAD_GAL. * When compiling with CMake option KICAD_GAL=ON, GLEW and Cairo libraries are required. * GAL-related code is compiled into a static library (common/libgal). * Build with KICAD_GAL=OFF should not need any new libraries and should come out as a standard version of Kicad Currently most of items in pcbnew can be displayed using OpenGL (to be done are DIMENSIONS and MARKERS). More details about GAL can be found in: http://www.ohwr.org/attachments/1884/view-spec.pdf
13 years ago
Introduction of Graphics Abstraction Layer based rendering for pcbnew. New classes: - VIEW - represents view that is seen by user, takes care of layer ordering & visibility and how it is displayed (which location, how much zoomed, etc.) - VIEW_ITEM - Base class for every item that can be displayed on VIEW (the biggest change is that now it may be necessary to override ViewBBox & ViewGetLayers method for derived classes). - EDA_DRAW_PANEL_GAL - Inherits after EDA_DRAW_PANEL, displays VIEW output, right now it is not editable (in opposite to usual EDA_DRAW_PANEL). - GAL/OPENGL_GAL/CAIRO_GAL - Base Graphics Abstraction Layer class + two different flavours (Cairo is not fully supported yet), that offers methods to draw primitives using different libraries. - WX_VIEW_CONTROLS - Controller for VIEW, handles user events, allows zooming, panning, etc. - PAINTER/PCB_PAINTER - Classes that uses GAL interface to draw items (as you may have already guessed - PCB_PAINTER is a class for drawing PCB specific object, PAINTER is an abstract class). Its methods are invoked by VIEW, when an item has to be drawn. To display a new type of item - you need to implement draw(ITEM_TYPE*) method that draws it using GAL methods. - STROKE_FONT - Implements stroke font drawing using GAL methods. Most important changes to Kicad original code: * EDA_ITEM now inherits from VIEW_ITEM, which is a base class for all drawable objects. * EDA_DRAW_FRAME contains both usual EDA_DRAW_PANEL and new EDA_DRAW_PANEL_GAL, that can be switched anytime. * There are some new layers for displaying multilayer pads, vias & pads holes (these are not shown yet on the right sidebar in pcbnew) * Display order of layers is different than in previous versions (if you are curious - you may check m_galLayerOrder@pcbnew/basepcbframe.cpp). Preserving usual order would result in not very natural display, such as showing silkscreen texts on the bottom. * Introduced new hotkey (Alt+F12) and new menu option (View->Switch canvas) for switching canvas during runtime. * Some of classes (mostly derived from BOARD_ITEM) now includes ViewBBox & ViewGetLayers methods. * Removed tools/class_painter.h, as now it is extended and included in source code. Build changes: * GAL-based rendering option is turned on by a new compilation CMake option KICAD_GAL. * When compiling with CMake option KICAD_GAL=ON, GLEW and Cairo libraries are required. * GAL-related code is compiled into a static library (common/libgal). * Build with KICAD_GAL=OFF should not need any new libraries and should come out as a standard version of Kicad Currently most of items in pcbnew can be displayed using OpenGL (to be done are DIMENSIONS and MARKERS). More details about GAL can be found in: http://www.ohwr.org/attachments/1884/view-spec.pdf
13 years ago
Introduction of Graphics Abstraction Layer based rendering for pcbnew. New classes: - VIEW - represents view that is seen by user, takes care of layer ordering & visibility and how it is displayed (which location, how much zoomed, etc.) - VIEW_ITEM - Base class for every item that can be displayed on VIEW (the biggest change is that now it may be necessary to override ViewBBox & ViewGetLayers method for derived classes). - EDA_DRAW_PANEL_GAL - Inherits after EDA_DRAW_PANEL, displays VIEW output, right now it is not editable (in opposite to usual EDA_DRAW_PANEL). - GAL/OPENGL_GAL/CAIRO_GAL - Base Graphics Abstraction Layer class + two different flavours (Cairo is not fully supported yet), that offers methods to draw primitives using different libraries. - WX_VIEW_CONTROLS - Controller for VIEW, handles user events, allows zooming, panning, etc. - PAINTER/PCB_PAINTER - Classes that uses GAL interface to draw items (as you may have already guessed - PCB_PAINTER is a class for drawing PCB specific object, PAINTER is an abstract class). Its methods are invoked by VIEW, when an item has to be drawn. To display a new type of item - you need to implement draw(ITEM_TYPE*) method that draws it using GAL methods. - STROKE_FONT - Implements stroke font drawing using GAL methods. Most important changes to Kicad original code: * EDA_ITEM now inherits from VIEW_ITEM, which is a base class for all drawable objects. * EDA_DRAW_FRAME contains both usual EDA_DRAW_PANEL and new EDA_DRAW_PANEL_GAL, that can be switched anytime. * There are some new layers for displaying multilayer pads, vias & pads holes (these are not shown yet on the right sidebar in pcbnew) * Display order of layers is different than in previous versions (if you are curious - you may check m_galLayerOrder@pcbnew/basepcbframe.cpp). Preserving usual order would result in not very natural display, such as showing silkscreen texts on the bottom. * Introduced new hotkey (Alt+F12) and new menu option (View->Switch canvas) for switching canvas during runtime. * Some of classes (mostly derived from BOARD_ITEM) now includes ViewBBox & ViewGetLayers methods. * Removed tools/class_painter.h, as now it is extended and included in source code. Build changes: * GAL-based rendering option is turned on by a new compilation CMake option KICAD_GAL. * When compiling with CMake option KICAD_GAL=ON, GLEW and Cairo libraries are required. * GAL-related code is compiled into a static library (common/libgal). * Build with KICAD_GAL=OFF should not need any new libraries and should come out as a standard version of Kicad Currently most of items in pcbnew can be displayed using OpenGL (to be done are DIMENSIONS and MARKERS). More details about GAL can be found in: http://www.ohwr.org/attachments/1884/view-spec.pdf
13 years ago
Introduction of Graphics Abstraction Layer based rendering for pcbnew. New classes: - VIEW - represents view that is seen by user, takes care of layer ordering & visibility and how it is displayed (which location, how much zoomed, etc.) - VIEW_ITEM - Base class for every item that can be displayed on VIEW (the biggest change is that now it may be necessary to override ViewBBox & ViewGetLayers method for derived classes). - EDA_DRAW_PANEL_GAL - Inherits after EDA_DRAW_PANEL, displays VIEW output, right now it is not editable (in opposite to usual EDA_DRAW_PANEL). - GAL/OPENGL_GAL/CAIRO_GAL - Base Graphics Abstraction Layer class + two different flavours (Cairo is not fully supported yet), that offers methods to draw primitives using different libraries. - WX_VIEW_CONTROLS - Controller for VIEW, handles user events, allows zooming, panning, etc. - PAINTER/PCB_PAINTER - Classes that uses GAL interface to draw items (as you may have already guessed - PCB_PAINTER is a class for drawing PCB specific object, PAINTER is an abstract class). Its methods are invoked by VIEW, when an item has to be drawn. To display a new type of item - you need to implement draw(ITEM_TYPE*) method that draws it using GAL methods. - STROKE_FONT - Implements stroke font drawing using GAL methods. Most important changes to Kicad original code: * EDA_ITEM now inherits from VIEW_ITEM, which is a base class for all drawable objects. * EDA_DRAW_FRAME contains both usual EDA_DRAW_PANEL and new EDA_DRAW_PANEL_GAL, that can be switched anytime. * There are some new layers for displaying multilayer pads, vias & pads holes (these are not shown yet on the right sidebar in pcbnew) * Display order of layers is different than in previous versions (if you are curious - you may check m_galLayerOrder@pcbnew/basepcbframe.cpp). Preserving usual order would result in not very natural display, such as showing silkscreen texts on the bottom. * Introduced new hotkey (Alt+F12) and new menu option (View->Switch canvas) for switching canvas during runtime. * Some of classes (mostly derived from BOARD_ITEM) now includes ViewBBox & ViewGetLayers methods. * Removed tools/class_painter.h, as now it is extended and included in source code. Build changes: * GAL-based rendering option is turned on by a new compilation CMake option KICAD_GAL. * When compiling with CMake option KICAD_GAL=ON, GLEW and Cairo libraries are required. * GAL-related code is compiled into a static library (common/libgal). * Build with KICAD_GAL=OFF should not need any new libraries and should come out as a standard version of Kicad Currently most of items in pcbnew can be displayed using OpenGL (to be done are DIMENSIONS and MARKERS). More details about GAL can be found in: http://www.ohwr.org/attachments/1884/view-spec.pdf
13 years ago
Introduction of Graphics Abstraction Layer based rendering for pcbnew. New classes: - VIEW - represents view that is seen by user, takes care of layer ordering & visibility and how it is displayed (which location, how much zoomed, etc.) - VIEW_ITEM - Base class for every item that can be displayed on VIEW (the biggest change is that now it may be necessary to override ViewBBox & ViewGetLayers method for derived classes). - EDA_DRAW_PANEL_GAL - Inherits after EDA_DRAW_PANEL, displays VIEW output, right now it is not editable (in opposite to usual EDA_DRAW_PANEL). - GAL/OPENGL_GAL/CAIRO_GAL - Base Graphics Abstraction Layer class + two different flavours (Cairo is not fully supported yet), that offers methods to draw primitives using different libraries. - WX_VIEW_CONTROLS - Controller for VIEW, handles user events, allows zooming, panning, etc. - PAINTER/PCB_PAINTER - Classes that uses GAL interface to draw items (as you may have already guessed - PCB_PAINTER is a class for drawing PCB specific object, PAINTER is an abstract class). Its methods are invoked by VIEW, when an item has to be drawn. To display a new type of item - you need to implement draw(ITEM_TYPE*) method that draws it using GAL methods. - STROKE_FONT - Implements stroke font drawing using GAL methods. Most important changes to Kicad original code: * EDA_ITEM now inherits from VIEW_ITEM, which is a base class for all drawable objects. * EDA_DRAW_FRAME contains both usual EDA_DRAW_PANEL and new EDA_DRAW_PANEL_GAL, that can be switched anytime. * There are some new layers for displaying multilayer pads, vias & pads holes (these are not shown yet on the right sidebar in pcbnew) * Display order of layers is different than in previous versions (if you are curious - you may check m_galLayerOrder@pcbnew/basepcbframe.cpp). Preserving usual order would result in not very natural display, such as showing silkscreen texts on the bottom. * Introduced new hotkey (Alt+F12) and new menu option (View->Switch canvas) for switching canvas during runtime. * Some of classes (mostly derived from BOARD_ITEM) now includes ViewBBox & ViewGetLayers methods. * Removed tools/class_painter.h, as now it is extended and included in source code. Build changes: * GAL-based rendering option is turned on by a new compilation CMake option KICAD_GAL. * When compiling with CMake option KICAD_GAL=ON, GLEW and Cairo libraries are required. * GAL-related code is compiled into a static library (common/libgal). * Build with KICAD_GAL=OFF should not need any new libraries and should come out as a standard version of Kicad Currently most of items in pcbnew can be displayed using OpenGL (to be done are DIMENSIONS and MARKERS). More details about GAL can be found in: http://www.ohwr.org/attachments/1884/view-spec.pdf
13 years ago
11 years ago
Introduction of Graphics Abstraction Layer based rendering for pcbnew. New classes: - VIEW - represents view that is seen by user, takes care of layer ordering & visibility and how it is displayed (which location, how much zoomed, etc.) - VIEW_ITEM - Base class for every item that can be displayed on VIEW (the biggest change is that now it may be necessary to override ViewBBox & ViewGetLayers method for derived classes). - EDA_DRAW_PANEL_GAL - Inherits after EDA_DRAW_PANEL, displays VIEW output, right now it is not editable (in opposite to usual EDA_DRAW_PANEL). - GAL/OPENGL_GAL/CAIRO_GAL - Base Graphics Abstraction Layer class + two different flavours (Cairo is not fully supported yet), that offers methods to draw primitives using different libraries. - WX_VIEW_CONTROLS - Controller for VIEW, handles user events, allows zooming, panning, etc. - PAINTER/PCB_PAINTER - Classes that uses GAL interface to draw items (as you may have already guessed - PCB_PAINTER is a class for drawing PCB specific object, PAINTER is an abstract class). Its methods are invoked by VIEW, when an item has to be drawn. To display a new type of item - you need to implement draw(ITEM_TYPE*) method that draws it using GAL methods. - STROKE_FONT - Implements stroke font drawing using GAL methods. Most important changes to Kicad original code: * EDA_ITEM now inherits from VIEW_ITEM, which is a base class for all drawable objects. * EDA_DRAW_FRAME contains both usual EDA_DRAW_PANEL and new EDA_DRAW_PANEL_GAL, that can be switched anytime. * There are some new layers for displaying multilayer pads, vias & pads holes (these are not shown yet on the right sidebar in pcbnew) * Display order of layers is different than in previous versions (if you are curious - you may check m_galLayerOrder@pcbnew/basepcbframe.cpp). Preserving usual order would result in not very natural display, such as showing silkscreen texts on the bottom. * Introduced new hotkey (Alt+F12) and new menu option (View->Switch canvas) for switching canvas during runtime. * Some of classes (mostly derived from BOARD_ITEM) now includes ViewBBox & ViewGetLayers methods. * Removed tools/class_painter.h, as now it is extended and included in source code. Build changes: * GAL-based rendering option is turned on by a new compilation CMake option KICAD_GAL. * When compiling with CMake option KICAD_GAL=ON, GLEW and Cairo libraries are required. * GAL-related code is compiled into a static library (common/libgal). * Build with KICAD_GAL=OFF should not need any new libraries and should come out as a standard version of Kicad Currently most of items in pcbnew can be displayed using OpenGL (to be done are DIMENSIONS and MARKERS). More details about GAL can be found in: http://www.ohwr.org/attachments/1884/view-spec.pdf
13 years ago
Introduction of Graphics Abstraction Layer based rendering for pcbnew. New classes: - VIEW - represents view that is seen by user, takes care of layer ordering & visibility and how it is displayed (which location, how much zoomed, etc.) - VIEW_ITEM - Base class for every item that can be displayed on VIEW (the biggest change is that now it may be necessary to override ViewBBox & ViewGetLayers method for derived classes). - EDA_DRAW_PANEL_GAL - Inherits after EDA_DRAW_PANEL, displays VIEW output, right now it is not editable (in opposite to usual EDA_DRAW_PANEL). - GAL/OPENGL_GAL/CAIRO_GAL - Base Graphics Abstraction Layer class + two different flavours (Cairo is not fully supported yet), that offers methods to draw primitives using different libraries. - WX_VIEW_CONTROLS - Controller for VIEW, handles user events, allows zooming, panning, etc. - PAINTER/PCB_PAINTER - Classes that uses GAL interface to draw items (as you may have already guessed - PCB_PAINTER is a class for drawing PCB specific object, PAINTER is an abstract class). Its methods are invoked by VIEW, when an item has to be drawn. To display a new type of item - you need to implement draw(ITEM_TYPE*) method that draws it using GAL methods. - STROKE_FONT - Implements stroke font drawing using GAL methods. Most important changes to Kicad original code: * EDA_ITEM now inherits from VIEW_ITEM, which is a base class for all drawable objects. * EDA_DRAW_FRAME contains both usual EDA_DRAW_PANEL and new EDA_DRAW_PANEL_GAL, that can be switched anytime. * There are some new layers for displaying multilayer pads, vias & pads holes (these are not shown yet on the right sidebar in pcbnew) * Display order of layers is different than in previous versions (if you are curious - you may check m_galLayerOrder@pcbnew/basepcbframe.cpp). Preserving usual order would result in not very natural display, such as showing silkscreen texts on the bottom. * Introduced new hotkey (Alt+F12) and new menu option (View->Switch canvas) for switching canvas during runtime. * Some of classes (mostly derived from BOARD_ITEM) now includes ViewBBox & ViewGetLayers methods. * Removed tools/class_painter.h, as now it is extended and included in source code. Build changes: * GAL-based rendering option is turned on by a new compilation CMake option KICAD_GAL. * When compiling with CMake option KICAD_GAL=ON, GLEW and Cairo libraries are required. * GAL-related code is compiled into a static library (common/libgal). * Build with KICAD_GAL=OFF should not need any new libraries and should come out as a standard version of Kicad Currently most of items in pcbnew can be displayed using OpenGL (to be done are DIMENSIONS and MARKERS). More details about GAL can be found in: http://www.ohwr.org/attachments/1884/view-spec.pdf
13 years ago
Introduction of Graphics Abstraction Layer based rendering for pcbnew. New classes: - VIEW - represents view that is seen by user, takes care of layer ordering & visibility and how it is displayed (which location, how much zoomed, etc.) - VIEW_ITEM - Base class for every item that can be displayed on VIEW (the biggest change is that now it may be necessary to override ViewBBox & ViewGetLayers method for derived classes). - EDA_DRAW_PANEL_GAL - Inherits after EDA_DRAW_PANEL, displays VIEW output, right now it is not editable (in opposite to usual EDA_DRAW_PANEL). - GAL/OPENGL_GAL/CAIRO_GAL - Base Graphics Abstraction Layer class + two different flavours (Cairo is not fully supported yet), that offers methods to draw primitives using different libraries. - WX_VIEW_CONTROLS - Controller for VIEW, handles user events, allows zooming, panning, etc. - PAINTER/PCB_PAINTER - Classes that uses GAL interface to draw items (as you may have already guessed - PCB_PAINTER is a class for drawing PCB specific object, PAINTER is an abstract class). Its methods are invoked by VIEW, when an item has to be drawn. To display a new type of item - you need to implement draw(ITEM_TYPE*) method that draws it using GAL methods. - STROKE_FONT - Implements stroke font drawing using GAL methods. Most important changes to Kicad original code: * EDA_ITEM now inherits from VIEW_ITEM, which is a base class for all drawable objects. * EDA_DRAW_FRAME contains both usual EDA_DRAW_PANEL and new EDA_DRAW_PANEL_GAL, that can be switched anytime. * There are some new layers for displaying multilayer pads, vias & pads holes (these are not shown yet on the right sidebar in pcbnew) * Display order of layers is different than in previous versions (if you are curious - you may check m_galLayerOrder@pcbnew/basepcbframe.cpp). Preserving usual order would result in not very natural display, such as showing silkscreen texts on the bottom. * Introduced new hotkey (Alt+F12) and new menu option (View->Switch canvas) for switching canvas during runtime. * Some of classes (mostly derived from BOARD_ITEM) now includes ViewBBox & ViewGetLayers methods. * Removed tools/class_painter.h, as now it is extended and included in source code. Build changes: * GAL-based rendering option is turned on by a new compilation CMake option KICAD_GAL. * When compiling with CMake option KICAD_GAL=ON, GLEW and Cairo libraries are required. * GAL-related code is compiled into a static library (common/libgal). * Build with KICAD_GAL=OFF should not need any new libraries and should come out as a standard version of Kicad Currently most of items in pcbnew can be displayed using OpenGL (to be done are DIMENSIONS and MARKERS). More details about GAL can be found in: http://www.ohwr.org/attachments/1884/view-spec.pdf
13 years ago
Introduction of Graphics Abstraction Layer based rendering for pcbnew. New classes: - VIEW - represents view that is seen by user, takes care of layer ordering & visibility and how it is displayed (which location, how much zoomed, etc.) - VIEW_ITEM - Base class for every item that can be displayed on VIEW (the biggest change is that now it may be necessary to override ViewBBox & ViewGetLayers method for derived classes). - EDA_DRAW_PANEL_GAL - Inherits after EDA_DRAW_PANEL, displays VIEW output, right now it is not editable (in opposite to usual EDA_DRAW_PANEL). - GAL/OPENGL_GAL/CAIRO_GAL - Base Graphics Abstraction Layer class + two different flavours (Cairo is not fully supported yet), that offers methods to draw primitives using different libraries. - WX_VIEW_CONTROLS - Controller for VIEW, handles user events, allows zooming, panning, etc. - PAINTER/PCB_PAINTER - Classes that uses GAL interface to draw items (as you may have already guessed - PCB_PAINTER is a class for drawing PCB specific object, PAINTER is an abstract class). Its methods are invoked by VIEW, when an item has to be drawn. To display a new type of item - you need to implement draw(ITEM_TYPE*) method that draws it using GAL methods. - STROKE_FONT - Implements stroke font drawing using GAL methods. Most important changes to Kicad original code: * EDA_ITEM now inherits from VIEW_ITEM, which is a base class for all drawable objects. * EDA_DRAW_FRAME contains both usual EDA_DRAW_PANEL and new EDA_DRAW_PANEL_GAL, that can be switched anytime. * There are some new layers for displaying multilayer pads, vias & pads holes (these are not shown yet on the right sidebar in pcbnew) * Display order of layers is different than in previous versions (if you are curious - you may check m_galLayerOrder@pcbnew/basepcbframe.cpp). Preserving usual order would result in not very natural display, such as showing silkscreen texts on the bottom. * Introduced new hotkey (Alt+F12) and new menu option (View->Switch canvas) for switching canvas during runtime. * Some of classes (mostly derived from BOARD_ITEM) now includes ViewBBox & ViewGetLayers methods. * Removed tools/class_painter.h, as now it is extended and included in source code. Build changes: * GAL-based rendering option is turned on by a new compilation CMake option KICAD_GAL. * When compiling with CMake option KICAD_GAL=ON, GLEW and Cairo libraries are required. * GAL-related code is compiled into a static library (common/libgal). * Build with KICAD_GAL=OFF should not need any new libraries and should come out as a standard version of Kicad Currently most of items in pcbnew can be displayed using OpenGL (to be done are DIMENSIONS and MARKERS). More details about GAL can be found in: http://www.ohwr.org/attachments/1884/view-spec.pdf
13 years ago
Introduction of Graphics Abstraction Layer based rendering for pcbnew. New classes: - VIEW - represents view that is seen by user, takes care of layer ordering & visibility and how it is displayed (which location, how much zoomed, etc.) - VIEW_ITEM - Base class for every item that can be displayed on VIEW (the biggest change is that now it may be necessary to override ViewBBox & ViewGetLayers method for derived classes). - EDA_DRAW_PANEL_GAL - Inherits after EDA_DRAW_PANEL, displays VIEW output, right now it is not editable (in opposite to usual EDA_DRAW_PANEL). - GAL/OPENGL_GAL/CAIRO_GAL - Base Graphics Abstraction Layer class + two different flavours (Cairo is not fully supported yet), that offers methods to draw primitives using different libraries. - WX_VIEW_CONTROLS - Controller for VIEW, handles user events, allows zooming, panning, etc. - PAINTER/PCB_PAINTER - Classes that uses GAL interface to draw items (as you may have already guessed - PCB_PAINTER is a class for drawing PCB specific object, PAINTER is an abstract class). Its methods are invoked by VIEW, when an item has to be drawn. To display a new type of item - you need to implement draw(ITEM_TYPE*) method that draws it using GAL methods. - STROKE_FONT - Implements stroke font drawing using GAL methods. Most important changes to Kicad original code: * EDA_ITEM now inherits from VIEW_ITEM, which is a base class for all drawable objects. * EDA_DRAW_FRAME contains both usual EDA_DRAW_PANEL and new EDA_DRAW_PANEL_GAL, that can be switched anytime. * There are some new layers for displaying multilayer pads, vias & pads holes (these are not shown yet on the right sidebar in pcbnew) * Display order of layers is different than in previous versions (if you are curious - you may check m_galLayerOrder@pcbnew/basepcbframe.cpp). Preserving usual order would result in not very natural display, such as showing silkscreen texts on the bottom. * Introduced new hotkey (Alt+F12) and new menu option (View->Switch canvas) for switching canvas during runtime. * Some of classes (mostly derived from BOARD_ITEM) now includes ViewBBox & ViewGetLayers methods. * Removed tools/class_painter.h, as now it is extended and included in source code. Build changes: * GAL-based rendering option is turned on by a new compilation CMake option KICAD_GAL. * When compiling with CMake option KICAD_GAL=ON, GLEW and Cairo libraries are required. * GAL-related code is compiled into a static library (common/libgal). * Build with KICAD_GAL=OFF should not need any new libraries and should come out as a standard version of Kicad Currently most of items in pcbnew can be displayed using OpenGL (to be done are DIMENSIONS and MARKERS). More details about GAL can be found in: http://www.ohwr.org/attachments/1884/view-spec.pdf
13 years ago
Introduction of Graphics Abstraction Layer based rendering for pcbnew. New classes: - VIEW - represents view that is seen by user, takes care of layer ordering & visibility and how it is displayed (which location, how much zoomed, etc.) - VIEW_ITEM - Base class for every item that can be displayed on VIEW (the biggest change is that now it may be necessary to override ViewBBox & ViewGetLayers method for derived classes). - EDA_DRAW_PANEL_GAL - Inherits after EDA_DRAW_PANEL, displays VIEW output, right now it is not editable (in opposite to usual EDA_DRAW_PANEL). - GAL/OPENGL_GAL/CAIRO_GAL - Base Graphics Abstraction Layer class + two different flavours (Cairo is not fully supported yet), that offers methods to draw primitives using different libraries. - WX_VIEW_CONTROLS - Controller for VIEW, handles user events, allows zooming, panning, etc. - PAINTER/PCB_PAINTER - Classes that uses GAL interface to draw items (as you may have already guessed - PCB_PAINTER is a class for drawing PCB specific object, PAINTER is an abstract class). Its methods are invoked by VIEW, when an item has to be drawn. To display a new type of item - you need to implement draw(ITEM_TYPE*) method that draws it using GAL methods. - STROKE_FONT - Implements stroke font drawing using GAL methods. Most important changes to Kicad original code: * EDA_ITEM now inherits from VIEW_ITEM, which is a base class for all drawable objects. * EDA_DRAW_FRAME contains both usual EDA_DRAW_PANEL and new EDA_DRAW_PANEL_GAL, that can be switched anytime. * There are some new layers for displaying multilayer pads, vias & pads holes (these are not shown yet on the right sidebar in pcbnew) * Display order of layers is different than in previous versions (if you are curious - you may check m_galLayerOrder@pcbnew/basepcbframe.cpp). Preserving usual order would result in not very natural display, such as showing silkscreen texts on the bottom. * Introduced new hotkey (Alt+F12) and new menu option (View->Switch canvas) for switching canvas during runtime. * Some of classes (mostly derived from BOARD_ITEM) now includes ViewBBox & ViewGetLayers methods. * Removed tools/class_painter.h, as now it is extended and included in source code. Build changes: * GAL-based rendering option is turned on by a new compilation CMake option KICAD_GAL. * When compiling with CMake option KICAD_GAL=ON, GLEW and Cairo libraries are required. * GAL-related code is compiled into a static library (common/libgal). * Build with KICAD_GAL=OFF should not need any new libraries and should come out as a standard version of Kicad Currently most of items in pcbnew can be displayed using OpenGL (to be done are DIMENSIONS and MARKERS). More details about GAL can be found in: http://www.ohwr.org/attachments/1884/view-spec.pdf
13 years ago
Introduction of Graphics Abstraction Layer based rendering for pcbnew. New classes: - VIEW - represents view that is seen by user, takes care of layer ordering & visibility and how it is displayed (which location, how much zoomed, etc.) - VIEW_ITEM - Base class for every item that can be displayed on VIEW (the biggest change is that now it may be necessary to override ViewBBox & ViewGetLayers method for derived classes). - EDA_DRAW_PANEL_GAL - Inherits after EDA_DRAW_PANEL, displays VIEW output, right now it is not editable (in opposite to usual EDA_DRAW_PANEL). - GAL/OPENGL_GAL/CAIRO_GAL - Base Graphics Abstraction Layer class + two different flavours (Cairo is not fully supported yet), that offers methods to draw primitives using different libraries. - WX_VIEW_CONTROLS - Controller for VIEW, handles user events, allows zooming, panning, etc. - PAINTER/PCB_PAINTER - Classes that uses GAL interface to draw items (as you may have already guessed - PCB_PAINTER is a class for drawing PCB specific object, PAINTER is an abstract class). Its methods are invoked by VIEW, when an item has to be drawn. To display a new type of item - you need to implement draw(ITEM_TYPE*) method that draws it using GAL methods. - STROKE_FONT - Implements stroke font drawing using GAL methods. Most important changes to Kicad original code: * EDA_ITEM now inherits from VIEW_ITEM, which is a base class for all drawable objects. * EDA_DRAW_FRAME contains both usual EDA_DRAW_PANEL and new EDA_DRAW_PANEL_GAL, that can be switched anytime. * There are some new layers for displaying multilayer pads, vias & pads holes (these are not shown yet on the right sidebar in pcbnew) * Display order of layers is different than in previous versions (if you are curious - you may check m_galLayerOrder@pcbnew/basepcbframe.cpp). Preserving usual order would result in not very natural display, such as showing silkscreen texts on the bottom. * Introduced new hotkey (Alt+F12) and new menu option (View->Switch canvas) for switching canvas during runtime. * Some of classes (mostly derived from BOARD_ITEM) now includes ViewBBox & ViewGetLayers methods. * Removed tools/class_painter.h, as now it is extended and included in source code. Build changes: * GAL-based rendering option is turned on by a new compilation CMake option KICAD_GAL. * When compiling with CMake option KICAD_GAL=ON, GLEW and Cairo libraries are required. * GAL-related code is compiled into a static library (common/libgal). * Build with KICAD_GAL=OFF should not need any new libraries and should come out as a standard version of Kicad Currently most of items in pcbnew can be displayed using OpenGL (to be done are DIMENSIONS and MARKERS). More details about GAL can be found in: http://www.ohwr.org/attachments/1884/view-spec.pdf
13 years ago
Introduction of Graphics Abstraction Layer based rendering for pcbnew. New classes: - VIEW - represents view that is seen by user, takes care of layer ordering & visibility and how it is displayed (which location, how much zoomed, etc.) - VIEW_ITEM - Base class for every item that can be displayed on VIEW (the biggest change is that now it may be necessary to override ViewBBox & ViewGetLayers method for derived classes). - EDA_DRAW_PANEL_GAL - Inherits after EDA_DRAW_PANEL, displays VIEW output, right now it is not editable (in opposite to usual EDA_DRAW_PANEL). - GAL/OPENGL_GAL/CAIRO_GAL - Base Graphics Abstraction Layer class + two different flavours (Cairo is not fully supported yet), that offers methods to draw primitives using different libraries. - WX_VIEW_CONTROLS - Controller for VIEW, handles user events, allows zooming, panning, etc. - PAINTER/PCB_PAINTER - Classes that uses GAL interface to draw items (as you may have already guessed - PCB_PAINTER is a class for drawing PCB specific object, PAINTER is an abstract class). Its methods are invoked by VIEW, when an item has to be drawn. To display a new type of item - you need to implement draw(ITEM_TYPE*) method that draws it using GAL methods. - STROKE_FONT - Implements stroke font drawing using GAL methods. Most important changes to Kicad original code: * EDA_ITEM now inherits from VIEW_ITEM, which is a base class for all drawable objects. * EDA_DRAW_FRAME contains both usual EDA_DRAW_PANEL and new EDA_DRAW_PANEL_GAL, that can be switched anytime. * There are some new layers for displaying multilayer pads, vias & pads holes (these are not shown yet on the right sidebar in pcbnew) * Display order of layers is different than in previous versions (if you are curious - you may check m_galLayerOrder@pcbnew/basepcbframe.cpp). Preserving usual order would result in not very natural display, such as showing silkscreen texts on the bottom. * Introduced new hotkey (Alt+F12) and new menu option (View->Switch canvas) for switching canvas during runtime. * Some of classes (mostly derived from BOARD_ITEM) now includes ViewBBox & ViewGetLayers methods. * Removed tools/class_painter.h, as now it is extended and included in source code. Build changes: * GAL-based rendering option is turned on by a new compilation CMake option KICAD_GAL. * When compiling with CMake option KICAD_GAL=ON, GLEW and Cairo libraries are required. * GAL-related code is compiled into a static library (common/libgal). * Build with KICAD_GAL=OFF should not need any new libraries and should come out as a standard version of Kicad Currently most of items in pcbnew can be displayed using OpenGL (to be done are DIMENSIONS and MARKERS). More details about GAL can be found in: http://www.ohwr.org/attachments/1884/view-spec.pdf
13 years ago
Introduction of Graphics Abstraction Layer based rendering for pcbnew. New classes: - VIEW - represents view that is seen by user, takes care of layer ordering & visibility and how it is displayed (which location, how much zoomed, etc.) - VIEW_ITEM - Base class for every item that can be displayed on VIEW (the biggest change is that now it may be necessary to override ViewBBox & ViewGetLayers method for derived classes). - EDA_DRAW_PANEL_GAL - Inherits after EDA_DRAW_PANEL, displays VIEW output, right now it is not editable (in opposite to usual EDA_DRAW_PANEL). - GAL/OPENGL_GAL/CAIRO_GAL - Base Graphics Abstraction Layer class + two different flavours (Cairo is not fully supported yet), that offers methods to draw primitives using different libraries. - WX_VIEW_CONTROLS - Controller for VIEW, handles user events, allows zooming, panning, etc. - PAINTER/PCB_PAINTER - Classes that uses GAL interface to draw items (as you may have already guessed - PCB_PAINTER is a class for drawing PCB specific object, PAINTER is an abstract class). Its methods are invoked by VIEW, when an item has to be drawn. To display a new type of item - you need to implement draw(ITEM_TYPE*) method that draws it using GAL methods. - STROKE_FONT - Implements stroke font drawing using GAL methods. Most important changes to Kicad original code: * EDA_ITEM now inherits from VIEW_ITEM, which is a base class for all drawable objects. * EDA_DRAW_FRAME contains both usual EDA_DRAW_PANEL and new EDA_DRAW_PANEL_GAL, that can be switched anytime. * There are some new layers for displaying multilayer pads, vias & pads holes (these are not shown yet on the right sidebar in pcbnew) * Display order of layers is different than in previous versions (if you are curious - you may check m_galLayerOrder@pcbnew/basepcbframe.cpp). Preserving usual order would result in not very natural display, such as showing silkscreen texts on the bottom. * Introduced new hotkey (Alt+F12) and new menu option (View->Switch canvas) for switching canvas during runtime. * Some of classes (mostly derived from BOARD_ITEM) now includes ViewBBox & ViewGetLayers methods. * Removed tools/class_painter.h, as now it is extended and included in source code. Build changes: * GAL-based rendering option is turned on by a new compilation CMake option KICAD_GAL. * When compiling with CMake option KICAD_GAL=ON, GLEW and Cairo libraries are required. * GAL-related code is compiled into a static library (common/libgal). * Build with KICAD_GAL=OFF should not need any new libraries and should come out as a standard version of Kicad Currently most of items in pcbnew can be displayed using OpenGL (to be done are DIMENSIONS and MARKERS). More details about GAL can be found in: http://www.ohwr.org/attachments/1884/view-spec.pdf
13 years ago
Introduction of Graphics Abstraction Layer based rendering for pcbnew. New classes: - VIEW - represents view that is seen by user, takes care of layer ordering & visibility and how it is displayed (which location, how much zoomed, etc.) - VIEW_ITEM - Base class for every item that can be displayed on VIEW (the biggest change is that now it may be necessary to override ViewBBox & ViewGetLayers method for derived classes). - EDA_DRAW_PANEL_GAL - Inherits after EDA_DRAW_PANEL, displays VIEW output, right now it is not editable (in opposite to usual EDA_DRAW_PANEL). - GAL/OPENGL_GAL/CAIRO_GAL - Base Graphics Abstraction Layer class + two different flavours (Cairo is not fully supported yet), that offers methods to draw primitives using different libraries. - WX_VIEW_CONTROLS - Controller for VIEW, handles user events, allows zooming, panning, etc. - PAINTER/PCB_PAINTER - Classes that uses GAL interface to draw items (as you may have already guessed - PCB_PAINTER is a class for drawing PCB specific object, PAINTER is an abstract class). Its methods are invoked by VIEW, when an item has to be drawn. To display a new type of item - you need to implement draw(ITEM_TYPE*) method that draws it using GAL methods. - STROKE_FONT - Implements stroke font drawing using GAL methods. Most important changes to Kicad original code: * EDA_ITEM now inherits from VIEW_ITEM, which is a base class for all drawable objects. * EDA_DRAW_FRAME contains both usual EDA_DRAW_PANEL and new EDA_DRAW_PANEL_GAL, that can be switched anytime. * There are some new layers for displaying multilayer pads, vias & pads holes (these are not shown yet on the right sidebar in pcbnew) * Display order of layers is different than in previous versions (if you are curious - you may check m_galLayerOrder@pcbnew/basepcbframe.cpp). Preserving usual order would result in not very natural display, such as showing silkscreen texts on the bottom. * Introduced new hotkey (Alt+F12) and new menu option (View->Switch canvas) for switching canvas during runtime. * Some of classes (mostly derived from BOARD_ITEM) now includes ViewBBox & ViewGetLayers methods. * Removed tools/class_painter.h, as now it is extended and included in source code. Build changes: * GAL-based rendering option is turned on by a new compilation CMake option KICAD_GAL. * When compiling with CMake option KICAD_GAL=ON, GLEW and Cairo libraries are required. * GAL-related code is compiled into a static library (common/libgal). * Build with KICAD_GAL=OFF should not need any new libraries and should come out as a standard version of Kicad Currently most of items in pcbnew can be displayed using OpenGL (to be done are DIMENSIONS and MARKERS). More details about GAL can be found in: http://www.ohwr.org/attachments/1884/view-spec.pdf
13 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2012 Torsten Hueter, torstenhtr <at> gmx.de
  5. * Copyright (C) 2013-2015 CERN
  6. * Copyright (C) 2012-2024 KiCad Developers, see AUTHORS.txt for contributors.
  7. *
  8. * @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
  9. * @author Maciej Suminski <maciej.suminski@cern.ch>
  10. *
  11. * This program is free software; you can redistribute it and/or
  12. * modify it under the terms of the GNU General Public License
  13. * as published by the Free Software Foundation; either version 2
  14. * of the License, or (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program; if not, you may find one here:
  23. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  24. * or you may search the http://www.gnu.org website for the version 2 license,
  25. * or you may write to the Free Software Foundation, Inc.,
  26. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  27. */
  28. #include <pgm_base.h>
  29. #include <core/profile.h>
  30. #include <view/view.h>
  31. #include <view/wx_view_controls.h>
  32. #include <view/zoom_controller.h>
  33. #include <gal/graphics_abstraction_layer.h>
  34. #include <tool/tool_dispatcher.h>
  35. #include <trace_helpers.h>
  36. #include <settings/common_settings.h>
  37. #include <math/util.h> // for KiROUND
  38. #include <geometry/geometry_utils.h>
  39. #include <widgets/ui_common.h>
  40. #include <class_draw_panel_gal.h>
  41. #include <eda_draw_frame.h>
  42. #include <kiway.h>
  43. #include <kiplatform/ui.h>
  44. #include <wx/log.h>
  45. #ifdef __WXMSW__
  46. #define USE_MOUSE_CAPTURE
  47. #endif
  48. using namespace KIGFX;
  49. const wxEventType WX_VIEW_CONTROLS::EVT_REFRESH_MOUSE = wxNewEventType();
  50. static std::unique_ptr<ZOOM_CONTROLLER> GetZoomControllerForPlatform( bool aAcceleration )
  51. {
  52. #ifdef __WXMAC__
  53. // On Apple pointer devices, wheel events occur frequently and with
  54. // smaller rotation values. For those devices, let's handle zoom
  55. // based on the rotation amount rather than the time difference.
  56. return std::make_unique<CONSTANT_ZOOM_CONTROLLER>( CONSTANT_ZOOM_CONTROLLER::MAC_SCALE );
  57. #elif __WXGTK3__
  58. // GTK3 is similar, but the scale constant is smaller
  59. return std::make_unique<CONSTANT_ZOOM_CONTROLLER>( CONSTANT_ZOOM_CONTROLLER::GTK3_SCALE );
  60. #else
  61. if( aAcceleration )
  62. return std::make_unique<ACCELERATING_ZOOM_CONTROLLER>();
  63. else
  64. return std::make_unique<CONSTANT_ZOOM_CONTROLLER>( CONSTANT_ZOOM_CONTROLLER::MSW_SCALE );
  65. #endif
  66. }
  67. WX_VIEW_CONTROLS::WX_VIEW_CONTROLS( VIEW* aView, EDA_DRAW_PANEL_GAL* aParentPanel ) :
  68. VIEW_CONTROLS( aView ),
  69. m_state( IDLE ),
  70. m_parentPanel( aParentPanel ),
  71. m_scrollScale( 1.0, 1.0 ),
  72. #ifdef __WXGTK3__
  73. m_lastTimestamp( 0 ),
  74. #endif
  75. m_cursorPos( 0, 0 ),
  76. m_updateCursor( true ),
  77. m_infinitePanWorks( false ),
  78. m_gestureLastZoomFactor( 1.0 )
  79. {
  80. LoadSettings();
  81. m_MotionEventCounter = std::make_unique<PROF_COUNTER>( "Mouse motion events" );
  82. m_parentPanel->Connect( wxEVT_MOTION,
  83. wxMouseEventHandler( WX_VIEW_CONTROLS::onMotion ), nullptr, this );
  84. m_parentPanel->Connect( wxEVT_MAGNIFY,
  85. wxMouseEventHandler( WX_VIEW_CONTROLS::onMagnify ), nullptr, this );
  86. m_parentPanel->Connect( wxEVT_MOUSEWHEEL,
  87. wxMouseEventHandler( WX_VIEW_CONTROLS::onWheel ), nullptr, this );
  88. m_parentPanel->Connect( wxEVT_MIDDLE_UP,
  89. wxMouseEventHandler( WX_VIEW_CONTROLS::onButton ), nullptr, this );
  90. m_parentPanel->Connect( wxEVT_MIDDLE_DOWN,
  91. wxMouseEventHandler( WX_VIEW_CONTROLS::onButton ), nullptr, this );
  92. m_parentPanel->Connect( wxEVT_LEFT_UP,
  93. wxMouseEventHandler( WX_VIEW_CONTROLS::onButton ), nullptr, this );
  94. m_parentPanel->Connect( wxEVT_LEFT_DOWN,
  95. wxMouseEventHandler( WX_VIEW_CONTROLS::onButton ), nullptr, this );
  96. m_parentPanel->Connect( wxEVT_RIGHT_UP,
  97. wxMouseEventHandler( WX_VIEW_CONTROLS::onButton ), nullptr, this );
  98. m_parentPanel->Connect( wxEVT_RIGHT_DOWN,
  99. wxMouseEventHandler( WX_VIEW_CONTROLS::onButton ), nullptr, this );
  100. #if defined __WXMSW__
  101. m_parentPanel->Connect( wxEVT_ENTER_WINDOW,
  102. wxMouseEventHandler( WX_VIEW_CONTROLS::onEnter ), nullptr, this );
  103. #endif
  104. m_parentPanel->Connect( wxEVT_LEAVE_WINDOW,
  105. wxMouseEventHandler( WX_VIEW_CONTROLS::onLeave ), nullptr, this );
  106. m_parentPanel->Connect( wxEVT_SCROLLWIN_THUMBTRACK,
  107. wxScrollWinEventHandler( WX_VIEW_CONTROLS::onScroll ), nullptr, this );
  108. m_parentPanel->Connect( wxEVT_SCROLLWIN_PAGEUP,
  109. wxScrollWinEventHandler( WX_VIEW_CONTROLS::onScroll ), nullptr, this );
  110. m_parentPanel->Connect( wxEVT_SCROLLWIN_PAGEDOWN,
  111. wxScrollWinEventHandler( WX_VIEW_CONTROLS::onScroll ), nullptr, this );
  112. m_parentPanel->Connect( wxEVT_SCROLLWIN_BOTTOM,
  113. wxScrollWinEventHandler( WX_VIEW_CONTROLS::onScroll ), nullptr, this );
  114. m_parentPanel->Connect( wxEVT_SCROLLWIN_TOP,
  115. wxScrollWinEventHandler( WX_VIEW_CONTROLS::onScroll ), nullptr, this );
  116. m_parentPanel->Connect( wxEVT_SCROLLWIN_LINEUP,
  117. wxScrollWinEventHandler( WX_VIEW_CONTROLS::onScroll ), nullptr, this );
  118. m_parentPanel->Connect( wxEVT_SCROLLWIN_LINEDOWN,
  119. wxScrollWinEventHandler( WX_VIEW_CONTROLS::onScroll ), nullptr, this );
  120. #if defined USE_MOUSE_CAPTURE
  121. m_parentPanel->Connect( wxEVT_MOUSE_CAPTURE_LOST,
  122. wxMouseEventHandler( WX_VIEW_CONTROLS::onCaptureLost ), nullptr, this );
  123. #endif
  124. #ifdef __WXMSW__
  125. if( m_parentPanel->EnableTouchEvents( wxTOUCH_ZOOM_GESTURE | wxTOUCH_PAN_GESTURES ) )
  126. {
  127. m_parentPanel->Connect( wxEVT_GESTURE_ZOOM,
  128. wxZoomGestureEventHandler( WX_VIEW_CONTROLS::onZoomGesture ),
  129. nullptr, this );
  130. m_parentPanel->Connect( wxEVT_GESTURE_PAN,
  131. wxPanGestureEventHandler( WX_VIEW_CONTROLS::onPanGesture ), nullptr,
  132. this );
  133. }
  134. #endif
  135. m_cursorWarped = false;
  136. m_panTimer.SetOwner( this );
  137. this->Connect( wxEVT_TIMER, wxTimerEventHandler( WX_VIEW_CONTROLS::onTimer ), nullptr, this );
  138. m_settings.m_lastKeyboardCursorPositionValid = false;
  139. m_settings.m_lastKeyboardCursorPosition = { 0.0, 0.0 };
  140. m_settings.m_lastKeyboardCursorCommand = 0;
  141. }
  142. WX_VIEW_CONTROLS::~WX_VIEW_CONTROLS()
  143. {
  144. #if defined USE_MOUSE_CAPTURE
  145. if( m_parentPanel->HasCapture() )
  146. m_parentPanel->ReleaseMouse();
  147. #endif
  148. }
  149. void WX_VIEW_CONTROLS::LoadSettings()
  150. {
  151. COMMON_SETTINGS* cfg = Pgm().GetCommonSettings();
  152. m_settings.m_warpCursor = cfg->m_Input.center_on_zoom;
  153. m_settings.m_focusFollowSchPcb = cfg->m_Input.focus_follow_sch_pcb;
  154. m_settings.m_autoPanSettingEnabled = cfg->m_Input.auto_pan;
  155. m_settings.m_autoPanAcceleration = cfg->m_Input.auto_pan_acceleration;
  156. m_settings.m_horizontalPan = cfg->m_Input.horizontal_pan;
  157. m_settings.m_zoomAcceleration = cfg->m_Input.zoom_acceleration;
  158. m_settings.m_zoomSpeed = cfg->m_Input.zoom_speed;
  159. m_settings.m_zoomSpeedAuto = cfg->m_Input.zoom_speed_auto;
  160. m_settings.m_scrollModifierZoom = cfg->m_Input.scroll_modifier_zoom;
  161. m_settings.m_scrollModifierPanH = cfg->m_Input.scroll_modifier_pan_h;
  162. m_settings.m_scrollModifierPanV = cfg->m_Input.scroll_modifier_pan_v;
  163. m_settings.m_dragLeft = cfg->m_Input.drag_left;
  164. m_settings.m_dragMiddle = cfg->m_Input.drag_middle;
  165. m_settings.m_dragRight = cfg->m_Input.drag_right;
  166. m_settings.m_scrollReverseZoom = cfg->m_Input.reverse_scroll_zoom;
  167. m_settings.m_scrollReversePanH = cfg->m_Input.reverse_scroll_pan_h;
  168. m_zoomController.reset();
  169. if( cfg->m_Input.zoom_speed_auto )
  170. {
  171. m_zoomController = GetZoomControllerForPlatform( cfg->m_Input.zoom_acceleration );
  172. }
  173. else
  174. {
  175. if( cfg->m_Input.zoom_acceleration )
  176. {
  177. m_zoomController =
  178. std::make_unique<ACCELERATING_ZOOM_CONTROLLER>( cfg->m_Input.zoom_speed );
  179. }
  180. else
  181. {
  182. double scale = CONSTANT_ZOOM_CONTROLLER::MANUAL_SCALE_FACTOR * cfg->m_Input.zoom_speed;
  183. m_zoomController = std::make_unique<CONSTANT_ZOOM_CONTROLLER>( scale );
  184. }
  185. }
  186. }
  187. void WX_VIEW_CONTROLS::onMotion( wxMouseEvent& aEvent )
  188. {
  189. ( *m_MotionEventCounter )++;
  190. // Because Weston sends a motion event to previous location after warping the pointer
  191. wxPoint mouseRel = m_parentPanel->ScreenToClient( KIPLATFORM::UI::GetMousePosition() );
  192. bool isAutoPanning = false;
  193. int x = mouseRel.x;
  194. int y = mouseRel.y;
  195. VECTOR2D mousePos( x, y );
  196. // Automatic focus switching between SCH and PCB windows on canvas mouse motion
  197. if( m_settings.m_focusFollowSchPcb )
  198. {
  199. if( EDA_DRAW_FRAME* frame = m_parentPanel->GetParentEDAFrame() )
  200. {
  201. KIWAY_PLAYER* otherFrame = nullptr;
  202. if( frame->IsType( FRAME_PCB_EDITOR ) )
  203. {
  204. otherFrame = frame->Kiway().Player( FRAME_SCH, false );
  205. }
  206. else if( frame->IsType( FRAME_SCH ) )
  207. {
  208. otherFrame = frame->Kiway().Player( FRAME_PCB_EDITOR, false );
  209. }
  210. if( otherFrame && KIPLATFORM::UI::IsWindowActive( otherFrame )
  211. && !KIPLATFORM::UI::IsWindowActive( frame ) )
  212. {
  213. frame->Raise();
  214. }
  215. }
  216. }
  217. if( m_state != DRAG_PANNING && m_state != DRAG_ZOOMING )
  218. handleCursorCapture( x, y );
  219. if( m_settings.m_autoPanEnabled && m_settings.m_autoPanSettingEnabled )
  220. isAutoPanning = handleAutoPanning( aEvent );
  221. if( !isAutoPanning && aEvent.Dragging() )
  222. {
  223. if( m_state == DRAG_PANNING )
  224. {
  225. static bool justWarped = false;
  226. int warpX = 0;
  227. int warpY = 0;
  228. wxSize parentSize = m_parentPanel->GetClientSize();
  229. if( x < 0 )
  230. {
  231. warpX = parentSize.x;
  232. }
  233. else if(x >= parentSize.x )
  234. {
  235. warpX = -parentSize.x;
  236. }
  237. if( y < 0 )
  238. {
  239. warpY = parentSize.y;
  240. }
  241. else if( y >= parentSize.y )
  242. {
  243. warpY = -parentSize.y;
  244. }
  245. if( !justWarped )
  246. {
  247. VECTOR2D d = m_dragStartPoint - mousePos;
  248. m_dragStartPoint = mousePos;
  249. VECTOR2D delta = m_view->ToWorld( d, false );
  250. m_view->SetCenter( m_view->GetCenter() + delta );
  251. aEvent.StopPropagation();
  252. }
  253. if( warpX || warpY )
  254. {
  255. if( !justWarped )
  256. {
  257. if( m_infinitePanWorks
  258. && KIPLATFORM::UI::WarpPointer( m_parentPanel, x + warpX, y + warpY ) )
  259. {
  260. m_dragStartPoint += VECTOR2D( warpX, warpY );
  261. justWarped = true;
  262. }
  263. }
  264. else
  265. justWarped = false;
  266. }
  267. else
  268. justWarped = false;
  269. }
  270. else if( m_state == DRAG_ZOOMING )
  271. {
  272. static bool justWarped = false;
  273. int warpY = 0;
  274. wxSize parentSize = m_parentPanel->GetClientSize();
  275. if( y < 0 )
  276. {
  277. warpY = parentSize.y;
  278. }
  279. else if( y >= parentSize.y )
  280. {
  281. warpY = -parentSize.y;
  282. }
  283. if( !justWarped )
  284. {
  285. VECTOR2D d = m_dragStartPoint - mousePos;
  286. m_dragStartPoint = mousePos;
  287. double scale = exp( d.y * m_settings.m_zoomSpeed * 0.001 );
  288. wxLogTrace( traceZoomScroll, wxString::Format( "dy: %f scale: %f", d.y, scale ) );
  289. m_view->SetScale( m_view->GetScale() * scale, m_view->ToWorld( m_zoomStartPoint ) );
  290. aEvent.StopPropagation();
  291. }
  292. if( warpY )
  293. {
  294. if( !justWarped )
  295. {
  296. KIPLATFORM::UI::WarpPointer( m_parentPanel, x, y + warpY );
  297. m_dragStartPoint += VECTOR2D( 0, warpY );
  298. justWarped = true;
  299. }
  300. else
  301. justWarped = false;
  302. }
  303. else
  304. justWarped = false;
  305. }
  306. }
  307. if( m_updateCursor ) // do not update the cursor position if it was explicitly set
  308. m_cursorPos = GetClampedCoords( m_view->ToWorld( mousePos ) );
  309. else
  310. m_updateCursor = true;
  311. aEvent.Skip();
  312. }
  313. void WX_VIEW_CONTROLS::onWheel( wxMouseEvent& aEvent )
  314. {
  315. #ifdef __WXGTK3__
  316. if( aEvent.GetTimestamp() == m_lastTimestamp )
  317. {
  318. aEvent.Skip( false );
  319. return;
  320. }
  321. m_lastTimestamp = aEvent.GetTimestamp();
  322. #endif
  323. const double wheelPanSpeed = 0.001;
  324. const int axis = aEvent.GetWheelAxis();
  325. if( axis == wxMOUSE_WHEEL_HORIZONTAL && !m_settings.m_horizontalPan )
  326. return;
  327. // Pick the modifier, if any. Shift beats control beats alt, we don't support more than one.
  328. int nMods = 0;
  329. int modifiers = 0;
  330. if( aEvent.ShiftDown() )
  331. {
  332. nMods += 1;
  333. modifiers = WXK_SHIFT;
  334. }
  335. if( aEvent.ControlDown() )
  336. {
  337. nMods += 1;
  338. modifiers = modifiers == 0 ? WXK_CONTROL : modifiers;
  339. }
  340. if( aEvent.AltDown() )
  341. {
  342. nMods += 1;
  343. modifiers = modifiers == 0 ? WXK_ALT : modifiers;
  344. }
  345. // Zero or one modifier is view control
  346. if( nMods <= 1 )
  347. {
  348. // Restrict zoom handling to the vertical axis, otherwise horizontal
  349. // scrolling events (e.g. touchpads and some mice) end up interpreted
  350. // as vertical scroll events and confuse the user.
  351. if( modifiers == m_settings.m_scrollModifierZoom && axis == wxMOUSE_WHEEL_VERTICAL )
  352. {
  353. const int rotation =
  354. aEvent.GetWheelRotation() * ( m_settings.m_scrollReverseZoom ? -1 : 1 );
  355. const double zoomScale = m_zoomController->GetScaleForRotation( rotation );
  356. if( IsCursorWarpingEnabled() )
  357. {
  358. CenterOnCursor();
  359. m_view->SetScale( m_view->GetScale() * zoomScale );
  360. }
  361. else
  362. {
  363. const VECTOR2D anchor = m_view->ToWorld( VECTOR2D( aEvent.GetX(), aEvent.GetY() ) );
  364. m_view->SetScale( m_view->GetScale() * zoomScale, anchor );
  365. }
  366. // Refresh the zoom level and mouse position on message panel
  367. // (mouse position has not changed, only the zoom level has changed):
  368. refreshMouse( true );
  369. }
  370. else
  371. {
  372. // Scrolling
  373. VECTOR2D scrollVec = m_view->ToWorld( m_view->GetScreenPixelSize(), false )
  374. * ( (double) aEvent.GetWheelRotation() * wheelPanSpeed );
  375. double scrollX = 0.0;
  376. double scrollY = 0.0;
  377. bool hReverse = false;
  378. if( axis != wxMOUSE_WHEEL_HORIZONTAL )
  379. hReverse = m_settings.m_scrollReversePanH;
  380. if( axis == wxMOUSE_WHEEL_HORIZONTAL || modifiers == m_settings.m_scrollModifierPanH )
  381. {
  382. if( hReverse )
  383. scrollX = scrollVec.x;
  384. else
  385. scrollX = ( axis == wxMOUSE_WHEEL_HORIZONTAL ) ? scrollVec.x : -scrollVec.x;
  386. }
  387. else
  388. {
  389. scrollY = -scrollVec.y;
  390. }
  391. VECTOR2D delta( scrollX, scrollY );
  392. m_view->SetCenter( m_view->GetCenter() + delta );
  393. refreshMouse( true );
  394. }
  395. // Do not skip this event, otherwise wxWidgets will fire
  396. // 3 wxEVT_SCROLLWIN_LINEUP or wxEVT_SCROLLWIN_LINEDOWN (normal wxWidgets behavior)
  397. // and we do not want that.
  398. }
  399. else
  400. {
  401. // When we have muliple mods, forward it for tool handling
  402. aEvent.Skip();
  403. }
  404. }
  405. void WX_VIEW_CONTROLS::onMagnify( wxMouseEvent& aEvent )
  406. {
  407. // Scale based on the magnification from our underlying magnification event.
  408. VECTOR2D anchor = m_view->ToWorld( VECTOR2D( aEvent.GetX(), aEvent.GetY() ) );
  409. m_view->SetScale( m_view->GetScale() * ( aEvent.GetMagnification() + 1.0f ), anchor );
  410. aEvent.Skip();
  411. }
  412. void WX_VIEW_CONTROLS::setState( STATE aNewState )
  413. {
  414. m_state = aNewState;
  415. }
  416. void WX_VIEW_CONTROLS::onButton( wxMouseEvent& aEvent )
  417. {
  418. switch( m_state )
  419. {
  420. case IDLE:
  421. case AUTO_PANNING:
  422. if( ( aEvent.MiddleDown() && m_settings.m_dragMiddle == MOUSE_DRAG_ACTION::PAN ) ||
  423. ( aEvent.RightDown() && m_settings.m_dragRight == MOUSE_DRAG_ACTION::PAN ) )
  424. {
  425. m_dragStartPoint = VECTOR2D( aEvent.GetX(), aEvent.GetY() );
  426. setState( DRAG_PANNING );
  427. m_infinitePanWorks = KIPLATFORM::UI::InfiniteDragPrepareWindow( m_parentPanel );
  428. #if defined USE_MOUSE_CAPTURE
  429. if( !m_parentPanel->HasCapture() )
  430. m_parentPanel->CaptureMouse();
  431. #endif
  432. }
  433. else if( ( aEvent.MiddleDown() && m_settings.m_dragMiddle == MOUSE_DRAG_ACTION::ZOOM ) ||
  434. ( aEvent.RightDown() && m_settings.m_dragRight == MOUSE_DRAG_ACTION::ZOOM ) )
  435. {
  436. m_dragStartPoint = VECTOR2D( aEvent.GetX(), aEvent.GetY() );
  437. m_zoomStartPoint = m_dragStartPoint;
  438. setState( DRAG_ZOOMING );
  439. #if defined USE_MOUSE_CAPTURE
  440. if( !m_parentPanel->HasCapture() )
  441. m_parentPanel->CaptureMouse();
  442. #endif
  443. }
  444. if( aEvent.LeftUp() )
  445. setState( IDLE ); // Stop autopanning when user release left mouse button
  446. break;
  447. case DRAG_ZOOMING:
  448. case DRAG_PANNING:
  449. if( aEvent.MiddleUp() || aEvent.LeftUp() || aEvent.RightUp() )
  450. {
  451. setState( IDLE );
  452. KIPLATFORM::UI::InfiniteDragReleaseWindow();
  453. #if defined USE_MOUSE_CAPTURE
  454. if( !m_settings.m_cursorCaptured && m_parentPanel->HasCapture() )
  455. m_parentPanel->ReleaseMouse();
  456. #endif
  457. }
  458. break;
  459. }
  460. aEvent.Skip();
  461. }
  462. void WX_VIEW_CONTROLS::onEnter( wxMouseEvent& aEvent )
  463. {
  464. // Avoid stealing focus from text controls
  465. // This is particularly important for users using On-Screen-Keyboards
  466. // They may move the mouse over the canvas to reach the keyboard
  467. if( KIUI::IsInputControlFocused() )
  468. {
  469. return;
  470. }
  471. #if defined( _WIN32 ) || defined( __WXGTK__ )
  472. // Win32 and some *nix WMs transmit mouse move and wheel events to all controls below the mouse regardless
  473. // of focus. Forcing the focus here will cause the EDA FRAMES to immediately become the
  474. // top level active window.
  475. if( m_parentPanel->GetParent() != nullptr )
  476. {
  477. // this assumes the parent panel's parent is the eda window
  478. if( KIPLATFORM::UI::IsWindowActive( m_parentPanel->GetParent() ) )
  479. {
  480. m_parentPanel->SetFocus();
  481. }
  482. }
  483. #else
  484. m_parentPanel->SetFocus();
  485. #endif
  486. }
  487. void WX_VIEW_CONTROLS::onLeave( wxMouseEvent& aEvent )
  488. {
  489. #if !defined USE_MOUSE_CAPTURE
  490. onMotion( aEvent );
  491. #endif
  492. }
  493. void WX_VIEW_CONTROLS::onCaptureLost( wxMouseEvent& aEvent )
  494. {
  495. // This method must be present to suppress the capture-lost assertion
  496. // Set the flag to allow calling m_parentPanel->CaptureMouse()
  497. // Note: One cannot call m_parentPanel->CaptureMouse() twice, this is not accepted
  498. // by wxWidgets (MSW specific) so we need this guard
  499. m_parentPanel->m_MouseCapturedLost = true;
  500. }
  501. void WX_VIEW_CONTROLS::onTimer( wxTimerEvent& aEvent )
  502. {
  503. switch( m_state )
  504. {
  505. case AUTO_PANNING:
  506. {
  507. if( !m_settings.m_autoPanEnabled )
  508. {
  509. setState( IDLE );
  510. return;
  511. }
  512. #ifdef __WXMSW__
  513. // Hackfix: It's possible for the mouse to leave the canvas
  514. // without triggering any leave events on windows
  515. // Use a MSW only wx function
  516. if( !m_parentPanel->IsMouseInWindow() )
  517. {
  518. m_panTimer.Stop();
  519. setState( IDLE );
  520. return;
  521. }
  522. #endif
  523. if( !m_parentPanel->HasFocus() && !m_parentPanel->StatusPopupHasFocus() )
  524. {
  525. setState( IDLE );
  526. return;
  527. }
  528. double borderSize = std::min( m_settings.m_autoPanMargin * m_view->GetScreenPixelSize().x,
  529. m_settings.m_autoPanMargin * m_view->GetScreenPixelSize().y );
  530. // When the mouse cursor is outside the area with no pan,
  531. // m_panDirection is the dist to this area limit ( in pixels )
  532. // It will be used also as pan value (the pan speed depends on this dist).
  533. VECTOR2D dir( m_panDirection );
  534. // When the mouse cursor is outside the area with no pan, the pan value
  535. // is accelerated depending on the dist between the area and the cursor
  536. float accel = 0.5f + ( m_settings.m_autoPanAcceleration / 5.0f );
  537. // For a small mouse cursor dist to area, just use the distance.
  538. // But for a dist > borderSize / 2, use an accelerated pan value
  539. if( dir.EuclideanNorm() >= borderSize ) // far from area limits
  540. dir = dir.Resize( borderSize * accel );
  541. else if( dir.EuclideanNorm() > borderSize / 2 ) // Near from area limits
  542. dir = dir.Resize( borderSize );
  543. dir = m_view->ToWorld( dir, false );
  544. m_view->SetCenter( m_view->GetCenter() + dir );
  545. refreshMouse( true );
  546. m_panTimer.Start();
  547. }
  548. break;
  549. case IDLE: // Just remove unnecessary warnings
  550. case DRAG_PANNING:
  551. case DRAG_ZOOMING:
  552. break;
  553. }
  554. }
  555. void WX_VIEW_CONTROLS::onZoomGesture( wxZoomGestureEvent& aEvent )
  556. {
  557. if( aEvent.IsGestureStart() )
  558. {
  559. m_gestureLastZoomFactor = 1.0;
  560. m_gestureLastPos = VECTOR2D( aEvent.GetPosition().x, aEvent.GetPosition().y );
  561. }
  562. VECTOR2D evtPos( aEvent.GetPosition().x, aEvent.GetPosition().y );
  563. VECTOR2D deltaWorld = m_view->ToWorld( evtPos - m_gestureLastPos, false );
  564. m_view->SetCenter( m_view->GetCenter() - deltaWorld );
  565. m_view->SetScale( m_view->GetScale() * aEvent.GetZoomFactor() / m_gestureLastZoomFactor,
  566. m_view->ToWorld( evtPos ) );
  567. m_gestureLastZoomFactor = aEvent.GetZoomFactor();
  568. m_gestureLastPos = evtPos;
  569. refreshMouse( true );
  570. }
  571. void WX_VIEW_CONTROLS::onPanGesture( wxPanGestureEvent& aEvent )
  572. {
  573. VECTOR2I screenDelta( aEvent.GetDelta().x, aEvent.GetDelta().y );
  574. VECTOR2D deltaWorld = m_view->ToWorld( screenDelta, false );
  575. m_view->SetCenter( m_view->GetCenter() - deltaWorld );
  576. refreshMouse( true );
  577. }
  578. void WX_VIEW_CONTROLS::onScroll( wxScrollWinEvent& aEvent )
  579. {
  580. const double linePanDelta = 0.05;
  581. const double pagePanDelta = 0.5;
  582. int type = aEvent.GetEventType();
  583. int dir = aEvent.GetOrientation();
  584. if( type == wxEVT_SCROLLWIN_THUMBTRACK )
  585. {
  586. auto center = m_view->GetCenter();
  587. const auto& boundary = m_view->GetBoundary();
  588. // Flip scroll direction in flipped view
  589. const double xstart = ( m_view->IsMirroredX() ?
  590. boundary.GetRight() : boundary.GetLeft() );
  591. const double xdelta = ( m_view->IsMirroredX() ? -1 : 1 );
  592. if( dir == wxHORIZONTAL )
  593. center.x = xstart + xdelta * ( aEvent.GetPosition() / m_scrollScale.x );
  594. else
  595. center.y = boundary.GetTop() + aEvent.GetPosition() / m_scrollScale.y;
  596. m_view->SetCenter( center );
  597. }
  598. else if( type == wxEVT_SCROLLWIN_THUMBRELEASE ||
  599. type == wxEVT_SCROLLWIN_TOP ||
  600. type == wxEVT_SCROLLWIN_BOTTOM )
  601. {
  602. // Do nothing on thumb release, we don't care about it.
  603. // We don't have a concept of top or bottom in our viewport, so ignore those events.
  604. }
  605. else
  606. {
  607. double dist = 0;
  608. if( type == wxEVT_SCROLLWIN_PAGEUP )
  609. {
  610. dist = pagePanDelta;
  611. }
  612. else if( type == wxEVT_SCROLLWIN_PAGEDOWN )
  613. {
  614. dist = -pagePanDelta;
  615. }
  616. else if( type == wxEVT_SCROLLWIN_LINEUP )
  617. {
  618. dist = linePanDelta;
  619. }
  620. else if( type == wxEVT_SCROLLWIN_LINEDOWN )
  621. {
  622. dist = -linePanDelta;
  623. }
  624. else
  625. {
  626. wxCHECK_MSG( false, /* void */, wxT( "Unhandled event type" ) );
  627. }
  628. VECTOR2D scroll = m_view->ToWorld( m_view->GetScreenPixelSize(), false ) * dist;
  629. double scrollX = 0.0;
  630. double scrollY = 0.0;
  631. if ( dir == wxHORIZONTAL )
  632. scrollX = -scroll.x;
  633. else
  634. scrollY = -scroll.y;
  635. VECTOR2D delta( scrollX, scrollY );
  636. m_view->SetCenter( m_view->GetCenter() + delta );
  637. }
  638. m_parentPanel->Refresh();
  639. }
  640. void WX_VIEW_CONTROLS::CaptureCursor( bool aEnabled )
  641. {
  642. #if defined USE_MOUSE_CAPTURE
  643. // Note: for some reason, m_parentPanel->HasCapture() can be false even if CaptureMouse()
  644. // was called (i.e. mouse was captured, so when need to test m_MouseCapturedLost to be
  645. // sure a wxEVT_MOUSE_CAPTURE_LOST event was fired before. Otherwise wxMSW complains
  646. // The IsModalDialogFocused is checked because it's possible to start a capture
  647. // due to event ordering while a modal dialog was just opened, the mouse capture steels focus
  648. // from the modal and causes odd behavior
  649. if( aEnabled && !m_parentPanel->HasCapture() && m_parentPanel->m_MouseCapturedLost
  650. && !KIUI::IsModalDialogFocused() )
  651. {
  652. m_parentPanel->CaptureMouse();
  653. // Clear the flag to allow calling m_parentPanel->CaptureMouse()
  654. // Calling it without calling ReleaseMouse() is not accepted by wxWidgets (MSW specific)
  655. m_parentPanel->m_MouseCapturedLost = false;
  656. }
  657. else if( !aEnabled && m_parentPanel->HasCapture()
  658. && m_state != DRAG_PANNING && m_state != DRAG_ZOOMING )
  659. {
  660. m_parentPanel->ReleaseMouse();
  661. // Mouse is released, calling CaptureMouse() is allowed now:
  662. m_parentPanel->m_MouseCapturedLost = true;
  663. }
  664. #endif
  665. VIEW_CONTROLS::CaptureCursor( aEnabled );
  666. }
  667. void WX_VIEW_CONTROLS::CancelDrag()
  668. {
  669. if( m_state == DRAG_PANNING || m_state == DRAG_ZOOMING )
  670. {
  671. setState( IDLE );
  672. #if defined USE_MOUSE_CAPTURE
  673. if( !m_settings.m_cursorCaptured && m_parentPanel->HasCapture() )
  674. m_parentPanel->ReleaseMouse();
  675. #endif
  676. }
  677. }
  678. VECTOR2D WX_VIEW_CONTROLS::GetMousePosition( bool aWorldCoordinates ) const
  679. {
  680. wxPoint msp = getMouseScreenPosition();
  681. VECTOR2D screenPos( msp.x, msp.y );
  682. return aWorldCoordinates ? GetClampedCoords( m_view->ToWorld( screenPos ) ) : screenPos;
  683. }
  684. VECTOR2D WX_VIEW_CONTROLS::GetRawCursorPosition( bool aEnableSnapping ) const
  685. {
  686. GAL* gal = m_view->GetGAL();
  687. if( aEnableSnapping && gal->GetGridSnapping() )
  688. {
  689. return gal->GetGridPoint( m_cursorPos );
  690. }
  691. else
  692. {
  693. return m_cursorPos;
  694. }
  695. }
  696. VECTOR2D WX_VIEW_CONTROLS::GetCursorPosition( bool aEnableSnapping ) const
  697. {
  698. if( m_settings.m_forceCursorPosition )
  699. {
  700. return m_settings.m_forcedPosition;
  701. }
  702. else
  703. {
  704. return GetClampedCoords( GetRawCursorPosition( aEnableSnapping ) );
  705. }
  706. }
  707. void WX_VIEW_CONTROLS::SetCursorPosition( const VECTOR2D& aPosition, bool aWarpView,
  708. bool aTriggeredByArrows, long aArrowCommand )
  709. {
  710. m_updateCursor = false;
  711. VECTOR2D clampedPosition = GetClampedCoords( aPosition );
  712. if( aTriggeredByArrows )
  713. {
  714. m_settings.m_lastKeyboardCursorPositionValid = true;
  715. m_settings.m_lastKeyboardCursorPosition = clampedPosition;
  716. m_settings.m_lastKeyboardCursorCommand = aArrowCommand;
  717. m_cursorWarped = false;
  718. }
  719. else
  720. {
  721. m_settings.m_lastKeyboardCursorPositionValid = false;
  722. m_settings.m_lastKeyboardCursorPosition = { 0.0, 0.0 };
  723. m_settings.m_lastKeyboardCursorCommand = 0;
  724. m_cursorWarped = true;
  725. }
  726. WarpMouseCursor( clampedPosition, true, aWarpView );
  727. m_cursorPos = clampedPosition;
  728. }
  729. void WX_VIEW_CONTROLS::SetCrossHairCursorPosition( const VECTOR2D& aPosition,
  730. bool aWarpView = true )
  731. {
  732. m_updateCursor = false;
  733. VECTOR2D clampedPosition = GetClampedCoords( aPosition );
  734. const VECTOR2I& screenSize = m_view->GetGAL()->GetScreenPixelSize();
  735. BOX2I screen( VECTOR2I( 0, 0 ), screenSize );
  736. VECTOR2D screenPos = m_view->ToScreen( clampedPosition );
  737. if( aWarpView && !screen.Contains( screenPos ) )
  738. m_view->SetCenter( clampedPosition );
  739. m_cursorPos = clampedPosition;
  740. }
  741. void WX_VIEW_CONTROLS::WarpMouseCursor( const VECTOR2D& aPosition, bool aWorldCoordinates,
  742. bool aWarpView )
  743. {
  744. if( aWorldCoordinates )
  745. {
  746. const VECTOR2I& screenSize = m_view->GetGAL()->GetScreenPixelSize();
  747. BOX2I screen( VECTOR2I( 0, 0 ), screenSize );
  748. VECTOR2D clampedPosition = GetClampedCoords( aPosition );
  749. VECTOR2D screenPos = m_view->ToScreen( clampedPosition );
  750. if( !screen.Contains( screenPos ) )
  751. {
  752. if( aWarpView )
  753. {
  754. m_view->SetCenter( clampedPosition );
  755. KIPLATFORM::UI::WarpPointer( m_parentPanel, screenSize.x / 2, screenSize.y / 2 );
  756. }
  757. }
  758. else
  759. {
  760. KIPLATFORM::UI::WarpPointer( m_parentPanel, screenPos.x, screenPos.y );
  761. }
  762. }
  763. else
  764. {
  765. KIPLATFORM::UI::WarpPointer( m_parentPanel, aPosition.x, aPosition.y );
  766. }
  767. // If we are not refreshing because of mouse movement, don't set the modifiers
  768. // because we are refreshing for keyboard movement, which uses the same modifiers for other actions
  769. refreshMouse( m_updateCursor );
  770. }
  771. void WX_VIEW_CONTROLS::CenterOnCursor()
  772. {
  773. const VECTOR2I& screenSize = m_view->GetGAL()->GetScreenPixelSize();
  774. VECTOR2D screenCenter( screenSize / 2 );
  775. if( GetMousePosition( false ) != screenCenter )
  776. {
  777. VECTOR2D newCenter = GetCursorPosition();
  778. if( KIPLATFORM::UI::WarpPointer( m_parentPanel, screenCenter.x, screenCenter.y ) )
  779. {
  780. m_view->SetCenter( newCenter );
  781. m_dragStartPoint = screenCenter;
  782. }
  783. }
  784. }
  785. void WX_VIEW_CONTROLS::PinCursorInsideNonAutoscrollArea( bool aWarpMouseCursor )
  786. {
  787. int border = std::min( m_settings.m_autoPanMargin * m_view->GetScreenPixelSize().x,
  788. m_settings.m_autoPanMargin * m_view->GetScreenPixelSize().y );
  789. border += 2;
  790. VECTOR2D topLeft( border, border );
  791. VECTOR2D botRight( m_view->GetScreenPixelSize().x - border,
  792. m_view->GetScreenPixelSize().y - border );
  793. topLeft = m_view->ToWorld( topLeft );
  794. botRight = m_view->ToWorld( botRight );
  795. VECTOR2D pos = GetMousePosition( true );
  796. if( pos.x < topLeft.x )
  797. pos.x = topLeft.x;
  798. else if( pos.x > botRight.x )
  799. pos.x = botRight.x;
  800. if( pos.y < topLeft.y )
  801. pos.y = topLeft.y;
  802. else if( pos.y > botRight.y )
  803. pos.y = botRight.y;
  804. SetCursorPosition( pos, false, false, 0 );
  805. if( aWarpMouseCursor )
  806. WarpMouseCursor( pos, true );
  807. }
  808. bool WX_VIEW_CONTROLS::handleAutoPanning( const wxMouseEvent& aEvent )
  809. {
  810. VECTOR2I p( aEvent.GetX(), aEvent.GetY() );
  811. VECTOR2I pKey( m_view->ToScreen(m_settings.m_lastKeyboardCursorPosition ) );
  812. if( m_cursorWarped || ( m_settings.m_lastKeyboardCursorPositionValid && p == pKey ) )
  813. {
  814. // last cursor move event came from keyboard cursor control. If auto-panning is enabled
  815. // and the next position is inside the autopan zone, check if it really came from a mouse
  816. // event, otherwise disable autopan temporarily. Also temporarily disable autopan if the
  817. // cursor is in the autopan zone because the application warped the cursor.
  818. m_cursorWarped = false;
  819. return true;
  820. }
  821. m_cursorWarped = false;
  822. // Compute areas where autopanning is active
  823. int borderStart = std::min( m_settings.m_autoPanMargin * m_view->GetScreenPixelSize().x,
  824. m_settings.m_autoPanMargin * m_view->GetScreenPixelSize().y );
  825. borderStart = std::max( borderStart, 2 );
  826. int borderEndX = m_view->GetScreenPixelSize().x - borderStart;
  827. int borderEndY = m_view->GetScreenPixelSize().y - borderStart;
  828. if( p.x < borderStart )
  829. m_panDirection.x = -( borderStart - p.x );
  830. else if( p.x > borderEndX )
  831. m_panDirection.x = ( p.x - borderEndX );
  832. else
  833. m_panDirection.x = 0;
  834. if( p.y < borderStart )
  835. m_panDirection.y = -( borderStart - p.y );
  836. else if( p.y > borderEndY )
  837. m_panDirection.y = ( p.y - borderEndY );
  838. else
  839. m_panDirection.y = 0;
  840. bool borderHit = ( m_panDirection.x != 0 || m_panDirection.y != 0 );
  841. switch( m_state )
  842. {
  843. case AUTO_PANNING:
  844. if( !borderHit )
  845. {
  846. m_panTimer.Stop();
  847. setState( IDLE );
  848. return false;
  849. }
  850. return true;
  851. case IDLE:
  852. if( borderHit )
  853. {
  854. setState( AUTO_PANNING );
  855. m_panTimer.Start( (int) ( 250.0 / 60.0 ), true );
  856. return true;
  857. }
  858. return false;
  859. case DRAG_PANNING:
  860. case DRAG_ZOOMING:
  861. return false;
  862. }
  863. wxCHECK_MSG( false, false, wxT( "This line should never be reached" ) );
  864. return false;
  865. }
  866. void WX_VIEW_CONTROLS::handleCursorCapture( int x, int y )
  867. {
  868. if( m_settings.m_cursorCaptured )
  869. {
  870. bool warp = false;
  871. wxSize parentSize = m_parentPanel->GetClientSize();
  872. if( x < 0 )
  873. {
  874. x = 0;
  875. warp = true;
  876. }
  877. else if( x >= parentSize.x )
  878. {
  879. x = parentSize.x - 1;
  880. warp = true;
  881. }
  882. if( y < 0 )
  883. {
  884. y = 0;
  885. warp = true;
  886. }
  887. else if( y >= parentSize.y )
  888. {
  889. y = parentSize.y - 1;
  890. warp = true;
  891. }
  892. if( warp )
  893. KIPLATFORM::UI::WarpPointer( m_parentPanel, x, y );
  894. }
  895. }
  896. void WX_VIEW_CONTROLS::refreshMouse( bool aSetModifiers )
  897. {
  898. // Notify tools that the cursor position has changed in the world coordinates
  899. wxMouseEvent moveEvent( EVT_REFRESH_MOUSE );
  900. wxPoint msp = getMouseScreenPosition();
  901. moveEvent.SetX( msp.x );
  902. moveEvent.SetY( msp.y );
  903. if( aSetModifiers )
  904. {
  905. // Set the modifiers state
  906. moveEvent.SetControlDown( wxGetKeyState( WXK_CONTROL ) );
  907. moveEvent.SetShiftDown( wxGetKeyState( WXK_SHIFT ) );
  908. moveEvent.SetAltDown( wxGetKeyState( WXK_ALT ) );
  909. }
  910. m_cursorPos = GetClampedCoords( m_view->ToWorld( VECTOR2D( msp.x, msp.y ) ) );
  911. wxPostEvent( m_parentPanel, moveEvent );
  912. }
  913. wxPoint WX_VIEW_CONTROLS::getMouseScreenPosition() const
  914. {
  915. wxPoint msp = KIPLATFORM::UI::GetMousePosition();
  916. m_parentPanel->ScreenToClient( &msp.x, &msp.y );
  917. return msp;
  918. }
  919. void WX_VIEW_CONTROLS::UpdateScrollbars()
  920. {
  921. const BOX2D viewport = m_view->GetViewport();
  922. const BOX2D& boundary = m_view->GetBoundary();
  923. m_scrollScale.x = 2e3 / viewport.GetWidth(); // TODO it does not have to be updated so often
  924. m_scrollScale.y = 2e3 / viewport.GetHeight();
  925. VECTOR2I newScroll( ( viewport.Centre().x - boundary.GetLeft() ) * m_scrollScale.x,
  926. ( viewport.Centre().y - boundary.GetTop() ) * m_scrollScale.y );
  927. // We add the width of the scroll bar thumb to the range because the scroll range is given by
  928. // the full bar while the position is given by the left/top position of the thumb
  929. VECTOR2I newRange( m_scrollScale.x * boundary.GetWidth() +
  930. m_parentPanel->GetScrollThumb( wxSB_HORIZONTAL ),
  931. m_scrollScale.y * boundary.GetHeight() +
  932. m_parentPanel->GetScrollThumb( wxSB_VERTICAL ) );
  933. // Flip scroll direction in flipped view
  934. if( m_view->IsMirroredX() )
  935. newScroll.x = ( boundary.GetRight() - viewport.Centre().x ) * m_scrollScale.x;
  936. // Adjust scrollbars only if it is needed. Otherwise there are cases when canvas is continuously
  937. // refreshed (Windows)
  938. if( m_scrollPos != newScroll || newRange.x != m_parentPanel->GetScrollRange( wxSB_HORIZONTAL )
  939. || newRange.y != m_parentPanel->GetScrollRange( wxSB_VERTICAL ) )
  940. {
  941. m_parentPanel->SetScrollbars( 1, 1, newRange.x, newRange.y, newScroll.x, newScroll.y,
  942. true );
  943. m_scrollPos = newScroll;
  944. #if !defined( __APPLE__ ) && !defined( WIN32 )
  945. // Trigger a mouse refresh to get the canvas update in GTK (re-draws the scrollbars).
  946. // Note that this causes an infinite loop on OSX and Windows (in certain cases) as it
  947. // generates a paint event.
  948. refreshMouse( false );
  949. #endif
  950. }
  951. }
  952. void WX_VIEW_CONTROLS::ForceCursorPosition( bool aEnabled, const VECTOR2D& aPosition )
  953. {
  954. VECTOR2D clampedPosition = GetClampedCoords( aPosition );
  955. m_settings.m_forceCursorPosition = aEnabled;
  956. m_settings.m_forcedPosition = clampedPosition;
  957. }