## Copyright (C) 2007-2012 John W. Eaton
##
## This file is part of Octave.
##
## Octave is free software; you can redistribute it and/or modify it
## under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 3 of the License, or (at
## your option) any later version.
##
## Octave is distributed in the hope that it will be useful, but
## WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
## General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with Octave; see the file COPYING.  If not, see
## <http://www.gnu.org/licenses/>.

## -*- texinfo -*-
## @deftypefn {Function File} {@var{rgb} =} __next_line_color__ (@var{reset})
## Undocumented internal function.
## @end deftypefn

## Return the next line color in the rotation.

## Author: ceo

function rgb = __next_line_color__ (reset)

  persistent hold_colors;

  if (nargin < 2)
    if (nargin == 1)
      % Indicates whether the next call will increment or not
      hold_colors = reset;
    else
      % Find and return the appropriate line color
      ca = gca();
      colorOrder = get(ca, "ColorOrder");
      if hold_colors
        color_index = 1;
      else
        % TODO __next_line_style__ should be similarly modified
        color_index = mod(length(get(ca, "Children")), rows(colorOrder)) + 1;
      endif
      rgb = colorOrder(color_index,:);
    endif
  else
    print_usage ();
  endif
endfunction
