comparison scripts/plot/backend.m @ 8060:09f32aac8fbc

Interface for backend switch/initialization
author John W. Eaton <jwe@octave.org>
date Tue, 26 Aug 2008 13:26:05 -0400
parents
children dbd0c77e575e
comparison
equal deleted inserted replaced
8059:75c99d3f97d7 8060:09f32aac8fbc
1 ## Copyright (C) 2008 Michael Goffioul
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} backend (@var{name})
21 ## @deftypefnx {Function File} backend (@var{hlist}, @var{name})
22 ## Change the default graphics backend to @var{name}. If the backend is
23 ## not already loaded, it is first initialized (initialization is done
24 ## through the execution of __init_@var{name}__).
25 ##
26 ## @var{hlist} is a list of figure handles. When given, this function
27 ## only switches the default backend for the corresponding figures.
28 ## @seealso{available_backends}
29 ## @end deftypefn
30
31 function backend (varargin)
32
33 name = "";
34 hlist = [];
35
36 if (nargin == 1)
37 if (ischar (varargin{1}))
38 name = varargin{1};
39 else
40 error ("backend: invalid backend name");
41 endif
42 elseif (nargin == 2)
43 if (isnumeric (varargin{1}) && ischar (varargin{2}))
44 hlist = varargin{1};
45 name = varargin{2};
46 elseif (ischar (varargin{2}))
47 error ("backend: invalid handle list");
48 else
49 error ("backend: invalid backend name");
50 endif
51 else
52 print_usage ();
53 endif
54
55 if (! any (strcmp (available_backends (), name)))
56 feval (["__init_", name, "__"]);
57 if (! any (strcmp (available_backends (), name)))
58 error ("backend: backend was not correctly registered");
59 endif
60 endif
61
62 if (isempty (hlist))
63 set (0, "defaultfigure__backend__", name);
64 else
65 for h = hlist(:)'
66 set (h, "__backend__", name);
67 endfor
68 endif
69
70 endfunction