Mercurial > octave-nkf
comparison src/DLD-FUNCTIONS/fltk_backend.cc @ 10792:91342260063e
mouse rotation for fltk backend
author | Shai Ayal <shaiay@users.sourceforge.net> |
---|---|
date | Mon, 19 Jul 2010 06:17:54 +0300 |
parents | 26d51c6e1c4c |
children | d479134f59de |
comparison
equal
deleted
inserted
replaced
10791:3140cb7a05a1 | 10792:91342260063e |
---|---|
67 static double fltk_maxtime = 1e-2; | 67 static double fltk_maxtime = 1e-2; |
68 | 68 |
69 const char* help_text = "\ | 69 const char* help_text = "\ |
70 Keyboard Shortcuts\n\ | 70 Keyboard Shortcuts\n\ |
71 a - autoscale\n\ | 71 a - autoscale\n\ |
72 p - pan/zoom\n\ | |
73 r - rotate\n\ | |
72 g - toggle grid\n\ | 74 g - toggle grid\n\ |
73 \n\ | 75 \n\ |
74 Mouse\n\ | 76 Mouse\n\ |
75 left drag - pan\n\ | 77 left drag - pan\n\ |
76 mouse wheel - zoom\n\ | 78 mouse wheel - zoom\n\ |
217 class plot_window : public Fl_Window | 219 class plot_window : public Fl_Window |
218 { | 220 { |
219 public: | 221 public: |
220 plot_window (int xx, int yy, int ww, int hh, figure::properties& xfp) | 222 plot_window (int xx, int yy, int ww, int hh, figure::properties& xfp) |
221 : Fl_Window (xx, yy, ww, hh, "octave"), window_label (), shift (0), | 223 : Fl_Window (xx, yy, ww, hh, "octave"), window_label (), shift (0), |
222 fp (xfp), canvas (0), autoscale (0), togglegrid (0), help (0), | 224 fp (xfp), canvas (0), autoscale (0), togglegrid (0), panzoom (0), rotate (0), help (0), status (0) |
223 status (0) | |
224 { | 225 { |
225 callback (window_close, static_cast<void*> (this)); | 226 callback (window_close, static_cast<void*> (this)); |
226 | 227 |
227 begin (); | 228 begin (); |
228 { | 229 { |
243 status_h, | 244 status_h, |
244 status_h, | 245 status_h, |
245 "G"); | 246 "G"); |
246 togglegrid->callback (button_callback, static_cast<void*> (this)); | 247 togglegrid->callback (button_callback, static_cast<void*> (this)); |
247 | 248 |
249 panzoom = new | |
250 Fl_Button (2 * status_h, | |
251 hh - status_h, | |
252 status_h, | |
253 status_h, | |
254 "P"); | |
255 panzoom->callback (button_callback, static_cast<void*> (this)); | |
256 | |
257 rotate = new | |
258 Fl_Button (3 * status_h, | |
259 hh - status_h, | |
260 status_h, | |
261 status_h, | |
262 "R"); | |
263 rotate->callback (button_callback, static_cast<void*> (this)); | |
264 | |
248 help = new | 265 help = new |
249 Fl_Button (2*status_h, | 266 Fl_Button (4 * status_h, |
250 hh - status_h, | 267 hh - status_h, |
251 status_h, | 268 status_h, |
252 status_h, | 269 status_h, |
253 "?"); | 270 "?"); |
254 help->callback (button_callback, static_cast<void*> (this)); | 271 help->callback (button_callback, static_cast<void*> (this)); |
255 | 272 |
256 status = new | 273 status = new |
257 Fl_Output (3*status_h, | 274 Fl_Output (5 * status_h, |
258 hh - status_h, | 275 hh - status_h, |
259 ww > 2*status_h ? ww - status_h : 0, | 276 ww > 2*status_h ? ww - status_h : 0, |
260 status_h, ""); | 277 status_h, ""); |
261 | 278 |
262 status->textcolor (FL_BLACK); | 279 status->textcolor (FL_BLACK); |
277 end (); | 294 end (); |
278 | 295 |
279 status->show (); | 296 status->show (); |
280 autoscale->show (); | 297 autoscale->show (); |
281 togglegrid->show (); | 298 togglegrid->show (); |
299 panzoom->show (); | |
300 rotate->show (); | |
282 | 301 |
283 set_name (); | 302 set_name (); |
284 resizable (canvas); | 303 resizable (canvas); |
285 size_range (4*status_h, 2*status_h); | 304 size_range (4*status_h, 2*status_h); |
286 | 305 gui_mode = 1; |
287 } | 306 } |
288 | 307 |
289 ~plot_window (void) | 308 ~plot_window (void) |
290 { | 309 { |
291 canvas->hide (); | 310 canvas->hide (); |
326 std::string window_label; | 345 std::string window_label; |
327 | 346 |
328 // Mod keys status | 347 // Mod keys status |
329 int shift; | 348 int shift; |
330 | 349 |
350 // Interactive Mode | |
351 // 1...pan/zoom, 2...rotate/zoom | |
352 int gui_mode; | |
353 | |
331 // Figure properties. | 354 // Figure properties. |
332 figure::properties& fp; | 355 figure::properties& fp; |
333 | 356 |
334 // Status area height. | 357 // Status area height. |
335 static const int status_h = 20; | 358 static const int status_h = 20; |
353 if (widg == autoscale) | 376 if (widg == autoscale) |
354 axis_auto (); | 377 axis_auto (); |
355 | 378 |
356 if (widg == togglegrid) | 379 if (widg == togglegrid) |
357 toggle_grid (); | 380 toggle_grid (); |
381 | |
382 if (widg == panzoom) | |
383 gui_mode = 1; | |
384 | |
385 if (widg == rotate) | |
386 gui_mode = 2; | |
358 | 387 |
359 if (widg == help) | 388 if (widg == help) |
360 fl_message ("%s", help_text); | 389 fl_message ("%s", help_text); |
361 } | 390 } |
362 | 391 |
363 OpenGL_fltk* canvas; | 392 OpenGL_fltk* canvas; |
364 Fl_Button* autoscale; | 393 Fl_Button* autoscale; |
365 Fl_Button* togglegrid; | 394 Fl_Button* togglegrid; |
395 Fl_Button* panzoom; | |
396 Fl_Button* rotate; | |
366 Fl_Button* help; | 397 Fl_Button* help; |
367 Fl_Output* status; | 398 Fl_Output* status; |
368 | 399 |
369 void axis_auto (void) | 400 void axis_auto (void) |
370 { | 401 { |
380 octave_value_list args; | 411 octave_value_list args; |
381 args(0) = fp.get_currentaxes ().as_octave_value (); | 412 args(0) = fp.get_currentaxes ().as_octave_value (); |
382 feval ("grid", args); | 413 feval ("grid", args); |
383 mark_modified (); | 414 mark_modified (); |
384 } | 415 } |
385 | 416 |
386 void pixel2pos | 417 void pixel2pos |
387 (graphics_handle ax, int px, int py, double& xx, double& yy) const | 418 (graphics_handle ax, int px, int py, double& xx, double& yy) const |
388 { | 419 { |
389 pixel2pos ( gh_manager::get_object (ax), px, py, xx, yy); | 420 pixel2pos ( gh_manager::get_object (ax), px, py, xx, yy); |
390 } | 421 } |
439 void pixel2status (graphics_object ax, int px0, int py0, | 470 void pixel2status (graphics_object ax, int px0, int py0, |
440 int px1 = -1, int py1 = -1) | 471 int px1 = -1, int py1 = -1) |
441 { | 472 { |
442 double x0, y0, x1, y1; | 473 double x0, y0, x1, y1; |
443 std::stringstream cbuf; | 474 std::stringstream cbuf; |
444 | 475 cbuf.precision (4); |
476 cbuf.width (6); | |
445 pixel2pos (ax, px0, py0, x0, y0); | 477 pixel2pos (ax, px0, py0, x0, y0); |
446 cbuf << "[" << x0 << ", " << y0 << "]"; | 478 cbuf << "[" << x0 << ", " << y0 << "]"; |
447 if (px1 >= 0) | 479 if (px1 >= 0) |
448 { | 480 { |
449 pixel2pos (ax, px1, py1, x1, y1); | 481 pixel2pos (ax, px1, py1, x1, y1); |
452 | 484 |
453 status->value (cbuf.str ().c_str ()); | 485 status->value (cbuf.str ().c_str ()); |
454 status->redraw (); | 486 status->redraw (); |
455 } | 487 } |
456 | 488 |
489 void view2status (graphics_object ax) | |
490 { | |
491 if (ax && ax.isa ("axes")) | |
492 { | |
493 axes::properties& ap = | |
494 dynamic_cast<axes::properties&> (ax.get_properties ()); | |
495 std::stringstream cbuf; | |
496 cbuf.precision (4); | |
497 cbuf.width (6); | |
498 Matrix v (1,2,0); | |
499 v = ap.get("view").matrix_value(); | |
500 cbuf << "[azimuth: " << v(0) << ", elevation: " << v(1) << "]"; | |
501 | |
502 status->value (cbuf.str ().c_str ()); | |
503 status->redraw (); | |
504 } | |
505 } | |
506 | |
457 void set_currentpoint (int px, int py) | 507 void set_currentpoint (int px, int py) |
458 { | 508 { |
459 Matrix pos (1,2,0); | 509 Matrix pos (1,2,0); |
460 pos(0) = px; | 510 pos(0) = px; |
461 pos(1) = h () - status_h - py; | 511 pos(1) = h () - status_h - py; |
581 | 631 |
582 case 'g': | 632 case 'g': |
583 case 'G': | 633 case 'G': |
584 toggle_grid (); | 634 toggle_grid (); |
585 break; | 635 break; |
636 | |
637 case 'p': | |
638 case 'P': | |
639 gui_mode = 1; | |
640 break; | |
641 | |
642 case 'r': | |
643 case 'R': | |
644 gui_mode = 2; | |
645 break; | |
586 } | 646 } |
587 } | 647 } |
588 break; | 648 break; |
589 | 649 |
590 case FL_KEYUP: | 650 case FL_KEYUP: |
622 if (Fl::event_button () == 1 || Fl::event_button () == 3) | 682 if (Fl::event_button () == 1 || Fl::event_button () == 3) |
623 return 1; | 683 return 1; |
624 break; | 684 break; |
625 | 685 |
626 case FL_DRAG: | 686 case FL_DRAG: |
627 pixel2status (ax0, px0, py0, Fl::event_x (), Fl::event_y ()); | |
628 if (fp.get_windowbuttonmotionfcn ().is_defined ()) | 687 if (fp.get_windowbuttonmotionfcn ().is_defined ()) |
629 { | 688 { |
630 set_currentpoint (Fl::event_x (), Fl::event_y ()); | 689 set_currentpoint (Fl::event_x (), Fl::event_y ()); |
631 fp.execute_windowbuttonmotionfcn (); | 690 fp.execute_windowbuttonmotionfcn (); |
632 } | 691 } |
633 | 692 |
634 if (Fl::event_button () == 1) | 693 if (Fl::event_button () == 1) |
635 { | 694 { |
636 if (ax0 && ax0.isa ("axes")) | 695 if (ax0 && ax0.isa ("axes")) |
637 { | 696 { |
697 if (gui_mode == 1) | |
698 pixel2status (ax0, px0, py0, Fl::event_x (), Fl::event_y ()); | |
699 else | |
700 view2status (ax0); | |
638 axes::properties& ap = | 701 axes::properties& ap = |
639 dynamic_cast<axes::properties&> (ax0.get_properties ()); | 702 dynamic_cast<axes::properties&> (ax0.get_properties ()); |
640 | 703 |
641 double x0, y0, x1, y1; | 704 double x0, y0, x1, y1; |
705 Matrix pos = fp.get_position ().matrix_value (); | |
642 pixel2pos (ax0, px0, py0, x0, y0); | 706 pixel2pos (ax0, px0, py0, x0, y0); |
643 pixel2pos (ax0, Fl::event_x (), Fl::event_y (), x1, y1); | 707 pixel2pos (ax0, Fl::event_x (), Fl::event_y (), x1, y1); |
708 | |
709 if (gui_mode == 1) | |
710 ap.translate_view (x0 - x1, y0 - y1); | |
711 else if (gui_mode == 2) | |
712 { | |
713 double daz, del; | |
714 daz = (Fl::event_x () - px0) / pos(2) * 360; | |
715 del = (Fl::event_y () - py0) / pos(3) * 360; | |
716 ap.rotate_view (del, daz); | |
717 } | |
718 | |
644 px0 = Fl::event_x (); | 719 px0 = Fl::event_x (); |
645 py0 = Fl::event_y (); | 720 py0 = Fl::event_y (); |
646 | |
647 ap.translate_view (x0 - x1, y0 - y1); | |
648 mark_modified (); | 721 mark_modified (); |
649 } | 722 } |
650 return 1; | 723 return 1; |
651 } | 724 } |
652 else if (Fl::event_button () == 3) | 725 else if (Fl::event_button () == 3) |
653 { | 726 { |
727 pixel2status (ax0, px0, py0, Fl::event_x (), Fl::event_y ()); | |
654 Matrix zoom_box (1,4,0); | 728 Matrix zoom_box (1,4,0); |
655 zoom_box (0) = px0; | 729 zoom_box (0) = px0; |
656 zoom_box (1) = py0; | 730 zoom_box (1) = py0; |
657 zoom_box (2) = Fl::event_x (); | 731 zoom_box (2) = Fl::event_x (); |
658 zoom_box (3) = Fl::event_y (); | 732 zoom_box (3) = Fl::event_y (); |