-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathyesnodialogwithimage.m
120 lines (112 loc) · 4.09 KB
/
yesnodialogwithimage.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
function usersanswer = yesnodialogwithimage(imagedata,txtmessage)
% function to show a user dialog that shows an image and two buttons with
% options "YES,continue" and "NO, return"
global DATA
% get current screensize in pixels
set(0,'units','pixels')
screensizeinpix = get(0,'screensize');
usersanswer = false;
% calculate figure position
figwidth = 300;
figheight = 500;
figstartx = floor(screensizeinpix(3)-figwidth)/2;
figstarty = floor(screensizeinpix(4)-figheight)/2;
% create an invisible figure
fig = figure(...
...'Visible', 'off',...
'Name',dprintf('Warning'), ...
'MenuBar','none',...
'Resize', 'off',...
'keypressfcn',@keypressed,...
'Position',[figstartx figstarty figwidth figheight],...
'Color',DATA.GUISettings.BackgroundColor,...
'NumberTitle','off'...
);
% load in image ad crop
offset = 20;
if ~exist('imagedata','var')|| isempty(imagedata)
if isdeployed
tmpimg = imread('drawing_guidance.png');
else
tmpimg = imread(['+straintagging' filesep 'drawing_guidance.png']);
end
imwidth = floor(size(tmpimg,2)/4);
imheight = size(tmpimg,1)- 50;
img = imcrop(tmpimg,[2*imwidth 0 imwidth imheight]);
else
imwidth = size(imagedata,2);
imheight = size(imagedata,1);
img = imagedata;
end
% add axes to the figure and show image
ax = axes(fig);
ax.Units = 'pixels';
axeswidth = figwidth-2*offset;
axesheight = floor(axeswidth*imheight/imwidth);
ax.Position = [offset 135 axeswidth axesheight];
imagesc(ax,img)
axis off;
% add text message
if ~exist('txtmessage','var')|| isempty(txtmessage)
txtmessage = dprintf('Warning');
end
txtposition = [offset 70 axeswidth 60];
msgtextcontrol = uicontrol(fig,...
'Style','text',...
'Units','pixels',...
'Position',txtposition,...
'keypressfcn',@yeskeypressed,...
'HorizontalAlignment', 'left',...
'BackgroundColor',DATA.GUISettings.BackgroundColor,...
'ForegroundColor',DATA.GUISettings.ForegroundColor,...
'String',txtmessage); %#ok<NASGU>
% add buttons
buttonheight = 30;
yesbuttonposition = [offset offset axeswidth/2-10 buttonheight];
yesbuttoncontrol = uicontrol(fig,...
'Style','pushbutton',...
'Units','pixels',...
'Position',yesbuttonposition,...
'Callback',@selection,...
'BackgroundColor',DATA.GUISettings.BackgroundColor,...
'ForegroundColor',DATA.GUISettings.ForegroundColor,...
'String',dprintf('YES, continue'),...
'UserData','yes'); %#ok<NASGU>
nobuttonposition = [offset+axeswidth/2+10 offset axeswidth/2-10 buttonheight];
nobuttoncontrol = uicontrol(fig,...
'Style','pushbutton',...
'Units','pixels',...
'Position',nobuttonposition,...
'Callback',@selection,...
'BackgroundColor',DATA.GUISettings.BackgroundColor,...
'ForegroundColor',DATA.GUISettings.ForegroundColor,...
'String',dprintf('NO, return'),...
'UserData','no'); %#ok<NASGU>
uiwait(fig)
function selection(src,~)
str = src.UserData;
if contains(lower(str),'yes')
usersanswer = true;
else
usersanswer = false;
end
uiresume(fig)
close(fig)
end
%----------------------------------
function keypressed(fignum,evnt) %#ok<INUSL>
%----------------------------------
key = getkey(evnt);
switch key
case {'y','Y'}
usersanswer = true;
uiresume(fig)
close(fig)
case {'n','N'}
usersanswer = true;
uiresume(fig)
close(fig)
otherwise
end
end
end