diff options
Diffstat (limited to 'apps/plugins/pdbox/PDa/extra/fatom.h')
-rw-r--r-- | apps/plugins/pdbox/PDa/extra/fatom.h | 486 |
1 files changed, 0 insertions, 486 deletions
diff --git a/apps/plugins/pdbox/PDa/extra/fatom.h b/apps/plugins/pdbox/PDa/extra/fatom.h deleted file mode 100644 index a7a153fad3..0000000000 --- a/apps/plugins/pdbox/PDa/extra/fatom.h +++ /dev/null | |||
@@ -1,486 +0,0 @@ | |||
1 | /* ------------------------ fatom ----------------------------- */ | ||
2 | |||
3 | #define x_val a_pos.a_w.w_float | ||
4 | #define DEBUG(x) | ||
5 | |||
6 | #include <string.h> | ||
7 | #include <stdio.h> | ||
8 | |||
9 | typedef struct _fatom | ||
10 | { | ||
11 | t_object x_obj; | ||
12 | t_atom a_pos; /* the value of the fatom */ | ||
13 | |||
14 | t_symbol* x_send; | ||
15 | t_symbol* x_receive; | ||
16 | t_glist * x_glist; /* value of the current canvas, intialized in _new */ | ||
17 | int x_rect_width; /* width of the widget */ | ||
18 | int x_rect_height; /* height of the widget */ | ||
19 | t_symbol* x_sym; /* symbol for receiving callbacks from GUI */ | ||
20 | t_symbol* x_type; /* type of fatom (vslider, hslider, checkbutton) */ | ||
21 | |||
22 | t_symbol* x_text; /* associated widget text */ | ||
23 | int x_max; /* maximum value of a_pos (x_val) */ | ||
24 | int x_min; /* minimum value of a_pos (x_val) */ | ||
25 | int x_width; /* width of widget (e.g x_rect_height + 15 for hslider, x_rect_width + 15 for slider) */ | ||
26 | t_symbol* x_color; | ||
27 | t_symbol* x_bgcolor; | ||
28 | } t_fatom; | ||
29 | |||
30 | /* widget helper functions */ | ||
31 | |||
32 | |||
33 | |||
34 | |||
35 | static void draw_inlets(t_fatom *x, t_glist *glist, int firsttime, int nin, int nout) | ||
36 | { | ||
37 | int n = nin; | ||
38 | int nplus, i; | ||
39 | nplus = (n == 1 ? 1 : n-1); | ||
40 | DEBUG(post("draw inlet");) | ||
41 | for (i = 0; i < n; i++) | ||
42 | { | ||
43 | int onset = text_xpix(&x->x_obj, glist) + (x->x_rect_width - IOWIDTH) * i / nplus; | ||
44 | if (firsttime) | ||
45 | sys_vgui(".x%x.c create rectangle %d %d %d %d -tags %xo%d\n", | ||
46 | glist_getcanvas(glist), | ||
47 | onset, text_ypix(&x->x_obj, glist) + x->x_rect_height - 1, | ||
48 | onset + IOWIDTH, text_ypix(&x->x_obj, glist) + x->x_rect_height, | ||
49 | x, i); | ||
50 | else | ||
51 | sys_vgui(".x%x.c coords %xo%d %d %d %d %d\n", | ||
52 | glist_getcanvas(glist), x, i, | ||
53 | onset, text_ypix(&x->x_obj, glist) + x->x_rect_height - 1, | ||
54 | onset + IOWIDTH, text_ypix(&x->x_obj, glist) + x->x_rect_height); | ||
55 | } | ||
56 | n = nout; | ||
57 | nplus = (n == 1 ? 1 : n-1); | ||
58 | for (i = 0; i < n; i++) | ||
59 | { | ||
60 | int onset = text_xpix(&x->x_obj, glist) + (x->x_rect_width - IOWIDTH) * i / nplus; | ||
61 | if (firsttime) | ||
62 | sys_vgui(".x%x.c create rectangle %d %d %d %d -tags %xi%d\n", | ||
63 | glist_getcanvas(glist), | ||
64 | onset, text_ypix(&x->x_obj, glist), | ||
65 | onset + IOWIDTH, text_ypix(&x->x_obj, glist) + 1, | ||
66 | x, i); | ||
67 | else | ||
68 | sys_vgui(".x%x.c coords %xi%d %d %d %d %d\n", | ||
69 | glist_getcanvas(glist), x, i, | ||
70 | onset, text_ypix(&x->x_obj, glist), | ||
71 | onset + IOWIDTH, text_ypix(&x->x_obj, glist) + 1); | ||
72 | |||
73 | } | ||
74 | DEBUG(post("draw inlet end");) | ||
75 | } | ||
76 | |||
77 | |||
78 | static void draw_handle(t_fatom *x, t_glist *glist, int firsttime) { | ||
79 | int onset = text_xpix(&x->x_obj, glist) + (x->x_rect_width - IOWIDTH+2); | ||
80 | |||
81 | if (firsttime) | ||
82 | sys_vgui(".x%x.c create rectangle %d %d %d %d -tags %xhandle\n", | ||
83 | glist_getcanvas(glist), | ||
84 | onset, text_ypix(&x->x_obj, glist) + x->x_rect_height - 12, | ||
85 | onset + IOWIDTH, text_ypix(&x->x_obj, glist) + x->x_rect_height-4, | ||
86 | x); | ||
87 | else | ||
88 | sys_vgui(".x%x.c coords %xhandle %d %d %d %d\n", | ||
89 | glist_getcanvas(glist), x, | ||
90 | onset, text_ypix(&x->x_obj, glist) + x->x_rect_height - 12, | ||
91 | onset + IOWIDTH, text_ypix(&x->x_obj, glist) + x->x_rect_height-4); | ||
92 | } | ||
93 | |||
94 | static void create_widget(t_fatom *x, t_glist *glist) | ||
95 | { | ||
96 | t_canvas *canvas=glist_getcanvas(glist); | ||
97 | |||
98 | if (!strcmp(x->x_type->s_name,"vslider")) { | ||
99 | x->x_rect_width = x->x_width+15; | ||
100 | x->x_rect_height = x->x_max-x->x_min+26; | ||
101 | |||
102 | sys_vgui("scale .x%x.c.s%x \ | ||
103 | -sliderlength 10 \ | ||
104 | -showvalue 0 \ | ||
105 | -length %d \ | ||
106 | -resolution 0.01 \ | ||
107 | -repeatinterval 20 \ | ||
108 | -from %d -to %d \ | ||
109 | -width %d \ | ||
110 | -bg %s \ | ||
111 | -activebackground %s \ | ||
112 | -troughcolor %s \ | ||
113 | -command fatom_cb%x\n",canvas,x, | ||
114 | x->x_max-x->x_min+14, | ||
115 | x->x_max, | ||
116 | x->x_min, | ||
117 | x->x_width, | ||
118 | x->x_color->s_name, | ||
119 | x->x_color->s_name, | ||
120 | x->x_bgcolor->s_name, | ||
121 | x); | ||
122 | } else if (!strcmp(x->x_type->s_name,"hslider")) { | ||
123 | x->x_rect_width = x->x_max-x->x_min + 24; | ||
124 | x->x_rect_height = x->x_width + 15; | ||
125 | sys_vgui("scale .x%x.c.s%x \ | ||
126 | -sliderlength 10 \ | ||
127 | -showvalue 0 \ | ||
128 | -length %d \ | ||
129 | -resolution 0.01 \ | ||
130 | -orient horizontal \ | ||
131 | -repeatinterval 20 \ | ||
132 | -from %d -to %d \ | ||
133 | -width %d \ | ||
134 | -bg %s \ | ||
135 | -activebackground %s \ | ||
136 | -troughcolor %s \ | ||
137 | -command fatom_cb%x\n",canvas,x, | ||
138 | x->x_max-x->x_min+14, | ||
139 | x->x_min, | ||
140 | x->x_max, | ||
141 | x->x_width, | ||
142 | x->x_color->s_name, | ||
143 | x->x_color->s_name, | ||
144 | x->x_bgcolor->s_name, | ||
145 | x); | ||
146 | } else if (!strcmp(x->x_type->s_name,"checkbutton")) { | ||
147 | x->x_rect_width = 32; | ||
148 | x->x_rect_height = 28; | ||
149 | sys_vgui("checkbutton .x%x.c.s%x \ | ||
150 | -command { fatom_cb%x $fatom_val%x} -variable fatom_val%x -text \"%s\" \ | ||
151 | -bg %s \ | ||
152 | -activebackground %s \ | ||
153 | \n",canvas,x,x,x,x, | ||
154 | x->x_text->s_name, | ||
155 | x->x_color->s_name, | ||
156 | x->x_bgcolor->s_name); | ||
157 | } else if (!strcmp(x->x_type->s_name,"hradio")) { | ||
158 | int i; | ||
159 | x->x_rect_width = 8*20; | ||
160 | x->x_rect_height = 25; | ||
161 | for (i=0;i<8;i++) { | ||
162 | sys_vgui("radiobutton .x%x.c.s%x%d \ | ||
163 | -command { fatom_cb%x $fatom_val%x} -variable fatom_val%x -value %d\n",canvas,x,i,x,x,x,i); | ||
164 | } | ||
165 | /* TODO pack them */ | ||
166 | } else if (!strcmp(x->x_type->s_name,"vradio")) { | ||
167 | int i; | ||
168 | x->x_rect_width = 30; | ||
169 | x->x_rect_height = 20*8+5; | ||
170 | for (i=0;i<8;i++) { | ||
171 | sys_vgui("radiobutton .x%x.c.s%x%d \ | ||
172 | -command { fatom_cb%x $fatom_val%x} -variable fatom_val%x -value %d\n",canvas,x,i,x,x,x,i); | ||
173 | } | ||
174 | /* TODO pack them */ | ||
175 | } else { | ||
176 | x->x_rect_width = 32; | ||
177 | x->x_rect_height = 140; | ||
178 | sys_vgui("scale .x%x.c.s%x \ | ||
179 | -sliderlength 10 \ | ||
180 | -showvalue 0 \ | ||
181 | -length 131 \ | ||
182 | -from 127 -to 0 \ | ||
183 | -command fatom_cb%x\n",canvas,x,x); | ||
184 | } | ||
185 | |||
186 | /* set the start value */ | ||
187 | if (!strcmp(x->x_type->s_name,"checkbutton")) { | ||
188 | if (x->x_val) | ||
189 | sys_vgui(".x%x.c.s%x select\n",canvas,x,x->x_val); | ||
190 | else | ||
191 | sys_vgui(".x%x.c.s%x deselect\n",canvas,x,x->x_val); | ||
192 | } else | ||
193 | sys_vgui(".x%x.c.s%x set %f\n",canvas,x,x->x_val); | ||
194 | |||
195 | } | ||
196 | |||
197 | |||
198 | |||
199 | |||
200 | |||
201 | static void fatom_drawme(t_fatom *x, t_glist *glist, int firsttime) | ||
202 | { | ||
203 | t_canvas *canvas=glist_getcanvas(glist);// x->x_glist;//glist_getcanvas(glist); | ||
204 | DEBUG(post("drawme %d",firsttime);) | ||
205 | if (firsttime) { | ||
206 | DEBUG(post("glist %x canvas %x",x->x_glist,canvas)); | ||
207 | create_widget(x,glist); | ||
208 | x->x_glist = canvas; | ||
209 | sys_vgui(".x%x.c create window %d %d -anchor nw -window .x%x.c.s%x -tags %xS\n", | ||
210 | canvas,text_xpix(&x->x_obj, glist), text_ypix(&x->x_obj, glist)+2,x->x_glist,x,x); | ||
211 | |||
212 | } | ||
213 | else { | ||
214 | sys_vgui(".x%x.c coords %xS \ | ||
215 | %d %d\n", | ||
216 | canvas, x, | ||
217 | text_xpix(&x->x_obj, glist), text_ypix(&x->x_obj, glist)+2); | ||
218 | } | ||
219 | draw_inlets(x, glist, firsttime, 1,1); | ||
220 | // draw_handle(x, glist, firsttime); | ||
221 | |||
222 | } | ||
223 | |||
224 | |||
225 | static void fatom_erase(t_fatom* x,t_glist* glist) | ||
226 | { | ||
227 | int n; | ||
228 | |||
229 | DEBUG(post("erase");) | ||
230 | sys_vgui("destroy .x%x.c.s%x\n",glist_getcanvas(glist),x); | ||
231 | |||
232 | sys_vgui(".x%x.c delete %xS\n",glist_getcanvas(glist), x); | ||
233 | |||
234 | /* inlets and outlets */ | ||
235 | |||
236 | sys_vgui(".x%x.c delete %xi%d\n",glist_getcanvas(glist),x,0); | ||
237 | sys_vgui(".x%x.c delete %xo%d\n",glist_getcanvas(glist),x,0); | ||
238 | sys_vgui(".x%x.c delete %xhandle\n",glist_getcanvas(glist),x,0); | ||
239 | } | ||
240 | |||
241 | |||
242 | |||
243 | /* ------------------------ fatom widgetbehaviour----------------------------- */ | ||
244 | |||
245 | |||
246 | static void fatom_getrect(t_gobj *z, t_glist *owner, | ||
247 | int *xp1, int *yp1, int *xp2, int *yp2) | ||
248 | { | ||
249 | int width, height; | ||
250 | t_fatom* s = (t_fatom*)z; | ||
251 | |||
252 | width = s->x_rect_width; | ||
253 | height = s->x_rect_height; | ||
254 | *xp1 = text_xpix(&s->x_obj, owner); | ||
255 | *yp1 = text_ypix(&s->x_obj, owner); | ||
256 | *xp2 = text_xpix(&s->x_obj, owner) + width; | ||
257 | *yp2 = text_ypix(&s->x_obj, owner) + height; | ||
258 | } | ||
259 | |||
260 | static void fatom_displace(t_gobj *z, t_glist *glist, | ||
261 | int dx, int dy) | ||
262 | { | ||
263 | t_fatom *x = (t_fatom *)z; | ||
264 | DEBUG(post("displace");) | ||
265 | x->x_obj.te_xpix += dx; | ||
266 | x->x_obj.te_ypix += dy; | ||
267 | if (glist_isvisible(glist)) | ||
268 | { | ||
269 | sys_vgui(".x%x.c coords %xSEL %d %d %d %d\n", | ||
270 | glist_getcanvas(glist), x, | ||
271 | text_xpix(&x->x_obj, glist), text_ypix(&x->x_obj, glist), | ||
272 | text_xpix(&x->x_obj, glist) + x->x_rect_width, text_ypix(&x->x_obj, glist) + x->x_rect_height); | ||
273 | |||
274 | fatom_drawme(x, glist, 0); | ||
275 | canvas_fixlinesfor(glist_getcanvas(glist),(t_text*) x); | ||
276 | } | ||
277 | DEBUG(post("displace end");) | ||
278 | } | ||
279 | |||
280 | static void fatom_select(t_gobj *z, t_glist *glist, int state) | ||
281 | { | ||
282 | t_fatom *x = (t_fatom *)z; | ||
283 | if (state) { | ||
284 | sys_vgui(".x%x.c create rectangle \ | ||
285 | %d %d %d %d -tags %xSEL -outline blue\n", | ||
286 | glist_getcanvas(glist), | ||
287 | text_xpix(&x->x_obj, glist), text_ypix(&x->x_obj, glist), | ||
288 | text_xpix(&x->x_obj, glist) + x->x_rect_width, text_ypix(&x->x_obj, glist) + x->x_rect_height, | ||
289 | x); | ||
290 | } | ||
291 | else { | ||
292 | sys_vgui(".x%x.c delete %xSEL\n", | ||
293 | glist_getcanvas(glist), x); | ||
294 | } | ||
295 | |||
296 | |||
297 | |||
298 | } | ||
299 | |||
300 | |||
301 | static void fatom_activate(t_gobj *z, t_glist *glist, int state) | ||
302 | { | ||
303 | /* t_text *x = (t_text *)z; | ||
304 | t_rtext *y = glist_findrtext(glist, x); | ||
305 | if (z->g_pd != gatom_class) rtext_activate(y, state);*/ | ||
306 | } | ||
307 | |||
308 | static void fatom_delete(t_gobj *z, t_glist *glist) | ||
309 | { | ||
310 | t_text *x = (t_text *)z; | ||
311 | canvas_deletelinesfor(glist_getcanvas(glist), x); | ||
312 | } | ||
313 | |||
314 | |||
315 | static void fatom_vis(t_gobj *z, t_glist *glist, int vis) | ||
316 | { | ||
317 | t_fatom* s = (t_fatom*)z; | ||
318 | t_rtext *y; | ||
319 | DEBUG(post("vis: %d",vis);) | ||
320 | if (vis) { | ||
321 | #ifdef PD_MINOR_VERSION | ||
322 | y = (t_rtext *) rtext_new(glist, (t_text *)z); | ||
323 | #else | ||
324 | y = (t_rtext *) rtext_new(glist, (t_text *)z,0,0); | ||
325 | #endif | ||
326 | fatom_drawme(s, glist, 1); | ||
327 | } | ||
328 | else { | ||
329 | y = glist_findrtext(glist, (t_text *)z); | ||
330 | fatom_erase(s,glist); | ||
331 | rtext_free(y); | ||
332 | } | ||
333 | } | ||
334 | |||
335 | static void fatom_save(t_gobj *z, t_binbuf *b); | ||
336 | |||
337 | t_widgetbehavior fatom_widgetbehavior; | ||
338 | |||
339 | |||
340 | |||
341 | |||
342 | static void fatom_size(t_fatom* x,t_floatarg w,t_floatarg h) { | ||
343 | x->x_rect_width = w; | ||
344 | x->x_rect_height = h; | ||
345 | } | ||
346 | |||
347 | static void fatom_color(t_fatom* x,t_symbol* col) | ||
348 | { | ||
349 | |||
350 | } | ||
351 | |||
352 | |||
353 | static void fatom_f(t_fatom* x,t_floatarg f) | ||
354 | { | ||
355 | x->x_val = f; | ||
356 | if (x->x_send == &s_) | ||
357 | outlet_float(x->x_obj.ob_outlet,f); | ||
358 | else | ||
359 | if (x->x_send->s_thing) pd_float(x->x_send->s_thing,f); | ||
360 | } | ||
361 | |||
362 | |||
363 | static void fatom_float(t_fatom* x,t_floatarg f) | ||
364 | { | ||
365 | if (glist_isvisible(x->x_glist)) { | ||
366 | if (!strcmp(x->x_type->s_name,"checkbutton")) { | ||
367 | if (x->x_val) | ||
368 | sys_vgui(".x%x.c.s%x select\n",x->x_glist,x,f); | ||
369 | else | ||
370 | sys_vgui(".x%x.c.s%x deselect\n",x->x_glist,x,f); | ||
371 | } else | ||
372 | sys_vgui(".x%x.c.s%x set %f\n",x->x_glist,x,f); | ||
373 | } | ||
374 | fatom_f(x,f); | ||
375 | } | ||
376 | |||
377 | |||
378 | static void fatom_bang(t_fatom* x,t_floatarg f) | ||
379 | { | ||
380 | outlet_float(x->x_obj.ob_outlet,x->x_val); | ||
381 | } | ||
382 | |||
383 | |||
384 | static void fatom_properties(t_gobj *z, t_glist *owner) | ||
385 | { | ||
386 | post("N/I"); | ||
387 | } | ||
388 | |||
389 | |||
390 | static void fatom_save(t_gobj *z, t_binbuf *b) | ||
391 | { | ||
392 | |||
393 | t_fatom *x = (t_fatom *)z; | ||
394 | |||
395 | binbuf_addv(b, "ssiiss", gensym("#X"),gensym("obj"), | ||
396 | x->x_obj.te_xpix, x->x_obj.te_ypix , | ||
397 | gensym("fatom"),x->x_type); | ||
398 | binbuf_addv(b, ";"); | ||
399 | } | ||
400 | |||
401 | |||
402 | static void *fatom_new(t_fatom* x,int argc,t_atom* argv) | ||
403 | { | ||
404 | char buf[256]; | ||
405 | int n = 0; | ||
406 | x->x_glist = canvas_getcurrent(); | ||
407 | |||
408 | x->x_text = gensym(""); | ||
409 | x->x_max = 127; | ||
410 | x->x_min = 0; | ||
411 | x->x_width = 15; | ||
412 | x->x_color = gensym("grey"); | ||
413 | x->x_bgcolor = gensym("grey"); | ||
414 | x->x_send = &s_; | ||
415 | |||
416 | while (argc) { | ||
417 | if (argv->a_type == A_FLOAT) { | ||
418 | if (n==0) x->x_max = atom_getfloat(argv); | ||
419 | if (n==1) x->x_min = atom_getfloat(argv); | ||
420 | if (n==2) x->x_width = atom_getfloat(argv); | ||
421 | } | ||
422 | |||
423 | if (argv->a_type == A_SYMBOL) { | ||
424 | post("%d: symbol value %s",n,atom_getsymbol(argv)->s_name); | ||
425 | if (n==3) x->x_send = atom_getsymbol(argv); | ||
426 | if (n==4) x->x_color = atom_getsymbol(argv); | ||
427 | if (n==5) x->x_bgcolor = atom_getsymbol(argv); | ||
428 | } | ||
429 | argv++; | ||
430 | argc--; | ||
431 | n++; | ||
432 | } | ||
433 | |||
434 | /* bind to a symbol for slider callback (later make this based on the | ||
435 | filepath ??) */ | ||
436 | |||
437 | sprintf(buf,"fatom%x",(t_int)x); | ||
438 | x->x_sym = gensym(buf); | ||
439 | pd_bind(&x->x_obj.ob_pd, x->x_sym); | ||
440 | |||
441 | /* pipe startup code to tk */ | ||
442 | |||
443 | sys_vgui("proc fatom_cb%x {v} {\n pd [concat fatom%x f $v \\;]\n }\n",x,x); | ||
444 | |||
445 | outlet_new(&x->x_obj, &s_float); | ||
446 | return (x); | ||
447 | } | ||
448 | |||
449 | static void fatom_setup_common(t_class* class) | ||
450 | { | ||
451 | |||
452 | fatom_widgetbehavior.w_getrectfn = fatom_getrect; | ||
453 | fatom_widgetbehavior.w_displacefn = fatom_displace; | ||
454 | fatom_widgetbehavior.w_selectfn = fatom_select; | ||
455 | fatom_widgetbehavior.w_activatefn = fatom_activate; | ||
456 | fatom_widgetbehavior.w_deletefn = fatom_delete; | ||
457 | fatom_widgetbehavior.w_visfn = fatom_vis; | ||
458 | #if PD_MINOR_VERSION < 37 | ||
459 | fatom_widgetbehavior.w_savefn = fatom_save; | ||
460 | fatom_widgetbehavior.w_propertiesfn = NULL; | ||
461 | #endif | ||
462 | fatom_widgetbehavior.w_clickfn = NULL; | ||
463 | |||
464 | class_addfloat(class, (t_method)fatom_float); | ||
465 | class_addbang(class, (t_method)fatom_bang); | ||
466 | class_addmethod(class, (t_method)fatom_f, gensym("f"), | ||
467 | A_FLOAT, 0); | ||
468 | |||
469 | /* | ||
470 | class_addmethod(class, (t_method)fatom_size, gensym("size"), | ||
471 | A_FLOAT, A_FLOAT, 0); | ||
472 | |||
473 | class_addmethod(class, (t_method)fatom_color, gensym("color"), | ||
474 | A_SYMBOL, 0); | ||
475 | */ | ||
476 | /* | ||
477 | class_addmethod(class, (t_method)fatom_open, gensym("open"), | ||
478 | A_SYMBOL, 0); | ||
479 | */ | ||
480 | |||
481 | class_setwidget(class,&fatom_widgetbehavior); | ||
482 | #if PD_MINOR_VERSION >= 37 | ||
483 | class_setsavefn(class,&fatom_save); | ||
484 | #endif | ||
485 | } | ||
486 | |||