2002-04-13 23:41:36 +00:00
|
|
|
// Geometry.cc for Openbox
|
|
|
|
// Copyright (c) 2002 - 2002 ben Jansens (ben@orodu.net)
|
|
|
|
//
|
|
|
|
// Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
// copy of this software and associated documentation files (the "Software"),
|
|
|
|
// to deal in the Software without restriction, including without limitation
|
|
|
|
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
// and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
// Software is furnished to do so, subject to the following conditions:
|
|
|
|
//
|
|
|
|
// The above copyright notice and this permission notice shall be included in
|
|
|
|
// all copies or substantial portions of the Software.
|
|
|
|
//
|
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
|
|
// DEALINGS IN THE SOFTWARE.
|
|
|
|
|
|
|
|
#include "Geometry.h"
|
|
|
|
|
|
|
|
Point::Point() : m_x(0), m_y(0) {
|
|
|
|
}
|
|
|
|
|
|
|
|
Point::Point(const Point &point) : m_x(point.m_x), m_y(point.m_y) {
|
|
|
|
}
|
|
|
|
|
|
|
|
Point::Point(const int x, const int y) : m_x(x), m_y(y) {
|
|
|
|
}
|
|
|
|
|
2002-04-14 18:28:11 +00:00
|
|
|
void Point::setX(const int x) {
|
2002-04-13 23:41:36 +00:00
|
|
|
m_x = x;
|
|
|
|
}
|
|
|
|
|
2002-04-14 18:28:11 +00:00
|
|
|
void Point::setY(const int y) {
|
2002-04-13 23:41:36 +00:00
|
|
|
m_y = y;
|
|
|
|
}
|
|
|
|
|
|
|
|
Size::Size() : m_w(0), m_h(0) {
|
|
|
|
}
|
|
|
|
|
|
|
|
Size::Size(const Size &size) : m_w(size.m_w), m_h(size.m_h) {
|
|
|
|
}
|
|
|
|
|
2002-04-14 18:48:32 +00:00
|
|
|
Size::Size(const unsigned int w, const unsigned int h) : m_w(w), m_h(h) {
|
2002-04-13 23:41:36 +00:00
|
|
|
}
|
|
|
|
|
2002-04-14 18:48:32 +00:00
|
|
|
void Size::setW(const unsigned int w) {
|
2002-04-13 23:41:36 +00:00
|
|
|
m_w = w;
|
|
|
|
}
|
|
|
|
|
2002-04-14 18:48:32 +00:00
|
|
|
void Size::setH(const unsigned int h) {
|
2002-04-13 23:41:36 +00:00
|
|
|
m_h = h;
|
|
|
|
}
|
|
|
|
|
|
|
|
Rect::Rect() : m_origin(0, 0), m_size(0, 0) {
|
|
|
|
}
|
|
|
|
|
|
|
|
Rect::Rect(const Point &origin, const Size &size) : m_origin(origin),
|
|
|
|
m_size(size) {
|
|
|
|
}
|
|
|
|
|
2002-04-14 18:48:32 +00:00
|
|
|
Rect::Rect(const int x, const int y, const unsigned int w, const unsigned int h)
|
|
|
|
: m_origin(x, y), m_size(w, h) {
|
2002-04-13 23:41:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Rect::setSize(const Size &size) {
|
|
|
|
m_size = size;
|
|
|
|
}
|
|
|
|
|
2002-04-14 19:30:38 +00:00
|
|
|
void Rect::setSize(const unsigned int w, const unsigned int h) {
|
|
|
|
m_size.setW(w);
|
|
|
|
m_size.setH(h);
|
|
|
|
}
|
|
|
|
|
2002-04-13 23:41:36 +00:00
|
|
|
void Rect::setOrigin(const Point &origin) {
|
|
|
|
m_origin = origin;
|
|
|
|
}
|
|
|
|
|
2002-04-14 19:30:38 +00:00
|
|
|
void Rect::setOrigin(const int x, const int y) {
|
|
|
|
m_origin.setX(x);
|
|
|
|
m_origin.setY(y);
|
|
|
|
}
|
|
|
|
|
2002-04-13 23:41:36 +00:00
|
|
|
void Rect::setX(const int x) {
|
|
|
|
m_origin.setX(x);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Rect::setY(const int y) {
|
|
|
|
m_origin.setY(y);
|
|
|
|
}
|
|
|
|
|
2002-04-14 18:48:32 +00:00
|
|
|
void Rect::setW(unsigned int w) {
|
2002-04-13 23:41:36 +00:00
|
|
|
m_size.setW(w);
|
|
|
|
}
|
|
|
|
|
2002-04-14 18:48:32 +00:00
|
|
|
void Rect::setH(unsigned int h) {
|
2002-04-13 23:41:36 +00:00
|
|
|
m_size.setH(h);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Rect::Intersect(const Rect &r) const {
|
|
|
|
return
|
|
|
|
(x() < (r.x()+r.w()) ) &&
|
|
|
|
( (x()+w()) > r.x()) &&
|
|
|
|
(y() < (r.y()+r.h()) ) &&
|
|
|
|
( (y()+h()) > r.y());
|
|
|
|
}
|
2002-04-18 18:11:33 +00:00
|
|
|
|
|
|
|
Rect Rect::Inflate(const unsigned int i) const {
|
|
|
|
return Rect(x(), y(), w()+i, h()+i);
|
|
|
|
}
|
|
|
|
|
|
|
|
Rect Rect::Inflate(const unsigned int iw, const unsigned int ih) const {
|
|
|
|
return Rect(x(), y(), w()+iw, h()+ih);
|
|
|
|
}
|
|
|
|
|
|
|
|
Rect Rect::Inflate(const Size &i) const {
|
|
|
|
return Rect(x(), y(), w()+i.w(), h()+i.h());
|
|
|
|
}
|
|
|
|
|
|
|
|
Rect Rect::Deflate(const unsigned int d) const {
|
|
|
|
return Rect(x(), y(), w()-d, h()-d);
|
|
|
|
}
|
|
|
|
|
|
|
|
Rect Rect::Deflate(const unsigned int dw, const unsigned int dh) const {
|
|
|
|
return Rect(x(), y(), w()-dw, h()-dh);
|
|
|
|
}
|
|
|
|
|
|
|
|
Rect Rect::Deflate(const Size &d) const {
|
|
|
|
return Rect(x(), y(), w()-d.w(), h()-d.h());
|
|
|
|
}
|
|
|
|
|
|
|
|
Rect Rect::Translate(const int t) const {
|
|
|
|
return Rect(x()+t, y()+t, w(), h());
|
|
|
|
}
|
|
|
|
|
|
|
|
Rect Rect::Translate(const int tx, const int ty) const {
|
|
|
|
return Rect(x()+tx, y()+ty, w(), h());
|
|
|
|
}
|
|
|
|
|
|
|
|
Rect Rect::Translate(const Point &t) const {
|
|
|
|
return Rect(x()+t.x(), y()+t.y(), w(), h());
|
|
|
|
}
|