summaryrefslogtreecommitdiff
path: root/LibGUI
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2019-04-11 22:52:34 +0200
committerAndreas Kling <awesomekling@gmail.com>2019-04-11 22:52:34 +0200
commitc425bc2e7141faa6d17ce5bf991eae96fd4fb59d (patch)
tree4197b5bc9c12571a50540d6c5412cfc4e4054508 /LibGUI
parentec841f3a23cd754033930b543b98f543eef97460 (diff)
downloadserenity-c425bc2e7141faa6d17ce5bf991eae96fd4fb59d.zip
GVariant: Add Point, Size and Rect variant types.
Diffstat (limited to 'LibGUI')
-rw-r--r--LibGUI/GVariant.cpp44
-rw-r--r--LibGUI/GVariant.h42
2 files changed, 86 insertions, 0 deletions
diff --git a/LibGUI/GVariant.cpp b/LibGUI/GVariant.cpp
index 0e9373aaba..958d66ad38 100644
--- a/LibGUI/GVariant.cpp
+++ b/LibGUI/GVariant.cpp
@@ -67,6 +67,24 @@ GVariant::GVariant(Color color)
m_value.as_color = color.value();
}
+GVariant::GVariant(const Point& point)
+ : m_type(Type::Point)
+{
+ m_value.as_point = { point.x(), point.y() };
+}
+
+GVariant::GVariant(const Size& size)
+ : m_type(Type::Size)
+{
+ m_value.as_size = { size.width(), size.height() };
+}
+
+GVariant::GVariant(const Rect& rect)
+ : m_type(Type::Rect)
+{
+ m_value.as_rect = (const RawRect&)rect;
+}
+
GVariant::GVariant(const GVariant& other)
: m_type(other.m_type)
{
@@ -95,6 +113,15 @@ GVariant::GVariant(const GVariant& other)
case Type::Color:
m_value.as_color = other.m_value.as_color;
break;
+ case Type::Point:
+ m_value.as_point = other.m_value.as_point;
+ break;
+ case Type::Size:
+ m_value.as_size = other.m_value.as_size;
+ break;
+ case Type::Rect:
+ m_value.as_rect = other.m_value.as_rect;
+ break;
case Type::Invalid:
break;
}
@@ -119,6 +146,12 @@ bool GVariant::operator==(const GVariant& other) const
return m_value.as_icon == other.m_value.as_icon;
case Type::Color:
return m_value.as_color == other.m_value.as_color;
+ case Type::Point:
+ return as_point() == other.as_point();
+ case Type::Size:
+ return as_size() == other.as_size();
+ case Type::Rect:
+ return as_rect() == other.as_rect();
case Type::Invalid:
break;
}
@@ -146,6 +179,11 @@ bool GVariant::operator<(const GVariant& other) const
return m_value.as_icon < other.m_value.as_icon;
case Type::Color:
return m_value.as_color < other.m_value.as_color;
+ case Type::Point:
+ case Type::Size:
+ case Type::Rect:
+ // FIXME: Figure out how to compare these.
+ ASSERT_NOT_REACHED();
case Type::Invalid:
break;
}
@@ -169,6 +207,12 @@ String GVariant::to_string() const
return "[GIcon]";
case Type::Color:
return as_color().to_string();
+ case Type::Point:
+ return as_point().to_string();
+ case Type::Size:
+ return as_size().to_string();
+ case Type::Rect:
+ return as_rect().to_string();
case Type::Invalid:
break;
}
diff --git a/LibGUI/GVariant.h b/LibGUI/GVariant.h
index 05b28a3564..83a97008a3 100644
--- a/LibGUI/GVariant.h
+++ b/LibGUI/GVariant.h
@@ -13,6 +13,9 @@ public:
GVariant(const String&);
GVariant(const GraphicsBitmap&);
GVariant(const GIcon&);
+ GVariant(const Point&);
+ GVariant(const Size&);
+ GVariant(const Rect&);
GVariant(Color);
GVariant(const GVariant&);
@@ -27,6 +30,9 @@ public:
Bitmap,
Color,
Icon,
+ Point,
+ Size,
+ Rect,
};
bool is_valid() const { return m_type != Type::Invalid; }
@@ -37,6 +43,9 @@ public:
bool is_bitmap() const { return m_type == Type::Bitmap; }
bool is_color() const { return m_type == Type::Color; }
bool is_icon() const { return m_type == Type::Icon; }
+ bool is_point() const { return m_type == Type::Point; }
+ bool is_size() const { return m_type == Type::Size; }
+ bool is_rect() const { return m_type == Type::Rect; }
Type type() const { return m_type; }
bool as_bool() const
@@ -57,6 +66,21 @@ public:
return m_value.as_float;
}
+ Point as_point() const
+ {
+ return { m_value.as_point.x, m_value.as_point.y };
+ }
+
+ Size as_size() const
+ {
+ return { m_value.as_size.width, m_value.as_size.height };
+ }
+
+ Rect as_rect() const
+ {
+ return { as_point(), as_size() };
+ }
+
String as_string() const
{
ASSERT(type() == Type::String);
@@ -94,6 +118,21 @@ public:
bool operator<(const GVariant&) const;
private:
+ struct RawPoint {
+ int x;
+ int y;
+ };
+
+ struct RawSize {
+ int width;
+ int height;
+ };
+
+ struct RawRect {
+ RawPoint location;
+ RawSize size;
+ };
+
union {
StringImpl* as_string;
GraphicsBitmap* as_bitmap;
@@ -102,6 +141,9 @@ private:
int as_int;
float as_float;
RGBA32 as_color;
+ RawPoint as_point;
+ RawSize as_size;
+ RawRect as_rect;
} m_value;
Type m_type { Type::Invalid };