Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583
  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 Libcaca
  15. {
  16. static function Rand($min, $max)
  17. {
  18. return caca_rand($min, $max);
  19. }
  20. static function getVersion()
  21. {
  22. return caca_get_version();
  23. }
  24. }
  25. class AnsiColor
  26. {
  27. const BLACK = CACA_BLACK;
  28. const BLUE = CACA_BLUE;
  29. const GREEN = CACA_GREEN;
  30. const CYAN = CACA_CYAN;
  31. const RED = CACA_RED;
  32. const MAGENTA = CACA_MAGENTA;
  33. const BROWN = CACA_BROWN;
  34. const LIGHTGRAY = CACA_LIGHTGRAY;
  35. const DARKGRAY = CACA_DARKGRAY;
  36. const LIGHTBLUE = CACA_LIGHTBLUE;
  37. const LIGHTGREEN = CACA_LIGHTGREEN;
  38. const LIGHTCYAN = CACA_LIGHTCYAN;
  39. const LIGHTRED = CACA_LIGHTRED;
  40. const LIGHTMAGENTA = CACA_LIGHTMAGENTA;
  41. const YELLOW = CACA_YELLOW;
  42. const WHITE = CACA_WHITE;
  43. /* NOTE: We can't call this one DEFAULT because that's a reserved
  44. * token in PHP. */
  45. const DEFAULTCOLOR = CACA_DEFAULT;
  46. const TRANSPARENT = CACA_TRANSPARENT;
  47. }
  48. class Canvas {
  49. private $cv;
  50. function importFile($path, $codec) {
  51. return caca_import_file($this->cv, $path, $codec);
  52. }
  53. function importString($str, $codec) {
  54. return caca_import_string($this->cv, $str, $codec);
  55. }
  56. function exportString($codec) {
  57. return caca_export_string($this->cv, $codec);
  58. }
  59. function freeFrame($id) {
  60. return caca_free_frame($this->cv, $id);
  61. }
  62. function frameCount() {
  63. return caca_get_frame_count($this->cv);
  64. }
  65. function createFrame($id) {
  66. return caca_create_frame($this->cv, $id);
  67. }
  68. function setFrameName($name) {
  69. return caca_set_frame_name($this->cv, $name);
  70. }
  71. function setFrame($id) {
  72. return caca_set_frame($this->cv, $id);
  73. }
  74. function putFigchar($char) {
  75. return caca_put_figchar($this->cv, $char);
  76. }
  77. function setFigfont($path) {
  78. return caca_canvas_set_figfont($this->cv, $path);
  79. }
  80. function putAttr($attr) {
  81. return caca_put_attr($this->cv, $attr);
  82. }
  83. function stretchRight() {
  84. return caca_stretch_right($this->cv);
  85. }
  86. function stretchLeft() {
  87. return caca_stretch_left($this->cv);
  88. }
  89. function setBoundaries($width, $height) {
  90. return caca_set_canvas_boundaries($this->cv, $width, $height);
  91. }
  92. function setHandle($x, $y) {
  93. return caca_set_canvas_handle($this->cv, $x, $y);
  94. }
  95. function getHandleX() {
  96. return caca_get_canvas_handle_x($this->cv);
  97. }
  98. function getHandleY() {
  99. return caca_get_canvas_handle_y($this->cv);
  100. }
  101. function getCursorX() {
  102. return caca_get_cursor_x($this->cv);
  103. }
  104. function getCursorY() {
  105. return caca_get_cursor_y($this->cv);
  106. }
  107. function getChars() {
  108. return caca_get_canvas_chars($this->cv);
  109. }
  110. function getAttrs() {
  111. return caca_get_canvas_attrs($this->cv);
  112. }
  113. function setSize($width, $height) {
  114. return caca_set_canvas_size($this->cv, $width, $height);
  115. }
  116. function getWidth() {
  117. return caca_get_canvas_width($this->cv);
  118. }
  119. function getHeight() {
  120. return caca_get_canvas_height($this->cv);
  121. }
  122. function getAttr($x, $y) {
  123. return caca_get_attr($this->cv, $x, $y);
  124. }
  125. function setAttr($attr) {
  126. return caca_set_attr($this->cv, $x, $y, $attr);
  127. }
  128. function setColorANSI($foreground, $background) {
  129. return caca_set_color_ansi($this->cv, $foreground, $background);
  130. }
  131. function setColorARGB($foreground, $background) {
  132. return caca_set_color_argb($this->cv, $foreground, $background);
  133. }
  134. function putChar($x, $y, $c) {
  135. return caca_put_char($this->cv, $x, $y, $c);
  136. }
  137. function getChar($x, $y) {
  138. return caca_get_char($this->cv, $x, $y);
  139. }
  140. function putStr($x, $y, $str) {
  141. return caca_put_str($this->cv, $x, $y, $str);
  142. }
  143. function Clear() {
  144. return caca_clear_canvas($this->cv);
  145. }
  146. function Blit($x, $y, $canvas, $mask = NULL) {
  147. if($mask)
  148. return caca_blit($this->cv, $x, $y, $canvas->get_resource(), $mask->get_resource());
  149. return caca_blit($this->cv, $x, $y, $canvas->get_resource());
  150. }
  151. function Invert() {
  152. return caca_invert($this->cv);
  153. }
  154. function Flip() {
  155. return caca_flip($this->cv);
  156. }
  157. function Flop() {
  158. return caca_flop($this->cv);
  159. }
  160. function Rotate180() {
  161. return caca_rotate_180($this->cv);
  162. }
  163. function RotateLeft() {
  164. return caca_rotate_left($this->cv);
  165. }
  166. function RotateRight() {
  167. return caca_rotate_right($this->cv);
  168. }
  169. function drawLine($x1, $y1, $x2, $y2, $char) {
  170. return caca_draw_line($this->cv, $x1, $y1, $x2, $y2, $char);
  171. }
  172. function drawPolyline($points, $char) {
  173. return caca_draw_polyline($this->cv, $points, $char);
  174. }
  175. function drawThinLine($x1, $y1, $x2, $y2) {
  176. return caca_draw_thin_line($this->cv, $x1, $y1, $x2, $y2);
  177. }
  178. function drawThinPolyline($points) {
  179. return caca_draw_thin_polyline($this->cv, $points);
  180. }
  181. function drawCircle($x, $y, $radius, $char) {
  182. return caca_draw_circle($this->cv, $x, $y, $radius, $char);
  183. }
  184. function drawEllipse($x1, $y1, $x2, $y2, $char) {
  185. return caca_draw_ellipse($this->cv, $x1, $y1, $x2, $y2, $char);
  186. }
  187. function drawThinEllipse($x1, $y1, $x2, $y2) {
  188. return caca_draw_thin_ellipse($this->cv, $x1, $y1, $x2, $y2);
  189. }
  190. function fillEllipse($x1, $y1, $x2, $y2, $char) {
  191. return caca_fill_ellipse($this->cv, $x1, $y1, $x2, $y2, $char);
  192. }
  193. function drawBox($x1, $y1, $x2, $y2, $char) {
  194. return caca_draw_box($this->cv, $x1, $y1, $x2, $y2, $char);
  195. }
  196. function drawThinBox($x1, $y1, $x2, $y2) {
  197. return caca_draw_thin_box($this->cv, $x1, $y1, $x2, $y2);
  198. }
  199. function drawCP437Box($x1, $y1, $x2, $y2) {
  200. return caca_draw_cp437_box($this->cv, $x1, $y1, $x2, $y2);
  201. }
  202. function fillBox($x1, $y1, $x2, $y2, $char) {
  203. return caca_fill_box($this->cv, $x1, $y1, $x2, $y2, $char);
  204. }
  205. function drawTriangle($x1, $y1, $x2, $y2, $x3, $y3, $char) {
  206. return caca_draw_triangle($this->cv, $x1, $y1, $x2, $y2, $x3, $y3, $char);
  207. }
  208. function drawThinTriangle($x1, $y1, $x2, $y2, $x3, $y3) {
  209. return caca_draw_thin_triangle($this->cv, $x1, $y1, $x2, $y2, $x3, $y3);
  210. }
  211. function fillTriangle($x1, $y1, $x2, $y2, $x3, $y3, $char) {
  212. return caca_fill_triangle($this->cv, $x1, $y1, $x2, $y2, $x3, $y3, $char);
  213. }
  214. function __construct($width = 0, $height = 0) {
  215. $this->cv = caca_create_canvas($width, $height);
  216. }
  217. function get_resource() {
  218. return $this->cv;
  219. }
  220. }
  221. class EventType
  222. {
  223. const NONE = CACA_EVENT_NONE;
  224. const KEY_PRESS = CACA_EVENT_KEY_PRESS;
  225. const KEY_RELEASE = CACA_EVENT_KEY_RELEASE;
  226. const MOUSE_PRESS = CACA_EVENT_MOUSE_PRESS;
  227. const MOUSE_RELEASE = CACA_EVENT_MOUSE_RELEASE;
  228. const MOUSE_MOTION = CACA_EVENT_MOUSE_MOTION;
  229. const RESIZE = CACA_EVENT_RESIZE;
  230. const QUIT = CACA_EVENT_QUIT;
  231. const ANY = CACA_EVENT_ANY;
  232. }
  233. class EventKey
  234. {
  235. const UNKNOWN = CACA_KEY_UNKNOWN;
  236. const CTRL_A = CACA_KEY_CTRL_A;
  237. const CTRL_B = CACA_KEY_CTRL_B;
  238. const CTRL_C = CACA_KEY_CTRL_C;
  239. const CTRL_D = CACA_KEY_CTRL_D;
  240. const CTRL_E = CACA_KEY_CTRL_E;
  241. const CTRL_F = CACA_KEY_CTRL_F;
  242. const CTRL_G = CACA_KEY_CTRL_G;
  243. const BACKSPACE = CACA_KEY_BACKSPACE;
  244. const TAB = CACA_KEY_TAB;
  245. const CTRL_J = CACA_KEY_CTRL_J;
  246. const CTRL_K = CACA_KEY_CTRL_K;
  247. const CTRL_L = CACA_KEY_CTRL_L;
  248. /* NOTE: We can't call this one RETURN because that's a
  249. * reserved token in PHP */
  250. const RETURN_KEY = CACA_KEY_RETURN;
  251. const CTRL_N = CACA_KEY_CTRL_N;
  252. const CTRL_O = CACA_KEY_CTRL_O;
  253. const CTRL_P = CACA_KEY_CTRL_P;
  254. const CTRL_Q = CACA_KEY_CTRL_Q;
  255. const CTRL_R = CACA_KEY_CTRL_R;
  256. const PAUSE = CACA_KEY_PAUSE;
  257. const CTRL_T = CACA_KEY_CTRL_T;
  258. const CTRL_U = CACA_KEY_CTRL_U;
  259. const CTRL_V = CACA_KEY_CTRL_V;
  260. const CTRL_W = CACA_KEY_CTRL_W;
  261. const CTRL_X = CACA_KEY_CTRL_X;
  262. const CTRL_Y = CACA_KEY_CTRL_Y;
  263. const CTRL_Z = CACA_KEY_CTRL_Z;
  264. const ESCAPE = CACA_KEY_ESCAPE;
  265. const DELETE = CACA_KEY_DELETE;
  266. const UP = CACA_KEY_UP;
  267. const DOWN = CACA_KEY_DOWN;
  268. const LEFT = CACA_KEY_LEFT;
  269. const RIGHT = CACA_KEY_RIGHT;
  270. const INSERT = CACA_KEY_INSERT;
  271. const HOME = CACA_KEY_HOME;
  272. const END = CACA_KEY_END;
  273. const PAGEUP = CACA_KEY_PAGEUP;
  274. const PAGEDOWN = CACA_KEY_PAGEDOWN;
  275. const F1 = CACA_KEY_F1;
  276. const F2 = CACA_KEY_F2;
  277. const F3 = CACA_KEY_F3;
  278. const F4 = CACA_KEY_F4;
  279. const F5 = CACA_KEY_F5;
  280. const F6 = CACA_KEY_F6;
  281. const F7 = CACA_KEY_F7;
  282. const F8 = CACA_KEY_F8;
  283. const F9 = CACA_KEY_F9;
  284. const F10 = CACA_KEY_F10;
  285. const F11 = CACA_KEY_F11;
  286. const F12 = CACA_KEY_F12;
  287. const F13 = CACA_KEY_F13;
  288. const F14 = CACA_KEY_F14;
  289. const F15 = CACA_KEY_F15;
  290. }
  291. class Event {
  292. private $ev;
  293. function getType() {
  294. return caca_get_event_type($this->ev);
  295. }
  296. function getKeyCh() {
  297. return caca_get_event_key_ch($this->ev);
  298. }
  299. function getMouseX() {
  300. return caca_get_event_mouse_x($this->ev);
  301. }
  302. function getResizeWidth() {
  303. return caca_get_event_resize_width($this->ev);
  304. }
  305. function getResizeHeight() {
  306. return caca_get_event_resize_height($this->ev);
  307. }
  308. function __construct($_ev) {
  309. $this->ev = $_ev;
  310. }
  311. function get_resource() {
  312. return $this->ev;
  313. }
  314. }
  315. class Display {
  316. private $dp;
  317. function setCursor($visible) {
  318. return caca_set_cursor($this->dp, $visible);
  319. }
  320. function refresh() {
  321. return caca_refresh_display($this->dp);
  322. }
  323. function getDriver() {
  324. return caca_get_display_driver($this->dp);
  325. }
  326. function setDriver($name) {
  327. return caca_set_display_driver($this->dp, $name);
  328. }
  329. function setDisplayTime($time) {
  330. return caca_set_display_time($this->dp, $time);
  331. }
  332. function getDisplayTime() {
  333. return caca_get_display_time($this->dp);
  334. }
  335. function getWidth() {
  336. return caca_get_display_width($this->dp);
  337. }
  338. function getHeight() {
  339. return caca_get_display_height($this->dp);
  340. }
  341. function setTitle($title) {
  342. return caca_set_display_title($this->dp, $title);
  343. }
  344. function gotoXY($x, $y) {
  345. return caca_gotoxy($this->dp, $x, $y);
  346. }
  347. function getMouseX() {
  348. return caca_get_mouse_x($this->dp);
  349. }
  350. function getMouseY() {
  351. return caca_get_mouse_y($this->dp);
  352. }
  353. function setMouse($state) {
  354. return caca_set_mouse($this->dp, $state);
  355. }
  356. function getEvent($t, $timeout = 0) {
  357. $ev = caca_get_event($this->dp, $t, $timeout);
  358. if(! $ev) {
  359. return NULL;
  360. }
  361. return new Event($ev);
  362. }
  363. function __construct($canvas, $driver = NULL) {
  364. if($driver)
  365. $this->dp = caca_create_display_with_driver($canvas->get_resource(), $driver);
  366. else
  367. $this->dp = caca_create_display($canvas->get_resource());
  368. }
  369. function get_resource() {
  370. return $this->dp;
  371. }
  372. }
  373. class Dither {
  374. private $dt;
  375. private $img;
  376. function setPalette($colors) {
  377. return caca_set_dither_palette($this->dt, $colors);
  378. }
  379. function setBrightness($value) {
  380. return caca_set_dither_brightness($this->dt, $value);
  381. }
  382. function getBrightness() {
  383. return caca_get_dither_brightness($this->dt);
  384. }
  385. function setGamme($value) {
  386. return caca_set_dither_gamma($this->dt, $value);
  387. }
  388. function getGamma() {
  389. return caca_get_dither_gamma($this->dt);
  390. }
  391. function setContrast($value) {
  392. return caca_set_dither_contrast($this->dt, $value);
  393. }
  394. function getContrast() {
  395. return caca_get_dither_contrast($this->dt);
  396. }
  397. function setAntialias($value) {
  398. return caca_set_dither_antialias($this->dt, $value);
  399. }
  400. function getAntialiasList() {
  401. return caca_get_dither_antialias_list($this->dt);
  402. }
  403. function getAntialias() {
  404. return caca_get_dither_antialias($this->dt);
  405. }
  406. function setColor($color) {
  407. return caca_set_dither_color($this->dt, $color);
  408. }
  409. function getColorList() {
  410. return caca_get_dither_color_list($this->dt);
  411. }
  412. function getColor() {
  413. return caca_get_dither_color($this->dt);
  414. }
  415. function setCharset($value) {
  416. return caca_set_dither_charset($this->dt, $value);
  417. }
  418. function getCharsetList() {
  419. return caca_get_dither_charset_list($this->dt);
  420. }
  421. function getCharset() {
  422. return caca_get_dither_charset($this->dt);
  423. }
  424. function setAlgorithm($name) {
  425. return caca_set_dither_algorithm($this->dt, $name);
  426. }
  427. function getAlgorithmList() {
  428. return caca_get_dither_algorithm_list($this->dt);
  429. }
  430. function getAlgorithm() {
  431. return caca_get_dither_algorithm($this->dt);
  432. }
  433. function bitmap($canvas, $x, $y, $width, $height, $load_palette = true) {
  434. return caca_dither_bitmap($canvas->get_resource(), $x, $y, $width, $height, $this->dt, $this->img, $load_palette);
  435. }
  436. function __construct($image) {
  437. $this->dt = caca_create_dither($image);
  438. $this->img = $image;
  439. }
  440. }
  441. class Font {
  442. private $f;
  443. function getWidth() {
  444. return caca_get_font_width($this->f);
  445. }
  446. function getHeight() {
  447. return caca_get_font_height($this->f);
  448. }
  449. function getBlocks() {
  450. return caca_get_font_blocks($this->f);
  451. }
  452. function Render($cv, $image) {
  453. return caca_render_canvas($cv->get_resource(), $this->f, $image);
  454. }
  455. static function getList() {
  456. return caca_get_font_list();
  457. }
  458. function __construct($name) {
  459. $this->f = caca_load_builtin_font($name);
  460. }
  461. }