2 * Copyright (C) 2016 Simon Fels <morphis@gravedo.de>
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.
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.
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/>.
18 #ifndef ANBOX_GRAPHICS_RECT_H_
19 #define ANBOX_GRAPHICS_RECT_H_
29 static const Rect Invalid;
30 static const Rect Empty;
32 inline Rect() : Rect(Empty) {}
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) {}
38 inline Rect(const std::int32_t &width, const std::int32_t &height)
39 : left_(0), top_(0), right_(width), bottom_(height) {}
41 inline void clear() { left_ = top_ = right_ = bottom_ = 0; }
43 inline bool valid() const { return width() >= 0 && height() >= 0; }
45 inline std::int32_t width() const { return right_ - left_; }
47 inline std::int32_t height() const { return bottom_ - top_; }
49 inline std::int32_t left() const { return left_; }
51 inline std::int32_t top() const { return top_; }
53 inline std::int32_t right() const { return right_; }
55 inline std::int32_t bottom() const { return bottom_; }
57 inline bool operator==(const Rect &rhs) const {
58 return (left_ == rhs.left() && top_ == rhs.top() && right_ == rhs.right() &&
59 bottom_ == rhs.bottom());
62 inline bool operator!=(const Rect &rhs) const { return !operator==(rhs); }
64 void merge(const Rect &rhs);
66 void translate(const std::int32_t &x, const std::int32_t &y);
68 void resize(const std::int32_t &width, const std::int32_t &height);
77 std::ostream &operator<<(std::ostream &out, const Rect &rect);
78 std::istream& operator>>(std::istream& in, anbox::graphics::Rect &rect);
79 } // namespace graphics