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