g_toggle.c 16.3 KB
Newer Older
Miller Puckette's avatar
Miller Puckette committed
1
2
3
4
5
6
7
/* 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 */

Hans-Christoph Steiner's avatar
Hans-Christoph Steiner committed
8
#include "config.h"
Miller Puckette's avatar
Miller Puckette committed
9
10
11
12
13
14
15
16
17
18
19

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

Hans-Christoph Steiner's avatar
Hans-Christoph Steiner committed
20
#ifdef HAVE_UNISTD_H
Miller Puckette's avatar
Miller Puckette committed
21
22
23
#include <unistd.h>
#endif

Hans-Christoph Steiner's avatar
Hans-Christoph Steiner committed
24
25
26
27
#ifdef HAVE_IO_H
#include <io.h>
#endif

28
29
30
31
extern int gfxstub_haveproperties(void *key);
void toggle_draw_select(t_toggle* x, t_glist* glist);
 

Miller Puckette's avatar
Miller Puckette committed
32
33
34
/* --------------- tgl     gui-toggle ------------------------- */

t_widgetbehavior toggle_widgetbehavior;
35
static t_class *toggle_class;
Miller Puckette's avatar
Miller Puckette committed
36
37
38

/* widget helper functions */

39
void toggle_draw_update(t_gobj *xgobj, t_glist *glist)
Miller Puckette's avatar
Miller Puckette committed
40
{
41
42
43
44
45
46
47
48
49
50
51
52
53
54
    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
55
56
}

57
58
59
void toggle_draw_io(t_toggle* x, t_glist* glist, int old_snd_rcv_flags)
{
    t_canvas *canvas=glist_getcanvas(glist);
60
    iemgui_io_draw(&x->x_gui,canvas,old_snd_rcv_flags);
61
62
}

Miller Puckette's avatar
Miller Puckette committed
63
64
65
void toggle_draw_new(t_toggle *x, t_glist *glist)
{
    t_canvas *canvas=glist_getcanvas(glist);
66
67
68
69
70
    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;
71
72
    scalehandle_draw_new(x->x_gui. x_handle,canvas);
    scalehandle_draw_new(x->x_gui.x_lhandle,canvas);
73

74
75
76
77
78
79
80
81
82
    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);
83
    toggle_draw_io(x,glist,7);
Miller Puckette's avatar
Miller Puckette committed
84
85
86
87
88
}

void toggle_draw_move(t_toggle *x, t_glist *glist)
{
    t_canvas *canvas=glist_getcanvas(glist);
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
    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
104
105
106
107
108
}

void toggle_draw_config(t_toggle* x, t_glist* glist)
{
    t_canvas *canvas=glist_getcanvas(glist);
109
    iemgui_label_draw_config(&x->x_gui,canvas);
110
111
112
    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
113
114
115
116
117
}

void toggle_draw_select(t_toggle* x, t_glist* glist)
{
    t_canvas *canvas=glist_getcanvas(glist);
118
    iemgui_base_draw_config(&x->x_gui,canvas);
119
    if(x->x_gui.x_selected)
120
121
    {
        if (x->x_gui.x_glist == glist_getcanvas(glist))
122
        {
123
            scalehandle_draw_select2(&x->x_gui,glist,
124
                x->x_gui.x_w-1,x->x_gui.x_h-1);
125
        }
126
127
128
129
130
131
    }
    else
    {
        scalehandle_draw_erase2(&x->x_gui,glist);
    }
    iemgui_label_draw_select(&x->x_gui,canvas);
132
    iemgui_tag_selected(&x->x_gui,canvas);
133
134
}

135
136
static void toggle__clickhook(t_scalehandle *sh, t_floatarg f,
    t_floatarg xxx, t_floatarg yyy)
137
{
138
    t_toggle *x = (t_toggle *)(sh->h_master);
139
    int newstate = (int)f;
140
    if (sh->h_dragon && newstate == 0 && sh->h_scale)
Miller Puckette's avatar
Miller Puckette committed
141
    {
142
143
144
        canvas_apply_setundo(x->x_gui.x_glist, (t_gobj *)x);
        if (sh->h_dragx || sh->h_dragy)
        {
145
146
            x->x_gui.x_w += sh->h_dragx;
            x->x_gui.x_h += sh->h_dragy;
147
148
149
150
151
            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);
152
            scalehandle_unclick_scale(sh);
153
        }
Miller Puckette's avatar
Miller Puckette committed
154
    }
155
    else if (!sh->h_dragon && newstate && sh->h_scale)
Miller Puckette's avatar
Miller Puckette committed
156
    {
157
        scalehandle_click_scale(sh);
158
159
160
    }
    else if (sh->h_dragon && !newstate && !sh->h_scale)
    {
161
        scalehandle_unclick_label(sh);
162
163
164
    }
    else if(!sh->h_dragon && newstate && !sh->h_scale)
    {
165
        scalehandle_click_label(sh);
Miller Puckette's avatar
Miller Puckette committed
166
    }
167
    sh->h_dragon = newstate;
Miller Puckette's avatar
Miller Puckette committed
168
169
}

170
static void toggle__motionhook(t_scalehandle *sh, t_floatarg f1, t_floatarg f2)
171
{
172
    if (sh->h_dragon && sh->h_scale)
173
    {
174
        t_toggle *x = (t_toggle *)(sh->h_master);
175
176
177
178
179
        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);
180
181
182
183

        int properties = gfxstub_haveproperties((void *)x);
        if (properties)
        {
184
            int new_w = x->x_gui.x_w + sh->h_dragx;
185
            properties_set_field_int(properties,"dim.w_ent",new_w);
186
        }
187
    }
188
    scalehandle_dragon_label(sh,f1,f2);
189
190
191
}


Miller Puckette's avatar
Miller Puckette committed
192
193
194
void toggle_draw(t_toggle *x, t_glist *glist, int mode)
{
    if(mode == IEM_GUI_DRAW_MODE_UPDATE)
195
        sys_queuegui((t_gobj*)x, x->x_gui.x_glist, toggle_draw_update);
196
        //toggle_draw_update(x, glist);
Miller Puckette's avatar
Miller Puckette committed
197
198
    else if(mode == IEM_GUI_DRAW_MODE_MOVE)
        toggle_draw_move(x, glist);
199
200
    else if(mode == IEM_GUI_DRAW_MODE_NEW)
    {
Miller Puckette's avatar
Miller Puckette committed
201
        toggle_draw_new(x, glist);
202
203
        sys_vgui(".x%lx.c raise all_cords\n", glist_getcanvas(glist));
    }
Miller Puckette's avatar
Miller Puckette committed
204
205
206
    else if(mode == IEM_GUI_DRAW_MODE_SELECT)
        toggle_draw_select(x, glist);
    else if(mode == IEM_GUI_DRAW_MODE_ERASE)
207
        iemgui_draw_erase(&x->x_gui, glist);
Miller Puckette's avatar
Miller Puckette committed
208
209
210
211
212
213
214
215
    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----------------------------- */

216
217
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
218
219
220
221
222
223
224
{
    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;
225

226
    iemgui_label_getrect(x->x_gui, glist, xp1, yp1, xp2, yp2);
Miller Puckette's avatar
Miller Puckette committed
227
228
229
230
231
232
233
234
235
236
237
238
239
}

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,
240
                iem_symargstoint(&x->x_gui),
Miller Puckette's avatar
Miller Puckette committed
241
242
                srl[0], srl[1], srl[2],
                x->x_gui.x_ldx, x->x_gui.x_ldy,
243
                iem_fstyletoint(&x->x_gui), x->x_gui.x_fontsize,
Miller Puckette's avatar
Miller Puckette committed
244
245
246
247
248
249
250
251
252
253
254
                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
255
    sprintf(buf, "pdtk_iemgui_dialog %%s |tgl| \
Miller Puckette's avatar
Miller Puckette committed
256
257
258
            ----------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
259
260
            {%s} {%s} \
            {%s} %d %d \
Miller Puckette's avatar
Miller Puckette committed
261
262
263
264
            %d %d \
            %d %d %d\n",
            x->x_gui.x_w, IEM_GUI_MINSIZE,
            x->x_nonzero, 1.0,/*non_zero-schedule*/
265
            x->x_gui.x_loadinit, -1, -1,/*no multi*/
Miller Puckette's avatar
Miller Puckette committed
266
267
            srl[0]->s_name, srl[1]->s_name,
            srl[2]->s_name, x->x_gui.x_ldx, x->x_gui.x_ldy,
268
            x->x_gui.x_font_style, x->x_gui.x_fontsize,
Miller Puckette's avatar
Miller Puckette committed
269
270
271
272
273
274
            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)
{
275
    x->x_gui.x_changed = 1;
Miller Puckette's avatar
Miller Puckette committed
276
277
278
    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);
279
    if(iemgui_has_snd(&x->x_gui) && x->x_gui.x_snd->s_thing)
Miller Puckette's avatar
Miller Puckette committed
280
281
282
283
284
        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)
{
285
    canvas_apply_setundo(x->x_gui.x_glist, (t_gobj *)x);
286

Miller Puckette's avatar
Miller Puckette committed
287
288
    t_symbol *srl[3];
    int a = (int)atom_getintarg(0, argc, argv);
289
    t_float nonzero = (t_float)atom_getfloatarg(2, argc, argv);
Miller Puckette's avatar
Miller Puckette committed
290
291
292
293
294
295
296
297
298
299
300
301
    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);
302
303
    //(*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);
304
    iemgui_shouldvis(&x->x_gui, IEM_GUI_DRAW_MODE_MOVE);
305

306
307
    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
308
309
}

310
311
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
312
313
{toggle_bang(x);}

314
315
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
316
317
{
    if(doit)
318
319
        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
320
321
322
323
324
    return (1);
}

static void toggle_set(t_toggle *x, t_floatarg f)
{
325
    if (x->x_on != f) x->x_gui.x_changed = 1;
Miller Puckette's avatar
Miller Puckette committed
326
327
328
329
330
331
332
333
334
    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);
335
    if(x->x_gui.x_put_in2out)
Miller Puckette's avatar
Miller Puckette committed
336
337
    {
        outlet_float(x->x_gui.x_obj.ob_outlet, x->x_on);
338
        if(iemgui_has_snd(&x->x_gui) && x->x_gui.x_snd->s_thing)
Miller Puckette's avatar
Miller Puckette committed
339
340
341
342
343
344
345
346
            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);
347
    if(iemgui_has_snd(&x->x_gui) && x->x_gui.x_snd->s_thing)
Miller Puckette's avatar
Miller Puckette committed
348
349
350
351
352
        pd_float(x->x_gui.x_snd->s_thing, x->x_on);
}

static void toggle_loadbang(t_toggle *x)
{
353
    if(!sys_noloadbang && x->x_gui.x_loadinit)
354
        toggle_fout(x, (t_float)x->x_on);
Miller Puckette's avatar
Miller Puckette committed
355
356
357
358
359
360
}

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;
361
    iemgui_size(&x->x_gui);
Miller Puckette's avatar
Miller Puckette committed
362
363
364
365
}

static void toggle_init(t_toggle *x, t_floatarg f)
{
366
    x->x_gui.x_loadinit = (f==0.0)?0:1;
Miller Puckette's avatar
Miller Puckette committed
367
368
369
370
371
372
373
374
375
376
377
378
}

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
379
    int a=IEM_GUI_DEFAULTSIZE;
Miller Puckette's avatar
Miller Puckette committed
380
381
    int ldx=17, ldy=7;
    int fs=10;
382
    t_float on=0.0, nonzero=1.0;
Miller Puckette's avatar
Miller Puckette committed
383

384
385
    iem_inttosymargs(&x->x_gui, 0);
    iem_inttofstyle(&x->x_gui, 0);
Miller Puckette's avatar
Miller Puckette committed
386
387
388
389
390
391
392
393
394
395
396

    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);
397
        iem_inttosymargs(&x->x_gui, atom_getintarg(1, argc, argv));
Miller Puckette's avatar
Miller Puckette committed
398
399
400
        iemgui_new_getnames(&x->x_gui, 2, argv);
        ldx = (int)atom_getintarg(5, argc, argv);
        ldy = (int)atom_getintarg(6, argc, argv);
401
        iem_inttofstyle(&x->x_gui, atom_getintarg(7, argc, argv));
Miller Puckette's avatar
Miller Puckette committed
402
403
404
405
        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);
406
        on = (t_float)atom_getfloatarg(12, argc, argv);
Miller Puckette's avatar
Miller Puckette committed
407
408
409
    }
    else iemgui_new_getnames(&x->x_gui, 2, 0);
    if((argc == 14)&&IS_A_FLOAT(argv,13))
410
        nonzero = (t_float)atom_getfloatarg(13, argc, argv);
Miller Puckette's avatar
Miller Puckette committed
411
412
413
    x->x_gui.x_draw = (t_iemfunptr)toggle_draw;

    x->x_gui.x_glist = (t_glist *)canvas_getcurrent();
414
    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
415
    x->x_nonzero = (nonzero!=0.0)?nonzero:1.0;
416
    if(x->x_gui.x_loadinit)
Miller Puckette's avatar
Miller Puckette committed
417
418
419
        x->x_on = (on!=0.0)?nonzero:0.0;
    else
        x->x_on = 0.0;
420
    if (iemgui_has_rcv(&x->x_gui))
Miller Puckette's avatar
Miller Puckette committed
421
422
423
424
425
426
427
428
429
430
431
432
        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);
433

434
435
    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);
436
437
    x->x_gui.x_obj.te_iemgui = 1;
    x->x_gui.x_changed = 1;
438

Miller Puckette's avatar
Miller Puckette committed
439
440
441
442
443
    return (x);
}

static void toggle_ff(t_toggle *x)
{
444
    if(iemgui_has_rcv(&x->x_gui))
Miller Puckette's avatar
Miller Puckette committed
445
446
        pd_unbind(&x->x_gui.x_obj.ob_pd, x->x_gui.x_rcv);
    gfxstub_deleteforkey(x);
447

448
449
    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
450
451
452
453
454
455
456
457
458
459
460
461
462
}

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);
463
464
465
466
467
468
    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);
469
    iemgui_class_addmethods(toggle_class);
470
471
472
473
    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);
474
475
 
    scalehandle_class = class_new(gensym("_scalehandle"), 0, 0,
476
                  sizeof(t_scalehandle), CLASS_PD, 0);
477
    class_addmethod(scalehandle_class, (t_method)toggle__clickhook,
478
            gensym("_click"), A_FLOAT, A_FLOAT, A_FLOAT, 0);
479
    class_addmethod(scalehandle_class, (t_method)toggle__motionhook,
480
            gensym("_motion"), A_FLOAT, A_FLOAT, 0);
481

482
    wb_init(&toggle_widgetbehavior,toggle_getrect,toggle_newclick);
Miller Puckette's avatar
Miller Puckette committed
483
484
485
486
487
    class_setwidget(toggle_class, &toggle_widgetbehavior);
    class_sethelpsymbol(toggle_class, gensym("toggle"));
    class_setsavefn(toggle_class, toggle_save);
    class_setpropertiesfn(toggle_class, toggle_properties);
}