diff options
Diffstat (limited to 'src/common.c')
-rw-r--r-- | src/common.c | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/common.c b/src/common.c index 74dcf44..249a0d3 100644 --- a/src/common.c +++ b/src/common.c @@ -1,6 +1,27 @@ #include "../include/common.h" +#include <mgl/window/window.h> + +static inline float max_float(float a, float b) { + return a >= b ? a : b; +} + +static inline float min_float(float a, float b) { + return a <= b ? a : b; +} bool mgui_rectangle_contains(mgl_vec2f rectangle_pos, mgl_vec2f rectangle_size, mgl_vec2f point) { return point.x >= rectangle_pos.x && point.x <= rectangle_pos.x + rectangle_size.x && point.y >= rectangle_pos.y && point.y <= rectangle_pos.y + rectangle_size.y; } + +bool mgui_rectangle_intersects_with_scissor(mgl_vec2i rectangle_pos, mgl_vec2i rectangle_size, mgl_window *window) { + mgl_scissor scissor; + mgl_window_get_scissor(window, &scissor); + + const int left_x = max_float(rectangle_pos.x, scissor.position.x); + const int right_x = min_float(rectangle_pos.x + rectangle_size.x, scissor.position.x + scissor.size.x); + const int top_y = max_float(rectangle_pos.y, scissor.position.y); + const int bottom_y = min_float(rectangle_pos.y + rectangle_size.y, scissor.position.y + scissor.size.y); + + return left_x <= right_x && top_y <= bottom_y; +} |