aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/helpers/Region.hpp
blob: 27f460f455c4a3c37d31edcb1f34d17dcf75cbc2 (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
#pragma once
#include <pixman.h>
#include <vector>
#include "Vector2D.hpp"
#include "Box.hpp"

struct wlr_box;

class CRegion {
  public:
    /* Create an empty region */
    CRegion();
    /* Create from a reference. Copies, does not own. */
    CRegion(const pixman_region32_t* const ref);
    /* Create from a box */
    CRegion(double x, double y, double w, double h);
    /* Create from a wlr_box */
    CRegion(wlr_box* box);
    /* Create from a CBox */
    CRegion(const CBox& box);
    /* Create from a pixman_box32_t */
    CRegion(pixman_box32_t* box);

    CRegion(const CRegion&);
    CRegion(CRegion&&);

    ~CRegion();

    CRegion& operator=(CRegion&& other) {
        pixman_region32_copy(&m_rRegion, other.pixman());
        return *this;
    }

    CRegion& operator=(CRegion& other) {
        pixman_region32_copy(&m_rRegion, other.pixman());
        return *this;
    }

    CRegion&                    clear();
    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);
    CRegion&                    translate(const Vector2D& vec);
    CRegion&                    transform(const wl_output_transform t, double w, double h);
    CRegion&                    invert(pixman_box32_t* box);
    CRegion&                    invert(const CBox& box);
    CRegion&                    scale(float scale);
    CRegion&                    scale(const Vector2D& scale);
    CBox                        getExtents();
    bool                        containsPoint(const Vector2D& vec) const;
    bool                        empty() const;
    Vector2D                    closestPoint(const Vector2D& vec) const;
    CRegion                     copy() const;

    std::vector<pixman_box32_t> getRects() const;

    //
    pixman_region32_t* pixman() {
        return &m_rRegion;
    }

  private:
    pixman_region32_t m_rRegion;
};