aboutsummaryrefslogtreecommitdiffstats
path: root/src/win.c
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2022-05-20 19:44:20 -0400
committerDavid Robillard <d@drobilla.net>2022-05-21 16:49:47 -0400
commita136586a339032126540ceb24f7c3f15eaba68c8 (patch)
treecd3e35e2cab5c71517c691cfad6dbeac8664b945 /src/win.c
parent1cd37cad0a06fbb15c44fd59dd6b2c12a0812a76 (diff)
downloadpugl-a136586a339032126540ceb24f7c3f15eaba68c8.tar.gz
pugl-a136586a339032126540ceb24f7c3f15eaba68c8.tar.bz2
pugl-a136586a339032126540ceb24f7c3f15eaba68c8.zip
Use consistent integer types for view positions and sizes
Actual window sizes and positions fit easily in a 16-bit integer. So, we use that in "representation contexts" like events. This makes structures smaller, and allows the values to be converted to float, double, or integer without casting (since any int16_t or uint16_t value can fit in them without loss). Setter APIs use native integers for convenience, to avoid casting hassles when doing arithmetic. Ranges are checked at runtime.
Diffstat (limited to 'src/win.c')
-rw-r--r--src/win.c25
1 files changed, 13 insertions, 12 deletions
diff --git a/src/win.c b/src/win.c
index 4c36afe..34f46d9 100644
--- a/src/win.c
+++ b/src/win.c
@@ -482,14 +482,14 @@ handleConfigure(PuglView* view, PuglEvent* event)
const LONG width = rect.right - rect.left;
const LONG height = rect.bottom - rect.top;
- view->frame.x = rect.left;
- view->frame.y = rect.top;
+ view->frame.x = (PuglCoord)rect.left;
+ view->frame.y = (PuglCoord)rect.top;
event->configure.type = PUGL_CONFIGURE;
- event->configure.x = view->frame.x;
- event->configure.y = view->frame.y;
- event->configure.width = width;
- event->configure.height = height;
+ event->configure.x = (PuglCoord)view->frame.x;
+ event->configure.y = (PuglCoord)view->frame.y;
+ event->configure.width = (PuglSpan)width;
+ event->configure.height = (PuglSpan)height;
return rect;
}
@@ -638,10 +638,10 @@ handleMessage(PuglView* view, UINT message, WPARAM wParam, LPARAM lParam)
case WM_PAINT:
GetUpdateRect(view->impl->hwnd, &rect, false);
event.expose.type = PUGL_EXPOSE;
- event.expose.x = rect.left;
- event.expose.y = rect.top;
- event.expose.width = rect.right - rect.left;
- event.expose.height = rect.bottom - rect.top;
+ event.expose.x = (PuglCoord)rect.left;
+ event.expose.y = (PuglCoord)rect.top;
+ event.expose.width = (PuglSpan)(rect.right - rect.left);
+ event.expose.height = (PuglSpan)(rect.bottom - rect.top);
break;
case WM_ERASEBKGND:
return true;
@@ -1200,8 +1200,9 @@ puglWinCreateWindow(PuglView* const view,
view->frame.width = defaultSize.width;
view->frame.height = defaultSize.height;
- view->frame.x = (screenWidth - view->frame.width) / 2.0;
- view->frame.y = (screenHeight - view->frame.height) / 2.0;
+
+ view->frame.x = (PuglCoord)((screenWidth - view->frame.width) / 2);
+ view->frame.y = (PuglCoord)((screenHeight - view->frame.height) / 2);
}
// The meaning of "parent" depends on the window type (WS_CHILD)