annotate scripts/gui/movegui.m @ 31548:c8ad083a5802 stable

maint: Clean up m-files before Octave 8.1 release. * external.txi, oop.txi, Table.h, documentation.cc, gui-preferences-ed.h, lo-specfun.cc, range.tst : Eliminate triple newlines. * Map.m, MemoizedFunction.m, delaunayn.m, inputParser.m, __publish_latex_output__.m, publish.m, unpack.m, fminbnd.m, __add_default_menu__.m, gammainc.m, gallery.m, hadamard.m, weboptions.m: Add newline after keyword "function" or before keyword "endfunction" for readability. * getaudiodata.m, pkg.m : Add semicolon to end of line for error() statement. * movegui.m: Combine mutliple calls to set() into one for performance. * __unimplemented__.m (missing_functions): Remove missing functions that have been implemented. * __vectorize__.m, check_default_input.m, betaincinv.m, gammaincinv.m: Remove semicolon at end of line with "function" declaration. * weboptions.m: Remove semicolon at end of line with "if" keyword. * integrate_adaptive.m, factor.m: Use keyword "endif" rather than bare "end".
author Rik <rik@octave.org>
date Fri, 25 Nov 2022 21:23:54 -0800
parents 796f54d4ddbf
children 597f3ee61a48
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
1 ########################################################################
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
2 ##
30564
796f54d4ddbf update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents: 29359
diff changeset
3 ## Copyright (C) 2018-2022 The Octave Project Developers
27918
b442ec6dda5c use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
4 ##
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
5 ## See the file COPYRIGHT.md in the top-level directory of this
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
6 ## distribution or <https://octave.org/copyright/>.
25970
3a66ae436d8a movegui: new function
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff changeset
7 ##
3a66ae436d8a movegui: new function
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff changeset
8 ## This file is part of Octave.
3a66ae436d8a movegui: new function
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff changeset
9 ##
3a66ae436d8a movegui: new function
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff changeset
10 ## Octave is free software: you can redistribute it and/or modify it
3a66ae436d8a movegui: new function
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff changeset
11 ## under the terms of the GNU General Public License as published by
3a66ae436d8a movegui: new function
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff changeset
12 ## the Free Software Foundation, either version 3 of the License, or
3a66ae436d8a movegui: new function
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff changeset
13 ## (at your option) any later version.
3a66ae436d8a movegui: new function
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff changeset
14 ## your option) any later version.
3a66ae436d8a movegui: new function
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff changeset
15 ##
3a66ae436d8a movegui: new function
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff changeset
16 ## Octave is distributed in the hope that it will be useful, but
3a66ae436d8a movegui: new function
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff changeset
17 ## WITHOUT ANY WARRANTY; without even the implied warranty of
3a66ae436d8a movegui: new function
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff changeset
18 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3a66ae436d8a movegui: new function
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff changeset
19 ## GNU General Public License for more details.
3a66ae436d8a movegui: new function
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff changeset
20 ##
3a66ae436d8a movegui: new function
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff changeset
21 ## You should have received a copy of the GNU General Public License
3a66ae436d8a movegui: new function
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff changeset
22 ## along with Octave; see the filename COPYING. If not, see
3a66ae436d8a movegui: new function
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff changeset
23 ## <https://www.gnu.org/licenses/>.
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
24 ##
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
25 ########################################################################
25970
3a66ae436d8a movegui: new function
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff changeset
26
3a66ae436d8a movegui: new function
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff changeset
27 ## -*- texinfo -*-
25978
be759ed27041 movegui.m: Clean up function.
Rik <rik@octave.org>
parents: 25970
diff changeset
28 ## @deftypefn {} {} movegui
be759ed27041 movegui.m: Clean up function.
Rik <rik@octave.org>
parents: 25970
diff changeset
29 ## @deftypefnx {} {} movegui (@var{h})
be759ed27041 movegui.m: Clean up function.
Rik <rik@octave.org>
parents: 25970
diff changeset
30 ## @deftypefnx {} {} movegui (@var{pos})
be759ed27041 movegui.m: Clean up function.
Rik <rik@octave.org>
parents: 25970
diff changeset
31 ## @deftypefnx {} {} movegui (@var{h}, @var{pos})
be759ed27041 movegui.m: Clean up function.
Rik <rik@octave.org>
parents: 25970
diff changeset
32 ## @deftypefnx {} {} movegui (@var{h}, @var{event})
be759ed27041 movegui.m: Clean up function.
Rik <rik@octave.org>
parents: 25970
diff changeset
33 ## @deftypefnx {} {} movegui (@var{h}, @var{event}, @var{pos})
25970
3a66ae436d8a movegui: new function
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff changeset
34 ## Move a figure specified by figure handle @var{h} to a position on the screen
3a66ae436d8a movegui: new function
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff changeset
35 ## defined by @var{pos}.
3a66ae436d8a movegui: new function
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff changeset
36 ##
3a66ae436d8a movegui: new function
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff changeset
37 ## @var{h} is a figure handle, or a handle to a graphics object. In the latter
25978
be759ed27041 movegui.m: Clean up function.
Rik <rik@octave.org>
parents: 25970
diff changeset
38 ## case, its parent figure will be used. If unspecified, @var{h} will be
be759ed27041 movegui.m: Clean up function.
Rik <rik@octave.org>
parents: 25970
diff changeset
39 ## set to the handle of the relevant figure if a callback is being executed
be759ed27041 movegui.m: Clean up function.
Rik <rik@octave.org>
parents: 25970
diff changeset
40 ## (@code{gcbf}), otherwise it will be set to the handle of the current figure
be759ed27041 movegui.m: Clean up function.
Rik <rik@octave.org>
parents: 25970
diff changeset
41 ## (@code{gcf}).
25970
3a66ae436d8a movegui: new function
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff changeset
42 ##
25978
be759ed27041 movegui.m: Clean up function.
Rik <rik@octave.org>
parents: 25970
diff changeset
43 ## @var{pos} is either a two-value numeric vector or a string. If @var{pos} is
be759ed27041 movegui.m: Clean up function.
Rik <rik@octave.org>
parents: 25970
diff changeset
44 ## numeric then it must be of the form @code{[h, v]} specifying the horizontal
be759ed27041 movegui.m: Clean up function.
Rik <rik@octave.org>
parents: 25970
diff changeset
45 ## and vertical offsets of the figure with respect to the screen. A positive
be759ed27041 movegui.m: Clean up function.
Rik <rik@octave.org>
parents: 25970
diff changeset
46 ## value indicates the offset between the left (or bottom for the vertical
be759ed27041 movegui.m: Clean up function.
Rik <rik@octave.org>
parents: 25970
diff changeset
47 ## component) of the screen, and the left (or bottom) of the figure. A
be759ed27041 movegui.m: Clean up function.
Rik <rik@octave.org>
parents: 25970
diff changeset
48 ## negative value indicates the offset between the right (or top) of the screen
be759ed27041 movegui.m: Clean up function.
Rik <rik@octave.org>
parents: 25970
diff changeset
49 ## and the right (or top) of the figure.
25970
3a66ae436d8a movegui: new function
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff changeset
50 ##
25978
be759ed27041 movegui.m: Clean up function.
Rik <rik@octave.org>
parents: 25970
diff changeset
51 ## Possible values for @var{pos} as a string are
25970
3a66ae436d8a movegui: new function
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff changeset
52 ##
3a66ae436d8a movegui: new function
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff changeset
53 ## @table @code
3a66ae436d8a movegui: new function
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff changeset
54 ## @item north
3a66ae436d8a movegui: new function
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff changeset
55 ## Top center of the screen.
25978
be759ed27041 movegui.m: Clean up function.
Rik <rik@octave.org>
parents: 25970
diff changeset
56 ##
25970
3a66ae436d8a movegui: new function
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff changeset
57 ## @item south
3a66ae436d8a movegui: new function
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff changeset
58 ## Bottom center of the screen.
25978
be759ed27041 movegui.m: Clean up function.
Rik <rik@octave.org>
parents: 25970
diff changeset
59 ##
25970
3a66ae436d8a movegui: new function
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff changeset
60 ## @item east
3a66ae436d8a movegui: new function
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff changeset
61 ## Right center of the screen.
25978
be759ed27041 movegui.m: Clean up function.
Rik <rik@octave.org>
parents: 25970
diff changeset
62 ##
25970
3a66ae436d8a movegui: new function
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff changeset
63 ## @item west
3a66ae436d8a movegui: new function
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff changeset
64 ## Left center of the screen.
25978
be759ed27041 movegui.m: Clean up function.
Rik <rik@octave.org>
parents: 25970
diff changeset
65 ##
25970
3a66ae436d8a movegui: new function
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff changeset
66 ## @item northeast
3a66ae436d8a movegui: new function
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff changeset
67 ## Top right of the screen.
25978
be759ed27041 movegui.m: Clean up function.
Rik <rik@octave.org>
parents: 25970
diff changeset
68 ##
25970
3a66ae436d8a movegui: new function
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff changeset
69 ## @item northwest
3a66ae436d8a movegui: new function
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff changeset
70 ## Top left of the screen.
25978
be759ed27041 movegui.m: Clean up function.
Rik <rik@octave.org>
parents: 25970
diff changeset
71 ##
25970
3a66ae436d8a movegui: new function
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff changeset
72 ## @item southeast
3a66ae436d8a movegui: new function
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff changeset
73 ## Bottom right of the screen.
25978
be759ed27041 movegui.m: Clean up function.
Rik <rik@octave.org>
parents: 25970
diff changeset
74 ##
25970
3a66ae436d8a movegui: new function
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff changeset
75 ## @item southwest
3a66ae436d8a movegui: new function
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff changeset
76 ## Bottom left of the screen.
25978
be759ed27041 movegui.m: Clean up function.
Rik <rik@octave.org>
parents: 25970
diff changeset
77 ##
25970
3a66ae436d8a movegui: new function
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff changeset
78 ## @item center
3a66ae436d8a movegui: new function
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff changeset
79 ## Center of the screen.
25978
be759ed27041 movegui.m: Clean up function.
Rik <rik@octave.org>
parents: 25970
diff changeset
80 ##
be759ed27041 movegui.m: Clean up function.
Rik <rik@octave.org>
parents: 25970
diff changeset
81 ## @item onscreen (default)
be759ed27041 movegui.m: Clean up function.
Rik <rik@octave.org>
parents: 25970
diff changeset
82 ## The figure will be minimally moved to be entirely visible on the screen,
be759ed27041 movegui.m: Clean up function.
Rik <rik@octave.org>
parents: 25970
diff changeset
83 ## with a 30 pixel extra padding from the sides of the screen. This is the
be759ed27041 movegui.m: Clean up function.
Rik <rik@octave.org>
parents: 25970
diff changeset
84 ## default value if none is provided.
25970
3a66ae436d8a movegui: new function
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff changeset
85 ## @end table
3a66ae436d8a movegui: new function
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff changeset
86 ##
3a66ae436d8a movegui: new function
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff changeset
87 ## @var{event} contains event data that will be ignored. This construct
3a66ae436d8a movegui: new function
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff changeset
88 ## facilitates a call to movegui from a callback.
3a66ae436d8a movegui: new function
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff changeset
89 ##
3a66ae436d8a movegui: new function
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff changeset
90 ## @end deftypefn
3a66ae436d8a movegui: new function
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff changeset
91
3a66ae436d8a movegui: new function
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff changeset
92 function movegui (varargin)
3a66ae436d8a movegui: new function
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff changeset
93
3a66ae436d8a movegui: new function
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff changeset
94 if (nargin > 3)
3a66ae436d8a movegui: new function
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff changeset
95 print_usage ();
3a66ae436d8a movegui: new function
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff changeset
96 endif
3a66ae436d8a movegui: new function
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff changeset
97
3a66ae436d8a movegui: new function
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff changeset
98 ## Default values for input arguments
3a66ae436d8a movegui: new function
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff changeset
99 h = [];
3a66ae436d8a movegui: new function
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff changeset
100 pos = "onscreen";
3a66ae436d8a movegui: new function
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff changeset
101
3a66ae436d8a movegui: new function
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff changeset
102 ## Get input arguments
3a66ae436d8a movegui: new function
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff changeset
103 if (nargin == 3)
3a66ae436d8a movegui: new function
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff changeset
104 h = varargin{1};
3a66ae436d8a movegui: new function
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff changeset
105 pos = varargin{3};
3a66ae436d8a movegui: new function
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff changeset
106 elseif (nargin == 2)
3a66ae436d8a movegui: new function
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff changeset
107 h = varargin{1};
3a66ae436d8a movegui: new function
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff changeset
108 pos = varargin{2};
3a66ae436d8a movegui: new function
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff changeset
109 elseif (nargin == 1)
3a66ae436d8a movegui: new function
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff changeset
110 if (ishghandle (varargin{1}) && isscalar (varargin{1}))
3a66ae436d8a movegui: new function
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff changeset
111 h = varargin{1};
3a66ae436d8a movegui: new function
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff changeset
112 else
3a66ae436d8a movegui: new function
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff changeset
113 pos = varargin{1};
3a66ae436d8a movegui: new function
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff changeset
114 endif
3a66ae436d8a movegui: new function
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff changeset
115 endif
3a66ae436d8a movegui: new function
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff changeset
116
3a66ae436d8a movegui: new function
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff changeset
117 ## Check figure handle
3a66ae436d8a movegui: new function
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff changeset
118 if (isempty (h))
3a66ae436d8a movegui: new function
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff changeset
119 h = gcbf ();
3a66ae436d8a movegui: new function
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff changeset
120 if (isempty (h))
3a66ae436d8a movegui: new function
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff changeset
121 h = gcf ();
3a66ae436d8a movegui: new function
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff changeset
122 endif
25978
be759ed27041 movegui.m: Clean up function.
Rik <rik@octave.org>
parents: 25970
diff changeset
123 elseif (ishghandle (h))
25970
3a66ae436d8a movegui: new function
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff changeset
124 h = ancestor (h, "figure");
3a66ae436d8a movegui: new function
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff changeset
125 else
25978
be759ed27041 movegui.m: Clean up function.
Rik <rik@octave.org>
parents: 25970
diff changeset
126 error ("movegui: H must be a graphics handle");
25970
3a66ae436d8a movegui: new function
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff changeset
127 endif
3a66ae436d8a movegui: new function
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff changeset
128
25978
be759ed27041 movegui.m: Clean up function.
Rik <rik@octave.org>
parents: 25970
diff changeset
129 ## Get current position in pixels
be759ed27041 movegui.m: Clean up function.
Rik <rik@octave.org>
parents: 25970
diff changeset
130 units_fig = get (h, "units");
be759ed27041 movegui.m: Clean up function.
Rik <rik@octave.org>
parents: 25970
diff changeset
131 set (h, "units", "pixels");
be759ed27041 movegui.m: Clean up function.
Rik <rik@octave.org>
parents: 25970
diff changeset
132 fpos = get (h, "position"); # OuterPosition seems unreliable
be759ed27041 movegui.m: Clean up function.
Rik <rik@octave.org>
parents: 25970
diff changeset
133 set (h, "units", units_fig);
25970
3a66ae436d8a movegui: new function
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff changeset
134
25978
be759ed27041 movegui.m: Clean up function.
Rik <rik@octave.org>
parents: 25970
diff changeset
135 ## Get screen size in pixels
be759ed27041 movegui.m: Clean up function.
Rik <rik@octave.org>
parents: 25970
diff changeset
136 units_groot = get (groot (), "units");
be759ed27041 movegui.m: Clean up function.
Rik <rik@octave.org>
parents: 25970
diff changeset
137 set (groot (), "units", "pixels");
25970
3a66ae436d8a movegui: new function
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff changeset
138 screen_size = get (groot (), "ScreenSize");
25978
be759ed27041 movegui.m: Clean up function.
Rik <rik@octave.org>
parents: 25970
diff changeset
139 set (groot (), "units", units_groot);
25970
3a66ae436d8a movegui: new function
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff changeset
140
3a66ae436d8a movegui: new function
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff changeset
141 ## Set default figure and screen border sizes [left, top, right, bottom]
25978
be759ed27041 movegui.m: Clean up function.
Rik <rik@octave.org>
parents: 25970
diff changeset
142 f = [0, 90, 0, 30];
be759ed27041 movegui.m: Clean up function.
Rik <rik@octave.org>
parents: 25970
diff changeset
143 s = [0, 0, 0, 30];
25970
3a66ae436d8a movegui: new function
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff changeset
144
3a66ae436d8a movegui: new function
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff changeset
145 ## Make sure figure is not larger than screen
3a66ae436d8a movegui: new function
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff changeset
146 fpos(1) = max (fpos(1), 1);
3a66ae436d8a movegui: new function
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff changeset
147 fpos(2) = max (fpos(2), 1);
3a66ae436d8a movegui: new function
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff changeset
148 fpos(3) = min (fpos(3), screen_size(3));
3a66ae436d8a movegui: new function
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff changeset
149 fpos(4) = min (fpos(4), screen_size(4));
3a66ae436d8a movegui: new function
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff changeset
150
3a66ae436d8a movegui: new function
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff changeset
151 ## Standard figure coordinates
3a66ae436d8a movegui: new function
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff changeset
152 ## left, middle, right
3a66ae436d8a movegui: new function
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff changeset
153 x = [s(1)+f(1), (screen_size(3)-fpos(3))/2, screen_size(3)-fpos(3)-s(3)-f(3)];
3a66ae436d8a movegui: new function
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff changeset
154 ## bottom, middle top
3a66ae436d8a movegui: new function
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff changeset
155 y = [s(4)+f(4), (screen_size(4)-fpos(4))/2, screen_size(4)-fpos(4)-s(2)-f(2)];
3a66ae436d8a movegui: new function
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff changeset
156
3a66ae436d8a movegui: new function
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff changeset
157 ## Compute new position
3a66ae436d8a movegui: new function
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff changeset
158 if (isnumeric (pos) && isreal (pos) && numel (pos) == 2)
3a66ae436d8a movegui: new function
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff changeset
159 fpos(1) = ifelse (pos(1) >= 0, pos(1), pos(1) + x(3));
3a66ae436d8a movegui: new function
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff changeset
160 fpos(2) = ifelse (pos(2) >= 0, pos(2), pos(2) + y(3));
3a66ae436d8a movegui: new function
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff changeset
161 elseif (ischar (pos))
3a66ae436d8a movegui: new function
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff changeset
162 switch (tolower (pos))
3a66ae436d8a movegui: new function
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff changeset
163 case "north"
25978
be759ed27041 movegui.m: Clean up function.
Rik <rik@octave.org>
parents: 25970
diff changeset
164 fpos(1:2) = [x(2), y(3)];
25970
3a66ae436d8a movegui: new function
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff changeset
165 case "south"
25978
be759ed27041 movegui.m: Clean up function.
Rik <rik@octave.org>
parents: 25970
diff changeset
166 fpos(1:2) = [x(2), y(1)];
25970
3a66ae436d8a movegui: new function
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff changeset
167 case "east"
25978
be759ed27041 movegui.m: Clean up function.
Rik <rik@octave.org>
parents: 25970
diff changeset
168 fpos(1:2) = [x(3), y(2)];
25970
3a66ae436d8a movegui: new function
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff changeset
169 case "west"
25978
be759ed27041 movegui.m: Clean up function.
Rik <rik@octave.org>
parents: 25970
diff changeset
170 fpos(1:2) = [x(1), y(2)];
25970
3a66ae436d8a movegui: new function
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff changeset
171 case "northeast"
25978
be759ed27041 movegui.m: Clean up function.
Rik <rik@octave.org>
parents: 25970
diff changeset
172 fpos(1:2) = [x(3), y(3)];
25970
3a66ae436d8a movegui: new function
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff changeset
173 case "northwest"
25978
be759ed27041 movegui.m: Clean up function.
Rik <rik@octave.org>
parents: 25970
diff changeset
174 fpos(1:2) = [x(1), y(3)];
25970
3a66ae436d8a movegui: new function
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff changeset
175 case "southeast"
25978
be759ed27041 movegui.m: Clean up function.
Rik <rik@octave.org>
parents: 25970
diff changeset
176 fpos(1:2) = [x(3), y(1)];
25970
3a66ae436d8a movegui: new function
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff changeset
177 case "southwest"
25978
be759ed27041 movegui.m: Clean up function.
Rik <rik@octave.org>
parents: 25970
diff changeset
178 fpos(1:2) = [x(1), y(1)];
25970
3a66ae436d8a movegui: new function
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff changeset
179 case "center"
25978
be759ed27041 movegui.m: Clean up function.
Rik <rik@octave.org>
parents: 25970
diff changeset
180 fpos(1:2) = [x(2), y(2)];
25970
3a66ae436d8a movegui: new function
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff changeset
181 case "onscreen"
3a66ae436d8a movegui: new function
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff changeset
182 if (fpos(1) > x(3))
3a66ae436d8a movegui: new function
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff changeset
183 fpos(1) = x(3) - 30;
3a66ae436d8a movegui: new function
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff changeset
184 endif
3a66ae436d8a movegui: new function
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff changeset
185 if (fpos(2) > y(3))
3a66ae436d8a movegui: new function
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff changeset
186 fpos(2) = y(3) - 30;
3a66ae436d8a movegui: new function
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff changeset
187 endif
28912
0de38a6ef693 maint: Use Octave convention of space after function name in scripts dir.
Rik <rik@octave.org>
parents: 27923
diff changeset
188 fpos(1) = max (fpos(1), 30);
0de38a6ef693 maint: Use Octave convention of space after function name in scripts dir.
Rik <rik@octave.org>
parents: 27923
diff changeset
189 fpos(2) = max (fpos(2), 30);
25970
3a66ae436d8a movegui: new function
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff changeset
190 otherwise
3a66ae436d8a movegui: new function
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff changeset
191 error ("movegui: invalid position");
3a66ae436d8a movegui: new function
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff changeset
192 endswitch
3a66ae436d8a movegui: new function
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff changeset
193 elseif (nargin == 2 && ! isempty (gcbo))
3a66ae436d8a movegui: new function
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff changeset
194 ## Ignore event data (from callback)
3a66ae436d8a movegui: new function
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff changeset
195 movegui (h);
3a66ae436d8a movegui: new function
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff changeset
196 return;
3a66ae436d8a movegui: new function
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff changeset
197 else
3a66ae436d8a movegui: new function
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff changeset
198 error ("movegui: invalid position");
3a66ae436d8a movegui: new function
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff changeset
199 endif
3a66ae436d8a movegui: new function
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff changeset
200
3a66ae436d8a movegui: new function
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff changeset
201 ## Move figure
31548
c8ad083a5802 maint: Clean up m-files before Octave 8.1 release.
Rik <rik@octave.org>
parents: 30564
diff changeset
202 set (h, "units", "pixels", "position", fpos);
25978
be759ed27041 movegui.m: Clean up function.
Rik <rik@octave.org>
parents: 25970
diff changeset
203 set (h, "units", units_fig);
25970
3a66ae436d8a movegui: new function
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff changeset
204
3a66ae436d8a movegui: new function
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff changeset
205 endfunction
3a66ae436d8a movegui: new function
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff changeset
206
25978
be759ed27041 movegui.m: Clean up function.
Rik <rik@octave.org>
parents: 25970
diff changeset
207
be759ed27041 movegui.m: Clean up function.
Rik <rik@octave.org>
parents: 25970
diff changeset
208 ## FIXME: This test does not verify the results, only that the function
be759ed27041 movegui.m: Clean up function.
Rik <rik@octave.org>
parents: 25970
diff changeset
209 ## can be invoked by different methods.
25970
3a66ae436d8a movegui: new function
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff changeset
210 %!test
3a66ae436d8a movegui: new function
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff changeset
211 %! unwind_protect
25978
be759ed27041 movegui.m: Clean up function.
Rik <rik@octave.org>
parents: 25970
diff changeset
212 %! h = figure ("visible", "off");
25970
3a66ae436d8a movegui: new function
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff changeset
213 %! pos = {[10 10], [10 -10], [-10 10], [-10 -10], [10 10]',...
3a66ae436d8a movegui: new function
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff changeset
214 %! "north", "east", "south", "west", ...
3a66ae436d8a movegui: new function
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff changeset
215 %! "northwest", "northeast", "southeast", "southwest", ...
3a66ae436d8a movegui: new function
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff changeset
216 %! "center", "onscreen"};
3a66ae436d8a movegui: new function
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff changeset
217 %! for i = 1:numel (pos)
3a66ae436d8a movegui: new function
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff changeset
218 %! movegui (h, pos{i});
3a66ae436d8a movegui: new function
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff changeset
219 %! movegui (pos{i});
3a66ae436d8a movegui: new function
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff changeset
220 %! movegui (h, struct ("evt", []), pos{i});
3a66ae436d8a movegui: new function
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff changeset
221 %! endfor
3a66ae436d8a movegui: new function
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff changeset
222 %! movegui ();
3a66ae436d8a movegui: new function
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff changeset
223 %! movegui (h);
3a66ae436d8a movegui: new function
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff changeset
224 %! unwind_protect_cleanup
3a66ae436d8a movegui: new function
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff changeset
225 %! close (h);
3a66ae436d8a movegui: new function
Guillaume Flandin <guillaume.offline@gmail.com>
parents:
diff changeset
226 %! end_unwind_protect
25978
be759ed27041 movegui.m: Clean up function.
Rik <rik@octave.org>
parents: 25970
diff changeset
227
be759ed27041 movegui.m: Clean up function.
Rik <rik@octave.org>
parents: 25970
diff changeset
228 ## Test input validation
be759ed27041 movegui.m: Clean up function.
Rik <rik@octave.org>
parents: 25970
diff changeset
229 %!error movegui (1,2,3,4)
be759ed27041 movegui.m: Clean up function.
Rik <rik@octave.org>
parents: 25970
diff changeset
230 %!error <H must be a graphics handle> movegui (-1, [1,1])
be759ed27041 movegui.m: Clean up function.
Rik <rik@octave.org>
parents: 25970
diff changeset
231 %!error <invalid position>
be759ed27041 movegui.m: Clean up function.
Rik <rik@octave.org>
parents: 25970
diff changeset
232 %! unwind_protect
be759ed27041 movegui.m: Clean up function.
Rik <rik@octave.org>
parents: 25970
diff changeset
233 %! h = figure ("visible", "off");
be759ed27041 movegui.m: Clean up function.
Rik <rik@octave.org>
parents: 25970
diff changeset
234 %! movegui (h, "foobar");
be759ed27041 movegui.m: Clean up function.
Rik <rik@octave.org>
parents: 25970
diff changeset
235 %! unwind_protect_cleanup
be759ed27041 movegui.m: Clean up function.
Rik <rik@octave.org>
parents: 25970
diff changeset
236 %! close (h);
be759ed27041 movegui.m: Clean up function.
Rik <rik@octave.org>
parents: 25970
diff changeset
237 %! end_unwind_protect
be759ed27041 movegui.m: Clean up function.
Rik <rik@octave.org>
parents: 25970
diff changeset
238 %!error <invalid position>
be759ed27041 movegui.m: Clean up function.
Rik <rik@octave.org>
parents: 25970
diff changeset
239 %! unwind_protect
be759ed27041 movegui.m: Clean up function.
Rik <rik@octave.org>
parents: 25970
diff changeset
240 %! h = figure ("visible", "off");
be759ed27041 movegui.m: Clean up function.
Rik <rik@octave.org>
parents: 25970
diff changeset
241 %! movegui (h, [1, 2, 3]);
be759ed27041 movegui.m: Clean up function.
Rik <rik@octave.org>
parents: 25970
diff changeset
242 %! unwind_protect_cleanup
be759ed27041 movegui.m: Clean up function.
Rik <rik@octave.org>
parents: 25970
diff changeset
243 %! close (h);
be759ed27041 movegui.m: Clean up function.
Rik <rik@octave.org>
parents: 25970
diff changeset
244 %! end_unwind_protect