Mercurial > MadButterfly
changeset 1454:e22df2f3bffe
Provide number of children for coords
author | Thinker K.F. Li <thinker@codemud.net> |
---|---|
date | Wed, 13 Apr 2011 19:57:58 +0800 |
parents | 0cb89e204824 |
children | 8ea0d32a1864 |
files | include/mb_types.h nodejs/coord.cc nodejs/coord.m4 nodejs/examples/simple/testtraveling.js |
diffstat | 4 files changed, 57 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/include/mb_types.h Wed Apr 13 17:34:09 2011 +0800 +++ b/include/mb_types.h Wed Apr 13 19:57:58 2011 +0800 @@ -331,6 +331,10 @@ #define coord_scaley(co) ((co)->matrix[4]) #define coord_x(co) ((co)->matrix[2]) #define coord_y(co) ((co)->matrix[5]) +#define FOR_COORD_CHILDREN(parent, child) \ + for((child) = STAILQ_HEAD((parent)->children); \ + (child) != NULL; \ + (child) = STAILQ_NEXT(coord_t, sibling, (child))) #define FOR_COORD_MEMBERS(coord, geo) \ for(geo = STAILQ_HEAD((coord)->members); \ geo != NULL; \
--- a/nodejs/coord.cc Wed Apr 13 17:34:09 2011 +0800 +++ b/nodejs/coord.cc Wed Apr 13 19:57:58 2011 +0800 @@ -363,20 +363,43 @@ child = STAILQ_HEAD(coord->children); FOR_COORD_MEMBERS(coord, geo) { while(child != NULL && child->before_pmem == member_idx) { - if(cnt == member_idx) + if(cnt == idx) return (mb_obj_t *)child; cnt++; child = COORD_NEXT_SIBLING(child); } - if(cnt == member_idx) + if(cnt == idx) return (mb_obj_t *)geo->shape; cnt++; + member_idx++; + } + + while(child != NULL) { + if(cnt == idx) + return (mb_obj_t *)child; + cnt++; + child = COORD_NEXT_SIBLING(child); } return NULL; } +static int +xnjsmb_coord_num_children(coord_t *coord, Handle<Object> self) { + int children_n_member_total; + int children_cnt; + coord_t *child; + + children_cnt = 0; + FOR_COORD_CHILDREN(coord, child) { + children_cnt++; + } + children_n_member_total = coord->num_members + children_cnt; + + return children_n_member_total; +} + static Handle<Value> xnjsmb_auto_coord_new(coord_t *data); static Handle<Value>
--- a/nodejs/coord.m4 Wed Apr 13 17:34:09 2011 +0800 +++ b/nodejs/coord.m4 Wed Apr 13 19:57:58 2011 +0800 @@ -1,6 +1,7 @@ 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])], [METHOD([add_shape], [xnjsmb_coord_add_shape], (SELF, OBJ([shape], [shape], [shape_t]), ERR), 1, []), METHOD([remove], [xnjsmb_coord_remove], (SELF), 0, []), @@ -10,6 +11,8 @@ (([MOD], [_xnjsmb_coord_clone_from_subtree_mod]))), METHOD([show], [xnjsmb_coord_show], (SELF), 0, []), METHOD([hide], [xnjsmb_coord_hide], (SELF), 0, []), + METHOD([num_children], [xnjsmb_coord_num_children], (SELF), + 0, [INT]), METHOD([get_child], [xnjsmb_coord_get_child], (SELF, INT(idx), ERR), 1, [VAL])], ((GET_INDEX, (coord_get_index, NUMBER)),
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/nodejs/examples/simple/testtraveling.js Wed Apr 13 19:57:58 2011 +0800 @@ -0,0 +1,24 @@ +// -*- indent-tabs-mode: t; tab-width: 8; c-basic-offset: 4; -*- +// vim: sw=4:ts=8:sts=4 +var svg = require("svg"); +var mbapp = require("mbapp"); +var sys=require("sys"); +var animate=require("animate"); + +app = new mbapp.app(); + +coord_parent = app.mb_rt.coord_new(app.mb_rt.root); +coord0 = app.mb_rt.coord_new(coord_parent) +coord = app.mb_rt.coord_new(coord_parent) +data=mbapp.ldr.load("sample.png"); +paint = app.mb_rt.paint_image_new(data); +img = app.mb_rt.image_new(10,10,50,50); +paint.fill(img); +coord.add_shape(img); + +sys.puts(coord_parent.num_children() == 2); +sys.puts(coord_parent.get_child(0) == coord0); +sys.puts(coord_parent.get_child(0) != coord); +sys.puts(coord_parent.get_child(1) == coord); +sys.puts(coord_parent.get_child(1).num_children() == 1); +sys.puts(coord_parent.get_child(1).get_child(0) == img);