[ Index ]
 

Code source de phpMyVisites 2.3

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/libs/artichow/php5/inc/ -> Shadow.class.php (source)

   1  <?php
   2  /*
   3   * This work is hereby released into the Public Domain.
   4   * To view a copy of the public domain dedication,
   5   * visit http://creativecommons.org/licenses/publicdomain/ or send a letter to
   6   * Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
   7   *
   8   */
   9   
  10  /* <php4> */
  11  
  12  define("SHADOW_LEFT_TOP", 1);
  13  define("SHADOW_LEFT_BOTTOM", 2);
  14  define("SHADOW_RIGHT_TOP", 3);
  15  define("SHADOW_RIGHT_BOTTOM", 4);
  16  
  17  define("SHADOW_IN", 1);
  18  define("SHADOW_OUT", 2);
  19  
  20  /* </php4> */
  21  
  22  /**
  23   * Draw shadows
  24   *
  25   */
  26  class awShadow {
  27  
  28      /**
  29       * Shadow on left and top sides
  30       *
  31       * @var int
  32       */
  33      const LEFT_TOP = 1;
  34  
  35      /**
  36       * Shadow on left and bottom sides
  37       *
  38       * @var int
  39       */
  40      const LEFT_BOTTOM = 2;
  41      
  42  
  43      /**
  44       * Shadow on right and top sides
  45       *
  46       * @var int
  47       */
  48      const RIGHT_TOP = 3;
  49  
  50      /**
  51       * Shadow on right and bottom sides
  52       *
  53       * @var int
  54       */
  55      const RIGHT_BOTTOM = 4;
  56      
  57      /**
  58       * In mode
  59       *
  60       * @var int
  61       */
  62      const IN = 1;
  63      
  64      /**
  65       * Out mode
  66       *
  67       * @var int
  68       */
  69      const OUT = 2;
  70  
  71      /**
  72       * Shadow size
  73       *
  74       * @var int
  75       */
  76      private $size = 0;
  77      
  78      /**
  79       * Hide shadow ?
  80       *
  81       * @var bool
  82       */
  83      protected $hide = FALSE;
  84  
  85      /**
  86       * Shadow color
  87       *
  88       * @var Color
  89       */
  90      private $color;
  91  
  92      /**
  93       * Shadow position
  94       *
  95       * @var int
  96       */
  97      private $position;
  98  
  99      /**
 100       * Smooth shadow ?
 101       *
 102       * @var bool
 103       */
 104      private $smooth = FALSE;
 105      
 106      /**
 107       * Shadow constructor
 108       *
 109       * @param int $position Shadow position
 110       */
 111  	public function __construct($position) {
 112          $this->setPosition($position);
 113      }
 114      
 115      /**
 116       * Hide shadow ?
 117       *
 118       * @param bool $hide
 119       */
 120  	public function hide($hide = TRUE) {
 121          $this->hide = (bool)$hide;
 122      }
 123      
 124      /**
 125       * Show shadow ?
 126       *
 127       * @param bool $show
 128       */
 129  	public function show($show = TRUE) {
 130          $this->hide = (bool)!$show;
 131      }
 132      
 133      /**
 134       * Change shadow size
 135       *
 136       * @param int $size
 137       * @param bool $smooth Smooth the shadow (facultative argument)
 138       */
 139  	public function setSize($size, $smooth = NULL) {
 140          $this->size = (int)$size;
 141          if($smooth !== NULL) {
 142              $this->smooth($smooth);
 143          }
 144      }
 145      
 146      /**
 147       * Change shadow color
 148       *
 149       * @param awColor $color
 150       */
 151  	public function setColor($color) {
 152          $this->color = $color;
 153      }
 154      
 155      /**
 156       * Change shadow position
 157       *
 158       * @param int $position
 159       */
 160  	public function setPosition($position) {
 161          $this->position = (int)$position;
 162      }
 163      
 164      /**
 165       * Smooth shadow ?
 166       *
 167       * @param bool $smooth
 168       */
 169  	public function smooth($smooth) {
 170          $this->smooth = (bool)$smooth;
 171      }
 172      
 173      /**
 174       * Get the space taken by the shadow
 175       *
 176       * @return Side
 177       */
 178  	public function getSpace() {
 179      
 180          return new awSide(
 181              ($this->position === awShadow::LEFT_TOP or $this->position === awShadow::LEFT_BOTTOM) ? $this->size : 0,
 182              ($this->position === awShadow::RIGHT_TOP or $this->position === awShadow::RIGHT_BOTTOM) ? $this->size : 0,
 183              ($this->position === awShadow::LEFT_TOP or $this->position === awShadow::RIGHT_TOP) ? $this->size : 0,
 184              ($this->position === awShadow::LEFT_BOTTOM or $this->position === awShadow::RIGHT_BOTTOM) ? $this->size : 0
 185          );
 186      
 187      }
 188      
 189      /**
 190       * Draw shadow
 191       *
 192       * @param awDrawer $drawer
 193       * @param awPoint $p1 Top-left point
 194       * @param awPoint $p2 Right-bottom point
 195       * @param int Drawing mode
 196       */
 197  	public function draw(awDrawer $drawer, awPoint $p1, awPoint $p2, $mode) {
 198      
 199          if($this->hide) {
 200              return;
 201          }
 202      
 203          if($this->size <= 0) {
 204              return;
 205          }
 206          
 207          $drawer = clone $drawer;
 208          
 209          $color = ($this->color instanceof awColor) ? $this->color : new awColor(125, 125, 125);
 210      
 211          switch($this->position) {
 212          
 213              case awShadow::RIGHT_BOTTOM :
 214              
 215                  if($mode === awShadow::OUT) {
 216                      $t1 = $p1->move(0, 0);
 217                      $t2 = $p2->move($this->size + 1, $this->size + 1);
 218                  } else { // PHP 4 compatibility
 219                      $t1 = $p1->move(0, 0);
 220                      $t2 = $p2->move(0, 0);
 221                  }
 222          
 223                  $width = $t2->x - $t1->x;
 224                  $height = $t2->y - $t1->y;
 225          
 226                  $drawer->setAbsPosition($t1->x + $drawer->x, $t1->y + $drawer->y);
 227              
 228                  $drawer->filledRectangle(
 229                      $color,
 230                      new awLine(
 231                          new awPoint($width - $this->size, $this->size),
 232                          new awPoint($width - 1, $height - 1)
 233                      )
 234                  );
 235              
 236                  $drawer->filledRectangle(
 237                      $color,
 238                      new awLine(
 239                          new awPoint($this->size, $height - $this->size),
 240                          new awPoint($width - $this->size - 1, $height - 1)
 241                      )
 242                  );
 243                  
 244                  $this->smoothPast($drawer, $color, $width, $height);
 245                  
 246                  break;
 247          
 248              case awShadow::LEFT_TOP :
 249              
 250                  if($mode === awShadow::OUT) {
 251                      $t1 = $p1->move(- $this->size, - $this->size);
 252                      $t2 = $p2->move(0, 0);
 253                  } else { // PHP 4 compatibility
 254                      $t1 = $p1->move(0, 0);
 255                      $t2 = $p2->move(0, 0);
 256                  }
 257          
 258                  $width = $t2->x - $t1->x;
 259                  $height = $t2->y - $t1->y;
 260          
 261                  $drawer->setAbsPosition($t1->x + $drawer->x, $t1->y + $drawer->y);
 262                  
 263                  $height = max($height + 1, $this->size);
 264              
 265                  $drawer->filledRectangle(
 266                      $color,
 267                      new awLine(
 268                          new awPoint(0, 0),
 269                          new awPoint($this->size - 1, $height - $this->size - 1)
 270                      )
 271                  );
 272              
 273                  $drawer->filledRectangle(
 274                      $color,
 275                      new awLine(
 276                          new awPoint($this->size, 0),
 277                          new awPoint($width - $this->size - 1, $this->size - 1)
 278                      )
 279                  );
 280                  
 281                  $this->smoothPast($drawer, $color, $width, $height);
 282                  
 283                  break;
 284          
 285              case awShadow::RIGHT_TOP :
 286              
 287                  if($mode === awShadow::OUT) {
 288                      $t1 = $p1->move(0, - $this->size);
 289                      $t2 = $p2->move($this->size + 1, 0);
 290                  } else { // PHP 4 compatibility
 291                      $t1 = $p1->move(0, 0);
 292                      $t2 = $p2->move(0, 0);
 293                  }
 294          
 295                  $width = $t2->x - $t1->x;
 296                  $height = $t2->y - $t1->y;
 297          
 298                  $drawer->setAbsPosition($t1->x + $drawer->x, $t1->y + $drawer->y);
 299                  
 300                  $height = max($height + 1, $this->size);
 301              
 302                  $drawer->filledRectangle(
 303                      $color,
 304                      new awLine(
 305                          new awPoint($width - $this->size, 0),
 306                          new awPoint($width - 1, $height - $this->size - 1)
 307                      )
 308                  );
 309              
 310                  $drawer->filledRectangle(
 311                      $color,
 312                      new awLine(
 313                          new awPoint($this->size, 0),
 314                          new awPoint($width - $this->size - 1, $this->size - 1)
 315                      )
 316                  );
 317                  
 318                  $this->smoothFuture($drawer, $color, $width, $height);
 319                  
 320                  break;
 321          
 322              case awShadow::LEFT_BOTTOM :
 323              
 324                  if($mode === awShadow::OUT) {
 325                      $t1 = $p1->move(- $this->size, 0);
 326                      $t2 = $p2->move(0, $this->size + 1);
 327                  } else { // PHP 4 compatibility
 328                      $t1 = $p1->move(0, 0);
 329                      $t2 = $p2->move(0, 0);
 330                  }
 331          
 332                  $width = $t2->x - $t1->x;
 333                  $height = $t2->y - $t1->y;
 334          
 335                  $drawer->setAbsPosition($t1->x + $drawer->x, $t1->y + $drawer->y);
 336              
 337                  $drawer->filledRectangle(
 338                      $color,
 339                      new awLine(
 340                          new awPoint(0, $this->size),
 341                          new awPoint($this->size - 1, $height - 1)
 342                      )
 343                  );
 344              
 345                  $drawer->filledRectangle(
 346                      $color,
 347                      new awLine(
 348                          new awPoint($this->size, $height - $this->size),
 349                          new awPoint($width - $this->size - 1, $height - 1)
 350                      )
 351                  );
 352                  
 353                  $this->smoothFuture($drawer, $color, $width, $height);
 354                  
 355                  break;
 356          
 357          }
 358      
 359      }
 360      
 361  	private function smoothPast(awDrawer $drawer, awColor $color, $width, $height) {
 362          
 363          if($this->smooth) {
 364          
 365              for($i = 0; $i < $this->size; $i++) {
 366                  for($j = 0; $j <= $i; $j++) {
 367                      $drawer->point(
 368                          $color,
 369                          new awPoint($i, $j + $height - $this->size)
 370                      );
 371                  }
 372              }
 373              
 374              for($i = 0; $i < $this->size; $i++) {
 375                  for($j = 0; $j <= $i; $j++) {
 376                      $drawer->point(
 377                          $color,
 378                          new awPoint($width - $this->size + $j, $i)
 379                      );
 380                  }
 381              }
 382              
 383          }
 384          
 385      }
 386      
 387  	private function smoothFuture(awDrawer $drawer, awColor $color, $width, $height) {
 388          
 389          if($this->smooth) {
 390          
 391              for($i = 0; $i < $this->size; $i++) {
 392                  for($j = 0; $j <= $i; $j++) {
 393                      $drawer->point(
 394                          $color,
 395                          new awPoint($i, $this->size - $j - 1)
 396                      );
 397                  }
 398              }
 399              
 400              for($i = 0; $i < $this->size; $i++) {
 401                  for($j = 0; $j <= $i; $j++) {
 402                      $drawer->point(
 403                          $color,
 404                          new awPoint($width - $this->size + $j, $height - $i - 1)
 405                      );
 406                  }
 407              }
 408              
 409          }
 410      }
 411  
 412  }
 413  
 414  registerClass('Shadow');
 415  ?>


Généré le : Mon Nov 26 14:10:01 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics