summaryrefslogtreecommitdiff
path: root/src/helpers/Box.hpp
blob: 98ba8d47faaf24024e1fb545fef4541fd98d4f55 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#pragma once

#include "Vector2D.hpp"
#include "../SharedDefs.hpp"
#include "../includes.hpp"

class CBox {
  public:
    CBox(double x_, double y_, double w_, double h_) {
        x = x_;
        y = y_;
        w = w_;
        h = h_;
    }

    CBox() {
        w = 0;
        h = 0;
    }

    CBox(const wlr_box& box) {
        x = box.x;
        y = box.y;
        w = box.width;
        h = box.height;
    }

    CBox(const double d) {
        x = d;
        y = d;
        w = d;
        h = d;
    }

    CBox(const Vector2D& pos, const Vector2D& size) {
        x = pos.x;
        y = pos.y;
        w = size.x;
        h = size.y;
    }

    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&                    expand(const double& value);
    CBox&                    noNegativeSize();

    CBox                     copy() const;
    CBox                     intersection(const CBox other) const;

    SWindowDecorationExtents extentsFrom(const CBox&); // this is the big box

    Vector2D                 middle() const;
    Vector2D                 pos() const;
    Vector2D                 size() const;

    bool                     containsPoint(const Vector2D& vec) const;
    bool                     empty() const;

    double                   x = 0, y = 0;
    union {
        double w;
        double width;
    };
    union {
        double h;
        double height;
    };

    double rot = 0; /* rad, ccw */

    //
    bool operator==(const CBox& rhs) const {
        return x == rhs.x && y == rhs.y && w == rhs.w && h == rhs.h;
    }

  private:
    CBox    roundInternal();

    wlr_box m_bWlrBox;
};