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

Source for file Border.class.php

Documentation is available at Border.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. require_once dirname(__FILE__)."/../Graph.class.php";
  11.  
  12. /**
  13.  * Draw border
  14.  *
  15.  * @package linea21.externals
  16.  * @subpackage artichow
  17.  */
  18. class awBorder {
  19.  
  20.     /**
  21.      * Border color
  22.      *
  23.      * @var Color 
  24.      */
  25.     protected $color;
  26.  
  27.     /**
  28.      * Hide border ?
  29.      *
  30.      * @var bool 
  31.      */
  32.     protected $hide = FALSE;
  33.  
  34.     /**
  35.      * Border line style
  36.      *
  37.      * @var int 
  38.      */
  39.     protected $style;
  40.     
  41.     /**
  42.      * Build the border
  43.      *
  44.      * @param awColor $color Border color
  45.      * @param int $style Border style
  46.      */
  47.     public function __construct($color NULL$style awLine::SOLID{
  48.     
  49.         $this->setStyle($style);
  50.         
  51.         if($color instanceof awColor{
  52.             $this->setColor($color);
  53.         else {
  54.             $this->setColor(new awBlack);
  55.         }
  56.         
  57.     }
  58.     
  59.     /**
  60.      * Change border color
  61.      * This method automatically shows the border if it is hidden
  62.      *
  63.      * @param awColor $color 
  64.      */
  65.     public function setColor(awColor $color{
  66.         $this->color = $color;
  67.         $this->show();
  68.     }
  69.     
  70.     /**
  71.      * Change border style
  72.      *
  73.      * @param int $style 
  74.      */
  75.     public function setStyle($style{
  76.         $this->style = (int)$style;
  77.     }
  78.     
  79.     /**
  80.      * Hide border ?
  81.      *
  82.      * @param bool $hide 
  83.      */
  84.     public function hide($hide TRUE{
  85.         $this->hide = (bool)$hide;
  86.     }
  87.     
  88.     /**
  89.      * Show border ?
  90.      *
  91.      * @param bool $show 
  92.      */
  93.     public function show($show TRUE{
  94.         $this->hide = (bool)!$show;
  95.     }
  96.     
  97.     /**
  98.      * Is the border visible ?
  99.      *
  100.      * @return bool 
  101.      */
  102.     public function visible({
  103.         return !$this->hide;
  104.     }
  105.     
  106.     /**
  107.      * Draw border as a rectangle
  108.      *
  109.      * @param awDriver $driver 
  110.      * @param awPoint $p1 Top-left corner
  111.      * @param awPoint $p2 Bottom-right corner
  112.      */
  113.     public function rectangle(awDriver $driverawPoint $p1awPoint $p2{
  114.     
  115.         // Border is hidden
  116.         if($this->hide{
  117.             return;
  118.         }
  119.     
  120.         $line new awLine;
  121.         $line->setStyle($this->style);
  122.         $line->setLocation($p1$p2);
  123.         
  124.         $driver->rectangle($this->color$line);
  125.         
  126.     }
  127.     
  128.     /**
  129.      * Draw border as an ellipse
  130.      *
  131.      * @param awDriver $driver 
  132.      * @param awPoint $center Ellipse center
  133.      * @param int $width Ellipse width
  134.      * @param int $height Ellipse height
  135.      */
  136.     public function ellipse(awDriver $driverawPoint $center$width$height{
  137.     
  138.         // Border is hidden
  139.         if($this->hide{
  140.             return;
  141.         }
  142.         
  143.         switch($this->style{
  144.         
  145.             case awLine::SOLID :
  146.                 $driver->ellipse($this->color$center$width$height);
  147.                 break;
  148.             
  149.             default :
  150.                 awImage::drawError("Class Border: Dashed and dotted borders and not yet implemented on ellipses.");
  151.                 break;
  152.         
  153.         }
  154.         
  155.         
  156.     }
  157.     
  158.     /**
  159.      * Draw border as a polygon
  160.      * 
  161.      * @param awDriver $driver A Driver object
  162.      * @param awPolygon $polygon A Polygon object
  163.      */
  164.     public function polygon(awDriver $driverawPolygon $polygon{
  165.         
  166.         // Border is hidden
  167.         if($this->hide{
  168.             return;
  169.         }
  170.         
  171.         $polygon->setStyle($this->style);
  172.         $driver->polygon($this->color$polygon);
  173.         
  174.         // In case of Line::SOLID, Driver::polygon() uses imagepolygon()
  175.         // which automatically closes the shape. In any other case,
  176.         // we have to do it manually here.
  177.         if($this->style !== Line::SOLID{
  178.             $this->closePolygon($driver$polygon);
  179.         }
  180.     }
  181.     
  182.     /**
  183.      * Draws the last line of a Polygon, between the first and last point
  184.      * 
  185.      * @param awDriver $driver A Driver object
  186.      * @param awPolygon $polygon The polygon object to close
  187.      */
  188.     private function closePolygon(awDriver $driverawPolygon $polygon{
  189.         $first $polygon->get(0);
  190.         $last  $polygon->get($polygon->count(1);
  191.         
  192.         $line new awLine($first$last$this->style$polygon->getThickness());
  193.         $driver->line($this->color$line);
  194.     }
  195.     
  196. }
  197.  
  198. registerClass('Border');
  199. ?>

Documentation generated on Fri, 16 Oct 2009 09:28:58 +0200 by phpDocumentor 1.4.1