Mercurial > hg > octave-nkf
annotate scripts/plot/util/private/__fltk_ginput__.m @ 19793:0e1f5a750d00
maint: Periodic merge of gui-release to default.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Tue, 20 Jan 2015 10:24:46 -0500 |
parents | 9ef286208da1 |
children | 4197fc428c7d |
rev | line source |
---|---|
17744
d63878346099
maint: Update copyright notices for release.
John W. Eaton <jwe@octave.org>
parents:
17572
diff
changeset
|
1 ## Copyright (C) 2010-2013 Shai Ayal |
10517 | 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 -*- | |
19205
60e54be64f37
Fix ginput for FLTK toolkit
Andreas Weber <andy.weber.aw@gmail.com>
parents:
19202
diff
changeset
|
20 ## @deftypefn {Function File} {[@var{x}, @var{y}, @var{buttons}] =} __fltk_ginput__ (@var{n}) |
10517 | 21 ## Undocumented internal function. |
22 ## @end deftypefn | |
23 | |
24 ## This is ginput.m implementation for fltk. | |
25 | |
19205
60e54be64f37
Fix ginput for FLTK toolkit
Andreas Weber <andy.weber.aw@gmail.com>
parents:
19202
diff
changeset
|
26 function [x, y, button] = __fltk_ginput__ (n = -1) |
10517 | 27 |
19205
60e54be64f37
Fix ginput for FLTK toolkit
Andreas Weber <andy.weber.aw@gmail.com>
parents:
19202
diff
changeset
|
28 if (isempty (gca)) |
10517 | 29 error ("ginput: must have at least one axes"); |
30 endif | |
31 | |
11194
b8585f8e11d5
__fltk_ginput__.m: Use semicolons to prevent internal function evaluations being output to screen.
Rik <octave@nomad.inbox5.com>
parents:
11092
diff
changeset
|
32 x = y = button = []; |
16787
2cfd8cd9e1b6
__fltk_ginput__.m: Restructure and clean up code.
Rik <rik@octave.org>
parents:
16785
diff
changeset
|
33 ginput_accumulator (0, 0, 0, 0); # initialize accumulator |
10517 | 34 |
35 unwind_protect | |
36 | |
19205
60e54be64f37
Fix ginput for FLTK toolkit
Andreas Weber <andy.weber.aw@gmail.com>
parents:
19202
diff
changeset
|
37 orig_buttondownfcn = get (gca, "buttondownfcn"); |
60e54be64f37
Fix ginput for FLTK toolkit
Andreas Weber <andy.weber.aw@gmail.com>
parents:
19202
diff
changeset
|
38 set (gca, "buttondownfcn", @ginput_buttondownfcn); |
10517 | 39 |
19205
60e54be64f37
Fix ginput for FLTK toolkit
Andreas Weber <andy.weber.aw@gmail.com>
parents:
19202
diff
changeset
|
40 orig_ginput_keypressfcn = get (gcf, "keypressfcn"); |
60e54be64f37
Fix ginput for FLTK toolkit
Andreas Weber <andy.weber.aw@gmail.com>
parents:
19202
diff
changeset
|
41 set (gcf, "keypressfcn", @ginput_keypressfcn); |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
42 |
16787
2cfd8cd9e1b6
__fltk_ginput__.m: Restructure and clean up code.
Rik <rik@octave.org>
parents:
16785
diff
changeset
|
43 do |
19202
c3af040956df
fix FLTK position/outerposition properties, respect units
Andreas Weber <andy.weber.aw@gmail.com>
parents:
17744
diff
changeset
|
44 __fltk_check__ (); |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
45 |
12219
17d7834df7b4
__fltk_ginput__.m: return keypress info
Petr Mikulik <mikulik@physics.muni.cz>
parents:
11587
diff
changeset
|
46 ## Release CPU. |
10517 | 47 sleep (0.01); |
48 | |
16787
2cfd8cd9e1b6
__fltk_ginput__.m: Restructure and clean up code.
Rik <rik@octave.org>
parents:
16785
diff
changeset
|
49 [x, y, n0, button] = ginput_accumulator (-1, 0, 0, 0); |
19567
3492b771c2e6
__fltk_ginput__.m: Fix freeze upon double-click (Bug #43664)
Andreas Weber <andy.weber.aw@gmail.com>
parents:
17744
diff
changeset
|
50 until ((n > -1 && n0 >= n) || n0 < 0) |
3492b771c2e6
__fltk_ginput__.m: Fix freeze upon double-click (Bug #43664)
Andreas Weber <andy.weber.aw@gmail.com>
parents:
17744
diff
changeset
|
51 |
3492b771c2e6
__fltk_ginput__.m: Fix freeze upon double-click (Bug #43664)
Andreas Weber <andy.weber.aw@gmail.com>
parents:
17744
diff
changeset
|
52 if (n0 > n) |
3492b771c2e6
__fltk_ginput__.m: Fix freeze upon double-click (Bug #43664)
Andreas Weber <andy.weber.aw@gmail.com>
parents:
17744
diff
changeset
|
53 ## More clicks than requested due to double-click or too fast clicking |
3492b771c2e6
__fltk_ginput__.m: Fix freeze upon double-click (Bug #43664)
Andreas Weber <andy.weber.aw@gmail.com>
parents:
17744
diff
changeset
|
54 x = x(1:n); |
3492b771c2e6
__fltk_ginput__.m: Fix freeze upon double-click (Bug #43664)
Andreas Weber <andy.weber.aw@gmail.com>
parents:
17744
diff
changeset
|
55 y = y(1:n); |
3492b771c2e6
__fltk_ginput__.m: Fix freeze upon double-click (Bug #43664)
Andreas Weber <andy.weber.aw@gmail.com>
parents:
17744
diff
changeset
|
56 button = button(1:n); |
3492b771c2e6
__fltk_ginput__.m: Fix freeze upon double-click (Bug #43664)
Andreas Weber <andy.weber.aw@gmail.com>
parents:
17744
diff
changeset
|
57 endif |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
58 |
10517 | 59 unwind_protect_cleanup |
19205
60e54be64f37
Fix ginput for FLTK toolkit
Andreas Weber <andy.weber.aw@gmail.com>
parents:
19202
diff
changeset
|
60 set (gca, "buttondownfcn", orig_buttondownfcn); |
60e54be64f37
Fix ginput for FLTK toolkit
Andreas Weber <andy.weber.aw@gmail.com>
parents:
19202
diff
changeset
|
61 set (gcf, "keypressfcn", orig_ginput_keypressfcn); |
10517 | 62 end_unwind_protect |
63 | |
64 endfunction | |
65 | |
16787
2cfd8cd9e1b6
__fltk_ginput__.m: Restructure and clean up code.
Rik <rik@octave.org>
parents:
16785
diff
changeset
|
66 function [x, y, n, button] = ginput_accumulator (mode, xn, yn, btn) |
12219
17d7834df7b4
__fltk_ginput__.m: return keypress info
Petr Mikulik <mikulik@physics.muni.cz>
parents:
11587
diff
changeset
|
67 persistent x y n button; |
10517 | 68 |
11194
b8585f8e11d5
__fltk_ginput__.m: Use semicolons to prevent internal function evaluations being output to screen.
Rik <octave@nomad.inbox5.com>
parents:
11092
diff
changeset
|
69 if (mode == 0) |
12219
17d7834df7b4
__fltk_ginput__.m: return keypress info
Petr Mikulik <mikulik@physics.muni.cz>
parents:
11587
diff
changeset
|
70 ## Initialize. |
16787
2cfd8cd9e1b6
__fltk_ginput__.m: Restructure and clean up code.
Rik <rik@octave.org>
parents:
16785
diff
changeset
|
71 x = y = button = []; |
10517 | 72 n = 0; |
73 elseif (mode == 1) | |
16787
2cfd8cd9e1b6
__fltk_ginput__.m: Restructure and clean up code.
Rik <rik@octave.org>
parents:
16785
diff
changeset
|
74 ## Append mouse button or key press. |
11194
b8585f8e11d5
__fltk_ginput__.m: Use semicolons to prevent internal function evaluations being output to screen.
Rik <octave@nomad.inbox5.com>
parents:
11092
diff
changeset
|
75 x = [x; xn]; |
b8585f8e11d5
__fltk_ginput__.m: Use semicolons to prevent internal function evaluations being output to screen.
Rik <octave@nomad.inbox5.com>
parents:
11092
diff
changeset
|
76 y = [y; yn]; |
12219
17d7834df7b4
__fltk_ginput__.m: return keypress info
Petr Mikulik <mikulik@physics.muni.cz>
parents:
11587
diff
changeset
|
77 button = [button; btn]; |
10517 | 78 n += 1; |
79 elseif (mode == 2) | |
12219
17d7834df7b4
__fltk_ginput__.m: return keypress info
Petr Mikulik <mikulik@physics.muni.cz>
parents:
11587
diff
changeset
|
80 ## The end due to Enter. |
11194
b8585f8e11d5
__fltk_ginput__.m: Use semicolons to prevent internal function evaluations being output to screen.
Rik <octave@nomad.inbox5.com>
parents:
11092
diff
changeset
|
81 n = -1; |
12219
17d7834df7b4
__fltk_ginput__.m: return keypress info
Petr Mikulik <mikulik@physics.muni.cz>
parents:
11587
diff
changeset
|
82 endif |
16787
2cfd8cd9e1b6
__fltk_ginput__.m: Restructure and clean up code.
Rik <rik@octave.org>
parents:
16785
diff
changeset
|
83 |
10517 | 84 endfunction |
85 | |
19205
60e54be64f37
Fix ginput for FLTK toolkit
Andreas Weber <andy.weber.aw@gmail.com>
parents:
19202
diff
changeset
|
86 function ginput_buttondownfcn (src, button) |
60e54be64f37
Fix ginput for FLTK toolkit
Andreas Weber <andy.weber.aw@gmail.com>
parents:
19202
diff
changeset
|
87 point = get (src, "currentpoint"); |
19219
0ee9daa71273
Fix axes property "currentpoint" for FLTK, extend documentation
Andreas Weber <andy.weber.aw@gmail.com>
parents:
19205
diff
changeset
|
88 ginput_accumulator (1, point(1,1), point(1,2), button); |
10517 | 89 endfunction |
90 | |
91 function ginput_keypressfcn (src, evt) | |
19205
60e54be64f37
Fix ginput for FLTK toolkit
Andreas Weber <andy.weber.aw@gmail.com>
parents:
19202
diff
changeset
|
92 point = get (gca, "currentpoint"); |
12219
17d7834df7b4
__fltk_ginput__.m: return keypress info
Petr Mikulik <mikulik@physics.muni.cz>
parents:
11587
diff
changeset
|
93 key = evt.Key; |
19205
60e54be64f37
Fix ginput for FLTK toolkit
Andreas Weber <andy.weber.aw@gmail.com>
parents:
19202
diff
changeset
|
94 if (key == "return") |
16787
2cfd8cd9e1b6
__fltk_ginput__.m: Restructure and clean up code.
Rik <rik@octave.org>
parents:
16785
diff
changeset
|
95 ## Enter key stops ginput. |
2cfd8cd9e1b6
__fltk_ginput__.m: Restructure and clean up code.
Rik <rik@octave.org>
parents:
16785
diff
changeset
|
96 ginput_accumulator (2, NaN, NaN, NaN); |
12219
17d7834df7b4
__fltk_ginput__.m: return keypress info
Petr Mikulik <mikulik@physics.muni.cz>
parents:
11587
diff
changeset
|
97 else |
19219
0ee9daa71273
Fix axes property "currentpoint" for FLTK, extend documentation
Andreas Weber <andy.weber.aw@gmail.com>
parents:
19205
diff
changeset
|
98 ginput_accumulator (1, point(1,1), point(1,2), uint8 (key(1))); |
10517 | 99 endif |
100 endfunction | |
101 |