annotate libgui/graphics/GLCanvas.cc @ 27302:5f170ea12fa1

use Qt signals to pass interpreter callbacks to octave-qobject * interpreter-qobject.h, interpreter-qobject.cc (interpreter_qobject::m_interpreter): New data member. (interpreter_qobject::execute): Cache pointer to interpreter after it is created. Set it to nullptr before exiting to disable interpreter events. (interpreter_qobject::interpreter_event): New functions. * octave-qobject.h, octave-qobject.cc (octave_qapplication::interpreter_event): New signals. (base_qobject::interpreter_event): New slots. Forward action to m_interpreter object interpreter_event functions. (base_qobject::base_qobject): Connect interpreter_event signals for octave_qapplication to the base_qobject::interpreter_event slots. (octave_qapplication::notify): Emit interpreter_event signal instead of using event_manager::post_exception. * qt-interpreter-events.cc: Declare and register octave::fcn_callback and octave::meth_callback as Qt meta types. * event-manager.h, event-manager.cc (event_manager::m_interpreter): New data member. Update constructor, change all uses. (octave::fcn_callback, octave::meth_callback): New typedefs. (event_manager::post_event): Limit allowable callback function signatures. For meth_callback functions, arrange for a reference to the interpreter object to be passed as the first argument. (event_manager::post_exception): Delete. (event_manager::rethrow_exception_callback): Delete. * GLCanvas.cc (GLCanvas::do_print): Use event_manager::post_event instead of event_manager::post_exception. * file-editor-tab.h (file_eitor_tab::interpreter_event): New signals. * file-editor.cc (file_editor::add_file_editor_tab): Forward interpreter_event signal from newly constructed file_editor_tab object to the interpreter_event signal of the file_editor object. * main-window.h, main-window.cc (main_window::construct): Connect the interpreter_event signal from the main_window object to the parent octave_qobject object. (main_window::interpreter_event): New signals. * octave-dock-widget.h, octave-dock-widget.cc (octave_dock_widget::octave_dock_widget) Forward the interpreter_event signal from the octave_dock_widget object to the interpreter_event signal for parent main_window object. (octave_dock_widget::interpreter_event): New signals. * variable-editor-model.h, variable-editor-model.cc (variable_editor_model::init_from_oct, variable_editor_model::retrieve_variable): Accept reference to interpreter object as an argument. Change all uses. (variable_editor_model::interpreter_event): New signals. * variable-editor.cc (variable_editor::edit_variable): Forward interpreter_event signal from newly constructed variable_editor_model to interpreter_event signal fro variable_editor object. * files-dock-widget.cc, file-editor-tab.cc, main-window.cc, variable-editor-model.cc: In all functions that need to perform interpreter actions, emit an interpreter_event signal instead of accessing the interprter event_manager and calling post_interpreter_event directly.
author John W. Eaton <jwe@octave.org>
date Mon, 29 Jul 2019 10:43:04 -0400
parents 99aa1bcb8848
children 07b330708e3c
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 {
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
71 gh_manager::auto_lock lock;
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
72 graphics_object go = gh_manager::get_object (gh);
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
73
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
74 if (go)
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
75 {
25884
4e108574385c Improve OpenGL rendering on high resolution screens with Qt 5 (bug #49053)
John Swensen <jpswensen@gmail.com>
parents: 25863
diff changeset
76 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
77 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
78 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
79 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
80 m_renderer.draw (go);
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
81 }
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
82 }
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
83
23535
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 23449
diff changeset
84 uint8NDArray
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 23449
diff changeset
85 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
86 {
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 23449
diff changeset
87 uint8NDArray retval;
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 23449
diff changeset
88 graphics_object go = gh_manager::get_object (gh);
25103
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25081
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 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
91 {
24798
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
92 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
93 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
94 pos(2) *= dpr;
8d2b3e3ff182 print.m: Implement "-opengl", "-painters" and "-RGBImage" options (bug #52866)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25889
diff changeset
95 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
96
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
97 // 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
98 if (! begin_rendering ())
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
99 return retval;
23535
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 23449
diff changeset
100
24798
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
101 // 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
102 // 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
103 // suitably large frame.
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
104 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
105 || 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
106 {
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
107 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
108 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
109 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
110
24798
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
111 fbo.bind ();
25103
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25081
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);
8a6bf76abf31 eliminate some duplicate OpenGL drawing code
John W. Eaton <jwe@octave.org>
parents: 25862
diff changeset
116 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
117
24798
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
118 fbo.release ();
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
119 }
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
120 else
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
121 {
25863
8a6bf76abf31 eliminate some duplicate OpenGL drawing code
John W. Eaton <jwe@octave.org>
parents: 25862
diff changeset
122 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
123 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
124 m_renderer.draw (go);
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 }
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
127
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
128 end_rendering ();
23535
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 23449
diff changeset
129 }
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 23449
diff changeset
130
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 23449
diff changeset
131 return retval;
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 23449
diff changeset
132 }
25103
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25081
diff changeset
133
24798
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
134 void
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
135 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
136 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
137 {
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
138 gh_manager::auto_lock lock;
27168
e6bc258df691 Use framebuffer object for printing invisible Qt figures on mac (bug #55268)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26617
diff changeset
139 graphics_object go = gh_manager::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
140
27168
e6bc258df691 Use framebuffer object for printing invisible Qt figures on mac (bug #55268)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26617
diff changeset
141 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
142 {
27168
e6bc258df691 Use framebuffer object for printing invisible Qt figures on mac (bug #55268)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26617
diff changeset
143 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
144
26277
e92a44730a6e Rethrow exceptions from the GUI to the interpreter thread (bug #54920)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25998
diff changeset
145 // 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
146 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
147 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
148
24798
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
149 try
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
150 {
27168
e6bc258df691 Use framebuffer object for printing invisible Qt figures on mac (bug #55268)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26617
diff changeset
151 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
152 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
153 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
154 else
e6bc258df691 Use framebuffer object for printing invisible Qt figures on mac (bug #55268)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26617
diff changeset
155 {
e6bc258df691 Use framebuffer object for printing invisible Qt figures on mac (bug #55268)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26617
diff changeset
156 // 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
157 // 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
158 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
159 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
160 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
161 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
162
e6bc258df691 Use framebuffer object for printing invisible Qt figures on mac (bug #55268)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26617
diff changeset
163 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
164 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
165 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
166
e6bc258df691 Use framebuffer object for printing invisible Qt figures on mac (bug #55268)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26617
diff changeset
167 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
168
e6bc258df691 Use framebuffer object for printing invisible Qt figures on mac (bug #55268)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26617
diff changeset
169 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
170 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
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 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
173 }
24798
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
174 }
25081
d3baac355a2c GLCanvas.cc: Catch exception by reference to silence -Wcatch-value warning (bug #53545).
Rik <rik@octave.org>
parents: 25054
diff changeset
175 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
176 {
27263
99aa1bcb8848 rename octave_link and octave_link_events classes, move inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27261
diff changeset
177 octave::event_manager& evmgr
99aa1bcb8848 rename octave_link and octave_link_events classes, move inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27261
diff changeset
178 = octave::__get_event_manager__ ("GLCanvas::do_print");
27261
dccdc3b001a2 eliminate static functions from octave_link class
John W. Eaton <jwe@octave.org>
parents: 27170
diff changeset
179
27302
5f170ea12fa1 use Qt signals to pass interpreter callbacks to octave-qobject
John W. Eaton <jwe@octave.org>
parents: 27263
diff changeset
180 evmgr.post_event
5f170ea12fa1 use Qt signals to pass interpreter callbacks to octave-qobject
John W. Eaton <jwe@octave.org>
parents: 27263
diff changeset
181 ([] (void)
5f170ea12fa1 use Qt signals to pass interpreter callbacks to octave-qobject
John W. Eaton <jwe@octave.org>
parents: 27263
diff changeset
182 {
5f170ea12fa1 use Qt signals to pass interpreter callbacks to octave-qobject
John W. Eaton <jwe@octave.org>
parents: 27263
diff changeset
183 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
184 });
24798
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
185 }
26617
98afb8bbd1f6 maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
186
26277
e92a44730a6e Rethrow exceptions from the GUI to the interpreter thread (bug #54920)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25998
diff changeset
187 end_rendering ();
24798
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
188 }
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
189 }
23535
2aab625b502c Add getframe function for opengl based toolkits (bug #48195)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 23449
diff changeset
190
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
191 graphics_object
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
192 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
193 {
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
194 makeCurrent ();
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
195
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
196 if (ax)
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
197 {
25862
e5a73a8c116c use wrapper class to call OpenGL functions
John W. Eaton <jwe@octave.org>
parents: 25103
diff changeset
198 octave::opengl_selector s (m_glfcns);
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
199
25889
2da65009cc7f Fix graphics object selection on high resolution screens (bug #49053)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25884
diff changeset
200 s.set_viewport (width (), height ());
24691
b658e0fa0cb3 maint: Remove trailing whitespace from files.
Rik <rik@octave.org>
parents: 24636
diff changeset
201 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
202 octave::select_ignore_hittest);
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
203 }
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
204
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
205 return graphics_object ();
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
206 }
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
207
25862
e5a73a8c116c use wrapper class to call OpenGL functions
John W. Eaton <jwe@octave.org>
parents: 25103
diff changeset
208 void
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
209 GLCanvas::drawZoomBox (const QPoint& p1, const QPoint& p2)
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
210 {
25863
8a6bf76abf31 eliminate some duplicate OpenGL drawing code
John W. Eaton <jwe@octave.org>
parents: 25862
diff changeset
211 Matrix overlaycolor (3, 1);
8a6bf76abf31 eliminate some duplicate OpenGL drawing code
John W. Eaton <jwe@octave.org>
parents: 25862
diff changeset
212 overlaycolor(0) = 0.45;
8a6bf76abf31 eliminate some duplicate OpenGL drawing code
John W. Eaton <jwe@octave.org>
parents: 25862
diff changeset
213 overlaycolor(1) = 0.62;
8a6bf76abf31 eliminate some duplicate OpenGL drawing code
John W. Eaton <jwe@octave.org>
parents: 25862
diff changeset
214 overlaycolor(2) = 0.81;
8a6bf76abf31 eliminate some duplicate OpenGL drawing code
John W. Eaton <jwe@octave.org>
parents: 25862
diff changeset
215 double overlayalpha = 0.1;
8a6bf76abf31 eliminate some duplicate OpenGL drawing code
John W. Eaton <jwe@octave.org>
parents: 25862
diff changeset
216 Matrix bordercolor = overlaycolor;
8a6bf76abf31 eliminate some duplicate OpenGL drawing code
John W. Eaton <jwe@octave.org>
parents: 25862
diff changeset
217 double borderalpha = 0.9;
8a6bf76abf31 eliminate some duplicate OpenGL drawing code
John W. Eaton <jwe@octave.org>
parents: 25862
diff changeset
218 double borderwidth = 1.5;
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
219
25863
8a6bf76abf31 eliminate some duplicate OpenGL drawing code
John W. Eaton <jwe@octave.org>
parents: 25862
diff changeset
220 m_renderer.draw_zoom_box (width (), height (),
8a6bf76abf31 eliminate some duplicate OpenGL drawing code
John W. Eaton <jwe@octave.org>
parents: 25862
diff changeset
221 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
222 overlaycolor, overlayalpha,
8a6bf76abf31 eliminate some duplicate OpenGL drawing code
John W. Eaton <jwe@octave.org>
parents: 25862
diff changeset
223 bordercolor, borderalpha, borderwidth);
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
224 }
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
225
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
226 void
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
227 GLCanvas::paintGL (void)
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
228 {
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
229 canvasPaintEvent ();
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
230 }
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
231
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
232 void
23449
c763214a8260 maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents: 23220
diff changeset
233 GLCanvas::mouseDoubleClickEvent (QMouseEvent *xevent)
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
234 {
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
235 canvasMouseDoubleClickEvent (xevent);
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
236 }
19663
dfea01b3425f more mouse interaction features for Qt plotting widget
John W. Eaton <jwe@octave.org>
parents: 19642
diff changeset
237
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
238 void
23449
c763214a8260 maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents: 23220
diff changeset
239 GLCanvas::mouseMoveEvent (QMouseEvent *xevent)
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
240 {
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
241 canvasMouseMoveEvent (xevent);
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
242 }
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
243
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
244 void
23449
c763214a8260 maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents: 23220
diff changeset
245 GLCanvas::mousePressEvent (QMouseEvent *xevent)
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
246 {
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
247 canvasMousePressEvent (xevent);
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
248 }
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
249
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
250 void
23449
c763214a8260 maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents: 23220
diff changeset
251 GLCanvas::mouseReleaseEvent (QMouseEvent *xevent)
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
252 {
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
253 canvasMouseReleaseEvent (xevent);
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
254 }
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
255
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
256 void
23449
c763214a8260 maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents: 23220
diff changeset
257 GLCanvas::wheelEvent (QWheelEvent *xevent)
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
258 {
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
259 canvasWheelEvent (xevent);
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
260 }
19663
dfea01b3425f more mouse interaction features for Qt plotting widget
John W. Eaton <jwe@octave.org>
parents: 19642
diff changeset
261
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
262 void
23449
c763214a8260 maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents: 23220
diff changeset
263 GLCanvas::keyPressEvent (QKeyEvent *xevent)
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
264 {
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
265 if (! canvasKeyPressEvent (xevent))
24142
59cdf06c940e use QOpenGLWidget if it is available
John W. Eaton <jwe@octave.org>
parents: 23535
diff changeset
266 OCTAVE_QT_OPENGL_WIDGET::keyPressEvent (xevent);
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
267 }
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
268
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
269 void
23449
c763214a8260 maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents: 23220
diff changeset
270 GLCanvas::keyReleaseEvent (QKeyEvent *xevent)
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
271 {
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
272 if (! canvasKeyReleaseEvent (xevent))
24142
59cdf06c940e use QOpenGLWidget if it is available
John W. Eaton <jwe@octave.org>
parents: 23535
diff changeset
273 OCTAVE_QT_OPENGL_WIDGET::keyReleaseEvent (xevent);
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22326
diff changeset
274 }
18498
2e7cad6f180c Initial integration of QtHandles.
John W. Eaton <jwe@octave.org>
parents:
diff changeset
275
24798
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
276 bool
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
277 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
278 {
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
279 bool retval = true;
25103
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25081
diff changeset
280
24798
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
281 if (! isValid ())
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
282 {
24837
ae6679369a80 Rely on QOffscreenSurface functionality rather than its presence (bug #53278)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24798
diff changeset
283 # 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
284 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
285 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
286 {
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
287 // 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
288 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
289 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
290 {
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
291 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
292 return false;
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
293 }
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
294 }
25103
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25081
diff changeset
295
24798
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
296 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
297 # else
24798
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
298 retval = false;
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
299 # endif
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
300 }
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
301 else
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
302 makeCurrent ();
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 return retval;
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
305 }
25103
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25081
diff changeset
306
24798
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
307 void
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
308 GLCanvas::end_rendering (void)
25103
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25081
diff changeset
309 {
24798
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
310 doneCurrent ();
45470049a43f Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 24691
diff changeset
311 }
22413
8758addcf265 maint: Remove ';' at end of namespace declaration.
Rik <rik@octave.org>
parents: 22411
diff changeset
312 }