www.gusucode.com > mbcguitools 工具箱 matlab 源码程序 > mbcguitools/@xregGui/@figureaxes/convertPosToFigure.m

    function Pos = convertPosToFigure(Pos, hComp)
%CONVERTPOSTOFIGURE Convert a position rectangle to figure coordinates
%
%   Pos = convertPosToFigure(Pos, hComp) converts a position rectangle from
%   the coordinate system of hComp to that of the figure.  It is assumed
%   that the position is in pixel coordinates.

%  Copyright 2000-2013 The MathWorks, Inc.


if isgraphics(hComp, 'figure')
    % The input position is already in the figure coordinates
    return
end

% Convert position rectangle from local coordinates to figure coordinates.
DestPos = getpixelposition(hComp, true);
Pos(1:2) = Pos(1:2)+DestPos(1:2)-1;

% Adjust for panel edge widths
Delta = iGetPanelBorderDelta(hComp);
Pos(1:2) = Pos(1:2)+Delta;


function Delta = iGetPanelBorderDelta(hObj)
Delta = 0;
hFig = ancestor(hObj, 'figure');
while hObj~=hFig
    if isgraphics(hObj, 'uipanel')
        W = mbcgui.util.getPanelBorderWidth(hObj);
        Delta = Delta + W;
    end 
    hObj = get(hObj, 'Parent'); 
end