Changeset 120
- Timestamp:
- 08/19/2007 17:59:05 (13 months ago)
- Location:
- trunk
- Files:
-
- 13 modified
-
lib/shoes.rb (modified) (1 diff)
-
samples/anim-move.rb (modified) (1 diff)
-
samples/bounce.rb (modified) (1 diff)
-
samples/calc.rb (modified) (1 diff)
-
samples/draw.rb (modified) (1 diff)
-
samples/edit.rb (modified) (1 diff)
-
samples/follow.rb (modified) (2 diffs)
-
samples/rect.rb (modified) (1 diff)
-
samples/timer.rb (modified) (1 diff)
-
shoes/canvas.c (modified) (3 diffs)
-
shoes/canvas.h (modified) (3 diffs)
-
shoes/ruby.c (modified) (16 diffs)
-
shoes/ruby.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/shoes.rb
r115 r120 9 9 class Range 10 10 def rand 11 (Kernel.rand * (self.end - self.begin)) + self.begin 11 conv = (self.end === Integer && self.begin === Integer ? :to_i : :to_f) 12 ((Kernel.rand * (self.end - self.begin)) + self.begin).send(conv) 12 13 end 13 14 end -
trunk/samples/anim-move.rb
r97 r120 1 1 Shoes.app do 2 background "rgb(0, 0, 0)"3 fill 1.0, 1.0, 1.02 background rgb(0, 0, 0) 3 fill rgb(255, 255, 255) 4 4 rects = [ 5 5 rect(0, 0, 50, 50), -
trunk/samples/bounce.rb
r115 r120 8 8 animate(30) do 9 9 clear do 10 background "rgb(102, 102, 102)"10 background rgb(102, 102, 102) 11 11 x += xspeed * xdir 12 12 y += yspeed * ydir -
trunk/samples/calc.rb
r85 r120 42 42 43 43 stack :margin => 4 do 44 background "rgb(240, 240, 210)", :radius => 544 background rgb(240, 240, 210), :radius => 5 45 45 46 46 stack do -
trunk/samples/draw.rb
r113 r120 1 1 Shoes.app do 2 background " rgb(102, 102, 102)"3 stroke 0, 0, 02 background "#999" 3 stroke "#000" 4 4 x, y = nil, nil 5 5 motion do |_x, _y| -
trunk/samples/edit.rb
r27 r120 1 1 str, t = "", nil 2 2 Shoes.app :height => 500, :width => 450 do 3 background "rgb(77, 77, 77)"3 background rgb(77, 77, 77) 4 4 stack :margin => 10 do 5 5 text "<span color='white'><span color='red' background='white'>TEXT EDITOR</span> * USE ALT-Q TO QUIT</span>" -
trunk/samples/follow.rb
r108 r120 2 2 Shoes.app do 3 3 nostroke 4 fill 1.0, 1.0, 1.0, 0.64 fill rgb(0x30, 0xFF, 0xFF, 0.6) 5 5 animate(24) do 6 6 trails.shift … … 8 8 9 9 clear do 10 background "rgb(51, 51, 51)"10 background rgb(51, 51, 51) 11 11 trails.each_with_index do |(x, y), i| 12 12 i += 1 -
trunk/samples/rect.rb
r86 r120 2 2 20.times do 3 3 nostroke 4 fill (0.6..1.0).rand, (0.1..1.0).rand, (0.2..1.0).rand, (0.4..1.0).rand4 fill rgb((0.6..1.0).rand, (0.1..1.0).rand, (0.2..1.0).rand, (0.4..1.0).rand) 5 5 r = rand(300) + 60 6 6 rect (10..100).rand, (10..200).rand, r, r -
trunk/samples/timer.rb
r12 r120 1 1 label, time = nil, Time.now 2 2 Shoes.app :height => 150, :width => 250 do 3 background "rgb(240, 250, 208)"3 background rgb(240, 250, 208) 4 4 stack :margin => 10 do 5 5 button "Start" do -
trunk/shoes/canvas.c
r115 r120 240 240 canvas->cr = cairo_create(cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 1, 1));; 241 241 canvas->sw = 1.; 242 canvas->fg.r = 0 .;243 canvas->fg.g = 0 .;244 canvas->fg.b = 0 .;245 canvas->fg.a = 1.;242 canvas->fg.r = 0x00; 243 canvas->fg.g = 0x00; 244 canvas->fg.b = 0x00; 245 canvas->fg.a = 0xFF; 246 246 canvas->fg.on = TRUE; 247 canvas->bg.r = 0 .;248 canvas->bg.g = 0 .;249 canvas->bg.b = 0 .;250 canvas->bg.a = 1.;247 canvas->bg.r = 0x00; 248 canvas->bg.g = 0x00; 249 canvas->bg.b = 0x00; 250 canvas->bg.a = 0xFF; 251 251 canvas->bg.on = TRUE; 252 252 canvas->mode = s_center; … … 299 299 shoes_canvas_stroke(int argc, VALUE *argv, VALUE self) 300 300 { 301 VALUE _r, _g, _b, _a; 302 SETUP(); 303 304 rb_scan_args(argc, argv, "31", &_r, &_g, &_b, &_a); 305 canvas->fg.on = TRUE; 306 canvas->fg.r = NUM2DBL(_r); 307 canvas->fg.g = NUM2DBL(_g); 308 canvas->fg.b = NUM2DBL(_b); 309 canvas->fg.a = 1.0; 310 if (!NIL_P(_a)) canvas->fg.a = NUM2DBL(_a); 301 shoes_color *color; 302 VALUE _r, _g, _b, _a, _color; 303 SETUP(); 304 305 argc = rb_scan_args(argc, argv, "13", &_r, &_g, &_b, &_a); 306 if (argc == 1 && rb_obj_is_kind_of(_r, cColor)) 307 _color = _r; 308 else if (argc == 1 && rb_obj_is_kind_of(_r, rb_cString)) 309 _color = shoes_color_parse(cColor, _r); 310 else if (argc == 1 || argc == 2) 311 _color = shoes_color_gray(argc, argv, cColor); 312 else 313 _color = shoes_color_rgb(argc, argv, cColor); 314 315 Data_Get_Struct(_color, shoes_color, color); 316 canvas->fg = *color; 311 317 312 318 return self; … … 333 339 shoes_canvas_fill(int argc, VALUE *argv, VALUE self) 334 340 { 335 VALUE _r, _g, _b, _a; 336 SETUP(); 337 338 rb_scan_args(argc, argv, "31", &_r, &_g, &_b, &_a); 339 canvas->bg.on = TRUE; 340 canvas->bg.r = NUM2DBL(_r); 341 canvas->bg.g = NUM2DBL(_g); 342 canvas->bg.b = NUM2DBL(_b); 343 canvas->bg.a = 1.0; 344 if (!NIL_P(_a)) canvas->bg.a = NUM2DBL(_a); 341 shoes_color *color; 342 VALUE _r, _g, _b, _a, _color; 343 SETUP(); 344 345 argc = rb_scan_args(argc, argv, "13", &_r, &_g, &_b, &_a); 346 if (argc == 1 && rb_obj_is_kind_of(_r, cColor)) 347 _color = _r; 348 else if (argc == 1 && rb_obj_is_kind_of(_r, rb_cString)) 349 _color = shoes_color_parse(cColor, _r); 350 else if (argc == 1 || argc == 2) 351 _color = shoes_color_gray(argc, argv, cColor); 352 else 353 _color = shoes_color_rgb(argc, argv, cColor); 354 355 Data_Get_Struct(_color, shoes_color, color); 356 canvas->bg = *color; 345 357 346 358 return self; -
trunk/shoes/canvas.h
r119 r120 27 27 // 28 28 typedef struct { 29 double r, g, b, a; 30 unsigned char on; 29 unsigned char r, g, b, a, on; 31 30 } shoes_color; 32 31 … … 181 180 VALUE shoes_canvas_nofill(VALUE); 182 181 VALUE shoes_canvas_fill(int, VALUE *, VALUE); 182 VALUE shoes_canvas_rgb(int, VALUE *, VALUE); 183 VALUE shoes_canvas_gray(int, VALUE *, VALUE); 183 184 VALUE shoes_canvas_rect(int, VALUE *, VALUE); 184 185 VALUE shoes_canvas_oval(VALUE, VALUE, VALUE, VALUE, VALUE); … … 278 279 void shoes_anim_call(VALUE); 279 280 280 VALUE shoes_color_new( double, double, double, double);281 VALUE shoes_color_new(int, int, int, int); 281 282 VALUE shoes_color_alloc(VALUE); 282 283 VALUE shoes_color_rgb(int, VALUE *, VALUE); 283 284 VALUE shoes_color_gray(int, VALUE *, VALUE); 285 cairo_pattern_t *shoes_color_pattern(VALUE); 284 286 VALUE shoes_color_parse(VALUE, VALUE); 285 287 VALUE shoes_color_to_s(VALUE); -
trunk/shoes/ruby.c
r119 r120 497 497 if (self_t->bg.on) 498 498 { 499 cairo_set_source_rgba(canvas->cr, self_t->bg.r , self_t->bg.g, self_t->bg.b, self_t->bg.a);499 cairo_set_source_rgba(canvas->cr, self_t->bg.r / 255., self_t->bg.g / 255., self_t->bg.b / 255., self_t->bg.a / 255.); 500 500 cairo_fill_preserve(canvas->cr); 501 501 } 502 502 if (self_t->fg.on) 503 503 { 504 cairo_set_source_rgba(canvas->cr, self_t->fg.r , self_t->fg.g, self_t->fg.b, self_t->fg.a);504 cairo_set_source_rgba(canvas->cr, self_t->fg.r / 255., self_t->fg.g / 255., self_t->fg.b / 255., self_t->fg.a / 255.); 505 505 cairo_stroke_preserve(canvas->cr); 506 506 } … … 608 608 shoes_pattern *pattern; 609 609 VALUE obj = shoes_pattern_alloc(klass); 610 VALUE rgb = rb_funcall(source, s_match, 1, reRGB_SOURCE);610 VALUE rgb; 611 611 Data_Get_Struct(obj, shoes_pattern, pattern); 612 612 pattern->source = source; 613 if (!NIL_P(rgb)) 614 { 615 int r = NUM2INT(rb_Integer(rb_reg_nth_match(1, rgb))); 616 int g = NUM2INT(rb_Integer(rb_reg_nth_match(2, rgb))); 617 int b = NUM2INT(rb_Integer(rb_reg_nth_match(3, rgb))); 618 pattern->pattern = cairo_pattern_create_rgb(r / 255., g / 255., b / 255.); 613 614 if (!rb_obj_is_kind_of(source, cColor)) 615 { 616 rgb = shoes_color_parse(cColor, source); 617 if (!NIL_P(rgb)) source = rgb; 618 } 619 620 if (rb_obj_is_kind_of(source, cColor)) 621 { 622 pattern->pattern = shoes_color_pattern(source); 619 623 pattern->width = pattern->height = 1.; 620 624 } … … 627 631 } 628 632 cairo_pattern_set_extend(pattern->pattern, CAIRO_EXTEND_REPEAT); 633 629 634 pattern->attr = attr; 630 635 pattern->parent = parent; … … 698 703 699 704 VALUE 700 shoes_color_new( double r, double g, double b, doublea)705 shoes_color_new(int r, int g, int b, int a) 701 706 { 702 707 shoes_color *color; … … 715 720 shoes_color *color; 716 721 VALUE obj = Data_Make_Struct(klass, shoes_color, shoes_color_mark, shoes_color_free, color); 717 color->r = 0 .0;718 color->g = 0 .0;719 color->b = 0 .0;720 color->a = 1.0;722 color->r = 0x00; 723 color->g = 0x00; 724 color->b = 0x00; 725 color->a = 0xFF; 721 726 color->on = TRUE; 722 727 return obj; … … 726 731 shoes_color_rgb(int argc, VALUE *argv, VALUE self) 727 732 { 728 doublea;733 int a; 729 734 VALUE _r, _g, _b, _a; 730 735 rb_scan_args(argc, argv, "31", &_r, &_g, &_b, &_a); 731 736 732 a = 1.0;733 if (!NIL_P( a)) a = NUM2DBL(_a);734 return shoes_color_new(NUM2 DBL(_r), NUM2DBL(_g), NUM2DBL(_b), a);737 a = 0xFF; 738 if (!NIL_P(_a)) a = NUM2RGBINT(_a); 739 return shoes_color_new(NUM2RGBINT(_r), NUM2RGBINT(_g), NUM2RGBINT(_b), a); 735 740 } 736 741 … … 740 745 shoes_color *color; 741 746 VALUE _g, _a; 742 doubleg, a;747 int g, a; 743 748 rb_scan_args(argc, argv, "11", &_g, &_a); 744 749 745 a = 1.0;746 g = NUM2 DBL(_g);747 if (!NIL_P( a)) a = NUM2DBL(_a);750 a = 0xFF; 751 g = NUM2RGBINT(_g); 752 if (!NIL_P(_a)) a = NUM2RGBINT(_a); 748 753 return shoes_color_new(g, g, g, a); 754 } 755 756 cairo_pattern_t * 757 shoes_color_pattern(VALUE obj) 758 { 759 shoes_color *color; 760 Data_Get_Struct(obj, shoes_color, color); 761 if (color->a == 255) 762 return cairo_pattern_create_rgb(color->r / 255., color->g / 255., color->b / 255.); 763 else 764 return cairo_pattern_create_rgba(color->r / 255., color->g / 255., color->b / 255., color->a / 255.); 749 765 } 750 766 … … 760 776 if (!NIL_P(reg)) 761 777 { 762 color->r = NUM2 DBL(rb_str2inum(rb_reg_nth_match(1, reg), 16) * 17) / 255.;763 color->g = NUM2 DBL(rb_str2inum(rb_reg_nth_match(2, reg), 16) * 17) / 255.;764 color->b = NUM2 DBL(rb_str2inum(rb_reg_nth_match(3, reg), 16) * 17) / 255.;778 color->r = NUM2INT(rb_str2inum(rb_reg_nth_match(1, reg), 16)) * 17; 779 color->g = NUM2INT(rb_str2inum(rb_reg_nth_match(2, reg), 16)) * 17; 780 color->b = NUM2INT(rb_str2inum(rb_reg_nth_match(3, reg), 16)) * 17; 765 781 return obj; 766 782 } … … 769 785 if (!NIL_P(reg)) 770 786 { 771 color->r = NUM2 DBL(rb_str2inum(rb_reg_nth_match(1, reg), 16)) / 255.;772 color->g = NUM2 DBL(rb_str2inum(rb_reg_nth_match(2, reg), 16)) / 255.;773 color->b = NUM2 DBL(rb_str2inum(rb_reg_nth_match(3, reg), 16)) / 255.;787 color->r = NUM2INT(rb_str2inum(rb_reg_nth_match(1, reg), 16)); 788 color->g = NUM2INT(rb_str2inum(rb_reg_nth_match(2, reg), 16)); 789 color->b = NUM2INT(rb_str2inum(rb_reg_nth_match(3, reg), 16)); 774 790 return obj; 775 791 } … … 778 794 if (!NIL_P(reg)) 779 795 { 780 color->r = NUM2 DBL(rb_Integer(rb_reg_nth_match(1, reg))) / 255.;781 color->g = NUM2 DBL(rb_Integer(rb_reg_nth_match(2, reg))) / 255.;782 color->b = NUM2 DBL(rb_Integer(rb_reg_nth_match(3, reg))) / 255.;796 color->r = NUM2INT(rb_Integer(rb_reg_nth_match(1, reg))); 797 color->g = NUM2INT(rb_Integer(rb_reg_nth_match(2, reg))); 798 color->b = NUM2INT(rb_Integer(rb_reg_nth_match(3, reg))); 783 799 return obj; 784 800 } … … 787 803 if (!NIL_P(reg)) 788 804 { 789 color->r = NUM2 DBL(rb_Integer(rb_reg_nth_match(1, reg))) / 255.;790 color->g = NUM2 DBL(rb_Integer(rb_reg_nth_match(2, reg))) / 255.;791 color->b = NUM2 DBL(rb_Integer(rb_reg_nth_match(3, reg))) / 255.;792 color->a = NUM2 DBL(rb_Integer(rb_reg_nth_match(4, reg))) / 255.;805 color->r = NUM2INT(rb_Integer(rb_reg_nth_match(1, reg))); 806 color->g = NUM2INT(rb_Integer(rb_reg_nth_match(2, reg))); 807 color->b = NUM2INT(rb_Integer(rb_reg_nth_match(3, reg))); 808 color->a = NUM2INT(rb_Integer(rb_reg_nth_match(4, reg))); 793 809 return obj; 794 810 } … … 797 813 if (!NIL_P(reg)) 798 814 { 799 color->r = color->g = color->b = NUM2 DBL(rb_Integer(rb_reg_nth_match(1, reg))) / 255.;815 color->r = color->g = color->b = NUM2INT(rb_Integer(rb_reg_nth_match(1, reg))); 800 816 return obj; 801 817 } … … 804 820 if (!NIL_P(reg)) 805 821 { 806 color->r = color->g = color->b = NUM2 DBL(rb_Integer(rb_reg_nth_match(1, reg))) / 255.;807 color->a = NUM2 DBL(rb_Integer(rb_reg_nth_match(2, reg))) / 255.;822 color->r = color->g = color->b = NUM2INT(rb_Integer(rb_reg_nth_match(1, reg))); 823 color->a = NUM2INT(rb_Integer(rb_reg_nth_match(2, reg))); 808 824 return obj; 809 825 } … … 817 833 shoes_color *color; 818 834 Data_Get_Struct(self, shoes_color, color); 819 VALUE ary = rb_ary_new3(4, INT2NUM(color->r * 255), INT2NUM(color->g * 255), INT2NUM(color->b * 255), INT2NUM(color->a * 255));835 VALUE ary = rb_ary_new3(4, INT2NUM(color->r), INT2NUM(color->g), INT2NUM(color->b), INT2NUM(color->a)); 820 836 if (color->a == 1.0) 821 837 return rb_funcall(rb_str_new2("rgb(%d, %d, %d)"), s_perc, 1, ary); … … 1232 1248 if (canvas->fg.on) 1233 1249 { 1234 cairo_set_source_rgba(canvas->cr, canvas->fg.r , canvas->fg.g, canvas->fg.b, canvas->fg.a);1250 cairo_set_source_rgba(canvas->cr, canvas->fg.r / 255., canvas->fg.g / 255., canvas->fg.b / 255., canvas->fg.a / 255.); 1235 1251 // cairo_stroke(canvas->cr); 1236 1252 } … … 1985 2001 rb_define_method(cCanvas, "nofill", CASTHOOK(shoes_canvas_nofill), 0); 1986 2002 rb_define_method(cCanvas, "fill", CASTHOOK(shoes_canvas_fill), -1); 2003 rb_define_method(cCanvas, "rgb", CASTHOOK(shoes_color_rgb), -1); 2004 rb_define_method(cCanvas, "gray", CASTHOOK(shoes_color_gray), -1); 1987 2005 rb_define_method(cCanvas, "rect", CASTHOOK(shoes_canvas_rect), -1); 1988 2006 rb_define_method(cCanvas, "oval", CASTHOOK(shoes_canvas_oval), 4); -
trunk/shoes/ruby.h
r119 r120 49 49 "end;" 50 50 51 #define NUM2RGBINT(x) (rb_obj_is_kind_of(x, rb_cFloat) ? NUM2DBL(x) * 255 : NUM2INT(x)) 52 51 53 // 52 54 // Common funcs for dealing with attribute hashes
