function varargout = advanced(varargin)
% ADVANCED M-file for advanced.fig
%      ADVANCED, by itself, creates a new ADVANCED or raises the existing
%      singleton*.
%
%      H = ADVANCED returns the handle to a new ADVANCED or the handle to
%      the existing singleton*.
%
%      ADVANCED('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named ADVANCED in ADVANCED.M with the given input arguments.
%
%      ADVANCED('Property','Value',...) creates a new ADVANCED or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before advanced_OpeningFunction gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to advanced_OpeningFcn via varargin.
%
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
%      instance to run (singleton)".
%
% Code construction assisted by GUIDE
%
%    GENERAL
%
%      Omitted.
%
%    INPUT/S
%
%      -
%          
%           
%    OUTPUT/S
%
%      -
%
%    PENDING WORK
%
%      -
%
%    KNOWN BUG/S
%
%      -
%
%    COMMENT/S
%
%      -
%
%    RELATED FUNCTION/S
%
%      
%
%    ABOUT
%
%      -Created:     February 12th, 2004
%      -Last update: 
%      -Revision:    0.0.9
%      -Author:      R. S. Schestowitz, University of Manchester
% ==============================================================

% Edit the above text to modify the response to help_button register

% Last Modified by GUIDE v2.5 23-Mar-2004 07:42:43

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
    'gui_Singleton',  gui_Singleton, ...
    'gui_OpeningFcn', @advanced_OpeningFcn, ...
    'gui_OutputFcn',  @advanced_OutputFcn, ...
    'gui_LayoutFcn',  [] , ...
    'gui_Callback',   []);
if nargin & isstr(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT

% ==================================================================== %  

% --- Executes just before register is made visible.
function advanced_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% varargin   command line arguments to register (see VARARGIN)

% Choose default command line output for register
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

if strcmp(get(hObject,'Visible'),'off')
    initialize_gui(hObject, handles);
end

% UIWAIT makes register pause for user response (see UIRESUME)
% uiwait(handles.Advanced_window);

% ==================================================================== %  

% --- Outputs from this function are returned to the command line.
function varargout = advanced_OutputFcn(hObject, eventdata, handles)
% varargout  cell array for returning output args (see VARARGOUT);
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure
varargout{1} = handles.output;

% ==================================================================== %  

function initialize_gui(fig_handle, handles)

set(handles.number_of_modes_number, 'String', getappdata(0, 'number_of_modes'));
set(handles.number_of_modes_slider, 'Value', str2num(get(handles.number_of_modes_number, 'String')));

set(handles.std_number, 'String', getappdata(0, 'std'));
set(handles.std_slider, 'Value', str2num(get(handles.std_number, 'String')));

set(handles.exit_flag, 'String', getappdata(0, 'exit_handle'));
set(handles.exit_option_button, 'Value', str2num(getappdata(0, 'exit_handle')));

set(handles.close_flag, 'String', getappdata(0, 'close_handle'));
set(handles.close_button, 'Value', str2num(getappdata(0, 'close_handle')));

set(handles.show_score_figures_flag, 'String', getappdata(0, 'show_score_figures'));
set(handles.show_score_figures, 'Value', str2num(getappdata(0, 'show_score_figures')));

set(handles.show_score_flag, 'String', getappdata(0, 'show_score_bar'));
set(handles.show_score_bar_button, 'Value', str2num(getappdata(0, 'show_score_bar')));


background = imread('background.jpg');

axes(handles.background);
axis off;
imshow(background,[0,255]);

% ==================================================================== %  

% --- Executes on button press in ok_botton.
function ok_botton_Callback(hObject, eventdata, handles)
% hObject    handle to ok_botton (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

setappdata(0, 'show_score_figures', get(handles.show_score_figures_flag, 'String'));
setappdata(0, 'exit_handle', get(handles.exit_flag, 'String'));
setappdata(0, 'close_handle', get(handles.close_flag, 'String'));
setappdata(0, 'show_score_bar', get(handles.show_score_flag, 'String'));
setappdata(0, 'number_of_modes', get(handles.number_of_modes_number, 'String'));
setappdata(0, 'std', get(handles.std_number, 'String'));
close;

% ==================================================================== %  

% --- Executes on button press in exit_option_button.
function exit_option_button_Callback(hObject, eventdata, handles)
% hObject    handle to exit_option_button (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of exit_option_button


if (get(handles.exit_option_button, 'Value') == 0),
    set(handles.exit_flag, 'String', '0');
else
    set(handles.exit_option_button, 'Value', 1);
    set(handles.exit_flag, 'String', '1');  
end

% ==================================================================== %  

% --- Executes on button press in cancel_button.
function cancel_button_Callback(hObject, eventdata, handles)
% hObject    handle to cancel_button (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
close;

% ==================================================================== %  

% --- Executes on button press in apply_button.
function apply_button_Callback(hObject, eventdata, handles)
% hObject    handle to apply_button (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

setappdata(0, 'exit_handle', get(handles.exit_flag, 'String'));
setappdata(0, 'show_score_figures', get(handles.show_score_figures_flag, 'String'));
setappdata(0, 'close_handle', get(handles.close_flag, 'String'));
setappdata(0, 'show_score_bar', get(handles.show_score_flag, 'String'));
setappdata(0, 'number_of_modes', get(handles.number_of_modes_number, 'String'));
setappdata(0, 'std', get(handles.std_number, 'String'));

% ==================================================================== %  

% --- Executes on button press in show_score_figures.
function show_score_figures_Callback(hObject, eventdata, handles)
% hObject    handle to show_score_figures (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of show_score_figures

if (get(handles.show_score_figures, 'Value') == 0),
    set(handles.show_score_figures_flag, 'String', '0');
else
    set(handles.show_score_figures, 'Value', 1);
    set(handles.show_score_figures_flag, 'String', '1');  
end

% ==================================================================== %  

% --- Executes on button press in close_button.
function close_button_Callback(hObject, eventdata, handles)
% hObject    handle to close_button (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of close_button
if (get(handles.close_button, 'Value') == 0),
    set(handles.close_flag, 'String', '0');
else
    set(handles.close_button, 'Value', 1);
    set(handles.close_flag, 'String', '1');  
end

% ==================================================================== %  

% --- Executes on button press in show_score_bar_button.
function show_score_bar_button_Callback(hObject, eventdata, handles)
% hObject    handle to show_score_bar_button (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of show_score_bar_button

if (get(handles.show_score_bar_button, 'Value') == 0),
    set(handles.show_score_flag, 'String', '0');
else
    set(handles.show_score_bar_button, 'Value', 1);
    set(handles.show_score_flag, 'String', '1');  
end

% ==================================================================== %  

% --- Executes during object creation, after setting all properties.
function number_of_modes_slider_CreateFcn(hObject, eventdata, handles)
% hObject    handle to number_of_modes_slider (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: slider controls usually have a light gray background, change
%       'usewhitebg' to 0 to use default.  See ISPC and COMPUTER.
usewhitebg = 1;
if usewhitebg
    set(hObject,'BackgroundColor',[.9 .9 .9]);
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end

% ==================================================================== %  

% --- Executes on slider movement.
function number_of_modes_slider_Callback(hObject, eventdata, handles)
% hObject    handle to number_of_modes_slider (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'Value') returns position of slider
%        get(hObject,'Min') and get(hObject,'Max') to determine range of slider

set(handles.number_of_modes_number, 'String', num2str(ceil(get(handles.number_of_modes_slider, 'Value'))));

% ==================================================================== %  

% --- Executes during object creation, after setting all properties.
function std_slider_CreateFcn(hObject, eventdata, handles)
% hObject    handle to std_slider (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: slider controls usually have a light gray background, change
%       'usewhitebg' to 0 to use default.  See ISPC and COMPUTER.
usewhitebg = 1;
if usewhitebg
    set(hObject,'BackgroundColor',[.9 .9 .9]);
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end

% ==================================================================== %  

% --- Executes on slider movement.
function std_slider_Callback(hObject, eventdata, handles)
% hObject    handle to std_slider (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'Value') returns position of slider
%        get(hObject,'Min') and get(hObject,'Max') to determine range of slider

set(handles.std_number, 'String', num2str(ceil(get(handles.std_slider, 'Value'))));

% ==================================================================== %  

% --- Executes on button press in pushbutton19.
function pushbutton19_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton19 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% ==================================================================== %  

% --- Executes on button press in pushbutton20.
function pushbutton20_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton20 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


