summaryrefslogtreecommitdiff
path: root/src/T2DLL/URect.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/T2DLL/URect.cpp')
-rw-r--r--src/T2DLL/URect.cpp49
1 files changed, 43 insertions, 6 deletions
diff --git a/src/T2DLL/URect.cpp b/src/T2DLL/URect.cpp
index 8b4aa21..ad2b552 100644
--- a/src/T2DLL/URect.cpp
+++ b/src/T2DLL/URect.cpp
@@ -1,19 +1,56 @@
#include "URect.h"
-/*static*/ void URect::SetEmpty(RECT&) {
+/*static*/ void URect::SetEmpty(RECT& outRect) {
+ ::SetRect(&outRect, 0, 0, 0, 0);
}
-/*static*/ void URect::Center(const RECT&, RECT&, int) {
+/*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;
}
-/*static*/ int URect::Width(const RECT&) {
+/*static*/ int URect::Width(const RECT& inRect) {
+ return inRect.right - inRect.left;
}
-/*static*/ int URect::Height(const RECT&) {
+/*static*/ int URect::Height(const RECT& inRect) {
+ return inRect.bottom - inRect.top;
}
-/*static*/ void URect::Union(const RECT&, const RECT&, RECT&) {
+/*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);
+ }
}
-/*static*/ POINT URect::Center(const RECT&) {
+/*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;
}