diff options
author | IOhannes m zmölnig <zmoelnig@users.sourceforge.net> | 2009-01-28 15:40:00 +0000 |
---|---|---|
committer | IOhannes m zmölnig <zmoelnig@users.sourceforge.net> | 2009-01-28 15:40:00 +0000 |
commit | c5372f246c7f50a8165d32069ffb538d6cbae2d5 (patch) | |
tree | a2bf98bf318db4eea2c92b43d9f1643580a66940 /src | |
parent | 003544adb9e136e8a39e3dd04fa06bce216645a6 (diff) |
an object that can delete itself (or it's parent)
svn path=/trunk/externals/iem/iemguts/; revision=10664
Diffstat (limited to 'src')
-rw-r--r-- | src/canvasdelete.c | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/src/canvasdelete.c b/src/canvasdelete.c new file mode 100644 index 0000000..c2854d0 --- /dev/null +++ b/src/canvasdelete.c @@ -0,0 +1,97 @@ + +/****************************************************** + * + * canvasdelete - implementation file + * + * copyleft (c) IOhannes m zmölnig + * + * 2007:forum::für::umläute:2007 + * + * institute of electronic music and acoustics (iem) + * + ****************************************************** + * + * license: GNU General Public License v.2 + * + ******************************************************/ + + +/* + * this object deletes itself (or the specified parent canvas) when banged + */ + +#include "m_pd.h" + +#include "g_canvas.h" +#include "m_imp.h" + +/* ------------------------- canvasdelete ---------------------------- */ + +static t_class *canvasdelete_class; + +typedef struct _canvasdelete +{ + t_object x_obj; + + t_glist*x_glist; + t_gobj *x_gobj; + + t_clock *x_clock; +} t_canvasdelete; +static void canvasdelete_doit(t_canvasdelete *x) +{ + clock_free(x->x_clock); + x->x_clock=NULL; + + glist_delete(x->x_glist, x->x_gobj); + +} + +static void canvasdelete_bang(t_canvasdelete *x) +{ + int x1=0, y1=0, width=0, height=0; + t_atom alist[2]; + + if(NULL==x->x_glist || NULL==x->x_gobj)return; + + x->x_clock=clock_new(x, (t_method)canvasdelete_doit); + clock_delay(x->x_clock, 0); +} + +static void *canvasdelete_new(t_floatarg f) +{ + t_canvasdelete *x = (t_canvasdelete *)pd_new(canvasdelete_class); + t_glist *glist=(t_glist *)canvas_getcurrent(); + t_canvas *canvas=(t_canvas*)glist_getcanvas(glist); + t_gobj*obj=(t_gobj*)x; + int depth=(int)f; + + if(depth<0)depth=0; + + while(depth && canvas) { + obj=(t_gobj*)canvas; + canvas=canvas->gl_owner; + depth--; + } + + x->x_glist = canvas; + x->x_gobj=obj; + + x->x_clock=NULL; + + return (x); +} + +static void canvasdelete_free(t_canvasdelete*x) +{ + +} + +void canvasdelete_setup(void) +{ + canvasdelete_class = class_new(gensym("canvasdelete"), + (t_newmethod)canvasdelete_new, (t_method)canvasdelete_free, + sizeof(t_canvasdelete), 0, + A_DEFFLOAT, 0); + class_addbang(canvasdelete_class, (t_method)canvasdelete_bang); +} |