diff options
Diffstat (limited to 'apps/plugins/pdbox/PDa/extra/fatom.h')
-rw-r--r-- | apps/plugins/pdbox/PDa/extra/fatom.h | 484 |
1 files changed, 0 insertions, 484 deletions
diff --git a/apps/plugins/pdbox/PDa/extra/fatom.h b/apps/plugins/pdbox/PDa/extra/fatom.h index abaf9b91c1..a7a153fad3 100644 --- a/apps/plugins/pdbox/PDa/extra/fatom.h +++ b/apps/plugins/pdbox/PDa/extra/fatom.h | |||
@@ -483,488 +483,4 @@ static void fatom_setup_common(t_class* class) | |||
483 | class_setsavefn(class,&fatom_save); | 483 | class_setsavefn(class,&fatom_save); |
484 | #endif | 484 | #endif |
485 | } | 485 | } |
486 | /* ------------------------ fatom ----------------------------- */ | ||
487 | |||
488 | #define x_val a_pos.a_w.w_float | ||
489 | #define DEBUG(x) | ||
490 | |||
491 | #include <string.h> | ||
492 | #include <stdio.h> | ||
493 | |||
494 | typedef struct _fatom | ||
495 | { | ||
496 | t_object x_obj; | ||
497 | t_atom a_pos; /* the value of the fatom */ | ||
498 | |||
499 | t_symbol* x_send; | ||
500 | t_symbol* x_receive; | ||
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) */ | ||
506 | |||
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) */ | ||
511 | t_symbol* x_color; | ||
512 | t_symbol* x_bgcolor; | ||
513 | } t_fatom; | ||
514 | |||
515 | /* widget helper functions */ | ||
516 | |||
517 | |||
518 | |||
519 | |||
520 | static void draw_inlets(t_fatom *x, t_glist *glist, int firsttime, int nin, int nout) | ||
521 | { | ||
522 | int n = nin; | ||
523 | int nplus, i; | ||
524 | nplus = (n == 1 ? 1 : n-1); | ||
525 | DEBUG(post("draw inlet");) | ||
526 | for (i = 0; i < n; i++) | ||
527 | { | ||
528 | int onset = text_xpix(&x->x_obj, glist) + (x->x_rect_width - IOWIDTH) * i / nplus; | ||
529 | if (firsttime) | ||
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, | ||
534 | x, i); | ||
535 | else | ||
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); | ||
540 | } | ||
541 | n = nout; | ||
542 | nplus = (n == 1 ? 1 : n-1); | ||
543 | for (i = 0; i < n; i++) | ||
544 | { | ||
545 | int onset = text_xpix(&x->x_obj, glist) + (x->x_rect_width - IOWIDTH) * i / nplus; | ||
546 | if (firsttime) | ||
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, | ||
551 | x, i); | ||
552 | else | ||
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); | ||
557 | |||
558 | } | ||
559 | DEBUG(post("draw inlet end");) | ||
560 | } | ||
561 | |||
562 | |||
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); | ||
565 | |||
566 | if (firsttime) | ||
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, | ||
571 | x); | ||
572 | else | ||
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); | ||
577 | } | ||
578 | |||
579 | static void create_widget(t_fatom *x, t_glist *glist) | ||
580 | { | ||
581 | t_canvas *canvas=glist_getcanvas(glist); | ||
582 | |||
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; | ||
586 | |||
587 | sys_vgui("scale .x%x.c.s%x \ | ||
588 | -sliderlength 10 \ | ||
589 | -showvalue 0 \ | ||
590 | -length %d \ | ||
591 | -resolution 0.01 \ | ||
592 | -repeatinterval 20 \ | ||
593 | -from %d -to %d \ | ||
594 | -width %d \ | ||
595 | -bg %s \ | ||
596 | -activebackground %s \ | ||
597 | -troughcolor %s \ | ||
598 | -command fatom_cb%x\n",canvas,x, | ||
599 | x->x_max-x->x_min+14, | ||
600 | x->x_max, | ||
601 | x->x_min, | ||
602 | x->x_width, | ||
603 | x->x_color->s_name, | ||
604 | x->x_color->s_name, | ||
605 | x->x_bgcolor->s_name, | ||
606 | x); | ||
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 \ | ||
611 | -sliderlength 10 \ | ||
612 | -showvalue 0 \ | ||
613 | -length %d \ | ||
614 | -resolution 0.01 \ | ||
615 | -orient horizontal \ | ||
616 | -repeatinterval 20 \ | ||
617 | -from %d -to %d \ | ||
618 | -width %d \ | ||
619 | -bg %s \ | ||
620 | -activebackground %s \ | ||
621 | -troughcolor %s \ | ||
622 | -command fatom_cb%x\n",canvas,x, | ||
623 | x->x_max-x->x_min+14, | ||
624 | x->x_min, | ||
625 | x->x_max, | ||
626 | x->x_width, | ||
627 | x->x_color->s_name, | ||
628 | x->x_color->s_name, | ||
629 | x->x_bgcolor->s_name, | ||
630 | x); | ||
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\" \ | ||
636 | -bg %s \ | ||
637 | -activebackground %s \ | ||
638 | \n",canvas,x,x,x,x, | ||
639 | x->x_text->s_name, | ||
640 | x->x_color->s_name, | ||
641 | x->x_bgcolor->s_name); | ||
642 | } else if (!strcmp(x->x_type->s_name,"hradio")) { | ||
643 | int i; | ||
644 | x->x_rect_width = 8*20; | ||
645 | x->x_rect_height = 25; | ||
646 | for (i=0;i<8;i++) { | ||
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); | ||
649 | } | ||
650 | /* TODO pack them */ | ||
651 | } else if (!strcmp(x->x_type->s_name,"vradio")) { | ||
652 | int i; | ||
653 | x->x_rect_width = 30; | ||
654 | x->x_rect_height = 20*8+5; | ||
655 | for (i=0;i<8;i++) { | ||
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); | ||
658 | } | ||
659 | /* TODO pack them */ | ||
660 | } else { | ||
661 | x->x_rect_width = 32; | ||
662 | x->x_rect_height = 140; | ||
663 | sys_vgui("scale .x%x.c.s%x \ | ||
664 | -sliderlength 10 \ | ||
665 | -showvalue 0 \ | ||
666 | -length 131 \ | ||
667 | -from 127 -to 0 \ | ||
668 | -command fatom_cb%x\n",canvas,x,x); | ||
669 | } | ||
670 | |||
671 | /* set the start value */ | ||
672 | if (!strcmp(x->x_type->s_name,"checkbutton")) { | ||
673 | if (x->x_val) | ||
674 | sys_vgui(".x%x.c.s%x select\n",canvas,x,x->x_val); | ||
675 | else | ||
676 | sys_vgui(".x%x.c.s%x deselect\n",canvas,x,x->x_val); | ||
677 | } else | ||
678 | sys_vgui(".x%x.c.s%x set %f\n",canvas,x,x->x_val); | ||
679 | |||
680 | } | ||
681 | |||
682 | |||
683 | |||
684 | |||
685 | |||
686 | static void fatom_drawme(t_fatom *x, t_glist *glist, int firsttime) | ||
687 | { | ||
688 | t_canvas *canvas=glist_getcanvas(glist);// x->x_glist;//glist_getcanvas(glist); | ||
689 | DEBUG(post("drawme %d",firsttime);) | ||
690 | if (firsttime) { | ||
691 | DEBUG(post("glist %x canvas %x",x->x_glist,canvas)); | ||
692 | create_widget(x,glist); | ||
693 | x->x_glist = canvas; | ||
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); | ||
696 | |||
697 | } | ||
698 | else { | ||
699 | sys_vgui(".x%x.c coords %xS \ | ||
700 | %d %d\n", | ||
701 | canvas, x, | ||
702 | text_xpix(&x->x_obj, glist), text_ypix(&x->x_obj, glist)+2); | ||
703 | } | ||
704 | draw_inlets(x, glist, firsttime, 1,1); | ||
705 | // draw_handle(x, glist, firsttime); | ||
706 | |||
707 | } | ||
708 | |||
709 | |||
710 | static void fatom_erase(t_fatom* x,t_glist* glist) | ||
711 | { | ||
712 | int n; | ||
713 | |||
714 | DEBUG(post("erase");) | ||
715 | sys_vgui("destroy .x%x.c.s%x\n",glist_getcanvas(glist),x); | ||
716 | |||
717 | sys_vgui(".x%x.c delete %xS\n",glist_getcanvas(glist), x); | ||
718 | |||
719 | /* inlets and outlets */ | ||
720 | |||
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); | ||
724 | } | ||
725 | |||
726 | |||
727 | |||
728 | /* ------------------------ fatom widgetbehaviour----------------------------- */ | ||
729 | |||
730 | |||
731 | static void fatom_getrect(t_gobj *z, t_glist *owner, | ||
732 | int *xp1, int *yp1, int *xp2, int *yp2) | ||
733 | { | ||
734 | int width, height; | ||
735 | t_fatom* s = (t_fatom*)z; | ||
736 | |||
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; | ||
743 | } | ||
744 | |||
745 | static void fatom_displace(t_gobj *z, t_glist *glist, | ||
746 | int dx, int dy) | ||
747 | { | ||
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)) | ||
753 | { | ||
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); | ||
758 | |||
759 | fatom_drawme(x, glist, 0); | ||
760 | canvas_fixlinesfor(glist_getcanvas(glist),(t_text*) x); | ||
761 | } | ||
762 | DEBUG(post("displace end");) | ||
763 | } | ||
764 | |||
765 | static void fatom_select(t_gobj *z, t_glist *glist, int state) | ||
766 | { | ||
767 | t_fatom *x = (t_fatom *)z; | ||
768 | if (state) { | ||
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, | ||
774 | x); | ||
775 | } | ||
776 | else { | ||
777 | sys_vgui(".x%x.c delete %xSEL\n", | ||
778 | glist_getcanvas(glist), x); | ||
779 | } | ||
780 | |||
781 | |||
782 | |||
783 | } | ||
784 | |||
785 | |||
786 | static void fatom_activate(t_gobj *z, t_glist *glist, int state) | ||
787 | { | ||
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);*/ | ||
791 | } | ||
792 | |||
793 | static void fatom_delete(t_gobj *z, t_glist *glist) | ||
794 | { | ||
795 | t_text *x = (t_text *)z; | ||
796 | canvas_deletelinesfor(glist_getcanvas(glist), x); | ||
797 | } | ||
798 | |||
799 | |||
800 | static void fatom_vis(t_gobj *z, t_glist *glist, int vis) | ||
801 | { | ||
802 | t_fatom* s = (t_fatom*)z; | ||
803 | t_rtext *y; | ||
804 | DEBUG(post("vis: %d",vis);) | ||
805 | if (vis) { | ||
806 | #ifdef PD_MINOR_VERSION | ||
807 | y = (t_rtext *) rtext_new(glist, (t_text *)z); | ||
808 | #else | ||
809 | y = (t_rtext *) rtext_new(glist, (t_text *)z,0,0); | ||
810 | #endif | ||
811 | fatom_drawme(s, glist, 1); | ||
812 | } | ||
813 | else { | ||
814 | y = glist_findrtext(glist, (t_text *)z); | ||
815 | fatom_erase(s,glist); | ||
816 | rtext_free(y); | ||
817 | } | ||
818 | } | ||
819 | |||
820 | static void fatom_save(t_gobj *z, t_binbuf *b); | ||
821 | |||
822 | t_widgetbehavior fatom_widgetbehavior; | ||
823 | |||
824 | |||
825 | |||
826 | |||
827 | static void fatom_size(t_fatom* x,t_floatarg w,t_floatarg h) { | ||
828 | x->x_rect_width = w; | ||
829 | x->x_rect_height = h; | ||
830 | } | ||
831 | |||
832 | static void fatom_color(t_fatom* x,t_symbol* col) | ||
833 | { | ||
834 | |||
835 | } | ||
836 | |||
837 | |||
838 | static void fatom_f(t_fatom* x,t_floatarg f) | ||
839 | { | ||
840 | x->x_val = f; | ||
841 | if (x->x_send == &s_) | ||
842 | outlet_float(x->x_obj.ob_outlet,f); | ||
843 | else | ||
844 | if (x->x_send->s_thing) pd_float(x->x_send->s_thing,f); | ||
845 | } | ||
846 | |||
847 | |||
848 | static void fatom_float(t_fatom* x,t_floatarg f) | ||
849 | { | ||
850 | if (glist_isvisible(x->x_glist)) { | ||
851 | if (!strcmp(x->x_type->s_name,"checkbutton")) { | ||
852 | if (x->x_val) | ||
853 | sys_vgui(".x%x.c.s%x select\n",x->x_glist,x,f); | ||
854 | else | ||
855 | sys_vgui(".x%x.c.s%x deselect\n",x->x_glist,x,f); | ||
856 | } else | ||
857 | sys_vgui(".x%x.c.s%x set %f\n",x->x_glist,x,f); | ||
858 | } | ||
859 | fatom_f(x,f); | ||
860 | } | ||
861 | 486 | ||
862 | |||
863 | static void fatom_bang(t_fatom* x,t_floatarg f) | ||
864 | { | ||
865 | outlet_float(x->x_obj.ob_outlet,x->x_val); | ||
866 | } | ||
867 | |||
868 | |||
869 | static void fatom_properties(t_gobj *z, t_glist *owner) | ||
870 | { | ||
871 | post("N/I"); | ||
872 | } | ||
873 | |||
874 | |||
875 | static void fatom_save(t_gobj *z, t_binbuf *b) | ||
876 | { | ||
877 | |||
878 | t_fatom *x = (t_fatom *)z; | ||
879 | |||
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); | ||
883 | binbuf_addv(b, ";"); | ||
884 | } | ||
885 | |||
886 | |||
887 | static void *fatom_new(t_fatom* x,int argc,t_atom* argv) | ||
888 | { | ||
889 | char buf[256]; | ||
890 | int n = 0; | ||
891 | x->x_glist = canvas_getcurrent(); | ||
892 | |||
893 | x->x_text = gensym(""); | ||
894 | x->x_max = 127; | ||
895 | x->x_min = 0; | ||
896 | x->x_width = 15; | ||
897 | x->x_color = gensym("grey"); | ||
898 | x->x_bgcolor = gensym("grey"); | ||
899 | x->x_send = &s_; | ||
900 | |||
901 | while (argc) { | ||
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); | ||
906 | } | ||
907 | |||
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); | ||
913 | } | ||
914 | argv++; | ||
915 | argc--; | ||
916 | n++; | ||
917 | } | ||
918 | |||
919 | /* bind to a symbol for slider callback (later make this based on the | ||
920 | filepath ??) */ | ||
921 | |||
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); | ||
925 | |||
926 | /* pipe startup code to tk */ | ||
927 | |||
928 | sys_vgui("proc fatom_cb%x {v} {\n pd [concat fatom%x f $v \\;]\n }\n",x,x); | ||
929 | |||
930 | outlet_new(&x->x_obj, &s_float); | ||
931 | return (x); | ||
932 | } | ||
933 | |||
934 | static void fatom_setup_common(t_class* class) | ||
935 | { | ||
936 | |||
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; | ||
946 | #endif | ||
947 | fatom_widgetbehavior.w_clickfn = NULL; | ||
948 | |||
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"), | ||
952 | A_FLOAT, 0); | ||
953 | |||
954 | /* | ||
955 | class_addmethod(class, (t_method)fatom_size, gensym("size"), | ||
956 | A_FLOAT, A_FLOAT, 0); | ||
957 | |||
958 | class_addmethod(class, (t_method)fatom_color, gensym("color"), | ||
959 | A_SYMBOL, 0); | ||
960 | */ | ||
961 | /* | ||
962 | class_addmethod(class, (t_method)fatom_open, gensym("open"), | ||
963 | A_SYMBOL, 0); | ||
964 | */ | ||
965 | |||
966 | class_setwidget(class,&fatom_widgetbehavior); | ||
967 | #if PD_MINOR_VERSION >= 37 | ||
968 | class_setsavefn(class,&fatom_save); | ||
969 | #endif | ||
970 | } | ||