GitHub Sale: sign up for any paid plan this week and pay nothing until January 1, 2009!  [ hide ]

public
Description: a tiny graphical app kit for ruby
Homepage: http://code.whytheluckystiff.net/shoes
Clone URL: git://github.com/why/shoes.git
 * shoes/ruby.c: drawing optimization to skip any shapes that are out of 
 the clip area.
why (author)
Tue Aug 12 14:01:41 -0700 2008
commit  6d2c2e0b1745706cbff0de3e1efbf6f85d517b7a
tree    9fafaf3a90be337d9f439a23453a4f5b93dacb70
parent  1bdd95cf7ca636f3e20286548c7a01e8a9291fc1
...
609
610
611
 
 
 
 
 
 
 
 
 
 
 
 
 
612
613
614
...
616
617
618
 
 
619
620
621
...
632
633
634
 
 
635
636
637
...
643
644
645
 
 
646
647
648
...
657
658
659
 
 
660
661
662
...
682
683
684
 
 
685
686
687
...
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
...
629
630
631
632
633
634
635
636
...
647
648
649
650
651
652
653
654
...
660
661
662
663
664
665
666
667
...
676
677
678
679
680
681
682
683
...
703
704
705
706
707
708
709
710
0
@@ -609,6 +609,19 @@ shoes_shape_attr(int argc, VALUE *argv, int syms, ...)
0
   return hsh;
0
 }
0
 
0
+unsigned char
0
+shoes_shape_check(cairo_t *cr, shoes_place *place)
0
+{
0
+ double ox1 = place->ix, oy1 = place->iy, ox2 = place->ix + place->iw, oy2 = place->iy + place->ih;
0
+ double cx1, cy1, cx2, cy2;
0
+ cairo_clip_extents(cr, &cx1, &cy1, &cx2, &cy2);
0
+ cairo_user_to_device(cr, &ox1, &oy1);
0
+ cairo_user_to_device(cr, &ox2, &oy2);
0
+ if ((ox1 < cx1 && ox2 < cx1) || (oy1 < cy1 && oy2 < cy1) ||
0
+ (ox1 > cx2 && ox2 > cx2) || (oy1 > cy2 && oy2 > cy2)) return 0;
0
+ return 1;
0
+}
0
+
0
 void
0
 shoes_shape_sketch(cairo_t *cr, ID name, shoes_place *place, shoes_transform *st, VALUE attr)
0
 {
0
@@ -616,6 +629,8 @@ shoes_shape_sketch(cairo_t *cr, ID name, shoes_place *place, shoes_transform *st
0
   {
0
     double sw = ATTR2(dbl, attr, strokewidth, 1.);
0
     shoes_apply_transformation(cr, st, place, RTEST(ATTR(attr, center)), 1);
0
+ if (!shoes_shape_check(cr, place))
0
+ return shoes_undo_transformation(cr, st, place, 1);
0
     cairo_new_path(cr);
0
     cairo_translate(cr, (place->x * 1.) + (place->w / 2.), (place->y * 1.) + (place->h / 2.));
0
     cairo_scale(cr, place->w / 2., place->h / 2.);
0
@@ -632,6 +647,8 @@ shoes_shape_sketch(cairo_t *cr, ID name, shoes_place *place, shoes_transform *st
0
     cv = ATTR2(dbl, attr, curve, 0.);
0
 
0
     shoes_apply_transformation(cr, st, place, RTEST(ATTR(attr, center)), 0);
0
+ if (!shoes_shape_check(cr, place))
0
+ return shoes_undo_transformation(cr, st, place, 0);
0
     shoes_cairo_rect(cr, SWPOS(place->x), SWPOS(place->y), place->w * 1., place->h * 1., cv);
0
     shoes_undo_transformation(cr, st, place, 0);
0
     PATH_OUT(cr, attr, *place, sw, fill, cairo_fill_preserve);
0
@@ -643,6 +660,8 @@ shoes_shape_sketch(cairo_t *cr, ID name, shoes_place *place, shoes_transform *st
0
     double sw, cv;
0
     sw = ATTR2(dbl, attr, strokewidth, 1.);
0
     shoes_apply_transformation(cr, st, place, RTEST(ATTR(attr, center)), 0);
0
+ if (!shoes_shape_check(cr, place))
0
+ return shoes_undo_transformation(cr, st, place, 0);
0
     cairo_move_to(cr, SWPOS(place->ix), SWPOS(place->iy));
0
     cairo_line_to(cr, SWPOS(place->ix + place->iw), SWPOS(place->iy + place->ih));
0
     shoes_undo_transformation(cr, st, place, 0);
0
@@ -657,6 +676,8 @@ shoes_shape_sketch(cairo_t *cr, ID name, shoes_place *place, shoes_transform *st
0
     sw = ATTR2(dbl, attr, strokewidth, 1.);
0
 
0
     shoes_apply_transformation(cr, st, place, RTEST(ATTR(attr, center)), 0);
0
+ if (!shoes_shape_check(cr, place))
0
+ return shoes_undo_transformation(cr, st, place, 0);
0
     cairo_move_to(cr, SWPOS(x), SWPOS(place->y));
0
     cairo_rel_line_to(cr, -tip, +(h*0.5));
0
     cairo_rel_line_to(cr, 0, -(h*0.25));
0
@@ -682,6 +703,8 @@ shoes_shape_sketch(cairo_t *cr, ID name, shoes_place *place, shoes_transform *st
0
     {
0
       place->w = place->h = outer;
0
       shoes_apply_transformation(cr, st, place, RTEST(ATTR(attr, center)), 0);
0
+ if (!shoes_shape_check(cr, place))
0
+ return shoes_undo_transformation(cr, st, place, 0);
0
       cairo_move_to(cr, place->x * 1., (place->y * 1.) + outer);
0
       for (i = 1; i <= points * 2; i++) {
0
         angle = (i * SHOES_PI) / (points * 1.);

Comments

    No one has commented yet.