# HG changeset patch # User wycc # Date 1284867363 -28800 # Node ID 2bcacd29d95f1b32ff884f7a7167ee816f24def8 # Parent 76fe4afce640f68d384c6b4ad2047744c8a5c339 Define accessor for x and y to implement absolute location diff -r 76fe4afce640 -r 2bcacd29d95f nodejs/coord.cc --- a/nodejs/coord.cc Sat Sep 18 21:23:51 2010 +0800 +++ b/nodejs/coord.cc Sun Sep 19 11:36:03 2010 +0800 @@ -282,6 +282,74 @@ return Number::New(opacity); } +#define cc(i) (coord_get_matrix(coord)[i]) +static void +xnjsmb_coord_set_y(Handle self, coord_t *coord, Handle value, const char **str) +{ + Handle js_rt; + redraw_man_t *rdman; + co_aix y,ty; + co_aix xx,yy; + + js_rt = GET(self, "mbrt")->ToObject(); + ASSERT(js_rt != NULL); + rdman = xnjsmb_rt_rdman(js_rt); + + + ty = value->NumberValue(); + xx = GET(self,"_x")->ToNumber()->NumberValue(); + yy = GET(self,"_y")->ToNumber()->NumberValue(); + y = ty-cc(3)*xx-cc(4)*yy; + coord_get_matrix(coord)[5] = y; + rdman_coord_changed(rdman, coord); +} + +static Handle +xnjsmb_coord_get_y(Handle self, coord_t *coord, + const char **err) { + co_aix y; + co_aix xx,yy; + + xx = GET(self,"_x")->ToNumber()->NumberValue(); + yy = GET(self,"_y")->ToNumber()->NumberValue(); + + y = cc(3)*xx+cc(4)*yy+cc(5); + return Number::New(y); +} +static void +xnjsmb_coord_set_x(Handle self, coord_t *coord, Handle value, const char **str) +{ + Handle js_rt; + redraw_man_t *rdman; + co_aix x,tx; + co_aix xx,yy; + + xx = GET(self,"_x")->ToNumber()->NumberValue(); + yy = GET(self,"_y")->ToNumber()->NumberValue(); + js_rt = GET(self, "mbrt")->ToObject(); + ASSERT(js_rt != NULL); + rdman = xnjsmb_rt_rdman(js_rt); + + tx = value->NumberValue(); + x = tx-cc(0)*xx-cc(1)*yy; + coord_get_matrix(coord)[2] = x; + rdman_coord_changed(rdman, coord); +} + +static Handle +xnjsmb_coord_get_x(Handle self, coord_t *coord, + const char **err) { + co_aix x; + co_aix xx,yy; + + xx = GET(self,"_x")->ToNumber()->NumberValue(); + yy = GET(self,"_y")->ToNumber()->NumberValue(); + + x = cc(0)*xx+cc(1)*yy+cc(2); + return Number::New(x); +} +#undef m + #include "coord-inc.h" /*! \brief This function used by \ref xnjsmb_mb_rt to wrap coord object. diff -r 76fe4afce640 -r 2bcacd29d95f nodejs/coord.m4 --- a/nodejs/coord.m4 Sat Sep 18 21:23:51 2010 +0800 +++ b/nodejs/coord.m4 Sun Sep 19 11:36:03 2010 +0800 @@ -1,6 +1,10 @@ define([PROJ_PREFIX], [xnjsmb_auto_])dnl STRUCT([coord], [coord_t], - [ACCESSOR([opacity], [xnjsmb_coord_get_opacity],[xnjsmb_coord_set_opacity])], + [ + ACCESSOR([opacity], [xnjsmb_coord_get_opacity],[xnjsmb_coord_set_opacity]), + ACCESSOR([x], [xnjsmb_coord_get_x],[xnjsmb_coord_set_x]), + ACCESSOR([y], [xnjsmb_coord_get_y],[xnjsmb_coord_set_y]), + ], [METHOD([add_shape], [xnjsmb_coord_add_shape], (SELF, OBJ([shape], [shape], [shape_t]), ERR), 1, []), METHOD([remove], [xnjsmb_coord_remove], (SELF), 0, []),