www.gusucode.com > mbcview 工具箱matlab源码程序 > mbcview/@cgtools/@cgsurfacedragger/pButtonDown.m
function pButtonDown(h) %PBUTTONDOWNFCN Private method, called in response to a click on the surface % Copyright 2000-2013 The MathWorks, Inc. and Ford Global Technologies, Inc. ax = h.Parent; fig = ancestor(ax,'figure'); pt = get(ax,'CurrentPoint'); v = get(ax,'View'); if mod(v(2),180)==90 % Dragging can't be done if the view is from above/below return end intersection = pClosestPoint(h, pt); % If no intersection was found, there can be no dragging. if isempty(intersection) return end r = intersection.yidx; c = intersection.xidx; % If there is a lock matrix, and this point is locked, don't allow dragging. locks = h.LockData; if ~isempty(locks) && locks(r,c) == 1 return end data = h.ZData; S.DragIndices = [r c]; S.DragValue = data(r,c); S.StartValue = data(r,c); % Make picker line visible MaxLim = max(abs(get(ax,'ZLim'))); R = 1000*MaxLim; set(h.PickerHandle, ... 'XData', [intersection.x intersection.x], ... 'YData', [intersection.y intersection.y], ... 'ZData', get(ax,'ZLim'), ... 'Visible', 'on'); S.PickerHandle = h.PickerHandle; % Change mouse pointer PR = xregGui.PointerRepository; S.PtrID = PR.stackSetPointer(fig, 'top'); DragDataPtr = xregGui.RunTimePointer(S); % Notify the listeners. evtdata = struct('DragIndex', S.DragIndices, 'DragValue', data(r,c)); send(h, 'PointGrab', xregGui.xregEventData(h, 'PointGrab', evtdata)); % Grab exclusive use of motion in the window 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; P = vertexpicker(S.PickerHandle, '-force'); if ~isempty(P) zpoint = P(3); else zpoint = S.StartValue; end S.DragValue = zpoint; DragDataPtr.info = S; dragindices = S.DragIndices; % Update surface zdata = h.ZData; zdata(dragindices(1),dragindices(2)) = zpoint; h.ZData = zdata; % Send a drag event evtdata = struct('DragIndex', dragindices, 'DragValue', zpoint); 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.DragIndices, 'NewValue', S.DragValue); send(h,'Update',xregGui.xregEventData(h, 'Update', evtdata));