aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuenter Geiger <ggeiger@users.sourceforge.net>2002-07-30 20:38:08 +0000
committerGuenter Geiger <ggeiger@users.sourceforge.net>2002-07-30 20:38:08 +0000
commit1e95251ece30b08cd2957e2f030a71badf9f12a5 (patch)
tree72e451d5a586c570b9c66a5632c458a994762097
parent6f650112690cda75d7691350f3bb5b571b3f14fb (diff)
added button and some bugfixes
svn path=/trunk/externals/ggee/; revision=68
-rw-r--r--gui/fatom.h415
-rw-r--r--gui/image.c1
-rwxr-xr-xgui/state.c6
-rwxr-xr-xgui/state.pd88
-rwxr-xr-xgui/testsave.19
-rwxr-xr-xgui/testsave.29
6 files changed, 464 insertions, 64 deletions
diff --git a/gui/fatom.h b/gui/fatom.h
new file mode 100644
index 0000000..fc814d7
--- /dev/null
+++ b/gui/fatom.h
@@ -0,0 +1,415 @@
+/* ------------------------ fatom ----------------------------- */
+
+#define x_val a_pos.a_w.w_float
+#define DEBUG(x)
+
+typedef struct _fatom
+{
+ t_object x_obj;
+ t_atom a_pos;
+
+ t_glist * x_glist;
+ int x_rect_width;
+ int x_rect_height;
+ t_symbol* x_sym;
+ t_symbol* x_type;
+
+ int x_max;
+ int x_min;
+ int x_width;
+} t_fatom;
+
+/* widget helper functions */
+
+
+
+
+static void draw_inlets(t_fatom *x, t_glist *glist, int firsttime, int nin, int nout)
+{
+ int n = nin;
+ int nplus, i;
+ nplus = (n == 1 ? 1 : n-1);
+ DEBUG(post("draw inlet");)
+ for (i = 0; i < n; i++)
+ {
+ int onset = text_xpix(&x->x_obj, glist) + (x->x_rect_width - IOWIDTH) * i / nplus;
+ if (firsttime)
+ sys_vgui(".x%x.c create rectangle %d %d %d %d -tags %xo%d\n",
+ glist_getcanvas(glist),
+ onset, text_ypix(&x->x_obj, glist) + x->x_rect_height - 1,
+ onset + IOWIDTH, text_ypix(&x->x_obj, glist) + x->x_rect_height,
+ x, i);
+ else
+ sys_vgui(".x%x.c coords %xo%d %d %d %d %d\n",
+ glist_getcanvas(glist), x, i,
+ onset, text_ypix(&x->x_obj, glist) + x->x_rect_height - 1,
+ onset + IOWIDTH, text_ypix(&x->x_obj, glist) + x->x_rect_height);
+ }
+ n = nout;
+ nplus = (n == 1 ? 1 : n-1);
+ for (i = 0; i < n; i++)
+ {
+ int onset = text_xpix(&x->x_obj, glist) + (x->x_rect_width - IOWIDTH) * i / nplus;
+ if (firsttime)
+ sys_vgui(".x%x.c create rectangle %d %d %d %d -tags %xi%d\n",
+ glist_getcanvas(glist),
+ onset, text_ypix(&x->x_obj, glist),
+ onset + IOWIDTH, text_ypix(&x->x_obj, glist) + 1,
+ x, i);
+ 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);
+
+ }
+ DEBUG(post("draw inlet end");)
+}
+
+
+static void draw_handle(t_fatom *x, t_glist *glist, int firsttime) {
+ int onset = text_xpix(&x->x_obj, glist) + (x->x_rect_width - IOWIDTH+2);
+
+ if (firsttime)
+ sys_vgui(".x%x.c create rectangle %d %d %d %d -tags %xhandle\n",
+ glist_getcanvas(glist),
+ onset, text_ypix(&x->x_obj, glist) + x->x_rect_height - 12,
+ onset + IOWIDTH, text_ypix(&x->x_obj, glist) + x->x_rect_height-4,
+ x);
+ else
+ sys_vgui(".x%x.c coords %xhandle %d %d %d %d\n",
+ glist_getcanvas(glist), x,
+ onset, text_ypix(&x->x_obj, glist) + x->x_rect_height - 12,
+ onset + IOWIDTH, text_ypix(&x->x_obj, glist) + x->x_rect_height-4);
+}
+
+static void create_widget(t_fatom *x, t_glist *glist)
+{
+ t_canvas *canvas=glist_getcanvas(glist);
+ if (!strcmp(x->x_type->s_name,"vslider")) {
+ x->x_rect_width = x->x_width+15;
+ x->x_rect_height = x->x_max-x->x_min+24;
+
+ sys_vgui("scale .x%x.c.s%x \
+ -sliderlength 10 \
+ -showvalue 0 \
+ -length %d \
+ -resolution 0.01 \
+ -repeatinterval 20 \
+ -from %d -to %d \
+ -width %d \
+ -command fatom_cb%x\n",canvas,x,
+ x->x_max-x->x_min+14,
+ x->x_max,
+ x->x_min,
+ x->x_width,
+ x);
+ } else if (!strcmp(x->x_type->s_name,"hslider")) {
+ x->x_rect_width = x->x_max-x->x_min + 24;
+ x->x_rect_height = x->x_width + 15;
+ sys_vgui("scale .x%x.c.s%x \
+ -sliderlength 10 \
+ -showvalue 0 \
+ -length %d \
+ -resolution 0.01 \
+ -orient horizontal \
+ -repeatinterval 20 \
+ -from %d -to %d \
+ -width %d \
+ -command fatom_cb%x\n",canvas,x,
+ x->x_max-x->x_min+14,
+ x->x_max,
+ x->x_min,
+ x->x_width,
+ x);
+ } else if (!strcmp(x->x_type->s_name,"checkbutton")) {
+ x->x_rect_width = 30;
+ x->x_rect_height = 25;
+ sys_vgui("checkbutton .x%x.c.s%x \
+ -command { fatom_cb%x $fatom_val%x} -variable fatom_val%x\n",canvas,x,x,x,x);
+ } else if (!strcmp(x->x_type->s_name,"hradio")) {
+ int i;
+ x->x_rect_width = 8*20;
+ x->x_rect_height = 25;
+ for (i=0;i<8;i++) {
+ sys_vgui("radiobutton .x%x.c.s%x%d \
+ -command { fatom_cb%x $fatom_val%x} -variable fatom_val%x -value %d\n",canvas,x,i,x,x,x,i);
+ }
+ /* TODO pack them */
+ } else if (!strcmp(x->x_type->s_name,"vradio")) {
+ int i;
+ x->x_rect_width = 30;
+ x->x_rect_height = 20*8+5;
+ for (i=0;i<8;i++) {
+ sys_vgui("radiobutton .x%x.c.s%x%d \
+ -command { fatom_cb%x $fatom_val%x} -variable fatom_val%x -value %d\n",canvas,x,i,x,x,x,i);
+ }
+ /* TODO pack them */
+ } else {
+ x->x_rect_width = 32;
+ x->x_rect_height = 140;
+ sys_vgui("scale .x%x.c.s%x \
+ -sliderlength 10 \
+ -showvalue 0 \
+ -length 131 \
+ -from 127 -to 0 \
+ -command fatom_cb%x\n",canvas,x,x);
+ }
+}
+
+
+
+
+
+static void fatom_drawme(t_fatom *x, t_glist *glist, int firsttime)
+{
+ t_canvas *canvas=glist_getcanvas(glist);
+ DEBUG(post("drawme %d",firsttime);)
+ if (firsttime) {
+ DEBUG(post("glist %x canvas %x",x->x_glist,canvas);)
+ if (x->x_glist != canvas) {
+ create_widget(x,glist);
+ x->x_glist = canvas;
+ }
+ sys_vgui(".x%x.c create window %d %d -anchor nw -window .x%x.c.s%x -tags %xS\n",
+ canvas,text_xpix(&x->x_obj, glist), text_ypix(&x->x_obj, glist)+2,x->x_glist,x,x);
+
+ }
+ else {
+ sys_vgui(".x%x.c coords %xS \
+%d %d\n",
+ canvas, x,
+ text_xpix(&x->x_obj, glist), text_ypix(&x->x_obj, glist)+2);
+ }
+ draw_inlets(x, glist, firsttime, 1,1);
+ draw_handle(x, glist, firsttime);
+
+}
+
+
+static void fatom_erase(t_fatom* x,t_glist* glist)
+{
+ int n;
+
+ DEBUG(post("erase");)
+// sys_vgui(".x%x.c.s%x delete\n",glist_getcanvas(glist),x);
+
+ sys_vgui(".x%x.c delete %xS\n",glist_getcanvas(glist), x);
+
+ /* inlets and outlets */
+
+ sys_vgui(".x%x.c delete %xi%d\n",glist_getcanvas(glist),x,0);
+ sys_vgui(".x%x.c delete %xo%d\n",glist_getcanvas(glist),x,0);
+ sys_vgui(".x%x.c delete %xhandle\n",glist_getcanvas(glist),x,0);
+}
+
+
+
+/* ------------------------ fatom widgetbehaviour----------------------------- */
+
+
+static void fatom_getrect(t_gobj *z, t_glist *owner,
+ int *xp1, int *yp1, int *xp2, int *yp2)
+{
+ int width, height;
+ t_fatom* s = (t_fatom*)z;
+
+ width = s->x_rect_width;
+ height = s->x_rect_height;
+ *xp1 = text_xpix(&s->x_obj, owner);
+ *yp1 = text_ypix(&s->x_obj, owner);
+ *xp2 = text_xpix(&s->x_obj, owner) + width;
+ *yp2 = text_ypix(&s->x_obj, owner) + height;
+}
+
+static void fatom_displace(t_gobj *z, t_glist *glist,
+ int dx, int dy)
+{
+ t_fatom *x = (t_fatom *)z;
+ DEBUG(post("displace");)
+ x->x_obj.te_xpix += dx;
+ x->x_obj.te_ypix += dy;
+ if (glist_isvisible(glist))
+ {
+ 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->x_rect_width, text_ypix(&x->x_obj, glist) + x->x_rect_height);
+
+ fatom_drawme(x, glist, 0);
+ canvas_fixlinesfor(glist_getcanvas(glist),(t_text*) x);
+ }
+ DEBUG(post("displace end");)
+}
+
+static void fatom_select(t_gobj *z, t_glist *glist, int state)
+{
+ t_fatom *x = (t_fatom *)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->x_rect_width, text_ypix(&x->x_obj, glist) + x->x_rect_height,
+ x);
+ }
+ else {
+ sys_vgui(".x%x.c delete %xSEL\n",
+ glist_getcanvas(glist), x);
+ }
+
+
+
+}
+
+
+static void fatom_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 fatom_delete(t_gobj *z, t_glist *glist)
+{
+ t_text *x = (t_text *)z;
+ canvas_deletelinesfor(glist_getcanvas(glist), x);
+}
+
+
+static void fatom_vis(t_gobj *z, t_glist *glist, int vis)
+{
+ t_fatom* s = (t_fatom*)z;
+ t_rtext *y;
+ DEBUG(post("vis: %d",vis);)
+ if (vis) {
+ y = (t_rtext *) rtext_new_without_senditup(glist, (t_text *)z, glist->gl_editor->e_rtext);
+ fatom_drawme(s, glist, 1);
+ }
+ else {
+ y = glist_findrtext(glist, (t_text *)z);
+ fatom_erase(s,glist);
+ rtext_free(y);
+ }
+}
+
+static void fatom_save(t_gobj *z, t_binbuf *b);
+
+t_widgetbehavior fatom_widgetbehavior = {
+ w_getrectfn: fatom_getrect,
+ w_displacefn: fatom_displace,
+ w_selectfn: fatom_select,
+ w_activatefn: fatom_activate,
+ w_deletefn: fatom_delete,
+ w_visfn: fatom_vis,
+ w_savefn: fatom_save,
+ w_clickfn: NULL,
+ w_propertiesfn: NULL,
+};
+
+
+void fatom_size(t_fatom* x,t_floatarg w,t_floatarg h) {
+ x->x_rect_width = w;
+ x->x_rect_height = h;
+}
+
+void fatom_color(t_fatom* x,t_symbol* col)
+{
+/* outlet_bang(x->x_obj.ob_outlet); only bang if there was a bang ..
+ so color black does the same as bang, but doesn't forward the bang
+*/
+}
+
+static void fatom_float(t_fatom* x,t_floatarg f)
+{
+
+ x->x_val = f;
+ if (!strcmp(x->x_type->s_name,"checkbutton")) {
+ if (x->x_val)
+ sys_vgui(".x%x.c.s%x select\n",x->x_glist,x,f);
+ else
+ sys_vgui(".x%x.c.s%x deselect\n",x->x_glist,x,f);
+ } else
+ sys_vgui(".x%x.c.s%x set %f\n",x->x_glist,x,f);
+ outlet_float(x->x_obj.ob_outlet,f);
+}
+
+static void fatom_f(t_fatom* x,t_floatarg f)
+{
+ x->x_val = f;
+ outlet_float(x->x_obj.ob_outlet,f);
+}
+
+
+
+static void fatom_save(t_gobj *z, t_binbuf *b)
+{
+
+ t_fatom *x = (t_fatom *)z;
+
+ binbuf_addv(b, "ssiiss", gensym("#X"),gensym("obj"),
+ x->x_obj.te_xpix, x->x_obj.te_ypix ,
+ gensym("fatom"),x->x_type);
+ binbuf_addv(b, ";");
+}
+
+
+static void *fatom_new(t_fatom* x,t_floatarg max, t_floatarg min, t_floatarg h)
+{
+ char buf[256];
+ x->x_glist = (t_glist*)NULL;
+
+
+ x->a_pos.a_type = A_FLOAT;
+
+ if (!max) x->x_max = 127;
+ else
+ x->x_max = max;
+ x->x_min = min;
+ if (h) x->x_width = h;
+ else x->x_width = 15;
+
+
+/*
+ if (o) x->x_height = o;
+ else
+*/
+
+ /* bind to a symbol for slider callback (later make this based on the
+ filepath ??) */
+
+ sprintf(buf,"fatom%x",x);
+ x->x_sym = gensym(buf);
+ pd_bind(&x->x_obj.ob_pd, x->x_sym);
+
+/* pipe startup code to slitk */
+
+ sys_vgui("proc fatom_cb%x {val} {\n
+ pd [concat fatom%x f $val \\;]\n
+ }\n",x,x);
+
+ outlet_new(&x->x_obj, &s_float);
+ return (x);
+}
+
+void fatom_setup_common(t_class* class)
+{
+
+ class_addfloat(class, (t_method)fatom_float);
+ class_addmethod(class, (t_method)fatom_f, gensym("f"),
+ A_FLOAT, 0);
+
+/*
+ class_addmethod(class, (t_method)fatom_size, gensym("size"),
+ A_FLOAT, A_FLOAT, 0);
+
+ class_addmethod(class, (t_method)fatom_color, gensym("color"),
+ A_SYMBOL, 0);
+*/
+/*
+ class_addmethod(class, (t_method)fatom_open, gensym("open"),
+ A_SYMBOL, 0);
+*/
+ class_setwidget(class,&fatom_widgetbehavior);
+
+}
diff --git a/gui/image.c b/gui/image.c
index 63b40d6..45ee761 100644
--- a/gui/image.c
+++ b/gui/image.c
@@ -32,7 +32,6 @@ void image_drawme(t_image *x, t_glist *glist, int firsttime)
sys_vgui("image create photo img%x -file %s\n",x,fname);
sys_vgui(".x%x.c create image %d %d -image img%x -tags %xS\n",
glist_getcanvas(glist),text_xpix(&x->x_obj, glist), text_ypix(&x->x_obj, glist),x,x);
- glist_getcanvas(glist),text_xpix(&x->x_obj, glist), text_ypix(&x->x_obj, glist),x,x);
/* TODO callback from gui
sys_vgui("image_size logo");
diff --git a/gui/state.c b/gui/state.c
index 40d3501..44f7aa0 100755
--- a/gui/state.c
+++ b/gui/state.c
@@ -119,6 +119,9 @@ void state_dosave(t_state *x)
if (!strcmp(class_getname(a->te_pd),"sliderh")) {
fprintf(fp,"%f\n",atom_getfloat(TATOM(a)));
}
+ if (!strcmp(class_getname(a->te_pd),"ticker")) {
+ fprintf(fp,"%f\n",atom_getfloat(TATOM(a)));
+ }
#if 0
if (!strcmp(class_getname(a->te_pd),"vsl")) {
/* float val = atom_getfloat(TATOM(a));*/
@@ -205,7 +208,8 @@ void state_load(t_state *x)
do {
if (a->te_type == T_ATOM ||
!strcmp(class_getname(a->te_pd),"slider")
- /* ||
+ ||
+ !strcmp(class_getname(a->te_pd),"ticker")/* ||
!strcmp(class_getname(a->te_pd),"vsl") ||
!strcmp(class_getname(a->te_pd),"hsl" ) */
) {
diff --git a/gui/state.pd b/gui/state.pd
index 1575e48..7ca9571 100755
--- a/gui/state.pd
+++ b/gui/state.pd
@@ -1,44 +1,44 @@
-#N canvas 182 231 789 437 10;
-#X obj 20 393 state;
-#X msg 20 322 save;
-#X floatatom 405 85 5 0 0;
-#X obj 371 291 ticker 15 15;
-#X obj 684 31 slider 127 0 15 1;
-#X obj 654 165 float;
-#X obj 654 136 toddle black 15 15;
-#X floatatom 654 194 5 0 0;
-#X text 87 10 The state object;
-#X text 7 37 With the state object settings within a patch;
-#X text 7 51 can be saved to a file. You can add a name to;
-#X text 7 66 the state (if you have several states in your;
-#X text 7 81 system this might be a good idea).;
-#X text 9 120 Note that the state object has several problems:;
-#X text 8 146 1) you can not delete "saveable objects" without;
-#X text 10 164 making the already saved states bogus;
-#X text 9 190 2) Not all the gui objects are saveable (Which is;
-#X text 8 208 good in some situations \, you might for example not
-;
-#X text 9 226 save the state selecting widget ....;
-#X text 373 8 saveable:;
-#X text 374 66 Numberboxes:;
-#X text 544 10 This is the "slider" object !!:;
-#X text 545 28 (not vslider);
-#X text 369 269 Not saveable:;
-#X obj 396 293 vsl 15 128 0 127 0 0 empty empty empty 20 8 0 8 -262144
--1 -1 0 1;
-#X text 422 292 ...etc (everything from the menu exept "number");
-#X obj 418 315 hdl 15 1 0 8 empty empty empty 20 8 0 8 -262144 -1 -1
-0;
-#X text 605 410 (C) Guenter Geiger 2002;
-#X obj 373 141 envgen;
-#X msg 29 346 1;
-#X msg 60 346 2;
-#X msg 90 346 3;
-#X text 370 118 envgen;
-#X connect 1 0 0 0;
-#X connect 4 0 5 1;
-#X connect 5 0 7 0;
-#X connect 6 0 5 0;
-#X connect 29 0 0 0;
-#X connect 30 0 0 0;
-#X connect 31 0 0 0;
+#N canvas 182 231 789 437 10;
+#X obj 20 393 state;
+#X msg 20 322 save;
+#X floatatom 405 85 5 0 0;
+#X obj 552 69 ticker;
+#X obj 684 31 slider 127 0 15;
+#X obj 654 192 float;
+#X obj 654 163 toddle black 15 15;
+#X floatatom 654 221 5 0 0;
+#X text 87 10 The state object;
+#X text 7 37 With the state object settings within a patch;
+#X text 7 51 can be saved to a file. You can add a name to;
+#X text 7 66 the state (if you have several states in your;
+#X text 7 81 system this might be a good idea).;
+#X text 9 120 Note that the state object has several problems:;
+#X text 8 146 1) you can not delete "saveable objects" without;
+#X text 10 164 making the already saved states bogus;
+#X text 9 190 2) Not all the gui objects are saveable (Which is;
+#X text 8 208 good in some situations \, you might for example not
+;
+#X text 9 226 save the state selecting widget ....;
+#X text 373 8 saveable:;
+#X text 374 66 Numberboxes:;
+#X text 544 10 This is the "slider" object !!:;
+#X text 545 28 (not vslider);
+#X text 299 289 Not saveable:;
+#X obj 403 295 vsl 15 128 0 127 0 0 empty empty empty 20 8 0 8 -262144
+-1 -1 0 1;
+#X obj 440 318 hdl 15 1 0 8 empty empty empty 20 8 0 8 -262144 -1 -1
+0;
+#X text 605 410 (C) Guenter Geiger 2002;
+#X obj 373 141 envgen 196 106;
+#X msg 29 346 1;
+#X msg 60 346 2;
+#X msg 90 346 3;
+#X text 370 118 envgen;
+#X text 422 292 ...etc (everything from the menu except "number");
+#X connect 1 0 0 0;
+#X connect 4 0 5 1;
+#X connect 5 0 7 0;
+#X connect 6 0 5 0;
+#X connect 28 0 0 0;
+#X connect 29 0 0 0;
+#X connect 30 0 0 0;
diff --git a/gui/testsave.1 b/gui/testsave.1
deleted file mode 100755
index da6c429..0000000
--- a/gui/testsave.1
+++ /dev/null
@@ -1,9 +0,0 @@
-60.000000
-30.000000
-20.000000
-1800.000000
-6.000000
-symbol
-symbol
-0.000000
-0.000000
diff --git a/gui/testsave.2 b/gui/testsave.2
deleted file mode 100755
index a9cc15c..0000000
--- a/gui/testsave.2
+++ /dev/null
@@ -1,9 +0,0 @@
-0.000000
-0.000000
-0.000000
-0.000000
-0.000000
-symbol
-symbol
-0.000000
-0.000000