Ignore:
Timestamp:
Sep 27, 2008, 4:11:36 PM (11 years ago)
Author:
Sam Hocevar
Message:

Continuing the libcucul-libcaca merge.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libcaca/trunk/ruby/ruby-caca.dox

    r2093 r2822  
    1 /* $Id$ */ /** \page libcaca-ruby-api Libcaca Ruby API
     1/*$Id$ */ /** \page libcaca-ruby-api Libcaca Ruby API
    22
    3 The classes available for libcaca are :
     3Theclasses available for libcaca are :
    44
    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
     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
     21Thecharacter set conversion functions are not available yet in the binding.
    1622
    1723\code
    18 $ irb -rcaca
    19 irb(main):001:0> class Object
    20 irb(main):002:1>   def Object.my_instance_methods
    21 irb(main):003:2>     instance_methods.sort - ancestors[1].instance_methods
    22 irb(main):004:2>   end
    23 irb(main):005:1>   def Object.my_methods
    24 irb(main):006:2>     methods.sort - ancestors[1].methods
    25 irb(main):007:2>   end
    26 irb(main):008:1> end
     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
    2733\endcode
    2834
    2935\code
    30 irb(main):009:0> Caca.my_methods
    31 => ["version"]
     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"]
    3241\endcode
    3342
    3443\code
    35 irb(main):010:0> Caca::Display.my_instance_methods
    36 => ["canvas", "get_event", "height", "mouse=", "mouse_x", "mouse_y", "refresh",
    37 "set_mouse", "set_time", "set_title", "time", "time=", "title=", "width"]
     44irb(main):010:0>Caca.my_methods
     45=>["version"]
    3846\endcode
    3947
    4048\code
    41 irb(main):011:0> Caca::Event.constants
    42 => ["Key", "Quit", "TYPE", "Mouse", "Resize"]
     49irb(main):011:0>Caca::Canvas.my_methods
     50=>["export_list", "import_list"]
    4351\endcode
    4452
    4553\code
    46 irb(main):012:0> Caca::Event.my_instance_methods
    47 => ["quit?"]
     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="]
    4868\endcode
    4969
    5070\code
    51 irb(main):013:0> Caca::Event::Key.my_instance_methods
    52 => ["ch", "utf32", "utf8"]
     71irb(main):013:0>Caca::Font.my_methods
     72=>["list"]
    5373\endcode
    5474
    5575\code
    56 irb(main):014:0> Caca::Event::Mouse.my_instance_methods
    57 => ["button", "x", "y"]
     76irb(main):014:0>Caca::Font.my_instance_methods
     77=>["blocks", "height", "width"]
    5878\endcode
    5979
    6080\code
    61 irb(main):015:0> Caca::Event::Resize.my_instance_methods
    62 => ["w", "h"]
     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"]
    6387\endcode
    6488
    65 \section Samples
     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
    6694
    6795\code
    68 require 'caca'
    69 c = Cucul::Canvas.new(20,10)
    70 c.put_str(2, 3, "plop!")
    71 c.draw_thin_polyline([[0,0], [0,2], [5,2], [0,0]])
    72 d = Caca::Display.new(c)
    73 d.title = "Test !"
     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\sectionSamples
     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 !"
    74160d.refresh
    75161
    76 # Redefine Event::Key#quit? so that q, Q, and Esc become exit keys
    77 module Caca
    78         class Event::Key
    79                 def quit?
    80                         "qQ^[".split('').member?(@ch.chr)
    81                 end
    82         end
     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
    83169end
    84170
    85 while((e = d.get_event(Caca::Event, -1)) && ! e.quit?)
    86     p e
    87     d.refresh
     171while((e= d.get_event(Caca::Event, -1)) && ! e.quit?)
     172p e
     173d.refresh
    88174end
    89175\endcode
Note: See TracChangeset for help on using the changeset viewer.