[PD-cvs] externals/bbogart/popup popup.c,1.11,1.12
IOhannes m zmölnig
zmoelnig at users.sourceforge.net
Mon Jun 6 17:13:46 CEST 2005
Update of /cvsroot/pure-data/externals/bbogart/popup
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31995
Modified Files:
popup.c
Log Message:
- removed the MAX_OPTIONS; we can now have an "infinite" number of options (without segfaulting !)
- you can now specify less than 5 arguments: "popup [<w> <h> [<c> [<n> [<o1> ...]]]]"
Index: popup.c
===================================================================
RCS file: /cvsroot/pure-data/externals/bbogart/popup/popup.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -C2 -d -r1.11 -r1.12
*** popup.c 17 Jan 2005 21:06:59 -0000 1.11
--- popup.c 6 Jun 2005 15:13:43 -0000 1.12
***************
*** 45,49 ****
t_glist * x_glist;
t_outlet* out2;
- t_inlet* in2;
int x_rect_width;
int x_rect_height;
--- 45,48 ----
***************
*** 58,63 ****
t_symbol* x_name;
! t_symbol* x_options[MAX_OPTIONS];
!
} t_popup;
--- 57,62 ----
t_symbol* x_name;
! t_symbol** x_options;
! int x_maxoptions;
} t_popup;
***************
*** 387,390 ****
--- 386,396 ----
sys_vgui(".x%x.c.s%x.menu delete 0 end \n", x->x_glist, x);
+ if(argc>x->x_maxoptions){
+ /* resize the options-array */
+ if(x->x_options)freebytes(x->x_options, sizeof(t_symbol*)*x->x_maxoptions);
+ x->x_maxoptions=argc;
+ x->x_options=(t_symbol**)getbytes(sizeof(t_symbol*)*x->x_maxoptions);
+ }
+
for(i=0 ; i<argc ; i++)
{
***************
*** 463,466 ****
--- 469,488 ----
new_limit = x->x_num_options + argc;
+ if(new_limit>x->x_maxoptions){
+ t_symbol**dummy;
+ int new_size=new_limit*2;
+ DEBUG(post("resizing options");)
+ dummy=(t_symbol**)getbytes(sizeof(t_symbol*)*new_size);
+ if(dummy)
+ {
+ memcpy(dummy, x->x_options, sizeof(t_symbol*)*x->x_maxoptions);
+ freebytes(x->x_options, sizeof(t_symbol*)*x->x_maxoptions);
+ x->x_maxoptions=new_size;
+ x->x_options=dummy;
+ } else {
+ error("popup: no memory for options");
+ return;
+ }
+ }
for(i=x->x_num_options ; i<new_limit ; i++)
***************
*** 480,483 ****
--- 502,510 ----
static t_class *popup_class;
+ static void popup_free(t_popup*x)
+ {
+ if(x->x_options)freebytes(x->x_options, sizeof(t_symbol*)*x->x_maxoptions);
+ }
+
static void *popup_new(t_symbol *s, int argc, t_atom *argv)
***************
*** 493,529 ****
x->x_height = 25;
x->current_selection = -1;
!
! if (argc < 5)
! {
! post("popup: You must enter at least 5 arguments. Default values used.\n\nArguments:\npopup [width] [height] [colour] [name] [option-1] [option-2] ...");
! x->x_width = 124;
! x->x_height = 25;
! x->x_num_options = 1;
! x->x_colour = gensym("#ffffff");
! x->x_name = gensym("popup");
!
! x->x_options[0] = gensym("option");
!
! } else {
! /* Copy args into structure */
! x->x_width = atom_getint(argv);
! x->x_height = atom_getint(argv+1);
! x->x_colour = atom_getsymbol(argv+2);
! x->x_name = atom_getsymbol(argv+3);
!
! x->x_num_options = argc-4;
! for(i=0 ; i<x->x_num_options ; i++)
! {
! x->x_options[i] = atom_getsymbol( argv+(i+4) );
! }
! }
! /* Bind the recieve "popup%p" to the widget outlet*/
! sprintf(buf,"popup%p",x);
! x->x_sym = gensym(buf);
! pd_bind(&x->x_obj.ob_pd, x->x_sym);
! /* define proc in tcl/tk where "popup%p" is the receive, "output" is the method, and "$index" is an argument. */
sys_vgui("proc popup_sel%x {index} {\n pd [concat popup%p output $index \\;]\n }\n",x,x);
--- 520,565 ----
x->x_height = 25;
x->current_selection = -1;
!
! x->x_maxoptions=MAX_OPTIONS;
! x->x_options=(t_symbol**)getbytes(sizeof(t_symbol*)*x->x_maxoptions);
!
!
! x->x_width = 124;
! x->x_height = 25;
! x->x_num_options = 1;
! x->x_colour = gensym("#ffffff");
! x->x_name = gensym("popup");
!
! x->x_options[0] = gensym("option");
!
! switch(argc){
! case 0: break; /* just use default values */
! case 1:
! post("popup: You must enter at least 5 arguments. Default values used.\n\nArguments:\npopup [width] [height] [colour] [name] [option-1] [option-2] ...");
! break;
! default:
! /* Copy args into structure */
! x->x_num_options = argc-4;
! for(i=0 ; i<x->x_num_options ; i++)
! {
! x->x_options[i] = atom_getsymbol( argv+(i+4) );
! }
! case 4:
! x->x_name = atom_getsymbol(argv+3);
! case 3:
! x->x_colour = atom_getsymbol(argv+2);
! case 2:
! x->x_width =atom_getint(argv+0);
! x->x_height=atom_getint(argv+1);
! break;
! }
! /* Bind the recieve "popup%p" to the widget outlet*/
! sprintf(buf,"popup%p",x);
! x->x_sym = gensym(buf);
! pd_bind(&x->x_obj.ob_pd, x->x_sym);
! /* define proc in tcl/tk where "popup%p" is the receive, "output" is the method, and "$index" is an argument. */
sys_vgui("proc popup_sel%x {index} {\n pd [concat popup%p output $index \\;]\n }\n",x,x);
***************
*** 542,546 ****
DEBUG(post("setup start");)
! popup_class = class_new(gensym("popup"), (t_newmethod)popup_new, 0,
sizeof(t_popup),0,A_GIMME,0);
--- 578,582 ----
DEBUG(post("setup start");)
! popup_class = class_new(gensym("popup"), (t_newmethod)popup_new, (t_method)popup_free,
sizeof(t_popup),0,A_GIMME,0);
***************
*** 577,581 ****
class_doaddfloat(popup_class, (t_method)popup_iselect);
! // class_addsymbol(popup_class, (t_method)popup_symselect);
class_setwidget(popup_class,&popup_widgetbehavior);
--- 613,617 ----
class_doaddfloat(popup_class, (t_method)popup_iselect);
! //class_addsymbol(popup_class, (t_method)popup_symselect);
class_setwidget(popup_class,&popup_widgetbehavior);
More information about the Pd-cvs
mailing list