From ec97c6d9ca32aa1ba9d3946e79a2857d496b2060 Mon Sep 17 00:00:00 2001 From: martinfouilleul Date: Mon, 28 Aug 2023 17:04:55 +0200 Subject: [PATCH] win32 implementation of oc_surface_bring_to_front/send_to_back --- sketches/multi_surface/build.bat | 2 +- src/app/win32_app.c | 41 ++++++++++++++++++++++++++++---- src/runtime.c | 6 ++--- 3 files changed, 40 insertions(+), 9 deletions(-) diff --git a/sketches/multi_surface/build.bat b/sketches/multi_surface/build.bat index 81c921a..49b55ff 100644 --- a/sketches/multi_surface/build.bat +++ b/sketches/multi_surface/build.bat @@ -3,4 +3,4 @@ set INCLUDES=/I ..\..\src /I ..\..\src\util /I ..\..\src\platform /I ../../ext / if not exist "bin" mkdir bin cl /we4013 /Zi /Zc:preprocessor /std:c11 /experimental:c11atomics %INCLUDES% main.c /link /LIBPATH:../../build/bin orca.dll.lib /out:bin/example_multi_surface.exe -cp ../../build/bin/orca.dll bin/ \ No newline at end of file +copy ..\..\build\bin\orca.dll bin diff --git a/src/app/win32_app.c b/src/app/win32_app.c index 08fbf47..e131178 100644 --- a/src/app/win32_app.c +++ b/src/app/win32_app.c @@ -266,20 +266,35 @@ static void oc_win32_update_child_layers(oc_window_data* window) int clientWidth = (clientRect.right - clientRect.left); int clientHeight = (clientRect.bottom - clientRect.top); + oc_list_for(&window->win32.layers, layer, oc_layer, listElt) + { + SetWindowPos(layer->hWnd, + 0, + point.x, + point.y, + clientWidth, + clientHeight, + SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOZORDER); + } +} + +static void oc_win32_update_child_layers_zorder(oc_window_data* window) +{ HWND insertAfter = window->win32.hWnd; oc_list_for(&window->win32.layers, layer, oc_layer, listElt) { SetWindowPos(layer->hWnd, insertAfter, - point.x, - point.y, - clientWidth, - clientHeight, - SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOZORDER); + 0, 0, 0, 0, + SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE | SWP_NOREDRAW | SWP_NOOWNERZORDER); insertAfter = layer->hWnd; } + SetWindowPos(window->win32.hWnd, + insertAfter, + 0, 0, 0, 0, + SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE | SWP_NOREDRAW); } LRESULT oc_win32_win_proc(HWND windowHandle, UINT message, WPARAM wParam, LPARAM lParam) @@ -1172,6 +1187,20 @@ void oc_win32_surface_set_hidden(oc_surface_data* surface, bool hidden) ShowWindow(surface->layer.hWnd, hidden ? SW_HIDE : SW_NORMAL); } +void oc_win32_surface_bring_to_front(oc_surface_data* surface) +{ + oc_list_remove(&surface->layer.parent->win32.layers, &surface->layer.listElt); + oc_list_push(&surface->layer.parent->win32.layers, &surface->layer.listElt); + oc_win32_update_child_layers_zorder(surface->layer.parent); +} + +void oc_win32_surface_send_to_back(oc_surface_data* surface) +{ + oc_list_remove(&surface->layer.parent->win32.layers, &surface->layer.listElt); + oc_list_push_back(&surface->layer.parent->win32.layers, &surface->layer.listElt); + oc_win32_update_child_layers_zorder(surface->layer.parent); +} + void* oc_win32_surface_native_layer(oc_surface_data* surface) { return ((void*)surface->layer.hWnd); @@ -1227,6 +1256,8 @@ void oc_surface_init_for_window(oc_surface_data* surface, oc_window_data* window surface->getHidden = oc_win32_surface_get_hidden; surface->setHidden = oc_win32_surface_set_hidden; surface->nativeLayer = oc_win32_surface_native_layer; + surface->bringToFront = oc_win32_surface_bring_to_front; + surface->sendToBack = oc_win32_surface_send_to_back; //NOTE(martin): create a child window for the surface WNDCLASS layerWindowClass = { .style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC, diff --git a/src/runtime.c b/src/runtime.c index 2f3d3c8..cfaa115 100644 --- a/src/runtime.c +++ b/src/runtime.c @@ -636,11 +636,11 @@ i32 orca_runloop(void* user) { if(event->key.action == OC_KEY_PRESS) { - if(event->key.code == OC_KEY_D && (event->key.mods & (OC_KEYMOD_SHIFT | OC_KEYMOD_CMD))) + if(event->key.code == OC_KEY_D + && (event->key.mods & OC_KEYMOD_SHIFT) + && (event->key.mods & OC_KEYMOD_MAIN_MODIFIER)) { -#if 1 // EPILEPSY WARNING! on windows this has a bug which causes a pretty strong stroboscopic effect debug_overlay_toggle(&app->debugOverlay); -#endif } if(exports[OC_EXPORT_KEY_DOWN])