From a3da8915b9135db99d219811a7a1021f69d49a37 Mon Sep 17 00:00:00 2001 From: vcaesar Date: Sat, 30 Nov 2019 10:44:40 -0400 Subject: [PATCH] add int32_t types support --- base/types.h | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/base/types.h b/base/types.h index dde1299..dbc8755 100644 --- a/base/types.h +++ b/base/types.h @@ -5,6 +5,7 @@ #include "os.h" #include "inline_keywords.h" /* For H_INLINE */ #include +#include /* Some generic, cross-platform types. */ @@ -15,6 +16,13 @@ struct _MMPoint { typedef struct _MMPoint MMPoint; +struct _MMSignedPoint { + int32_t x; + int32_t y; +}; + +typedef struct _MMSignedPoint MMSignedPoint; + struct _MMSize { size_t width; size_t height; @@ -22,6 +30,14 @@ struct _MMSize { typedef struct _MMSize MMSize; +struct _MMSignedSize { + int32_t w; + int32_t h; +}; + +typedef struct _MMSignedSize MMSignedSize; + + struct _MMRect { MMPoint origin; MMSize size; @@ -29,6 +45,13 @@ struct _MMRect { typedef struct _MMRect MMRect; +struct _MMSignedRect { + MMSignedPoint origin; + MMSignedSize size; +}; + +typedef struct _MMSignedRect MMSignedRect; + H_INLINE MMPoint MMPointMake(size_t x, size_t y) { MMPoint point; @@ -37,6 +60,14 @@ H_INLINE MMPoint MMPointMake(size_t x, size_t y) return point; } +H_INLINE MMSignedPoint MMSignedPointMake(int32_t x, int32_t y) +{ + MMSignedPoint point; + point.x = x; + point.y = y; + return point; +} + H_INLINE MMSize MMSizeMake(size_t width, size_t height) { MMSize size; @@ -45,6 +76,14 @@ H_INLINE MMSize MMSizeMake(size_t width, size_t height) return size; } +H_INLINE MMSignedSize MMSignedSizeMake(int32_t w, int32_t h) +{ + MMSignedSize size; + size.w = w; + size.h = h; + return size; +} + H_INLINE MMRect MMRectMake(size_t x, size_t y, size_t width, size_t height) { MMRect rect; @@ -53,6 +92,15 @@ H_INLINE MMRect MMRectMake(size_t x, size_t y, size_t width, size_t height) return rect; } +H_INLINE MMSignedRect MMSignedRectMake(int32_t x, int32_t y, int32_t w, int32_t h) +{ + MMSignedRect rect; + rect.origin = MMSignedPointMake(x, y); + rect.size = MMSignedSizeMake(w, h); + return rect; +} + +// #define MMPointZero MMPointMake(0, 0) #if defined(IS_MACOSX) @@ -60,6 +108,9 @@ H_INLINE MMRect MMRectMake(size_t x, size_t y, size_t width, size_t height) #define CGPointFromMMPoint(p) CGPointMake((CGFloat)(p).x, (CGFloat)(p).y) #define MMPointFromCGPoint(p) MMPointMake((size_t)(p).x, (size_t)(p).y) +#define CGPointFromMMSignedPoint(p) CGPointMake((CGFloat)(p).x, (CGFloat)(p).y) +#define MMSignedPointFromCGPoint(p) MMPointMake((int32_t)(p).x, (int32_t)(p).y) + #elif defined(IS_WINDOWS) #define MMPointFromPOINT(p) MMPointMake((size_t)p.x, (size_t)p.y)