Skip to content
Snippets Groups Projects
Commit 52f1edb1 authored by Ivica Bukvic's avatar Ivica Bukvic
Browse files

external clean-up

parent bc9ab087
No related branches found
No related tags found
Loading
...@@ -19,7 +19,6 @@ ...@@ -19,7 +19,6 @@
static t_class *imagebang_class; static t_class *imagebang_class;
t_widgetbehavior imagebang_widgetbehavior; t_widgetbehavior imagebang_widgetbehavior;
typedef struct _imagebang typedef struct _imagebang
{ {
t_object x_obj; t_object x_obj;
...@@ -36,7 +35,6 @@ typedef struct _imagebang ...@@ -36,7 +35,6 @@ typedef struct _imagebang
t_outlet* outlet; t_outlet* outlet;
} t_imagebang; } t_imagebang;
static void imagebang_bang(t_imagebang *x) static void imagebang_bang(t_imagebang *x)
{ {
...@@ -75,7 +73,6 @@ static void imagebang_brk_timeout(t_imagebang *x) ...@@ -75,7 +73,6 @@ static void imagebang_brk_timeout(t_imagebang *x)
} }
/* widget helper functions */ /* widget helper functions */
static const char* imagebang_get_filename(t_imagebang *x,char *file) { static const char* imagebang_get_filename(t_imagebang *x,char *file) {
...@@ -96,38 +93,29 @@ static const char* imagebang_get_filename(t_imagebang *x,char *file) { ...@@ -96,38 +93,29 @@ static const char* imagebang_get_filename(t_imagebang *x,char *file) {
} }
static int imagebang_click(t_imagebang *x, struct _glist *glist, static int imagebang_click(t_imagebang *x, struct _glist *glist,
int xpos, int ypos, int shift, int alt, int dbl, int doit) { int xpos, int ypos, int shift, int alt, int dbl, int doit)
//DEBUG(post("x:%i y:%i dbl:%i doit:%i",xpos,ypos,dbl,doit);) {
if ( doit) imagebang_bang(x) ; //DEBUG(post("x:%i y:%i dbl:%i doit:%i",xpos,ypos,dbl,doit);)
if (doit) imagebang_bang(x);
return (1); return (1);
} }
static void imagebang_drawme(t_imagebang *x, t_glist *glist, int firsttime) { static void imagebang_drawme(t_imagebang *x, t_glist *glist, int firsttime) {
if (firsttime) { if (firsttime) {
DEBUG(post("Rendering: \n %x_imagebang:%s \n %x_imagebang:%s",x->image_a,x->image_a->s_name,x->image_b,x->image_b->s_name);)
DEBUG(post("Rendering: \n %x_imagebang:%s \n %x_imagebang:%s",x->image_a,x->image_a->s_name,x->image_b,x->image_b->s_name);)
sys_vgui(".x%x.c create image %d %d -anchor nw -image %x_imagebang -disabledimage %x_imagebang -tags %ximage\n", sys_vgui(".x%x.c create image %d %d -anchor nw -image %x_imagebang -disabledimage %x_imagebang -tags %ximage\n",
glist_getcanvas(glist), glist_getcanvas(glist),
text_xpix(&x->x_obj, glist), text_ypix(&x->x_obj, glist),x->image_a,x->image_b,x); text_xpix(&x->x_obj, glist), text_ypix(&x->x_obj, glist),x->image_a,x->image_b,x);
sys_vgui("pd [concat %s _imagesize [image width %x_imagebang] [image height %x_imagebang] \\;]\n",x->receive->s_name,x->image_a,x->image_a);
sys_vgui("pd [concat %s _imagesize [image width %x_imagebang] [image height %x_imagebang] \\;]\n",x->receive->s_name,x->image_a,x->image_a);
} else { } else {
sys_vgui(".x%x.c coords %ximage %d %d\n", sys_vgui(".x%x.c coords %ximage %d %d\n",
glist_getcanvas(glist), x, glist_getcanvas(glist), x,
text_xpix(&x->x_obj, glist), text_ypix(&x->x_obj, glist)); text_xpix(&x->x_obj, glist), text_ypix(&x->x_obj, glist));
} }
} }
void imagebang_erase(t_imagebang* x,t_glist* glist) void imagebang_erase(t_imagebang* x,t_glist* glist)
{ {
int n; int n;
...@@ -135,7 +123,6 @@ void imagebang_erase(t_imagebang* x,t_glist* glist) ...@@ -135,7 +123,6 @@ void imagebang_erase(t_imagebang* x,t_glist* glist)
glist_getcanvas(glist), x); glist_getcanvas(glist), x);
} }
/* ------------------------ image widgetbehaviour----------------------------- */ /* ------------------------ image widgetbehaviour----------------------------- */
...@@ -147,13 +134,13 @@ static void imagebang_getrect(t_gobj *z, t_glist *glist, ...@@ -147,13 +134,13 @@ static void imagebang_getrect(t_gobj *z, t_glist *glist,
int width, height; int width, height;
t_imagebang* x = (t_imagebang*)z; t_imagebang* x = (t_imagebang*)z;
width = x->width; width = x->width;
height = x->height; height = x->height;
*xp1 = text_xpix(&x->x_obj, glist); *xp1 = text_xpix(&x->x_obj, glist);
*yp1 = text_ypix(&x->x_obj, glist); *yp1 = text_ypix(&x->x_obj, glist);
*xp2 = text_xpix(&x->x_obj, glist) + width; *xp2 = text_xpix(&x->x_obj, glist) + width;
*yp2 = text_ypix(&x->x_obj, glist) + height; *yp2 = text_ypix(&x->x_obj, glist) + height;
//fprintf(stderr,"%d %d %d %d\n", *xp1, *yp1, *xp2, *yp2);
} }
static void imagebang_displace(t_gobj *z, t_glist *glist, static void imagebang_displace(t_gobj *z, t_glist *glist,
...@@ -176,22 +163,19 @@ static void imagebang_select(t_gobj *z, t_glist *glist, int state) ...@@ -176,22 +163,19 @@ static void imagebang_select(t_gobj *z, t_glist *glist, int state)
t_imagebang *x = (t_imagebang *)z; t_imagebang *x = (t_imagebang *)z;
if (state) { if (state) {
sys_vgui(".x%x.c create rectangle \ sys_vgui(".x%x.c create rectangle \
%d %d %d %d -tags %xSEL -outline blue\n", %d %d %d %d -tags %xSEL -outline $select_color\n",
glist_getcanvas(glist), glist_getcanvas(glist),
text_xpix(&x->x_obj, glist), text_ypix(&x->x_obj, glist), text_xpix(&x->x_obj, glist), text_ypix(&x->x_obj, glist),
text_xpix(&x->x_obj, glist) + x->width, text_ypix(&x->x_obj, glist) + x->height, text_xpix(&x->x_obj, glist) + x->width,
x); text_ypix(&x->x_obj, glist) + x->height,
x);
} }
else { else {
sys_vgui(".x%x.c delete %xSEL\n", sys_vgui(".x%x.c delete %xSEL\n",
glist_getcanvas(glist), x); glist_getcanvas(glist), x);
} }
} }
static void imagebang_activate(t_gobj *z, t_glist *glist, int state) static void imagebang_activate(t_gobj *z, t_glist *glist, int state)
{ {
/* t_text *x = (t_text *)z; /* t_text *x = (t_text *)z;
...@@ -205,28 +189,21 @@ static void imagebang_delete(t_gobj *z, t_glist *glist) ...@@ -205,28 +189,21 @@ static void imagebang_delete(t_gobj *z, t_glist *glist)
//canvas_deletelinesfor(glist_getcanvas(glist), x); //canvas_deletelinesfor(glist_getcanvas(glist), x);
canvas_deletelinesfor(glist, x); canvas_deletelinesfor(glist, x);
} }
static void imagebang_vis(t_gobj *z, t_glist *glist, int vis) static void imagebang_vis(t_gobj *z, t_glist *glist, int vis)
{ {
t_imagebang* s = (t_imagebang*)z; t_imagebang* s = (t_imagebang*)z;
if (vis) if (vis)
imagebang_drawme(s, glist, 1); imagebang_drawme(s, glist, 1);
else else
imagebang_erase(s,glist); imagebang_erase(s,glist);
} }
static void imagebang_size(t_imagebang* x,t_floatarg w,t_floatarg h) { static void imagebang_size(t_imagebang* x,t_floatarg w,t_floatarg h) {
x->width = w; x->width = w;
x->height = h; x->height = h;
} }
static void imagebang_imagesize_callback(t_imagebang *x, t_float w, t_float h) { static void imagebang_imagesize_callback(t_imagebang *x, t_float w, t_float h) {
DEBUG(post("received w %f h %f",w,h);) DEBUG(post("received w %f h %f",w,h);)
x->width = w; x->width = w;
...@@ -234,7 +211,6 @@ static void imagebang_imagesize_callback(t_imagebang *x, t_float w, t_float h) { ...@@ -234,7 +211,6 @@ static void imagebang_imagesize_callback(t_imagebang *x, t_float w, t_float h) {
canvas_fixlinesfor(x->glist,(t_text*) x); canvas_fixlinesfor(x->glist,(t_text*) x);
} }
static void imagebang_free(t_imagebang *x) { static void imagebang_free(t_imagebang *x) {
// check first if variable has been unset and image is unused // check first if variable has been unset and image is unused
...@@ -256,7 +232,6 @@ static void imagebang_free(t_imagebang *x) { ...@@ -256,7 +232,6 @@ static void imagebang_free(t_imagebang *x) {
} }
static void *imagebang_new(t_symbol *s, int argc, t_atom *argv) static void *imagebang_new(t_symbol *s, int argc, t_atom *argv)
{ {
t_imagebang *x = (t_imagebang *)pd_new(imagebang_class); t_imagebang *x = (t_imagebang *)pd_new(imagebang_class);
...@@ -292,12 +267,10 @@ static void *imagebang_new(t_symbol *s, int argc, t_atom *argv) ...@@ -292,12 +267,10 @@ static void *imagebang_new(t_symbol *s, int argc, t_atom *argv)
sys_vgui("if { [info exists %x_imagebang] == 0 } { image create photo %x_imagebang -file \"%s\"\n set %x_imagebang 1\n} \n",x->image_a,x->image_a,fname,x->image_a); sys_vgui("if { [info exists %x_imagebang] == 0 } { image create photo %x_imagebang -file \"%s\"\n set %x_imagebang 1\n} \n",x->image_a,x->image_a,fname,x->image_a);
//sys_vgui("pd [concat test %x_imagebang \\;]\n",x->image_a); //sys_vgui("pd [concat test %x_imagebang \\;]\n",x->image_a);
} else { } else {
post("Oups... [imagebang] could not find \"%s\"",image_a->s_name); post("Oops... [imagebang] could not find \"%s\"",image_a->s_name);
} }
} }
if ( argc > 1 && (argv+1)->a_type == A_SYMBOL ) { if ( argc > 1 && (argv+1)->a_type == A_SYMBOL ) {
image_b= atom_getsymbol(argv+1); image_b= atom_getsymbol(argv+1);
fname = imagebang_get_filename(x,image_b->s_name); // Get image file path fname = imagebang_get_filename(x,image_b->s_name); // Get image file path
...@@ -307,7 +280,7 @@ static void *imagebang_new(t_symbol *s, int argc, t_atom *argv) ...@@ -307,7 +280,7 @@ static void *imagebang_new(t_symbol *s, int argc, t_atom *argv)
sys_vgui("if { [info exists %x_imagebang] == 0} { image create photo %x_imagebang -file \"%s\"\n set %x_imagebang 1\n} \n",x->image_b,x->image_b,fname,x->image_b); sys_vgui("if { [info exists %x_imagebang] == 0} { image create photo %x_imagebang -file \"%s\"\n set %x_imagebang 1\n} \n",x->image_b,x->image_b,fname,x->image_b);
//sys_vgui("pd [concat test %x_imagebang \\;]\n",x->image_b); //sys_vgui("pd [concat test %x_imagebang \\;]\n",x->image_b);
} else { } else {
post("Oups... [imagebang] could not find \"%s\"",image_b->s_name); post("Oops... [imagebang] could not find \"%s\"",image_b->s_name);
} }
} }
...@@ -333,50 +306,42 @@ static void *imagebang_new(t_symbol *s, int argc, t_atom *argv) ...@@ -333,50 +306,42 @@ static void *imagebang_new(t_symbol *s, int argc, t_atom *argv)
pd_bind(&x->x_obj.ob_pd, x->receive ); pd_bind(&x->x_obj.ob_pd, x->receive );
x->clock_flash = clock_new(x, (t_method)imagebang_flash_timeout); x->clock_flash = clock_new(x, (t_method)imagebang_flash_timeout);
x->clock_brk = clock_new(x, (t_method)imagebang_brk_timeout); x->clock_brk = clock_new(x, (t_method)imagebang_brk_timeout);
x->outlet = outlet_new(&x->x_obj, &s_float);
return (x);
x->outlet = outlet_new(&x->x_obj, &s_float);
return (x);
} }
void imagebang_setup(void) void imagebang_setup(void)
{ {
imagebang_class = class_new(gensym("imagebang"),
(t_newmethod)imagebang_new, (t_method)imagebang_free,
imagebang_class = class_new(gensym("imagebang"), (t_newmethod)imagebang_new, (t_method)imagebang_free, sizeof(t_imagebang),0, A_GIMME,0);
sizeof(t_imagebang),0, A_GIMME,0);
class_addmethod(imagebang_class, (t_method)imagebang_imagesize_callback,\ class_addmethod(imagebang_class, (t_method)imagebang_imagesize_callback,\
gensym("_imagesize"), A_DEFFLOAT, A_DEFFLOAT, 0); gensym("_imagesize"), A_DEFFLOAT, A_DEFFLOAT, 0);
class_addbang(imagebang_class,(t_method)imagebang_bang); class_addbang(imagebang_class,(t_method)imagebang_bang);
imagebang_widgetbehavior.w_getrectfn = imagebang_getrect; imagebang_widgetbehavior.w_getrectfn = imagebang_getrect;
imagebang_widgetbehavior.w_displacefn = imagebang_displace; imagebang_widgetbehavior.w_displacefn = imagebang_displace;
imagebang_widgetbehavior.w_selectfn = imagebang_select; imagebang_widgetbehavior.w_selectfn = imagebang_select;
imagebang_widgetbehavior.w_activatefn = imagebang_activate; imagebang_widgetbehavior.w_activatefn = imagebang_activate;
imagebang_widgetbehavior.w_deletefn = imagebang_delete; imagebang_widgetbehavior.w_deletefn = imagebang_delete;
imagebang_widgetbehavior.w_visfn = imagebang_vis; imagebang_widgetbehavior.w_visfn = imagebang_vis;
imagebang_widgetbehavior.w_clickfn = (t_clickfn)imagebang_click; imagebang_widgetbehavior.w_clickfn = (t_clickfn)imagebang_click;
#if PD_MINOR_VERSION < 37 #if PD_MINOR_VERSION < 37
imagebang_widgetbehavior.w_propertiesfn = NULL; imagebang_widgetbehavior.w_propertiesfn = NULL;
//imagebang_widgetbehavior.w_savefn = imagebang_save; //imagebang_widgetbehavior.w_savefn = imagebang_save;
#endif #endif
class_setwidget(imagebang_class,&imagebang_widgetbehavior); class_setwidget(imagebang_class,&imagebang_widgetbehavior);
#if PD_MINOR_VERSION >= 37 #if PD_MINOR_VERSION >= 37
// class_setsavefn(imagebang_class,&imagebang_save); // class_setsavefn(imagebang_class,&imagebang_save);
#endif #endif
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment