Mercurial > hg > octave-nkf
comparison src/graphics/fltk_backend/fltk_backend.cc @ 7869:e6d5532f760e
style fixes
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 05 Jun 2008 01:06:29 -0400 |
parents | 7397a0026ca8 |
children |
comparison
equal
deleted
inserted
replaced
7868:1b85fcb94c6a | 7869:e6d5532f760e |
---|---|
55 left drag - zoom\n\ | 55 left drag - zoom\n\ |
56 right click - unzoom\n\ | 56 right click - unzoom\n\ |
57 double click - copy coordinates to clipboard\ | 57 double click - copy coordinates to clipboard\ |
58 "; | 58 "; |
59 | 59 |
60 class OpenGL_fltk : public Fl_Gl_Window { | 60 class OpenGL_fltk : public Fl_Gl_Window |
61 { | |
61 public: | 62 public: |
62 OpenGL_fltk (int x, int y, int w, int h, double num) : | 63 OpenGL_fltk (int xx, int yy, int ww, int hh, double num) |
63 Fl_Gl_Window (x, y, w, h, 0), | 64 : Fl_Gl_Window (xx, yy, ww, hh, 0), number (num), in_zoom (false) |
64 number (num), | |
65 in_zoom (false) | |
66 { | 65 { |
67 // ask for double buffering and a depth buffer | 66 // ask for double buffering and a depth buffer |
68 mode(FL_DEPTH | FL_DOUBLE ); | 67 mode (FL_DEPTH | FL_DOUBLE); |
69 }; | 68 } |
70 ~OpenGL_fltk () {}; | 69 |
71 | 70 ~OpenGL_fltk (void) { } |
72 void zoom (bool z) {in_zoom = z;} | 71 |
73 bool zoom () {return in_zoom;} | 72 void zoom (bool z) { in_zoom = z; } |
74 void set_zoom_box (Matrix zb) {zoom_box = zb;} | 73 bool zoom (void) { return in_zoom; } |
74 void set_zoom_box (const Matrix& zb) { zoom_box = zb; } | |
75 | 75 |
76 private: | 76 private: |
77 double number; | 77 double number; |
78 opengl_renderer renderer; | 78 opengl_renderer renderer; |
79 bool in_zoom; | 79 bool in_zoom; |
80 | 80 |
81 // (x1,y1,x2,y2) | 81 // (x1,y1,x2,y2) |
82 Matrix zoom_box; | 82 Matrix zoom_box; |
83 | 83 |
84 void setup_viewport (int _w, int _h) { | 84 void setup_viewport (int _w, int _h) |
85 glMatrixMode(GL_PROJECTION); | 85 { |
86 glLoadIdentity(); | 86 glMatrixMode (GL_PROJECTION); |
87 glLoadIdentity (); | |
87 glViewport (0, 0, _w, _h); | 88 glViewport (0, 0, _w, _h); |
88 } | 89 } |
89 | 90 |
90 void draw () { | 91 void draw (void) |
91 if (!valid ()) { | 92 { |
92 valid (1); | 93 if (!valid ()) |
93 setup_viewport (w (), h ()); | 94 { |
94 } | 95 valid (1); |
96 setup_viewport (w (), h ()); | |
97 } | |
95 | 98 |
96 renderer.draw (gh_manager::lookup (number)); | 99 renderer.draw (gh_manager::lookup (number)); |
97 }; | 100 } |
98 | 101 |
99 void resize (int _x,int _y,int _w,int _h) { | 102 void resize (int _x,int _y,int _w,int _h) |
103 { | |
100 Fl_Gl_Window::resize (_x, _y, _w, _h); | 104 Fl_Gl_Window::resize (_x, _y, _w, _h); |
101 setup_viewport (_w, _h); | 105 setup_viewport (_w, _h); |
102 redraw (); | 106 redraw (); |
103 }; | 107 } |
104 | 108 |
105 void draw_overlay(void) | 109 void draw_overlay (void) |
106 { | 110 { |
107 if(!in_zoom) return; | 111 if (!in_zoom) |
108 | 112 return; |
109 if(!valid()) { | 113 |
110 valid(1); | 114 if (!valid()) |
111 setup_viewport (w (), h ()); | 115 { |
112 } | 116 valid(1); |
117 setup_viewport (w (), h ()); | |
118 } | |
113 | 119 |
114 glPushMatrix (); | 120 glPushMatrix (); |
115 | 121 |
116 glMatrixMode (GL_MODELVIEW); | 122 glMatrixMode (GL_MODELVIEW); |
117 glLoadIdentity (); | 123 glLoadIdentity (); |
124 glDisable (GL_DEPTH_TEST); | 130 glDisable (GL_DEPTH_TEST); |
125 | 131 |
126 glLineWidth (1); | 132 glLineWidth (1); |
127 glBegin (GL_LINE_STRIP); | 133 glBegin (GL_LINE_STRIP); |
128 gl_color(0); | 134 gl_color(0); |
129 glVertex2d ( zoom_box(0), h () - zoom_box(1) ); | 135 glVertex2d (zoom_box(0), h () - zoom_box(1)); |
130 glVertex2d ( zoom_box(0), h () - zoom_box(3) ); | 136 glVertex2d (zoom_box(0), h () - zoom_box(3)); |
131 glVertex2d ( zoom_box(2), h () - zoom_box(3) ); | 137 glVertex2d (zoom_box(2), h () - zoom_box(3)); |
132 glVertex2d ( zoom_box(2), h () - zoom_box(1) ); | 138 glVertex2d (zoom_box(2), h () - zoom_box(1)); |
133 glVertex2d ( zoom_box(0), h () - zoom_box(1) ); | 139 glVertex2d (zoom_box(0), h () - zoom_box(1)); |
134 glEnd (); | 140 glEnd (); |
135 | 141 |
136 glPopAttrib (); | 142 glPopAttrib (); |
137 glPopMatrix (); | 143 glPopMatrix (); |
138 } | 144 } |
144 switch (event) | 150 switch (event) |
145 { | 151 { |
146 case FL_ENTER: | 152 case FL_ENTER: |
147 window ()->cursor (FL_CURSOR_CROSS); | 153 window ()->cursor (FL_CURSOR_CROSS); |
148 return 1; | 154 return 1; |
149 | 155 |
150 case FL_LEAVE: | 156 case FL_LEAVE: |
151 window ()->cursor (FL_CURSOR_DEFAULT); | 157 window ()->cursor (FL_CURSOR_DEFAULT); |
152 return 1; | 158 return 1; |
153 } | 159 } |
154 | 160 |
155 return retval; | 161 return retval; |
156 }; | 162 } |
157 | |
158 }; | 163 }; |
159 | 164 |
160 class plot_window : public Fl_Window { | 165 class plot_window : public Fl_Window |
166 { | |
161 public: | 167 public: |
162 plot_window (int _x, int _y, int _w, int _h, figure::properties& _fp) : | 168 plot_window (int _x, int _y, int _w, int _h, figure::properties& _fp) |
163 Fl_Window (_x, _y, _w, _h, "octave"), | 169 : Fl_Window (_x, _y, _w, _h, "octave"), fp (_fp) |
164 fp (_fp) | |
165 { | 170 { |
166 callback (window_close, static_cast<void*> (this)); | 171 callback (window_close, static_cast<void*> (this)); |
167 | 172 |
168 begin(); | 173 begin (); |
169 { | 174 { |
170 canvas = new | 175 canvas = new |
171 OpenGL_fltk (0, 0, _w , _h - status_h, number ()); | 176 OpenGL_fltk (0, 0, _w , _h - status_h, number ()); |
172 | 177 |
173 autoscale = new | 178 autoscale = new |
174 Fl_Button (0, | 179 Fl_Button (0, |
175 _h - status_h, | 180 _h - status_h, |
176 status_h, | 181 status_h, |
177 status_h, | 182 status_h, |
178 "A"); | 183 "A"); |
179 autoscale->callback (button_callback, static_cast<void*> (this)); | 184 autoscale->callback (button_callback, static_cast<void*> (this)); |
180 | 185 |
181 togglegrid = new | 186 togglegrid = new |
182 Fl_Button (status_h, | 187 Fl_Button (status_h, |
183 _h - status_h, | 188 _h - status_h, |
184 status_h, | 189 status_h, |
185 status_h, | 190 status_h, |
186 "G"); | 191 "G"); |
187 togglegrid->callback (button_callback, static_cast<void*> (this)); | 192 togglegrid->callback (button_callback, static_cast<void*> (this)); |
188 | 193 |
189 help = new | 194 help = new |
190 Fl_Button (2*status_h, | 195 Fl_Button (2*status_h, |
191 _h - status_h, | 196 _h - status_h, |
192 status_h, | 197 status_h, |
193 status_h, | 198 status_h, |
194 "H"); | 199 "H"); |
195 help->callback (button_callback, static_cast<void*> (this)); | 200 help->callback (button_callback, static_cast<void*> (this)); |
196 | 201 |
197 status = new | 202 status = new |
198 Fl_Output (3*status_h, | 203 Fl_Output (3*status_h, |
199 _h - status_h, | 204 _h - status_h, |
200 _w > 2*status_h ? _w - status_h : 0, | 205 _w > 2*status_h ? _w - status_h : 0, |
201 status_h, ""); | 206 status_h, ""); |
202 | 207 |
203 status->textcolor (FL_BLACK); | 208 status->textcolor (FL_BLACK); |
204 status->color (FL_GRAY); | 209 status->color (FL_GRAY); |
205 status->textfont (FL_COURIER); | 210 status->textfont (FL_COURIER); |
206 status->textsize (10); | 211 status->textsize (10); |
207 status->box (FL_ENGRAVED_BOX); | 212 status->box (FL_ENGRAVED_BOX); |
224 std::stringstream name; | 229 std::stringstream name; |
225 name << "octave: figure " << number (); | 230 name << "octave: figure " << number (); |
226 label (name.str ().c_str ()); | 231 label (name.str ().c_str ()); |
227 } | 232 } |
228 | 233 |
229 ~plot_window () { | 234 ~plot_window (void) |
230 canvas->hide(); | 235 { |
231 status->hide(); | 236 canvas->hide (); |
232 this->hide(); | 237 status->hide (); |
238 this->hide (); | |
233 delete canvas; | 239 delete canvas; |
234 delete status; | 240 delete status; |
235 }; | 241 } |
236 | 242 |
237 // FIXME -- this could change | 243 // FIXME -- this could change |
238 double number () { return fp.get___myhandle__ ().value ();}; | 244 double number (void) { return fp.get___myhandle__ ().value (); } |
239 | 245 |
240 void mark_modified () | 246 void mark_modified (void) |
241 { | 247 { |
242 damage (FL_DAMAGE_ALL); | 248 damage (FL_DAMAGE_ALL); |
243 canvas->damage (FL_DAMAGE_ALL); | 249 canvas->damage (FL_DAMAGE_ALL); |
244 } | 250 } |
245 | 251 |
246 private: | 252 private: |
247 // figure properties | 253 // figure properties |
248 figure::properties& fp; | 254 figure::properties& fp; |
249 | 255 |
250 // status area height | 256 // status area height |
251 static const int status_h = 20; | 257 static const int status_h = 20; |
252 | 258 |
253 // window callback | 259 // window callback |
254 static void window_close (Fl_Widget* w, void* data) | 260 static void window_close (Fl_Widget*, void* data) |
255 { | 261 { |
256 octave_value_list args; | 262 octave_value_list args; |
257 args(0) = static_cast<plot_window*> (data)-> number (); | 263 args(0) = static_cast<plot_window*> (data)->number (); |
258 feval("close",args); | 264 feval ("close", args); |
259 } | 265 } |
260 | 266 |
261 // button callbacks | 267 // button callbacks |
262 static void button_callback (Fl_Widget* w, void* data) { | 268 static void button_callback (Fl_Widget* ww, void* data) |
263 static_cast<plot_window*> (data)-> button_press (w); | 269 { |
264 }; | 270 static_cast<plot_window*> (data)->button_press (ww); |
265 | 271 } |
266 void button_press (Fl_Widget* widg) { | 272 |
267 if (widg == autoscale) axis_auto (); | 273 void button_press (Fl_Widget* widg) |
268 if (widg == togglegrid) toggle_grid (); | 274 { |
269 if (widg == help) fl_message (help_text); | 275 if (widg == autoscale) |
270 } | 276 axis_auto (); |
271 | 277 |
272 OpenGL_fltk* canvas; | 278 if (widg == togglegrid) |
273 Fl_Button* autoscale; | 279 toggle_grid (); |
274 Fl_Button* togglegrid; | 280 |
275 Fl_Button* help; | 281 if (widg == help) |
276 Fl_Output* status; | 282 fl_message (help_text); |
277 | 283 } |
278 void axis_auto () | 284 |
279 { | 285 OpenGL_fltk* canvas; |
280 octave_value_list args; | 286 Fl_Button* autoscale; |
287 Fl_Button* togglegrid; | |
288 Fl_Button* help; | |
289 Fl_Output* status; | |
290 | |
291 void axis_auto (void) | |
292 { | |
293 octave_value_list args; | |
281 args(0) = "auto"; | 294 args(0) = "auto"; |
282 feval("axis",args); | 295 feval ("axis",args); |
283 mark_modified (); | 296 mark_modified (); |
284 } | 297 } |
285 | 298 |
286 void toggle_grid () | 299 void toggle_grid (void) |
287 { | 300 { |
288 feval ("grid"); | 301 feval ("grid"); |
289 mark_modified (); | 302 mark_modified (); |
290 } | 303 } |
291 | 304 |
292 void pixel2pos (int px, int py, double& x, double& y) const { | 305 void pixel2pos (int px, int py, double& xx, double& yy) const |
306 { | |
293 graphics_object ax = gh_manager::get_object (fp.get_currentaxes ()); | 307 graphics_object ax = gh_manager::get_object (fp.get_currentaxes ()); |
294 if (ax && ax.isa ("axes")) | 308 |
295 { | 309 if (ax && ax.isa ("axes")) |
296 axes::properties& ap = | 310 { |
311 axes::properties& ap = | |
297 dynamic_cast<axes::properties&> (ax.get_properties ()); | 312 dynamic_cast<axes::properties&> (ax.get_properties ()); |
298 ColumnVector pp = ap.pixel2coord (px, py); | 313 ColumnVector pp = ap.pixel2coord (px, py); |
299 x = pp(0); | 314 xx = pp(0); |
300 y = pp(1); | 315 yy = pp(1); |
301 } | 316 } |
302 } | 317 } |
303 | 318 |
304 graphics_handle pixel2axes (int px, int py) { | 319 graphics_handle pixel2axes (int /* px */, int /* py */) |
305 double x,y; | 320 { |
306 | 321 Matrix kids = fp.get_children (); |
307 Matrix children = fp.get_children (); | 322 |
308 for (octave_idx_type n = 0; n < children.numel (); n++) | 323 for (octave_idx_type n = 0; n < kids.numel (); n++) |
309 { | 324 { |
310 graphics_object ax = gh_manager::get_object (children (n)); | 325 graphics_object ax = gh_manager::get_object (kids (n)); |
311 if (ax && ax.isa ("axes")) | 326 if (ax && ax.isa ("axes")) |
312 { | 327 { |
313 axes::properties& ap = | 328 #if 0 |
314 dynamic_cast<axes::properties&> (ax.get_properties ()); | 329 axes::properties& ap = |
315 | 330 dynamic_cast<axes::properties&> (ax.get_properties ()); |
316 // std::cout << "\npixpos="<<pixpos<<"(px,py)=("<<px<<","<<py<<")\n"; | 331 |
317 // if (px >= pixpos(0) && px <= pixpos(2) | 332 // std::cout << "\npixpos="<<pixpos<<"(px,py)=("<<px<<","<<py<<")\n"; |
318 // && | 333 if (px >= pixpos(0) && px <= pixpos(2) |
319 // py >= pixpos(1) && py <= pixpos(3)) | 334 && py >= pixpos(1) && py <= pixpos(3)) |
320 // return ap.get___myhandle__ (); | 335 return ap.get___myhandle__ (); |
336 #endif | |
321 } | 337 } |
322 } | 338 } |
339 | |
323 return graphics_handle (); | 340 return graphics_handle (); |
324 } | 341 } |
325 | 342 |
326 void pixel2status (int px0, int py0, int px1 = -1, int py1 = -1) { | 343 void pixel2status (int px0, int py0, int px1 = -1, int py1 = -1) |
327 double x0,y0,x1,y1; | 344 { |
345 double x0, y0, x1, y1; | |
328 std::stringstream cbuf; | 346 std::stringstream cbuf; |
329 | 347 |
330 pixel2pos (px0, py0, x0, y0); | 348 pixel2pos (px0, py0, x0, y0); |
331 cbuf << "[" << x0 << ", " << y0 << "]"; | 349 cbuf << "[" << x0 << ", " << y0 << "]"; |
332 if (px1 >= 0) | 350 if (px1 >= 0) |
335 cbuf << " -> ["<< x1 << ", " << y1 << "]"; | 353 cbuf << " -> ["<< x1 << ", " << y1 << "]"; |
336 } | 354 } |
337 | 355 |
338 status->value (cbuf.str ().c_str ()); | 356 status->value (cbuf.str ().c_str ()); |
339 status->redraw (); | 357 status->redraw (); |
340 } | 358 } |
341 | 359 |
342 void resize (int _x,int _y,int _w,int _h) | 360 void resize (int _x,int _y,int _w,int _h) |
343 { | 361 { |
344 Fl_Window::resize (_x, _y, _w, _h); | 362 Fl_Window::resize (_x, _y, _w, _h); |
345 | 363 |
346 Matrix pos (1,4,0); | 364 Matrix pos (1,4,0); |
347 pos(0) = _x; | 365 pos(0) = _x; |
357 Matrix pos = fp.get_position ().matrix_value (); | 375 Matrix pos = fp.get_position ().matrix_value (); |
358 Fl_Window::resize (pos(0), pos(1) , pos(2), pos(3) + status_h); | 376 Fl_Window::resize (pos(0), pos(1) , pos(2), pos(3) + status_h); |
359 | 377 |
360 return Fl_Window::draw (); | 378 return Fl_Window::draw (); |
361 } | 379 } |
362 | 380 |
363 int handle (int event) { | 381 int handle (int event) |
382 { | |
364 static int px0,py0; | 383 static int px0,py0; |
365 static graphics_handle h0 = graphics_handle (); | 384 static graphics_handle h0 = graphics_handle (); |
366 | 385 |
367 int retval = Fl_Window::handle (event); | 386 int retval = Fl_Window::handle (event); |
368 | 387 |
371 return retval; | 390 return retval; |
372 | 391 |
373 switch (event) | 392 switch (event) |
374 { | 393 { |
375 case FL_KEYDOWN: | 394 case FL_KEYDOWN: |
376 switch(Fl::event_key ()) | 395 switch(Fl::event_key ()) |
377 { | 396 { |
378 case 'a': | 397 case 'a': |
379 case 'A': | 398 case 'A': |
380 axis_auto (); | 399 axis_auto (); |
381 break; | 400 break; |
401 | |
382 case 'g': | 402 case 'g': |
383 case 'G': | 403 case 'G': |
384 toggle_grid (); | 404 toggle_grid (); |
385 break; | 405 break; |
386 } | 406 } |
387 break; | 407 break; |
388 | 408 |
389 case FL_MOVE: | 409 case FL_MOVE: |
390 pixel2status (Fl::event_x (), Fl::event_y ()); | 410 pixel2status (Fl::event_x (), Fl::event_y ()); |
391 break; | 411 break; |
392 | 412 |
393 case FL_PUSH: | 413 case FL_PUSH: |
394 if (Fl::event_button () == 1) | 414 if (Fl::event_button () == 1) |
395 { | 415 { |
396 px0 = Fl::event_x (); | 416 px0 = Fl::event_x (); |
397 py0 = Fl::event_y (); | 417 py0 = Fl::event_y (); |
422 // end of drag -- zoom | 442 // end of drag -- zoom |
423 if (canvas->zoom ()) | 443 if (canvas->zoom ()) |
424 { | 444 { |
425 canvas->zoom (false); | 445 canvas->zoom (false); |
426 double x0,y0,x1,y1; | 446 double x0,y0,x1,y1; |
427 graphics_object ax = | 447 graphics_object ax = |
428 gh_manager::get_object (fp.get_currentaxes ()); | 448 gh_manager::get_object (fp.get_currentaxes ()); |
429 if (ax && ax.isa ("axes")) | 449 if (ax && ax.isa ("axes")) |
430 { | 450 { |
431 axes::properties& ap = | 451 axes::properties& ap = |
432 dynamic_cast<axes::properties&> (ax.get_properties ()); | 452 dynamic_cast<axes::properties&> (ax.get_properties ()); |
433 pixel2pos (px0, py0, x0, y0); | 453 pixel2pos (px0, py0, x0, y0); |
434 pixel2pos (Fl::event_x (), Fl::event_y (), x1, y1); | 454 pixel2pos (Fl::event_x (), Fl::event_y (), x1, y1); |
435 Matrix xl (1,2,0); | 455 Matrix xl (1,2,0); |
436 Matrix yl (1,2,0); | 456 Matrix yl (1,2,0); |
442 else | 462 else |
443 { | 463 { |
444 xl(0) = x1; | 464 xl(0) = x1; |
445 xl(1) = x0; | 465 xl(1) = x0; |
446 } | 466 } |
467 | |
447 if (y0 < y1) | 468 if (y0 < y1) |
448 { | 469 { |
449 yl(0) = y0; | 470 yl(0) = y0; |
450 yl(1) = y1; | 471 yl(1) = y1; |
451 } | 472 } |
467 return 1; | 488 return 1; |
468 } | 489 } |
469 } | 490 } |
470 else if (Fl::event_button () == 3) | 491 else if (Fl::event_button () == 3) |
471 { | 492 { |
472 graphics_object ax = | 493 graphics_object ax = |
473 gh_manager::get_object (fp.get_currentaxes ()); | 494 gh_manager::get_object (fp.get_currentaxes ()); |
474 if (ax && ax.isa ("axes")) | 495 if (ax && ax.isa ("axes")) |
475 { | 496 { |
476 axes::properties& ap = | 497 axes::properties& ap = |
477 dynamic_cast<axes::properties&> (ax.get_properties ()); | 498 dynamic_cast<axes::properties&> (ax.get_properties ()); |
478 ap.unzoom (); | 499 ap.unzoom (); |
479 mark_modified (); | 500 mark_modified (); |
480 } | 501 } |
481 } | 502 } |
482 break; | 503 break; |
483 } | 504 } |
484 | 505 |
485 return retval; | 506 return retval; |
486 } | 507 } |
487 | |
488 }; | 508 }; |
489 | 509 |
490 class figure_manager { | 510 class figure_manager |
511 { | |
491 public: | 512 public: |
492 | 513 |
493 static figure_manager& Instance () { | 514 static figure_manager& Instance (void) |
515 { | |
494 static figure_manager fm; | 516 static figure_manager fm; |
495 return fm; | 517 return fm; |
496 } | 518 } |
497 | 519 |
498 ~figure_manager () { | 520 ~figure_manager (void) |
521 { | |
499 close_all (); | 522 close_all (); |
500 } | 523 } |
501 | 524 |
502 void close_all () { | 525 void close_all (void) |
526 { | |
503 wm_iterator win; | 527 wm_iterator win; |
504 for (win = windows.begin (); win != windows.end (); win++) | 528 for (win = windows.begin (); win != windows.end (); win++) |
505 delete (*win).second; | 529 delete (*win).second; |
506 windows.clear (); | 530 windows.clear (); |
507 } | 531 } |
508 | 532 |
509 void new_window (figure::properties& fp) { | 533 void new_window (figure::properties& fp) |
510 int x,y,w,h; | 534 { |
535 int x, y, w, h; | |
511 | 536 |
512 int idx = figprops2idx (fp); | 537 int idx = figprops2idx (fp); |
513 if (idx >= 0 && windows.find (idx) == windows.end ()) | 538 if (idx >= 0 && windows.find (idx) == windows.end ()) |
514 { | 539 { |
515 default_size(x,y,w,h); | 540 default_size(x,y,w,h); |
516 idx2figprops (curr_index , fp); | 541 idx2figprops (curr_index , fp); |
517 windows[curr_index++] = new plot_window (x, y, w, h, fp); | 542 windows[curr_index++] = new plot_window (x, y, w, h, fp); |
518 } | 543 } |
519 }; | 544 } |
520 | 545 |
521 void delete_window (int idx) { | 546 void delete_window (int idx) |
547 { | |
522 wm_iterator win; | 548 wm_iterator win; |
523 if ( (win=windows.find (idx)) != windows.end ()) | 549 if ((win = windows.find (idx)) != windows.end ()) |
524 { | 550 { |
525 delete (*win).second; | 551 delete (*win).second; |
526 windows.erase (win); | 552 windows.erase (win); |
527 } | 553 } |
528 }; | 554 } |
529 | 555 |
530 void delete_window (std::string idx_str) | 556 void delete_window (std::string idx_str) |
531 { delete_window (str2idx (idx_str)); } | 557 { |
532 | 558 delete_window (str2idx (idx_str)); |
533 void mark_modified (int idx) { | 559 } |
560 | |
561 void mark_modified (int idx) | |
562 { | |
534 wm_iterator win; | 563 wm_iterator win; |
535 if ( (win=windows.find (idx)) != windows.end ()) | 564 if ((win=windows.find (idx)) != windows.end ()) |
536 { | 565 { |
537 (*win).second->mark_modified (); | 566 (*win).second->mark_modified (); |
538 } | 567 } |
539 }; | 568 } |
540 | 569 |
541 void mark_modified (const graphics_handle& gh) | 570 void mark_modified (const graphics_handle& gh) |
542 { mark_modified (hnd2idx(gh)); } | 571 { |
572 mark_modified (hnd2idx (gh)); | |
573 } | |
543 | 574 |
544 Matrix get_size (int idx) | 575 Matrix get_size (int idx) |
545 { | 576 { |
546 Matrix sz (1, 2, 0.0); | 577 Matrix sz (1, 2, 0.0); |
547 | 578 |
548 wm_iterator win; | 579 wm_iterator win; |
549 if ( (win=windows.find (idx)) != windows.end ()) | 580 if ((win = windows.find (idx)) != windows.end ()) |
550 { | 581 { |
551 sz(0) = (*win).second->w (); | 582 sz(0) = (*win).second->w (); |
552 sz(1) = (*win).second->h (); | 583 sz(1) = (*win).second->h (); |
553 } | 584 } |
554 | 585 |
555 return sz; | 586 return sz; |
556 } | 587 } |
557 | 588 |
558 Matrix get_size (const graphics_handle& gh) | 589 Matrix get_size (const graphics_handle& gh) |
559 { return get_size (hnd2idx (gh)); } | 590 { |
591 return get_size (hnd2idx (gh)); | |
592 } | |
560 | 593 |
561 private: | 594 private: |
562 figure_manager () {}; | 595 figure_manager (void) { } |
563 figure_manager (const figure_manager& ) {}; | 596 figure_manager (const figure_manager&) { } |
564 figure_manager& operator = (const figure_manager&) {return *this;}; | 597 figure_manager& operator = (const figure_manager&) { return *this; } |
565 // singelton -- hide all of the above | 598 // singelton -- hide all of the above |
566 | 599 |
567 static int curr_index; | 600 static int curr_index; |
568 typedef std::map<int, plot_window*> window_map; | 601 typedef std::map<int, plot_window*> window_map; |
569 typedef window_map::iterator wm_iterator;; | 602 typedef window_map::iterator wm_iterator;; |
570 window_map windows; | 603 window_map windows; |
571 | 604 |
572 static std::string fltk_idx_header; | 605 static std::string fltk_idx_header; |
573 | 606 |
574 void default_size (int& x, int& y, int& w, int& h) { | 607 void default_size (int& x, int& y, int& w, int& h) |
608 { | |
575 x = 10; | 609 x = 10; |
576 y = 10; | 610 y = 10; |
577 w = 400; | 611 w = 400; |
578 h = 300; | 612 h = 300; |
579 } | 613 } |
582 { | 616 { |
583 int ind; | 617 int ind; |
584 if (clstr.find (fltk_idx_header,0) == 0) | 618 if (clstr.find (fltk_idx_header,0) == 0) |
585 { | 619 { |
586 std::istringstream istr (clstr.substr (fltk_idx_header.size ())); | 620 std::istringstream istr (clstr.substr (fltk_idx_header.size ())); |
587 if (istr >> ind ) | 621 if (istr >> ind) |
588 return ind; | 622 return ind; |
589 } | 623 } |
590 error ("fltk_backend: could not recognize fltk index"); | 624 error ("fltk_backend: could not recognize fltk index"); |
591 return -1; | 625 return -1; |
592 } | 626 } |
611 error ("fltk_backend:: figure is not fltk"); | 645 error ("fltk_backend:: figure is not fltk"); |
612 return -1; | 646 return -1; |
613 } | 647 } |
614 | 648 |
615 int hnd2idx (const graphics_handle& fh) | 649 int hnd2idx (const graphics_handle& fh) |
616 { return hnd2idx (fh.value ()); } | 650 { |
651 return hnd2idx (fh.value ()); | |
652 } | |
617 | 653 |
618 int hnd2idx (const double h) | 654 int hnd2idx (const double h) |
619 { | 655 { |
620 graphics_object fobj = gh_manager::get_object (h); | 656 graphics_object fobj = gh_manager::get_object (h); |
621 if (fobj && fobj.isa ("figure")) | 657 if (fobj && fobj.isa ("figure")) |
622 { | 658 { |
623 figure::properties& fp = | 659 figure::properties& fp = |
624 dynamic_cast<figure::properties&> (fobj.get_properties ()); | 660 dynamic_cast<figure::properties&> (fobj.get_properties ()); |
625 return figprops2idx (fp); | 661 return figprops2idx (fp); |
626 } | 662 } |
627 error ("fltk_backend:: not a figure"); | 663 error ("fltk_backend:: not a figure"); |
628 return -1; | 664 return -1; |
629 } | 665 } |
630 | |
631 }; | 666 }; |
632 | 667 |
633 std::string figure_manager::fltk_idx_header="fltk index="; | 668 std::string figure_manager::fltk_idx_header="fltk index="; |
634 int figure_manager::curr_index = 1; | 669 int figure_manager::curr_index = 1; |
635 | 670 |
636 class fltk_backend : public base_graphics_backend | 671 class fltk_backend : public base_graphics_backend |
637 { | 672 { |
638 public: | 673 public: |
639 fltk_backend (void) | 674 fltk_backend (void) |
640 : base_graphics_backend (FLTK_BACKEND_NAME) { } | 675 : base_graphics_backend (FLTK_BACKEND_NAME) { } |
641 | 676 |
642 ~fltk_backend (void) { } | 677 ~fltk_backend (void) { } |
643 | 678 |
644 bool is_valid (void) const { return true; } | 679 bool is_valid (void) const { return true; } |
645 | 680 |
646 void close_figure (const octave_value& ov) const | 681 void close_figure (const octave_value& ov) const |
647 { | 682 { |
648 if (ov.is_string ()) | 683 if (ov.is_string ()) |
649 figure_manager::Instance ().delete_window (ov.string_value ()); | 684 figure_manager::Instance ().delete_window (ov.string_value ()); |
650 } | 685 } |
651 | 686 |
652 void redraw_figure (const graphics_handle& fh) const | 687 void redraw_figure (const graphics_handle& fh) const |
653 { | 688 { |
654 figure_manager::Instance ().mark_modified (fh); | 689 figure_manager::Instance ().mark_modified (fh); |
655 } | 690 } |
656 | 691 |
657 void print_figure (const graphics_handle& fh, const std::string& term, | 692 void print_figure (const graphics_handle& /*fh*/, |
658 const std::string& file, bool mono, | 693 const std::string& /*term*/, |
659 const std::string& debug_file) const | 694 const std::string& /*file*/, bool /*mono*/, |
660 { | 695 const std::string& /*debug_file*/) const { } |
661 } | |
662 | 696 |
663 Matrix get_canvas_size (const graphics_handle& fh) const | 697 Matrix get_canvas_size (const graphics_handle& fh) const |
664 { | 698 { |
665 return figure_manager::Instance ().get_size (fh); | 699 return figure_manager::Instance ().get_size (fh); |
666 } | 700 } |
667 | 701 |
668 double get_screen_resolution (void) const | 702 double get_screen_resolution (void) const |
669 { | 703 { |
670 // FLTK doesn't give this info | 704 // FLTK doesn't give this info |
671 return 72.0; | 705 return 72.0; |
672 } | 706 } |
673 | 707 |
674 Matrix get_screen_size (void) const | 708 Matrix get_screen_size (void) const |
675 { | 709 { |
676 Matrix sz (1, 2, 0.0); | 710 Matrix sz (1, 2, 0.0); |
677 sz(0) = Fl::w (); | 711 sz(0) = Fl::w (); |
678 sz(1) = Fl::h (); | 712 sz(1) = Fl::h (); |
679 return sz; | 713 return sz; |
680 } | 714 } |
681 }; | 715 }; |
682 | 716 |
683 static bool backend_registered = false; | 717 static bool backend_registered = false; |
684 // call this to init the fltk backend | 718 // call this to init the fltk backend |
685 DEFUN_DLD (__init_fltk__, args, nargout,"") | 719 DEFUN_DLD (__init_fltk__, , , "") |
686 { | 720 { |
687 graphics_backend::register_backend (new fltk_backend); | 721 graphics_backend::register_backend (new fltk_backend); |
688 backend_registered = true; | 722 backend_registered = true; |
689 | 723 |
690 octave_value retval; | 724 octave_value retval; |
691 return retval; | 725 return retval; |
692 } | 726 } |
693 | 727 |
694 | 728 |
695 // call this to delete the fltk backend | 729 // call this to delete the fltk backend |
696 DEFUN_DLD (__remove_fltk__, args, nargout,"") | 730 DEFUN_DLD (__remove_fltk__, , , "") |
697 { | 731 { |
698 figure_manager::Instance ().close_all (); | 732 figure_manager::Instance ().close_all (); |
699 graphics_backend::unregister_backend (FLTK_BACKEND_NAME); | 733 graphics_backend::unregister_backend (FLTK_BACKEND_NAME); |
700 backend_registered = false; | 734 backend_registered = false; |
701 | 735 |
702 | 736 // FIXME ??? |
703 // give FLTK 10 seconds to wrap it up | 737 // give FLTK 10 seconds to wrap it up |
704 Fl::wait(10); | 738 Fl::wait(10); |
705 octave_value retval; | 739 octave_value retval; |
706 return retval; | 740 return retval; |
707 } | 741 } |
708 | 742 |
709 // give FLTK no more than 0.01 sec to do it's stuff | 743 // give FLTK no more than 0.01 sec to do it's stuff |
710 static double fltk_maxtime = 1e-2; | 744 static double fltk_maxtime = 1e-2; |
711 | 745 |
712 // call this to delete the fltk backend | 746 // call this to delete the fltk backend |
713 DEFUN_DLD (__fltk_maxtime__, args, nargout,"") | 747 DEFUN_DLD (__fltk_maxtime__, args, ,"") |
714 { | 748 { |
715 octave_value retval=fltk_maxtime; | 749 octave_value retval = fltk_maxtime; |
716 | 750 |
717 if (args.length () == 1 ) | 751 if (args.length () == 1) |
718 { | 752 { |
719 if (args(0).is_real_scalar ()) | 753 if (args(0).is_real_scalar ()) |
720 fltk_maxtime = args(0).double_value (); | 754 fltk_maxtime = args(0).double_value (); |
721 else | 755 else |
722 error("argument must be a real scalar"); | 756 error ("argument must be a real scalar"); |
723 } | 757 } |
724 | 758 |
725 return retval; | 759 return retval; |
726 } | 760 } |
727 | 761 |
728 // call this from the idle_callback to refresh windows | 762 // call this from the idle_callback to refresh windows |
729 DEFUN_DLD (__fltk_redraw__, args, nargout,\ | 763 DEFUN_DLD (__fltk_redraw__, , , |
730 "internal function for the fltk backend") | 764 "internal function for the fltk backend") |
731 { | 765 { |
732 octave_value retval; | 766 octave_value retval; |
733 | 767 |
734 if (!backend_registered) | 768 if (!backend_registered) |
735 return retval; | 769 return retval; |
739 if (obj && obj.isa ("root_figure")) | 773 if (obj && obj.isa ("root_figure")) |
740 { | 774 { |
741 base_properties& props = obj.get_properties (); | 775 base_properties& props = obj.get_properties (); |
742 Matrix children = props.get_children (); | 776 Matrix children = props.get_children (); |
743 | 777 |
744 for (octave_idx_type n = 0; n < children.numel (); n++) | 778 for (octave_idx_type n = 0; n < children.numel (); n++) |
745 { | 779 { |
746 graphics_object fobj = gh_manager::get_object (children (n)); | 780 graphics_object fobj = gh_manager::get_object (children (n)); |
747 if (fobj) | 781 if (fobj && fobj.isa ("figure")) |
748 if (fobj.isa ("figure")) | 782 { |
749 { | 783 figure::properties& fp = |
750 figure::properties& fp = | 784 dynamic_cast<figure::properties&> (fobj.get_properties ()); |
751 dynamic_cast<figure::properties&> (fobj.get_properties ()); | 785 if (fp.get___backend__ () == FLTK_BACKEND_NAME) |
752 if (fp.get___backend__ () == FLTK_BACKEND_NAME) | 786 figure_manager::Instance ().new_window (fp); |
753 figure_manager::Instance ().new_window (fp); | 787 } |
754 } | |
755 } | 788 } |
756 } | 789 } |
757 | 790 |
758 Fl::wait(fltk_maxtime); | 791 Fl::wait (fltk_maxtime); |
759 | 792 |
760 return retval; | 793 return retval; |
761 } | 794 } |
762 | 795 |
763 /* to init | 796 /* to init |