www.gusucode.com > mbcguitools 工具箱 matlab 源码程序 > mbcguitools/@xregGui/@scrollaxes/doZoom.m

    function doZoom(h)
% Set up zooming on scroll axes.

%  Copyright 2000-2010 The MathWorks, Inc. and Ford Global Technologies, Inc.


switch h.ZoomMode
    case 'off'
        % Zoom is off
        % unset ButtonDownFcn
        set(h.AxesHandle, 'ButtonDownFcn', '', 'HitTest', 'off');
    case {'x', 'y'}
        % Zoom is x or y
        % set ButtonDownFcn
        set(h.AxesHandle, 'ButtonDownFcn',{@i_zoom, h, h.AxesHandle}, 'HitTest', 'on');
end



function i_zoom(src,evt, h, hAx)
% funnel function for button down events

seltype= get(ancestor(hAx, 'figure'),'SelectionType');

switch seltype
    case 'open'
        i_restore(h, hAx);
    case 'extend'
        % first make sure that there is no other
        % button down function defined
        set(ancestor(hAx, 'figure'), ...
            'WindowButtonDownFcn','',...
            'WindowButtonUpFcn','');
        i_dozoom(h, hAx);
end


function i_dozoom(h, hAx)
% zooms in

% First check to see if there are any text objects...
tH=findobj(hAx,'Type','text','Clipping','off');

% and clip all of them
set(tH,'Clipping','on');

% draw the line
newlim = xregrbline(h.ZoomMode, [],hAx);

% get axes position.
axesPos = get(hAx, 'Position');

switch lower(h.ZoomMode)
    
    case 'x'
        newxlim = newlim;
        if diff(newxlim)>0
            axesW = axesPos(3)-axesPos(1);
            LimDelta  = newxlim(2)-newxlim(1);
            dataperpix = LimDelta/axesW;
            h.Xdataperpixel = dataperpix;
            h.Xviewpos = mean(newxlim);
        end
        
    case 'y'
        newylim = newlim;
        if diff(newylim)>0
            axesW = axesPos(4)-axesPos(2);
            LimDelta  = newylim(2)-newylim(1);
            dataperpix = LimDelta/axesW;
            h.Ydataperpixel = dataperpix;
            h.Yviewpos = mean(newylim);
        end
end


function i_restore(h, hAx)
% zooms out

% get axes position.
axesPos =  get(hAx, 'Position');

% re-calc limits and set
switch h.ZoomMode
    
    case 'x'
        h.Xdataperpixel = diff(h.xlim)/(axesPos(3)-axesPos(1));
    case 'y'
        h.Ydataperpixel = diff(h.ylim)/(axesPos(4)-axesPos(2));
end