Newer
Older
Mathieu L Bouchard
committed
// g_radio.c
// written by Thomas Musil (c) IEM KUG Graz Austria 2000-2001 as hdial/vdial.
// thanks to Miller Puckette, Guenther Geiger and Krzystof Czaja.
// Copyright (c) 2014 by Mathieu Bouchard. (rewrite).
// For information on usage and redistribution, and for a DISCLAIMER OF ALL
// WARRANTIES, see the file, "LICENSE.txt", in this distribution.
// name change to hradio/vradio by MSP (it's a radio button really) and
// changed to put out a "float" as in sliders, toggles, etc.
#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>
Mathieu L Bouchard
committed
#define IEM_RADIO_MAX 128
Mathieu L Bouchard
committed
extern int gfxstub_haveproperties(void *key);
Mathieu L Bouchard
committed
t_widgetbehavior radio_widgetbehavior;
Mathieu L Bouchard
committed
t_class *hradio_class, *hradio_old_class;
t_class *vradio_class, *vradio_old_class;
void radio_draw_update(t_gobj *client, t_glist *glist)
{
t_radio *x = (t_radio *)client;
if(!glist_isvisible(glist)) return;
t_canvas *canvas=glist_getcanvas(glist);
//sys_vgui(".x%lx.c itemconfigure %lxBUT%d -fill #%6.6x -stroke #%6.6x\n",
// canvas, x, x->x_drawn, x->x_gui.x_bcol, x->x_gui.x_bcol);
//sys_vgui(".x%lx.c itemconfigure %lxBUT%d -fill #%6.6x -stroke #%6.6x\n",
// canvas, x, x->x_on, x->x_gui.x_fcol, x->x_gui.x_fcol);
char fcol[8], bcol[8];
sprintf(fcol, "#%6.6x", x->x_gui.x_fcol);
sprintf(bcol, "#%6.6x", x->x_gui.x_bcol);
gui_vmess("gui_radio_update", "xxsii", canvas,
x, fcol, x->x_drawn, x->x_on);
Mathieu L Bouchard
committed
x->x_drawn = x->x_on;
}
Mathieu L Bouchard
committed
void radio_draw_new(t_radio *x, t_glist *glist)
Mathieu L Bouchard
committed
{
t_canvas *canvas=glist_getcanvas(glist);
int n=x->x_number, i, d=x->x_gui.x_w, s=d/4;
int x1=text_xpix(&x->x_gui.x_obj, glist), xi=x1;
Mathieu L Bouchard
committed
int y1=text_ypix(&x->x_gui.x_obj, glist), yi=y1;
Mathieu L Bouchard
committed
iemgui_base_draw_new(&x->x_gui);
Mathieu L Bouchard
committed
Mathieu L Bouchard
committed
for(i=0; i<n; i++) if (x->x_orient) {
//sys_vgui(".x%lx.c create prect %d %d %d %d "
//"-stroke $pd_colors(iemgui_border) "
//"-tags {%lxBASE%d %lxBASE x%lx text iemgui border}\n",
//canvas, x1, yi, x1+d, yi, x, i, x, x);
gui_vmess("gui_create_radio", "xxiiiiiii",
canvas, x, x1, yi, x1+d, yi, i, x1, y1);
//sys_vgui(".x%lx.c create prect %d %d %d %d -fill #%6.6x "
// "-stroke #%6.6x -tags {%lxBUT%d x%lx text iemgui}\n",
// canvas, x1+s, yi+s, x1+d-s, yi+d-s,
// (x->x_on==i)?x->x_gui.x_fcol:x->x_gui.x_bcol,
// (x->x_on==i)?x->x_gui.x_fcol:x->x_gui.x_bcol,
// x, i, x);
char tagbuf[MAXPDSTRING];
sprintf(tagbuf, "x%lx", (long unsigned int)x);
char colorbuf[MAXPDSTRING];
sprintf(colorbuf, "#%6.6x", x->x_gui.x_fcol);
gui_vmess("gui_create_radio_buttons", "xxsiiiiiiii",
canvas, x,
colorbuf, x1+s, yi+s, x1+d-s, yi+d-s, x1, y1, i, x->x_on==i);
Mathieu L Bouchard
committed
yi += d;
Mathieu L Bouchard
committed
x->x_drawn = x->x_on;
Mathieu L Bouchard
committed
} else {
//sys_vgui(".x%lx.c create prect %d %d %d %d "
//"-stroke $pd_colors(iemgui_border) "
//"-tags {%lxBASE%d %lxBASE x%lx text iemgui border}\n",
//canvas, xi, y1, xi, y1+d, x, i, x, x);
gui_vmess("gui_create_radio", "xxiiiiiii", canvas,
x, xi, y1, xi, y1+d, i, x1, y1);
//sys_vgui(".x%lx.c create prect %d %d %d %d -fill #%6.6x "
// "-stroke #%6.6x -tags {%lxBUT%d x%lx text iemgui}\n",
// canvas, xi+s, y1+s, xi+d-s, y1+d-s,
// (x->x_on==i)?x->x_gui.x_fcol:x->x_gui.x_bcol,
// (x->x_on==i)?x->x_gui.x_fcol:x->x_gui.x_bcol,
// x, i, x);
char colorbuf[MAXPDSTRING];
sprintf(colorbuf, "#%6.6x", x->x_gui.x_fcol);
gui_vmess("gui_create_radio_buttons", "xxsiiiiiiii",
canvas, x,
colorbuf, xi+s, y1+s, xi+d-s, yi+d-s, x1, y1, i, x->x_on==i);
Mathieu L Bouchard
committed
xi += d;
Mathieu L Bouchard
committed
x->x_drawn = x->x_on;
}
}
Mathieu L Bouchard
committed
void radio_draw_move(t_radio *x, t_glist *glist)
Mathieu L Bouchard
committed
{
t_canvas *canvas=glist_getcanvas(glist);
if (!glist_isvisible(canvas)) return;
int n=x->x_number, i, d=x->x_gui.x_w, s=d/4;
int x1=text_xpix(&x->x_gui.x_obj, glist), xi=0;
int y1=text_ypix(&x->x_gui.x_obj, glist), yi=0;
Mathieu L Bouchard
committed
iemgui_base_draw_move(&x->x_gui);
Mathieu L Bouchard
committed
for(i=0; i<n; i++) if (x->x_orient) {
//sys_vgui(".x%lx.c coords %lxBASE%d %d %d %d %d\n",
// canvas, x, i, x1, yi, x1+d, yi);
//sys_vgui(".x%lx.c coords %lxBUT%d %d %d %d %d\n",
// canvas, x, i, x1+s, yi+s, x1+d-s, yi+d-s);
gui_vmess("gui_radio_button_coords", "xxiiiiiiii",
canvas, x,
x1, y1, xi, yi, i, s, d, x->x_orient);
Mathieu L Bouchard
committed
yi += d;
Mathieu L Bouchard
committed
} else {
//sys_vgui(".x%lx.c coords %lxBASE%d %d %d %d %d\n",
// canvas, x, i, xi, y1, xi, y1+d);
//sys_vgui(".x%lx.c coords %lxBUT%d %d %d %d %d\n",
// canvas, x, i, xi+s, y1+s, xi+d-s, y1+d-s);
gui_vmess("gui_radio_button_coords", "xxiiiiiiii",
canvas, x,
x1, y1, xi, yi, i, s, d, x->x_orient);
Mathieu L Bouchard
committed
xi += d;
Mathieu L Bouchard
committed
}
}
void radio_draw_config(t_radio *x, t_glist *glist)
{
t_canvas *canvas=glist_getcanvas(glist);
int n=x->x_number, i;
Mathieu L Bouchard
committed
iemgui_base_draw_config(&x->x_gui);
Mathieu L Bouchard
committed
for(i=0; i<n; i++)
{
//sys_vgui(".x%lx.c itemconfigure %lxBUT%d -fill #%6.6x -stroke #%6.6x\n",
// canvas, x, i,
// (x->x_on==i) ? x->x_gui.x_fcol : x->x_gui.x_bcol,
// (x->x_on==i) ? x->x_gui.x_fcol : x->x_gui.x_bcol);
Mathieu L Bouchard
committed
}
char col[8];
sprintf(col, "#%6.6x", x->x_gui.x_fcol);
gui_vmess("gui_radio_update", "xxsii",
canvas, x, col, 0, x->x_on);
Mathieu L Bouchard
committed
}
static void radio__clickhook(t_scalehandle *sh, int newstate)
Mathieu L Bouchard
committed
{
if (sh->h_dragon && newstate == 0 && sh->h_scale)
{
Mathieu L Bouchard
committed
t_radio *x = (t_radio *)(sh->h_master);
Mathieu L Bouchard
committed
canvas_apply_setundo(x->x_gui.x_glist, (t_gobj *)x);
if (sh->h_dragx || sh->h_dragy)
{
Mathieu L Bouchard
committed
if (x->x_orient) {
x->x_gui.x_w += sh->h_dragx;
x->x_gui.x_h += sh->h_dragx;
} else {
x->x_gui.x_w += sh->h_dragy;
x->x_gui.x_h += sh->h_dragy;
}
Mathieu L Bouchard
committed
canvas_dirty(x->x_gui.x_glist, 1);
}
if (glist_isvisible(x->x_gui.x_glist))
{
Mathieu L Bouchard
committed
radio_draw_move(x, x->x_gui.x_glist);
Mathieu L Bouchard
committed
scalehandle_unclick_scale(sh);
}
}
Mathieu L Bouchard
committed
iemgui__clickhook3(sh,newstate);
Mathieu L Bouchard
committed
}
Mathieu L Bouchard
committed
static void radio__motionhook(t_scalehandle *sh, t_floatarg f1, t_floatarg f2)
Mathieu L Bouchard
committed
{
if (sh->h_dragon && sh->h_scale)
{
t_radio *x = (t_radio *)(sh->h_master);
int dx = (int)f1, dy = (int)f2;
Mathieu L Bouchard
committed
if (x->x_orient) {
dy = maxi(dy,(IEM_GUI_MINSIZE-x->x_gui.x_h)*x->x_number);
dx = dy/x->x_number;
} else {
dx = maxi(dx,(IEM_GUI_MINSIZE-x->x_gui.x_w)*x->x_number);
dy = dx/x->x_number;
Mathieu L Bouchard
committed
}
sh->h_dragx = dx;
sh->h_dragy = dy;
scalehandle_drag_scale(sh);
int properties = gfxstub_haveproperties((void *)x);
if (properties)
{
Mathieu L Bouchard
committed
properties_set_field_int(properties,"dim.w_ent", x->x_orient ?
x->x_gui.x_h + sh->h_dragy :
x->x_gui.x_w + sh->h_dragx);
Mathieu L Bouchard
committed
}
}
scalehandle_dragon_label(sh,f1,f2);
}
Mathieu L Bouchard
committed
void radio_draw(t_radio *x, t_glist *glist, int mode)
Mathieu L Bouchard
committed
{
if(mode == IEM_GUI_DRAW_MODE_UPDATE) sys_queuegui(x, glist, radio_draw_update);
Mathieu L Bouchard
committed
else if(mode == IEM_GUI_DRAW_MODE_MOVE) radio_draw_move(x, glist);
Mathieu L Bouchard
committed
else if(mode == IEM_GUI_DRAW_MODE_NEW) radio_draw_new(x, glist);
Mathieu L Bouchard
committed
else if(mode == IEM_GUI_DRAW_MODE_CONFIG) radio_draw_config(x, glist);
}
Mathieu L Bouchard
committed
static void radio_getrect(t_gobj *z, t_glist *glist, int *xp1, int *yp1,
Mathieu L Bouchard
committed
int *xp2, int *yp2)
{
t_radio *x = (t_radio *)z;
*xp1 = text_xpix(&x->x_gui.x_obj, glist);
*yp1 = text_ypix(&x->x_gui.x_obj, glist);
Mathieu L Bouchard
committed
if (x->x_orient) {
*xp2 = *xp1 + x->x_gui.x_w;
*yp2 = *yp1 + x->x_gui.x_h*x->x_number;
} else {
*xp2 = *xp1 + x->x_gui.x_w*x->x_number;
*yp2 = *yp1 + x->x_gui.x_h;
}
Mathieu L Bouchard
committed
iemgui_label_getrect(x->x_gui, glist, xp1, yp1, xp2, yp2);
}
Mathieu L Bouchard
committed
static void radio_save(t_gobj *z, t_binbuf *b)
Mathieu L Bouchard
committed
{
t_radio *x = (t_radio *)z;
int bflcol[3];
t_symbol *srl[3];
Mathieu L Bouchard
committed
t_class *c = pd_class((t_pd *)x);
t_symbol *cname =
c == vradio_old_class ? gensym("vdl") :
c == hradio_old_class ? gensym("hdl") :
x->x_orient ? gensym("vradio") : gensym("hradio");
Mathieu L Bouchard
committed
iemgui_save(&x->x_gui, srl, bflcol);
binbuf_addv(b, "ssiisiiiisssiiiiiiii", gensym("#X"),gensym("obj"),
Mathieu L Bouchard
committed
(int)x->x_gui.x_obj.te_xpix, (int)x->x_gui.x_obj.te_ypix,
cname, x->x_gui.x_w,
x->x_change, iem_symargstoint(&x->x_gui), x->x_number,
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], x->x_on);
Mathieu L Bouchard
committed
binbuf_addv(b, ";");
}
Mathieu L Bouchard
committed
static void radio_properties(t_gobj *z, t_glist *owner)
Mathieu L Bouchard
committed
{
t_radio *x = (t_radio *)z;
char buf[800], *gfx_tag;
Mathieu L Bouchard
committed
t_symbol *srl[3];
int hchange=-1;
iemgui_properties(&x->x_gui, srl);
Mathieu L Bouchard
committed
if (pd_class((t_pd *)x) == hradio_old_class || pd_class((t_pd *)x) == vradio_old_class)
Mathieu L Bouchard
committed
hchange = x->x_change;
Mathieu L Bouchard
committed
sprintf(buf, "pdtk_iemgui_dialog %%s |%cradio| \
Mathieu L Bouchard
committed
----------dimensions(pix):----------- %d %d size: 0 0 empty \
empty 0.0 empty 0.0 empty %d %d new-only new&old %d %d number: %d \
{%s} {%s} {%s} %d %d %d %d %d %d %d\n",
Mathieu L Bouchard
committed
x->x_orient ? 'v' : 'h',
Mathieu L Bouchard
committed
x->x_gui.x_w, IEM_GUI_MINSIZE, 0,/*no_schedule*/
hchange, x->x_gui.x_loadinit, -1, x->x_number,
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,
0xffffff & x->x_gui.x_bcol, 0xffffff & x->x_gui.x_fcol,
0xffffff & x->x_gui.x_lcol);
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
//gfxstub_new(&x->x_gui.x_obj.ob_pd, x, buf);
gfx_tag = gfxstub_new2(&x->x_gui.x_obj.ob_pd, x);
gui_start_vmess("gui_iemgui_dialog", "s", gfx_tag);
gui_start_array();
gui_s("type"); gui_s(x->x_orient ? "vradio" : "hradio");
gui_s("size"); gui_i(x->x_gui.x_w);
gui_s("minimum-size"); gui_i(IEM_GUI_MINSIZE);
gui_s("range-schedule"); // no idea what this is...
gui_i(0);
gui_s("hchange"); // no idea...
gui_i(hchange);
gui_s("init"); gui_i(x->x_gui.x_loadinit);
gui_s("number"); gui_i(x->x_number);
gui_s("send-symbol"); gui_s(srl[0]->s_name);
gui_s("receive-symbol"); gui_s(srl[1]->s_name);
gui_s("label"); gui_s(srl[2]->s_name);
gui_s("x-offset"); gui_i(x->x_gui.x_ldx);
gui_s("y-offset"); gui_i(x->x_gui.x_ldy);
gui_s("font-style"); gui_i(x->x_gui.x_font_style);
gui_s("font-size"); gui_i(x->x_gui.x_fontsize);
gui_s("background-color"); gui_i(0xffffff & x->x_gui.x_bcol);
gui_s("foreground-color"); gui_i(0xffffff & x->x_gui.x_fcol);
gui_s("label-color"); gui_i(0xffffff & x->x_gui.x_lcol);
gui_end_array();
gui_end_vmess();
Mathieu L Bouchard
committed
}
Mathieu L Bouchard
committed
static void radio_dialog(t_radio *x, t_symbol *s, int argc, t_atom *argv)
Mathieu L Bouchard
committed
{
canvas_apply_setundo(x->x_gui.x_glist, (t_gobj *)x);
Mathieu L Bouchard
committed
x->x_gui.x_h =
x->x_gui.x_w = iemgui_clip_size(atom_getintarg(0, argc, argv));
x->x_change = !!atom_getintarg(4, argc, argv);
int num = atom_getintarg(6, argc, argv);
int sr_flags = iemgui_dialog(&x->x_gui, argc, argv);
Mathieu L Bouchard
committed
if(x->x_number != num)
{
Mathieu L Bouchard
committed
iemgui_draw_erase(&x->x_gui);
Mathieu L Bouchard
committed
x->x_number = num;
if(x->x_on >= x->x_number)
{
x->x_on = x->x_number - 1;
x->x_on_old = x->x_on;
}
iemgui_shouldvis(&x->x_gui, IEM_GUI_DRAW_MODE_NEW);
Ivica Bukvic
committed
if (glist_isselected(x->x_gui.x_glist, (t_gobj *)x))
iemgui_select((t_gobj *)x, x->x_gui.x_glist, 1);
Mathieu L Bouchard
committed
}
else
{
Mathieu L Bouchard
committed
iemgui_draw_config(&x->x_gui);
iemgui_draw_io(&x->x_gui, sr_flags);
Mathieu L Bouchard
committed
iemgui_shouldvis(&x->x_gui, IEM_GUI_DRAW_MODE_MOVE);
}
Mathieu L Bouchard
committed
scalehandle_draw(&x->x_gui);
Mathieu L Bouchard
committed
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
scrollbar_update(x->x_gui.x_glist);
}
static void radio_set(t_radio *x, t_floatarg f)
{
int i=mini(maxi((int)f,0),x->x_number-1);
if(x->x_on != x->x_on_old)
{
int old = x->x_on_old;
x->x_on_old = x->x_on;
x->x_on = i;
if (x->x_on != x->x_on_old)
x->x_gui.x_draw(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
x->x_on_old = old;
}
else
{
x->x_on = i;
if (x->x_on != x->x_on_old)
x->x_gui.x_draw(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
}
}
static void radio_bang(t_radio *x)
{
if (pd_class(&x->x_gui.x_obj.ob_pd) == hradio_old_class ||
pd_class(&x->x_gui.x_obj.ob_pd) == vradio_old_class)
{
if((x->x_change)&&(x->x_on != x->x_on_old))
{
SETFLOAT(x->x_at, (t_float)x->x_on_old);
SETFLOAT(x->x_at+1, 0.0);
Mathieu L Bouchard
committed
iemgui_out_list(&x->x_gui, 0, 0, &s_list, 2, x->x_at);
Mathieu L Bouchard
committed
}
x->x_on_old = x->x_on;
SETFLOAT(x->x_at, (t_float)x->x_on);
SETFLOAT(x->x_at+1, 1.0);
Mathieu L Bouchard
committed
iemgui_out_list(&x->x_gui, 0, 0, &s_list, 2, x->x_at);
Mathieu L Bouchard
committed
}
Mathieu L Bouchard
committed
else iemgui_out_float(&x->x_gui, 0, 0, x->x_on);
Mathieu L Bouchard
committed
}
Mathieu L Bouchard
committed
static void radio_float2(t_radio *x, t_floatarg f, int doout)
Mathieu L Bouchard
committed
{
int i=mini(maxi((int)f,0),x->x_number-1);
if (pd_class(&x->x_gui.x_obj.ob_pd) == hradio_old_class ||
pd_class(&x->x_gui.x_obj.ob_pd) == vradio_old_class)
{
if((x->x_change)&&(i != x->x_on_old))
{
Mathieu L Bouchard
committed
if(doout)
Mathieu L Bouchard
committed
{
SETFLOAT(x->x_at, (t_float)x->x_on_old);
SETFLOAT(x->x_at+1, 0.0);
Mathieu L Bouchard
committed
iemgui_out_list(&x->x_gui, 0, 0, &s_list, 2, x->x_at);
Mathieu L Bouchard
committed
}
}
Mathieu L Bouchard
committed
x->x_on_old = x->x_on;
Mathieu L Bouchard
committed
x->x_on = i;
x->x_gui.x_draw(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
x->x_on_old = x->x_on;
Mathieu L Bouchard
committed
if(doout)
Mathieu L Bouchard
committed
{
SETFLOAT(x->x_at, (t_float)x->x_on);
SETFLOAT(x->x_at+1, 1.0);
Mathieu L Bouchard
committed
iemgui_out_list(&x->x_gui, 0, 0, &s_list, 2, x->x_at);
Mathieu L Bouchard
committed
}
}
else
{
x->x_on_old = x->x_on;
x->x_on = i;
if (i != x->x_on_old)
x->x_gui.x_draw(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
Mathieu L Bouchard
committed
if (doout)
Mathieu L Bouchard
committed
{
Mathieu L Bouchard
committed
iemgui_out_float(&x->x_gui, 0, 0, x->x_on);
Mathieu L Bouchard
committed
}
}
}
Mathieu L Bouchard
committed
static void radio_fout(t_radio *x, t_floatarg f)
Mathieu L Bouchard
committed
{
Mathieu L Bouchard
committed
radio_float2(x,f,1);
Mathieu L Bouchard
committed
}
Mathieu L Bouchard
committed
static void radio_float(t_radio *x, t_floatarg f)
Mathieu L Bouchard
committed
{
Mathieu L Bouchard
committed
radio_float2(x,f,x->x_gui.x_put_in2out);
Mathieu L Bouchard
committed
}
Mathieu L Bouchard
committed
static void radio_click(t_radio *x, t_floatarg xpos, t_floatarg ypos,
t_floatarg shift, t_floatarg ctrl, t_floatarg alt)
Mathieu L Bouchard
committed
{
Mathieu L Bouchard
committed
if (x->x_orient) {
int yy = (int)ypos - text_ypix(&x->x_gui.x_obj, x->x_gui.x_glist);
radio_fout(x, (t_float)(yy / x->x_gui.x_h));
} else {
int xx = (int)xpos - text_xpix(&x->x_gui.x_obj, x->x_gui.x_glist);
radio_fout(x, (t_float)(xx / x->x_gui.x_w));
}
Mathieu L Bouchard
committed
}
Mathieu L Bouchard
committed
static int radio_newclick(t_gobj *z, struct _glist *glist, int xpix, int ypix,
Mathieu L Bouchard
committed
int shift, int alt, int dbl, int doit)
{
if(doit)
Mathieu L Bouchard
committed
radio_click((t_radio *)z, (t_floatarg)xpix, (t_floatarg)ypix,
Mathieu L Bouchard
committed
(t_floatarg)shift, 0, (t_floatarg)alt);
return (1);
}
static void radio_loadbang(t_radio *x)
{
if(!sys_noloadbang && x->x_gui.x_loadinit)
Mathieu L Bouchard
committed
radio_bang(x);
Mathieu L Bouchard
committed
}
static void radio_number(t_radio *x, t_floatarg num)
{
int n=mini(maxi((int)num,1),IEM_RADIO_MAX);
if(n != x->x_number)
{
Mathieu L Bouchard
committed
iemgui_draw_erase(&x->x_gui);
Mathieu L Bouchard
committed
x->x_number = n;
if(x->x_on >= x->x_number)
x->x_on = x->x_number - 1;
x->x_on_old = x->x_on;
Mathieu L Bouchard
committed
iemgui_draw_new(&x->x_gui);
Mathieu L Bouchard
committed
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
}
}
static void radio_size(t_radio *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;
iemgui_size(&x->x_gui);
}
static void radio_double_change(t_radio *x) {x->x_change = 1;}
static void radio_single_change(t_radio *x) {x->x_change = 0;}
static void *radio_new(t_symbol *s, int argc, t_atom *argv)
{
t_radio *x = (t_radio *)pd_new(
s==gensym("hdl") ? hradio_old_class :
s==gensym("vdl") ? vradio_old_class :
s==gensym("vradio") ? vradio_class : hradio_class);
x->x_orient = s==gensym("vdl") || s==gensym("vradio");
int bflcol[]={-262144, -1, -1};
int a=IEM_GUI_DEFAULTSIZE, on=0, ldx=0, ldy=-8, chg=1, num=8, fs=10;
iem_inttosymargs(&x->x_gui, 0);
iem_inttofstyle(&x->x_gui, 0);
if((argc == 15)&&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)&&IS_A_FLOAT(argv,14))
{
Mathieu L Bouchard
committed
a = atom_getintarg(0, argc, argv);
chg = atom_getintarg(1, argc, argv);
Mathieu L Bouchard
committed
iem_inttosymargs(&x->x_gui, atom_getintarg(2, argc, argv));
Mathieu L Bouchard
committed
num = mini(maxi(atom_getintarg(3, argc, argv),1),IEM_RADIO_MAX);
Mathieu L Bouchard
committed
iemgui_new_getnames(&x->x_gui, 4, argv);
Mathieu L Bouchard
committed
ldx = atom_getintarg(7, argc, argv);
ldy = atom_getintarg(8, argc, argv);
Mathieu L Bouchard
committed
iem_inttofstyle(&x->x_gui, atom_getintarg(9, argc, argv));
Mathieu L Bouchard
committed
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);
on = mini(maxi(atom_getintarg(14, argc, argv),0),num-1);
Mathieu L Bouchard
committed
}
else iemgui_new_getnames(&x->x_gui, 4, 0);
Mathieu L Bouchard
committed
x->x_gui.x_draw = (t_iemfunptr)radio_draw;
Mathieu L Bouchard
committed
x->x_gui.x_glist = (t_glist *)canvas_getcurrent();
if (x->x_gui.x_font_style<0 || x->x_gui.x_font_style>2) x->x_gui.x_font_style=0;
x->x_number = num;
Mathieu L Bouchard
committed
x->x_on = x->x_gui.x_loadinit ? on : 0;
Mathieu L Bouchard
committed
x->x_change = (chg==0)?0:1;
if (iemgui_has_rcv(&x->x_gui))
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;
iemgui_verify_snd_ne_rcv(&x->x_gui);
iemgui_all_colfromload(&x->x_gui, bflcol);
outlet_new(&x->x_gui.x_obj, &s_list);
x->x_gui. x_handle = scalehandle_new((t_object *)x,x->x_gui.x_glist,1,radio__clickhook,radio__motionhook);
x->x_gui.x_lhandle = scalehandle_new((t_object *)x,x->x_gui.x_glist,0,radio__clickhook,radio__motionhook);
Mathieu L Bouchard
committed
x->x_gui.x_obj.te_iemgui = 1;
return (x);
}
static void radio_free(t_radio *x)
{
if(iemgui_has_rcv(&x->x_gui))
pd_unbind(&x->x_gui.x_obj.ob_pd, x->x_gui.x_rcv);
gfxstub_deleteforkey(x);
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);
}
void radio_addmethods(t_class *c)
{
Mathieu L Bouchard
committed
class_addbang(c, radio_bang);
class_addfloat(c, radio_float);
Mathieu L Bouchard
committed
class_addmethod(c, (t_method)radio_loadbang, gensym("loadbang"), 0);
class_addmethod(c, (t_method)radio_set, gensym("set"), A_FLOAT, 0);
class_addmethod(c, (t_method)radio_size, gensym("size"), A_GIMME, 0);
Mathieu L Bouchard
committed
class_addmethod(c, (t_method)iemgui_init, gensym("init"), A_FLOAT, 0);
Mathieu L Bouchard
committed
class_addmethod(c, (t_method)radio_number, gensym("number"), A_FLOAT, 0);
class_addmethod(c, (t_method)radio_single_change,
gensym("single_change"), 0);
class_addmethod(c, (t_method)radio_double_change,
gensym("double_change"), 0);
Mathieu L Bouchard
committed
class_addmethod(c, (t_method)radio_click, gensym("click"),
A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, 0);
class_setpropertiesfn(c, radio_properties);
class_addmethod(c, (t_method)radio_dialog, gensym("dialog"), A_GIMME, 0);
class_setsavefn(c, radio_save);
class_setwidget(c, &radio_widgetbehavior);
Mathieu L Bouchard
committed
}
Mathieu L Bouchard
committed
void g_radio_setup(void)
Mathieu L Bouchard
committed
{
Mathieu L Bouchard
committed
wb_init(&radio_widgetbehavior,radio_getrect,radio_newclick);
Mathieu L Bouchard
committed
hradio_class = class_new(gensym("hradio"), (t_newmethod)radio_new,
(t_method)radio_free, sizeof(t_radio), 0, A_GIMME, 0);
hradio_old_class = class_new(gensym("hdl"), (t_newmethod)radio_new,
(t_method)radio_free, sizeof(t_radio), 0, A_GIMME, 0);
Mathieu L Bouchard
committed
vradio_class = class_new(gensym("vradio"), (t_newmethod)radio_new,
(t_method)radio_free, sizeof(t_radio), 0, A_GIMME, 0);
vradio_old_class = class_new(gensym("vdl"), (t_newmethod)radio_new,
(t_method)radio_free, sizeof(t_radio), 0, A_GIMME, 0);
Mathieu L Bouchard
committed
class_addcreator((t_newmethod)radio_new, gensym("rdb"), A_GIMME, 0);
class_addcreator((t_newmethod)radio_new, gensym("radiobut"), A_GIMME, 0);
class_addcreator((t_newmethod)radio_new, gensym("radiobutton"),
A_GIMME, 0);
Mathieu L Bouchard
committed
iemgui_class_addmethods(hradio_class);
Mathieu L Bouchard
committed
iemgui_class_addmethods(hradio_old_class);
Mathieu L Bouchard
committed
iemgui_class_addmethods(vradio_class);
iemgui_class_addmethods(vradio_old_class);
Mathieu L Bouchard
committed
Mathieu L Bouchard
committed
radio_addmethods(hradio_class);
radio_addmethods(hradio_old_class);
Mathieu L Bouchard
committed
radio_addmethods(vradio_class);
Mathieu L Bouchard
committed
radio_addmethods(vradio_old_class);
class_sethelpsymbol(hradio_class, gensym("hradio"));
class_sethelpsymbol(hradio_old_class, gensym("hradio"));
class_sethelpsymbol(vradio_class, gensym("vradio"));
class_sethelpsymbol(vradio_old_class, gensym("vradio"));