2847
|
1 ## Copyright (C) 1996, 1997 John W. Eaton |
2313
|
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 2, or (at your option) |
|
8 ## 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, write to the Free |
5307
|
17 ## Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
18 ## 02110-1301, USA. |
2290
|
19 |
3368
|
20 ## -*- texinfo -*- |
|
21 ## @deftypefn {Function File} {} figure (@var{n}) |
6257
|
22 ## Set the current plot window to plot window @var{n}. If @var{n} is |
|
23 ## not specified, the next available window number is chosen. |
3368
|
24 ## @end deftypefn |
2290
|
25 |
6257
|
26 ## Author: jwe, Bill Denney |
2314
|
27 |
6257
|
28 function h = figure (varargin) |
3263
|
29 |
6257
|
30 nargs = nargin; |
5406
|
31 |
6283
|
32 f = []; |
|
33 |
6293
|
34 init_new_figure = false; |
6283
|
35 if (mod (nargs, 2) == 1) |
6257
|
36 tmp = varargin{1}; |
|
37 if (ishandle (tmp) && strcmp (get (tmp, "type"), "figure")) |
|
38 f = tmp; |
|
39 varargin(1) = []; |
|
40 nargs--; |
|
41 elseif (isnumeric (tmp) && tmp > 0 && round (tmp) == tmp) |
|
42 f = tmp; |
6293
|
43 init_new_figure = true; |
6257
|
44 varargin(1) = []; |
|
45 nargs--; |
|
46 else |
|
47 error ("figure: expecting figure handle or figure number"); |
|
48 endif |
3263
|
49 endif |
|
50 |
6293
|
51 ## Check to see if we already have a figure on the screen. If we do, |
|
52 ## then update it if it is different from the figure we are creating |
|
53 ## or switching to. |
|
54 cf = get (0, "currentfigure"); |
|
55 if (! isempty (cf) && cf != 0) |
|
56 if (isempty (f) || cf != f) |
|
57 drawnow (); |
|
58 endif |
|
59 endif |
|
60 |
6257
|
61 if (rem (nargs, 2) == 0) |
6293
|
62 if (isempty (f) || init_new_figure) |
|
63 f = __uiobject_init_figure__ (f); |
6283
|
64 endif |
6257
|
65 if (nargs > 0) |
|
66 set (f, varargin{:}); |
2290
|
67 endif |
6257
|
68 __uiobject_adopt__ (0, f); |
|
69 set (0, "currentfigure", f); |
2290
|
70 else |
6046
|
71 print_usage (); |
2290
|
72 endif |
3263
|
73 |
6283
|
74 if (nargout > 0) |
|
75 h = f; |
|
76 endif |
|
77 |
2290
|
78 endfunction |