-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathmyicon.m
343 lines (309 loc) · 12.4 KB
/
myicon.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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
%MYICON add icon to MYICONPLACEHOLDER
% Constructor takes (axes,image,text,exestring,dentstick (Says if the button stays indented afterpress),indentimage)
%Klas Berggren & Einar Heiberg
classdef myicon < handle %Inherits from handles to get persistent objects.
properties (SetAccess = public)
name='';
dropdowniconcell={};
dropdowniconholder=[];
dropdownpanel = []; %dropdown axes are placed in panels
dropdownaxes=[];
parentobj=[];
mouseovertext=[];
cdata = [];
cdataDisplay=[];
cdataClicked=[];
cdataIndent=[];
cdataDisabled=[];
enabled=1;
execute=[];
isindented=0;
type=0
group=1;
end
methods
function g = myicon(name,parentobj,cdata,text,execute,type,group,cdataIndent,dropdowniconcell)%cdataClicked,cdataDisplay)
if nargin==1
text=[];
end
if nargin<6
g.type=1;
else
g.type=type;
end
if nargin<7
g.group=1;
else
g.group=group;
end
%Set properties
g.name=name;
g.parentobj=parentobj;
g.mouseovertext=text;
g.cdata = cdata;
g.cdataDisplay=cdata;
g.execute=execute;
if nargin<8 || isempty(cdataIndent)
g.generateclickeddisabledandindent(cdata)
else
g.generateclickeddisabledandindent(cdata,cdataIndent)
end
%generate all stuff needed for dropdowniconholders
if nargin==9
g.dropdowniconcell = dropdowniconcell;
% fig = g.parentobj.axeshandle.Parent.Parent;
% p = uipanel('parent',fig,'units','normalized','position',[0 0 1 1],'BorderType','none','Visible','off');
% ax = axes('parent',p,'units','normalized','position',[0 0 1 1]);
% g.dropdowniconholder = myiconplaceholder(ax);
% add(g.dropdowniconholder,g.dropdowniconcell);
% g.dropdownpanel.Visible = 'off';
% g.dropdownpanel = p;
% g.dropdownaxes = ax;
% % % fig = g.parentobj.axeshandle.Parent.Parent;
% % % p = uipanel('parent',fig,'units','normalized','position',[0 0 0 0],'BorderType','none','Visible','off');
% % % ax = axes('parent',p,'units','normalized','position',[0 0 1 1]);
% % add(g.dropdowniconholder,g.dropdowniconcell)
% g.dropdownpanel.Visible = 'off';
end
if g.type ~= 0 && g.type ~= 1 && g.type ~= 2 && g.type ~= 3
g.enabled = 0;
g.cdataDisplay=g.cdataDisabled;
end
end
%--------------------------------------------------
function generateclickeddisabledandindent(varargin)
g = varargin{1};
cdata = varargin{2};
tmp = cdata;
tmp(cdata==240) = 100;
g.cdataClicked = uint8(tmp);
cdataDisabled = rgb2gray(cdata)/5;
cdataDisabled = cdataDisabled+(240-max(max(cdataDisabled)));%(cdataDisabled>240)=240;
g.cdataDisabled=uint8(repmat(cdataDisabled,1,1,3));
%Allows user to specify how indented button should look like
if nargin<3
tmp=g.cdata;
tmp(g.cdata==240)=160;
g.cdataIndent=uint8(tmp);
else
g.cdataIndent=varargin{3};
end
end
%---------------------------
function highlight(varargin)
g=varargin{1};
if g.enabled
g.cdataDisplay=g.cdataClicked;
end
end
%-----------------------------
function unhighlight(varargin)
g=varargin{1};
%First check so that button is enabled
if g.enabled
%Check that if the button we are over is the same as the the
%clicked button, if so indent it. If not we want to unhighlight the previous button
currenticon=g.parentobj.geticon;
crit1 = isequal(currenticon,g.parentobj.clickedicon);
crit2 = isequal(hittest(g.parentobj.fig),g.parentobj.imagehandle);
if crit1 && crit2
switch g.type
case 0 %one click button
g.cdataDisplay=g.cdata;
case 1 %dentstick button
g.cdataDisplay=g.cdataIndent;
g.isindented=1;
case 2 %toggle button
if g.isindented
g.cdataDisplay=g.cdata;
g.isindented=0;
else
g.cdataDisplay=g.cdataIndent;
g.isindented=1;
end
case 3 %dropdown button
if g.isindented
g.cdataDisplay=g.cdata;
g.isindented=0;
else
g.cdataDisplay=g.cdataIndent;
g.isindented=1;
end
end
%Redundant for most cases but assures that play button gets
%proper appearance
g.parentobj.render
%Kill timer in parent so we dont display text
if ~isempty(g.parentobj.texttimer)
g.parentobj.displayinfo=0;
stop(g.parentobj.texttimer);
delete(g.parentobj.texttimer);
g.parentobj.texttimer=[];
end
if g.type~=3
feval(g.execute);
else
%g.setdropdown
% if g.isindented
% %do dropdown i.e place new temporary iconaxes which contains
% %a dropdown iconholder
%
% %Number of rows and cols in iconholder divide this with the height and width of
% %the axes of iconholder also calculate lower left corner of
% [iconcornerx,iconcornery] = buttoncorner(g.parentobj,g.name);
%
% rows = size(g.parentobj.iconCell,1);
% cols = size(g.parentobj.iconCell,2);
% pos =plotboxpos(g.parentobj.axeshandle);%get(g.parentobj.axeshandle,'position');
% iconheight = pos(4)/rows; %in gui
% iconwidth = pos(3)/cols; %in gui
% offsety = size(g.dropdowniconcell,1)*iconheight;
%
% %place new axes on bottom left corner of dropdown icon
% newaxespos = [iconcornerx,iconcornery-offsety,iconwidth,offsety+iconheight/2];
% fig = get(g.parentobj.axeshandle,'parent');
% ax = axes('parent',fig,'units','normalized','position',newaxespos);
% g.dropdownaxes=ax; %add to dropdown axes field
% %add iconholder to axes and render
% g.dropdowniconholder = myiconplaceholder(ax,0,3);
% g.parentobj.dropdowniconholders{end+1} = g.dropdowniconholder;
% add(g.dropdowniconholder,g.dropdowniconcell)
%
% for i = 1:numel(g.dropdowniconcell)
% g.dropdowniconcell{i}.parentobj.axeshandle
% end
%
% else
% g.parentobj.dropdowniconholders([g.parentobj.dropdowniconholders{:}]==g.dropdowniconholder)=[];
% delete(g.dropdownaxes);
% delete(g.dropdowniconholder);
% g.dropdowniconholder = [];
% g.dropdownaxes=[];
% end
end
else
g.cdataDisplay=g.cdata;
end
end
end
%-----------------------------
function showdropdown(varargin)
g = varargin{1};
if g.isindented
if isequal(g.dropdownpanel.Visible,'off')
%uistack(g.dropdownpanel,'top');
g.dropdownpanel.Visible = 'on';
add(g.dropdowniconholder,g.dropdowniconcell)
end
else
if isequal(g.dropdownpanel.Visible,'on')
g.dropdownpanel.Visible = 'off';
end
end
end
%-----------------------------
function placedropdown(varargin)
g = varargin{1};
%do dropdown i.e place new temporary iconaxes which contains
%a dropdown iconholder
%Number of rows and cols in iconholder divide this with the height and width of
%the axes of iconholder also calculate lower left corner of
[iconcornerx,iconcornery] = buttoncorner(g.parentobj,g.name);
rows = size(g.parentobj.iconCell,1);
cols = size(g.parentobj.iconCell,2);
pos = plotboxpos(g.parentobj.axeshandle);%get(g.parentobj.axeshandle,'position');
panelpos = g.parentobj.axeshandle.Parent.Position;
%snap buttoncorner to panelbottom
iconcornery = panelpos(2);
iconheight = pos(4)*panelpos(4)/rows; %in gui
iconwidth = pos(3)*panelpos(3)/cols*1.2; %in gui
offsety = (size(g.dropdowniconcell,1))*iconheight-0*iconheight/2;
newaxespos = [iconcornerx,iconcornery-offsety-iconheight/2,iconwidth,offsety+iconheight/2];
g.dropdownpanel.Position = newaxespos;
end
% if isindented
% %do dropdown i.e place new temporary iconaxes which contains
% %a dropdown iconholder
%
% %Number of rows and cols in iconholder divide this with the height and width of
% %the axes of iconholder also calculate lower left corner of
% [iconcornerx,iconcornery] = buttoncorner(g.parentobj,g.name);
%
% rows = size(g.parentobj.iconCell,1);
% cols = size(g.parentobj.iconCell,2);
% pos = plotboxpos(g.parentobj.axeshandle);%get(g.parentobj.axeshandle,'position');
%
% if strcmp(g.parentobj.axeshandle.Parent.Type,'uipanel')
% panelpos = g.parentobj.axeshandle.Parent.Position;
% fig = g.parentobj.axeshandle.Parent.Parent;
% %snap buttoncorner to panelbottom
% iconcornery = panelpos(2);
% else
% panelpos = [0,0,1,1];
% fig = g.parentobj.axeshandle.Parent;
% end
%
% iconheight = pos(4)*panelpos(4)/rows; %in gui
% iconwidth = pos(3)*panelpos(3)/cols*1.2; %in gui
% offsety = (size(g.dropdowniconcell,1))*iconheight-0*iconheight/2;
%
% %place new axes on bottom left corner of dropdown icon
% newaxespos = [iconcornerx,iconcornery-offsety-iconheight/2,iconwidth,offsety+iconheight/2];
% p = uipanel('parent',fig,'units','normalized','position',newaxespos,'BorderType','none');
% ax = axes('parent',p,'units','normalized','position',[0 0 1 1]);
% g.dropdownpanel = p;
% g.dropdownaxes = ax; %add to dropdown axes field
%
% %add iconholder to axes and render
% g.dropdowniconholder = myiconplaceholder(ax,0,3);
% if isempty(g.parentobj.dropdowniconholders)
% g.parentobj.dropdowniconholders = g.dropdowniconholder;
% else
% g.parentobj.dropdowniconholders(end+1) = g.dropdowniconholder;
% end
% add(g.dropdowniconholder,g.dropdowniconcell)
% else
%
% if (~isempty(g.parentobj.dropdowniconholders)) && (~isempty(g.dropdowniconholder))
% g.parentobj.dropdowniconholders(g.parentobj.dropdowniconholders==g.dropdowniconholder)=[];
% delete(g.dropdownaxes);
% delete(g.dropdownpanel);
% delete(g.dropdowniconholder);
% g.dropdowniconholder = [];
% g.dropdownpanel = [];
% g.dropdownaxes = [];
% end
%
% end
% end
%------------------------
function undent(varargin)
g=varargin{1};
g.isindented=0;
if g.enabled
g.cdataDisplay=g.cdata;
else
g.cdataDisplay=g.cdataDisabled;
end
end
%------------------------
function enable(varargin)
g=varargin{1};
g.enabled=1;
g.cdataDisplay=g.cdata;
g.parentobj.render
end
%-------------------------
function disable(varargin)
g=varargin{1};
g.enabled=0;
g.cdataDisplay=g.cdataDisabled;
g.parentobj.render
end
%-------------------------
function setIcon(varargin)
g=varargin{1};
g.cdata=varargin{2};
end
end
end