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