~aleteoryx/muditaos

ref: 3ed010cfd3df2c66b3ae6f9a7eb5fd3481b26351 muditaos/module-gui/gui/core/BoundingBox.hpp -rw-r--r-- 1.6 KiB
3ed010cf — Artur Śleszyński [EGD-3119] Do not convert InputEvent to numeric if not digit 4 years ago
                                                                                
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
// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#pragma once

#include "Axes.hpp"
#include <cstdint>
#include <string>

namespace gui
{

    /// defines both: size & position
    /// size is always in:     { zero_size < max_size }
    /// position is always in: { min_position < zero_position < max_position }
    class BoundingBox
    {
      public:
        static const uint16_t zero_size;
        static const uint16_t max_size;
        static const uint16_t min_size;

        static const int16_t zero_position;
        static const int16_t max_position;
        static const int16_t min_position;

        struct
        {
            int16_t x = zero_position, y = zero_position;
            uint16_t w = zero_size, h = zero_size;
        };
        BoundingBox(int32_t x = 0, int32_t y = 0, uint32_t w = 0, uint32_t h = 0);
        virtual ~BoundingBox() = default;

        static bool intersect(const BoundingBox &box1, const BoundingBox &box2, BoundingBox &result);

        /// set x,y,w,h to zero
        void clear();
        /// get size in axis - in x get width in y get height
        uint16_t size(gui::Axis axis) const;
        /// get position in axis - in x get x, in y get y
        int16_t pos(gui::Axis axis) const;
        std::string str() const;
        /// logical sum of bounding box by another bounding box values
        void sum(const BoundingBox &box);
        bool operator==(const BoundingBox &box) const;
        bool operator!=(const BoundingBox &box) const;
    };

} /* namespace gui */