Readded SDL safe area calculations to GUI
This commit is contained in:
parent
6312fc264e
commit
3061c604c5
7 changed files with 35 additions and 10 deletions
|
|
@ -304,7 +304,7 @@ template <typename T> 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<size_t>(a.size()); i++) {
|
||||
if(i == a.size() - 1)
|
||||
ss << a[i] << "]";
|
||||
else
|
||||
|
|
|
|||
|
|
@ -100,7 +100,7 @@ void GUIHolder::update() {
|
|||
|
||||
void GUIHolder::window_update() {
|
||||
calculate_final_gui_scale();
|
||||
gui.update_window({0, 0}, main.window.size.cast<float>(), final_gui_scale());
|
||||
gui.update_window(main.window.safeArea.min, main.window.safeArea.dim(), final_gui_scale());
|
||||
}
|
||||
|
||||
float GUIHolder::final_gui_scale() {
|
||||
|
|
|
|||
|
|
@ -72,14 +72,14 @@ void GUIManager::clip_rect_transform(SkCanvas* canvas, std::vector<SCollision::A
|
|||
calculate_new_clip_rect(clipRectStack, clipRect, clipNoDraw);
|
||||
if(clipRect.has_value()) {
|
||||
SCollision::AABB<float> 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<size_t>(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); });
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<float>({safeArea.x, safeArea.y}, {safeArea.x + safeArea.w, safeArea.y + safeArea.h});
|
||||
else
|
||||
main.window.safeArea = SCollision::AABB<float>({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);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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<std::string, RichText::TextData>& plainAndRichtextPair);
|
||||
std::string get_clipboard_str_SDL();
|
||||
|
|
@ -395,6 +397,7 @@ struct InputManager {
|
|||
|
||||
struct WindowResizeCallbackArgs {
|
||||
Vector2i size;
|
||||
SCollision::AABB<float> safeArea;
|
||||
float density;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -45,6 +45,9 @@ class MainProgram {
|
|||
|
||||
struct Window {
|
||||
std::chrono::steady_clock::duration lastFrameTime = std::chrono::milliseconds(16);
|
||||
|
||||
SCollision::AABB<float> safeArea;
|
||||
|
||||
Vector2i size = {-1, -1};
|
||||
Vector2i pos = {-1, -1};
|
||||
Vector2i writtenSize = {-1, -1};
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue