g_toggle.c 15.8 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
static t_class *scalehandle_class;
17
18
19
20
extern int gfxstub_haveproperties(void *key);
void toggle_draw_select(t_toggle* x, t_glist* glist);
 

Miller Puckette's avatar
Miller Puckette committed
21
22
23
/* --------------- tgl     gui-toggle ------------------------- */

t_widgetbehavior toggle_widgetbehavior;
24
static t_class *toggle_class;
Miller Puckette's avatar
Miller Puckette committed
25
26
27

/* widget helper functions */

28
void toggle_draw_update(t_gobj *xgobj, t_glist *glist)
Miller Puckette's avatar
Miller Puckette committed
29
{
30
31
32
33
34
35
36
37
38
39
40
41
42
43
    t_toggle *x = (t_toggle *)xgobj;
    if (x->x_gui.x_changed)
    {
        if(glist_isvisible(glist))
        {
            t_canvas *canvas=glist_getcanvas(glist);

            sys_vgui(".x%lx.c itemconfigure %lxX1 -stroke #%6.6x\n", canvas, x,
                     (x->x_on!=0.0)?x->x_gui.x_fcol:x->x_gui.x_bcol);
            sys_vgui(".x%lx.c itemconfigure %lxX2 -stroke #%6.6x\n", canvas, x,
                     (x->x_on!=0.0)?x->x_gui.x_fcol:x->x_gui.x_bcol);
        }
        x->x_gui.x_changed = 0;
    }
Miller Puckette's avatar
Miller Puckette committed
44
45
}

46
47
48
void toggle_draw_io(t_toggle* x, t_glist* glist, int old_snd_rcv_flags)
{
    t_canvas *canvas=glist_getcanvas(glist);
49
    iemgui_io_draw(&x->x_gui,canvas,old_snd_rcv_flags);
50
51
}

Miller Puckette's avatar
Miller Puckette committed
52
53
54
void toggle_draw_new(t_toggle *x, t_glist *glist)
{
    t_canvas *canvas=glist_getcanvas(glist);
55
56
57
58
59
    int w=(x->x_gui.x_w+29)/30;
    int x1=text_xpix(&x->x_gui.x_obj, glist);
    int y1=text_ypix(&x->x_gui.x_obj, glist);
    int x2=x1+x->x_gui.x_w, y2=y1+x->x_gui.x_h;
    int col = (x->x_on!=0.0)?x->x_gui.x_fcol:x->x_gui.x_bcol;
60
61
    scalehandle_draw_new(x->x_gui. x_handle,canvas);
    scalehandle_draw_new(x->x_gui.x_lhandle,canvas);
62

63
64
65
66
67
68
69
70
71
    char *nlet_tag = iem_get_tag(glist, (t_iemgui *)x);
    iemgui_base_draw_new(&x->x_gui, canvas, nlet_tag);
    sys_vgui(".x%lx.c create polyline %d %d %d %d -strokewidth %d "
        "-stroke #%6.6x -tags {%lxX1 %lxOBJ %s text iemgui}\n",
        canvas, x1+w+1, y1+w+1, x2-w-1, y2-w-1, w, col, x, x, nlet_tag);
    sys_vgui(".x%lx.c create polyline %d %d %d %d -strokewidth %d "
        "-stroke #%6.6x -tags {%lxX2 %lxOBJ %s text iemgui}\n",
        canvas, x1+w+1, y2-w-1, x2-w-1, y1+w+1, w, col, x, x, nlet_tag);
    iemgui_label_draw_new(&x->x_gui,canvas,x1,y1,nlet_tag);
72
    toggle_draw_io(x,glist,7);
Miller Puckette's avatar
Miller Puckette committed
73
74
75
76
77
}

void toggle_draw_move(t_toggle *x, t_glist *glist)
{
    t_canvas *canvas=glist_getcanvas(glist);
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
    if (!glist_isvisible(canvas)) return;
    int w=(x->x_gui.x_w+29)/30, s=w+1;
    int x1=text_xpix(&x->x_gui.x_obj, glist), x2=x1+x->x_gui.x_w;
    int y1=text_ypix(&x->x_gui.x_obj, glist), y2=y1+x->x_gui.x_h;

    char *nlet_tag = iem_get_tag(glist, (t_iemgui *)x);
    iemgui_base_draw_move(&x->x_gui, canvas, nlet_tag);
    sys_vgui(".x%lx.c itemconfigure {%lxX1||%lxX2} -strokewidth %d\n", canvas, x, x, w);
    sys_vgui(".x%lx.c coords %lxX1 %d %d %d %d\n",
        canvas, x, x1+s, y1+s, x2-s, y2-s);
    sys_vgui(".x%lx.c coords %lxX2 %d %d %d %d\n",
        canvas, x, x1+s, y2-s, x2-s, y1+s);
    iemgui_label_draw_move(&x->x_gui,canvas,x1,y1);
    iemgui_io_draw_move(&x->x_gui,canvas,nlet_tag);
    if (x->x_gui.x_selected) toggle_draw_select(x, x->x_gui.x_glist);
Miller Puckette's avatar
Miller Puckette committed
93
94
95
96
97
}

void toggle_draw_config(t_toggle* x, t_glist* glist)
{
    t_canvas *canvas=glist_getcanvas(glist);
98
    iemgui_label_draw_config(&x->x_gui,canvas);
99
100
101
    iemgui_base_draw_config(&x->x_gui,canvas);
    sys_vgui(".x%lx.c itemconfigure {%lxX1||%lX2} -fill #%6.6x\n",
        canvas, x, x, x->x_on?x->x_gui.x_fcol:x->x_gui.x_bcol);
Miller Puckette's avatar
Miller Puckette committed
102
103
104
105
106
}

void toggle_draw_select(t_toggle* x, t_glist* glist)
{
    t_canvas *canvas=glist_getcanvas(glist);
107
    iemgui_base_draw_config(&x->x_gui,canvas);
108
    if(x->x_gui.x_selected)
109
110
    {
        if (x->x_gui.x_glist == glist_getcanvas(glist))
111
        {
112
            scalehandle_draw_select2(&x->x_gui,glist,
113
                x->x_gui.x_w-1,x->x_gui.x_h-1);
114
        }
115
116
117
118
119
120
    }
    else
    {
        scalehandle_draw_erase2(&x->x_gui,glist);
    }
    iemgui_label_draw_select(&x->x_gui,canvas);
121
    iemgui_tag_selected(&x->x_gui,canvas);
122
123
}

124
125
static void toggle__clickhook(t_scalehandle *sh, t_floatarg f,
    t_floatarg xxx, t_floatarg yyy)
126
{
127
    t_toggle *x = (t_toggle *)(sh->h_master);
128
    int newstate = (int)f;
129
    if (sh->h_dragon && newstate == 0 && sh->h_scale)
Miller Puckette's avatar
Miller Puckette committed
130
    {
131
132
133
        canvas_apply_setundo(x->x_gui.x_glist, (t_gobj *)x);
        if (sh->h_dragx || sh->h_dragy)
        {
134
135
            x->x_gui.x_w += sh->h_dragx;
            x->x_gui.x_h += sh->h_dragy;
136
137
138
139
140
            canvas_dirty(x->x_gui.x_glist, 1);
        }
        if (glist_isvisible(x->x_gui.x_glist))
        {
            toggle_draw_move(x, x->x_gui.x_glist);
141
            scalehandle_unclick_scale(sh);
142
        }
Miller Puckette's avatar
Miller Puckette committed
143
    }
144
    iemgui__clickhook3(sh,newstate);
Miller Puckette's avatar
Miller Puckette committed
145
146
}

147
static void toggle__motionhook(t_scalehandle *sh, t_floatarg f1, t_floatarg f2)
148
{
149
    if (sh->h_dragon && sh->h_scale)
150
    {
151
        t_toggle *x = (t_toggle *)(sh->h_master);
152
153
154
155
156
        int d = maxi((int)f1,(int)f2);
        d = maxi(d,IEM_GUI_MINSIZE-x->x_gui.x_w);
        sh->h_dragx = d;
        sh->h_dragy = d;
        scalehandle_drag_scale(sh);
157
158
159
160

        int properties = gfxstub_haveproperties((void *)x);
        if (properties)
        {
161
            int new_w = x->x_gui.x_w + sh->h_dragx;
162
            properties_set_field_int(properties,"dim.w_ent",new_w);
163
        }
164
    }
165
    scalehandle_dragon_label(sh,f1,f2);
166
167
168
}


Miller Puckette's avatar
Miller Puckette committed
169
170
171
void toggle_draw(t_toggle *x, t_glist *glist, int mode)
{
    if(mode == IEM_GUI_DRAW_MODE_UPDATE)
172
        sys_queuegui((t_gobj*)x, x->x_gui.x_glist, toggle_draw_update);
173
        //toggle_draw_update(x, glist);
Miller Puckette's avatar
Miller Puckette committed
174
175
    else if(mode == IEM_GUI_DRAW_MODE_MOVE)
        toggle_draw_move(x, glist);
176
177
    else if(mode == IEM_GUI_DRAW_MODE_NEW)
    {
Miller Puckette's avatar
Miller Puckette committed
178
        toggle_draw_new(x, glist);
179
180
        sys_vgui(".x%lx.c raise all_cords\n", glist_getcanvas(glist));
    }
Miller Puckette's avatar
Miller Puckette committed
181
182
183
    else if(mode == IEM_GUI_DRAW_MODE_SELECT)
        toggle_draw_select(x, glist);
    else if(mode == IEM_GUI_DRAW_MODE_ERASE)
184
        iemgui_draw_erase(&x->x_gui, glist);
Miller Puckette's avatar
Miller Puckette committed
185
186
187
188
189
190
191
192
    else if(mode == IEM_GUI_DRAW_MODE_CONFIG)
        toggle_draw_config(x, glist);
    else if(mode >= IEM_GUI_DRAW_MODE_IO)
        toggle_draw_io(x, glist, mode - IEM_GUI_DRAW_MODE_IO);
}

/* ------------------------ tgl widgetbehaviour----------------------------- */

193
194
static void toggle_getrect(t_gobj *z, t_glist *glist,
    int *xp1, int *yp1, int *xp2, int *yp2)
Miller Puckette's avatar
Miller Puckette committed
195
196
197
198
199
200
201
{
    t_toggle *x = (t_toggle *)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;
202

203
    iemgui_label_getrect(x->x_gui, glist, xp1, yp1, xp2, yp2);
Miller Puckette's avatar
Miller Puckette committed
204
205
206
207
208
209
210
211
212
213
214
215
216
}

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

    iemgui_save(&x->x_gui, srl, bflcol);
    binbuf_addv(b, "ssiisiisssiiiiiiiff", gensym("#X"),gensym("obj"),
                (int)x->x_gui.x_obj.te_xpix,
                (int)x->x_gui.x_obj.te_ypix,
                gensym("tgl"), x->x_gui.x_w,
217
                iem_symargstoint(&x->x_gui),
Miller Puckette's avatar
Miller Puckette committed
218
219
                srl[0], srl[1], srl[2],
                x->x_gui.x_ldx, x->x_gui.x_ldy,
220
                iem_fstyletoint(&x->x_gui), x->x_gui.x_fontsize,
Miller Puckette's avatar
Miller Puckette committed
221
222
223
224
225
226
227
228
229
230
231
                bflcol[0], bflcol[1], bflcol[2], x->x_on, x->x_nonzero);
    binbuf_addv(b, ";");
}

static void toggle_properties(t_gobj *z, t_glist *owner)
{
    t_toggle *x = (t_toggle *)z;
    char buf[800];
    t_symbol *srl[3];

    iemgui_properties(&x->x_gui, srl);
Miller Puckette's avatar
Miller Puckette committed
232
    sprintf(buf, "pdtk_iemgui_dialog %%s |tgl| \
Miller Puckette's avatar
Miller Puckette committed
233
234
235
            ----------dimensions(pix):----------- %d %d size: 0 0 empty \
            -----------non-zero-value:----------- %g value: 0.0 empty %g \
            -1 lin log %d %d empty %d \
Ivica Ico Bukvic's avatar
Ivica Ico Bukvic committed
236
237
            {%s} {%s} \
            {%s} %d %d \
Miller Puckette's avatar
Miller Puckette committed
238
239
240
241
            %d %d \
            %d %d %d\n",
            x->x_gui.x_w, IEM_GUI_MINSIZE,
            x->x_nonzero, 1.0,/*non_zero-schedule*/
242
            x->x_gui.x_loadinit, -1, -1,/*no multi*/
Miller Puckette's avatar
Miller Puckette committed
243
244
            srl[0]->s_name, srl[1]->s_name,
            srl[2]->s_name, x->x_gui.x_ldx, x->x_gui.x_ldy,
245
            x->x_gui.x_font_style, x->x_gui.x_fontsize,
Miller Puckette's avatar
Miller Puckette committed
246
247
248
249
250
251
            0xffffff & x->x_gui.x_bcol, 0xffffff & x->x_gui.x_fcol, 0xffffff & x->x_gui.x_lcol);
    gfxstub_new(&x->x_gui.x_obj.ob_pd, x, buf);
}

static void toggle_bang(t_toggle *x)
{
252
    x->x_gui.x_changed = 1;
Miller Puckette's avatar
Miller Puckette committed
253
254
255
    x->x_on = (x->x_on==0.0)?x->x_nonzero:0.0;
    (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
    outlet_float(x->x_gui.x_obj.ob_outlet, x->x_on);
256
    if(iemgui_has_snd(&x->x_gui) && x->x_gui.x_snd->s_thing)
Miller Puckette's avatar
Miller Puckette committed
257
258
259
260
261
        pd_float(x->x_gui.x_snd->s_thing, x->x_on);
}

static void toggle_dialog(t_toggle *x, t_symbol *s, int argc, t_atom *argv)
{
262
    canvas_apply_setundo(x->x_gui.x_glist, (t_gobj *)x);
263

Miller Puckette's avatar
Miller Puckette committed
264
265
    t_symbol *srl[3];
    int a = (int)atom_getintarg(0, argc, argv);
266
    t_float nonzero = (t_float)atom_getfloatarg(2, argc, argv);
Miller Puckette's avatar
Miller Puckette committed
267
268
269
270
271
272
273
274
275
276
277
278
    int sr_flags;

    if(nonzero == 0.0)
        nonzero = 1.0;
    x->x_nonzero = nonzero;
    if(x->x_on != 0.0)
        x->x_on = x->x_nonzero;
    sr_flags = iemgui_dialog(&x->x_gui, srl, argc, argv);
    x->x_gui.x_w = iemgui_clip_size(a);
    x->x_gui.x_h = x->x_gui.x_w;
    (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_CONFIG);
    (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_IO + sr_flags);
279
280
    //(*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_MOVE);
    //canvas_fixlinesfor(glist_getcanvas(x->x_gui.x_glist), (t_text*)x);
281
    iemgui_shouldvis(&x->x_gui, IEM_GUI_DRAW_MODE_MOVE);
282

283
284
    if (x->x_gui.x_selected) toggle_draw_select(x, x->x_gui.x_glist);
    scrollbar_update(x->x_gui.x_glist);
Miller Puckette's avatar
Miller Puckette committed
285
286
}

287
288
static void toggle_click(t_toggle *x, t_floatarg xpos, t_floatarg ypos,
    t_floatarg shift, t_floatarg ctrl, t_floatarg alt)
Miller Puckette's avatar
Miller Puckette committed
289
290
{toggle_bang(x);}

291
292
static int toggle_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
293
294
{
    if(doit)
295
296
        toggle_click((t_toggle *)z, (t_floatarg)xpix, (t_floatarg)ypix,
            (t_floatarg)shift, 0, (t_floatarg)alt);
Miller Puckette's avatar
Miller Puckette committed
297
298
299
300
301
    return (1);
}

static void toggle_set(t_toggle *x, t_floatarg f)
{
302
    if (x->x_on != f) x->x_gui.x_changed = 1;
Miller Puckette's avatar
Miller Puckette committed
303
304
305
306
307
308
309
310
311
    x->x_on = f;
    if(f != 0.0)
        x->x_nonzero = f;
    (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
}

static void toggle_float(t_toggle *x, t_floatarg f)
{
    toggle_set(x, f);
312
    if(x->x_gui.x_put_in2out)
Miller Puckette's avatar
Miller Puckette committed
313
314
    {
        outlet_float(x->x_gui.x_obj.ob_outlet, x->x_on);
315
        if(iemgui_has_snd(&x->x_gui) && x->x_gui.x_snd->s_thing)
Miller Puckette's avatar
Miller Puckette committed
316
317
318
319
320
321
322
323
            pd_float(x->x_gui.x_snd->s_thing, x->x_on);
    }
}

static void toggle_fout(t_toggle *x, t_floatarg f)
{
    toggle_set(x, f);
    outlet_float(x->x_gui.x_obj.ob_outlet, x->x_on);
324
    if(iemgui_has_snd(&x->x_gui) && x->x_gui.x_snd->s_thing)
Miller Puckette's avatar
Miller Puckette committed
325
326
327
328
329
        pd_float(x->x_gui.x_snd->s_thing, x->x_on);
}

static void toggle_loadbang(t_toggle *x)
{
330
    if(!sys_noloadbang && x->x_gui.x_loadinit)
331
        toggle_fout(x, (t_float)x->x_on);
Miller Puckette's avatar
Miller Puckette committed
332
333
334
335
336
337
}

static void toggle_size(t_toggle *x, t_symbol *s, int ac, t_atom *av)
{
    x->x_gui.x_w = iemgui_clip_size((int)atom_getintarg(0, ac, av));
    x->x_gui.x_h = x->x_gui.x_w;
338
    iemgui_size(&x->x_gui);
Miller Puckette's avatar
Miller Puckette committed
339
340
341
342
}

static void toggle_init(t_toggle *x, t_floatarg f)
{
343
    x->x_gui.x_loadinit = (f==0.0)?0:1;
Miller Puckette's avatar
Miller Puckette committed
344
345
346
347
348
349
350
351
352
353
354
355
}

static void toggle_nonzero(t_toggle *x, t_floatarg f)
{
    if(f != 0.0)
        x->x_nonzero = f;
}

static void *toggle_new(t_symbol *s, int argc, t_atom *argv)
{
    t_toggle *x = (t_toggle *)pd_new(toggle_class);
    int bflcol[]={-262144, -1, -1};
Mathieu L Bouchard's avatar
Mathieu L Bouchard committed
356
    int a=IEM_GUI_DEFAULTSIZE;
Miller Puckette's avatar
Miller Puckette committed
357
358
    int ldx=17, ldy=7;
    int fs=10;
359
    t_float on=0.0, nonzero=1.0;
Miller Puckette's avatar
Miller Puckette committed
360

361
362
    iem_inttosymargs(&x->x_gui, 0);
    iem_inttofstyle(&x->x_gui, 0);
Miller Puckette's avatar
Miller Puckette committed
363
364
365
366
367
368
369
370
371
372
373

    if(((argc == 13)||(argc == 14))&&IS_A_FLOAT(argv,0)
       &&IS_A_FLOAT(argv,1)
       &&(IS_A_SYMBOL(argv,2)||IS_A_FLOAT(argv,2))
       &&(IS_A_SYMBOL(argv,3)||IS_A_FLOAT(argv,3))
       &&(IS_A_SYMBOL(argv,4)||IS_A_FLOAT(argv,4))
       &&IS_A_FLOAT(argv,5)&&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))
    {
        a = (int)atom_getintarg(0, argc, argv);
374
        iem_inttosymargs(&x->x_gui, atom_getintarg(1, argc, argv));
Miller Puckette's avatar
Miller Puckette committed
375
376
377
        iemgui_new_getnames(&x->x_gui, 2, argv);
        ldx = (int)atom_getintarg(5, argc, argv);
        ldy = (int)atom_getintarg(6, argc, argv);
378
        iem_inttofstyle(&x->x_gui, atom_getintarg(7, argc, argv));
Miller Puckette's avatar
Miller Puckette committed
379
380
381
382
        fs = (int)atom_getintarg(8, argc, argv);
        bflcol[0] = (int)atom_getintarg(9, argc, argv);
        bflcol[1] = (int)atom_getintarg(10, argc, argv);
        bflcol[2] = (int)atom_getintarg(11, argc, argv);
383
        on = (t_float)atom_getfloatarg(12, argc, argv);
Miller Puckette's avatar
Miller Puckette committed
384
385
386
    }
    else iemgui_new_getnames(&x->x_gui, 2, 0);
    if((argc == 14)&&IS_A_FLOAT(argv,13))
387
        nonzero = (t_float)atom_getfloatarg(13, argc, argv);
Miller Puckette's avatar
Miller Puckette committed
388
389
390
    x->x_gui.x_draw = (t_iemfunptr)toggle_draw;

    x->x_gui.x_glist = (t_glist *)canvas_getcurrent();
391
    if (x->x_gui.x_font_style<0 || x->x_gui.x_font_style>2) x->x_gui.x_font_style=0;
Miller Puckette's avatar
Miller Puckette committed
392
    x->x_nonzero = (nonzero!=0.0)?nonzero:1.0;
393
    if(x->x_gui.x_loadinit)
Miller Puckette's avatar
Miller Puckette committed
394
395
396
        x->x_on = (on!=0.0)?nonzero:0.0;
    else
        x->x_on = 0.0;
397
    if (iemgui_has_rcv(&x->x_gui))
Miller Puckette's avatar
Miller Puckette committed
398
399
400
401
402
403
404
405
406
407
408
409
        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;

    if(fs < 4)
        fs = 4;
    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;
    iemgui_all_colfromload(&x->x_gui, bflcol);
    iemgui_verify_snd_ne_rcv(&x->x_gui);
    outlet_new(&x->x_gui.x_obj, &s_float);
410

411
412
    x->x_gui. x_handle = scalehandle_new(scalehandle_class,(t_iemgui *)x,1);
    x->x_gui.x_lhandle = scalehandle_new(scalehandle_class,(t_iemgui *)x,0);
413
414
    x->x_gui.x_obj.te_iemgui = 1;
    x->x_gui.x_changed = 1;
415

Miller Puckette's avatar
Miller Puckette committed
416
417
418
419
420
    return (x);
}

static void toggle_ff(t_toggle *x)
{
421
    if(iemgui_has_rcv(&x->x_gui))
Miller Puckette's avatar
Miller Puckette committed
422
423
        pd_unbind(&x->x_gui.x_obj.ob_pd, x->x_gui.x_rcv);
    gfxstub_deleteforkey(x);
424

425
426
    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
427
428
429
430
431
432
433
434
435
436
437
438
439
}

void g_toggle_setup(void)
{
    toggle_class = class_new(gensym("tgl"), (t_newmethod)toggle_new,
                             (t_method)toggle_ff, sizeof(t_toggle), 0, A_GIMME, 0);
    class_addcreator((t_newmethod)toggle_new, gensym("toggle"), A_GIMME, 0);
    class_addbang(toggle_class, toggle_bang);
    class_addfloat(toggle_class, toggle_float);
    class_addmethod(toggle_class, (t_method)toggle_click, gensym("click"),
                    A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, 0);
    class_addmethod(toggle_class, (t_method)toggle_dialog, gensym("dialog"),
                    A_GIMME, 0);
440
441
442
443
444
445
    class_addmethod(toggle_class, (t_method)toggle_loadbang, gensym("loadbang"),
        0);
    class_addmethod(toggle_class, (t_method)toggle_set, gensym("set"),
        A_FLOAT, 0);
    class_addmethod(toggle_class, (t_method)toggle_size, gensym("size"),
        A_GIMME, 0);
446
    iemgui_class_addmethods(toggle_class);
447
448
449
450
    class_addmethod(toggle_class, (t_method)toggle_init, gensym("init"),
        A_FLOAT, 0);
    class_addmethod(toggle_class, (t_method)toggle_nonzero, gensym("nonzero"),
        A_FLOAT, 0);
451
452
 
    scalehandle_class = class_new(gensym("_scalehandle"), 0, 0,
453
                  sizeof(t_scalehandle), CLASS_PD, 0);
454
    class_addmethod(scalehandle_class, (t_method)toggle__clickhook,
455
            gensym("_click"), A_FLOAT, A_FLOAT, A_FLOAT, 0);
456
    class_addmethod(scalehandle_class, (t_method)toggle__motionhook,
457
            gensym("_motion"), A_FLOAT, A_FLOAT, 0);
458

459
    wb_init(&toggle_widgetbehavior,toggle_getrect,toggle_newclick);
Miller Puckette's avatar
Miller Puckette committed
460
461
462
463
464
    class_setwidget(toggle_class, &toggle_widgetbehavior);
    class_sethelpsymbol(toggle_class, gensym("toggle"));
    class_setsavefn(toggle_class, toggle_save);
    class_setpropertiesfn(toggle_class, toggle_properties);
}