summaryrefslogtreecommitdiff
path: root/apps/plugins/pdbox/PDa/src/g_toggle.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/pdbox/PDa/src/g_toggle.c')
-rw-r--r--apps/plugins/pdbox/PDa/src/g_toggle.c948
1 files changed, 948 insertions, 0 deletions
diff --git a/apps/plugins/pdbox/PDa/src/g_toggle.c b/apps/plugins/pdbox/PDa/src/g_toggle.c
new file mode 100644
index 0000000000..b6bb9f3daf
--- /dev/null
+++ b/apps/plugins/pdbox/PDa/src/g_toggle.c
@@ -0,0 +1,948 @@
1/* Copyright (c) 1997-1999 Miller Puckette.
2 * For information on usage and redistribution, and for a DISCLAIMER OF ALL
3 * WARRANTIES, see the file, "LICENSE.txt," in this distribution. */
4
5/* g_7_guis.c written by Thomas Musil (c) IEM KUG Graz Austria 2000-2001 */
6/* thanks to Miller Puckette, Guenther Geiger and Krzystof Czaja */
7
8
9#include <stdlib.h>
10#include <string.h>
11#include <stdio.h>
12#include <ctype.h>
13#include "m_pd.h"
14#include "g_canvas.h"
15#include "t_tk.h"
16#include "g_all_guis.h"
17#include <math.h>
18
19#ifdef MSW
20#include <io.h>
21#else
22#include <unistd.h>
23#endif
24
25/* --------------- tgl gui-toggle ------------------------- */
26
27t_widgetbehavior toggle_widgetbehavior;
28static t_class *toggle_class;
29
30/* widget helper functions */
31
32void toggle_draw_update(t_toggle *x, t_glist *glist)
33{
34 if(glist_isvisible(glist))
35 {
36 t_canvas *canvas=glist_getcanvas(glist);
37
38 sys_vgui(".x%x.c itemconfigure %xX1 -fill #%6.6x\n", canvas, x,
39 (x->x_on!=0.0)?x->x_gui.x_fcol:x->x_gui.x_bcol);
40 sys_vgui(".x%x.c itemconfigure %xX2 -fill #%6.6x\n", canvas, x,
41 (x->x_on!=0.0)?x->x_gui.x_fcol:x->x_gui.x_bcol);
42 }
43}
44
45void toggle_draw_new(t_toggle *x, t_glist *glist)
46{
47 t_canvas *canvas=glist_getcanvas(glist);
48 int w=1, xx=text_xpix(&x->x_gui.x_obj, glist), yy=text_ypix(&x->x_gui.x_obj, glist);
49
50 if(x->x_gui.x_w >= 30)
51 w = 2;
52 if(x->x_gui.x_w >= 60)
53 w = 3;
54 sys_vgui(".x%x.c create rectangle %d %d %d %d -fill #%6.6x -tags %xBASE\n",
55 canvas, xx, yy, xx + x->x_gui.x_w, yy + x->x_gui.x_h,
56 x->x_gui.x_bcol, x);
57 sys_vgui(".x%x.c create line %d %d %d %d -width %d -fill #%6.6x -tags %xX1\n",
58 canvas, xx+w+1, yy+w+1, xx + x->x_gui.x_w-w, yy + x->x_gui.x_h-w, w,
59 (x->x_on!=0.0)?x->x_gui.x_fcol:x->x_gui.x_bcol, x);
60 sys_vgui(".x%x.c create line %d %d %d %d -width %d -fill #%6.6x -tags %xX2\n",
61 canvas, xx+w+1, yy + x->x_gui.x_h-w-1, xx + x->x_gui.x_w-w, yy+w, w,
62 (x->x_on!=0.0)?x->x_gui.x_fcol:x->x_gui.x_bcol, x);
63 sys_vgui(".x%x.c create text %d %d -text {%s} -anchor w \
64 -font {%s %d bold} -fill #%6.6x -tags %xLABEL\n",
65 canvas, xx+x->x_gui.x_ldx,
66 yy+x->x_gui.x_ldy,
67 strcmp(x->x_gui.x_lab->s_name, "empty")?x->x_gui.x_lab->s_name:"",
68 x->x_gui.x_font, x->x_gui.x_fontsize, x->x_gui.x_lcol, x);
69 if(!x->x_gui.x_fsf.x_snd_able)
70 sys_vgui(".x%x.c create rectangle %d %d %d %d -tags %xOUT%d\n",
71 canvas, xx, yy + x->x_gui.x_h-1, xx + IOWIDTH, yy + x->x_gui.x_h, x, 0);
72 if(!x->x_gui.x_fsf.x_rcv_able)
73 sys_vgui(".x%x.c create rectangle %d %d %d %d -tags %xIN%d\n",
74 canvas, xx, yy, xx + IOWIDTH, yy+1, x, 0);
75}
76
77void toggle_draw_move(t_toggle *x, t_glist *glist)
78{
79 t_canvas *canvas=glist_getcanvas(glist);
80 int w=1, xx=text_xpix(&x->x_gui.x_obj, glist), yy=text_ypix(&x->x_gui.x_obj, glist);
81
82 if(x->x_gui.x_w >= 30)
83 w = 2;
84
85 if(x->x_gui.x_w >= 60)
86 w = 3;
87 sys_vgui(".x%x.c coords %xBASE %d %d %d %d\n",
88 canvas, x, xx, yy, xx + x->x_gui.x_w, yy + x->x_gui.x_h);
89 sys_vgui(".x%x.c itemconfigure %xX1 -width %d\n", canvas, x, w);
90 sys_vgui(".x%x.c coords %xX1 %d %d %d %d\n",
91 canvas, x, xx+w+1, yy+w+1, xx + x->x_gui.x_w-w, yy + x->x_gui.x_h-w);
92 sys_vgui(".x%x.c itemconfigure %xX2 -width %d\n", canvas, x, w);
93 sys_vgui(".x%x.c coords %xX2 %d %d %d %d\n",
94 canvas, x, xx+w+1, yy + x->x_gui.x_h-w-1, xx + x->x_gui.x_w-w, yy+w);
95 sys_vgui(".x%x.c coords %xLABEL %d %d\n",
96 canvas, x, xx+x->x_gui.x_ldx, yy+x->x_gui.x_ldy);
97 if(!x->x_gui.x_fsf.x_snd_able)
98 sys_vgui(".x%x.c coords %xOUT%d %d %d %d %d\n",
99 canvas, x, 0, xx, yy + x->x_gui.x_h-1, xx + IOWIDTH, yy + x->x_gui.x_h);
100 if(!x->x_gui.x_fsf.x_rcv_able)
101 sys_vgui(".x%x.c coords %xIN%d %d %d %d %d\n",
102 canvas, x, 0, xx, yy, xx + IOWIDTH, yy+1);
103}
104
105void toggle_draw_erase(t_toggle* x, t_glist* glist)
106{
107 t_canvas *canvas=glist_getcanvas(glist);
108
109 sys_vgui(".x%x.c delete %xBASE\n", canvas, x);
110 sys_vgui(".x%x.c delete %xX1\n", canvas, x);
111 sys_vgui(".x%x.c delete %xX2\n", canvas, x);
112 sys_vgui(".x%x.c delete %xLABEL\n", canvas, x);
113 if(!x->x_gui.x_fsf.x_snd_able)
114 sys_vgui(".x%x.c delete %xOUT%d\n", canvas, x, 0);
115 if(!x->x_gui.x_fsf.x_rcv_able)
116 sys_vgui(".x%x.c delete %xIN%d\n", canvas, x, 0);
117}
118
119void toggle_draw_config(t_toggle* x, t_glist* glist)
120{
121 t_canvas *canvas=glist_getcanvas(glist);
122
123 sys_vgui(".x%x.c itemconfigure %xLABEL -font {%s %d bold} -fill #%6.6x -text {%s} \n",
124 canvas, x, x->x_gui.x_font, x->x_gui.x_fontsize,
125 x->x_gui.x_fsf.x_selected?IEM_GUI_COLOR_SELECTED:x->x_gui.x_lcol,
126 strcmp(x->x_gui.x_lab->s_name, "empty")?x->x_gui.x_lab->s_name:"");
127 sys_vgui(".x%x.c itemconfigure %xBASE -fill #%6.6x\n", canvas, x,
128 x->x_gui.x_bcol);
129 sys_vgui(".x%x.c itemconfigure %xX1 -fill #%6.6x\n", canvas, x,
130 x->x_on?x->x_gui.x_fcol:x->x_gui.x_bcol);
131 sys_vgui(".x%x.c itemconfigure %xX2 -fill #%6.6x\n", canvas, x,
132 x->x_on?x->x_gui.x_fcol:x->x_gui.x_bcol);
133}
134
135void toggle_draw_io(t_toggle* x, t_glist* glist, int old_snd_rcv_flags)
136{
137 int xpos=text_xpix(&x->x_gui.x_obj, glist);
138 int ypos=text_ypix(&x->x_gui.x_obj, glist);
139 t_canvas *canvas=glist_getcanvas(glist);
140
141 if((old_snd_rcv_flags & IEM_GUI_OLD_SND_FLAG) && !x->x_gui.x_fsf.x_snd_able)
142 sys_vgui(".x%x.c create rectangle %d %d %d %d -tags %xOUT%d\n",
143 canvas, xpos,
144 ypos + x->x_gui.x_h-1, xpos + IOWIDTH,
145 ypos + x->x_gui.x_h, x, 0);
146 if(!(old_snd_rcv_flags & IEM_GUI_OLD_SND_FLAG) && x->x_gui.x_fsf.x_snd_able)
147 sys_vgui(".x%x.c delete %xOUT%d\n", canvas, x, 0);
148 if((old_snd_rcv_flags & IEM_GUI_OLD_RCV_FLAG) && !x->x_gui.x_fsf.x_rcv_able)
149 sys_vgui(".x%x.c create rectangle %d %d %d %d -tags %xIN%d\n",
150 canvas, xpos, ypos,
151 xpos + IOWIDTH, ypos+1, x, 0);
152 if(!(old_snd_rcv_flags & IEM_GUI_OLD_RCV_FLAG) && x->x_gui.x_fsf.x_rcv_able)
153 sys_vgui(".x%x.c delete %xIN%d\n", canvas, x, 0);
154}
155
156void toggle_draw_select(t_toggle* x, t_glist* glist)
157{
158 t_canvas *canvas=glist_getcanvas(glist);
159
160 if(x->x_gui.x_fsf.x_selected)
161 {
162 sys_vgui(".x%x.c itemconfigure %xBASE -outline #%6.6x\n", canvas, x, IEM_GUI_COLOR_SELECTED);
163 sys_vgui(".x%x.c itemconfigure %xLABEL -fill #%6.6x\n", canvas, x, IEM_GUI_COLOR_SELECTED);
164 }
165 else
166 {
167 sys_vgui(".x%x.c itemconfigure %xBASE -outline #%6.6x\n", canvas, x, IEM_GUI_COLOR_NORMAL);
168 sys_vgui(".x%x.c itemconfigure %xLABEL -fill #%6.6x\n", canvas, x, x->x_gui.x_lcol);
169 }
170}
171
172void toggle_draw(t_toggle *x, t_glist *glist, int mode)
173{
174 if(mode == IEM_GUI_DRAW_MODE_UPDATE)
175 toggle_draw_update(x, glist);
176 else if(mode == IEM_GUI_DRAW_MODE_MOVE)
177 toggle_draw_move(x, glist);
178 else if(mode == IEM_GUI_DRAW_MODE_NEW)
179 toggle_draw_new(x, glist);
180 else if(mode == IEM_GUI_DRAW_MODE_SELECT)
181 toggle_draw_select(x, glist);
182 else if(mode == IEM_GUI_DRAW_MODE_ERASE)
183 toggle_draw_erase(x, glist);
184 else if(mode == IEM_GUI_DRAW_MODE_CONFIG)
185 toggle_draw_config(x, glist);
186 else if(mode >= IEM_GUI_DRAW_MODE_IO)
187 toggle_draw_io(x, glist, mode - IEM_GUI_DRAW_MODE_IO);
188}
189
190/* ------------------------ tgl widgetbehaviour----------------------------- */
191
192static void toggle_getrect(t_gobj *z, t_glist *glist, int *xp1, int *yp1, int *xp2, int *yp2)
193{
194 t_toggle *x = (t_toggle *)z;
195
196 *xp1 = text_xpix(&x->x_gui.x_obj, glist);
197 *yp1 = text_ypix(&x->x_gui.x_obj, glist);
198 *xp2 = *xp1 + x->x_gui.x_w;
199 *yp2 = *yp1 + x->x_gui.x_h;
200}
201
202static void toggle_save(t_gobj *z, t_binbuf *b)
203{
204 t_toggle *x = (t_toggle *)z;
205 int bflcol[3];
206 t_symbol *srl[3];
207
208 iemgui_save(&x->x_gui, srl, bflcol);
209 binbuf_addv(b, "ssiisiisssiiiiiiiff", gensym("#X"),gensym("obj"),
210 (t_int)x->x_gui.x_obj.te_xpix,
211 (t_int)x->x_gui.x_obj.te_ypix,
212 gensym("tgl"), x->x_gui.x_w,
213 iem_symargstoint(&x->x_gui.x_isa),
214 srl[0], srl[1], srl[2],
215 x->x_gui.x_ldx, x->x_gui.x_ldy,
216 iem_fstyletoint(&x->x_gui.x_fsf), x->x_gui.x_fontsize,
217 bflcol[0], bflcol[1], bflcol[2], x->x_on, x->x_nonzero);
218 binbuf_addv(b, ";");
219}
220
221static void toggle_properties(t_gobj *z, t_glist *owner)
222{
223 t_toggle *x = (t_toggle *)z;
224 char buf[800];
225 t_symbol *srl[3];
226
227 iemgui_properties(&x->x_gui, srl);
228 sprintf(buf, "pdtk_iemgui_dialog %%s TOGGLE \
229 ----------dimensions(pix):----------- %d %d size: 0 0 empty \
230 -----------non-zero-value:----------- %g value: 0.0 empty %g \
231 -1 lin log %d %d empty %d \
232 %s %s \
233 %s %d %d \
234 %d %d \
235 %d %d %d\n",
236 x->x_gui.x_w, IEM_GUI_MINSIZE,
237 x->x_nonzero, 1.0,/*non_zero-schedule*/
238 x->x_gui.x_isa.x_loadinit, -1, -1,/*no multi*/
239 srl[0]->s_name, srl[1]->s_name,
240 srl[2]->s_name, x->x_gui.x_ldx, x->x_gui.x_ldy,
241 x->x_gui.x_fsf.x_font_style, x->x_gui.x_fontsize,
242 0xffffff & x->x_gui.x_bcol, 0xffffff & x->x_gui.x_fcol, 0xffffff & x->x_gui.x_lcol);
243 gfxstub_new(&x->x_gui.x_obj.ob_pd, x, buf);
244}
245
246static void toggle_bang(t_toggle *x)
247{
248 x->x_on = (x->x_on==0.0)?x->x_nonzero:0.0;
249 (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
250 outlet_float(x->x_gui.x_obj.ob_outlet, x->x_on);
251 if(x->x_gui.x_fsf.x_snd_able && x->x_gui.x_snd->s_thing)
252 pd_float(x->x_gui.x_snd->s_thing, x->x_on);
253}
254
255static void toggle_dialog(t_toggle *x, t_symbol *s, int argc, t_atom *argv)
256{
257 t_symbol *srl[3];
258 int a = (int)atom_getintarg(0, argc, argv);
259 float nonzero = (float)atom_getfloatarg(2, argc, argv);
260 int sr_flags;
261
262 if(nonzero == 0.0)
263 nonzero = 1.0;
264 x->x_nonzero = nonzero;
265 if(x->x_on != 0.0)
266 x->x_on = x->x_nonzero;
267 sr_flags = iemgui_dialog(&x->x_gui, srl, argc, argv);
268 x->x_gui.x_w = iemgui_clip_size(a);
269 x->x_gui.x_h = x->x_gui.x_w;
270 (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_CONFIG);
271 (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_IO + sr_flags);
272 (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_MOVE);
273 canvas_fixlinesfor(glist_getcanvas(x->x_gui.x_glist), (t_text*)x);
274}
275
276static void toggle_click(t_toggle *x, t_floatarg xpos, t_floatarg ypos, t_floatarg shift, t_floatarg ctrl, t_floatarg alt)
277{toggle_bang(x);}
278
279static int toggle_newclick(t_gobj *z, struct _glist *glist, int xpix, int ypix, int shift, int alt, int dbl, int doit)
280{
281 if(doit)
282 toggle_click((t_toggle *)z, (t_floatarg)xpix, (t_floatarg)ypix, (t_floatarg)shift, 0, (t_floatarg)alt);
283 return (1);
284}
285
286static void toggle_set(t_toggle *x, t_floatarg f)
287{
288 x->x_on = f;
289 if(f != 0.0)
290 x->x_nonzero = f;
291 (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
292}
293
294static void toggle_float(t_toggle *x, t_floatarg f)
295{
296 toggle_set(x, f);
297 if(x->x_gui.x_fsf.x_put_in2out)
298 {
299 outlet_float(x->x_gui.x_obj.ob_outlet, x->x_on);
300 if(x->x_gui.x_fsf.x_snd_able && x->x_gui.x_snd->s_thing)
301 pd_float(x->x_gui.x_snd->s_thing, x->x_on);
302 }
303}
304
305static void toggle_fout(t_toggle *x, t_floatarg f)
306{
307 toggle_set(x, f);
308 outlet_float(x->x_gui.x_obj.ob_outlet, x->x_on);
309 if(x->x_gui.x_fsf.x_snd_able && x->x_gui.x_snd->s_thing)
310 pd_float(x->x_gui.x_snd->s_thing, x->x_on);
311}
312
313static void toggle_loadbang(t_toggle *x)
314{
315 if(!sys_noloadbang && x->x_gui.x_isa.x_loadinit)
316 toggle_fout(x, (float)x->x_on);
317}
318
319static void toggle_size(t_toggle *x, t_symbol *s, int ac, t_atom *av)
320{
321 x->x_gui.x_w = iemgui_clip_size((int)atom_getintarg(0, ac, av));
322 x->x_gui.x_h = x->x_gui.x_w;
323 iemgui_size((void *)x, &x->x_gui);
324}
325
326static void toggle_delta(t_toggle *x, t_symbol *s, int ac, t_atom *av)
327{iemgui_delta((void *)x, &x->x_gui, s, ac, av);}
328
329static void toggle_pos(t_toggle *x, t_symbol *s, int ac, t_atom *av)
330{iemgui_pos((void *)x, &x->x_gui, s, ac, av);}
331
332static void toggle_color(t_toggle *x, t_symbol *s, int ac, t_atom *av)
333{iemgui_color((void *)x, &x->x_gui, s, ac, av);}
334
335static void toggle_send(t_toggle *x, t_symbol *s)
336{iemgui_send(x, &x->x_gui, s);}
337
338static void toggle_receive(t_toggle *x, t_symbol *s)
339{iemgui_receive(x, &x->x_gui, s);}
340
341static void toggle_label(t_toggle *x, t_symbol *s)
342{iemgui_label((void *)x, &x->x_gui, s);}
343
344static void toggle_label_font(t_toggle *x, t_symbol *s, int ac, t_atom *av)
345{iemgui_label_font((void *)x, &x->x_gui, s, ac, av);}
346
347static void toggle_label_pos(t_toggle *x, t_symbol *s, int ac, t_atom *av)
348{iemgui_label_pos((void *)x, &x->x_gui, s, ac, av);}
349
350static void toggle_init(t_toggle *x, t_floatarg f)
351{
352 x->x_gui.x_isa.x_loadinit = (f==0.0)?0:1;
353}
354
355static void toggle_nonzero(t_toggle *x, t_floatarg f)
356{
357 if(f != 0.0)
358 x->x_nonzero = f;
359}
360
361static void *toggle_new(t_symbol *s, int argc, t_atom *argv)
362{
363 t_toggle *x = (t_toggle *)pd_new(toggle_class);
364 int bflcol[]={-262144, -1, -1};
365 int a=IEM_GUI_DEFAULTSIZE, f=0;
366 int ldx=0, ldy=-6;
367 int fs=8;
368 float on=0.0, nonzero=1.0;
369 char str[144];
370
371 iem_inttosymargs(&x->x_gui.x_isa, 0);
372 iem_inttofstyle(&x->x_gui.x_fsf, 0);
373
374 if(((argc == 13)||(argc == 14))&&IS_A_FLOAT(argv,0)
375 &&IS_A_FLOAT(argv,1)
376 &&(IS_A_SYMBOL(argv,2)||IS_A_FLOAT(argv,2))
377 &&(IS_A_SYMBOL(argv,3)||IS_A_FLOAT(argv,3))
378 &&(IS_A_SYMBOL(argv,4)||IS_A_FLOAT(argv,4))
379 &&IS_A_FLOAT(argv,5)&&IS_A_FLOAT(argv,6)
380 &&IS_A_FLOAT(argv,7)&&IS_A_FLOAT(argv,8)&&IS_A_FLOAT(argv,9)
381 &&IS_A_FLOAT(argv,10)&&IS_A_FLOAT(argv,11)&&IS_A_FLOAT(argv,12))
382 {
383 a = (int)atom_getintarg(0, argc, argv);
384 iem_inttosymargs(&x->x_gui.x_isa, atom_getintarg(1, argc, argv));
385 iemgui_new_getnames(&x->x_gui, 2, argv);
386 ldx = (int)atom_getintarg(5, argc, argv);
387 ldy = (int)atom_getintarg(6, argc, argv);
388 iem_inttofstyle(&x->x_gui.x_fsf, atom_getintarg(7, argc, argv));
389 fs = (int)atom_getintarg(8, argc, argv);
390 bflcol[0] = (int)atom_getintarg(9, argc, argv);
391 bflcol[1] = (int)atom_getintarg(10, argc, argv);
392 bflcol[2] = (int)atom_getintarg(11, argc, argv);
393 on = (float)atom_getfloatarg(12, argc, argv);
394 }
395 else iemgui_new_getnames(&x->x_gui, 2, 0);
396 if((argc == 14)&&IS_A_FLOAT(argv,13))
397 nonzero = (float)atom_getfloatarg(13, argc, argv);
398 x->x_gui.x_draw = (t_iemfunptr)toggle_draw;
399
400 x->x_gui.x_fsf.x_snd_able = 1;
401 x->x_gui.x_fsf.x_rcv_able = 1;
402 x->x_gui.x_glist = (t_glist *)canvas_getcurrent();
403 if (!strcmp(x->x_gui.x_snd->s_name, "empty"))
404 x->x_gui.x_fsf.x_snd_able = 0;
405 if (!strcmp(x->x_gui.x_rcv->s_name, "empty"))
406 x->x_gui.x_fsf.x_rcv_able = 0;
407 if(x->x_gui.x_fsf.x_font_style == 1) strcpy(x->x_gui.x_font, "helvetica");
408 else if(x->x_gui.x_fsf.x_font_style == 2) strcpy(x->x_gui.x_font, "times");
409 else { x->x_gui.x_fsf.x_font_style = 0;
410 strcpy(x->x_gui.x_font, "courier"); }
411 x->x_nonzero = (nonzero!=0.0)?nonzero:1.0;
412 if(x->x_gui.x_isa.x_loadinit)
413 x->x_on = (on!=0.0)?nonzero:0.0;
414 else
415 x->x_on = 0.0;
416 if (x->x_gui.x_fsf.x_rcv_able)
417 pd_bind(&x->x_gui.x_obj.ob_pd, x->x_gui.x_rcv);
418 x->x_gui.x_ldx = ldx;
419 x->x_gui.x_ldy = ldy;
420
421 if(fs < 4)
422 fs = 4;
423 x->x_gui.x_fontsize = fs;
424 x->x_gui.x_w = iemgui_clip_size(a);
425 x->x_gui.x_h = x->x_gui.x_w;
426 iemgui_all_colfromload(&x->x_gui, bflcol);
427 iemgui_verify_snd_ne_rcv(&x->x_gui);
428 outlet_new(&x->x_gui.x_obj, &s_float);
429 return (x);
430}
431
432static void toggle_ff(t_toggle *x)
433{
434 if(x->x_gui.x_fsf.x_rcv_able)
435 pd_unbind(&x->x_gui.x_obj.ob_pd, x->x_gui.x_rcv);
436 gfxstub_deleteforkey(x);
437}
438
439void g_toggle_setup(void)
440{
441 toggle_class = class_new(gensym("tgl"), (t_newmethod)toggle_new,
442 (t_method)toggle_ff, sizeof(t_toggle), 0, A_GIMME, 0);
443 class_addcreator((t_newmethod)toggle_new, gensym("toggle"), A_GIMME, 0);
444 class_addbang(toggle_class, toggle_bang);
445 class_addfloat(toggle_class, toggle_float);
446 class_addmethod(toggle_class, (t_method)toggle_click, gensym("click"),
447 A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, 0);
448 class_addmethod(toggle_class, (t_method)toggle_dialog, gensym("dialog"),
449 A_GIMME, 0);
450 class_addmethod(toggle_class, (t_method)toggle_loadbang, gensym("loadbang"), 0);
451 class_addmethod(toggle_class, (t_method)toggle_set, gensym("set"), A_FLOAT, 0);
452 class_addmethod(toggle_class, (t_method)toggle_size, gensym("size"), A_GIMME, 0);
453 class_addmethod(toggle_class, (t_method)toggle_delta, gensym("delta"), A_GIMME, 0);
454 class_addmethod(toggle_class, (t_method)toggle_pos, gensym("pos"), A_GIMME, 0);
455 class_addmethod(toggle_class, (t_method)toggle_color, gensym("color"), A_GIMME, 0);
456 class_addmethod(toggle_class, (t_method)toggle_send, gensym("send"), A_DEFSYM, 0);
457 class_addmethod(toggle_class, (t_method)toggle_receive, gensym("receive"), A_DEFSYM, 0);
458 class_addmethod(toggle_class, (t_method)toggle_label, gensym("label"), A_DEFSYM, 0);
459 class_addmethod(toggle_class, (t_method)toggle_label_pos, gensym("label_pos"), A_GIMME, 0);
460 class_addmethod(toggle_class, (t_method)toggle_label_font, gensym("label_font"), A_GIMME, 0);
461 class_addmethod(toggle_class, (t_method)toggle_init, gensym("init"), A_FLOAT, 0);
462 class_addmethod(toggle_class, (t_method)toggle_nonzero, gensym("nonzero"), A_FLOAT, 0);
463 toggle_widgetbehavior.w_getrectfn = toggle_getrect;
464 toggle_widgetbehavior.w_displacefn = iemgui_displace;
465 toggle_widgetbehavior.w_selectfn = iemgui_select;
466 toggle_widgetbehavior.w_activatefn = NULL;
467 toggle_widgetbehavior.w_deletefn = iemgui_delete;
468 toggle_widgetbehavior.w_visfn = iemgui_vis;
469 toggle_widgetbehavior.w_clickfn = toggle_newclick;
470 class_setwidget(toggle_class, &toggle_widgetbehavior);
471 class_sethelpsymbol(toggle_class, gensym("toggle"));
472 class_setsavefn(toggle_class, toggle_save);
473 class_setpropertiesfn(toggle_class, toggle_properties);
474}
475/* Copyright (c) 1997-1999 Miller Puckette.
476 * For information on usage and redistribution, and for a DISCLAIMER OF ALL
477 * WARRANTIES, see the file, "LICENSE.txt," in this distribution. */
478
479/* g_7_guis.c written by Thomas Musil (c) IEM KUG Graz Austria 2000-2001 */
480/* thanks to Miller Puckette, Guenther Geiger and Krzystof Czaja */
481
482
483#include <stdlib.h>
484#include <string.h>
485#include <stdio.h>
486#include <ctype.h>
487#include "m_pd.h"
488#include "g_canvas.h"
489#include "t_tk.h"
490#include "g_all_guis.h"
491#include <math.h>
492
493#ifdef MSW
494#include <io.h>
495#else
496#include <unistd.h>
497#endif
498
499/* --------------- tgl gui-toggle ------------------------- */
500
501t_widgetbehavior toggle_widgetbehavior;
502static t_class *toggle_class;
503
504/* widget helper functions */
505
506void toggle_draw_update(t_toggle *x, t_glist *glist)
507{
508 if(glist_isvisible(glist))
509 {
510 t_canvas *canvas=glist_getcanvas(glist);
511
512 sys_vgui(".x%x.c itemconfigure %xX1 -fill #%6.6x\n", canvas, x,
513 (x->x_on!=0.0)?x->x_gui.x_fcol:x->x_gui.x_bcol);
514 sys_vgui(".x%x.c itemconfigure %xX2 -fill #%6.6x\n", canvas, x,
515 (x->x_on!=0.0)?x->x_gui.x_fcol:x->x_gui.x_bcol);
516 }
517}
518
519void toggle_draw_new(t_toggle *x, t_glist *glist)
520{
521 t_canvas *canvas=glist_getcanvas(glist);
522 int w=1, xx=text_xpix(&x->x_gui.x_obj, glist), yy=text_ypix(&x->x_gui.x_obj, glist);
523
524 if(x->x_gui.x_w >= 30)
525 w = 2;
526 if(x->x_gui.x_w >= 60)
527 w = 3;
528 sys_vgui(".x%x.c create rectangle %d %d %d %d -fill #%6.6x -tags %xBASE\n",
529 canvas, xx, yy, xx + x->x_gui.x_w, yy + x->x_gui.x_h,
530 x->x_gui.x_bcol, x);
531 sys_vgui(".x%x.c create line %d %d %d %d -width %d -fill #%6.6x -tags %xX1\n",
532 canvas, xx+w+1, yy+w+1, xx + x->x_gui.x_w-w, yy + x->x_gui.x_h-w, w,
533 (x->x_on!=0.0)?x->x_gui.x_fcol:x->x_gui.x_bcol, x);
534 sys_vgui(".x%x.c create line %d %d %d %d -width %d -fill #%6.6x -tags %xX2\n",
535 canvas, xx+w+1, yy + x->x_gui.x_h-w-1, xx + x->x_gui.x_w-w, yy+w, w,
536 (x->x_on!=0.0)?x->x_gui.x_fcol:x->x_gui.x_bcol, x);
537 sys_vgui(".x%x.c create text %d %d -text {%s} -anchor w \
538 -font {%s %d bold} -fill #%6.6x -tags %xLABEL\n",
539 canvas, xx+x->x_gui.x_ldx,
540 yy+x->x_gui.x_ldy,
541 strcmp(x->x_gui.x_lab->s_name, "empty")?x->x_gui.x_lab->s_name:"",
542 x->x_gui.x_font, x->x_gui.x_fontsize, x->x_gui.x_lcol, x);
543 if(!x->x_gui.x_fsf.x_snd_able)
544 sys_vgui(".x%x.c create rectangle %d %d %d %d -tags %xOUT%d\n",
545 canvas, xx, yy + x->x_gui.x_h-1, xx + IOWIDTH, yy + x->x_gui.x_h, x, 0);
546 if(!x->x_gui.x_fsf.x_rcv_able)
547 sys_vgui(".x%x.c create rectangle %d %d %d %d -tags %xIN%d\n",
548 canvas, xx, yy, xx + IOWIDTH, yy+1, x, 0);
549}
550
551void toggle_draw_move(t_toggle *x, t_glist *glist)
552{
553 t_canvas *canvas=glist_getcanvas(glist);
554 int w=1, xx=text_xpix(&x->x_gui.x_obj, glist), yy=text_ypix(&x->x_gui.x_obj, glist);
555
556 if(x->x_gui.x_w >= 30)
557 w = 2;
558
559 if(x->x_gui.x_w >= 60)
560 w = 3;
561 sys_vgui(".x%x.c coords %xBASE %d %d %d %d\n",
562 canvas, x, xx, yy, xx + x->x_gui.x_w, yy + x->x_gui.x_h);
563 sys_vgui(".x%x.c itemconfigure %xX1 -width %d\n", canvas, x, w);
564 sys_vgui(".x%x.c coords %xX1 %d %d %d %d\n",
565 canvas, x, xx+w+1, yy+w+1, xx + x->x_gui.x_w-w, yy + x->x_gui.x_h-w);
566 sys_vgui(".x%x.c itemconfigure %xX2 -width %d\n", canvas, x, w);
567 sys_vgui(".x%x.c coords %xX2 %d %d %d %d\n",
568 canvas, x, xx+w+1, yy + x->x_gui.x_h-w-1, xx + x->x_gui.x_w-w, yy+w);
569 sys_vgui(".x%x.c coords %xLABEL %d %d\n",
570 canvas, x, xx+x->x_gui.x_ldx, yy+x->x_gui.x_ldy);
571 if(!x->x_gui.x_fsf.x_snd_able)
572 sys_vgui(".x%x.c coords %xOUT%d %d %d %d %d\n",
573 canvas, x, 0, xx, yy + x->x_gui.x_h-1, xx + IOWIDTH, yy + x->x_gui.x_h);
574 if(!x->x_gui.x_fsf.x_rcv_able)
575 sys_vgui(".x%x.c coords %xIN%d %d %d %d %d\n",
576 canvas, x, 0, xx, yy, xx + IOWIDTH, yy+1);
577}
578
579void toggle_draw_erase(t_toggle* x, t_glist* glist)
580{
581 t_canvas *canvas=glist_getcanvas(glist);
582
583 sys_vgui(".x%x.c delete %xBASE\n", canvas, x);
584 sys_vgui(".x%x.c delete %xX1\n", canvas, x);
585 sys_vgui(".x%x.c delete %xX2\n", canvas, x);
586 sys_vgui(".x%x.c delete %xLABEL\n", canvas, x);
587 if(!x->x_gui.x_fsf.x_snd_able)
588 sys_vgui(".x%x.c delete %xOUT%d\n", canvas, x, 0);
589 if(!x->x_gui.x_fsf.x_rcv_able)
590 sys_vgui(".x%x.c delete %xIN%d\n", canvas, x, 0);
591}
592
593void toggle_draw_config(t_toggle* x, t_glist* glist)
594{
595 t_canvas *canvas=glist_getcanvas(glist);
596
597 sys_vgui(".x%x.c itemconfigure %xLABEL -font {%s %d bold} -fill #%6.6x -text {%s} \n",
598 canvas, x, x->x_gui.x_font, x->x_gui.x_fontsize,
599 x->x_gui.x_fsf.x_selected?IEM_GUI_COLOR_SELECTED:x->x_gui.x_lcol,
600 strcmp(x->x_gui.x_lab->s_name, "empty")?x->x_gui.x_lab->s_name:"");
601 sys_vgui(".x%x.c itemconfigure %xBASE -fill #%6.6x\n", canvas, x,
602 x->x_gui.x_bcol);
603 sys_vgui(".x%x.c itemconfigure %xX1 -fill #%6.6x\n", canvas, x,
604 x->x_on?x->x_gui.x_fcol:x->x_gui.x_bcol);
605 sys_vgui(".x%x.c itemconfigure %xX2 -fill #%6.6x\n", canvas, x,
606 x->x_on?x->x_gui.x_fcol:x->x_gui.x_bcol);
607}
608
609void toggle_draw_io(t_toggle* x, t_glist* glist, int old_snd_rcv_flags)
610{
611 int xpos=text_xpix(&x->x_gui.x_obj, glist);
612 int ypos=text_ypix(&x->x_gui.x_obj, glist);
613 t_canvas *canvas=glist_getcanvas(glist);
614
615 if((old_snd_rcv_flags & IEM_GUI_OLD_SND_FLAG) && !x->x_gui.x_fsf.x_snd_able)
616 sys_vgui(".x%x.c create rectangle %d %d %d %d -tags %xOUT%d\n",
617 canvas, xpos,
618 ypos + x->x_gui.x_h-1, xpos + IOWIDTH,
619 ypos + x->x_gui.x_h, x, 0);
620 if(!(old_snd_rcv_flags & IEM_GUI_OLD_SND_FLAG) && x->x_gui.x_fsf.x_snd_able)
621 sys_vgui(".x%x.c delete %xOUT%d\n", canvas, x, 0);
622 if((old_snd_rcv_flags & IEM_GUI_OLD_RCV_FLAG) && !x->x_gui.x_fsf.x_rcv_able)
623 sys_vgui(".x%x.c create rectangle %d %d %d %d -tags %xIN%d\n",
624 canvas, xpos, ypos,
625 xpos + IOWIDTH, ypos+1, x, 0);
626 if(!(old_snd_rcv_flags & IEM_GUI_OLD_RCV_FLAG) && x->x_gui.x_fsf.x_rcv_able)
627 sys_vgui(".x%x.c delete %xIN%d\n", canvas, x, 0);
628}
629
630void toggle_draw_select(t_toggle* x, t_glist* glist)
631{
632 t_canvas *canvas=glist_getcanvas(glist);
633
634 if(x->x_gui.x_fsf.x_selected)
635 {
636 sys_vgui(".x%x.c itemconfigure %xBASE -outline #%6.6x\n", canvas, x, IEM_GUI_COLOR_SELECTED);
637 sys_vgui(".x%x.c itemconfigure %xLABEL -fill #%6.6x\n", canvas, x, IEM_GUI_COLOR_SELECTED);
638 }
639 else
640 {
641 sys_vgui(".x%x.c itemconfigure %xBASE -outline #%6.6x\n", canvas, x, IEM_GUI_COLOR_NORMAL);
642 sys_vgui(".x%x.c itemconfigure %xLABEL -fill #%6.6x\n", canvas, x, x->x_gui.x_lcol);
643 }
644}
645
646void toggle_draw(t_toggle *x, t_glist *glist, int mode)
647{
648 if(mode == IEM_GUI_DRAW_MODE_UPDATE)
649 toggle_draw_update(x, glist);
650 else if(mode == IEM_GUI_DRAW_MODE_MOVE)
651 toggle_draw_move(x, glist);
652 else if(mode == IEM_GUI_DRAW_MODE_NEW)
653 toggle_draw_new(x, glist);
654 else if(mode == IEM_GUI_DRAW_MODE_SELECT)
655 toggle_draw_select(x, glist);
656 else if(mode == IEM_GUI_DRAW_MODE_ERASE)
657 toggle_draw_erase(x, glist);
658 else if(mode == IEM_GUI_DRAW_MODE_CONFIG)
659 toggle_draw_config(x, glist);
660 else if(mode >= IEM_GUI_DRAW_MODE_IO)
661 toggle_draw_io(x, glist, mode - IEM_GUI_DRAW_MODE_IO);
662}
663
664/* ------------------------ tgl widgetbehaviour----------------------------- */
665
666static void toggle_getrect(t_gobj *z, t_glist *glist, int *xp1, int *yp1, int *xp2, int *yp2)
667{
668 t_toggle *x = (t_toggle *)z;
669
670 *xp1 = text_xpix(&x->x_gui.x_obj, glist);
671 *yp1 = text_ypix(&x->x_gui.x_obj, glist);
672 *xp2 = *xp1 + x->x_gui.x_w;
673 *yp2 = *yp1 + x->x_gui.x_h;
674}
675
676static void toggle_save(t_gobj *z, t_binbuf *b)
677{
678 t_toggle *x = (t_toggle *)z;
679 int bflcol[3];
680 t_symbol *srl[3];
681
682 iemgui_save(&x->x_gui, srl, bflcol);
683 binbuf_addv(b, "ssiisiisssiiiiiiiff", gensym("#X"),gensym("obj"),
684 (t_int)x->x_gui.x_obj.te_xpix,
685 (t_int)x->x_gui.x_obj.te_ypix,
686 gensym("tgl"), x->x_gui.x_w,
687 iem_symargstoint(&x->x_gui.x_isa),
688 srl[0], srl[1], srl[2],
689 x->x_gui.x_ldx, x->x_gui.x_ldy,
690 iem_fstyletoint(&x->x_gui.x_fsf), x->x_gui.x_fontsize,
691 bflcol[0], bflcol[1], bflcol[2], x->x_on, x->x_nonzero);
692 binbuf_addv(b, ";");
693}
694
695static void toggle_properties(t_gobj *z, t_glist *owner)
696{
697 t_toggle *x = (t_toggle *)z;
698 char buf[800];
699 t_symbol *srl[3];
700
701 iemgui_properties(&x->x_gui, srl);
702 sprintf(buf, "pdtk_iemgui_dialog %%s TOGGLE \
703 ----------dimensions(pix):----------- %d %d size: 0 0 empty \
704 -----------non-zero-value:----------- %g value: 0.0 empty %g \
705 -1 lin log %d %d empty %d \
706 %s %s \
707 %s %d %d \
708 %d %d \
709 %d %d %d\n",
710 x->x_gui.x_w, IEM_GUI_MINSIZE,
711 x->x_nonzero, 1.0,/*non_zero-schedule*/
712 x->x_gui.x_isa.x_loadinit, -1, -1,/*no multi*/
713 srl[0]->s_name, srl[1]->s_name,
714 srl[2]->s_name, x->x_gui.x_ldx, x->x_gui.x_ldy,
715 x->x_gui.x_fsf.x_font_style, x->x_gui.x_fontsize,
716 0xffffff & x->x_gui.x_bcol, 0xffffff & x->x_gui.x_fcol, 0xffffff & x->x_gui.x_lcol);
717 gfxstub_new(&x->x_gui.x_obj.ob_pd, x, buf);
718}
719
720static void toggle_bang(t_toggle *x)
721{
722 x->x_on = (x->x_on==0.0)?x->x_nonzero:0.0;
723 (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
724 outlet_float(x->x_gui.x_obj.ob_outlet, x->x_on);
725 if(x->x_gui.x_fsf.x_snd_able && x->x_gui.x_snd->s_thing)
726 pd_float(x->x_gui.x_snd->s_thing, x->x_on);
727}
728
729static void toggle_dialog(t_toggle *x, t_symbol *s, int argc, t_atom *argv)
730{
731 t_symbol *srl[3];
732 int a = (int)atom_getintarg(0, argc, argv);
733 float nonzero = (float)atom_getfloatarg(2, argc, argv);
734 int sr_flags;
735
736 if(nonzero == 0.0)
737 nonzero = 1.0;
738 x->x_nonzero = nonzero;
739 if(x->x_on != 0.0)
740 x->x_on = x->x_nonzero;
741 sr_flags = iemgui_dialog(&x->x_gui, srl, argc, argv);
742 x->x_gui.x_w = iemgui_clip_size(a);
743 x->x_gui.x_h = x->x_gui.x_w;
744 (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_CONFIG);
745 (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_IO + sr_flags);
746 (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_MOVE);
747 canvas_fixlinesfor(glist_getcanvas(x->x_gui.x_glist), (t_text*)x);
748}
749
750static void toggle_click(t_toggle *x, t_floatarg xpos, t_floatarg ypos, t_floatarg shift, t_floatarg ctrl, t_floatarg alt)
751{toggle_bang(x);}
752
753static int toggle_newclick(t_gobj *z, struct _glist *glist, int xpix, int ypix, int shift, int alt, int dbl, int doit)
754{
755 if(doit)
756 toggle_click((t_toggle *)z, (t_floatarg)xpix, (t_floatarg)ypix, (t_floatarg)shift, 0, (t_floatarg)alt);
757 return (1);
758}
759
760static void toggle_set(t_toggle *x, t_floatarg f)
761{
762 x->x_on = f;
763 if(f != 0.0)
764 x->x_nonzero = f;
765 (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
766}
767
768static void toggle_float(t_toggle *x, t_floatarg f)
769{
770 toggle_set(x, f);
771 if(x->x_gui.x_fsf.x_put_in2out)
772 {
773 outlet_float(x->x_gui.x_obj.ob_outlet, x->x_on);
774 if(x->x_gui.x_fsf.x_snd_able && x->x_gui.x_snd->s_thing)
775 pd_float(x->x_gui.x_snd->s_thing, x->x_on);
776 }
777}
778
779static void toggle_fout(t_toggle *x, t_floatarg f)
780{
781 toggle_set(x, f);
782 outlet_float(x->x_gui.x_obj.ob_outlet, x->x_on);
783 if(x->x_gui.x_fsf.x_snd_able && x->x_gui.x_snd->s_thing)
784 pd_float(x->x_gui.x_snd->s_thing, x->x_on);
785}
786
787static void toggle_loadbang(t_toggle *x)
788{
789 if(!sys_noloadbang && x->x_gui.x_isa.x_loadinit)
790 toggle_fout(x, (float)x->x_on);
791}
792
793static void toggle_size(t_toggle *x, t_symbol *s, int ac, t_atom *av)
794{
795 x->x_gui.x_w = iemgui_clip_size((int)atom_getintarg(0, ac, av));
796 x->x_gui.x_h = x->x_gui.x_w;
797 iemgui_size((void *)x, &x->x_gui);
798}
799
800static void toggle_delta(t_toggle *x, t_symbol *s, int ac, t_atom *av)
801{iemgui_delta((void *)x, &x->x_gui, s, ac, av);}
802
803static void toggle_pos(t_toggle *x, t_symbol *s, int ac, t_atom *av)
804{iemgui_pos((void *)x, &x->x_gui, s, ac, av);}
805
806static void toggle_color(t_toggle *x, t_symbol *s, int ac, t_atom *av)
807{iemgui_color((void *)x, &x->x_gui, s, ac, av);}
808
809static void toggle_send(t_toggle *x, t_symbol *s)
810{iemgui_send(x, &x->x_gui, s);}
811
812static void toggle_receive(t_toggle *x, t_symbol *s)
813{iemgui_receive(x, &x->x_gui, s);}
814
815static void toggle_label(t_toggle *x, t_symbol *s)
816{iemgui_label((void *)x, &x->x_gui, s);}
817
818static void toggle_label_font(t_toggle *x, t_symbol *s, int ac, t_atom *av)
819{iemgui_label_font((void *)x, &x->x_gui, s, ac, av);}
820
821static void toggle_label_pos(t_toggle *x, t_symbol *s, int ac, t_atom *av)
822{iemgui_label_pos((void *)x, &x->x_gui, s, ac, av);}
823
824static void toggle_init(t_toggle *x, t_floatarg f)
825{
826 x->x_gui.x_isa.x_loadinit = (f==0.0)?0:1;
827}
828
829static void toggle_nonzero(t_toggle *x, t_floatarg f)
830{
831 if(f != 0.0)
832 x->x_nonzero = f;
833}
834
835static void *toggle_new(t_symbol *s, int argc, t_atom *argv)
836{
837 t_toggle *x = (t_toggle *)pd_new(toggle_class);
838 int bflcol[]={-262144, -1, -1};
839 int a=IEM_GUI_DEFAULTSIZE, f=0;
840 int ldx=0, ldy=-6;
841 int fs=8;
842 float on=0.0, nonzero=1.0;
843 char str[144];
844
845 iem_inttosymargs(&x->x_gui.x_isa, 0);
846 iem_inttofstyle(&x->x_gui.x_fsf, 0);
847
848 if(((argc == 13)||(argc == 14))&&IS_A_FLOAT(argv,0)
849 &&IS_A_FLOAT(argv,1)
850 &&(IS_A_SYMBOL(argv,2)||IS_A_FLOAT(argv,2))
851 &&(IS_A_SYMBOL(argv,3)||IS_A_FLOAT(argv,3))
852 &&(IS_A_SYMBOL(argv,4)||IS_A_FLOAT(argv,4))
853 &&IS_A_FLOAT(argv,5)&&IS_A_FLOAT(argv,6)
854 &&IS_A_FLOAT(argv,7)&&IS_A_FLOAT(argv,8)&&IS_A_FLOAT(argv,9)
855 &&IS_A_FLOAT(argv,10)&&IS_A_FLOAT(argv,11)&&IS_A_FLOAT(argv,12))
856 {
857 a = (int)atom_getintarg(0, argc, argv);
858 iem_inttosymargs(&x->x_gui.x_isa, atom_getintarg(1, argc, argv));
859 iemgui_new_getnames(&x->x_gui, 2, argv);
860 ldx = (int)atom_getintarg(5, argc, argv);
861 ldy = (int)atom_getintarg(6, argc, argv);
862 iem_inttofstyle(&x->x_gui.x_fsf, atom_getintarg(7, argc, argv));
863 fs = (int)atom_getintarg(8, argc, argv);
864 bflcol[0] = (int)atom_getintarg(9, argc, argv);
865 bflcol[1] = (int)atom_getintarg(10, argc, argv);
866 bflcol[2] = (int)atom_getintarg(11, argc, argv);
867 on = (float)atom_getfloatarg(12, argc, argv);
868 }
869 else iemgui_new_getnames(&x->x_gui, 2, 0);
870 if((argc == 14)&&IS_A_FLOAT(argv,13))
871 nonzero = (float)atom_getfloatarg(13, argc, argv);
872 x->x_gui.x_draw = (t_iemfunptr)toggle_draw;
873
874 x->x_gui.x_fsf.x_snd_able = 1;
875 x->x_gui.x_fsf.x_rcv_able = 1;
876 x->x_gui.x_glist = (t_glist *)canvas_getcurrent();
877 if (!strcmp(x->x_gui.x_snd->s_name, "empty"))
878 x->x_gui.x_fsf.x_snd_able = 0;
879 if (!strcmp(x->x_gui.x_rcv->s_name, "empty"))
880 x->x_gui.x_fsf.x_rcv_able = 0;
881 if(x->x_gui.x_fsf.x_font_style == 1) strcpy(x->x_gui.x_font, "helvetica");
882 else if(x->x_gui.x_fsf.x_font_style == 2) strcpy(x->x_gui.x_font, "times");
883 else { x->x_gui.x_fsf.x_font_style = 0;
884 strcpy(x->x_gui.x_font, "courier"); }
885 x->x_nonzero = (nonzero!=0.0)?nonzero:1.0;
886 if(x->x_gui.x_isa.x_loadinit)
887 x->x_on = (on!=0.0)?nonzero:0.0;
888 else
889 x->x_on = 0.0;
890 if (x->x_gui.x_fsf.x_rcv_able)
891 pd_bind(&x->x_gui.x_obj.ob_pd, x->x_gui.x_rcv);
892 x->x_gui.x_ldx = ldx;
893 x->x_gui.x_ldy = ldy;
894
895 if(fs < 4)
896 fs = 4;
897 x->x_gui.x_fontsize = fs;
898 x->x_gui.x_w = iemgui_clip_size(a);
899 x->x_gui.x_h = x->x_gui.x_w;
900 iemgui_all_colfromload(&x->x_gui, bflcol);
901 iemgui_verify_snd_ne_rcv(&x->x_gui);
902 outlet_new(&x->x_gui.x_obj, &s_float);
903 return (x);
904}
905
906static void toggle_ff(t_toggle *x)
907{
908 if(x->x_gui.x_fsf.x_rcv_able)
909 pd_unbind(&x->x_gui.x_obj.ob_pd, x->x_gui.x_rcv);
910 gfxstub_deleteforkey(x);
911}
912
913void g_toggle_setup(void)
914{
915 toggle_class = class_new(gensym("tgl"), (t_newmethod)toggle_new,
916 (t_method)toggle_ff, sizeof(t_toggle), 0, A_GIMME, 0);
917 class_addcreator((t_newmethod)toggle_new, gensym("toggle"), A_GIMME, 0);
918 class_addbang(toggle_class, toggle_bang);
919 class_addfloat(toggle_class, toggle_float);
920 class_addmethod(toggle_class, (t_method)toggle_click, gensym("click"),
921 A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, 0);
922 class_addmethod(toggle_class, (t_method)toggle_dialog, gensym("dialog"),
923 A_GIMME, 0);
924 class_addmethod(toggle_class, (t_method)toggle_loadbang, gensym("loadbang"), 0);
925 class_addmethod(toggle_class, (t_method)toggle_set, gensym("set"), A_FLOAT, 0);
926 class_addmethod(toggle_class, (t_method)toggle_size, gensym("size"), A_GIMME, 0);
927 class_addmethod(toggle_class, (t_method)toggle_delta, gensym("delta"), A_GIMME, 0);
928 class_addmethod(toggle_class, (t_method)toggle_pos, gensym("pos"), A_GIMME, 0);
929 class_addmethod(toggle_class, (t_method)toggle_color, gensym("color"), A_GIMME, 0);
930 class_addmethod(toggle_class, (t_method)toggle_send, gensym("send"), A_DEFSYM, 0);
931 class_addmethod(toggle_class, (t_method)toggle_receive, gensym("receive"), A_DEFSYM, 0);
932 class_addmethod(toggle_class, (t_method)toggle_label, gensym("label"), A_DEFSYM, 0);
933 class_addmethod(toggle_class, (t_method)toggle_label_pos, gensym("label_pos"), A_GIMME, 0);
934 class_addmethod(toggle_class, (t_method)toggle_label_font, gensym("label_font"), A_GIMME, 0);
935 class_addmethod(toggle_class, (t_method)toggle_init, gensym("init"), A_FLOAT, 0);
936 class_addmethod(toggle_class, (t_method)toggle_nonzero, gensym("nonzero"), A_FLOAT, 0);
937 toggle_widgetbehavior.w_getrectfn = toggle_getrect;
938 toggle_widgetbehavior.w_displacefn = iemgui_displace;
939 toggle_widgetbehavior.w_selectfn = iemgui_select;
940 toggle_widgetbehavior.w_activatefn = NULL;
941 toggle_widgetbehavior.w_deletefn = iemgui_delete;
942 toggle_widgetbehavior.w_visfn = iemgui_vis;
943 toggle_widgetbehavior.w_clickfn = toggle_newclick;
944 class_setwidget(toggle_class, &toggle_widgetbehavior);
945 class_sethelpsymbol(toggle_class, gensym("toggle"));
946 class_setsavefn(toggle_class, toggle_save);
947 class_setpropertiesfn(toggle_class, toggle_properties);
948}