-
Notifications
You must be signed in to change notification settings - Fork 22
/
uisetlineprops.m
277 lines (229 loc) · 9.23 KB
/
uisetlineprops.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
function varargout = uisetlineprops(varargin)
% UISETLINEPROPS is a GUI tool for setting line and marker properties
% Usage:
% uisetlineprops(H) where H is the handle to a line object
%
% Example:
% s=peaks;
% handle=plot(s(:,25));
% props=uisetlineprops(handle)
% MJ - Mar 7, 2007
% Begin initialization code - DO NOT EDIT
if nargin==0
feval('help',mfilename); return
end
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @uisetlineprops_OpeningFcn, ...
'gui_OutputFcn', @uisetlineprops_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 uisetlineprops is made visible.
function uisetlineprops_OpeningFcn(hObject, eventdata, handles, varargin)
%Display gui in center of screen
set( handles.figure1,'Units', 'pixels' );
screenSize = get(0, 'ScreenSize');
position = get( handles.figure1,'Position' );
position(1) = (screenSize(3)-position(3))/2;
position(2) = (screenSize(4)-position(4))/2;
set( handles.figure1,'Position', position );
h=[];
obj.PropName={'visible','color'};
obj.PropVal=getprops(handles);
if nargin>3
h=varargin{1}; h=h(ishandle(h));
objtype=get(h,'type'); isline=false(size(h));
% ii=strmatch('line',objtype,'exact'); isline(ii)=true;
% if any(~isline)
% disp('Warning: Only "line" objects are supported'); h=h(isline);
% end
if isempty(h)
disp('Warning: Invalid object handle.');
end
end
obj.handle=h;
if ~isempty(h)
obj.PropVal=get(h(1),obj.PropName)'; rgb=round(obj.PropVal{2}.*255);
if ~strcmp(obj.PropVal{2},'none') obj.PropVal{5}=obj.PropVal{2}(1); end
setprops(handles,obj.PropVal);
end
%keyboard
setappdata(hObject,'object',obj);
% Choose default command line output for uisetlineprops
handles.output = [];
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes uisetlineprops wait for user response (see UIRESUME)
setrgbcolor(handles);
uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = uisetlineprops_OutputFcn(hObject, eventdata, handles)
varargout = getappdata(0,'varargout');
% load varargout
% closereq
return
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function edit_Red_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
set(hObject,'val',str2double(get(hObject,'str')));
function edit_Green_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
set(hObject,'val',str2double(get(hObject,'str')));
function edit_Blue_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
set(hObject,'val',str2double(get(hObject,'str')));
%set(hObject,'userdata',get(hObject,'val'));
%%%%%%%%%%%%%%%------------------------------------------------
%%%%%%%%%%%%%%%------------------------------------------------
%%%%%%%%%%%%%%%------------------------------------------------
%%%%%%%%%%%%%%%------------------------------------------------
function checkbox_visibility_Callback(hObject, eventdata, handles)
obj=getappdata(handles.figure1,'object');
set(obj.handle,'visible',ooflag(get(hObject,'value')));
function edit_Red_Callback(hObject, eventdata, handles)
obj=getappdata(handles.figure1,'object');
str=get(hObject,'string'); num=str2double(str);
num0=get(hObject,'value'); str0=num2str(num0);
if num>255 | num<0, num=nan; end
if num>0 & num<1, num=num.*255; end
num=round(num); str=num2str(num);
if ~isnan(num)
set(hObject,'value',num,'string',str);
clr=[num get(handles.edit_Green,'val') get(handles.edit_Blue,'val')]./255;
sett(obj.handle,'color',clr);
setrgbcolor(handles);
else
set(hObject,'string',str0);
end
function edit_Green_Callback(hObject, eventdata, handles)
obj=getappdata(handles.figure1,'object');
str=get(hObject,'string'); num=str2double(str);
num0=get(hObject,'value'); str0=num2str(num0);
if num>255 | num<0, num=nan; end
if num>0 & num<1, num=num.*255; end
num=round(num); str=num2str(num);
if ~isnan(num)
set(hObject,'value',num,'string',str);
clr=[get(handles.edit_Red,'val') num get(handles.edit_Blue,'val')]./255;
sett(obj.handle,'color',clr);
setrgbcolor(handles);
else
set(hObject,'string',str0);
end
function edit_Blue_Callback(hObject, eventdata, handles)
obj=getappdata(handles.figure1,'object');
str=get(hObject,'string'); num=str2double(str);
num0=get(hObject,'value'); str0=num2str(num0);
if num>255 | num<0, num=nan; end
if num>0 & num<1, num=num.*255; end
num=round(num); str=num2str(num);
if ~isnan(num)
set(hObject,'value',num,'string',str);
clr=[get(handles.edit_Red,'val') get(handles.edit_Green,'val') num]./255;
sett(obj.handle,'color',clr);
setrgbcolor(handles);
else
set(hObject,'string',str0);
end
function pushbutton_uisetcolor_Callback(hObject, eventdata, handles)
obj=getappdata(handles.figure1,'object');
if isempty(obj.handle)
clr=uisetcolor('Set Line Color');
else
clr=uisetcolor(obj.handle,'Set Line Color');
end
rgb=round(clr.*255);
set(handles.edit_Red,'str',num2str(rgb(1)),'val',rgb(1));
set(handles.edit_Green,'str',num2str(rgb(2)),'val',rgb(2));
set(handles.edit_Blue,'str',num2str(rgb(3)),'val',rgb(3));
setrgbcolor(handles);
function pushbutton_OK_Callback(hObject, eventdata, handles)
obj=getappdata(handles.figure1,'object');
obj.PropVal=getprops(handles); % get new properties
handles.output=cell2struct(obj.PropVal(:),obj.PropName(:));
guidata(handles.figure1,handles);
% uiresume(handles.figure1);
try
varargout{1} = handles.output;
catch
varargout{1} = [];
end
setappdata(0,'varargout',varargout);
% save varargout
closereq
% function pushbutton_Cancel_Callback(hObject, eventdata, handles)
% obj=getappdata(handles.figure1,'object');
% %% set old properties
% set(obj.handle,obj.PropName',obj.PropVal');
% handles.output=cell2struct(obj.PropVal(:),obj.PropName(:));
% guidata(handles.figure1,handles);
% uiresume(handles.figure1);
% function pushbutton_reset_Callback(hObject, eventdata, handles)
% obj=getappdata(handles.figure1,'object');
% %% set old properties
% set(obj.handle,obj.PropName',obj.PropVal');
% setprops(handles,obj.PropVal);
% setrgbcolor(handles);
% %handles.output=cell2struct(obj.PropVal(:),obj.PropName(:));
% %guidata(handles.figure1,handles);
%%%%%(((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((
%%%%%(((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((
function setprops(handles,PropVal)
choices=getappdata(handles.figure1,'choices');
rgb=round(PropVal{2}.*255);
set(handles.checkbox_visibility,'val',ooflag(PropVal{1}));
set(handles.edit_Red,'str',num2str(rgb(1)),'val',rgb(1));
set(handles.edit_Green,'str',num2str(rgb(2)),'val',rgb(2));
set(handles.edit_Blue,'str',num2str(rgb(3)),'val',rgb(3));
function PropVal=getprops(handles)
%obj=getappdata(handles.figure1,'object');
choices=getappdata(handles.figure1,'choices');
PropVal{1}=ooflag(get(handles.checkbox_visibility,'val'));
rgb(1,1)=get(handles.edit_Red,'val');
rgb(1,2)=get(handles.edit_Green,'val');
rgb(1,3)=get(handles.edit_Blue,'val');
PropVal{2}=rgb./255;
%setappdata(handles.figure1,'object',obj);
function setrgbcolor(h)
rgb(1,1)=get(h.edit_Red,'val');
rgb(1,2)=get(h.edit_Green,'val');
rgb(1,3)=get(h.edit_Blue,'val');
clr=rgb./255;
set([h.textR h.textG h.textB],'BackGroundColor',clr);
set([h.textR h.textG h.textB],'ForeGroundColor',1-clr);
function out=ooflag(in) %% convert 'on'/'off' to 0/1 and vice versa
oo={'off','on'};
if isnumeric(in)
if isscalar(in)
out=oo{logical(in)+1}; return % return string 'on' or 'off'
else
out=oo(logical(in)+1); return % return cell array {'on','off',...}
end
elseif ischar(in)
out=logical(strmatch(in,oo,'exact')-1); return % 0, 1, or []
elseif iscell(in)
out=false(size(in)); ii=strmatch(oo{2},in,'exact');
out(ii)=true; % return logical array [0 0 1 0 1 1 1 0 ...]
end
function sett(h,varargin)
h=h(ishandle(h));
try, set(h,varargin{:}); end
% --- Executes when user attempts to close figure1.
function figure1_CloseRequestFcn(hObject, eventdata, handles)
delete(hObject);