diff options
author | David Robillard <d@drobilla.net> | 2025-01-22 18:42:13 -0500 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2025-01-22 18:42:13 -0500 |
commit | 44e65f78fca1597471d31a96907d5be465ca1ec1 (patch) | |
tree | 8c6394d767a0166fc7f69166b278f20a94dad454 /src | |
parent | 8905c1176aa5099545fd9abb2e673efc136d0311 (diff) | |
download | pugl-44e65f78fca1597471d31a96907d5be465ca1ec1.tar.gz pugl-44e65f78fca1597471d31a96907d5be465ca1ec1.tar.bz2 pugl-44e65f78fca1597471d31a96907d5be465ca1ec1.zip |
Factor out puglIsValidPosition()
Diffstat (limited to 'src')
-rw-r--r-- | src/common.c | 3 | ||||
-rw-r--r-- | src/internal.c | 6 | ||||
-rw-r--r-- | src/internal.h | 4 | ||||
-rw-r--r-- | src/mac.m | 4 | ||||
-rw-r--r-- | src/win.c | 4 | ||||
-rw-r--r-- | src/x11.c | 4 |
6 files changed, 17 insertions, 8 deletions
diff --git a/src/common.c b/src/common.c index 8c2268b..2e6e0e6 100644 --- a/src/common.c +++ b/src/common.c @@ -12,7 +12,6 @@ #include <limits.h> #include <stdbool.h> -#include <stdint.h> #include <stdlib.h> #include <string.h> @@ -302,7 +301,7 @@ puglGetFrame(const PuglView* view) // Get the default position if set, or fallback to (0, 0) int x = view->defaultX; int y = view->defaultY; - if (x < INT16_MIN || x > INT16_MAX || y < INT16_MIN || y > INT16_MAX) { + if (!puglIsValidPosition(x, y)) { x = 0; y = 0; } diff --git a/src/internal.c b/src/internal.c index 1a7b61f..3799e97 100644 --- a/src/internal.c +++ b/src/internal.c @@ -13,6 +13,12 @@ #include <string.h> bool +puglIsValidPosition(const int x, const int y) +{ + return x >= INT16_MIN && x <= INT16_MAX && y >= INT16_MIN && y <= INT16_MAX; +} + +bool puglIsValidArea(const PuglArea size) { return size.width && size.height; diff --git a/src/internal.h b/src/internal.h index e4296c8..3a2663b 100644 --- a/src/internal.h +++ b/src/internal.h @@ -18,6 +18,10 @@ PUGL_BEGIN_DECLS +/// Return true if `x`,`y` is a valid position +bool +puglIsValidPosition(int x, int y); + /// Return true if `size` is a valid view size bool puglIsValidArea(PuglArea size); @@ -1167,7 +1167,7 @@ getInitialFrame(PuglView* const view) const int x = view->defaultX; const int y = view->defaultY; - if (x >= INT16_MIN && x <= INT16_MAX && y >= INT16_MIN && y <= INT16_MAX) { + if (puglIsValidPosition(x, y)) { // Use the default position set with puglSetPosition while unrealized const PuglRect frame = {(PuglCoord)x, (PuglCoord)y, @@ -1773,7 +1773,7 @@ puglSetFrame(PuglView* view, const PuglRect frame) PuglStatus puglSetPosition(PuglView* const view, const int x, const int y) { - if (x < INT16_MIN || x > INT16_MAX || y < INT16_MIN || y > INT16_MAX) { + if (!puglIsValidPosition(x, y)) { return PUGL_BAD_PARAMETER; } @@ -1302,7 +1302,7 @@ puglSetFrame(PuglView* view, const PuglRect frame) PuglStatus puglSetPosition(PuglView* const view, const int x, const int y) { - if (x < INT16_MIN || x > INT16_MAX || y < INT16_MIN || y > INT16_MAX) { + if (!puglIsValidPosition(x, y)) { return PUGL_BAD_PARAMETER; } @@ -1592,7 +1592,7 @@ getInitialFrame(PuglView* const view) const PuglSpan defaultHeight = view->sizeHints[PUGL_DEFAULT_SIZE].height; const int x = view->defaultX; const int y = view->defaultY; - if (x >= INT16_MIN && x <= INT16_MAX && y >= INT16_MIN && y <= INT16_MAX) { + if (puglIsValidPosition(x, y)) { // Use the default position set with puglSetPosition while unrealized const PuglRect frame = { (PuglCoord)x, (PuglCoord)y, defaultWidth, defaultHeight}; @@ -526,7 +526,7 @@ getInitialFrame(PuglView* const view) const PuglSpan defaultHeight = view->sizeHints[PUGL_DEFAULT_SIZE].height; const int x = view->defaultX; const int y = view->defaultY; - if (x >= INT16_MIN && x <= INT16_MAX && y >= INT16_MIN && y <= INT16_MAX) { + if (puglIsValidPosition(x, y)) { // Use the default position set with puglSetPosition while unrealized const PuglRect frame = { (PuglCoord)x, (PuglCoord)y, defaultWidth, defaultHeight}; @@ -1999,7 +1999,7 @@ puglSetPosition(PuglView* const view, const int x, const int y) { Display* const display = view->world->impl->display; - if (x < INT16_MIN || x > INT16_MAX || y < INT16_MIN || y > INT16_MAX) { + if (!puglIsValidPosition(x, y)) { return PUGL_BAD_PARAMETER; } |