GNU Octave  4.2.1
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-2017 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 #if defined (HAVE_CONFIG_H)
24 # include "config.h"
25 #endif
26 
27 #include "gl-render.h"
28 #include "graphics.h"
29 
30 #include "GLCanvas.h"
31 #include "gl-select.h"
32 
33 namespace QtHandles
34 {
35 
37 #if defined (Q_OS_WIN32)
38  : QGLWidget (QGLFormat (QGL::SampleBuffers | QGL::AlphaChannel |
39  QGL::IndirectRendering),
40  xparent),
41  Canvas (gh)
42 #else
43  : QGLWidget (QGLFormat (QGL::SampleBuffers | QGL::AlphaChannel),
44  xparent),
45  Canvas (gh)
46 #endif
47  {
48  setFocusPolicy (Qt::ClickFocus);
49  setFocus();
50  }
51 
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  glMatrixMode (GL_MODELVIEW);
118  glPushMatrix ();
119  glLoadIdentity ();
120 
121  glMatrixMode (GL_PROJECTION);
122  glPushMatrix ();
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  glLineWidth (1.5);
135  glBegin (GL_LINE_STRIP);
136  glColor4f (0.45, 0.62, 0.81, 0.9);
137  glDrawZoomBox (p1, p2);
138  glEnd ();
139 
140  glPopAttrib ();
141 
142  glMatrixMode (GL_MODELVIEW);
143  glPopMatrix ();
144 
145  glMatrixMode (GL_PROJECTION);
146  glPopMatrix ();
147  }
148 
149  void
151  {
152  canvasPaintEvent ();
153  }
154 
155  void
156  GLCanvas::mouseDoubleClickEvent (QMouseEvent* xevent)
157  {
159  }
160 
161  void
162  GLCanvas::mouseMoveEvent (QMouseEvent* xevent)
163  {
164  canvasMouseMoveEvent (xevent);
165  }
166 
167  void
168  GLCanvas::mousePressEvent (QMouseEvent* xevent)
169  {
170  canvasMousePressEvent (xevent);
171  }
172 
173  void
174  GLCanvas::mouseReleaseEvent (QMouseEvent* xevent)
175  {
176  canvasMouseReleaseEvent (xevent);
177  }
178 
179  void
180  GLCanvas::wheelEvent (QWheelEvent* xevent)
181  {
182  canvasWheelEvent (xevent);
183  }
184 
185  void
186  GLCanvas::keyPressEvent (QKeyEvent* xevent)
187  {
188  if (! canvasKeyPressEvent (xevent))
189  QGLWidget::keyPressEvent (xevent);
190  }
191 
192  void
193  GLCanvas::keyReleaseEvent (QKeyEvent* xevent)
194  {
195  if (! canvasKeyReleaseEvent (xevent))
196  QGLWidget::keyReleaseEvent (xevent);
197  }
198 
199 }
void autoAxes(const graphics_handle &handle)
Definition: GLCanvas.cc:83
void mouseDoubleClickEvent(QMouseEvent *event)
Definition: GLCanvas.cc:156
graphics_object selectFromAxes(const graphics_object &ax, const QPoint &pt)
Definition: GLCanvas.cc:89
virtual void draw(const graphics_object &go, bool toplevel=true)
Definition: gl-render.cc:652
GLCanvas(QWidget *parent, const graphics_handle &handle)
Definition: GLCanvas.cc:36
graphics_handle gh
Definition: graphics.cc:11209
s
Definition: file-io.cc:2682
void wheelEvent(QWheelEvent *event)
Definition: GLCanvas.cc:180
void mouseMoveEvent(QMouseEvent *event)
Definition: GLCanvas.cc:162
void canvasToggleGrid(const graphics_handle &handle)
Definition: Canvas.cc:239
graphics_object select(const graphics_object &ax, int x, int y, int flags=0)
Definition: gl-select.cc:66
void canvasMouseDoubleClickEvent(QMouseEvent *event)
Definition: Canvas.cc:576
void draw(const graphics_handle &handle)
Definition: GLCanvas.cc:56
void keyReleaseEvent(QKeyEvent *event)
Definition: GLCanvas.cc:193
void toggleAxes(const graphics_handle &handle)
Definition: GLCanvas.cc:71
void canvasToggleAxes(const graphics_handle &handle)
Definition: Canvas.cc:210
void glDrawZoomBox(const QPoint &p1, const QPoint &p2)
Definition: GLCanvas.cc:105
void canvasMousePressEvent(QMouseEvent *event)
Definition: Canvas.cc:609
void canvasWheelEvent(QWheelEvent *event)
Definition: Canvas.cc:888
bool canvasKeyPressEvent(QKeyEvent *event)
Definition: Canvas.cc:996
void canvasMouseMoveEvent(QMouseEvent *event)
Definition: Canvas.cc:477
void canvasAutoAxes(const graphics_handle &handle)
Definition: Canvas.cc:287
void canvasPaintEvent(void)
Definition: Canvas.cc:313
virtual void set_viewport(int w, int h)
Definition: gl-render.cc:3481
void canvasMouseReleaseEvent(QMouseEvent *event)
Definition: Canvas.cc:789
void paintGL(void)
Definition: GLCanvas.cc:150
bool canvasKeyReleaseEvent(QKeyEvent *event)
Definition: Canvas.cc:1023
void toggleGrid(const graphics_handle &handle)
Definition: GLCanvas.cc:77
void mousePressEvent(QMouseEvent *event)
Definition: GLCanvas.cc:168
void drawZoomBox(const QPoint &p1, const QPoint &p2)
Definition: GLCanvas.cc:115
static graphics_object get_object(double val)
Definition: graphics.h:13794
void mouseReleaseEvent(QMouseEvent *event)
Definition: GLCanvas.cc:174
void keyPressEvent(QKeyEvent *event)
Definition: GLCanvas.cc:186