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 (C) 2016-2022 Kicad Developers, see change_log.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, const wxPoint& aPos,
33 const wxSize& aSize, long aStyle, const wxString& aName,
34 const wxPalette& aPalette ) :
35 HIDPI_GL_CANVAS( aVcSettings, aParent, aGLAttribs, wxID_ANY, 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 if( event.LeftIsDown() ) // Drag
57 m_camera.Drag( nativePosition );
58 else if( event.MiddleIsDown() ) // Pan
59 m_camera.Pan( nativePosition );
60
61 m_mouse_is_moving = true;
62 m_mouse_was_moved = true;
63 }
64
65 m_camera.SetCurMousePosition( nativePosition );
66}
67
68void HIDPI_GL_3D_CANVAS::OnMouseWheelCamera( wxMouseEvent& event, bool aPan )
69{
70 bool mouseActivity = false;
71
73 return;
74
75 // Pick the modifier, if any. Shift beats control beats alt, we don't support more than one.
76 int modifiers = event.ShiftDown() ? WXK_SHIFT
77 : ( event.ControlDown() ? WXK_CONTROL
78 : ( event.AltDown() ? WXK_ALT : 0 ) );
79
80 float delta_move = m_delta_move_step_factor * m_camera.GetZoom();
81 float horizontalSign = m_settings.m_scrollReversePanH ? -1 : 1;
82 float zoomSign = m_settings.m_scrollReverseZoom ? -1 : 1;
83
84 if( aPan )
85 delta_move *= 0.01f * event.GetWheelRotation();
86 else if( event.GetWheelRotation() < 0 )
87 delta_move = -delta_move;
88
89 // mousewheel_panning enabled:
90 // wheel -> pan;
91 // wheel + shift -> horizontal scrolling;
92 // wheel + ctrl -> zooming;
93 // mousewheel_panning disabled:
94 // wheel + shift -> vertical scrolling;
95 // wheel + ctrl -> horizontal scrolling;
96 // wheel -> zooming.
97
98 if( aPan && modifiers != m_settings.m_scrollModifierZoom )
99 {
100 if( event.GetWheelAxis() == wxMOUSE_WHEEL_HORIZONTAL
101 || modifiers == m_settings.m_scrollModifierPanH )
102 m_camera.Pan( SFVEC3F( -delta_move, 0.0f, 0.0f ) );
103 else
104 m_camera.Pan( SFVEC3F( 0.0f, -delta_move, 0.0f ) );
105
106 mouseActivity = true;
107 }
108 else if( modifiers == m_settings.m_scrollModifierPanV && !aPan )
109 {
110 m_camera.Pan( SFVEC3F( 0.0f, -delta_move, 0.0f ) );
111 mouseActivity = true;
112 }
113 else if( modifiers == m_settings.m_scrollModifierPanH && !aPan )
114 {
115 m_camera.Pan( SFVEC3F( delta_move * horizontalSign, 0.0f, 0.0f ) );
116 mouseActivity = true;
117 }
118 else
119 {
120 mouseActivity =
121 m_camera.Zoom( ( event.GetWheelRotation() * zoomSign ) > 0 ? 1.1f : 1 / 1.1f );
122 }
123
124 // If it results on a camera movement
125 if( mouseActivity )
126 {
127 m_mouse_is_moving = true;
128 m_mouse_was_moved = true;
129 }
130
131 // Update the cursor current mouse position on the camera
132 m_camera.SetCurMousePosition( GetNativePosition( event.GetPosition() ) );
133}
A class used to derive camera objects from.
Definition: camera.h:103
bool Zoom(float aFactor)
Definition: camera.cpp:597
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:570
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:553
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
int m_scrollModifierZoom
What modifier key to enable horizontal pan with the (vertical) scroll wheel.
int m_scrollModifierPanH
What modifier key to enable vertical with the (vertical) scroll wheel.
bool m_scrollReverseZoom
Whether to invert the scroll wheel movement for horizontal pan.
glm::vec3 SFVEC3F
Definition: xv3d_types.h:44