| 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 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 | |
|---|
| 31 | function getAttr($x, $y) { |
|---|
| 32 | return caca_get_attr($this->cv, $x, $y); |
|---|
| 33 | } |
|---|
| 34 | |
|---|
| 35 | function setAttr($attr) { |
|---|
| 36 | return caca_set_attr($this->cv, $x, $y, $attr); |
|---|
| 37 | } |
|---|
| 38 | |
|---|
| 39 | function setColorANSI($foreground, $background) { |
|---|
| 40 | return caca_set_color_ansi($this->cv, $foreground, $background); |
|---|
| 41 | } |
|---|
| 42 | |
|---|
| 43 | function setColorARGB($foreground, $background) { |
|---|
| 44 | return caca_set_color_argb($this->cv, $foreground, $background); |
|---|
| 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 | |
|---|
| 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 ); |
|---|
| 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 | |
|---|
| 91 | function drawLine($x1, $y1, $x2, $y2, $char) { |
|---|
| 92 | return caca_draw_line($this->cv, $x1, $y1, $x2, $y2, $color); |
|---|
| 93 | } |
|---|
| 94 | |
|---|
| 95 | function drawPolyline($points, $char) { |
|---|
| 96 | return caca_draw_polyline($this->cv, $points, $char); |
|---|
| 97 | } |
|---|
| 98 | |
|---|
| 99 | function drawThinLine($x1, $y1, $x2, $y2) { |
|---|
| 100 | return caca_draw_thin_line($this->cv, $x1, $y1, $x2, $y2); |
|---|
| 101 | } |
|---|
| 102 | |
|---|
| 103 | function drawThinPolyline($points) { |
|---|
| 104 | return caca_draw_thin_polyline($this->cv, $points); |
|---|
| 105 | } |
|---|
| 106 | |
|---|
| 107 | function drawCircle($x, $y, $radius, $char) { |
|---|
| 108 | return caca_draw_circle($this->cv, $x, $y, $radius, $char); |
|---|
| 109 | } |
|---|
| 110 | |
|---|
| 111 | function drawEllipse($x1, $y1, $x2, $y2, $char) { |
|---|
| 112 | caca_draw_ellipse($this->cv, $x1, $y1, $x2, $y2, $char); |
|---|
| 113 | } |
|---|
| 114 | |
|---|
| 115 | function drawThinEllipse($x1, $y1, $x2, $y2) { |
|---|
| 116 | caca_draw_ellipse($this->cv, $x1, $y1, $x2, $y2); |
|---|
| 117 | } |
|---|
| 118 | |
|---|
| 119 | function fillEllipse($x1, $y1, $x2, $y2, $char) { |
|---|
| 120 | caca_fill_ellipse($this->cv, $x1, $y1, $x2, $y2, $char); |
|---|
| 121 | } |
|---|
| 122 | |
|---|
| 123 | function drawBox($x1, $y1, $x2, $y2, $char) { |
|---|
| 124 | caca_draw_box($this->cv, $x1, $y1, $x2, $y2, $char); |
|---|
| 125 | } |
|---|
| 126 | |
|---|
| 127 | function drawThinBox($x1, $y1, $x2, $y2) { |
|---|
| 128 | caca_draw_thin_box($this->cv, $x1, $y1, $x2, $y2); |
|---|
| 129 | } |
|---|
| 130 | |
|---|
| 131 | function drawCP437Box($x1, $y1, $x2, $y2) { |
|---|
| 132 | caca_draw_cp437_box($this->cv, $x1, $y1, $x2, $y2); |
|---|
| 133 | } |
|---|
| 134 | |
|---|
| 135 | function fillBox($x1, $y1, $x2, $y2, $char) { |
|---|
| 136 | caca_fill_box($this->cv, $x1, $y1, $x2, $y2, $char); |
|---|
| 137 | } |
|---|
| 138 | |
|---|
| 139 | function drawTriangle($x1, $y1, $x2, $y2, $x3, $y3, $char) { |
|---|
| 140 | caca_draw_triangle($this->cv, $x1, $y1, $x2, $y2, $x3, $y3, $char); |
|---|
| 141 | } |
|---|
| 142 | |
|---|
| 143 | function drawThinTriangle($x1, $y1, $x2, $y2, $x3, $y3) { |
|---|
| 144 | caca_draw_thin_triangle($this->cv, $x1, $y1, $x2, $y2, $x3, $y3); |
|---|
| 145 | } |
|---|
| 146 | |
|---|
| 147 | function fillTriangle($x1, $y1, $x2, $y2, $x3, $y3, $char) { |
|---|
| 148 | caca_fill_triangle($this->cv, $x1, $y1, $x2, $y2, $x3, $y3, $char); |
|---|
| 149 | } |
|---|
| 150 | |
|---|
| 151 | function __construct($width = 0, $height = 0) { |
|---|
| 152 | $this->cv = caca_create_canvas($width, $height); |
|---|
| 153 | } |
|---|
| 154 | |
|---|
| 155 | function get_resource() { |
|---|
| 156 | return $this->cv; |
|---|
| 157 | } |
|---|
| 158 | } |
|---|
| 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 | } |
|---|