From ed411f53bdcf8d455f9e6ca769693aa84dc8372f Mon Sep 17 00:00:00 2001 From: Vaxry Date: Sun, 5 May 2024 22:18:10 +0100 Subject: cursor: move to a hyprland impl This moves wlr_cursor to a completely new impl mostly under CPointerManager Also adds beginSimple to OpenGL for simple render passes (e.g. cursor) --- src/helpers/Box.cpp | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'src/helpers/Box.cpp') diff --git a/src/helpers/Box.cpp b/src/helpers/Box.cpp index 8470b509..77406ecf 100644 --- a/src/helpers/Box.cpp +++ b/src/helpers/Box.cpp @@ -121,7 +121,7 @@ CBox& CBox::noNegativeSize() { return *this; } -CBox CBox::intersection(const CBox other) const { +CBox CBox::intersection(const CBox& other) const { const float newX = std::max(x, other.x); const float newY = std::max(y, other.y); const float newBottom = std::min(y + h, other.y + other.h); @@ -137,6 +137,14 @@ CBox CBox::intersection(const CBox other) const { return {newX, newY, newW, newH}; } +bool CBox::overlaps(const CBox& other) const { + return (other.x + other.w >= x) && (x + w >= other.x) && (other.y + other.h >= y) && (y + h >= other.y); +} + +bool CBox::inside(const CBox& bound) const { + return bound.x < x && bound.y < y && x + w < bound.x + bound.w && y + h < bound.y + bound.h; +} + CBox CBox::roundInternal() { float newW = x + w - std::floor(x); float newH = y + h - std::floor(y); @@ -156,6 +164,16 @@ Vector2D CBox::size() const { return {w, h}; } +Vector2D CBox::closestPoint(const Vector2D& vec) const { + if (containsPoint(vec)) + return vec; + + Vector2D nv = vec; + nv.x = std::clamp(nv.x, x, x + w); + nv.y = std::clamp(nv.y, y, y + h); + return nv; +} + SWindowDecorationExtents CBox::extentsFrom(const CBox& small) { return {{small.x - x, small.y - y}, {w - small.w - (small.x - x), h - small.h - (small.y - y)}}; } -- cgit v1.2.3