summaryrefslogtreecommitdiff
path: root/apps/plugins/pdbox/PDa/src/g_bang.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/pdbox/PDa/src/g_bang.c')
-rw-r--r--apps/plugins/pdbox/PDa/src/g_bang.c1108
1 files changed, 1108 insertions, 0 deletions
diff --git a/apps/plugins/pdbox/PDa/src/g_bang.c b/apps/plugins/pdbox/PDa/src/g_bang.c
new file mode 100644
index 0000000000..c676bf8675
--- /dev/null
+++ b/apps/plugins/pdbox/PDa/src/g_bang.c
@@ -0,0 +1,1108 @@
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
26/* --------------- bng gui-bang ------------------------- */
27
28t_widgetbehavior bng_widgetbehavior;
29static t_class *bng_class;
30
31/* widget helper functions */
32
33
34void bng_draw_update(t_bng *x, t_glist *glist)
35{
36 if(glist_isvisible(glist))
37 {
38 sys_vgui(".x%x.c itemconfigure %xBUT -fill #%6.6x\n", glist_getcanvas(glist), x,
39 x->x_flashed?x->x_gui.x_fcol:x->x_gui.x_bcol);
40 }
41}
42
43void bng_draw_new(t_bng *x, t_glist *glist)
44{
45 int xpos=text_xpix(&x->x_gui.x_obj, glist);
46 int ypos=text_ypix(&x->x_gui.x_obj, glist);
47 t_canvas *canvas=glist_getcanvas(glist);
48
49 sys_vgui(".x%x.c create rectangle %d %d %d %d -fill #%6.6x -tags %xBASE\n",
50 canvas, xpos, ypos,
51 xpos + x->x_gui.x_w, ypos + x->x_gui.x_h,
52 x->x_gui.x_bcol, x);
53 sys_vgui(".x%x.c create oval %d %d %d %d -fill #%6.6x -tags %xBUT\n",
54 canvas, xpos+1, ypos+1,
55 xpos + x->x_gui.x_w-1, ypos + x->x_gui.x_h-1,
56 x->x_flashed?x->x_gui.x_fcol:x->x_gui.x_bcol, x);
57 sys_vgui(".x%x.c create text %d %d -text {%s} -anchor w \
58 -font {%s %d bold} -fill #%6.6x -tags %xLABEL\n",
59 canvas, xpos+x->x_gui.x_ldx,
60 ypos+x->x_gui.x_ldy,
61 strcmp(x->x_gui.x_lab->s_name, "empty")?x->x_gui.x_lab->s_name:"",
62 x->x_gui.x_font, x->x_gui.x_fontsize, x->x_gui.x_lcol, x);
63 if(!x->x_gui.x_fsf.x_snd_able)
64 sys_vgui(".x%x.c create rectangle %d %d %d %d -tags %xOUT%d\n",
65 canvas, xpos,
66 ypos + x->x_gui.x_h-1, xpos + IOWIDTH,
67 ypos + x->x_gui.x_h, x, 0);
68 if(!x->x_gui.x_fsf.x_rcv_able)
69 sys_vgui(".x%x.c create rectangle %d %d %d %d -tags %xIN%d\n",
70 canvas, xpos, ypos,
71 xpos + IOWIDTH, ypos+1, x, 0);
72}
73
74void bng_draw_move(t_bng *x, t_glist *glist)
75{
76 int xpos=text_xpix(&x->x_gui.x_obj, glist);
77 int ypos=text_ypix(&x->x_gui.x_obj, glist);
78 t_canvas *canvas=glist_getcanvas(glist);
79
80 sys_vgui(".x%x.c coords %xBASE %d %d %d %d\n",
81 canvas, x, xpos, ypos,
82 xpos + x->x_gui.x_w, ypos + x->x_gui.x_h);
83 sys_vgui(".x%x.c coords %xBUT %d %d %d %d\n",
84 canvas, x, xpos+1,ypos+1,
85 xpos + x->x_gui.x_w-1, ypos + x->x_gui.x_h-1);
86 sys_vgui(".x%x.c itemconfigure %xBUT -fill #%6.6x\n", canvas, x,
87 x->x_flashed?x->x_gui.x_fcol:x->x_gui.x_bcol);
88 sys_vgui(".x%x.c coords %xLABEL %d %d\n",
89 canvas, x, xpos+x->x_gui.x_ldx, ypos+x->x_gui.x_ldy);
90 if(!x->x_gui.x_fsf.x_snd_able)
91 sys_vgui(".x%x.c coords %xOUT%d %d %d %d %d\n",
92 canvas, x, 0, xpos,
93 ypos + x->x_gui.x_h-1, xpos + IOWIDTH,
94 ypos + x->x_gui.x_h);
95 if(!x->x_gui.x_fsf.x_rcv_able)
96 sys_vgui(".x%x.c coords %xIN%d %d %d %d %d\n",
97 canvas, x, 0, xpos, ypos,
98 xpos + IOWIDTH, ypos+1);
99}
100
101void bng_draw_erase(t_bng* x, t_glist* glist)
102{
103 t_canvas *canvas=glist_getcanvas(glist);
104
105 sys_vgui(".x%x.c delete %xBASE\n", canvas, x);
106 sys_vgui(".x%x.c delete %xBUT\n", canvas, x);
107 sys_vgui(".x%x.c delete %xLABEL\n", canvas, x);
108 if(!x->x_gui.x_fsf.x_snd_able)
109 sys_vgui(".x%x.c delete %xOUT%d\n", canvas, x, 0);
110 if(!x->x_gui.x_fsf.x_rcv_able)
111 sys_vgui(".x%x.c delete %xIN%d\n", canvas, x, 0);
112}
113
114void bng_draw_config(t_bng* x, t_glist* glist)
115{
116 t_canvas *canvas=glist_getcanvas(glist);
117
118 sys_vgui(".x%x.c itemconfigure %xLABEL -font {%s %d bold} -fill #%6.6x -text {%s} \n",
119 canvas, x, x->x_gui.x_font, x->x_gui.x_fontsize,
120 x->x_gui.x_fsf.x_selected?IEM_GUI_COLOR_SELECTED:x->x_gui.x_lcol,
121 strcmp(x->x_gui.x_lab->s_name, "empty")?x->x_gui.x_lab->s_name:"");
122 sys_vgui(".x%x.c itemconfigure %xBASE -fill #%6.6x\n", canvas, x, x->x_gui.x_bcol);
123 sys_vgui(".x%x.c itemconfigure %xBUT -fill #%6.6x\n", canvas, x,
124 x->x_flashed?x->x_gui.x_fcol:x->x_gui.x_bcol);
125}
126
127void bng_draw_io(t_bng* x, t_glist* glist, int old_snd_rcv_flags)
128{
129 int xpos=text_xpix(&x->x_gui.x_obj, glist);
130 int ypos=text_ypix(&x->x_gui.x_obj, glist);
131 t_canvas *canvas=glist_getcanvas(glist);
132
133 if((old_snd_rcv_flags & IEM_GUI_OLD_SND_FLAG) && !x->x_gui.x_fsf.x_snd_able)
134 sys_vgui(".x%x.c create rectangle %d %d %d %d -tags %xOUT%d\n",
135 canvas, xpos,
136 ypos + x->x_gui.x_h-1, xpos + IOWIDTH,
137 ypos + x->x_gui.x_h, x, 0);
138 if(!(old_snd_rcv_flags & IEM_GUI_OLD_SND_FLAG) && x->x_gui.x_fsf.x_snd_able)
139 sys_vgui(".x%x.c delete %xOUT%d\n", canvas, x, 0);
140 if((old_snd_rcv_flags & IEM_GUI_OLD_RCV_FLAG) && !x->x_gui.x_fsf.x_rcv_able)
141 sys_vgui(".x%x.c create rectangle %d %d %d %d -tags %xIN%d\n",
142 canvas, xpos, ypos,
143 xpos + IOWIDTH, ypos+1, x, 0);
144 if(!(old_snd_rcv_flags & IEM_GUI_OLD_RCV_FLAG) && x->x_gui.x_fsf.x_rcv_able)
145 sys_vgui(".x%x.c delete %xIN%d\n", canvas, x, 0);
146}
147
148void bng_draw_select(t_bng* x, t_glist* glist)
149{
150 t_canvas *canvas=glist_getcanvas(glist);
151
152 if(x->x_gui.x_fsf.x_selected)
153 {
154 sys_vgui(".x%x.c itemconfigure %xBASE -outline #%6.6x\n", canvas, x, IEM_GUI_COLOR_SELECTED);
155 sys_vgui(".x%x.c itemconfigure %xBUT -outline #%6.6x\n", canvas, x, IEM_GUI_COLOR_SELECTED);
156 sys_vgui(".x%x.c itemconfigure %xLABEL -fill #%6.6x\n", canvas, x, IEM_GUI_COLOR_SELECTED);
157 }
158 else
159 {
160 sys_vgui(".x%x.c itemconfigure %xBASE -outline #%6.6x\n", canvas, x, IEM_GUI_COLOR_NORMAL);
161 sys_vgui(".x%x.c itemconfigure %xBUT -outline #%6.6x\n", canvas, x, IEM_GUI_COLOR_NORMAL);
162 sys_vgui(".x%x.c itemconfigure %xLABEL -fill #%6.6x\n", canvas, x, x->x_gui.x_lcol);
163 }
164}
165
166void bng_draw(t_bng *x, t_glist *glist, int mode)
167{
168 if(mode == IEM_GUI_DRAW_MODE_UPDATE)
169 bng_draw_update(x, glist);
170 else if(mode == IEM_GUI_DRAW_MODE_MOVE)
171 bng_draw_move(x, glist);
172 else if(mode == IEM_GUI_DRAW_MODE_NEW)
173 bng_draw_new(x, glist);
174 else if(mode == IEM_GUI_DRAW_MODE_SELECT)
175 bng_draw_select(x, glist);
176 else if(mode == IEM_GUI_DRAW_MODE_ERASE)
177 bng_draw_erase(x, glist);
178 else if(mode == IEM_GUI_DRAW_MODE_CONFIG)
179 bng_draw_config(x, glist);
180 else if(mode >= IEM_GUI_DRAW_MODE_IO)
181 bng_draw_io(x, glist, mode - IEM_GUI_DRAW_MODE_IO);
182}
183
184/* ------------------------ bng widgetbehaviour----------------------------- */
185
186static void bng_getrect(t_gobj *z, t_glist *glist, int *xp1, int *yp1, int *xp2, int *yp2)
187{
188 t_bng *x = (t_bng *)z;
189
190 *xp1 = text_xpix(&x->x_gui.x_obj, glist);
191 *yp1 = text_ypix(&x->x_gui.x_obj, glist);
192 *xp2 = *xp1 + x->x_gui.x_w;
193 *yp2 = *yp1 + x->x_gui.x_h;
194}
195
196static void bng_save(t_gobj *z, t_binbuf *b)
197{
198 t_bng *x = (t_bng *)z;
199 int bflcol[3];
200 t_symbol *srl[3];
201
202 iemgui_save(&x->x_gui, srl, bflcol);
203 binbuf_addv(b, "ssiisiiiisssiiiiiii", gensym("#X"),gensym("obj"),
204 (t_int)x->x_gui.x_obj.te_xpix, (t_int)x->x_gui.x_obj.te_ypix,
205 gensym("bng"), x->x_gui.x_w,
206 x->x_flashtime_hold, x->x_flashtime_break,
207 iem_symargstoint(&x->x_gui.x_isa),
208 srl[0], srl[1], srl[2],
209 x->x_gui.x_ldx, x->x_gui.x_ldy,
210 iem_fstyletoint(&x->x_gui.x_fsf), x->x_gui.x_fontsize,
211 bflcol[0], bflcol[1], bflcol[2]);
212 binbuf_addv(b, ";");
213}
214
215void bng_check_minmax(t_bng *x, int ftbreak, int fthold)
216{
217 if(ftbreak > fthold)
218 {
219 int h;
220
221 h = ftbreak;
222 ftbreak = fthold;
223 fthold = h;
224 }
225 if(ftbreak < IEM_BNG_MINBREAKFLASHTIME)
226 ftbreak = IEM_BNG_MINBREAKFLASHTIME;
227 if(fthold < IEM_BNG_MINHOLDFLASHTIME)
228 fthold = IEM_BNG_MINHOLDFLASHTIME;
229 x->x_flashtime_break = ftbreak;
230 x->x_flashtime_hold = fthold;
231}
232
233static void bng_properties(t_gobj *z, t_glist *owner)
234{
235 t_bng *x = (t_bng *)z;
236 char buf[800];
237 t_symbol *srl[3];
238
239 iemgui_properties(&x->x_gui, srl);
240 sprintf(buf, "pdtk_iemgui_dialog %%s BANG \
241 ----------dimensions(pix):----------- %d %d size: 0 0 empty \
242 --------flash-time(ms)(ms):--------- %d intrrpt: %d hold: %d \
243 %d empty empty %d %d empty %d \
244 %s %s \
245 %s %d %d \
246 %d %d \
247 %d %d %d\n",
248 x->x_gui.x_w, IEM_GUI_MINSIZE,
249 x->x_flashtime_break, x->x_flashtime_hold, 2,/*min_max_schedule+clip*/
250 -1, x->x_gui.x_isa.x_loadinit, -1, -1,/*no linlog, no multi*/
251 srl[0]->s_name, srl[1]->s_name,
252 srl[2]->s_name, x->x_gui.x_ldx, x->x_gui.x_ldy,
253 x->x_gui.x_fsf.x_font_style, x->x_gui.x_fontsize,
254 0xffffff & x->x_gui.x_bcol, 0xffffff & x->x_gui.x_fcol, 0xffffff & x->x_gui.x_lcol);
255 gfxstub_new(&x->x_gui.x_obj.ob_pd, x, buf);
256}
257
258static void bng_set(t_bng *x)
259{
260 if(x->x_flashed)
261 {
262 x->x_flashed = 0;
263 (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
264 clock_delay(x->x_clock_brk, x->x_flashtime_break);
265 x->x_flashed = 1;
266 }
267 else
268 {
269 x->x_flashed = 1;
270 (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
271 }
272 clock_delay(x->x_clock_hld, x->x_flashtime_hold);
273}
274
275static void bng_bout1(t_bng *x)/*wird nur mehr gesendet, wenn snd != rcv*/
276{
277 if(!x->x_gui.x_fsf.x_put_in2out)
278 {
279 x->x_gui.x_isa.x_locked = 1;
280 clock_delay(x->x_clock_lck, 2);
281 }
282 outlet_bang(x->x_gui.x_obj.ob_outlet);
283 if(x->x_gui.x_fsf.x_snd_able && x->x_gui.x_snd->s_thing && x->x_gui.x_fsf.x_put_in2out)
284 pd_bang(x->x_gui.x_snd->s_thing);
285}
286
287static void bng_bout2(t_bng *x)/*wird immer gesendet, wenn moeglich*/
288{
289 if(!x->x_gui.x_fsf.x_put_in2out)
290 {
291 x->x_gui.x_isa.x_locked = 1;
292 clock_delay(x->x_clock_lck, 2);
293 }
294 outlet_bang(x->x_gui.x_obj.ob_outlet);
295 if(x->x_gui.x_fsf.x_snd_able && x->x_gui.x_snd->s_thing)
296 pd_bang(x->x_gui.x_snd->s_thing);
297}
298
299static void bng_bang(t_bng *x)/*wird nur mehr gesendet, wenn snd != rcv*/
300{
301 if(!x->x_gui.x_isa.x_locked)
302 {
303 bng_set(x);
304 bng_bout1(x);
305 }
306}
307
308static void bng_bang2(t_bng *x)/*wird immer gesendet, wenn moeglich*/
309{
310 if(!x->x_gui.x_isa.x_locked)
311 {
312 bng_set(x);
313 bng_bout2(x);
314 }
315}
316
317static void bng_dialog(t_bng *x, t_symbol *s, int argc, t_atom *argv)
318{
319 t_symbol *srl[3];
320 int a = (int)atom_getintarg(0, argc, argv);
321 int fthold = (int)atom_getintarg(2, argc, argv);
322 int ftbreak = (int)atom_getintarg(3, argc, argv);
323 int sr_flags = iemgui_dialog(&x->x_gui, srl, argc, argv);
324
325 x->x_gui.x_w = iemgui_clip_size(a);
326 x->x_gui.x_h = x->x_gui.x_w;
327 bng_check_minmax(x, ftbreak, fthold);
328 (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_CONFIG);
329 (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_IO + sr_flags);
330 (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_MOVE);
331 canvas_fixlinesfor(glist_getcanvas(x->x_gui.x_glist), (t_text*)x);
332}
333
334static void bng_click(t_bng *x, t_floatarg xpos, t_floatarg ypos, t_floatarg shift, t_floatarg ctrl, t_floatarg alt)
335{
336 bng_set(x);
337 bng_bout2(x);
338}
339
340static int bng_newclick(t_gobj *z, struct _glist *glist, int xpix, int ypix, int shift, int alt, int dbl, int doit)
341{
342 if(doit)
343 bng_click((t_bng *)z, (t_floatarg)xpix, (t_floatarg)ypix, (t_floatarg)shift, 0, (t_floatarg)alt);
344 return (1);
345}
346
347static void bng_float(t_bng *x, t_floatarg f)
348{bng_bang2(x);}
349
350static void bng_symbol(t_bng *x, t_symbol *s)
351{bng_bang2(x);}
352
353static void bng_pointer(t_bng *x, t_gpointer *gp)
354{bng_bang2(x);}
355
356static void bng_list(t_bng *x, t_symbol *s, int ac, t_atom *av)
357{
358 bng_bang2(x);
359}
360
361static void bng_anything(t_bng *x, t_symbol *s, int argc, t_atom *argv)
362{bng_bang2(x);}
363
364static void bng_loadbang(t_bng *x)
365{
366 if(!sys_noloadbang && x->x_gui.x_isa.x_loadinit)
367 {
368 bng_set(x);
369 bng_bout2(x);
370 }
371}
372
373static void bng_size(t_bng *x, t_symbol *s, int ac, t_atom *av)
374{
375 x->x_gui.x_w = iemgui_clip_size((int)atom_getintarg(0, ac, av));
376 x->x_gui.x_h = x->x_gui.x_w;
377 iemgui_size((void *)x, &x->x_gui);
378}
379
380static void bng_delta(t_bng *x, t_symbol *s, int ac, t_atom *av)
381{iemgui_delta((void *)x, &x->x_gui, s, ac, av);}
382
383static void bng_pos(t_bng *x, t_symbol *s, int ac, t_atom *av)
384{iemgui_pos((void *)x, &x->x_gui, s, ac, av);}
385
386static void bng_flashtime(t_bng *x, t_symbol *s, int ac, t_atom *av)
387{
388 bng_check_minmax(x, (int)atom_getintarg(0, ac, av),
389 (int)atom_getintarg(1, ac, av));
390}
391
392static void bng_color(t_bng *x, t_symbol *s, int ac, t_atom *av)
393{iemgui_color((void *)x, &x->x_gui, s, ac, av);}
394
395static void bng_send(t_bng *x, t_symbol *s)
396{iemgui_send(x, &x->x_gui, s);}
397
398static void bng_receive(t_bng *x, t_symbol *s)
399{iemgui_receive(x, &x->x_gui, s);}
400
401static void bng_label(t_bng *x, t_symbol *s)
402{iemgui_label((void *)x, &x->x_gui, s);}
403
404static void bng_label_pos(t_bng *x, t_symbol *s, int ac, t_atom *av)
405{iemgui_label_pos((void *)x, &x->x_gui, s, ac, av);}
406
407static void bng_label_font(t_bng *x, t_symbol *s, int ac, t_atom *av)
408{iemgui_label_font((void *)x, &x->x_gui, s, ac, av);}
409
410static void bng_init(t_bng *x, t_floatarg f)
411{
412 x->x_gui.x_isa.x_loadinit = (f==0.0)?0:1;
413}
414
415static void bng_tick_hld(t_bng *x)
416{
417 x->x_flashed = 0;
418 (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
419}
420
421static void bng_tick_brk(t_bng *x)
422{
423 (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
424}
425
426static void bng_tick_lck(t_bng *x)
427{
428 x->x_gui.x_isa.x_locked = 0;
429}
430
431static void *bng_new(t_symbol *s, int argc, t_atom *argv)
432{
433 t_bng *x = (t_bng *)pd_new(bng_class);
434 int bflcol[]={-262144, -1, -1};
435 int a=IEM_GUI_DEFAULTSIZE;
436 int ldx=0, ldy=-6;
437 int fs=8;
438 int ftbreak=IEM_BNG_DEFAULTBREAKFLASHTIME,
439 fthold=IEM_BNG_DEFAULTHOLDFLASHTIME;
440 char str[144];
441
442 iem_inttosymargs(&x->x_gui.x_isa, 0);
443 iem_inttofstyle(&x->x_gui.x_fsf, 0);
444
445 if((argc == 14)&&IS_A_FLOAT(argv,0)
446 &&IS_A_FLOAT(argv,1)&&IS_A_FLOAT(argv,2)
447 &&IS_A_FLOAT(argv,3)
448 &&(IS_A_SYMBOL(argv,4)||IS_A_FLOAT(argv,4))
449 &&(IS_A_SYMBOL(argv,5)||IS_A_FLOAT(argv,5))
450 &&(IS_A_SYMBOL(argv,6)||IS_A_FLOAT(argv,6))
451 &&IS_A_FLOAT(argv,7)&&IS_A_FLOAT(argv,8)
452 &&IS_A_FLOAT(argv,9)&&IS_A_FLOAT(argv,10)&&IS_A_FLOAT(argv,11)
453 &&IS_A_FLOAT(argv,12)&&IS_A_FLOAT(argv,13))
454 {
455
456 a = (int)atom_getintarg(0, argc, argv);
457 fthold = (int)atom_getintarg(1, argc, argv);
458 ftbreak = (int)atom_getintarg(2, argc, argv);
459 iem_inttosymargs(&x->x_gui.x_isa, atom_getintarg(3, argc, argv));
460 iemgui_new_getnames(&x->x_gui, 4, argv);
461 ldx = (int)atom_getintarg(7, argc, argv);
462 ldy = (int)atom_getintarg(8, argc, argv);
463 iem_inttofstyle(&x->x_gui.x_fsf, atom_getintarg(9, argc, argv));
464 fs = (int)atom_getintarg(10, argc, argv);
465 bflcol[0] = (int)atom_getintarg(11, argc, argv);
466 bflcol[1] = (int)atom_getintarg(12, argc, argv);
467 bflcol[2] = (int)atom_getintarg(13, argc, argv);
468 }
469 else iemgui_new_getnames(&x->x_gui, 4, 0);
470
471 x->x_gui.x_draw = (t_iemfunptr)bng_draw;
472
473 x->x_gui.x_fsf.x_snd_able = 1;
474 x->x_gui.x_fsf.x_rcv_able = 1;
475 x->x_flashed = 0;
476 x->x_gui.x_glist = (t_glist *)canvas_getcurrent();
477 if (!strcmp(x->x_gui.x_snd->s_name, "empty"))
478 x->x_gui.x_fsf.x_snd_able = 0;
479 if (!strcmp(x->x_gui.x_rcv->s_name, "empty"))
480 x->x_gui.x_fsf.x_rcv_able = 0;
481 if(x->x_gui.x_fsf.x_font_style == 1) strcpy(x->x_gui.x_font, "helvetica");
482 else if(x->x_gui.x_fsf.x_font_style == 2) strcpy(x->x_gui.x_font, "times");
483 else { x->x_gui.x_fsf.x_font_style = 0;
484 strcpy(x->x_gui.x_font, "courier"); }
485
486 if (x->x_gui.x_fsf.x_rcv_able)
487 pd_bind(&x->x_gui.x_obj.ob_pd, x->x_gui.x_rcv);
488 x->x_gui.x_ldx = ldx;
489 x->x_gui.x_ldy = ldy;
490
491 if(fs < 4)
492 fs = 4;
493 x->x_gui.x_fontsize = fs;
494 x->x_gui.x_w = iemgui_clip_size(a);
495 x->x_gui.x_h = x->x_gui.x_w;
496 bng_check_minmax(x, ftbreak, fthold);
497 iemgui_all_colfromload(&x->x_gui, bflcol);
498 x->x_gui.x_isa.x_locked = 0;
499 iemgui_verify_snd_ne_rcv(&x->x_gui);
500 x->x_clock_hld = clock_new(x, (t_method)bng_tick_hld);
501 x->x_clock_brk = clock_new(x, (t_method)bng_tick_brk);
502 x->x_clock_lck = clock_new(x, (t_method)bng_tick_lck);
503 outlet_new(&x->x_gui.x_obj, &s_bang);
504 return (x);
505}
506
507static void bng_ff(t_bng *x)
508{
509 if(x->x_gui.x_fsf.x_rcv_able)
510 pd_unbind(&x->x_gui.x_obj.ob_pd, x->x_gui.x_rcv);
511 clock_free(x->x_clock_lck);
512 clock_free(x->x_clock_brk);
513 clock_free(x->x_clock_hld);
514 gfxstub_deleteforkey(x);
515}
516
517void g_bang_setup(void)
518{
519 bng_class = class_new(gensym("bng"), (t_newmethod)bng_new,
520 (t_method)bng_ff, sizeof(t_bng), 0, A_GIMME, 0);
521 class_addbang(bng_class, bng_bang);
522 class_addfloat(bng_class, bng_float);
523 class_addsymbol(bng_class, bng_symbol);
524 class_addpointer(bng_class, bng_pointer);
525 class_addlist(bng_class, bng_list);
526 class_addanything(bng_class, bng_anything);
527 class_addmethod(bng_class, (t_method)bng_click, gensym("click"),
528 A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, 0);
529 class_addmethod(bng_class, (t_method)bng_dialog, gensym("dialog"),
530 A_GIMME, 0);
531 class_addmethod(bng_class, (t_method)bng_loadbang, gensym("loadbang"), 0);
532 class_addmethod(bng_class, (t_method)bng_size, gensym("size"), A_GIMME, 0);
533 class_addmethod(bng_class, (t_method)bng_delta, gensym("delta"), A_GIMME, 0);
534 class_addmethod(bng_class, (t_method)bng_pos, gensym("pos"), A_GIMME, 0);
535 class_addmethod(bng_class, (t_method)bng_flashtime, gensym("flashtime"), A_GIMME, 0);
536 class_addmethod(bng_class, (t_method)bng_color, gensym("color"), A_GIMME, 0);
537 class_addmethod(bng_class, (t_method)bng_send, gensym("send"), A_DEFSYM, 0);
538 class_addmethod(bng_class, (t_method)bng_receive, gensym("receive"), A_DEFSYM, 0);
539 class_addmethod(bng_class, (t_method)bng_label, gensym("label"), A_DEFSYM, 0);
540 class_addmethod(bng_class, (t_method)bng_label_pos, gensym("label_pos"), A_GIMME, 0);
541 class_addmethod(bng_class, (t_method)bng_label_font, gensym("label_font"), A_GIMME, 0);
542 class_addmethod(bng_class, (t_method)bng_init, gensym("init"), A_FLOAT, 0);
543 bng_widgetbehavior.w_getrectfn = bng_getrect;
544 bng_widgetbehavior.w_displacefn = iemgui_displace;
545 bng_widgetbehavior.w_selectfn = iemgui_select;
546 bng_widgetbehavior.w_activatefn = NULL;
547 bng_widgetbehavior.w_deletefn = iemgui_delete;
548 bng_widgetbehavior.w_visfn = iemgui_vis;
549 bng_widgetbehavior.w_clickfn = bng_newclick;
550 class_setwidget(bng_class, &bng_widgetbehavior);
551 class_sethelpsymbol(bng_class, gensym("bng"));
552 class_setsavefn(bng_class, bng_save);
553 class_setpropertiesfn(bng_class, bng_properties);
554}
555/* Copyright (c) 1997-1999 Miller Puckette.
556 * For information on usage and redistribution, and for a DISCLAIMER OF ALL
557 * WARRANTIES, see the file, "LICENSE.txt," in this distribution. */
558
559/* g_7_guis.c written by Thomas Musil (c) IEM KUG Graz Austria 2000-2001 */
560/* thanks to Miller Puckette, Guenther Geiger and Krzystof Czaja */
561
562
563#include <stdlib.h>
564#include <string.h>
565#include <stdio.h>
566#include <ctype.h>
567#include "m_pd.h"
568#include "g_canvas.h"
569#include "t_tk.h"
570#include "g_all_guis.h"
571#include <math.h>
572
573#ifdef MSW
574#include <io.h>
575#else
576#include <unistd.h>
577#endif
578
579
580/* --------------- bng gui-bang ------------------------- */
581
582t_widgetbehavior bng_widgetbehavior;
583static t_class *bng_class;
584
585/* widget helper functions */
586
587
588void bng_draw_update(t_bng *x, t_glist *glist)
589{
590 if(glist_isvisible(glist))
591 {
592 sys_vgui(".x%x.c itemconfigure %xBUT -fill #%6.6x\n", glist_getcanvas(glist), x,
593 x->x_flashed?x->x_gui.x_fcol:x->x_gui.x_bcol);
594 }
595}
596
597void bng_draw_new(t_bng *x, t_glist *glist)
598{
599 int xpos=text_xpix(&x->x_gui.x_obj, glist);
600 int ypos=text_ypix(&x->x_gui.x_obj, glist);
601 t_canvas *canvas=glist_getcanvas(glist);
602
603 sys_vgui(".x%x.c create rectangle %d %d %d %d -fill #%6.6x -tags %xBASE\n",
604 canvas, xpos, ypos,
605 xpos + x->x_gui.x_w, ypos + x->x_gui.x_h,
606 x->x_gui.x_bcol, x);
607 sys_vgui(".x%x.c create oval %d %d %d %d -fill #%6.6x -tags %xBUT\n",
608 canvas, xpos+1, ypos+1,
609 xpos + x->x_gui.x_w-1, ypos + x->x_gui.x_h-1,
610 x->x_flashed?x->x_gui.x_fcol:x->x_gui.x_bcol, x);
611 sys_vgui(".x%x.c create text %d %d -text {%s} -anchor w \
612 -font {%s %d bold} -fill #%6.6x -tags %xLABEL\n",
613 canvas, xpos+x->x_gui.x_ldx,
614 ypos+x->x_gui.x_ldy,
615 strcmp(x->x_gui.x_lab->s_name, "empty")?x->x_gui.x_lab->s_name:"",
616 x->x_gui.x_font, x->x_gui.x_fontsize, x->x_gui.x_lcol, x);
617 if(!x->x_gui.x_fsf.x_snd_able)
618 sys_vgui(".x%x.c create rectangle %d %d %d %d -tags %xOUT%d\n",
619 canvas, xpos,
620 ypos + x->x_gui.x_h-1, xpos + IOWIDTH,
621 ypos + x->x_gui.x_h, x, 0);
622 if(!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}
627
628void bng_draw_move(t_bng *x, t_glist *glist)
629{
630 int xpos=text_xpix(&x->x_gui.x_obj, glist);
631 int ypos=text_ypix(&x->x_gui.x_obj, glist);
632 t_canvas *canvas=glist_getcanvas(glist);
633
634 sys_vgui(".x%x.c coords %xBASE %d %d %d %d\n",
635 canvas, x, xpos, ypos,
636 xpos + x->x_gui.x_w, ypos + x->x_gui.x_h);
637 sys_vgui(".x%x.c coords %xBUT %d %d %d %d\n",
638 canvas, x, xpos+1,ypos+1,
639 xpos + x->x_gui.x_w-1, ypos + x->x_gui.x_h-1);
640 sys_vgui(".x%x.c itemconfigure %xBUT -fill #%6.6x\n", canvas, x,
641 x->x_flashed?x->x_gui.x_fcol:x->x_gui.x_bcol);
642 sys_vgui(".x%x.c coords %xLABEL %d %d\n",
643 canvas, x, xpos+x->x_gui.x_ldx, ypos+x->x_gui.x_ldy);
644 if(!x->x_gui.x_fsf.x_snd_able)
645 sys_vgui(".x%x.c coords %xOUT%d %d %d %d %d\n",
646 canvas, x, 0, xpos,
647 ypos + x->x_gui.x_h-1, xpos + IOWIDTH,
648 ypos + x->x_gui.x_h);
649 if(!x->x_gui.x_fsf.x_rcv_able)
650 sys_vgui(".x%x.c coords %xIN%d %d %d %d %d\n",
651 canvas, x, 0, xpos, ypos,
652 xpos + IOWIDTH, ypos+1);
653}
654
655void bng_draw_erase(t_bng* x, t_glist* glist)
656{
657 t_canvas *canvas=glist_getcanvas(glist);
658
659 sys_vgui(".x%x.c delete %xBASE\n", canvas, x);
660 sys_vgui(".x%x.c delete %xBUT\n", canvas, x);
661 sys_vgui(".x%x.c delete %xLABEL\n", canvas, x);
662 if(!x->x_gui.x_fsf.x_snd_able)
663 sys_vgui(".x%x.c delete %xOUT%d\n", canvas, x, 0);
664 if(!x->x_gui.x_fsf.x_rcv_able)
665 sys_vgui(".x%x.c delete %xIN%d\n", canvas, x, 0);
666}
667
668void bng_draw_config(t_bng* x, t_glist* glist)
669{
670 t_canvas *canvas=glist_getcanvas(glist);
671
672 sys_vgui(".x%x.c itemconfigure %xLABEL -font {%s %d bold} -fill #%6.6x -text {%s} \n",
673 canvas, x, x->x_gui.x_font, x->x_gui.x_fontsize,
674 x->x_gui.x_fsf.x_selected?IEM_GUI_COLOR_SELECTED:x->x_gui.x_lcol,
675 strcmp(x->x_gui.x_lab->s_name, "empty")?x->x_gui.x_lab->s_name:"");
676 sys_vgui(".x%x.c itemconfigure %xBASE -fill #%6.6x\n", canvas, x, x->x_gui.x_bcol);
677 sys_vgui(".x%x.c itemconfigure %xBUT -fill #%6.6x\n", canvas, x,
678 x->x_flashed?x->x_gui.x_fcol:x->x_gui.x_bcol);
679}
680
681void bng_draw_io(t_bng* x, t_glist* glist, int old_snd_rcv_flags)
682{
683 int xpos=text_xpix(&x->x_gui.x_obj, glist);
684 int ypos=text_ypix(&x->x_gui.x_obj, glist);
685 t_canvas *canvas=glist_getcanvas(glist);
686
687 if((old_snd_rcv_flags & IEM_GUI_OLD_SND_FLAG) && !x->x_gui.x_fsf.x_snd_able)
688 sys_vgui(".x%x.c create rectangle %d %d %d %d -tags %xOUT%d\n",
689 canvas, xpos,
690 ypos + x->x_gui.x_h-1, xpos + IOWIDTH,
691 ypos + x->x_gui.x_h, x, 0);
692 if(!(old_snd_rcv_flags & IEM_GUI_OLD_SND_FLAG) && x->x_gui.x_fsf.x_snd_able)
693 sys_vgui(".x%x.c delete %xOUT%d\n", canvas, x, 0);
694 if((old_snd_rcv_flags & IEM_GUI_OLD_RCV_FLAG) && !x->x_gui.x_fsf.x_rcv_able)
695 sys_vgui(".x%x.c create rectangle %d %d %d %d -tags %xIN%d\n",
696 canvas, xpos, ypos,
697 xpos + IOWIDTH, ypos+1, x, 0);
698 if(!(old_snd_rcv_flags & IEM_GUI_OLD_RCV_FLAG) && x->x_gui.x_fsf.x_rcv_able)
699 sys_vgui(".x%x.c delete %xIN%d\n", canvas, x, 0);
700}
701
702void bng_draw_select(t_bng* x, t_glist* glist)
703{
704 t_canvas *canvas=glist_getcanvas(glist);
705
706 if(x->x_gui.x_fsf.x_selected)
707 {
708 sys_vgui(".x%x.c itemconfigure %xBASE -outline #%6.6x\n", canvas, x, IEM_GUI_COLOR_SELECTED);
709 sys_vgui(".x%x.c itemconfigure %xBUT -outline #%6.6x\n", canvas, x, IEM_GUI_COLOR_SELECTED);
710 sys_vgui(".x%x.c itemconfigure %xLABEL -fill #%6.6x\n", canvas, x, IEM_GUI_COLOR_SELECTED);
711 }
712 else
713 {
714 sys_vgui(".x%x.c itemconfigure %xBASE -outline #%6.6x\n", canvas, x, IEM_GUI_COLOR_NORMAL);
715 sys_vgui(".x%x.c itemconfigure %xBUT -outline #%6.6x\n", canvas, x, IEM_GUI_COLOR_NORMAL);
716 sys_vgui(".x%x.c itemconfigure %xLABEL -fill #%6.6x\n", canvas, x, x->x_gui.x_lcol);
717 }
718}
719
720void bng_draw(t_bng *x, t_glist *glist, int mode)
721{
722 if(mode == IEM_GUI_DRAW_MODE_UPDATE)
723 bng_draw_update(x, glist);
724 else if(mode == IEM_GUI_DRAW_MODE_MOVE)
725 bng_draw_move(x, glist);
726 else if(mode == IEM_GUI_DRAW_MODE_NEW)
727 bng_draw_new(x, glist);
728 else if(mode == IEM_GUI_DRAW_MODE_SELECT)
729 bng_draw_select(x, glist);
730 else if(mode == IEM_GUI_DRAW_MODE_ERASE)
731 bng_draw_erase(x, glist);
732 else if(mode == IEM_GUI_DRAW_MODE_CONFIG)
733 bng_draw_config(x, glist);
734 else if(mode >= IEM_GUI_DRAW_MODE_IO)
735 bng_draw_io(x, glist, mode - IEM_GUI_DRAW_MODE_IO);
736}
737
738/* ------------------------ bng widgetbehaviour----------------------------- */
739
740static void bng_getrect(t_gobj *z, t_glist *glist, int *xp1, int *yp1, int *xp2, int *yp2)
741{
742 t_bng *x = (t_bng *)z;
743
744 *xp1 = text_xpix(&x->x_gui.x_obj, glist);
745 *yp1 = text_ypix(&x->x_gui.x_obj, glist);
746 *xp2 = *xp1 + x->x_gui.x_w;
747 *yp2 = *yp1 + x->x_gui.x_h;
748}
749
750static void bng_save(t_gobj *z, t_binbuf *b)
751{
752 t_bng *x = (t_bng *)z;
753 int bflcol[3];
754 t_symbol *srl[3];
755
756 iemgui_save(&x->x_gui, srl, bflcol);
757 binbuf_addv(b, "ssiisiiiisssiiiiiii", gensym("#X"),gensym("obj"),
758 (t_int)x->x_gui.x_obj.te_xpix, (t_int)x->x_gui.x_obj.te_ypix,
759 gensym("bng"), x->x_gui.x_w,
760 x->x_flashtime_hold, x->x_flashtime_break,
761 iem_symargstoint(&x->x_gui.x_isa),
762 srl[0], srl[1], srl[2],
763 x->x_gui.x_ldx, x->x_gui.x_ldy,
764 iem_fstyletoint(&x->x_gui.x_fsf), x->x_gui.x_fontsize,
765 bflcol[0], bflcol[1], bflcol[2]);
766 binbuf_addv(b, ";");
767}
768
769void bng_check_minmax(t_bng *x, int ftbreak, int fthold)
770{
771 if(ftbreak > fthold)
772 {
773 int h;
774
775 h = ftbreak;
776 ftbreak = fthold;
777 fthold = h;
778 }
779 if(ftbreak < IEM_BNG_MINBREAKFLASHTIME)
780 ftbreak = IEM_BNG_MINBREAKFLASHTIME;
781 if(fthold < IEM_BNG_MINHOLDFLASHTIME)
782 fthold = IEM_BNG_MINHOLDFLASHTIME;
783 x->x_flashtime_break = ftbreak;
784 x->x_flashtime_hold = fthold;
785}
786
787static void bng_properties(t_gobj *z, t_glist *owner)
788{
789 t_bng *x = (t_bng *)z;
790 char buf[800];
791 t_symbol *srl[3];
792
793 iemgui_properties(&x->x_gui, srl);
794 sprintf(buf, "pdtk_iemgui_dialog %%s BANG \
795 ----------dimensions(pix):----------- %d %d size: 0 0 empty \
796 --------flash-time(ms)(ms):--------- %d intrrpt: %d hold: %d \
797 %d empty empty %d %d empty %d \
798 %s %s \
799 %s %d %d \
800 %d %d \
801 %d %d %d\n",
802 x->x_gui.x_w, IEM_GUI_MINSIZE,
803 x->x_flashtime_break, x->x_flashtime_hold, 2,/*min_max_schedule+clip*/
804 -1, x->x_gui.x_isa.x_loadinit, -1, -1,/*no linlog, no multi*/
805 srl[0]->s_name, srl[1]->s_name,
806 srl[2]->s_name, x->x_gui.x_ldx, x->x_gui.x_ldy,
807 x->x_gui.x_fsf.x_font_style, x->x_gui.x_fontsize,
808 0xffffff & x->x_gui.x_bcol, 0xffffff & x->x_gui.x_fcol, 0xffffff & x->x_gui.x_lcol);
809 gfxstub_new(&x->x_gui.x_obj.ob_pd, x, buf);
810}
811
812static void bng_set(t_bng *x)
813{
814 if(x->x_flashed)
815 {
816 x->x_flashed = 0;
817 (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
818 clock_delay(x->x_clock_brk, x->x_flashtime_break);
819 x->x_flashed = 1;
820 }
821 else
822 {
823 x->x_flashed = 1;
824 (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
825 }
826 clock_delay(x->x_clock_hld, x->x_flashtime_hold);
827}
828
829static void bng_bout1(t_bng *x)/*wird nur mehr gesendet, wenn snd != rcv*/
830{
831 if(!x->x_gui.x_fsf.x_put_in2out)
832 {
833 x->x_gui.x_isa.x_locked = 1;
834 clock_delay(x->x_clock_lck, 2);
835 }
836 outlet_bang(x->x_gui.x_obj.ob_outlet);
837 if(x->x_gui.x_fsf.x_snd_able && x->x_gui.x_snd->s_thing && x->x_gui.x_fsf.x_put_in2out)
838 pd_bang(x->x_gui.x_snd->s_thing);
839}
840
841static void bng_bout2(t_bng *x)/*wird immer gesendet, wenn moeglich*/
842{
843 if(!x->x_gui.x_fsf.x_put_in2out)
844 {
845 x->x_gui.x_isa.x_locked = 1;
846 clock_delay(x->x_clock_lck, 2);
847 }
848 outlet_bang(x->x_gui.x_obj.ob_outlet);
849 if(x->x_gui.x_fsf.x_snd_able && x->x_gui.x_snd->s_thing)
850 pd_bang(x->x_gui.x_snd->s_thing);
851}
852
853static void bng_bang(t_bng *x)/*wird nur mehr gesendet, wenn snd != rcv*/
854{
855 if(!x->x_gui.x_isa.x_locked)
856 {
857 bng_set(x);
858 bng_bout1(x);
859 }
860}
861
862static void bng_bang2(t_bng *x)/*wird immer gesendet, wenn moeglich*/
863{
864 if(!x->x_gui.x_isa.x_locked)
865 {
866 bng_set(x);
867 bng_bout2(x);
868 }
869}
870
871static void bng_dialog(t_bng *x, t_symbol *s, int argc, t_atom *argv)
872{
873 t_symbol *srl[3];
874 int a = (int)atom_getintarg(0, argc, argv);
875 int fthold = (int)atom_getintarg(2, argc, argv);
876 int ftbreak = (int)atom_getintarg(3, argc, argv);
877 int sr_flags = iemgui_dialog(&x->x_gui, srl, argc, argv);
878
879 x->x_gui.x_w = iemgui_clip_size(a);
880 x->x_gui.x_h = x->x_gui.x_w;
881 bng_check_minmax(x, ftbreak, fthold);
882 (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_CONFIG);
883 (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_IO + sr_flags);
884 (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_MOVE);
885 canvas_fixlinesfor(glist_getcanvas(x->x_gui.x_glist), (t_text*)x);
886}
887
888static void bng_click(t_bng *x, t_floatarg xpos, t_floatarg ypos, t_floatarg shift, t_floatarg ctrl, t_floatarg alt)
889{
890 bng_set(x);
891 bng_bout2(x);
892}
893
894static int bng_newclick(t_gobj *z, struct _glist *glist, int xpix, int ypix, int shift, int alt, int dbl, int doit)
895{
896 if(doit)
897 bng_click((t_bng *)z, (t_floatarg)xpix, (t_floatarg)ypix, (t_floatarg)shift, 0, (t_floatarg)alt);
898 return (1);
899}
900
901static void bng_float(t_bng *x, t_floatarg f)
902{bng_bang2(x);}
903
904static void bng_symbol(t_bng *x, t_symbol *s)
905{bng_bang2(x);}
906
907static void bng_pointer(t_bng *x, t_gpointer *gp)
908{bng_bang2(x);}
909
910static void bng_list(t_bng *x, t_symbol *s, int ac, t_atom *av)
911{
912 bng_bang2(x);
913}
914
915static void bng_anything(t_bng *x, t_symbol *s, int argc, t_atom *argv)
916{bng_bang2(x);}
917
918static void bng_loadbang(t_bng *x)
919{
920 if(!sys_noloadbang && x->x_gui.x_isa.x_loadinit)
921 {
922 bng_set(x);
923 bng_bout2(x);
924 }
925}
926
927static void bng_size(t_bng *x, t_symbol *s, int ac, t_atom *av)
928{
929 x->x_gui.x_w = iemgui_clip_size((int)atom_getintarg(0, ac, av));
930 x->x_gui.x_h = x->x_gui.x_w;
931 iemgui_size((void *)x, &x->x_gui);
932}
933
934static void bng_delta(t_bng *x, t_symbol *s, int ac, t_atom *av)
935{iemgui_delta((void *)x, &x->x_gui, s, ac, av);}
936
937static void bng_pos(t_bng *x, t_symbol *s, int ac, t_atom *av)
938{iemgui_pos((void *)x, &x->x_gui, s, ac, av);}
939
940static void bng_flashtime(t_bng *x, t_symbol *s, int ac, t_atom *av)
941{
942 bng_check_minmax(x, (int)atom_getintarg(0, ac, av),
943 (int)atom_getintarg(1, ac, av));
944}
945
946static void bng_color(t_bng *x, t_symbol *s, int ac, t_atom *av)
947{iemgui_color((void *)x, &x->x_gui, s, ac, av);}
948
949static void bng_send(t_bng *x, t_symbol *s)
950{iemgui_send(x, &x->x_gui, s);}
951
952static void bng_receive(t_bng *x, t_symbol *s)
953{iemgui_receive(x, &x->x_gui, s);}
954
955static void bng_label(t_bng *x, t_symbol *s)
956{iemgui_label((void *)x, &x->x_gui, s);}
957
958static void bng_label_pos(t_bng *x, t_symbol *s, int ac, t_atom *av)
959{iemgui_label_pos((void *)x, &x->x_gui, s, ac, av);}
960
961static void bng_label_font(t_bng *x, t_symbol *s, int ac, t_atom *av)
962{iemgui_label_font((void *)x, &x->x_gui, s, ac, av);}
963
964static void bng_init(t_bng *x, t_floatarg f)
965{
966 x->x_gui.x_isa.x_loadinit = (f==0.0)?0:1;
967}
968
969static void bng_tick_hld(t_bng *x)
970{
971 x->x_flashed = 0;
972 (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
973}
974
975static void bng_tick_brk(t_bng *x)
976{
977 (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
978}
979
980static void bng_tick_lck(t_bng *x)
981{
982 x->x_gui.x_isa.x_locked = 0;
983}
984
985static void *bng_new(t_symbol *s, int argc, t_atom *argv)
986{
987 t_bng *x = (t_bng *)pd_new(bng_class);
988 int bflcol[]={-262144, -1, -1};
989 int a=IEM_GUI_DEFAULTSIZE;
990 int ldx=0, ldy=-6;
991 int fs=8;
992 int ftbreak=IEM_BNG_DEFAULTBREAKFLASHTIME,
993 fthold=IEM_BNG_DEFAULTHOLDFLASHTIME;
994 char str[144];
995
996 iem_inttosymargs(&x->x_gui.x_isa, 0);
997 iem_inttofstyle(&x->x_gui.x_fsf, 0);
998
999 if((argc == 14)&&IS_A_FLOAT(argv,0)
1000 &&IS_A_FLOAT(argv,1)&&IS_A_FLOAT(argv,2)
1001 &&IS_A_FLOAT(argv,3)
1002 &&(IS_A_SYMBOL(argv,4)||IS_A_FLOAT(argv,4))
1003 &&(IS_A_SYMBOL(argv,5)||IS_A_FLOAT(argv,5))
1004 &&(IS_A_SYMBOL(argv,6)||IS_A_FLOAT(argv,6))
1005 &&IS_A_FLOAT(argv,7)&&IS_A_FLOAT(argv,8)
1006 &&IS_A_FLOAT(argv,9)&&IS_A_FLOAT(argv,10)&&IS_A_FLOAT(argv,11)
1007 &&IS_A_FLOAT(argv,12)&&IS_A_FLOAT(argv,13))
1008 {
1009
1010 a = (int)atom_getintarg(0, argc, argv);
1011 fthold = (int)atom_getintarg(1, argc, argv);
1012 ftbreak = (int)atom_getintarg(2, argc, argv);
1013 iem_inttosymargs(&x->x_gui.x_isa, atom_getintarg(3, argc, argv));
1014 iemgui_new_getnames(&x->x_gui, 4, argv);
1015 ldx = (int)atom_getintarg(7, argc, argv);
1016 ldy = (int)atom_getintarg(8, argc, argv);
1017 iem_inttofstyle(&x->x_gui.x_fsf, atom_getintarg(9, argc, argv));
1018 fs = (int)atom_getintarg(10, argc, argv);
1019 bflcol[0] = (int)atom_getintarg(11, argc, argv);
1020 bflcol[1] = (int)atom_getintarg(12, argc, argv);
1021 bflcol[2] = (int)atom_getintarg(13, argc, argv);
1022 }
1023 else iemgui_new_getnames(&x->x_gui, 4, 0);
1024
1025 x->x_gui.x_draw = (t_iemfunptr)bng_draw;
1026
1027 x->x_gui.x_fsf.x_snd_able = 1;
1028 x->x_gui.x_fsf.x_rcv_able = 1;
1029 x->x_flashed = 0;
1030 x->x_gui.x_glist = (t_glist *)canvas_getcurrent();
1031 if (!strcmp(x->x_gui.x_snd->s_name, "empty"))
1032 x->x_gui.x_fsf.x_snd_able = 0;
1033 if (!strcmp(x->x_gui.x_rcv->s_name, "empty"))
1034 x->x_gui.x_fsf.x_rcv_able = 0;
1035 if(x->x_gui.x_fsf.x_font_style == 1) strcpy(x->x_gui.x_font, "helvetica");
1036 else if(x->x_gui.x_fsf.x_font_style == 2) strcpy(x->x_gui.x_font, "times");
1037 else { x->x_gui.x_fsf.x_font_style = 0;
1038 strcpy(x->x_gui.x_font, "courier"); }
1039
1040 if (x->x_gui.x_fsf.x_rcv_able)
1041 pd_bind(&x->x_gui.x_obj.ob_pd, x->x_gui.x_rcv);
1042 x->x_gui.x_ldx = ldx;
1043 x->x_gui.x_ldy = ldy;
1044
1045 if(fs < 4)
1046 fs = 4;
1047 x->x_gui.x_fontsize = fs;
1048 x->x_gui.x_w = iemgui_clip_size(a);
1049 x->x_gui.x_h = x->x_gui.x_w;
1050 bng_check_minmax(x, ftbreak, fthold);
1051 iemgui_all_colfromload(&x->x_gui, bflcol);
1052 x->x_gui.x_isa.x_locked = 0;
1053 iemgui_verify_snd_ne_rcv(&x->x_gui);
1054 x->x_clock_hld = clock_new(x, (t_method)bng_tick_hld);
1055 x->x_clock_brk = clock_new(x, (t_method)bng_tick_brk);
1056 x->x_clock_lck = clock_new(x, (t_method)bng_tick_lck);
1057 outlet_new(&x->x_gui.x_obj, &s_bang);
1058 return (x);
1059}
1060
1061static void bng_ff(t_bng *x)
1062{
1063 if(x->x_gui.x_fsf.x_rcv_able)
1064 pd_unbind(&x->x_gui.x_obj.ob_pd, x->x_gui.x_rcv);
1065 clock_free(x->x_clock_lck);
1066 clock_free(x->x_clock_brk);
1067 clock_free(x->x_clock_hld);
1068 gfxstub_deleteforkey(x);
1069}
1070
1071void g_bang_setup(void)
1072{
1073 bng_class = class_new(gensym("bng"), (t_newmethod)bng_new,
1074 (t_method)bng_ff, sizeof(t_bng), 0, A_GIMME, 0);
1075 class_addbang(bng_class, bng_bang);
1076 class_addfloat(bng_class, bng_float);
1077 class_addsymbol(bng_class, bng_symbol);
1078 class_addpointer(bng_class, bng_pointer);
1079 class_addlist(bng_class, bng_list);
1080 class_addanything(bng_class, bng_anything);
1081 class_addmethod(bng_class, (t_method)bng_click, gensym("click"),
1082 A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, 0);
1083 class_addmethod(bng_class, (t_method)bng_dialog, gensym("dialog"),
1084 A_GIMME, 0);
1085 class_addmethod(bng_class, (t_method)bng_loadbang, gensym("loadbang"), 0);
1086 class_addmethod(bng_class, (t_method)bng_size, gensym("size"), A_GIMME, 0);
1087 class_addmethod(bng_class, (t_method)bng_delta, gensym("delta"), A_GIMME, 0);
1088 class_addmethod(bng_class, (t_method)bng_pos, gensym("pos"), A_GIMME, 0);
1089 class_addmethod(bng_class, (t_method)bng_flashtime, gensym("flashtime"), A_GIMME, 0);
1090 class_addmethod(bng_class, (t_method)bng_color, gensym("color"), A_GIMME, 0);
1091 class_addmethod(bng_class, (t_method)bng_send, gensym("send"), A_DEFSYM, 0);
1092 class_addmethod(bng_class, (t_method)bng_receive, gensym("receive"), A_DEFSYM, 0);
1093 class_addmethod(bng_class, (t_method)bng_label, gensym("label"), A_DEFSYM, 0);
1094 class_addmethod(bng_class, (t_method)bng_label_pos, gensym("label_pos"), A_GIMME, 0);
1095 class_addmethod(bng_class, (t_method)bng_label_font, gensym("label_font"), A_GIMME, 0);
1096 class_addmethod(bng_class, (t_method)bng_init, gensym("init"), A_FLOAT, 0);
1097 bng_widgetbehavior.w_getrectfn = bng_getrect;
1098 bng_widgetbehavior.w_displacefn = iemgui_displace;
1099 bng_widgetbehavior.w_selectfn = iemgui_select;
1100 bng_widgetbehavior.w_activatefn = NULL;
1101 bng_widgetbehavior.w_deletefn = iemgui_delete;
1102 bng_widgetbehavior.w_visfn = iemgui_vis;
1103 bng_widgetbehavior.w_clickfn = bng_newclick;
1104 class_setwidget(bng_class, &bng_widgetbehavior);
1105 class_sethelpsymbol(bng_class, gensym("bng"));
1106 class_setsavefn(bng_class, bng_save);
1107 class_setpropertiesfn(bng_class, bng_properties);
1108}