#include "nasal_traits.hxx"
+#include <simgear/math/SGMath.hxx>
+#include <simgear/math/SGRect.hxx>
#include <simgear/nasal/nasal.h>
#include <simgear/nasal/cppbind/NasalObjectHolder.hxx>
#include <simgear/nasal/cppbind/to_nasal.hxx>
return Vec2(vec[0], vec[1]);
}
+ /**
+ * Convert a Nasal vector with 4 elements ([x, y, w, h]) to an SGRect
+ */
+ template<class T>
+ SGRect<T> from_nasal_helper(naContext c, naRef ref, const SGRect<T>*)
+ {
+ std::vector<double> vec =
+ from_nasal_helper(c, ref, static_cast<std::vector<double>*>(0));
+ if( vec.size() != 4 )
+ throw bad_nasal_cast("Expected vector with four elements");
+
+ return SGRect<T>(vec[0], vec[1], vec[2], vec[3]);
+ }
+
// Helpers for wrapping calls to Nasal functions into boost::function
namespace detail
{
template<class T>
naRef to_nasal_helper(naContext c, const SGRect<T>& rect)
{
- std::vector<float> vec(4);
- vec[0] = rect.l();
- vec[1] = rect.t();
- vec[2] = rect.r();
- vec[3] = rect.b();
+ std::vector<double> vec(4);
+ vec[0] = rect.x();
+ vec[1] = rect.y();
+ vec[2] = rect.width();
+ vec[3] = rect.height();
return to_nasal_helper(c, vec);
}