aboutsummaryrefslogtreecommitdiff
path: root/pugl/src/win.h
diff options
context:
space:
mode:
Diffstat (limited to 'pugl/src/win.h')
-rw-r--r--pugl/src/win.h168
1 files changed, 89 insertions, 79 deletions
diff --git a/pugl/src/win.h b/pugl/src/win.h
index bc1f763..ccab36a 100644
--- a/pugl/src/win.h
+++ b/pugl/src/win.h
@@ -26,62 +26,62 @@
typedef PIXELFORMATDESCRIPTOR PuglWinPFD;
struct PuglWorldInternalsImpl {
- double timerFrequency;
+ double timerFrequency;
};
struct PuglInternalsImpl {
- PuglWinPFD pfd;
- int pfId;
- HWND hwnd;
- HCURSOR cursor;
- HDC hdc;
- PuglSurface* surface;
- bool flashing;
- bool mouseTracked;
+ PuglWinPFD pfd;
+ int pfId;
+ HWND hwnd;
+ HCURSOR cursor;
+ HDC hdc;
+ PuglSurface* surface;
+ bool flashing;
+ bool mouseTracked;
};
static inline PuglWinPFD
puglWinGetPixelFormatDescriptor(const PuglHints hints)
{
- const int rgbBits = (hints[PUGL_RED_BITS] + //
- hints[PUGL_GREEN_BITS] + //
- hints[PUGL_BLUE_BITS]);
-
- const DWORD dwFlags = hints[PUGL_DOUBLE_BUFFER] ? PFD_DOUBLEBUFFER : 0u;
-
- PuglWinPFD pfd;
- ZeroMemory(&pfd, sizeof(pfd));
- pfd.nSize = sizeof(pfd);
- pfd.nVersion = 1;
- pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | dwFlags;
- pfd.iPixelType = PFD_TYPE_RGBA;
- pfd.cColorBits = (BYTE)rgbBits;
- pfd.cRedBits = (BYTE)hints[PUGL_RED_BITS];
- pfd.cGreenBits = (BYTE)hints[PUGL_GREEN_BITS];
- pfd.cBlueBits = (BYTE)hints[PUGL_BLUE_BITS];
- pfd.cAlphaBits = (BYTE)hints[PUGL_ALPHA_BITS];
- pfd.cDepthBits = (BYTE)hints[PUGL_DEPTH_BITS];
- pfd.cStencilBits = (BYTE)hints[PUGL_STENCIL_BITS];
- pfd.iLayerType = PFD_MAIN_PLANE;
- return pfd;
+ const int rgbBits = (hints[PUGL_RED_BITS] + //
+ hints[PUGL_GREEN_BITS] + //
+ hints[PUGL_BLUE_BITS]);
+
+ const DWORD dwFlags = hints[PUGL_DOUBLE_BUFFER] ? PFD_DOUBLEBUFFER : 0u;
+
+ PuglWinPFD pfd;
+ ZeroMemory(&pfd, sizeof(pfd));
+ pfd.nSize = sizeof(pfd);
+ pfd.nVersion = 1;
+ pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | dwFlags;
+ pfd.iPixelType = PFD_TYPE_RGBA;
+ pfd.cColorBits = (BYTE)rgbBits;
+ pfd.cRedBits = (BYTE)hints[PUGL_RED_BITS];
+ pfd.cGreenBits = (BYTE)hints[PUGL_GREEN_BITS];
+ pfd.cBlueBits = (BYTE)hints[PUGL_BLUE_BITS];
+ pfd.cAlphaBits = (BYTE)hints[PUGL_ALPHA_BITS];
+ pfd.cDepthBits = (BYTE)hints[PUGL_DEPTH_BITS];
+ pfd.cStencilBits = (BYTE)hints[PUGL_STENCIL_BITS];
+ pfd.iLayerType = PFD_MAIN_PLANE;
+ return pfd;
}
static inline unsigned
puglWinGetWindowFlags(const PuglView* const view)
{
- const bool resizable = view->hints[PUGL_RESIZABLE];
- const unsigned sizeFlags = resizable ? (WS_SIZEBOX | WS_MAXIMIZEBOX) : 0u;
+ const bool resizable = view->hints[PUGL_RESIZABLE];
+ const unsigned sizeFlags = resizable ? (WS_SIZEBOX | WS_MAXIMIZEBOX) : 0u;
- return (WS_CLIPCHILDREN | WS_CLIPSIBLINGS |
- (view->parent
- ? WS_CHILD
- : (WS_POPUPWINDOW | WS_CAPTION | WS_MINIMIZEBOX | sizeFlags)));
+ return (WS_CLIPCHILDREN | WS_CLIPSIBLINGS |
+ (view->parent
+ ? WS_CHILD
+ : (WS_POPUPWINDOW | WS_CAPTION | WS_MINIMIZEBOX | sizeFlags)));
}
static inline unsigned
puglWinGetWindowExFlags(const PuglView* const view)
{
- return WS_EX_NOINHERITLAYOUT | (view->parent ? 0u : WS_EX_APPWINDOW);
+ return WS_EX_NOINHERITLAYOUT | (view->parent ? 0u : WS_EX_APPWINDOW);
}
static inline PuglStatus
@@ -90,48 +90,58 @@ puglWinCreateWindow(PuglView* const view,
HWND* const hwnd,
HDC* const hdc)
{
- const char* className = (const char*)view->world->className;
- const unsigned winFlags = puglWinGetWindowFlags(view);
- const unsigned winExFlags = puglWinGetWindowExFlags(view);
-
- if (view->frame.width == 0.0 && view->frame.height == 0.0) {
- if (view->defaultWidth == 0.0 && view->defaultHeight == 0.0) {
- return PUGL_BAD_CONFIGURATION;
- }
-
- RECT desktopRect;
- GetClientRect(GetDesktopWindow(), &desktopRect);
-
- const int screenWidth = desktopRect.right - desktopRect.left;
- const int screenHeight = desktopRect.bottom - desktopRect.top;
-
- view->frame.width = view->defaultWidth;
- view->frame.height = view->defaultHeight;
- view->frame.x = screenWidth / 2.0 - view->frame.width / 2.0;
- view->frame.y = screenHeight / 2.0 - view->frame.height / 2.0;
- }
-
- // The meaning of "parent" depends on the window type (WS_CHILD)
- PuglNativeView parent = view->parent ? view->parent : view->transientParent;
-
- // Calculate total window size to accommodate requested view size
- RECT wr = { (long)view->frame.x, (long)view->frame.y,
- (long)view->frame.width, (long)view->frame.height };
- AdjustWindowRectEx(&wr, winFlags, FALSE, winExFlags);
-
- // Create window and get drawing context
- if (!(*hwnd = CreateWindowEx(winExFlags, className, title, winFlags,
- CW_USEDEFAULT, CW_USEDEFAULT,
- wr.right-wr.left, wr.bottom-wr.top,
- (HWND)parent, NULL, NULL, NULL))) {
- return PUGL_REALIZE_FAILED;
- } else if (!(*hdc = GetDC(*hwnd))) {
- DestroyWindow(*hwnd);
- *hwnd = NULL;
- return PUGL_REALIZE_FAILED;
- }
-
- return PUGL_SUCCESS;
+ const char* className = (const char*)view->world->className;
+ const unsigned winFlags = puglWinGetWindowFlags(view);
+ const unsigned winExFlags = puglWinGetWindowExFlags(view);
+
+ if (view->frame.width == 0.0 && view->frame.height == 0.0) {
+ if (view->defaultWidth == 0.0 && view->defaultHeight == 0.0) {
+ return PUGL_BAD_CONFIGURATION;
+ }
+
+ RECT desktopRect;
+ GetClientRect(GetDesktopWindow(), &desktopRect);
+
+ const int screenWidth = desktopRect.right - desktopRect.left;
+ const int screenHeight = desktopRect.bottom - desktopRect.top;
+
+ view->frame.width = view->defaultWidth;
+ view->frame.height = view->defaultHeight;
+ view->frame.x = screenWidth / 2.0 - view->frame.width / 2.0;
+ view->frame.y = screenHeight / 2.0 - view->frame.height / 2.0;
+ }
+
+ // The meaning of "parent" depends on the window type (WS_CHILD)
+ PuglNativeView parent = view->parent ? view->parent : view->transientParent;
+
+ // Calculate total window size to accommodate requested view size
+ RECT wr = {(long)view->frame.x,
+ (long)view->frame.y,
+ (long)view->frame.width,
+ (long)view->frame.height};
+ AdjustWindowRectEx(&wr, winFlags, FALSE, winExFlags);
+
+ // Create window and get drawing context
+ if (!(*hwnd = CreateWindowEx(winExFlags,
+ className,
+ title,
+ winFlags,
+ CW_USEDEFAULT,
+ CW_USEDEFAULT,
+ wr.right - wr.left,
+ wr.bottom - wr.top,
+ (HWND)parent,
+ NULL,
+ NULL,
+ NULL))) {
+ return PUGL_REALIZE_FAILED;
+ } else if (!(*hdc = GetDC(*hwnd))) {
+ DestroyWindow(*hwnd);
+ *hwnd = NULL;
+ return PUGL_REALIZE_FAILED;
+ }
+
+ return PUGL_SUCCESS;
}
PuglStatus