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