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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
9cdd6c8c05a4 [mq]: fltk_cb
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff changeset
2 ##
9cdd6c8c05a4 [mq]: fltk_cb
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff changeset
3 ## This file is part of Octave.
9cdd6c8c05a4 [mq]: fltk_cb
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff changeset
4 ##
9cdd6c8c05a4 [mq]: fltk_cb
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff changeset
5 ## Octave is free software; you can redistribute it and/or modify it
9cdd6c8c05a4 [mq]: fltk_cb
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff changeset
6 ## under the terms of the GNU General Public License as published by
9cdd6c8c05a4 [mq]: fltk_cb
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff changeset
7 ## the Free Software Foundation; either version 3 of the License, or (at
9cdd6c8c05a4 [mq]: fltk_cb
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff changeset
8 ## your option) any later version.
9cdd6c8c05a4 [mq]: fltk_cb
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff changeset
9 ##
9cdd6c8c05a4 [mq]: fltk_cb
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff changeset
10 ## Octave is distributed in the hope that it will be useful, but
9cdd6c8c05a4 [mq]: fltk_cb
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff changeset
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
9cdd6c8c05a4 [mq]: fltk_cb
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff changeset
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
9cdd6c8c05a4 [mq]: fltk_cb
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff changeset
13 ## General Public License for more details.
9cdd6c8c05a4 [mq]: fltk_cb
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff changeset
14 ##
9cdd6c8c05a4 [mq]: fltk_cb
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff changeset
15 ## You should have received a copy of the GNU General Public License
9cdd6c8c05a4 [mq]: fltk_cb
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff changeset
16 ## along with Octave; see the file COPYING. If not, see
9cdd6c8c05a4 [mq]: fltk_cb
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff changeset
17 ## <http://www.gnu.org/licenses/>.
9cdd6c8c05a4 [mq]: fltk_cb
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff changeset
18
9cdd6c8c05a4 [mq]: fltk_cb
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff changeset
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
9cdd6c8c05a4 [mq]: fltk_cb
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff changeset
21 ## Undocumented internal function.
9cdd6c8c05a4 [mq]: fltk_cb
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff changeset
22 ## @end deftypefn
9cdd6c8c05a4 [mq]: fltk_cb
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff changeset
23
9cdd6c8c05a4 [mq]: fltk_cb
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff changeset
24 ## This is ginput.m implementation for fltk.
9cdd6c8c05a4 [mq]: fltk_cb
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff changeset
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
9cdd6c8c05a4 [mq]: fltk_cb
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff changeset
27
19205
60e54be64f37 Fix ginput for FLTK toolkit
Andreas Weber <andy.weber.aw@gmail.com>
parents: 19202
diff changeset
28 if (isempty (gca))
10517
9cdd6c8c05a4 [mq]: fltk_cb
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff changeset
29 error ("ginput: must have at least one axes");
9cdd6c8c05a4 [mq]: fltk_cb
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff changeset
30 endif
9cdd6c8c05a4 [mq]: fltk_cb
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff changeset
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
9cdd6c8c05a4 [mq]: fltk_cb
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff changeset
34
9cdd6c8c05a4 [mq]: fltk_cb
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff changeset
35 unwind_protect
9cdd6c8c05a4 [mq]: fltk_cb
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff changeset
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
9cdd6c8c05a4 [mq]: fltk_cb
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff changeset
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
9cdd6c8c05a4 [mq]: fltk_cb
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff changeset
47 sleep (0.01);
9cdd6c8c05a4 [mq]: fltk_cb
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff changeset
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
9cdd6c8c05a4 [mq]: fltk_cb
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff changeset
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
9cdd6c8c05a4 [mq]: fltk_cb
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff changeset
62 end_unwind_protect
9cdd6c8c05a4 [mq]: fltk_cb
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff changeset
63
9cdd6c8c05a4 [mq]: fltk_cb
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff changeset
64 endfunction
9cdd6c8c05a4 [mq]: fltk_cb
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff changeset
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
9cdd6c8c05a4 [mq]: fltk_cb
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff changeset
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
9cdd6c8c05a4 [mq]: fltk_cb
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff changeset
72 n = 0;
9cdd6c8c05a4 [mq]: fltk_cb
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff changeset
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
9cdd6c8c05a4 [mq]: fltk_cb
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff changeset
78 n += 1;
9cdd6c8c05a4 [mq]: fltk_cb
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff changeset
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
9cdd6c8c05a4 [mq]: fltk_cb
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff changeset
84 endfunction
9cdd6c8c05a4 [mq]: fltk_cb
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff changeset
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
9cdd6c8c05a4 [mq]: fltk_cb
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff changeset
89 endfunction
9cdd6c8c05a4 [mq]: fltk_cb
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff changeset
90
9cdd6c8c05a4 [mq]: fltk_cb
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff changeset
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
9cdd6c8c05a4 [mq]: fltk_cb
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff changeset
99 endif
9cdd6c8c05a4 [mq]: fltk_cb
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff changeset
100 endfunction
9cdd6c8c05a4 [mq]: fltk_cb
Shai Ayal <shaiay@users.sourceforge.net>
parents:
diff changeset
101