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 // Honor the "Pan left/right with horizontal movement" setting for native horizontal wheel
84 if( event.GetWheelAxis() == wxMOUSE_WHEEL_HORIZONTAL && !m_settings.m_horizontalPan )
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: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