function varargout = rozvrzeni_formulare4(varargin)
% ROZVRZENI_FORMULARE4 M-file for rozvrzeni_formulare4.fig
%      ROZVRZENI_FORMULARE4, by itself, creates a new ROZVRZENI_FORMULARE4 or raises the existing
%      singleton*.
%
%      H = ROZVRZENI_FORMULARE4 returns the handle to a new ROZVRZENI_FORMULARE4 or the handle to
%      the existing singleton*.
%
%      ROZVRZENI_FORMULARE4('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in ROZVRZENI_FORMULARE4.M with the given input arguments.
%
%      ROZVRZENI_FORMULARE4('Property','Value',...) creates a new ROZVRZENI_FORMULARE4 or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before rozvrzeni_formulare4_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to rozvrzeni_formulare4_OpeningFcn via varargin.
%
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
%      instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help rozvrzeni_formulare4

% Last Modified by GUIDE v2.5 15-Feb-2013 12:12:32

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @rozvrzeni_formulare4_OpeningFcn, ...
                   'gui_OutputFcn',  @rozvrzeni_formulare4_OutputFcn, ...
                   'gui_LayoutFcn',  [] , ...
                   'gui_Callback',   []);
if nargin && ischar(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 rozvrzeni_formulare4 is made visible.
function rozvrzeni_formulare4_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 rozvrzeni_formulare4 (see VARARGIN)

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

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes rozvrzeni_formulare4 wait for user response (see UIRESUME)
% uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = rozvrzeni_formulare4_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;



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% po spuštění
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
       
set(findobj('tag','editt1'),'BackgroundColor', 'white');
set(findobj('tag','editt2'),'BackgroundColor', 'white');
set(findobj('tag','editt3'),'BackgroundColor', 'white');
set(findobj('tag','editt4'),'BackgroundColor', 'white');

if exist('data\ulozeny_format.mat','file') == 2
    load data\ulozeny_format.mat
    mezirka = mezera/velikost_textu;
    
    okrajD = round(100*okrajD/3507);
    okrajH = round(100*okrajH/3507);
    okrajL = round(100*okrajL/2496);
    okrajP = round(100*okrajP/2496);
else
    % počáteční nastavení
    okrajD = 10;
    okrajH = okrajD;
    okrajL = 10;
    okrajP = okrajL;
    velikost_textu = 70;
    mezirka = 0.5;
end

% vyplnění kolonek
set(findobj('tag','editt1'),'string', okrajD);
set(findobj('tag','editt2'),'string', okrajH);
set(findobj('tag','editt3'),'string', okrajL);
set(findobj('tag','editt4'),'string', okrajP);
set(findobj('tag','editt5'),'string', velikost_textu);
set(findobj('tag','editt6'),'string', mezirka);


% nechápu kde je chyba, nepřepisuje to !!!
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% políčka pro zadání rozměrů
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function editt1_Callback(hObject, eventdata, handles)
% hObject    handle to editt1 (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,'String') returns contents of editt1 as text
%        str2double(get(hObject,'String')) returns contents of editt1 as a double


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

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function editt2_Callback(hObject, eventdata, handles)
% hObject    handle to editt2 (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,'String') returns contents of editt2 as text
%        str2double(get(hObject,'String')) returns contents of editt2 as a double


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

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function editt3_Callback(hObject, eventdata, handles)
% hObject    handle to editt3 (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,'String') returns contents of editt3 as text
%        str2double(get(hObject,'String')) returns contents of editt3 as a double


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

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function editt4_Callback(hObject, eventdata, handles)
% hObject    handle to editt4 (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,'String') returns contents of editt4 as text
%        str2double(get(hObject,'String')) returns contents of editt4 as a double


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

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% okno pro zadání počtu řádků
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function editt5_Callback(hObject, eventdata, handles)
% hObject    handle to editt5 (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,'String') returns contents of editt5 as text
%        str2double(get(hObject,'String')) returns contents of editt5 as a double


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

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% okno pro zadání mezery mezi řádky
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function editt6_Callback(hObject, eventdata, handles)
% hObject    handle to editt6 (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,'String') returns contents of editt6 as text
%        str2double(get(hObject,'String')) returns contents of editt6 as a double


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

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


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

global rozdeleni

if exist('data\ulozeny_format.mat','file') == 2
    delete data\ulozeny_format.mat
end

okrajD = str2double(get(handles.editt1,'String'));
okrajH = str2double(get(handles.editt2,'String'));
okrajL = str2double(get(handles.editt3,'String'));
okrajP = str2double(get(handles.editt4,'String'));

okrajD = round(3507/100*okrajD);
okrajH = round(3507/100*okrajH);
okrajL = round(2496/100*okrajL);
okrajP = round(2496/100*okrajP);

velikost_textu = str2double(get(handles.editt5,'String'));
mezera = velikost_textu * str2double(get(handles.editt6,'String'));

save data\ulozeny_format.mat rozdeleni okrajD okrajH okrajL okrajP velikost_textu mezera
close;



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% náhled na nastavené parametry
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

global rozdeleni;

rozdeleni = ones(3507,2496);

okrajDp = str2double(get(handles.editt1,'String'));
okrajHp = str2double(get(handles.editt2,'String'));
okrajLp = str2double(get(handles.editt3,'String'));
okrajPp = str2double(get(handles.editt4,'String'));

okrajD = round(3507/100*okrajDp);
okrajH = round(3507/100*okrajHp);
okrajL = round(2496/100*okrajLp);
okrajP = round(2496/100*okrajPp);

velikost_textu = str2double(get(handles.editt5,'String'));
mezera = velikost_textu * str2double(get(handles.editt6,'String'));

% pokud jsou zvolené hodnoty moc velké, nevykresluj nic jenom červené 
if okrajD >3507/2 || okrajD < 1
    set(findobj('tag','editt1'),'BackgroundColor', 'red');
    return;
else
    set(findobj('tag','editt1'),'BackgroundColor', 'white');
end

if okrajH >3507/2  || okrajH < 1    
    set(findobj('tag','editt2'),'BackgroundColor', 'red');
    return;
else
    set(findobj('tag','editt2'),'BackgroundColor', 'white');
end

if okrajL >2496/2  || okrajL < 1 
    set(findobj('tag','editt3'),'BackgroundColor', 'red');
    return;
else
    set(findobj('tag','editt3'),'BackgroundColor', 'white');
end

if okrajP >2496/2 || okrajP < 1    
    set(findobj('tag','editt4'),'BackgroundColor', 'red');
    return;
else
    set(findobj('tag','editt4'),'BackgroundColor', 'white');
end

% zobrazení okrajů
rozdeleni(1:okrajH,:) = 0;
rozdeleni(end - okrajD:end,:) = 0;
rozdeleni(:,1:okrajL) = 0;
rozdeleni(:,end - okrajP:end) = 0;

% vykreslení řádků
[rozdeleniX, rozdeleniY] = size(rozdeleni);
vyska_radku = velikost_textu + mezera;
for i = okrajH:vyska_radku:(rozdeleniX - okrajD)
   rozdeleni(i:i+10,okrajL:rozdeleniY - okrajP) = 0; 
end

imshow(rozdeleni);


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
