diff options
author | Peter D'Hoye <peter.dhoye@gmail.com> | 2009-05-22 21:58:48 +0000 |
---|---|---|
committer | Peter D'Hoye <peter.dhoye@gmail.com> | 2009-05-22 21:58:48 +0000 |
commit | 513389b4c1bc8afe4b2dc9947c534bfeb105e3da (patch) | |
tree | 10e673b35651ac567fed2eda0c679c7ade64cbc6 /apps/plugins/pdbox/PDa/src/g_vdial.c | |
parent | 95fa7f6a2ef466444fbe3fe87efc6d5db6b77b36 (diff) | |
download | rockbox-513389b4c1bc8afe4b2dc9947c534bfeb105e3da.tar.gz rockbox-513389b4c1bc8afe4b2dc9947c534bfeb105e3da.zip |
Add FS #10214. Initial commit of the original PDa code for the GSoC Pure Data plugin project of Wincent Balin. Stripped some non-sourcefiles and added a rockbox readme that needs a bit more info from Wincent. Is added to CATEGORIES and viewers, but not yet to SUBDIRS (ie doesn't build yet)
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@21044 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/plugins/pdbox/PDa/src/g_vdial.c')
-rw-r--r-- | apps/plugins/pdbox/PDa/src/g_vdial.c | 1432 |
1 files changed, 1432 insertions, 0 deletions
diff --git a/apps/plugins/pdbox/PDa/src/g_vdial.c b/apps/plugins/pdbox/PDa/src/g_vdial.c new file mode 100644 index 0000000000..08b1338daf --- /dev/null +++ b/apps/plugins/pdbox/PDa/src/g_vdial.c | |||
@@ -0,0 +1,1432 @@ | |||
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 | /* vdial.c written by Thomas Musil (c) IEM KUG Graz Austria 2000-2001 */ | ||
6 | |||
7 | /* name change to vradio by MSP (it's a radio button really) and changed to | ||
8 | put out a "float" as in sliders, toggles, etc. */ | ||
9 | |||
10 | #include <stdlib.h> | ||
11 | #include <string.h> | ||
12 | #include <stdio.h> | ||
13 | #include <ctype.h> | ||
14 | #include "m_pd.h" | ||
15 | #include "g_canvas.h" | ||
16 | #include "t_tk.h" | ||
17 | #include "g_all_guis.h" | ||
18 | #include <math.h> | ||
19 | |||
20 | /*------------------ global variables -------------------------*/ | ||
21 | |||
22 | |||
23 | /*------------------ global functions -------------------------*/ | ||
24 | |||
25 | |||
26 | |||
27 | |||
28 | /* ------------- vdl gui-vertical radio button ---------------------- */ | ||
29 | |||
30 | t_widgetbehavior vradio_widgetbehavior; | ||
31 | static t_class *vradio_class, *vradio_old_class; | ||
32 | |||
33 | /* widget helper functions */ | ||
34 | |||
35 | void vradio_draw_update(t_vradio *x, t_glist *glist) | ||
36 | { | ||
37 | if(glist_isvisible(glist)) | ||
38 | { | ||
39 | t_canvas *canvas=glist_getcanvas(glist); | ||
40 | |||
41 | sys_vgui(".x%x.c itemconfigure %xBUT%d -fill #%6.6x -outline #%6.6x\n", | ||
42 | canvas, x, x->x_on_old, | ||
43 | x->x_gui.x_bcol, x->x_gui.x_bcol); | ||
44 | sys_vgui(".x%x.c itemconfigure %xBUT%d -fill #%6.6x -outline #%6.6x\n", | ||
45 | canvas, x, x->x_on, | ||
46 | x->x_gui.x_fcol, x->x_gui.x_fcol); | ||
47 | } | ||
48 | } | ||
49 | |||
50 | void vradio_draw_new(t_vradio *x, t_glist *glist) | ||
51 | { | ||
52 | t_canvas *canvas=glist_getcanvas(glist); | ||
53 | int n=x->x_number, i, dy=x->x_gui.x_h, s4=dy/4; | ||
54 | int yy11b=text_ypix(&x->x_gui.x_obj, glist); | ||
55 | int yy11=yy11b, yy12=yy11+dy; | ||
56 | int yy21=yy11+s4, yy22=yy12-s4; | ||
57 | int xx11=text_xpix(&x->x_gui.x_obj, glist), xx12=xx11+dy; | ||
58 | int xx21=xx11+s4, xx22=xx12-s4; | ||
59 | |||
60 | for(i=0; i<n; i++) | ||
61 | { | ||
62 | sys_vgui(".x%x.c create rectangle %d %d %d %d -fill #%6.6x -tags %xBASE%d\n", | ||
63 | canvas, xx11, yy11, xx12, yy12, | ||
64 | x->x_gui.x_bcol, x, i); | ||
65 | sys_vgui(".x%x.c create rectangle %d %d %d %d -fill #%6.6x -outline #%6.6x -tags %xBUT%d\n", | ||
66 | canvas, xx21, yy21, xx22, yy22, | ||
67 | (x->x_on==i)?x->x_gui.x_fcol:x->x_gui.x_bcol, | ||
68 | (x->x_on==i)?x->x_gui.x_fcol:x->x_gui.x_bcol, x, i); | ||
69 | yy11 += dy; | ||
70 | yy12 += dy; | ||
71 | yy21 += dy; | ||
72 | yy22 += dy; | ||
73 | } | ||
74 | sys_vgui(".x%x.c create text %d %d -text {%s} -anchor w \ | ||
75 | -font {%s %d bold} -fill #%6.6x -tags %xLABEL\n", | ||
76 | canvas, xx11+x->x_gui.x_ldx, yy11b+x->x_gui.x_ldy, | ||
77 | strcmp(x->x_gui.x_lab->s_name, "empty")?x->x_gui.x_lab->s_name:"", | ||
78 | x->x_gui.x_font, x->x_gui.x_fontsize, | ||
79 | x->x_gui.x_lcol, x); | ||
80 | if(!x->x_gui.x_fsf.x_snd_able) | ||
81 | sys_vgui(".x%x.c create rectangle %d %d %d %d -tags %xOUT%d\n", | ||
82 | canvas, xx11, yy11-1, xx11 + IOWIDTH, yy11, x, 0); | ||
83 | if(!x->x_gui.x_fsf.x_rcv_able) | ||
84 | sys_vgui(".x%x.c create rectangle %d %d %d %d -tags %xIN%d\n", | ||
85 | canvas, xx11, yy11b, xx11 + IOWIDTH, yy11b+1, x, 0); | ||
86 | } | ||
87 | |||
88 | void vradio_draw_move(t_vradio *x, t_glist *glist) | ||
89 | { | ||
90 | t_canvas *canvas=glist_getcanvas(glist); | ||
91 | int n=x->x_number, i, dy=x->x_gui.x_h, s4=dy/4; | ||
92 | int yy11b=text_ypix(&x->x_gui.x_obj, glist); | ||
93 | int yy11=yy11b, yy12=yy11+dy; | ||
94 | int yy21=yy11+s4, yy22=yy12-s4; | ||
95 | int xx11=text_xpix(&x->x_gui.x_obj, glist), xx12=xx11+dy; | ||
96 | int xx21=xx11+s4, xx22=xx12-s4; | ||
97 | |||
98 | for(i=0; i<n; i++) | ||
99 | { | ||
100 | sys_vgui(".x%x.c coords %xBASE%d %d %d %d %d\n", | ||
101 | canvas, x, i, xx11, yy11, xx12, yy12); | ||
102 | sys_vgui(".x%x.c coords %xBUT%d %d %d %d %d\n", | ||
103 | canvas, x, i, xx21, yy21, xx22, yy22); | ||
104 | yy11 += dy; | ||
105 | yy12 += dy; | ||
106 | yy21 += dy; | ||
107 | yy22 += dy; | ||
108 | } | ||
109 | sys_vgui(".x%x.c coords %xLABEL %d %d\n", | ||
110 | canvas, x, xx11+x->x_gui.x_ldx, yy11b+x->x_gui.x_ldy); | ||
111 | if(!x->x_gui.x_fsf.x_snd_able) | ||
112 | sys_vgui(".x%x.c coords %xOUT%d %d %d %d %d\n", | ||
113 | canvas, x, 0, xx11, yy11-1, xx11 + IOWIDTH, yy11); | ||
114 | if(!x->x_gui.x_fsf.x_rcv_able) | ||
115 | sys_vgui(".x%x.c coords %xIN%d %d %d %d %d\n", | ||
116 | canvas, x, 0, xx11, yy11b, xx11 + IOWIDTH, yy11b+1); | ||
117 | } | ||
118 | |||
119 | void vradio_draw_erase(t_vradio* x, t_glist* glist) | ||
120 | { | ||
121 | t_canvas *canvas=glist_getcanvas(glist); | ||
122 | int n=x->x_number, i; | ||
123 | |||
124 | for(i=0; i<n; i++) | ||
125 | { | ||
126 | sys_vgui(".x%x.c delete %xBASE%d\n", canvas, x, i); | ||
127 | sys_vgui(".x%x.c delete %xBUT%d\n", canvas, x, i); | ||
128 | } | ||
129 | sys_vgui(".x%x.c delete %xLABEL\n", canvas, x); | ||
130 | if(!x->x_gui.x_fsf.x_snd_able) | ||
131 | sys_vgui(".x%x.c delete %xOUT%d\n", canvas, x, 0); | ||
132 | if(!x->x_gui.x_fsf.x_rcv_able) | ||
133 | sys_vgui(".x%x.c delete %xIN%d\n", canvas, x, 0); | ||
134 | } | ||
135 | |||
136 | void vradio_draw_config(t_vradio* x, t_glist* glist) | ||
137 | { | ||
138 | t_canvas *canvas=glist_getcanvas(glist); | ||
139 | int n=x->x_number, i; | ||
140 | |||
141 | sys_vgui(".x%x.c itemconfigure %xLABEL -font {%s %d bold} -fill #%6.6x -text {%s} \n", | ||
142 | canvas, x, x->x_gui.x_font, x->x_gui.x_fontsize, | ||
143 | x->x_gui.x_fsf.x_selected?IEM_GUI_COLOR_SELECTED:x->x_gui.x_lcol, | ||
144 | strcmp(x->x_gui.x_lab->s_name, "empty")?x->x_gui.x_lab->s_name:""); | ||
145 | for(i=0; i<n; i++) | ||
146 | { | ||
147 | sys_vgui(".x%x.c itemconfigure %xBASE%d -fill #%6.6x\n", canvas, x, i, | ||
148 | x->x_gui.x_bcol); | ||
149 | sys_vgui(".x%x.c itemconfigure %xBUT%d -fill #%6.6x -outline #%6.6x\n", canvas, x, i, | ||
150 | (x->x_on==i)?x->x_gui.x_fcol:x->x_gui.x_bcol, | ||
151 | (x->x_on==i)?x->x_gui.x_fcol:x->x_gui.x_bcol); | ||
152 | } | ||
153 | } | ||
154 | |||
155 | void vradio_draw_io(t_vradio* x, t_glist* glist, int old_snd_rcv_flags) | ||
156 | { | ||
157 | t_canvas *canvas=glist_getcanvas(glist); | ||
158 | int xpos=text_xpix(&x->x_gui.x_obj, glist); | ||
159 | int ypos=text_ypix(&x->x_gui.x_obj, glist); | ||
160 | |||
161 | if((old_snd_rcv_flags & IEM_GUI_OLD_SND_FLAG) && !x->x_gui.x_fsf.x_snd_able) | ||
162 | sys_vgui(".x%x.c create rectangle %d %d %d %d -tags %xOUT%d\n", | ||
163 | canvas, xpos, | ||
164 | ypos+(x->x_number*x->x_gui.x_h)-1, | ||
165 | xpos+ IOWIDTH, | ||
166 | ypos+(x->x_number*x->x_gui.x_h), x, 0); | ||
167 | if(!(old_snd_rcv_flags & IEM_GUI_OLD_SND_FLAG) && x->x_gui.x_fsf.x_snd_able) | ||
168 | sys_vgui(".x%x.c delete %xOUT%d\n", canvas, x, 0); | ||
169 | if((old_snd_rcv_flags & IEM_GUI_OLD_RCV_FLAG) && !x->x_gui.x_fsf.x_rcv_able) | ||
170 | sys_vgui(".x%x.c create rectangle %d %d %d %d -tags %xIN%d\n", | ||
171 | canvas, xpos, ypos, | ||
172 | xpos+ IOWIDTH, ypos+1, | ||
173 | x, 0); | ||
174 | if(!(old_snd_rcv_flags & IEM_GUI_OLD_RCV_FLAG) && x->x_gui.x_fsf.x_rcv_able) | ||
175 | sys_vgui(".x%x.c delete %xIN%d\n", canvas, x, 0); | ||
176 | } | ||
177 | |||
178 | void vradio_draw_select(t_vradio* x, t_glist* glist) | ||
179 | { | ||
180 | t_canvas *canvas=glist_getcanvas(glist); | ||
181 | int n=x->x_number, i; | ||
182 | |||
183 | if(x->x_gui.x_fsf.x_selected) | ||
184 | { | ||
185 | for(i=0; i<n; i++) | ||
186 | { | ||
187 | sys_vgui(".x%x.c itemconfigure %xBASE%d -outline #%6.6x\n", canvas, x, i, | ||
188 | IEM_GUI_COLOR_SELECTED); | ||
189 | } | ||
190 | sys_vgui(".x%x.c itemconfigure %xLABEL -fill #%6.6x\n", canvas, x, IEM_GUI_COLOR_SELECTED); | ||
191 | } | ||
192 | else | ||
193 | { | ||
194 | for(i=0; i<n; i++) | ||
195 | { | ||
196 | sys_vgui(".x%x.c itemconfigure %xBASE%d -outline #%6.6x\n", canvas, x, i, | ||
197 | IEM_GUI_COLOR_NORMAL); | ||
198 | } | ||
199 | sys_vgui(".x%x.c itemconfigure %xLABEL -fill #%6.6x\n", canvas, x, | ||
200 | x->x_gui.x_lcol); | ||
201 | } | ||
202 | } | ||
203 | |||
204 | void vradio_draw(t_vradio *x, t_glist *glist, int mode) | ||
205 | { | ||
206 | if(mode == IEM_GUI_DRAW_MODE_UPDATE) | ||
207 | vradio_draw_update(x, glist); | ||
208 | else if(mode == IEM_GUI_DRAW_MODE_MOVE) | ||
209 | vradio_draw_move(x, glist); | ||
210 | else if(mode == IEM_GUI_DRAW_MODE_NEW) | ||
211 | vradio_draw_new(x, glist); | ||
212 | else if(mode == IEM_GUI_DRAW_MODE_SELECT) | ||
213 | vradio_draw_select(x, glist); | ||
214 | else if(mode == IEM_GUI_DRAW_MODE_ERASE) | ||
215 | vradio_draw_erase(x, glist); | ||
216 | else if(mode == IEM_GUI_DRAW_MODE_CONFIG) | ||
217 | vradio_draw_config(x, glist); | ||
218 | else if(mode >= IEM_GUI_DRAW_MODE_IO) | ||
219 | vradio_draw_io(x, glist, mode - IEM_GUI_DRAW_MODE_IO); | ||
220 | } | ||
221 | |||
222 | /* ------------------------ vdl widgetbehaviour----------------------------- */ | ||
223 | |||
224 | static void vradio_getrect(t_gobj *z, t_glist *glist, int *xp1, int *yp1, int *xp2, int *yp2) | ||
225 | { | ||
226 | t_vradio *x = (t_vradio *)z; | ||
227 | |||
228 | *xp1 = text_xpix(&x->x_gui.x_obj, glist); | ||
229 | *yp1 = text_ypix(&x->x_gui.x_obj, glist); | ||
230 | *xp2 = *xp1 + x->x_gui.x_w; | ||
231 | *yp2 = *yp1 + x->x_gui.x_h*x->x_number; | ||
232 | } | ||
233 | |||
234 | static void vradio_save(t_gobj *z, t_binbuf *b) | ||
235 | { | ||
236 | t_vradio *x = (t_vradio *)z; | ||
237 | int bflcol[3]; | ||
238 | t_symbol *srl[3]; | ||
239 | |||
240 | iemgui_save(&x->x_gui, srl, bflcol); | ||
241 | binbuf_addv(b, "ssiisiiiisssiiiiiiii", gensym("#X"),gensym("obj"), | ||
242 | (t_int)x->x_gui.x_obj.te_xpix, | ||
243 | (t_int)x->x_gui.x_obj.te_ypix, | ||
244 | (pd_class(&x->x_gui.x_obj.ob_pd) == vradio_old_class ? | ||
245 | gensym("vdl") : gensym("vradio")), | ||
246 | x->x_gui.x_w, | ||
247 | x->x_change, iem_symargstoint(&x->x_gui.x_isa), x->x_number, | ||
248 | srl[0], srl[1], srl[2], | ||
249 | x->x_gui.x_ldx, x->x_gui.x_ldy, | ||
250 | iem_fstyletoint(&x->x_gui.x_fsf), x->x_gui.x_fontsize, | ||
251 | bflcol[0], bflcol[1], bflcol[2], x->x_on); | ||
252 | binbuf_addv(b, ";"); | ||
253 | } | ||
254 | |||
255 | static void vradio_properties(t_gobj *z, t_glist *owner) | ||
256 | { | ||
257 | t_vradio *x = (t_vradio *)z; | ||
258 | char buf[800]; | ||
259 | t_symbol *srl[3]; | ||
260 | int hchange=-1; | ||
261 | |||
262 | iemgui_properties(&x->x_gui, srl); | ||
263 | if(pd_class(&x->x_gui.x_obj.ob_pd) == vradio_old_class) | ||
264 | hchange = x->x_change; | ||
265 | sprintf(buf, "pdtk_iemgui_dialog %%s vradio \ | ||
266 | ----------dimensions(pix):----------- %d %d size: 0 0 empty \ | ||
267 | empty 0.0 empty 0.0 empty %d \ | ||
268 | %d new-only new&old %d %d number: %d \ | ||
269 | %s %s \ | ||
270 | %s %d %d \ | ||
271 | %d %d \ | ||
272 | %d %d %d\n", | ||
273 | x->x_gui.x_w, IEM_GUI_MINSIZE, | ||
274 | 0,/*no_schedule*/ | ||
275 | hchange, x->x_gui.x_isa.x_loadinit, -1, x->x_number, | ||
276 | srl[0]->s_name, srl[1]->s_name, | ||
277 | srl[2]->s_name, x->x_gui.x_ldx, x->x_gui.x_ldy, | ||
278 | x->x_gui.x_fsf.x_font_style, x->x_gui.x_fontsize, | ||
279 | 0xffffff & x->x_gui.x_bcol, 0xffffff & x->x_gui.x_fcol, 0xffffff & x->x_gui.x_lcol); | ||
280 | gfxstub_new(&x->x_gui.x_obj.ob_pd, x, buf); | ||
281 | } | ||
282 | |||
283 | static void vradio_dialog(t_vradio *x, t_symbol *s, int argc, t_atom *argv) | ||
284 | { | ||
285 | t_symbol *srl[3]; | ||
286 | int a = (int)atom_getintarg(0, argc, argv); | ||
287 | int chg = (int)atom_getintarg(4, argc, argv); | ||
288 | int num = (int)atom_getintarg(6, argc, argv); | ||
289 | int sr_flags; | ||
290 | |||
291 | if(chg != 0) chg = 1; | ||
292 | x->x_change = chg; | ||
293 | sr_flags = iemgui_dialog(&x->x_gui, srl, argc, argv); | ||
294 | x->x_gui.x_w = iemgui_clip_size(a); | ||
295 | x->x_gui.x_h = x->x_gui.x_w; | ||
296 | if(x->x_number != num) | ||
297 | { | ||
298 | (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_ERASE); | ||
299 | x->x_number = num; | ||
300 | if(x->x_on >= x->x_number) | ||
301 | { | ||
302 | x->x_on = x->x_number - 1; | ||
303 | x->x_on_old = x->x_on; | ||
304 | } | ||
305 | (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_NEW); | ||
306 | } | ||
307 | else | ||
308 | { | ||
309 | (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_CONFIG); | ||
310 | (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_IO + sr_flags); | ||
311 | (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_MOVE); | ||
312 | canvas_fixlinesfor(glist_getcanvas(x->x_gui.x_glist), (t_text*)x); | ||
313 | } | ||
314 | } | ||
315 | |||
316 | static void vradio_set(t_vradio *x, t_floatarg f) | ||
317 | { | ||
318 | int i=(int)f; | ||
319 | int old; | ||
320 | |||
321 | if(i < 0) | ||
322 | i = 0; | ||
323 | if(i >= x->x_number) | ||
324 | i = x->x_number-1; | ||
325 | if(x->x_on != x->x_on_old) | ||
326 | { | ||
327 | old = x->x_on_old; | ||
328 | x->x_on_old = x->x_on; | ||
329 | x->x_on = i; | ||
330 | (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE); | ||
331 | x->x_on_old = old; | ||
332 | } | ||
333 | else | ||
334 | { | ||
335 | x->x_on = i; | ||
336 | (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE); | ||
337 | } | ||
338 | } | ||
339 | |||
340 | static void vradio_bang(t_vradio *x) | ||
341 | { | ||
342 | /* compatibility with earlier "vdial" behavior */ | ||
343 | if (pd_class(&x->x_gui.x_obj.ob_pd) == vradio_old_class) | ||
344 | { | ||
345 | if((x->x_change)&&(x->x_on != x->x_on_old)) | ||
346 | { | ||
347 | SETFLOAT(x->x_at, (float)x->x_on_old); | ||
348 | SETFLOAT(x->x_at+1, 0.0); | ||
349 | outlet_list(x->x_gui.x_obj.ob_outlet, &s_list, 2, x->x_at); | ||
350 | if(x->x_gui.x_fsf.x_snd_able && x->x_gui.x_snd->s_thing) | ||
351 | pd_list(x->x_gui.x_snd->s_thing, &s_list, 2, x->x_at); | ||
352 | } | ||
353 | x->x_on_old = x->x_on; | ||
354 | SETFLOAT(x->x_at, (float)x->x_on); | ||
355 | SETFLOAT(x->x_at+1, 1.0); | ||
356 | outlet_list(x->x_gui.x_obj.ob_outlet, &s_list, 2, x->x_at); | ||
357 | if(x->x_gui.x_fsf.x_snd_able && x->x_gui.x_snd->s_thing) | ||
358 | pd_list(x->x_gui.x_snd->s_thing, &s_list, 2, x->x_at); | ||
359 | } | ||
360 | else | ||
361 | { | ||
362 | outlet_float(x->x_gui.x_obj.ob_outlet, x->x_on); | ||
363 | if(x->x_gui.x_fsf.x_snd_able && x->x_gui.x_snd->s_thing) | ||
364 | pd_float(x->x_gui.x_snd->s_thing, x->x_on); | ||
365 | } | ||
366 | } | ||
367 | |||
368 | static void vradio_fout(t_vradio *x, t_floatarg f) | ||
369 | { | ||
370 | int i=(int)f; | ||
371 | |||
372 | if(i < 0) | ||
373 | i = 0; | ||
374 | if(i >= x->x_number) | ||
375 | i = x->x_number-1; | ||
376 | |||
377 | if (pd_class(&x->x_gui.x_obj.ob_pd) == vradio_old_class) | ||
378 | { | ||
379 | /* compatibility with earlier "vdial" behavior */ | ||
380 | if((x->x_change)&&(i != x->x_on_old)) | ||
381 | { | ||
382 | SETFLOAT(x->x_at, (float)x->x_on_old); | ||
383 | SETFLOAT(x->x_at+1, 0.0); | ||
384 | outlet_list(x->x_gui.x_obj.ob_outlet, &s_list, 2, x->x_at); | ||
385 | if(x->x_gui.x_fsf.x_snd_able && x->x_gui.x_snd->s_thing) | ||
386 | pd_list(x->x_gui.x_snd->s_thing, &s_list, 2, x->x_at); | ||
387 | } | ||
388 | if(x->x_on != x->x_on_old) | ||
389 | x->x_on_old = x->x_on; | ||
390 | x->x_on = i; | ||
391 | (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE); | ||
392 | x->x_on_old = x->x_on; | ||
393 | SETFLOAT(x->x_at, (float)x->x_on); | ||
394 | SETFLOAT(x->x_at+1, 1.0); | ||
395 | outlet_list(x->x_gui.x_obj.ob_outlet, &s_list, 2, x->x_at); | ||
396 | if(x->x_gui.x_fsf.x_snd_able && x->x_gui.x_snd->s_thing) | ||
397 | pd_list(x->x_gui.x_snd->s_thing, &s_list, 2, x->x_at); | ||
398 | } | ||
399 | else | ||
400 | { | ||
401 | x->x_on_old = x->x_on; | ||
402 | x->x_on = i; | ||
403 | (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE); | ||
404 | outlet_float(x->x_gui.x_obj.ob_outlet, x->x_on); | ||
405 | if (x->x_gui.x_fsf.x_snd_able && x->x_gui.x_snd->s_thing) | ||
406 | pd_float(x->x_gui.x_snd->s_thing, x->x_on); | ||
407 | } | ||
408 | } | ||
409 | |||
410 | static void vradio_float(t_vradio *x, t_floatarg f) | ||
411 | { | ||
412 | int i=(int)f; | ||
413 | |||
414 | if(i < 0) | ||
415 | i = 0; | ||
416 | if(i >= x->x_number) | ||
417 | i = x->x_number-1; | ||
418 | |||
419 | if (pd_class(&x->x_gui.x_obj.ob_pd) == vradio_old_class) | ||
420 | { | ||
421 | /* compatibility with earlier "vdial" behavior */ | ||
422 | if((x->x_change)&&(i != x->x_on_old)) | ||
423 | { | ||
424 | if(x->x_gui.x_fsf.x_put_in2out) | ||
425 | { | ||
426 | SETFLOAT(x->x_at, (float)x->x_on_old); | ||
427 | SETFLOAT(x->x_at+1, 0.0); | ||
428 | outlet_list(x->x_gui.x_obj.ob_outlet, &s_list, 2, x->x_at); | ||
429 | if(x->x_gui.x_fsf.x_snd_able && x->x_gui.x_snd->s_thing) | ||
430 | pd_list(x->x_gui.x_snd->s_thing, &s_list, 2, x->x_at); | ||
431 | } | ||
432 | } | ||
433 | if(x->x_on != x->x_on_old) | ||
434 | x->x_on_old = x->x_on; | ||
435 | x->x_on = i; | ||
436 | (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE); | ||
437 | x->x_on_old = x->x_on; | ||
438 | if(x->x_gui.x_fsf.x_put_in2out) | ||
439 | { | ||
440 | SETFLOAT(x->x_at, (float)x->x_on); | ||
441 | SETFLOAT(x->x_at+1, 1.0); | ||
442 | outlet_list(x->x_gui.x_obj.ob_outlet, &s_list, 2, x->x_at); | ||
443 | if(x->x_gui.x_fsf.x_snd_able && x->x_gui.x_snd->s_thing) | ||
444 | pd_list(x->x_gui.x_snd->s_thing, &s_list, 2, x->x_at); | ||
445 | } | ||
446 | } | ||
447 | else | ||
448 | { | ||
449 | x->x_on_old = x->x_on; | ||
450 | x->x_on = i; | ||
451 | (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE); | ||
452 | if (x->x_gui.x_fsf.x_put_in2out) | ||
453 | { | ||
454 | outlet_float(x->x_gui.x_obj.ob_outlet, x->x_on); | ||
455 | if(x->x_gui.x_fsf.x_snd_able && x->x_gui.x_snd->s_thing) | ||
456 | pd_float(x->x_gui.x_snd->s_thing, x->x_on); | ||
457 | } | ||
458 | } | ||
459 | } | ||
460 | |||
461 | static void vradio_click(t_vradio *x, t_floatarg xpos, t_floatarg ypos, | ||
462 | t_floatarg shift, t_floatarg ctrl, t_floatarg alt) | ||
463 | { | ||
464 | int yy = (int)ypos - text_ypix(&x->x_gui.x_obj, x->x_gui.x_glist); | ||
465 | |||
466 | vradio_fout(x, (float)(yy / x->x_gui.x_h)); | ||
467 | } | ||
468 | |||
469 | static int vradio_newclick(t_gobj *z, struct _glist *glist, | ||
470 | int xpix, int ypix, int shift, int alt, int dbl, int doit) | ||
471 | { | ||
472 | if(doit) | ||
473 | vradio_click((t_vradio *)z, (t_floatarg)xpix, (t_floatarg)ypix, | ||
474 | (t_floatarg)shift, 0, (t_floatarg)alt); | ||
475 | return (1); | ||
476 | } | ||
477 | |||
478 | static void vradio_loadbang(t_vradio *x) | ||
479 | { | ||
480 | if(!sys_noloadbang && x->x_gui.x_isa.x_loadinit) | ||
481 | vradio_bang(x); | ||
482 | } | ||
483 | |||
484 | static void vradio_number(t_vradio *x, t_floatarg num) | ||
485 | { | ||
486 | int n=(int)num; | ||
487 | |||
488 | if(n < 1) | ||
489 | n = 1; | ||
490 | if(n > IEM_RADIO_MAX) | ||
491 | n = IEM_RADIO_MAX; | ||
492 | if(n != x->x_number) | ||
493 | { | ||
494 | (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_ERASE); | ||
495 | x->x_number = n; | ||
496 | if(x->x_on >= x->x_number) | ||
497 | x->x_on = x->x_number - 1; | ||
498 | x->x_on_old = x->x_on; | ||
499 | (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_NEW); | ||
500 | } | ||
501 | } | ||
502 | |||
503 | static void vradio_size(t_vradio *x, t_symbol *s, int ac, t_atom *av) | ||
504 | { | ||
505 | x->x_gui.x_w = iemgui_clip_size((int)atom_getintarg(0, ac, av)); | ||
506 | x->x_gui.x_h = x->x_gui.x_w; | ||
507 | iemgui_size((void *)x, &x->x_gui); | ||
508 | } | ||
509 | |||
510 | static void vradio_delta(t_vradio *x, t_symbol *s, int ac, t_atom *av) | ||
511 | {iemgui_delta((void *)x, &x->x_gui, s, ac, av);} | ||
512 | |||
513 | static void vradio_pos(t_vradio *x, t_symbol *s, int ac, t_atom *av) | ||
514 | {iemgui_pos((void *)x, &x->x_gui, s, ac, av);} | ||
515 | |||
516 | static void vradio_color(t_vradio *x, t_symbol *s, int ac, t_atom *av) | ||
517 | {iemgui_color((void *)x, &x->x_gui, s, ac, av);} | ||
518 | |||
519 | static void vradio_send(t_vradio *x, t_symbol *s) | ||
520 | {iemgui_send(x, &x->x_gui, s);} | ||
521 | |||
522 | static void vradio_receive(t_vradio *x, t_symbol *s) | ||
523 | {iemgui_receive(x, &x->x_gui, s);} | ||
524 | |||
525 | static void vradio_label(t_vradio *x, t_symbol *s) | ||
526 | {iemgui_label((void *)x, &x->x_gui, s);} | ||
527 | |||
528 | static void vradio_label_pos(t_vradio *x, t_symbol *s, int ac, t_atom *av) | ||
529 | {iemgui_label_pos((void *)x, &x->x_gui, s, ac, av);} | ||
530 | |||
531 | static void vradio_label_font(t_vradio *x, t_symbol *s, int ac, t_atom *av) | ||
532 | {iemgui_label_font((void *)x, &x->x_gui, s, ac, av);} | ||
533 | |||
534 | static void vradio_init(t_vradio *x, t_floatarg f) | ||
535 | { | ||
536 | x->x_gui.x_isa.x_loadinit = (f==0.0)?0:1; | ||
537 | } | ||
538 | |||
539 | static void vradio_double_change(t_vradio *x) | ||
540 | {x->x_change = 1;} | ||
541 | |||
542 | static void vradio_single_change(t_vradio *x) | ||
543 | {x->x_change = 0;} | ||
544 | |||
545 | static void *vradio_donew(t_symbol *s, int argc, t_atom *argv, int old) | ||
546 | { | ||
547 | t_vradio *x = (t_vradio *)pd_new(old? vradio_old_class : vradio_class); | ||
548 | int bflcol[]={-262144, -1, -1}; | ||
549 | int a=IEM_GUI_DEFAULTSIZE, on=0, f=0; | ||
550 | int ldx=0, ldy=-6, chg=1, num=8; | ||
551 | int fs=8; | ||
552 | int ftbreak=IEM_BNG_DEFAULTBREAKFLASHTIME, fthold=IEM_BNG_DEFAULTHOLDFLASHTIME; | ||
553 | char str[144]; | ||
554 | |||
555 | if((argc == 15)&&IS_A_FLOAT(argv,0)&&IS_A_FLOAT(argv,1)&&IS_A_FLOAT(argv,2) | ||
556 | &&IS_A_FLOAT(argv,3) | ||
557 | &&(IS_A_SYMBOL(argv,4)||IS_A_FLOAT(argv,4)) | ||
558 | &&(IS_A_SYMBOL(argv,5)||IS_A_FLOAT(argv,5)) | ||
559 | &&(IS_A_SYMBOL(argv,6)||IS_A_FLOAT(argv,6)) | ||
560 | &&IS_A_FLOAT(argv,7)&&IS_A_FLOAT(argv,8) | ||
561 | &&IS_A_FLOAT(argv,9)&&IS_A_FLOAT(argv,10)&&IS_A_FLOAT(argv,11) | ||
562 | &&IS_A_FLOAT(argv,12)&&IS_A_FLOAT(argv,13)&&IS_A_FLOAT(argv,14)) | ||
563 | { | ||
564 | a = (int)atom_getintarg(0, argc, argv); | ||
565 | chg = (int)atom_getintarg(1, argc, argv); | ||
566 | iem_inttosymargs(&x->x_gui.x_isa, atom_getintarg(2, argc, argv)); | ||
567 | num = (int)atom_getintarg(3, argc, argv); | ||
568 | iemgui_new_getnames(&x->x_gui, 4, argv); | ||
569 | ldx = (int)atom_getintarg(7, argc, argv); | ||
570 | ldy = (int)atom_getintarg(8, argc, argv); | ||
571 | iem_inttofstyle(&x->x_gui.x_fsf, atom_getintarg(9, argc, argv)); | ||
572 | fs = (int)atom_getintarg(10, argc, argv); | ||
573 | bflcol[0] = (int)atom_getintarg(11, argc, argv); | ||
574 | bflcol[1] = (int)atom_getintarg(12, argc, argv); | ||
575 | bflcol[2] = (int)atom_getintarg(13, argc, argv); | ||
576 | on = (int)atom_getintarg(14, argc, argv); | ||
577 | } | ||
578 | else iemgui_new_getnames(&x->x_gui, 4, 0); | ||
579 | x->x_gui.x_draw = (t_iemfunptr)vradio_draw; | ||
580 | x->x_gui.x_fsf.x_snd_able = 1; | ||
581 | x->x_gui.x_fsf.x_rcv_able = 1; | ||
582 | x->x_gui.x_glist = (t_glist *)canvas_getcurrent(); | ||
583 | if (!strcmp(x->x_gui.x_snd->s_name, "empty")) | ||
584 | x->x_gui.x_fsf.x_snd_able = 0; | ||
585 | if (!strcmp(x->x_gui.x_rcv->s_name, "empty")) | ||
586 | x->x_gui.x_fsf.x_rcv_able = 0; | ||
587 | if(x->x_gui.x_fsf.x_font_style == 1) strcpy(x->x_gui.x_font, "helvetica"); | ||
588 | else if(x->x_gui.x_fsf.x_font_style == 2) strcpy(x->x_gui.x_font, "times"); | ||
589 | else { x->x_gui.x_fsf.x_font_style = 0; | ||
590 | strcpy(x->x_gui.x_font, "courier"); } | ||
591 | if(num < 1) | ||
592 | num = 1; | ||
593 | if(num > IEM_RADIO_MAX) | ||
594 | num = IEM_RADIO_MAX; | ||
595 | x->x_number = num; | ||
596 | if(on < 0) | ||
597 | on = 0; | ||
598 | if(on >= x->x_number) | ||
599 | on = x->x_number - 1; | ||
600 | if(x->x_gui.x_isa.x_loadinit) | ||
601 | x->x_on = on; | ||
602 | else | ||
603 | x->x_on = 0; | ||
604 | x->x_on_old = x->x_on; | ||
605 | x->x_change = (chg==0)?0:1; | ||
606 | if (x->x_gui.x_fsf.x_rcv_able) | ||
607 | pd_bind(&x->x_gui.x_obj.ob_pd, x->x_gui.x_rcv); | ||
608 | x->x_gui.x_ldx = ldx; | ||
609 | x->x_gui.x_ldy = ldy; | ||
610 | if(fs < 4) | ||
611 | fs = 4; | ||
612 | x->x_gui.x_fontsize = fs; | ||
613 | x->x_gui.x_w = iemgui_clip_size(a); | ||
614 | x->x_gui.x_h = x->x_gui.x_w; | ||
615 | iemgui_verify_snd_ne_rcv(&x->x_gui); | ||
616 | iemgui_all_colfromload(&x->x_gui, bflcol); | ||
617 | outlet_new(&x->x_gui.x_obj, &s_list); | ||
618 | return (x); | ||
619 | } | ||
620 | |||
621 | static void *vradio_new(t_symbol *s, int argc, t_atom *argv) | ||
622 | { | ||
623 | return (vradio_donew(s, argc, argv, 0)); | ||
624 | } | ||
625 | |||
626 | static void *vdial_new(t_symbol *s, int argc, t_atom *argv) | ||
627 | { | ||
628 | return (vradio_donew(s, argc, argv, 1)); | ||
629 | } | ||
630 | |||
631 | static void vradio_ff(t_vradio *x) | ||
632 | { | ||
633 | if(x->x_gui.x_fsf.x_rcv_able) | ||
634 | pd_unbind(&x->x_gui.x_obj.ob_pd, x->x_gui.x_rcv); | ||
635 | gfxstub_deleteforkey(x); | ||
636 | } | ||
637 | |||
638 | void g_vradio_setup(void) | ||
639 | { | ||
640 | vradio_class = class_new(gensym("vradio"), (t_newmethod)vradio_new, | ||
641 | (t_method)vradio_ff, sizeof(t_vradio), 0, A_GIMME, 0); | ||
642 | class_addbang(vradio_class, vradio_bang); | ||
643 | class_addfloat(vradio_class, vradio_float); | ||
644 | class_addmethod(vradio_class, (t_method)vradio_click, gensym("click"), | ||
645 | A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, 0); | ||
646 | class_addmethod(vradio_class, (t_method)vradio_dialog, gensym("dialog"), | ||
647 | A_GIMME, 0); | ||
648 | class_addmethod(vradio_class, (t_method)vradio_loadbang, | ||
649 | gensym("loadbang"), 0); | ||
650 | class_addmethod(vradio_class, (t_method)vradio_set, | ||
651 | gensym("set"), A_FLOAT, 0); | ||
652 | class_addmethod(vradio_class, (t_method)vradio_size, | ||
653 | gensym("size"), A_GIMME, 0); | ||
654 | class_addmethod(vradio_class, (t_method)vradio_delta, | ||
655 | gensym("delta"), A_GIMME, 0); | ||
656 | class_addmethod(vradio_class, (t_method)vradio_pos, | ||
657 | gensym("pos"), A_GIMME, 0); | ||
658 | class_addmethod(vradio_class, (t_method)vradio_color, | ||
659 | gensym("color"), A_GIMME, 0); | ||
660 | class_addmethod(vradio_class, (t_method)vradio_send, | ||
661 | gensym("send"), A_DEFSYM, 0); | ||
662 | class_addmethod(vradio_class, (t_method)vradio_receive, | ||
663 | gensym("receive"), A_DEFSYM, 0); | ||
664 | class_addmethod(vradio_class, (t_method)vradio_label, | ||
665 | gensym("label"), A_DEFSYM, 0); | ||
666 | class_addmethod(vradio_class, (t_method)vradio_label_pos, | ||
667 | gensym("label_pos"), A_GIMME, 0); | ||
668 | class_addmethod(vradio_class, (t_method)vradio_label_font, | ||
669 | gensym("label_font"), A_GIMME, 0); | ||
670 | class_addmethod(vradio_class, (t_method)vradio_init, | ||
671 | gensym("init"), A_FLOAT, 0); | ||
672 | class_addmethod(vradio_class, (t_method)vradio_number, | ||
673 | gensym("number"), A_FLOAT, 0); | ||
674 | class_addmethod(vradio_class, (t_method)vradio_single_change, | ||
675 | gensym("single_change"), 0); | ||
676 | class_addmethod(vradio_class, (t_method)vradio_double_change, | ||
677 | gensym("double_change"), 0); | ||
678 | vradio_widgetbehavior.w_getrectfn = vradio_getrect; | ||
679 | vradio_widgetbehavior.w_displacefn = iemgui_displace; | ||
680 | vradio_widgetbehavior.w_selectfn = iemgui_select; | ||
681 | vradio_widgetbehavior.w_activatefn = NULL; | ||
682 | vradio_widgetbehavior.w_deletefn = iemgui_delete; | ||
683 | vradio_widgetbehavior.w_visfn = iemgui_vis; | ||
684 | vradio_widgetbehavior.w_clickfn = vradio_newclick; | ||
685 | class_setwidget(vradio_class, &vradio_widgetbehavior); | ||
686 | class_sethelpsymbol(vradio_class, gensym("vradio")); | ||
687 | class_setsavefn(vradio_class, vradio_save); | ||
688 | class_setpropertiesfn(vradio_class, vradio_properties); | ||
689 | |||
690 | /* obsolete version (0.34-0.35) */ | ||
691 | vradio_old_class = class_new(gensym("vdl"), (t_newmethod)vdial_new, | ||
692 | (t_method)vradio_ff, sizeof(t_vradio), 0, A_GIMME, 0); | ||
693 | class_addbang(vradio_old_class, vradio_bang); | ||
694 | class_addfloat(vradio_old_class, vradio_float); | ||
695 | class_addmethod(vradio_old_class, (t_method)vradio_click, gensym("click"), | ||
696 | A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, 0); | ||
697 | class_addmethod(vradio_old_class, (t_method)vradio_dialog, gensym("dialog"), | ||
698 | A_GIMME, 0); | ||
699 | class_addmethod(vradio_old_class, (t_method)vradio_loadbang, gensym("loadbang"), 0); | ||
700 | class_addmethod(vradio_old_class, (t_method)vradio_set, gensym("set"), A_FLOAT, 0); | ||
701 | class_addmethod(vradio_old_class, (t_method)vradio_size, gensym("size"), A_GIMME, 0); | ||
702 | class_addmethod(vradio_old_class, (t_method)vradio_delta, gensym("delta"), A_GIMME, 0); | ||
703 | class_addmethod(vradio_old_class, (t_method)vradio_pos, gensym("pos"), A_GIMME, 0); | ||
704 | class_addmethod(vradio_old_class, (t_method)vradio_color, gensym("color"), A_GIMME, 0); | ||
705 | class_addmethod(vradio_old_class, (t_method)vradio_send, gensym("send"), A_DEFSYM, 0); | ||
706 | class_addmethod(vradio_old_class, (t_method)vradio_receive, gensym("receive"), A_DEFSYM, 0); | ||
707 | class_addmethod(vradio_old_class, (t_method)vradio_label, gensym("label"), A_DEFSYM, 0); | ||
708 | class_addmethod(vradio_old_class, (t_method)vradio_label_pos, gensym("label_pos"), A_GIMME, 0); | ||
709 | class_addmethod(vradio_old_class, (t_method)vradio_label_font, gensym("label_font"), A_GIMME, 0); | ||
710 | class_addmethod(vradio_old_class, (t_method)vradio_init, gensym("init"), A_FLOAT, 0); | ||
711 | class_addmethod(vradio_old_class, (t_method)vradio_number, gensym("number"), A_FLOAT, 0); | ||
712 | class_addmethod(vradio_old_class, (t_method)vradio_single_change, gensym("single_change"), 0); | ||
713 | class_addmethod(vradio_old_class, (t_method)vradio_double_change, gensym("double_change"), 0); | ||
714 | class_setwidget(vradio_old_class, &vradio_widgetbehavior); | ||
715 | class_sethelpsymbol(vradio_old_class, gensym("vradio")); | ||
716 | } | ||
717 | /* Copyright (c) 1997-1999 Miller Puckette. | ||
718 | * For information on usage and redistribution, and for a DISCLAIMER OF ALL | ||
719 | * WARRANTIES, see the file, "LICENSE.txt," in this distribution. */ | ||
720 | |||
721 | /* vdial.c written by Thomas Musil (c) IEM KUG Graz Austria 2000-2001 */ | ||
722 | |||
723 | /* name change to vradio by MSP (it's a radio button really) and changed to | ||
724 | put out a "float" as in sliders, toggles, etc. */ | ||
725 | |||
726 | #include <stdlib.h> | ||
727 | #include <string.h> | ||
728 | #include <stdio.h> | ||
729 | #include <ctype.h> | ||
730 | #include "m_pd.h" | ||
731 | #include "g_canvas.h" | ||
732 | #include "t_tk.h" | ||
733 | #include "g_all_guis.h" | ||
734 | #include <math.h> | ||
735 | |||
736 | /*------------------ global variables -------------------------*/ | ||
737 | |||
738 | |||
739 | /*------------------ global functions -------------------------*/ | ||
740 | |||
741 | |||
742 | |||
743 | |||
744 | /* ------------- vdl gui-vertical radio button ---------------------- */ | ||
745 | |||
746 | t_widgetbehavior vradio_widgetbehavior; | ||
747 | static t_class *vradio_class, *vradio_old_class; | ||
748 | |||
749 | /* widget helper functions */ | ||
750 | |||
751 | void vradio_draw_update(t_vradio *x, t_glist *glist) | ||
752 | { | ||
753 | if(glist_isvisible(glist)) | ||
754 | { | ||
755 | t_canvas *canvas=glist_getcanvas(glist); | ||
756 | |||
757 | sys_vgui(".x%x.c itemconfigure %xBUT%d -fill #%6.6x -outline #%6.6x\n", | ||
758 | canvas, x, x->x_on_old, | ||
759 | x->x_gui.x_bcol, x->x_gui.x_bcol); | ||
760 | sys_vgui(".x%x.c itemconfigure %xBUT%d -fill #%6.6x -outline #%6.6x\n", | ||
761 | canvas, x, x->x_on, | ||
762 | x->x_gui.x_fcol, x->x_gui.x_fcol); | ||
763 | } | ||
764 | } | ||
765 | |||
766 | void vradio_draw_new(t_vradio *x, t_glist *glist) | ||
767 | { | ||
768 | t_canvas *canvas=glist_getcanvas(glist); | ||
769 | int n=x->x_number, i, dy=x->x_gui.x_h, s4=dy/4; | ||
770 | int yy11b=text_ypix(&x->x_gui.x_obj, glist); | ||
771 | int yy11=yy11b, yy12=yy11+dy; | ||
772 | int yy21=yy11+s4, yy22=yy12-s4; | ||
773 | int xx11=text_xpix(&x->x_gui.x_obj, glist), xx12=xx11+dy; | ||
774 | int xx21=xx11+s4, xx22=xx12-s4; | ||
775 | |||
776 | for(i=0; i<n; i++) | ||
777 | { | ||
778 | sys_vgui(".x%x.c create rectangle %d %d %d %d -fill #%6.6x -tags %xBASE%d\n", | ||
779 | canvas, xx11, yy11, xx12, yy12, | ||
780 | x->x_gui.x_bcol, x, i); | ||
781 | sys_vgui(".x%x.c create rectangle %d %d %d %d -fill #%6.6x -outline #%6.6x -tags %xBUT%d\n", | ||
782 | canvas, xx21, yy21, xx22, yy22, | ||
783 | (x->x_on==i)?x->x_gui.x_fcol:x->x_gui.x_bcol, | ||
784 | (x->x_on==i)?x->x_gui.x_fcol:x->x_gui.x_bcol, x, i); | ||
785 | yy11 += dy; | ||
786 | yy12 += dy; | ||
787 | yy21 += dy; | ||
788 | yy22 += dy; | ||
789 | } | ||
790 | sys_vgui(".x%x.c create text %d %d -text {%s} -anchor w \ | ||
791 | -font {%s %d bold} -fill #%6.6x -tags %xLABEL\n", | ||
792 | canvas, xx11+x->x_gui.x_ldx, yy11b+x->x_gui.x_ldy, | ||
793 | strcmp(x->x_gui.x_lab->s_name, "empty")?x->x_gui.x_lab->s_name:"", | ||
794 | x->x_gui.x_font, x->x_gui.x_fontsize, | ||
795 | x->x_gui.x_lcol, x); | ||
796 | if(!x->x_gui.x_fsf.x_snd_able) | ||
797 | sys_vgui(".x%x.c create rectangle %d %d %d %d -tags %xOUT%d\n", | ||
798 | canvas, xx11, yy11-1, xx11 + IOWIDTH, yy11, x, 0); | ||
799 | if(!x->x_gui.x_fsf.x_rcv_able) | ||
800 | sys_vgui(".x%x.c create rectangle %d %d %d %d -tags %xIN%d\n", | ||
801 | canvas, xx11, yy11b, xx11 + IOWIDTH, yy11b+1, x, 0); | ||
802 | } | ||
803 | |||
804 | void vradio_draw_move(t_vradio *x, t_glist *glist) | ||
805 | { | ||
806 | t_canvas *canvas=glist_getcanvas(glist); | ||
807 | int n=x->x_number, i, dy=x->x_gui.x_h, s4=dy/4; | ||
808 | int yy11b=text_ypix(&x->x_gui.x_obj, glist); | ||
809 | int yy11=yy11b, yy12=yy11+dy; | ||
810 | int yy21=yy11+s4, yy22=yy12-s4; | ||
811 | int xx11=text_xpix(&x->x_gui.x_obj, glist), xx12=xx11+dy; | ||
812 | int xx21=xx11+s4, xx22=xx12-s4; | ||
813 | |||
814 | for(i=0; i<n; i++) | ||
815 | { | ||
816 | sys_vgui(".x%x.c coords %xBASE%d %d %d %d %d\n", | ||
817 | canvas, x, i, xx11, yy11, xx12, yy12); | ||
818 | sys_vgui(".x%x.c coords %xBUT%d %d %d %d %d\n", | ||
819 | canvas, x, i, xx21, yy21, xx22, yy22); | ||
820 | yy11 += dy; | ||
821 | yy12 += dy; | ||
822 | yy21 += dy; | ||
823 | yy22 += dy; | ||
824 | } | ||
825 | sys_vgui(".x%x.c coords %xLABEL %d %d\n", | ||
826 | canvas, x, xx11+x->x_gui.x_ldx, yy11b+x->x_gui.x_ldy); | ||
827 | if(!x->x_gui.x_fsf.x_snd_able) | ||
828 | sys_vgui(".x%x.c coords %xOUT%d %d %d %d %d\n", | ||
829 | canvas, x, 0, xx11, yy11-1, xx11 + IOWIDTH, yy11); | ||
830 | if(!x->x_gui.x_fsf.x_rcv_able) | ||
831 | sys_vgui(".x%x.c coords %xIN%d %d %d %d %d\n", | ||
832 | canvas, x, 0, xx11, yy11b, xx11 + IOWIDTH, yy11b+1); | ||
833 | } | ||
834 | |||
835 | void vradio_draw_erase(t_vradio* x, t_glist* glist) | ||
836 | { | ||
837 | t_canvas *canvas=glist_getcanvas(glist); | ||
838 | int n=x->x_number, i; | ||
839 | |||
840 | for(i=0; i<n; i++) | ||
841 | { | ||
842 | sys_vgui(".x%x.c delete %xBASE%d\n", canvas, x, i); | ||
843 | sys_vgui(".x%x.c delete %xBUT%d\n", canvas, x, i); | ||
844 | } | ||
845 | sys_vgui(".x%x.c delete %xLABEL\n", canvas, x); | ||
846 | if(!x->x_gui.x_fsf.x_snd_able) | ||
847 | sys_vgui(".x%x.c delete %xOUT%d\n", canvas, x, 0); | ||
848 | if(!x->x_gui.x_fsf.x_rcv_able) | ||
849 | sys_vgui(".x%x.c delete %xIN%d\n", canvas, x, 0); | ||
850 | } | ||
851 | |||
852 | void vradio_draw_config(t_vradio* x, t_glist* glist) | ||
853 | { | ||
854 | t_canvas *canvas=glist_getcanvas(glist); | ||
855 | int n=x->x_number, i; | ||
856 | |||
857 | sys_vgui(".x%x.c itemconfigure %xLABEL -font {%s %d bold} -fill #%6.6x -text {%s} \n", | ||
858 | canvas, x, x->x_gui.x_font, x->x_gui.x_fontsize, | ||
859 | x->x_gui.x_fsf.x_selected?IEM_GUI_COLOR_SELECTED:x->x_gui.x_lcol, | ||
860 | strcmp(x->x_gui.x_lab->s_name, "empty")?x->x_gui.x_lab->s_name:""); | ||
861 | for(i=0; i<n; i++) | ||
862 | { | ||
863 | sys_vgui(".x%x.c itemconfigure %xBASE%d -fill #%6.6x\n", canvas, x, i, | ||
864 | x->x_gui.x_bcol); | ||
865 | sys_vgui(".x%x.c itemconfigure %xBUT%d -fill #%6.6x -outline #%6.6x\n", canvas, x, i, | ||
866 | (x->x_on==i)?x->x_gui.x_fcol:x->x_gui.x_bcol, | ||
867 | (x->x_on==i)?x->x_gui.x_fcol:x->x_gui.x_bcol); | ||
868 | } | ||
869 | } | ||
870 | |||
871 | void vradio_draw_io(t_vradio* x, t_glist* glist, int old_snd_rcv_flags) | ||
872 | { | ||
873 | t_canvas *canvas=glist_getcanvas(glist); | ||
874 | int xpos=text_xpix(&x->x_gui.x_obj, glist); | ||
875 | int ypos=text_ypix(&x->x_gui.x_obj, glist); | ||
876 | |||
877 | if((old_snd_rcv_flags & IEM_GUI_OLD_SND_FLAG) && !x->x_gui.x_fsf.x_snd_able) | ||
878 | sys_vgui(".x%x.c create rectangle %d %d %d %d -tags %xOUT%d\n", | ||
879 | canvas, xpos, | ||
880 | ypos+(x->x_number*x->x_gui.x_h)-1, | ||
881 | xpos+ IOWIDTH, | ||
882 | ypos+(x->x_number*x->x_gui.x_h), x, 0); | ||
883 | if(!(old_snd_rcv_flags & IEM_GUI_OLD_SND_FLAG) && x->x_gui.x_fsf.x_snd_able) | ||
884 | sys_vgui(".x%x.c delete %xOUT%d\n", canvas, x, 0); | ||
885 | if((old_snd_rcv_flags & IEM_GUI_OLD_RCV_FLAG) && !x->x_gui.x_fsf.x_rcv_able) | ||
886 | sys_vgui(".x%x.c create rectangle %d %d %d %d -tags %xIN%d\n", | ||
887 | canvas, xpos, ypos, | ||
888 | xpos+ IOWIDTH, ypos+1, | ||
889 | x, 0); | ||
890 | if(!(old_snd_rcv_flags & IEM_GUI_OLD_RCV_FLAG) && x->x_gui.x_fsf.x_rcv_able) | ||
891 | sys_vgui(".x%x.c delete %xIN%d\n", canvas, x, 0); | ||
892 | } | ||
893 | |||
894 | void vradio_draw_select(t_vradio* x, t_glist* glist) | ||
895 | { | ||
896 | t_canvas *canvas=glist_getcanvas(glist); | ||
897 | int n=x->x_number, i; | ||
898 | |||
899 | if(x->x_gui.x_fsf.x_selected) | ||
900 | { | ||
901 | for(i=0; i<n; i++) | ||
902 | { | ||
903 | sys_vgui(".x%x.c itemconfigure %xBASE%d -outline #%6.6x\n", canvas, x, i, | ||
904 | IEM_GUI_COLOR_SELECTED); | ||
905 | } | ||
906 | sys_vgui(".x%x.c itemconfigure %xLABEL -fill #%6.6x\n", canvas, x, IEM_GUI_COLOR_SELECTED); | ||
907 | } | ||
908 | else | ||
909 | { | ||
910 | for(i=0; i<n; i++) | ||
911 | { | ||
912 | sys_vgui(".x%x.c itemconfigure %xBASE%d -outline #%6.6x\n", canvas, x, i, | ||
913 | IEM_GUI_COLOR_NORMAL); | ||
914 | } | ||
915 | sys_vgui(".x%x.c itemconfigure %xLABEL -fill #%6.6x\n", canvas, x, | ||
916 | x->x_gui.x_lcol); | ||
917 | } | ||
918 | } | ||
919 | |||
920 | void vradio_draw(t_vradio *x, t_glist *glist, int mode) | ||
921 | { | ||
922 | if(mode == IEM_GUI_DRAW_MODE_UPDATE) | ||
923 | vradio_draw_update(x, glist); | ||
924 | else if(mode == IEM_GUI_DRAW_MODE_MOVE) | ||
925 | vradio_draw_move(x, glist); | ||
926 | else if(mode == IEM_GUI_DRAW_MODE_NEW) | ||
927 | vradio_draw_new(x, glist); | ||
928 | else if(mode == IEM_GUI_DRAW_MODE_SELECT) | ||
929 | vradio_draw_select(x, glist); | ||
930 | else if(mode == IEM_GUI_DRAW_MODE_ERASE) | ||
931 | vradio_draw_erase(x, glist); | ||
932 | else if(mode == IEM_GUI_DRAW_MODE_CONFIG) | ||
933 | vradio_draw_config(x, glist); | ||
934 | else if(mode >= IEM_GUI_DRAW_MODE_IO) | ||
935 | vradio_draw_io(x, glist, mode - IEM_GUI_DRAW_MODE_IO); | ||
936 | } | ||
937 | |||
938 | /* ------------------------ vdl widgetbehaviour----------------------------- */ | ||
939 | |||
940 | static void vradio_getrect(t_gobj *z, t_glist *glist, int *xp1, int *yp1, int *xp2, int *yp2) | ||
941 | { | ||
942 | t_vradio *x = (t_vradio *)z; | ||
943 | |||
944 | *xp1 = text_xpix(&x->x_gui.x_obj, glist); | ||
945 | *yp1 = text_ypix(&x->x_gui.x_obj, glist); | ||
946 | *xp2 = *xp1 + x->x_gui.x_w; | ||
947 | *yp2 = *yp1 + x->x_gui.x_h*x->x_number; | ||
948 | } | ||
949 | |||
950 | static void vradio_save(t_gobj *z, t_binbuf *b) | ||
951 | { | ||
952 | t_vradio *x = (t_vradio *)z; | ||
953 | int bflcol[3]; | ||
954 | t_symbol *srl[3]; | ||
955 | |||
956 | iemgui_save(&x->x_gui, srl, bflcol); | ||
957 | binbuf_addv(b, "ssiisiiiisssiiiiiiii", gensym("#X"),gensym("obj"), | ||
958 | (t_int)x->x_gui.x_obj.te_xpix, | ||
959 | (t_int)x->x_gui.x_obj.te_ypix, | ||
960 | (pd_class(&x->x_gui.x_obj.ob_pd) == vradio_old_class ? | ||
961 | gensym("vdl") : gensym("vradio")), | ||
962 | x->x_gui.x_w, | ||
963 | x->x_change, iem_symargstoint(&x->x_gui.x_isa), x->x_number, | ||
964 | srl[0], srl[1], srl[2], | ||
965 | x->x_gui.x_ldx, x->x_gui.x_ldy, | ||
966 | iem_fstyletoint(&x->x_gui.x_fsf), x->x_gui.x_fontsize, | ||
967 | bflcol[0], bflcol[1], bflcol[2], x->x_on); | ||
968 | binbuf_addv(b, ";"); | ||
969 | } | ||
970 | |||
971 | static void vradio_properties(t_gobj *z, t_glist *owner) | ||
972 | { | ||
973 | t_vradio *x = (t_vradio *)z; | ||
974 | char buf[800]; | ||
975 | t_symbol *srl[3]; | ||
976 | int hchange=-1; | ||
977 | |||
978 | iemgui_properties(&x->x_gui, srl); | ||
979 | if(pd_class(&x->x_gui.x_obj.ob_pd) == vradio_old_class) | ||
980 | hchange = x->x_change; | ||
981 | sprintf(buf, "pdtk_iemgui_dialog %%s vradio \ | ||
982 | ----------dimensions(pix):----------- %d %d size: 0 0 empty \ | ||
983 | empty 0.0 empty 0.0 empty %d \ | ||
984 | %d new-only new&old %d %d number: %d \ | ||
985 | %s %s \ | ||
986 | %s %d %d \ | ||
987 | %d %d \ | ||
988 | %d %d %d\n", | ||
989 | x->x_gui.x_w, IEM_GUI_MINSIZE, | ||
990 | 0,/*no_schedule*/ | ||
991 | hchange, x->x_gui.x_isa.x_loadinit, -1, x->x_number, | ||
992 | srl[0]->s_name, srl[1]->s_name, | ||
993 | srl[2]->s_name, x->x_gui.x_ldx, x->x_gui.x_ldy, | ||
994 | x->x_gui.x_fsf.x_font_style, x->x_gui.x_fontsize, | ||
995 | 0xffffff & x->x_gui.x_bcol, 0xffffff & x->x_gui.x_fcol, 0xffffff & x->x_gui.x_lcol); | ||
996 | gfxstub_new(&x->x_gui.x_obj.ob_pd, x, buf); | ||
997 | } | ||
998 | |||
999 | static void vradio_dialog(t_vradio *x, t_symbol *s, int argc, t_atom *argv) | ||
1000 | { | ||
1001 | t_symbol *srl[3]; | ||
1002 | int a = (int)atom_getintarg(0, argc, argv); | ||
1003 | int chg = (int)atom_getintarg(4, argc, argv); | ||
1004 | int num = (int)atom_getintarg(6, argc, argv); | ||
1005 | int sr_flags; | ||
1006 | |||
1007 | if(chg != 0) chg = 1; | ||
1008 | x->x_change = chg; | ||
1009 | sr_flags = iemgui_dialog(&x->x_gui, srl, argc, argv); | ||
1010 | x->x_gui.x_w = iemgui_clip_size(a); | ||
1011 | x->x_gui.x_h = x->x_gui.x_w; | ||
1012 | if(x->x_number != num) | ||
1013 | { | ||
1014 | (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_ERASE); | ||
1015 | x->x_number = num; | ||
1016 | if(x->x_on >= x->x_number) | ||
1017 | { | ||
1018 | x->x_on = x->x_number - 1; | ||
1019 | x->x_on_old = x->x_on; | ||
1020 | } | ||
1021 | (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_NEW); | ||
1022 | } | ||
1023 | else | ||
1024 | { | ||
1025 | (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_CONFIG); | ||
1026 | (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_IO + sr_flags); | ||
1027 | (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_MOVE); | ||
1028 | canvas_fixlinesfor(glist_getcanvas(x->x_gui.x_glist), (t_text*)x); | ||
1029 | } | ||
1030 | } | ||
1031 | |||
1032 | static void vradio_set(t_vradio *x, t_floatarg f) | ||
1033 | { | ||
1034 | int i=(int)f; | ||
1035 | int old; | ||
1036 | |||
1037 | if(i < 0) | ||
1038 | i = 0; | ||
1039 | if(i >= x->x_number) | ||
1040 | i = x->x_number-1; | ||
1041 | if(x->x_on != x->x_on_old) | ||
1042 | { | ||
1043 | old = x->x_on_old; | ||
1044 | x->x_on_old = x->x_on; | ||
1045 | x->x_on = i; | ||
1046 | (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE); | ||
1047 | x->x_on_old = old; | ||
1048 | } | ||
1049 | else | ||
1050 | { | ||
1051 | x->x_on = i; | ||
1052 | (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE); | ||
1053 | } | ||
1054 | } | ||
1055 | |||
1056 | static void vradio_bang(t_vradio *x) | ||
1057 | { | ||
1058 | /* compatibility with earlier "vdial" behavior */ | ||
1059 | if (pd_class(&x->x_gui.x_obj.ob_pd) == vradio_old_class) | ||
1060 | { | ||
1061 | if((x->x_change)&&(x->x_on != x->x_on_old)) | ||
1062 | { | ||
1063 | SETFLOAT(x->x_at, (float)x->x_on_old); | ||
1064 | SETFLOAT(x->x_at+1, 0.0); | ||
1065 | outlet_list(x->x_gui.x_obj.ob_outlet, &s_list, 2, x->x_at); | ||
1066 | if(x->x_gui.x_fsf.x_snd_able && x->x_gui.x_snd->s_thing) | ||
1067 | pd_list(x->x_gui.x_snd->s_thing, &s_list, 2, x->x_at); | ||
1068 | } | ||
1069 | x->x_on_old = x->x_on; | ||
1070 | SETFLOAT(x->x_at, (float)x->x_on); | ||
1071 | SETFLOAT(x->x_at+1, 1.0); | ||
1072 | outlet_list(x->x_gui.x_obj.ob_outlet, &s_list, 2, x->x_at); | ||
1073 | if(x->x_gui.x_fsf.x_snd_able && x->x_gui.x_snd->s_thing) | ||
1074 | pd_list(x->x_gui.x_snd->s_thing, &s_list, 2, x->x_at); | ||
1075 | } | ||
1076 | else | ||
1077 | { | ||
1078 | outlet_float(x->x_gui.x_obj.ob_outlet, x->x_on); | ||
1079 | if(x->x_gui.x_fsf.x_snd_able && x->x_gui.x_snd->s_thing) | ||
1080 | pd_float(x->x_gui.x_snd->s_thing, x->x_on); | ||
1081 | } | ||
1082 | } | ||
1083 | |||
1084 | static void vradio_fout(t_vradio *x, t_floatarg f) | ||
1085 | { | ||
1086 | int i=(int)f; | ||
1087 | |||
1088 | if(i < 0) | ||
1089 | i = 0; | ||
1090 | if(i >= x->x_number) | ||
1091 | i = x->x_number-1; | ||
1092 | |||
1093 | if (pd_class(&x->x_gui.x_obj.ob_pd) == vradio_old_class) | ||
1094 | { | ||
1095 | /* compatibility with earlier "vdial" behavior */ | ||
1096 | if((x->x_change)&&(i != x->x_on_old)) | ||
1097 | { | ||
1098 | SETFLOAT(x->x_at, (float)x->x_on_old); | ||
1099 | SETFLOAT(x->x_at+1, 0.0); | ||
1100 | outlet_list(x->x_gui.x_obj.ob_outlet, &s_list, 2, x->x_at); | ||
1101 | if(x->x_gui.x_fsf.x_snd_able && x->x_gui.x_snd->s_thing) | ||
1102 | pd_list(x->x_gui.x_snd->s_thing, &s_list, 2, x->x_at); | ||
1103 | } | ||
1104 | if(x->x_on != x->x_on_old) | ||
1105 | x->x_on_old = x->x_on; | ||
1106 | x->x_on = i; | ||
1107 | (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE); | ||
1108 | x->x_on_old = x->x_on; | ||
1109 | SETFLOAT(x->x_at, (float)x->x_on); | ||
1110 | SETFLOAT(x->x_at+1, 1.0); | ||
1111 | outlet_list(x->x_gui.x_obj.ob_outlet, &s_list, 2, x->x_at); | ||
1112 | if(x->x_gui.x_fsf.x_snd_able && x->x_gui.x_snd->s_thing) | ||
1113 | pd_list(x->x_gui.x_snd->s_thing, &s_list, 2, x->x_at); | ||
1114 | } | ||
1115 | else | ||
1116 | { | ||
1117 | x->x_on_old = x->x_on; | ||
1118 | x->x_on = i; | ||
1119 | (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE); | ||
1120 | outlet_float(x->x_gui.x_obj.ob_outlet, x->x_on); | ||
1121 | if (x->x_gui.x_fsf.x_snd_able && x->x_gui.x_snd->s_thing) | ||
1122 | pd_float(x->x_gui.x_snd->s_thing, x->x_on); | ||
1123 | } | ||
1124 | } | ||
1125 | |||
1126 | static void vradio_float(t_vradio *x, t_floatarg f) | ||
1127 | { | ||
1128 | int i=(int)f; | ||
1129 | |||
1130 | if(i < 0) | ||
1131 | i = 0; | ||
1132 | if(i >= x->x_number) | ||
1133 | i = x->x_number-1; | ||
1134 | |||
1135 | if (pd_class(&x->x_gui.x_obj.ob_pd) == vradio_old_class) | ||
1136 | { | ||
1137 | /* compatibility with earlier "vdial" behavior */ | ||
1138 | if((x->x_change)&&(i != x->x_on_old)) | ||
1139 | { | ||
1140 | if(x->x_gui.x_fsf.x_put_in2out) | ||
1141 | { | ||
1142 | SETFLOAT(x->x_at, (float)x->x_on_old); | ||
1143 | SETFLOAT(x->x_at+1, 0.0); | ||
1144 | outlet_list(x->x_gui.x_obj.ob_outlet, &s_list, 2, x->x_at); | ||
1145 | if(x->x_gui.x_fsf.x_snd_able && x->x_gui.x_snd->s_thing) | ||
1146 | pd_list(x->x_gui.x_snd->s_thing, &s_list, 2, x->x_at); | ||
1147 | } | ||
1148 | } | ||
1149 | if(x->x_on != x->x_on_old) | ||
1150 | x->x_on_old = x->x_on; | ||
1151 | x->x_on = i; | ||
1152 | (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE); | ||
1153 | x->x_on_old = x->x_on; | ||
1154 | if(x->x_gui.x_fsf.x_put_in2out) | ||
1155 | { | ||
1156 | SETFLOAT(x->x_at, (float)x->x_on); | ||
1157 | SETFLOAT(x->x_at+1, 1.0); | ||
1158 | outlet_list(x->x_gui.x_obj.ob_outlet, &s_list, 2, x->x_at); | ||
1159 | if(x->x_gui.x_fsf.x_snd_able && x->x_gui.x_snd->s_thing) | ||
1160 | pd_list(x->x_gui.x_snd->s_thing, &s_list, 2, x->x_at); | ||
1161 | } | ||
1162 | } | ||
1163 | else | ||
1164 | { | ||
1165 | x->x_on_old = x->x_on; | ||
1166 | x->x_on = i; | ||
1167 | (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE); | ||
1168 | if (x->x_gui.x_fsf.x_put_in2out) | ||
1169 | { | ||
1170 | outlet_float(x->x_gui.x_obj.ob_outlet, x->x_on); | ||
1171 | if(x->x_gui.x_fsf.x_snd_able && x->x_gui.x_snd->s_thing) | ||
1172 | pd_float(x->x_gui.x_snd->s_thing, x->x_on); | ||
1173 | } | ||
1174 | } | ||
1175 | } | ||
1176 | |||
1177 | static void vradio_click(t_vradio *x, t_floatarg xpos, t_floatarg ypos, | ||
1178 | t_floatarg shift, t_floatarg ctrl, t_floatarg alt) | ||
1179 | { | ||
1180 | int yy = (int)ypos - text_ypix(&x->x_gui.x_obj, x->x_gui.x_glist); | ||
1181 | |||
1182 | vradio_fout(x, (float)(yy / x->x_gui.x_h)); | ||
1183 | } | ||
1184 | |||
1185 | static int vradio_newclick(t_gobj *z, struct _glist *glist, | ||
1186 | int xpix, int ypix, int shift, int alt, int dbl, int doit) | ||
1187 | { | ||
1188 | if(doit) | ||
1189 | vradio_click((t_vradio *)z, (t_floatarg)xpix, (t_floatarg)ypix, | ||
1190 | (t_floatarg)shift, 0, (t_floatarg)alt); | ||
1191 | return (1); | ||
1192 | } | ||
1193 | |||
1194 | static void vradio_loadbang(t_vradio *x) | ||
1195 | { | ||
1196 | if(!sys_noloadbang && x->x_gui.x_isa.x_loadinit) | ||
1197 | vradio_bang(x); | ||
1198 | } | ||
1199 | |||
1200 | static void vradio_number(t_vradio *x, t_floatarg num) | ||
1201 | { | ||
1202 | int n=(int)num; | ||
1203 | |||
1204 | if(n < 1) | ||
1205 | n = 1; | ||
1206 | if(n > IEM_RADIO_MAX) | ||
1207 | n = IEM_RADIO_MAX; | ||
1208 | if(n != x->x_number) | ||
1209 | { | ||
1210 | (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_ERASE); | ||
1211 | x->x_number = n; | ||
1212 | if(x->x_on >= x->x_number) | ||
1213 | x->x_on = x->x_number - 1; | ||
1214 | x->x_on_old = x->x_on; | ||
1215 | (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_NEW); | ||
1216 | } | ||
1217 | } | ||
1218 | |||
1219 | static void vradio_size(t_vradio *x, t_symbol *s, int ac, t_atom *av) | ||
1220 | { | ||
1221 | x->x_gui.x_w = iemgui_clip_size((int)atom_getintarg(0, ac, av)); | ||
1222 | x->x_gui.x_h = x->x_gui.x_w; | ||
1223 | iemgui_size((void *)x, &x->x_gui); | ||
1224 | } | ||
1225 | |||
1226 | static void vradio_delta(t_vradio *x, t_symbol *s, int ac, t_atom *av) | ||
1227 | {iemgui_delta((void *)x, &x->x_gui, s, ac, av);} | ||
1228 | |||
1229 | static void vradio_pos(t_vradio *x, t_symbol *s, int ac, t_atom *av) | ||
1230 | {iemgui_pos((void *)x, &x->x_gui, s, ac, av);} | ||
1231 | |||
1232 | static void vradio_color(t_vradio *x, t_symbol *s, int ac, t_atom *av) | ||
1233 | {iemgui_color((void *)x, &x->x_gui, s, ac, av);} | ||
1234 | |||
1235 | static void vradio_send(t_vradio *x, t_symbol *s) | ||
1236 | {iemgui_send(x, &x->x_gui, s);} | ||
1237 | |||
1238 | static void vradio_receive(t_vradio *x, t_symbol *s) | ||
1239 | {iemgui_receive(x, &x->x_gui, s);} | ||
1240 | |||
1241 | static void vradio_label(t_vradio *x, t_symbol *s) | ||
1242 | {iemgui_label((void *)x, &x->x_gui, s);} | ||
1243 | |||
1244 | static void vradio_label_pos(t_vradio *x, t_symbol *s, int ac, t_atom *av) | ||
1245 | {iemgui_label_pos((void *)x, &x->x_gui, s, ac, av);} | ||
1246 | |||
1247 | static void vradio_label_font(t_vradio *x, t_symbol *s, int ac, t_atom *av) | ||
1248 | {iemgui_label_font((void *)x, &x->x_gui, s, ac, av);} | ||
1249 | |||
1250 | static void vradio_init(t_vradio *x, t_floatarg f) | ||
1251 | { | ||
1252 | x->x_gui.x_isa.x_loadinit = (f==0.0)?0:1; | ||
1253 | } | ||
1254 | |||
1255 | static void vradio_double_change(t_vradio *x) | ||
1256 | {x->x_change = 1;} | ||
1257 | |||
1258 | static void vradio_single_change(t_vradio *x) | ||
1259 | {x->x_change = 0;} | ||
1260 | |||
1261 | static void *vradio_donew(t_symbol *s, int argc, t_atom *argv, int old) | ||
1262 | { | ||
1263 | t_vradio *x = (t_vradio *)pd_new(old? vradio_old_class : vradio_class); | ||
1264 | int bflcol[]={-262144, -1, -1}; | ||
1265 | int a=IEM_GUI_DEFAULTSIZE, on=0, f=0; | ||
1266 | int ldx=0, ldy=-6, chg=1, num=8; | ||
1267 | int fs=8; | ||
1268 | int ftbreak=IEM_BNG_DEFAULTBREAKFLASHTIME, fthold=IEM_BNG_DEFAULTHOLDFLASHTIME; | ||
1269 | char str[144]; | ||
1270 | |||
1271 | if((argc == 15)&&IS_A_FLOAT(argv,0)&&IS_A_FLOAT(argv,1)&&IS_A_FLOAT(argv,2) | ||
1272 | &&IS_A_FLOAT(argv,3) | ||
1273 | &&(IS_A_SYMBOL(argv,4)||IS_A_FLOAT(argv,4)) | ||
1274 | &&(IS_A_SYMBOL(argv,5)||IS_A_FLOAT(argv,5)) | ||
1275 | &&(IS_A_SYMBOL(argv,6)||IS_A_FLOAT(argv,6)) | ||
1276 | &&IS_A_FLOAT(argv,7)&&IS_A_FLOAT(argv,8) | ||
1277 | &&IS_A_FLOAT(argv,9)&&IS_A_FLOAT(argv,10)&&IS_A_FLOAT(argv,11) | ||
1278 | &&IS_A_FLOAT(argv,12)&&IS_A_FLOAT(argv,13)&&IS_A_FLOAT(argv,14)) | ||
1279 | { | ||
1280 | a = (int)atom_getintarg(0, argc, argv); | ||
1281 | chg = (int)atom_getintarg(1, argc, argv); | ||
1282 | iem_inttosymargs(&x->x_gui.x_isa, atom_getintarg(2, argc, argv)); | ||
1283 | num = (int)atom_getintarg(3, argc, argv); | ||
1284 | iemgui_new_getnames(&x->x_gui, 4, argv); | ||
1285 | ldx = (int)atom_getintarg(7, argc, argv); | ||
1286 | ldy = (int)atom_getintarg(8, argc, argv); | ||
1287 | iem_inttofstyle(&x->x_gui.x_fsf, atom_getintarg(9, argc, argv)); | ||
1288 | fs = (int)atom_getintarg(10, argc, argv); | ||
1289 | bflcol[0] = (int)atom_getintarg(11, argc, argv); | ||
1290 | bflcol[1] = (int)atom_getintarg(12, argc, argv); | ||
1291 | bflcol[2] = (int)atom_getintarg(13, argc, argv); | ||
1292 | on = (int)atom_getintarg(14, argc, argv); | ||
1293 | } | ||
1294 | else iemgui_new_getnames(&x->x_gui, 4, 0); | ||
1295 | x->x_gui.x_draw = (t_iemfunptr)vradio_draw; | ||
1296 | x->x_gui.x_fsf.x_snd_able = 1; | ||
1297 | x->x_gui.x_fsf.x_rcv_able = 1; | ||
1298 | x->x_gui.x_glist = (t_glist *)canvas_getcurrent(); | ||
1299 | if (!strcmp(x->x_gui.x_snd->s_name, "empty")) | ||
1300 | x->x_gui.x_fsf.x_snd_able = 0; | ||
1301 | if (!strcmp(x->x_gui.x_rcv->s_name, "empty")) | ||
1302 | x->x_gui.x_fsf.x_rcv_able = 0; | ||
1303 | if(x->x_gui.x_fsf.x_font_style == 1) strcpy(x->x_gui.x_font, "helvetica"); | ||
1304 | else if(x->x_gui.x_fsf.x_font_style == 2) strcpy(x->x_gui.x_font, "times"); | ||
1305 | else { x->x_gui.x_fsf.x_font_style = 0; | ||
1306 | strcpy(x->x_gui.x_font, "courier"); } | ||
1307 | if(num < 1) | ||
1308 | num = 1; | ||
1309 | if(num > IEM_RADIO_MAX) | ||
1310 | num = IEM_RADIO_MAX; | ||
1311 | x->x_number = num; | ||
1312 | if(on < 0) | ||
1313 | on = 0; | ||
1314 | if(on >= x->x_number) | ||
1315 | on = x->x_number - 1; | ||
1316 | if(x->x_gui.x_isa.x_loadinit) | ||
1317 | x->x_on = on; | ||
1318 | else | ||
1319 | x->x_on = 0; | ||
1320 | x->x_on_old = x->x_on; | ||
1321 | x->x_change = (chg==0)?0:1; | ||
1322 | if (x->x_gui.x_fsf.x_rcv_able) | ||
1323 | pd_bind(&x->x_gui.x_obj.ob_pd, x->x_gui.x_rcv); | ||
1324 | x->x_gui.x_ldx = ldx; | ||
1325 | x->x_gui.x_ldy = ldy; | ||
1326 | if(fs < 4) | ||
1327 | fs = 4; | ||
1328 | x->x_gui.x_fontsize = fs; | ||
1329 | x->x_gui.x_w = iemgui_clip_size(a); | ||
1330 | x->x_gui.x_h = x->x_gui.x_w; | ||
1331 | iemgui_verify_snd_ne_rcv(&x->x_gui); | ||
1332 | iemgui_all_colfromload(&x->x_gui, bflcol); | ||
1333 | outlet_new(&x->x_gui.x_obj, &s_list); | ||
1334 | return (x); | ||
1335 | } | ||
1336 | |||
1337 | static void *vradio_new(t_symbol *s, int argc, t_atom *argv) | ||
1338 | { | ||
1339 | return (vradio_donew(s, argc, argv, 0)); | ||
1340 | } | ||
1341 | |||
1342 | static void *vdial_new(t_symbol *s, int argc, t_atom *argv) | ||
1343 | { | ||
1344 | return (vradio_donew(s, argc, argv, 1)); | ||
1345 | } | ||
1346 | |||
1347 | static void vradio_ff(t_vradio *x) | ||
1348 | { | ||
1349 | if(x->x_gui.x_fsf.x_rcv_able) | ||
1350 | pd_unbind(&x->x_gui.x_obj.ob_pd, x->x_gui.x_rcv); | ||
1351 | gfxstub_deleteforkey(x); | ||
1352 | } | ||
1353 | |||
1354 | void g_vradio_setup(void) | ||
1355 | { | ||
1356 | vradio_class = class_new(gensym("vradio"), (t_newmethod)vradio_new, | ||
1357 | (t_method)vradio_ff, sizeof(t_vradio), 0, A_GIMME, 0); | ||
1358 | class_addbang(vradio_class, vradio_bang); | ||
1359 | class_addfloat(vradio_class, vradio_float); | ||
1360 | class_addmethod(vradio_class, (t_method)vradio_click, gensym("click"), | ||
1361 | A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, 0); | ||
1362 | class_addmethod(vradio_class, (t_method)vradio_dialog, gensym("dialog"), | ||
1363 | A_GIMME, 0); | ||
1364 | class_addmethod(vradio_class, (t_method)vradio_loadbang, | ||
1365 | gensym("loadbang"), 0); | ||
1366 | class_addmethod(vradio_class, (t_method)vradio_set, | ||
1367 | gensym("set"), A_FLOAT, 0); | ||
1368 | class_addmethod(vradio_class, (t_method)vradio_size, | ||
1369 | gensym("size"), A_GIMME, 0); | ||
1370 | class_addmethod(vradio_class, (t_method)vradio_delta, | ||
1371 | gensym("delta"), A_GIMME, 0); | ||
1372 | class_addmethod(vradio_class, (t_method)vradio_pos, | ||
1373 | gensym("pos"), A_GIMME, 0); | ||
1374 | class_addmethod(vradio_class, (t_method)vradio_color, | ||
1375 | gensym("color"), A_GIMME, 0); | ||
1376 | class_addmethod(vradio_class, (t_method)vradio_send, | ||
1377 | gensym("send"), A_DEFSYM, 0); | ||
1378 | class_addmethod(vradio_class, (t_method)vradio_receive, | ||
1379 | gensym("receive"), A_DEFSYM, 0); | ||
1380 | class_addmethod(vradio_class, (t_method)vradio_label, | ||
1381 | gensym("label"), A_DEFSYM, 0); | ||
1382 | class_addmethod(vradio_class, (t_method)vradio_label_pos, | ||
1383 | gensym("label_pos"), A_GIMME, 0); | ||
1384 | class_addmethod(vradio_class, (t_method)vradio_label_font, | ||
1385 | gensym("label_font"), A_GIMME, 0); | ||
1386 | class_addmethod(vradio_class, (t_method)vradio_init, | ||
1387 | gensym("init"), A_FLOAT, 0); | ||
1388 | class_addmethod(vradio_class, (t_method)vradio_number, | ||
1389 | gensym("number"), A_FLOAT, 0); | ||
1390 | class_addmethod(vradio_class, (t_method)vradio_single_change, | ||
1391 | gensym("single_change"), 0); | ||
1392 | class_addmethod(vradio_class, (t_method)vradio_double_change, | ||
1393 | gensym("double_change"), 0); | ||
1394 | vradio_widgetbehavior.w_getrectfn = vradio_getrect; | ||
1395 | vradio_widgetbehavior.w_displacefn = iemgui_displace; | ||
1396 | vradio_widgetbehavior.w_selectfn = iemgui_select; | ||
1397 | vradio_widgetbehavior.w_activatefn = NULL; | ||
1398 | vradio_widgetbehavior.w_deletefn = iemgui_delete; | ||
1399 | vradio_widgetbehavior.w_visfn = iemgui_vis; | ||
1400 | vradio_widgetbehavior.w_clickfn = vradio_newclick; | ||
1401 | class_setwidget(vradio_class, &vradio_widgetbehavior); | ||
1402 | class_sethelpsymbol(vradio_class, gensym("vradio")); | ||
1403 | class_setsavefn(vradio_class, vradio_save); | ||
1404 | class_setpropertiesfn(vradio_class, vradio_properties); | ||
1405 | |||
1406 | /* obsolete version (0.34-0.35) */ | ||
1407 | vradio_old_class = class_new(gensym("vdl"), (t_newmethod)vdial_new, | ||
1408 | (t_method)vradio_ff, sizeof(t_vradio), 0, A_GIMME, 0); | ||
1409 | class_addbang(vradio_old_class, vradio_bang); | ||
1410 | class_addfloat(vradio_old_class, vradio_float); | ||
1411 | class_addmethod(vradio_old_class, (t_method)vradio_click, gensym("click"), | ||
1412 | A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, 0); | ||
1413 | class_addmethod(vradio_old_class, (t_method)vradio_dialog, gensym("dialog"), | ||
1414 | A_GIMME, 0); | ||
1415 | class_addmethod(vradio_old_class, (t_method)vradio_loadbang, gensym("loadbang"), 0); | ||
1416 | class_addmethod(vradio_old_class, (t_method)vradio_set, gensym("set"), A_FLOAT, 0); | ||
1417 | class_addmethod(vradio_old_class, (t_method)vradio_size, gensym("size"), A_GIMME, 0); | ||
1418 | class_addmethod(vradio_old_class, (t_method)vradio_delta, gensym("delta"), A_GIMME, 0); | ||
1419 | class_addmethod(vradio_old_class, (t_method)vradio_pos, gensym("pos"), A_GIMME, 0); | ||
1420 | class_addmethod(vradio_old_class, (t_method)vradio_color, gensym("color"), A_GIMME, 0); | ||
1421 | class_addmethod(vradio_old_class, (t_method)vradio_send, gensym("send"), A_DEFSYM, 0); | ||
1422 | class_addmethod(vradio_old_class, (t_method)vradio_receive, gensym("receive"), A_DEFSYM, 0); | ||
1423 | class_addmethod(vradio_old_class, (t_method)vradio_label, gensym("label"), A_DEFSYM, 0); | ||
1424 | class_addmethod(vradio_old_class, (t_method)vradio_label_pos, gensym("label_pos"), A_GIMME, 0); | ||
1425 | class_addmethod(vradio_old_class, (t_method)vradio_label_font, gensym("label_font"), A_GIMME, 0); | ||
1426 | class_addmethod(vradio_old_class, (t_method)vradio_init, gensym("init"), A_FLOAT, 0); | ||
1427 | class_addmethod(vradio_old_class, (t_method)vradio_number, gensym("number"), A_FLOAT, 0); | ||
1428 | class_addmethod(vradio_old_class, (t_method)vradio_single_change, gensym("single_change"), 0); | ||
1429 | class_addmethod(vradio_old_class, (t_method)vradio_double_change, gensym("double_change"), 0); | ||
1430 | class_setwidget(vradio_old_class, &vradio_widgetbehavior); | ||
1431 | class_sethelpsymbol(vradio_old_class, gensym("vradio")); | ||
1432 | } | ||