-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathglwidgetcustom.h
97 lines (75 loc) · 2.27 KB
/
glwidgetcustom.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#ifndef GLWIDGETCUSTOM_H
#define GLWIDGETCUSTOM_H
#include <QOpenGLWidget>
#include <QOpenGLFunctions>
#include <QOpenGLShaderProgram>
#include <QOpenGLBuffer>
#include <QOpenGLVertexArrayObject>
#include <QVector>
#include <QMatrix4x4> // Required for matrices
#include "vizdata.h"
class GLWidgetCustom : public QOpenGLWidget, protected QOpenGLFunctions
{
Q_OBJECT
public:
public:
GLWidgetCustom(QWidget *parent = nullptr);
~GLWidgetCustom();
protected:
void initializeGL() override;
void resizeGL(int w, int h) override;
void paintGL() override;
// Mouse interaction handlers
void mousePressEvent(QMouseEvent *event) override;
void mouseMoveEvent(QMouseEvent *event) override;
void mouseReleaseEvent(QMouseEvent *event) override;
void wheelEvent(QWheelEvent *event) override;
// void paintEvent(QPaintEvent *event) override;
private:
void setupShaders();
void checkOpenGLError(const QString &functionName);
void setRasterColor(const QVector3D &color);
void renderTextAboveSquare(QPainter &painter, int col, int row, float x, float y);
QOpenGLShaderProgram *shaderProgram;
QOpenGLBuffer vbo;
QOpenGLBuffer instanceVBO;
QOpenGLVertexArrayObject vao;
QOpenGLBuffer instanceColorVBO;
QVector<float> vertices;
QVector<float> instanceOffsets;
QVector<QVector3D> instanceColors;
int instanceCount;
// Matrices for transformations
QMatrix4x4 projection;
QMatrix4x4 view;
QMatrix4x4 model;
// For panning and zooming
QPoint lastMousePosition;
std::tuple<float,float,float> lastView;
std::tuple<float,float,float> lastProjection;
float panX;
float panY;
float aspectRatio;
bool panning;
float prevXForPan;
float prevYForPan;
float distance;
public:
VizData *vizData;
float pixelScale;
float initPixelScaleX;
float initPixelScaleY;
float pixelScaleX;
float pixelScaleY;
bool inspectMode;
public:
void updateInstanceData();
void updateInstanceDataAll();
void updateInstanceDataMedian(QString colName, int month);
void setupVertexBuffers();
Q_INVOKABLE void updateVertexData();
Q_INVOKABLE void updateVertexBuffers();
signals:
void mouseMoved(const QPoint &pos);
};
#endif // GLWIDGETCUSTOM_H