#include "StdAfx.h" #include "URect.h" /*static*/ void URect::SetEmpty(RECT& outRect) { ::SetRect(&outRect, 0, 0, 0, 0); } /*static*/ void URect::Center(const RECT& inRect, RECT& ioRect, BOOL inFlag) { #pragma var_order(yOffset, xRatio, xOffset, ratio, width1, height1, yRatio, width2, height2) int width1 = Width(inRect); int height1 = Height(inRect); int width2 = Width(ioRect); int height2 = Height(ioRect); int xRatio, yRatio, ratio; if (inFlag) { xRatio = width1 / width2; yRatio = height1 / height2; ratio = (xRatio > yRatio) ? yRatio : xRatio; width2 *= ratio; height2 *= ratio; } int xOffset = inRect.left + ((width1 - width2) / 2); int yOffset = inRect.top + ((height1 - height2) / 2); ioRect.left = xOffset; ioRect.top = yOffset; ioRect.right = ioRect.left + width2; ioRect.bottom = ioRect.top + height2; } inline /*static*/ int URect::Width(const RECT& inRect) { return inRect.right - inRect.left; } inline /*static*/ int URect::Height(const RECT& inRect) { return inRect.bottom - inRect.top; } inline /*static*/ void URect::Union(const RECT& inRect1, const RECT& inRect2, RECT& outRect) { if (::IsRectEmpty(&inRect1)) { outRect = inRect2; } else if (::IsRectEmpty(&inRect2)) { outRect = inRect1; } else { CRect result; result.IntersectRect(&inRect1, &inRect2); ::SetRect(&outRect, result.left, result.top, result.right, result.bottom); } } inline /*static*/ POINT URect::Center(const RECT& inRect) { POINT pt; pt.x = (inRect.left + inRect.right) / 2; pt.y = (inRect.top + inRect.bottom) / 2; return pt; }