| @@ -4,7 +4,7 @@ | |||||
| * cacapig.php sample program for libcaca php binding | * cacapig.php sample program for libcaca php binding | ||||
| * Copyright (c) 2008 Nicolas Vion <nico@yojik.eu> | * Copyright (c) 2008 Nicolas Vion <nico@yojik.eu> | ||||
| * | * | ||||
| * This file is a Php port of "cxx/cpptest.cpp" | |||||
| * This file is a Php port of "cxx/cxxtest.cpp" | |||||
| * which is: | * which is: | ||||
| * Copyright (c) 2006 Jean-Yves Lamoureux <jylam@lnxscene.org> | * Copyright (c) 2006 Jean-Yves Lamoureux <jylam@lnxscene.org> | ||||
| * All Rights Reserved | * All Rights Reserved | ||||
| @@ -20,6 +20,8 @@ if (php_sapi_name() != "cli") { | |||||
| die("You have to run this program with php-cli!\n"); | die("You have to run this program with php-cli!\n"); | ||||
| } | } | ||||
| include dirname($argv[0]) . '/../caca.php'; | |||||
| $pig_str = <<<EOT | $pig_str = <<<EOT | ||||
| _._ _..._ .-', _.._(`)) | _._ _..._ .-', _.._(`)) | ||||
| @@ -37,51 +39,51 @@ $pig_str = <<<EOT | |||||
| /,_/ '`-' | /,_/ '`-' | ||||
| EOT; | EOT; | ||||
| $canvas = caca_create_canvas(0, 0); | |||||
| $canvas = new Canvas(); | |||||
| if (!$canvas) { | if (!$canvas) { | ||||
| die("Error while creating main canvas\n"); | die("Error while creating main canvas\n"); | ||||
| } | } | ||||
| $pig = caca_create_canvas(0, 0); | |||||
| $pig = new Canvas(); | |||||
| if (!$pig) { | if (!$pig) { | ||||
| die("Error while creating canvas pig\n"); | die("Error while creating canvas pig\n"); | ||||
| } | } | ||||
| $display = caca_create_display($canvas); | |||||
| $display = new Display($canvas); | |||||
| if (!$display) { | if (!$display) { | ||||
| die("Error while attaching canvas to display\n"); | die("Error while attaching canvas to display\n"); | ||||
| } | } | ||||
| caca_set_color_ansi($pig, CACA_LIGHTMAGENTA, CACA_TRANSPARENT); | |||||
| caca_set_color_ansi($canvas, CACA_LIGHTBLUE, CACA_TRANSPARENT); | |||||
| caca_import_string($pig, $pig_str, "text"); | |||||
| caca_set_display_time($display, 30000); | |||||
| $pig->setColorANSI(AnsiColor::LIGHTMAGENTA, AnsiColor::TRANSPARENT); | |||||
| $pig->importString($pig_str, "text"); | |||||
| $display->setDisplayTime(20000); | |||||
| $x = $y = 0; | $x = $y = 0; | ||||
| $ix = $iy = 1; | $ix = $iy = 1; | ||||
| while (!caca_get_event($display, CACA_EVENT_KEY_PRESS)) { | |||||
| while (! $display->getEvent(EventType::KEY_PRESS)) { | |||||
| // In case of resize ... | // 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; | $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; | $y = 0; | ||||
| caca_clear_canvas($canvas); | |||||
| $canvas->Clear(); | |||||
| // Draw | // 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 | // Move cursor | ||||
| $x += $ix; | $x += $ix; | ||||
| $y += $iy; | $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; | $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; | $iy = -$iy; | ||||
| } | } | ||||