From a136586a339032126540ceb24f7c3f15eaba68c8 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Fri, 20 May 2022 19:44:20 -0400 Subject: 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. --- src/win.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) (limited to 'src/win.c') 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) -- cgit v1.2.1