[DEV] add multiple color format
This commit is contained in:
parent
1de2ed72bf
commit
4f308f38dd
@ -40,8 +40,11 @@ etk::Stream& fluorine::operator <<(etk::Stream& _os, const fluorine::Variant& _o
|
||||
case fluorine::variantType::String:
|
||||
_os << _obj.getString();
|
||||
break;
|
||||
case fluorine::variantType::Color:
|
||||
_os << _obj.getColor();
|
||||
case fluorine::variantType::ColorFloat:
|
||||
_os << _obj.getColorFloat();
|
||||
break;
|
||||
case fluorine::variantType::ColorInt:
|
||||
_os << _obj.getColorInt();
|
||||
break;
|
||||
case fluorine::variantType::Vec2:
|
||||
_os << _obj.getVec2();
|
||||
@ -114,8 +117,10 @@ fluorine::Variant fluorine::Variant::clone() const {
|
||||
return fluorine::Variant{getRawPointer()};
|
||||
case fluorine::variantType::String:
|
||||
return fluorine::Variant{getString()};
|
||||
case fluorine::variantType::Color:
|
||||
return fluorine::Variant{getColor()};
|
||||
case fluorine::variantType::ColorFloat:
|
||||
return fluorine::Variant{getColorFloat()};
|
||||
case fluorine::variantType::ColorInt:
|
||||
return fluorine::Variant{getColorInt()};
|
||||
case fluorine::variantType::Vec2:
|
||||
return fluorine::Variant{getVec2()};
|
||||
case fluorine::variantType::IVec2:
|
||||
@ -141,8 +146,11 @@ void fluorine::Variant::clear() {
|
||||
case fluorine::variantType::String:
|
||||
ETK_DELETE(etk::String, m_dataUnion.m_string);
|
||||
break;
|
||||
case fluorine::variantType::Color:
|
||||
ETK_DELETE(etk::Color<>, m_dataUnion.m_color);
|
||||
case fluorine::variantType::ColorFloat:
|
||||
ETK_DELETE(etk::Color<float>, m_dataUnion.m_colorFloat);
|
||||
break;
|
||||
case fluorine::variantType::ColorInt:
|
||||
ETK_DELETE(etk::Color<>, m_dataUnion.m_colorInt);
|
||||
break;
|
||||
case fluorine::variantType::Vec2:
|
||||
ETK_DELETE(vec2, m_dataUnion.m_vec2);
|
||||
@ -250,9 +258,13 @@ fluorine::Variant::Variant(const ivec3& _value):
|
||||
m_dataUnion.m_ivec3 = ETK_NEW(ivec3, _value);
|
||||
}
|
||||
|
||||
fluorine::Variant::Variant(const etk::Color<float>& _value):
|
||||
m_dataType(fluorine::variantType::ColorFloat) {
|
||||
m_dataUnion.m_colorFloat = ETK_NEW(etk::Color<float>, _value);
|
||||
}
|
||||
fluorine::Variant::Variant(const etk::Color<>& _value):
|
||||
m_dataType(fluorine::variantType::Color) {
|
||||
m_dataUnion.m_color = ETK_NEW(etk::Color<>, _value);
|
||||
m_dataType(fluorine::variantType::ColorInt) {
|
||||
m_dataUnion.m_colorInt = ETK_NEW(etk::Color<>, _value);
|
||||
}
|
||||
|
||||
fluorine::Variant::~Variant() {
|
||||
@ -307,12 +319,28 @@ bool fluorine::Variant::isString() const {
|
||||
return m_dataType == fluorine::variantType::String;
|
||||
}
|
||||
|
||||
etk::Color<> fluorine::Variant::getColor() const {
|
||||
return *(m_dataUnion.m_color);
|
||||
etk::Color<float> fluorine::Variant::getColorFloat() const {
|
||||
if (m_dataType == fluorine::variantType::ColorFloat) {
|
||||
return *(m_dataUnion.m_colorFloat);
|
||||
}
|
||||
return *(m_dataUnion.m_colorInt);
|
||||
}
|
||||
etk::Color<> fluorine::Variant::getColorInt() const {
|
||||
if (m_dataType == fluorine::variantType::ColorFloat) {
|
||||
return *(m_dataUnion.m_colorFloat);
|
||||
}
|
||||
return *(m_dataUnion.m_colorInt);
|
||||
}
|
||||
|
||||
bool fluorine::Variant::isColor() const {
|
||||
return m_dataType == fluorine::variantType::Color;
|
||||
return m_dataType == fluorine::variantType::ColorFloat
|
||||
|| m_dataType == fluorine::variantType::ColorInt;
|
||||
}
|
||||
bool fluorine::Variant::isColorFloat() const {
|
||||
return m_dataType == fluorine::variantType::ColorFloat;
|
||||
}
|
||||
bool fluorine::Variant::isColorInt() const {
|
||||
return m_dataType == fluorine::variantType::ColorInt;
|
||||
}
|
||||
|
||||
vec2 fluorine::Variant::getVec2() const {
|
||||
|
@ -26,7 +26,8 @@ namespace fluorine {
|
||||
vec2* m_vec2;
|
||||
ivec3* m_ivec3;
|
||||
vec3* m_vec3;
|
||||
etk::Color<>* m_color;
|
||||
etk::Color<float>* m_colorFloat;
|
||||
etk::Color<>* m_colorInt;
|
||||
};
|
||||
/**
|
||||
* @brief Basic main object of all json elements.
|
||||
@ -120,6 +121,10 @@ namespace fluorine {
|
||||
* @brief Constuctor that generate a ivec3 value
|
||||
*/
|
||||
Variant(const ivec3& _value);
|
||||
/**
|
||||
* @brief Constuctor that generate a etk::Color<float> value
|
||||
*/
|
||||
Variant(const etk::Color<float>& _value);
|
||||
/**
|
||||
* @brief Constuctor that generate a etk::Color<> value
|
||||
*/
|
||||
@ -200,12 +205,34 @@ namespace fluorine {
|
||||
* @brief Get the etk::Color Value.
|
||||
* @return requested value if compatible.
|
||||
*/
|
||||
etk::Color<> getColor() const;
|
||||
etk::Color<float> getColorFloat() const;
|
||||
/**
|
||||
* @brief check if the node is a fluorine::Color
|
||||
* @return true if the node is a fluorine::Color
|
||||
* @brief Get the etk::Color Value.
|
||||
* @return requested value if compatible.
|
||||
*/
|
||||
etk::Color<> getColorInt() const;
|
||||
/**
|
||||
* @brief Get the etk::Color Value (generic etk type).
|
||||
* @return requested value if compatible.
|
||||
*/
|
||||
etk::Color<> getColor() const {
|
||||
return getColorInt();
|
||||
}
|
||||
/**
|
||||
* @brief check if the node is a fluorine::ColorFloat or fluorine::ColorInt
|
||||
* @return true if the node is a fluorine::ColorFloat or fluorine::ColorInt
|
||||
*/
|
||||
bool isColor() const;
|
||||
/**
|
||||
* @brief check if the node is a fluorine::ColorFloat
|
||||
* @return true if the node is a fluorine::ColorFloat
|
||||
*/
|
||||
bool isColorFloat() const;
|
||||
/**
|
||||
* @brief check if the node is a fluorine::ColorInt
|
||||
* @return true if the node is a fluorine::ColorInt
|
||||
*/
|
||||
bool isColorInt() const;
|
||||
public:
|
||||
/**
|
||||
* @brief Get the vec2 Value.
|
||||
|
@ -35,8 +35,11 @@ etk::Stream& fluorine::operator <<(etk::Stream& _os, enum fluorine::variantType
|
||||
case fluorine::variantType::Boolean:
|
||||
_os << "fluorine::variantType::Boolean";
|
||||
break;
|
||||
case fluorine::variantType::Color:
|
||||
_os << "fluorine::variantType::Color";
|
||||
case fluorine::variantType::ColorFloat:
|
||||
_os << "fluorine::variantType::ColorFloat";
|
||||
break;
|
||||
case fluorine::variantType::ColorInt:
|
||||
_os << "fluorine::variantType::ColorInt";
|
||||
break;
|
||||
case fluorine::variantType::Vec2:
|
||||
_os << "fluorine::variantType::Vec2";
|
||||
|
@ -20,7 +20,8 @@ namespace fluorine {
|
||||
RawPointer, //!< Void * pointer
|
||||
String, //!< String element
|
||||
Boolean, //!< Boolean element
|
||||
Color, //!< Color RGBA float element
|
||||
ColorFloat, //!< Color RGBA float element
|
||||
ColorInt, //!< Color RGBA int element
|
||||
Vec2, //!< 2D vector Position (float)
|
||||
IVec2, //!< 2D vector Position (integer)
|
||||
Vec3, //!< 3D vector Position (float)
|
||||
|
@ -146,7 +146,25 @@ TEST(constructor, testString_2) {
|
||||
EXPECT_EQ(element.isNull(), false);
|
||||
}
|
||||
|
||||
TEST(constructor, testColor) {
|
||||
TEST(constructor, testColorFloat) {
|
||||
fluorine::Variant element(etk::Color<float>(1.0,0.5,0.7,0.6));
|
||||
EXPECT_EQ(element.isUndefined(), false);
|
||||
EXPECT_EQ(element.isBoolean(), false);
|
||||
EXPECT_EQ(element.isInt(), false);
|
||||
EXPECT_EQ(element.isUInt(), false);
|
||||
EXPECT_EQ(element.isFloat(), false);
|
||||
EXPECT_EQ(element.isRawPointer(), false);
|
||||
EXPECT_EQ(element.isString(), false);
|
||||
EXPECT_EQ(element.isColor(), true);
|
||||
EXPECT_EQ(element.isVec2(), false);
|
||||
EXPECT_EQ(element.isIVec2(), false);
|
||||
EXPECT_EQ(element.isVec3(), false);
|
||||
EXPECT_EQ(element.isIVec3(), false);
|
||||
EXPECT_EQ(element.isNull(), false);
|
||||
EXPECT_EQ(element.isColorFloat(), true);
|
||||
EXPECT_EQ(element.isColorInt(), false);
|
||||
}
|
||||
TEST(constructor, testColorInt) {
|
||||
fluorine::Variant element(etk::Color<>(55,55,55,65));
|
||||
EXPECT_EQ(element.isUndefined(), false);
|
||||
EXPECT_EQ(element.isBoolean(), false);
|
||||
@ -161,6 +179,8 @@ TEST(constructor, testColor) {
|
||||
EXPECT_EQ(element.isVec3(), false);
|
||||
EXPECT_EQ(element.isIVec3(), false);
|
||||
EXPECT_EQ(element.isNull(), false);
|
||||
EXPECT_EQ(element.isColorFloat(), false);
|
||||
EXPECT_EQ(element.isColorInt(), true);
|
||||
}
|
||||
|
||||
TEST(constructor, testVec2) {
|
||||
@ -294,9 +314,13 @@ TEST(constructor, testString_2Value) {
|
||||
EXPECT_EQ(element.getString(), "HGFDSQ");
|
||||
}
|
||||
|
||||
TEST(constructor, testColorValue) {
|
||||
TEST(constructor, testColorValueFloat) {
|
||||
fluorine::Variant element(etk::Color<float>(1.0,0.5,0.7,0.6));
|
||||
EXPECT_EQ(element.getColorFloat(), etk::Color<float>(1.0,0.5,0.7,0.6));
|
||||
}
|
||||
TEST(constructor, testColorValueInt) {
|
||||
fluorine::Variant element(etk::Color<>(55,55,55,65));
|
||||
EXPECT_EQ(element.getColor(), etk::Color<>(55,55,55,65));
|
||||
EXPECT_EQ(element.getColorInt(), etk::Color<>(55,55,55,65));
|
||||
}
|
||||
|
||||
TEST(constructor, testVec2Value) {
|
||||
@ -379,11 +403,18 @@ TEST(constructor, testString_2ValueOperator) {
|
||||
EXPECT_EQ(element.getString(), "HGFDSQ");
|
||||
}
|
||||
|
||||
TEST(constructor, testColorValueOperator) {
|
||||
TEST(constructor, testColorValueOperatorFloat) {
|
||||
fluorine::Variant element;
|
||||
EXPECT_EQ(element.isUndefined(), true);
|
||||
element = etk::Color<float>(1.0,0.5,0.7,0.6);
|
||||
EXPECT_EQ(element.getColorFloat(), etk::Color<float>(1.0,0.5,0.7,0.6));
|
||||
}
|
||||
|
||||
TEST(constructor, testColorValueOperatorInt) {
|
||||
fluorine::Variant element;
|
||||
EXPECT_EQ(element.isUndefined(), true);
|
||||
element = etk::Color<>(55,55,55,65);
|
||||
EXPECT_EQ(element.getColor(), etk::Color<>(55,55,55,65));
|
||||
EXPECT_EQ(element.getColorInt(), etk::Color<>(55,55,55,65));
|
||||
}
|
||||
|
||||
TEST(constructor, testVec2ValueOperator) {
|
||||
|
Loading…
Reference in New Issue
Block a user