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

Last change on this file since 4333 was 4333, checked in by Sam Hocevar, 10 years ago

Large source code cleanup, getting rid of spaces, tabs, and svn keywords.

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