source: libcaca/trunk/ruby/ruby-caca.dox @ 3473

Last change on this file since 3473 was 3473, checked in by Sam Hocevar, 11 years ago

A lot of documentation updates here and there, including bugfixes dating
back to the libcucul merge.

File size: 4.8 KB
Line 
1/*$Id$ */ /** \page libcaca-ruby-api Libcaca Ruby API
2
3The classes available for libcaca are :
4
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
20
21The character set conversion functions are not available yet in the binding.
22
23\code
24$irb -rcaca
25irb(main):001:0>class Object
26irb(main):002:1>def Object.my_instance_methods
27irb(main):003:2>instance_methods.sort - ancestors[1].instance_methods
28irb(main):004:2>end
29irb(main):005:1>def Object.my_methods
30irb(main):006:2>methods.sort - ancestors[1].methods
31irb(main):007:2>end
32irb(main):008:1>end
33\endcode
34
35\code
36irb(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"]
41\endcode
42
43\code
44irb(main):010:0>Caca.my_methods
45=>["version"]
46\endcode
47
48\code
49irb(main):011:0>Caca::Canvas.my_methods
50=>["export_list", "import_list"]
51\endcode
52
53\code
54irb(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="]
68\endcode
69
70\code
71irb(main):013:0>Caca::Font.my_methods
72=>["list"]
73\endcode
74
75\code
76irb(main):014:0>Caca::Font.my_instance_methods
77=>["blocks", "height", "width"]
78\endcode
79
80\code
81irb(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"]
87\endcode
88
89\code
90irb(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
94
95\code
96irb(main):011:0>Caca::Event.constants
97=>["Key", "Quit", "TYPE", "Mouse", "Resize"]
98\endcode
99
100\code
101irb(main):012:0>Caca::Event.my_instance_methods
102=>["quit?"]
103\endcode
104
105\code
106irb(main):013:0>Caca::Event::Key.my_instance_methods
107=>["ch", "utf32", "utf8"]
108\endcode
109
110\code
111irb(main):014:0>Caca::Event::Mouse.my_instance_methods
112=>["button", "x", "y"]
113\endcode
114
115\code
116irb(main):015:0>Caca::Event::Resize.my_instance_methods
117=>["w", "h"]
118\endcode
119
120\section Samples
121
122\code
123$ruby -rcaca -e 'c=Caca::Canvas.new(6, 3).fill_box(0,0,2,2,"#"[0]);
124c2=Caca::Canvas.new(1,1).put_str(0,0,"x"); c.blit(1,1,c2); puts
125c.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
142withANSI escape codes"], ["utf8cr", "UTF-8 with ANSI escape codes and
143MS-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
154require'caca'
155c= Caca::Canvas.new(20,10)
156c.put_str(2,3, "plop!")
157c.draw_thin_polyline([[0,0],[0,2], [5,2], [0,0]])
158d= Caca::Display.new(c)
159d.title= "Test !"
160d.refresh
161
162#Redefine Event::Key#quit? so that q, Q, and Esc become exit keys
163moduleCaca
164class Event::Key
165def quit?
166"qQ^[".split('').member?(@ch.chr)
167end
168end
169end
170
171while((e= d.get_event(Caca::Event, -1)) && ! e.quit?)
172p e
173d.refresh
174end
175\endcode
176
177*/
Note: See TracBrowser for help on using the repository browser.