cppbind: expose SGRect as [x, y, w, h]

This commit is contained in:
Thomas Geymayer
2014-06-10 18:42:12 +02:00
parent ade4627f1a
commit c716cfbb07
2 changed files with 21 additions and 5 deletions

View File

@@ -22,6 +22,8 @@
#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>
@@ -208,6 +210,20 @@ namespace nasal
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
{

View File

@@ -155,11 +155,11 @@ namespace nasal
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);
}