Mercurial > hg > octave-lyh
annotate scripts/plot/private/__fltk_ginput__.m @ 13808:d5bfaa582eaa
correctly handle RGB color spec for patch object
* __patch__.m: Set facecolor from RGB color spec
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 03 Nov 2011 16:14:28 -0400 |
parents | 6f91ca83d2be |
children | 72c96de7a403 |
rev | line source |
---|---|
11523 | 1 ## Copyright (C) 2010-2011 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 -*- | |
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 | |
12219
17d7834df7b4
__fltk_ginput__.m: return keypress info
Petr Mikulik <mikulik@physics.muni.cz>
parents:
11587
diff
changeset
|
26 ## FIXME -- Key presses cannot toggle menu items nor hotkey functionality |
17d7834df7b4
__fltk_ginput__.m: return keypress info
Petr Mikulik <mikulik@physics.muni.cz>
parents:
11587
diff
changeset
|
27 ## (grid, autoscale) during ginput! |
17d7834df7b4
__fltk_ginput__.m: return keypress info
Petr Mikulik <mikulik@physics.muni.cz>
parents:
11587
diff
changeset
|
28 |
10517 | 29 function [x, y, button] = __fltk_ginput__ (f, n = -1) |
30 | |
31 if (isempty (get (f, "currentaxes"))) | |
32 error ("ginput: must have at least one axes"); | |
33 endif | |
34 | |
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
|
35 x = y = button = []; |
12219
17d7834df7b4
__fltk_ginput__.m: return keypress info
Petr Mikulik <mikulik@physics.muni.cz>
parents:
11587
diff
changeset
|
36 ginput_aggregator (0, 0, 0, 0); |
10517 | 37 |
38 unwind_protect | |
39 | |
40 orig_windowbuttondownfcn = get (f, "windowbuttondownfcn"); | |
41 set (f, "windowbuttondownfcn", @ginput_windowbuttondownfcn); | |
42 | |
43 orig_ginput_keypressfcn = get (f, "keypressfcn"); | |
44 set (f, "keypressfcn", @ginput_keypressfcn); | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
45 |
10517 | 46 while (true) |
47 __fltk_redraw__ (); | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
48 |
12219
17d7834df7b4
__fltk_ginput__.m: return keypress info
Petr Mikulik <mikulik@physics.muni.cz>
parents:
11587
diff
changeset
|
49 ## Release CPU. |
10517 | 50 sleep (0.01); |
51 | |
12219
17d7834df7b4
__fltk_ginput__.m: return keypress info
Petr Mikulik <mikulik@physics.muni.cz>
parents:
11587
diff
changeset
|
52 [x, y, n0, button] = ginput_aggregator (-1, 0, 0, 0); |
11092
8b9aeb20c03c
__fltk_ginput__.m: use || instead of | in IF condition
John W. Eaton <jwe@octave.org>
parents:
10517
diff
changeset
|
53 if (n0 == n || n0 < 0) |
10517 | 54 break; |
55 endif | |
56 endwhile | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
57 |
10517 | 58 unwind_protect_cleanup |
59 set (f, "windowbuttondownfcn", orig_windowbuttondownfcn); | |
60 set (f, "keypressfcn", orig_ginput_keypressfcn); | |
61 end_unwind_protect | |
62 | |
63 endfunction | |
64 | |
12219
17d7834df7b4
__fltk_ginput__.m: return keypress info
Petr Mikulik <mikulik@physics.muni.cz>
parents:
11587
diff
changeset
|
65 function [x, y, n, button] = ginput_aggregator (mode, xn, yn, btn) |
17d7834df7b4
__fltk_ginput__.m: return keypress info
Petr Mikulik <mikulik@physics.muni.cz>
parents:
11587
diff
changeset
|
66 persistent x y n button; |
10517 | 67 |
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
|
68 if (mode == 0) |
12219
17d7834df7b4
__fltk_ginput__.m: return keypress info
Petr Mikulik <mikulik@physics.muni.cz>
parents:
11587
diff
changeset
|
69 ## Initialize. |
10517 | 70 x = []; |
71 y = []; | |
12219
17d7834df7b4
__fltk_ginput__.m: return keypress info
Petr Mikulik <mikulik@physics.muni.cz>
parents:
11587
diff
changeset
|
72 button = []; |
10517 | 73 n = 0; |
74 elseif (mode == 1) | |
12219
17d7834df7b4
__fltk_ginput__.m: return keypress info
Petr Mikulik <mikulik@physics.muni.cz>
parents:
11587
diff
changeset
|
75 ## Accept 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
|
76 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
|
77 y = [y; yn]; |
12219
17d7834df7b4
__fltk_ginput__.m: return keypress info
Petr Mikulik <mikulik@physics.muni.cz>
parents:
11587
diff
changeset
|
78 button = [button; btn]; |
10517 | 79 n += 1; |
80 elseif (mode == 2) | |
12219
17d7834df7b4
__fltk_ginput__.m: return keypress info
Petr Mikulik <mikulik@physics.muni.cz>
parents:
11587
diff
changeset
|
81 ## 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
|
82 n = -1; |
12219
17d7834df7b4
__fltk_ginput__.m: return keypress info
Petr Mikulik <mikulik@physics.muni.cz>
parents:
11587
diff
changeset
|
83 endif |
10517 | 84 endfunction |
85 | |
86 function ginput_windowbuttondownfcn (src, data) | |
87 point = get (get (src,"currentaxes"), "currentpoint"); | |
12219
17d7834df7b4
__fltk_ginput__.m: return keypress info
Petr Mikulik <mikulik@physics.muni.cz>
parents:
11587
diff
changeset
|
88 ## FIXME -- How to get the actual mouse button pressed (1,2,3) into |
17d7834df7b4
__fltk_ginput__.m: return keypress info
Petr Mikulik <mikulik@physics.muni.cz>
parents:
11587
diff
changeset
|
89 ## "button"? |
17d7834df7b4
__fltk_ginput__.m: return keypress info
Petr Mikulik <mikulik@physics.muni.cz>
parents:
11587
diff
changeset
|
90 button = 1; |
17d7834df7b4
__fltk_ginput__.m: return keypress info
Petr Mikulik <mikulik@physics.muni.cz>
parents:
11587
diff
changeset
|
91 ginput_aggregator (1, point(1,1), point(2,1), button); |
10517 | 92 endfunction |
93 | |
94 function ginput_keypressfcn (src, evt) | |
12219
17d7834df7b4
__fltk_ginput__.m: return keypress info
Petr Mikulik <mikulik@physics.muni.cz>
parents:
11587
diff
changeset
|
95 point = get (get (src, "currentaxes"), "currentpoint"); |
17d7834df7b4
__fltk_ginput__.m: return keypress info
Petr Mikulik <mikulik@physics.muni.cz>
parents:
11587
diff
changeset
|
96 ## FIXME -- use evt.Key or evt.Character? |
17d7834df7b4
__fltk_ginput__.m: return keypress info
Petr Mikulik <mikulik@physics.muni.cz>
parents:
11587
diff
changeset
|
97 key = evt.Key; |
17d7834df7b4
__fltk_ginput__.m: return keypress info
Petr Mikulik <mikulik@physics.muni.cz>
parents:
11587
diff
changeset
|
98 if (key == 10) |
17d7834df7b4
__fltk_ginput__.m: return keypress info
Petr Mikulik <mikulik@physics.muni.cz>
parents:
11587
diff
changeset
|
99 ## Enter key. |
17d7834df7b4
__fltk_ginput__.m: return keypress info
Petr Mikulik <mikulik@physics.muni.cz>
parents:
11587
diff
changeset
|
100 ginput_aggregator (2, point(1,1), point(2,1), key); |
17d7834df7b4
__fltk_ginput__.m: return keypress info
Petr Mikulik <mikulik@physics.muni.cz>
parents:
11587
diff
changeset
|
101 else |
17d7834df7b4
__fltk_ginput__.m: return keypress info
Petr Mikulik <mikulik@physics.muni.cz>
parents:
11587
diff
changeset
|
102 ginput_aggregator (1, point(1,1), point(2,1), key); |
10517 | 103 endif |
104 endfunction | |
105 |