KiCad PCB EDA Suite
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
30HIDPI_GL_3D_CANVAS::HIDPI_GL_3D_CANVAS( CAMERA& aCamera, wxWindow* aParent, wxWindowID,
31 const int* aAttribList, const wxPoint& aPos,
32 const wxSize& aSize, long aStyle, const wxString& aName,
33 const wxPalette& aPalette ) :
34 HIDPI_GL_CANVAS( aParent, wxID_ANY, aAttribList, aPos, aSize, aStyle, aName, aPalette ),
35 m_mouse_is_moving( false ),
36 m_mouse_was_moved( false ),
37 m_camera_is_moving( false ),
38 m_camera( aCamera )
39{
40}
41
42
43void HIDPI_GL_3D_CANVAS::OnMouseMoveCamera( wxMouseEvent& event )
44{
46 return;
47
48 const wxSize& nativeWinSize = GetNativePixelSize();
49 const wxPoint& nativePosition = GetNativePosition( event.GetPosition() );
50
51 m_camera.SetCurWindowSize( nativeWinSize );
52
53 if( event.Dragging() )
54 {
55 if( event.LeftIsDown() ) // Drag
56 m_camera.Drag( nativePosition );
57 else if( event.MiddleIsDown() ) // Pan
58 m_camera.Pan( nativePosition );
59
60 m_mouse_is_moving = true;
61 m_mouse_was_moved = true;
62 }
63
64 m_camera.SetCurMousePosition( nativePosition );
65}
66
67void HIDPI_GL_3D_CANVAS::OnMouseWheelCamera( wxMouseEvent& event, bool aPan )
68{
69 bool mouseActivity = false;
70
72 return;
73
74 float delta_move = m_delta_move_step_factor * m_camera.GetZoom();
75
76 if( aPan )
77 delta_move *= 0.01f * event.GetWheelRotation();
78 else if( event.GetWheelRotation() < 0 )
79 delta_move = -delta_move;
80
81 // mousewheel_panning enabled:
82 // wheel -> pan;
83 // wheel + shift -> horizontal scrolling;
84 // wheel + ctrl -> zooming;
85 // mousewheel_panning disabled:
86 // wheel + shift -> vertical scrolling;
87 // wheel + ctrl -> horizontal scrolling;
88 // wheel -> zooming.
89
90 if( aPan && !event.ControlDown() )
91 {
92 if( event.GetWheelAxis() == wxMOUSE_WHEEL_HORIZONTAL || event.ShiftDown() )
93 m_camera.Pan( SFVEC3F( -delta_move, 0.0f, 0.0f ) );
94 else
95 m_camera.Pan( SFVEC3F( 0.0f, -delta_move, 0.0f ) );
96
97 mouseActivity = true;
98 }
99 else if( event.ShiftDown() && !aPan )
100 {
101 m_camera.Pan( SFVEC3F( 0.0f, -delta_move, 0.0f ) );
102 mouseActivity = true;
103 }
104 else if( event.ControlDown() && !aPan )
105 {
106 m_camera.Pan( SFVEC3F( delta_move, 0.0f, 0.0f ) );
107 mouseActivity = true;
108 }
109 else
110 {
111 mouseActivity = m_camera.Zoom( event.GetWheelRotation() > 0 ? 1.1f : 1 / 1.1f );
112 }
113
114 // If it results on a camera movement
115 if( mouseActivity )
116 {
117 m_mouse_is_moving = true;
118 m_mouse_was_moved = true;
119 }
120
121 // Update the cursor current mouse position on the camera
122 m_camera.SetCurMousePosition( GetNativePosition( event.GetPosition() ) );
123}
A class used to derive camera objects from.
Definition: camera.h:78
bool Zoom(float aFactor)
Definition: camera.cpp:539
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:512
float GetZoom() const
Definition: camera.h:192
void SetCurMousePosition(const wxPoint &aPosition)
Update the current mouse position without make any new calculations on camera.
Definition: camera.cpp:495
static const float m_delta_move_step_factor
HIDPI_GL_3D_CANVAS(CAMERA &aCamera, wxWindow *parent, wxWindowID id=wxID_ANY, const int *attribList=nullptr, 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.
virtual wxSize GetNativePixelSize() const
wxPoint GetNativePosition(const wxPoint &aPoint) const
Convert the given point from client coordinates to native pixel coordinates.
glm::vec3 SFVEC3F
Definition: xv3d_types.h:44