linea21-externals
[ class tree: linea21-externals ] [ index: linea21-externals ] [ all elements ]

Source for file Shadow.class.php

Documentation is available at Shadow.class.php

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

Documentation generated on Thu, 03 May 2012 15:07:37 +0200 by phpDocumentor 1.4.1