summaryrefslogtreecommitdiff
path: root/src/T2DLL/UT2Coordinate.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/T2DLL/UT2Coordinate.cpp')
-rw-r--r--src/T2DLL/UT2Coordinate.cpp194
1 files changed, 163 insertions, 31 deletions
diff --git a/src/T2DLL/UT2Coordinate.cpp b/src/T2DLL/UT2Coordinate.cpp
index 4c1323e..caecdb1 100644
--- a/src/T2DLL/UT2Coordinate.cpp
+++ b/src/T2DLL/UT2Coordinate.cpp
@@ -1,94 +1,226 @@
#include "UT2Coordinate.h"
-/*static*/ void UT2Coordinate::UnitToQD(int&, int&, int) {
+/*static*/ void UT2Coordinate::UnitToQD(int& ioV, int& ioH, int inZoomLevel) {
+ ioV *= UnitVSize(inZoomLevel);
+ ioH <<= (3 - inZoomLevel);
}
-/*static*/ void UT2Coordinate::UnitToQD(POINT&, int, int) {
+/*static*/ void UT2Coordinate::UnitToQD(POINT& ioPoint, int inZoomLevel, BOOL inExcludeRoof) {
+ ioPoint.y *= UnitVSize(inZoomLevel);
+ ioPoint.x <<= (3 - inZoomLevel);
+ if (!inExcludeRoof)
+ ioPoint.y += CalcRoofThick(inZoomLevel);
}
-/*static*/ void UT2Coordinate::UnitToQD(RECT&, int, int) {
+/*static*/ void UT2Coordinate::UnitToQD(RECT& ioRect, int inZoomLevel, BOOL inExcludeRoofAndFloor) {
+ ioRect.top *= UnitVSize(inZoomLevel);
+ ioRect.left <<= (3 - inZoomLevel);
+ ioRect.bottom *= UnitVSize(inZoomLevel);
+ ioRect.right <<= (3 - inZoomLevel);
+ if (!inExcludeRoofAndFloor) {
+ ioRect.top += CalcRoofThick(inZoomLevel);
+ ioRect.bottom -= CalcFloorThick(inZoomLevel);
+ }
}
-/*static*/ void UT2Coordinate::UnitToQD(const RECT&, RECT&, int, int) {
+/*static*/ void UT2Coordinate::UnitToQD(const RECT& inUnitRect, RECT& outQDRect, int inZoomLevel, BOOL inExcludeRoofAndFloor) {
+ outQDRect.top = inUnitRect.top * UnitVSize(inZoomLevel);
+ outQDRect.left = inUnitRect.left << (3 - inZoomLevel);
+ outQDRect.bottom = inUnitRect.bottom * UnitVSize(inZoomLevel);
+ outQDRect.right = inUnitRect.right << (3 - inZoomLevel);
+ if (!inExcludeRoofAndFloor) {
+ outQDRect.top += CalcRoofThick(inZoomLevel);
+ outQDRect.bottom -= CalcFloorThick(inZoomLevel);
+ }
}
-/*static*/ void UT2Coordinate::UnitToQDRoof(const RECT&, RECT&, int) {
+/*static*/ void UT2Coordinate::UnitToQDRoof(const RECT& inUnitRect, RECT& outQDRect, int inZoomLevel) {
+ outQDRect.top = inUnitRect.top * UnitVSize(inZoomLevel);
+ outQDRect.left = inUnitRect.left << (3 - inZoomLevel);
+ outQDRect.bottom = outQDRect.top + CalcRoofThick(inZoomLevel);
+ outQDRect.right = inUnitRect.right << (3 - inZoomLevel);
}
-/*static*/ void UT2Coordinate::UnitToQDFloor(const RECT&, RECT&, int) {
+/*static*/ void UT2Coordinate::UnitToQDFloor(const RECT& inUnitRect, RECT& outQDRect, int inZoomLevel) {
+ outQDRect.left = inUnitRect.left << (3 - inZoomLevel);
+ outQDRect.bottom = inUnitRect.bottom * UnitVSize(inZoomLevel);
+ outQDRect.right = inUnitRect.right << (3 - inZoomLevel);
+ outQDRect.top = outQDRect.bottom - CalcFloorThick(inZoomLevel);
}
-/*static*/ void UT2Coordinate::UnitToOffRect(const RECT&, RECT&, int) {
+/*static*/ void UT2Coordinate::UnitToOffRect(const RECT& inUnitRect, RECT& outQDRect, int inHeight) {
+ UnitToQD(inUnitRect, outQDRect);
+ OffsetRect(&outQDRect, 0, -outQDRect.top);
+ int var = outQDRect.bottom;
+ OffsetRect(&outQDRect, 0, var * inHeight);
}
-/*static*/ void UT2Coordinate::QDToUnit(int&, int&, int) {
+/*static*/ void UT2Coordinate::QDToUnit(int& ioV, int& ioH, int inZoomLevel) {
+ ioV /= UnitVSize(inZoomLevel);
+ ioH >>= (3 - inZoomLevel);
}
-/*static*/ void UT2Coordinate::QDToUnit(POINT&, int) {
+/*static*/ void UT2Coordinate::QDToUnit(POINT& ioPoint, int inZoomLevel) {
+ ioPoint.y /= UnitVSize(inZoomLevel);
+ ioPoint.x >>= (3 - inZoomLevel);
}
-/*static*/ void UT2Coordinate::QDToUnit(SDimension16&, int) {
+/*static*/ void UT2Coordinate::QDToUnit(SDimension16& ioSize, int inZoomLevel) {
+ ioSize.height /= UnitVSize(inZoomLevel);
+ ioSize.width >>= (3 - inZoomLevel);
}
-/*static*/ void UT2Coordinate::QDToUnit(RECT&, int) {
+/*static*/ void UT2Coordinate::QDToUnit(RECT& ioRect, int inZoomLevel) {
+ RECT orig = ioRect;
+ ioRect.top /= UnitVSize(inZoomLevel);
+ ioRect.left >>= (3 - inZoomLevel);
+ ioRect.bottom /= UnitVSize(inZoomLevel);
+ ioRect.right >>= (3 - inZoomLevel);
+
+ if ((orig.bottom % UnitVSize(inZoomLevel)) != 0)
+ ioRect.bottom++;
+ if ((orig.right % UnitHSize(inZoomLevel)) != 0)
+ ioRect.right++;
}
-/*static*/ void UT2Coordinate::QDToUnit(const RECT&, RECT&, int) {
+/*static*/ void UT2Coordinate::QDToUnit(const RECT& inQDRect, RECT& outUnitRect, int inZoomLevel) {
+ outUnitRect.top = inQDRect.top / UnitVSize(inZoomLevel);
+ outUnitRect.left = inQDRect.left >> (3 - inZoomLevel);
+ outUnitRect.bottom = inQDRect.bottom / UnitVSize(inZoomLevel);
+ outUnitRect.right = inQDRect.right >> (3 - inZoomLevel);
+
+ if ((inQDRect.bottom % UnitVSize(inZoomLevel)) != 0)
+ outUnitRect.bottom++;
+ if ((inQDRect.right % UnitHSize(inZoomLevel)) != 0)
+ outUnitRect.right++;
}
-/*static*/ void UT2Coordinate::NoRoofQDToUnit(const RECT&, RECT&, int) {
+/*static*/ void UT2Coordinate::NoRoofQDToUnit(const RECT& inQDRect, RECT& outUnitRect, int inZoomLevel) {
+ outUnitRect.top = inQDRect.top / UnitVSize(inZoomLevel);
+ outUnitRect.left = inQDRect.left >> (3 - inZoomLevel);
+ outUnitRect.bottom = (inQDRect.bottom + CalcRoofThick(inZoomLevel) + CalcFloorThick(inZoomLevel)) / UnitVSize(inZoomLevel);
+ outUnitRect.right = inQDRect.right >> (3 - inZoomLevel);
}
-/*static*/ void UT2Coordinate::BkgndToQD(int&, int&, int) {
+/*static*/ void UT2Coordinate::BkgndToQD(int& ioV, int& ioH, int inZoomLevel) {
+ ioV *= BkgndVSize(inZoomLevel);
+ ioH <<= (6 - inZoomLevel);
}
-/*static*/ void UT2Coordinate::BkgndToQD(POINT&, int) {
+/*static*/ void UT2Coordinate::BkgndToQD(POINT& ioPoint, int inZoomLevel) {
+ ioPoint.y *= BkgndVSize(inZoomLevel);
+ ioPoint.x <<= (6 - inZoomLevel);
}
-/*static*/ void UT2Coordinate::BkgndToQD(RECT&, int) {
+/*static*/ void UT2Coordinate::BkgndToQD(RECT& ioRect, int inZoomLevel) {
+ ioRect.top *= BkgndVSize(inZoomLevel);
+ ioRect.left <<= (6 - inZoomLevel);
+ ioRect.bottom *= BkgndVSize(inZoomLevel);
+ ioRect.right <<= (6 - inZoomLevel);
}
-/*static*/ void UT2Coordinate::BkgndToQD(const RECT&, RECT&, int) {
+/*static*/ void UT2Coordinate::BkgndToQD(const RECT& inBkgndRect, RECT& outQDRect, int inZoomLevel) {
+ outQDRect.top = inBkgndRect.top * BkgndVSize(inZoomLevel);
+ outQDRect.left = inBkgndRect.left << (6 - inZoomLevel);
+ outQDRect.bottom = inBkgndRect.bottom * BkgndVSize(inZoomLevel);
+ outQDRect.right = inBkgndRect.right << (6 - inZoomLevel);
}
-/*static*/ void UT2Coordinate::QDToBkgnd(int&, int&, int) {
+/*static*/ void UT2Coordinate::QDToBkgnd(int& ioV, int& ioH, int inZoomLevel) {
+ ioV /= BkgndVSize(inZoomLevel);
+ ioH >>= (6 - inZoomLevel);
}
-/*static*/ void UT2Coordinate::QDToBkgnd(POINT&, int) {
+/*static*/ void UT2Coordinate::QDToBkgnd(POINT& ioPoint, int inZoomLevel) {
+ ioPoint.y /= BkgndVSize(inZoomLevel);
+ ioPoint.x >>= (6 - inZoomLevel);
}
-/*static*/ void UT2Coordinate::QDToBkgnd(SDimension16&, int) {
+/*static*/ void UT2Coordinate::QDToBkgnd(SDimension16& ioSize, int inZoomLevel) {
+ ioSize.height /= BkgndVSize(inZoomLevel);
+ ioSize.width >>= (6 - inZoomLevel);
}
-/*static*/ void UT2Coordinate::QDToBkgnd(RECT&, int) {
+/*static*/ void UT2Coordinate::QDToBkgnd(RECT& ioRect, int inZoomLevel) {
+ ioRect.top /= BkgndVSize(inZoomLevel);
+ ioRect.left >>= (6 - inZoomLevel);
+ ioRect.bottom /= BkgndVSize(inZoomLevel);
+ ioRect.right >>= (6 - inZoomLevel);
}
-/*static*/ void UT2Coordinate::QDToBkgnd(const RECT&, RECT&, int) {
+/*static*/ void UT2Coordinate::QDToBkgnd(const RECT& inQDRect, RECT& outBkgndRect, int inZoomLevel) {
+ outBkgndRect.top = inQDRect.top / BkgndVSize(inZoomLevel);
+ outBkgndRect.left = inQDRect.left >> (6 - inZoomLevel);
+ outBkgndRect.bottom = inQDRect.bottom / BkgndVSize(inZoomLevel);
+ outBkgndRect.right = inQDRect.right >> (6 - inZoomLevel);
}
-/*static*/ void UT2Coordinate::UnitToBkgnd(const RECT&, RECT&) {
+/*static*/ void UT2Coordinate::UnitToBkgnd(const RECT& inUnitRect, RECT& outBkgndRect) {
+ outBkgndRect.top = inUnitRect.top >> 1;
+ outBkgndRect.left = inUnitRect.left >> 3;
+ outBkgndRect.bottom = inUnitRect.bottom >> 1;
+ outBkgndRect.right = inUnitRect.right >> 3;
+
+ if ((inUnitRect.bottom % 2) != 0)
+ outBkgndRect.bottom++;
+ if ((inUnitRect.right % 8) != 0)
+ outBkgndRect.right++;
}
-/*static*/ void UT2Coordinate::BkgndToUnit(const RECT&, RECT&) {
+/*static*/ void UT2Coordinate::BkgndToUnit(const RECT& inBkgndRect, RECT& outUnitRect) {
+ outUnitRect.top = inBkgndRect.top << 1;
+ outUnitRect.left = inBkgndRect.left << 3;
+ outUnitRect.bottom = inBkgndRect.bottom << 1;
+ outUnitRect.right = inBkgndRect.right << 3;
}
-/*static*/ void UT2Coordinate::MakeRect(RECT&, const POINT&, const SDimension16&) {
+/*static*/ void UT2Coordinate::MakeRect(RECT& outRect, const POINT& inPoint, const SDimension16& inSize) {
+ outRect.top = inPoint.y;
+ outRect.left = inPoint.x;
+ outRect.bottom = outRect.top + inSize.height;
+ outRect.right = outRect.left + inSize.width;
}
-/*static*/ void UT2Coordinate::MakeRect(RECT&, const POINT&, int, int) {
+/*static*/ void UT2Coordinate::MakeRect(RECT& outRect, const POINT& inPoint, int inWidth, int inHeight) {
+ outRect.top = inPoint.y;
+ outRect.left = inPoint.x;
+ outRect.bottom = outRect.top + inHeight;
+ outRect.right = outRect.left + inWidth;
}
-/*static*/ void UT2Coordinate::MakeRect(RECT&, int, int) {
+/*static*/ void UT2Coordinate::MakeRect(RECT& outRect, int inWidth, int inHeight) {
+ outRect.top = 0;
+ outRect.left = 0;
+ outRect.bottom = inHeight;
+ outRect.right = inWidth;
}
-/*static*/ void UT2Coordinate::MakeCenterRect(RECT&, const POINT&, int, int) {
+/*static*/ void UT2Coordinate::MakeCenterRect(RECT& outRect, const POINT& inPoint, int inWidth, int inHeight) {
+ int xDist = inWidth >> 1;
+ int yDist = inHeight >> 1;
+ outRect.top = inPoint.y - yDist;
+ outRect.left = inPoint.x - xDist;
+ outRect.bottom = outRect.top + inHeight;
+ outRect.right = outRect.left + inWidth;
}
-/*static*/ void UT2Coordinate::AddRect(RECT&, const RECT&) {
+/*static*/ void UT2Coordinate::AddRect(RECT& ioRectA, const RECT& inRectB) {
+ ioRectA.top += inRectB.top;
+ ioRectA.left += inRectB.left;
+ ioRectA.bottom += inRectB.bottom;
+ ioRectA.right += inRectB.right;
}
-/*static*/ void UT2Coordinate::SubRect(RECT&, const RECT&) {
+/*static*/ void UT2Coordinate::SubRect(RECT& ioRectA, const RECT& inRectB) {
+ ioRectA.top -= inRectB.top;
+ ioRectA.left -= inRectB.left;
+ ioRectA.bottom -= inRectB.bottom;
+ ioRectA.right -= inRectB.right;
}
-/*static*/ void UT2Coordinate::ZoomOut(RECT&, int) {
+/*static*/ void UT2Coordinate::ZoomOut(RECT& ioRect, int inZoomLevel) {
+ ioRect.top >>= inZoomLevel;
+ ioRect.left >>= inZoomLevel;
+ ioRect.bottom >>= inZoomLevel;
+ ioRect.right >>= inZoomLevel;
}