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 #include "anbox/graphics/rect.h"
19 #include "anbox/utils.h"
24 #include <boost/lexical_cast.hpp>
28 const Rect Rect::Invalid{-1, -1, -1, -1};
29 const Rect Rect::Empty{0, 0, 0, 0};
31 void Rect::merge(const Rect &rhs) {
32 left_ = std::min(left_, rhs.left());
33 top_ = std::min(top_, rhs.top());
34 right_ = std::max(right_, rhs.right());
35 bottom_ = std::max(bottom_, rhs.bottom());
38 void Rect::translate(const std::int32_t &x, const std::int32_t &y) {
39 auto old_width = width();
40 auto old_height = height();
43 right_ = x + old_width;
44 bottom_ = y + old_height;
47 void Rect::resize(const std::int32_t &width, const std::int32_t &height) {
48 right_ = left_ + width;
49 bottom_ = top_ + height;
52 std::ostream &operator<<(std::ostream &out, const Rect &rect) {
53 return out << "{" << rect.left() << "," << rect.top() << "," << rect.right()
54 << "," << rect.bottom() << "} {" << rect.width() << ","
55 << rect.height() << "}";
58 std::istream& operator>>(std::istream& in, anbox::graphics::Rect &rect)
62 auto tokens = anbox::utils::string_split(str, ',');
64 switch (tokens.size()) {
66 rect = anbox::graphics::Rect(0, 0,
67 boost::lexical_cast<std::int32_t>(tokens[0]),
68 boost::lexical_cast<std::int32_t>(tokens[1]));
72 rect = anbox::graphics::Rect(
73 boost::lexical_cast<std::int32_t>(tokens[0]),
74 boost::lexical_cast<std::int32_t>(tokens[1]),
75 boost::lexical_cast<std::int32_t>(tokens[2]),
76 boost::lexical_cast<std::int32_t>(tokens[3]));
86 } // namespace graphics