mirror of https://github.com/CGAL/cgal
small code refactor
This commit is contained in:
parent
2ee383241c
commit
1c98dba72a
|
|
@ -1,5 +1,3 @@
|
||||||
// Copyright (C) 2016 The Qt Company Ltd.
|
|
||||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
|
|
||||||
|
|
||||||
#include "mainwidget.h"
|
#include "mainwidget.h"
|
||||||
|
|
||||||
|
|
@ -17,18 +15,23 @@ MainWidget::~MainWidget()
|
||||||
doneCurrent();
|
doneCurrent();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWidget::mousePressEvent(QMouseEvent *e)
|
|
||||||
|
void MainWidget::set_mouse_button_pressed_flag(QMouseEvent* e, bool flag)
|
||||||
{
|
{
|
||||||
switch (e->button())
|
switch (e->button())
|
||||||
{
|
{
|
||||||
case Qt::LeftButton:
|
case Qt::LeftButton:
|
||||||
m_left_mouse_button_down = true;
|
m_left_mouse_button_down = flag;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Qt::MiddleButton:
|
case Qt::MiddleButton:
|
||||||
m_middle_mouse_button_down = true;
|
m_middle_mouse_button_down = flag;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
void MainWidget::mousePressEvent(QMouseEvent *e)
|
||||||
|
{
|
||||||
|
set_mouse_button_pressed_flag(e, true);
|
||||||
m_last_mouse_pos = QVector2D(e->position());
|
m_last_mouse_pos = QVector2D(e->position());
|
||||||
}
|
}
|
||||||
void MainWidget::mouseMoveEvent(QMouseEvent* e)
|
void MainWidget::mouseMoveEvent(QMouseEvent* e)
|
||||||
|
|
@ -41,10 +44,9 @@ void MainWidget::mouseMoveEvent(QMouseEvent* e)
|
||||||
const float rotation_scale_factor = 0.1f;
|
const float rotation_scale_factor = 0.1f;
|
||||||
const float theta_around_x = rotation_scale_factor * diff.y();
|
const float theta_around_x = rotation_scale_factor * diff.y();
|
||||||
const float theta_around_y = rotation_scale_factor * diff.x();
|
const float theta_around_y = rotation_scale_factor * diff.x();
|
||||||
|
|
||||||
m_camera.rotate(theta_around_x, theta_around_y);
|
m_camera.rotate(theta_around_x, theta_around_y);
|
||||||
}
|
}
|
||||||
else
|
else if(m_middle_mouse_button_down)
|
||||||
{
|
{
|
||||||
const float zoom_scale_factor = 0.01f;
|
const float zoom_scale_factor = 0.01f;
|
||||||
const auto distance = zoom_scale_factor * diff.y();
|
const auto distance = zoom_scale_factor * diff.y();
|
||||||
|
|
@ -53,23 +55,9 @@ void MainWidget::mouseMoveEvent(QMouseEvent* e)
|
||||||
|
|
||||||
m_last_mouse_pos = current_mouse_pos;
|
m_last_mouse_pos = current_mouse_pos;
|
||||||
}
|
}
|
||||||
void MainWidget::wheelEvent(QWheelEvent* e)
|
|
||||||
{
|
|
||||||
auto distance = e->angleDelta();
|
|
||||||
m_camera.move_forward(distance.x());
|
|
||||||
}
|
|
||||||
void MainWidget::mouseReleaseEvent(QMouseEvent *e)
|
void MainWidget::mouseReleaseEvent(QMouseEvent *e)
|
||||||
{
|
{
|
||||||
switch (e->button())
|
set_mouse_button_pressed_flag(e, false);
|
||||||
{
|
|
||||||
case Qt::LeftButton:
|
|
||||||
m_left_mouse_button_down = false;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case Qt::MiddleButton:
|
|
||||||
m_middle_mouse_button_down = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
void MainWidget::timerEvent(QTimerEvent *)
|
void MainWidget::timerEvent(QTimerEvent *)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -22,31 +22,32 @@
|
||||||
|
|
||||||
class MainWidget : public QOpenGLWidget, protected OpenGLFunctionsBase
|
class MainWidget : public QOpenGLWidget, protected OpenGLFunctionsBase
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
using QOpenGLWidget::QOpenGLWidget;
|
using QOpenGLWidget::QOpenGLWidget;
|
||||||
~MainWidget();
|
~MainWidget();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void mousePressEvent(QMouseEvent *e) override;
|
void set_mouse_button_pressed_flag(QMouseEvent* e, bool flag);
|
||||||
void mouseMoveEvent(QMouseEvent* e) override;
|
void mousePressEvent(QMouseEvent *e) override;
|
||||||
void wheelEvent(QWheelEvent* event) override;
|
void mouseMoveEvent(QMouseEvent* e) override;
|
||||||
void mouseReleaseEvent(QMouseEvent *e) override;
|
void mouseReleaseEvent(QMouseEvent *e) override;
|
||||||
void timerEvent(QTimerEvent *e) override;
|
void timerEvent(QTimerEvent *e) override;
|
||||||
|
|
||||||
void initializeGL() override;
|
|
||||||
void resizeGL(int w, int h) override;
|
|
||||||
void paintGL() override;
|
|
||||||
|
|
||||||
|
|
||||||
void add_shader(GLuint the_program,
|
void initializeGL() override;
|
||||||
const char* shader_code,
|
void resizeGL(int w, int h) override;
|
||||||
GLenum shader_type);
|
void paintGL() override;
|
||||||
|
|
||||||
|
|
||||||
|
void add_shader(GLuint the_program,
|
||||||
|
const char* shader_code,
|
||||||
|
GLenum shader_type);
|
||||||
|
|
||||||
void init_camera();
|
void init_camera();
|
||||||
void init_geometry();
|
void init_geometry();
|
||||||
void init_shader_program();
|
void init_shader_program();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::unique_ptr<Sphere> m_sphere;
|
std::unique_ptr<Sphere> m_sphere;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue