]> git.sur5r.net Git - fstl/blob - src/canvas.h
New upstream version 0.9.3
[fstl] / src / canvas.h
1 #ifndef CANVAS_H
2 #define CANVAS_H
3
4 #include <QWidget>
5 #include <QPropertyAnimation>
6 #include <QtOpenGL/QGLWidget>
7 #include <QtOpenGL/QGLFunctions>
8 #include <QtOpenGL/QGLShaderProgram>
9 #include <QMatrix4x4>
10
11 class GLMesh;
12 class Mesh;
13 class Backdrop;
14
15 class Canvas : public QGLWidget, protected QGLFunctions
16 {
17     Q_OBJECT
18
19 public:
20     Canvas(const QGLFormat& format, QWidget* parent=0);
21
22     void initializeGL();
23     void paintEvent(QPaintEvent* event);
24     ~Canvas();
25
26     void view_orthographic();
27     void view_perspective();
28
29 public slots:
30     void set_status(const QString& s);
31     void clear_status();
32     void load_mesh(Mesh* m, bool is_reload);
33
34
35 protected:
36     void mousePressEvent(QMouseEvent* event);
37     void mouseReleaseEvent(QMouseEvent* event);
38     void mouseMoveEvent(QMouseEvent* event);
39     void wheelEvent(QWheelEvent* event);
40     void resizeGL(int width, int height);
41     void set_perspective(float p);
42     void view_anim(float v);
43
44
45 private:
46     void draw_mesh();
47
48     QMatrix4x4 transform_matrix() const;
49     QMatrix4x4 view_matrix() const;
50
51     QGLShaderProgram mesh_shader;
52     QGLShaderProgram quad_shader;
53
54     GLMesh* mesh;
55     Backdrop* backdrop;
56
57     QVector3D center;
58     float scale;
59     float zoom;
60     float tilt;
61     float yaw;
62
63     float perspective;
64     Q_PROPERTY(float perspective WRITE set_perspective);
65     QPropertyAnimation anim;
66
67     QPoint mouse_pos;
68     QString status;
69 };
70
71 #endif // CANVAS_H