TYPE3
[iec.git] / src / type3_AndroidCloud / anbox-master / src / anbox / graphics / rect.h
1 /*
2  * Copyright (C) 2016 Simon Fels <morphis@gravedo.de>
3  *
4  * This program is free software: you can redistribute it and/or modify it
5  * under the terms of the GNU General Public License version 3, as published
6  * by the Free Software Foundation.
7  *
8  * This program is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranties of
10  * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
11  * PURPOSE.  See the GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License along
14  * with this program.  If not, see <http://www.gnu.org/licenses/>.
15  *
16  */
17
18 #ifndef ANBOX_GRAPHICS_RECT_H_
19 #define ANBOX_GRAPHICS_RECT_H_
20
21 #include <cstdint>
22
23 #include <ostream>
24
25 namespace anbox {
26 namespace graphics {
27 class Rect {
28  public:
29   static const Rect Invalid;
30   static const Rect Empty;
31
32   inline Rect() : Rect(Empty) {}
33
34   inline Rect(const std::int32_t &left, const std::int32_t &top,
35               const std::int32_t &right, const std::int32_t &bottom)
36       : left_(left), top_(top), right_(right), bottom_(bottom) {}
37
38   inline Rect(const std::int32_t &width, const std::int32_t &height)
39       : left_(0), top_(0), right_(width), bottom_(height) {}
40
41   inline void clear() { left_ = top_ = right_ = bottom_ = 0; }
42
43   inline bool valid() const { return width() >= 0 && height() >= 0; }
44
45   inline std::int32_t width() const { return right_ - left_; }
46
47   inline std::int32_t height() const { return bottom_ - top_; }
48
49   inline std::int32_t left() const { return left_; }
50
51   inline std::int32_t top() const { return top_; }
52
53   inline std::int32_t right() const { return right_; }
54
55   inline std::int32_t bottom() const { return bottom_; }
56
57   inline bool operator==(const Rect &rhs) const {
58     return (left_ == rhs.left() && top_ == rhs.top() && right_ == rhs.right() &&
59             bottom_ == rhs.bottom());
60   }
61
62   inline bool operator!=(const Rect &rhs) const { return !operator==(rhs); }
63
64   void merge(const Rect &rhs);
65
66   void translate(const std::int32_t &x, const std::int32_t &y);
67
68   void resize(const std::int32_t &width, const std::int32_t &height);
69
70  private:
71   std::int32_t left_;
72   std::int32_t top_;
73   std::int32_t right_;
74   std::int32_t bottom_;
75 };
76
77 std::ostream &operator<<(std::ostream &out, const Rect &rect);
78 std::istream& operator>>(std::istream& in, anbox::graphics::Rect &rect);
79 }  // namespace graphics
80 }  // namespace anbox
81
82 #endif