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/canvasdollarzero.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 src/canvasdollarzero.c (limited to 'src/canvasdollarzero.c') diff --git a/src/canvasdollarzero.c b/src/canvasdollarzero.c new file mode 100644 index 0000000..6a43eb9 --- /dev/null +++ b/src/canvasdollarzero.c @@ -0,0 +1,58 @@ +/* For information on usage and redistribution, and for a DISCLAIMER OF ALL +* WARRANTIES, see the file, "LICENSE.txt," in this distribution. + +based on iemlib2 written by Thomas Musil, Copyright (c) IEM KUG Graz Austria 2000 - 2006 */ + + +#include "m_pd.h" +#include "g_canvas.h" + + +/* -------------- canvasdollarzero --------------- */ +/* -- receives the $0 value of the parent canvas --*/ + +static t_class *canvasdollarzero_class; + +typedef struct _canvasdollarzero +{ + t_object x_obj; + t_symbol *s_dollzero; +} t_canvasdollarzero; + +static void canvasdollarzero_bang(t_canvasdollarzero *x) +{ + if(x->s_dollzero) + outlet_symbol(x->x_obj.ob_outlet, x->s_dollzero); +} + +static void *canvasdollarzero_new(t_floatarg f) +{ + t_canvasdollarzero *x = (t_canvasdollarzero *)pd_new(canvasdollarzero_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->s_dollzero=0; + if(canvas) { + x->s_dollzero = canvas_realizedollar(canvas, gensym("$0")); + } + + outlet_new(&x->x_obj, &s_symbol); + return (x); +} + +void canvasdollarzero_setup(void) +{ + canvasdollarzero_class = class_new(gensym("canvasdollarzero"), + (t_newmethod)canvasdollarzero_new, 0, + sizeof(t_canvasdollarzero), 0, + A_DEFFLOAT, 0); + class_addbang(canvasdollarzero_class, (t_method)canvasdollarzero_bang); +} -- cgit v1.2.1