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 | |
---|
15 | |
---|
16 | class Canvas { |
---|
17 | private $cv; |
---|
18 | |
---|
19 | function importFile($path, $codec) { |
---|
20 | return caca_import_file($this->cv, $path, $codec); |
---|
21 | } |
---|
22 | |
---|
23 | function importString($codec) { |
---|
24 | return caca_import_string($this->cv, $codec); |
---|
25 | } |
---|
26 | |
---|
27 | function exportString($codec) { |
---|
28 | return caca_export_string($this->cv, $codec); |
---|
29 | } |
---|
30 | |
---|
31 | function freeFrame($id) { |
---|
32 | return caca_free_frame($this->cv, $id); |
---|
33 | } |
---|
34 | |
---|
35 | function frameCount() { |
---|
36 | return caca_get_frame_count($this->cv); |
---|
37 | } |
---|
38 | |
---|
39 | function createFrame($id) { |
---|
40 | return caca_create_frame($this->cv, $id); |
---|
41 | } |
---|
42 | |
---|
43 | function setFrameName($name) { |
---|
44 | return caca_set_frame_name($this->cv, $name); |
---|
45 | } |
---|
46 | |
---|
47 | function setFrame($id) { |
---|
48 | return caca_set_frame($this->cv, $id); |
---|
49 | } |
---|
50 | |
---|
51 | function putFigchar($char) { |
---|
52 | return caca_put_figchar($this->cv, $char); |
---|
53 | } |
---|
54 | |
---|
55 | function setFigfont($path) { |
---|
56 | return caca_canvas_set_figfont($this->cv, $path); |
---|
57 | } |
---|
58 | |
---|
59 | function putAttr($attr) { |
---|
60 | return caca_put_attr($this->cv, $attr); |
---|
61 | } |
---|
62 | |
---|
63 | function stretchRight() { |
---|
64 | return caca_stretch_right($this->cv); |
---|
65 | } |
---|
66 | |
---|
67 | function stretchLeft() { |
---|
68 | return caca_stretch_left($this->cv); |
---|
69 | } |
---|
70 | |
---|
71 | function setBoundaries($width, $height) { |
---|
72 | return caca_set_canvas_boundaries($this->cv, $width, $height); |
---|
73 | } |
---|
74 | |
---|
75 | function setHandle($x, $y) { |
---|
76 | return caca_set_canvas_handle($this->cv, $x, $y); |
---|
77 | } |
---|
78 | |
---|
79 | function getHandleX() { |
---|
80 | return caca_get_canvas_handle_x($this->cv); |
---|
81 | } |
---|
82 | |
---|
83 | function getHandleY() { |
---|
84 | return caca_get_canvas_handle_y($this->cv); |
---|
85 | } |
---|
86 | |
---|
87 | function getCursorX() { |
---|
88 | return caca_get_cursor_x($this->cv); |
---|
89 | } |
---|
90 | |
---|
91 | function getCursorY() { |
---|
92 | return caca_get_cursor_y($this->cv); |
---|
93 | } |
---|
94 | |
---|
95 | function getChars() { |
---|
96 | return caca_get_canvas_chars($this->cv); |
---|
97 | } |
---|
98 | |
---|
99 | function getAttrs() { |
---|
100 | return caca_get_canvas_attrs($this->cv); |
---|
101 | } |
---|
102 | |
---|
103 | function setSize($width, $height) { |
---|
104 | return caca_set_canvas_size($this->cv, $width, $height); |
---|
105 | } |
---|
106 | |
---|
107 | function getWidth() { |
---|
108 | return caca_get_canvas_width($this->cv); |
---|
109 | } |
---|
110 | |
---|
111 | function getHeight() { |
---|
112 | return caca_get_canvas_height($this->cv); |
---|
113 | } |
---|
114 | |
---|
115 | function getAttr($x, $y) { |
---|
116 | return caca_get_attr($this->cv, $x, $y); |
---|
117 | } |
---|
118 | |
---|
119 | function setAttr($attr) { |
---|
120 | return caca_set_attr($this->cv, $x, $y, $attr); |
---|
121 | } |
---|
122 | |
---|
123 | function setColorANSI($foreground, $background) { |
---|
124 | return caca_set_color_ansi($this->cv, $foreground, $background); |
---|
125 | } |
---|
126 | |
---|
127 | function setColorARGB($foreground, $background) { |
---|
128 | return caca_set_color_argb($this->cv, $foreground, $background); |
---|
129 | } |
---|
130 | |
---|
131 | function putChar($x, $y, $c) { |
---|
132 | return caca_put_char($this->cv, $x, $y, $c); |
---|
133 | } |
---|
134 | |
---|
135 | function getChar($x, $y) { |
---|
136 | return caca_get_char($this->cv, $x, $y); |
---|
137 | } |
---|
138 | |
---|
139 | function putStr($x, $y, $str) { |
---|
140 | return caca_put_str($this->cv, $x, $y, $str); |
---|
141 | } |
---|
142 | |
---|
143 | function Clear() { |
---|
144 | return caca_clear_canvas($this->cv); |
---|
145 | } |
---|
146 | |
---|
147 | function Blit($x, $y, $canvas, $mask = false) { |
---|
148 | return caca_blit($this->cv, $x, $y, $canvas->get_resource(), ($mask != false) ? $mask->get_resource() : false ); |
---|
149 | } |
---|
150 | |
---|
151 | function Invert() { |
---|
152 | return caca_invert($this->cv); |
---|
153 | } |
---|
154 | |
---|
155 | function Flip() { |
---|
156 | return caca_flip($this->cv); |
---|
157 | } |
---|
158 | |
---|
159 | function Flop() { |
---|
160 | return caca_flop($this->cv); |
---|
161 | } |
---|
162 | |
---|
163 | function Rotate180() { |
---|
164 | return caca_rotate_180($this->cv); |
---|
165 | } |
---|
166 | |
---|
167 | function RotateLeft() { |
---|
168 | return caca_rotate_left($this->cv); |
---|
169 | } |
---|
170 | |
---|
171 | function RotateRight() { |
---|
172 | return caca_rotate_right($this->cv); |
---|
173 | } |
---|
174 | |
---|
175 | function drawLine($x1, $y1, $x2, $y2, $char) { |
---|
176 | return caca_draw_line($this->cv, $x1, $y1, $x2, $y2, $color); |
---|
177 | } |
---|
178 | |
---|
179 | function drawPolyline($points, $char) { |
---|
180 | return caca_draw_polyline($this->cv, $points, $char); |
---|
181 | } |
---|
182 | |
---|
183 | function drawThinLine($x1, $y1, $x2, $y2) { |
---|
184 | return caca_draw_thin_line($this->cv, $x1, $y1, $x2, $y2); |
---|
185 | } |
---|
186 | |
---|
187 | function drawThinPolyline($points) { |
---|
188 | return caca_draw_thin_polyline($this->cv, $points); |
---|
189 | } |
---|
190 | |
---|
191 | function drawCircle($x, $y, $radius, $char) { |
---|
192 | return caca_draw_circle($this->cv, $x, $y, $radius, $char); |
---|
193 | } |
---|
194 | |
---|
195 | function drawEllipse($x1, $y1, $x2, $y2, $char) { |
---|
196 | return caca_draw_ellipse($this->cv, $x1, $y1, $x2, $y2, $char); |
---|
197 | } |
---|
198 | |
---|
199 | function drawThinEllipse($x1, $y1, $x2, $y2) { |
---|
200 | return caca_draw_thin_ellipse($this->cv, $x1, $y1, $x2, $y2); |
---|
201 | } |
---|
202 | |
---|
203 | function fillEllipse($x1, $y1, $x2, $y2, $char) { |
---|
204 | return caca_fill_ellipse($this->cv, $x1, $y1, $x2, $y2, $char); |
---|
205 | } |
---|
206 | |
---|
207 | function drawBox($x1, $y1, $x2, $y2, $char) { |
---|
208 | return caca_draw_box($this->cv, $x1, $y1, $x2, $y2, $char); |
---|
209 | } |
---|
210 | |
---|
211 | function drawThinBox($x1, $y1, $x2, $y2) { |
---|
212 | return caca_draw_thin_box($this->cv, $x1, $y1, $x2, $y2); |
---|
213 | } |
---|
214 | |
---|
215 | function drawCP437Box($x1, $y1, $x2, $y2) { |
---|
216 | return caca_draw_cp437_box($this->cv, $x1, $y1, $x2, $y2); |
---|
217 | } |
---|
218 | |
---|
219 | function fillBox($x1, $y1, $x2, $y2, $char) { |
---|
220 | return caca_fill_box($this->cv, $x1, $y1, $x2, $y2, $char); |
---|
221 | } |
---|
222 | |
---|
223 | function drawTriangle($x1, $y1, $x2, $y2, $x3, $y3, $char) { |
---|
224 | return caca_draw_triangle($this->cv, $x1, $y1, $x2, $y2, $x3, $y3, $char); |
---|
225 | } |
---|
226 | |
---|
227 | function drawThinTriangle($x1, $y1, $x2, $y2, $x3, $y3) { |
---|
228 | return caca_draw_thin_triangle($this->cv, $x1, $y1, $x2, $y2, $x3, $y3); |
---|
229 | } |
---|
230 | |
---|
231 | function fillTriangle($x1, $y1, $x2, $y2, $x3, $y3, $char) { |
---|
232 | return caca_fill_triangle($this->cv, $x1, $y1, $x2, $y2, $x3, $y3, $char); |
---|
233 | } |
---|
234 | |
---|
235 | function __construct($width = 0, $height = 0) { |
---|
236 | $this->cv = caca_create_canvas($width, $height); |
---|
237 | } |
---|
238 | |
---|
239 | function get_resource() { |
---|
240 | return $this->cv; |
---|
241 | } |
---|
242 | } |
---|
243 | |
---|
244 | class Display { |
---|
245 | private $dp; |
---|
246 | |
---|
247 | function setCursor($visible) { |
---|
248 | return caca_set_cursor($this->dp, $visible); |
---|
249 | } |
---|
250 | |
---|
251 | function refresh() { |
---|
252 | return caca_refresh_display($this->dp); |
---|
253 | } |
---|
254 | |
---|
255 | function getDriver() { |
---|
256 | return caca_get_display_driver($this->dp); |
---|
257 | } |
---|
258 | |
---|
259 | function setDriver($name) { |
---|
260 | return caca_set_display_driver($this->dp, $name); |
---|
261 | } |
---|
262 | |
---|
263 | function setDisplayTime($time) { |
---|
264 | return caca_set_display_time($this->dp, $time); |
---|
265 | } |
---|
266 | |
---|
267 | function getDisplayTime() { |
---|
268 | return caca_get_display_time($this->dp); |
---|
269 | } |
---|
270 | |
---|
271 | function getWidth() { |
---|
272 | return caca_get_display_width($this->dp); |
---|
273 | } |
---|
274 | |
---|
275 | function getHeight() { |
---|
276 | return caca_get_display_height($this->dp); |
---|
277 | } |
---|
278 | |
---|
279 | function setTitle($title) { |
---|
280 | return caca_set_display_title($this->dp, $title); |
---|
281 | } |
---|
282 | |
---|
283 | function gotoXY($x, $y) { |
---|
284 | return caca_gotoxy($this->dp, $x, $y); |
---|
285 | } |
---|
286 | |
---|
287 | function getMouseX() { |
---|
288 | return caca_get_mouse_x($this->dp); |
---|
289 | } |
---|
290 | |
---|
291 | function getMouseY() { |
---|
292 | return caca_get_mouse_y($this->dp); |
---|
293 | } |
---|
294 | |
---|
295 | function setMouse($state) { |
---|
296 | return caca_set_mouse($this->dp, $state); |
---|
297 | } |
---|
298 | |
---|
299 | function __construct($canvas, $driver = false) { |
---|
300 | if ($driver) |
---|
301 | $this->dp = caca_create_display_with_driver($canvas->get_resource(), $driver); |
---|
302 | else |
---|
303 | $this->dp = caca_create_display($canvas->get_resource()); |
---|
304 | } |
---|
305 | |
---|
306 | function get_resource() { |
---|
307 | return $this->dp; |
---|
308 | } |
---|
309 | } |
---|
310 | |
---|
311 | class Dither { |
---|
312 | private $dt; |
---|
313 | private $img; |
---|
314 | |
---|
315 | function setPalette($colors) { |
---|
316 | return caca_set_dither_palette($this->dt, $colors); |
---|
317 | } |
---|
318 | |
---|
319 | function setBrightness($value) { |
---|
320 | return caca_set_dither_brightness($this->dt, $value); |
---|
321 | } |
---|
322 | |
---|
323 | function getBrightness() { |
---|
324 | return caca_get_dither_brightness($this->dt); |
---|
325 | } |
---|
326 | |
---|
327 | function setGamme($value) { |
---|
328 | return caca_set_dither_gamma($this->dt, $value); |
---|
329 | } |
---|
330 | |
---|
331 | function getGamma() { |
---|
332 | return caca_get_dither_gamma($this->dt); |
---|
333 | } |
---|
334 | |
---|
335 | function setContrast($value) { |
---|
336 | return caca_set_dither_contrast($this->dt, $value); |
---|
337 | } |
---|
338 | |
---|
339 | function getContrast() { |
---|
340 | return caca_get_dither_contrast($this->dt); |
---|
341 | } |
---|
342 | |
---|
343 | function setAntialias($value) { |
---|
344 | return caca_set_dither_antialias($this->dt, $value); |
---|
345 | } |
---|
346 | |
---|
347 | function getAntialiasList() { |
---|
348 | return caca_get_dither_antialias_list($this->dt); |
---|
349 | } |
---|
350 | |
---|
351 | function getAntialias() { |
---|
352 | return caca_get_dither_antialias($this->dt); |
---|
353 | } |
---|
354 | |
---|
355 | function setColor($color) { |
---|
356 | return caca_set_dither_color($this->dt, $color); |
---|
357 | } |
---|
358 | |
---|
359 | function getColorList() { |
---|
360 | return caca_get_dither_color_list($this->dt); |
---|
361 | } |
---|
362 | |
---|
363 | function getColor() { |
---|
364 | return caca_get_dither_color($this->dt); |
---|
365 | } |
---|
366 | |
---|
367 | function setCharset($value) { |
---|
368 | return caca_set_dither_charset($this->dt, $value); |
---|
369 | } |
---|
370 | |
---|
371 | function getCharsetList() { |
---|
372 | return caca_get_dither_charset_list($this->dt); |
---|
373 | } |
---|
374 | |
---|
375 | function getCharset() { |
---|
376 | return caca_get_dither_charset($this->dt); |
---|
377 | } |
---|
378 | |
---|
379 | function setAlgorithm($name) { |
---|
380 | return caca_set_dither_algorithm($this->dt, $name); |
---|
381 | } |
---|
382 | |
---|
383 | function getAlgorithmList() { |
---|
384 | return caca_get_dither_algorithm_list($this->dt); |
---|
385 | } |
---|
386 | |
---|
387 | function getAlgorithm() { |
---|
388 | return caca_get_dither_algorithm($this->dt); |
---|
389 | } |
---|
390 | |
---|
391 | function bitmap($canvas, $x, $y, $width, $height, $load_palette = true) { |
---|
392 | return caca_dither_bitmap($canvas, $x, $y, $width, $height, $this->dt, $this->img, $load_palette); |
---|
393 | } |
---|
394 | |
---|
395 | function __construct($image) { |
---|
396 | $this->dt = caca_create_dither($image); |
---|
397 | $this->img = $image; |
---|
398 | } |
---|
399 | } |
---|
400 | |
---|
401 | class Font { |
---|
402 | private $f; |
---|
403 | |
---|
404 | function getWidth() { |
---|
405 | return caca_get_font_width($this->f); |
---|
406 | } |
---|
407 | |
---|
408 | function getHeight() { |
---|
409 | return caca_get_font_height($this->f); |
---|
410 | } |
---|
411 | |
---|
412 | function getBlocks() { |
---|
413 | return caca_get_font_blocks($this->f); |
---|
414 | } |
---|
415 | |
---|
416 | function __construct($name) { |
---|
417 | $this->f = caca_load_builtin_font($name); |
---|
418 | } |
---|
419 | } |
---|