diff --git a/include/Helpers/MathExtras.hpp b/include/Helpers/MathExtras.hpp index 16314a8..0767448 100644 --- a/include/Helpers/MathExtras.hpp +++ b/include/Helpers/MathExtras.hpp @@ -304,7 +304,7 @@ template std::string vec_pretty(const T& a) { return "[]"; std::stringstream ss; ss << "["; - for(size_t i = 0; i < a.size(); i++) { + for(size_t i = 0; i < static_cast(a.size()); i++) { if(i == a.size() - 1) ss << a[i] << "]"; else diff --git a/src/GUIHolder.cpp b/src/GUIHolder.cpp index 31840a7..1c3b8fc 100644 --- a/src/GUIHolder.cpp +++ b/src/GUIHolder.cpp @@ -100,7 +100,7 @@ void GUIHolder::update() { void GUIHolder::window_update() { calculate_final_gui_scale(); - gui.update_window({0, 0}, main.window.size.cast(), final_gui_scale()); + gui.update_window(main.window.safeArea.min, main.window.safeArea.dim(), final_gui_scale()); } float GUIHolder::final_gui_scale() { diff --git a/src/GUIStuff/GUIManager.cpp b/src/GUIStuff/GUIManager.cpp index 4323816..6bb01d0 100644 --- a/src/GUIStuff/GUIManager.cpp +++ b/src/GUIStuff/GUIManager.cpp @@ -72,14 +72,14 @@ void GUIManager::clip_rect_transform(SkCanvas* canvas, std::vector c = clipRect.value(); - c.min += io.windowPos * io.guiScaleMultiplier; - c.max += io.windowPos * io.guiScaleMultiplier; c.min *= io.guiScaleMultiplier; c.max *= io.guiScaleMultiplier; + c.min += io.windowPos; + c.max += io.windowPos; canvas->clipIRect(c.get_sk_irect()); } - canvas->scale(io.guiScaleMultiplier, io.guiScaleMultiplier); canvas->translate(io.windowPos.x(), io.windowPos.y()); + canvas->scale(io.guiScaleMultiplier, io.guiScaleMultiplier); } void GUIManager::draw(SkCanvas* c, bool skiaAA) { @@ -286,8 +286,8 @@ void GUIManager::draw(SkCanvas* c, bool skiaAA) { void GUIManager::draw_force(SkCanvas* canvas, bool skiaAA) { canvas->save(); - canvas->scale(io.guiScaleMultiplier, io.guiScaleMultiplier); canvas->translate(io.windowPos.x(), io.windowPos.y()); + canvas->scale(io.guiScaleMultiplier, io.guiScaleMultiplier); for(size_t i = 0; i < static_cast(renderCommands.length); i++) { Clay_RenderCommand* command = Clay_RenderCommandArray_Get(&renderCommands, i); @@ -692,16 +692,19 @@ void GUIManager::input_key_callback(const InputManager::KeyCallbackArgs& key) { } void GUIManager::input_mouse_button_callback(InputManager::MouseButtonCallbackArgs button) { + button.pos -= io.windowPos; button.pos /= io.guiScaleMultiplier; mouse_callback(button.pos, [&button] (ElementContainer* e) { e->elem->input_mouse_button_callback(button); }); } void GUIManager::input_mouse_motion_callback(InputManager::MouseMotionCallbackArgs motion) { + motion.pos -= io.windowPos; motion.pos /= io.guiScaleMultiplier; mouse_callback(motion.pos, [&motion] (ElementContainer* e) { e->elem->input_mouse_motion_callback(motion); }); } void GUIManager::input_mouse_wheel_callback(InputManager::MouseWheelCallbackArgs wheel) { + wheel.mousePos -= io.windowPos; wheel.mousePos /= io.guiScaleMultiplier; mouse_callback(wheel.mousePos, [&wheel] (ElementContainer* e) { e->elem->input_mouse_wheel_callback(wheel); }); } diff --git a/src/InputManager.cpp b/src/InputManager.cpp index c728f5d..b3bdbb3 100644 --- a/src/InputManager.cpp +++ b/src/InputManager.cpp @@ -816,10 +816,20 @@ void InputManager::backend_touch_finger_motion_update(const SDL_TouchFingerEvent isTouchDevice = true; } -void InputManager::backend_window_resize_update(const SDL_WindowEvent& e) { +void InputManager::update_safe_area() { + SDL_Rect safeArea; + if(SDL_GetWindowSafeArea(main.window.sdlWindow, &safeArea)) + main.window.safeArea = SCollision::AABB({safeArea.x, safeArea.y}, {safeArea.x + safeArea.w, safeArea.y + safeArea.h}); + else + main.window.safeArea = SCollision::AABB({0, 0}, {main.window.size.x(), main.window.size.y()}); +} + +void InputManager::backend_window_resize_update() { + update_safe_area(); WindowResizeCallbackArgs w; - w.size = {e.data1, e.data2}; w.density = main.window.density; + w.size = main.window.size; + w.safeArea = main.window.safeArea; main.input_window_resize_callback(w); } diff --git a/src/InputManager.hpp b/src/InputManager.hpp index c0c433d..b2c0490 100644 --- a/src/InputManager.hpp +++ b/src/InputManager.hpp @@ -274,9 +274,11 @@ struct InputManager { void backend_touch_finger_down_update(const SDL_TouchFingerEvent& e); void backend_touch_finger_up_update(const SDL_TouchFingerEvent& e); void backend_touch_finger_motion_update(const SDL_TouchFingerEvent& e); - void backend_window_resize_update(const SDL_WindowEvent& e); + void backend_window_resize_update(); void backend_window_scale_update(const SDL_WindowEvent& e); + void update_safe_area(); + void set_clipboard_str(std::string_view s); void set_clipboard_plain_and_richtext_pair(const std::pair& plainAndRichtextPair); std::string get_clipboard_str_SDL(); @@ -395,6 +397,7 @@ struct InputManager { struct WindowResizeCallbackArgs { Vector2i size; + SCollision::AABB safeArea; float density; }; diff --git a/src/MainProgram.hpp b/src/MainProgram.hpp index f107692..2a06e71 100644 --- a/src/MainProgram.hpp +++ b/src/MainProgram.hpp @@ -45,6 +45,9 @@ class MainProgram { struct Window { std::chrono::steady_clock::duration lastFrameTime = std::chrono::milliseconds(16); + + SCollision::AABB safeArea; + Vector2i size = {-1, -1}; Vector2i pos = {-1, -1}; Vector2i writtenSize = {-1, -1}; diff --git a/src/main.cpp b/src/main.cpp index 142008e..8748207 100755 --- a/src/main.cpp +++ b/src/main.cpp @@ -520,6 +520,8 @@ SDL_AppResult SDL_AppInit(void **appstate, int argc, char **argv) { SDL_SetWindowFullscreen(mS.window, true); #endif + mS.m->input.update_safe_area(); + mS.m->window.canCreateSurfaces = true; resize_window(mS); @@ -657,7 +659,7 @@ SDL_AppResult SDL_AppEvent(void *appstate, SDL_Event *event) { } resize_window(mS); mS.m->update_scale_and_density(); - mS.m->input.backend_window_resize_update(event->window); + mS.m->input.backend_window_resize_update(); get_refresh_rate(mS); break; case SDL_EVENT_WINDOW_DISPLAY_SCALE_CHANGED: @@ -673,6 +675,10 @@ SDL_AppResult SDL_AppEvent(void *appstate, SDL_Event *event) { mS.m->window.maximized = false; get_refresh_rate(mS); break; + case SDL_EVENT_WINDOW_SAFE_AREA_CHANGED: { + mS.m->input.backend_window_resize_update(); + break; + } case SDL_EVENT_MOUSE_MOTION: #ifdef _WIN32 if(!mS.m->conf.tabletOptions.ignoreMouseMovementWhenPenInProximity || !mS.m->input.pen.inProximity)