www.gusucode.com > mbcview 工具箱matlab源码程序 > mbcview/@cgdatasetnode/private/selectbox.m
function selectbox(src,ev,nd,cb) %SELECTBOX % Copyright 2000-2013 The MathWorks, Inc. and Ford Global Technologies, Inc. ax = src; hFig = ancestor(ax, 'figure'); seltype=get(hFig,'SelectionType'); switch seltype case 'normal' i_zoom(ax, cb); case {'open','extend'} mv_zoom; end %---------------------------------------------------------- % function i_zoom %---------------------------------------------------------- function i_zoom(myax, cb) % get the axes position and oldunits=get(myax,'Units'); set(myax,'Units','pixels'); apos=get(myax,'Position'); set(myax,'Units',oldunits); xlim=get(myax,'XLim'); xlen=xlim(2)-xlim(1); ylim=get(myax,'YLim'); ylen=ylim(2)-ylim(1); % get ratios to convert pt to pixel units. xratio=xlen/apos(3); yratio=ylen/apos(4); % check for a shift in x or y xshift=(0-xlim(1)); yshift=(0-ylim(1)); F = ancestor(myax, 'figure'); pt = get(F, 'CurrentPoint'); % draw the rubber band box frect=rbbox([pt(1) pt(2) 0 0 ]); % Convert into the axes coordinates frect(1:2) = mbcgui.util.convertLocation(frect(1:2), myax); newxlim=sort(([frect(1) frect(1)+frect(3)]).*xratio)-xshift; newylim=sort(([frect(2) frect(2)+frect(4)]).*yratio)-yshift; % Ensure box remains within axis newxlim(2) = min(newxlim(2),xlim(2)); newxlim(1) = max(newxlim(1),xlim(1)); newylim(2) = min(newylim(2),ylim(2)); newylim(1) = max(newylim(1),ylim(1)); if diff(newxlim)>0 && diff(newylim)>0 % update the axes limits if iscell(cb) xregcallback(cb) else xregcallback({cb,newxlim,newylim}); end end