diff options
author | Peter D'Hoye <peter.dhoye@gmail.com> | 2009-05-24 21:28:16 +0000 |
---|---|---|
committer | Peter D'Hoye <peter.dhoye@gmail.com> | 2009-05-24 21:28:16 +0000 |
commit | 526b5580dabbfed7cfe5439dc3a90ec727f563c2 (patch) | |
tree | 22b1af92348785daad16714ee5e2b633017e0e48 /apps/plugins/pdbox/PDa/extra/gcanvas.c | |
parent | 4f2dfcc01b260d946044ef2b6af5fe36cb772c8d (diff) | |
download | rockbox-526b5580dabbfed7cfe5439dc3a90ec727f563c2.tar.gz rockbox-526b5580dabbfed7cfe5439dc3a90ec727f563c2.zip |
Cut the files in half and it might work better (note to self: check your tree is really clean before patching)
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@21070 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/plugins/pdbox/PDa/extra/gcanvas.c')
-rw-r--r-- | apps/plugins/pdbox/PDa/extra/gcanvas.c | 381 |
1 files changed, 1 insertions, 380 deletions
diff --git a/apps/plugins/pdbox/PDa/extra/gcanvas.c b/apps/plugins/pdbox/PDa/extra/gcanvas.c index aed5c96cec..9e3f934299 100644 --- a/apps/plugins/pdbox/PDa/extra/gcanvas.c +++ b/apps/plugins/pdbox/PDa/extra/gcanvas.c | |||
@@ -376,383 +376,4 @@ void gcanvas_setup(void) | |||
376 | class_setwidget(gcanvas_class,&gcanvas_widgetbehavior); | 376 | class_setwidget(gcanvas_class,&gcanvas_widgetbehavior); |
377 | } | 377 | } |
378 | 378 | ||
379 | 379 | ||
380 | /* (C) Guenter Geiger <geiger@xdv.org> */ | ||
381 | |||
382 | |||
383 | #include "m_pd.h" | ||
384 | #include "g_canvas.h" | ||
385 | |||
386 | /* ------------------------ gcanvas ----------------------------- */ | ||
387 | |||
388 | |||
389 | #define BACKGROUNDCOLOR "grey" | ||
390 | |||
391 | #define DEFAULTSIZE 80 | ||
392 | |||
393 | static t_class *gcanvas_class; | ||
394 | |||
395 | typedef struct _gcanvas | ||
396 | { | ||
397 | t_object x_obj; | ||
398 | t_glist * x_glist; | ||
399 | t_outlet* out2; | ||
400 | t_outlet* out3; | ||
401 | int x_width; | ||
402 | int x_height; | ||
403 | int x; | ||
404 | int y; | ||
405 | int x_xgrid; | ||
406 | int x_ygrid; | ||
407 | } t_gcanvas; | ||
408 | |||
409 | |||
410 | static void rectangle(void* cv,void* o,char c,int x, int y,int w,int h,char* color) { | ||
411 | sys_vgui(".x%x.c create rectangle \ | ||
412 | %d %d %d %d -tags %x%c -fill %s\n",cv,x,y,x+w,y+h,o,c,color); | ||
413 | } | ||
414 | |||
415 | static void move_object(void* cv,void* o,char c,int x, int y,int w,int h) { | ||
416 | sys_vgui(".x%x.c coords %x%c %d %d %d %d\n", | ||
417 | cv,o,c,x,y,x+w,y+h); | ||
418 | |||
419 | } | ||
420 | |||
421 | static void color_object(void* cv,void* o,char c,char* color) { | ||
422 | sys_vgui(".x%x.c itemconfigure %x%c -fill %s\n", cv, | ||
423 | o, c,color); | ||
424 | } | ||
425 | |||
426 | static void delete_object(void* cv,void* o,char c) { | ||
427 | sys_vgui(".x%x.c delete %x%c\n", | ||
428 | cv, o,c); | ||
429 | } | ||
430 | |||
431 | static void line(void* cv,void* o,char c,int x,int y,int w,int h,char* color) { | ||
432 | sys_vgui(".x%x.c create line \ | ||
433 | %d %d %d %d -tags %x%c -fill %s\n",cv,x,y,x+w,y+h,o,c,color); | ||
434 | } | ||
435 | |||
436 | |||
437 | /* widget helper functions */ | ||
438 | |||
439 | void gcanvas_drawme(t_gcanvas *x, t_glist *glist, int firsttime) | ||
440 | { | ||
441 | int i; | ||
442 | if (firsttime) { | ||
443 | rectangle(glist_getcanvas(glist),x,'a', | ||
444 | x->x_obj.te_xpix, x->x_obj.te_ypix, | ||
445 | x->x_width, x->x_height,BACKGROUNDCOLOR); | ||
446 | for (i=1;i<x->x_xgrid;i++) | ||
447 | line(glist_getcanvas(glist),x,'b'+ i, | ||
448 | x->x_obj.te_xpix + x->x_width*i/x->x_xgrid, | ||
449 | x->x_obj.te_ypix, | ||
450 | 0, x->x_height,"red"); | ||
451 | for (i=1;i<x->x_ygrid;i++) | ||
452 | line(glist_getcanvas(glist),x,'B'+ i, | ||
453 | x->x_obj.te_xpix, | ||
454 | x->x_obj.te_ypix + x->x_height*i/x->x_ygrid, | ||
455 | x->x_width, 0,"blue"); | ||
456 | } | ||
457 | else { | ||
458 | move_object( | ||
459 | glist_getcanvas(glist),x,'a', | ||
460 | x->x_obj.te_xpix, x->x_obj.te_ypix, | ||
461 | x->x_width, x->x_height); | ||
462 | for (i=1;i<x->x_xgrid;i++) | ||
463 | move_object(glist_getcanvas(glist),x,'b'+ i, | ||
464 | x->x_obj.te_xpix + x->x_width*i/x->x_xgrid, | ||
465 | x->x_obj.te_ypix, | ||
466 | 0, x->x_height); | ||
467 | for (i=1;i<x->x_ygrid;i++) | ||
468 | move_object(glist_getcanvas(glist),x,'B'+ i, | ||
469 | x->x_obj.te_xpix, | ||
470 | x->x_obj.te_ypix + x->x_height*i/x->x_ygrid, | ||
471 | x->x_width, 0); | ||
472 | } | ||
473 | |||
474 | { | ||
475 | /* outlets */ | ||
476 | int n = 3; | ||
477 | int nplus, i; | ||
478 | nplus = (n == 1 ? 1 : n-1); | ||
479 | for (i = 0; i < n; i++) | ||
480 | { | ||
481 | int onset = x->x_obj.te_xpix + (x->x_width - IOWIDTH) * i / nplus; | ||
482 | if (firsttime) | ||
483 | sys_vgui(".x%x.c create rectangle %d %d %d %d -tags %xo%d\n", | ||
484 | glist_getcanvas(glist), | ||
485 | onset, x->x_obj.te_ypix + x->x_height - 1, | ||
486 | onset + IOWIDTH, x->x_obj.te_ypix + x->x_height, | ||
487 | x, i); | ||
488 | else | ||
489 | sys_vgui(".x%x.c coords %xo%d %d %d %d %d\n", | ||
490 | glist_getcanvas(glist), x, i, | ||
491 | onset, x->x_obj.te_ypix + x->x_height - 1, | ||
492 | onset + IOWIDTH, x->x_obj.te_ypix + x->x_height); | ||
493 | } | ||
494 | /* inlets */ | ||
495 | n = 0; | ||
496 | nplus = (n == 1 ? 1 : n-1); | ||
497 | for (i = 0; i < n; i++) | ||
498 | { | ||
499 | int onset = x->x_obj.te_xpix + (x->x_width - IOWIDTH) * i / nplus; | ||
500 | if (firsttime) | ||
501 | sys_vgui(".x%x.c create rectangle %d %d %d %d -tags %xi%d\n", | ||
502 | glist_getcanvas(glist), | ||
503 | onset, x->x_obj.te_ypix, | ||
504 | onset + IOWIDTH, x->x_obj.te_ypix + 1, | ||
505 | x, i); | ||
506 | else | ||
507 | sys_vgui(".x%x.c coords %xi%d %d %d %d %d\n", | ||
508 | glist_getcanvas(glist), x, i, | ||
509 | onset, x->x_obj.te_ypix, | ||
510 | onset + IOWIDTH, x->x_obj.te_ypix + 1); | ||
511 | |||
512 | } | ||
513 | } | ||
514 | |||
515 | } | ||
516 | |||
517 | |||
518 | |||
519 | |||
520 | void gcanvas_erase(t_gcanvas* x,t_glist* glist) | ||
521 | { | ||
522 | int n,i; | ||
523 | delete_object(glist_getcanvas(glist),x,'a'); | ||
524 | for (i=1;i<x->x_xgrid;i++) | ||
525 | delete_object(glist_getcanvas(glist),x,'b'+ i); | ||
526 | for (i=1;i<x->x_ygrid;i++) | ||
527 | delete_object(glist_getcanvas(glist),x,'B'+ i); | ||
528 | |||
529 | n = 2; | ||
530 | while (n--) { | ||
531 | sys_vgui(".x%x.c delete %xo%d\n",glist_getcanvas(glist),x,n); | ||
532 | } | ||
533 | } | ||
534 | |||
535 | |||
536 | |||
537 | /* ------------------------ gcanvas widgetbehaviour----------------------------- */ | ||
538 | |||
539 | |||
540 | static void gcanvas_getrect(t_gobj *z, t_glist *owner, | ||
541 | int *xp1, int *yp1, int *xp2, int *yp2) | ||
542 | { | ||
543 | int width, height; | ||
544 | t_gcanvas* s = (t_gcanvas*)z; | ||
545 | |||
546 | |||
547 | width = s->x_width; | ||
548 | height = s->x_height; | ||
549 | *xp1 = s->x_obj.te_xpix; | ||
550 | *yp1 = s->x_obj.te_ypix; | ||
551 | *xp2 = s->x_obj.te_xpix + width; | ||
552 | *yp2 = s->x_obj.te_ypix + height; | ||
553 | } | ||
554 | |||
555 | static void gcanvas_displace(t_gobj *z, t_glist *glist, | ||
556 | int dx, int dy) | ||
557 | { | ||
558 | t_gcanvas *x = (t_gcanvas *)z; | ||
559 | x->x_obj.te_xpix += dx; | ||
560 | x->x_obj.te_ypix += dy; | ||
561 | gcanvas_drawme(x, glist, 0); | ||
562 | canvas_fixlinesfor(glist_getcanvas(glist),(t_text*) x); | ||
563 | } | ||
564 | |||
565 | static void gcanvas_select(t_gobj *z, t_glist *glist, int state) | ||
566 | { | ||
567 | t_gcanvas *x = (t_gcanvas *)z; | ||
568 | color_object(glist,x,'a',state ? "blue" : BACKGROUNDCOLOR); | ||
569 | } | ||
570 | |||
571 | |||
572 | static void gcanvas_activate(t_gobj *z, t_glist *glist, int state) | ||
573 | { | ||
574 | /* t_text *x = (t_text *)z; | ||
575 | t_rtext *y = glist_findrtext(glist, x); | ||
576 | if (z->g_pd != gatom_class) rtext_activate(y, state);*/ | ||
577 | } | ||
578 | |||
579 | static void gcanvas_delete(t_gobj *z, t_glist *glist) | ||
580 | { | ||
581 | t_text *x = (t_text *)z; | ||
582 | canvas_deletelinesfor(glist_getcanvas(glist), x); | ||
583 | } | ||
584 | |||
585 | |||
586 | static void gcanvas_vis(t_gobj *z, t_glist *glist, int vis) | ||
587 | { | ||
588 | t_gcanvas* s = (t_gcanvas*)z; | ||
589 | if (vis) | ||
590 | gcanvas_drawme(s, glist, 1); | ||
591 | else | ||
592 | gcanvas_erase(s,glist); | ||
593 | } | ||
594 | |||
595 | /* can we use the normal text save function ?? */ | ||
596 | |||
597 | static void gcanvas_save(t_gobj *z, t_binbuf *b) | ||
598 | { | ||
599 | t_gcanvas *x = (t_gcanvas *)z; | ||
600 | binbuf_addv(b, "ssiisiiii", gensym("#X"),gensym("obj"), | ||
601 | (t_int)x->x_obj.te_xpix, (t_int)x->x_obj.te_ypix, | ||
602 | gensym("gcanvas"),x->x_width,x->x_height, | ||
603 | x->x_xgrid, | ||
604 | x->x_ygrid); | ||
605 | binbuf_addv(b, ";"); | ||
606 | } | ||
607 | |||
608 | |||
609 | t_widgetbehavior gcanvas_widgetbehavior; | ||
610 | |||
611 | static void gcanvas_motion(t_gcanvas *x, t_floatarg dx, t_floatarg dy) | ||
612 | { | ||
613 | x->x += dx; | ||
614 | x->y += dy; | ||
615 | outlet_float(x->out2,x->y); | ||
616 | outlet_float(x->x_obj.ob_outlet,x->x); | ||
617 | } | ||
618 | |||
619 | void gcanvas_key(t_gcanvas *x, t_floatarg f) | ||
620 | { | ||
621 | post("key"); | ||
622 | } | ||
623 | |||
624 | |||
625 | static void gcanvas_click(t_gcanvas *x, | ||
626 | t_floatarg xpos, t_floatarg ypos, t_floatarg shift, t_floatarg ctrl, | ||
627 | t_floatarg doit,int up) | ||
628 | { | ||
629 | glist_grab(x->x_glist, &x->x_obj.te_g, (t_glistmotionfn) gcanvas_motion, | ||
630 | (t_glistkeyfn) NULL, xpos, ypos); | ||
631 | |||
632 | x->x = xpos - x->x_obj.te_xpix; | ||
633 | x->y = ypos - x->x_obj.te_ypix; | ||
634 | outlet_float(x->out2,x->y); | ||
635 | outlet_float(x->x_obj.ob_outlet,x->x); | ||
636 | outlet_float(x->out3,0); | ||
637 | } | ||
638 | |||
639 | static int gcanvas_newclick(t_gobj *z, struct _glist *glist, | ||
640 | int xpix, int ypix, int shift, int alt, int dbl, int doit) | ||
641 | { | ||
642 | if (doit) | ||
643 | gcanvas_click((t_gcanvas *)z, (t_floatarg)xpix, (t_floatarg)ypix, | ||
644 | (t_floatarg)shift, 0, (t_floatarg)alt,dbl); | ||
645 | |||
646 | if (dbl) outlet_float(((t_gcanvas*)z)->out3,1); | ||
647 | return (1); | ||
648 | } | ||
649 | |||
650 | void gcanvas_size(t_gcanvas* x,t_floatarg w,t_floatarg h) { | ||
651 | x->x_width = w; | ||
652 | x->x_height = h; | ||
653 | gcanvas_drawme(x, x->x_glist, 0); | ||
654 | } | ||
655 | |||
656 | static void gcanvas_setwidget(void) | ||
657 | { | ||
658 | gcanvas_widgetbehavior.w_getrectfn = gcanvas_getrect; | ||
659 | gcanvas_widgetbehavior.w_displacefn = gcanvas_displace; | ||
660 | gcanvas_widgetbehavior.w_selectfn = gcanvas_select; | ||
661 | gcanvas_widgetbehavior.w_activatefn = gcanvas_activate; | ||
662 | gcanvas_widgetbehavior.w_deletefn = gcanvas_delete; | ||
663 | gcanvas_widgetbehavior.w_visfn = gcanvas_vis; | ||
664 | gcanvas_widgetbehavior.w_clickfn = gcanvas_newclick; | ||
665 | class_setsavefn(gcanvas_class,gcanvas_save); | ||
666 | } | ||
667 | |||
668 | |||
669 | static void *gcanvas_new(t_symbol* s,t_int ac,t_atom* at) | ||
670 | { | ||
671 | t_gcanvas *x = (t_gcanvas *)pd_new(gcanvas_class); | ||
672 | |||
673 | x->x_glist = (t_glist*) canvas_getcurrent(); | ||
674 | |||
675 | |||
676 | /* Fetch the width */ | ||
677 | |||
678 | x->x_width = DEFAULTSIZE; | ||
679 | if (ac-- > 0) { | ||
680 | if (at->a_type != A_FLOAT) | ||
681 | error("gcanvas: wrong argument type"); | ||
682 | else | ||
683 | x->x_width = atom_getfloat(at++); | ||
684 | |||
685 | if (x->x_width < 0 || x->x_width > 2000) { | ||
686 | error("gcanvas: unallowed width %f",x->x_width); | ||
687 | x->x_width = DEFAULTSIZE; | ||
688 | } | ||
689 | } | ||
690 | |||
691 | /* Fetch the height */ | ||
692 | |||
693 | x->x_height = DEFAULTSIZE; | ||
694 | if (ac-- > 0) { | ||
695 | if (at->a_type != A_FLOAT) | ||
696 | error("gcanvas: wrong argument type"); | ||
697 | else | ||
698 | x->x_height = atom_getfloat(at++); | ||
699 | |||
700 | if (x->x_height < 0 || x->x_height > 2000) { | ||
701 | error("gcanvas: unallowed height %f",x->x_height); | ||
702 | x->x_width = DEFAULTSIZE; | ||
703 | } | ||
704 | } | ||
705 | |||
706 | /* Fetch the xgrid */ | ||
707 | |||
708 | x->x_xgrid = 0; | ||
709 | if (ac-- > 0) { | ||
710 | if (at->a_type != A_FLOAT) | ||
711 | error("gcanvas: wrong argument type"); | ||
712 | else | ||
713 | x->x_xgrid = atom_getfloat(at++); | ||
714 | |||
715 | if (x->x_xgrid < 0 || x->x_xgrid > x->x_width/2) { | ||
716 | error("gcanvas: unallowed xgrid %f",x->x_xgrid); | ||
717 | x->x_xgrid = 0; | ||
718 | } | ||
719 | } | ||
720 | |||
721 | /* Fetch the ygrid */ | ||
722 | |||
723 | x->x_ygrid = 0; | ||
724 | if (ac-- > 0) { | ||
725 | if (at->a_type != A_FLOAT) | ||
726 | error("gcanvas: wrong argument type"); | ||
727 | else | ||
728 | x->x_ygrid = atom_getfloat(at++); | ||
729 | |||
730 | if (x->x_ygrid < 0 || x->x_ygrid > x->x_height/2) { | ||
731 | error("gcanvas: unallowed xgrid %f",x->x_ygrid); | ||
732 | x->x_ygrid = 0; | ||
733 | } | ||
734 | } | ||
735 | |||
736 | outlet_new(&x->x_obj, &s_float); | ||
737 | x->out2 = outlet_new(&x->x_obj, &s_float); | ||
738 | x->out3 = outlet_new(&x->x_obj, &s_float); | ||
739 | return (x); | ||
740 | } | ||
741 | |||
742 | |||
743 | |||
744 | void gcanvas_setup(void) | ||
745 | { | ||
746 | gcanvas_class = class_new(gensym("gcanvas"), (t_newmethod)gcanvas_new, 0, | ||
747 | sizeof(t_gcanvas),0, A_GIMME,0); | ||
748 | |||
749 | class_addmethod(gcanvas_class, (t_method)gcanvas_click, gensym("click"), | ||
750 | A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, 0); | ||
751 | class_addmethod(gcanvas_class, (t_method)gcanvas_size, gensym("size"), | ||
752 | A_FLOAT, A_FLOAT, 0); | ||
753 | |||
754 | gcanvas_setwidget(); | ||
755 | class_setwidget(gcanvas_class,&gcanvas_widgetbehavior); | ||
756 | } | ||
757 | |||
758 | |||