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, see <https://www.gnu.org/licenses/>.
20 */
21
24
26
27HIDPI_GL_3D_CANVAS::HIDPI_GL_3D_CANVAS( const KIGFX::VC_SETTINGS& aVcSettings, CAMERA& aCamera, wxWindow* aParent,
28 const wxGLAttributes& aGLAttribs, wxWindowID aId, const wxPoint& aPos,
29 const wxSize& aSize, long aStyle, const wxString& aName,
30 const wxPalette& aPalette ) :
31 HIDPI_GL_CANVAS( aVcSettings, aParent, aGLAttribs, aId, aPos, aSize, aStyle, aName, aPalette ),
32 m_mouse_is_moving( false ),
33 m_mouse_was_moved( false ),
34 m_camera_is_moving( false ),
35 m_camera( aCamera )
36{
37}
38
39
40void HIDPI_GL_3D_CANVAS::OnMouseMoveCamera( wxMouseEvent& event )
41{
43 return;
44
45 const wxSize& nativeWinSize = GetNativePixelSize();
46 const wxPoint& nativePosition = GetNativePosition( event.GetPosition() );
47
48 m_camera.SetCurWindowSize( nativeWinSize );
49
50 if( event.Dragging() )
51 {
52 bool handled = false;
53
54 if( event.LeftIsDown() )
55 {
56 m_camera.Drag( nativePosition );
57 handled = true;
58 }
59 else if( ( event.MiddleIsDown() && m_settings.m_dragMiddle == MOUSE_DRAG_ACTION::PAN )
60 || ( event.RightIsDown() && m_settings.m_dragRight == MOUSE_DRAG_ACTION::PAN ) )
61 {
62 m_camera.Pan( nativePosition );
63 handled = true;
64 }
65
66 if( handled )
67 {
68 m_mouse_is_moving = true;
69 m_mouse_was_moved = true;
70 }
71 }
72
73 m_camera.SetCurMousePosition( nativePosition );
74}
75
76void HIDPI_GL_3D_CANVAS::OnMouseWheelCamera( wxMouseEvent& event, bool aPan )
77{
78 bool mouseActivity = false;
79
81 return;
82
83 // Pick the modifier, if any. Shift beats control beats alt, we don't support more than one.
84 int modifiers =
85 event.ShiftDown() ? WXK_SHIFT : ( event.ControlDown() ? WXK_CONTROL : ( event.AltDown() ? WXK_ALT : 0 ) );
86
87 float delta_move = m_delta_move_step_factor * m_camera.GetZoom();
88 float horizontalSign = m_settings.m_scrollReversePanH ? -1 : 1;
89 float zoomSign = m_settings.m_scrollReverseZoom ? -1 : 1;
90
91 if( aPan )
92 delta_move *= 0.01f * event.GetWheelRotation();
93 else if( event.GetWheelRotation() < 0 )
94 delta_move = -delta_move;
95
96 // mousewheel_panning enabled:
97 // wheel -> pan;
98 // wheel + shift -> horizontal scrolling;
99 // wheel + ctrl -> zooming;
100 // mousewheel_panning disabled:
101 // wheel + shift -> vertical scrolling;
102 // wheel + ctrl -> horizontal scrolling;
103 // wheel -> zooming.
104
105 if( aPan && modifiers != m_settings.m_scrollModifierZoom )
106 {
107 if( event.GetWheelAxis() == wxMOUSE_WHEEL_HORIZONTAL || modifiers == m_settings.m_scrollModifierPanH )
108 m_camera.Pan( SFVEC3F( -delta_move, 0.0f, 0.0f ) );
109 else
110 m_camera.Pan( SFVEC3F( 0.0f, -delta_move, 0.0f ) );
111
112 mouseActivity = true;
113 }
114 else if( modifiers == m_settings.m_scrollModifierPanV && !aPan )
115 {
116 m_camera.Pan( SFVEC3F( 0.0f, -delta_move, 0.0f ) );
117 mouseActivity = true;
118 }
119 else if( modifiers == m_settings.m_scrollModifierPanH && !aPan )
120 {
121 m_camera.Pan( SFVEC3F( delta_move * horizontalSign, 0.0f, 0.0f ) );
122 mouseActivity = true;
123 }
124 else
125 {
126 mouseActivity = m_camera.Zoom( ( event.GetWheelRotation() * zoomSign ) > 0 ? 1.1f : 1 / 1.1f );
127 }
128
129 // If it results on a camera movement
130 if( mouseActivity )
131 {
132 m_mouse_is_moving = true;
133 m_mouse_was_moved = true;
134 }
135
136 // Update the cursor current mouse position on the camera
137 m_camera.SetCurMousePosition( GetNativePosition( event.GetPosition() ) );
138}
A class used to derive camera objects from.
Definition camera.h:99
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)
HIDPI_GL_CANVAS(const KIGFX::VC_SETTINGS &aSettings, wxWindow *aParent, const wxGLAttributes &aGLAttribs, wxWindowID aId=wxID_ANY, const wxPoint &aPos=wxDefaultPosition, const wxSize &aSize=wxDefaultSize, long aStyle=0, const wxString &aName=wxGLCanvasName, const wxPalette &aPalette=wxNullPalette)
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.
glm::vec3 SFVEC3F
Definition xv3d_types.h:40