function colors = getsyscol(varargin)
% GETSYSCOL
%
% Returns a structure containing all the default system colors.
%
% GETSYSCOL('matlab') - default
% Returns colors in the standard matlab color format 0-1.
%
% GETSYSCOL('rgb') - not case sensitive
% Returns colors as individual RGB values using the range 0-255.
%
% GETSYSCOL(format,color)
% Returns the specified color from the list below in the specified
% format ('matlab' or 'rgb')
%
% Colors returned by this function:
%
% ActiveBorder GradientActiveTitle Menu
% ActiveTitle GradientInactiveTitle MenuBar
% AppWorkSpace GrayText MenuHilight
% Background Hilight MenuText
% ButtonAlternateFace HilightText Scrollbar
% ButtonDkShadow HotTrackingColor TitleText
% ButtonFace InactiveBorder Window
% ButtonHilight InactiveTitle WindowFrame
% ButtonLight InactiveTitleText WindowText
% ButtonShadow InfoText
% ButtonText InfoWindow
%
%
% This function only works on the Windows Platform.
%
% Richard Medlock, 2003.
SysColFields = {...
'ActiveBorder',...
'ActiveTitle',...
'AppWorkSpace',...
'Background',...
'ButtonAlternateFace',...
'ButtonDkShadow',...
'ButtonFace',...
'ButtonHilight',...
'ButtonLight',...
'ButtonShadow',...
'ButtonText',...
'GradientActiveTitle',...
'GradientInactiveTitle',...
'GrayText',...
'Hilight',...
'HilightText',...
'HotTrackingColor',...
'InactiveBorder',...
'InactiveTitle',...
'InactiveTitleText',...
'InfoText',...
'InfoWindow',...
'Menu',...
'MenuBar',...
'MenuHilight',...
'MenuText',...
'Scrollbar',...
'TitleText',...
'Window',...
'WindowFrame',...
'WindowText'};
% For each of these colors, read the value from the registry and
% convert it to a matlab color vector.
HKCU = 'HKEY_CURRENT_USER';
if nargin == 0 | nargin == 1
C1 = 1;
C2 = 31;
elseif nargin == 2
C1 = strmatch(lower(varargin{2}),lower(SysColFields));
C2 = C1;
if isempty(C1)
error('Invalid Color')
end
end
for i = C1:C2
% Read Color from registry: (color is returns as Red Green Blue in a string)
ColStr = winqueryreg (HKCU,'Control Panel\Colors',SysColFields{i});
% Find the spaces in the color string:
spaces = findstr(ColStr,' ');
Red = str2num(ColStr(1:spaces(1)-1));
Green = str2num(ColStr(spaces(1)+1:spaces(2)-1));
Blue = str2num(ColStr(spaces(2)+1:end));
% Arrange in an array like a standard Matlab Color Vector:
if nargin == 1 | nargin == 2
switch lower(varargin{1})
case 'matlab'
CV = [Red Green Blue]/255;
case 'rgb'
CV = [Red Green Blue];
case 'show'
CV = [Red Green Blue]/255;
otherwise
error('Invalid color type')
end
% Make sure correct number of inputs:
elseif nargin == 0
CV = [Red Green Blue]/255;
else
error('Only one input argument accepted')
end
if nargin == 2
% Don't bother making a strcuture, just return the value:
colors = CV;
else
% Add the field to the color list:
colors.(SysColFields{i}) = CV;
end
end
if nargin == 1 | nargin == 2
switch lower(varargin{1})
case 'show'
f = figure;
set(f,'color',get(0,'DefaultUiControlBackgroundColor'));
for i = C1:C2
Color = colors.(SysColFields{i});
CheckSum = sum(Color);
if CheckSum > 1.5
FontColor = [0 0 0];
else
FontColor = [1 1 1];
end
plot([-0.01 1],[i i],'color',Color,'Linewidth',16);
hold on
text(0,i,SysColFields{i},'backgroundcolor',Color,...
'Color',FontColor);
end
set(gca,'xlim',[-0.02 1]);
set(gca,'ylim',[C1-1 C2+1]);
set(gca,'color',get(0,'DefaultUiControlBackgroundColor'));
set(gca,'xtick',[]);
end
end