diff options
author | Andreas Kling <awesomekling@gmail.com> | 2018-10-10 20:06:58 +0200 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2018-10-10 20:06:58 +0200 |
commit | 77bac7216cbd3bc102f53bec594b9178fc139655 (patch) | |
tree | 8e586e7078fe3c567a7d8535ead8e9bd37ff6aa1 /Widgets/Rect.h | |
parent | 6f37429f5744066e28a1dbfdd30d6406ec653c27 (diff) | |
download | serenity-77bac7216cbd3bc102f53bec594b9178fc139655.zip |
More rage hacking on Widgets. Some very basic text drawing. :^)
Diffstat (limited to 'Widgets/Rect.h')
-rw-r--r-- | Widgets/Rect.h | 36 |
1 files changed, 21 insertions, 15 deletions
diff --git a/Widgets/Rect.h b/Widgets/Rect.h index 7726dbc718..8316f6fc98 100644 --- a/Widgets/Rect.h +++ b/Widgets/Rect.h @@ -1,11 +1,12 @@ #pragma once +#include "Point.h" + class Rect { public: Rect() { } Rect(int x, int y, int width, int height) - : m_x(x) - , m_y(y) + : m_location(x, y) , m_width(width) , m_height(height) { @@ -13,33 +14,38 @@ public: void moveBy(int dx, int dy) { - m_x += dx; - m_y += dy; + m_location.moveBy(dx, dy); } bool contains(int x, int y) const { - return x >= m_x && x <= right() && y >= m_y && y <= bottom(); + return x >= m_location.x() && x <= right() && y >= m_location.y() && y <= bottom(); } - int left() const { return m_x; } - int right() const { return m_x + m_width; } - int top() const { return m_y; } - int bottom() const { return m_y + m_height; } + bool contains(const Point& point) const + { + return contains(point.x(), point.y()); + } - int x() const { return m_x; } - int y() const { return m_y; } + int left() const { return x(); } + int right() const { return x() + width(); } + int top() const { return y(); } + int bottom() const { return y() + height(); } + + int x() const { return location().x(); } + int y() const { return location().y(); } int width() const { return m_width; } int height() const { return m_height; } - void setX(int x) { m_x = x; } - void setY(int y) { m_y = y; } + void setX(int x) { m_location.setX(x); } + void setY(int y) { m_location.setY(y); } void setWidth(int width) { m_width = width; } void setHeight(int height) { m_height = height; } + Point location() const { return m_location; } + private: - int m_x { 0 }; - int m_y { 0 }; + Point m_location; int m_width { 0 }; int m_height { 0 }; }; |