-
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: added gui_event_handler base class & derived Camera_manip f…
…rom this
- Loading branch information
1 parent
f8d58de
commit f785ef7
Showing
6 changed files
with
146 additions
and
73 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
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,55 @@ | ||
// Copyright(c) 2012, 2020 Tel - Aviv University(Israel). | ||
// All rights reserved. | ||
// | ||
// This file is part of CGAL (www.cgal.org). | ||
// | ||
// SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial | ||
// | ||
// Author(s): Engin Deniz Diktas <[email protected]> | ||
|
||
#include "GUI_event_handler.h" | ||
|
||
|
||
void GUI_event_handler::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 GUI_event_handler::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 GUI_event_handler::mouseMoveEvent(QMouseEvent* e) | ||
{ | ||
m_current_mouse_pos = QVector2D(e->position()); | ||
m_diff = m_current_mouse_pos - m_last_mouse_pos; | ||
|
||
// call the function overridden by the derived class | ||
mouse_move_event(e); | ||
|
||
m_last_mouse_pos = m_current_mouse_pos; | ||
} | ||
void GUI_event_handler::mouseReleaseEvent(QMouseEvent* e) | ||
{ | ||
set_mouse_button_pressed_flag(e, false); | ||
|
||
// call the function overridden by the derived class | ||
mouse_release_event(e); | ||
} | ||
void GUI_event_handler::resizeGL(int w, int h) | ||
{ | ||
resize(w, h); | ||
} | ||
|
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,45 @@ | ||
// Copyright(c) 2012, 2020 Tel - Aviv University(Israel). | ||
// All rights reserved. | ||
// | ||
// This file is part of CGAL (www.cgal.org). | ||
// | ||
// SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial | ||
// | ||
// Author(s): Engin Deniz Diktas <[email protected]> | ||
|
||
#ifndef GUI_EVENT_HANDLER_H | ||
#define GUI_EVENT_HANDLER_H | ||
|
||
#include <qevent.h> | ||
#include <qvector2d.h> | ||
|
||
|
||
class GUI_event_handler | ||
{ | ||
public: | ||
virtual ~GUI_event_handler() {}; | ||
|
||
void mousePressEvent(QMouseEvent* e); | ||
void mouseMoveEvent(QMouseEvent* e); | ||
void mouseReleaseEvent(QMouseEvent* e); | ||
void resizeGL(int w, int h); | ||
|
||
protected: | ||
void set_mouse_button_pressed_flag(QMouseEvent* e, bool flag); | ||
|
||
virtual void mouse_press_event(QMouseEvent* e) {} | ||
virtual void mouse_move_event(QMouseEvent* e) {} | ||
virtual void mouse_release_event(QMouseEvent* e) {} | ||
virtual void resize(int w, int h) {} | ||
|
||
|
||
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; | ||
QVector2D m_diff; | ||
}; | ||
|
||
|
||
#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