X-Git-Url: https://gerrit.akraino.org/r/gitweb?a=blobdiff_plain;f=src%2Ftype3_AndroidCloud%2Fanbox-master%2Fsrc%2Fanbox%2Fgraphics%2Frect.cpp;fp=src%2Ftype3_AndroidCloud%2Fanbox-master%2Fsrc%2Fanbox%2Fgraphics%2Frect.cpp;h=d3306c52a57dc0a059c003c9f05c9a9f20d3baa5;hb=e26c1ec581be598521517829adba8c8dd23a768f;hp=0000000000000000000000000000000000000000;hpb=6699c1aea74eeb0eb400e6299079f0c7576f716f;p=iec.git diff --git a/src/type3_AndroidCloud/anbox-master/src/anbox/graphics/rect.cpp b/src/type3_AndroidCloud/anbox-master/src/anbox/graphics/rect.cpp new file mode 100644 index 0000000..d3306c5 --- /dev/null +++ b/src/type3_AndroidCloud/anbox-master/src/anbox/graphics/rect.cpp @@ -0,0 +1,87 @@ +/* + * Copyright (C) 2016 Simon Fels + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3, as published + * by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranties of + * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + * + */ + +#include "anbox/graphics/rect.h" +#include "anbox/utils.h" + +#include +#include + +#include + +namespace anbox { +namespace graphics { +const Rect Rect::Invalid{-1, -1, -1, -1}; +const Rect Rect::Empty{0, 0, 0, 0}; + +void Rect::merge(const Rect &rhs) { + left_ = std::min(left_, rhs.left()); + top_ = std::min(top_, rhs.top()); + right_ = std::max(right_, rhs.right()); + bottom_ = std::max(bottom_, rhs.bottom()); +} + +void Rect::translate(const std::int32_t &x, const std::int32_t &y) { + auto old_width = width(); + auto old_height = height(); + left_ = x; + top_ = y; + right_ = x + old_width; + bottom_ = y + old_height; +} + +void Rect::resize(const std::int32_t &width, const std::int32_t &height) { + right_ = left_ + width; + bottom_ = top_ + height; +} + +std::ostream &operator<<(std::ostream &out, const Rect &rect) { + return out << "{" << rect.left() << "," << rect.top() << "," << rect.right() + << "," << rect.bottom() << "} {" << rect.width() << "," + << rect.height() << "}"; +} + +std::istream& operator>>(std::istream& in, anbox::graphics::Rect &rect) +try { + std::string str; + in >> str; + auto tokens = anbox::utils::string_split(str, ','); + + switch (tokens.size()) { + case 2: { + rect = anbox::graphics::Rect(0, 0, + boost::lexical_cast(tokens[0]), + boost::lexical_cast(tokens[1])); + break; + } + case 4: + rect = anbox::graphics::Rect( + boost::lexical_cast(tokens[0]), + boost::lexical_cast(tokens[1]), + boost::lexical_cast(tokens[2]), + boost::lexical_cast(tokens[3])); + break; + default: + break; + } + + return in; +} catch (...) { + return in; +} +} // namespace graphics +} // namespace anbox