summaryrefslogtreecommitdiff
path: root/apps/plugins/pdbox/PDa/src/g_mycanvas.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/pdbox/PDa/src/g_mycanvas.c')
-rw-r--r--apps/plugins/pdbox/PDa/src/g_mycanvas.c384
1 files changed, 0 insertions, 384 deletions
diff --git a/apps/plugins/pdbox/PDa/src/g_mycanvas.c b/apps/plugins/pdbox/PDa/src/g_mycanvas.c
index 24dfbb246b..92615e912f 100644
--- a/apps/plugins/pdbox/PDa/src/g_mycanvas.c
+++ b/apps/plugins/pdbox/PDa/src/g_mycanvas.c
@@ -383,388 +383,4 @@ void g_mycanvas_setup(void)
383 class_setsavefn(my_canvas_class, my_canvas_save); 383 class_setsavefn(my_canvas_class, my_canvas_save);
384 class_setpropertiesfn(my_canvas_class, my_canvas_properties); 384 class_setpropertiesfn(my_canvas_class, my_canvas_properties);
385} 385}
386/* Copyright (c) 1997-1999 Miller Puckette.
387 * For information on usage and redistribution, and for a DISCLAIMER OF ALL
388 * WARRANTIES, see the file, "LICENSE.txt," in this distribution. */
389
390/* g_7_guis.c written by Thomas Musil (c) IEM KUG Graz Austria 2000-2001 */
391/* thanks to Miller Puckette, Guenther Geiger and Krzystof Czaja */
392
393
394#include <stdlib.h>
395#include <string.h>
396#include <stdio.h>
397#include <ctype.h>
398#include "m_pd.h"
399#include "g_canvas.h"
400#include "t_tk.h"
401#include "g_all_guis.h"
402#include <math.h>
403
404#ifdef MSW
405#include <io.h>
406#else
407#include <unistd.h>
408#endif
409
410/* ---------- cnv my gui-canvas for a window ---------------- */
411
412t_widgetbehavior my_canvas_widgetbehavior;
413static t_class *my_canvas_class;
414
415/* widget helper functions */
416
417void my_canvas_draw_new(t_my_canvas *x, t_glist *glist)
418{
419 int xpos=text_xpix(&x->x_gui.x_obj, glist);
420 int ypos=text_ypix(&x->x_gui.x_obj, glist);
421 t_canvas *canvas=glist_getcanvas(glist);
422
423 sys_vgui(".x%x.c create rectangle %d %d %d %d -fill #%6.6x -outline #%6.6x -tags %xRECT\n",
424 canvas, xpos, ypos,
425 xpos + x->x_vis_w, ypos + x->x_vis_h,
426 x->x_gui.x_bcol, x->x_gui.x_bcol, x);
427 sys_vgui(".x%x.c create rectangle %d %d %d %d -outline #%6.6x -tags %xBASE\n",
428 canvas, xpos, ypos,
429 xpos + x->x_gui.x_w, ypos + x->x_gui.x_h,
430 x->x_gui.x_bcol, x);
431 sys_vgui(".x%x.c create text %d %d -text {%s} -anchor w \
432 -font {%s %d bold} -fill #%6.6x -tags %xLABEL\n",
433 canvas, xpos+x->x_gui.x_ldx, ypos+x->x_gui.x_ldy,
434 strcmp(x->x_gui.x_lab->s_name, "empty")?x->x_gui.x_lab->s_name:"",
435 x->x_gui.x_font, x->x_gui.x_fontsize, x->x_gui.x_lcol, x);
436}
437
438void my_canvas_draw_move(t_my_canvas *x, t_glist *glist)
439{
440 int xpos=text_xpix(&x->x_gui.x_obj, glist);
441 int ypos=text_ypix(&x->x_gui.x_obj, glist);
442 t_canvas *canvas=glist_getcanvas(glist);
443
444 sys_vgui(".x%x.c coords %xRECT %d %d %d %d\n",
445 canvas, x, xpos, ypos, xpos + x->x_vis_w,
446 ypos + x->x_vis_h);
447 sys_vgui(".x%x.c coords %xBASE %d %d %d %d\n",
448 canvas, x, xpos, ypos,
449 xpos + x->x_gui.x_w, ypos + x->x_gui.x_h);
450 sys_vgui(".x%x.c coords %xLABEL %d %d\n",
451 canvas, x, xpos+x->x_gui.x_ldx,
452 ypos+x->x_gui.x_ldy);
453}
454
455void my_canvas_draw_erase(t_my_canvas* x, t_glist* glist)
456{
457 t_canvas *canvas=glist_getcanvas(glist);
458
459 sys_vgui(".x%x.c delete %xBASE\n", canvas, x);
460 sys_vgui(".x%x.c delete %xRECT\n", canvas, x);
461 sys_vgui(".x%x.c delete %xLABEL\n", canvas, x);
462}
463
464void my_canvas_draw_config(t_my_canvas* x, t_glist* glist)
465{
466 t_canvas *canvas=glist_getcanvas(glist);
467
468 sys_vgui(".x%x.c itemconfigure %xRECT -fill #%6.6x -outline #%6.6x\n", canvas, x,
469 x->x_gui.x_bcol, x->x_gui.x_bcol);
470 sys_vgui(".x%x.c itemconfigure %xBASE -outline #%6.6x\n", canvas, x,
471 x->x_gui.x_fsf.x_selected?IEM_GUI_COLOR_SELECTED:x->x_gui.x_bcol);
472 sys_vgui(".x%x.c itemconfigure %xLABEL -font {%s %d bold} -fill #%6.6x -text {%s} \n",
473 canvas, x, x->x_gui.x_font, x->x_gui.x_fontsize, x->x_gui.x_lcol,
474 strcmp(x->x_gui.x_lab->s_name, "empty")?x->x_gui.x_lab->s_name:"");
475}
476
477void my_canvas_draw_select(t_my_canvas* x, t_glist* glist)
478{
479 t_canvas *canvas=glist_getcanvas(glist);
480
481 if(x->x_gui.x_fsf.x_selected)
482 {
483 sys_vgui(".x%x.c itemconfigure %xBASE -outline #%6.6x\n", canvas, x, IEM_GUI_COLOR_SELECTED);
484 }
485 else
486 {
487 sys_vgui(".x%x.c itemconfigure %xBASE -outline #%6.6x\n", canvas, x, x->x_gui.x_bcol);
488 }
489}
490
491void my_canvas_draw(t_my_canvas *x, t_glist *glist, int mode)
492{
493 if(mode == IEM_GUI_DRAW_MODE_MOVE)
494 my_canvas_draw_move(x, glist);
495 else if(mode == IEM_GUI_DRAW_MODE_NEW)
496 my_canvas_draw_new(x, glist);
497 else if(mode == IEM_GUI_DRAW_MODE_SELECT)
498 my_canvas_draw_select(x, glist);
499 else if(mode == IEM_GUI_DRAW_MODE_ERASE)
500 my_canvas_draw_erase(x, glist);
501 else if(mode == IEM_GUI_DRAW_MODE_CONFIG)
502 my_canvas_draw_config(x, glist);
503}
504
505/* ------------------------ cnv widgetbehaviour----------------------------- */
506
507static void my_canvas_getrect(t_gobj *z, t_glist *glist, int *xp1, int *yp1, int *xp2, int *yp2)
508{
509 t_my_canvas *x = (t_my_canvas *)z;
510
511 *xp1 = text_xpix(&x->x_gui.x_obj, glist);
512 *yp1 = text_ypix(&x->x_gui.x_obj, glist);
513 *xp2 = *xp1 + x->x_gui.x_w;
514 *yp2 = *yp1 + x->x_gui.x_h;
515}
516
517static void my_canvas_save(t_gobj *z, t_binbuf *b)
518{
519 t_my_canvas *x = (t_my_canvas *)z;
520 int bflcol[3];
521 t_symbol *srl[3];
522
523 iemgui_save(&x->x_gui, srl, bflcol);
524 binbuf_addv(b, "ssiisiiisssiiiiiii", gensym("#X"),gensym("obj"),
525 (t_int)x->x_gui.x_obj.te_xpix, (t_int)x->x_gui.x_obj.te_ypix,
526 gensym("cnv"), x->x_gui.x_w, x->x_vis_w, x->x_vis_h,
527 srl[0], srl[1], srl[2], x->x_gui.x_ldx, x->x_gui.x_ldy,
528 iem_fstyletoint(&x->x_gui.x_fsf), x->x_gui.x_fontsize,
529 bflcol[0], bflcol[2], iem_symargstoint(&x->x_gui.x_isa));
530 binbuf_addv(b, ";");
531}
532
533static void my_canvas_properties(t_gobj *z, t_glist *owner)
534{
535 t_my_canvas *x = (t_my_canvas *)z;
536 char buf[800];
537 t_symbol *srl[3];
538
539 iemgui_properties(&x->x_gui, srl);
540 sprintf(buf, "pdtk_iemgui_dialog %%s MY_CANVAS \
541 ------selectable_dimensions(pix):------ %d %d size: 0.0 0.0 empty \
542 ------visible_rectangle(pix)(pix):------ %d width: %d height: %d \
543 %d empty empty %d %d empty %d \
544 %s %s \
545 %s %d %d \
546 %d %d \
547 %d %d %d\n",
548 x->x_gui.x_w, 1,
549 x->x_vis_w, x->x_vis_h, 0,/*no_schedule*/
550 -1, -1, -1, -1,/*no linlog, no init, no multi*/
551 srl[0]->s_name, srl[1]->s_name,
552 srl[2]->s_name, x->x_gui.x_ldx, x->x_gui.x_ldy,
553 x->x_gui.x_fsf.x_font_style, x->x_gui.x_fontsize,
554 0xffffff & x->x_gui.x_bcol, -1/*no frontcolor*/, 0xffffff & x->x_gui.x_lcol);
555 gfxstub_new(&x->x_gui.x_obj.ob_pd, x, buf);
556}
557
558static void my_canvas_get_pos(t_my_canvas *x)
559{
560 if(x->x_gui.x_fsf.x_snd_able && x->x_gui.x_snd->s_thing)
561 {
562 x->x_at[0].a_w.w_float = text_xpix(&x->x_gui.x_obj, x->x_gui.x_glist);
563 x->x_at[1].a_w.w_float = text_ypix(&x->x_gui.x_obj, x->x_gui.x_glist);
564 pd_list(x->x_gui.x_snd->s_thing, &s_list, 2, x->x_at);
565 }
566}
567
568static void my_canvas_dialog(t_my_canvas *x, t_symbol *s, int argc, t_atom *argv)
569{
570 t_symbol *srl[3];
571 int a = (int)atom_getintarg(0, argc, argv);
572 int w = (int)atom_getintarg(2, argc, argv);
573 int h = (int)atom_getintarg(3, argc, argv);
574 int sr_flags = iemgui_dialog(&x->x_gui, srl, argc, argv);
575
576 x->x_gui.x_isa.x_loadinit = 0;
577 if(a < 1)
578 a = 1;
579 x->x_gui.x_w = a;
580 x->x_gui.x_h = x->x_gui.x_w;
581 if(w < 1)
582 w = 1;
583 x->x_vis_w = w;
584 if(h < 1)
585 h = 1;
586 x->x_vis_h = h;
587 (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_CONFIG);
588 (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_MOVE);
589}
590
591static void my_canvas_size(t_my_canvas *x, t_symbol *s, int ac, t_atom *av)
592{
593 int i = (int)atom_getintarg(0, ac, av);
594
595 if(i < 1)
596 i = 1;
597 x->x_gui.x_w = i;
598 x->x_gui.x_h = i;
599 iemgui_size((void *)x, &x->x_gui);
600}
601
602static void my_canvas_delta(t_my_canvas *x, t_symbol *s, int ac, t_atom *av)
603{iemgui_delta((void *)x, &x->x_gui, s, ac, av);}
604
605static void my_canvas_pos(t_my_canvas *x, t_symbol *s, int ac, t_atom *av)
606{iemgui_pos((void *)x, &x->x_gui, s, ac, av);}
607
608static void my_canvas_vis_size(t_my_canvas *x, t_symbol *s, int ac, t_atom *av)
609{
610 int i;
611
612 i = (int)atom_getintarg(0, ac, av);
613 if(i < 1)
614 i = 1;
615 x->x_vis_w = i;
616 if(ac > 1)
617 {
618 i = (int)atom_getintarg(1, ac, av);
619 if(i < 1)
620 i = 1;
621 }
622 x->x_vis_h = i;
623 if(glist_isvisible(x->x_gui.x_glist))
624 (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_MOVE);
625}
626
627static void my_canvas_color(t_my_canvas *x, t_symbol *s, int ac, t_atom *av)
628{iemgui_color((void *)x, &x->x_gui, s, ac, av);}
629
630static void my_canvas_send(t_my_canvas *x, t_symbol *s)
631{iemgui_send(x, &x->x_gui, s);}
632
633static void my_canvas_receive(t_my_canvas *x, t_symbol *s)
634{iemgui_receive(x, &x->x_gui, s);}
635
636static void my_canvas_label(t_my_canvas *x, t_symbol *s)
637{iemgui_label((void *)x, &x->x_gui, s);}
638
639static void my_canvas_label_pos(t_my_canvas *x, t_symbol *s, int ac, t_atom *av)
640{iemgui_label_pos((void *)x, &x->x_gui, s, ac, av);}
641
642static void my_canvas_label_font(t_my_canvas *x, t_symbol *s, int ac, t_atom *av)
643{iemgui_label_font((void *)x, &x->x_gui, s, ac, av);}
644
645static void *my_canvas_new(t_symbol *s, int argc, t_atom *argv)
646{
647 t_my_canvas *x = (t_my_canvas *)pd_new(my_canvas_class);
648 int bflcol[]={-233017, -1, -66577};
649 int a=IEM_GUI_DEFAULTSIZE, w=100, h=60;
650 int ldx=20, ldy=12, f=2, i=0;
651 int fs=14;
652 char str[144];
653
654 iem_inttosymargs(&x->x_gui.x_isa, 0);
655 iem_inttofstyle(&x->x_gui.x_fsf, 0);
656
657 if(((argc >= 10)&&(argc <= 13))
658 &&IS_A_FLOAT(argv,0)&&IS_A_FLOAT(argv,1)&&IS_A_FLOAT(argv,2))
659 {
660 a = (int)atom_getintarg(0, argc, argv);
661 w = (int)atom_getintarg(1, argc, argv);
662 h = (int)atom_getintarg(2, argc, argv);
663 }
664 if((argc >= 12)&&(IS_A_SYMBOL(argv,3)||IS_A_FLOAT(argv,3))&&(IS_A_SYMBOL(argv,4)||IS_A_FLOAT(argv,4)))
665 {
666 i = 2;
667 iemgui_new_getnames(&x->x_gui, 3, argv);
668 }
669 else if((argc == 11)&&(IS_A_SYMBOL(argv,3)||IS_A_FLOAT(argv,3)))
670 {
671 i = 1;
672 iemgui_new_getnames(&x->x_gui, 3, argv);
673 }
674 else iemgui_new_getnames(&x->x_gui, 3, 0);
675
676 if(((argc >= 10)&&(argc <= 13))
677 &&(IS_A_SYMBOL(argv,i+3)||IS_A_FLOAT(argv,i+3))&&IS_A_FLOAT(argv,i+4)
678 &&IS_A_FLOAT(argv,i+5)&&IS_A_FLOAT(argv,i+6)
679 &&IS_A_FLOAT(argv,i+7)&&IS_A_FLOAT(argv,i+8)
680 &&IS_A_FLOAT(argv,i+9))
681 {
682 /* disastrously, the "label" sits in a different part of the
683 message. So we have to track its location separately (in
684 the slot x_labelbindex) and initialize it specially here. */
685 iemgui_new_dogetname(&x->x_gui, i+3, argv);
686 x->x_gui.x_labelbindex = i+4;
687 ldx = (int)atom_getintarg(i+4, argc, argv);
688 ldy = (int)atom_getintarg(i+5, argc, argv);
689 iem_inttofstyle(&x->x_gui.x_fsf, atom_getintarg(i+6, argc, argv));
690 fs = (int)atom_getintarg(i+7, argc, argv);
691 bflcol[0] = (int)atom_getintarg(i+8, argc, argv);
692 bflcol[2] = (int)atom_getintarg(i+9, argc, argv);
693 }
694 if((argc == 13)&&IS_A_FLOAT(argv,i+10))
695 {
696 iem_inttosymargs(&x->x_gui.x_isa, atom_getintarg(i+10, argc, argv));
697 }
698 x->x_gui.x_draw = (t_iemfunptr)my_canvas_draw;
699 x->x_gui.x_fsf.x_snd_able = 1;
700 x->x_gui.x_fsf.x_rcv_able = 1;
701 x->x_gui.x_glist = (t_glist *)canvas_getcurrent();
702 if (!strcmp(x->x_gui.x_snd->s_name, "empty"))
703 x->x_gui.x_fsf.x_snd_able = 0;
704 if (!strcmp(x->x_gui.x_rcv->s_name, "empty"))
705 x->x_gui.x_fsf.x_rcv_able = 0;
706 if(a < 1)
707 a = 1;
708 x->x_gui.x_w = a;
709 x->x_gui.x_h = x->x_gui.x_w;
710 if(w < 1)
711 w = 1;
712 x->x_vis_w = w;
713 if(h < 1)
714 h = 1;
715 x->x_vis_h = h;
716 if(x->x_gui.x_fsf.x_font_style == 1) strcpy(x->x_gui.x_font, "helvetica");
717 else if(x->x_gui.x_fsf.x_font_style == 2) strcpy(x->x_gui.x_font, "times");
718 else { x->x_gui.x_fsf.x_font_style = 0;
719 strcpy(x->x_gui.x_font, "courier"); }
720 if (x->x_gui.x_fsf.x_rcv_able)
721 pd_bind(&x->x_gui.x_obj.ob_pd, x->x_gui.x_rcv);
722 x->x_gui.x_ldx = ldx;
723 x->x_gui.x_ldy = ldy;
724 if(fs < 4)
725 fs = 4;
726 x->x_gui.x_fontsize = fs;
727 iemgui_all_colfromload(&x->x_gui, bflcol);
728 x->x_at[0].a_type = A_FLOAT;
729 x->x_at[1].a_type = A_FLOAT;
730 iemgui_verify_snd_ne_rcv(&x->x_gui);
731 return (x);
732}
733
734static void my_canvas_ff(t_my_canvas *x)
735{
736 if(x->x_gui.x_fsf.x_rcv_able)
737 pd_unbind(&x->x_gui.x_obj.ob_pd, x->x_gui.x_rcv);
738 gfxstub_deleteforkey(x);
739}
740
741void g_mycanvas_setup(void)
742{
743 my_canvas_class = class_new(gensym("cnv"), (t_newmethod)my_canvas_new,
744 (t_method)my_canvas_ff, sizeof(t_my_canvas), CLASS_NOINLET, A_GIMME, 0);
745 class_addcreator((t_newmethod)my_canvas_new, gensym("my_canvas"), A_GIMME, 0);
746 class_addmethod(my_canvas_class, (t_method)my_canvas_dialog, gensym("dialog"), A_GIMME, 0);
747 class_addmethod(my_canvas_class, (t_method)my_canvas_size, gensym("size"), A_GIMME, 0);
748 class_addmethod(my_canvas_class, (t_method)my_canvas_delta, gensym("delta"), A_GIMME, 0);
749 class_addmethod(my_canvas_class, (t_method)my_canvas_pos, gensym("pos"), A_GIMME, 0);
750 class_addmethod(my_canvas_class, (t_method)my_canvas_vis_size, gensym("vis_size"), A_GIMME, 0);
751 class_addmethod(my_canvas_class, (t_method)my_canvas_color, gensym("color"), A_GIMME, 0);
752 class_addmethod(my_canvas_class, (t_method)my_canvas_send, gensym("send"), A_DEFSYM, 0);
753 class_addmethod(my_canvas_class, (t_method)my_canvas_receive, gensym("receive"), A_DEFSYM, 0);
754 class_addmethod(my_canvas_class, (t_method)my_canvas_label, gensym("label"), A_DEFSYM, 0);
755 class_addmethod(my_canvas_class, (t_method)my_canvas_label_pos, gensym("label_pos"), A_GIMME, 0);
756 class_addmethod(my_canvas_class, (t_method)my_canvas_label_font, gensym("label_font"), A_GIMME, 0);
757 class_addmethod(my_canvas_class, (t_method)my_canvas_get_pos, gensym("get_pos"), 0);
758 386
759 my_canvas_widgetbehavior.w_getrectfn = my_canvas_getrect;
760 my_canvas_widgetbehavior.w_displacefn = iemgui_displace;
761 my_canvas_widgetbehavior.w_selectfn = iemgui_select;
762 my_canvas_widgetbehavior.w_activatefn = NULL;
763 my_canvas_widgetbehavior.w_deletefn = iemgui_delete;
764 my_canvas_widgetbehavior.w_visfn = iemgui_vis;
765 my_canvas_widgetbehavior.w_clickfn = NULL;
766 class_setwidget(my_canvas_class, &my_canvas_widgetbehavior);
767 class_sethelpsymbol(my_canvas_class, gensym("my_canvas"));
768 class_setsavefn(my_canvas_class, my_canvas_save);
769 class_setpropertiesfn(my_canvas_class, my_canvas_properties);
770}