Debian Codegraph @

src/Gui/GLPainter.h

raw
1 /***************************************************************************
2 * Copyright (c) 2013 Werner Mayer <wmayer[at]users.sourceforge.net> *
3 * *
4 * This file is part of the FreeCAD CAx development system. *
5 * *
6 * This library is free software; you can redistribute it and/or *
7 * modify it under the terms of the GNU Library General Public *
8 * License as published by the Free Software Foundation; either *
9 * version 2 of the License, or (at your option) any later version. *
10 * *
11 * This library is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU Library General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU Library General Public *
17 * License along with this library; see the file COPYING.LIB. If not, *
18 * write to the Free Software Foundation, Inc., 59 Temple Place, *
19 * Suite 330, Boston, MA 02111-1307, USA *
20 * *
21 ***************************************************************************/
22
23
24 #ifndef GUI_GLPAINTER_H
25 #define GUI_GLPAINTER_H
26
27 #include <FCConfig.h>
28
29 #ifdef FC_OS_WIN32
30 # include <windows.h>
31 #endif
32 #ifdef FC_OS_MACOSX
33 # include <OpenGL/gl.h>
34 #else
35 # include <GL/gl.h>
36 #endif
37
38 #include <Base/BaseClass.h>
39 #include <FCGlobal.h>
40 #include <QPoint>
41
42 class QPaintDevice;
43 class QOpenGLWidget;
44
45 namespace Gui
46 {
47 class View3DInventorViewer;
48 class GuiExport GLPainter
49 {
50 public:
51 GLPainter();
52 virtual ~GLPainter();
53
54 bool begin(QPaintDevice* device);
55 bool end();
56 bool isActive() const;
57
58 /** @name Setter methods */
59 //@{
60 void setLineWidth(float);
61 void setPointSize(float);
62 void setColor(float, float, float, float = 0);
63 void setLogicOp(GLenum);
64 void resetLogicOp();
65 void setDrawBuffer(GLenum);
66 void setLineStipple(GLint factor, GLushort pattern);
67 void resetLineStipple();
68 //@}
69
70 /** @name Draw routines */
71 //@{
72 void drawRect(int x, int y, int w, int h);
73 void drawLine(int x1, int y1, int x2, int y2);
74 void drawPoint(int x, int y);
75 //@}
76
77 private:
78 GLfloat depthrange[2];
79 GLdouble projectionmatrix[16];
80 GLint width {0}, height {0};
81 QOpenGLWidget* viewer {nullptr};
82 bool logicOp {false};
83 bool lineStipple {false};
84 };
85
86 class GuiExport GLGraphicsItem: public Base::BaseClass
87 {
88 TYPESYSTEM_HEADER_WITH_OVERRIDE();
89
90 public:
91 GLGraphicsItem() = default;
92 ~GLGraphicsItem() override = default;
93 virtual void paintGL() = 0;
94 };
95
96 class GuiExport Rubberband: public Gui::GLGraphicsItem
97 {
98 View3DInventorViewer* viewer;
99 int x_old, y_old, x_new, y_new;
100 float rgb_r, rgb_g, rgb_b, rgb_a;
101 bool working, stipple;
102
103 public:
104 explicit Rubberband(View3DInventorViewer* v);
105 Rubberband();
106 ~Rubberband() override;
107 void setWorking(bool on);
108 void setLineStipple(bool on);
109 bool isWorking();
110 void setViewer(View3DInventorViewer* v);
111 void setCoords(int x1, int y1, int x2, int y2);
112 void setColor(float r, float g, float b, float a);
113 void paintGL() override;
114 };
115
116 class GuiExport Polyline: public Gui::GLGraphicsItem
117 {
118 View3DInventorViewer* viewer;
119 std::vector<QPoint> _cNodeVector;
120 int x_new, y_new;
121 float rgb_r, rgb_g, rgb_b, rgb_a, line;
122 bool working, closed, stippled;
123 GLPainter p;
124
125 public:
126 explicit Polyline(View3DInventorViewer* v);
127 Polyline();
128 ~Polyline() override;
129 void setWorking(bool on);
130 bool isWorking() const;
131 void setViewer(View3DInventorViewer* v);
132 void setCoords(int x, int y);
133 void setColor(int r, int g, int b, int a = 0);
134 void setLineWidth(float l);
135 void setClosed(bool c);
136 void setCloseStippled(bool c);
137 void addNode(const QPoint& p);
138 void popNode();
139 void clear();
140 void paintGL() override;
141 };
142
143 } // namespace Gui
144
145 #endif // GUI_GLPAINTER_H