您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 
 
 

293 行
6.4 KiB

  1. <?php
  2. /*
  3. * php-caca Php binding for Libcaca
  4. * caca.php object layer for caca-php
  5. * Copyright (c) 2008 Vion Nicolas <nico@picapo.net>
  6. *
  7. *
  8. * This library is free software. It comes without any warranty, to
  9. * the extent permitted by applicable law. You can redistribute it
  10. * and/or modify it under the terms of the Do What The Fuck You Want
  11. * To Public License, Version 2, as published by Sam Hocevar. See
  12. * http://sam.zoy.org/wtfpl/COPYING for more details.
  13. */
  14. class Canvas {
  15. private $cv;
  16. function setSize($width, $height) {
  17. return caca_set_canvas_width($this->cv, $width, $height);
  18. }
  19. function getWidth() {
  20. return caca_get_canvas_width($this->cv);
  21. }
  22. function getHeight() {
  23. return caca_get_canvas_height($this->cv);
  24. }
  25. function getAttr($x, $y) {
  26. return caca_get_attr($this->cv, $x, $y);
  27. }
  28. function setAttr($attr) {
  29. return caca_set_attr($this->cv, $x, $y, $attr);
  30. }
  31. function setColorANSI($foreground, $background) {
  32. return caca_set_color_ansi($this->cv, $foreground, $background);
  33. }
  34. function setColorARGB($foreground, $background) {
  35. return caca_set_color_argb($this->cv, $foreground, $background);
  36. }
  37. function putChar($x, $y, $c) {
  38. return caca_put_char($this->cv, $x, $y, $c);
  39. }
  40. function getChar($x, $y) {
  41. return caca_get_char($this->cv, $x, $y);
  42. }
  43. function putStr($x, $y, $str) {
  44. return caca_put_str($this->cv, $x, $y, $str);
  45. }
  46. function Clear() {
  47. return caca_canvas_clear($this->cv);
  48. }
  49. function Blit($x, $y, $canvas, $mask = false) {
  50. return caca_blit($this->cv, $x, $y, $canvas->get_resource(), ($mask != false) ? $mask->get_resource() : false );
  51. }
  52. function Invert() {
  53. return caca_invert($this->cv);
  54. }
  55. function Flip() {
  56. return caca_flip($this->cv);
  57. }
  58. function Flop() {
  59. return caca_flop($this->cv);
  60. }
  61. function Rotate180() {
  62. return caca_rotate_180($this->cv);
  63. }
  64. function RotateLeft() {
  65. return caca_rotate_left($this->cv);
  66. }
  67. function RotateRight() {
  68. return caca_rotate_right($this->cv);
  69. }
  70. function drawLine($x1, $y1, $x2, $y2, $char) {
  71. return caca_draw_line($this->cv, $x1, $y1, $x2, $y2, $color);
  72. }
  73. function drawPolyline($points, $char) {
  74. return caca_draw_polyline($this->cv, $points, $char);
  75. }
  76. function drawThinLine($x1, $y1, $x2, $y2) {
  77. return caca_draw_thin_line($this->cv, $x1, $y1, $x2, $y2);
  78. }
  79. function drawThinPolyline($points) {
  80. return caca_draw_thin_polyline($this->cv, $points);
  81. }
  82. function drawCircle($x, $y, $radius, $char) {
  83. return caca_draw_circle($this->cv, $x, $y, $radius, $char);
  84. }
  85. function drawEllipse($x1, $y1, $x2, $y2, $char) {
  86. caca_draw_ellipse($this->cv, $x1, $y1, $x2, $y2, $char);
  87. }
  88. function drawThinEllipse($x1, $y1, $x2, $y2) {
  89. caca_draw_ellipse($this->cv, $x1, $y1, $x2, $y2);
  90. }
  91. function fillEllipse($x1, $y1, $x2, $y2, $char) {
  92. caca_fill_ellipse($this->cv, $x1, $y1, $x2, $y2, $char);
  93. }
  94. function drawBox($x1, $y1, $x2, $y2, $char) {
  95. caca_draw_box($this->cv, $x1, $y1, $x2, $y2, $char);
  96. }
  97. function drawThinBox($x1, $y1, $x2, $y2) {
  98. caca_draw_thin_box($this->cv, $x1, $y1, $x2, $y2);
  99. }
  100. function drawCP437Box($x1, $y1, $x2, $y2) {
  101. caca_draw_cp437_box($this->cv, $x1, $y1, $x2, $y2);
  102. }
  103. function fillBox($x1, $y1, $x2, $y2, $char) {
  104. caca_fill_box($this->cv, $x1, $y1, $x2, $y2, $char);
  105. }
  106. function drawTriangle($x1, $y1, $x2, $y2, $x3, $y3, $char) {
  107. caca_draw_triangle($this->cv, $x1, $y1, $x2, $y2, $x3, $y3, $char);
  108. }
  109. function drawThinTriangle($x1, $y1, $x2, $y2, $x3, $y3) {
  110. caca_draw_thin_triangle($this->cv, $x1, $y1, $x2, $y2, $x3, $y3);
  111. }
  112. function fillTriangle($x1, $y1, $x2, $y2, $x3, $y3, $char) {
  113. caca_fill_triangle($this->cv, $x1, $y1, $x2, $y2, $x3, $y3, $char);
  114. }
  115. function __construct($width = 0, $height = 0) {
  116. $this->cv = caca_create_canvas($width, $height);
  117. }
  118. function get_resource() {
  119. return $this->cv;
  120. }
  121. }
  122. class Display {
  123. private $dp;
  124. function setDisplayTime($time) {
  125. return caca_set_display_time($this->dp, $time);
  126. }
  127. function getDisplayTime() {
  128. return caca_get_display_time($this->dp);
  129. }
  130. function getWidth() {
  131. return caca_get_display_width($this->dp);
  132. }
  133. function getHeight() {
  134. return caca_get_display_height($this->dp);
  135. }
  136. function setTitle($title) {
  137. return caca_set_display_title($this->dp, $title);
  138. }
  139. function getMouseX() {
  140. return caca_get_mouse_x($this->dp);
  141. }
  142. function getMouseY() {
  143. return caca_get_mouse_y($this->dp);
  144. }
  145. function setMouse($state) {
  146. return caca_set_mouse($this->dp, $state);
  147. }
  148. function __construct($canvas) {
  149. $this->dp = caca_create_display($canvas->get_resource());
  150. }
  151. function get_resource() {
  152. return $this->dp;
  153. }
  154. }
  155. class Dither {
  156. private $dt;
  157. private $img;
  158. function setPalette($colors) {
  159. return caca_set_dither_palette($this->dt, $colors);
  160. }
  161. function setBrightness($value) {
  162. return caca_set_dither_brightness($this->dt, $value);
  163. }
  164. function getBrightness() {
  165. return caca_get_dither_brightness($this->dt);
  166. }
  167. function setGamme($value) {
  168. return caca_set_dither_gamma($this->dt, $value);
  169. }
  170. function getGamma() {
  171. return caca_get_dither_gamma($this->dt);
  172. }
  173. function setContrast($value) {
  174. return caca_set_dither_contrast($this->dt, $value);
  175. }
  176. function getContrast() {
  177. return caca_get_dither_contrast($this->dt);
  178. }
  179. function setAntialias($value) {
  180. return caca_set_dither_antialias($this->dt, $value);
  181. }
  182. function getAntialiasList() {
  183. return caca_get_dither_antialias_list($this->dt);
  184. }
  185. function getAntialias() {
  186. return caca_get_dither_antialias($this->dt);
  187. }
  188. function setColor($color) {
  189. return caca_set_dither_color($this->dt, $color);
  190. }
  191. function getColorList() {
  192. return caca_get_dither_color_list($this->dt);
  193. }
  194. function getColor() {
  195. return caca_get_dither_color($this->dt);
  196. }
  197. function setCharset($value) {
  198. return caca_set_dither_charset($this->dt, $value);
  199. }
  200. function getCharsetList() {
  201. return caca_get_dither_charset_list($this->dt);
  202. }
  203. function getCharset() {
  204. return caca_get_dither_charset($this->dt);
  205. }
  206. function setAlgorithm($name) {
  207. return caca_set_dither_algorithm($this->dt, $name);
  208. }
  209. function getAlgorithmList() {
  210. return caca_get_dither_algorithm_list($this->dt);
  211. }
  212. function getAlgorithm() {
  213. return caca_get_dither_algorithm($this->dt);
  214. }
  215. function bitmap($canvas, $x, $y, $width, $height, $load_palette = true) {
  216. return caca_dither_bitmap($canvas, $x, $y, $width, $height, $this->dt, $this->img, $load_palette);
  217. }
  218. function __construct($image) {
  219. $this->dt = caca_create_dither($image);
  220. $this->img = $image;
  221. }
  222. }