aboutsummaryrefslogtreecommitdiff
path: root/src/canvasindex.c
diff options
context:
space:
mode:
authorIOhannes m zmölnig <zmoelnig@users.sourceforge.net>2008-07-29 12:20:52 +0000
committerIOhannes m zmölnig <zmoelnig@users.sourceforge.net>2008-07-29 12:20:52 +0000
commit330173fc6f2897c2b15b523ea5ee9679bd5ca045 (patch)
tree362e812b4451b1acb63128d20c5d72265d18dde3 /src/canvasindex.c
parent14a08e3d8a694b7fb718717130d4ff69d14243fb (diff)
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
Diffstat (limited to 'src/canvasindex.c')
-rw-r--r--src/canvasindex.c25
1 files changed, 18 insertions, 7 deletions
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);
}