function MTB_Week11_GUI2
if ~isempty(findobj('tag','fig_Priklad2'))
    resetDialog = questdlg('GUI Pøíklad 2 existuje, resetovat?',...
       'Resetovat','Ano','Ne','Ano');
    if strcmp(resetDialog,'Ano')
        delete(findobj('tag','fig_Priklad2'));
        MTB_GUI2;
        disp('Resetováno...')
    else
        return;
    end
else 
Monitor = get(0,'ScreenSize'); % vrací rozlišení obrazovky
x_size = 400;
y_size = 250;
figure2 = figure('units','pixels','Name','Pøíklad2','Position',...
    [Monitor(3)/2-x_size/2 Monitor(4)/2-y_size/2 x_size y_size],...
    'Tag','fig_Priklad2','Color',[.9 .9 .9],'Menu','none',...
    'NumberTitle','off');
text1_Xlabel = uicontrol('Units','Normalized','Style','Text',...
    'BackgroundColor',[.9 .9 .9],'String','X-pozice:','Visible','off',...
    'Fontsize',9,'Position',[.1 .4 .15 .075]); % vytvoøí prvek uicontrol
text2_Xdata = uicontrol('Units','Normalized','Style','Text',...
    'BackgroundColor',[.95 .95 .95],'Visible','off',...
    'Fontsize',10,'Position',[.26 .4 .175 .075]); % vytvoøí prvek uicontrol
text3_Ylabel = uicontrol('Units','Normalized','Style','Text',...
    'BackgroundColor',[.9 .9 .9],'String','Y-pozice:','Visible','off',...
    'Fontsize',9,'Position',[.55 .4 .15 .075]); % vytvoøí prvek uicontrol
text4_Ydata = uicontrol('Units','Normalized','Style','Text',...
    'BackgroundColor',[.95 .95 .95],'Visible','off',...
    'Fontsize',10,'Position',[.71 .4 .175 .075]); % vytvoøí prvek uicontrol

uicontrol('Units','Pixels','Style','Text','Pos',[5 130 390 1],...
    'BackgroundColor',[.7 .7 .7]); % oddìlovaè
uicontrol('Units','Pixels','Style','Text','Pos',[5 90 390 1],...
    'BackgroundColor',[.7 .7 .7]); % oddìlovaè
panelColor = [.98 .98 .98]; % barvu použijeme vícekrát, proto pøedpis
panel1 = uipanel('Units','pixels','Title',...
    'Viditelnost','BackgroundColor',panelColor,'Position',...
    [90 180 220 60],'tag','panelViditelnost');
visibleHandle = uicontrol('Units','Normalized','Style',...
    'check','Position',[.225 .25 .6 .5],'Tag','vyberViditelnosti',...
    'String','Zobraz pozici myši','BackgroundColor',panelColor,...
    'TooltipString','Switch the mouse-position visibility',...
    'Parent',panel1);
handles = [text1_Xlabel text2_Xdata text3_Ylabel text4_Ydata];
set(visibleHandle,'Callback',...
    @(scr,event)switchVisibility(visibleHandle,handles));
uicontrol('Units','Normalized','Style','Push','String',...
    'Konec','Callback',@(scr,event)endFunction,'ForegroundColor',...
    [.8 .9 .9],'BackgroundColor',[.1 .5 .6],...
    'Fontsize',9,'Position',[.3 .1 .4 .125]); % vytvoøí prvek uicontrol
set(figure2,...
    'WindowButtonMotionFcn',@(scr,event)motionFcn(figure2,handles),...
    'WindowButtonDownFcn',@(scr,event)clickDownFcn(figure2,handles));
end
end

function switchVisibility(visibleHandle,handles)
    visible = get(visibleHandle,'Value');
    if visible % Value = true, tedy prvek je zaškrtnut
        set(handles,'Visible','on');
    else % není zaškrtnut => skryj texty
        set(handles,'Visible','off');
    end
end

function motionFcn(fig,handl)
    mousePos = get(fig,'CurrentPoint');
    posXpixels = mousePos(1); %x-ová pozice myši
    posYpixels = mousePos(2); %y-ová pozice myši
    set(handl(2),'String',num2str(posXpixels));
    set(handl(4),'String',num2str(posYpixels));
end

function clickDownFcn(fig,handl)
    typTlacitka = get(fig,'SelectionType');
    if strcmp(typTlacitka,'normal') % stisknuto levé tlaèítko
        if strcmp(get(handl(1),'FontWeight'),'normal')
            set(handl(1),'FontWeight','bold');
        else
            set(handl(1),'FontWeight','normal');
        end
    elseif strcmp(typTlacitka,'alt') % pravé tlaèítko
        if strcmp(get(handl(3),'FontWeight'),'normal')
            set(handl(3),'FontWeight','bold');
        else
            set(handl(3),'FontWeight','normal');
        end        
    end
end

function endFunction
    closereq; % podobnì jako v pøíkladu1 (MAA_GUI1)
end