diff --git a/caca-php/examples/cacapig.php b/caca-php/examples/cacapig.php index 0ea30b6..c6d0713 100755 --- a/caca-php/examples/cacapig.php +++ b/caca-php/examples/cacapig.php @@ -4,7 +4,7 @@ * cacapig.php sample program for libcaca php binding * Copyright (c) 2008 Nicolas Vion * - * This file is a Php port of "cxx/cpptest.cpp" + * This file is a Php port of "cxx/cxxtest.cpp" * which is: * Copyright (c) 2006 Jean-Yves Lamoureux * All Rights Reserved @@ -20,6 +20,8 @@ if (php_sapi_name() != "cli") { die("You have to run this program with php-cli!\n"); } +include dirname($argv[0]) . '/../caca.php'; + $pig_str = <<setColorANSI(AnsiColor::LIGHTMAGENTA, AnsiColor::TRANSPARENT); +$pig->importString($pig_str, "text"); +$display->setDisplayTime(20000); $x = $y = 0; $ix = $iy = 1; -while (!caca_get_event($display, CACA_EVENT_KEY_PRESS)) { +while (! $display->getEvent(EventType::KEY_PRESS)) { // In case of resize ... - if ($x + caca_get_canvas_width($pig) - 1 >= caca_get_canvas_width($canvas) || $x < 0 ) + if ($x + $pig->getWidth() - 1 >= $canvas->getWidth() || $x < 0 ) $x = 0; - if ($y + caca_get_canvas_height($pig) - 1 >= caca_get_canvas_height($canvas) || $y < 0 ) + if ($y + $pig->getHeight() - 1 >= $canvas->getHeight() || $y < 0 ) $y = 0; - caca_clear_canvas($canvas); + $canvas->Clear(); // Draw - caca_blit($canvas, $x, $y, $pig); - caca_put_str($canvas, caca_get_canvas_width($canvas) / 2 - 10, caca_get_canvas_height($canvas) / 2, "Powered by libcaca ".caca_get_version()); - caca_refresh_display($display); + $canvas->Blit($x, $y, $pig, NULL); + $canvas->setColorANSI(AnsiColor::LIGHTBLUE, AnsiColor::BLACK); + $canvas->putStr($canvas->getWidth() / 2 - 10, $canvas->getHeight() / 2, "Powered by libcaca ".Libcaca::getVersion()); + $display->refresh(); // Move cursor $x += $ix; $y += $iy; - if ($x + caca_get_canvas_width($pig) >= caca_get_canvas_width($canvas) || $x < 0 ) + if ($x + $pig->getWidth() >= $canvas->getWidth() || $x < 0 ) $ix = -$ix; - if ($y + caca_get_canvas_height($pig) >= caca_get_canvas_height($canvas) || $y < 0 ) + if ($y + $pig->getHeight() >= $canvas->getHeight() || $y < 0 ) $iy = -$iy; }