0001 function [out_regs] = zinput(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 ax0 = axis;
0027 out_regs = [];
0028 c = computer;
0029 if ~strcmp(c(1:2),'PC')
0030 tp = get(0,'TerminalProtocol');
0031 else
0032 tp = 'micro';
0033 end
0034
0035 if ~strcmp(tp,'none') & ~strcmp(tp,'x') & ~strcmp(tp,'micro') & 0,
0036
0037
0038 else
0039
0040 fig = gcf;
0041 figure(gcf);
0042
0043 if nargin == 0
0044 how_many = inf;
0045 b = [];
0046 else
0047 how_many = arg1;
0048 b = [];
0049 if isstr(how_many) ...
0050 | size(how_many,1) ~= 1 | size(how_many,2) ~= 1 ...
0051 | ~(fix(how_many) == how_many) ...
0052 | how_many < 0
0053 error('Requires a positive integer.');
0054 end
0055 if how_many == 0
0056 ptr_fig = 0;
0057 while(ptr_fig ~= fig)
0058 ptr_fig = get(0,'PointerWindow');
0059 end
0060 scrn_pt = get(0,'PointerLocation');
0061 loc = get(fig,'Position');
0062 pt = [scrn_pt(1) - loc(1), scrn_pt(2) - loc(2)];
0063 out1 = pt(1); y = pt(2);
0064 elseif how_many < 0
0065 error('Argument must be a positive integer.');
0066 end
0067 end
0068
0069
0070 state = uisuspend(fig);
0071 pointer = get(gcf,'pointer');
0072 set(gcf,'pointer','fullcrosshair');
0073
0074 fig_units = get(fig,'units');
0075 char = 0;
0076 while size(out_regs,1) < how_many
0077
0078 waserr = 0;
0079 try
0080 keydown = wfbp;
0081 catch
0082 waserr = 1;
0083 end
0084 if(waserr == 1)
0085 if(ishandle(fig))
0086 set(fig,'units',fig_units);
0087 uirestore(state);
0088 error('Interrupted');
0089 else
0090 error('Interrupted by figure deletion');
0091 end
0092 end
0093
0094 ptr_fig = get(0,'CurrentFigure');
0095 if(ptr_fig == fig)
0096 if keydown
0097 axis(ax0);
0098 char = get(fig, 'CurrentCharacter');
0099 else
0100 char = get(fig, 'CurrentCharacter');
0101 button = abs(get(fig, 'CurrentCharacter'));
0102
0103 pnt = get(gcf,'currentpoint');
0104 xy1 = get(gca,'currentpoint');
0105 rbbox([pnt 0 0],pnt)
0106 xy2 = get(gca,'currentpoint');
0107 selection_type = get(gcf,'selectiontype');
0108
0109 if all(xy1==xy2)
0110 ax1 = axis;
0111
0112 dx = abs(ax1(2)-ax1(1));
0113 dy = abs(ax1(4)-ax1(3));
0114
0115 xmin = max(ax1(1),xy1(1)-dx/4);
0116 xmax = min(ax1(2),xy1(1)+dx/4);
0117 ymin = max(ax1(3),xy1(1,2)-dy/4);
0118 ymax = min(ax1(4),xy1(1,2)+dy/4);
0119 zoom2ax = [xmin xmax ymin ymax];
0120 else
0121
0122 zoom2ax = [sort([xy1(1,1) xy2(1,1)]) sort([xy1(1,2) xy2(1,2)])];
0123 end
0124
0125 switch selection_type
0126 case 'normal'
0127 axis(zoom2ax)
0128 reg = [];
0129 case 'alt'
0130 reg = axis;
0131 axis(ax0)
0132 case 'extend'
0133 reg = xy1(1,[1 1 2 2]);
0134 axis(ax0)
0135 otherwise
0136 axis(ax0);
0137 reg = [];
0138 end
0139 end
0140 pt = get(gca, 'CurrentPoint');
0141
0142 if (char == 'r')
0143 rmi = size(out_regs,1);
0144 if rmi > 0
0145 out_regs(rmi,:) = [];
0146 end
0147 set(fig, 'CurrentCharacter','q')
0148 char = 'q';
0149 reg = [];
0150 end
0151 if(char == 13)
0152
0153
0154
0155
0156
0157
0158
0159 break;
0160 end
0161
0162 if ~isempty(reg)
0163 out_regs = [out_regs;reg];
0164 end
0165 end
0166
0167 end
0168
0169 uirestore(state);
0170 set(gcf,'pointer','arrow');
0171 set(fig,'units',fig_units);
0172 set(fig, 'CurrentCharacter','q');
0173
0174 end
0175
0176
0177 function key = wfbp
0178
0179
0180 fig = gcf;
0181 current_char = [];
0182
0183
0184 waserr = 0;
0185 try
0186 h=findall(fig,'type','uimenu','accel','C');
0187 set(h,'accel','');
0188 keydown = waitforbuttonpress;
0189 current_char = double(get(fig,'CurrentCharacter'));
0190 if~isempty(current_char) & (keydown == 1)
0191 if(current_char == 3)
0192 waserr = 1;
0193 end
0194 end
0195
0196 set(h,'accel','C');
0197 catch
0198 waserr = 1;
0199 end
0200 drawnow;
0201 if(waserr == 1)
0202 set(h,'accel','C');
0203 error('Interrupted');
0204 end
0205
0206 selection_type = get(gcf,'selectiontype');
0207 if strcmp(selection_type,'open')
0208 axis(ax0)
0209 end
0210 if nargout>0, key = keydown; end
0211