1 /* ------------------------ fatom ----------------------------- */
3 #define x_val a_pos.a_w.w_float
12 t_atom a_pos
; /* the value of the fatom */
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) */
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) */
30 /* widget helper functions */
35 static void draw_inlets(t_fatom
*x
, t_glist
*glist
, int firsttime
, int nin
, int nout
)
39 nplus
= (n
== 1 ? 1 : n
-1);
40 DEBUG(post("draw inlet");)
41 for (i
= 0; i
< n
; i
++)
43 int onset
= text_xpix(&x
->x_obj
, glist
) + (x
->x_rect_width
- IOWIDTH
) * i
/ nplus
;
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
,
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
);
57 nplus
= (n
== 1 ? 1 : n
-1);
58 for (i
= 0; i
< n
; i
++)
60 int onset
= text_xpix(&x
->x_obj
, glist
) + (x
->x_rect_width
- IOWIDTH
) * i
/ nplus
;
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,
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);
74 DEBUG(post("draw inlet end");)
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);
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,
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);
94 static void create_widget(t_fatom
*x
, t_glist
*glist
)
96 t_canvas
*canvas
=glist_getcanvas(glist
);
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;
102 sys_vgui("scale .x%x.c.s%x \
111 -activebackground %s \
113 -command fatom_cb%x\n",canvas
,x
,
114 x
->x_max
-x
->x_min
+14,
120 x
->x_bgcolor
->s_name
,
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 \
135 -activebackground %s \
137 -command fatom_cb%x\n",canvas
,x
,
138 x
->x_max
-x
->x_min
+14,
144 x
->x_bgcolor
->s_name
,
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\" \
152 -activebackground %s \
156 x
->x_bgcolor
->s_name
);
157 } else if (!strcmp(x
->x_type
->s_name
,"hradio")) {
159 x
->x_rect_width
= 8*20;
160 x
->x_rect_height
= 25;
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
);
166 } else if (!strcmp(x
->x_type
->s_name
,"vradio")) {
168 x
->x_rect_width
= 30;
169 x
->x_rect_height
= 20*8+5;
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
);
176 x
->x_rect_width
= 32;
177 x
->x_rect_height
= 140;
178 sys_vgui("scale .x%x.c.s%x \
183 -command fatom_cb%x\n",canvas
,x
,x
);
186 /* set the start value */
187 if (!strcmp(x
->x_type
->s_name
,"checkbutton")) {
189 sys_vgui(".x%x.c.s%x select\n",canvas
,x
,x
->x_val
);
191 sys_vgui(".x%x.c.s%x deselect\n",canvas
,x
,x
->x_val
);
193 sys_vgui(".x%x.c.s%x set %f\n",canvas
,x
,x
->x_val
);
201 static void fatom_drawme(t_fatom
*x
, t_glist
*glist
, int firsttime
)
203 t_canvas
*canvas
=glist_getcanvas(glist
);// x->x_glist;//glist_getcanvas(glist);
204 DEBUG(post("drawme %d",firsttime
);)
206 DEBUG(post("glist %x canvas %x",x
->x_glist
,canvas
));
207 create_widget(x
,glist
);
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
);
214 sys_vgui(".x%x.c coords %xS \
217 text_xpix(&x
->x_obj
, glist
), text_ypix(&x
->x_obj
, glist
)+2);
219 draw_inlets(x
, glist
, firsttime
, 1,1);
220 // draw_handle(x, glist, firsttime);
225 static void fatom_erase(t_fatom
* x
,t_glist
* glist
)
229 DEBUG(post("erase");)
230 sys_vgui("destroy .x%x.c.s%x\n",glist_getcanvas(glist
),x
);
232 sys_vgui(".x%x.c delete %xS\n",glist_getcanvas(glist
), x
);
234 /* inlets and outlets */
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);
243 /* ------------------------ fatom widgetbehaviour----------------------------- */
246 static void fatom_getrect(t_gobj
*z
, t_glist
*owner
,
247 int *xp1
, int *yp1
, int *xp2
, int *yp2
)
250 t_fatom
* s
= (t_fatom
*)z
;
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
;
260 static void fatom_displace(t_gobj
*z
, t_glist
*glist
,
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
))
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
);
274 fatom_drawme(x
, glist
, 0);
275 canvas_fixlinesfor(glist_getcanvas(glist
),(t_text
*) x
);
277 DEBUG(post("displace end");)
280 static void fatom_select(t_gobj
*z
, t_glist
*glist
, int state
)
282 t_fatom
*x
= (t_fatom
*)z
;
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
,
292 sys_vgui(".x%x.c delete %xSEL\n",
293 glist_getcanvas(glist
), x
);
301 static void fatom_activate(t_gobj
*z
, t_glist
*glist
, int state
)
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);*/
308 static void fatom_delete(t_gobj
*z
, t_glist
*glist
)
310 t_text
*x
= (t_text
*)z
;
311 canvas_deletelinesfor(glist_getcanvas(glist
), x
);
315 static void fatom_vis(t_gobj
*z
, t_glist
*glist
, int vis
)
317 t_fatom
* s
= (t_fatom
*)z
;
319 DEBUG(post("vis: %d",vis
);)
321 #ifdef PD_MINOR_VERSION
322 y
= (t_rtext
*) rtext_new(glist
, (t_text
*)z
);
324 y
= (t_rtext
*) rtext_new(glist
, (t_text
*)z
,0,0);
326 fatom_drawme(s
, glist
, 1);
329 y
= glist_findrtext(glist
, (t_text
*)z
);
330 fatom_erase(s
,glist
);
335 static void fatom_save(t_gobj
*z
, t_binbuf
*b
);
337 t_widgetbehavior fatom_widgetbehavior
;
342 static void fatom_size(t_fatom
* x
,t_floatarg w
,t_floatarg h
) {
344 x
->x_rect_height
= h
;
347 static void fatom_color(t_fatom
* x
,t_symbol
* col
)
353 static void fatom_f(t_fatom
* x
,t_floatarg f
)
356 if (x
->x_send
== &s_
)
357 outlet_float(x
->x_obj
.ob_outlet
,f
);
359 if (x
->x_send
->s_thing
) pd_float(x
->x_send
->s_thing
,f
);
363 static void fatom_float(t_fatom
* x
,t_floatarg f
)
365 if (glist_isvisible(x
->x_glist
)) {
366 if (!strcmp(x
->x_type
->s_name
,"checkbutton")) {
368 sys_vgui(".x%x.c.s%x select\n",x
->x_glist
,x
,f
);
370 sys_vgui(".x%x.c.s%x deselect\n",x
->x_glist
,x
,f
);
372 sys_vgui(".x%x.c.s%x set %f\n",x
->x_glist
,x
,f
);
378 static void fatom_bang(t_fatom
* x
,t_floatarg f
)
380 outlet_float(x
->x_obj
.ob_outlet
,x
->x_val
);
384 static void fatom_properties(t_gobj
*z
, t_glist
*owner
)
390 static void fatom_save(t_gobj
*z
, t_binbuf
*b
)
393 t_fatom
*x
= (t_fatom
*)z
;
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
);
402 static void *fatom_new(t_fatom
* x
,int argc
,t_atom
* argv
)
406 x
->x_glist
= canvas_getcurrent();
408 x
->x_text
= gensym("");
412 x
->x_color
= gensym("grey");
413 x
->x_bgcolor
= gensym("grey");
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
);
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
);
434 /* bind to a symbol for slider callback (later make this based on the
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
);
441 /* pipe startup code to tk */
443 sys_vgui("proc fatom_cb%x {v} {\n pd [concat fatom%x f $v \\;]\n }\n",x
,x
);
445 outlet_new(&x
->x_obj
, &s_float
);
449 static void fatom_setup_common(t_class
* class)
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
;
462 fatom_widgetbehavior
.w_clickfn
= NULL
;
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"),
470 class_addmethod(class, (t_method)fatom_size, gensym("size"),
471 A_FLOAT, A_FLOAT, 0);
473 class_addmethod(class, (t_method)fatom_color, gensym("color"),
477 class_addmethod(class, (t_method)fatom_open, gensym("open"),
481 class_setwidget(class,&fatom_widgetbehavior
);
482 #if PD_MINOR_VERSION >= 37
483 class_setsavefn(class,&fatom_save
);
486 /* ------------------------ fatom ----------------------------- */
488 #define x_val a_pos.a_w.w_float
494 typedef struct _fatom
497 t_atom a_pos
; /* the value of the fatom */
501 t_glist
* x_glist
; /* value of the current canvas, intialized in _new */
502 int x_rect_width
; /* width of the widget */
503 int x_rect_height
; /* height of the widget */
504 t_symbol
* x_sym
; /* symbol for receiving callbacks from GUI */
505 t_symbol
* x_type
; /* type of fatom (vslider, hslider, checkbutton) */
507 t_symbol
* x_text
; /* associated widget text */
508 int x_max
; /* maximum value of a_pos (x_val) */
509 int x_min
; /* minimum value of a_pos (x_val) */
510 int x_width
; /* width of widget (e.g x_rect_height + 15 for hslider, x_rect_width + 15 for slider) */
515 /* widget helper functions */
520 static void draw_inlets(t_fatom
*x
, t_glist
*glist
, int firsttime
, int nin
, int nout
)
524 nplus
= (n
== 1 ? 1 : n
-1);
525 DEBUG(post("draw inlet");)
526 for (i
= 0; i
< n
; i
++)
528 int onset
= text_xpix(&x
->x_obj
, glist
) + (x
->x_rect_width
- IOWIDTH
) * i
/ nplus
;
530 sys_vgui(".x%x.c create rectangle %d %d %d %d -tags %xo%d\n",
531 glist_getcanvas(glist
),
532 onset
, text_ypix(&x
->x_obj
, glist
) + x
->x_rect_height
- 1,
533 onset
+ IOWIDTH
, text_ypix(&x
->x_obj
, glist
) + x
->x_rect_height
,
536 sys_vgui(".x%x.c coords %xo%d %d %d %d %d\n",
537 glist_getcanvas(glist
), x
, i
,
538 onset
, text_ypix(&x
->x_obj
, glist
) + x
->x_rect_height
- 1,
539 onset
+ IOWIDTH
, text_ypix(&x
->x_obj
, glist
) + x
->x_rect_height
);
542 nplus
= (n
== 1 ? 1 : n
-1);
543 for (i
= 0; i
< n
; i
++)
545 int onset
= text_xpix(&x
->x_obj
, glist
) + (x
->x_rect_width
- IOWIDTH
) * i
/ nplus
;
547 sys_vgui(".x%x.c create rectangle %d %d %d %d -tags %xi%d\n",
548 glist_getcanvas(glist
),
549 onset
, text_ypix(&x
->x_obj
, glist
),
550 onset
+ IOWIDTH
, text_ypix(&x
->x_obj
, glist
) + 1,
553 sys_vgui(".x%x.c coords %xi%d %d %d %d %d\n",
554 glist_getcanvas(glist
), x
, i
,
555 onset
, text_ypix(&x
->x_obj
, glist
),
556 onset
+ IOWIDTH
, text_ypix(&x
->x_obj
, glist
) + 1);
559 DEBUG(post("draw inlet end");)
563 static void draw_handle(t_fatom
*x
, t_glist
*glist
, int firsttime
) {
564 int onset
= text_xpix(&x
->x_obj
, glist
) + (x
->x_rect_width
- IOWIDTH
+2);
567 sys_vgui(".x%x.c create rectangle %d %d %d %d -tags %xhandle\n",
568 glist_getcanvas(glist
),
569 onset
, text_ypix(&x
->x_obj
, glist
) + x
->x_rect_height
- 12,
570 onset
+ IOWIDTH
, text_ypix(&x
->x_obj
, glist
) + x
->x_rect_height
-4,
573 sys_vgui(".x%x.c coords %xhandle %d %d %d %d\n",
574 glist_getcanvas(glist
), x
,
575 onset
, text_ypix(&x
->x_obj
, glist
) + x
->x_rect_height
- 12,
576 onset
+ IOWIDTH
, text_ypix(&x
->x_obj
, glist
) + x
->x_rect_height
-4);
579 static void create_widget(t_fatom
*x
, t_glist
*glist
)
581 t_canvas
*canvas
=glist_getcanvas(glist
);
583 if (!strcmp(x
->x_type
->s_name
,"vslider")) {
584 x
->x_rect_width
= x
->x_width
+15;
585 x
->x_rect_height
= x
->x_max
-x
->x_min
+26;
587 sys_vgui("scale .x%x.c.s%x \
596 -activebackground %s \
598 -command fatom_cb%x\n",canvas
,x
,
599 x
->x_max
-x
->x_min
+14,
605 x
->x_bgcolor
->s_name
,
607 } else if (!strcmp(x
->x_type
->s_name
,"hslider")) {
608 x
->x_rect_width
= x
->x_max
-x
->x_min
+ 24;
609 x
->x_rect_height
= x
->x_width
+ 15;
610 sys_vgui("scale .x%x.c.s%x \
620 -activebackground %s \
622 -command fatom_cb%x\n",canvas
,x
,
623 x
->x_max
-x
->x_min
+14,
629 x
->x_bgcolor
->s_name
,
631 } else if (!strcmp(x
->x_type
->s_name
,"checkbutton")) {
632 x
->x_rect_width
= 32;
633 x
->x_rect_height
= 28;
634 sys_vgui("checkbutton .x%x.c.s%x \
635 -command { fatom_cb%x $fatom_val%x} -variable fatom_val%x -text \"%s\" \
637 -activebackground %s \
641 x
->x_bgcolor
->s_name
);
642 } else if (!strcmp(x
->x_type
->s_name
,"hradio")) {
644 x
->x_rect_width
= 8*20;
645 x
->x_rect_height
= 25;
647 sys_vgui("radiobutton .x%x.c.s%x%d \
648 -command { fatom_cb%x $fatom_val%x} -variable fatom_val%x -value %d\n",canvas
,x
,i
,x
,x
,x
,i
);
651 } else if (!strcmp(x
->x_type
->s_name
,"vradio")) {
653 x
->x_rect_width
= 30;
654 x
->x_rect_height
= 20*8+5;
656 sys_vgui("radiobutton .x%x.c.s%x%d \
657 -command { fatom_cb%x $fatom_val%x} -variable fatom_val%x -value %d\n",canvas
,x
,i
,x
,x
,x
,i
);
661 x
->x_rect_width
= 32;
662 x
->x_rect_height
= 140;
663 sys_vgui("scale .x%x.c.s%x \
668 -command fatom_cb%x\n",canvas
,x
,x
);
671 /* set the start value */
672 if (!strcmp(x
->x_type
->s_name
,"checkbutton")) {
674 sys_vgui(".x%x.c.s%x select\n",canvas
,x
,x
->x_val
);
676 sys_vgui(".x%x.c.s%x deselect\n",canvas
,x
,x
->x_val
);
678 sys_vgui(".x%x.c.s%x set %f\n",canvas
,x
,x
->x_val
);
686 static void fatom_drawme(t_fatom
*x
, t_glist
*glist
, int firsttime
)
688 t_canvas
*canvas
=glist_getcanvas(glist
);// x->x_glist;//glist_getcanvas(glist);
689 DEBUG(post("drawme %d",firsttime
);)
691 DEBUG(post("glist %x canvas %x",x
->x_glist
,canvas
));
692 create_widget(x
,glist
);
694 sys_vgui(".x%x.c create window %d %d -anchor nw -window .x%x.c.s%x -tags %xS\n",
695 canvas
,text_xpix(&x
->x_obj
, glist
), text_ypix(&x
->x_obj
, glist
)+2,x
->x_glist
,x
,x
);
699 sys_vgui(".x%x.c coords %xS \
702 text_xpix(&x
->x_obj
, glist
), text_ypix(&x
->x_obj
, glist
)+2);
704 draw_inlets(x
, glist
, firsttime
, 1,1);
705 // draw_handle(x, glist, firsttime);
710 static void fatom_erase(t_fatom
* x
,t_glist
* glist
)
714 DEBUG(post("erase");)
715 sys_vgui("destroy .x%x.c.s%x\n",glist_getcanvas(glist
),x
);
717 sys_vgui(".x%x.c delete %xS\n",glist_getcanvas(glist
), x
);
719 /* inlets and outlets */
721 sys_vgui(".x%x.c delete %xi%d\n",glist_getcanvas(glist
),x
,0);
722 sys_vgui(".x%x.c delete %xo%d\n",glist_getcanvas(glist
),x
,0);
723 sys_vgui(".x%x.c delete %xhandle\n",glist_getcanvas(glist
),x
,0);
728 /* ------------------------ fatom widgetbehaviour----------------------------- */
731 static void fatom_getrect(t_gobj
*z
, t_glist
*owner
,
732 int *xp1
, int *yp1
, int *xp2
, int *yp2
)
735 t_fatom
* s
= (t_fatom
*)z
;
737 width
= s
->x_rect_width
;
738 height
= s
->x_rect_height
;
739 *xp1
= text_xpix(&s
->x_obj
, owner
);
740 *yp1
= text_ypix(&s
->x_obj
, owner
);
741 *xp2
= text_xpix(&s
->x_obj
, owner
) + width
;
742 *yp2
= text_ypix(&s
->x_obj
, owner
) + height
;
745 static void fatom_displace(t_gobj
*z
, t_glist
*glist
,
748 t_fatom
*x
= (t_fatom
*)z
;
749 DEBUG(post("displace");)
750 x
->x_obj
.te_xpix
+= dx
;
751 x
->x_obj
.te_ypix
+= dy
;
752 if (glist_isvisible(glist
))
754 sys_vgui(".x%x.c coords %xSEL %d %d %d %d\n",
755 glist_getcanvas(glist
), x
,
756 text_xpix(&x
->x_obj
, glist
), text_ypix(&x
->x_obj
, glist
),
757 text_xpix(&x
->x_obj
, glist
) + x
->x_rect_width
, text_ypix(&x
->x_obj
, glist
) + x
->x_rect_height
);
759 fatom_drawme(x
, glist
, 0);
760 canvas_fixlinesfor(glist_getcanvas(glist
),(t_text
*) x
);
762 DEBUG(post("displace end");)
765 static void fatom_select(t_gobj
*z
, t_glist
*glist
, int state
)
767 t_fatom
*x
= (t_fatom
*)z
;
769 sys_vgui(".x%x.c create rectangle \
770 %d %d %d %d -tags %xSEL -outline blue\n",
771 glist_getcanvas(glist
),
772 text_xpix(&x
->x_obj
, glist
), text_ypix(&x
->x_obj
, glist
),
773 text_xpix(&x
->x_obj
, glist
) + x
->x_rect_width
, text_ypix(&x
->x_obj
, glist
) + x
->x_rect_height
,
777 sys_vgui(".x%x.c delete %xSEL\n",
778 glist_getcanvas(glist
), x
);
786 static void fatom_activate(t_gobj
*z
, t_glist
*glist
, int state
)
788 /* t_text *x = (t_text *)z;
789 t_rtext *y = glist_findrtext(glist, x);
790 if (z->g_pd != gatom_class) rtext_activate(y, state);*/
793 static void fatom_delete(t_gobj
*z
, t_glist
*glist
)
795 t_text
*x
= (t_text
*)z
;
796 canvas_deletelinesfor(glist_getcanvas(glist
), x
);
800 static void fatom_vis(t_gobj
*z
, t_glist
*glist
, int vis
)
802 t_fatom
* s
= (t_fatom
*)z
;
804 DEBUG(post("vis: %d",vis
);)
806 #ifdef PD_MINOR_VERSION
807 y
= (t_rtext
*) rtext_new(glist
, (t_text
*)z
);
809 y
= (t_rtext
*) rtext_new(glist
, (t_text
*)z
,0,0);
811 fatom_drawme(s
, glist
, 1);
814 y
= glist_findrtext(glist
, (t_text
*)z
);
815 fatom_erase(s
,glist
);
820 static void fatom_save(t_gobj
*z
, t_binbuf
*b
);
822 t_widgetbehavior fatom_widgetbehavior
;
827 static void fatom_size(t_fatom
* x
,t_floatarg w
,t_floatarg h
) {
829 x
->x_rect_height
= h
;
832 static void fatom_color(t_fatom
* x
,t_symbol
* col
)
838 static void fatom_f(t_fatom
* x
,t_floatarg f
)
841 if (x
->x_send
== &s_
)
842 outlet_float(x
->x_obj
.ob_outlet
,f
);
844 if (x
->x_send
->s_thing
) pd_float(x
->x_send
->s_thing
,f
);
848 static void fatom_float(t_fatom
* x
,t_floatarg f
)
850 if (glist_isvisible(x
->x_glist
)) {
851 if (!strcmp(x
->x_type
->s_name
,"checkbutton")) {
853 sys_vgui(".x%x.c.s%x select\n",x
->x_glist
,x
,f
);
855 sys_vgui(".x%x.c.s%x deselect\n",x
->x_glist
,x
,f
);
857 sys_vgui(".x%x.c.s%x set %f\n",x
->x_glist
,x
,f
);
863 static void fatom_bang(t_fatom
* x
,t_floatarg f
)
865 outlet_float(x
->x_obj
.ob_outlet
,x
->x_val
);
869 static void fatom_properties(t_gobj
*z
, t_glist
*owner
)
875 static void fatom_save(t_gobj
*z
, t_binbuf
*b
)
878 t_fatom
*x
= (t_fatom
*)z
;
880 binbuf_addv(b
, "ssiiss", gensym("#X"),gensym("obj"),
881 x
->x_obj
.te_xpix
, x
->x_obj
.te_ypix
,
882 gensym("fatom"),x
->x_type
);
887 static void *fatom_new(t_fatom
* x
,int argc
,t_atom
* argv
)
891 x
->x_glist
= canvas_getcurrent();
893 x
->x_text
= gensym("");
897 x
->x_color
= gensym("grey");
898 x
->x_bgcolor
= gensym("grey");
902 if (argv
->a_type
== A_FLOAT
) {
903 if (n
==0) x
->x_max
= atom_getfloat(argv
);
904 if (n
==1) x
->x_min
= atom_getfloat(argv
);
905 if (n
==2) x
->x_width
= atom_getfloat(argv
);
908 if (argv
->a_type
== A_SYMBOL
) {
909 post("%d: symbol value %s",n
,atom_getsymbol(argv
)->s_name
);
910 if (n
==3) x
->x_send
= atom_getsymbol(argv
);
911 if (n
==4) x
->x_color
= atom_getsymbol(argv
);
912 if (n
==5) x
->x_bgcolor
= atom_getsymbol(argv
);
919 /* bind to a symbol for slider callback (later make this based on the
922 sprintf(buf
,"fatom%x",(t_int
)x
);
923 x
->x_sym
= gensym(buf
);
924 pd_bind(&x
->x_obj
.ob_pd
, x
->x_sym
);
926 /* pipe startup code to tk */
928 sys_vgui("proc fatom_cb%x {v} {\n pd [concat fatom%x f $v \\;]\n }\n",x
,x
);
930 outlet_new(&x
->x_obj
, &s_float
);
934 static void fatom_setup_common(t_class
* class)
937 fatom_widgetbehavior
.w_getrectfn
= fatom_getrect
;
938 fatom_widgetbehavior
.w_displacefn
= fatom_displace
;
939 fatom_widgetbehavior
.w_selectfn
= fatom_select
;
940 fatom_widgetbehavior
.w_activatefn
= fatom_activate
;
941 fatom_widgetbehavior
.w_deletefn
= fatom_delete
;
942 fatom_widgetbehavior
.w_visfn
= fatom_vis
;
943 #if PD_MINOR_VERSION < 37
944 fatom_widgetbehavior
.w_savefn
= fatom_save
;
945 fatom_widgetbehavior
.w_propertiesfn
= NULL
;
947 fatom_widgetbehavior
.w_clickfn
= NULL
;
949 class_addfloat(class, (t_method
)fatom_float
);
950 class_addbang(class, (t_method
)fatom_bang
);
951 class_addmethod(class, (t_method
)fatom_f
, gensym("f"),
955 class_addmethod(class, (t_method)fatom_size, gensym("size"),
956 A_FLOAT, A_FLOAT, 0);
958 class_addmethod(class, (t_method)fatom_color, gensym("color"),
962 class_addmethod(class, (t_method)fatom_open, gensym("open"),
966 class_setwidget(class,&fatom_widgetbehavior
);
967 #if PD_MINOR_VERSION >= 37
968 class_setsavefn(class,&fatom_save
);