Selaa lähdekoodia

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 17 vuotta sitten
vanhempi
commit
0b32c1d6eb
2 muutettua tiedostoa jossa 56 lisäystä ja 43 poistoa
  1. +50
    -37
      caca-php/caca.php
  2. +6
    -6
      caca-php/examples/test.php

+ 50
- 37
caca-php/caca.php Näytä tiedosto

@@ -12,6 +12,19 @@
* http://sam.zoy.org/wtfpl/COPYING for more details. * 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 class AnsiColor
{ {
const BLACK = CACA_BLACK; const BLACK = CACA_BLACK;
@@ -80,15 +93,15 @@ class Canvas {
} }


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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

+ 6
- 6
caca-php/examples/test.php Näytä tiedosto

@@ -5,7 +5,7 @@
* Copyright (c) 2008 Benjamin C. Wiley Sittler <bsittler@gmail.com> * Copyright (c) 2008 Benjamin C. Wiley Sittler <bsittler@gmail.com>
* *
* This file is a Php port of "caca-sharp/test.cs" * This file is a Php port of "caca-sharp/test.cs"
* which is:
* which is:
* Copyright (c) 2006 Jean-Yves Lamoureux <jylam@lnxscene.org> * Copyright (c) 2006 Jean-Yves Lamoureux <jylam@lnxscene.org>
* 2007 Sam Hocevar <sam@zoy.org> * 2007 Sam Hocevar <sam@zoy.org>
* All Rights Reserved * All Rights Reserved
@@ -68,7 +68,7 @@ class DemoCanvas extends Canvas
for($i = 0; $i < $barCount; $i++) for($i = 0; $i < $barCount; $i++)
{ {
$v = ((sin(($t / 500.0) $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); $p1_x = 0; $p1_y = intval($v);
$p2_x = $this->getWidth() - 1; $p2_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); $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, - $x, $h / 2 - $y, $w * 12, $y * 2);
$this->d->bitmap($this, 12 * $w - $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->setColorAnsi(AnsiColor::WHITE, AnsiColor::BLUE);
$this->putStr($this->getWidth() - 30, $this->getHeight() - 2, " -=[ Powered by libcaca ]=- "); $this->putStr($this->getWidth() - 30, $this->getHeight() - 2, " -=[ Powered by libcaca ]=- ");
$this->setColorAnsi(AnsiColor::WHITE, AnsiColor::BLACK); $this->setColorAnsi(AnsiColor::WHITE, AnsiColor::BLACK);
@@ -126,7 +126,7 @@ class Test
{ {
static function Main() 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) 2006 Jean-Yves Lamoureux <jylam@lnxscene.org>\n");
printf("(c) 2007 Sam Hocevar <sam@zoy.org>\n"); printf("(c) 2007 Sam Hocevar <sam@zoy.org>\n");
printf("(c) 2008 Benjamin C. Wiley Sittler <bsittler@gmail.com>\n"); printf("(c) 2008 Benjamin C. Wiley Sittler <bsittler@gmail.com>\n");
@@ -138,8 +138,8 @@ class Test
$dp = new DemoDisplay($cv); $dp = new DemoDisplay($cv);


/* Random number. This is a static method, /* 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(); $dp->EventLoop();
} }


Ladataan…
Peruuta
Tallenna