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

Last change on this file since 2048 was 2048, checked in by Pascal Terjan, 13 years ago
  • Little improvements in ruby doc + Made the doc a little more easy to read + Added an example on a nice way to have q, Q and Esc to cause exit
File size: 1.9 KB
RevLine 
[2033]1/* $Id$ */ /** \page libcaca-ruby-api Libcaca Ruby API
2
3The classes available for libcaca are :
4
5\li \b Caca::Display
6\li \b Caca::Event
7\li \b Caca::Event::Key
8\li \b Caca::Event::Key::Press
9\li \b Caca::Event::Key::Release
10\li \b Caca::Event::Mouse
11\li \b Caca::Event::Mouse::Press
12\li \b Caca::Event::Mouse::Release
13\li \b Caca::Event::Mouse::Motion
14\li \b Caca::Event::Resize
15\li \b Caca::Event::Quit
16
17\code
[2048]18$ irb -rcaca
19irb(main):001:0> class Object
20irb(main):002:1>   def Object.my_instance_methods
21irb(main):003:2>     instance_methods.sort - ancestors[1].instance_methods
22irb(main):004:2>   end
23irb(main):005:1>   def Object.my_methods
24irb(main):006:2>     methods.sort - ancestors[1].methods
25irb(main):007:2>   end
26irb(main):008:1> end
27
28irb(main):009:0> Caca::Display.my_instance_methods
[2033]29=> ["get_event", "height", "mouse=", "mouse_x", "mouse_y", "refresh",
30"set_mouse", "set_time", "set_title", "time", "time=", "title=", "width"]
31\endcode
32
33\code
[2048]34irb(main):010:0> Caca::Event.constants
[2033]35=> ["Key", "Quit", "TYPE", "Mouse", "Resize"]
36\endcode
37
38\code
[2048]39irb(main):011:0> Caca::Event.my_instance_methods
40=> ["quit?"]
[2033]41\endcode
42
43\code
[2048]44irb(main):012:0> Caca::Event::Key.my_instance_methods
[2033]45=> ["ch", "utf32", "utf8"]
46\endcode
47
48\code
[2048]49irb(main):013:0> Caca::Event::Mouse.my_instance_methods
[2033]50=> ["button", "x", "y"]
51\endcode
52
53\code
[2048]54irb(main):014:0> Caca::Event::Resize.my_instance_methods
[2033]55=> ["w", "h"]
56\endcode
57
58\section Samples
59
60\code
61require 'caca'
62c = Cucul::Canvas.new(20,10)
63c.put_str(2, 3, "plop!")
64c.draw_thin_polyline([[0,0], [0,2], [5,2], [0,0]])
65d = Caca::Display.new(c)
66d.title = "Test !"
67d.refresh
[2048]68
69# Redefine Event::Key#quit? so that q, Q, and Esc become exit keys
70module Caca
71        class Event::Key
72                def quit?
73                        "qQ^[".split('').member?(@ch.chr)
74                end
75        end
76end
77
[2042]78while((e = d.get_event(Caca::Event, -1)) && ! e.quit?)
[2033]79    p e
80    d.refresh
81end
82\endcode
83
84*/
Note: See TracBrowser for help on using the repository browser.