Changeset 3296 for libcaca/trunk


Ignore:
Timestamp:
Nov 6, 2008, 8:16:59 AM (11 years ago)
Author:
bsittler
Message:

convert to use PHP object layer similar to the C++ one used in its C++ predecessor, cxx/cxxtest.cpp; also change behavior and appearance to more closely match that version (perhaps, though, the changes should have been ported in the other direction instead...)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libcaca/trunk/caca-php/examples/cacapig.php

    r3268 r3296  
    55 *  Copyright (c) 2008 Nicolas Vion <nico@yojik.eu>
    66 *
    7  *  This file is a Php port of "cxx/cpptest.cpp"
     7 *  This file is a Php port of "cxx/cxxtest.cpp"
    88 *  which is:
    99 *  Copyright (c) 2006 Jean-Yves Lamoureux <jylam@lnxscene.org>
     
    2020        die("You have to run this program with php-cli!\n");
    2121}
     22
     23include dirname($argv[0]) . '/../caca.php';
    2224
    2325$pig_str = <<<EOT
     
    3840EOT;
    3941
    40 $canvas = caca_create_canvas(0, 0);
     42$canvas = new Canvas();
    4143if (!$canvas) {
    4244        die("Error while creating main canvas\n");
    4345}
    4446
    45 $pig = caca_create_canvas(0, 0);
     47$pig = new Canvas();
    4648if (!$pig) {
    4749        die("Error while creating canvas pig\n");
    4850}
    4951
    50 $display = caca_create_display($canvas);
     52$display = new Display($canvas);
    5153if (!$display) {
    5254        die("Error while attaching canvas to display\n");
     
    5456
    5557
    56 caca_set_color_ansi($pig, CACA_LIGHTMAGENTA, CACA_TRANSPARENT);
    57 caca_set_color_ansi($canvas, CACA_LIGHTBLUE, CACA_TRANSPARENT);
    58 caca_import_string($pig, $pig_str, "text");
    59 caca_set_display_time($display, 30000);
     58$pig->setColorANSI(AnsiColor::LIGHTMAGENTA, AnsiColor::TRANSPARENT);
     59$pig->importString($pig_str, "text");
     60$display->setDisplayTime(20000);
    6061
    6162$x = $y = 0;
    6263$ix = $iy = 1;
    6364
    64 while (!caca_get_event($display, CACA_EVENT_KEY_PRESS)) {
     65while (! $display->getEvent(EventType::KEY_PRESS)) {
    6566        // In case of resize ...
    66         if ($x + caca_get_canvas_width($pig) - 1 >= caca_get_canvas_width($canvas) || $x < 0 )
     67        if ($x + $pig->getWidth() - 1 >= $canvas->getWidth() || $x < 0 )
    6768                $x = 0;
    68         if ($y + caca_get_canvas_height($pig) - 1 >= caca_get_canvas_height($canvas) || $y < 0 )
     69        if ($y + $pig->getHeight() - 1 >= $canvas->getHeight() || $y < 0 )
    6970                $y = 0;
    7071
    71         caca_clear_canvas($canvas);
     72        $canvas->Clear();
    7273
    7374        // Draw
    74         caca_blit($canvas, $x, $y, $pig);
    75         caca_put_str($canvas, caca_get_canvas_width($canvas) / 2 - 10, caca_get_canvas_height($canvas) / 2, "Powered by libcaca ".caca_get_version());
    76         caca_refresh_display($display);
     75        $canvas->Blit($x, $y, $pig, NULL);
     76        $canvas->setColorANSI(AnsiColor::LIGHTBLUE, AnsiColor::BLACK);
     77        $canvas->putStr($canvas->getWidth() / 2 - 10, $canvas->getHeight() / 2, "Powered by libcaca ".Libcaca::getVersion());
     78        $display->refresh();
    7779
    7880
     
    8082        $x += $ix;
    8183        $y += $iy;
    82         if ($x + caca_get_canvas_width($pig) >= caca_get_canvas_width($canvas) || $x < 0 )
     84        if ($x + $pig->getWidth() >= $canvas->getWidth() || $x < 0 )
    8385                $ix = -$ix;
    84         if ($y + caca_get_canvas_height($pig) >= caca_get_canvas_height($canvas) || $y < 0 )
     86        if ($y + $pig->getHeight() >= $canvas->getHeight() || $y < 0 )
    8587                $iy = -$iy;
    8688}
Note: See TracChangeset for help on using the changeset viewer.