GNU Octave  4.0.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
GLCanvas.cc
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 2011-2015 Michael Goffioul
4 
5 This file is part of Octave.
6 
7 Octave is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by the
9 Free Software Foundation; either version 3 of the License, or (at your
10 option) any later version.
11 
12 Octave is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
16 
17 You should have received a copy of the GNU General Public License
18 along with Octave; see the file COPYING. If not, see
19 <http://www.gnu.org/licenses/>.
20 
21 */
22 
23 #ifdef HAVE_CONFIG_H
24 #include <config.h>
25 #endif
26 
27 #ifdef HAVE_CONFIG_H
28 #include <config.h>
29 #endif
30 
31 #include "gl-render.h"
32 #include "graphics.h"
33 
34 #include "GLCanvas.h"
35 #include "gl-select.h"
36 
37 namespace QtHandles
38 {
39 
41 #if defined (Q_OS_WIN32)
42  : QGLWidget (QGLFormat (QGL::SampleBuffers | QGL::IndirectRendering),
43  xparent), Canvas (gh)
44 #else
45  : QGLWidget (QGLFormat (QGL::SampleBuffers), xparent), Canvas (gh)
46 #endif
47 {
48  setFocusPolicy (Qt::ClickFocus);
49 }
50 
52 {
53 }
54 
55 void
57 {
60 
61  if (go)
62  {
64 
65  r.set_viewport (width (), height ());
66  r.draw(go);
67  }
68 }
69 
70 void
72 {
73  canvasToggleAxes (gh);
74 }
75 
76 void
78 {
79  canvasToggleGrid (gh);
80 }
81 
82 void
84 {
85  canvasAutoAxes (gh);
86 }
87 
89 GLCanvas::selectFromAxes (const graphics_object& ax, const QPoint& pt)
90 {
91  makeCurrent ();
92 
93  if (ax)
94  {
96 
97  s.set_viewport (width (), height ());
98  return s.select (ax, pt.x (), height () - pt.y ());
99  }
100 
101  return graphics_object ();
102 }
103 
104 inline void
105 glDrawZoomBox (const QPoint& p1, const QPoint& p2)
106 {
107  glVertex2d (p1.x (), p1.y ());
108  glVertex2d (p2.x (), p1.y ());
109  glVertex2d (p2.x (), p2.y ());
110  glVertex2d (p1.x (), p2.y ());
111  glVertex2d (p1.x (), p1.y ());
112 }
113 
114 void
115 GLCanvas::drawZoomBox (const QPoint& p1, const QPoint& p2)
116 {
117  glPushMatrix ();
118 
119  glMatrixMode (GL_MODELVIEW);
120  glLoadIdentity ();
121 
122  glMatrixMode (GL_PROJECTION);
123  glLoadIdentity ();
124  glOrtho (0, width (), height (), 0, 1, -1);
125 
126  glPushAttrib (GL_DEPTH_BUFFER_BIT | GL_CURRENT_BIT);
127  glDisable (GL_DEPTH_TEST);
128 
129  glBegin (GL_POLYGON);
130  glColor4f (0.45, 0.62, 0.81, 0.1);
131  glDrawZoomBox (p1, p2);
132  glEnd ();
133 
134  glBegin (GL_LINE_STRIP);
135  glLineWidth (1.5);
136  glColor4f (0.45, 0.62, 0.81, 0.9);
137  glDrawZoomBox (p1, p2);
138  glEnd ();
139 
140  glPopAttrib ();
141  glPopMatrix ();
142 }
143 
144 void
146 {
147  canvasPaintEvent ();
148 }
149 
150 void
151 GLCanvas::mouseDoubleClickEvent (QMouseEvent* xevent)
152 {
154 }
155 
156 void
157 GLCanvas::mouseMoveEvent (QMouseEvent* xevent)
158 {
159  canvasMouseMoveEvent (xevent);
160 }
161 
162 void
163 GLCanvas::mousePressEvent (QMouseEvent* xevent)
164 {
165  canvasMousePressEvent (xevent);
166 }
167 
168 void
169 GLCanvas::mouseReleaseEvent (QMouseEvent* xevent)
170 {
171  canvasMouseReleaseEvent (xevent);
172 }
173 
174 void
175 GLCanvas::wheelEvent (QWheelEvent* xevent)
176 {
177  canvasWheelEvent (xevent);
178 }
179 
180 void
181 GLCanvas::keyPressEvent (QKeyEvent* xevent)
182 {
183  if (! canvasKeyPressEvent (xevent))
184  QGLWidget::keyPressEvent (xevent);
185 }
186 
187 void
188 GLCanvas::keyReleaseEvent (QKeyEvent* xevent)
189 {
190  if (! canvasKeyReleaseEvent (xevent))
191  QGLWidget::keyReleaseEvent (xevent);
192 }
193 
194 }; // namespace QtHandles
void autoAxes(const graphics_handle &handle)
Definition: GLCanvas.cc:83
void mouseDoubleClickEvent(QMouseEvent *event)
Definition: GLCanvas.cc:151
graphics_object selectFromAxes(const graphics_object &ax, const QPoint &pt)
Definition: GLCanvas.cc:89
GLCanvas(QWidget *parent, const graphics_handle &handle)
Definition: GLCanvas.cc:40
void wheelEvent(QWheelEvent *event)
Definition: GLCanvas.cc:175
void mouseMoveEvent(QMouseEvent *event)
Definition: GLCanvas.cc:157
void canvasToggleGrid(const graphics_handle &handle)
Definition: Canvas.cc:238
void canvasMouseDoubleClickEvent(QMouseEvent *event)
Definition: Canvas.cc:469
void draw(const graphics_handle &handle)
Definition: GLCanvas.cc:56
void keyReleaseEvent(QKeyEvent *event)
Definition: GLCanvas.cc:188
void toggleAxes(const graphics_handle &handle)
Definition: GLCanvas.cc:71
void canvasToggleAxes(const graphics_handle &handle)
Definition: Canvas.cc:209
void glDrawZoomBox(const QPoint &p1, const QPoint &p2)
Definition: GLCanvas.cc:105
void canvasMousePressEvent(QMouseEvent *event)
Definition: Canvas.cc:502
void canvasWheelEvent(QWheelEvent *event)
Definition: Canvas.cc:817
bool canvasKeyPressEvent(QKeyEvent *event)
Definition: Canvas.cc:925
void canvasMouseMoveEvent(QMouseEvent *event)
Definition: Canvas.cc:399
void canvasAutoAxes(const graphics_handle &handle)
Definition: Canvas.cc:287
void canvasPaintEvent(void)
Definition: Canvas.cc:313
void canvasMouseReleaseEvent(QMouseEvent *event)
Definition: Canvas.cc:719
void paintGL(void)
Definition: GLCanvas.cc:145
bool canvasKeyReleaseEvent(QKeyEvent *event)
Definition: Canvas.cc:952
void toggleGrid(const graphics_handle &handle)
Definition: GLCanvas.cc:77
void mousePressEvent(QMouseEvent *event)
Definition: GLCanvas.cc:163
void drawZoomBox(const QPoint &p1, const QPoint &p2)
Definition: GLCanvas.cc:115
static graphics_object get_object(double val)
Definition: graphics.h:13212
void mouseReleaseEvent(QMouseEvent *event)
Definition: GLCanvas.cc:169
void keyPressEvent(QKeyEvent *event)
Definition: GLCanvas.cc:181
graphics_object select(const graphics_object &ax, int x, int y, int flags=0)
Definition: gl-select.cc:63