www.gusucode.com > mbcguitools 工具箱 matlab 源码程序 > mbcguitools/@xregGui/@axisslider/doDrawMarker.m
function doDrawMarker(h) %DODRAWMARKER Redraw the value marker % % DODRAWMARKER(OBJ) redraws the value marker on the axis % Copyright 2000-2010 The MathWorks, Inc. and Ford Global Technologies, Inc. val = h.Value; if isnan(val) set(h.Marker, 'Visible','off'); if strcmp(h.Orientation, 'vertical') mbcxlabel(h.Axes, ''); mbcylabel(h.Axes, h.String); else mbcxlabel(h.Axes, h.String); mbcylabel(h.Axes, ''); end else % The figure units are pixels, and the % size of the axes is 1 pixel in the "minor" direction. The % limits of the axes are the same in both directions. pos = h.position; lims = get(h.Axes, 'XLim'); % same as "ylim" % This is the value at which the marker is to be positioned. val = min(max(h.Value,lims(1)),lims(2)); vert = zeros(3,3); hw = h.MarkerSize; % in pixels (in the "minor" direction) rng = lims(2)-lims(1); % slider range if strcmp(h.Orientation, 'vertical') axissize = max(pos(4),1); % size, in pixels of the axes in the "major" direction % In the "major" direction, the marker extends "MarkerSize" pixels % in either direction. Calculate this in axis units. markerdelta_major = (hw/axissize)*rng; % Same as above, except that we know the axis size in this direction is 1 pixel markerdelta_minor = hw*rng; % One vertex at the current value vert(1, 1) = lims(2); vert(1, 2) = val; % One vertext up and to the right vert(2, 1) = lims(2) + markerdelta_minor; vert(2, 2) = val + markerdelta_major; % One vertext down and to the right vert(3, 1) = vert(2, 1); vert(3, 2) = val - markerdelta_major; else % See explanation above axissize = max(pos(3),1); markerdelta_major = (hw/axissize)*rng; markerdelta_minor = hw*rng; vert(1, 1) = val; vert(1, 2) = lims(1); vert(2, 1) = val + markerdelta_major; vert(2, 2) = lims(1)+ markerdelta_minor; vert(3, 1) = val - markerdelta_major; vert(3, 2) = vert(2, 2); end % Patch has only one face, joining the three vertices. set(h.Marker, 'Vertices', vert, 'Faces', [1 2 3], 'Visible', h.visible); end