feat(region): add integer versions of SRgn functions

This commit is contained in:
Adam Heinermann 2025-09-13 02:24:31 -07:00 committed by fallenoak
parent 547fc6d4f0
commit a96d1270d4
5 changed files with 1033 additions and 60 deletions

View file

@ -435,6 +435,21 @@ void SRgnCombineRectf(HSRGN handle, const RECTF* rect, void* param, int32_t comb
s_rgntable.Unlock(lockedHandle);
}
void SRgnCombineRecti(HSRGN handle, const RECT* rect, void* param, int32_t combineMode) {
STORM_VALIDATE_BEGIN;
STORM_VALIDATE(rect);
STORM_VALIDATE_END_VOID;
// NOTE: top and bottom get flipped, this is a bug in Storm
RECTF rectf = {
static_cast<float>(rect->left),
static_cast<float>(rect->top),
static_cast<float>(rect->right),
static_cast<float>(rect->bottom)
};
SRgnCombineRectf(handle, &rectf, param, combineMode);
}
void SRgnClear(HSRGN handle) {
STORM_VALIDATE_BEGIN;
STORM_VALIDATE(handle);
@ -539,6 +554,21 @@ void SRgnGetBoundingRectf(HSRGN handle, RECTF* rect) {
}
}
void SRgnGetBoundingRecti(HSRGN handle, RECT* rect) {
STORM_VALIDATE_BEGIN;
STORM_VALIDATE(rect);
STORM_VALIDATE_END_VOID;
RECTF rectf;
SRgnGetBoundingRectf(handle, &rectf);
// NOTE: top and bottom get flipped, this is a bug in Storm
rect->left = static_cast<int32_t>(rectf.left);
rect->top = static_cast<int32_t>(rectf.bottom);
rect->right = static_cast<int32_t>(rectf.right);
rect->bottom = static_cast<int32_t>(rectf.top);
}
void SRgnGetRectParamsf(HSRGN handle, const RECTF* rect, uint32_t* numParams, void** buffer) {
STORM_VALIDATE_BEGIN;
STORM_VALIDATE(handle);
@ -580,6 +610,21 @@ void SRgnGetRectParamsf(HSRGN handle, const RECTF* rect, uint32_t* numParams, vo
s_rgntable.Unlock(lockedHandle);
}
void SRgnGetRectParamsi(HSRGN handle, const RECT* rect, uint32_t* numParams, void** buffer) {
STORM_VALIDATE_BEGIN;
STORM_VALIDATE(rect);
STORM_VALIDATE_END_VOID;
// NOTE: top and bottom get flipped, this is a bug in Storm
RECTF rectf = {
static_cast<float>(rect->left),
static_cast<float>(rect->top),
static_cast<float>(rect->right),
static_cast<float>(rect->bottom)
};
SRgnGetRectParamsf(handle, &rectf, numParams, buffer);
}
void SRgnGetRectsf(HSRGN handle, uint32_t* numRects, RECTF* buffer) {
STORM_VALIDATE_BEGIN;
STORM_VALIDATE(handle);
@ -609,6 +654,22 @@ void SRgnGetRectsf(HSRGN handle, uint32_t* numRects, RECTF* buffer) {
s_rgntable.Unlock(lockedHandle);
}
void SRgnGetRectsi(HSRGN handle, uint32_t* numRects, RECT* buffer) {
RECTF* bufferf = reinterpret_cast<RECTF*>(buffer);
SRgnGetRectsf(handle, numRects, bufferf);
if (buffer) {
for (uint32_t i = 0; i < *numRects; i++) {
float bottom = bufferf[i].bottom;
float top = bufferf[i].top;
buffer[i].left = static_cast<int32_t>(bufferf[i].left);
buffer[i].bottom = static_cast<int32_t>(bottom);
buffer[i].right = static_cast<int32_t>(bufferf[i].right);
buffer[i].top = static_cast<int32_t>(top);
}
}
}
int32_t SRgnIsPointInRegionf(HSRGN handle, float x, float y) {
STORM_VALIDATE_BEGIN;
STORM_VALIDATE(handle);
@ -638,6 +699,10 @@ int32_t SRgnIsPointInRegionf(HSRGN handle, float x, float y) {
return result;
}
int32_t SRgnIsPointInRegioni(HSRGN handle, int32_t x, int32_t y) {
return SRgnIsPointInRegionf(handle, static_cast<float>(x), static_cast<float>(y));
}
int32_t SRgnIsRectInRegionf(HSRGN handle, const RECTF* rect) {
STORM_VALIDATE_BEGIN;
STORM_VALIDATE(handle);
@ -667,6 +732,21 @@ int32_t SRgnIsRectInRegionf(HSRGN handle, const RECTF* rect) {
return result;
}
int32_t SRgnIsRectInRegioni(HSRGN handle, const RECT* rect) {
STORM_VALIDATE_BEGIN;
STORM_VALIDATE(rect);
STORM_VALIDATE_END;
// NOTE: top and bottom get flipped, this is a bug in Storm
RECTF rectf = {
static_cast<float>(rect->left),
static_cast<float>(rect->top),
static_cast<float>(rect->right),
static_cast<float>(rect->bottom)
};
return SRgnIsRectInRegionf(handle, &rectf);
}
void SRgnOffsetf(HSRGN handle, float xoffset, float yoffset) {
STORM_VALIDATE_BEGIN;
STORM_VALIDATE(handle);
@ -690,3 +770,7 @@ void SRgnOffsetf(HSRGN handle, float xoffset, float yoffset) {
s_rgntable.Unlock(lockedHandle);
}
void SRgnOffseti(HSRGN handle, int32_t xoffset, int32_t yoffset) {
SRgnOffsetf(handle, static_cast<float>(xoffset), static_cast<float>(yoffset));
}

View file

@ -8,6 +8,8 @@ void SRgnClear(HSRGN handle);
void SRgnCombineRectf(HSRGN handle, const RECTF* rect, void* param, int32_t combineMode);
void SRgnCombineRecti(HSRGN handle, const RECT* rect, void* param, int32_t combineMode);
void SRgnCreate(HSRGN* handlePtr, uint32_t reserved = 0);
void SRgnDelete(HSRGN handle);
@ -16,14 +18,26 @@ void SRgnDuplicate(HSRGN origHandle, HSRGN* handle, uint32_t reserved = 0);
void SRgnGetBoundingRectf(HSRGN handle, RECTF* rect);
void SRgnGetBoundingRecti(HSRGN handle, RECT* rect);
void SRgnGetRectParamsf(HSRGN handle, const RECTF* rect, uint32_t* numParams, void** buffer);
void SRgnGetRectParamsi(HSRGN handle, const RECT* rect, uint32_t* numParams, void** buffer);
void SRgnGetRectsf(HSRGN handle, uint32_t* numRects, RECTF* buffer);
void SRgnGetRectsi(HSRGN handle, uint32_t* numRects, RECT* buffer);
int32_t SRgnIsPointInRegionf(HSRGN handle, float x, float y);
int32_t SRgnIsPointInRegioni(HSRGN handle, int32_t x, int32_t y);
int32_t SRgnIsRectInRegionf(HSRGN handle, const RECTF* rect);
int32_t SRgnIsRectInRegioni(HSRGN handle, const RECT* rect);
void SRgnOffsetf(HSRGN handle, float xoffset, float yoffset);
void SRgnOffseti(HSRGN handle, int32_t xoffset, int32_t yoffset);
#endif

View file

@ -3,9 +3,9 @@
#include "storm/Handle.hpp"
#include <cstdint>
#include <limits>
DECLARE_STORM_HANDLE(HSRGN);
DECLARE_STORM_HANDLE(HLOCKEDRGN);
struct RECTF {
@ -15,6 +15,15 @@ struct RECTF {
float top;
};
#if defined(WHOA_SYSTEM_WIN)
// NOTE: WINAPI's RECT uses `long`.
#include <Windows.h>
#else
struct RECT {
int32_t left, top, right, bottom;
};
#endif
// Combine modes
#define SRGN_AND 1
#define SRGN_OR 2

File diff suppressed because it is too large Load diff

View file

@ -26,6 +26,12 @@ std::ostream& operator <<(std::ostream& os, RECTF const& value) {
return os;
}
// Helpers for comparing RECTF structs
std::ostream& operator <<(std::ostream& os, RECT const& value) {
os << "{ " << value.left << ", " << value.top << ", " << value.right << ", " << value.bottom << " }";
return os;
}
template <class T>
class RECTMatcher : public Catch::MatcherBase<T> {
private:
@ -45,6 +51,10 @@ class RECTMatcher : public Catch::MatcherBase<T> {
}
};
RECTMatcher<RECTF> MatchesRect(RECTF arg) {
RECTMatcher<RECTF> MatchesRectf(RECTF arg) {
return { arg };
}
RECTMatcher<RECT> MatchesRecti(RECT arg) {
return { arg };
}