diff options
author | Andreas Kling <kling@serenityos.org> | 2020-04-12 19:16:27 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-04-12 19:23:39 +0200 |
commit | 5c780c9ef759465f8ac72585ab857ff3fe9f41bc (patch) | |
tree | abeb7269cf9462fa4d2c83c7b1c8b88bcd26ad42 /Libraries/LibGfx | |
parent | dd7796515fe34a80c2d2cce2ff0cc6fde41e02b4 (diff) | |
download | serenity-5c780c9ef759465f8ac72585ab857ff3fe9f41bc.zip |
LibGfx: Allow constructing Float{Rect,Point,Size} from integer buddies
Diffstat (limited to 'Libraries/LibGfx')
-rw-r--r-- | Libraries/LibGfx/FloatPoint.h | 8 | ||||
-rw-r--r-- | Libraries/LibGfx/FloatRect.h | 5 | ||||
-rw-r--r-- | Libraries/LibGfx/FloatSize.h | 6 |
3 files changed, 19 insertions, 0 deletions
diff --git a/Libraries/LibGfx/FloatPoint.h b/Libraries/LibGfx/FloatPoint.h index 40d7636df4..9d929639a3 100644 --- a/Libraries/LibGfx/FloatPoint.h +++ b/Libraries/LibGfx/FloatPoint.h @@ -29,6 +29,7 @@ #include <AK/LogStream.h> #include <AK/String.h> #include <LibGfx/Orientation.h> +#include <LibGfx/Point.h> namespace Gfx { @@ -42,6 +43,13 @@ public: , m_y(y) { } + + explicit FloatPoint(const Point& other) + : m_x(other.x()) + , m_y(other.y()) + { + } + float x() const { return m_x; } float y() const { return m_y; } diff --git a/Libraries/LibGfx/FloatRect.h b/Libraries/LibGfx/FloatRect.h index 4b08043db2..39caf90e03 100644 --- a/Libraries/LibGfx/FloatRect.h +++ b/Libraries/LibGfx/FloatRect.h @@ -56,6 +56,11 @@ public: { } + explicit FloatRect(const Rect& other) + : FloatRect((FloatPoint)other.location(), (FloatSize)other.size()) + { + } + bool is_null() const { return width() == 0 && height() == 0; diff --git a/Libraries/LibGfx/FloatSize.h b/Libraries/LibGfx/FloatSize.h index b58a8df84b..02638e5058 100644 --- a/Libraries/LibGfx/FloatSize.h +++ b/Libraries/LibGfx/FloatSize.h @@ -29,6 +29,7 @@ #include <AK/LogStream.h> #include <AK/String.h> #include <LibGfx/Orientation.h> +#include <LibGfx/Size.h> namespace Gfx { @@ -40,6 +41,11 @@ public: , m_height(h) { } + explicit FloatSize(const Size& other) + : m_width(other.width()) + , m_height(other.height()) + { + } bool is_null() const { return !m_width && !m_height; } bool is_empty() const { return m_width <= 0 || m_height <= 0; } |