37 #if defined (HAVE_CONFIG_H)
45 #if defined (HAVE_X_WINDOWS)
46 # include <X11/Xlib.h>
58 # define WIN32_LEAN_AND_MEAN
61 #if defined (HAVE_FLTK)
63 # include <FL/Fl_Box.H>
64 # include <FL/Fl_Button.H>
65 # include <FL/Fl_Choice.H>
66 # include <FL/Fl_File_Chooser.H>
67 # include <FL/Fl_Gl_Window.H>
68 # include <FL/names.h>
69 # include <FL/Fl_Menu_Bar.H>
70 # include <FL/Fl_Menu_Button.H>
71 # include <FL/Fl_Output.H>
72 # include <FL/Fl_Window.H>
73 # include <FL/fl_ask.H>
74 # include <FL/fl_draw.H>
109 #if defined (HAVE_FLTK)
111 #define FLTK_GRAPHICS_TOOLKIT_NAME "fltk"
113 const char *help_text =
"\
114 Keyboard Shortcuts\n\
122 mouse wheel - zoom\n\
123 right drag - rectangle zoom\n\
124 left double click - autoscale\n\
127 class OpenGL_fltk :
public Fl_Gl_Window
131 OpenGL_fltk (
int xx,
int yy,
int ww,
int hh,
double num)
132 : Fl_Gl_Window (xx, yy, ww, hh, nullptr), m_number (num),
133 m_glfcns (), m_renderer (m_glfcns), m_in_zoom (false), m_zoom_box ()
135 #if defined (HAVE_OPENGL)
138 mode (FL_DEPTH | FL_DOUBLE | FL_MULTISAMPLE);
147 OCTAVE_DISABLE_CONSTRUCT_COPY_MOVE (OpenGL_fltk)
149 ~OpenGL_fltk () =
default;
158 bool zoom () {
return m_in_zoom; }
159 void set_zoom_box (
const Matrix& zb) { m_zoom_box = zb; }
161 void print (
const std::string& cmd,
const std::string& term)
172 m_renderer.draw (gh_mgr.
get_object (m_number));
174 return m_renderer.get_pixels (
w (), h ());
177 void resize (
int xx,
int yy,
int ww,
int hh)
179 #if defined (HAVE_OPENGL)
181 Fl_Gl_Window::resize (xx, yy, ww, hh);
185 octave_unused_parameter (xx);
186 octave_unused_parameter (yy);
187 octave_unused_parameter (ww);
188 octave_unused_parameter (hh);
198 bool renumber (
double new_number)
202 if (m_number != new_number)
204 m_number = new_number;
215 octave::opengl_functions m_glfcns;
216 octave::opengl_renderer m_renderer;
225 #if defined (HAVE_OPENGL)
229 m_glfcns.glMatrixMode (GL_PROJECTION);
230 m_glfcns.glLoadIdentity ();
231 m_glfcns.glViewport (0, 0,
w (), h ());
236 m_renderer.draw (gh_mgr.
get_object (m_number));
253 Matrix overlaycolor (3, 1);
254 overlaycolor(0) = 0.45;
255 overlaycolor(1) = 0.62;
256 overlaycolor(2) = 0.81;
257 double overlayalpha = 0.1;
258 Matrix bordercolor = overlaycolor;
259 double borderalpha = 0.9;
260 double borderwidth = 1.5;
262 m_renderer.draw_zoom_box (
w (), h (),
263 m_zoom_box(0), m_zoom_box(1),
264 m_zoom_box(2), m_zoom_box(3),
265 overlaycolor, overlayalpha,
266 bordercolor, borderalpha, borderwidth);
269 int handle (
int event)
271 #if defined (HAVE_OPENGL)
276 cursor (FL_CURSOR_CROSS);
280 cursor (FL_CURSOR_DEFAULT);
284 return Fl_Gl_Window::handle (event);
288 octave_unused_parameter (event);
300 script_cb (Fl_Widget *,
void *data)
309 fltk_uimenu (
int xx,
int yy,
int ww,
int hh)
310 : m_menubar (new Fl_Menu_Bar (xx, yy, ww, hh))
313 OCTAVE_DISABLE_CONSTRUCT_COPY_MOVE (fltk_uimenu)
315 ~fltk_uimenu () =
default;
320 int len = m_menubar->size ();
322 for (
int t = 0; t <
len; t++)
324 const Fl_Menu_Item *
m
325 =
static_cast<const Fl_Menu_Item *
> (&(m_menubar->menu ()[t]));
327 if (
m->label () &&
m->visible ())
337 m_menubar->redraw ();
343 m_menubar->redraw ();
348 return m_menubar->visible ();
351 int find_index_by_name (
const std::string& findname)
359 std::string menupath;
360 for (
int t = 0; t < m_menubar->size (); t++)
362 Fl_Menu_Item *
m =
const_cast<Fl_Menu_Item *
> (&(m_menubar->menu ()[t]));
366 if (! menupath.empty ())
368 menupath +=
m->label ();
370 if (menupath == findname)
378 std::size_t idx = menupath.find_last_of (
'/');
379 if (idx != std::string::npos)
380 menupath.erase (idx);
386 std::string itempath = menupath;
387 if (! itempath.empty ())
389 itempath +=
m->label ();
391 if (itempath == findname)
401 Matrix retval = do_find_uimenu_children (uimenu_childs);
408 Matrix retval = do_find_uimenu_children (uimenu_childs);
412 Matrix do_find_uimenu_children (
Matrix uimenu_childs)
const
426 uimenu_childs(k) = uimenu_childs(ii);
431 uimenu_childs.
resize (k, 1);
438 retval(ii) = uimenu_childs (sidx(ii));
446 int idx = find_index_by_name (fltk_label.c_str ());
449 m_menubar->remove (idx);
455 if (! fltk_label.empty ())
457 Fl_Menu_Item *item =
const_cast<Fl_Menu_Item *
> (m_menubar->find_item (fltk_label.c_str ()));
462 if (acc.length () > 0)
464 int key = FL_CTRL + acc[0];
465 item->shortcut (key);
474 if (! fltk_label.empty ())
477 =
const_cast<Fl_Menu_Item *
> (m_menubar->find_item (fltk_label.c_str ()));
481 item->callback (
static_cast<Fl_Callback *
> (script_cb),
482 static_cast<void *
> (&uimenup));
484 item->callback (
nullptr,
static_cast<void *
> (
nullptr));
492 if (! fltk_label.empty ())
495 =
const_cast<Fl_Menu_Item *
> (m_menubar->find_item (fltk_label.c_str ()));
509 if (! fltk_label.empty ())
512 =
const_cast<Fl_Menu_Item *
> (m_menubar->find_item (fltk_label.c_str ()));
517 uchar
r =
static_cast<uchar
> (
std::floor (rgb (0) * 255));
518 uchar g =
static_cast<uchar
> (
std::floor (rgb (1) * 255));
519 uchar b =
static_cast<uchar
> (
std::floor (rgb (2) * 255));
521 item->labelcolor (fl_rgb_color (
r, g, b));
532 if (! fltk_label.empty ())
534 int itemflags = 0, idx;
535 int curr_idx = find_index_by_name (fltk_label.c_str ());
537 for (idx = curr_idx - 1; idx >= 0; idx--)
540 =
const_cast<Fl_Menu_Item *
> (&m_menubar->menu () [idx]);
541 itemflags = item->flags;
546 if (idx >= 0 && idx < m_menubar->size ())
550 if (! (itemflags & FL_SUBMENU))
551 m_menubar->mode (idx, itemflags | FL_MENU_DIVIDER);
554 m_menubar->mode (idx, itemflags & (~FL_MENU_DIVIDER));
562 if (! fltk_label.empty ())
565 =
const_cast<Fl_Menu_Item *
> (m_menubar->find_item (fltk_label.c_str ()));
587 if (! fltk_label.empty ())
589 bool item_added =
false;
592 const Fl_Menu_Item *item
593 = m_menubar->find_item (fltk_label.c_str ());
598 std::size_t idx1 = fltk_label.find_last_of (
'(');
599 std::size_t idx2 = fltk_label.find_last_of (
')');
600 int len = idx2 - idx1;
604 std::string valstr = fltk_label.substr (idx1 + 1,
len - 1);
605 fltk_label.erase (idx1,
len + 1);
606 val = atoi (valstr.c_str ());
607 if (val > 0 && val < 99)
610 std::ostringstream valstream;
612 fltk_label +=
'(' + valstream.str () +
')';
616 Matrix uimenu_ch = find_uimenu_children (uimenup);
622 flags += FL_MENU_TOGGLE + FL_MENU_VALUE;
623 m_menubar->add (fltk_label.c_str (),
624 0,
nullptr,
nullptr, flags);
628 while (! item_added);
635 std::vector<int> delayed_menus;
636 Matrix kids = find_uimenu_children (uimenup);
642 update_foregroundcolor (uimenup);
643 update_menuselectedfcn (uimenup);
644 update_accelerator (uimenup);
645 update_enable (uimenup);
646 update_visible (uimenup);
647 update_seperator (uimenup);
663 delayed_menus.push_back ((
len - (ii + 1)));
672 for (std::size_t ii = 0; ii < delayed_menus.size (); ii++)
681 update_position (kprop, ++count);
688 std::vector<int> delayed_menus;
689 Matrix kids = find_uimenu_children (figp);
709 delayed_menus.push_back ((
len - (ii + 1)));
713 update_position (kprop, ++count);
719 for (std::size_t ii = 0; ii < delayed_menus.size (); ii++)
728 update_position (kprop, ++count);
733 template <
typename T_prop>
734 void remove_from_menu (T_prop& prop)
737 std::string type = prop.get_type ();
738 kids = find_uimenu_children (prop);
751 remove_from_menu (kprop);
755 if (type ==
"uimenu")
757 else if (type ==
"figure")
763 Fl_Menu_Bar *m_menubar;
766 #if defined (HAVE_X_WINDOWS)
768 xerror_handler (Display *, XErrorEvent *)
774 class plot_window :
public Fl_Window
776 friend class fltk_uimenu;
782 : Fl_Window (xx, yy, ww, hh + MENU_H + STATUS_H + 2,
"octave"),
783 m_window_label (), m_fp (xfp), m_uimenu (nullptr), m_canvas (nullptr),
784 m_autoscale (nullptr), m_togglegrid (nullptr), m_panzoom (nullptr),
785 m_rotate (nullptr), m_help (nullptr), m_status (nullptr),
786 m_resize_dummy (nullptr), m_ax_obj (), m_pos_x (0), m_pos_y (0)
788 callback (window_close,
static_cast<void *
> (
this));
792 m_resize_dummy =
new Fl_Box (5 * STATUS_H, MENU_H,
793 ww - 5 * STATUS_H, hh);
797 resizable (m_resize_dummy);
807 m_uimenu =
new fltk_uimenu (0, 0, ww, MENU_H);
808 m_canvas =
new OpenGL_fltk (0, MENU_H, ww, hh, number ());
814 int toolbar_y = MENU_H + hh + 1;
815 m_status =
new Fl_Output (5 * STATUS_H, toolbar_y,
816 ww - 5 * STATUS_H, STATUS_H,
"");
818 m_status->textcolor (FL_BLACK);
819 m_status->color (FL_GRAY);
820 m_status->textfont (FL_COURIER);
821 m_status->textsize (10);
822 m_status->box (FL_ENGRAVED_BOX);
824 m_autoscale =
new Fl_Button (0, toolbar_y, STATUS_H, STATUS_H,
"A");
825 m_autoscale->callback (button_callback,
static_cast<void *
> (
this));
826 m_autoscale->tooltip (
"Autoscale");
828 m_togglegrid =
new Fl_Button (STATUS_H, toolbar_y, STATUS_H, STATUS_H,
"G");
829 m_togglegrid->callback (button_callback,
static_cast<void *
> (
this));
830 m_togglegrid->tooltip (
"Toggle Grid");
832 m_panzoom =
new Fl_Button (2* STATUS_H, toolbar_y, STATUS_H, STATUS_H,
"P");
833 m_panzoom->callback (button_callback,
static_cast<void *
> (
this));
834 m_panzoom->tooltip (
"Mouse Pan/Zoom");
836 m_rotate =
new Fl_Button (3 * STATUS_H, toolbar_y, STATUS_H, STATUS_H,
"R");
837 m_rotate->callback (button_callback,
static_cast<void *
> (
this));
838 m_rotate->tooltip (
"Mouse Rotate");
840 m_help =
new Fl_Button (4 * STATUS_H, toolbar_y, STATUS_H, STATUS_H,
"?");
841 m_help->callback (button_callback,
static_cast<void *
> (
this));
842 m_help->tooltip (
"Help");
847 m_uimenu->add_to_menu (m_fp);
848 if (m_fp.menubar_is (
"none") || ! m_uimenu->items_to_show ())
851 update_boundingbox (
internal);
853 if (m_fp.is_visible ())
865 #if defined (HAVE_X_WINDOWS)
866 std::string show_gui_msgs
867 = octave::sys::env::getenv (
"OCTAVE_SHOW_GUI_MESSAGES");
870 if (show_gui_msgs.empty ())
871 XSetErrorHandler (xerror_handler);
874 if (m_fp.get_currentaxes ().ok ())
881 OCTAVE_DISABLE_CONSTRUCT_COPY_MOVE (plot_window)
893 double number () {
return m_fp.get___myhandle__ ().value (); }
895 void renumber (
double new_number)
898 error (
"unable to renumber figure");
900 if (m_canvas->renumber (new_number))
904 void print (
const std::string& cmd,
const std::string& term)
906 m_canvas->print (cmd, term);
911 return m_canvas->get_pixels ();
917 update_toolbar_position ();
923 update_toolbar_position ();
944 m_uimenu->remove_from_menu (uimenup);
948 m_uimenu->update_visible (uimenup);
952 m_uimenu->update_accelerator (uimenup);
956 m_uimenu->update_menuselectedfcn (uimenup);
960 m_uimenu->add_to_menu (figp);
964 m_uimenu->update_enable (uimenup);
968 m_uimenu->update_foregroundcolor (uimenup);
972 m_uimenu->add_to_menu (figp);
976 m_uimenu->add_to_menu (figp);
980 m_uimenu->update_seperator (uimenup);
984 if (m_uimenu->items_to_show ())
993 if (! m_canvas->can_do ())
994 error (
"unable to plot due to insufficient OpenGL support");
995 else if (m_fp.is_visible ())
998 m_canvas->make_current ();
1011 void update_toolbar_position ()
1013 int old_canvas_h = m_canvas->h ();
1016 update_boundingbox (
true);
1017 m_canvas->resize (0, menu_dy (),
w (), old_canvas_h);
1019 int toolbar_y = m_canvas->h () + menu_dy () + 1;
1020 m_autoscale->position (0, toolbar_y);
1021 m_togglegrid->position (STATUS_H, toolbar_y);
1022 m_panzoom->position (2 * STATUS_H, toolbar_y);
1023 m_rotate->position (3 * STATUS_H, toolbar_y);
1024 m_help->position (4 * STATUS_H, toolbar_y);
1025 m_status->resize (5 * STATUS_H, toolbar_y,
1026 w () - 5 * STATUS_H, STATUS_H);
1034 pos(1) += menu_dy ();
1035 pos(3) -= menu_dy () + STATUS_H + 2;
1042 outerpos(1) -= menu_dy ();
1043 outerpos(3) += menu_dy () + STATUS_H + 2;
1052 void update_boundingbox (
bool internal)
1054 Matrix bb = m_fp.get_boundingbox (
internal);
1056 bb = position2outerposition (bb);
1057 resize (bb(0), bb(1), bb(2), bb(3));
1060 void mark_modified ()
1062 m_canvas->redraw ();
1067 m_window_label = m_fp.get_title ();
1068 label (m_window_label.c_str ());
1075 std::string m_window_label;
1081 static const int STATUS_H = 20;
1084 static const int MENU_H = 25;
1086 fltk_uimenu *m_uimenu;
1088 OpenGL_fltk *m_canvas;
1090 Fl_Button *m_autoscale;
1091 Fl_Button *m_togglegrid;
1092 Fl_Button *m_panzoom;
1093 Fl_Button *m_rotate;
1095 Fl_Output *m_status;
1097 Fl_Box *m_resize_dummy;
1105 static void window_close (Fl_Widget *,
void *data)
1110 args(0) =
static_cast<plot_window *
> (data)->number ();
1112 interp.
feval (
"close", args);
1116 static void button_callback (Fl_Widget *ww,
void *data)
1118 static_cast<plot_window *
> (data)->button_press (ww, data);
1121 void button_press (Fl_Widget *widg,
void *)
1123 if (widg == m_autoscale)
1125 else if (widg == m_togglegrid)
1127 else if (widg == m_panzoom)
1129 else if (widg == m_rotate)
1131 else if (widg == m_help)
1132 fl_message (
"%s", help_text);
1135 void set_on_ax_obj (
const std::string& name,
const std::string& value)
1138 if (m_ax_obj && m_ax_obj.
isa (
"axes")
1144 ap.
set (name, value);
1158 ap.
set (name, value);
1173 interp.
feval (
"axis", args);
1187 interp.
feval (
"grid", args);
1192 void pixel2pos (
const graphics_handle& ax,
int px,
int py,
double& xx,
1197 pixel2pos (gh_mgr.
get_object (ax), px, py, xx, yy);
1203 if (ax && ax.
isa (
"axes"))
1220 for (
int k = 0; k <
len; k++)
1232 if (bb(0) <= px && px < (bb(0)+bb(2))
1233 && bb(1) <= py && py < (bb(1)+bb(3)))
1244 int px1 = -1,
int py1 = -1)
1248 pixel2status (gh_mgr.
get_object (ax), px0, py0, px1, py1);
1252 int px1 = -1,
int py1 = -1)
1254 double x0, y0, x1, y1;
1256 std::stringstream cbuf;
1259 pixel2pos (ax, px0, py0, x0, y0);
1260 cbuf <<
'[' << x0 <<
", " << y0 <<
']';
1263 pixel2pos (ax, px1, py1, x1, y1);
1264 cbuf <<
" -> ["<< x1 <<
", " << y1 <<
']';
1267 m_status->value (cbuf.str ().c_str ());
1272 if (ax && ax.
isa (
"axes"))
1276 std::stringstream cbuf;
1281 cbuf <<
"[azimuth: " << v(0) <<
", elevation: " << v(1) <<
']';
1283 m_status->value (cbuf.str ().c_str ());
1287 void set_currentpoint (
int px,
int py)
1335 if (m_uimenu->is_visible ())
1349 std::string key_str;
1350 std::ostringstream tmp_str;
1352 if (e_key == FL_Escape)
1354 else if (e_key == FL_Tab)
1356 else if (e_key == FL_Caps_Lock)
1357 key_str =
"capslock";
1358 else if (e_key == FL_Shift_L || e_key == FL_Shift_R)
1360 else if (e_key == FL_Control_L || e_key == FL_Control_R)
1361 key_str =
"control";
1362 else if (e_key == FL_Meta_L || e_key == FL_Meta_R)
1363 key_str =
"windows";
1364 else if (e_key == FL_Alt_L || e_key == FL_Alt_R)
1366 else if (e_key == 32)
1368 else if (e_key == FL_Enter)
1370 else if (e_key == FL_BackSpace)
1371 key_str =
"backspace";
1372 else if (e_key == FL_Print)
1373 key_str =
"printscreen";
1374 else if (e_key == FL_Pause)
1376 else if (e_key == FL_Home)
1378 else if (e_key == FL_End)
1380 else if (e_key == FL_Insert)
1382 else if (e_key == FL_Page_Up)
1384 else if (e_key == FL_Delete)
1386 else if (e_key == FL_Page_Down)
1387 key_str =
"pagedown";
1388 else if (e_key == FL_Left)
1389 key_str =
"leftarrow";
1390 else if (e_key == FL_Up)
1391 key_str =
"uparrow";
1392 else if (e_key == FL_Right)
1393 key_str =
"rightarrow";
1394 else if (e_key == FL_Down)
1395 key_str =
"downarrow";
1396 else if (e_key == FL_Num_Lock)
1397 key_str =
"numlock";
1398 else if (e_key == 0xffaf)
1400 else if (e_key == 0xffaa)
1401 key_str =
"multiply";
1402 else if (e_key == 0xffad)
1403 key_str =
"subtract";
1404 else if (e_key == 0xffab)
1406 else if (e_key == 0xff8d)
1408 else if (e_key == 0xffac)
1409 key_str =
"separator";
1410 else if (e_key >= 0xffb0 && e_key <= 0xffb9)
1412 tmp_str <<
"numpad" << (e_key - 0xffb0);
1413 key_str = tmp_str.str ();
1415 else if (e_key >= (FL_F + 1) && e_key <= (FL_F + 12))
1417 tmp_str <<
'f' << (e_key - FL_F);
1418 key_str = tmp_str.str ();
1420 else if (e_key ==
',')
1422 else if (e_key ==
'.')
1424 else if (e_key ==
'-')
1426 else if (e_key ==
'^' || e_key ==
'+' || e_key ==
'#'
1427 || e_key ==
'<' || e_key == 0xfe03 )
1429 else if (isalnum (e_key))
1430 key_str = std::tolower (e_key);
1431 else if (isprint (e_text[0]))
1438 Cell modifier2cell (
int e_state)
1442 if (e_state & FL_SHIFT)
1443 mod.append (std::string (
"shift"));
1444 if (e_state & FL_CTRL)
1445 mod.append (std::string (
"control"));
1446 if (e_state & FL_ALT)
1447 mod.append (std::string (
"alt"));
1448 if (e_state & FL_COMMAND)
1449 mod.append (std::string (
"command"));
1453 void resize (
int xx,
int yy,
int ww,
int hh)
1455 Fl_Window::resize (xx, yy, ww, hh);
1480 std::string pan_mode ()
1490 bool rotate_enabled ()
1500 int handle (
int event)
1502 if (event == FL_FOCUS)
1512 static bool key_resent_detected =
false;
1521 static int last_event_key = 0;
1522 static char last_event_text = 0;
1524 int e_key = Fl::event_key ();
1525 char e_text = Fl::event_text ()[0];
1526 key_resent_detected = (e_key == last_event_key
1527 && std::tolower (last_event_text) == std::tolower (e_text)
1528 && ((islower (last_event_text) && isupper (e_text))
1529 || (isupper (last_event_text) && islower (e_text))));
1531 last_event_key = e_key;
1532 last_event_text = e_text;
1538 int e_key = Fl::event_key ();
1539 const char *e_text = Fl::event_text ();
1540 int e_state = Fl::event_state ();
1549 if (Fl::event_inside (m_canvas))
1551 m_pos_x = Fl::event_x ();
1552 m_pos_y = Fl::event_y () - menu_dy ();
1554 set_currentpoint (m_pos_x, m_pos_y);
1556 gh = pixel2axes_or_ca (m_pos_x, m_pos_y);
1561 set_axes_currentpoint (m_ax_obj, m_pos_x, m_pos_y);
1596 int e_key = Fl::event_key ();
1597 int e_state = Fl::event_state ();
1599 if (key_resent_detected && Fl::event_length () == 1)
1604 tmp_e_text[0] = Fl::event_text ()[0];
1607 if (std::islower (tmp_e_text[0]))
1608 tmp_e_text[0] = std::toupper (tmp_e_text[0]);
1610 tmp_e_text[0] = std::tolower (tmp_e_text[0]);
1611 evt = format_key_event (e_key, tmp_e_text, e_state);
1615 const char *e_text = Fl::event_text ();
1616 evt = format_key_event (e_key, e_text, e_state);
1628 if (Fl::event_inside (m_canvas))
1632 pixel2status (pixel2axes_or_ca (Fl::event_x (),
1633 Fl::event_y () - menu_dy ()),
1634 Fl::event_x (), Fl::event_y () - menu_dy ());
1638 m_pos_x = Fl::event_x ();
1639 m_pos_y = Fl::event_y () - menu_dy ();
1641 set_currentpoint (m_pos_x, m_pos_y);
1643 if (Fl::event_clicks ())
1645 else if (Fl::event_button () == FL_MIDDLE_MOUSE
1646 || (Fl::event_button () == FL_LEFT_MOUSE
1647 && Fl::event_shift ()))
1649 else if (Fl::event_button () == FL_RIGHT_MOUSE
1650 || (Fl::event_button () == FL_LEFT_MOUSE
1651 && Fl::event_ctrl ()))
1656 gh = pixel2axes_or_ca (m_pos_x, m_pos_y);
1661 set_axes_currentpoint (m_ax_obj, m_pos_x, m_pos_y);
1687 set_currentpoint (Fl::event_x (), Fl::event_y () - menu_dy ());
1691 if (Fl::event_button () == 1)
1693 if (m_ax_obj && m_ax_obj.
isa (
"axes"))
1698 if (ap.
get_tag () !=
"legend")
1700 if (rotate_enabled ())
1701 view2status (m_ax_obj);
1703 pixel2status (m_ax_obj, m_pos_x, m_pos_y,
1705 Fl::event_y () - menu_dy ());
1707 double x0, y0, x1, y1;
1709 pixel2pos (m_ax_obj, m_pos_x, m_pos_y, x0, y0);
1710 pixel2pos (m_ax_obj, Fl::event_x (),
1711 Fl::event_y () - menu_dy (),
1716 std::string mode = pan_mode ();
1720 else if (rotate_enabled ())
1723 daz = (Fl::event_x () - m_pos_x) / pos(2) * 360;
1724 del = (Fl::event_y () - menu_dy () - m_pos_y)
1733 pos(0) += double (Fl::event_x () - m_pos_x)
1735 pos(1) -= double (Fl::event_y () - menu_dy () - m_pos_y)
1740 m_pos_x = Fl::event_x ();
1741 m_pos_y = Fl::event_y () - menu_dy ();
1746 else if (Fl::event_button () == 3)
1748 pixel2status (m_ax_obj, m_pos_x, m_pos_y,
1749 Fl::event_x (), Fl::event_y () - menu_dy ());
1750 Matrix zoom_box (1, 4, 0);
1751 zoom_box(0) = m_pos_x;
1752 zoom_box(1) = m_pos_y;
1753 zoom_box(2) = Fl::event_x ();
1754 zoom_box(3) = Fl::event_y () - menu_dy ();
1755 m_canvas->set_zoom_box (zoom_box);
1756 m_canvas->zoom (
true);
1766 = gh_mgr.
get_object (pixel2axes_or_ca (Fl::event_x (),
1769 if (ax && ax.
isa (
"axes"))
1778 const double factor = (Fl::event_dy () < 0
1779 ? 1 / (1.0 - wheel_zoom_speed)
1780 : 1.0 - wheel_zoom_speed);
1784 pixel2pos (ax, Fl::event_x (), Fl::event_y () - menu_dy (),
1800 set_currentpoint (Fl::event_x (),
1801 Fl::event_y () - menu_dy ());
1805 if ((Fl::event_button () == 1) && Fl::event_clicks ())
1808 set_on_ax_obj (
"xlimmode",
"auto");
1809 set_on_ax_obj (
"ylimmode",
"auto");
1810 set_on_ax_obj (
"zlimmode",
"auto");
1814 if (Fl::event_button () == 3)
1817 if (m_canvas->zoom ())
1819 m_canvas->zoom (
false);
1820 double x0, y0, x1, y1;
1821 if (m_ax_obj && m_ax_obj.
isa (
"axes"))
1825 pixel2pos (m_ax_obj, m_pos_x, m_pos_y, x0, y0);
1826 int pos_x1 = Fl::event_x ();
1827 int pos_y1 = Fl::event_y () - menu_dy ();
1828 pixel2pos (m_ax_obj, pos_x1, pos_y1, x1, y1);
1831 int dx =
abs (m_pos_x - pos_x1);
1832 int dy =
abs (m_pos_y - pos_y1);
1834 if ((dx > 4) && (dy > 4))
1856 ap.
zoom (
"both", xl, yl);
1867 return Fl_Window::handle (event);
1871 class figure_manager
1875 figure_manager () =
default;
1879 OCTAVE_DISABLE_COPY_MOVE (figure_manager)
1886 static bool instance_ok ()
1891 s_instance =
new figure_manager ();
1896 static void close_all ()
1899 s_instance->do_close_all ();
1905 s_instance->do_new_window (fp);
1908 static void delete_window (
int idx)
1911 s_instance->do_delete_window (idx);
1914 static void delete_window (
const std::string& idx_str)
1916 delete_window (str2idx (idx_str));
1919 static void renumber_figure (
const std::string& idx_str,
double new_number)
1922 s_instance->do_renumber_figure (str2idx (idx_str), new_number);
1925 static void toggle_window_visibility (
int idx,
bool is_visible)
1928 s_instance->do_toggle_window_visibility (idx, is_visible);
1931 static void toggle_window_visibility (
const std::string& idx_str,
1934 toggle_window_visibility (str2idx (idx_str), is_visible);
1937 static void mark_modified (
int idx)
1940 s_instance->do_mark_modified (idx);
1945 mark_modified (hnd2idx (gh));
1948 static void set_name (
int idx)
1951 s_instance->do_set_name (idx);
1954 static void set_name (
const std::string& idx_str)
1956 set_name (str2idx (idx_str));
1959 static Matrix get_size (
int idx)
1961 return instance_ok () ? s_instance->do_get_size (idx) :
Matrix ();
1966 return get_size (hnd2idx (gh));
1970 const std::string& term)
1973 s_instance->do_print (hnd2idx (gh), cmd, term);
1980 retval = s_instance->do_get_pixels (hnd2idx (gh));
1989 s_instance->do_uimenu_update (hnd2idx (figh), uimenuh,
id);
1996 s_instance->do_update_canvas (hnd2idx (gh), ca);
1999 static void update_boundingbox (
const std::string& fig_idx_str,
2003 s_instance->do_update_boundingbox (str2idx (fig_idx_str),
internal);
2006 static void toggle_menubar_visibility (
const std::string& fig_idx_str,
2007 bool menubar_is_figure)
2010 s_instance->do_toggle_menubar_visibility (str2idx (fig_idx_str),
2016 static figure_manager *s_instance;
2020 static int s_curr_index;
2022 typedef std::map<int, plot_window *> window_map;
2024 typedef window_map::iterator wm_iterator;
2026 window_map m_windows;
2028 static std::string s_fltk_idx_header;
2030 void do_close_all ()
2032 for (
auto& win : m_windows)
2039 int idx = figprops2idx (fp);
2041 if (idx >= 0 && m_windows.find (idx) == m_windows.end ())
2044 bool internal =
false;
2046 if (pos(2) != -1.0 && pos(3) != -1.0)
2057 idx2figprops (s_curr_index, fp);
2059 m_windows[s_curr_index++] =
new plot_window (pos(0), pos(1), pos(2), pos(3),
2064 void do_delete_window (
int idx)
2066 wm_iterator win = m_windows.find (idx);
2068 if (win != m_windows.end ())
2071 m_windows.erase (win);
2075 void do_renumber_figure (
int idx,
double new_number)
2077 wm_iterator win = m_windows.find (idx);
2079 if (win != m_windows.end ())
2080 win->second->renumber (new_number);
2083 void do_toggle_window_visibility (
int idx,
bool is_visible)
2085 wm_iterator win = m_windows.find (idx);
2087 if (win != m_windows.end ())
2091 win->second->show ();
2092 win->second->show_canvas ();
2095 win->second->hide ();
2100 void do_toggle_menubar_visibility (
int fig_idx,
bool menubar_is_figure)
2102 wm_iterator win = m_windows.find (fig_idx);
2104 if (win != m_windows.end ())
2106 if (menubar_is_figure)
2107 win->second->show_menubar ();
2109 win->second->hide_menubar ();
2111 win->second->redraw ();
2115 void do_mark_modified (
int idx)
2117 wm_iterator win = m_windows.find (idx);
2119 if (win != m_windows.end ())
2121 win->second->mark_modified ();
2125 void do_set_name (
int idx)
2127 wm_iterator win = m_windows.find (idx);
2129 if (win != m_windows.end ())
2130 win->second->set_name ();
2133 Matrix do_get_size (
int idx)
2137 wm_iterator win = m_windows.find (idx);
2139 if (win != m_windows.end ())
2141 sz(0) = win->second->w ();
2142 sz(1) = win->second->h ();
2148 void do_print (
int idx,
const std::string& cmd,
const std::string& term)
2150 wm_iterator win = m_windows.find (idx);
2152 if (win != m_windows.end ())
2153 win->second->print (cmd, term);
2159 wm_iterator win = m_windows.
find (idx);
2161 if (win != m_windows.end ())
2162 retval = win->second->get_pixels ();
2169 wm_iterator win = m_windows.
find (idx);
2171 if (win != m_windows.end ())
2172 win->second->uimenu_update (gh,
id);
2177 wm_iterator win = m_windows.
find (idx);
2179 if (win != m_windows.end ())
2182 win->second->show_canvas ();
2184 win->second->hide_canvas ();
2188 void do_update_boundingbox (
int idx,
bool internal)
2190 wm_iterator win = m_windows.
find (idx);
2192 if (win != m_windows.end ())
2193 win->second->update_boundingbox (
internal);
2199 if (clstr.find (s_fltk_idx_header, 0) == 0)
2201 std::istringstream istr (clstr.substr (s_fltk_idx_header.size ()));
2206 error (
"figure_manager: could not recognize fltk index");
2211 std::ostringstream ind_str;
2212 ind_str << s_fltk_idx_header << idx;
2227 error (
"figure_manager: figure is not fltk");
2230 static int hnd2idx (
double h)
2236 if (fobj && fobj.
isa (
"figure"))
2240 return figprops2idx (fp);
2243 error (
"figure_manager: H (= %g) is not a figure", h);
2248 return hnd2idx (fh.
value ());
2252 figure_manager *figure_manager::s_instance =
nullptr;
2254 std::string figure_manager::s_fltk_idx_header=
"fltk index=";
2255 int figure_manager::s_curr_index = 1;
2257 static bool toolkit_loaded =
false;
2259 class fltk_graphics_toolkit :
public octave::base_graphics_toolkit
2263 fltk_graphics_toolkit (octave::interpreter& interp)
2265 m_interpreter (interp), m_input_event_hook_fcn_id ()
2267 static bool warned =
false;
2272 (
"Octave:fltk-graphics",
2273 "using the fltk graphics toolkit is discouraged\n\
2275 The FLTK graphics toolkit is not actively maintained and has a number\n\
2276 of limitations that are unlikely to be fixed.\n\
2277 The qt toolkit is recommended instead.\n");
2282 Fl::visual (FL_RGB);
2285 OCTAVE_DISABLE_CONSTRUCT_COPY_MOVE (fltk_graphics_toolkit)
2287 ~fltk_graphics_toolkit () =
default;
2289 bool is_valid ()
const {
return true; }
2293 if (go.
isa (
"figure")
2294 || go.
isa (
"uimenu"))
2296 if (go.
isa (
"uimenu"))
2307 if (go.
isa (
"figure"))
2322 std::string fltk_label = uimenup.
get_label ();
2324 gh_manager& gh_mgr = m_interpreter.get_gh_manager ();
2328 if (go.
isa (
"uimenu"))
2333 else if (go.
isa (
"figure") || go.
isa (
"uicontextmenu"))
2336 error (
"invalid parent object\n");
2344 if (go.
isa (
"figure"))
2356 figure_manager::toggle_window_visibility (ov.
string_value (),
2361 figure_manager::toggle_menubar_visibility
2366 figure_manager::update_canvas (go.
get_handle (),
2379 figure_manager::renumber_figure (tmp, gh.
value ());
2380 figure_manager::set_name (tmp);
2385 figure_manager::update_boundingbox (ov.
string_value (),
true);
2389 figure_manager::update_boundingbox (ov.
string_value (),
false);
2394 else if (go.
isa (
"uimenu"))
2397 uimenu_set___fltk_label__ (go);
2408 gh_manager& gh_mgr = m_interpreter.get_gh_manager ();
2412 if (obj && obj.
isa (
"root"))
2421 if (fobj && fobj.
isa (
"figure"))
2427 == FLTK_GRAPHICS_TOOLKIT_NAME)
2428 figure_manager::new_window (fp);
2433 figure_manager::mark_modified (go.
get_handle ());
2438 const std::string& term,
2439 const std::string& file_cmd,
2440 const std::string& )
const
2442 figure_manager::print (go.
get_handle (), file_cmd, term);
2447 return figure_manager::get_pixels (go.
get_handle ());
2452 return figure_manager::get_size (fh);
2466 Matrix get_screen_size ()
const
2478 m_interpreter.munlock (
"__init_fltk__");
2485 figure_manager::close_all ();
2491 m_input_event_hook_fcn_id = id;
2496 octave::interpreter& m_interpreter;
2509 #if defined (HAVE_FLTK)
2517 octave_unused_parameter (interp);
2531 #if defined (HAVE_FLTK)
2532 octave::display_info& dpy_info = interp.get_display_info ();
2534 if (! dpy_info.display_available ())
2535 error (
"__init_fltk__: no graphics DISPLAY available");
2536 else if (! toolkit_loaded)
2540 octave::gtk_manager& gtk_mgr = interp.get_gtk_manager ();
2542 fltk_graphics_toolkit *fltk =
new fltk_graphics_toolkit (interp);
2543 octave::graphics_toolkit tk (fltk);
2544 gtk_mgr.load_toolkit (tk);
2545 toolkit_loaded =
true;
2551 ovl (fcn_handle), 1);
2553 fltk->set_input_event_hook_id (
id);
2559 octave_unused_parameter (interp);
2570 OCTAVE_END_NAMESPACE(
octave)
octave_value_list Fdrawnow(octave::interpreter &, const octave_value_list &=octave_value_list(), int=0)
octave_value_list Fadd_input_event_hook(octave::interpreter &, const octave_value_list &=octave_value_list(), int=0)
octave_value_list Fremove_input_event_hook(octave::interpreter &, const octave_value_list &=octave_value_list(), int=0)
Array< octave_idx_type > sort_rows_idx(sortmode mode=ASCENDING) const
Sort by rows returns only indices.
Array< octave_idx_type > find(octave_idx_type n=-1, bool backward=false) const
Find indices of (at most n) nonzero elements.
octave_idx_type numel() const
Number of elements in the array.
void resize(octave_idx_type nr, octave_idx_type nc, double rfv=0)
void rotate_view(double delta_az, double delta_el, bool push_to_zoom_stack=true)
octave_value get_position() const
void zoom(const std::string &mode, double factor, bool push_to_zoom_stack=true)
void set_currentpoint(const octave_value &val)
ColumnVector pixel2coord(double px, double py) const
octave_value get(bool all=false) const
double get_mousewheelzoom() const
graphics_xform get_transform() const
void set(const caseless_str &pname, const octave_value &val)
Matrix get_transform_zlim() const
void set_position(const octave_value &val)
void zoom_about_point(const std::string &mode, double x, double y, double factor, bool push_to_zoom_stack=true)
void translate_view(const std::string &mode, double x0, double x1, double y0, double y1, bool push_to_zoom_stack=true)
bool is_beingdeleted() const
graphics_handle get_parent() const
graphics_handle get___myhandle__() const
Matrix get_all_children() const
Matrix get_children() const
void execute_buttondownfcn(const octave_value &new_data=octave_value()) const
octave_value get_buttondownfcn() const
virtual Matrix get_boundingbox(bool=false, const Matrix &=Matrix()) const
std::string get_tag() const
graphics_object get_object(double val) const
graphics_handle lookup(double val) const
octave_value get(bool all=false) const
graphics_object get_ancestor(const std::string &type) const
base_properties & get_properties()
bool isa(const std::string &go_name) const
graphics_handle get_parent() const
graphics_handle get_handle() const
bool valid_object() const
octave_value_list feval(const char *name, const octave_value_list &args=octave_value_list(), int nargout=0)
Evaluate an Octave function (built-in or interpreted) and return the list of result values.
octave_value as_octave_value() const
const octave_value & contents(const_iterator p) const
void assign(const std::string &k, const octave_value &val)
octave_value_list & append(const octave_value &val)
octave_scalar_map scalar_map_value() const
std::string string_value(bool force=false) const
octave_idx_type length() const
Matrix matrix_value(bool frc_str_conv=false) const
bool set(const octave_value &val, bool do_run=true, bool do_notify_toolkit=true)
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
#define DEFMETHOD_DLD(name, interp_name, args_name, nargout_name, doc)
Macro to define an at run time dynamically loadable builtin method.
void warning_with_id(const char *id, const char *fmt,...)
void() error(const char *fmt,...)
#define panic_impossible()
void err_disabled_feature(const std::string &fcn, const std::string &feature, const std::string &pkg)
void gl2ps_print(opengl_functions &glfcns, const graphics_object &fig, const std::string &stream, const std::string &term)
gh_manager & __get_gh_manager__()
interpreter & __get_interpreter__()
std::complex< T > floor(const std::complex< T > &x)
std::complex< double > w(std::complex< double > z, double relerr=0)
octave_value_list F__fltk_check__(octave::interpreter &, const octave_value_list &, int)
void draw(QDomElement &parent_elt, pdfpainter &painter)
octave_value_list ovl(const OV_Args &... args)
Construct an octave_value_list with less typing.
template int8_t abs(int8_t)