annotate libgui/graphics/GLCanvas.cc @ 27393:efe72866b483

mark all interpreter_event lambda functions with special comment * Canvas.cc, GLCanvas.cc, file-editor-tab.cc, main-window.cc, octave-qobject.cc, set-path-model.cc: Mark all lambda functions passed to interpreter_event signals with "INTERPRETER THREAD" comments as a reminder that they will be executed in the interpreter thread.
author John W. Eaton <jwe@octave.org>
date Wed, 11 Sep 2019 16:46:54 -0400
parents 50216d7a2f6b
children f844b1f03dcc
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1 /*
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2
26376
00f796120a6d maint: Update copyright dates in all source files.
John W. Eaton <jwe@octave.org>
parents: 26277
diff changeset
3 Copyright (C) 2011-2019 Michael Goffioul
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4
18500
49877d3be064 update copyright notices for new QtHandles code
John W. Eaton <jwe@octave.org>
parents: 18498
diff changeset
5 This file is part of Octave.
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 24142
diff changeset
7 Octave is free software: you can redistribute it and/or modify it
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22490
diff changeset
8 under the terms of the GNU General Public License as published by
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 24142
diff changeset
9 the Free Software Foundation, either version 3 of the License, or
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22490
diff changeset
10 (at your option) any later version.
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
11
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22490
diff changeset
12 Octave is distributed in the hope that it will be useful, but
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22490
diff changeset
13 WITHOUT ANY WARRANTY; without even the implied warranty of
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22490
diff changeset
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22490
diff changeset
15 GNU General Public License for more details.
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
16
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
18500
49877d3be064 update copyright notices for new QtHandles code
John W. Eaton <jwe@octave.org>
parents: 18498
diff changeset
18 along with Octave; see the file COPYING. If not, see
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 24142
diff changeset
19 <https://www.gnu.org/licenses/>.
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
20
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
21 */
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
22
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21692
diff changeset
23 #if defined (HAVE_CONFIG_H)
21301
40de9f8f23a6 Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents: 21203
diff changeset
24 # include "config.h"
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
25 #endif
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
26
27263
99aa1bcb8848 rename octave_link and octave_link_events classes, move inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27261
diff changeset
27 #include "event-manager.h"
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
28 #include "gl-render.h"
24798
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
29 #include "gl2ps-print.h"
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
30 #include "graphics.h"
27261
dccdc3b001a2 eliminate static functions from octave_link class
John W. Eaton <jwe@octave.org>
parents: 27170
diff changeset
31 #include "interpreter-private.h"
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
32
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
33 #include "GLCanvas.h"
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
34 #include "gl-select.h"
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
35
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
36 namespace QtHandles
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
37 {
24142
59cdf06c940e use QOpenGLWidget if it is available
John W. Eaton <jwe@octave.org>
parents: 23535
diff changeset
38 #if defined (HAVE_QOPENGLWIDGET)
59cdf06c940e use QOpenGLWidget if it is available
John W. Eaton <jwe@octave.org>
parents: 23535
diff changeset
39 # define OCTAVE_QT_OPENGL_WIDGET_FORMAT_ARGS
59cdf06c940e use QOpenGLWidget if it is available
John W. Eaton <jwe@octave.org>
parents: 23535
diff changeset
40 #else
59cdf06c940e use QOpenGLWidget if it is available
John W. Eaton <jwe@octave.org>
parents: 23535
diff changeset
41 # if defined (Q_OS_WIN32)
59cdf06c940e use QOpenGLWidget if it is available
John W. Eaton <jwe@octave.org>
parents: 23535
diff changeset
42 # define OCTAVE_QT_OPENGL_WIDGET_FORMAT_ARGS \
59cdf06c940e use QOpenGLWidget if it is available
John W. Eaton <jwe@octave.org>
parents: 23535
diff changeset
43 QGLFormat (QGL::SampleBuffers | QGL::AlphaChannel \
59cdf06c940e use QOpenGLWidget if it is available
John W. Eaton <jwe@octave.org>
parents: 23535
diff changeset
44 | QGL::IndirectRendering),
59cdf06c940e use QOpenGLWidget if it is available
John W. Eaton <jwe@octave.org>
parents: 23535
diff changeset
45 # else
59cdf06c940e use QOpenGLWidget if it is available
John W. Eaton <jwe@octave.org>
parents: 23535
diff changeset
46 # define OCTAVE_QT_OPENGL_WIDGET_FORMAT_ARGS \
59cdf06c940e use QOpenGLWidget if it is available
John W. Eaton <jwe@octave.org>
parents: 23535
diff changeset
47 QGLFormat (QGL::SampleBuffers | QGL::AlphaChannel),
59cdf06c940e use QOpenGLWidget if it is available
John W. Eaton <jwe@octave.org>
parents: 23535
diff changeset
48 # endif
59cdf06c940e use QOpenGLWidget if it is available
John W. Eaton <jwe@octave.org>
parents: 23535
diff changeset
49 #endif
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
50
23449
c763214a8260 maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents: 23220
diff changeset
51 GLCanvas::GLCanvas (QWidget *xparent, const graphics_handle& gh)
24142
59cdf06c940e use QOpenGLWidget if it is available
John W. Eaton <jwe@octave.org>
parents: 23535
diff changeset
52 : OCTAVE_QT_OPENGL_WIDGET (OCTAVE_QT_OPENGL_WIDGET_FORMAT_ARGS xparent),
25863
8a6bf76abf31 eliminate some duplicate OpenGL drawing code
John W. Eaton <jwe@octave.org>
parents: 25862
diff changeset
53 Canvas (gh), m_glfcns (), m_renderer (m_glfcns)
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
54 {
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
55 setFocusPolicy (Qt::ClickFocus);
23070
bef714f45999 maint: Use space after function name/before parenthesis in libgui.
Rik <rik@octave.org>
parents: 22755
diff changeset
56 setFocus ();
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
57 }
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
58
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
59 GLCanvas::~GLCanvas (void)
22417
48c00363dc74 maint: Use '{ }' for empty function bodies in C++.
Rik <rik@octave.org>
parents: 22413
diff changeset
60 { }
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
61
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
62 void
25862
e5a73a8c116c use wrapper class to call OpenGL functions
John W. Eaton <jwe@octave.org>
parents: 25103
diff changeset
63 GLCanvas::initializeGL (void)
e5a73a8c116c use wrapper class to call OpenGL functions
John W. Eaton <jwe@octave.org>
parents: 25103
diff changeset
64 {
e5a73a8c116c use wrapper class to call OpenGL functions
John W. Eaton <jwe@octave.org>
parents: 25103
diff changeset
65 m_glfcns.init ();
e5a73a8c116c use wrapper class to call OpenGL functions
John W. Eaton <jwe@octave.org>
parents: 25103
diff changeset
66 }
e5a73a8c116c use wrapper class to call OpenGL functions
John W. Eaton <jwe@octave.org>
parents: 25103
diff changeset
67
e5a73a8c116c use wrapper class to call OpenGL functions
John W. Eaton <jwe@octave.org>
parents: 25103
diff changeset
68 void
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
69 GLCanvas::draw (const graphics_handle& gh)
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
70 {
27335
50216d7a2f6b eliminate static wrapper functions in gh_manager class
John W. Eaton <jwe@octave.org>
parents: 27303
diff changeset
71 gh_manager& gh_mgr = octave::__get_gh_manager__ ("GLCanvas::draw");
50216d7a2f6b eliminate static wrapper functions in gh_manager class
John W. Eaton <jwe@octave.org>
parents: 27303
diff changeset
72
50216d7a2f6b eliminate static wrapper functions in gh_manager class
John W. Eaton <jwe@octave.org>
parents: 27303
diff changeset
73 octave::autolock guard (gh_mgr.graphics_lock ());
50216d7a2f6b eliminate static wrapper functions in gh_manager class
John W. Eaton <jwe@octave.org>
parents: 27303
diff changeset
74
50216d7a2f6b eliminate static wrapper functions in gh_manager class
John W. Eaton <jwe@octave.org>
parents: 27303
diff changeset
75 graphics_object go = gh_mgr.get_object (gh);
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
76
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
77 if (go)
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
78 {
25884
4e108574385c Improve OpenGL rendering on high resolution screens with Qt 5 (bug #49053)
John Swensen <jpswensen@gmail.com>
parents: 25863
diff changeset
79 graphics_object fig = go.get_ancestor ("figure");
4e108574385c Improve OpenGL rendering on high resolution screens with Qt 5 (bug #49053)
John Swensen <jpswensen@gmail.com>
parents: 25863
diff changeset
80 double dpr = fig.get ("__device_pixel_ratio__").double_value ();
4e108574385c Improve OpenGL rendering on high resolution screens with Qt 5 (bug #49053)
John Swensen <jpswensen@gmail.com>
parents: 25863
diff changeset
81 m_renderer.set_viewport (dpr * width (), dpr * height ());
25889
2da65009cc7f Fix graphics object selection on high resolution screens (bug #49053)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25884
diff changeset
82 m_renderer.set_device_pixel_ratio (dpr);
25863
8a6bf76abf31 eliminate some duplicate OpenGL drawing code
John W. Eaton <jwe@octave.org>
parents: 25862
diff changeset
83 m_renderer.draw (go);
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
84 }
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
85 }
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
86
23535
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 23449
diff changeset
87 uint8NDArray
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 23449
diff changeset
88 GLCanvas::do_getPixels (const graphics_handle& gh)
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 23449
diff changeset
89 {
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 23449
diff changeset
90 uint8NDArray retval;
27335
50216d7a2f6b eliminate static wrapper functions in gh_manager class
John W. Eaton <jwe@octave.org>
parents: 27303
diff changeset
91
50216d7a2f6b eliminate static wrapper functions in gh_manager class
John W. Eaton <jwe@octave.org>
parents: 27303
diff changeset
92 gh_manager& gh_mgr = octave::__get_gh_manager__ ("GLCanvas::do_getPixels");
50216d7a2f6b eliminate static wrapper functions in gh_manager class
John W. Eaton <jwe@octave.org>
parents: 27303
diff changeset
93
50216d7a2f6b eliminate static wrapper functions in gh_manager class
John W. Eaton <jwe@octave.org>
parents: 27303
diff changeset
94 graphics_object go = gh_mgr.get_object (gh);
25103
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25081
diff changeset
95
24798
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
96 if (go && go.isa ("figure"))
23535
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 23449
diff changeset
97 {
24798
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
98 Matrix pos = go.get ("position").matrix_value ();
25998
8d2b3e3ff182 print.m: Implement "-opengl", "-painters" and "-RGBImage" options (bug #52866)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25889
diff changeset
99 double dpr = go.get ("__device_pixel_ratio__").double_value ();
8d2b3e3ff182 print.m: Implement "-opengl", "-painters" and "-RGBImage" options (bug #52866)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25889
diff changeset
100 pos(2) *= dpr;
8d2b3e3ff182 print.m: Implement "-opengl", "-painters" and "-RGBImage" options (bug #52866)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25889
diff changeset
101 pos(3) *= dpr;
24798
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
102
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
103 // Make sure we have a valid current context
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
104 if (! begin_rendering ())
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
105 return retval;
23535
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 23449
diff changeset
106
24798
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
107 // When the figure is not visible or its size is frozen for printing,
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
108 // we use a framebuffer object to make sure we are rendering on a
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
109 // suitably large frame.
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
110 if (go.get ("visible").string_value () == "off"
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
111 || go.get ("__printing__").string_value () == "on")
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
112 {
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
113 OCTAVE_QT_OPENGL_FBO
25998
8d2b3e3ff182 print.m: Implement "-opengl", "-painters" and "-RGBImage" options (bug #52866)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25889
diff changeset
114 fbo (pos(2), pos(3),
8d2b3e3ff182 print.m: Implement "-opengl", "-painters" and "-RGBImage" options (bug #52866)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25889
diff changeset
115 OCTAVE_QT_OPENGL_FBO::Attachment::Depth);
25103
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25081
diff changeset
116
24798
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
117 fbo.bind ();
25103
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25081
diff changeset
118
25863
8a6bf76abf31 eliminate some duplicate OpenGL drawing code
John W. Eaton <jwe@octave.org>
parents: 25862
diff changeset
119 m_renderer.set_viewport (pos(2), pos(3));
25998
8d2b3e3ff182 print.m: Implement "-opengl", "-painters" and "-RGBImage" options (bug #52866)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25889
diff changeset
120 m_renderer.set_device_pixel_ratio (dpr);
25863
8a6bf76abf31 eliminate some duplicate OpenGL drawing code
John W. Eaton <jwe@octave.org>
parents: 25862
diff changeset
121 m_renderer.draw (go);
8a6bf76abf31 eliminate some duplicate OpenGL drawing code
John W. Eaton <jwe@octave.org>
parents: 25862
diff changeset
122 retval = m_renderer.get_pixels (pos(2), pos(3));
25103
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25081
diff changeset
123
24798
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
124 fbo.release ();
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
125 }
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
126 else
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
127 {
25863
8a6bf76abf31 eliminate some duplicate OpenGL drawing code
John W. Eaton <jwe@octave.org>
parents: 25862
diff changeset
128 m_renderer.set_viewport (pos(2), pos(3));
25998
8d2b3e3ff182 print.m: Implement "-opengl", "-painters" and "-RGBImage" options (bug #52866)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25889
diff changeset
129 m_renderer.set_device_pixel_ratio (dpr);
25863
8a6bf76abf31 eliminate some duplicate OpenGL drawing code
John W. Eaton <jwe@octave.org>
parents: 25862
diff changeset
130 m_renderer.draw (go);
8a6bf76abf31 eliminate some duplicate OpenGL drawing code
John W. Eaton <jwe@octave.org>
parents: 25862
diff changeset
131 retval = m_renderer.get_pixels (pos(2), pos(3));
24798
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
132 }
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
133
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
134 end_rendering ();
23535
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 23449
diff changeset
135 }
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 23449
diff changeset
136
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 23449
diff changeset
137 return retval;
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 23449
diff changeset
138 }
25103
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25081
diff changeset
139
24798
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
140 void
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
141 GLCanvas::do_print (const QString& file_cmd, const QString& term,
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
142 const graphics_handle& handle)
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
143 {
27335
50216d7a2f6b eliminate static wrapper functions in gh_manager class
John W. Eaton <jwe@octave.org>
parents: 27303
diff changeset
144 gh_manager& gh_mgr = octave::__get_gh_manager__ ("GLCanvas::do_print");
50216d7a2f6b eliminate static wrapper functions in gh_manager class
John W. Eaton <jwe@octave.org>
parents: 27303
diff changeset
145
50216d7a2f6b eliminate static wrapper functions in gh_manager class
John W. Eaton <jwe@octave.org>
parents: 27303
diff changeset
146 octave::autolock guard (gh_mgr.graphics_lock ());
50216d7a2f6b eliminate static wrapper functions in gh_manager class
John W. Eaton <jwe@octave.org>
parents: 27303
diff changeset
147
50216d7a2f6b eliminate static wrapper functions in gh_manager class
John W. Eaton <jwe@octave.org>
parents: 27303
diff changeset
148 graphics_object go = gh_mgr.get_object (handle);
24798
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
149
27168
e6bc258df691 Use framebuffer object for printing invisible Qt figures on mac (bug #55268)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26617
diff changeset
150 if (go.valid_object ())
24798
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
151 {
27168
e6bc258df691 Use framebuffer object for printing invisible Qt figures on mac (bug #55268)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26617
diff changeset
152 graphics_object fig (go.get_ancestor ("figure"));
26617
98afb8bbd1f6 maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
153
26277
e92a44730a6e Rethrow exceptions from the GUI to the interpreter thread (bug #54920)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25998
diff changeset
154 // Make sure we have a valid current context
e92a44730a6e Rethrow exceptions from the GUI to the interpreter thread (bug #54920)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25998
diff changeset
155 if (! begin_rendering ())
e92a44730a6e Rethrow exceptions from the GUI to the interpreter thread (bug #54920)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25998
diff changeset
156 error ("print: no valid OpenGL offscreen context");
26617
98afb8bbd1f6 maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
157
24798
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
158 try
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
159 {
27168
e6bc258df691 Use framebuffer object for printing invisible Qt figures on mac (bug #55268)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26617
diff changeset
160 if (fig.get ("visible").string_value () == "on")
e6bc258df691 Use framebuffer object for printing invisible Qt figures on mac (bug #55268)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26617
diff changeset
161 octave::gl2ps_print (m_glfcns, fig, file_cmd.toStdString (),
e6bc258df691 Use framebuffer object for printing invisible Qt figures on mac (bug #55268)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26617
diff changeset
162 term.toStdString ());
e6bc258df691 Use framebuffer object for printing invisible Qt figures on mac (bug #55268)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26617
diff changeset
163 else
e6bc258df691 Use framebuffer object for printing invisible Qt figures on mac (bug #55268)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26617
diff changeset
164 {
e6bc258df691 Use framebuffer object for printing invisible Qt figures on mac (bug #55268)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26617
diff changeset
165 // When the figure is not visible, we use a framebuffer object
e6bc258df691 Use framebuffer object for printing invisible Qt figures on mac (bug #55268)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26617
diff changeset
166 // to make sure we are rendering on a suitably large frame.
e6bc258df691 Use framebuffer object for printing invisible Qt figures on mac (bug #55268)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26617
diff changeset
167 Matrix pos = fig.get ("position").matrix_value ();
e6bc258df691 Use framebuffer object for printing invisible Qt figures on mac (bug #55268)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26617
diff changeset
168 double dpr = fig.get ("__device_pixel_ratio__").double_value ();
e6bc258df691 Use framebuffer object for printing invisible Qt figures on mac (bug #55268)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26617
diff changeset
169 pos(2) *= dpr;
e6bc258df691 Use framebuffer object for printing invisible Qt figures on mac (bug #55268)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26617
diff changeset
170 pos(3) *= dpr;
e6bc258df691 Use framebuffer object for printing invisible Qt figures on mac (bug #55268)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26617
diff changeset
171
e6bc258df691 Use framebuffer object for printing invisible Qt figures on mac (bug #55268)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26617
diff changeset
172 OCTAVE_QT_OPENGL_FBO
e6bc258df691 Use framebuffer object for printing invisible Qt figures on mac (bug #55268)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26617
diff changeset
173 fbo (pos(2), pos(3),
e6bc258df691 Use framebuffer object for printing invisible Qt figures on mac (bug #55268)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26617
diff changeset
174 OCTAVE_QT_OPENGL_FBO::Attachment::Depth);
e6bc258df691 Use framebuffer object for printing invisible Qt figures on mac (bug #55268)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26617
diff changeset
175
e6bc258df691 Use framebuffer object for printing invisible Qt figures on mac (bug #55268)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26617
diff changeset
176 fbo.bind ();
e6bc258df691 Use framebuffer object for printing invisible Qt figures on mac (bug #55268)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26617
diff changeset
177
e6bc258df691 Use framebuffer object for printing invisible Qt figures on mac (bug #55268)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26617
diff changeset
178 octave::gl2ps_print (m_glfcns, fig, file_cmd.toStdString (),
e6bc258df691 Use framebuffer object for printing invisible Qt figures on mac (bug #55268)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26617
diff changeset
179 term.toStdString ());
e6bc258df691 Use framebuffer object for printing invisible Qt figures on mac (bug #55268)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26617
diff changeset
180
e6bc258df691 Use framebuffer object for printing invisible Qt figures on mac (bug #55268)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26617
diff changeset
181 fbo.release ();
e6bc258df691 Use framebuffer object for printing invisible Qt figures on mac (bug #55268)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26617
diff changeset
182 }
24798
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
183 }
25081
d3baac355a2c GLCanvas.cc: Catch exception by reference to silence -Wcatch-value warning (bug #53545).
Rik <rik@octave.org>
parents: 25054
diff changeset
184 catch (octave::execution_exception& e)
24798
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
185 {
27303
07b330708e3c use Qt signals for interpreter callbacks in Qt graphics toolkit
John W. Eaton <jwe@octave.org>
parents: 27302
diff changeset
186 emit interpreter_event
27302
5f170ea12fa1 use Qt signals to pass interpreter callbacks to octave-qobject
John W. Eaton <jwe@octave.org>
parents: 27263
diff changeset
187 ([] (void)
5f170ea12fa1 use Qt signals to pass interpreter callbacks to octave-qobject
John W. Eaton <jwe@octave.org>
parents: 27263
diff changeset
188 {
27393
efe72866b483 mark all interpreter_event lambda functions with special comment
John W. Eaton <jwe@octave.org>
parents: 27335
diff changeset
189 // INTERPRETER THREAD
efe72866b483 mark all interpreter_event lambda functions with special comment
John W. Eaton <jwe@octave.org>
parents: 27335
diff changeset
190
27302
5f170ea12fa1 use Qt signals to pass interpreter callbacks to octave-qobject
John W. Eaton <jwe@octave.org>
parents: 27263
diff changeset
191 std::rethrow_exception (std::current_exception ());
5f170ea12fa1 use Qt signals to pass interpreter callbacks to octave-qobject
John W. Eaton <jwe@octave.org>
parents: 27263
diff changeset
192 });
24798
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
193 }
26617
98afb8bbd1f6 maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
194
26277
e92a44730a6e Rethrow exceptions from the GUI to the interpreter thread (bug #54920)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25998
diff changeset
195 end_rendering ();
24798
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
196 }
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
197 }
23535
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 23449
diff changeset
198
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
199 graphics_object
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
200 GLCanvas::selectFromAxes (const graphics_object& ax, const QPoint& pt)
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
201 {
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
202 makeCurrent ();
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
203
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
204 if (ax)
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
205 {
25862
e5a73a8c116c use wrapper class to call OpenGL functions
John W. Eaton <jwe@octave.org>
parents: 25103
diff changeset
206 octave::opengl_selector s (m_glfcns);
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
207
25889
2da65009cc7f Fix graphics object selection on high resolution screens (bug #49053)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25884
diff changeset
208 s.set_viewport (width (), height ());
24691
b658e0fa0cb3 maint: Remove trailing whitespace from files.
Rik <rik@octave.org>
parents: 24636
diff changeset
209 return s.select (ax, pt.x (), height () - pt.y (),
24636
9d01ce02d5cb Make selection and "HitTest" compatible with Matlab (bug #52795).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24534
diff changeset
210 octave::select_ignore_hittest);
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
211 }
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
212
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
213 return graphics_object ();
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
214 }
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
215
25862
e5a73a8c116c use wrapper class to call OpenGL functions
John W. Eaton <jwe@octave.org>
parents: 25103
diff changeset
216 void
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
217 GLCanvas::drawZoomBox (const QPoint& p1, const QPoint& p2)
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
218 {
25863
8a6bf76abf31 eliminate some duplicate OpenGL drawing code
John W. Eaton <jwe@octave.org>
parents: 25862
diff changeset
219 Matrix overlaycolor (3, 1);
8a6bf76abf31 eliminate some duplicate OpenGL drawing code
John W. Eaton <jwe@octave.org>
parents: 25862
diff changeset
220 overlaycolor(0) = 0.45;
8a6bf76abf31 eliminate some duplicate OpenGL drawing code
John W. Eaton <jwe@octave.org>
parents: 25862
diff changeset
221 overlaycolor(1) = 0.62;
8a6bf76abf31 eliminate some duplicate OpenGL drawing code
John W. Eaton <jwe@octave.org>
parents: 25862
diff changeset
222 overlaycolor(2) = 0.81;
8a6bf76abf31 eliminate some duplicate OpenGL drawing code
John W. Eaton <jwe@octave.org>
parents: 25862
diff changeset
223 double overlayalpha = 0.1;
8a6bf76abf31 eliminate some duplicate OpenGL drawing code
John W. Eaton <jwe@octave.org>
parents: 25862
diff changeset
224 Matrix bordercolor = overlaycolor;
8a6bf76abf31 eliminate some duplicate OpenGL drawing code
John W. Eaton <jwe@octave.org>
parents: 25862
diff changeset
225 double borderalpha = 0.9;
8a6bf76abf31 eliminate some duplicate OpenGL drawing code
John W. Eaton <jwe@octave.org>
parents: 25862
diff changeset
226 double borderwidth = 1.5;
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
227
25863
8a6bf76abf31 eliminate some duplicate OpenGL drawing code
John W. Eaton <jwe@octave.org>
parents: 25862
diff changeset
228 m_renderer.draw_zoom_box (width (), height (),
8a6bf76abf31 eliminate some duplicate OpenGL drawing code
John W. Eaton <jwe@octave.org>
parents: 25862
diff changeset
229 p1.x (), p1.y (), p2.x (), p2.y (),
8a6bf76abf31 eliminate some duplicate OpenGL drawing code
John W. Eaton <jwe@octave.org>
parents: 25862
diff changeset
230 overlaycolor, overlayalpha,
8a6bf76abf31 eliminate some duplicate OpenGL drawing code
John W. Eaton <jwe@octave.org>
parents: 25862
diff changeset
231 bordercolor, borderalpha, borderwidth);
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
232 }
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
233
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
234 void
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
235 GLCanvas::paintGL (void)
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
236 {
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
237 canvasPaintEvent ();
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
238 }
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
239
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
240 void
23449
c763214a8260 maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents: 23220
diff changeset
241 GLCanvas::mouseDoubleClickEvent (QMouseEvent *xevent)
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
242 {
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
243 canvasMouseDoubleClickEvent (xevent);
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
244 }
19663
dfea01b3425f more mouse interaction features for Qt plotting widget
John W. Eaton <jwe@octave.org>
parents: 19642
diff changeset
245
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
246 void
23449
c763214a8260 maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents: 23220
diff changeset
247 GLCanvas::mouseMoveEvent (QMouseEvent *xevent)
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
248 {
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
249 canvasMouseMoveEvent (xevent);
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
250 }
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
251
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
252 void
23449
c763214a8260 maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents: 23220
diff changeset
253 GLCanvas::mousePressEvent (QMouseEvent *xevent)
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
254 {
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
255 canvasMousePressEvent (xevent);
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
256 }
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
257
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
258 void
23449
c763214a8260 maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents: 23220
diff changeset
259 GLCanvas::mouseReleaseEvent (QMouseEvent *xevent)
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
260 {
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
261 canvasMouseReleaseEvent (xevent);
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
262 }
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
263
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
264 void
23449
c763214a8260 maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents: 23220
diff changeset
265 GLCanvas::wheelEvent (QWheelEvent *xevent)
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
266 {
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
267 canvasWheelEvent (xevent);
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
268 }
19663
dfea01b3425f more mouse interaction features for Qt plotting widget
John W. Eaton <jwe@octave.org>
parents: 19642
diff changeset
269
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
270 void
23449
c763214a8260 maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents: 23220
diff changeset
271 GLCanvas::keyPressEvent (QKeyEvent *xevent)
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
272 {
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
273 if (! canvasKeyPressEvent (xevent))
24142
59cdf06c940e use QOpenGLWidget if it is available
John W. Eaton <jwe@octave.org>
parents: 23535
diff changeset
274 OCTAVE_QT_OPENGL_WIDGET::keyPressEvent (xevent);
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
275 }
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
276
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
277 void
23449
c763214a8260 maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents: 23220
diff changeset
278 GLCanvas::keyReleaseEvent (QKeyEvent *xevent)
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
279 {
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
280 if (! canvasKeyReleaseEvent (xevent))
24142
59cdf06c940e use QOpenGLWidget if it is available
John W. Eaton <jwe@octave.org>
parents: 23535
diff changeset
281 OCTAVE_QT_OPENGL_WIDGET::keyReleaseEvent (xevent);
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
282 }
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
283
24798
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
284 bool
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
285 GLCanvas::begin_rendering (void)
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
286 {
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
287 bool retval = true;
25103
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25081
diff changeset
288
24798
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
289 if (! isValid ())
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
290 {
24837
ae6679369a80 Rely on QOffscreenSurface functionality rather than its presence (bug #53278)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24798
diff changeset
291 # if defined (HAVE_QT_OFFSCREEN)
24798
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
292 static bool os_ctx_ok = true;
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
293 if (os_ctx_ok && ! m_os_context.isValid ())
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
294 {
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
295 // Try to initialize offscreen context
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
296 m_os_surface.create ();
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
297 if (! m_os_context.create ())
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
298 {
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
299 os_ctx_ok = false;
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
300 return false;
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
301 }
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
302 }
25103
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25081
diff changeset
303
24798
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
304 retval = m_os_context.makeCurrent (&m_os_surface);
25103
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25081
diff changeset
305 # else
24798
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
306 retval = false;
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
307 # endif
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
308 }
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
309 else
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
310 makeCurrent ();
25103
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25081
diff changeset
311
24798
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
312 return retval;
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
313 }
25103
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25081
diff changeset
314
24798
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
315 void
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
316 GLCanvas::end_rendering (void)
25103
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25081
diff changeset
317 {
24798
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
318 doneCurrent ();
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
319 }
22413
8758addcf265 maint: Remove ';' at end of namespace declaration.
Rik <rik@octave.org>
parents: 22411
diff changeset
320 }