-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor: moved basic gui-handling in Camera_manip_rot into Camera_manip
- Loading branch information
1 parent
e7db9ce
commit b800d9a
Showing
7 changed files
with
107 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
|
||
#include "Camera_manip.h" | ||
|
||
|
||
Camera_manip::Camera_manip(Camera& camera) : | ||
m_camera(camera) | ||
{ | ||
} | ||
|
||
|
||
void Camera_manip::set_mouse_button_pressed_flag(QMouseEvent* e, bool flag) | ||
{ | ||
switch (e->button()) | ||
{ | ||
case Qt::LeftButton: | ||
m_left_mouse_button_down = flag; | ||
break; | ||
|
||
case Qt::MiddleButton: | ||
m_middle_mouse_button_down = flag; | ||
break; | ||
} | ||
} | ||
void Camera_manip::mousePressEvent(QMouseEvent* e) | ||
{ | ||
set_mouse_button_pressed_flag(e, true); | ||
m_mouse_press_pos = m_last_mouse_pos = QVector2D(e->position()); | ||
|
||
// call the function overridden by the derived class | ||
mouse_press_event(e); | ||
} | ||
void Camera_manip::mouseMoveEvent(QMouseEvent* e) | ||
{ | ||
auto current_mouse_pos = QVector2D(e->position()); | ||
const auto diff = current_mouse_pos - m_last_mouse_pos; | ||
|
||
// call the function overridden by the derived class | ||
mouse_move_event(e); | ||
|
||
m_last_mouse_pos = current_mouse_pos; | ||
} | ||
void Camera_manip::mouseReleaseEvent(QMouseEvent* e) | ||
{ | ||
set_mouse_button_pressed_flag(e, false); | ||
|
||
// call the function overridden by the derived class | ||
mouse_release_event(e); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
|
||
#ifndef CAMERA_MANIP_H | ||
#define CAMERA_MANIP_H | ||
|
||
#include <qevent.h> | ||
#include <qvector2d.h> | ||
|
||
#include "Camera.h" | ||
|
||
|
||
class Camera_manip | ||
{ | ||
public: | ||
Camera_manip(Camera& camera); | ||
virtual ~Camera_manip() {}; | ||
|
||
void mousePressEvent(QMouseEvent* e); | ||
void mouseMoveEvent(QMouseEvent* e); | ||
void mouseReleaseEvent(QMouseEvent* e); | ||
|
||
protected: | ||
void set_mouse_button_pressed_flag(QMouseEvent* e, bool flag); | ||
|
||
virtual void mouse_press_event(QMouseEvent* e) = 0; | ||
virtual void mouse_move_event(QMouseEvent* e) = 0; | ||
virtual void mouse_release_event(QMouseEvent* e) = 0; | ||
|
||
Camera& m_camera; | ||
float m_theta = 0, m_phi = 0; | ||
|
||
bool m_left_mouse_button_down = false; | ||
bool m_middle_mouse_button_down = false; | ||
//QVector2D m_current_mouse_pos; | ||
QVector2D m_last_mouse_pos; | ||
QVector2D m_mouse_press_pos; | ||
}; | ||
|
||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters