27#include <SDL3/SDL_rect.h>
44 SDL_FPoint scale{ 1.0f, 1.0f };
52[[nodiscard]]
inline std::optional<SDL_FPoint>
53sdl_pointer_in_window(
const SDL_FPoint& pos,
const SDL_Rect& source,
const SDL_Rect& target)
55 if (source.w <= 0 || source.h <= 0 || target.w <= 0 || target.h <= 0)
58 const SDL_FPoint local{ pos.x +
static_cast<float>(source.x) -
static_cast<float>(target.x),
59 pos.y +
static_cast<float>(source.y) -
static_cast<float>(target.y) };
60 if (local.x >= 0 && local.y >= 0 && local.x <
static_cast<float>(target.w) &&
61 local.y <
static_cast<float>(target.h))
68[[nodiscard]]
inline SDL_Point sdl_layout_input_origin(
const std::vector<SDL_Rect>& monitors)
71 for (
const auto& monitor : monitors)
73 origin.x = std::min(origin.x, monitor.x);
74 origin.y = std::min(origin.y, monitor.y);
84[[nodiscard]]
inline std::optional<SDL_FPoint>
85sdl_window_to_input(
const std::vector<SdlInputWindow>& windows,
size_t source,
86 const SDL_FPoint& pos,
const SDL_Point& origin)
88 if (source >= windows.size())
91 const auto* target = &windows[source];
93 const auto& bounds = target->local;
94 if ((bounds.w > 0) && (bounds.h > 0) && !sdl_pointer_in_window(pos, bounds, bounds))
96 for (
const auto& window : windows)
98 if (
const auto point = sdl_pointer_in_window(pos, bounds, window.local))
107 if ((target->density <= 0.0f) || (target->scale.x <= 0.0f) || (target->scale.y <= 0.0f))
110 const auto x =
static_cast<float>(target->layout.x - origin.x) +
111 local.x * target->density / target->scale.x;
112 const auto y =
static_cast<float>(target->layout.y - origin.y) +
113 local.y * target->density / target->scale.y;
114 return SDL_FPoint{ x, y };
119[[nodiscard]]
inline SDL_FPoint sdl_window_delta_to_input(
const SdlInputWindow& window,
120 const SDL_FPoint& delta)
122 if ((window.density <= 0.0f) || (window.scale.x <= 0.0f) || (window.scale.y <= 0.0f))
124 return SDL_FPoint{ delta.x * window.density / window.scale.x,
125 delta.y * window.density / window.scale.y };