Debian Codegraph @

caca-php/caca.php

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