From: Thomas Geymayer Date: Tue, 10 Jun 2014 16:42:12 +0000 (+0200) Subject: cppbind: expose SGRect as [x, y, w, h] X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=c716cfbb07b6b5a0a85893961795f3c4c9bd9a22;p=simgear.git cppbind: expose SGRect as [x, y, w, h] --- diff --git a/simgear/nasal/cppbind/detail/from_nasal_helper.hxx b/simgear/nasal/cppbind/detail/from_nasal_helper.hxx index 0769fc64..6d84bf83 100644 --- a/simgear/nasal/cppbind/detail/from_nasal_helper.hxx +++ b/simgear/nasal/cppbind/detail/from_nasal_helper.hxx @@ -22,6 +22,8 @@ #include "nasal_traits.hxx" +#include +#include #include #include #include @@ -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 + SGRect from_nasal_helper(naContext c, naRef ref, const SGRect*) + { + std::vector vec = + from_nasal_helper(c, ref, static_cast*>(0)); + if( vec.size() != 4 ) + throw bad_nasal_cast("Expected vector with four elements"); + + return SGRect(vec[0], vec[1], vec[2], vec[3]); + } + // Helpers for wrapping calls to Nasal functions into boost::function namespace detail { diff --git a/simgear/nasal/cppbind/detail/to_nasal_helper.hxx b/simgear/nasal/cppbind/detail/to_nasal_helper.hxx index 55933017..f34d9fb6 100644 --- a/simgear/nasal/cppbind/detail/to_nasal_helper.hxx +++ b/simgear/nasal/cppbind/detail/to_nasal_helper.hxx @@ -155,11 +155,11 @@ namespace nasal template naRef to_nasal_helper(naContext c, const SGRect& rect) { - std::vector vec(4); - vec[0] = rect.l(); - vec[1] = rect.t(); - vec[2] = rect.r(); - vec[3] = rect.b(); + std::vector vec(4); + vec[0] = rect.x(); + vec[1] = rect.y(); + vec[2] = rect.width(); + vec[3] = rect.height(); return to_nasal_helper(c, vec); }