changeset 16787:2cfd8cd9e1b6

__fltk_ginput__.m: Restructure and clean up code. * scripts/plot/private/__fltk_ginput__.m: Use do/until loop for clarity. Place common initializations on 1 line. Remove FIXME comments that have been dealt with. Rename aggregator to accumulator for clarity.
author Rik <rik@octave.org>
date Thu, 20 Jun 2013 14:32:20 -0700
parents 0e75f5412f1e
children f89de736eecd
files scripts/plot/private/__fltk_ginput__.m
diffstat 1 files changed, 13 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/plot/private/__fltk_ginput__.m
+++ b/scripts/plot/private/__fltk_ginput__.m
@@ -23,9 +23,6 @@
 
 ## This is ginput.m implementation for fltk.
 
-## FIXME -- Key presses cannot toggle menu items nor hotkey functionality
-## (grid, autoscale) during ginput!
-
 function [x, y, button] = __fltk_ginput__ (f, n = -1)
 
   if (isempty (get (f, "currentaxes")))
@@ -33,7 +30,7 @@
   endif
 
   x = y = button = [];
-  ginput_aggregator (0, 0, 0, 0);
+  ginput_accumulator (0, 0, 0, 0);  # initialize accumulator
 
   unwind_protect
 
@@ -43,17 +40,14 @@
     orig_ginput_keypressfcn = get (f, "keypressfcn");
     set (f, "keypressfcn", @ginput_keypressfcn);
 
-    while (true)
+    do
       __fltk_redraw__ ();
 
       ## Release CPU.
       sleep (0.01);
 
-      [x, y, n0, button] = ginput_aggregator (-1, 0, 0, 0);
-      if (n0 == n || n0 < 0)
-        break;
-      endif
-    endwhile
+      [x, y, n0, button] = ginput_accumulator (-1, 0, 0, 0);
+    until (n0 == n || n0 < 0)
 
   unwind_protect_cleanup
     set (f, "windowbuttondownfcn", orig_windowbuttondownfcn);
@@ -62,17 +56,15 @@
 
 endfunction
 
-function [x, y, n, button] = ginput_aggregator (mode, xn, yn, btn)
+function [x, y, n, button] = ginput_accumulator (mode, xn, yn, btn)
   persistent x y n button;
 
   if (mode == 0)
     ## Initialize.
-    x = [];
-    y = [];
-    button = [];
+    x = y = button = [];
     n = 0;
   elseif (mode == 1)
-    ## Accept mouse button or key press.
+    ## Append mouse button or key press.
     x = [x; xn];
     y = [y; yn];
     button = [button; btn];
@@ -81,23 +73,24 @@
     ## The end due to Enter.
     n = -1;
  endif
+
 endfunction
 
 function ginput_windowbuttondownfcn (src, data)
   point = get (get (src,"currentaxes"), "currentpoint");
   button = data;
-  ginput_aggregator (1, point(1,1), point(2,1), button);
+  ginput_accumulator (1, point(1,1), point(2,1), button);
 endfunction
 
 function ginput_keypressfcn (src, evt)
   point = get (get (src, "currentaxes"), "currentpoint");
-  ## FIXME -- use evt.Key or evt.Character?
+  keyboard ();
   key = evt.Key;
   if (key == 10)
-    ## Enter key.
-    ginput_aggregator (2, point(1,1), point(2,1), key);
+    ## Enter key stops ginput.
+    ginput_accumulator (2, NaN, NaN, NaN);
   else
-    ginput_aggregator (1, point(1,1), point(2,1), key);
+    ginput_accumulator (1, point(1,1), point(2,1), key);
   endif
 endfunction