g_bang.c 16.3 KB
Newer Older
Miller Puckette's avatar
Miller Puckette committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
/* Copyright (c) 1997-1999 Miller Puckette.
 * For information on usage and redistribution, and for a DISCLAIMER OF ALL
 * WARRANTIES, see the file, "LICENSE.txt," in this distribution. */

/* g_7_guis.c written by Thomas Musil (c) IEM KUG Graz Austria 2000-2001 */
/* thanks to Miller Puckette, Guenther Geiger and Krzystof Czaja */

#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include "m_pd.h"
#include "g_canvas.h"
#include "g_all_guis.h"
#include <math.h>

16
17
18
19
20
#define IEM_BNG_DEFAULTHOLDFLASHTIME 250
#define IEM_BNG_DEFAULTBREAKFLASHTIME 50
#define IEM_BNG_MINHOLDFLASHTIME 50
#define IEM_BNG_MINBREAKFLASHTIME 10

21
extern int gfxstub_haveproperties(void *key);
Miller Puckette's avatar
Miller Puckette committed
22
t_widgetbehavior bng_widgetbehavior;
23
static t_class *bng_class;
Miller Puckette's avatar
Miller Puckette committed
24

25
void bng_draw_update(t_gobj *xgobj, t_glist *glist)
Miller Puckette's avatar
Miller Puckette committed
26
{
27
    t_bng *x = (t_bng *)xgobj;
28
    if (x->x_gui.x_changed != x->x_flashed && glist_isvisible(glist))
29
    {
30
31
32
        gui_vmess("gui_bng_button_color", "xxx",
            glist_getcanvas(glist),
            &x->x_gui,
33
            x->x_flashed ? x->x_gui.x_fcol : x->x_gui.x_bcol);
34
    }
35
    x->x_gui.x_changed = x->x_flashed;
Miller Puckette's avatar
Miller Puckette committed
36
37
38
39
40
}

void bng_draw_new(t_bng *x, t_glist *glist)
{
    t_canvas *canvas=glist_getcanvas(glist);
41
42
    int x1=text_xpix(&x->x_gui.x_obj, glist);
    int y1=text_ypix(&x->x_gui.x_obj, glist);
43
    iemgui_base_draw_new(&x->x_gui);
44
    t_float cr = (x->x_gui.x_w-2)/2.0;
45
46
    t_float cx = x1+cr+1.5;
    t_float cy = y1+cr+1.5;
47
48
49
    /* The circle isn't quite centered in the nw.js port. Let's use the
       old interface to see if there's anything we're doing wrong. Then once
       we get the circle placement right we can remove the old code here... */
50
51
52
53
54
    //sys_vgui(".x%lx.c create circle %f %f -r %f "
    //         "-stroke $pd_colors(iemgui_border) -fill #%6.6x "
    //         "-tags {%lxBUT x%lx text iemgui border}\n",
    //     canvas, cx, cy, cr, x->x_flashed?x->x_gui.x_fcol:x->x_gui.x_bcol,
    //     x, x);
55
    gui_vmess("gui_bng_new", "xxfff",
56
57
58
59
60
        canvas,
        &x->x_gui,
        cx - x1,
        cy - y1,
        cr);
Miller Puckette's avatar
Miller Puckette committed
61
62
63
64
}

void bng_draw_move(t_bng *x, t_glist *glist)
{
65
66
    t_canvas *canvas=glist_getcanvas(glist);
    if (!glist_isvisible(canvas)) return;
67
68
    int x1=text_xpix(&x->x_gui.x_obj, glist);
    int y1=text_ypix(&x->x_gui.x_obj, glist);
69

70
    iemgui_base_draw_move(&x->x_gui);
71
    t_float cr = (x->x_gui.x_w-2)/2.0;
72
73
    t_float cx = x1+cr+1.5;
    t_float cy = y1+cr+1.5;
74
75
76
77
78
79
80
    gui_vmess("gui_bng_configure", "xxxfff",
        canvas,
        x,
        x->x_flashed ? x->x_gui.x_fcol : x->x_gui.x_bcol,
        cx - x1,
        cy - y1,
        cr);
Miller Puckette's avatar
Miller Puckette committed
81
82
83
84
85
}

void bng_draw_config(t_bng* x, t_glist* glist)
{
    t_canvas *canvas=glist_getcanvas(glist);
86
    iemgui_base_draw_config(&x->x_gui);
87
88
89
90
    gui_vmess("gui_bng_button_color", "xxx",
        canvas,
        x,
        x->x_flashed ? x->x_gui.x_fcol : x->x_gui.x_bcol);
Miller Puckette's avatar
Miller Puckette committed
91
92
}

93
/* we may no longer need h_dragon... */
94
95
96
static void bng__clickhook(t_scalehandle *sh, int newstate)
{
    t_bng *x = (t_bng *)(sh->h_master);
97
    if (newstate)
98
99
    {
        canvas_apply_setundo(x->x_gui.x_glist, (t_gobj *)x);
100
101
        if (!sh->h_scale) /* click on a label handle */
            scalehandle_click_label(sh);
102
    }
103
104
105
    /* We no longer need this "clickhook", as we can handle the dragging
       either in the GUI (for the label handle) or or in canvas_doclick */
    //iemgui__clickhook3(sh,newstate);
106
    sh->h_dragon = newstate;
107
108
}

109
static void bng__motionhook(t_scalehandle *sh,
110
                    t_floatarg mouse_x, t_floatarg mouse_y)
111
{
112
    if (sh->h_scale)
Miller Puckette's avatar
Miller Puckette committed
113
    {
114
        t_bng *x = (t_bng *)(sh->h_master);
115
116
        int width = x->x_gui.x_w,
            height = x->x_gui.x_h;
117
        int x1, y1, x2, y2, d;
118
119
120
121
122
        x1 = text_xpix(&x->x_gui.x_obj, x->x_gui.x_glist);
        y1 = text_ypix(&x->x_gui.x_obj, x->x_gui.x_glist);
        x2 = x1 + width;
        y2 = y1 + height;

123
124
        /* This is convoluted, but I can't think of another
           way to get this behavior... */
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
        if (mouse_x <= x2)
        {
            if (mouse_y > y2)
                d = mouse_y - y2;
            else if (abs(mouse_y - y2) < abs(mouse_x - x2))
                d = mouse_y - y2;
            else
                d = mouse_x - x2;
        }
        else
        {
            if (mouse_y <= y2)
                d = mouse_x - x2;
            else
                d = maxi(mouse_y - y2, mouse_x - x2);
        }
141
142
143
        sh->h_dragx = d;
        sh->h_dragy = d;
        scalehandle_drag_scale(sh);
144

145
146
147
148
149
150
151
152
153
154
155
156
        width = maxi(width + d, IEM_GUI_MINSIZE);
        height = width;

        x->x_gui.x_w = width;
        x->x_gui.x_h = height;

        if (glist_isvisible(x->x_gui.x_glist))
        {
            bng_draw_move(x, x->x_gui.x_glist);
            scalehandle_unclick_scale(sh);
        }

157
158
159
        int properties = gfxstub_haveproperties((void *)x);
        if (properties)
        {
160
            int new_w = x->x_gui.x_w + sh->h_dragx;
161
            properties_set_field_int(properties,"size",new_w);
162
        }
163
    }
164
    scalehandle_dragon_label(sh,mouse_x, mouse_y);
Miller Puckette's avatar
Miller Puckette committed
165
166
167
168
}

void bng_draw(t_bng *x, t_glist *glist, int mode)
{
169
170
171
172
    if(mode == IEM_GUI_DRAW_MODE_UPDATE)      sys_queuegui(x, x->x_gui.x_glist, bng_draw_update);
    else if(mode == IEM_GUI_DRAW_MODE_MOVE)   bng_draw_move(x, glist);
    else if(mode == IEM_GUI_DRAW_MODE_NEW)    bng_draw_new(x, glist);
    else if(mode == IEM_GUI_DRAW_MODE_CONFIG) bng_draw_config(x, glist);
Miller Puckette's avatar
Miller Puckette committed
173
174
175
176
}

/* ------------------------ bng widgetbehaviour----------------------------- */

177
178
static void bng_getrect(t_gobj *z, t_glist *glist, int *xp1, int *yp1,
    int *xp2, int *yp2)
Miller Puckette's avatar
Miller Puckette committed
179
180
181
182
183
184
185
{
    t_bng *x = (t_bng *)z;

    *xp1 = text_xpix(&x->x_gui.x_obj, glist);
    *yp1 = text_ypix(&x->x_gui.x_obj, glist);
    *xp2 = *xp1 + x->x_gui.x_w;
    *yp2 = *yp1 + x->x_gui.x_h;
186

187
    iemgui_label_getrect(x->x_gui, glist, xp1, yp1, xp2, yp2);
Miller Puckette's avatar
Miller Puckette committed
188
189
190
191
192
193
194
195
196
}

static void bng_save(t_gobj *z, t_binbuf *b)
{
    t_bng *x = (t_bng *)z;
    int bflcol[3];
    t_symbol *srl[3];

    iemgui_save(&x->x_gui, srl, bflcol);
197
198
199
200
201
202
203
204
    binbuf_addv(b, "ssiisiiiisssiiiiiii;", gensym("#X"),gensym("obj"),
        (int)x->x_gui.x_obj.te_xpix, (int)x->x_gui.x_obj.te_ypix,
        gensym("bng"), x->x_gui.x_w,
        x->x_flashtime_hold, x->x_flashtime_break,
        iem_symargstoint(&x->x_gui),
        srl[0], srl[1], srl[2], x->x_gui.x_ldx, x->x_gui.x_ldy,
        iem_fstyletoint(&x->x_gui), x->x_gui.x_fontsize,
        bflcol[0], bflcol[1], bflcol[2]);
Miller Puckette's avatar
Miller Puckette committed
205
206
207
208
209
210
}

void bng_check_minmax(t_bng *x, int ftbreak, int fthold)
{
    if(ftbreak > fthold)
    {
211
        int h = ftbreak;
Miller Puckette's avatar
Miller Puckette committed
212
213
214
        ftbreak = fthold;
        fthold = h;
    }
215
216
    x->x_flashtime_break = maxi(ftbreak,IEM_BNG_MINBREAKFLASHTIME);
    x->x_flashtime_hold  = maxi(fthold,  IEM_BNG_MINHOLDFLASHTIME);
Miller Puckette's avatar
Miller Puckette committed
217
218
219
220
221
}

static void bng_properties(t_gobj *z, t_glist *owner)
{
    t_bng *x = (t_bng *)z;
222
    char buf[800], *gfx_tag;
Miller Puckette's avatar
Miller Puckette committed
223
224
225
    t_symbol *srl[3];

    iemgui_properties(&x->x_gui, srl);
Miller Puckette's avatar
Miller Puckette committed
226
    sprintf(buf, "pdtk_iemgui_dialog %%s |bang| \
227
228
229
        ----------dimensions(pix):----------- %d %d size: 0 0 empty \
        --------flash-time(ms)(ms):--------- %d intrrpt: %d hold: %d \
        %d empty empty %d %d empty %d {%s} {%s} {%s} %d %d %d %d %d %d %d\n",
230
231
232
233
234
235
236
237
238
239

        x->x_gui.x_w,
        IEM_GUI_MINSIZE,
        x->x_flashtime_break,
        x->x_flashtime_hold,
        2, /*min_max_schedule+clip*/
        -1,
        x->x_gui.x_loadinit,
        -1,
        -1, /*no linlog, no multi*/
240
241
242
        srl[0]->s_name, srl[1]->s_name, srl[2]->s_name,
        x->x_gui.x_ldx, x->x_gui.x_ldy,
        x->x_gui.x_font_style, x->x_gui.x_fontsize,
243
244
245
246
247
248
249
250
251
252
253
        0xffffff & x->x_gui.x_bcol,
        0xffffff & x->x_gui.x_fcol,
        0xffffff & x->x_gui.x_lcol);

    gfx_tag = gfxstub_new2(&x->x_gui.x_obj.ob_pd, x);
    /* todo: send along the x/y of the object here so we can
       create the window in the right place */

    gui_start_vmess("gui_iemgui_dialog", "s", gfx_tag);
    gui_start_array();

254
255
    gui_s("type");
    gui_s("bng");
256

257
258
    gui_s("size"); 
    gui_i(x->x_gui.x_w);
259

260
261
    gui_s("minimum-size");
    gui_i(IEM_GUI_MINSIZE);
262

263
264
    gui_s("range-schedule"); // no idea what this is...
    gui_i(2);
265

266
267
    gui_s("flash-interrupt");
    gui_i(x->x_flashtime_break);
268

269
270
    gui_s("flash-hold");
    gui_i(x->x_flashtime_hold);
271

272
273
    gui_s("init");
    gui_i(x->x_gui.x_loadinit);
274

275
276
    gui_s("send-symbol");
    gui_s(srl[0]->s_name);
277

278
279
    gui_s("receive-symbol");
    gui_s(srl[1]->s_name);
280

281
282
    gui_s("label");
    gui_s(srl[2]->s_name);
283

284
285
    gui_s("x-offset");
    gui_i(x->x_gui.x_ldx);
286

287
288
    gui_s("y-offset");
    gui_i(x->x_gui.x_ldy);
289

290
291
    gui_s("font-style");
    gui_i(x->x_gui.x_font_style);
292

293
294
    gui_s("font-size");
    gui_i(x->x_gui.x_fontsize);
295

296
297
    gui_s("background-color");
    gui_i(0xffffff & x->x_gui.x_bcol);
298

299
300
    gui_s("foreground-color");
    gui_i(0xffffff & x->x_gui.x_fcol);
301

302
303
    gui_s("label-color");
    gui_i(0xffffff & x->x_gui.x_lcol);
304
305
306

    gui_end_array();
    gui_end_vmess();
Miller Puckette's avatar
Miller Puckette committed
307
308
309
310
311
312
313
}

static void bng_set(t_bng *x)
{
    if(x->x_flashed)
    {
        x->x_flashed = 0;
314
        x->x_gui.x_draw(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
Miller Puckette's avatar
Miller Puckette committed
315
316
317
318
319
320
        clock_delay(x->x_clock_brk, x->x_flashtime_break);
        x->x_flashed = 1;
    }
    else
    {
        x->x_flashed = 1;
321
        x->x_gui.x_draw(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
Miller Puckette's avatar
Miller Puckette committed
322
323
324
325
    }
    clock_delay(x->x_clock_hld, x->x_flashtime_hold);
}

326
327
328
static void bng_bout(t_bng *x, int chk_putin)
/* chk_putin=1: wird nur mehr gesendet, wenn snd != rcv*/
/* chk_putin=0: wird immer gesendet, wenn moeglich */
Miller Puckette's avatar
Miller Puckette committed
329
{
330
    if(!x->x_gui.x_put_in2out)
Miller Puckette's avatar
Miller Puckette committed
331
    {
332
        x->x_gui.x_locked = 1;
Miller Puckette's avatar
Miller Puckette committed
333
334
        clock_delay(x->x_clock_lck, 2);
    }
335
    iemgui_out_bang(&x->x_gui,0,chk_putin);
Miller Puckette's avatar
Miller Puckette committed
336
337
338
}
static void bng_bang(t_bng *x)/*wird nur mehr gesendet, wenn snd != rcv*/
{
339
    if(!x->x_gui.x_locked) {bng_set(x); bng_bout(x,1);}
Miller Puckette's avatar
Miller Puckette committed
340
341
342
343
}

static void bng_bang2(t_bng *x)/*wird immer gesendet, wenn moeglich*/
{
344
    if(!x->x_gui.x_locked) {bng_set(x); bng_bout(x,0);}
Miller Puckette's avatar
Miller Puckette committed
345
346
347
348
}

static void bng_dialog(t_bng *x, t_symbol *s, int argc, t_atom *argv)
{
349
350
    if (atom_getintarg(19, argc, argv))
        canvas_apply_setundo(x->x_gui.x_glist, (t_gobj *)x);
351
352
353
    x->x_gui.x_h = x->x_gui.x_w = atom_getintarg(0, argc, argv);
    int fthold = atom_getintarg(2, argc, argv);
    int ftbreak = atom_getintarg(3, argc, argv);
354
    int sr_flags = iemgui_dialog(&x->x_gui, argc, argv);
Miller Puckette's avatar
Miller Puckette committed
355
    bng_check_minmax(x, ftbreak, fthold);
356
357
    iemgui_draw_config(&x->x_gui);
    iemgui_draw_io(&x->x_gui, sr_flags);
358
    iemgui_shouldvis(&x->x_gui, IEM_GUI_DRAW_MODE_MOVE);
359
    scalehandle_draw(&x->x_gui);
360
    scrollbar_update(x->x_gui.x_glist);
Miller Puckette's avatar
Miller Puckette committed
361
362
}

363
364
static void bng_click(t_bng *x, t_floatarg xpos, t_floatarg ypos,
    t_floatarg shift, t_floatarg ctrl, t_floatarg alt)
Miller Puckette's avatar
Miller Puckette committed
365
366
{
    bng_set(x);
367
    bng_bout(x,0);
Miller Puckette's avatar
Miller Puckette committed
368
369
}

370
371
static int bng_newclick(t_gobj *z, struct _glist *glist, int xpix, int ypix,
    int shift, int alt, int dbl, int doit)
Miller Puckette's avatar
Miller Puckette committed
372
373
{
    if(doit)
374
375
        bng_click((t_bng *)z, (t_floatarg)xpix, (t_floatarg)ypix,
            (t_floatarg)shift, 0, (t_floatarg)alt);
Miller Puckette's avatar
Miller Puckette committed
376
377
378
    return (1);
}

379
380
381
382
static void bng_float(t_bng *x, t_floatarg f)                  {bng_bang2(x);}
static void bng_symbol(t_bng *x, t_symbol *s)                  {bng_bang2(x);}
static void bng_pointer(t_bng *x, t_gpointer *gp)              {bng_bang2(x);}
static void bng_list(t_bng *x, t_symbol *s, int ac, t_atom *av){bng_bang2(x);}
Miller Puckette's avatar
Miller Puckette committed
383
384
385
386
387
388

static void bng_anything(t_bng *x, t_symbol *s, int argc, t_atom *argv)
{bng_bang2(x);}

static void bng_loadbang(t_bng *x)
{
389
    if(!sys_noloadbang && x->x_gui.x_loadinit)
Miller Puckette's avatar
Miller Puckette committed
390
391
    {
        bng_set(x);
392
        bng_bout(x,0);
Miller Puckette's avatar
Miller Puckette committed
393
394
395
396
397
    }
}

static void bng_size(t_bng *x, t_symbol *s, int ac, t_atom *av)
{
398
    x->x_gui.x_h = x->x_gui.x_w = iemgui_clip_size((int)atom_getintarg(0, ac, av));
399
    iemgui_size(&x->x_gui);
Miller Puckette's avatar
Miller Puckette committed
400
401
402
403
404
405
406
407
408
409
410
}

static void bng_flashtime(t_bng *x, t_symbol *s, int ac, t_atom *av)
{
    bng_check_minmax(x, (int)atom_getintarg(0, ac, av),
                     (int)atom_getintarg(1, ac, av));
}

static void bng_tick_hld(t_bng *x)
{
    x->x_flashed = 0;
411
    x->x_gui.x_draw(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
Miller Puckette's avatar
Miller Puckette committed
412
413
414
415
}

static void bng_tick_brk(t_bng *x)
{
416
    x->x_gui.x_draw(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
Miller Puckette's avatar
Miller Puckette committed
417
418
419
420
}

static void bng_tick_lck(t_bng *x)
{
421
    x->x_gui.x_locked = 0;
Miller Puckette's avatar
Miller Puckette committed
422
423
424
425
426
427
428
429
430
431
432
433
}

static void *bng_new(t_symbol *s, int argc, t_atom *argv)
{
    t_bng *x = (t_bng *)pd_new(bng_class);
    int bflcol[]={-262144, -1, -1};
    int a=IEM_GUI_DEFAULTSIZE;
    int ldx=17, ldy=7;
    int fs=10;
    int ftbreak=IEM_BNG_DEFAULTBREAKFLASHTIME,
        fthold=IEM_BNG_DEFAULTHOLDFLASHTIME;

434
435
    iem_inttosymargs(&x->x_gui, 0);
    iem_inttofstyle(&x->x_gui, 0);
Miller Puckette's avatar
Miller Puckette committed
436
437
438
439
440
441
442
443
444
445
446
447

    if((argc == 14)&&IS_A_FLOAT(argv,0)
       &&IS_A_FLOAT(argv,1)&&IS_A_FLOAT(argv,2)
       &&IS_A_FLOAT(argv,3)
       &&(IS_A_SYMBOL(argv,4)||IS_A_FLOAT(argv,4))
       &&(IS_A_SYMBOL(argv,5)||IS_A_FLOAT(argv,5))
       &&(IS_A_SYMBOL(argv,6)||IS_A_FLOAT(argv,6))
       &&IS_A_FLOAT(argv,7)&&IS_A_FLOAT(argv,8)
       &&IS_A_FLOAT(argv,9)&&IS_A_FLOAT(argv,10)&&IS_A_FLOAT(argv,11)
       &&IS_A_FLOAT(argv,12)&&IS_A_FLOAT(argv,13))
    {

448
449
450
        a = atom_getintarg(0, argc, argv);
        fthold = atom_getintarg(1, argc, argv);
        ftbreak = atom_getintarg(2, argc, argv);
451
        iem_inttosymargs(&x->x_gui, atom_getintarg(3, argc, argv));
Miller Puckette's avatar
Miller Puckette committed
452
        iemgui_new_getnames(&x->x_gui, 4, argv);
453
454
        ldx = atom_getintarg(7, argc, argv);
        ldy = atom_getintarg(8, argc, argv);
455
        iem_inttofstyle(&x->x_gui, atom_getintarg(9, argc, argv));
456
457
458
459
        fs = maxi(atom_getintarg(10, argc, argv),4);
        bflcol[0] = atom_getintarg(11, argc, argv);
        bflcol[1] = atom_getintarg(12, argc, argv);
        bflcol[2] = atom_getintarg(13, argc, argv);
Miller Puckette's avatar
Miller Puckette committed
460
461
462
463
464
465
466
    }
    else iemgui_new_getnames(&x->x_gui, 4, 0);

    x->x_gui.x_draw = (t_iemfunptr)bng_draw;

    x->x_flashed = 0;
    x->x_gui.x_glist = (t_glist *)canvas_getcurrent();
467
468
    if (x->x_gui.x_font_style<0 || x->x_gui.x_font_style>2) x->x_gui.x_font_style=0;
    if (iemgui_has_rcv(&x->x_gui))
Miller Puckette's avatar
Miller Puckette committed
469
470
471
472
473
474
475
476
        pd_bind(&x->x_gui.x_obj.ob_pd, x->x_gui.x_rcv);
    x->x_gui.x_ldx = ldx;
    x->x_gui.x_ldy = ldy;
    x->x_gui.x_fontsize = fs;
    x->x_gui.x_w = iemgui_clip_size(a);
    x->x_gui.x_h = x->x_gui.x_w;
    bng_check_minmax(x, ftbreak, fthold);
    iemgui_all_colfromload(&x->x_gui, bflcol);
477
    x->x_gui.x_locked = 0;
Miller Puckette's avatar
Miller Puckette committed
478
479
480
481
482
    iemgui_verify_snd_ne_rcv(&x->x_gui);
    x->x_clock_hld = clock_new(x, (t_method)bng_tick_hld);
    x->x_clock_brk = clock_new(x, (t_method)bng_tick_brk);
    x->x_clock_lck = clock_new(x, (t_method)bng_tick_lck);
    outlet_new(&x->x_gui.x_obj, &s_bang);
483

484
    x->x_gui.x_handle = scalehandle_new((t_object *)x,x->x_gui.x_glist,1,bng__clickhook,bng__motionhook);
485
    x->x_gui.x_lhandle = scalehandle_new((t_object *)x,x->x_gui.x_glist,0,bng__clickhook,bng__motionhook);
486
    x->x_gui.x_obj.te_iemgui = 1;
487
    x->x_gui.x_changed = -1;
488

489
    x->x_gui.legacy_x = 0;
490
    x->x_gui.legacy_y = 1;
491
492
493
494

    //x->x_gui.click_x = 1;
    //x->x_gui.click_y = 2;

Miller Puckette's avatar
Miller Puckette committed
495
496
497
498
499
    return (x);
}

static void bng_ff(t_bng *x)
{
500
    if(iemgui_has_rcv(&x->x_gui))
Miller Puckette's avatar
Miller Puckette committed
501
502
503
504
505
        pd_unbind(&x->x_gui.x_obj.ob_pd, x->x_gui.x_rcv);
    clock_free(x->x_clock_lck);
    clock_free(x->x_clock_brk);
    clock_free(x->x_clock_hld);
    gfxstub_deleteforkey(x);
506

507
508
    if (x->x_gui. x_handle) scalehandle_free(x->x_gui. x_handle);
    if (x->x_gui.x_lhandle) scalehandle_free(x->x_gui.x_lhandle);
Miller Puckette's avatar
Miller Puckette committed
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
}

void g_bang_setup(void)
{
    bng_class = class_new(gensym("bng"), (t_newmethod)bng_new,
                          (t_method)bng_ff, sizeof(t_bng), 0, A_GIMME, 0);
    class_addbang(bng_class, bng_bang);
    class_addfloat(bng_class, bng_float);
    class_addsymbol(bng_class, bng_symbol);
    class_addpointer(bng_class, bng_pointer);
    class_addlist(bng_class, bng_list);
    class_addanything(bng_class, bng_anything);
    class_addmethod(bng_class, (t_method)bng_click, gensym("click"),
                    A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, 0);
    class_addmethod(bng_class, (t_method)bng_dialog, gensym("dialog"),
                    A_GIMME, 0);
    class_addmethod(bng_class, (t_method)bng_loadbang, gensym("loadbang"), 0);
    class_addmethod(bng_class, (t_method)bng_size, gensym("size"), A_GIMME, 0);
527
    iemgui_class_addmethods(bng_class);
528
529
    class_addmethod(bng_class, (t_method)bng_flashtime, gensym("flashtime"),
        A_GIMME, 0);
530
    class_addmethod(bng_class, (t_method)iemgui_init, gensym("init"), A_FLOAT, 0);
531
 
532
    wb_init(&bng_widgetbehavior,bng_getrect,bng_newclick);
Miller Puckette's avatar
Miller Puckette committed
533
534
535
536
537
    class_setwidget(bng_class, &bng_widgetbehavior);
    class_sethelpsymbol(bng_class, gensym("bng"));
    class_setsavefn(bng_class, bng_save);
    class_setpropertiesfn(bng_class, bng_properties);
}