www.gusucode.com > mbcview 工具箱matlab源码程序 > mbcview/@cgtradeoffgui/@tradeoffGraphView/pStartValueDrag.m
function pStartValueDrag(obj, hAxes) %PSTARTVALUEDRAG Instruct object to initiate a value-line drag % % PSTARTVALUEDRAG(OBJ, HAXES) is called by the cell objects when the user % tries to drag the value line. HAXES is the handle to the actual axes % that the dragging is initiated in and this provides the current value of % the pointer location. % Copyright 2000-2010 The MathWorks, Inc. and Ford Global Technologies, Inc. % First of all hook up the buttonup function data = struct('Axes', hAxes, ... 'StillRunning', true, ... 'Object', obj, ... 'Column', 0, ... 'Offset', 0, ... 'MinValue', 0, ... 'MaxValue',1, ... 'HeaderObject', [], ... 'CellObjects', [], ... 'DragPointerID', 0); pInfo = xregGui.RunTimePointer(data); bm = xregGui.ButtonUpManager(obj.Parent); bm.getNextEvent({@i_end_drag, pInfo}); % Now update selection obj.pPerformClick; % Now set up the dragging dm = obj.hDataModel; hTable = obj.hGraphTable; data = pInfo.info; data.Column = dm.SelectedColumn; % Get the initial offset of the click from the current value xval = get(data.Axes, 'CurrentPoint'); xval = xval(1,1); data.Offset = dm.ColumnItemValues(data.Column) - xval; % Get the cell and header objects that need to be updated during the drag C = dm.SelectedColumn - hTable.CurrentColumn + 1; data.HeaderObject = hTable.ColumnHeaderObjects(C); data.CellObjects = hTable.MainObjects( ... ~dm.IsBlank(hTable.CurrentRow:hTable.CurrentRow+size(hTable.MainObjects,1)-1, data.Column), ... C); % Limit the dragging to the current visible limits of the graph Lims = dm.getGraphXLimits(dm.SelectedRow, data.Column); data.MinValue = Lims(1); data.MaxValue = Lims(2); pInfo.info = data; if data.StillRunning PR = xregGui.PointerRepository; data.DragPointerID = PR.stackSetPointer(obj.Parent, 'lrdrag'); pInfo.info = data; set(ancestor(obj.Parent,'figure'), 'WindowButtonMotionFcn', {@i_motion, pInfo}); else i_end_drag([], [], pInfo); end function i_end_drag(src, evt, pInfo) % Set a flag that will prevent a motion function from being subsequently % set data = pInfo.info; data.StillRunning = false; pInfo.info = data; if data.Column>0 obj = data.Object; set(ancestor(obj.Parent,'figure'), 'WindowButtonMotionFcn', ''); % capture final point value and update object xval = get(data.Axes, 'CurrentPoint'); xval = xval(1,1) + data.Offset; if xval<data.MinValue xval = data.MinValue; end if xval>data.MaxValue xval = data.MaxValue; end obj.pSetValue(data.Column, xval); PR = xregGui.PointerRepository; PR.stackRemovePointer(obj.Parent, data.DragPointerID); end function i_motion(src, evt, pInfo) data = pInfo.info; if data.StillRunning % Get current point in axes and limit it xval = get(data.Axes, 'CurrentPoint'); xval = xval(1,1) + data.Offset; if xval<data.MinValue xval = data.MinValue; end if xval>data.MaxValue xval = data.MaxValue; end % Set all objects in the column to have correct value data.HeaderObject.setInputValue(xval); for n = 1:length(data.CellObjects) data.CellObjects(n).setInputValue(xval); end end