colour: move json deserialisation into cpp
This commit is contained in:
parent
673dfd87dd
commit
701e76c381
31
colour.cpp
31
colour.cpp
|
@ -20,6 +20,7 @@
|
||||||
#include "random.hpp"
|
#include "random.hpp"
|
||||||
#include "stream.hpp"
|
#include "stream.hpp"
|
||||||
|
|
||||||
|
#include <map>
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
using util::colour;
|
using util::colour;
|
||||||
|
@ -341,26 +342,22 @@ util::hsv_to_rgb (colour3f hsv)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
///----------------------------------------------------------------------------
|
///----------------------------------------------------------------------------
|
||||||
//! Extract a colour object from a JSON node.
|
/// Extract a colour object from a JSON node.
|
||||||
//!
|
#include "json/tree.hpp"
|
||||||
//! Data must be an array or 3 or 4 numbers. Guarantees success, or throws a
|
|
||||||
//! json::tree::type_error.
|
|
||||||
const json::tree::node&
|
|
||||||
operator>> (const json::tree::node &node, util::colour4f &c) {
|
|
||||||
c.r = static_cast<float> (node[0].as_number ());
|
|
||||||
c.g = static_cast<float> (node[1].as_number ());
|
|
||||||
c.b = static_cast<float> (node[2].as_number ());
|
|
||||||
|
|
||||||
try {
|
namespace json { namespace tree {
|
||||||
c.a = static_cast<float> (node[3].as_number ());
|
template <>
|
||||||
} catch (...) {
|
util::colour4f
|
||||||
c.a = 1;
|
io<util::colour4f>::deserialise (const node &root) {
|
||||||
|
return {
|
||||||
|
root[0].as<float> (),
|
||||||
|
root[1].as<float> (),
|
||||||
|
root[2].as<float> (),
|
||||||
|
root[3].as<float> (),
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
} }
|
||||||
return node;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
|
@ -19,8 +19,6 @@
|
||||||
|
|
||||||
#include "coord.hpp"
|
#include "coord.hpp"
|
||||||
|
|
||||||
#include "json/tree.hpp"
|
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
namespace util {
|
namespace util {
|
||||||
|
@ -61,9 +59,6 @@ namespace util {
|
||||||
colour3f rgb_to_hsv (colour3f);
|
colour3f rgb_to_hsv (colour3f);
|
||||||
colour3f hsv_to_rgb (colour3f);
|
colour3f hsv_to_rgb (colour3f);
|
||||||
|
|
||||||
// Serialisation
|
|
||||||
const json::tree::node& operator>> (const json::tree::node&, util::colour4f&);
|
|
||||||
|
|
||||||
template <size_t S, typename T>
|
template <size_t S, typename T>
|
||||||
std::ostream& operator<< (std::ostream&, util::colour<S,T>);
|
std::ostream& operator<< (std::ostream&, util::colour<S,T>);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user