10517
|
1 ## Copyright (C) 2010 Shai Ayal |
|
2 ## |
|
3 ## This file is part of Octave. |
|
4 ## |
|
5 ## Octave is free software; you can redistribute it and/or modify it |
|
6 ## under the terms of the GNU General Public License as published by |
|
7 ## the Free Software Foundation; either version 3 of the License, or (at |
|
8 ## your option) any later version. |
|
9 ## |
|
10 ## Octave is distributed in the hope that it will be useful, but |
|
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
13 ## General Public License for more details. |
|
14 ## |
|
15 ## You should have received a copy of the GNU General Public License |
|
16 ## along with Octave; see the file COPYING. If not, see |
|
17 ## <http://www.gnu.org/licenses/>. |
|
18 |
|
19 ## -*- texinfo -*- |
|
20 ## @deftypefn {Function File} {[@var{x}, @var{y}, @var{buttons}] =} __fltk_ginput__ (@var{f}, @var{n}) |
|
21 ## Undocumented internal function. |
|
22 ## @end deftypefn |
|
23 |
|
24 ## This is ginput.m implementation for fltk. |
|
25 |
|
26 function [x, y, button] = __fltk_ginput__ (f, n = -1) |
|
27 |
|
28 if (isempty (get (f, "currentaxes"))) |
|
29 error ("ginput: must have at least one axes"); |
|
30 endif |
|
31 |
|
32 x = []; |
|
33 y = []; |
|
34 button = []; |
|
35 ginput_aggregator (0, 0, 0); |
|
36 |
|
37 unwind_protect |
|
38 |
|
39 orig_windowbuttondownfcn = get (f, "windowbuttondownfcn"); |
|
40 set (f, "windowbuttondownfcn", @ginput_windowbuttondownfcn); |
|
41 |
|
42 orig_ginput_keypressfcn = get (f, "keypressfcn"); |
|
43 set (f, "keypressfcn", @ginput_keypressfcn); |
|
44 |
|
45 while (true) |
|
46 __fltk_redraw__ (); |
|
47 |
|
48 ## release CPU |
|
49 sleep (0.01); |
|
50 |
|
51 [x, y, n0] = ginput_aggregator (-1, 0, 0); |
|
52 if (n0 == n | n0 < 0) |
|
53 break; |
|
54 endif |
|
55 endwhile |
|
56 |
|
57 ## FIXME -- got to get the buttons somehow |
|
58 button = ones (size (x)); |
|
59 unwind_protect_cleanup |
|
60 set (f, "windowbuttondownfcn", orig_windowbuttondownfcn); |
|
61 set (f, "keypressfcn", orig_ginput_keypressfcn); |
|
62 end_unwind_protect |
|
63 |
|
64 endfunction |
|
65 |
|
66 function [x, y, n] = ginput_aggregator (mode , xn, yn) |
|
67 persistent x y n |
|
68 |
|
69 if (mode == 0), |
|
70 x = []; |
|
71 y = []; |
|
72 n = 0; |
|
73 elseif (mode == 1) |
|
74 x = [x, xn]; |
|
75 y = [y, yn]; |
|
76 n += 1; |
|
77 elseif (mode == 2) |
|
78 n = -1 |
|
79 endif |
|
80 endfunction |
|
81 |
|
82 function ginput_windowbuttondownfcn (src, data) |
|
83 point = get (get (src,"currentaxes"), "currentpoint"); |
|
84 ginput_aggregator (1, point(1,1), point(2,1)); |
|
85 endfunction |
|
86 |
|
87 function ginput_keypressfcn (src, evt) |
|
88 if (evt.Key == 10) |
|
89 ginput_aggregator (2, 0, 0) |
|
90 endif |
|
91 endfunction |
|
92 |