51 #define WIN32_LEAN_AND_MEAN
55 #include <FL/Fl_Box.H>
56 #include <FL/Fl_Button.H>
57 #include <FL/Fl_Choice.H>
58 #include <FL/Fl_File_Chooser.H>
59 #include <FL/Fl_Gl_Window.H>
60 #include <FL/Fl_Menu_Bar.H>
61 #include <FL/Fl_Menu_Button.H>
62 #include <FL/Fl_Output.H>
63 #include <FL/Fl_Window.H>
64 #include <FL/fl_ask.H>
65 #include <FL/fl_draw.H>
87 #define FLTK_GRAPHICS_TOOLKIT_NAME "fltk"
90 static double fltk_maxtime = 1e-2;
92 const char* help_text =
"\
101 mouse wheel - zoom\n\
102 right drag - rectangle zoom\n\
103 left double click - autoscale\n\
106 class OpenGL_fltk :
public Fl_Gl_Window
109 OpenGL_fltk (
int xx,
int yy,
int ww,
int hh,
double num)
110 : Fl_Gl_Window (xx, yy, ww, hh, 0), number (num), renderer (),
111 in_zoom (false), zoom_box (), print_mode (false)
114 mode (FL_DEPTH | FL_DOUBLE);
117 ~OpenGL_fltk (
void) { }
126 bool zoom (
void) {
return in_zoom; }
127 void set_zoom_box (
const Matrix& zb) { zoom_box = zb; }
129 void print (
const std::string& cmd,
const std::string& term)
136 void resize (
int xx,
int yy,
int ww,
int hh)
138 Fl_Gl_Window::resize (xx, yy, ww, hh);
139 setup_viewport (ww, hh);
143 bool renumber (
double new_number)
147 if (number != new_number)
164 std::string print_cmd;
165 std::string print_term;
167 void setup_viewport (
int ww,
int hh)
169 glMatrixMode (GL_PROJECTION);
171 glViewport (0, 0, ww, hh);
179 setup_viewport (
w (), h ());
186 glps_renderer rend (fp, print_term);
194 error (
"fltk: printing not available without gl2ps library");
207 void zoom_box_vertex (
void)
209 glVertex2d (zoom_box(0), h () - zoom_box(1));
210 glVertex2d (zoom_box(0), h () - zoom_box(3));
211 glVertex2d (zoom_box(2), h () - zoom_box(3));
212 glVertex2d (zoom_box(2), h () - zoom_box(1));
213 glVertex2d (zoom_box(0), h () - zoom_box(1));
220 glMatrixMode (GL_MODELVIEW);
223 glMatrixMode (GL_PROJECTION);
225 gluOrtho2D (0.0,
w (), 0.0, h ());
227 glPushAttrib (GL_DEPTH_BUFFER_BIT | GL_CURRENT_BIT);
228 glDisable (GL_DEPTH_TEST);
230 glBegin (GL_POLYGON);
231 glColor4f (0.45, 0.62, 0.81, 0.1);
235 glBegin (GL_LINE_STRIP);
237 glColor4f (0.45, 0.62, 0.81, 0.9);
245 int handle (
int event)
247 int retval = Fl_Gl_Window::handle (event);
252 window ()->cursor (FL_CURSOR_CROSS);
256 window ()->cursor (FL_CURSOR_DEFAULT);
265 static double Vwheel_zoom_speed = 0.05;
267 static enum { pan_zoom, rotate_zoom, none } gui_mode;
269 void script_cb (Fl_Widget*,
void* data)
278 fltk_uimenu (
int xx,
int yy,
int ww,
int hh)
281 Fl_Menu_Bar (xx, yy, ww, hh);
284 int items_to_show (
void)
287 int len = menubar->size ();
289 for (
int t = 0; t < len; t++ )
291 const Fl_Menu_Item *m =
static_cast<const Fl_Menu_Item*
> (&
292 (menubar->menu ()[t]));
293 if (m->label () && m->visible ())
310 bool is_visible (
void)
312 return menubar->visible ();
315 int find_index_by_name (
const std::string& findname)
323 std::string menupath;
324 for (
int t = 0; t < menubar->size (); t++ )
326 Fl_Menu_Item *m =
const_cast<Fl_Menu_Item*
> (&(menubar->menu ()[t]));
330 if (!menupath.empty ())
332 menupath += m->label ();
334 if (menupath.compare (findname) == 0 )
342 std::size_t idx = menupath.find_last_of (
"/");
343 if (idx != std::string::npos)
344 menupath.erase (idx);
350 std::string itempath = menupath;
351 if (!itempath.empty ())
353 itempath += m->label ();
355 if (itempath.compare (findname) == 0)
365 Matrix retval = do_find_uimenu_children (uimenu_childs);
372 Matrix retval = do_find_uimenu_children (uimenu_childs);
376 Matrix do_find_uimenu_children (
Matrix uimenu_childs)
const
389 uimenu_childs(k) = uimenu_childs(ii);
396 uimenu_childs.
resize (k, 1);
403 retval(ii) = uimenu_childs (sidx(ii));
411 int idx = find_index_by_name (fltk_label.c_str ());
414 menubar->remove (idx);
420 if (!fltk_label.empty ())
422 Fl_Menu_Item* item =
const_cast<Fl_Menu_Item*
> (menubar->find_item (
423 fltk_label.c_str ()));
427 if (acc.length () > 0)
429 int key = FL_CTRL + acc[0];
430 item->shortcut (key);
439 if (!fltk_label.empty ())
441 Fl_Menu_Item* item =
const_cast<Fl_Menu_Item*
> (menubar->find_item (
442 fltk_label.c_str ()));
446 item->callback (static_cast<Fl_Callback*> (script_cb),
447 static_cast<void*> (&uimenup));
449 item->callback (0, static_cast<void*> (0));
457 if (!fltk_label.empty ())
459 Fl_Menu_Item* item =
const_cast<Fl_Menu_Item*
> (menubar->find_item (
460 fltk_label.c_str ()));
474 if (!fltk_label.empty ())
476 Fl_Menu_Item* item =
const_cast<Fl_Menu_Item*
> (menubar->find_item (
477 fltk_label.c_str ()));
482 uchar r =
static_cast<uchar
> (
gnulib::floor (rgb (0) * 255));
483 uchar g =
static_cast<uchar
> (
gnulib::floor (rgb (1) * 255));
484 uchar b =
static_cast<uchar
> (
gnulib::floor (rgb (2) * 255));
486 item->labelcolor (fl_rgb_color (r, g, b));
497 if (!fltk_label.empty ())
499 int itemflags = 0, idx;
500 int curr_idx = find_index_by_name (fltk_label.c_str ());
502 for (idx = curr_idx - 1; idx >= 0; idx--)
505 =
const_cast<Fl_Menu_Item*
> (&menubar->menu () [idx]);
506 itemflags = item->flags;
511 if (idx >= 0 && idx < menubar->
size ())
515 if (idx >= 0 && !(itemflags & FL_SUBMENU))
516 menubar->mode (idx, itemflags | FL_MENU_DIVIDER);
519 menubar->mode (idx, itemflags & (~FL_MENU_DIVIDER));
527 if (!fltk_label.empty ())
530 =
const_cast<Fl_Menu_Item*
> (menubar->find_item (fltk_label.c_str ()));
546 if (!fltk_label.empty ())
548 bool item_added =
false;
551 const Fl_Menu_Item* item
552 = menubar->find_item (fltk_label.c_str ());
557 std::size_t idx1 = fltk_label.find_last_of (
"(");
558 std::size_t idx2 = fltk_label.find_last_of (
")");
559 int len = idx2 - idx1;
563 std::string valstr = fltk_label.substr (idx1 + 1, len - 1);
564 fltk_label.erase (idx1, len + 1);
565 val = atoi (valstr.c_str ());
566 if (val > 0 && val < 99)
569 std::ostringstream valstream;
571 fltk_label +=
"(" + valstream.str () +
")";
575 Matrix uimenu_ch = find_uimenu_children (uimenup);
576 int len = uimenu_ch.
numel ();
581 flags += FL_MENU_TOGGLE + FL_MENU_VALUE;
582 menubar->add (fltk_label.c_str (), 0, 0, 0, flags);
593 Matrix kids = find_uimenu_children (uimenup);
598 update_foregroundcolor (uimenup);
599 update_callback (uimenup);
600 update_accelerator (uimenup);
601 update_enable (uimenup);
602 update_visible (uimenup);
603 update_seperator (uimenup);
619 Matrix kids = find_uimenu_children (figp);
635 template <
class T_prop>
636 void remove_from_menu (T_prop& prop)
639 std::string
type = prop.get_type ();
640 kids = find_uimenu_children (prop);
651 remove_from_menu (kprop);
655 if (type.compare (
"uimenu") == 0)
656 delete_entry (dynamic_cast<uimenu::properties&> (prop));
657 else if (type.compare (
"figure") == 0)
670 fltk_uimenu (
const fltk_uimenu&);
672 fltk_uimenu operator = (
const fltk_uimenu&);
674 Fl_Menu_Bar* menubar;
677 class plot_window :
public Fl_Window
679 friend class fltk_uimenu;
682 : Fl_Window (xx, yy - menu_h, ww, hh + menu_h + status_h,
"octave"),
683 window_label (), shift (0), ndim (2), fp (xfp), canvas (0),
684 autoscale (0), togglegrid (0), panzoom (0), rotate (0), help (0),
685 status (0), ax_obj (), pos_x (0), pos_y (0)
687 callback (window_close, static_cast<void*> (
this));
688 size_range (4*status_h, 2*status_h);
703 canvas =
new OpenGL_fltk (0, menu_h, ww, hh, number ());
705 uimenu =
new fltk_uimenu (0, 0, ww, menu_h);
712 bottom =
new Fl_Box (0, yy, ww, status_h);
713 bottom->box (FL_FLAT_BOX);
717 autoscale =
new Fl_Button (0, yy, status_h, status_h,
"A");
718 autoscale->callback (button_callback, static_cast<void*> (
this));
719 autoscale->tooltip (
"Autoscale");
721 togglegrid =
new Fl_Button (status_h, yy, status_h,
723 togglegrid->callback (button_callback, static_cast<void*> (
this));
724 togglegrid->tooltip (
"Toggle Grid");
726 panzoom =
new Fl_Button (2 * status_h, yy, status_h,
728 panzoom->callback (button_callback, static_cast<void*> (
this));
729 panzoom->tooltip (
"Mouse Pan/Zoom");
731 rotate =
new Fl_Button (3 * status_h, yy, status_h,
733 rotate->callback (button_callback, static_cast<void*> (
this));
734 rotate->tooltip (
"Mouse Rotate");
737 rotate->deactivate ();
739 help =
new Fl_Button (4 * status_h, yy, status_h,
741 help->callback (button_callback, static_cast<void*> (
this));
742 help->tooltip (
"Help");
744 status =
new Fl_Output (5 * status_h, yy,
745 ww > 2*status_h ? ww - status_h : 0,
748 status->textcolor (FL_BLACK);
749 status->color (FL_GRAY);
750 status->textfont (FL_COURIER);
751 status->textsize (10);
752 status->box (FL_ENGRAVED_BOX);
755 canvas->mode (FL_DEPTH | FL_DOUBLE );
756 if (fp.is_visible ())
766 if (fp.get_currentaxes ().ok ())
782 gui_mode = (ndim == 3 ? rotate_zoom : pan_zoom);
784 if (
uimenu->items_to_show ())
798 double number (
void) {
return fp.get___myhandle__ ().value (); }
800 void renumber (
double new_number)
804 if (canvas->renumber (new_number))
808 error (
"unable to renumber figure");
811 void print (
const std::string& cmd,
const std::string& term)
813 canvas->print (cmd, term);
818 Fl::wait (fltk_maxtime);
821 void show_menubar (
void)
823 if (!
uimenu->is_visible ())
831 void hide_menubar (
void)
833 if (
uimenu->is_visible ())
857 uimenu->remove_from_menu (uimenup);
861 uimenu->update_visible (uimenup);
865 uimenu->update_accelerator (uimenup);
869 uimenu->update_callback (uimenup);
873 uimenu->add_to_menu (figp);
877 uimenu->update_enable (uimenup);
881 uimenu->update_foregroundcolor (uimenup);
885 uimenu->add_to_menu (figp);
889 uimenu->add_to_menu (figp);
893 uimenu->update_seperator (uimenup);
897 if (
uimenu->items_to_show ())
906 void show_canvas (
void)
908 if (fp.is_visible ())
911 canvas->make_current ();
915 void hide_canvas (
void)
920 void mark_modified (
void)
922 damage (FL_DAMAGE_ALL);
923 canvas->damage (FL_DAMAGE_ALL);
928 else if (ndim == 2 && gui_mode == rotate_zoom)
930 rotate->deactivate ();
937 window_label = fp.get_title ();
938 label (window_label.c_str ());
945 plot_window (
const plot_window&);
947 plot_window& operator = (
const plot_window&);
951 std::string window_label;
963 static const int status_h = 20;
966 static const int menu_h = 20;
969 static void window_close (Fl_Widget*,
void* data)
972 args(0) =
static_cast<plot_window*
> (data)->number ();
973 feval (
"close", args);
977 static void button_callback (Fl_Widget* ww,
void* data)
979 static_cast<plot_window*
> (data)->button_press (ww, data);
982 void button_press (Fl_Widget* widg,
void*)
984 if (widg == autoscale)
987 if (widg == togglegrid)
993 if (widg == rotate && ndim == 3)
994 gui_mode = rotate_zoom;
997 fl_message (
"%s", help_text);
1001 OpenGL_fltk* canvas;
1003 Fl_Button* autoscale;
1004 Fl_Button* togglegrid;
1013 void axis_auto (
void)
1016 args(0) = fp.get_currentaxes ().as_octave_value ();
1018 feval (
"axis", args);
1022 void toggle_grid (
void)
1025 if (fp.get_currentaxes ().ok ())
1026 args(0) = fp.get_currentaxes ().as_octave_value ();
1028 feval (
"grid", args);
1032 void pixel2pos (
const graphics_handle& ax,
int px,
int py,
double& xx,
1041 if (ax && ax.
isa (
"axes"))
1053 Matrix kids = fp.get_children ();
1054 int len = kids.
length ();
1056 for (
int k = 0; k < len; k++)
1068 if (bb(0) <= px && px < (bb(0)+bb(2))
1069 && bb(1) <= py && py < (bb(1)+bb(3)))
1076 return fp.get_currentaxes ();
1080 int px1 = -1,
int py1 = -1)
1086 int px1 = -1,
int py1 = -1)
1088 double x0, y0, x1, y1;
1090 std::stringstream cbuf;
1093 pixel2pos (ax, px0, py0, x0, y0);
1094 cbuf <<
"[" << x0 <<
", " << y0 <<
"]";
1097 pixel2pos (ax, px1, py1, x1, y1);
1098 cbuf <<
" -> ["<< x1 <<
", " << y1 <<
"]";
1101 status->value (cbuf.str ().c_str ());
1107 if (ax && ax.
isa (
"axes"))
1111 std::stringstream cbuf;
1116 cbuf <<
"[azimuth: " << v(0) <<
", elevation: " << v(1) <<
"]";
1118 status->value (cbuf.str ().c_str ());
1123 void set_currentpoint (
int px,
int py)
1125 if (!fp.is_beingdeleted ())
1129 pos(1) = h () - (py + status_h + menu_dy ());
1130 fp.set_currentpoint (pos);
1146 pixel2pos (ax, px, py, xx, yy);
1161 if (
uimenu->is_visible ())
1167 int key2shift (
int key)
1169 if (key == FL_Shift_L || key == FL_Shift_R)
1172 if (key == FL_Control_L || key == FL_Control_R)
1175 if (key == FL_Alt_L || key == FL_Alt_R)
1178 if (key == FL_Meta_L || key == FL_Meta_R)
1184 int key2ascii (
int key)
1186 if (key < 256)
return key;
1187 if (key == FL_Tab)
return '\t';
1188 if (key == FL_Enter)
return 0x0a;
1189 if (key == FL_BackSpace)
return 0x08;
1190 if (key == FL_Escape)
return 0x1b;
1195 Cell modifier2cell ()
1199 if (shift & FL_SHIFT)
1200 mod.
append (std::string (
"shift"));
1201 if (shift & FL_CTRL)
1202 mod.
append (std::string (
"control"));
1203 if (shift & FL_ALT || shift & FL_META)
1204 mod.
append (std::string (
"alt"));
1209 void resize (
int xx,
int yy,
int ww,
int hh)
1211 Fl_Window::resize (xx, yy, ww, hh);
1215 pos(1) = yy + menu_dy ();
1217 pos(3) = hh - menu_dy () - status_h;
1219 fp.set_boundingbox (pos,
true);
1225 Matrix pos = fp.get_boundingbox (
true);
1226 int canvas_h = pos(3);
1227 int canvas_w = pos(2);
1228 int canvas_y = menu_dy ();
1229 int toolbar_y = menu_dy () + canvas_h;
1230 pos(1) = pos(1) - menu_dy ();
1231 pos(3) = pos(3) + menu_dy () + status_h;
1233 Fl_Window::resize (pos(0), pos(1), pos(2), pos(3));
1235 bottom->resize (0, toolbar_y, status_h, status_h);
1236 autoscale->resize (0, toolbar_y, status_h, status_h);
1237 togglegrid->resize (status_h, toolbar_y, status_h, status_h);
1238 panzoom->resize (2 * status_h, toolbar_y, status_h, status_h);
1239 rotate->resize (3 * status_h, toolbar_y, status_h, status_h);
1240 help->resize (4 * status_h, toolbar_y, status_h, status_h);
1241 status->resize (5 * status_h, toolbar_y, pos(2) - 4 * status_h, status_h);
1242 if (canvas->valid ())
1243 canvas->resize (0, canvas_y, canvas_w, canvas_h);
1245 return Fl_Window::draw ();
1248 int handle (
int event)
1253 int retval = Fl_Window::handle (event);
1256 if (!Fl::event_inside (canvas))
1259 if (!fp.is_beingdeleted ())
1265 int key = Fl::event_key ();
1267 shift |= key2shift (key);
1268 int key_a = key2ascii (key);
1269 if (key_a && fp.get_keypressfcn ().is_defined ())
1275 fp.execute_keypressfcn (evt);
1291 gui_mode = pan_zoom;
1296 gui_mode = rotate_zoom;
1304 int key = Fl::event_key ();
1306 shift &= (~key2shift (key));
1307 int key_a = key2ascii (key);
1308 if (key_a && fp.get_keyreleasefcn ().is_defined ())
1314 fp.execute_keyreleasefcn (evt);
1320 pixel2status (pixel2axes_or_ca (Fl::event_x (),
1321 Fl::event_y () - menu_dy ()),
1322 Fl::event_x (), Fl::event_y () - menu_dy ());
1326 pos_x = Fl::event_x ();
1327 pos_y = Fl::event_y () - menu_dy ();
1329 set_currentpoint (Fl::event_x (), Fl::event_y () - menu_dy ());
1331 gh = pixel2axes_or_ca (pos_x, pos_y);
1336 set_axes_currentpoint (ax_obj, pos_x, pos_y);
1339 fp.execute_windowbuttondownfcn (Fl::event_button());
1341 if (Fl::event_button () == 1 || Fl::event_button () == 3)
1347 if (fp.get_windowbuttonmotionfcn ().is_defined ())
1349 set_currentpoint (Fl::event_x (), Fl::event_y () - menu_dy ());
1350 fp.execute_windowbuttonmotionfcn ();
1353 if (Fl::event_button () == 1)
1355 if (ax_obj && ax_obj.isa (
"axes"))
1357 if (gui_mode == pan_zoom)
1358 pixel2status (ax_obj, pos_x, pos_y,
1360 Fl::event_y () - menu_dy ());
1362 view2status (ax_obj);
1365 (ax_obj.get_properties ());
1367 double x0, y0, x1, y1;
1368 Matrix pos = fp.get_boundingbox (
true);
1369 pixel2pos (ax_obj, pos_x, pos_y, x0, y0);
1370 pixel2pos (ax_obj, Fl::event_x (),
1371 Fl::event_y () - menu_dy (),
1374 if (gui_mode == pan_zoom)
1376 else if (gui_mode == rotate_zoom)
1379 daz = (Fl::event_x () - pos_x) / pos(2) * 360;
1380 del = (Fl::event_y () - menu_dy () - pos_y)
1385 pos_x = Fl::event_x ();
1386 pos_y = Fl::event_y () - menu_dy ();
1391 else if (Fl::event_button () == 3)
1393 pixel2status (ax_obj, pos_x, pos_y,
1394 Fl::event_x (), Fl::event_y () - menu_dy ());
1396 zoom_box (0) = pos_x;
1397 zoom_box (1) = pos_y;
1398 zoom_box (2) = Fl::event_x ();
1399 zoom_box (3) = Fl::event_y () - menu_dy ();
1400 canvas->set_zoom_box (zoom_box);
1401 canvas->zoom (
true);
1413 if (ax && ax.
isa (
"axes"))
1419 const double factor =
1420 (Fl::event_dy () > 0) ? 1 / (1.0 - Vwheel_zoom_speed)
1421 : 1.0 - Vwheel_zoom_speed;
1425 pixel2pos (ax, Fl::event_x (), Fl::event_y () - menu_dy (),
1435 if (fp.get_windowbuttonupfcn ().is_defined ())
1437 set_currentpoint (Fl::event_x (), Fl::event_y () - menu_dy ());
1438 fp.execute_windowbuttonupfcn ();
1441 if (Fl::event_button () == 1)
1443 if ( Fl::event_clicks () == 1)
1445 if (ax_obj && ax_obj.isa (
"axes"))
1448 (ax_obj.get_properties ());
1456 if (Fl::event_button () == 3)
1459 if (canvas->zoom ())
1461 canvas->zoom (
false);
1463 if (ax_obj && ax_obj.isa (
"axes"))
1466 (ax_obj.get_properties ());
1467 pixel2pos (ax_obj, pos_x, pos_y, x0, y0);
1468 int pos_x1 = Fl::event_x ();
1469 int pos_y1 = Fl::event_y () - menu_dy ();
1470 pixel2pos (ax_obj, pos_x1, pos_y1, x1, y1);
1473 int dx =
abs (pos_x - pos_x1);
1474 int dy =
abs (pos_y - pos_y1);
1476 if ((dx > 4) && (dy > 4))
1512 class figure_manager
1516 static bool instance_ok (
void)
1521 instance =
new figure_manager ();
1525 ::error (
"unable to create figure_manager object!");
1533 ~figure_manager (
void)
1538 static void close_all (
void)
1541 instance->do_close_all ();
1547 instance->do_new_window (fp);
1550 static void delete_window (
int idx)
1553 instance->do_delete_window (idx);
1556 static void delete_window (
const std::string& idx_str)
1558 delete_window (str2idx (idx_str));
1561 static void renumber_figure (
const std::string& idx_str,
double new_number)
1564 instance->do_renumber_figure (str2idx (idx_str), new_number);
1567 static void toggle_window_visibility (
int idx,
bool is_visible)
1570 instance->do_toggle_window_visibility (idx, is_visible);
1573 static void toggle_window_visibility (
const std::string& idx_str,
1576 toggle_window_visibility (str2idx (idx_str), is_visible);
1579 static void mark_modified (
int idx)
1582 instance->do_mark_modified (idx);
1587 mark_modified (hnd2idx (gh));
1590 static void set_name (
int idx)
1593 instance->do_set_name (idx);
1596 static void set_name (
const std::string& idx_str)
1598 set_name (str2idx (idx_str));
1603 return instance_ok () ? instance->do_get_size (idx) :
Matrix ();
1612 const std::string& term)
1615 instance->do_print (hnd2idx (gh), cmd, term);
1622 instance->do_uimenu_update (hnd2idx (figh), uimenuh,
id);
1629 instance->do_update_canvas (hnd2idx (gh), ca);
1632 static void toggle_menubar_visibility (
int fig_idx,
bool menubar_is_figure)
1635 instance->do_toggle_menubar_visibility (fig_idx, menubar_is_figure);
1638 static void toggle_menubar_visibility (
const std::string& fig_idx_str,
1639 bool menubar_is_figure)
1641 toggle_menubar_visibility (str2idx (fig_idx_str), menubar_is_figure);
1646 static figure_manager *instance;
1648 figure_manager (
void) { }
1651 figure_manager (
const figure_manager&);
1652 figure_manager& operator = (
const figure_manager&);
1656 static int curr_index;
1657 typedef std::map<int, plot_window*> window_map;
1658 typedef window_map::iterator wm_iterator;;
1661 static std::string fltk_idx_header;
1663 void do_close_all (
void)
1666 for (win = windows.begin (); win != windows.end (); win++)
1673 int idx = figprops2idx (fp);
1675 if (idx >= 0 && windows.find (idx) == windows.end ())
1684 idx2figprops (curr_index, fp);
1686 windows[curr_index++] =
new plot_window (x, y, w, h, fp);
1690 void do_delete_window (
int idx)
1692 wm_iterator win = windows.find (idx);
1694 if (win != windows.end ())
1697 windows.erase (win);
1701 void do_renumber_figure (
int idx,
double new_number)
1703 wm_iterator win = windows.find (idx);
1705 if (win != windows.end ())
1706 win->second->renumber (new_number);
1709 void do_toggle_window_visibility (
int idx,
bool is_visible)
1711 wm_iterator win = windows.find (idx);
1713 if (win != windows.end ())
1716 win->second->show ();
1718 win->second->hide ();
1720 win->second->redraw ();
1724 void do_toggle_menubar_visibility (
int fig_idx,
bool menubar_is_figure)
1726 wm_iterator win = windows.find (fig_idx);
1728 if (win != windows.end ())
1730 if (menubar_is_figure)
1731 win->second->show_menubar ();
1733 win->second->hide_menubar ();
1735 win->second->redraw ();
1739 void do_mark_modified (
int idx)
1741 wm_iterator win = windows.find (idx);
1743 if (win != windows.end ())
1744 win->second->mark_modified ();
1747 void do_set_name (
int idx)
1749 wm_iterator win = windows.find (idx);
1751 if (win != windows.end ())
1752 win->second->set_name ();
1755 Matrix do_get_size (
int idx)
1759 wm_iterator win = windows.find (idx);
1761 if (win != windows.end ())
1763 sz(0) = win->second->w ();
1764 sz(1) = win->second->h ();
1770 void do_print (
int idx,
const std::string& cmd,
const std::string& term)
1772 wm_iterator win = windows.find (idx);
1774 if (win != windows.end ())
1775 win->second->print (cmd, term);
1780 wm_iterator win = windows.find (idx);
1782 if (win != windows.end ())
1783 win->second->uimenu_update (gh,
id);
1788 wm_iterator win = windows.find (idx);
1790 if (win != windows.end ())
1793 win->second->show_canvas ();
1795 win->second->hide_canvas ();
1802 if (clstr.find (fltk_idx_header,0) == 0)
1804 std::istringstream istr (clstr.substr (fltk_idx_header.size ()));
1808 error (
"figure_manager: could not recognize fltk index");
1814 std::ostringstream ind_str;
1815 ind_str << fltk_idx_header << idx;
1829 error (
"figure_manager: figure is not fltk");
1833 static int hnd2idx (
double h)
1836 if (fobj && fobj.
isa (
"figure"))
1840 return figprops2idx (fp);
1842 error (
"figure_manager: H (= %g) is not a figure", h);
1848 return hnd2idx (fh.
value ());
1852 figure_manager *figure_manager::instance = 0;
1854 std::string figure_manager::fltk_idx_header=
"fltk index=";
1855 int figure_manager::curr_index = 1;
1860 __fltk_redraw__ (
void)
1866 if (obj && obj.
isa (
"root"))
1874 if (fobj && fobj.
isa (
"figure"))
1879 == FLTK_GRAPHICS_TOOLKIT_NAME)
1880 figure_manager::new_window (fp);
1896 fltk_graphics_toolkit (
void)
1898 input_event_hook_fcn_id ()
1901 ~fltk_graphics_toolkit (
void) { }
1903 bool is_valid (
void)
const {
return true; }
1907 if (go.
isa (
"figure")
1908 || go.
isa (
"uimenu"))
1910 if (go.
isa (
"uimenu"))
1921 if (go.
isa (
"figure"))
1936 std::string fltk_label = uimenup.
get_label ();
1938 if (go.
isa (
"uimenu"))
1939 fltk_label = dynamic_cast<const uimenu::properties&>
1943 else if (go.
isa (
"figure"))
1946 error (
"unexpected parent object\n");
1954 if (go.
isa (
"figure"))
1966 figure_manager::toggle_window_visibility (ov.
string_value (),
1971 figure_manager::toggle_menubar_visibility
1976 figure_manager::update_canvas (go.
get_handle (),
1989 figure_manager::renumber_figure (tmp, gh.
value ());
1990 figure_manager::set_name (tmp);
1996 else if (go.
isa (
"uimenu"))
1999 uimenu_set_fltk_label (go);
2008 figure_manager::mark_modified (go.
get_handle ());
2014 const std::string& term,
2015 const std::string& file_cmd,
bool ,
2016 const std::string& )
const
2018 figure_manager::print (go.
get_handle (), file_cmd, term);
2047 figure_manager::close_all ();
2056 Fl::wait (fltk_maxtime);
2062 input_event_hook_fcn_id = id;
2073 @deftypefn {Loadable Function} {} __fltk_redraw__ ()\n\
2074 Undocumented internal function.\n\
2080 error (
"__fltk_redraw__: not available without OpenGL and FLTK libraries");
2090 @deftypefn {Loadable Function} {} __init_fltk__ ()\n\
2091 Undocumented internal function.\n\
2096 error (
"__init_fltk__: no graphics DISPLAY available");
2097 else if (! toolkit_loaded)
2101 fltk_graphics_toolkit *fltk =
new fltk_graphics_toolkit ();
2104 toolkit_loaded =
true;
2110 fltk->set_input_event_hook_id (
id);
2113 error (
"__init_fltk__: not available without OpenGL and FLTK libraries");
2121 @deftypefn {Loadable Function} {@var{maxtime} =} __fltk_maxtime__ ()\n\
2122 @deftypefnx {Loadable Function} {} __fltk_maxtime__ (@var{maxtime})\n\
2123 Undocumented internal function.\n\
2131 if (args(0).is_real_scalar ())
2132 fltk_maxtime = args(0).double_value ();
2134 error (
"argument must be a real scalar");
2139 error (
"__fltk_maxtime__: not available without OpenGL and FLTK libraries");
2146 @deftypefn {Loadable Function} {@var{FLTK_available} =} __have_fltk__ ()\n\
2147 Undocumented internal function.\n\
2170 @deftypefn {Loadable Function} {@var{val} =} mouse_wheel_zoom ()\n\
2171 @deftypefnx {Loadable Function} {@var{old_val} =} mouse_wheel_zoom (@var{new_val})\n\
2172 @deftypefnx {Loadable Function} {} mouse_wheel_zoom (@var{new_val}, \"local\")\n\
2173 Query or set the mouse wheel zoom factor.\n\
2175 The zoom factor is a number in the range (0,1) which is the percentage of the\n\
2176 current axis limits that will be used when zooming. For example, if the\n\
2177 current x-axis limits are [0, 50] and @code{mouse_wheel_zoom} is 0.4 (40%),\n\
2178 then a zoom operation will change the limits by 20.\n\
2180 When called from inside a function with the @qcode{\"local\"} option, the\n\
2181 variable is changed locally for the function and any subroutines it calls. \n\
2182 The original variable value is restored when exiting the function.\n\
2184 This function is currently implemented only for the FLTK graphics toolkit.\n\
2185 @seealso{gui_mode}\n\
2191 error (
"mouse_wheel_zoom: not available without OpenGL and FLTK libraries");
2198 @deftypefn {Built-in Function} {@var{mode} =} gui_mode ()\n\
2199 @deftypefnx {Built-in Function} {} gui_mode (@var{mode})\n\
2200 Query or set the GUI mode for the current graphics toolkit.\n\
2201 The @var{mode} argument can be one of the following strings:\n\
2204 @item @qcode{\"2d\"}\n\
2205 Allows panning and zooming of current axes.\n\
2207 @item @qcode{\"3d\"}\n\
2208 Allows rotating and zooming of current axes.\n\
2210 @item @qcode{\"none\"}\n\
2211 Mouse inputs have no effect.\n\
2214 This function is currently implemented only for the FLTK graphics toolkit.\n\
2215 @seealso{mouse_wheel_zoom}\n\
2221 if (gui_mode == pan_zoom)
2223 else if (gui_mode == rotate_zoom)
2228 bool failed =
false;
2232 if (args(0).is_string ())
2234 mode_str = args(0).string_value ();
2237 gui_mode = pan_zoom;
2238 else if (mode_str.
compare (
"3d"))
2239 gui_mode = rotate_zoom;
2240 else if (mode_str.
compare (
"none"))
2250 error (
"MODE must be one of the strings: \"2D\", \"3D\", or \"none\"");
2254 error (
"gui_mode: not available without OpenGL and FLTK libraries");