1 | % By Philip Torr 2002 |
---|
2 | % copyright Microsoft Corp. |
---|
3 | function F_param_out = torr_c_menu(varargin) |
---|
4 | % C_MENU Application M-file for c_menu.fig |
---|
5 | % FIG = C_MENU launch c_menu GUI. |
---|
6 | % C_MENU('callback_name', ...) invoke the named callback. |
---|
7 | |
---|
8 | % Last Modified by GUIDE v2.0 10-Apr-2002 16:21:13 |
---|
9 | error(nargchk(0,4,nargin)) % function takes only 0 or 2 argument |
---|
10 | if nargin == 2 % LAUNCH GUI |
---|
11 | |
---|
12 | |
---|
13 | fig = openfig(mfilename,'reuse'); |
---|
14 | % Use system color scheme for figure: |
---|
15 | set(fig,'Color',get(0,'defaultUicontrolBackgroundColor')); |
---|
16 | |
---|
17 | |
---|
18 | % % Position figure |
---|
19 | % if nargin == 2 |
---|
20 | % pos_size = get(fig,'Position'); |
---|
21 | % pos = varargin{2}; |
---|
22 | % if length(pos) ~= 2 |
---|
23 | % errordlg('Input argument must be a 2-element vector','argh') |
---|
24 | % end |
---|
25 | % new_pos = [pos(1) pos(2) pos_size(3) pos_size(4)]; |
---|
26 | % set(fig,'Position',new_pos,'Visible','on') |
---|
27 | % figure(fig) |
---|
28 | % |
---|
29 | % end |
---|
30 | |
---|
31 | |
---|
32 | |
---|
33 | % Use system color scheme for figure: |
---|
34 | set(fig,'Color',get(0,'defaultUicontrolBackgroundColor')); |
---|
35 | |
---|
36 | % Generate a structure of handles to pass to callbacks, and store it. |
---|
37 | handles = guihandles(fig); |
---|
38 | |
---|
39 | |
---|
40 | |
---|
41 | F_param = varargin{1}; |
---|
42 | handles.no_samp = F_param.no_samp; |
---|
43 | handles.threshold = F_param.f_threshold; |
---|
44 | |
---|
45 | |
---|
46 | set(handles.number_samples_button, 'String', num2str(handles.no_samp)); |
---|
47 | set(handles.T_button, 'String', num2str(handles.threshold)); |
---|
48 | |
---|
49 | |
---|
50 | |
---|
51 | guidata(fig, handles); |
---|
52 | |
---|
53 | % Wait for callbacks to run and window to be dismissed: |
---|
54 | uiwait(fig); |
---|
55 | |
---|
56 | % |
---|
57 | % UIWAIT might have returned because the window was deleted using |
---|
58 | % the close box - in that case, return 'cancel' as the answer, and |
---|
59 | % don't bother deleting the window! |
---|
60 | if ~ishandle(fig) |
---|
61 | disp('No changes made'); |
---|
62 | F_param_out(1) = handles.no_samp; |
---|
63 | F_param_out(2) = handles.threshold; |
---|
64 | else |
---|
65 | % otherwise, we got here because the user pushed one of the two buttons. |
---|
66 | % retrieve the latest copy of the 'handles' struct, and return the answer. |
---|
67 | % Also, we need to delete the window. |
---|
68 | handles = guidata(fig); |
---|
69 | F_param_out(1) = handles.no_samp |
---|
70 | F_param_out(2) = handles.threshold |
---|
71 | delete(fig); |
---|
72 | end |
---|
73 | |
---|
74 | |
---|
75 | |
---|
76 | elseif ischar(varargin{1}) % INVOKE NAMED SUBFUNCTION OR CALLBACK |
---|
77 | |
---|
78 | try |
---|
79 | [varargout{1:nargout}] = feval(varargin{:}); % FEVAL switchyard |
---|
80 | catch |
---|
81 | disp(lasterr); |
---|
82 | end |
---|
83 | |
---|
84 | end |
---|
85 | |
---|
86 | |
---|
87 | %| ABOUT CALLBACKS: |
---|
88 | %| GUIDE automatically appends subfunction prototypes to this file, and |
---|
89 | %| sets objects' callback properties to call them through the FEVAL |
---|
90 | %| switchyard above. This comment describes that mechanism. |
---|
91 | %| |
---|
92 | %| Each callback subfunction declaration has the following form: |
---|
93 | %| <SUBFUNCTION_NAME>(H, EVENTDATA, HANDLES, VARARGIN) |
---|
94 | %| |
---|
95 | %| The subfunction name is composed using the object's Tag and the |
---|
96 | %| callback type separated by '_', e.g. 'slider2_Callback', |
---|
97 | %| 'figure1_CloseRequestFcn', 'axis1_ButtondownFcn'. |
---|
98 | %| |
---|
99 | %| H is the callback object's handle (obtained using GCBO). |
---|
100 | %| |
---|
101 | %| EVENTDATA is empty, but reserved for future use. |
---|
102 | %| |
---|
103 | %| HANDLES is a structure containing handles of components in GUI using |
---|
104 | %| tags as fieldnames, e.g. handles.figure1, handles.slider2. This |
---|
105 | %| structure is created at GUI startup using GUIHANDLES and stored in |
---|
106 | %| the figure's application data using GUIDATA. A copy of the structure |
---|
107 | %| is passed to each callback. You can store additional information in |
---|
108 | %| this structure at GUI startup, and you can change the structure |
---|
109 | %| during callbacks. Call guidata(h, handles) after changing your |
---|
110 | %| copy to replace the stored original so that subsequent callbacks see |
---|
111 | %| the updates. Type "help guihandles" and "help guidata" for more |
---|
112 | %| information. |
---|
113 | %| |
---|
114 | %| VARARGIN contains any extra arguments you have passed to the |
---|
115 | %| callback. Specify the extra arguments by editing the callback |
---|
116 | %| property in the inspector. By default, GUIDE sets the property to: |
---|
117 | %| <MFILENAME>('<SUBFUNCTION_NAME>', gcbo, [], guidata(gcbo)) |
---|
118 | %| Add any extra arguments after the last argument, before the final |
---|
119 | %| closing parenthesis. |
---|
120 | |
---|
121 | |
---|
122 | |
---|
123 | % -------------------------------------------------------------------- |
---|
124 | function varargout = close_button_Callback(h, eventdata, handles, varargin) |
---|
125 | % Stub for Callback of the uicontrol handles.close_button. |
---|
126 | %Stub for Callback of the uicontrol handles.close_button. |
---|
127 | % |
---|
128 | % Obtaining the Figure Handle from Within a Callback. In general, dismissing a modal figure requires the handle |
---|
129 | % of the figure. Since most GUIs hide figure handles to prevent accidental access, the gcbf (get callback figure) |
---|
130 | % command provides the most effective method to get the figure handle from within a callback routine. |
---|
131 | % |
---|
132 | % gcbf returns the handle of the figure containing the object whose callback is executing. This enables you to use |
---|
133 | % gcbf in the callback of the component that will dismiss the dialog. For example, suppose your dialog includes a |
---|
134 | % push button (tagged pushbutton1) that closes the dialog. Its callback could include a call to delete at the end of |
---|
135 | % its callback subfunction. |
---|
136 | |
---|
137 | disp('closing'); |
---|
138 | % F_param_out.no_samp = handles.no_samp; |
---|
139 | % F_param_out.threshold = handles.threshold; |
---|
140 | % F_param_out.corner_width = handles.corner_width; |
---|
141 | |
---|
142 | uiresume(handles.figure1); |
---|
143 | |
---|
144 | |
---|
145 | |
---|
146 | % -------------------------------------------------------------------- |
---|
147 | function varargout = T_button_Callback(h, eventdata, handles, varargin) |
---|
148 | nc = str2num(get(handles.T_button, 'String')); |
---|
149 | minnc = 0; |
---|
150 | maxnc = 20; |
---|
151 | if (isempty(nc) | (nc <= minnc) | (nc >maxnc)) |
---|
152 | nc = handles.threshold; |
---|
153 | WARNDLG(['out of range' num2str(minnc) '-' num2str(maxnc)],'ooops') |
---|
154 | end; |
---|
155 | handles.threshold = nc; |
---|
156 | set(handles.T_button, 'String', num2str(handles.threshold)); |
---|
157 | |
---|
158 | %save data |
---|
159 | guidata(handles.figure1, handles); |
---|
160 | |
---|
161 | % -------------------------------------------------------------------- |
---|
162 | function varargout = number_samples_button_Callback(h, eventdata, handles, varargin) |
---|
163 | % Stub for Callback of the uicontrol handles.number_samples_button. |
---|
164 | nc = str2num(get(handles.number_samples_button, 'String')); |
---|
165 | |
---|
166 | minnc = 10; |
---|
167 | maxnc = 10000; |
---|
168 | if (isempty(nc) | (nc < minnc) | (nc >maxnc)) |
---|
169 | nc = handles.no_samp; |
---|
170 | WARNDLG(['out of range' num2str(minnc) '-' num2str(maxnc)],'ooops') |
---|
171 | end; |
---|
172 | handles.no_samp = nc; |
---|
173 | set(handles.number_samples_button, 'String', num2str(handles.no_samp)); |
---|
174 | |
---|
175 | %save data |
---|
176 | guidata(handles.figure1, handles); |
---|
177 | |
---|
178 | |
---|
179 | |
---|
180 | |
---|
181 | % -------------------------------------------------------------------- |
---|
182 | function varargout = text3_Callback(h, eventdata, handles, varargin) |
---|
183 | % Stub for Callback of the uicontrol handles.text3. |
---|
184 | disp('text3 Callback not implemented yet.') |
---|