Core/Color: Add serialization
Former-commit-id: ef50b4303a3fbc5e2b49ba440d9008fb6d51a7e3
This commit is contained in:
parent
300dc82806
commit
a39cfcc92e
|
|
@ -13,6 +13,8 @@
|
||||||
|
|
||||||
namespace Nz
|
namespace Nz
|
||||||
{
|
{
|
||||||
|
struct SerializationContext;
|
||||||
|
|
||||||
class Color
|
class Color
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
@ -62,6 +64,9 @@ namespace Nz
|
||||||
private:
|
private:
|
||||||
static float Hue2RGB(float v1, float v2, float vH);
|
static float Hue2RGB(float v1, float v2, float vH);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
inline bool Serialize(SerializationContext& context, const Color& color);
|
||||||
|
inline bool Unserialize(SerializationContext& context, Color* color);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::ostream& operator<<(std::ostream& out, const Nz::Color& color);
|
std::ostream& operator<<(std::ostream& out, const Nz::Color& color);
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
// This file is part of the "Nazara Engine - Core module"
|
// This file is part of the "Nazara Engine - Core module"
|
||||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||||
|
|
||||||
|
#include <Nazara/Core/Algorithm.hpp>
|
||||||
#include <Nazara/Core/StringStream.hpp>
|
#include <Nazara/Core/StringStream.hpp>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
|
@ -610,6 +611,54 @@ namespace Nz
|
||||||
|
|
||||||
return v1;
|
return v1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief Serializes a Color
|
||||||
|
* \return true if successfully serialized
|
||||||
|
*
|
||||||
|
* \param context Serialization context
|
||||||
|
* \param color Input color
|
||||||
|
*/
|
||||||
|
inline bool Serialize(SerializationContext& context, const Color& color)
|
||||||
|
{
|
||||||
|
if (!Serialize(context, color.r))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (!Serialize(context, color.g))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (!Serialize(context, color.b))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (!Serialize(context, color.a))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief Unserializes a Color
|
||||||
|
* \return true if successfully unserialized
|
||||||
|
*
|
||||||
|
* \param context Serialization context
|
||||||
|
* \param color Output color
|
||||||
|
*/
|
||||||
|
inline bool Unserialize(SerializationContext& context, Color* color)
|
||||||
|
{
|
||||||
|
if (!Unserialize(context, &color->r))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (!Unserialize(context, &color->g))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (!Unserialize(context, &color->b))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (!Unserialize(context, &color->a))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue