From 3767b3a53a8f0dc410f097a521a9cd7dbe3783a1 Mon Sep 17 00:00:00 2001 From: Thomas O Fredericks Date: Wed, 12 May 2010 19:44:04 +0000 Subject: Update Makefile so it copies gifs needed by my help files svn path=/trunk/externals/tof/; revision=13516 --- src/imagebang.c | 382 +++++++++++++++++++++++++++++++++++++++++++++++++ src/pmenu.c | 436 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/pmenu_w.h | 91 ++++++++++++ 3 files changed, 909 insertions(+) create mode 100644 src/imagebang.c create mode 100644 src/pmenu.c create mode 100644 src/pmenu_w.h (limited to 'src') diff --git a/src/imagebang.c b/src/imagebang.c new file mode 100644 index 0000000..b140cfe --- /dev/null +++ b/src/imagebang.c @@ -0,0 +1,382 @@ +#include +#include +#include +#include +#include + +#ifdef _MSC_VER +#pragma warning( disable : 4244 ) +#pragma warning( disable : 4305 ) +#endif + +/* Append " x " to the following line to show debugging messages */ +#define DEBUG(x) + + + +/* ------------------------ imagebang ----------------------------- */ + +static t_class *imagebang_class; +t_widgetbehavior imagebang_widgetbehavior; + + +typedef struct _imagebang +{ + t_object x_obj; + t_glist * glist; + int width; + int height; + t_symbol* image_a; + t_symbol* image_b; + t_symbol* receive; + t_symbol* send; + t_clock* clock_flash; + t_clock* clock_brk; + int flashing; + t_outlet* outlet; +} t_imagebang; + + +static void imagebang_bang(t_imagebang *x) +{ + + t_glist* glist = glist_getcanvas(x->glist); + if(x->flashing) { + sys_vgui(".x%x.c itemconfigure %ximage -image %x_imagebang \n", glist, x,x->image_a); + clock_delay(x->clock_brk, 50); + //x->flashed = 1; + } else { + sys_vgui(".x%x.c itemconfigure %ximage -image %x_imagebang \n", glist, x,x->image_b); + x->flashing = 1; + + } + clock_delay(x->clock_flash, 250); + + + outlet_bang(x->outlet); + + if(x->send && x->send->s_thing ) pd_bang(x->send->s_thing); + +} + +static void imagebang_flash_timeout(t_imagebang *x) +{ + t_glist* glist = glist_getcanvas(x->glist); + x->flashing = 0; + sys_vgui(".x%x.c itemconfigure %ximage -image %x_imagebang \n", glist, x,x->image_a); + +} + +static void imagebang_brk_timeout(t_imagebang *x) +{ + t_glist* glist = glist_getcanvas(x->glist); + x->flashing = 1; + sys_vgui(".x%x.c itemconfigure %ximage -image %x_imagebang \n", glist, x,x->image_b); + +} + + +/* widget helper functions */ + +static const char* imagebang_get_filename(t_imagebang *x,char *file) { + static char fname[MAXPDSTRING]; + char *bufptr; + int fd; + + fd=open_via_path(canvas_getdir(glist_getcanvas(x->glist))->s_name, + file, "",fname, &bufptr, MAXPDSTRING, 1); + if(fd>0){ + fname[strlen(fname)]='/'; + DEBUG(post("image file: %s",fname);) + close(fd); + return fname; + } else { + return 0; + } +} + +static int imagebang_click(t_imagebang *x, struct _glist *glist, + 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) ; + + return (1); + } + + + + +static void imagebang_drawme(t_imagebang *x, t_glist *glist, int 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);) + + sys_vgui(".x%x.c create image %d %d -anchor nw -image %x_imagebang -disabledimage %x_imagebang -tags %ximage\n", + glist_getcanvas(glist), + 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); + + + } else { + sys_vgui(".x%x.c coords %ximage %d %d\n", + glist_getcanvas(glist), x, + text_xpix(&x->x_obj, glist), text_ypix(&x->x_obj, glist)); + } + +} + + +void imagebang_erase(t_imagebang* x,t_glist* glist) +{ + int n; + sys_vgui(".x%x.c delete %ximage\n", + glist_getcanvas(glist), x); + +} + + + +/* ------------------------ image widgetbehaviour----------------------------- */ + + +static void imagebang_getrect(t_gobj *z, t_glist *glist, + int *xp1, int *yp1, int *xp2, int *yp2) +{ + int width, height; + t_imagebang* x = (t_imagebang*)z; + + + width = x->width; + height = x->height; + *xp1 = text_xpix(&x->x_obj, glist); + *yp1 = text_ypix(&x->x_obj, glist); + *xp2 = text_xpix(&x->x_obj, glist) + width; + *yp2 = text_ypix(&x->x_obj, glist) + height; +} + +static void imagebang_displace(t_gobj *z, t_glist *glist, + int dx, int dy) +{ + t_imagebang *x = (t_imagebang *)z; + x->x_obj.te_xpix += dx; + x->x_obj.te_ypix += dy; + sys_vgui(".x%x.c coords %xSEL %d %d %d %d\n", + glist_getcanvas(glist), x, + 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); + + imagebang_drawme(x, glist, 0); + canvas_fixlinesfor(glist_getcanvas(glist),(t_text*) x); +} + +static void imagebang_select(t_gobj *z, t_glist *glist, int state) +{ + t_imagebang *x = (t_imagebang *)z; + if (state) { + sys_vgui(".x%x.c create rectangle \ +%d %d %d %d -tags %xSEL -outline blue\n", + glist_getcanvas(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, + x); + } + else { + sys_vgui(".x%x.c delete %xSEL\n", + glist_getcanvas(glist), x); + } + + + +} + + +static void imagebang_activate(t_gobj *z, t_glist *glist, int state) +{ +/* t_text *x = (t_text *)z; + t_rtext *y = glist_findrtext(glist, x); + if (z->g_pd != gatom_class) rtext_activate(y, state);*/ +} + +static void imagebang_delete(t_gobj *z, t_glist *glist) +{ + t_text *x = (t_text *)z; + //canvas_deletelinesfor(glist_getcanvas(glist), x); + canvas_deletelinesfor(glist, x); +} + + +static void imagebang_vis(t_gobj *z, t_glist *glist, int vis) +{ + t_imagebang* s = (t_imagebang*)z; + if (vis) + imagebang_drawme(s, glist, 1); + else + imagebang_erase(s,glist); +} + + + + +static void imagebang_size(t_imagebang* x,t_floatarg w,t_floatarg h) { + x->width = w; + x->height = h; +} + + + + +static void imagebang_imagesize_callback(t_imagebang *x, t_float w, t_float h) { + DEBUG(post("received w %f h %f",w,h);) + x->width = w; + x->height = h; + canvas_fixlinesfor(glist_getcanvas(x->glist),(t_text*) x); +} + + +static void imagebang_free(t_imagebang *x) { + + // check first if variable has been unset and image is unused + // then delete image and unset variable + DEBUG(sys_vgui("pd [concat DEBUG b in use [image inuse %x_imagebang] \\;]\n",x->image_b);) + DEBUG(sys_vgui("pd [concat DEBUG a in use [image inuse %x_imagebang] \\;]\n",x->image_a);) + + sys_vgui("if { [info exists %x_imagebang] == 1 && [image inuse %x_imagebang] == 0} { image delete %x_imagebang \n unset %x_imagebang\n} \n",x->image_b,x->image_b,x->image_b,x->image_b); + sys_vgui("if { [info exists %x_imagebang] == 1 && [image inuse %x_imagebang] == 0} { image delete %x_imagebang \n unset %x_imagebang\n} \n",x->image_a,x->image_a,x->image_a,x->image_a); + + DEBUG(sys_vgui("pd [concat DEBUG b exists [info exists %x_imagebang] \\;]\n",x->image_b);) + DEBUG(sys_vgui("pd [concat DEBUG a exists [info exists %x_imagebang] \\;]\n",x->image_a);) + + if (x->receive) { + pd_unbind(&x->x_obj.ob_pd,x->receive); + } + clock_free(x->clock_flash); + clock_free(x->clock_brk); + +} + + +static void *imagebang_new(t_symbol *s, int argc, t_atom *argv) +{ + t_imagebang *x = (t_imagebang *)pd_new(imagebang_class); + + x->glist = (t_glist*) canvas_getcurrent(); + + // Set up a callback to get the size + x->width = 10; + x->height = 10; + + x->flashing = 0; + + x->image_a = NULL; + x->image_b = NULL; + + t_symbol* image_a = NULL; + t_symbol* image_b = NULL; + + const char *fname; + + // CREATE IMAGES + // images are only created if they have not been created yet + // we use the symbol pointer to distinguish between image files + + + if ( argc && (argv)->a_type == A_SYMBOL ) { + image_a= atom_getsymbol(argv); + fname = imagebang_get_filename(x,image_a->s_name); // Get image file path + if (fname) { + x->image_a = gensym(fname); + //sys_vgui("set %x_a \"%s\" \n",x,fname); + // Create the image only if the class has not already loaded the same image (with the same symbolic path name) + 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); + } else { + post("Oups... [imagebang] could not find \"%s\"",image_a->s_name); + } + } + + + + if ( argc > 1 && (argv+1)->a_type == A_SYMBOL ) { + image_b= atom_getsymbol(argv+1); + fname = imagebang_get_filename(x,image_b->s_name); // Get image file path + if (fname) { + x->image_b = gensym(fname); + //sys_vgui("set %x_b \"%s\" \n",x,fname); + 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); + } else { + post("Oups... [imagebang] could not find \"%s\"",image_b->s_name); + } + } + + // Stop if no images + if (x->image_a == NULL || x->image_b == NULL) { + post("Could not create [imagebang]... either no gif images defined or found!"); + return NULL; + } + + x->send = NULL; + if ( argc > 2 && (argv+2)->a_type == A_SYMBOL ) { + x->send = atom_getsymbol(argv+2); + } + + if ( argc > 3 && (argv+3)->a_type == A_SYMBOL ) { + x->receive = atom_getsymbol(argv+3); + } else { + // Create default receiver if none set + char buf[MAXPDSTRING]; + sprintf(buf, "#%lx", (long)x); + x->receive = gensym(buf); + } + + pd_bind(&x->x_obj.ob_pd, x->receive ); + + x->clock_flash = clock_new(x, (t_method)imagebang_flash_timeout); + x->clock_brk = clock_new(x, (t_method)imagebang_brk_timeout); + + + x->outlet = outlet_new(&x->x_obj, &s_float); + + + return (x); + +} + +void imagebang_setup(void) +{ + + + imagebang_class = class_new(gensym("imagebang"), (t_newmethod)imagebang_new, (t_method)imagebang_free, + sizeof(t_imagebang),0, A_GIMME,0); + + class_addmethod(imagebang_class, (t_method)imagebang_imagesize_callback,\ + gensym("_imagesize"), A_DEFFLOAT, A_DEFFLOAT, 0); + + class_addbang(imagebang_class,(t_method)imagebang_bang); + + imagebang_widgetbehavior.w_getrectfn = imagebang_getrect; + imagebang_widgetbehavior.w_displacefn = imagebang_displace; + imagebang_widgetbehavior.w_selectfn = imagebang_select; + imagebang_widgetbehavior.w_activatefn = imagebang_activate; + imagebang_widgetbehavior.w_deletefn = imagebang_delete; + imagebang_widgetbehavior.w_visfn = imagebang_vis; + + imagebang_widgetbehavior.w_clickfn = (t_clickfn)imagebang_click; + + +#if PD_MINOR_VERSION < 37 + imagebang_widgetbehavior.w_propertiesfn = NULL; + //imagebang_widgetbehavior.w_savefn = imagebang_save; +#endif + + + class_setwidget(imagebang_class,&imagebang_widgetbehavior); +#if PD_MINOR_VERSION >= 37 + // class_setsavefn(imagebang_class,&imagebang_save); +#endif + +} + + diff --git a/src/pmenu.c b/src/pmenu.c new file mode 100644 index 0000000..458a0b6 --- /dev/null +++ b/src/pmenu.c @@ -0,0 +1,436 @@ +/* pmenu widget for PD * + * Based on: + * pmenu by Ben Bogart + * and button from GGEE by Guenter Geiger * + + * This program is distributed under the terms of the GNU General Public * + * License * + + * pmenu is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + + * pmenu is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. */ + + + + +/* Append " x " to the following line to show debugging messages */ +#define DEBUG(x) + + +#include +#include +#include +#include + + + + + +typedef struct _pmenu +{ + t_object x_obj; + + t_glist * x_glist; + + t_symbol* callback; + + int current_selection; + int x_num_options; + t_symbol* bg_color; + t_symbol* fg_color; + t_symbol* hi_color; + t_symbol* co_color; + + t_symbol** x_options; + int x_maxoptions; + + int indicator; + int focusing; + +} t_pmenu; + +#include "pmenu_w.h" + +static void pmenu_output(t_pmenu* x) +{ + + + + t_atom atoms[2]; + SETFLOAT(atoms,x->current_selection); + SETSYMBOL(atoms+1,x->x_options[x->current_selection]); + outlet_list(x->x_obj.ob_outlet, &s_list, 2, atoms); + //if ( x->send != x->s_empty && x->send->s_thing) pd_forwardmess(x->send->s_thing, 2,atoms); + +} + + +static void pmenu_callback(t_pmenu* x, t_floatarg f) +{ + //DEBUG(post("output start");) + x->current_selection= (int)f; + //pmenu_w_text(x,x->x_options[x->current_selection]); + pmenu_output(x); + +} +/* +static void pmenu_save(t_gobj *z, t_binbuf *b) +{ + DEBUG(post("save start");) + + + t_pmenu *x = (t_pmenu *)z; + + t_atom* creation = binbuf_getvec(x->x_obj.te_binbuf); + + + t_symbol* send = x->s_empty; + t_symbol* receive = x->s_empty; + char buf[80]; + if ( x->send_set ) { + atom_string(creation + 3, buf, 80); + send = gensym(buf); + } + + if ( x->receive_set ) { + atom_string(creation + 4, buf, 80); + receive = gensym(buf); + } + + DEBUG(post("send: %s receive: %s",send->s_name,receive->s_name);) + + binbuf_addv(b, "ssiisiississss", gensym("#X"), gensym("obj"), + x->x_obj.te_xpix, x->x_obj.te_ypix , + atom_getsymbol(creation), + x->x_width, x->x_height, send,receive,x->saveitems, + x->bg_color, x->fg_color,x->hi_color,x->co_color); + + // Loop for menu items + int i; + if ( x->saveitems) { + for(i=0 ; ix_num_options ; i++) + { + DEBUG(post("saving option: %s",x->x_options[i]->s_name);) + binbuf_addv(b, "s", x->x_options[i]); + } + } + binbuf_addv(b, ";"); + + DEBUG(post("save end");) +} +*/ + +static void pmenu_clear(t_pmenu* x) { + + x->x_num_options = 0; + x->current_selection = -1; + pmenu_w_clear(x); + +} + +/* +static void pmenu_size(t_pmenu* x,t_symbol *s, int argc, t_atom *argv) { + + if (argc>2) argc =2; + switch (argc) { + case 2: if ( (argv+1)->a_type == A_FLOAT) x->x_height = atom_getfloat(argv+1); + case 1: if ( argv->a_type == A_FLOAT) x->x_width = atom_getfloat(argv); + break; + } + + if ( x->x_width < 10) x->x_width = 10; + if ( x->x_height < 10) x->x_height = 10; + + if ( pmenu_w_is_visible(x) ) { + pmenu_w_resize(x); + } +} +*/ + + +static void pmenu_add(t_pmenu* x, t_symbol *s, int argc, t_atom *argv) { + + + + // resize the options-array if it is too small + if((argc + x->x_num_options) > x->x_maxoptions){ + + x->x_options = resizebytes( x->x_options, x->x_maxoptions*sizeof(*(x->x_options)), + (argc + x->x_num_options+10)*sizeof(*(x->x_options))); + x->x_maxoptions=argc + x->x_num_options+10; + } + + int i; + t_symbol* label; + for ( i=0;ia_type==A_SYMBOL) { + + label = atom_getsymbol(argv+i); + DEBUG(post("adding option: %s",label->s_name);) + x->x_options[x->x_num_options] = label; + + pmenu_w_additem( x,label,x->x_num_options); + + x->x_num_options = x->x_num_options + 1; + } + + } + + +} + + + +// function to change the colors + +static void pmenu_colors(t_pmenu* x, t_symbol* s, int argc, t_atom* argv) +{ + + DEBUG(post("bgcolour start");) + + if ( argc && argv->a_type==A_SYMBOL && atom_getsymbol(argv)==gensym("default")) { + x->bg_color = gensym("grey90"); + x->fg_color = gensym("black"); + x->hi_color = gensym("grey95"); + x->co_color = gensym("black"); + } else { + + if (argc > 4) argc = 4; + switch (argc) { + case 4: if ((argv+3)->a_type==A_SYMBOL) x->co_color = atom_getsymbol(argv+3); + case 3: if ((argv+2)->a_type==A_SYMBOL) x->hi_color = atom_getsymbol(argv+2); + case 2: if ((argv+1)->a_type==A_SYMBOL) x->fg_color = atom_getsymbol(argv+1); + case 1: if ((argv)->a_type==A_SYMBOL) x->bg_color = atom_getsymbol(argv); + break; + } + } + + pmenu_w_apply_colors(x); + +} + + +static int pmenu_set_float(t_pmenu* x, t_floatarg item) { + + + int i=(int)item; + if( (i < x->x_num_options) && (i >= 0)) { + x->current_selection = i; + //if(pmenu_w_is_visible(x)) pmenu_w_text(x,x->x_options[x->current_selection]); + pmenu_w_activate(x); + return 1; + } else { + x->current_selection = -1; + pmenu_w_activate(x); + return 0; + } + +} + +/* Function to select a menu option by inlet */ +static void pmenu_float(t_pmenu* x, t_floatarg item) +{ + DEBUG(post("iselect start");) + + if ( pmenu_set_float(x,item) ) { + pmenu_output(x); + } else { + + //pd_error(x,"pmenu: expecting value between 0 and %i",x->x_num_options); + } + + DEBUG(post("iselect end");) +} + +static int pmenu_set_symbol(t_pmenu* x, t_symbol *s) { + + + int i; + + /* Compare inlet symbol to each option */ + for(i=0; i < x->x_num_options; i++) { + if(x->x_options[i]->s_name == s->s_name) { + x->current_selection = i; + //if(pmenu_w_is_visible(x)) pmenu_w_text(x,s); + pmenu_w_activate(x); + return 1; + } + } + x->current_selection = -1; + pmenu_w_activate(x); + return 0; +} + + +/* Function to choose value via symbol name */ +static void pmenu_symbol(t_pmenu* x, t_symbol *s) +{ + if(pmenu_set_symbol(x,s)) { + pmenu_output(x); + } else { + post("pmenu: '%s' is not an available option.", s->s_name); + } + +} + +/* Function to choose value via name/index but without outputting it*/ +static void pmenu_set(t_pmenu* x, t_symbol *S, int argc, t_atom*argv) +{ + if(!argc)return; + + if(argv->a_type==A_FLOAT) { + pmenu_set_float(x,atom_getfloat(argv)); + } else if(argv->a_type==A_SYMBOL) { + pmenu_set_symbol(x,atom_getsymbol(argv)); + } else { + pd_error(x, "pmenu: can only 'set' symbols or floats"); + } +} + + + + + + +static t_class *pmenu_class; + +/* +static void pmenu_receive(t_pmenu* x, t_symbol* s) { + if ( x->receive != x->s_empty ) pd_unbind(&x->x_obj.ob_pd, x->receive); + if ( s == x->s_empty || s == x->s_) { + x->receive = x->s_empty; + } else { + x->receive = s; + pd_bind(&x->x_obj.ob_pd, x->receive); + } + +} + +static void pmenu_send(t_pmenu* x, t_symbol* s) { + + if ( s == x->s_empty || s == x->s_ ) { + x->send = x->s_empty; + } else { + x->send = s; + } + + + +} +*/ + +static void pmenu_free(t_pmenu*x) +{ + pmenu_w_menu(x,DESTROY); + + + if(x->x_options)freebytes(x->x_options, sizeof(t_symbol*)*x->x_maxoptions); + pd_unbind(&x->x_obj.ob_pd, x->callback); + + //if ( x->receive != x->s_empty ) pd_unbind(&x->x_obj.ob_pd, x->receive); +} +/* +static void pmenu_saveitems( t_pmenu* x, t_float f) { + x->saveitems = (f != 0); +} +*/ + +static void *pmenu_new(t_symbol *s, int argc, t_atom *argv) +{ + DEBUG(post("pmenu new start");) + + t_pmenu *x = (t_pmenu *)pd_new(pmenu_class); + int i; + char buf[256]; + + + x->current_selection = -1; + + x->x_maxoptions=10; + x->x_options=(t_symbol**)getbytes(sizeof(t_symbol*)*x->x_maxoptions); + + x->x_num_options = 0 ; + + x->indicator = 1; + x->focusing = 1; + + + // These should match the default colors in pmenu_colors + x->bg_color = gensym("grey90"); + x->fg_color = gensym("black"); + x->hi_color = gensym("grey95"); + x->co_color = gensym("black"); + + + if (argc > 6) argc = 6; + switch(argc){ + case 6: if ((argv+5)->a_type==A_SYMBOL) x->co_color = atom_getsymbol(argv+5); + case 5: if ((argv+4)->a_type==A_SYMBOL) x->hi_color = atom_getsymbol(argv+4); + case 4: if ((argv+3)->a_type==A_SYMBOL) x->fg_color = atom_getsymbol(argv+3); + case 3: if ((argv+2)->a_type==A_SYMBOL) x->bg_color = atom_getsymbol(argv+2); + case 2: if ((argv+1)->a_type==A_FLOAT) x->focusing = atom_getfloat(argv+1); + case 1: if ((argv)->a_type==A_FLOAT) x->indicator = atom_getfloat(argv); + break; + } + + /* Bind the recieve "pmenu%p" to the widget outlet*/ + sprintf(buf,"pmenu%p",x); + x->callback = gensym(buf); + pd_bind(&x->x_obj.ob_pd, x->callback); + + /* define proc in tcl/tk where "pmenu%p" is the receive, "callback" is the method, and "$index" is an argument. */ + sys_vgui("proc select%x {index} {\n pd [concat pmenu%p callback $index \\;]\n }\n",x,x); + + + outlet_new(&x->x_obj, &s_symbol); + + pmenu_w_menu(x,CREATE); + pmenu_w_apply_colors(x); + //if (argc > 5) pmenu_add(x,&s_list,argc-5,argv+5); + + +DEBUG(post("pmenu new end");) + + return (x); +} + +void pmenu_setup(void) { + + DEBUG(post("setup start");) + + pmenu_class = class_new(gensym("pmenu"), (t_newmethod)pmenu_new, (t_method)pmenu_free, + sizeof(t_pmenu),0,A_GIMME,0); + + class_addbang(pmenu_class, (t_method)pmenu_w_pop); + + class_addmethod(pmenu_class, (t_method)pmenu_callback, + gensym("callback"),A_DEFFLOAT,0); + + class_addmethod(pmenu_class, (t_method)pmenu_add, + gensym("add"), A_GIMME,0); + + class_addmethod(pmenu_class, (t_method)pmenu_clear, + gensym("clear"), 0); + + class_addmethod(pmenu_class, (t_method)pmenu_colors, + gensym("colors"),A_GIMME,0); + + class_addmethod(pmenu_class, (t_method)pmenu_set, + gensym("set"),A_GIMME,0); + + class_addsymbol(pmenu_class, (t_method)pmenu_symbol); + + class_addfloat(pmenu_class, (t_method)pmenu_float); + + + + post("pmenu v0.02 by tof"); +} + + diff --git a/src/pmenu_w.h b/src/pmenu_w.h new file mode 100644 index 0000000..b1ff496 --- /dev/null +++ b/src/pmenu_w.h @@ -0,0 +1,91 @@ + +#define UPDATE 0 +#define CREATE 1 +#define DESTROY 2 + +#define COLUMNBREAK 30 + +static void pmenu_w_activate(t_pmenu* x){ + //sys_vgui("$%xw activate %i\n", x,x->current_selection); + //if ( x->indicator) { + sys_vgui("set %xradio %i\n",x,x->current_selection); + //} else { + + // sys_vgui("set %xradio %i\n",x,-1); + //} +} + + +static void pmenu_w_clear(t_pmenu* x){ + sys_vgui("$%xw delete 0 end \n", x); + //sys_vgui("set %xradio %i\n",x,-1); + x->current_selection = -1; + pmenu_w_activate(x); +} + +static void pmenu_w_additem(t_pmenu* x, t_symbol *label, int i) { + if ( x->indicator) { + sys_vgui("$%xw add radiobutton -label \"%s\" -command {select%x \"%d\"} -variable %xradio -value %d \n", + x, label->s_name, x, i,x,i); + + } else { + sys_vgui("$%xw add command -label \"%s\" -command {select%x \"%d\"} \n", + x, label->s_name, x, i,x,i); + } + if ( i == COLUMNBREAK ) sys_vgui("$%xw entryconfigure %i -columnbreak true \n",x,i); + +} + +static void pmenu_w_apply_colors(t_pmenu* x) { + + sys_vgui("$%xw configure -background \"%s\" -foreground \"%s\" -activeforeground \"%s\" -activebackground \"%s\" -selectcolor \"%s\"\n", x, + x->bg_color->s_name,x->fg_color->s_name,x->fg_color->s_name,x->hi_color->s_name,x->fg_color->s_name); + + +} + + +static void pmenu_w_menu(t_pmenu *x, int draw) +{ + DEBUG(post("menu start");) + + if ( draw == CREATE ) { + //x->created = 1; + // Create menu + //sys_vgui("set %xw .x%x.c.s%x ; menubutton $%xw -justify left + // Create a variable to store a pointer to the menu, create the menu, create a variable to store the selected item + sys_vgui("set %xw .%x ; menu $%xw -relief solid -tearoff 0; set %xradio -1 \n",x,x,x); + int i; + for(i=0 ; ix_num_options ; i++) + { + // Add menu itmes + pmenu_w_additem(x,x->x_options[i],i); + } + } else if ( draw == DESTROY) { + //x->created = 0; + + + sys_vgui("destroy $%xw \n",x); + + } + + //DEBUG(post("id: .x%x.c.s%x", glist, x);) + DEBUG(post("menu end");) +} + + +static void pmenu_w_pop(t_pmenu *x) { + + if (x->x_num_options > 0) { + //if ( x->created == 0 ) pmenu_w_menu(x, glist, CREATE); + if ( x->current_selection != -1 && x->focusing) { + sys_vgui("tk_popup $%xw [winfo pointerx .] [winfo pointery .] %i\n",x,x->current_selection); + } else { + sys_vgui("tk_popup $%xw [winfo pointerx .] [winfo pointery .] \n",x); + } + } + +} + + + -- cgit v1.2.1