Ignore:
Timestamp:
Feb 8, 2010, 2:27:22 AM (10 years ago)
Author:
Sam Hocevar
Message:

Large source code cleanup, getting rid of spaces, tabs, and svn keywords.

File:
1 edited

Legend:

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

    r4148 r4333  
    1111   *                All Rights Reserved
    1212   *
    13    *  $Id$
    14    *
    1513   *  This program is free software. It comes without any warranty, to
    1614   *  the extent permitted by applicable law. You can redistribute it
     
    2119
    2220if (php_sapi_name() != "cli") {
    23         die("You have to run this program with php-cli!\n");
     21    die("You have to run this program with php-cli!\n");
    2422}
    2523
     
    2826class DemoCanvas extends Canvas
    2927{
    30         private $image;
     28    private $image;
    3129
    32         private $startTime;
    33         private $d;
    34         private $scroll;
     30    private $startTime;
     31    private $d;
     32    private $scroll;
    3533
    36         function __construct()
    37         {
    38                 parent::__construct();
    39                 $this->startTime = gettimeofday(true);
     34    function __construct()
     35    {
     36        parent::__construct();
     37        $this->startTime = gettimeofday(true);
    4038
    41                 $message = " --- POWERED BY LIBCACA --- OLDSCHOOL TEXT EFFECTS ARE 100% PURE WIN";
     39        $message = " --- POWERED BY LIBCACA --- OLDSCHOOL TEXT EFFECTS ARE 100% PURE WIN";
    4240
    43                 $this->scroll = new Canvas(strlen($message), 1);
    44                 $this->scroll->setColorAnsi(AnsiColor::WHITE, AnsiColor::TRANSPARENT);
    45                 $this->scroll->putStr(0, 0, $message);
     41        $this->scroll = new Canvas(strlen($message), 1);
     42        $this->scroll->setColorAnsi(AnsiColor::WHITE, AnsiColor::TRANSPARENT);
     43        $this->scroll->putStr(0, 0, $message);
    4644
    47                 $fontList = Font::getList();
    48                 $f = new Font($fontList[1]);
    49                 $w = $f->getWidth() * strlen($message);
    50                 $h = $f->getHeight();
    51                 $this->image = imagecreatetruecolor($w, $h);
    52                 imagealphablending($this->image, false);
    53                 imagesavealpha($this->image, true);
    54                 $this->d = new Dither($this->image);
    55                 $f->Render($this->scroll, $this->image);
    56         }
     45        $fontList = Font::getList();
     46        $f = new Font($fontList[1]);
     47        $w = $f->getWidth() * strlen($message);
     48        $h = $f->getHeight();
     49        $this->image = imagecreatetruecolor($w, $h);
     50        imagealphablending($this->image, false);
     51        imagesavealpha($this->image, true);
     52        $this->d = new Dither($this->image);
     53        $f->Render($this->scroll, $this->image);
     54    }
    5755
    58         function Draw()
    59         {
    60                 $barCount = 6;
    61                 $t = (gettimeofday(true) - $this->startTime) * 1000;
     56    function Draw()
     57    {
     58        $barCount = 6;
     59        $t = (gettimeofday(true) - $this->startTime) * 1000;
    6260
    63                 $this->Clear();
     61        $this->Clear();
    6462
    65                 $this->setColorAnsi(AnsiColor::WHITE, AnsiColor::BLACK);
    66                 for($i = 0; $i < $barCount; $i++)
    67                 {
    68                         $v = ((sin(($t / 500.0)
    69                                            + (1.0 * $i / $barCount)) + 1) / 2) * $this->getHeight();
    70                         $p1_x = 0; $p1_y = intval($v);
    71                         $p2_x = $this->getWidth() - 1; $p2_y = intval($v);
     63        $this->setColorAnsi(AnsiColor::WHITE, AnsiColor::BLACK);
     64        for($i = 0; $i < $barCount; $i++)
     65        {
     66            $v = ((sin(($t / 500.0)
     67                       + (1.0 * $i / $barCount)) + 1) / 2) * $this->getHeight();
     68            $p1_x = 0; $p1_y = intval($v);
     69            $p2_x = $this->getWidth() - 1; $p2_y = intval($v);
    7270
    73                         $this->setColorAnsi(($i + 9), AnsiColor::BLACK);
    74                         /* drawLine is already clipped, we don't care about overflows */
    75                         $this->drawLine($p1_x + 0, $p1_y - 2, $p2_x + 0, $p2_y - 2, ord('-'));
    76                         $this->drawLine($p1_x + 0, $p1_y - 1, $p2_x + 0, $p2_y - 1, ord('*'));
    77                         $this->drawLine($p1_x,     $p1_y,     $p2_x,     $p2_y,     ord('#'));
    78                         $this->drawLine($p1_x + 0, $p1_y + 1, $p2_x + 0, $p2_y + 1, ord('*'));
    79                         $this->drawLine($p1_x + 0, $p1_y + 2, $p2_x + 0, $p2_y + 2, ord('-'));
    80                 }
     71            $this->setColorAnsi(($i + 9), AnsiColor::BLACK);
     72            /* drawLine is already clipped, we don't care about overflows */
     73            $this->drawLine($p1_x + 0, $p1_y - 2, $p2_x + 0, $p2_y - 2, ord('-'));
     74            $this->drawLine($p1_x + 0, $p1_y - 1, $p2_x + 0, $p2_y - 1, ord('*'));
     75            $this->drawLine($p1_x,     $p1_y,     $p2_x,     $p2_y,     ord('#'));
     76            $this->drawLine($p1_x + 0, $p1_y + 1, $p2_x + 0, $p2_y + 1, ord('*'));
     77            $this->drawLine($p1_x + 0, $p1_y + 2, $p2_x + 0, $p2_y + 2, ord('-'));
     78        }
    8179
    82                 $w = $this->getWidth();
    83                 $h = $this->getHeight();
    84                 $x = intval(($t / 10) % (12 * $w));
    85                 $y = intval($h * (2.0 + sin($t / 200.0)) / 4);
    86                 $this->d->bitmap($this, - $x, $h / 2 - $y, $w * 12, $y * 2);
    87                 $this->d->bitmap($this, 12 * $w - $x, $h / 2 - $y, $w * 12, $y * 2);
     80        $w = $this->getWidth();
     81        $h = $this->getHeight();
     82        $x = intval(($t / 10) % (12 * $w));
     83        $y = intval($h * (2.0 + sin($t / 200.0)) / 4);
     84        $this->d->bitmap($this, - $x, $h / 2 - $y, $w * 12, $y * 2);
     85        $this->d->bitmap($this, 12 * $w - $x, $h / 2 - $y, $w * 12, $y * 2);
    8886
    89                 $this->setColorAnsi(AnsiColor::WHITE, AnsiColor::BLUE);
    90                 $this->putStr($this->getWidth() - 30, $this->getHeight() - 2, " -=[ Powered by libcaca ]=- ");
    91                 $this->setColorAnsi(AnsiColor::WHITE, AnsiColor::BLACK);
    92         }
     87        $this->setColorAnsi(AnsiColor::WHITE, AnsiColor::BLUE);
     88        $this->putStr($this->getWidth() - 30, $this->getHeight() - 2, " -=[ Powered by libcaca ]=- ");
     89        $this->setColorAnsi(AnsiColor::WHITE, AnsiColor::BLACK);
     90    }
    9391}
    9492
    9593class DemoDisplay extends Display
    9694{
    97         private $cv;
     95    private $cv;
    9896
    99         function __construct(DemoCanvas $_cv)
    100         {
    101                 parent::__construct($_cv);
    102                 $this->setTitle("libcaca PHP Bindings test suite");
    103                 $this->setDisplayTime(20000); // Refresh every 20 ms
    104                 $this->cv = $_cv;
    105         }
     97    function __construct(DemoCanvas $_cv)
     98    {
     99        parent::__construct($_cv);
     100        $this->setTitle("libcaca PHP Bindings test suite");
     101        $this->setDisplayTime(20000); // Refresh every 20 ms
     102        $this->cv = $_cv;
     103    }
    106104
    107         function EventLoop()
    108         {
    109                 while(! ($ev = $this->getEvent(EventType::KEY_RELEASE, 10)))
    110                 {
    111                         $this->cv->Draw();
     105    function EventLoop()
     106    {
     107        while(! ($ev = $this->getEvent(EventType::KEY_RELEASE, 10)))
     108        {
     109            $this->cv->Draw();
    112110
    113                         $this->Refresh();
    114                 }
     111            $this->Refresh();
     112        }
    115113
    116                 if($ev->getKeyCh() > 0x20 && $ev->getKeyCh() < 0x7f)
    117                         printf("Key pressed: %c\n", $ev->getKeyCh());
    118                 else
    119                         printf("Key pressed: 0x%x\n", $ev->getKeyCh());
    120         }
     114        if($ev->getKeyCh() > 0x20 && $ev->getKeyCh() < 0x7f)
     115            printf("Key pressed: %c\n", $ev->getKeyCh());
     116        else
     117            printf("Key pressed: 0x%x\n", $ev->getKeyCh());
     118    }
    121119}
    122120
    123121class Test
    124122{
    125         static function Main()
    126         {
    127                 printf("libcaca %s PHP test\n", Libcaca::getVersion());
    128                 printf("(c) 2006 Jean-Yves Lamoureux <jylam@lnxscene.org>\n");
    129                 printf("(c) 2007 Sam Hocevar <sam@hocevar.net>\n");
    130                 printf("(c) 2008 Benjamin C. Wiley Sittler <bsittler@gmail.com>\n");
     123    static function Main()
     124    {
     125        printf("libcaca %s PHP test\n", Libcaca::getVersion());
     126        printf("(c) 2006 Jean-Yves Lamoureux <jylam@lnxscene.org>\n");
     127        printf("(c) 2007 Sam Hocevar <sam@hocevar.net>\n");
     128        printf("(c) 2008 Benjamin C. Wiley Sittler <bsittler@gmail.com>\n");
    131129
    132                 /* Instanciate a caca canvas */
    133                 $cv = new DemoCanvas();
     130        /* Instanciate a caca canvas */
     131        $cv = new DemoCanvas();
    134132
    135                 /* We have a proper canvas, let's display it using Caca */
    136                 $dp = new DemoDisplay($cv);
     133        /* We have a proper canvas, let's display it using Caca */
     134        $dp = new DemoDisplay($cv);
    137135
    138                 /* Random number. This is a static method,
    139                 not to be used with previous instance */
    140                 printf("A random number: %d\n", Libcaca::Rand(0, 1337));
     136        /* Random number. This is a static method,
     137        not to be used with previous instance */
     138        printf("A random number: %d\n", Libcaca::Rand(0, 1337));
    141139
    142                 $dp->EventLoop();
    143         }
     140        $dp->EventLoop();
     141    }
    144142}
    145143
Note: See TracChangeset for help on using the changeset viewer.