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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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. }