aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--popup/popup-help.pd48
-rw-r--r--popup/popup.c62
2 files changed, 65 insertions, 45 deletions
diff --git a/popup/popup-help.pd b/popup/popup-help.pd
index 2aa0ae8..3142ff8 100644
--- a/popup/popup-help.pd
+++ b/popup/popup-help.pd
@@ -1,35 +1,39 @@
-#N canvas 119 198 631 397 10;
-#X obj 106 300 popup 124 25 grey90 duh! one two three four five six
+#N canvas 119 198 626 449 10;
+#X obj 106 340 popup 124 25 grey90 duh! one two three four five six
seven eight nine ten eleven twelve thirteen i14 i15 i16 i17 i18 i19
i20 i21 i22 i23 i24 i25 i26 i27 i28 i29 i30;
-#X obj 152 359 print index;
-#X msg 96 108 name popup;
-#X obj 239 359 print symbol;
-#X floatatom 43 94 5 0 0 0 - - -;
-#X text 13 11 popup \, a popup menu for PD. Copyright Ben Bogart 2004
-Released under the GPL.;
+#X obj 152 399 print index;
+#X msg 30 98 name popup;
+#X obj 239 399 print symbol;
+#X floatatom 163 292 5 0 0 0 - - -;
#X text 14 43 Left outlet sends out a bang on load \, used to set default
value. Using a loadbang to send a float will result in a crash.;
-#X msg 173 235 options;
-#X msg 166 186 options one two three four five six seven eight nine
+#X msg 107 225 options;
+#X msg 100 176 options one two three four five six seven eight nine
ten eleven twelve thirteen i14 i15 i16 i17 i18 i19 i20 i21 i22 i23
i24 i25 i26 i27 i28 i29 i30;
-#X msg 184 261 append append-one append-two append-three;
-#X obj 106 332 route bang;
-#X msg 33 298 10;
-#X text 187 332 Choose 10 as the default value on load \, does send
+#X msg 118 251 append append-one append-two append-three;
+#X obj 106 372 route bang;
+#X msg 33 338 10;
+#X text 187 372 Choose 10 as the default value on load \, does send
output.;
-#X msg 119 133 bgcolour #047992;
-#X msg 149 160 bgcolour grey90;
-#X connect 0 0 10 0;
+#X msg 53 123 bgcolour #047992;
+#X msg 83 150 bgcolour grey90;
+#X symbolatom 223 315 10 0 0 0 - - -;
+#X text 209 289 Select by index;
+#X text 302 314 Select by symbol name;
+#X text 13 11 popup \, a popup menu for PD. Copyright Ben Bogart 2004
+\, 2005 Released under the GPL.;
+#X connect 0 0 9 0;
#X connect 0 1 3 0;
#X connect 2 0 0 0;
#X connect 4 0 0 0;
+#X connect 6 0 0 0;
#X connect 7 0 0 0;
#X connect 8 0 0 0;
-#X connect 9 0 0 0;
-#X connect 10 0 11 0;
-#X connect 10 1 1 0;
-#X connect 11 0 0 0;
+#X connect 9 0 10 0;
+#X connect 9 1 1 0;
+#X connect 10 0 0 0;
+#X connect 12 0 0 0;
#X connect 13 0 0 0;
-#X connect 14 0 0 0;
+#X connect 14 0 0 1;
diff --git a/popup/popup.c b/popup/popup.c
index 854a185..0713db5 100644
--- a/popup/popup.c
+++ b/popup/popup.c
@@ -44,6 +44,7 @@ typedef struct _popup
t_glist * x_glist;
t_outlet* out2;
+ t_inlet* in2;
int x_rect_width;
int x_rect_height;
t_symbol* x_sym;
@@ -62,7 +63,7 @@ typedef struct _popup
/* widget helper functions */
/* Append " x " to the following line to show debugging messages */
-#define DEBUG(x)
+#define DEBUG(x)
static void draw_inlets(t_popup *x, t_glist *glist, int firsttime, int nin, int nout)
@@ -96,14 +97,14 @@ static void draw_inlets(t_popup *x, t_glist *glist, int firsttime, int nin, int
if (firsttime)
sys_vgui(".x%x.c create rectangle %d %d %d %d -tags {%xi%d %xi}\n",
glist_getcanvas(glist),
- onset, text_ypix(&x->x_obj, glist),
- onset + IOWIDTH, text_ypix(&x->x_obj, glist)+1,
+ onset, text_ypix(&x->x_obj, glist)-2,
+ onset + IOWIDTH, text_ypix(&x->x_obj, glist)-1,
x, i, x);
else
sys_vgui(".x%x.c coords %xi%d %d %d %d %d\n",
glist_getcanvas(glist), x, i,
onset, text_ypix(&x->x_obj, glist),
- onset + IOWIDTH, text_ypix(&x->x_obj, glist)+1);
+ onset + IOWIDTH, text_ypix(&x->x_obj, glist)-1);
}
DEBUG(post("draw inlet end");)
@@ -173,18 +174,17 @@ static void popup_drawme(t_popup *x, t_glist *glist, int firsttime)
}
else {
- sys_vgui(".x%x.c coords %xS \
-%d %d\n",
+ sys_vgui(".x%x.c coords %xS %d %d\n",
canvas, x,
text_xpix(&x->x_obj, glist), text_ypix(&x->x_obj, glist));
}
- draw_inlets(x, glist, firsttime, 2,1);
+ draw_inlets(x, glist, firsttime, 2,2);
// draw_handle(x, glist, firsttime);
- DEBUG(post("drawme end");)
+ // Output a bang to first outlet when we're ready to receive float messages the first time!.
+ if(firsttime) {outlet_bang(x->x_obj.ob_outlet);}
-// Output a bang to first outlet when we're ready to receive float messages the first time!.
-if(firsttime) {outlet_bang(x->x_obj.ob_outlet);}
+ DEBUG(post("drawme end");)
}
@@ -419,20 +419,27 @@ static void popup_iselect(t_popup* x, t_floatarg item)
DEBUG(post("iselect end");)
}
-/* Function to append symbols to popup list
-static void popup_append(t_popup* x, t_symbol *item)
+/* Function to choose value via symbol name */
+static void popup_symselect(t_popup* x, t_symbol *s)
{
- // Add menu item
- sys_vgui(".x%x.c.s%x.menu add command -label \"%s\" -command {.x%x.c.s%x configure -text \"%s\" ; popup_sel%x \"%d\"} \n",
- x->x_glist, x, item->s_name, x->x_glist, x, item->s_name, x, (x->x_num_options-1) );
+ int i,match=0;
- post("orig num_options: %d", x->x_num_options);
-
- // Incriment num_options
- x->x_num_options++;
+ /* 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)
+ {
+ sys_vgui(".x%x.c.s%x configure -text \"%s\" ; popup_sel%x \"%d\" \n",
+ glist_getcanvas(x->x_glist), x, x->x_options[i]->s_name,x, i);
+ match = 1;
+ break;
+ }
+ }
- post("post num_options: %d", x->x_num_options);
-} */
+ if(match != 1)
+ post("popup: '%s' is not an available option.", s->s_name);
+
+}
/* Function to append symbols to popup list */
void popup_append(t_popup* x, t_symbol *s, int argc, t_atom *argv)
@@ -507,8 +514,10 @@ static void *popup_new(t_symbol *s, int argc, t_atom *argv)
/* 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);
+ /* Add symbol inlet (hard to say how this actually works?? */
+ inlet_new(&x->x_obj, &x->x_obj.ob_pd, gensym("symbol"), gensym(""));
outlet_new(&x->x_obj, &s_float);
- x->out2 = outlet_new(&x->x_obj, &s_symbol);
+ x->out2 = outlet_new(&x->x_obj, &s_symbol);
return (x);
DEBUG(post("popup new end");)
@@ -547,14 +556,21 @@ void popup_setup(void) {
A_GIMME,
0);
+ class_addmethod(popup_class, (t_method)popup_symselect,
+ gensym(""),
+ A_DEFSYMBOL,
+ 0);
+
class_doaddfloat(popup_class, (t_method)popup_iselect);
+// class_addsymbol(popup_class, (t_method)popup_symselect);
+
class_setwidget(popup_class,&popup_widgetbehavior);
#if PD_MINOR_VERSION >= 37
class_setsavefn(popup_class,&popup_save);
#endif
- post("Popup v0.1 Ben Bogart.\nCVS: $Revision: 1.9 $ $Date: 2004-12-13 23:56:59 $");
+ post("Popup v0.1 Ben Bogart.\nCVS: $Revision: 1.10 $ $Date: 2005-01-14 20:12:00 $");
}