[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 | |
---|
| 19 | function setSize($width, $height) { |
---|
| 20 | return caca_set_canvas_width($this->cv, $width, $height); |
---|
| 21 | } |
---|
| 22 | |
---|
| 23 | function getWidth() { |
---|
| 24 | return caca_get_canvas_width($this->cv); |
---|
| 25 | } |
---|
| 26 | |
---|
| 27 | function getHeight() { |
---|
| 28 | return caca_get_canvas_height($this->cv); |
---|
| 29 | } |
---|
| 30 | |
---|
[3193] | 31 | function getAttr($x, $y) { |
---|
| 32 | return caca_get_attr($this->cv, $x, $y); |
---|
[3192] | 33 | } |
---|
| 34 | |
---|
[3193] | 35 | function setAttr($attr) { |
---|
| 36 | return caca_set_attr($this->cv, $x, $y, $attr); |
---|
[3192] | 37 | } |
---|
| 38 | |
---|
| 39 | function setColorANSI($foreground, $background) { |
---|
| 40 | return caca_set_color_ansi($this->cv, $foreground, $background); |
---|
| 41 | } |
---|
| 42 | |
---|
| 43 | function setColorARGB($foreground, $background) { |
---|
[3193] | 44 | return caca_set_color_argb($this->cv, $foreground, $background); |
---|
[3192] | 45 | } |
---|
| 46 | |
---|
| 47 | function putChar($x, $y, $c) { |
---|
| 48 | return caca_put_char($this->cv, $x, $y, $c); |
---|
| 49 | } |
---|
| 50 | |
---|
| 51 | function getChar($x, $y) { |
---|
| 52 | return caca_get_char($this->cv, $x, $y); |
---|
| 53 | } |
---|
| 54 | |
---|
| 55 | function putStr($x, $y, $str) { |
---|
| 56 | return caca_put_str($this->cv, $x, $y, $str); |
---|
| 57 | } |
---|
| 58 | |
---|
| 59 | function Clear() { |
---|
| 60 | return caca_canvas_clear($this->cv); |
---|
| 61 | } |
---|
| 62 | |
---|
[3193] | 63 | function Blit($x, $y, $canvas, $mask = false) { |
---|
| 64 | return caca_blit($this->cv, $x, $y, $canvas->get_resource(), ($mask != false) ? $mask->get_resource() : false ); |
---|
[3192] | 65 | } |
---|
| 66 | |
---|
| 67 | function Invert() { |
---|
| 68 | return caca_invert($this->cv); |
---|
| 69 | } |
---|
| 70 | |
---|
| 71 | function Flip() { |
---|
| 72 | return caca_flip($this->cv); |
---|
| 73 | } |
---|
| 74 | |
---|
| 75 | function Flop() { |
---|
| 76 | return caca_flop($this->cv); |
---|
| 77 | } |
---|
| 78 | |
---|
| 79 | function Rotate180() { |
---|
| 80 | return caca_rotate_180($this->cv); |
---|
| 81 | } |
---|
| 82 | |
---|
| 83 | function RotateLeft() { |
---|
| 84 | return caca_rotate_left($this->cv); |
---|
| 85 | } |
---|
| 86 | |
---|
| 87 | function RotateRight() { |
---|
| 88 | return caca_rotate_right($this->cv); |
---|
| 89 | } |
---|
| 90 | |
---|
[3193] | 91 | function drawLine($x1, $y1, $x2, $y2, $char) { |
---|
| 92 | return caca_draw_line($this->cv, $x1, $y1, $x2, $y2, $color); |
---|
[3192] | 93 | } |
---|
| 94 | |
---|
[3193] | 95 | function drawPolyline($points, $char) { |
---|
| 96 | return caca_draw_polyline($this->cv, $points, $char); |
---|
[3192] | 97 | } |
---|
| 98 | |
---|
[3193] | 99 | function drawThinLine($x1, $y1, $x2, $y2) { |
---|
| 100 | return caca_draw_thin_line($this->cv, $x1, $y1, $x2, $y2); |
---|
[3192] | 101 | } |
---|
| 102 | |
---|
[3193] | 103 | function drawThinPolyline($points) { |
---|
| 104 | return caca_draw_thin_polyline($this->cv, $points); |
---|
[3192] | 105 | } |
---|
| 106 | |
---|
[3193] | 107 | function drawCircle($x, $y, $radius, $char) { |
---|
| 108 | return caca_draw_circle($this->cv, $x, $y, $radius, $char); |
---|
[3192] | 109 | } |
---|
| 110 | |
---|
[3193] | 111 | function drawEllipse($x1, $y1, $x2, $y2, $char) { |
---|
| 112 | caca_draw_ellipse($this->cv, $x1, $y1, $x2, $y2, $char); |
---|
[3192] | 113 | } |
---|
| 114 | |
---|
[3193] | 115 | function drawThinEllipse($x1, $y1, $x2, $y2) { |
---|
| 116 | caca_draw_ellipse($this->cv, $x1, $y1, $x2, $y2); |
---|
[3192] | 117 | } |
---|
| 118 | |
---|
[3193] | 119 | function fillEllipse($x1, $y1, $x2, $y2, $char) { |
---|
| 120 | caca_fill_ellipse($this->cv, $x1, $y1, $x2, $y2, $char); |
---|
[3192] | 121 | } |
---|
| 122 | |
---|
[3193] | 123 | function drawBox($x1, $y1, $x2, $y2, $char) { |
---|
| 124 | caca_draw_box($this->cv, $x1, $y1, $x2, $y2, $char); |
---|
[3192] | 125 | } |
---|
| 126 | |
---|
[3193] | 127 | function drawThinBox($x1, $y1, $x2, $y2) { |
---|
| 128 | caca_draw_thin_box($this->cv, $x1, $y1, $x2, $y2); |
---|
[3192] | 129 | } |
---|
| 130 | |
---|
[3193] | 131 | function drawCP437Box($x1, $y1, $x2, $y2) { |
---|
| 132 | caca_draw_cp437_box($this->cv, $x1, $y1, $x2, $y2); |
---|
[3192] | 133 | } |
---|
| 134 | |
---|
[3193] | 135 | function fillBox($x1, $y1, $x2, $y2, $char) { |
---|
| 136 | caca_fill_box($this->cv, $x1, $y1, $x2, $y2, $char); |
---|
[3192] | 137 | } |
---|
| 138 | |
---|
[3193] | 139 | function drawTriangle($x1, $y1, $x2, $y2, $x3, $y3, $char) { |
---|
| 140 | caca_draw_triangle($this->cv, $x1, $y1, $x2, $y2, $x3, $y3, $char); |
---|
[3192] | 141 | } |
---|
| 142 | |
---|
[3193] | 143 | function drawThinTriangle($x1, $y1, $x2, $y2, $x3, $y3) { |
---|
| 144 | caca_draw_thin_triangle($this->cv, $x1, $y1, $x2, $y2, $x3, $y3); |
---|
[3192] | 145 | } |
---|
| 146 | |
---|
[3193] | 147 | function fillTriangle($x1, $y1, $x2, $y2, $x3, $y3, $char) { |
---|
| 148 | caca_fill_triangle($this->cv, $x1, $y1, $x2, $y2, $x3, $y3, $char); |
---|
[3192] | 149 | } |
---|
| 150 | |
---|
| 151 | function __construct($width = 0, $height = 0) { |
---|
[3195] | 152 | $this->cv = caca_create_canvas($width, $height); |
---|
[3192] | 153 | } |
---|
[3193] | 154 | |
---|
| 155 | function get_resource() { |
---|
| 156 | return $this->cv; |
---|
| 157 | } |
---|
[3192] | 158 | } |
---|
[3195] | 159 | |
---|
| 160 | class Display { |
---|
| 161 | private $dp; |
---|
| 162 | |
---|
| 163 | function setDisplayTime($time) { |
---|
| 164 | return caca_set_display_time($this->dp, $time); |
---|
| 165 | } |
---|
| 166 | |
---|
| 167 | function getDisplayTime() { |
---|
| 168 | return caca_get_display_time($this->dp); |
---|
| 169 | } |
---|
| 170 | |
---|
| 171 | function getWidth() { |
---|
| 172 | return caca_get_display_width($this->dp); |
---|
| 173 | } |
---|
| 174 | |
---|
| 175 | function getHeight() { |
---|
| 176 | return caca_get_display_height($this->dp); |
---|
| 177 | } |
---|
| 178 | |
---|
| 179 | function setTitle($title) { |
---|
| 180 | return caca_set_display_title($this->dp, $title); |
---|
| 181 | } |
---|
| 182 | |
---|
| 183 | function getMouseX() { |
---|
| 184 | return caca_get_mouse_x($this->dp); |
---|
| 185 | } |
---|
| 186 | |
---|
| 187 | function getMouseY() { |
---|
| 188 | return caca_get_mouse_y($this->dp); |
---|
| 189 | } |
---|
| 190 | |
---|
| 191 | function setMouse($state) { |
---|
| 192 | return caca_set_mouse($this->dp, $state); |
---|
| 193 | } |
---|
| 194 | |
---|
| 195 | function __construct($canvas) { |
---|
| 196 | $this->dp = caca_create_display($canvas->get_resource()); |
---|
| 197 | } |
---|
| 198 | |
---|
| 199 | function get_resource() { |
---|
| 200 | return $this->dp; |
---|
| 201 | } |
---|
| 202 | } |
---|
[3216] | 203 | |
---|
| 204 | class Dither { |
---|
| 205 | private $dt; |
---|
| 206 | private $img; |
---|
| 207 | |
---|
| 208 | function setPalette($colors) { |
---|
[3217] | 209 | return caca_set_dither_palette($this->dt, $colors); |
---|
[3216] | 210 | } |
---|
| 211 | |
---|
| 212 | function setBrightness($value) { |
---|
[3217] | 213 | return caca_set_dither_brightness($this->dt, $value); |
---|
[3216] | 214 | } |
---|
| 215 | |
---|
| 216 | function getBrightness() { |
---|
[3217] | 217 | return caca_get_dither_brightness($this->dt); |
---|
[3216] | 218 | } |
---|
| 219 | |
---|
| 220 | function setGamme($value) { |
---|
[3217] | 221 | return caca_set_dither_gamma($this->dt, $value); |
---|
[3216] | 222 | } |
---|
| 223 | |
---|
| 224 | function getGamma() { |
---|
[3217] | 225 | return caca_get_dither_gamma($this->dt); |
---|
[3216] | 226 | } |
---|
| 227 | |
---|
| 228 | function setContrast($value) { |
---|
[3217] | 229 | return caca_set_dither_contrast($this->dt, $value); |
---|
[3216] | 230 | } |
---|
| 231 | |
---|
| 232 | function getContrast() { |
---|
[3217] | 233 | return caca_get_dither_contrast($this->dt); |
---|
[3216] | 234 | } |
---|
| 235 | |
---|
| 236 | function setAntialias($value) { |
---|
[3217] | 237 | return caca_set_dither_antialias($this->dt, $value); |
---|
[3216] | 238 | } |
---|
| 239 | |
---|
| 240 | function getAntialiasList() { |
---|
[3217] | 241 | return caca_get_dither_antialias_list($this->dt); |
---|
[3216] | 242 | } |
---|
| 243 | |
---|
| 244 | function getAntialias() { |
---|
[3217] | 245 | return caca_get_dither_antialias($this->dt); |
---|
[3216] | 246 | } |
---|
| 247 | |
---|
| 248 | function setColor($color) { |
---|
[3217] | 249 | return caca_set_dither_color($this->dt, $color); |
---|
[3216] | 250 | } |
---|
| 251 | |
---|
| 252 | function getColorList() { |
---|
[3217] | 253 | return caca_get_dither_color_list($this->dt); |
---|
[3216] | 254 | } |
---|
| 255 | |
---|
| 256 | function getColor() { |
---|
[3217] | 257 | return caca_get_dither_color($this->dt); |
---|
[3216] | 258 | } |
---|
| 259 | |
---|
| 260 | function setCharset($value) { |
---|
[3217] | 261 | return caca_set_dither_charset($this->dt, $value); |
---|
[3216] | 262 | } |
---|
| 263 | |
---|
| 264 | function getCharsetList() { |
---|
[3217] | 265 | return caca_get_dither_charset_list($this->dt); |
---|
[3216] | 266 | } |
---|
| 267 | |
---|
| 268 | function getCharset() { |
---|
[3217] | 269 | return caca_get_dither_charset($this->dt); |
---|
[3216] | 270 | } |
---|
| 271 | |
---|
| 272 | function setAlgorithm($name) { |
---|
[3217] | 273 | return caca_set_dither_algorithm($this->dt, $name); |
---|
[3216] | 274 | } |
---|
| 275 | |
---|
| 276 | function getAlgorithmList() { |
---|
[3217] | 277 | return caca_get_dither_algorithm_list($this->dt); |
---|
[3216] | 278 | } |
---|
| 279 | |
---|
| 280 | function getAlgorithm() { |
---|
[3217] | 281 | return caca_get_dither_algorithm($this->dt); |
---|
[3216] | 282 | } |
---|
| 283 | |
---|
| 284 | function bitmap($canvas, $x, $y, $width, $height, $load_palette = true) { |
---|
[3217] | 285 | return caca_dither_bitmap($canvas, $x, $y, $width, $height, $this->dt, $this->img, $load_palette); |
---|
[3216] | 286 | } |
---|
| 287 | |
---|
| 288 | function __construct($image) { |
---|
| 289 | $this->dt = caca_create_dither($image); |
---|
| 290 | $this->img = $image; |
---|
| 291 | } |
---|
| 292 | } |
---|