changeset 19047:60e54be64f37

Fix ginput for FLTK toolkit * __init_fltk__.cc: Execute callback for base_properties::buttondownfcn and figure_properties::buttondownfcn. Now it is possible to have different callbacks for each axes in a subplot. * __fltk_ginput__.m: Adapt to recent FLTK toolkit changes
author Andreas Weber <andy.weber.aw@gmail.com>
date Sat, 16 Aug 2014 22:59:44 +0200
parents 7f73293d8423
children 90a541a12c4b
files libinterp/dldfcn/__init_fltk__.cc scripts/plot/util/ginput.m scripts/plot/util/private/__fltk_ginput__.m
diffstat 3 files changed, 24 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/dldfcn/__init_fltk__.cc	Sat Aug 16 19:08:52 2014 +0200
+++ b/libinterp/dldfcn/__init_fltk__.cc	Sat Aug 16 22:59:44 2014 +0200
@@ -1133,6 +1133,7 @@
   {
     if (!fp.is_beingdeleted ())
       {
+        // FIXME: consider figures units property
         Matrix pos (1,2,0);
         pos(0) = px;
         pos(1) = h () - (py + status_h + menu_dy ());
@@ -1443,8 +1444,14 @@
 
                 fp.set_currentobject (ax_obj.get_handle ().value ());
 
+                base_properties& props = ax_obj.get_properties ();
+                if (props.get_buttondownfcn ().is_defined ())
+                  props.execute_buttondownfcn (Fl::event_button ());
+
                 return 1;
               }
+            else if (fp.get_buttondownfcn ().is_defined ())
+              fp.execute_buttondownfcn (Fl::event_button ());
 
             break;
 
--- a/scripts/plot/util/ginput.m	Sat Aug 16 19:08:52 2014 +0200
+++ b/scripts/plot/util/ginput.m	Sat Aug 16 22:59:44 2014 +0200
@@ -39,16 +39,15 @@
     print_usage ();
   endif
 
-  f = gcf ();
   a = gca ();  # Create an axis, if necessary
   drawnow ();
-  toolkit = get (f, "__graphics_toolkit__");
+  toolkit = get (gcf, "__graphics_toolkit__");
 
   varargout = cell (1, nargout);
   if (nargin == 0)
-    [varargout{:}] = feval (["__" toolkit "_ginput__"], f);
+    [varargout{:}] = feval (["__" toolkit "_ginput__"]);
   else
-    [varargout{:}] = feval (["__" toolkit "_ginput__"], f, n);
+    [varargout{:}] = feval (["__" toolkit "_ginput__"], n);
   endif
 
 endfunction
--- a/scripts/plot/util/private/__fltk_ginput__.m	Sat Aug 16 19:08:52 2014 +0200
+++ b/scripts/plot/util/private/__fltk_ginput__.m	Sat Aug 16 22:59:44 2014 +0200
@@ -17,15 +17,15 @@
 ## <http://www.gnu.org/licenses/>.
 
 ## -*- texinfo -*-
-## @deftypefn {Function File} {[@var{x}, @var{y}, @var{buttons}] =} __fltk_ginput__ (@var{f}, @var{n})
+## @deftypefn {Function File} {[@var{x}, @var{y}, @var{buttons}] =} __fltk_ginput__ (@var{n})
 ## Undocumented internal function.
 ## @end deftypefn
 
 ## This is ginput.m implementation for fltk.
 
-function [x, y, button] = __fltk_ginput__ (f, n = -1)
+function [x, y, button] = __fltk_ginput__ (n = -1)
 
-  if (isempty (get (f, "currentaxes")))
+  if (isempty (gca))
     error ("ginput: must have at least one axes");
   endif
 
@@ -34,11 +34,11 @@
 
   unwind_protect
 
-    orig_windowbuttondownfcn = get (f, "windowbuttondownfcn");
-    set (f, "windowbuttondownfcn", @ginput_windowbuttondownfcn);
+    orig_buttondownfcn = get (gca, "buttondownfcn");
+    set (gca, "buttondownfcn", @ginput_buttondownfcn);
 
-    orig_ginput_keypressfcn = get (f, "keypressfcn");
-    set (f, "keypressfcn", @ginput_keypressfcn);
+    orig_ginput_keypressfcn = get (gcf, "keypressfcn");
+    set (gcf, "keypressfcn", @ginput_keypressfcn);
 
     do
       __fltk_check__ ();
@@ -50,8 +50,8 @@
     until (n0 == n || n0 < 0)
 
   unwind_protect_cleanup
-    set (f, "windowbuttondownfcn", orig_windowbuttondownfcn);
-    set (f, "keypressfcn", orig_ginput_keypressfcn);
+    set (gca, "buttondownfcn", orig_buttondownfcn);
+    set (gcf, "keypressfcn", orig_ginput_keypressfcn);
   end_unwind_protect
 
 endfunction
@@ -76,20 +76,19 @@
 
 endfunction
 
-function ginput_windowbuttondownfcn (src, data)
-  point = get (get (src,"currentaxes"), "currentpoint");
-  button = data;
+function ginput_buttondownfcn (src, button)
+  point = get (src, "currentpoint");
   ginput_accumulator (1, point(1,1), point(2,1), button);
 endfunction
 
 function ginput_keypressfcn (src, evt)
-  point = get (get (src, "currentaxes"), "currentpoint");
+  point = get (gca, "currentpoint");
   key = evt.Key;
-  if (key == 10)
+  if (key == "return")
     ## Enter key stops ginput.
     ginput_accumulator (2, NaN, NaN, NaN);
   else
-    ginput_accumulator (1, point(1,1), point(2,1), key);
+    ginput_accumulator (1, point(1,1), point(2,1), uint8 (key(1)));
   endif
 endfunction