[2822] | 1 | /*$Id$ */ /** \page libcaca-ruby-api Libcaca Ruby API |
---|
[2033] | 2 | |
---|
[2822] | 3 | Theclasses available for libcaca are : |
---|
[2033] | 4 | |
---|
[2822] | 5 | \li\b Caca::Canvas : functions that have a caca_canvas_t* as first argument |
---|
| 6 | \li\b Caca::Dither : functions that have a caca_dither_t* as first argument |
---|
| 7 | \li\b Caca::Font : functions that have a caca_font_t* as first argument |
---|
| 8 | (The constructor can currently only accept the name of a builtin font) |
---|
| 9 | \li\b Caca::Display |
---|
| 10 | \li\b Caca::Event |
---|
| 11 | \li\b Caca::Event::Key |
---|
| 12 | \li\b Caca::Event::Key::Press |
---|
| 13 | \li\b Caca::Event::Key::Release |
---|
| 14 | \li\b Caca::Event::Mouse |
---|
| 15 | \li\b Caca::Event::Mouse::Press |
---|
| 16 | \li\b Caca::Event::Mouse::Release |
---|
| 17 | \li\b Caca::Event::Mouse::Motion |
---|
| 18 | \li\b Caca::Event::Resize |
---|
| 19 | \li\b Caca::Event::Quit |
---|
[2033] | 20 | |
---|
[2822] | 21 | Thecharacter set conversion functions are not available yet in the binding. |
---|
| 22 | |
---|
[2033] | 23 | \code |
---|
[2822] | 24 | $irb -rcaca |
---|
| 25 | irb(main):001:0>class Object |
---|
| 26 | irb(main):002:1>def Object.my_instance_methods |
---|
| 27 | irb(main):003:2>instance_methods.sort - ancestors[1].instance_methods |
---|
| 28 | irb(main):004:2>end |
---|
| 29 | irb(main):005:1>def Object.my_methods |
---|
| 30 | irb(main):006:2>methods.sort - ancestors[1].methods |
---|
| 31 | irb(main):007:2>end |
---|
| 32 | irb(main):008:1>end |
---|
[2077] | 33 | \endcode |
---|
[2048] | 34 | |
---|
[2077] | 35 | \code |
---|
[2822] | 36 | irb(main):009:0>Caca.constants |
---|
| 37 | =>["BROWN", "BOLD", "GREEN", "LIGHTMAGENTA", "LIGHTBLUE", "BLINK", |
---|
| 38 | "MAGENTA","DEFAULT", "TRANSPARENT", "BLUE", "LIGHTRED", "DARKGRAY", |
---|
| 39 | "UNDERLINE","RED", "WHITE", "BLACK", "LIGHTCYAN", "LIGHTGRAY", |
---|
| 40 | "ITALICS","CYAN", "YELLOW", "LIGHTGREEN", "Canvas", "Dither", "Font"] |
---|
[2077] | 41 | \endcode |
---|
| 42 | |
---|
| 43 | \code |
---|
[2822] | 44 | irb(main):010:0>Caca.my_methods |
---|
| 45 | =>["version"] |
---|
[2033] | 46 | \endcode |
---|
| 47 | |
---|
| 48 | \code |
---|
[2822] | 49 | irb(main):011:0>Caca::Canvas.my_methods |
---|
| 50 | =>["export_list", "import_list"] |
---|
[2033] | 51 | \endcode |
---|
| 52 | |
---|
| 53 | \code |
---|
[2822] | 54 | irb(main):012:0>Caca::Canvas.my_instance_methods |
---|
| 55 | =>["attr=", "blit", "clear", "create_frame", "cursor_x", "cursor_y", |
---|
| 56 | "dither_bitmap","draw_box", "draw_circle", "draw_cp437_box", "draw_ellipse", |
---|
| 57 | "draw_line","draw_polyline", "draw_thin_box", "draw_thin_ellipse", |
---|
| 58 | "draw_thin_line","draw_thin_polyline", "draw_thin_triangle", |
---|
| 59 | "draw_triangle","export_memory", "fill_box", "fill_ellipse", |
---|
| 60 | "fill_triangle","flip", "flop", "frame=", "frame_count", "frame_name", |
---|
| 61 | "frame_name=","free_frame", "get_attr", "get_char", "gotoxy", |
---|
| 62 | "handle_x","handle_y", "height", "height=", "import_file", |
---|
| 63 | "import_memory","invert", "printf", "put_attr", "put_char", "put_str", |
---|
| 64 | "rotate_180","rotate_left", "rotate_right", "set_attr", |
---|
| 65 | "set_boundaries","set_color_ansi", "set_color_argb", "set_frame", |
---|
| 66 | "set_frame_name","set_handle", "set_height", "set_size", "set_width", |
---|
| 67 | "stretch_left","stretch_right", "width", "width="] |
---|
[2033] | 68 | \endcode |
---|
| 69 | |
---|
| 70 | \code |
---|
[2822] | 71 | irb(main):013:0>Caca::Font.my_methods |
---|
| 72 | =>["list"] |
---|
[2033] | 73 | \endcode |
---|
| 74 | |
---|
| 75 | \code |
---|
[2822] | 76 | irb(main):014:0>Caca::Font.my_instance_methods |
---|
| 77 | =>["blocks", "height", "width"] |
---|
[2033] | 78 | \endcode |
---|
| 79 | |
---|
| 80 | \code |
---|
[2822] | 81 | irb(main):015:0>Caca::Dither.my_instance_methods |
---|
| 82 | =>["algorithm=", "algorithm_list", "antialias=", "antialias_list", |
---|
| 83 | "brightness=","charset=", "charset_list", "color=", "color_list", |
---|
| 84 | "contrast=","gamma=", "palette=", "set_algorithm", "set_antialias", |
---|
| 85 | "set_brightness","set_charset", "set_color", "set_contrast", |
---|
| 86 | "set_gamma","set_palette"] |
---|
[2033] | 87 | \endcode |
---|
| 88 | |
---|
[2822] | 89 | \code |
---|
| 90 | irb(main):010:0>Caca::Display.my_instance_methods |
---|
| 91 | =>["canvas", "get_event", "height", "mouse=", "mouse_x", "mouse_y", "refresh", |
---|
| 92 | "set_mouse","set_time", "set_title", "time", "time=", "title=", "width"] |
---|
| 93 | \endcode |
---|
[2033] | 94 | |
---|
| 95 | \code |
---|
[2822] | 96 | irb(main):011:0>Caca::Event.constants |
---|
| 97 | =>["Key", "Quit", "TYPE", "Mouse", "Resize"] |
---|
| 98 | \endcode |
---|
| 99 | |
---|
| 100 | \code |
---|
| 101 | irb(main):012:0>Caca::Event.my_instance_methods |
---|
| 102 | =>["quit?"] |
---|
| 103 | \endcode |
---|
| 104 | |
---|
| 105 | \code |
---|
| 106 | irb(main):013:0>Caca::Event::Key.my_instance_methods |
---|
| 107 | =>["ch", "utf32", "utf8"] |
---|
| 108 | \endcode |
---|
| 109 | |
---|
| 110 | \code |
---|
| 111 | irb(main):014:0>Caca::Event::Mouse.my_instance_methods |
---|
| 112 | =>["button", "x", "y"] |
---|
| 113 | \endcode |
---|
| 114 | |
---|
| 115 | \code |
---|
| 116 | irb(main):015:0>Caca::Event::Resize.my_instance_methods |
---|
| 117 | =>["w", "h"] |
---|
| 118 | \endcode |
---|
| 119 | |
---|
| 120 | \sectionSamples |
---|
| 121 | |
---|
| 122 | \code |
---|
| 123 | $ruby -rcaca -e 'c=Caca::Canvas.new(6, 3).fill_box(0,0,2,2,"#"[0]); |
---|
| 124 | c2=Caca::Canvas.new(1,1).put_str(0,0,"x"); c.blit(1,1,c2); puts |
---|
| 125 | c.export_memory("irc")' |
---|
| 126 | ### |
---|
| 127 | #x# |
---|
| 128 | ### |
---|
| 129 | \endcode |
---|
| 130 | |
---|
| 131 | \code |
---|
| 132 | $ruby -e 'puts Caca::Canvas.new(6,3).draw_thin_polyline([[0,0], [0,2], |
---|
| 133 | [5,2],[0,0]]).export_memory("irc")' |
---|
| 134 | -. |
---|
| 135 | |`. |
---|
| 136 | ----`- |
---|
| 137 | \endcode |
---|
| 138 | |
---|
| 139 | \code |
---|
| 140 | $ruby -rcaca -e 'p Caca::Canvas.export_list' |
---|
| 141 | [["caca","native libcaca format"], ["ansi", "ANSI"], ["utf8", "UTF-8 |
---|
| 142 | withANSI escape codes"], ["utf8cr", "UTF-8 with ANSI escape codes and |
---|
| 143 | MS-DOS\\r"], ["html", "HTML"], ["html3", "backwards-compatible HTML"], |
---|
| 144 | ["irc","IRC with mIRC colours"], ["ps", "PostScript document"], ["svg", |
---|
| 145 | "SVGvector image"], ["tga", "TGA image"]] |
---|
| 146 | \endcode |
---|
| 147 | |
---|
| 148 | \code |
---|
| 149 | $ruby -rcaca -e 'p Caca::Font.list' |
---|
| 150 | ["Monospace9", "Monospace Bold 12"] |
---|
| 151 | \endcode |
---|
| 152 | |
---|
| 153 | \code |
---|
| 154 | require'caca' |
---|
| 155 | c= Caca::Canvas.new(20,10) |
---|
| 156 | c.put_str(2,3, "plop!") |
---|
| 157 | c.draw_thin_polyline([[0,0],[0,2], [5,2], [0,0]]) |
---|
| 158 | d= Caca::Display.new(c) |
---|
| 159 | d.title= "Test !" |
---|
[2033] | 160 | d.refresh |
---|
[2048] | 161 | |
---|
[2822] | 162 | #Redefine Event::Key#quit? so that q, Q, and Esc become exit keys |
---|
| 163 | moduleCaca |
---|
| 164 | class Event::Key |
---|
| 165 | def quit? |
---|
| 166 | "qQ^[".split('').member?(@ch.chr) |
---|
[2048] | 167 | end |
---|
[2822] | 168 | end |
---|
| 169 | end |
---|
[2048] | 170 | |
---|
[2822] | 171 | while((e= d.get_event(Caca::Event, -1)) && ! e.quit?) |
---|
| 172 | p e |
---|
| 173 | d.refresh |
---|
[2033] | 174 | end |
---|
| 175 | \endcode |
---|
| 176 | |
---|
| 177 | */ |
---|