KiCad PCB EDA Suite
Loading...
Searching...
No Matches
hidpi_gl_3D_canvas.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KICAD, a free EDA CAD application.
3 *
4 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * Base class for HiDPI aware wxGLCanvas implementations.
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, you may find one here:
20 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
21 * or you may search the http://www.gnu.org website for the version 2 license,
22 * or you may write to the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24 */
25
28
30
31HIDPI_GL_3D_CANVAS::HIDPI_GL_3D_CANVAS( const KIGFX::VC_SETTINGS& aVcSettings, CAMERA& aCamera, wxWindow* aParent,
32 const wxGLAttributes& aGLAttribs, wxWindowID aId, const wxPoint& aPos,
33 const wxSize& aSize, long aStyle, const wxString& aName,
34 const wxPalette& aPalette ) :
35 HIDPI_GL_CANVAS( aVcSettings, aParent, aGLAttribs, aId, aPos, aSize, aStyle, aName, aPalette ),
36 m_mouse_is_moving( false ),
37 m_mouse_was_moved( false ),
38 m_camera_is_moving( false ),
39 m_camera( aCamera )
40{
41}
42
43
44void HIDPI_GL_3D_CANVAS::OnMouseMoveCamera( wxMouseEvent& event )
45{
47 return;
48
49 const wxSize& nativeWinSize = GetNativePixelSize();
50 const wxPoint& nativePosition = GetNativePosition( event.GetPosition() );
51
52 m_camera.SetCurWindowSize( nativeWinSize );
53
54 if( event.Dragging() )
55 {
56 bool handled = false;
57
58 if( event.LeftIsDown() )
59 {
60 m_camera.Drag( nativePosition );
61 handled = true;
62 }
63 else if( ( event.MiddleIsDown() && m_settings.m_dragMiddle == MOUSE_DRAG_ACTION::PAN )
64 || ( event.RightIsDown() && m_settings.m_dragRight == MOUSE_DRAG_ACTION::PAN ) )
65 {
66 m_camera.Pan( nativePosition );
67 handled = true;
68 }
69
70 if( handled )
71 {
72 m_mouse_is_moving = true;
73 m_mouse_was_moved = true;
74 }
75 }
76
77 m_camera.SetCurMousePosition( nativePosition );
78}
79
80void HIDPI_GL_3D_CANVAS::OnMouseWheelCamera( wxMouseEvent& event, bool aPan )
81{
82 bool mouseActivity = false;
83
85 return;
86
87 // Pick the modifier, if any. Shift beats control beats alt, we don't support more than one.
88 int modifiers =
89 event.ShiftDown() ? WXK_SHIFT : ( event.ControlDown() ? WXK_CONTROL : ( event.AltDown() ? WXK_ALT : 0 ) );
90
91 float delta_move = m_delta_move_step_factor * m_camera.GetZoom();
92 float horizontalSign = m_settings.m_scrollReversePanH ? -1 : 1;
93 float zoomSign = m_settings.m_scrollReverseZoom ? -1 : 1;
94
95 if( aPan )
96 delta_move *= 0.01f * event.GetWheelRotation();
97 else if( event.GetWheelRotation() < 0 )
98 delta_move = -delta_move;
99
100 // mousewheel_panning enabled:
101 // wheel -> pan;
102 // wheel + shift -> horizontal scrolling;
103 // wheel + ctrl -> zooming;
104 // mousewheel_panning disabled:
105 // wheel + shift -> vertical scrolling;
106 // wheel + ctrl -> horizontal scrolling;
107 // wheel -> zooming.
108
109 if( aPan && modifiers != m_settings.m_scrollModifierZoom )
110 {
111 if( event.GetWheelAxis() == wxMOUSE_WHEEL_HORIZONTAL || modifiers == m_settings.m_scrollModifierPanH )
112 m_camera.Pan( SFVEC3F( -delta_move, 0.0f, 0.0f ) );
113 else
114 m_camera.Pan( SFVEC3F( 0.0f, -delta_move, 0.0f ) );
115
116 mouseActivity = true;
117 }
118 else if( modifiers == m_settings.m_scrollModifierPanV && !aPan )
119 {
120 m_camera.Pan( SFVEC3F( 0.0f, -delta_move, 0.0f ) );
121 mouseActivity = true;
122 }
123 else if( modifiers == m_settings.m_scrollModifierPanH && !aPan )
124 {
125 m_camera.Pan( SFVEC3F( delta_move * horizontalSign, 0.0f, 0.0f ) );
126 mouseActivity = true;
127 }
128 else
129 {
130 mouseActivity = m_camera.Zoom( ( event.GetWheelRotation() * zoomSign ) > 0 ? 1.1f : 1 / 1.1f );
131 }
132
133 // If it results on a camera movement
134 if( mouseActivity )
135 {
136 m_mouse_is_moving = true;
137 m_mouse_was_moved = true;
138 }
139
140 // Update the cursor current mouse position on the camera
141 m_camera.SetCurMousePosition( GetNativePosition( event.GetPosition() ) );
142}
A class used to derive camera objects from.
Definition: camera.h:103
bool Zoom(float aFactor)
Definition: camera.cpp:598
virtual void Pan(const wxPoint &aNewMousePosition)=0
virtual void Drag(const wxPoint &aNewMousePosition)=0
Calculate a new mouse drag position.
bool SetCurWindowSize(const wxSize &aSize)
Update the windows size of the camera.
Definition: camera.cpp:571
float GetZoom() const
Definition: camera.h:221
void SetCurMousePosition(const wxPoint &aPosition)
Update the current mouse position without make any new calculations on camera.
Definition: camera.cpp:554
static const float m_delta_move_step_factor
HIDPI_GL_3D_CANVAS(const KIGFX::VC_SETTINGS &aVcSettings, CAMERA &aCamera, wxWindow *parent, const wxGLAttributes &aGLAttribs, wxWindowID id=wxID_ANY, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=0, const wxString &name=wxGLCanvasName, const wxPalette &palette=wxNullPalette)
void OnMouseWheelCamera(wxMouseEvent &event, bool aPan)
void OnMouseMoveCamera(wxMouseEvent &event)
wxGLCanvas wrapper for HiDPI/Retina support.
KIGFX::VC_SETTINGS m_settings
< Current VIEW_CONTROLS settings.
virtual wxSize GetNativePixelSize() const
wxPoint GetNativePosition(const wxPoint &aPoint) const
Convert the given point from client coordinates to native pixel coordinates.
Structure to keep VIEW_CONTROLS settings for easy store/restore operations.
Definition: view_controls.h:43
bool m_scrollReversePanH
Whether to invert the scroll wheel movement for horizontal pan.
MOUSE_DRAG_ACTION m_dragMiddle
int m_scrollModifierZoom
What modifier key to enable zoom with the (vertical) scroll wheel.
int m_scrollModifierPanH
What modifier key to enable horizontal pan with the (vertical) scroll wheel.
MOUSE_DRAG_ACTION m_dragRight
bool m_scrollReverseZoom
Whether to invert the scroll wheel movement for zoom.
int m_scrollModifierPanV
What modifier key to enable vertical with the (vertical) scroll wheel.
glm::vec3 SFVEC3F
Definition: xv3d_types.h:44