Commit fcec3833 authored by Mathieu Faverge's avatar Mathieu Faverge

Avoid to refresh all the time, but do it only when necessary

parent 3a19369a
...@@ -40,25 +40,18 @@ static void drawTemporarySelection(int x, int y, int dx, int dy) ...@@ -40,25 +40,18 @@ static void drawTemporarySelection(int x, int y, int dx, int dy)
} }
MatrixGLWidget::MatrixGLWidget(QWidget* parent, symbol_matrix_t* matrix, QLabel* label) MatrixGLWidget::MatrixGLWidget(QWidget* parent, symbol_matrix_t* matrix, QLabel* label)
:
#ifdef USE_QT5 #ifdef USE_QT5
: QOpenGLWidget(parent) QOpenGLWidget(parent)
#else #else
: QGLWidget(parent) QGLWidget(parent)
#endif #endif
, m_label(label) , m_label(label)
, m_frameCount(0) , m_frameCount(0)
{ {
this->setFixedSize(MATRIX_WINDOW_LENGTH, MATRIX_WINDOW_HEIGHT); this->setFixedSize(MATRIX_WINDOW_LENGTH, MATRIX_WINDOW_HEIGHT);
m_zooming = new Zooming(matrix); m_zooming = new Zooming( matrix );
#ifdef USE_QT5
connect(&m_updateTimer, &QTimer::timeout, this, &MatrixGLWidget::updateTimer);
#else
connect(&m_updateTimer, SIGNAL(timeout()), this, SLOT(updateTimer()));
#endif
m_updateTimer.start(1000 / 60);
m_qtToGLWidthCoeff = 1.f; m_qtToGLWidthCoeff = 1.f;
m_qtToGLHeightCoeff = 1.f; m_qtToGLHeightCoeff = 1.f;
...@@ -157,13 +150,6 @@ void MatrixGLWidget::paintGL() ...@@ -157,13 +150,6 @@ void MatrixGLWidget::paintGL()
m_frameCount++; m_frameCount++;
} }
void MatrixGLWidget::updateTimer()
{
// Need to do this because the connect function cannot
// differenciate overloaded cases of update
update();
}
void MatrixGLWidget::keyPressEvent(QKeyEvent *keyEvent) void MatrixGLWidget::keyPressEvent(QKeyEvent *keyEvent)
{ {
switch (keyEvent->key()) switch (keyEvent->key())
...@@ -208,12 +194,15 @@ void MatrixGLWidget::mouseMoveEvent(QMouseEvent* mouseEvent) ...@@ -208,12 +194,15 @@ void MatrixGLWidget::mouseMoveEvent(QMouseEvent* mouseEvent)
m_tempSelectionY = m_mouseYClicked; m_tempSelectionY = m_mouseYClicked;
m_tempSelectionDx = glPosX - m_mouseXClicked; m_tempSelectionDx = glPosX - m_mouseXClicked;
m_tempSelectionDy = glPosY - m_mouseYClicked; m_tempSelectionDy = glPosY - m_mouseYClicked;
update();
} }
} }
void MatrixGLWidget::mouseReleaseEvent(QMouseEvent* mouseEvent) void MatrixGLWidget::mouseReleaseEvent(QMouseEvent* mouseEvent)
{ {
if (m_mouseXClicked != -1 && m_mouseYClicked != -1) if ( (m_mouseXClicked != -1) &&
(m_mouseYClicked != -1) )
{ {
int xmin, xmax, ymin, ymax; int xmin, xmax, ymin, ymax;
int glPosX = mouseEvent->x() * m_qtToGLWidthCoeff; int glPosX = mouseEvent->x() * m_qtToGLWidthCoeff;
...@@ -259,15 +248,17 @@ void MatrixGLWidget::mouseReleaseEvent(QMouseEvent* mouseEvent) ...@@ -259,15 +248,17 @@ void MatrixGLWidget::mouseReleaseEvent(QMouseEvent* mouseEvent)
dX = dX * m_camera.m_cameraDx; dX = dX * m_camera.m_cameraDx;
dY = dY * m_camera.m_cameraDy; dY = dY * m_camera.m_cameraDy;
m_drawTempSelection = 0;
// Return if in the upper triangular part // Return if in the upper triangular part
if ( (Y + dY) < X ) if ( (Y + dY) < X )
{ {
update();
return; return;
} }
// Position is valid, we save it // Position is valid, we save it
m_savedPositions.push(m_camera); m_savedPositions.push(m_camera);
m_drawTempSelection = 0;
m_camera.m_cameraX = X; m_camera.m_cameraX = X;
m_camera.m_cameraY = Y; m_camera.m_cameraY = Y;
...@@ -283,6 +274,7 @@ void MatrixGLWidget::mouseReleaseEvent(QMouseEvent* mouseEvent) ...@@ -283,6 +274,7 @@ void MatrixGLWidget::mouseReleaseEvent(QMouseEvent* mouseEvent)
void MatrixGLWidget::refreshCamera() void MatrixGLWidget::refreshCamera()
{ {
m_zooming->move(m_camera.m_cameraX, m_camera.m_cameraX + m_camera.m_cameraDx, m_zooming->move( m_camera.m_cameraX, m_camera.m_cameraX + m_camera.m_cameraDx,
m_camera.m_cameraY, m_camera.m_cameraY + m_camera.m_cameraDy); m_camera.m_cameraY, m_camera.m_cameraY + m_camera.m_cameraDy );
update();
} }
...@@ -52,14 +52,9 @@ private: ...@@ -52,14 +52,9 @@ private:
private: private:
void refreshCamera(); void refreshCamera();
private slots:
/* Helpers */
void updateTimer();
private: private:
uint32_t m_frameCount; uint32_t m_frameCount;
QTime m_time; QTime m_time;
QTimer m_updateTimer;
QLabel* m_label; QLabel* m_label;
char m_fpsString[256]; char m_fpsString[256];
......
...@@ -6,13 +6,13 @@ ...@@ -6,13 +6,13 @@
** use, modify and/or redistribute the software under the terms of the ** use, modify and/or redistribute the software under the terms of the
** CeCILL-A license as circulated by CEA, CNRS and INRIA at the following ** CeCILL-A license as circulated by CEA, CNRS and INRIA at the following
** URL: "http://www.cecill.info". ** URL: "http://www.cecill.info".
** **
** As a counterpart to the access to the source code and rights to copy, ** As a counterpart to the access to the source code and rights to copy,
** modify and redistribute granted by the license, users are provided ** modify and redistribute granted by the license, users are provided
** only with a limited warranty and the software's author, the holder of ** only with a limited warranty and the software's author, the holder of
** the economic rights, and the successive licensors have only limited ** the economic rights, and the successive licensors have only limited
** liability. ** liability.
** **
** In this respect, the user's attention is drawn to the risks associated ** In this respect, the user's attention is drawn to the risks associated
** with loading, using, modifying and/or developing or reproducing the ** with loading, using, modifying and/or developing or reproducing the
** software by the user in light of its specific status of free software, ** software by the user in light of its specific status of free software,
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
** their requirements in conditions enabling the security of their ** their requirements in conditions enabling the security of their
** systems and/or data to be ensured and, more generally, to use and ** systems and/or data to be ensured and, more generally, to use and
** operate it in the same conditions as regards security. ** operate it in the same conditions as regards security.
** **
** The fact that you are presently reading this means that you have had ** The fact that you are presently reading this means that you have had
** knowledge of the CeCILL-A license and that you accept its terms. ** knowledge of the CeCILL-A license and that you accept its terms.
** **
...@@ -37,7 +37,7 @@ ...@@ -37,7 +37,7 @@
** - MARCOUEILLE Jule ** - MARCOUEILLE Jule
** - NOISETTE Pascal ** - NOISETTE Pascal
** - REDONDY Arthur ** - REDONDY Arthur
** - VUCHENER Clément ** - VUCHENER Clément
** **
*/ */
/*! /*!
...@@ -45,7 +45,7 @@ ...@@ -45,7 +45,7 @@
*/ */
#ifdef _WIN32 #ifdef _WIN32
#include <Windows.h> #include <Windows.h>
#endif #endif
#include <cstdio> #include <cstdio>
...@@ -86,7 +86,7 @@ void Render_stats_opengl::initializeGL(){ ...@@ -86,7 +86,7 @@ void Render_stats_opengl::initializeGL(){
void Render_stats_opengl::resizeGL(int width, int height){ void Render_stats_opengl::resizeGL(int width, int height){
glViewport(0, 0, width, height); glViewport(0, 0, width, height);
/* update informations about widget size */ /* update informations about widget size */
_screen_width = width; _screen_width = width;
_screen_height = height; _screen_height = height;
...@@ -104,7 +104,7 @@ void Render_stats_opengl::paintGL(){ ...@@ -104,7 +104,7 @@ void Render_stats_opengl::paintGL(){
glClearDepth(1.0); glClearDepth(1.0);
glClearColor(1.f, 1.f, 1.f, 1.0f); glClearColor(1.f, 1.f, 1.f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity(); glLoadIdentity();
glMatrixMode(GL_PROJECTION); glMatrixMode(GL_PROJECTION);
...@@ -121,7 +121,7 @@ void Render_stats_opengl::paintGL(){ ...@@ -121,7 +121,7 @@ void Render_stats_opengl::paintGL(){
list<string>::const_iterator it_txt; list<string>::const_iterator it_txt;
Element_pos buf_x; Element_pos buf_x;
Element_pos buf_y; Element_pos buf_y;
string buf_txt; string buf_txt;
if (glIsList(_rect_list) == GL_FALSE) if (glIsList(_rect_list) == GL_FALSE)
printf("ERROR LIST not exist for stats\n"); printf("ERROR LIST not exist for stats\n");
...@@ -129,7 +129,7 @@ void Render_stats_opengl::paintGL(){ ...@@ -129,7 +129,7 @@ void Render_stats_opengl::paintGL(){
glCallList(_rect_list); glCallList(_rect_list);
glFlush(); glFlush();
/* Check the errors */ /* Check the errors */
GLenum glerror; GLenum glerror;
glerror = glGetError(); glerror = glGetError();
...@@ -139,11 +139,11 @@ void Render_stats_opengl::paintGL(){ ...@@ -139,11 +139,11 @@ void Render_stats_opengl::paintGL(){
const QFont &arial_font = QFont("Arial", 10); const QFont &arial_font = QFont("Arial", 10);
qglColor(QColor(0, 0, 0)); // We put the text in black qglColor(QColor(0, 0, 0)); // We put the text in black
for (it_txt=_text_value.begin(), it_pos=_text_pos.begin() ; it_txt!=_text_value.end() ; it_txt ++, it_pos ++) { for (it_txt=_text_value.begin(), it_pos=_text_pos.begin() ; it_txt!=_text_value.end() ; it_txt ++, it_pos ++) {
buf_x = *it_pos - _translated_x; buf_x = *it_pos - _translated_x;
it_pos ++; it_pos ++;
buf_y = *it_pos - _translated_y + height() - _size_for_one_container; buf_y = *it_pos - _translated_y + height() - _size_for_one_container;
buf_txt = *it_txt; buf_txt = *it_txt;
......
...@@ -6,13 +6,13 @@ ...@@ -6,13 +6,13 @@
** use, modify and/or redistribute the software under the terms of the ** use, modify and/or redistribute the software under the terms of the
** CeCILL-A license as circulated by CEA, CNRS and INRIA at the following ** CeCILL-A license as circulated by CEA, CNRS and INRIA at the following
** URL: "http://www.cecill.info". ** URL: "http://www.cecill.info".
** **
** As a counterpart to the access to the source code and rights to copy, ** As a counterpart to the access to the source code and rights to copy,
** modify and redistribute granted by the license, users are provided ** modify and redistribute granted by the license, users are provided
** only with a limited warranty and the software's author, the holder of ** only with a limited warranty and the software's author, the holder of
** the economic rights, and the successive licensors have only limited ** the economic rights, and the successive licensors have only limited
** liability. ** liability.
** **
** In this respect, the user's attention is drawn to the risks associated ** In this respect, the user's attention is drawn to the risks associated
** with loading, using, modifying and/or developing or reproducing the ** with loading, using, modifying and/or developing or reproducing the
** software by the user in light of its specific status of free software, ** software by the user in light of its specific status of free software,
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
** their requirements in conditions enabling the security of their ** their requirements in conditions enabling the security of their
** systems and/or data to be ensured and, more generally, to use and ** systems and/or data to be ensured and, more generally, to use and
** operate it in the same conditions as regards security. ** operate it in the same conditions as regards security.
** **
** The fact that you are presently reading this means that you have had ** The fact that you are presently reading this means that you have had
** knowledge of the CeCILL-A license and that you accept its terms. ** knowledge of the CeCILL-A license and that you accept its terms.
** **
...@@ -37,7 +37,7 @@ ...@@ -37,7 +37,7 @@
** - MARCOUEILLE Jule ** - MARCOUEILLE Jule
** - NOISETTE Pascal ** - NOISETTE Pascal
** - REDONDY Arthur ** - REDONDY Arthur
** - VUCHENER Clément ** - VUCHENER Clément
** **
*/ */
/*! /*!
...@@ -67,12 +67,12 @@ class Render_stats_opengl : public QGLWidget, public Render_stats { ...@@ -67,12 +67,12 @@ class Render_stats_opengl : public QGLWidget, public Render_stats {
Q_OBJECT Q_OBJECT
private: private:
/*! /*!
* \brief Contains container text coordinates. * \brief Contains container text coordinates.
*/ */
std::list<Element_pos> _text_pos; std::list<Element_pos> _text_pos;
/*! /*!
* \brief Contains container strings. * \brief Contains container strings.
*/ */
...@@ -81,7 +81,7 @@ private: ...@@ -81,7 +81,7 @@ private:
GLuint _rect_list; GLuint _rect_list;
double _translated_y; double _translated_y;
double _translated_x; double _translated_x;
bool _stats_beginned_drawed; bool _stats_beginned_drawed;
...@@ -92,7 +92,7 @@ public: ...@@ -92,7 +92,7 @@ public:
* \brief The default constructor * \brief The default constructor
*/ */
Render_stats_opengl(QWidget *parent); Render_stats_opengl(QWidget *parent);
/*! /*!
* \brief The destructor * \brief The destructor
*/ */
...@@ -102,23 +102,23 @@ public: ...@@ -102,23 +102,23 @@ public:
* \brief Call by the system to initialize the OpenGL render area. * \brief Call by the system to initialize the OpenGL render area.
*/ */
void initializeGL(); void initializeGL();
/*! /*!
* \brief Call by the system when the render area was resized (occurs during a window resizement). * \brief Call by the system when the render area was resized (occurs during a window resizement).
* \param width : the new width of the render area. * \param width : the new width of the render area.
* \param height : the new height of the render area. * \param height : the new height of the render area.
*/ */
void resizeGL(int width, int height); void resizeGL(int width, int height);
/*! /*!
* \brief Call by the system each time the render area need to be updated. * \brief Call by the system each time the render area need to be updated.
*/ */
void paintGL(); void paintGL();
/*! /*!
* \brief Proceeds with the initialization of draw functions. * \brief Proceeds with the initialization of draw functions.
*/ */
void start_draw(); void start_draw();
/*! /*!
...@@ -183,7 +183,7 @@ public: ...@@ -183,7 +183,7 @@ public:
* \brief Proceeds with the end of draw functions. * \brief Proceeds with the end of draw functions.
*/ */
void end_draw(); void end_draw();
/*! /*!
* \fn translate_y(int value) * \fn translate_y(int value)
* \brief Translate the window on the vertical axis. * \brief Translate the window on the vertical axis.
...@@ -238,7 +238,7 @@ inline void Render_stats_opengl::start_draw(){ ...@@ -238,7 +238,7 @@ inline void Render_stats_opengl::start_draw(){
inline void Render_stats_opengl::draw_text(const Element_pos x, const Element_pos y, const std::string value) { inline void Render_stats_opengl::draw_text(const Element_pos x, const Element_pos y, const std::string value) {
_text_pos.push_back(x); _text_pos.push_back(x);
_text_pos.push_back(y); _text_pos.push_back(y);
_text_value.push_back(value); _text_value.push_back(value);
} }
......
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