aboutsummaryrefslogtreecommitdiffstats
path: root/src/win.c
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2022-05-20 19:44:23 -0400
committerDavid Robillard <d@drobilla.net>2022-05-21 17:05:51 -0400
commit82405e8c177de446d03c340b4b6876370d79883a (patch)
tree8b58d94ce03810d95558d725f9a3394d2e7d0fc7 /src/win.c
parenta136586a339032126540ceb24f7c3f15eaba68c8 (diff)
downloadpugl-82405e8c177de446d03c340b4b6876370d79883a.tar.gz
pugl-82405e8c177de446d03c340b4b6876370d79883a.tar.bz2
pugl-82405e8c177de446d03c340b4b6876370d79883a.zip
Add puglSetPosition() and puglSetSize()
These are redundant with puglSetFrame in a sense, but allow setting the size of a view without the position, or vice-versa. This API also maps more nicely to Wayland, where applications can not position themselves (but can resize).
Diffstat (limited to 'src/win.c')
-rw-r--r--src/win.c82
1 files changed, 74 insertions, 8 deletions
diff --git a/src/win.c b/src/win.c
index 34f46d9..26dd4c8 100644
--- a/src/win.c
+++ b/src/win.c
@@ -984,17 +984,27 @@ puglSetWindowTitle(PuglView* view, const char* title)
return PUGL_SUCCESS;
}
+static RECT
+adjustedWindowRect(PuglView* const view,
+ const long x,
+ const long y,
+ const long width,
+ const long height)
+{
+ const unsigned flags = puglWinGetWindowFlags(view);
+ const unsigned exFlags = puglWinGetWindowExFlags(view);
+
+ RECT rect = {(long)x, (long)y, (long)x + (long)width, (long)y + (long)height};
+ AdjustWindowRectEx(&rect, flags, FALSE, exFlags);
+ return rect;
+}
+
PuglStatus
puglSetFrame(PuglView* view, const PuglRect frame)
{
if (view->impl->hwnd) {
- RECT rect = {(long)frame.x,
- (long)frame.y,
- (long)frame.x + (long)frame.width,
- (long)frame.y + (long)frame.height};
-
- AdjustWindowRectEx(
- &rect, puglWinGetWindowFlags(view), FALSE, puglWinGetWindowExFlags(view));
+ const RECT rect =
+ adjustedWindowRect(view, frame.x, frame.y, frame.width, frame.height);
if (!SetWindowPos(view->impl->hwnd,
HWND_TOP,
@@ -1012,12 +1022,68 @@ puglSetFrame(PuglView* view, const PuglRect frame)
}
PuglStatus
+puglSetPosition(PuglView* const view, const int x, const int y)
+{
+ if (x > INT16_MAX || y > INT16_MAX) {
+ return PUGL_BAD_PARAMETER;
+ }
+
+ if (view->impl->hwnd) {
+ const RECT rect =
+ adjustedWindowRect(view, x, y, view->frame.width, view->frame.height);
+
+ if (!SetWindowPos(view->impl->hwnd,
+ HWND_TOP,
+ rect.left,
+ rect.top,
+ 0,
+ 0,
+ SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOZORDER |
+ SWP_NOSIZE)) {
+ return PUGL_UNKNOWN_ERROR;
+ }
+ }
+
+ view->frame.x = (PuglCoord)x;
+ view->frame.y = (PuglCoord)y;
+ return PUGL_SUCCESS;
+}
+
+PuglStatus
+puglSetSize(PuglView* const view, const unsigned width, const unsigned height)
+{
+ if (width > INT16_MAX || height > INT16_MAX) {
+ return PUGL_BAD_PARAMETER;
+ }
+
+ if (view->impl->hwnd) {
+ const RECT rect = adjustedWindowRect(
+ view, view->frame.x, view->frame.y, (long)width, (long)height);
+
+ if (!SetWindowPos(view->impl->hwnd,
+ HWND_TOP,
+ 0,
+ 0,
+ rect.right - rect.left,
+ rect.bottom - rect.top,
+ SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOZORDER |
+ SWP_NOMOVE)) {
+ return PUGL_UNKNOWN_ERROR;
+ }
+ }
+
+ view->frame.width = (PuglSpan)width;
+ view->frame.height = (PuglSpan)height;
+ return PUGL_SUCCESS;
+}
+
+PuglStatus
puglSetSizeHint(PuglView* const view,
const PuglSizeHint hint,
const PuglSpan width,
const PuglSpan height)
{
- if ((unsigned)hint > (unsigned)PUGL_MAX_ASPECT || width < 0 || height < 0) {
+ if ((unsigned)hint > (unsigned)PUGL_MAX_ASPECT) {
return PUGL_BAD_PARAMETER;
}