Commit 50717384 authored by bbguimaraes's avatar bbguimaraes
Browse files

sms: rate-limit selections from mouse move events

parent c9e204a2
......@@ -21,6 +21,7 @@ class Display : public QGLWidget {
const unsigned int GRID_SIZE = 100;
const float AXES_HEIGHT = 5.0f;
const unsigned int AXES_SLICES = 32;
const float SELECT_RATE_LIMIT = 1000.0f / 5.0f;
public:
Display(QWidget * parent = nullptr);
......@@ -52,7 +53,7 @@ class Display : public QGLWidget {
virtual void wheelEvent(QWheelEvent * event);
private:
void select(Vector click);
void select(Vector click, bool rate_limit);
void draw_simulation(Simulation * s);
void update_fps();
......@@ -62,6 +63,7 @@ class Display : public QGLWidget {
GLuint m_texture;
GLUquadric * m_quadric;
QTime m_last_select;
QTime m_last_frame;
unsigned int m_frame_count;
unsigned int m_fps;
......
......@@ -12,6 +12,7 @@ Display::Display(QWidget * parent) :
m_selected(nullptr),
m_texture(0),
m_quadric(nullptr),
m_last_select(QTime::currentTime()),
m_last_frame(QTime::currentTime()),
m_ctrl_key_down(false),
m_draw_grid(false),
......@@ -61,7 +62,10 @@ void Display::paintGL() {
Rendering::draw_hud(this->m_fps);
}
void Display::select(Vector click) {
void Display::select(Vector click, bool rate_limit) {
if(rate_limit && this->m_last_select.elapsed() < this->SELECT_RATE_LIMIT)
return;
this->m_last_select = QTime::currentTime();
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
GLint viewport[4];
glGetIntegerv(GL_VIEWPORT, viewport);
......@@ -176,7 +180,7 @@ void Display::keyReleaseEvent(QKeyEvent * event) {
void Display::mousePressEvent(QMouseEvent * event) {
this->m_click_position = Vector(event->x(), event->y());
if(event->button() == Qt::LeftButton)
this->select(this->m_click_position);
this->select(this->m_click_position, false);
}
void Display::mouseReleaseEvent(QMouseEvent * event) {
......@@ -198,7 +202,7 @@ void Display::mouseMoveEvent(QMouseEvent * event) {
}
} else {
if(!(event->buttons() & Qt::LeftButton))
this->select(position);
this->select(position, true);
else if(this->m_selected) {
auto move = (this->m_click_position - position)
/ this->m_camera.distance();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment