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
83 if( aPan )
84 delta_move *= 0.01f * event.GetWheelRotation();
85 else if( event.GetWheelRotation() < 0 )
86 delta_move = -delta_move;
87
88 // mousewheel_panning enabled:
89 // wheel -> pan;
90 // wheel + shift -> horizontal scrolling;
91 // wheel + ctrl -> zooming;
92 // mousewheel_panning disabled:
93 // wheel + shift -> vertical scrolling;
94 // wheel + ctrl -> horizontal scrolling;
95 // wheel -> zooming.
96
97 if( aPan && modifiers != m_settings.m_scrollModifierZoom )
98 {
99 if( event.GetWheelAxis() == wxMOUSE_WHEEL_HORIZONTAL
100 || modifiers == m_settings.m_scrollModifierPanH )
101 m_camera.Pan( SFVEC3F( -delta_move, 0.0f, 0.0f ) );
102 else
103 m_camera.Pan( SFVEC3F( 0.0f, -delta_move, 0.0f ) );
104
105 mouseActivity = true;
106 }
107 else if( modifiers == m_settings.m_scrollModifierPanV && !aPan )
108 {
109 m_camera.Pan( SFVEC3F( 0.0f, -delta_move, 0.0f ) );
110 mouseActivity = true;
111 }
112 else if( modifiers == m_settings.m_scrollModifierPanH && !aPan )
113 {
114 m_camera.Pan( SFVEC3F( delta_move * horizontalSign, 0.0f, 0.0f ) );
115 mouseActivity = true;
116 }
117 else
118 {
119 mouseActivity = m_camera.Zoom( event.GetWheelRotation() > 0 ? 1.1f : 1 / 1.1f );
120 }
121
122 // If it results on a camera movement
123 if( mouseActivity )
124 {
125 m_mouse_is_moving = true;
126 m_mouse_was_moved = true;
127 }
128
129 // Update the cursor current mouse position on the camera
130 m_camera.SetCurMousePosition( GetNativePosition( event.GetPosition() ) );
131}
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.
glm::vec3 SFVEC3F
Definition: xv3d_types.h:44