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
27
29
31 wxWindow* aParent, const wxGLAttributes& aGLAttribs,
32 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,
36 aPalette ),
37 m_mouse_is_moving( false ),
38 m_mouse_was_moved( false ),
39 m_camera_is_moving( false ),
40 m_camera( aCamera )
41{
42}
43
44
45void HIDPI_GL_3D_CANVAS::OnMouseMoveCamera( wxMouseEvent& event )
46{
48 return;
49
50 const wxSize& nativeWinSize = GetNativePixelSize();
51 const wxPoint& nativePosition = GetNativePosition( event.GetPosition() );
52
53 m_camera.SetCurWindowSize( nativeWinSize );
54
55 if( event.Dragging() )
56 {
57 if( event.LeftIsDown() ) // Drag
58 m_camera.Drag( nativePosition );
59 else if( event.MiddleIsDown() ) // Pan
60 m_camera.Pan( nativePosition );
61
62 m_mouse_is_moving = true;
63 m_mouse_was_moved = true;
64 }
65
66 m_camera.SetCurMousePosition( nativePosition );
67}
68
69void HIDPI_GL_3D_CANVAS::OnMouseWheelCamera( wxMouseEvent& event, bool aPan )
70{
71 bool mouseActivity = false;
72
74 return;
75
76 // Pick the modifier, if any. Shift beats control beats alt, we don't support more than one.
77 int modifiers = event.ShiftDown() ? WXK_SHIFT
78 : ( event.ControlDown() ? WXK_CONTROL
79 : ( event.AltDown() ? WXK_ALT : 0 ) );
80
81 float delta_move = m_delta_move_step_factor * m_camera.GetZoom();
82 float horizontalSign = m_settings.m_scrollReversePanH ? -1 : 1;
83 float zoomSign = m_settings.m_scrollReverseZoom ? -1 : 1;
84
85 if( aPan )
86 delta_move *= 0.01f * event.GetWheelRotation();
87 else if( event.GetWheelRotation() < 0 )
88 delta_move = -delta_move;
89
90 // mousewheel_panning enabled:
91 // wheel -> pan;
92 // wheel + shift -> horizontal scrolling;
93 // wheel + ctrl -> zooming;
94 // mousewheel_panning disabled:
95 // wheel + shift -> vertical scrolling;
96 // wheel + ctrl -> horizontal scrolling;
97 // wheel -> zooming.
98
99 if( aPan && modifiers != m_settings.m_scrollModifierZoom )
100 {
101 if( event.GetWheelAxis() == wxMOUSE_WHEEL_HORIZONTAL
102 || modifiers == m_settings.m_scrollModifierPanH )
103 m_camera.Pan( SFVEC3F( -delta_move, 0.0f, 0.0f ) );
104 else
105 m_camera.Pan( SFVEC3F( 0.0f, -delta_move, 0.0f ) );
106
107 mouseActivity = true;
108 }
109 else if( modifiers == m_settings.m_scrollModifierPanV && !aPan )
110 {
111 m_camera.Pan( SFVEC3F( 0.0f, -delta_move, 0.0f ) );
112 mouseActivity = true;
113 }
114 else if( modifiers == m_settings.m_scrollModifierPanH && !aPan )
115 {
116 m_camera.Pan( SFVEC3F( delta_move * horizontalSign, 0.0f, 0.0f ) );
117 mouseActivity = true;
118 }
119 else
120 {
121 mouseActivity =
122 m_camera.Zoom( ( event.GetWheelRotation() * zoomSign ) > 0 ? 1.1f : 1 / 1.1f );
123 }
124
125 // If it results on a camera movement
126 if( mouseActivity )
127 {
128 m_mouse_is_moving = true;
129 m_mouse_was_moved = true;
130 }
131
132 // Update the cursor current mouse position on the camera
133 m_camera.SetCurMousePosition( GetNativePosition( event.GetPosition() ) );
134}
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.
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.
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