function fbcolour(Action,Para)
% Filename: FBCOLOUR.M
% Version: 1.0 (Matlab 5.0)
% Author: Mr. K.M. Leung
% Date: 30-Sep-1997
% Update: -
% Usages: For selection background and foreground colour
% Command: fbcolour
% Variable List
% ==================================================================================
% Action - Arriable option for this program
% BackColour() - Background colour
% ForeColour() - Foreground colour
% Para - Optional parameter
% TempData - Temporary data variable
% Handle List
% ==================================================================================
% hFig - Handle of figure
% Option List
% ==================================================================================
% 'new' - Program initialization
% 'updateslr' - Update slider value
% 'updateedt' - Update edit box value
% 'updatesample' - Update sample box
% Para List
% ==================================================================================
% 1 - Background red value
% 2 - Background green value
% 3 - Background blue value
% 4 - Background red value
% 5 - Background green value
% 6 - Background blue value
% Global variable
global BackColour ForeColour
% Program initialization
clc;
if nargin<1
Action='new';
end;
% Program option
switch lower(Action)
case 'new'
%Interface setup
hFig=figure('Color',[0.8 0.8 0.8], ...
'Name','Colour Selector', ...
'NumberTitle','off', ...
'Position',[200 140 400 320], ...
'Resize','off', ...
'Tag','ColorSelect');
uicontrol('Parent',hFig, ...
'Units','points', ...
'BackgroundColor',[1 1 1], ...
'Position',[9 215.25 280 12.75], ...
'String','Matlab V5.0 Text Colour Selector', ...
'Style','text', ...
'Tag','txtColour');
uicontrol('Parent',hFig, ...
'Units','points', ...
'BackgroundColor',[0.8 0.8 0.8], ...
'HorizontalAlignment','left', ...
'Position',[6 190 111 13.5], ...
'String','Background Colour', ...
'Style','text', ...
'Tag','StaticText3');
uicontrol('Parent',hFig, ...
'Units','points', ...
'BackgroundColor',[0.8 0.8 0.8], ...
'ForegroundColor',[1 0 0], ...
'HorizontalAlignment','left', ...
'Position',[6 172.75 30 14.25], ...
'String','Red', ...
'Style','text', ...
'Tag','StaticText2');
uicontrol('Parent',hFig, ...
'Units','points', ...
'BackgroundColor',[1 1 1], ...
'Callback','colour(''updateslr'',1);', ...
'HorizontalAlignment','left', ...
'Position',[46 172.75 48.75 14.25], ...
'String','1', ...
'Style','edit', ...
'Tag','edtBgRed');
uicontrol('Parent',hFig, ...
'Units','points', ...
'BackgroundColor',[0.8 0.8 0.8], ...
'Callback','colour(''updateedt'',1);', ...
'Position',[104.75 174.25 170.25 12.75], ...
'Style','slider', ...
'Tag','slrBgRed', ...
'Value',1);
uicontrol('Parent',hFig, ...
'Units','points', ...
'BackgroundColor',[0.8 0.8 0.8], ...
'ForegroundColor',[0 1 0], ...
'HorizontalAlignment','left', ...
'Position',[6 150.25 30 14.25], ...
'String','Green', ...
'Style','text', ...
'Tag','StaticText2');
uicontrol('Parent',hFig, ...
'Units','points', ...
'BackgroundColor',[1 1 1], ...
'Callback','colour(''updateslr'',2);', ...
'HorizontalAlignment','left', ...
'Position',[46 150.25 48.75 14.25], ...
'String','1', ...
'Style','edit', ...
'Tag','edtBgGreen');
uicontrol('Parent',hFig, ...
'Units','points', ...
'BackgroundColor',[0.8 0.8 0.8], ...
'Callback','colour(''updateedt'',2);', ...
'Position',[104.75 151.75 170.25 12.75], ...
'Style','slider', ...
'Tag','slrBgGreen', ...
'Value',1);
uicontrol('Parent',hFig, ...
'Units','points', ...
'BackgroundColor',[0.8 0.8 0.8], ...
'ForegroundColor',[0 0 1], ...
'HorizontalAlignment','left', ...
'Position',[6 127.75 30 14.25], ...
'String','Blue', ...
'Style','text', ...
'Tag','StaticText2');
uicontrol('Parent',hFig, ...
'Units','points', ...
'BackgroundColor',[1 1 1], ...
'Callback','colour(''updateslr'',3);', ...
'HorizontalAlignment','left', ...
'Position',[46 127.75 48.75 14.25], ...
'String','1', ...
'Style','edit', ...
'Tag','edtBgBlue');
uicontrol('Parent',hFig, ...
'Units','points', ...
'BackgroundColor',[0.8 0.8 0.8], ...
'Callback','colour(''updateedt'',3);', ...
'Position',[104.75 129.25 170.25 12.75], ...
'Style','slider', ...
'Tag','slrBgBlue', ...
'Value',1);
uicontrol('Parent',hFig, ...
'Units','points', ...
'BackgroundColor',[0.8 0.8 0.8], ...
'HorizontalAlignment','left', ...
'Position',[6 98.25 111 13.5], ...
'String','Foreground Colour', ...
'Style','text', ...
'Tag','StaticText3');
uicontrol('Parent',hFig, ...
'Units','points', ...
'BackgroundColor',[0.8 0.8 0.8], ...
'ForegroundColor',[1 0 0], ...
'HorizontalAlignment','left', ...
'Position',[6 80.25 30 14.25], ...
'String','Red', ...
'Style','text', ...
'Tag','StaticText2');
uicontrol('Parent',hFig, ...
'Units','points', ...
'Callback','colour(''updateslr'',4);', ...
'BackgroundColor',[1 1 1], ...
'HorizontalAlignment','left', ...
'Position',[46 80.25 48.75 14.25], ...
'String','0', ...
'Style','edit', ...
'Tag','edtFgRed');
uicontrol('Parent',hFig, ...
'Units','points', ...
'BackgroundColor',[0.8 0.8 0.8], ...
'Callback','colour(''updateedt'',4);', ...
'Position',[104.75 81.75 170.25 12.75], ...
'Style','slider', ...
'Tag','slrFgRed', ...
'Value',0);
uicontrol('Parent',hFig, ...
'Units','points', ...
'BackgroundColor',[0.8 0.8 0.8], ...
'ForegroundColor',[0 1 0], ...
'HorizontalAlignment','left', ...
'Position',[6 57.75 30 14.25], ...
'String','Green', ...
'Style','text', ...
'Tag','StaticText2');
uicontrol('Parent',hFig, ...
'Units','points', ...
'BackgroundColor',[1 1 1], ...
'Callback','colour(''updateslr'',5);', ...
'HorizontalAlignment','left', ...
'Position',[46 57.75 48.75 14.25], ...
'String','0', ...
'Style','edit', ...
'Tag','edtFgGreen');
uicontrol('Parent',hFig, ...
'Units','points', ...
'BackgroundColor',[0.8 0.8 0.8], ...
'Callback','colour(''updateedt'',5);', ...
'Position',[104.75 59.25 170.25 12.75], ...
'Style','slider', ...
'Tag','slrFgGreen', ...
'Value',0);
uicontrol('Parent',hFig, ...
'Units','points', ...
'BackgroundColor',[0.8 0.8 0.8], ...
'ForegroundColor',[0 0 1], ...
'HorizontalAlignment','left', ...
'Position',[6 35.25 30 14.25], ...
'String','Blue', ...
'Style','text', ...
'Tag','StaticText2');
uicontrol('Parent',hFig, ...
'Units','points', ...
'BackgroundColor',[1 1 1], ...
'Callback','colour(''updateslr'',6);', ...
'HorizontalAlignment','left', ...
'Position',[46 35.25 48.75 14.25], ...
'String','0', ...
'Style','edit', ...
'Tag','edtFgBlue');
uicontrol('Parent',hFig, ...
'Units','points', ...
'BackgroundColor',[0.8 0.8 0.8], ...
'Callback','colour(''updateedt'',6);', ...
'Position',[104.75 36.75 170.25 12.75], ...
'Style','slider', ...
'Tag','slrFgBlue', ...
'Value',0);
BackColour=[1 1 1];
ForeColour=[0 0 0];
case 'updateslr'
% To update slider value
switch Para
case 1
% Background red
TempData=str2num(get(findobj('Tag','edtBgRed'),'String'));
if TempData<0 | TempData>1
msgbox('Value must be in the range 0 to 1','Data Input Error','error');
set(findobj('Tag','edtBgRed'),'String',num2str(BackColour(1)));
else
BackColour(1)=TempData;
end
set(findobj('Tag','slrBgRed'),'Value',BackColour(1));
case 2
% Background green
TempData=str2num(get(findobj('Tag','edtBgGreen'),'String'));
if TempData<0 | TempData>1
msgbox('Value must be in the range 0 to 1','Data Input Error','error');
set(findobj('Tag','edtBgGreen'),'String',num2str(BackColour(2)));
else
BackColour(2)=TempData;
end
set(findobj('Tag','slrBgGreen'),'Value',BackColour(2));
case 3
% Background blue
TempData=str2num(get(findobj('Tag','edtBgBlue'),'String'));
if TempData<0 | TempData>1
msgbox('Value must be in the range 0 to 1','Data Input Error','error');
set(findobj('Tag','edtBgBlue'),'String',num2str(BackColour(3)));
else
BackColour(3)=TempData;
end
set(findobj('Tag','slrBgBlue'),'Value',BackColour(3));
case 4
% Foreground red
TempData=str2num(get(findobj('Tag','edtFgRed'),'String'));
if TempData<0 | TempData>1
msgbox('Value must be in the range 0 to 1','Data Input Error','error');
set(findobj('Tag','edtFgRed'),'String',num2str(ForeColour(1)));
else
ForeColour(1)=TempData;
end
set(findobj('Tag','slrFgRed'),'Value',ForeColour(1));
case 5
% Foreground green
TempData=str2num(get(findobj('Tag','edtFgGreen'),'String'));
if TempData<0 | TempData>1
msgbox('Value must be in the range 0 to 1','Data Input Error','error');
set(findobj('Tag','edtFgGreen'),'String',num2str(ForeColour(2)));
else
ForeColour(2)=TempData;
end
set(findobj('Tag','slrFgGreen'),'Value',ForeColour(2));
case 6
% Foreground blue
TempData=str2num(get(findobj('Tag','edtFgBlue'),'String'));
if TempData<0 | TempData>1
msgbox('Value must be in the range 0 to 1','Data Input Error','error');
set(findobj('Tag','edtFgBlue'),'String',num2str(ForeColour(3)));
else
ForeColour(3)=TempData;
end
set(findobj('Tag','slrFgBlue'),'Value',ForeColour(3));
end
colour('updatesample');
case 'updateedt'
% To update edit box value
switch Para
case 1
% Background red
BackColour(1)=get(findobj('Tag','slrBgRed'),'Value');
set(findobj('Tag','edtBgRed'),'String',num2str(BackColour(1)));
case 2
% Background green
BackColour(2)=get(findobj('Tag','slrBgGreen'),'Value');
set(findobj('Tag','edtBgGreen'),'String',num2str(BackColour(2)));
case 3
% Background blue
BackColour(3)=get(findobj('Tag','slrBgBlue'),'Value');
set(findobj('Tag','edtBgBlue'),'String',num2str(BackColour(3)));
case 4
% Foreground red
ForeColour(1)=get(findobj('Tag','slrFgRed'),'Value');
set(findobj('Tag','edtFgRed'),'String',num2str(ForeColour(1)));
case 5
% Foreground green
ForeColour(2)=get(findobj('Tag','slrFgGreen'),'Value');
set(findobj('Tag','edtFgGreen'),'String',num2str(ForeColour(2)));
case 6
% Foreground blue
ForeColour(3)=get(findobj('Tag','slrFgBlue'),'Value');
set(findobj('Tag','edtFgBlue'),'String',num2str(ForeColour(3)));
end
colour('updatesample');
case 'updatesample'
% To update sample box
set(findobj('Tag','txtColour'),'BackgroundColor',BackColour, ...
'ForegroundColor',ForeColour);
end