www.gusucode.com > mbcview 工具箱matlab源码程序 > mbcview/@cgtools/@cglinedragger/pButtonDown.m
function pButtonDown(h) %PBUTTONDOWNFCN Private method that iscalled when the user clicks on the line. % Copyright 2000-2010 The MathWorks, Inc. and Ford Global Technologies, Inc. ax = h.Parent; fig = ancestor(ax,'figure'); % find the nearest point cp = get(ax,'CurrentPoint'); [unused, vertpoint] = vertexpicker(h.LineHandle, cp, '-force'); [unused, I] = min(abs(vertpoint(1)-h.xdata)); if isempty(I) || (~isempty(h.LockData) && h.LockData(I)==1) % No point, or point is locked return end ypoint = h.ydata(I); xpoint = h.xdata(I); S.DragIndex = I; S.DragValue = ypoint; S.offset = ypoint - cp(1,2); % Display picker line and change mouse icon set(h.PickerHandle, ... 'XData', [xpoint xpoint], ... 'YData', get(ax, 'YLim'), ... 'ZData', [-1 -1], ... 'Visible', 'on'); PR = xregGui.PointerRepository; S.PtrID = PR.stackSetPointer(fig, 'top'); S.PickerHandle = h.PickerHandle; DragDataPtr = xregGui.RunTimePointer(S); % Send point grab event evtdata = struct('DragIndex', I, 'DragValue', ypoint); send(h,'PointGrab',xregGui.xregEventData(h,'PointGrab', evtdata)); % Grab exclusive control of the Window motion function set(fig,'WindowButtonMotionFcn', {@i_Motion, h, DragDataPtr}); % Get following button-up event bm = xregGui.ButtonUpManager(fig); bm.getNextEvent({@i_ButtonUp, h, DragDataPtr}); function i_Motion(src, evt, h, DragDataPtr) S = DragDataPtr.info; cp = get(h.Parent,'CurrentPoint'); ymouse = cp(1,2); ydrag = ymouse + S.offset; S.DragValue = ydrag; DragDataPtr.info = S; % Update YData of line ydata = h.YData; ydata(S.DragIndex) = ydrag; h.YData = ydata; % Send a drag event evtdata = struct('DragIndex', S.DragIndex, 'DragValue', ydrag); send(h,'PointDrag',xregGui.xregEventData(h,'PointDrag', evtdata)); function i_ButtonUp(src, evt, h, DragDataPtr) ax = h.Parent; fig = ancestor(ax,'figure'); S = DragDataPtr.info; % Remove motion function set(fig,'WindowButtonMotionFcn',''); % Re-set pointer and remove picker line PR = xregGui.PointerRepository; PR.stackRemovePointer(fig, S.PtrID); set(S.PickerHandle, 'Visible', 'off'); % Send upate event evtdata = struct('ChangedIndex', S.DragIndex, 'NewValue', S.DragValue); send(h,'Update',xregGui.xregEventData(h, 'Update', evtdata));