summaryrefslogtreecommitdiff
path: root/apps/plugins/pdbox/PDa/src/g_all_guis.c
diff options
context:
space:
mode:
authorPeter D'Hoye <peter.dhoye@gmail.com>2009-05-22 21:58:48 +0000
committerPeter D'Hoye <peter.dhoye@gmail.com>2009-05-22 21:58:48 +0000
commit513389b4c1bc8afe4b2dc9947c534bfeb105e3da (patch)
tree10e673b35651ac567fed2eda0c679c7ade64cbc6 /apps/plugins/pdbox/PDa/src/g_all_guis.c
parent95fa7f6a2ef466444fbe3fe87efc6d5db6b77b36 (diff)
downloadrockbox-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_all_guis.c')
-rw-r--r--apps/plugins/pdbox/PDa/src/g_all_guis.c1324
1 files changed, 1324 insertions, 0 deletions
diff --git a/apps/plugins/pdbox/PDa/src/g_all_guis.c b/apps/plugins/pdbox/PDa/src/g_all_guis.c
new file mode 100644
index 0000000000..9254bafebd
--- /dev/null
+++ b/apps/plugins/pdbox/PDa/src/g_all_guis.c
@@ -0,0 +1,1324 @@
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/* g_7_guis.c written by Thomas Musil (c) IEM KUG Graz Austria 2000-2001 */
6/* thanks to Miller Puckette, Guenther Geiger and Krzystof Czaja */
7
8
9#include <stdlib.h>
10#include <string.h>
11#include <stdio.h>
12#include <ctype.h>
13#include "m_pd.h"
14#include "g_canvas.h"
15#include "t_tk.h"
16#include "g_all_guis.h"
17#include <math.h>
18
19#ifdef MSW
20#include <io.h>
21#else
22#include <unistd.h>
23#endif
24
25/* #define GGEE_HSLIDER_COMPATIBLE */
26
27/*------------------ global varaibles -------------------------*/
28
29int iemgui_color_hex[]=
30{
31 16579836, 10526880, 4210752, 16572640, 16572608,
32 16579784, 14220504, 14220540, 14476540, 16308476,
33 14737632, 8158332, 2105376, 16525352, 16559172,
34 15263784, 1370132, 2684148, 3952892, 16003312,
35 12369084, 6316128, 0, 9177096, 5779456,
36 7874580, 2641940, 17488, 5256, 5767248
37};
38
39int iemgui_vu_db2i[]=
40{
41 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
42 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
43 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
44 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
45 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
46 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
47 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
48 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
49 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
50 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
51 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
52 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
53 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
54 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
55 9, 9, 9, 9, 9,10,10,10,10,10,
56 11,11,11,11,11,12,12,12,12,12,
57 13,13,13,13,14,14,14,14,15,15,
58 15,15,16,16,16,16,17,17,17,18,
59 18,18,19,19,19,20,20,20,21,21,
60 22,22,23,23,24,24,25,26,27,28,
61 29,30,31,32,33,33,34,34,35,35,
62 36,36,37,37,37,38,38,38,39,39,
63 39,39,39,39,40,40
64};
65
66int iemgui_vu_col[]=
67{
68 0,17,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,
69 15,15,15,15,15,15,15,15,15,15,14,14,13,13,13,13,13,13,13,13,13,13,13,19,19,19
70};
71
72char *iemgui_vu_scale_str[]=
73{
74 "",
75 "<-99",
76 "",
77 "",
78 "",
79 "-50",
80 "",
81 "",
82 "",
83 "-30",
84 "",
85 "",
86 "",
87 "-20",
88 "",
89 "",
90 "",
91 "-12",
92 "",
93 "",
94 "",
95 "-6",
96 "",
97 "",
98 "",
99 "-2",
100 "",
101 "",
102 "",
103 "-0dB",
104 "",
105 "",
106 "",
107 "+2",
108 "",
109 "",
110 "",
111 "+6",
112 "",
113 "",
114 "",
115 ">+12",
116 "",
117 "",
118 "",
119 "",
120 "",
121};
122
123
124/*------------------ global functions -------------------------*/
125
126
127int iemgui_clip_size(int size)
128{
129 if(size < IEM_GUI_MINSIZE)
130 size = IEM_GUI_MINSIZE;
131 return(size);
132}
133
134int iemgui_clip_font(int size)
135{
136 if(size < IEM_FONT_MINSIZE)
137 size = IEM_FONT_MINSIZE;
138 return(size);
139}
140
141int iemgui_modulo_color(int col)
142{
143 while(col >= IEM_GUI_MAX_COLOR)
144 col -= IEM_GUI_MAX_COLOR;
145 while(col < 0)
146 col += IEM_GUI_MAX_COLOR;
147 return(col);
148}
149
150t_symbol *iemgui_raute2dollar(t_symbol *s)
151{
152 if (s->s_name[0] == '#')
153 {
154 char buf[MAXPDSTRING];
155 strncpy(buf, s->s_name, MAXPDSTRING);
156 buf[MAXPDSTRING-1] = 0;
157 buf[0] = '$';
158 return (gensym(buf));
159 }
160 else return (s);
161}
162
163t_symbol *iemgui_dollar2raute(t_symbol *s)
164{
165 if (s->s_name[0] == '$')
166 {
167 char buf[MAXPDSTRING];
168 strncpy(buf, s->s_name, MAXPDSTRING);
169 buf[MAXPDSTRING-1] = 0;
170 buf[0] = '#';
171 return (gensym(buf));
172 }
173 else return (s);
174}
175
176void iemgui_verify_snd_ne_rcv(t_iemgui *iemgui)
177{
178 iemgui->x_fsf.x_put_in2out = 1;
179 if(iemgui->x_fsf.x_snd_able && iemgui->x_fsf.x_rcv_able)
180 {
181 if(!strcmp(iemgui->x_snd->s_name, iemgui->x_rcv->s_name))
182 iemgui->x_fsf.x_put_in2out = 0;
183 }
184}
185
186t_symbol *iemgui_new_dogetname(t_iemgui *iemgui, int indx, t_atom *argv)
187{
188 if (IS_A_SYMBOL(argv, indx))
189 return (atom_getsymbolarg(indx, 100000, argv));
190 else if (IS_A_FLOAT(argv, indx))
191 {
192 char str[80];
193 sprintf(str, "%d", (int)atom_getintarg(indx, 100000, argv));
194 return (gensym(str));
195 }
196 else return (gensym("empty"));
197}
198
199void iemgui_new_getnames(t_iemgui *iemgui, int indx, t_atom *argv)
200{
201 if (argv)
202 {
203 iemgui->x_snd = iemgui_new_dogetname(iemgui, indx, argv);
204 iemgui->x_rcv = iemgui_new_dogetname(iemgui, indx+1, argv);
205 iemgui->x_lab = iemgui_new_dogetname(iemgui, indx+2, argv);
206 }
207 else iemgui->x_snd = iemgui->x_rcv = iemgui->x_lab = gensym("empty");
208 iemgui->x_snd_unexpanded = iemgui->x_rcv_unexpanded =
209 iemgui->x_lab_unexpanded = 0;
210 iemgui->x_binbufindex = indx;
211 iemgui->x_labelbindex = indx + 3;
212}
213
214 /* convert symbols in "$" form to the expanded symbols */
215void iemgui_all_dollararg2sym(t_iemgui *iemgui, t_symbol **srlsym)
216{
217 /* save unexpanded ones for later */
218 iemgui->x_snd_unexpanded = srlsym[0];
219 iemgui->x_rcv_unexpanded = srlsym[1];
220 iemgui->x_lab_unexpanded = srlsym[2];
221 srlsym[0] = canvas_realizedollar(iemgui->x_glist, srlsym[0]);
222 srlsym[1] = canvas_realizedollar(iemgui->x_glist, srlsym[1]);
223 srlsym[2] = canvas_realizedollar(iemgui->x_glist, srlsym[2]);
224}
225
226 /* initialize a single symbol in unexpanded form. We reach into the
227 binbuf to grab them; if there's nothing there, set it to the
228 fallback; if still nothing, set to "empty". */
229static void iemgui_init_sym2dollararg(t_iemgui *iemgui, t_symbol **symp,
230 int indx, t_symbol *fallback)
231{
232 if (!*symp)
233 {
234 t_binbuf *b = iemgui->x_obj.ob_binbuf;
235 if (binbuf_getnatom(b) > indx)
236 {
237 char buf[80];
238 atom_string(binbuf_getvec(b) + indx, buf, 80);
239 *symp = gensym(buf);
240 }
241 else if (fallback)
242 *symp = fallback;
243 else *symp = gensym("empty");
244 }
245}
246
247 /* get the unexpanded versions of the symbols; initialize them if
248 necessary. */
249void iemgui_all_sym2dollararg(t_iemgui *iemgui, t_symbol **srlsym)
250{
251 iemgui_init_sym2dollararg(iemgui, &iemgui->x_snd_unexpanded,
252 iemgui->x_binbufindex+1, iemgui->x_snd);
253 iemgui_init_sym2dollararg(iemgui, &iemgui->x_rcv_unexpanded,
254 iemgui->x_binbufindex+2, iemgui->x_rcv);
255 iemgui_init_sym2dollararg(iemgui, &iemgui->x_lab_unexpanded,
256 iemgui->x_labelbindex, iemgui->x_lab);
257 srlsym[0] = iemgui->x_snd_unexpanded;
258 srlsym[1] = iemgui->x_rcv_unexpanded;
259 srlsym[2] = iemgui->x_lab_unexpanded;
260}
261
262void iemgui_first_dollararg2sym(t_iemgui *iemgui, t_symbol **srlsym)
263{
264 /* delete this function */
265}
266
267void iemgui_all_col2save(t_iemgui *iemgui, int *bflcol)
268{
269 bflcol[0] = -1 - (((0xfc0000 & iemgui->x_bcol) >> 6)|
270 ((0xfc00 & iemgui->x_bcol) >> 4)|((0xfc & iemgui->x_bcol) >> 2));
271 bflcol[1] = -1 - (((0xfc0000 & iemgui->x_fcol) >> 6)|
272 ((0xfc00 & iemgui->x_fcol) >> 4)|((0xfc & iemgui->x_fcol) >> 2));
273 bflcol[2] = -1 - (((0xfc0000 & iemgui->x_lcol) >> 6)|
274 ((0xfc00 & iemgui->x_lcol) >> 4)|((0xfc & iemgui->x_lcol) >> 2));
275}
276
277void iemgui_all_colfromload(t_iemgui *iemgui, int *bflcol)
278{
279 if(bflcol[0] < 0)
280 {
281 bflcol[0] = -1 - bflcol[0];
282 iemgui->x_bcol = ((bflcol[0] & 0x3f000) << 6)|((bflcol[0] & 0xfc0) << 4)|
283 ((bflcol[0] & 0x3f) << 2);
284 }
285 else
286 {
287 bflcol[0] = iemgui_modulo_color(bflcol[0]);
288 iemgui->x_bcol = iemgui_color_hex[bflcol[0]];
289 }
290 if(bflcol[1] < 0)
291 {
292 bflcol[1] = -1 - bflcol[1];
293 iemgui->x_fcol = ((bflcol[1] & 0x3f000) << 6)|((bflcol[1] & 0xfc0) << 4)|
294 ((bflcol[1] & 0x3f) << 2);
295 }
296 else
297 {
298 bflcol[1] = iemgui_modulo_color(bflcol[1]);
299 iemgui->x_fcol = iemgui_color_hex[bflcol[1]];
300 }
301 if(bflcol[2] < 0)
302 {
303 bflcol[2] = -1 - bflcol[2];
304 iemgui->x_lcol = ((bflcol[2] & 0x3f000) << 6)|((bflcol[2] & 0xfc0) << 4)|
305 ((bflcol[2] & 0x3f) << 2);
306 }
307 else
308 {
309 bflcol[2] = iemgui_modulo_color(bflcol[2]);
310 iemgui->x_lcol = iemgui_color_hex[bflcol[2]];
311 }
312}
313
314int iemgui_compatible_col(int i)
315{
316 int j;
317
318 if(i >= 0)
319 {
320 j = iemgui_modulo_color(i);
321 return(iemgui_color_hex[(j)]);
322 }
323 else
324 return((-1 -i)&0xffffff);
325}
326
327void iemgui_all_dollar2raute(t_symbol **srlsym)
328{
329 srlsym[0] = iemgui_dollar2raute(srlsym[0]);
330 srlsym[1] = iemgui_dollar2raute(srlsym[1]);
331 srlsym[2] = iemgui_dollar2raute(srlsym[2]);
332}
333
334void iemgui_all_raute2dollar(t_symbol **srlsym)
335{
336 srlsym[0] = iemgui_raute2dollar(srlsym[0]);
337 srlsym[1] = iemgui_raute2dollar(srlsym[1]);
338 srlsym[2] = iemgui_raute2dollar(srlsym[2]);
339}
340
341void iemgui_send(void *x, t_iemgui *iemgui, t_symbol *s)
342{
343 t_symbol *snd;
344 int pargc, tail_len, nth_arg, sndable=1, oldsndrcvable=0;
345 t_atom *pargv;
346
347 if(iemgui->x_fsf.x_rcv_able)
348 oldsndrcvable += IEM_GUI_OLD_RCV_FLAG;
349 if(iemgui->x_fsf.x_snd_able)
350 oldsndrcvable += IEM_GUI_OLD_SND_FLAG;
351
352 if(!strcmp(s->s_name, "empty")) sndable = 0;
353 snd = iemgui_raute2dollar(s);
354 iemgui->x_snd_unexpanded = snd;
355 iemgui->x_snd = snd = canvas_realizedollar(iemgui->x_glist, snd);
356 post("send: before %s, after %s", iemgui->x_snd_unexpanded->s_name,
357 iemgui->x_snd->s_name);
358
359 iemgui->x_fsf.x_snd_able = sndable;
360 iemgui_verify_snd_ne_rcv(iemgui);
361 (*iemgui->x_draw)(x, iemgui->x_glist, IEM_GUI_DRAW_MODE_IO + oldsndrcvable);
362}
363
364void iemgui_receive(void *x, t_iemgui *iemgui, t_symbol *s)
365{
366 t_symbol *rcv;
367 int pargc, tail_len, nth_arg, rcvable=1, oldsndrcvable=0;
368 t_atom *pargv;
369
370 if(iemgui->x_fsf.x_rcv_able)
371 oldsndrcvable += IEM_GUI_OLD_RCV_FLAG;
372 if(iemgui->x_fsf.x_snd_able)
373 oldsndrcvable += IEM_GUI_OLD_SND_FLAG;
374
375 if(!strcmp(s->s_name, "empty")) rcvable = 0;
376 rcv = iemgui_raute2dollar(s);
377 iemgui->x_rcv_unexpanded = rcv;
378 iemgui->x_rcv = rcv = canvas_realizedollar(iemgui->x_glist, rcv);
379 if(rcvable)
380 {
381 if(strcmp(rcv->s_name, iemgui->x_rcv->s_name))
382 {
383 if(iemgui->x_fsf.x_rcv_able)
384 pd_unbind(&iemgui->x_obj.ob_pd, iemgui->x_rcv);
385 iemgui->x_rcv = rcv;
386 pd_bind(&iemgui->x_obj.ob_pd, iemgui->x_rcv);
387 }
388 }
389 else if(!rcvable && iemgui->x_fsf.x_rcv_able)
390 {
391 pd_unbind(&iemgui->x_obj.ob_pd, iemgui->x_rcv);
392 iemgui->x_rcv = rcv;
393 }
394 iemgui->x_fsf.x_rcv_able = rcvable;
395 iemgui_verify_snd_ne_rcv(iemgui);
396 (*iemgui->x_draw)(x, iemgui->x_glist, IEM_GUI_DRAW_MODE_IO + oldsndrcvable);
397}
398
399void iemgui_label(void *x, t_iemgui *iemgui, t_symbol *s)
400{
401 t_symbol *lab;
402 int pargc, tail_len, nth_arg;
403 t_atom *pargv;
404
405 lab = iemgui_raute2dollar(s);
406 iemgui->x_lab_unexpanded = lab;
407 iemgui->x_lab = lab = canvas_realizedollar(iemgui->x_glist, lab);
408
409 if(glist_isvisible(iemgui->x_glist))
410 sys_vgui(".x%x.c itemconfigure %xLABEL -text {%s} \n",
411 glist_getcanvas(iemgui->x_glist), x,
412 strcmp(s->s_name, "empty")?iemgui->x_lab->s_name:"");
413}
414
415void iemgui_label_pos(void *x, t_iemgui *iemgui, t_symbol *s, int ac, t_atom *av)
416{
417 iemgui->x_ldx = (int)atom_getintarg(0, ac, av);
418 iemgui->x_ldy = (int)atom_getintarg(1, ac, av);
419 if(glist_isvisible(iemgui->x_glist))
420 sys_vgui(".x%x.c coords %xLABEL %d %d\n",
421 glist_getcanvas(iemgui->x_glist), x,
422 iemgui->x_obj.te_xpix+iemgui->x_ldx,
423 iemgui->x_obj.te_ypix+iemgui->x_ldy);
424}
425
426void iemgui_label_font(void *x, t_iemgui *iemgui, t_symbol *s, int ac, t_atom *av)
427{
428 int f = (int)atom_getintarg(0, ac, av);
429
430 if(f == 1) strcpy(iemgui->x_font, "helvetica");
431 else if(f == 2) strcpy(iemgui->x_font, "times");
432 else
433 {
434 f = 0;
435 strcpy(iemgui->x_font, "courier");
436 }
437 iemgui->x_fsf.x_font_style = f;
438 f = (int)atom_getintarg(1, ac, av);
439 if(f < 4)
440 f = 4;
441 iemgui->x_fontsize = f;
442 if(glist_isvisible(iemgui->x_glist))
443 sys_vgui(".x%x.c itemconfigure %xLABEL -font {%s %d bold}\n",
444 glist_getcanvas(iemgui->x_glist), x, iemgui->x_font, iemgui->x_fontsize);
445}
446
447void iemgui_size(void *x, t_iemgui *iemgui)
448{
449 if(glist_isvisible(iemgui->x_glist))
450 {
451 (*iemgui->x_draw)(x, iemgui->x_glist, IEM_GUI_DRAW_MODE_MOVE);
452 canvas_fixlinesfor(glist_getcanvas(iemgui->x_glist), (t_text*)x);
453 }
454}
455
456void iemgui_delta(void *x, t_iemgui *iemgui, t_symbol *s, int ac, t_atom *av)
457{
458 iemgui->x_obj.te_xpix += (int)atom_getintarg(0, ac, av);
459 iemgui->x_obj.te_ypix += (int)atom_getintarg(1, ac, av);
460 if(glist_isvisible(iemgui->x_glist))
461 {
462 (*iemgui->x_draw)(x, iemgui->x_glist, IEM_GUI_DRAW_MODE_MOVE);
463 canvas_fixlinesfor(glist_getcanvas(iemgui->x_glist), (t_text*)x);
464 }
465}
466
467void iemgui_pos(void *x, t_iemgui *iemgui, t_symbol *s, int ac, t_atom *av)
468{
469 iemgui->x_obj.te_xpix = (int)atom_getintarg(0, ac, av);
470 iemgui->x_obj.te_ypix = (int)atom_getintarg(1, ac, av);
471 if(glist_isvisible(iemgui->x_glist))
472 {
473 (*iemgui->x_draw)(x, iemgui->x_glist, IEM_GUI_DRAW_MODE_MOVE);
474 canvas_fixlinesfor(glist_getcanvas(iemgui->x_glist), (t_text*)x);
475 }
476}
477
478void iemgui_color(void *x, t_iemgui *iemgui, t_symbol *s, int ac, t_atom *av)
479{
480 iemgui->x_bcol = iemgui_compatible_col(atom_getintarg(0, ac, av));
481 if(ac > 2)
482 {
483 iemgui->x_fcol = iemgui_compatible_col(atom_getintarg(1, ac, av));
484 iemgui->x_lcol = iemgui_compatible_col(atom_getintarg(2, ac, av));
485 }
486 else
487 iemgui->x_lcol = iemgui_compatible_col(atom_getintarg(1, ac, av));
488 if(glist_isvisible(iemgui->x_glist))
489 (*iemgui->x_draw)(x, iemgui->x_glist, IEM_GUI_DRAW_MODE_CONFIG);
490}
491
492void iemgui_displace(t_gobj *z, t_glist *glist, int dx, int dy)
493{
494 t_iemguidummy *x = (t_iemguidummy *)z;
495
496 x->x_gui.x_obj.te_xpix += dx;
497 x->x_gui.x_obj.te_ypix += dy;
498 (*x->x_gui.x_draw)((void *)z, glist, IEM_GUI_DRAW_MODE_MOVE);
499 canvas_fixlinesfor(glist_getcanvas(glist), (t_text *)z);
500}
501
502void iemgui_select(t_gobj *z, t_glist *glist, int selected)
503{
504 t_iemguidummy *x = (t_iemguidummy *)z;
505
506 x->x_gui.x_fsf.x_selected = selected;
507 (*x->x_gui.x_draw)((void *)z, glist, IEM_GUI_DRAW_MODE_SELECT);
508}
509
510void iemgui_delete(t_gobj *z, t_glist *glist)
511{
512 canvas_deletelinesfor(glist, (t_text *)z);
513}
514
515void iemgui_vis(t_gobj *z, t_glist *glist, int vis)
516{
517 t_iemguidummy *x = (t_iemguidummy *)z;
518
519 if (vis)
520 (*x->x_gui.x_draw)((void *)z, glist, IEM_GUI_DRAW_MODE_NEW);
521 else
522 (*x->x_gui.x_draw)((void *)z, glist, IEM_GUI_DRAW_MODE_ERASE);
523}
524
525void iemgui_save(t_iemgui *iemgui, t_symbol **srl, int *bflcol)
526{
527 srl[0] = iemgui->x_snd;
528 srl[1] = iemgui->x_rcv;
529 srl[2] = iemgui->x_lab;
530 iemgui_all_sym2dollararg(iemgui, srl);
531 iemgui_all_col2save(iemgui, bflcol);
532}
533
534void iemgui_properties(t_iemgui *iemgui, t_symbol **srl)
535{
536 srl[0] = iemgui->x_snd;
537 srl[1] = iemgui->x_rcv;
538 srl[2] = iemgui->x_lab;
539 iemgui_all_sym2dollararg(iemgui, srl);
540 iemgui_all_dollar2raute(srl);
541}
542
543int iemgui_dialog(t_iemgui *iemgui, t_symbol **srl, int argc, t_atom *argv)
544{
545 char str[144];
546 int init = (int)atom_getintarg(5, argc, argv);
547 int ldx = (int)atom_getintarg(10, argc, argv);
548 int ldy = (int)atom_getintarg(11, argc, argv);
549 int f = (int)atom_getintarg(12, argc, argv);
550 int fs = (int)atom_getintarg(13, argc, argv);
551 int bcol = (int)atom_getintarg(14, argc, argv);
552 int fcol = (int)atom_getintarg(15, argc, argv);
553 int lcol = (int)atom_getintarg(16, argc, argv);
554 int sndable=1, rcvable=1, oldsndrcvable=0;
555
556 if(iemgui->x_fsf.x_rcv_able)
557 oldsndrcvable += IEM_GUI_OLD_RCV_FLAG;
558 if(iemgui->x_fsf.x_snd_able)
559 oldsndrcvable += IEM_GUI_OLD_SND_FLAG;
560 if(IS_A_SYMBOL(argv,7))
561 srl[0] = atom_getsymbolarg(7, argc, argv);
562 else if(IS_A_FLOAT(argv,7))
563 {
564 sprintf(str, "%d", (int)atom_getintarg(7, argc, argv));
565 srl[0] = gensym(str);
566 }
567 if(IS_A_SYMBOL(argv,8))
568 srl[1] = atom_getsymbolarg(8, argc, argv);
569 else if(IS_A_FLOAT(argv,8))
570 {
571 sprintf(str, "%d", (int)atom_getintarg(8, argc, argv));
572 srl[1] = gensym(str);
573 }
574 if(IS_A_SYMBOL(argv,9))
575 srl[2] = atom_getsymbolarg(9, argc, argv);
576 else if(IS_A_FLOAT(argv,9))
577 {
578 sprintf(str, "%d", (int)atom_getintarg(9, argc, argv));
579 srl[2] = gensym(str);
580 }
581 if(init != 0) init = 1;
582 iemgui->x_isa.x_loadinit = init;
583 if(!strcmp(srl[0]->s_name, "empty")) sndable = 0;
584 if(!strcmp(srl[1]->s_name, "empty")) rcvable = 0;
585 iemgui_all_raute2dollar(srl);
586 iemgui_all_dollararg2sym(iemgui, srl);
587 if(rcvable)
588 {
589 if(strcmp(srl[1]->s_name, iemgui->x_rcv->s_name))
590 {
591 if(iemgui->x_fsf.x_rcv_able)
592 pd_unbind(&iemgui->x_obj.ob_pd, iemgui->x_rcv);
593 iemgui->x_rcv = srl[1];
594 pd_bind(&iemgui->x_obj.ob_pd, iemgui->x_rcv);
595 }
596 }
597 else if(!rcvable && iemgui->x_fsf.x_rcv_able)
598 {
599 pd_unbind(&iemgui->x_obj.ob_pd, iemgui->x_rcv);
600 iemgui->x_rcv = srl[1];
601 }
602 iemgui->x_snd = srl[0];
603 iemgui->x_fsf.x_snd_able = sndable;
604 iemgui->x_fsf.x_rcv_able = rcvable;
605 iemgui->x_lcol = lcol & 0xffffff;
606 iemgui->x_fcol = fcol & 0xffffff;
607 iemgui->x_bcol = bcol & 0xffffff;
608 iemgui->x_lab = srl[2];
609 iemgui->x_ldx = ldx;
610 iemgui->x_ldy = ldy;
611 if(f == 1) strcpy(iemgui->x_font, "helvetica");
612 else if(f == 2) strcpy(iemgui->x_font, "times");
613 else
614 {
615 f = 0;
616 strcpy(iemgui->x_font, "courier");
617 }
618 iemgui->x_fsf.x_font_style = f;
619 if(fs < 4)
620 fs = 4;
621 iemgui->x_fontsize = fs;
622 iemgui_verify_snd_ne_rcv(iemgui);
623 return(oldsndrcvable);
624}
625
626void iem_inttosymargs(t_iem_init_symargs *symargp, int n)
627{
628 memset(symargp, 0, sizeof(*symargp));
629 symargp->x_loadinit = (n >> 0);
630 symargp->x_scale = (n >> 20);
631 symargp->x_flashed = 0;
632 symargp->x_locked = 0;
633 symargp->x_reverse = 0;
634 symargp->dummy = 0;
635}
636
637int iem_symargstoint(t_iem_init_symargs *symargp)
638{
639 return (
640 (((symargp->x_loadinit & 1) << 0) |
641 ((symargp->x_scale & 1) << 20)));
642}
643
644void iem_inttofstyle(t_iem_fstyle_flags *fstylep, int n)
645{
646 memset(fstylep, 0, sizeof(*fstylep));
647 fstylep->x_font_style = (n >> 0);
648 fstylep->x_shiftdown = 0;
649 fstylep->x_selected = 0;
650 fstylep->x_finemoved = 0;
651 fstylep->x_put_in2out = 0;
652 fstylep->x_change = 0;
653 fstylep->x_thick = 0;
654 fstylep->x_lin0_log1 = 0;
655 fstylep->x_steady = 0;
656 fstylep->dummy = 0;
657}
658
659int iem_fstyletoint(t_iem_fstyle_flags *fstylep)
660{
661 return ((fstylep->x_font_style << 0) & 63);
662}
663/* Copyright (c) 1997-1999 Miller Puckette.
664 * For information on usage and redistribution, and for a DISCLAIMER OF ALL
665 * WARRANTIES, see the file, "LICENSE.txt," in this distribution. */
666
667/* g_7_guis.c written by Thomas Musil (c) IEM KUG Graz Austria 2000-2001 */
668/* thanks to Miller Puckette, Guenther Geiger and Krzystof Czaja */
669
670
671#include <stdlib.h>
672#include <string.h>
673#include <stdio.h>
674#include <ctype.h>
675#include "m_pd.h"
676#include "g_canvas.h"
677#include "t_tk.h"
678#include "g_all_guis.h"
679#include <math.h>
680
681#ifdef MSW
682#include <io.h>
683#else
684#include <unistd.h>
685#endif
686
687/* #define GGEE_HSLIDER_COMPATIBLE */
688
689/*------------------ global varaibles -------------------------*/
690
691int iemgui_color_hex[]=
692{
693 16579836, 10526880, 4210752, 16572640, 16572608,
694 16579784, 14220504, 14220540, 14476540, 16308476,
695 14737632, 8158332, 2105376, 16525352, 16559172,
696 15263784, 1370132, 2684148, 3952892, 16003312,
697 12369084, 6316128, 0, 9177096, 5779456,
698 7874580, 2641940, 17488, 5256, 5767248
699};
700
701int iemgui_vu_db2i[]=
702{
703 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
704 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
705 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
706 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
707 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
708 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
709 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
710 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
711 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
712 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
713 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
714 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
715 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
716 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
717 9, 9, 9, 9, 9,10,10,10,10,10,
718 11,11,11,11,11,12,12,12,12,12,
719 13,13,13,13,14,14,14,14,15,15,
720 15,15,16,16,16,16,17,17,17,18,
721 18,18,19,19,19,20,20,20,21,21,
722 22,22,23,23,24,24,25,26,27,28,
723 29,30,31,32,33,33,34,34,35,35,
724 36,36,37,37,37,38,38,38,39,39,
725 39,39,39,39,40,40
726};
727
728int iemgui_vu_col[]=
729{
730 0,17,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,
731 15,15,15,15,15,15,15,15,15,15,14,14,13,13,13,13,13,13,13,13,13,13,13,19,19,19
732};
733
734char *iemgui_vu_scale_str[]=
735{
736 "",
737 "<-99",
738 "",
739 "",
740 "",
741 "-50",
742 "",
743 "",
744 "",
745 "-30",
746 "",
747 "",
748 "",
749 "-20",
750 "",
751 "",
752 "",
753 "-12",
754 "",
755 "",
756 "",
757 "-6",
758 "",
759 "",
760 "",
761 "-2",
762 "",
763 "",
764 "",
765 "-0dB",
766 "",
767 "",
768 "",
769 "+2",
770 "",
771 "",
772 "",
773 "+6",
774 "",
775 "",
776 "",
777 ">+12",
778 "",
779 "",
780 "",
781 "",
782 "",
783};
784
785
786/*------------------ global functions -------------------------*/
787
788
789int iemgui_clip_size(int size)
790{
791 if(size < IEM_GUI_MINSIZE)
792 size = IEM_GUI_MINSIZE;
793 return(size);
794}
795
796int iemgui_clip_font(int size)
797{
798 if(size < IEM_FONT_MINSIZE)
799 size = IEM_FONT_MINSIZE;
800 return(size);
801}
802
803int iemgui_modulo_color(int col)
804{
805 while(col >= IEM_GUI_MAX_COLOR)
806 col -= IEM_GUI_MAX_COLOR;
807 while(col < 0)
808 col += IEM_GUI_MAX_COLOR;
809 return(col);
810}
811
812t_symbol *iemgui_raute2dollar(t_symbol *s)
813{
814 if (s->s_name[0] == '#')
815 {
816 char buf[MAXPDSTRING];
817 strncpy(buf, s->s_name, MAXPDSTRING);
818 buf[MAXPDSTRING-1] = 0;
819 buf[0] = '$';
820 return (gensym(buf));
821 }
822 else return (s);
823}
824
825t_symbol *iemgui_dollar2raute(t_symbol *s)
826{
827 if (s->s_name[0] == '$')
828 {
829 char buf[MAXPDSTRING];
830 strncpy(buf, s->s_name, MAXPDSTRING);
831 buf[MAXPDSTRING-1] = 0;
832 buf[0] = '#';
833 return (gensym(buf));
834 }
835 else return (s);
836}
837
838void iemgui_verify_snd_ne_rcv(t_iemgui *iemgui)
839{
840 iemgui->x_fsf.x_put_in2out = 1;
841 if(iemgui->x_fsf.x_snd_able && iemgui->x_fsf.x_rcv_able)
842 {
843 if(!strcmp(iemgui->x_snd->s_name, iemgui->x_rcv->s_name))
844 iemgui->x_fsf.x_put_in2out = 0;
845 }
846}
847
848t_symbol *iemgui_new_dogetname(t_iemgui *iemgui, int indx, t_atom *argv)
849{
850 if (IS_A_SYMBOL(argv, indx))
851 return (atom_getsymbolarg(indx, 100000, argv));
852 else if (IS_A_FLOAT(argv, indx))
853 {
854 char str[80];
855 sprintf(str, "%d", (int)atom_getintarg(indx, 100000, argv));
856 return (gensym(str));
857 }
858 else return (gensym("empty"));
859}
860
861void iemgui_new_getnames(t_iemgui *iemgui, int indx, t_atom *argv)
862{
863 if (argv)
864 {
865 iemgui->x_snd = iemgui_new_dogetname(iemgui, indx, argv);
866 iemgui->x_rcv = iemgui_new_dogetname(iemgui, indx+1, argv);
867 iemgui->x_lab = iemgui_new_dogetname(iemgui, indx+2, argv);
868 }
869 else iemgui->x_snd = iemgui->x_rcv = iemgui->x_lab = gensym("empty");
870 iemgui->x_snd_unexpanded = iemgui->x_rcv_unexpanded =
871 iemgui->x_lab_unexpanded = 0;
872 iemgui->x_binbufindex = indx;
873 iemgui->x_labelbindex = indx + 3;
874}
875
876 /* convert symbols in "$" form to the expanded symbols */
877void iemgui_all_dollararg2sym(t_iemgui *iemgui, t_symbol **srlsym)
878{
879 /* save unexpanded ones for later */
880 iemgui->x_snd_unexpanded = srlsym[0];
881 iemgui->x_rcv_unexpanded = srlsym[1];
882 iemgui->x_lab_unexpanded = srlsym[2];
883 srlsym[0] = canvas_realizedollar(iemgui->x_glist, srlsym[0]);
884 srlsym[1] = canvas_realizedollar(iemgui->x_glist, srlsym[1]);
885 srlsym[2] = canvas_realizedollar(iemgui->x_glist, srlsym[2]);
886}
887
888 /* initialize a single symbol in unexpanded form. We reach into the
889 binbuf to grab them; if there's nothing there, set it to the
890 fallback; if still nothing, set to "empty". */
891static void iemgui_init_sym2dollararg(t_iemgui *iemgui, t_symbol **symp,
892 int indx, t_symbol *fallback)
893{
894 if (!*symp)
895 {
896 t_binbuf *b = iemgui->x_obj.ob_binbuf;
897 if (binbuf_getnatom(b) > indx)
898 {
899 char buf[80];
900 atom_string(binbuf_getvec(b) + indx, buf, 80);
901 *symp = gensym(buf);
902 }
903 else if (fallback)
904 *symp = fallback;
905 else *symp = gensym("empty");
906 }
907}
908
909 /* get the unexpanded versions of the symbols; initialize them if
910 necessary. */
911void iemgui_all_sym2dollararg(t_iemgui *iemgui, t_symbol **srlsym)
912{
913 iemgui_init_sym2dollararg(iemgui, &iemgui->x_snd_unexpanded,
914 iemgui->x_binbufindex+1, iemgui->x_snd);
915 iemgui_init_sym2dollararg(iemgui, &iemgui->x_rcv_unexpanded,
916 iemgui->x_binbufindex+2, iemgui->x_rcv);
917 iemgui_init_sym2dollararg(iemgui, &iemgui->x_lab_unexpanded,
918 iemgui->x_labelbindex, iemgui->x_lab);
919 srlsym[0] = iemgui->x_snd_unexpanded;
920 srlsym[1] = iemgui->x_rcv_unexpanded;
921 srlsym[2] = iemgui->x_lab_unexpanded;
922}
923
924void iemgui_first_dollararg2sym(t_iemgui *iemgui, t_symbol **srlsym)
925{
926 /* delete this function */
927}
928
929void iemgui_all_col2save(t_iemgui *iemgui, int *bflcol)
930{
931 bflcol[0] = -1 - (((0xfc0000 & iemgui->x_bcol) >> 6)|
932 ((0xfc00 & iemgui->x_bcol) >> 4)|((0xfc & iemgui->x_bcol) >> 2));
933 bflcol[1] = -1 - (((0xfc0000 & iemgui->x_fcol) >> 6)|
934 ((0xfc00 & iemgui->x_fcol) >> 4)|((0xfc & iemgui->x_fcol) >> 2));
935 bflcol[2] = -1 - (((0xfc0000 & iemgui->x_lcol) >> 6)|
936 ((0xfc00 & iemgui->x_lcol) >> 4)|((0xfc & iemgui->x_lcol) >> 2));
937}
938
939void iemgui_all_colfromload(t_iemgui *iemgui, int *bflcol)
940{
941 if(bflcol[0] < 0)
942 {
943 bflcol[0] = -1 - bflcol[0];
944 iemgui->x_bcol = ((bflcol[0] & 0x3f000) << 6)|((bflcol[0] & 0xfc0) << 4)|
945 ((bflcol[0] & 0x3f) << 2);
946 }
947 else
948 {
949 bflcol[0] = iemgui_modulo_color(bflcol[0]);
950 iemgui->x_bcol = iemgui_color_hex[bflcol[0]];
951 }
952 if(bflcol[1] < 0)
953 {
954 bflcol[1] = -1 - bflcol[1];
955 iemgui->x_fcol = ((bflcol[1] & 0x3f000) << 6)|((bflcol[1] & 0xfc0) << 4)|
956 ((bflcol[1] & 0x3f) << 2);
957 }
958 else
959 {
960 bflcol[1] = iemgui_modulo_color(bflcol[1]);
961 iemgui->x_fcol = iemgui_color_hex[bflcol[1]];
962 }
963 if(bflcol[2] < 0)
964 {
965 bflcol[2] = -1 - bflcol[2];
966 iemgui->x_lcol = ((bflcol[2] & 0x3f000) << 6)|((bflcol[2] & 0xfc0) << 4)|
967 ((bflcol[2] & 0x3f) << 2);
968 }
969 else
970 {
971 bflcol[2] = iemgui_modulo_color(bflcol[2]);
972 iemgui->x_lcol = iemgui_color_hex[bflcol[2]];
973 }
974}
975
976int iemgui_compatible_col(int i)
977{
978 int j;
979
980 if(i >= 0)
981 {
982 j = iemgui_modulo_color(i);
983 return(iemgui_color_hex[(j)]);
984 }
985 else
986 return((-1 -i)&0xffffff);
987}
988
989void iemgui_all_dollar2raute(t_symbol **srlsym)
990{
991 srlsym[0] = iemgui_dollar2raute(srlsym[0]);
992 srlsym[1] = iemgui_dollar2raute(srlsym[1]);
993 srlsym[2] = iemgui_dollar2raute(srlsym[2]);
994}
995
996void iemgui_all_raute2dollar(t_symbol **srlsym)
997{
998 srlsym[0] = iemgui_raute2dollar(srlsym[0]);
999 srlsym[1] = iemgui_raute2dollar(srlsym[1]);
1000 srlsym[2] = iemgui_raute2dollar(srlsym[2]);
1001}
1002
1003void iemgui_send(void *x, t_iemgui *iemgui, t_symbol *s)
1004{
1005 t_symbol *snd;
1006 int pargc, tail_len, nth_arg, sndable=1, oldsndrcvable=0;
1007 t_atom *pargv;
1008
1009 if(iemgui->x_fsf.x_rcv_able)
1010 oldsndrcvable += IEM_GUI_OLD_RCV_FLAG;
1011 if(iemgui->x_fsf.x_snd_able)
1012 oldsndrcvable += IEM_GUI_OLD_SND_FLAG;
1013
1014 if(!strcmp(s->s_name, "empty")) sndable = 0;
1015 snd = iemgui_raute2dollar(s);
1016 iemgui->x_snd_unexpanded = snd;
1017 iemgui->x_snd = snd = canvas_realizedollar(iemgui->x_glist, snd);
1018 post("send: before %s, after %s", iemgui->x_snd_unexpanded->s_name,
1019 iemgui->x_snd->s_name);
1020
1021 iemgui->x_fsf.x_snd_able = sndable;
1022 iemgui_verify_snd_ne_rcv(iemgui);
1023 (*iemgui->x_draw)(x, iemgui->x_glist, IEM_GUI_DRAW_MODE_IO + oldsndrcvable);
1024}
1025
1026void iemgui_receive(void *x, t_iemgui *iemgui, t_symbol *s)
1027{
1028 t_symbol *rcv;
1029 int pargc, tail_len, nth_arg, rcvable=1, oldsndrcvable=0;
1030 t_atom *pargv;
1031
1032 if(iemgui->x_fsf.x_rcv_able)
1033 oldsndrcvable += IEM_GUI_OLD_RCV_FLAG;
1034 if(iemgui->x_fsf.x_snd_able)
1035 oldsndrcvable += IEM_GUI_OLD_SND_FLAG;
1036
1037 if(!strcmp(s->s_name, "empty")) rcvable = 0;
1038 rcv = iemgui_raute2dollar(s);
1039 iemgui->x_rcv_unexpanded = rcv;
1040 iemgui->x_rcv = rcv = canvas_realizedollar(iemgui->x_glist, rcv);
1041 if(rcvable)
1042 {
1043 if(strcmp(rcv->s_name, iemgui->x_rcv->s_name))
1044 {
1045 if(iemgui->x_fsf.x_rcv_able)
1046 pd_unbind(&iemgui->x_obj.ob_pd, iemgui->x_rcv);
1047 iemgui->x_rcv = rcv;
1048 pd_bind(&iemgui->x_obj.ob_pd, iemgui->x_rcv);
1049 }
1050 }
1051 else if(!rcvable && iemgui->x_fsf.x_rcv_able)
1052 {
1053 pd_unbind(&iemgui->x_obj.ob_pd, iemgui->x_rcv);
1054 iemgui->x_rcv = rcv;
1055 }
1056 iemgui->x_fsf.x_rcv_able = rcvable;
1057 iemgui_verify_snd_ne_rcv(iemgui);
1058 (*iemgui->x_draw)(x, iemgui->x_glist, IEM_GUI_DRAW_MODE_IO + oldsndrcvable);
1059}
1060
1061void iemgui_label(void *x, t_iemgui *iemgui, t_symbol *s)
1062{
1063 t_symbol *lab;
1064 int pargc, tail_len, nth_arg;
1065 t_atom *pargv;
1066
1067 lab = iemgui_raute2dollar(s);
1068 iemgui->x_lab_unexpanded = lab;
1069 iemgui->x_lab = lab = canvas_realizedollar(iemgui->x_glist, lab);
1070
1071 if(glist_isvisible(iemgui->x_glist))
1072 sys_vgui(".x%x.c itemconfigure %xLABEL -text {%s} \n",
1073 glist_getcanvas(iemgui->x_glist), x,
1074 strcmp(s->s_name, "empty")?iemgui->x_lab->s_name:"");
1075}
1076
1077void iemgui_label_pos(void *x, t_iemgui *iemgui, t_symbol *s, int ac, t_atom *av)
1078{
1079 iemgui->x_ldx = (int)atom_getintarg(0, ac, av);
1080 iemgui->x_ldy = (int)atom_getintarg(1, ac, av);
1081 if(glist_isvisible(iemgui->x_glist))
1082 sys_vgui(".x%x.c coords %xLABEL %d %d\n",
1083 glist_getcanvas(iemgui->x_glist), x,
1084 iemgui->x_obj.te_xpix+iemgui->x_ldx,
1085 iemgui->x_obj.te_ypix+iemgui->x_ldy);
1086}
1087
1088void iemgui_label_font(void *x, t_iemgui *iemgui, t_symbol *s, int ac, t_atom *av)
1089{
1090 int f = (int)atom_getintarg(0, ac, av);
1091
1092 if(f == 1) strcpy(iemgui->x_font, "helvetica");
1093 else if(f == 2) strcpy(iemgui->x_font, "times");
1094 else
1095 {
1096 f = 0;
1097 strcpy(iemgui->x_font, "courier");
1098 }
1099 iemgui->x_fsf.x_font_style = f;
1100 f = (int)atom_getintarg(1, ac, av);
1101 if(f < 4)
1102 f = 4;
1103 iemgui->x_fontsize = f;
1104 if(glist_isvisible(iemgui->x_glist))
1105 sys_vgui(".x%x.c itemconfigure %xLABEL -font {%s %d bold}\n",
1106 glist_getcanvas(iemgui->x_glist), x, iemgui->x_font, iemgui->x_fontsize);
1107}
1108
1109void iemgui_size(void *x, t_iemgui *iemgui)
1110{
1111 if(glist_isvisible(iemgui->x_glist))
1112 {
1113 (*iemgui->x_draw)(x, iemgui->x_glist, IEM_GUI_DRAW_MODE_MOVE);
1114 canvas_fixlinesfor(glist_getcanvas(iemgui->x_glist), (t_text*)x);
1115 }
1116}
1117
1118void iemgui_delta(void *x, t_iemgui *iemgui, t_symbol *s, int ac, t_atom *av)
1119{
1120 iemgui->x_obj.te_xpix += (int)atom_getintarg(0, ac, av);
1121 iemgui->x_obj.te_ypix += (int)atom_getintarg(1, ac, av);
1122 if(glist_isvisible(iemgui->x_glist))
1123 {
1124 (*iemgui->x_draw)(x, iemgui->x_glist, IEM_GUI_DRAW_MODE_MOVE);
1125 canvas_fixlinesfor(glist_getcanvas(iemgui->x_glist), (t_text*)x);
1126 }
1127}
1128
1129void iemgui_pos(void *x, t_iemgui *iemgui, t_symbol *s, int ac, t_atom *av)
1130{
1131 iemgui->x_obj.te_xpix = (int)atom_getintarg(0, ac, av);
1132 iemgui->x_obj.te_ypix = (int)atom_getintarg(1, ac, av);
1133 if(glist_isvisible(iemgui->x_glist))
1134 {
1135 (*iemgui->x_draw)(x, iemgui->x_glist, IEM_GUI_DRAW_MODE_MOVE);
1136 canvas_fixlinesfor(glist_getcanvas(iemgui->x_glist), (t_text*)x);
1137 }
1138}
1139
1140void iemgui_color(void *x, t_iemgui *iemgui, t_symbol *s, int ac, t_atom *av)
1141{
1142 iemgui->x_bcol = iemgui_compatible_col(atom_getintarg(0, ac, av));
1143 if(ac > 2)
1144 {
1145 iemgui->x_fcol = iemgui_compatible_col(atom_getintarg(1, ac, av));
1146 iemgui->x_lcol = iemgui_compatible_col(atom_getintarg(2, ac, av));
1147 }
1148 else
1149 iemgui->x_lcol = iemgui_compatible_col(atom_getintarg(1, ac, av));
1150 if(glist_isvisible(iemgui->x_glist))
1151 (*iemgui->x_draw)(x, iemgui->x_glist, IEM_GUI_DRAW_MODE_CONFIG);
1152}
1153
1154void iemgui_displace(t_gobj *z, t_glist *glist, int dx, int dy)
1155{
1156 t_iemguidummy *x = (t_iemguidummy *)z;
1157
1158 x->x_gui.x_obj.te_xpix += dx;
1159 x->x_gui.x_obj.te_ypix += dy;
1160 (*x->x_gui.x_draw)((void *)z, glist, IEM_GUI_DRAW_MODE_MOVE);
1161 canvas_fixlinesfor(glist_getcanvas(glist), (t_text *)z);
1162}
1163
1164void iemgui_select(t_gobj *z, t_glist *glist, int selected)
1165{
1166 t_iemguidummy *x = (t_iemguidummy *)z;
1167
1168 x->x_gui.x_fsf.x_selected = selected;
1169 (*x->x_gui.x_draw)((void *)z, glist, IEM_GUI_DRAW_MODE_SELECT);
1170}
1171
1172void iemgui_delete(t_gobj *z, t_glist *glist)
1173{
1174 canvas_deletelinesfor(glist, (t_text *)z);
1175}
1176
1177void iemgui_vis(t_gobj *z, t_glist *glist, int vis)
1178{
1179 t_iemguidummy *x = (t_iemguidummy *)z;
1180
1181 if (vis)
1182 (*x->x_gui.x_draw)((void *)z, glist, IEM_GUI_DRAW_MODE_NEW);
1183 else
1184 (*x->x_gui.x_draw)((void *)z, glist, IEM_GUI_DRAW_MODE_ERASE);
1185}
1186
1187void iemgui_save(t_iemgui *iemgui, t_symbol **srl, int *bflcol)
1188{
1189 srl[0] = iemgui->x_snd;
1190 srl[1] = iemgui->x_rcv;
1191 srl[2] = iemgui->x_lab;
1192 iemgui_all_sym2dollararg(iemgui, srl);
1193 iemgui_all_col2save(iemgui, bflcol);
1194}
1195
1196void iemgui_properties(t_iemgui *iemgui, t_symbol **srl)
1197{
1198 srl[0] = iemgui->x_snd;
1199 srl[1] = iemgui->x_rcv;
1200 srl[2] = iemgui->x_lab;
1201 iemgui_all_sym2dollararg(iemgui, srl);
1202 iemgui_all_dollar2raute(srl);
1203}
1204
1205int iemgui_dialog(t_iemgui *iemgui, t_symbol **srl, int argc, t_atom *argv)
1206{
1207 char str[144];
1208 int init = (int)atom_getintarg(5, argc, argv);
1209 int ldx = (int)atom_getintarg(10, argc, argv);
1210 int ldy = (int)atom_getintarg(11, argc, argv);
1211 int f = (int)atom_getintarg(12, argc, argv);
1212 int fs = (int)atom_getintarg(13, argc, argv);
1213 int bcol = (int)atom_getintarg(14, argc, argv);
1214 int fcol = (int)atom_getintarg(15, argc, argv);
1215 int lcol = (int)atom_getintarg(16, argc, argv);
1216 int sndable=1, rcvable=1, oldsndrcvable=0;
1217
1218 if(iemgui->x_fsf.x_rcv_able)
1219 oldsndrcvable += IEM_GUI_OLD_RCV_FLAG;
1220 if(iemgui->x_fsf.x_snd_able)
1221 oldsndrcvable += IEM_GUI_OLD_SND_FLAG;
1222 if(IS_A_SYMBOL(argv,7))
1223 srl[0] = atom_getsymbolarg(7, argc, argv);
1224 else if(IS_A_FLOAT(argv,7))
1225 {
1226 sprintf(str, "%d", (int)atom_getintarg(7, argc, argv));
1227 srl[0] = gensym(str);
1228 }
1229 if(IS_A_SYMBOL(argv,8))
1230 srl[1] = atom_getsymbolarg(8, argc, argv);
1231 else if(IS_A_FLOAT(argv,8))
1232 {
1233 sprintf(str, "%d", (int)atom_getintarg(8, argc, argv));
1234 srl[1] = gensym(str);
1235 }
1236 if(IS_A_SYMBOL(argv,9))
1237 srl[2] = atom_getsymbolarg(9, argc, argv);
1238 else if(IS_A_FLOAT(argv,9))
1239 {
1240 sprintf(str, "%d", (int)atom_getintarg(9, argc, argv));
1241 srl[2] = gensym(str);
1242 }
1243 if(init != 0) init = 1;
1244 iemgui->x_isa.x_loadinit = init;
1245 if(!strcmp(srl[0]->s_name, "empty")) sndable = 0;
1246 if(!strcmp(srl[1]->s_name, "empty")) rcvable = 0;
1247 iemgui_all_raute2dollar(srl);
1248 iemgui_all_dollararg2sym(iemgui, srl);
1249 if(rcvable)
1250 {
1251 if(strcmp(srl[1]->s_name, iemgui->x_rcv->s_name))
1252 {
1253 if(iemgui->x_fsf.x_rcv_able)
1254 pd_unbind(&iemgui->x_obj.ob_pd, iemgui->x_rcv);
1255 iemgui->x_rcv = srl[1];
1256 pd_bind(&iemgui->x_obj.ob_pd, iemgui->x_rcv);
1257 }
1258 }
1259 else if(!rcvable && iemgui->x_fsf.x_rcv_able)
1260 {
1261 pd_unbind(&iemgui->x_obj.ob_pd, iemgui->x_rcv);
1262 iemgui->x_rcv = srl[1];
1263 }
1264 iemgui->x_snd = srl[0];
1265 iemgui->x_fsf.x_snd_able = sndable;
1266 iemgui->x_fsf.x_rcv_able = rcvable;
1267 iemgui->x_lcol = lcol & 0xffffff;
1268 iemgui->x_fcol = fcol & 0xffffff;
1269 iemgui->x_bcol = bcol & 0xffffff;
1270 iemgui->x_lab = srl[2];
1271 iemgui->x_ldx = ldx;
1272 iemgui->x_ldy = ldy;
1273 if(f == 1) strcpy(iemgui->x_font, "helvetica");
1274 else if(f == 2) strcpy(iemgui->x_font, "times");
1275 else
1276 {
1277 f = 0;
1278 strcpy(iemgui->x_font, "courier");
1279 }
1280 iemgui->x_fsf.x_font_style = f;
1281 if(fs < 4)
1282 fs = 4;
1283 iemgui->x_fontsize = fs;
1284 iemgui_verify_snd_ne_rcv(iemgui);
1285 return(oldsndrcvable);
1286}
1287
1288void iem_inttosymargs(t_iem_init_symargs *symargp, int n)
1289{
1290 memset(symargp, 0, sizeof(*symargp));
1291 symargp->x_loadinit = (n >> 0);
1292 symargp->x_scale = (n >> 20);
1293 symargp->x_flashed = 0;
1294 symargp->x_locked = 0;
1295 symargp->x_reverse = 0;
1296 symargp->dummy = 0;
1297}
1298
1299int iem_symargstoint(t_iem_init_symargs *symargp)
1300{
1301 return (
1302 (((symargp->x_loadinit & 1) << 0) |
1303 ((symargp->x_scale & 1) << 20)));
1304}
1305
1306void iem_inttofstyle(t_iem_fstyle_flags *fstylep, int n)
1307{
1308 memset(fstylep, 0, sizeof(*fstylep));
1309 fstylep->x_font_style = (n >> 0);
1310 fstylep->x_shiftdown = 0;
1311 fstylep->x_selected = 0;
1312 fstylep->x_finemoved = 0;
1313 fstylep->x_put_in2out = 0;
1314 fstylep->x_change = 0;
1315 fstylep->x_thick = 0;
1316 fstylep->x_lin0_log1 = 0;
1317 fstylep->x_steady = 0;
1318 fstylep->dummy = 0;
1319}
1320
1321int iem_fstyletoint(t_iem_fstyle_flags *fstylep)
1322{
1323 return ((fstylep->x_font_style << 0) & 63);
1324}