function varargout = mimagui(varargin)
% MIMAGUI MATLAB code for mimagui.fig
% MIMAGUI, by itself, creates a new MIMAGUI or raises the existing
% singleton*.
%
% H = MIMAGUI returns the handle to a new MIMAGUI or the handle to
% the existing singleton*.
%
% MIMAGUI('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in MIMAGUI.M with the given input arguments.
%
% MIMAGUI('Property','Value',...) creates a new MIMAGUI or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before mimagui_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to mimagui_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 mimagui
% Last Modified by GUIDE v2.5 14-Jun-2018 09:05:19
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @mimagui_OpeningFcn, ...
'gui_OutputFcn', @mimagui_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
end
% --- Executes just before mimagui is made visible.
function mimagui_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 mimagui (see VARARGIN)
% Choose default command line output for mimagui
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
global mimaset mimapan mimakey mimapanflag
%初始化参数设置
mimapan = zeros(1,6);%为密码盘上的数值
mimaset = 0; %标志位指示密码是否已经设置
mimakey = zeros(1,6);%初始密码设置
mimapanflag = zeros(1,6);
set(handles.pushbutton1,'string','设置密码');
%读取宝箱图片
ImageBxClose = imread('1.jpg');
%显示宝箱图片(关闭模式)
axes(handles.axes1);
imshow(ImageBxClose);
%设置密码盘初始设置
set(handles.pushbutton2,'string','0');
set(handles.pushbutton3,'string','0');
set(handles.pushbutton4,'string','0');
set(handles.pushbutton5,'string','0');
set(handles.pushbutton6,'string','0');
set(handles.pushbutton7,'string','0');
%设置密码盘显示字体
set(handles.pushbutton2,'fontsize',12);
set(handles.pushbutton3,'fontsize',12);
set(handles.pushbutton4,'fontsize',12);
set(handles.pushbutton5,'fontsize',12);
set(handles.pushbutton6,'fontsize',12);
set(handles.pushbutton7,'fontsize',12);
set(handles.pushbutton2,'ButtonDownFcn',@(hObject,eventdata)mimagui('pushbutton2_ButtonDownFcn',hObject,eventdata,guidata(hObject)));
set(handles.pushbutton3,'ButtonDownFcn',@(hObject,eventdata)mimagui('pushbutton3_ButtonDownFcn',hObject,eventdata,guidata(hObject)));
set(handles.pushbutton4,'ButtonDownFcn',@(hObject,eventdata)mimagui('pushbutton4_ButtonDownFcn',hObject,eventdata,guidata(hObject)));
set(handles.pushbutton5,'ButtonDownFcn',@(hObject,eventdata)mimagui('pushbutton5_ButtonDownFcn',hObject,eventdata,guidata(hObject)));
set(handles.pushbutton6,'ButtonDownFcn',@(hObject,eventdata)mimagui('pushbutton6_ButtonDownFcn',hObject,eventdata,guidata(hObject)));
set(handles.pushbutton7,'ButtonDownFcn',@(hObject,eventdata)mimagui('pushbutton7_ButtonDownFcn',hObject,eventdata,guidata(hObject)));
% UIWAIT makes mimagui wait for user response (see UIRESUME)
% uiwait(handles.figure1);
end
% --- Outputs from this function are returned to the command line.
function varargout = mimagui_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;
end
% --- 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 mimaset mimapan mimakey
global mimapanflag
mimapanflag = zeros(1,6);
%密码未设置时
if (mimaset==0)
%讲密码盘显示进行保存
mimakey = mimapan;
%并且恢复初始的密码盘
mimapan = zeros(1,6);
set(handles.pushbutton2,'string','0');
set(handles.pushbutton3,'string','0');
set(handles.pushbutton4,'string','0');
set(handles.pushbutton5,'string','0');
set(handles.pushbutton6,'string','0');
set(handles.pushbutton7,'string','0');
set(handles.pushbutton1,'string','开锁');
mimaset = 1;
else
%开箱
%若密码盘与存储密码一样
if (mimakey == mimapan)
%密码正确
%显示宝箱打开图片
ImageBxOpen = imread('2.jpg');
axes(handles.axes1);
imshow(ImageBxOpen);
else
%密码错误
%显示宝箱关闭图片
ImageBxClose = imread('1.jpg');
axes(handles.axes1);
imshow(ImageBxClose);
end
end
end
% --- Executes on mouse press over axes background.
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject handle to axes2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global mimapanflag mimapan
Ind = 1;
%函数占用标志位,防止多次调用冲突
if (mimapanflag(Ind)==0)
mimapanflag(Ind) = 1;
%开始波动密码盘
mimapan(Ind) = mod(mimapan(Ind)+1,10);
set(handles.pushbutton2,'string',num2str(mimapan(Ind)));
mimapanflag(Ind) = 0;
end
end
function pushbutton3_Callback(hObject, eventdata, handles)
% hObject handle to axes2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global mimapanflag mimapan
Ind = 2;
if (mimapanflag(Ind)==0)
mimapanflag(Ind) = 1;
mimapan(Ind) = mod(mimapan(Ind)+1,10);
set(handles.pushbutton3,'string',num2str(mimapan(Ind)));
mimapanflag(Ind) = 0;
end
end
function pushbutton4_Callback(hObject, eventdata, handles)
% hObject handle to axes2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global mimapanflag mimapan
Ind = 3;
if (mimapanflag(Ind)==0)
mimapanflag(Ind) = 1;
mimapan(Ind) = mod(mimapan(Ind)+1,10);
set(handles.pushbutton4,'string',num2str(mimapan(Ind)));
mimapanflag(Ind) = 0;
end
end
function pushbutton5_Callback(hObject, eventdata, handles)
% hObject handle to axes2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global mimapanflag mimapan
Ind = 4;
if (mimapanflag(Ind)==0)
mimapanflag(Ind) = 1;
mimapan(Ind) = mod(mimapan(Ind)+1,10);
set(handles.pushbutton5,'string',num2str(mimapan(Ind)));
mimapanflag(Ind) = 0;
end
end
function pushbutton6_Callback(hObject, eventdata, handles)
% hObject handle to axes2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global mimapanflag mimapan
Ind = 5;
if (mimapanflag(Ind)==0)
mimapanflag(Ind) = 1;
mimapan(Ind) = mod(mimapan(Ind)+1,10);
set(handles.pushbutton6,'string',num2str(mimapan(Ind)));
mimapanflag(Ind) =