You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

README 5.2 KiB

17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. /* $Id$ */ /** \page libcaca-ruby Libcaca ruby bindings
  2. This a Ruby binding for libcucul and libcaca.
  3. There is no real documentation but "methods" on any object should help you :)
  4. The classes available for libcucul are :
  5. - Cucul::Canvas (functions that have a cucul_canvas_t* as first argument)
  6. - Cucul::Dither (functions that have a cucul_dither_t* as first argument)
  7. - Cucul::Font (functions that have a cucul_font_t* as first argument)
  8. * The constructor can currently only accept the name of a builtin font
  9. The classes available for libcaca are :
  10. - Caca::Display
  11. - Caca::Event
  12. - Caca::Event::Key
  13. - Caca::Event::Key::Press
  14. - Caca::Event::Key::Release
  15. - Caca::Event::Mouse
  16. - Caca::Event::Mouse::Press
  17. - Caca::Event::Mouse::Release
  18. - Caca::Event::Mouse::Motion
  19. - Caca::Event::Resize
  20. - Caca::Event::Quit
  21. The character set conversion functions are not available yet in the binding.
  22. I tried to follow Ruby spirit meaning that :
  23. - most of the methods return self
  24. - the methods set_foo with only an argument are also available as foo=
  25. (returning the value instead of self)
  26. - the methods originally named get_foo are available only as foo
  27. What is currently available is :
  28. \code
  29. $ irb -rcucul
  30. irb(main):001:0> Cucul.constants
  31. => ["BROWN", "BOLD", "GREEN", "LIGHTMAGENTA", "LIGHTBLUE", "BLINK",
  32. "MAGENTA", "DEFAULT", "TRANSPARENT", "BLUE", "LIGHTRED", "DARKGRAY",
  33. "UNDERLINE", "RED", "WHITE", "BLACK", "LIGHTCYAN", "LIGHTGRAY",
  34. "ITALICS", "CYAN", "YELLOW", "LIGHTGREEN", "Canvas", "Dither", "Font"]
  35. \endcode
  36. \code
  37. irb(main):002:0> Cucul::Canvas.methods.sort -
  38. Cucul::Canvas.ancestors[1].methods
  39. => ["export_list", "import_list"]
  40. \endcode
  41. \code
  42. irb(main):003:0> Cucul::Canvas.instance_methods.sort -
  43. Cucul::Canvas.ancestors[1].instance_methods
  44. => ["attr=", "blit", "clear", "create_frame", "cursor_x", "cursor_y",
  45. "dither_bitmap", "draw_box", "draw_circle", "draw_cp437_box", "draw_ellipse",
  46. "draw_line", "draw_polyline", "draw_thin_box", "draw_thin_ellipse",
  47. "draw_thin_line", "draw_thin_polyline", "draw_thin_triangle",
  48. "draw_triangle", "export_memory", "fill_box", "fill_ellipse",
  49. "fill_triangle", "flip", "flop", "frame=", "frame_count", "frame_name",
  50. "frame_name=", "free_frame", "get_attr", "get_char", "gotoxy",
  51. "handle_x", "handle_y", "height", "height=", "import_file",
  52. "import_memory", "invert", "printf", "put_attr", "put_char", "put_str",
  53. "rotate_180", "rotate_left", "rotate_right", "set_attr",
  54. "set_boundaries", "set_color_ansi", "set_color_argb", "set_frame",
  55. "set_frame_name", "set_handle", "set_height", "set_size", "set_width",
  56. "stretch_left", "stretch_right", "width", "width="]
  57. \endcode
  58. \code
  59. irb(main):004:0> Cucul::Font.methods.sort -
  60. Cucul::Font.ancestors[1].methods
  61. => ["list"]
  62. \endcode
  63. \code
  64. irb(main):005:0> Cucul::Font.instance_methods.sort -
  65. Cucul::Font.ancestors[1].instance_methods
  66. => ["blocks", "height", "width"]
  67. \endcode
  68. \code
  69. irb(main):006:0> Cucul::Dither.instance_methods.sort -
  70. Cucul::Dither.ancestors[1].instance_methods
  71. => ["algorithm=", "algorithm_list", "antialias=", "antialias_list",
  72. "brightness=", "charset=", "charset_list", "color=", "color_list",
  73. "contrast=", "gamma=", "palette=", "set_algorithm", "set_antialias",
  74. "set_brightness", "set_charset", "set_color", "set_contrast",
  75. "set_gamma", "set_palette"]
  76. \endcode
  77. \code
  78. irb(main):007:0> Caca::Display.instance_methods.sort -
  79. Caca::Display.ancestors[1].instance_methods
  80. => ["get_event", "height", "mouse=", "mouse_x", "mouse_y", "refresh",
  81. "set_mouse", "set_time", "set_title", "time", "time=", "title=", "width"]
  82. \endcode
  83. \code
  84. irb(main):008:0> Caca::Event.constants
  85. => ["Key", "Quit", "TYPE", "Mouse", "Resize"]
  86. \endcode
  87. \code
  88. irb(main):009:0> Caca::Event::Key.instance_methods - Caca::Event::Key.ancestors[1].instance_methods
  89. => ["ch", "utf32", "utf8"]
  90. \endcode
  91. \code
  92. irb(main):010:0> Caca::Event::Key.instance_methods - Caca::Event::Mouse.ancestors[1].instance_methods
  93. => ["ch", "utf32", "utf8"]
  94. \endcode
  95. \code
  96. irb(main):011:0> Caca::Event::Mouse.instance_methods - Caca::Event::Mouse.ancestors[1].instance_methods
  97. => ["button", "x", "y"]
  98. \endcode
  99. \code
  100. irb(main):018:0> Caca::Event::Resize.instance_methods - Caca::Event::Resize.ancestors[1].instance_methods
  101. => ["w", "h"]
  102. \endcode
  103. And here are sample uses :
  104. \code
  105. $ ruby -rcucul -e 'c=Cucul::Canvas.new(6, 3).fill_box(0,0,2,2,"#"[0]);
  106. c2=Cucul::Canvas.new(1, 1).put_str(0,0,"x"); c.blit(1,1,c2); puts
  107. c.export_memory("irc")'
  108. ###
  109. #x#
  110. ###
  111. \endcode
  112. \code
  113. $ ruby -e 'puts Cucul::Canvas.new(6,3).draw_thin_polyline([[0,0], [2,0],
  114. [5,2],[0,0]]).export_memory("irc")'
  115. -.
  116. | `.
  117. ----`-
  118. \endcode
  119. \code
  120. $ ruby -rcucul -e 'p Cucul::Canvas.export_list'
  121. [["caca", "native libcaca format"], ["ansi", "ANSI"], ["utf8", "UTF-8
  122. with ANSI escape codes"], ["utf8cr", "UTF-8 with ANSI escape codes and
  123. MS-DOS \\r"], ["html", "HTML"], ["html3", "backwards-compatible HTML"],
  124. ["irc", "IRC with mIRC colours"], ["ps", "PostScript document"], ["svg",
  125. "SVG vector image"], ["tga", "TGA image"]]
  126. \endcode
  127. \code
  128. $ ruby -rcucul -e 'p Cucul::Font.list'
  129. ["Monospace 9", "Monospace Bold 12"]
  130. \endcode
  131. And now a real one:
  132. \code
  133. require 'caca'
  134. d = Caca::Display.new(Cucul::Canvas.new(20,10))
  135. d.title = "Test !"
  136. while((e = d.get_event(Caca::Event, -1)) &&
  137. ! e.kind_of?(Caca::Event::Quit))
  138. p e
  139. d.refresh
  140. end
  141. \endcode
  142. */