www.gusucode.com > mbcguitools 工具箱 matlab 源码程序 > mbcguitools/@xregGui/@javaToolbar/pMouseMove.m
function pMouseMove(obj, xPos) %PMOUSEMOVE Execute mouse position change actions % % PMOUSEMOVE(OBJ, XPOS) performs the actions that are required whenever % the mouse pointer moves within the toolbar region. % Copyright 2000-2005 The MathWorks, Inc. and Ford Global Technologies, Inc. if obj.MousePressed % Item index cannot be altered while mouse is down. We just need to % work out whether the mouse is over the current button or not CurrentIndex = obj.CurrentButtonIndex; if CurrentIndex>0 overBtn = (xPos>=obj.ButtonEdges(CurrentIndex,1)) ... && (xPos<=obj.ButtonEdges(CurrentIndex,2)); if overBtn~=obj.MousePressedAndOverButton % Need to update the image im_int = obj.pGetCurrentImage; imdata = obj.hColors.convertToRGBTriplet( ... im_int(:, obj.ButtonEdges(CurrentIndex,1):obj.ButtonEdges(CurrentIndex,2))); obj.pCleanCanvas(imdata, 1, -1, obj.hColors.CTRL_BACK); obj.CurrentButton.pDrawButton(imdata, 1, 1, ... size(imdata,2), obj.pGetImageHeight, overBtn, true); obj.hJavaImage.Peer.setImageSection(obj.ButtonEdges(CurrentIndex,1), ... obj.hColors.convertToIRGB(imdata)); obj.MousePressedAndOverButton = overBtn; end end else % Normal mouse movement across toolbar if isempty(obj.ButtonEdges) ... || xPos < obj.ButtonEdges(1,1) || xPos > obj.ButtonEdges(end,2) newItemIdx = 0; else newItemIdx = find(xPos<=obj.ButtonEdges(:,2), 1,'first'); if isempty(newItemIdx) ... || xPos<obj.ButtonEdges(newItemIdx,1) ... || newItemIdx>obj.NButtonsToRender newItemIdx = 0; end end oldItemIdx = obj.CurrentButtonIndex; if newItemIdx~=oldItemIdx % Redraw the old and new buttons jT = obj.hJavaImage.Peer; hC = obj.hColors; if oldItemIdx~=0 && oldItemIdx<=obj.NButtonsToRender start1 = obj.ButtonEdges(oldItemIdx,1); im_int = jT.getImageSection(start1, obj.ButtonEdges(oldItemIdx,2)); imdata1 = hC.convertToRGBTriplet(im_int); obj.CurrentButton.pDrawMouseOver(imdata1, 1, 1, ... size(imdata1,2), obj.pGetImageHeight, false, false); else imdata1 = zeros(0,0,3,'uint8'); start1 = 0; end obj.pSetCurrentButton(newItemIdx); hCB = obj.CurrentButton; if newItemIdx~=0 start2 = obj.ButtonEdges(newItemIdx,1); im_int = jT.getImageSection(start2, obj.ButtonEdges(newItemIdx,2)); imdata2 = hC.convertToRGBTriplet(im_int); hCB.pDrawMouseOver(imdata2, 1, 1, ... size(imdata2,2), obj.pGetImageHeight, true, false); else imdata2 = zeros(0,0,3,'uint8'); start2 = 0; end if start1~=0 || start2~=0 jT.setDualImageSection( ... start1, hC.convertToIRGB(imdata1), ... start2, hC.convertToIRGB(imdata2)); end if newItemIdx~=0 % Set up for a tooltip jT.setTooltip(hCB.TooltipString); % Set button-down dispatching mode to match button's interruptible % setting %set(jT, 'Interruptible', hCB.Interruptible); else jT.setTooltip(''); end end end