comparison libgui/graphics/gl-select.cc @ 18498:2e7cad6f180c gui-release

Initial integration of QtHandles. * configure.ac: Check for QtOpenGL module. * libgui/Makefile.am: Include libgui/graphics/module.mk. (liboctgui_la_LIBADD): Include graphics/libgui-graphics.la in the list. (rcc-command): Pass "-name DIR" to rcc command. * main-window.cc (main_window::construct): Install qt functions and register qt toolkit. * libgui/src/module.mk (src_libgui_src_la_CPPFLAGS): Include $(FONTCONFIG_CPPFLAGS) and -I$(srcdir)/graphics in the list. * graphics.cc (gtk_manager::gtk_manager): Make qt the default toolkit if it is available. * libgui/graphics/Backend.cc, libgui/graphics/Backend.h, libgui/graphics/BaseControl.cc, libgui/graphics/BaseControl.h, libgui/graphics/ButtonControl.cc, libgui/graphics/ButtonControl.h, libgui/graphics/Canvas.cc, libgui/graphics/Canvas.h, libgui/graphics/CheckBoxControl.cc, libgui/graphics/CheckBoxControl.h, libgui/graphics/Container.cc, libgui/graphics/Container.h, libgui/graphics/ContextMenu.cc, libgui/graphics/ContextMenu.h, libgui/graphics/EditControl.cc, libgui/graphics/EditControl.h, libgui/graphics/Figure.cc, libgui/graphics/Figure.h, libgui/graphics/FigureWindow.cc, libgui/graphics/FigureWindow.h, libgui/graphics/GLCanvas.cc, libgui/graphics/GLCanvas.h, , libgui/graphics/GenericEventNotify.h, libgui/graphics/KeyMap.cc, libgui/graphics/KeyMap.h, libgui/graphics/ListBoxControl.cc, libgui/graphics/ListBoxControl.h, libgui/graphics/Logger.cc, libgui/graphics/Logger.h, libgui/graphics/Menu.cc, libgui/graphics/Menu.h, libgui/graphics/MenuContainer.h, libgui/graphics/MouseModeActionGroup.cc, libgui/graphics/MouseModeActionGroup.h, libgui/graphics/Object.cc, libgui/graphics/Object.h, libgui/graphics/ObjectFactory.cc, libgui/graphics/ObjectFactory.h, libgui/graphics/ObjectProxy.cc, libgui/graphics/ObjectProxy.h, libgui/graphics/Panel.cc, libgui/graphics/Panel.h, libgui/graphics/PopupMenuControl.cc, libgui/graphics/PopupMenuControl.h, libgui/graphics/PushButtonControl.cc, libgui/graphics/PushButtonControl.h, libgui/graphics/PushTool.cc, libgui/graphics/PushTool.h, libgui/graphics/RadioButtonControl.cc, libgui/graphics/RadioButtonControl.h, libgui/graphics/SliderControl.cc, libgui/graphics/SliderControl.h, libgui/graphics/TextControl.cc, libgui/graphics/TextControl.h, libgui/graphics/TextEdit.cc, libgui/graphics/TextEdit.h, libgui/graphics/ToggleButtonControl.cc, libgui/graphics/ToggleButtonControl.h, libgui/graphics/ToggleTool.cc, libgui/graphics/ToggleTool.h, libgui/graphics/ToolBar.cc, libgui/graphics/ToolBar.h, libgui/graphics/ToolBarButton.cc, libgui/graphics/ToolBarButton.h, libgui/graphics/Utils.cc, libgui/graphics/Utils.h, libgui/graphics/__init_qt__.cc, libgui/graphics/__init_qt__.h, libgui/graphics/gl-select.cc, libgui/graphics/gl-select.h, libgui/graphics/images/README, libgui/graphics/images/pan.png, libgui/graphics/images/rotate.png, libgui/graphics/images/select.png, libgui/graphics/images/zoom.png, libgui/graphics/module.mk, libgui/graphics/qthandles.qrc: New files.
author John W. Eaton <jwe@octave.org>
date Thu, 20 Feb 2014 14:05:45 -0500
parents
children 49877d3be064
comparison
equal deleted inserted replaced
18495:1ec884e5ff00 18498:2e7cad6f180c
1 /*
2
3 Copyright (C) 2011 Michael Goffioul.
4
5 This file is part of QtHandles.
6
7 Foobar is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11
12 QtHandles is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with Foobar. If not, see <http://www.gnu.org/licenses/>.
19
20 */
21
22 #ifdef HAVE_CONFIG_H
23 #include <config.h>
24 #endif
25
26 #include "gl-select.h"
27
28 #include <iostream>
29
30 void
31 opengl_selector::apply_pick_matrix (void)
32 {
33 GLdouble p_matrix[16];
34 GLint viewport[4];
35
36 glGetDoublev (GL_PROJECTION_MATRIX, p_matrix);
37 glGetIntegerv (GL_VIEWPORT, viewport);
38 glMatrixMode (GL_PROJECTION);
39 glLoadIdentity ();
40 gluPickMatrix (xp, yp, size, size, viewport);
41 glMultMatrixd (p_matrix);
42 glMatrixMode (GL_MODELVIEW);
43 }
44
45 void
46 opengl_selector::setup_opengl_transformation (const axes::properties& props)
47 {
48 opengl_renderer::setup_opengl_transformation (props);
49 apply_pick_matrix ();
50 }
51
52 void
53 opengl_selector::init_marker (const std::string& m, double size, float width)
54 {
55 opengl_renderer::init_marker (m, size, width);
56 apply_pick_matrix ();
57 }
58
59 # define BUFFER_SIZE 128
60
61 graphics_object
62 opengl_selector::select (const graphics_object& ax, int x, int y, int flags)
63 {
64 glEnable (GL_DEPTH_TEST);
65 glDepthFunc (GL_LEQUAL);
66
67 xp = x;
68 yp = y;
69
70 GLuint select_buffer[BUFFER_SIZE];
71
72 glSelectBuffer (BUFFER_SIZE, select_buffer);
73 glRenderMode (GL_SELECT);
74 glInitNames ();
75
76 object_map.clear ();
77
78 draw (ax);
79
80 int hits = glRenderMode (GL_RENDER);
81 graphics_object obj;
82
83 if (hits > 0)
84 {
85 GLuint current_minZ = 0xffffffff;
86 GLuint current_name = 0xffffffff;
87
88 for (int i = 0, j = 0; i < hits && j < BUFFER_SIZE-3; i++)
89 {
90 GLuint n = select_buffer[j++],
91 minZ = select_buffer[j++];
92
93 j++; // skip maxZ
94 if (((flags & select_last) == 0 && (minZ <= current_minZ)) ||
95 ((flags & select_last) != 0 && (minZ >= current_minZ)))
96 {
97 bool candidate = true;
98 GLuint name =
99 select_buffer[std::min (j + n, GLuint (BUFFER_SIZE)) - 1];
100
101 if ((flags & select_ignore_hittest) == 0)
102 {
103 graphics_object go = object_map[name];
104
105 if (! go.get_properties ().is_hittest ())
106 candidate = false;
107 }
108
109 if (candidate)
110 {
111 current_minZ = minZ;
112 current_name = name;
113 }
114
115 j += n;
116 }
117 else
118 j += n;
119 }
120
121 if (current_name != 0xffffffff)
122 obj = object_map[current_name];
123 }
124 else if (hits < 0)
125 warning ("opengl_selector::select: selection buffer overflow");
126
127 object_map.clear ();
128
129 return obj;
130 }
131
132 void
133 opengl_selector::draw (const graphics_object& go, bool toplevel)
134 {
135 GLuint name = object_map.size ();
136
137 object_map[name] = go;
138 glPushName (name);
139 opengl_renderer::draw (go, toplevel);
140 glPopName ();
141 }
142
143 void
144 opengl_selector::fake_text (double x, double y, double z, const Matrix& bbox,
145 bool use_scale)
146 {
147 ColumnVector xpos, xp1, xp2;
148
149 xpos = get_transform ().transform (x, y, z, use_scale);
150
151 xp1 = xp2 = xpos;
152 xp1(0) += bbox(0);
153 xp1(1) -= bbox(1);
154 xp2(0) += (bbox(0) + bbox(2));
155 xp2(1) -= (bbox(1) + bbox(3));
156
157 ColumnVector p1, p2, p3, p4;
158
159 p1 = get_transform ().untransform (xp1(0), xp1(1), xp1(2), false);
160 p2 = get_transform ().untransform (xp2(0), xp1(1), xp1(2), false);
161 p3 = get_transform ().untransform (xp2(0), xp2(1), xp1(2), false);
162 p4 = get_transform ().untransform (xp1(0), xp2(1), xp1(2), false);
163
164 glBegin (GL_QUADS);
165 glVertex3dv (p1.data ());
166 glVertex3dv (p2.data ());
167 glVertex3dv (p3.data ());
168 glVertex3dv (p4.data ());
169 glEnd ();
170 }
171
172 void
173 opengl_selector::draw_text (const text::properties& props)
174 {
175 if (props.get_string ().is_empty ())
176 return;
177
178 Matrix pos = props.get_data_position ();
179 const Matrix bbox = props.get_extent_matrix ();
180
181 fake_text (pos(0), pos(1), pos.numel () > 2 ? pos(2) : 0.0, bbox);
182 }
183
184 Matrix
185 opengl_selector::render_text (const std::string& txt,
186 double x, double y, double z,
187 int halign, int valign, double rotation)
188 {
189 #if HAVE_FREETYPE
190 uint8NDArray pixels;
191 Matrix bbox;
192
193 // FIXME: probably more efficient to only compute bbox instead
194 // of doing full text rendering...
195 text_to_pixels (txt, pixels, bbox, halign, valign, rotation);
196 fake_text (x, y, z, bbox, false);
197
198 return bbox;
199 #else
200 return Matrix (1, 4, 0.0);
201 #endif
202 }