Parcourir la source

add a Libcaca class to the PHP class interface, parallel to the Libcaca class in the .NET interface; fix a bunch of whitespace inconsistencies

tags/v0.99.beta17
Ben Wiley Sittler bsittler il y a 16 ans
Parent
révision
0b32c1d6eb
2 fichiers modifiés avec 56 ajouts et 43 suppressions
  1. +50
    -37
      caca-php/caca.php
  2. +6
    -6
      caca-php/examples/test.php

+ 50
- 37
caca-php/caca.php Voir le fichier

@@ -12,6 +12,19 @@
* http://sam.zoy.org/wtfpl/COPYING for more details.
*/

class Libcaca
{
static function Rand($min, $max)
{
return caca_rand($min, $max);
}

static function getVersion()
{
return caca_get_version();
}
}

class AnsiColor
{
const BLACK = CACA_BLACK;
@@ -80,15 +93,15 @@ class Canvas {
}

function putAttr($attr) {
return caca_put_attr($this->cv, $attr);
return caca_put_attr($this->cv, $attr);
}

function stretchRight() {
return caca_stretch_right($this->cv);
return caca_stretch_right($this->cv);
}

function stretchLeft() {
return caca_stretch_left($this->cv);
return caca_stretch_left($this->cv);
}

function setBoundaries($width, $height) {
@@ -100,27 +113,27 @@ class Canvas {
}

function getHandleX() {
return caca_get_canvas_handle_x($this->cv);
return caca_get_canvas_handle_x($this->cv);
}

function getHandleY() {
return caca_get_canvas_handle_y($this->cv);
return caca_get_canvas_handle_y($this->cv);
}

function getCursorX() {
return caca_get_cursor_x($this->cv);
return caca_get_cursor_x($this->cv);
}

function getCursorY() {
return caca_get_cursor_y($this->cv);
return caca_get_cursor_y($this->cv);
}

function getChars() {
return caca_get_canvas_chars($this->cv);
return caca_get_canvas_chars($this->cv);
}

function getAttrs() {
return caca_get_canvas_attrs($this->cv);
return caca_get_canvas_attrs($this->cv);
}

function setSize($width, $height) {
@@ -134,7 +147,7 @@ class Canvas {
function getHeight() {
return caca_get_canvas_height($this->cv);
}
function getAttr($x, $y) {
return caca_get_attr($this->cv, $x, $y);
}
@@ -216,15 +229,15 @@ class Canvas {
}

function drawEllipse($x1, $y1, $x2, $y2, $char) {
return caca_draw_ellipse($this->cv, $x1, $y1, $x2, $y2, $char);
return caca_draw_ellipse($this->cv, $x1, $y1, $x2, $y2, $char);
}

function drawThinEllipse($x1, $y1, $x2, $y2) {
return caca_draw_thin_ellipse($this->cv, $x1, $y1, $x2, $y2);
return caca_draw_thin_ellipse($this->cv, $x1, $y1, $x2, $y2);
}

function fillEllipse($x1, $y1, $x2, $y2, $char) {
return caca_fill_ellipse($this->cv, $x1, $y1, $x2, $y2, $char);
return caca_fill_ellipse($this->cv, $x1, $y1, $x2, $y2, $char);
}

function drawBox($x1, $y1, $x2, $y2, $char) {
@@ -258,7 +271,7 @@ class Canvas {
function __construct($width = 0, $height = 0) {
$this->cv = caca_create_canvas($width, $height);
}
function get_resource() {
return $this->cv;
}
@@ -278,7 +291,7 @@ class EventType

const ANY = CACA_EVENT_ANY;
}
class EventKey
{
const UNKNOWN = CACA_KEY_UNKNOWN;
@@ -368,7 +381,7 @@ class Event {
function __construct($_ev) {
$this->ev = $_ev;
}
function get_resource() {
return $this->ev;
}
@@ -442,7 +455,7 @@ class Display {
$this->dp = caca_create_display_with_driver($canvas->get_resource(), $driver);
else
$this->dp = caca_create_display($canvas->get_resource());
}
}

function get_resource() {
return $this->dp;
@@ -464,71 +477,71 @@ class Dither {
function getBrightness() {
return caca_get_dither_brightness($this->dt);
}
function setGamme($value) {
return caca_set_dither_gamma($this->dt, $value);
}
function getGamma() {
return caca_get_dither_gamma($this->dt);
}
function setContrast($value) {
return caca_set_dither_contrast($this->dt, $value);
}
function getContrast() {
return caca_get_dither_contrast($this->dt);
}
function setAntialias($value) {
return caca_set_dither_antialias($this->dt, $value);
}
function getAntialiasList() {
return caca_get_dither_antialias_list($this->dt);
}
function getAntialias() {
return caca_get_dither_antialias($this->dt);
}
function setColor($color) {
return caca_set_dither_color($this->dt, $color);
}
function getColorList() {
return caca_get_dither_color_list($this->dt);
}
function getColor() {
return caca_get_dither_color($this->dt);
}
function setCharset($value) {
return caca_set_dither_charset($this->dt, $value);
}
function getCharsetList() {
return caca_get_dither_charset_list($this->dt);
}
function getCharset() {
return caca_get_dither_charset($this->dt);
}
function setAlgorithm($name) {
return caca_set_dither_algorithm($this->dt, $name);
}
function getAlgorithmList() {
return caca_get_dither_algorithm_list($this->dt);
}
function getAlgorithm() {
return caca_get_dither_algorithm($this->dt);
}
function bitmap($canvas, $x, $y, $width, $height, $load_palette = true) {
return caca_dither_bitmap($canvas->get_resource(), $x, $y, $width, $height, $this->dt, $this->img, $load_palette);
}
@@ -536,12 +549,12 @@ class Dither {
function __construct($image) {
$this->dt = caca_create_dither($image);
$this->img = $image;
}
}
}

class Font {
private $f;
function getWidth() {
return caca_get_font_width($this->f);
}
@@ -564,5 +577,5 @@ class Font {

function __construct($name) {
$this->f = caca_load_builtin_font($name);
}
}
}

+ 6
- 6
caca-php/examples/test.php Voir le fichier

@@ -5,7 +5,7 @@
* Copyright (c) 2008 Benjamin C. Wiley Sittler <bsittler@gmail.com>
*
* This file is a Php port of "caca-sharp/test.cs"
* which is:
* which is:
* Copyright (c) 2006 Jean-Yves Lamoureux <jylam@lnxscene.org>
* 2007 Sam Hocevar <sam@zoy.org>
* All Rights Reserved
@@ -68,7 +68,7 @@ class DemoCanvas extends Canvas
for($i = 0; $i < $barCount; $i++)
{
$v = ((sin(($t / 500.0)
+ (1.0 * $i / $barCount)) + 1) / 2) * $this->getHeight();
+ (1.0 * $i / $barCount)) + 1) / 2) * $this->getHeight();
$p1_x = 0; $p1_y = intval($v);
$p2_x = $this->getWidth() - 1; $p2_y = intval($v);

@@ -87,7 +87,7 @@ class DemoCanvas extends Canvas
$y = intval($h * (2.0 + sin($t / 200.0)) / 4);
$this->d->bitmap($this, - $x, $h / 2 - $y, $w * 12, $y * 2);
$this->d->bitmap($this, 12 * $w - $x, $h / 2 - $y, $w * 12, $y * 2);
$this->setColorAnsi(AnsiColor::WHITE, AnsiColor::BLUE);
$this->putStr($this->getWidth() - 30, $this->getHeight() - 2, " -=[ Powered by libcaca ]=- ");
$this->setColorAnsi(AnsiColor::WHITE, AnsiColor::BLACK);
@@ -126,7 +126,7 @@ class Test
{
static function Main()
{
printf("libcaca %s PHP test\n", caca_get_version());
printf("libcaca %s PHP test\n", Libcaca::getVersion());
printf("(c) 2006 Jean-Yves Lamoureux <jylam@lnxscene.org>\n");
printf("(c) 2007 Sam Hocevar <sam@zoy.org>\n");
printf("(c) 2008 Benjamin C. Wiley Sittler <bsittler@gmail.com>\n");
@@ -138,8 +138,8 @@ class Test
$dp = new DemoDisplay($cv);

/* Random number. This is a static method,
not to be used with previous instance */
printf("A random number: %d\n", caca_rand(0, 1337));
not to be used with previous instance */
printf("A random number: %d\n", Libcaca::Rand(0, 1337));

$dp->EventLoop();
}


Chargement…
Annuler
Enregistrer