summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2019-03-03 13:34:50 +0100
committerAndreas Kling <awesomekling@gmail.com>2019-03-03 13:34:50 +0100
commit483e0a55262326846a1f3181ab2642449caf8be7 (patch)
tree9ef138d5d15783f72796f68671ddb2346e8a0d5c
parent0e4b7990c0206d49537bdf317ebeea75b525b46d (diff)
downloadserenity-483e0a55262326846a1f3181ab2642449caf8be7.zip
SharedGraphics: Add Rect::center_within(Rect).
-rw-r--r--SharedGraphics/Rect.h6
1 files changed, 6 insertions, 0 deletions
diff --git a/SharedGraphics/Rect.h b/SharedGraphics/Rect.h
index dc095166f4..86fc790a9e 100644
--- a/SharedGraphics/Rect.h
+++ b/SharedGraphics/Rect.h
@@ -196,6 +196,12 @@ public:
Point bottom_left() const { return { left(), bottom() }; }
Point bottom_right() const { return { right(), bottom() }; }
+ void center_within(const Rect& other)
+ {
+ set_x(other.center().x() - width() / 2);
+ set_y(other.center().y() - height() / 2);
+ }
+
String to_string() const { return String::format("[%d,%d %dx%d]", x(), y(), width(), height()); }
private: