# HG changeset patch # User Rik # Date 1371763940 25200 # Node ID 2cfd8cd9e1b6869d6e706b725104d64ddaa914c4 # Parent 0e75f5412f1e58383d9ee1a0387612df036d5164 __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. diff --git a/scripts/plot/private/__fltk_ginput__.m b/scripts/plot/private/__fltk_ginput__.m --- 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