Changeset 2009
- Timestamp:
- Nov 17, 2007, 2:36:15 PM (15 years ago)
- Location:
- libcaca/trunk/ruby
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
libcaca/trunk/ruby/README
r2008 r2009 5 5 There is no real documentation but "methods" on any object should help you :) 6 6 7 The objects available for noware :7 The objects available are : 8 8 9 9 - Cucul::Canvas (functions that have a cucul_canvas_t* as first argument) … … 13 13 - Cucul::Font (functions that have a cucul_font_t* as first argument) 14 14 * The constructor can currently only accept the name of a builtin font 15 16 The character set conversion functions are not available yet in the binding. 15 17 16 18 I tried to follow Ruby spirit meaning that : … … 69 71 \code 70 72 irb(main):006:0> Cucul::Dither.instance_methods.sort - 71 Cucul::Dither.ancestors[1].instance_methods => ["brightness=", 72 "contrast=", "gamma=", "palette=", "set_brightness", "set_contrast", 73 Cucul::Dither.ancestors[1].instance_methods 74 => ["algorithm=", "algorithm_list", "antialias=", "antialias_list", 75 "brightness=", "charset=", "charset_list", "color=", "color_list", 76 "contrast=", "gamma=", "palette=", "set_algorithm", "set_antialias", 77 "set_brightness", "set_charset", "set_color", "set_contrast", 73 78 "set_gamma", "set_palette"] 74 79 \endcode -
libcaca/trunk/ruby/common.h
r1995 r2009 4 4 #define _SELF (DATA_PTR(self)) 5 5 6 #define get_singleton_double_list(x) \ 7 static VALUE x##_list(void) \ 8 { \ 9 VALUE ary, ary2; \ 10 char const* const* list; \ 11 \ 12 list = cucul_get_##x##_list(); \ 13 ary = rb_ary_new(); \ 14 while (*list != NULL) \ 15 { \ 16 ary2 = rb_ary_new(); \ 17 rb_ary_push(ary2, rb_str_new2(*list)); \ 18 list++; \ 19 rb_ary_push(ary2, rb_str_new2(*list)); \ 20 list++; \ 21 rb_ary_push(ary, ary2); \ 22 } \ 23 \ 24 return ary; \ 25 } 26 27 #define get_double_list(x) \ 28 static VALUE x##_list(VALUE self) \ 29 { \ 30 VALUE ary, ary2; \ 31 char const* const* list; \ 32 \ 33 list = cucul_get_##x##_list(_SELF); \ 34 ary = rb_ary_new(); \ 35 while (*list != NULL) \ 36 { \ 37 ary2 = rb_ary_new(); \ 38 rb_ary_push(ary2, rb_str_new2(*list)); \ 39 list++; \ 40 rb_ary_push(ary2, rb_str_new2(*list)); \ 41 list++; \ 42 rb_ary_push(ary, ary2); \ 43 } \ 44 \ 45 return ary; \ 46 } 47 6 48 #endif -
libcaca/trunk/ruby/cucul-canvas.c
r2004 r2009 13 13 #include <cucul.h> 14 14 #include <errno.h> 15 #include "cucul-dither.h" 15 16 #include "cucul-font.h" 16 17 #include "common.h" … … 439 440 } 440 441 442 static VALUE dither_bitmap(VALUE self, VALUE x, VALUE y, VALUE w, VALUE h, VALUE d, VALUE pixels) 443 { 444 if(CLASS_OF(d) != cDither) 445 rb_raise(rb_eArgError, "d is not a Cucul::Dither"); 446 Check_Type(pixels, T_STRING); 447 448 cucul_dither_bitmap(_SELF, NUM2INT(x), NUM2INT(y), NUM2INT(w), NUM2INT(h), DATA_PTR(d), StringValuePtr(pixels)); 449 return self; 450 } 451 441 452 /****/ 442 453 … … 550 561 } 551 562 552 static VALUE export_list(void) 553 { 554 VALUE ary, ary2; 555 556 char const* const* list; 557 558 list = cucul_get_export_list(); 559 560 ary = rb_ary_new(); 561 562 while (*list != NULL) 563 { 564 ary2 = rb_ary_new(); 565 rb_ary_push(ary2, rb_str_new2(*list)); 566 list++; 567 rb_ary_push(ary2, rb_str_new2(*list)); 568 list++; 569 rb_ary_push(ary, ary2); 570 } 571 572 return ary; 573 } 574 575 static VALUE import_list(void) 576 { 577 VALUE ary, ary2; 578 579 char const* const* list; 580 581 list = cucul_get_import_list(); 582 583 ary = rb_ary_new(); 584 585 while (*list != NULL) 586 { 587 ary2 = rb_ary_new(); 588 rb_ary_push(ary2, rb_str_new2(*list)); 589 list++; 590 rb_ary_push(ary2, rb_str_new2(*list)); 591 list++; 592 rb_ary_push(ary, ary2); 593 } 594 595 return ary; 596 } 563 get_singleton_double_list(export) 564 get_singleton_double_list(import) 597 565 598 566 /****/ … … 659 627 rb_define_method(cCanvas, "draw_thin_triangle", draw_thin_triangle, 6); 660 628 rb_define_method(cCanvas, "fill_triangle", fill_triangle, 7); 629 rb_define_method(cCanvas, "dither_bitmap", dither_bitmap, 6); 661 630 662 631 rb_define_method(cCanvas, "frame_count", get_frame_count, 0); -
libcaca/trunk/ruby/cucul-dither.c
r2008 r2009 15 15 #include "common.h" 16 16 17 VALUE c Font;17 VALUE cDither; 18 18 19 19 void dither_free(void *dither) … … 140 140 141 141 #define set_float(x) \ 142 static VALUE set_##x 142 static VALUE set_##x(VALUE self, VALUE x) \ 143 143 { \ 144 144 if(cucul_set_dither_##x(_SELF, (float)NUM2DBL(x))<0)\ … … 148 148 } \ 149 149 \ 150 static VALUE set_##x##2 150 static VALUE set_##x##2(VALUE self, VALUE x) \ 151 151 { \ 152 152 set_##x(self, x); \ … … 158 158 set_float(contrast) 159 159 160 /* 161 int cucul_set_dither_invert (cucul_dither_t *, int) 162 Invert colors of dither. 163 */ 160 #define get_set_str_from_list(x) \ 161 get_double_list(dither_##x) \ 162 static VALUE set_dither_##x(VALUE self, VALUE x) \ 163 { \ 164 if(cucul_set_dither_##x(_SELF, StringValuePtr(x))<0) \ 165 { \ 166 rb_raise(rb_eRuntimeError, strerror(errno)); \ 167 } \ 168 return x; \ 169 } \ 170 \ 171 static VALUE set_dither_##x##2(VALUE self, VALUE x) \ 172 { \ 173 set_dither_##x(self, x); \ 174 return self; \ 175 } 176 177 get_set_str_from_list(antialias) 178 get_set_str_from_list(color) 179 get_set_str_from_list(charset) 180 get_set_str_from_list(algorithm) 164 181 165 182 void Init_cucul_dither(VALUE mCucul) 166 183 { 167 cFont = rb_define_class_under(mCucul, "Dither", rb_cObject); 168 rb_define_alloc_func(cFont, dither_alloc); 169 170 rb_define_method(cFont, "initialize", dither_initialize, 8); 171 rb_define_method(cFont, "palette=", set_dither_palette, 1); 172 rb_define_method(cFont, "set_palette", set_dither_palette2, 1); 173 rb_define_method(cFont, "brightness=", set_brightness, 1); 174 rb_define_method(cFont, "set_brightness", set_brightness2, 1); 175 rb_define_method(cFont, "gamma=", set_gamma, 1); 176 rb_define_method(cFont, "set_gamma", set_gamma2, 1); 177 rb_define_method(cFont, "contrast=", set_contrast, 1); 178 rb_define_method(cFont, "set_contrast", set_contrast2, 1); 179 } 180 184 cDither = rb_define_class_under(mCucul, "Dither", rb_cObject); 185 rb_define_alloc_func(cDither, dither_alloc); 186 187 rb_define_method(cDither, "initialize", dither_initialize, 8); 188 rb_define_method(cDither, "palette=", set_dither_palette, 1); 189 rb_define_method(cDither, "set_palette", set_dither_palette2, 1); 190 rb_define_method(cDither, "brightness=", set_brightness, 1); 191 rb_define_method(cDither, "set_brightness", set_brightness2, 1); 192 rb_define_method(cDither, "gamma=", set_gamma, 1); 193 rb_define_method(cDither, "set_gamma", set_gamma2, 1); 194 rb_define_method(cDither, "contrast=", set_contrast, 1); 195 rb_define_method(cDither, "set_contrast", set_contrast2, 1); 196 rb_define_method(cDither, "antialias_list", dither_antialias_list, 0); 197 rb_define_method(cDither, "antialias=", set_dither_antialias, 1); 198 rb_define_method(cDither, "set_antialias", set_dither_antialias2, 1); 199 rb_define_method(cDither, "color_list", dither_color_list, 0); 200 rb_define_method(cDither, "color=", set_dither_color, 1); 201 rb_define_method(cDither, "set_color", set_dither_color2, 1); 202 rb_define_method(cDither, "charset_list", dither_charset_list, 0); 203 rb_define_method(cDither, "charset=", set_dither_charset, 1); 204 rb_define_method(cDither, "set_charset", set_dither_charset2, 1); 205 rb_define_method(cDither, "algorithm_list", dither_algorithm_list, 0); 206 rb_define_method(cDither, "algorithm=", set_dither_algorithm, 1); 207 rb_define_method(cDither, "set_algorithm", set_dither_algorithm2, 1); 208 } 209
Note: See TracChangeset
for help on using the changeset viewer.