function buttonMotion(src, evnt)
% buttonMotion
%   button motion callback

%   Project: IMPACT
%   Title of Code: buttonMotion
%   Relevant additional documentation:
%   Developer: Carlos Gonzalez
%   External Dependencies: NA
%
%   Disclaimer
%   CAUTION: It is strongly recommended that changes to this code
%   should be avoided without first consulting with authors.


handles = guidata(src);
% crossover frequency dialog is open
if gcf~=handles.hFig
    return;
end
   
hAx = gca;
pt = get(hAx, 'CurrentPoint');
ptX = pt(1,1);
ptY = pt(1,2);

hMag = handles.hMag;
hPhase = handles.hPhase;

str = handles.Tb.selected;
switch str
    case 'arrow'
        
    case {'pole', 'zero', 'comPole', 'comZero', 'eraser', 'zoomOut'}
    case 'zoomIn'
        ZoomIn = handles.Tb.ZoomIn;
        if strcmp(ZoomIn.status, 'off')
            return;
        end
        hLine = ZoomIn.hLine;
        downPoint = handles.Tb.ZoomIn.downPoint;
        drawLine(downPoint, [ptX, ptY], hLine);
    case 'hand'
        Hand = handles.Tb.Hand;
        if strcmp(Hand.zpk, '')
            return;
        end
        yLim = get(handles.hMag(1), 'YLim');
        set(handles.hMag(1), 'YLim', yLim);
        changeZPK(Hand, [ptX, ptY], handles);
end


function drawLine(downPoint, pt, hLine)
% draw rectangle for zoom in

minX = min(downPoint(1), pt(1));
maxX = max(downPoint(1), pt(1));
minY = min(downPoint(2), pt(2));
maxY = max(downPoint(2), pt(2));
set(hLine(1), 'XData', [minX, minX], 'YData', [minY, maxY]);
set(hLine(2), 'XData', [minX, maxX], 'YData', [minY, minY]);
set(hLine(3), 'XData', [minX, maxX], 'YData', [maxY, maxY]);
set(hLine(4), 'XData', [maxX, maxX], 'YData', [minY, maxY]);

