Mercurial > octave
comparison scripts/plot/__fltk_ginput__.m @ 12299:96db5945cfd7 release-3-4-x
__fltk_ginput__.m: return keypress info
author | Petr Mikulik <mikulik@physics.muni.cz> |
---|---|
date | Sun, 30 Jan 2011 03:20:29 -0500 |
parents | c792872f8942 |
children | 88fa9e9efdea |
comparison
equal
deleted
inserted
replaced
12298:edaf29362c50 | 12299:96db5945cfd7 |
---|---|
21 ## Undocumented internal function. | 21 ## Undocumented internal function. |
22 ## @end deftypefn | 22 ## @end deftypefn |
23 | 23 |
24 ## This is ginput.m implementation for fltk. | 24 ## This is ginput.m implementation for fltk. |
25 | 25 |
26 ## FIXME -- Key presses cannot toggle menu items nor hotkey functionality | |
27 ## (grid, autoscale) during ginput! | |
28 | |
26 function [x, y, button] = __fltk_ginput__ (f, n = -1) | 29 function [x, y, button] = __fltk_ginput__ (f, n = -1) |
27 | 30 |
28 if (isempty (get (f, "currentaxes"))) | 31 if (isempty (get (f, "currentaxes"))) |
29 error ("ginput: must have at least one axes"); | 32 error ("ginput: must have at least one axes"); |
30 endif | 33 endif |
31 | 34 |
32 x = y = button = []; | 35 x = y = button = []; |
33 ginput_aggregator (0, 0, 0); | 36 ginput_aggregator (0, 0, 0, 0); |
34 | 37 |
35 unwind_protect | 38 unwind_protect |
36 | 39 |
37 orig_windowbuttondownfcn = get (f, "windowbuttondownfcn"); | 40 orig_windowbuttondownfcn = get (f, "windowbuttondownfcn"); |
38 set (f, "windowbuttondownfcn", @ginput_windowbuttondownfcn); | 41 set (f, "windowbuttondownfcn", @ginput_windowbuttondownfcn); |
41 set (f, "keypressfcn", @ginput_keypressfcn); | 44 set (f, "keypressfcn", @ginput_keypressfcn); |
42 | 45 |
43 while (true) | 46 while (true) |
44 __fltk_redraw__ (); | 47 __fltk_redraw__ (); |
45 | 48 |
46 ## release CPU | 49 ## Release CPU. |
47 sleep (0.01); | 50 sleep (0.01); |
48 | 51 |
49 [x, y, n0] = ginput_aggregator (-1, 0, 0); | 52 [x, y, n0, button] = ginput_aggregator (-1, 0, 0, 0); |
50 if (n0 == n || n0 < 0) | 53 if (n0 == n || n0 < 0) |
51 break; | 54 break; |
52 endif | 55 endif |
53 endwhile | 56 endwhile |
54 | 57 |
59 set (f, "keypressfcn", orig_ginput_keypressfcn); | 62 set (f, "keypressfcn", orig_ginput_keypressfcn); |
60 end_unwind_protect | 63 end_unwind_protect |
61 | 64 |
62 endfunction | 65 endfunction |
63 | 66 |
64 function [x, y, n] = ginput_aggregator (mode , xn, yn) | 67 function [x, y, n, button] = ginput_aggregator (mode, xn, yn, btn) |
65 persistent x y n; | 68 persistent x y n button; |
66 | 69 |
67 if (mode == 0) | 70 if (mode == 0) |
71 ## Initialize. | |
68 x = []; | 72 x = []; |
69 y = []; | 73 y = []; |
74 button = []; | |
70 n = 0; | 75 n = 0; |
71 elseif (mode == 1) | 76 elseif (mode == 1) |
77 ## Accept mouse button or key press. | |
72 x = [x; xn]; | 78 x = [x; xn]; |
73 y = [y; yn]; | 79 y = [y; yn]; |
80 button = [button; btn]; | |
74 n += 1; | 81 n += 1; |
75 elseif (mode == 2) | 82 elseif (mode == 2) |
83 ## The end due to Enter. | |
76 n = -1; | 84 n = -1; |
77 endif | 85 endif |
78 endfunction | 86 endfunction |
79 | 87 |
80 function ginput_windowbuttondownfcn (src, data) | 88 function ginput_windowbuttondownfcn (src, data) |
81 point = get (get (src,"currentaxes"), "currentpoint"); | 89 point = get (get (src,"currentaxes"), "currentpoint"); |
82 ginput_aggregator (1, point(1,1), point(2,1)); | 90 ## FIXME -- How to get the actual mouse button pressed (1,2,3) into |
91 ## "button"? | |
92 button = 1; | |
93 ginput_aggregator (1, point(1,1), point(2,1), button); | |
83 endfunction | 94 endfunction |
84 | 95 |
85 function ginput_keypressfcn (src, evt) | 96 function ginput_keypressfcn (src, evt) |
86 if (evt.Key == 10) # linefeed character | 97 point = get (get (src, "currentaxes"), "currentpoint"); |
87 ginput_aggregator (2, 0, 0); | 98 ## FIXME -- use evt.Key or evt.Character? |
99 key = evt.Key; | |
100 if (key == 10) | |
101 ## Enter key. | |
102 ginput_aggregator (2, point(1,1), point(2,1), key); | |
103 else | |
104 ginput_aggregator (1, point(1,1), point(2,1), key); | |
88 endif | 105 endif |
89 endfunction | 106 endfunction |
90 | 107 |