NCCOOS Trac Projects: Top | Web | Platforms | Processing | Viz | Sprints | Sandbox | (Wind)

root/gliderproc/trunk/MATLAB/plots/prstuff/EditColor.m

Revision 495 (checked in by cbc, 11 years ago)

Initial import of Stark code.

Line 
1 function EditColor(arg, command, option)
2
3 if nargin==0,arg='rgb';,end
4
5 global LASTOBJECT LASTTYPE
6
7 selectedObj = LASTOBJECT;
8 if isempty(selectedObj),return,end      % exit if no selected object
9 type = LASTTYPE;
10
11 if arg==0
12  
13   if(command == 3)
14    if(strcmp(type,'line') | strcmp(type,'text'))
15       set(selectedObj,'Color',option);
16    elseif(strcmp(type,'patch'))
17       set(selectedObj,'EdgeColor',option);
18    elseif(strcmp(type,'axes'))
19       set(selectedObj,'Xcolor',option);
20       set(selectedObj,'Ycolor',option);
21       set(selectedObj,'Zcolor',option);
22    end
23  end
24
25 elseif strcmp(arg,'rgb')
26
27    % Allow only one RGB_EDIT at a time
28    %
29    RGB_Edit=findobj(0,'Type','figure','Tag','RGB_Edit');
30    if ~isempty(RGB_Edit),return,end
31    
32    rgbfig = figure('Position',[150 200 220 300],...
33                    'NumberTitle','off',...
34                    'Name','Edit RGB',...
35                    'NextPlot','new',...
36                    'Tag','RGB_Edit',...
37                    'Units','normalized');
38    wh_ratio=320/400;
39
40    htR1=uicontrol('Parent',rgbfig,...
41                  'Units','normalized',...
42                  'Position',[.05 .5 .11 .08],...
43                  'Style','edit',...
44                  'String','126',...
45                  'BackGroundColor',[1 0 0],...
46                  'ForeGroundColor',[0 0 0],...
47                  'Tag','RedVal1');
48    Rslider=uicontrol('Parent',rgbfig,...
49                      'Style','slider',...
50                      'Units','normalized',...
51                      'Position',[.2 .5 .6 .08],...
52                      'Tag','Red_Slider',...
53                      'Min',0,'Max',255,'Value',126,...
54                      'BackGroundColor',[1 0 0],...
55                      'ForeGroundColor',[0 0 0],...
56                      'CallBack','EditColor(2)');
57    htR2=uicontrol('Parent',rgbfig,...
58                  'Units','normalized',...
59                  'Position',[.84 .5 .11 .08],...
60                  'Style','text',...
61                  'String','.5',...
62                  'BackGroundColor',[1 0 0],...
63                  'ForeGroundColor',[0 0 0],...
64                  'Tag','RedVal2');
65                  
66    htG1=uicontrol('Parent',rgbfig,...
67                  'Units','normalized',...
68                  'Position',[.05 .395 .11 .08],...
69                  'Style','text',...
70                  'String','126',...
71                  'BackGroundColor',[0 1 0],...
72                  'ForeGroundColor',[0 0 0],...
73                  'Tag','GreenVal1');
74    GRslider=uicontrol('Parent',rgbfig,...
75                      'Style','slider',...
76                      'Units','normalized',...
77                      'Position',[.2 .395 .6 .08],...
78                      'Min',0,'Max',255,'Value',126,...
79                      'Tag','Green_Slider',...
80                      'BackGroundColor',[0 1 0],...
81                      'ForeGroundColor',[0 0 0],...
82                      'CallBack','EditColor(3)');
83    htG2=uicontrol('Parent',rgbfig,...
84                  'Units','normalized',...
85                  'Position',[.84 .395 .11 .08],...
86                  'Style','text',...
87                  'String','.5',...
88                  'BackGroundColor',[0 1 0],...
89                  'ForeGroundColor',[0 0 0],...
90                  'Tag','GreenVal2');
91                  
92    htB1=uicontrol('Parent',rgbfig,...
93                  'Units','normalized',...
94                  'Position',[.05 .28 .11 .08],...
95                  'Style','text',...
96                  'String','126',...
97                  'BackGroundColor',[0 0 1],...
98                  'ForeGroundColor',[1 1 1],...
99                  'Tag','BlueVal1');
100    Bslider=uicontrol('Parent',rgbfig,...
101                      'Style','slider',...
102                      'Units','normalized',...
103                      'Position',[.2 .28 .6 .08],...
104                      'Min',0,'Max',255,'Value',126,...
105                      'Tag','Blue_Slider',...
106                      'BackGroundColor',[0 0 1],...
107                      'ForeGroundColor',[1 1 1],...
108                      'CallBack','EditColor(4)');
109    htB2=uicontrol('Parent',rgbfig,...
110                  'Units','normalized',...
111                  'Position',[.84 .28 .11 .08],...
112                  'Style','text',...
113                  'String','.5',...
114                  'BackGroundColor',[0 0 1],...
115                  'ForeGroundColor',[1 1 1],...
116                  'Tag','BlueVal2');
117                  
118    FPatchR=uicontrol('Parent',rgbfig,...
119                     'Units','normalized',...
120                     'Position',[.10 .75 .1/wh_ratio .1],...
121                     'Style','text',...
122                     'BackGroundColor',[.5 0 0],...
123                     'Tag','FPatchR');
124    uicontrol('Parent',rgbfig,...
125                  'Units','normalized',...
126                  'Position',[.21 .75 .1/wh_ratio .1],...
127                  'Style','text',...
128                  'String','+',...
129                  'BackGroundColor',[0 0 0],...
130                  'ForeGroundColor',[1 1 1]);
131    FPatchG=uicontrol('Parent',rgbfig,...
132                     'Units','normalized',...
133                     'Position',[.32 .75 .1/wh_ratio .1],...
134                     'Style','text',...
135                     'BackGroundColor',[0 .5 0],...
136                     'Tag','FPatchG');
137    uicontrol('Parent',rgbfig,...
138                  'Units','normalized',...
139                  'Position',[.43 .75 .1/wh_ratio .1],...
140                  'Style','text',...
141                  'String','+',...
142                  'BackGroundColor',[0 0 0],...
143                  'ForeGroundColor',[1 1 1]);
144    FPatchB=uicontrol('Parent',rgbfig,...
145                     'Units','normalized',...
146                     'Position',[.54 .75 .1/wh_ratio .1],...
147                     'Style','text',...
148                     'BackGroundColor',[0 0 .5],...
149                     'Tag','FPatchB');
150                    
151    uicontrol('Parent',rgbfig,...
152                  'Units','normalized',...
153                  'Position',[.65 .75 .1/wh_ratio .1],...
154                  'Style','text',...
155                  'String','=',...
156                  'BackGroundColor',[0 0 0],...
157                  'ForeGroundColor',[1 1 1]);
158    FPatchEq=uicontrol('Parent',rgbfig,...
159                     'Units','normalized',...
160                     'Position',[.77 .75 .1/wh_ratio .1],...
161                     'Style','text',...
162                     'BackGroundColor',[.5 .5 .5],...
163                     'Tag','FPatchEq');
164 %                    'Position',[.15 .7 .7 .2],...
165                  
166    
167    GetColorbutton = uicontrol('Parent',rgbfig,...
168                            'Style','pushbutton',...
169                            'String','Get Color',...
170                            'Units','normalized',...
171                            'Position',[.05 .05 .25 .1],...
172                            'Callback','EditColor(6)',...
173                            'BackGroundColor','g',...
174                            'ForeGroundColor','k',...
175                             'Tag','GetColorbutton');
176    Applybutton = uicontrol('Parent',rgbfig,...
177                            'Style','Checkbox',...
178                            'String','Apply',...
179                            'Units','normalized',...
180                            'Position',[.375 .05 .25 .1],...
181                            'Callback','EditColor(7)',...
182                            'BackGroundColor','g',...
183                            'ForeGroundColor','k',...
184                             'Tag','Applybutton');
185
186    Cancelbutton = uicontrol('Parent',rgbfig,...
187                             'Style','pushbutton',...
188                             'String','Cancel',...
189                             'Units','normalized',...
190                             'Position',[.7 .05 .25 .1],...
191                             'Callback','EditColor(9)',...
192                             'BackGroundColor','r',...
193                             'ForeGroundColor','k',...
194                             'Tag','Cancelbutton');
195
196 elseif arg==2   %  Affect Red Color
197
198    fig=findobj(0,'Type','figure','Tag','RGB_Edit');
199    Red_Slider=findobj(fig,'Type','uicontrol','Tag','Red_Slider');
200    RVal1=findobj(fig,'Type','uicontrol','Tag','RedVal1');
201    RVal2=findobj(fig,'Type','uicontrol','Tag','RedVal2');
202    FPatchR=findobj(fig,'Type','uicontrol','Tag','FPatchR');
203    FPatchEq=findobj(fig,'Type','uicontrol','Tag','FPatchEq');
204    newval=get(Red_Slider,'Value');
205    set(RVal1,'String',int2str(newval));
206    
207    if newval==255
208       s='01.';
209    elseif newval==0
210       s='00.';
211    else
212       s=num2str(newval/255,3);
213    end
214    set(RVal2,'String',s(2:length(s)));
215    oldcolor=get(FPatchEq,'BackGroundColor');
216    set(FPatchR,'BackGroundColor',[newval/255 0 0]);
217    set(FPatchEq,'BackGroundColor',[newval/255 oldcolor(2) oldcolor(3)]);
218
219    ApButton=findobj(fig,'Type','uicontrol','Tag','Applybutton');   
220    if get(ApButton,'Value')==1,EditColor(8),end
221
222 elseif arg==3    %  Affect Green Color
223
224    fig=findobj(0,'Type','figure','Tag','RGB_Edit');
225    Green_Slider=findobj(fig,'Type','uicontrol','Tag','Green_Slider');
226    GVal1=findobj(fig,'Type','uicontrol','Tag','GreenVal1');
227    GVal2=findobj(fig,'Type','uicontrol','Tag','GreenVal2');
228    FPatchEq=findobj(fig,'Type','uicontrol','Tag','FPatchEq');
229    FPatchG=findobj(fig,'Type','uicontrol','Tag','FPatchG');
230    newval=get(Green_Slider,'Value');
231    set(GVal1,'String',int2str(newval));
232
233    if newval==255
234       s='01.';
235    elseif newval==0
236       s='00.';
237    else
238       s=num2str(newval/255,3);
239    end
240    set(GVal2,'String',s(2:length(s)));
241    oldcolor=get(FPatchEq,'BackGroundColor');
242    set(FPatchG,'BackGroundColor',[0 newval/255 0]);
243    set(FPatchEq,'BackGroundColor',[oldcolor(1) newval/255 oldcolor(3)]);
244
245    ApButton=findobj(fig,'Type','uicontrol','Tag','Applybutton');   
246    if get(ApButton,'Value')==1,EditColor(8),end
247    
248 elseif arg==4    %  Affect Blue Color
249
250    fig=findobj(0,'Type','figure','Tag','RGB_Edit');
251    Blue_Slider=findobj(fig,'Type','uicontrol','Tag','Blue_Slider');
252    BVal1=findobj(fig,'Type','uicontrol','Tag','BlueVal1');
253    BVal2=findobj(fig,'Type','uicontrol','Tag','BlueVal2');
254    FPatchEq=findobj(fig,'Type','uicontrol','Tag','FPatchEq');
255    FPatchB=findobj(fig,'Type','uicontrol','Tag','FPatchB');
256    newval=get(Blue_Slider,'Value');
257    set(BVal1,'String',int2str(newval));
258    
259    if newval==255
260       s='01.';
261    elseif newval==0
262       s='00.';
263    else
264       s=num2str(newval/255,3);
265    end
266    set(BVal2,'String',s(2:length(s)));
267    oldcolor=get(FPatchEq,'BackGroundColor');
268    set(FPatchB,'BackGroundColor',[0 0 newval/255]);
269    set(FPatchEq,'BackGroundColor',[oldcolor(1) oldcolor(2) newval/255]);
270    
271    ApButton=findobj(fig,'Type','uicontrol','Tag','Applybutton');   
272    if get(ApButton,'Value')==1,EditColor(8),end
273    
274 elseif arg==6    %  Get Color from object
275                  %  Must not be a GUI, or a child of the RGB_Edit figure
276
277    waitforbuttonpress;
278    gtype=get(gco,'Type');
279    if strcmp(gtype,'uicontrol')|strcmp(gtype,'uimenu'),return,end
280    fig=findobj(0,'Type','figure','Tag','RGB_Edit');
281    par=get(gco,'parent');
282    if par==fig|gco==fig,return,end
283    
284    if strcmp(gtype,'patch')
285       color=get(gco,'FaceColor');
286    else
287       color=get(gco,'Color');
288    end
289    
290    if strcmp(color,'none'),return,end
291    
292    Rt1=findobj(fig,'Type','uicontrol','Tag','RedVal1');
293    Gt1=findobj(fig,'Type','uicontrol','Tag','GreenVal1');
294    Bt1=findobj(fig,'Type','uicontrol','Tag','BlueVal1');
295    Rt2=findobj(fig,'Type','uicontrol','Tag','RedVal2');
296    Gt2=findobj(fig,'Type','uicontrol','Tag','GreenVal2');
297    Bt2=findobj(fig,'Type','uicontrol','Tag','BlueVal2');
298    Red_Slider=findobj(fig,'Type','uicontrol','Tag','Red_Slider');
299    Green_Slider=findobj(fig,'Type','uicontrol','Tag','Green_Slider');
300    Blue_Slider=findobj(fig,'Type','uicontrol','Tag','Blue_Slider');
301    FPatchR=findobj(fig,'Type','uicontrol','Tag','FPatchR');
302    FPatchG=findobj(fig,'Type','uicontrol','Tag','FPatchG');
303    FPatchB=findobj(fig,'Type','uicontrol','Tag','FPatchB');
304    FPatchEq=findobj(fig,'Type','uicontrol','Tag','FPatchEq');
305    
306    Rval=floor(color(1)*255.);
307    Gval=floor(color(2)*255.);
308    Bval=floor(color(3)*255.);
309    set(Red_Slider,'Value',Rval);
310    set(Green_Slider,'Value',Gval);
311    set(Blue_Slider,'Value',Bval);
312    set(Rt1,'String',int2str(Rval));
313    set(Gt1,'String',int2str(Gval));
314    set(Bt1,'String',int2str(Bval));
315    
316    if color(1)==1
317       s1='01.';
318    elseif color(1)==0
319       s1='00.';
320    else
321       s1=num2str(color(1),3);
322    end
323    set(Rt2,'String',s1(2:length(s1)));
324    
325    if color(2)==1
326       s2='01.';
327    elseif color(2)==0
328       s2='00.';
329    else
330       s2=num2str(color(2),3);
331    end
332    set(Gt2,'String',s2(2:length(s2)));
333    
334    if color(3)==1
335       s3='01.';
336    elseif color(3)==0
337       s3='00.';
338    else
339       s3=num2str(color(3),3);
340    end
341    set(Bt2,'String',s3(2:length(s3)));
342    
343    set(FPatchR,'BackGroundColor',[color(1) 0 0]);
344    set(FPatchG,'BackGroundColor',[0 color(2) 0]);
345    set(FPatchB,'BackGroundColor',[0 0 color(3)]);
346    set(FPatchEq,'BackGroundColor',color);
347    
348
349 elseif arg==7    %  Apply Color to chosen object
350                  %  Must not be a GUI, or a child of the RGB_Edit figure
351
352    fig=findobj(0,'Type','figure','Tag','RGB_Edit');
353    ApButton=findobj(fig,'Type','uicontrol','Tag','Applybutton');
354    if get(ApButton,'Value')==0,return,end
355    
356    waitforbuttonpress;
357    
358    gtype=get(gco,'Type');
359    if strcmp(gtype,'uicontrol')|strcmp(gtype,'uimenu'),return,end
360    par=get(gco,'parent');
361    if par==fig|gco==fig,return,end
362    
363    Rt1=findobj(fig,'Type','uicontrol','Tag','RedVal1');
364    Gt1=findobj(fig,'Type','uicontrol','Tag','GreenVal1');
365    Bt1=findobj(fig,'Type','uicontrol','Tag','BlueVal1');
366    R=str2num(get(Rt1,'String'));
367    G=str2num(get(Gt1,'String'));
368    B=str2num(get(Bt1,'String'));
369    newcolor=[R G B]/255;
370      
371    if strcmp(gtype,'patch')
372       set(gco,'FaceColor',newcolor);
373    else
374       set(gco,'Color',newcolor);
375    end
376    set(ApButton,'UserData',gco)
377
378 elseif arg==8
379    fig=findobj(0,'Type','figure','Tag','RGB_Edit');
380    ApButton=findobj(fig,'Type','uicontrol','Tag','Applybutton');
381    cobj=get(ApButton,'UserData');
382    if isempty(cobj),return,end
383    gtype=get(cobj,'Type');
384    
385    Rt1=findobj(fig,'Type','uicontrol','Tag','RedVal1');
386    Gt1=findobj(fig,'Type','uicontrol','Tag','GreenVal1');
387    Bt1=findobj(fig,'Type','uicontrol','Tag','BlueVal1');
388    R=str2num(get(Rt1,'String'));
389    G=str2num(get(Gt1,'String'));
390    B=str2num(get(Bt1,'String'));
391    newcolor=[R G B]/255;
392      
393    if strcmp(gtype,'patch')
394       set(cobj,'FaceColor',newcolor);
395    else
396       set(cobj,'Color',newcolor);
397    end
398    
399    
400 elseif arg==9
401    fig=findobj(0,'Type','figure','Tag','RGB_Edit');
402    delete(fig);
403 end
Note: See TracBrowser for help on using the browser.