1########################################################################
2##
3## Copyright (C) 2007-2021 The Octave Project Developers
4##
5## See the file COPYRIGHT.md in the top-level directory of this
6## distribution or <https://octave.org/copyright/>.
7##
8## This file is part of Octave.
9##
10## Octave is free software: you can redistribute it and/or modify it
11## under the terms of the GNU General Public License as published by
12## the Free Software Foundation, either version 3 of the License, or
13## (at your option) any later version.
14##
15## Octave is distributed in the hope that it will be useful, but
16## WITHOUT ANY WARRANTY; without even the implied warranty of
17## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18## GNU General Public License for more details.
19##
20## You should have received a copy of the GNU General Public License
21## along with Octave; see the file COPYING.  If not, see
22## <https://www.gnu.org/licenses/>.
23##
24########################################################################
25
26## -*- texinfo -*-
27## @deftypefn  {} {} hidden
28## @deftypefnx {} {} hidden on
29## @deftypefnx {} {} hidden off
30## @deftypefnx {} {@var{mode} =} hidden (@dots{})
31## Control mesh hidden line removal.
32##
33## When called with no argument the hidden line removal state is toggled.
34##
35## When called with one of the modes @qcode{"on"} or @qcode{"off"} the state
36## is set accordingly.
37##
38## The optional output argument @var{mode} is the current state.
39##
40## Hidden Line Removal determines what graphic objects behind a mesh plot
41## are visible.  The default is for the mesh to be opaque and lines behind
42## the mesh are not visible.  If hidden line removal is turned off then
43## objects behind the mesh can be seen through the faces (openings) of the
44## mesh, although the mesh grid lines are still opaque.
45##
46## @seealso{mesh, meshc, meshz, ezmesh, ezmeshc, trimesh, waterfall}
47## @end deftypefn
48
49function state = hidden (mode = "toggle")
50
51  if (nargin > 2)
52    print_usage ();
53  elseif (nargin == 1)
54    if (! ischar (mode))
55      error ("hidden: MODE must be a string");
56    elseif (! any (strcmpi (mode, {"on", "off"})))
57      error ('hidden: MODE must be "on" or "off"');
58    endif
59  endif
60
61  for h = (get (gca (), "children")).'
62    [htype, htag] = get (h, {"type", "tag"}){:};
63    if (strcmp (htype, "surface") || strcmp (htag, "trimesh"))
64      fc = get (h, "facecolor");
65      if ((! ischar (fc) && is_white (fc))
66          || (ischar (fc) && strcmp (fc, "none")))
67        switch (mode)
68          case "on"
69            set (h, "facecolor", "w");
70          case "off"
71            set (h, "facecolor", "none");
72          case "toggle"
73            if (ischar (fc))
74              set (h, "facecolor", "w");
75              mode = "on";
76            else
77              set (h, "facecolor", "none");
78              mode = "off";
79            endif
80        endswitch
81      endif
82    endif
83  endfor
84
85  if (nargout > 0)
86    state = mode;
87  endif
88
89endfunction
90
91function retval = is_white (color)
92  retval = all (color == 1);
93endfunction
94