From 330173fc6f2897c2b15b523ea5ee9679bd5ca045 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?IOhannes=20m=20zm=C3=B6lnig?= Date: Tue, 29 Jul 2008 12:20:52 +0000 Subject: added new object [canvasdollarzero] which is a clone of iemlib2's [parentdollarzero] with the added feature of allowing you to specify the depth of the parent. depthified other objects svn path=/trunk/externals/iem/iemguts/; revision=10225 --- src/canvasindex.c | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) (limited to 'src/canvasindex.c') diff --git a/src/canvasindex.c b/src/canvasindex.c index 8092351..2ebd6d8 100644 --- a/src/canvasindex.c +++ b/src/canvasindex.c @@ -20,6 +20,11 @@ * this object provides a way to get the position of the containing abstraction * within the parent-patch * this makes it easy to (dis)connect this abstraction to others + * + * by default the index of the containing abstraction within the parent-patch is + * queried; however you can give the "depth" as argument: + * e.g. [canvasindex 1] will give you the index of the abstraction containing the + * abstraction that holds this object */ #include "m_pd.h" @@ -44,14 +49,10 @@ static void canvasindex_bang(t_canvasindex *x) t_canvas*c=x->x_canvas; t_canvas*c0=0; - // int index=-1; - if(!c) return; c0=c->gl_owner; if(!c0)return; - // index=glist_getindex(c0, c); - // index=glist_getindex(c0, (t_gobj*)c); outlet_float(x->youtlet, (t_float)(glist_getindex(c0, 0))); outlet_float(x->xoutlet, (t_float)(glist_getindex(c0, (t_gobj*)c))); } @@ -62,12 +63,20 @@ static void canvasindex_free(t_canvasindex *x) outlet_free(x->youtlet); } -static void *canvasindex_new(void) +static void *canvasindex_new(t_floatarg f) { t_canvasindex *x = (t_canvasindex *)pd_new(canvasindex_class); t_glist *glist=(t_glist *)canvas_getcurrent(); t_canvas *canvas=(t_canvas*)glist_getcanvas(glist); + int depth=(int)f; + + if(depth<0)depth=0; + while(depth && canvas) { + canvas=canvas->gl_owner; + depth--; + } + x->x_canvas = canvas; x->xoutlet=outlet_new(&x->x_obj, &s_float); @@ -78,7 +87,9 @@ static void *canvasindex_new(void) void canvasindex_setup(void) { - canvasindex_class = class_new(gensym("canvasindex"), (t_newmethod)canvasindex_new, - (t_method)canvasindex_free, sizeof(t_canvasindex), 0, 0); + canvasindex_class = class_new(gensym("canvasindex"), + (t_newmethod)canvasindex_new, (t_method)canvasindex_free, + sizeof(t_canvasindex), 0, + A_DEFFLOAT, 0); class_addbang(canvasindex_class, (t_method)canvasindex_bang); } -- cgit v1.2.1