From 2a14ba99a77894a42af1551013269aed840fc3d1 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sat, 20 Jul 2019 22:16:40 +0200 Subject: [PATCH] LibDraw: Add orientation-based size helpers to Size as well. Now you can ask for e.g Size::primary_size_for_orientation(Orientation). --- Libraries/LibDraw/Rect.h | 29 ++++------------------------- Libraries/LibDraw/Size.h | 27 +++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 25 deletions(-) diff --git a/Libraries/LibDraw/Rect.h b/Libraries/LibDraw/Rect.h index af81bbc294..363f491b11 100644 --- a/Libraries/LibDraw/Rect.h +++ b/Libraries/LibDraw/Rect.h @@ -138,31 +138,10 @@ public: int secondary_offset_for_orientation(Orientation orientation) const { return m_location.secondary_offset_for_orientation(orientation); } void set_secondary_offset_for_orientation(Orientation orientation, int value) { m_location.set_secondary_offset_for_orientation(orientation, value); } - 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); - } + int primary_size_for_orientation(Orientation orientation) const { return m_size.primary_size_for_orientation(orientation); } + int secondary_size_for_orientation(Orientation orientation) const { return m_size.secondary_size_for_orientation(orientation); } + void set_primary_size_for_orientation(Orientation orientation, int value) { m_size.set_primary_size_for_orientation(orientation, value); } + void set_secondary_size_for_orientation(Orientation orientation, int value) { m_size.set_secondary_size_for_orientation(orientation, value); } int first_edge_for_orientation(Orientation orientation) const { 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 #include +#include 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); }