0001 function [out1,out2,out3] = ginput(arg1)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029 out1 = []; out2 = []; out3 = []; y = [];
0030 c = computer;
0031 if ~strcmp(c(1:2),'PC')
0032 tp = get(0,'TerminalProtocol');
0033 else
0034 tp = 'micro';
0035 end
0036
0037 if ~strcmp(tp,'none') && ~strcmp(tp,'x') && ~strcmp(tp,'micro'),
0038 if nargout == 1,
0039 if nargin == 1,
0040 out1 = trmginput(arg1);
0041 else
0042 out1 = trmginput;
0043 end
0044 elseif nargout == 2 || nargout == 0,
0045 if nargin == 1,
0046 [out1,out2] = trmginput(arg1);
0047 else
0048 [out1,out2] = trmginput;
0049 end
0050 if nargout == 0
0051 out1 = [ out1 out2 ];
0052 end
0053 elseif nargout == 3,
0054 if nargin == 1,
0055 [out1,out2,out3] = trmginput(arg1);
0056 else
0057 [out1,out2,out3] = trmginput;
0058 end
0059 end
0060 else
0061
0062 fig = gcf;
0063 figure(gcf);
0064
0065 if nargin == 0
0066 how_many = -1;
0067 b = [];
0068 else
0069 how_many = arg1;
0070 b = [];
0071 if ischar(how_many) ...
0072 || size(how_many,1) ~= 1 || size(how_many,2) ~= 1 ...
0073 || ~(fix(how_many) == how_many) ...
0074 || how_many < 0
0075 error('MATLAB:ginput:NeedPositiveInt', 'Requires a positive integer.')
0076 end
0077 if how_many == 0
0078 ptr_fig = 0;
0079 while(ptr_fig ~= fig)
0080 ptr_fig = get(0,'PointerWindow');
0081 end
0082 scrn_pt = get(0,'PointerLocation');
0083 loc = get(fig,'Position');
0084 pt = [scrn_pt(1) - loc(1), scrn_pt(2) - loc(2)];
0085 out1 = pt(1); y = pt(2);
0086 elseif how_many < 0
0087 error('MATLAB:ginput:InvalidArgument', 'Argument must be a positive integer.')
0088 end
0089 end
0090
0091
0092 state = uisuspend(fig);
0093
0094 toolbar = findobj(allchild(fig),'flat','Type','uitoolbar');
0095 if ~isempty(toolbar)
0096 ptButtons = [uigettool(toolbar,'Plottools.PlottoolsOff'), ...
0097 uigettool(toolbar,'Plottools.PlottoolsOn')];
0098 ptState = get (ptButtons,'Enable');
0099 set (ptButtons,'Enable','off');
0100 end
0101
0102 set(fig,'pointer','fullcrosshair');
0103 fig_units = get(fig,'units');
0104 char = 0;
0105
0106
0107
0108 drawnow
0109
0110 while how_many ~= 0
0111
0112 waserr = 0;
0113 try
0114 keydown = wfbp;
0115 catch
0116 waserr = 1;
0117 end
0118 if(waserr == 1)
0119 if(ishghandle(fig))
0120 set(fig,'units',fig_units);
0121 uirestore(state);
0122 error('MATLAB:ginput:Interrupted', 'Interrupted');
0123 else
0124 error('MATLAB:ginput:FigureDeletionPause', 'Interrupted by figure deletion');
0125 end
0126 end
0127
0128
0129
0130 figchildren = allchild(0);
0131 if ~isempty(figchildren)
0132 ptr_fig = figchildren(1);
0133 else
0134 error('MATLAB:ginput:FigureUnavailable','No figure available to process a mouse/key event');
0135 end
0136
0137
0138 if(ptr_fig == fig)
0139 if keydown
0140 char = get(fig, 'CurrentCharacter');
0141 button = abs(get(fig, 'CurrentCharacter'));
0142 scrn_pt = get(0, 'PointerLocation');
0143 set(fig,'units','pixels')
0144 loc = get(fig, 'Position');
0145
0146 pt = [scrn_pt(1) - loc(1) + 1, scrn_pt(2) - loc(2) + 1];
0147 set(fig,'CurrentPoint',pt);
0148 else
0149 button = get(fig, 'SelectionType');
0150 if strcmp(button,'open')
0151 button = 1;
0152 elseif strcmp(button,'normal')
0153 button = 1;
0154 elseif strcmp(button,'extend')
0155 button = 2;
0156 elseif strcmp(button,'alt')
0157 button = 3;
0158 else
0159 error('MATLAB:ginput:InvalidSelection', 'Invalid mouse selection.')
0160 end
0161 end
0162 pt = get(gca, 'CurrentPoint');
0163
0164 how_many = how_many - 1;
0165
0166 if(char == 13)
0167
0168
0169
0170
0171
0172
0173
0174 break;
0175 end
0176
0177 out1 = [out1;pt(1,1)];
0178 y = [y;pt(1,2)];
0179 b = [b;button];
0180 end
0181 end
0182
0183 uirestore(state);
0184 if ~isempty(toolbar) && ~isempty(ptButtons)
0185 set (ptButtons(1),'Enable',ptState{1});
0186 set (ptButtons(2),'Enable',ptState{2});
0187 end
0188 set(fig,'units',fig_units);
0189
0190 if nargout > 1
0191 out2 = y;
0192 if nargout > 2
0193 out3 = b;
0194 end
0195 else
0196 out1 = [out1 y];
0197 end
0198
0199 end
0200
0201
0202 function key = wfbp
0203
0204
0205 fig = gcf;
0206 current_char = [];
0207
0208
0209 waserr = 0;
0210 try
0211 h=findall(fig,'type','uimenu','accel','C');
0212 set(h,'accel','');
0213 keydown = waitforbuttonpress;
0214 current_char = double(get(fig,'CurrentCharacter'));
0215 if~isempty(current_char) && (keydown == 1)
0216 if(current_char == 3)
0217 waserr = 1;
0218 end
0219 end
0220
0221 set(h,'accel','C');
0222 catch
0223 waserr = 1;
0224 end
0225 drawnow;
0226 if(waserr == 1)
0227 set(h,'accel','C');
0228 error('MATLAB:ginput:Interrupted', 'Interrupted');
0229 end
0230
0231 if nargout>0, key = keydown; end
0232