annotate libgui/graphics/GLCanvas.cc @ 31762:d94ceed56929

GLCanvas: avoid multiple inheritance from both QWidget and QObject To avoid having GLCanvas inherit from both QWidget and QObject, create a separate class, GLWidget, derived from QOpenGLWidget and use that as a member of GLCanvas instead of a base class. * Canvas.h (class Canvas): Derive from QWidget instead of QObject. (Canvas::Canvas): New argument for parent widget. Pass parent to QWidget base class constructor. * GLCanvas.h, GLCanvas.cc (class GLCanvas): Split QOpenGLWidget parts into separate GLWidget class. GLCanvas now processes things related to the interpreter and forwards to GLWidget for rendering. Use unwind_action objects to ensure OpenGL context is restored. (GLCanvas::m_glwidget): New data member for GLWidget. * libbgui/graphics/module.mk (OCTAVE_GUI_GRAPHICS_MOC): Add moc-GLCanvas.cc to the list.
author John W. Eaton <jwe@octave.org>
date Fri, 20 Jan 2023 08:49:19 -0500
parents 345a3f5890e7
children 1d1eff97670e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
1 ////////////////////////////////////////////////////////////////////////
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
2 //
31706
597f3ee61a48 update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents: 31648
diff changeset
3 // Copyright (C) 2011-2023 The Octave Project Developers
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
4 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
5 // See the file COPYRIGHT.md in the top-level directory of this
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
6 // distribution or <https://octave.org/copyright/>.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
7 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
8 // This file is part of Octave.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
9 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
10 // Octave is free software: you can redistribute it and/or modify it
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
11 // under the terms of the GNU General Public License as published by
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
12 // the Free Software Foundation, either version 3 of the License, or
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
13 // (at your option) any later version.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
14 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
15 // Octave is distributed in the hope that it will be useful, but
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
18 // GNU General Public License for more details.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
19 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
20 // You should have received a copy of the GNU General Public License
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
21 // along with Octave; see the file COPYING. If not, see
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
22 // <https://www.gnu.org/licenses/>.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
23 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
24 ////////////////////////////////////////////////////////////////////////
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
25
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21692
diff changeset
26 #if defined (HAVE_CONFIG_H)
21301
40de9f8f23a6 Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents: 21203
diff changeset
27 # include "config.h"
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
28 #endif
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
29
27417
f844b1f03dcc update some header file lists in libgui sources
John W. Eaton <jwe@octave.org>
parents: 27393
diff changeset
30 #include "GLCanvas.h"
f844b1f03dcc update some header file lists in libgui sources
John W. Eaton <jwe@octave.org>
parents: 27393
diff changeset
31 #include "gl-select.h"
f844b1f03dcc update some header file lists in libgui sources
John W. Eaton <jwe@octave.org>
parents: 27393
diff changeset
32
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
33 #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
34 #include "gl2ps-print.h"
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
35 #include "graphics.h"
27647
2a506bc4a7af eliminate global access to Octave interpreter in qt graphics classes
John W. Eaton <jwe@octave.org>
parents: 27645
diff changeset
36 #include "interpreter.h"
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
37
31646
c6d54dd31a7e maint: Use macros to begin/end C++ namespaces.
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
38 OCTAVE_BEGIN_NAMESPACE(octave)
c6d54dd31a7e maint: Use macros to begin/end C++ namespaces.
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
39
31762
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
40 GLWidget::GLWidget (Canvas &parent_canvas)
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
41 : QOpenGLWidget (&parent_canvas), m_parent_canvas (parent_canvas),
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
42 m_glfcns (), m_renderer (m_glfcns)
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
43 {
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
44 setFocusPolicy (Qt::ClickFocus);
23070
bef714f45999 maint: Use space after function name/before parenthesis in libgui.
Rik <rik@octave.org>
parents: 22755
diff changeset
45 setFocus ();
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
46 }
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
47
31762
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
48 GLWidget::~GLWidget (void) { }
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
49
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
50 void
31762
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
51 GLWidget::initializeGL (void)
25862
e5a73a8c116c use wrapper class to call OpenGL functions
John W. Eaton <jwe@octave.org>
parents: 25103
diff changeset
52 {
31762
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
53 // The qopengl_functions object (part of Octave, not Qt) is just
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
54 // wrapper around QOpenGLFunctions_1_1. Does initialization really
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
55 // need to be deferred until initializeGL is called?
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
56
25862
e5a73a8c116c use wrapper class to call OpenGL functions
John W. Eaton <jwe@octave.org>
parents: 25103
diff changeset
57 m_glfcns.init ();
31762
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
58
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
59 // All other resources we need are currently (supposed to be)
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
60 // managed by the QOpenGLWidget object so there is else nothing to
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
61 // do here. If we used custom shader programs, then we would need
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
62 // to initialize them here.
25862
e5a73a8c116c use wrapper class to call OpenGL functions
John W. Eaton <jwe@octave.org>
parents: 25103
diff changeset
63 }
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 void
31762
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
66 GLWidget::draw (graphics_object go)
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
67 {
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
68 if (go)
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
69 {
31762
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
70 begin_rendering ();
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
71
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
72 unwind_action reset_current ([=] () { end_rendering (); });
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
73
25884
4e108574385c Improve OpenGL rendering on high resolution screens with Qt 5 (bug #49053)
John Swensen <jpswensen@gmail.com>
parents: 25863
diff changeset
74 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
75 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
76 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
77 m_renderer.set_device_pixel_ratio (dpr);
31762
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
78
25863
8a6bf76abf31 eliminate some duplicate OpenGL drawing code
John W. Eaton <jwe@octave.org>
parents: 25862
diff changeset
79 m_renderer.draw (go);
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
80 }
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
81 }
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
82
23535
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 23449
diff changeset
83 uint8NDArray
31762
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
84 GLWidget::do_getPixels (graphics_object go)
23535
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 23449
diff changeset
85 {
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 23449
diff changeset
86 uint8NDArray retval;
27335
50216d7a2f6b eliminate static wrapper functions in gh_manager class
John W. Eaton <jwe@octave.org>
parents: 27303
diff changeset
87
24798
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
88 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
89 {
24798
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
90 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
91 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
92 pos(2) *= dpr;
8d2b3e3ff182 print.m: Implement "-opengl", "-painters" and "-RGBImage" options (bug #52866)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25889
diff changeset
93 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
94
31762
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
95 begin_rendering ();
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
96
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
97 unwind_action reset_current ([=] () { end_rendering (); });
23535
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 23449
diff changeset
98
24798
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
99 // 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
100 // 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
101 // suitably large frame.
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
102 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
103 || 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
104 {
31752
345a3f5890e7 assume QOpenGLWidget is available
John W. Eaton <jwe@octave.org>
parents: 31751
diff changeset
105 QOpenGLFramebufferObject
345a3f5890e7 assume QOpenGLWidget is available
John W. Eaton <jwe@octave.org>
parents: 31751
diff changeset
106 fbo (pos(2), pos(3),
345a3f5890e7 assume QOpenGLWidget is available
John W. Eaton <jwe@octave.org>
parents: 31751
diff changeset
107 QOpenGLFramebufferObject::Attachment::Depth);
25103
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25081
diff changeset
108
24798
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
109 fbo.bind ();
25103
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25081
diff changeset
110
31762
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
111 unwind_action release_fbo ([&] () { fbo.release (); });
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
112
25863
8a6bf76abf31 eliminate some duplicate OpenGL drawing code
John W. Eaton <jwe@octave.org>
parents: 25862
diff changeset
113 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
114 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
115 m_renderer.draw (go);
31762
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
116
25863
8a6bf76abf31 eliminate some duplicate OpenGL drawing code
John W. Eaton <jwe@octave.org>
parents: 25862
diff changeset
117 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
118 }
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
119 else
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
120 {
25863
8a6bf76abf31 eliminate some duplicate OpenGL drawing code
John W. Eaton <jwe@octave.org>
parents: 25862
diff changeset
121 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
122 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
123 m_renderer.draw (go);
31762
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
124
25863
8a6bf76abf31 eliminate some duplicate OpenGL drawing code
John W. Eaton <jwe@octave.org>
parents: 25862
diff changeset
125 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
126 }
23535
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 23449
diff changeset
127 }
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 23449
diff changeset
128
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 23449
diff changeset
129 return retval;
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 23449
diff changeset
130 }
25103
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25081
diff changeset
131
24798
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
132 void
31762
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
133 GLWidget::do_print (const QString& file_cmd, const QString& term,
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
134 graphics_object go)
24798
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
135 {
27168
e6bc258df691 Use framebuffer object for printing invisible Qt figures on mac (bug #55268)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26617
diff changeset
136 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
137 {
31762
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
138 begin_rendering ();
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
139
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
140 unwind_action reset_current ([=] () { end_rendering (); });
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
141
27168
e6bc258df691 Use framebuffer object for printing invisible Qt figures on mac (bug #55268)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26617
diff changeset
142 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
143
31762
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
144 if (fig.get ("visible").string_value () == "on")
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
145 octave::gl2ps_print (m_glfcns, fig, file_cmd.toStdString (),
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
146 term.toStdString ());
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
147 else
24798
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
148 {
31762
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
149 // When the figure is not visible, we use a framebuffer object
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
150 // to make sure we are rendering on a suitably large frame.
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
151 Matrix pos = fig.get ("position").matrix_value ();
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
152 double dpr = fig.get ("__device_pixel_ratio__").double_value ();
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
153 pos(2) *= dpr;
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
154 pos(3) *= dpr;
27168
e6bc258df691 Use framebuffer object for printing invisible Qt figures on mac (bug #55268)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26617
diff changeset
155
31762
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
156 QOpenGLFramebufferObject
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
157 fbo (pos(2), pos(3),
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
158 QOpenGLFramebufferObject::Attachment::Depth);
27168
e6bc258df691 Use framebuffer object for printing invisible Qt figures on mac (bug #55268)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26617
diff changeset
159
31762
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
160 fbo.bind ();
27168
e6bc258df691 Use framebuffer object for printing invisible Qt figures on mac (bug #55268)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26617
diff changeset
161
31762
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
162 unwind_action release_fbo ([&] () { fbo.release (); });
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
163
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
164 octave::gl2ps_print (m_glfcns, fig, file_cmd.toStdString (),
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
165 term.toStdString ());
24798
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
166 }
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
167 }
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
168 }
23535
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 23449
diff changeset
169
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
170 graphics_object
31762
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
171 GLWidget::selectFromAxes (const graphics_object& ax, const QPoint& pt)
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
172 {
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
173 if (ax)
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
174 {
31762
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
175 begin_rendering ();
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
176
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
177 unwind_action reset_current ([=] () { end_rendering (); });
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
178
25862
e5a73a8c116c use wrapper class to call OpenGL functions
John W. Eaton <jwe@octave.org>
parents: 25103
diff changeset
179 octave::opengl_selector s (m_glfcns);
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
180
25889
2da65009cc7f Fix graphics object selection on high resolution screens (bug #49053)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25884
diff changeset
181 s.set_viewport (width (), height ());
31762
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
182
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
183 graphics_object go = s.select (ax, pt.x (), height () - pt.y (),
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
184 octave::select_ignore_hittest);
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
185
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
186 doneCurrent ();
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
187 }
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
188
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
189 return graphics_object ();
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
190 }
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
191
25862
e5a73a8c116c use wrapper class to call OpenGL functions
John W. Eaton <jwe@octave.org>
parents: 25103
diff changeset
192 void
31762
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
193 GLWidget::drawZoomBox (const QPoint& p1, const QPoint& p2)
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
194 {
25863
8a6bf76abf31 eliminate some duplicate OpenGL drawing code
John W. Eaton <jwe@octave.org>
parents: 25862
diff changeset
195 Matrix overlaycolor (3, 1);
8a6bf76abf31 eliminate some duplicate OpenGL drawing code
John W. Eaton <jwe@octave.org>
parents: 25862
diff changeset
196 overlaycolor(0) = 0.45;
8a6bf76abf31 eliminate some duplicate OpenGL drawing code
John W. Eaton <jwe@octave.org>
parents: 25862
diff changeset
197 overlaycolor(1) = 0.62;
8a6bf76abf31 eliminate some duplicate OpenGL drawing code
John W. Eaton <jwe@octave.org>
parents: 25862
diff changeset
198 overlaycolor(2) = 0.81;
8a6bf76abf31 eliminate some duplicate OpenGL drawing code
John W. Eaton <jwe@octave.org>
parents: 25862
diff changeset
199 double overlayalpha = 0.1;
8a6bf76abf31 eliminate some duplicate OpenGL drawing code
John W. Eaton <jwe@octave.org>
parents: 25862
diff changeset
200 Matrix bordercolor = overlaycolor;
8a6bf76abf31 eliminate some duplicate OpenGL drawing code
John W. Eaton <jwe@octave.org>
parents: 25862
diff changeset
201 double borderalpha = 0.9;
8a6bf76abf31 eliminate some duplicate OpenGL drawing code
John W. Eaton <jwe@octave.org>
parents: 25862
diff changeset
202 double borderwidth = 1.5;
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
203
25863
8a6bf76abf31 eliminate some duplicate OpenGL drawing code
John W. Eaton <jwe@octave.org>
parents: 25862
diff changeset
204 m_renderer.draw_zoom_box (width (), height (),
8a6bf76abf31 eliminate some duplicate OpenGL drawing code
John W. Eaton <jwe@octave.org>
parents: 25862
diff changeset
205 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
206 overlaycolor, overlayalpha,
8a6bf76abf31 eliminate some duplicate OpenGL drawing code
John W. Eaton <jwe@octave.org>
parents: 25862
diff changeset
207 bordercolor, borderalpha, borderwidth);
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
208 }
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
209
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
210 void
31762
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
211 GLWidget::paintGL (void)
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
212 {
31762
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
213 m_parent_canvas.canvasPaintEvent ();
22411
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
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
216 void
31762
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
217 GLWidget::mouseDoubleClickEvent (QMouseEvent *xevent)
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
218 {
31762
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
219 m_parent_canvas.canvasMouseDoubleClickEvent (xevent);
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
220 }
19663
dfea01b3425f more mouse interaction features for Qt plotting widget
John W. Eaton <jwe@octave.org>
parents: 19642
diff changeset
221
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
222 void
31762
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
223 GLWidget::mouseMoveEvent (QMouseEvent *xevent)
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
224 {
31762
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
225 m_parent_canvas.canvasMouseMoveEvent (xevent);
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
226 }
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
227
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
228 void
31762
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
229 GLWidget::mousePressEvent (QMouseEvent *xevent)
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
230 {
31762
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
231 m_parent_canvas.canvasMousePressEvent (xevent);
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
31762
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
235 GLWidget::mouseReleaseEvent (QMouseEvent *xevent)
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
236 {
31762
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
237 m_parent_canvas.canvasMouseReleaseEvent (xevent);
22411
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
31762
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
241 GLWidget::wheelEvent (QWheelEvent *xevent)
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
242 {
31762
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
243 m_parent_canvas.canvasWheelEvent (xevent);
22411
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
31762
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
247 GLWidget::keyPressEvent (QKeyEvent *xevent)
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
248 {
31762
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
249 if (! m_parent_canvas.canvasKeyPressEvent (xevent))
31752
345a3f5890e7 assume QOpenGLWidget is available
John W. Eaton <jwe@octave.org>
parents: 31751
diff changeset
250 QOpenGLWidget::keyPressEvent (xevent);
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
251 }
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
252
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
253 void
31762
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
254 GLWidget::keyReleaseEvent (QKeyEvent *xevent)
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
255 {
31762
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
256 if (! m_parent_canvas.canvasKeyReleaseEvent (xevent))
31752
345a3f5890e7 assume QOpenGLWidget is available
John W. Eaton <jwe@octave.org>
parents: 31751
diff changeset
257 QOpenGLWidget::keyReleaseEvent (xevent);
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
258 }
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
259
24798
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
260 bool
31762
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
261 GLWidget::begin_rendering (void)
24798
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
262 {
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
263 bool retval = true;
25103
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25081
diff changeset
264
24798
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
265 if (! isValid ())
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
266 {
31762
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
267 // FIXME: Is this really the right way to manager offscreen
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
268 // rendering for printing?
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
269
24798
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
270 static bool os_ctx_ok = true;
31762
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
271
24798
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
272 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
273 {
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
274 // 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
275 m_os_surface.create ();
31762
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
276
24798
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
277 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
278 {
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
279 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
280 return false;
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
281 }
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
282 }
25103
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25081
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 retval = m_os_context.makeCurrent (&m_os_surface);
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
285 }
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
286 else
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
287 makeCurrent ();
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 return retval;
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
290 }
25103
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25081
diff changeset
291
24798
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
292 void
31762
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
293 GLWidget::end_rendering (void)
25103
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25081
diff changeset
294 {
24798
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
295 doneCurrent ();
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
296 }
31646
c6d54dd31a7e maint: Use macros to begin/end C++ namespaces.
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
297
31762
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
298 GLCanvas::GLCanvas (octave::interpreter& interp,
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
299 const graphics_handle& gh, QWidget *parent)
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
300 : Canvas (interp, gh, parent), m_glwidget (new GLWidget (*this))
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
301 { }
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
302
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
303 GLCanvas::~GLCanvas (void)
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
304 {
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
305 delete m_glwidget;
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
306 }
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
307
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
308 void
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
309 GLCanvas::draw (const graphics_handle& gh)
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
310 {
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
311 gh_manager& gh_mgr = m_interpreter.get_gh_manager ();
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
312
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
313 octave::autolock guard (gh_mgr.graphics_lock ());
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
314
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
315 graphics_object go = gh_mgr.get_object (gh);
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
316
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
317 m_glwidget->draw (go);
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
318 }
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
319
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
320 uint8NDArray
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
321 GLCanvas::do_getPixels (const graphics_handle& gh)
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
322 {
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
323 uint8NDArray retval;
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
324
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
325 gh_manager& gh_mgr = m_interpreter.get_gh_manager ();
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
326
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
327 graphics_object go = gh_mgr.get_object (gh);
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
328
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
329 return m_glwidget->do_getPixels (go);
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
330 }
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
331
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
332 void
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
333 GLCanvas::do_print (const QString& file_cmd, const QString& term,
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
334 const graphics_handle& handle)
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
335 {
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
336 gh_manager& gh_mgr = m_interpreter.get_gh_manager ();
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
337
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
338 octave::autolock guard (gh_mgr.graphics_lock ());
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
339
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
340 graphics_object go = gh_mgr.get_object (handle);
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
341
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
342 try
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
343 {
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
344 m_glwidget->do_print (file_cmd, term, go);
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
345 }
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
346 catch (octave::execution_exception& ee)
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
347 {
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
348 emit interpreter_event
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
349 ([=] (void)
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
350 {
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
351 // INTERPRETER THREAD
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
352 throw ee;
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
353 });
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
354 }
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
355 }
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
356
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
357 graphics_object
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
358 GLCanvas::selectFromAxes (const graphics_object& ax, const QPoint& pt)
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
359 {
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
360 return m_glwidget->selectFromAxes (ax, pt);
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
361 }
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
362
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
363 void
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
364 GLCanvas::drawZoomBox (const QPoint& p1, const QPoint& p2)
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
365 {
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
366 m_glwidget->drawZoomBox (p1, p2);
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
367 }
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
368
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
369 bool
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
370 GLCanvas::begin_rendering (void)
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
371 {
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
372 return m_glwidget->begin_rendering ();
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
373 }
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
374
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
375 void
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
376 GLCanvas::end_rendering (void)
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
377 {
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
378 m_glwidget->end_rendering ();
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
379 }
d94ceed56929 GLCanvas: avoid multiple inheritance from both QWidget and QObject
John W. Eaton <jwe@octave.org>
parents: 31752
diff changeset
380
31646
c6d54dd31a7e maint: Use macros to begin/end C++ namespaces.
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
381 OCTAVE_END_NAMESPACE(octave)