Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
bbguimaraes
college
Commits
50717384
Commit
50717384
authored
Jul 16, 2016
by
bbguimaraes
Browse files
sms: rate-limit selections from mouse move events
parent
c9e204a2
Changes
2
Hide whitespace changes
Inline
Side-by-side
sms/sms/include/display.h
View file @
50717384
...
...
@@ -21,6 +21,7 @@ class Display : public QGLWidget {
const
unsigned
int
GRID_SIZE
=
100
;
const
float
AXES_HEIGHT
=
5.0
f
;
const
unsigned
int
AXES_SLICES
=
32
;
const
float
SELECT_RATE_LIMIT
=
1000.0
f
/
5.0
f
;
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
;
...
...
sms/sms/src/display.cpp
View file @
50717384
...
...
@@ -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
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment