KiCad PCB EDA Suite
HIDPI_GL_3D_CANVAS Class Reference

Provides basic 3D controls ( zoom, rotate, translate, ... ) More...

#include <hidpi_gl_3D_canvas.h>

Inheritance diagram for HIDPI_GL_3D_CANVAS:
HIDPI_GL_CANVAS EDA_3D_CANVAS

Public Member Functions

 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)
 
CAMERAGetCamera ()
 Get the canvas camera. More...
 
void OnMouseMoveCamera (wxMouseEvent &event)
 
void OnMouseWheelCamera (wxMouseEvent &event, bool aPan)
 
virtual wxSize GetNativePixelSize () const
 
wxPoint GetNativePosition (const wxPoint &aPoint) const
 Convert the given point from client coordinates to native pixel coordinates. More...
 
void SetScaleFactor (double aFactor)
 Set the canvas scale factor, probably for a hi-DPI display. More...
 
double GetScaleFactor () const
 Get the current scale factor. More...
 

Public Attributes

bool m_mouse_is_moving
 
bool m_mouse_was_moved
 
bool m_camera_is_moving
 
CAMERAm_camera
 

Static Public Attributes

static const float m_delta_move_step_factor = 0.7f
 

Private Attributes

double m_scale_factor
 The current scale factor (e.g. More...
 

Detailed Description

Provides basic 3D controls ( zoom, rotate, translate, ... )

Definition at line 44 of file hidpi_gl_3D_canvas.h.

Constructor & Destructor Documentation

◆ HIDPI_GL_3D_CANVAS()

HIDPI_GL_3D_CANVAS::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 
)

Definition at line 30 of file hidpi_gl_3D_canvas.cpp.

33 :
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}
HIDPI_GL_CANVAS(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)

Member Function Documentation

◆ GetCamera()

CAMERA * HIDPI_GL_3D_CANVAS::GetCamera ( )
inline

Get the canvas camera.

Definition at line 66 of file hidpi_gl_3D_canvas.h.

66{ return &m_camera; }

References m_camera.

Referenced by NL_3D_VIEWER_PLUGIN_IMPL::NL_3D_VIEWER_PLUGIN_IMPL().

◆ GetNativePixelSize()

wxSize HIDPI_GL_CANVAS::GetNativePixelSize ( ) const
virtualinherited

Definition at line 41 of file hidpi_gl_canvas.cpp.

42{
43 wxSize size = wxGLCanvas::GetClientSize();
44
45 const double scaleFactor = GetScaleFactor();
46 size.x *= scaleFactor;
47 size.y *= scaleFactor;
48
49 return size;
50}
double GetScaleFactor() const
Get the current scale factor.

References HIDPI_GL_CANVAS::GetScaleFactor().

Referenced by EDA_3D_CANVAS::DoRePaint(), EDA_3D_MODEL_VIEWER::OnMouseMove(), OnMouseMoveCamera(), EDA_3D_MODEL_VIEWER::OnPaint(), and KIGFX::OPENGL_GAL::OPENGL_GAL().

◆ GetNativePosition()

wxPoint HIDPI_GL_CANVAS::GetNativePosition ( const wxPoint &  aPoint) const
inherited

Convert the given point from client coordinates to native pixel coordinates.

Definition at line 53 of file hidpi_gl_canvas.cpp.

54{
55 wxPoint nativePoint = aPoint;
56
57 const double scaleFactor = GetScaleFactor();
58 nativePoint.x *= scaleFactor;
59 nativePoint.y *= scaleFactor;
60
61 return nativePoint;
62}

References HIDPI_GL_CANVAS::GetScaleFactor().

Referenced by EDA_3D_MODEL_VIEWER::OnMouseMove(), OnMouseMoveCamera(), and OnMouseWheelCamera().

◆ GetScaleFactor()

◆ OnMouseMoveCamera()

void HIDPI_GL_3D_CANVAS::OnMouseMoveCamera ( wxMouseEvent &  event)

Definition at line 43 of file hidpi_gl_3D_canvas.cpp.

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}
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
void SetCurMousePosition(const wxPoint &aPosition)
Update the current mouse position without make any new calculations on camera.
Definition: camera.cpp:495
virtual wxSize GetNativePixelSize() const
wxPoint GetNativePosition(const wxPoint &aPoint) const
Convert the given point from client coordinates to native pixel coordinates.

References CAMERA::Drag(), HIDPI_GL_CANVAS::GetNativePixelSize(), HIDPI_GL_CANVAS::GetNativePosition(), m_camera, m_camera_is_moving, m_mouse_is_moving, m_mouse_was_moved, CAMERA::Pan(), CAMERA::SetCurMousePosition(), and CAMERA::SetCurWindowSize().

Referenced by EDA_3D_CANVAS::OnMouseMove().

◆ OnMouseWheelCamera()

void HIDPI_GL_3D_CANVAS::OnMouseWheelCamera ( wxMouseEvent &  event,
bool  aPan 
)

Definition at line 67 of file hidpi_gl_3D_canvas.cpp.

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}
bool Zoom(float aFactor)
Definition: camera.cpp:539
float GetZoom() const
Definition: camera.h:192
static const float m_delta_move_step_factor
glm::vec3 SFVEC3F
Definition: xv3d_types.h:44

References HIDPI_GL_CANVAS::GetNativePosition(), CAMERA::GetZoom(), m_camera, m_camera_is_moving, m_delta_move_step_factor, m_mouse_is_moving, m_mouse_was_moved, CAMERA::Pan(), CAMERA::SetCurMousePosition(), and CAMERA::Zoom().

Referenced by EDA_3D_CANVAS::OnMouseWheel().

◆ SetScaleFactor()

void HIDPI_GL_CANVAS::SetScaleFactor ( double  aFactor)
inherited

Set the canvas scale factor, probably for a hi-DPI display.

Definition at line 65 of file hidpi_gl_canvas.cpp.

66{
67 m_scale_factor = aNewScaleFactor;
68}

References HIDPI_GL_CANVAS::m_scale_factor.

Referenced by EDA_3D_MODEL_VIEWER::EDA_3D_MODEL_VIEWER(), EDA_3D_VIEWER_FRAME::loadCommonSettings(), PANEL_PREVIEW_3D_MODEL::loadSettings(), and KIGFX::OPENGL_GAL::updatedGalDisplayOptions().

Member Data Documentation

◆ m_camera

◆ m_camera_is_moving

◆ m_delta_move_step_factor

const float HIDPI_GL_3D_CANVAS::m_delta_move_step_factor = 0.7f
static

Definition at line 60 of file hidpi_gl_3D_canvas.h.

Referenced by OnMouseWheelCamera(), and EDA_3D_CANVAS::SetView3D().

◆ m_mouse_is_moving

◆ m_mouse_was_moved

◆ m_scale_factor

double HIDPI_GL_CANVAS::m_scale_factor
privateinherited

The current scale factor (e.g.

for hi-DPI displays)

Definition at line 68 of file hidpi_gl_canvas.h.

Referenced by HIDPI_GL_CANVAS::GetScaleFactor(), and HIDPI_GL_CANVAS::SetScaleFactor().


The documentation for this class was generated from the following files: