Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 
 
 

180 строки
4.9 KiB

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