summaryrefslogtreecommitdiff
path: root/Libraries/LibDraw/Size.h
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2019-07-20 22:16:40 +0200
committerAndreas Kling <awesomekling@gmail.com>2019-07-20 22:16:40 +0200
commit2a14ba99a77894a42af1551013269aed840fc3d1 (patch)
treefbcfd353d73d57805fb3978f56ad0b365f280a72 /Libraries/LibDraw/Size.h
parentc59b053ad6197f94a14b0690654684170dc6d85d (diff)
downloadserenity-2a14ba99a77894a42af1551013269aed840fc3d1.zip
LibDraw: Add orientation-based size helpers to Size as well.
Now you can ask for e.g Size::primary_size_for_orientation(Orientation).
Diffstat (limited to 'Libraries/LibDraw/Size.h')
-rw-r--r--Libraries/LibDraw/Size.h27
1 files changed, 27 insertions, 0 deletions
diff --git a/Libraries/LibDraw/Size.h b/Libraries/LibDraw/Size.h
index a499dbc2fd..a9209ab448 100644
--- a/Libraries/LibDraw/Size.h
+++ b/Libraries/LibDraw/Size.h
@@ -2,6 +2,7 @@
#include <AK/AKString.h>
#include <AK/LogStream.h>
+#include <LibDraw/Orientation.h>
struct WSAPI_Size;
@@ -50,6 +51,32 @@ public:
return *this;
}
+ int primary_size_for_orientation(Orientation orientation) const
+ {
+ return orientation == Orientation::Vertical ? height() : width();
+ }
+
+ void set_primary_size_for_orientation(Orientation orientation, int value)
+ {
+ if (orientation == Orientation::Vertical)
+ set_height(value);
+ else
+ set_width(value);
+ }
+
+ int secondary_size_for_orientation(Orientation orientation) const
+ {
+ return orientation == Orientation::Vertical ? width() : height();
+ }
+
+ void set_secondary_size_for_orientation(Orientation orientation, int value)
+ {
+ if (orientation == Orientation::Vertical)
+ set_width(value);
+ else
+ set_height(value);
+ }
+
operator WSAPI_Size() const;
String to_string() const { return String::format("[%dx%d]", m_width, m_height); }