summaryrefslogtreecommitdiff
path: root/src/helpers
diff options
context:
space:
mode:
authorVaxry <43317083+vaxerski@users.noreply.github.com>2023-11-11 14:37:17 +0000
committerGitHub <noreply@github.com>2023-11-11 14:37:17 +0000
commit9be6fbf5eae8c4b902b818881a4dc34f87bb630d (patch)
treea5d440cd8f5d57a659df670548263eba1cd93a0a /src/helpers
parent7345b1a1ea2671953df48c8a18524a7e556d383c (diff)
decorations: Decoration Positioner (#3800)
Diffstat (limited to 'src/helpers')
-rw-r--r--src/helpers/Box.cpp13
-rw-r--r--src/helpers/Box.hpp35
-rw-r--r--src/helpers/Region.cpp9
-rw-r--r--src/helpers/Region.hpp3
-rw-r--r--src/helpers/Vector2D.cpp4
-rw-r--r--src/helpers/Vector2D.hpp1
6 files changed, 46 insertions, 19 deletions
diff --git a/src/helpers/Box.cpp b/src/helpers/Box.cpp
index 55300f5f..29aa81fa 100644
--- a/src/helpers/Box.cpp
+++ b/src/helpers/Box.cpp
@@ -96,6 +96,15 @@ CBox& CBox::scaleFromCenter(double scale) {
return *this;
}
+CBox& CBox::expand(const double& value) {
+ x -= value;
+ y -= value;
+ w += value * 2.0;
+ h += value * 2.0;
+
+ return *this;
+}
+
CBox CBox::roundInternal() {
float newW = x + w - std::floor(x);
float newH = y + h - std::floor(y);
@@ -110,3 +119,7 @@ Vector2D CBox::pos() const {
Vector2D CBox::size() const {
return {w, h};
}
+
+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)}};
+}
diff --git a/src/helpers/Box.hpp b/src/helpers/Box.hpp
index 592bb417..cb07df06 100644
--- a/src/helpers/Box.hpp
+++ b/src/helpers/Box.hpp
@@ -39,26 +39,29 @@ class CBox {
h = size.y;
}
- wlr_box wlr();
- wlr_box* pWlr();
+ wlr_box wlr();
+ wlr_box* pWlr();
- CBox& applyFromWlr();
- CBox& scale(double scale);
- CBox& scaleFromCenter(double scale);
- CBox& scale(const Vector2D& scale);
- CBox& translate(const Vector2D& vec);
- CBox& round();
- CBox& transform(const wl_output_transform t, double w, double h);
- CBox& addExtents(const SWindowDecorationExtents& e);
+ CBox& applyFromWlr();
+ CBox& scale(double scale);
+ CBox& scaleFromCenter(double scale);
+ CBox& scale(const Vector2D& scale);
+ CBox& translate(const Vector2D& vec);
+ CBox& round();
+ CBox& transform(const wl_output_transform t, double w, double h);
+ CBox& addExtents(const SWindowDecorationExtents& e);
+ CBox& expand(const double& value);
- Vector2D middle() const;
- Vector2D pos() const;
- Vector2D size() const;
+ SWindowDecorationExtents extentsFrom(const CBox&); // this is the big box
- bool containsPoint(const Vector2D& vec) const;
- bool empty() const;
+ Vector2D middle() const;
+ Vector2D pos() const;
+ Vector2D size() const;
- double x = 0, y = 0;
+ bool containsPoint(const Vector2D& vec) const;
+ bool empty() const;
+
+ double x = 0, y = 0;
union {
double w;
double width;
diff --git a/src/helpers/Region.cpp b/src/helpers/Region.cpp
index fdf8a242..06b8536c 100644
--- a/src/helpers/Region.cpp
+++ b/src/helpers/Region.cpp
@@ -21,8 +21,8 @@ CRegion::CRegion(wlr_box* box) {
pixman_region32_init_rect(&m_rRegion, box->x, box->y, box->width, box->height);
}
-CRegion::CRegion(CBox* box) {
- pixman_region32_init_rect(&m_rRegion, box->x, box->y, box->w, box->h);
+CRegion::CRegion(const CBox& box) {
+ pixman_region32_init_rect(&m_rRegion, box.x, box.y, box.w, box.h);
}
CRegion::CRegion(pixman_box32_t* box) {
@@ -63,6 +63,11 @@ CRegion& CRegion::add(double x, double y, double w, double h) {
return *this;
}
+CRegion& CRegion::add(const CBox& other) {
+ pixman_region32_union_rect(&m_rRegion, &m_rRegion, other.x, other.y, other.w, other.h);
+ return *this;
+}
+
CRegion& CRegion::subtract(const CRegion& other) {
pixman_region32_subtract(&m_rRegion, &m_rRegion, const_cast<CRegion*>(&other)->pixman());
return *this;
diff --git a/src/helpers/Region.hpp b/src/helpers/Region.hpp
index 80153cff..1c6923df 100644
--- a/src/helpers/Region.hpp
+++ b/src/helpers/Region.hpp
@@ -17,7 +17,7 @@ class CRegion {
/* Create from a wlr_box */
CRegion(wlr_box* box);
/* Create from a CBox */
- CRegion(CBox* box);
+ CRegion(const CBox& box);
/* Create from a pixman_box32_t */
CRegion(pixman_box32_t* box);
@@ -40,6 +40,7 @@ class CRegion {
CRegion& set(const CRegion& other);
CRegion& add(const CRegion& other);
CRegion& add(double x, double y, double w, double h);
+ CRegion& add(const CBox& other);
CRegion& subtract(const CRegion& other);
CRegion& intersect(const CRegion& other);
CRegion& intersect(double x, double y, double w, double h);
diff --git a/src/helpers/Vector2D.cpp b/src/helpers/Vector2D.cpp
index ae2484b3..7bc6412d 100644
--- a/src/helpers/Vector2D.cpp
+++ b/src/helpers/Vector2D.cpp
@@ -28,6 +28,10 @@ Vector2D Vector2D::floor() const {
return Vector2D(std::floor(x), std::floor(y));
}
+Vector2D Vector2D::round() const {
+ return Vector2D(std::round(x), std::round(y));
+}
+
Vector2D Vector2D::clamp(const Vector2D& min, const Vector2D& max) const {
return Vector2D(std::clamp(this->x, min.x, max.x < min.x ? INFINITY : max.x), std::clamp(this->y, min.y, max.y < min.y ? INFINITY : max.y));
}
diff --git a/src/helpers/Vector2D.hpp b/src/helpers/Vector2D.hpp
index 17415289..c79c967c 100644
--- a/src/helpers/Vector2D.hpp
+++ b/src/helpers/Vector2D.hpp
@@ -61,6 +61,7 @@ class Vector2D {
Vector2D clamp(const Vector2D& min, const Vector2D& max = Vector2D()) const;
Vector2D floor() const;
+ Vector2D round() const;
bool inTriangle(const Vector2D& p1, const Vector2D& p2, const Vector2D& p3) const;
};