mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 19:57:35 +00:00
GVariant: Add to_bool(), to_int() and to_color().
This commit is contained in:
parent
4df360be8c
commit
0f4050903d
2 changed files with 37 additions and 0 deletions
|
@ -60,12 +60,40 @@ public:
|
|||
return m_value.as_bool;
|
||||
}
|
||||
|
||||
bool to_bool() const
|
||||
{
|
||||
if (type() == Type::Bool)
|
||||
return as_bool();
|
||||
if (type() == Type::String)
|
||||
return !!m_value.as_string;
|
||||
if (type() == Type::Int)
|
||||
return m_value.as_int != 0;
|
||||
if (type() == Type::Rect)
|
||||
return !as_rect().is_null();
|
||||
if (type() == Type::Size)
|
||||
return !as_size().is_null();
|
||||
if (type() == Type::Point)
|
||||
return !as_point().is_null();
|
||||
return is_valid();
|
||||
}
|
||||
|
||||
int as_int() const
|
||||
{
|
||||
ASSERT(type() == Type::Int);
|
||||
return m_value.as_int;
|
||||
}
|
||||
|
||||
int to_int() const
|
||||
{
|
||||
if (is_int())
|
||||
return as_int();
|
||||
if (is_bool())
|
||||
return as_bool() ? 1 : 0;
|
||||
if (is_float())
|
||||
return (int)as_float();
|
||||
return 0;
|
||||
}
|
||||
|
||||
float as_float() const
|
||||
{
|
||||
ASSERT(type() == Type::Float);
|
||||
|
@ -111,6 +139,13 @@ public:
|
|||
return Color::from_rgba(m_value.as_color);
|
||||
}
|
||||
|
||||
Color to_color() const
|
||||
{
|
||||
if (is_color())
|
||||
return as_color();
|
||||
return Color();
|
||||
}
|
||||
|
||||
Color to_color(Color default_value) const
|
||||
{
|
||||
if (type() == Type::Color)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue