Mercurial > octave
diff scripts/plot/util/pan.m @ 28901:3c37ae43996a
maint: Code cleanup associated with varargin checking.
* runtests.m, flipdim.m: Add newline before "endfunction" for looks.
* check_default_input.m: Replace varargin in function prototype with
explicit variables y0, yp0. Add input validation on nargin.
* annotation.m: Use standard "mod (numel (), 2) != 0" test to check
for even number of PROP/VAL pairs.
* comet.m: Validate nargin does not exceed number of possible args.
* cylinder.m: Move input validation for nargin to top of function.
* ostreamtube.m, stream2.m, stream3.m, streamribbon.m, streamtube.m: Call
print_usage() if number of input arguments is incorrect rather than homegrown
error text. Make error() message for OPTIONS input more specific about what is
wrong. Adjust input validation tests to pass again.
* __plt__.m: Move input validation for number of inputs to top of
function.
* rectangle.m: Hyphenate "4-element vector" in error() message.
* rose.m: Add input validation for maximum number of inputs.
Add BIST test to check new code.
* tetramesh.m: Use numel() in preference to length().
* pan.m, rotate3d.m, zoom.m: Switch from using varargin to explictly named
input arguments.
* etreeplot.m: Add check on maximum number of input arguments.
Add BIST tests for input validation code.
* strchr.m: Add check on maximum number of input arguments.
Add BIST test for new input validation code.
author | Rik <rik@octave.org> |
---|---|
date | Tue, 13 Oct 2020 11:36:33 -0700 |
parents | bd51beb6205e |
children | 7854d5752dd2 |
line wrap: on
line diff
--- a/scripts/plot/util/pan.m Tue Oct 13 20:08:05 2020 +0200 +++ b/scripts/plot/util/pan.m Tue Oct 13 11:36:33 2020 -0700 @@ -46,35 +46,31 @@ ## @seealso{rotate3d, zoom} ## @end deftypefn -function pan (varargin) - - hfig = NaN; - - nargs = nargin; +function h = pan (hfig, option) - if (nargs > 2) - print_usage (); - endif - - if (nargin == 1 && nargout > 0 && isfigure (varargin{1})) + ## FIXME: Presumably should implement this for Matlab compatibility. + if (nargin == 1 && nargout > 0 && isfigure (hfig)) error ("pan: syntax 'handle = pan (hfig)' not implemented"); endif - if (nargs == 2) - hfig = varargin{1}; - if (isfigure (hfig)) - varargin(1) = []; - nargs -= 1; + if (nargin == 0) + hfig = gcf (); + else + if (nargin == 1) + option = hfig; + hfig = gcf (); else - error ("pan: invalid figure handle HFIG"); + if (! isfigure (hfig)) + error ("pan: invalid figure handle HFIG"); + endif + endif + + if (! ischar (option)) + error ("pan: OPTION must be a string"); endif endif - if (isnan (hfig)) - hfig = gcf (); - endif - - if (nargs == 0) + if (nargin == 0) pm = get (hfig, "__pan_mode__"); if (strcmp (pm.Enable, "on")) pm.Enable = "off"; @@ -83,31 +79,26 @@ endif set (hfig, "__pan_mode__", pm); update_mouse_mode (hfig, pm.Enable); - elseif (nargs == 1) - arg = varargin{1}; - if (ischar (arg)) - switch (arg) - case {"on", "off", "xon", "yon"} - pm = get (hfig, "__pan_mode__"); - switch (arg) - case {"on", "off"} - pm.Enable = arg; - pm.Motion = "both"; - case "xon" - pm.Enable = "on"; - pm.Motion = "horizontal"; - case "yon" - pm.Enable = "on"; - pm.Motion = "vertical"; - endswitch - set (hfig, "__pan_mode__", pm); - update_mouse_mode (hfig, arg); - otherwise - error ("pan: unrecognized OPTION '%s'", arg); - endswitch - else - error ("pan: wrong type argument '%s'", class (arg)); - endif + else + switch (option) + case {"on", "off", "xon", "yon"} + pm = get (hfig, "__pan_mode__"); + switch (option) + case {"on", "off"} + pm.Enable = option; + pm.Motion = "both"; + case "xon" + pm.Enable = "on"; + pm.Motion = "horizontal"; + case "yon" + pm.Enable = "on"; + pm.Motion = "vertical"; + endswitch + set (hfig, "__pan_mode__", pm); + update_mouse_mode (hfig, option); + otherwise + error ("pan: unrecognized OPTION '%s'", option); + endswitch endif endfunction @@ -119,8 +110,8 @@ else ## FIXME: Is there a better way other than calling these functions ## to set the other mouse mode Enable fields to "off"? - rotate3d ("off"); - zoom ("off"); + rotate3d (hfig, "off"); + zoom (hfig, "off"); set (hfig, "__mouse_mode__", "pan"); endif