- <?php
-
- /*
- **************************************************
- Class: Line.php
- **************************************************
- Author: Tsiavos Chris <jaames@freemail.gr>
- Date: October 2004
- **************************************************/
-
- /**
- *Includes the shape abstract class
- */
- require_once("Shape.php");
-
- /**
- *Wrapper around gd's ImageLine function
- *@author Tsiavos Chris <jaames@freemail.gr>
- *@license http://opensource.org/licenses/gpl-license.php GNU Public License
- */
- class Line extends Shape {
-
- /**
- *@access private
- *@var string[]
- */
- private $Points=array();
-
- /**
- *The line breadth
- *@access private
- *@return integer
- */
- private $Breadth;
-
- /**
- *Constructor
- *@param mixed &$Canvas reference to the image handler the line will be drawn in
- *@param ColorAllocator &$ColorAllocator reference to the ColorAllocator the class will use for allocating the line color
- *@param string ("Yes","No") $UseAntialias specifies if antialias functions should be used or not when drawing the line
- *@param integer $Breadth
- */
- public function __construct(&$Canvas,ColorAllocator &$ColorAllocator,$UseAntialias,$Breadth=NULL) {
- Shape::__construct($Canvas,$ColorAllocator,$UseAntialias);
- $this->Breadth=$Breadth;
- }
-
- /**
- *Adds a point to the line
- *@access public
- *@return void
- */
- public function add_Point($point) {
- array_push($this->Points,$point);
- }
-
- /**
- *Returns the line's points
- *@access public
- *@return string[]
- */
- public function get_Points() {
- return $this->Points;
- }
-
- /**
- *Draws a dashed line
- *@access public
- *@return void
- *@param string $BorderColor
- *@param integer 0-127 $Alpha
- */
- public function draw_Dashed($BorderColor,$Alpha) {
- $ColorHandler=$this->ColorAllocator->Allocate($this->Canvas,$BorderColor,$BorderColor,$Alpha,1);
-
- for ($i=0;$i<count($this->Points);$i++) {
-
- $current=$i;
-
- if ($current==count($this->Points)-1)
- $next=$current;
- else
- $next=$i+1;
-
- $StartPoint=explode(",",$this->Points[$current]);
- $FinishPoint=explode(",",$this->Points[$next]);
-
- ImageDashedLine($this->Canvas,$StartPoint[0],$StartPoint[1],$FinishPoint[0],$FinishPoint[1],$ColorHandler);
- }
- }
-
- /**
- *Draws the border of a line
- *@access public
- *@return void
- *@param string $BorderColor
- *@param integer 0-127 $Alpha
- */
- public function draw($BorderColor,$Alpha) {
- if ($this->UseAntialias=="Yes")
- ImageAntialias($this->Canvas,1);
-
- $ColorHandler=$this->ColorAllocator->Allocate($this->Canvas,$BorderColor,$BorderColor,$Alpha,1);
-
- for ($i=0;$i<count($this->Points);$i++) {
-
- $current=$i;
-
- if ($current==count($this->Points)-1)
- $next=$current;
- else
- $next=$i+1;
-
- $StartPoint=explode(",",$this->Points[$current]);
- $FinishPoint=explode(",",$this->Points[$next]);
-
- ImageLine($this->Canvas,$StartPoint[0],$StartPoint[1],$FinishPoint[0],$FinishPoint[1],$ColorHandler);
-
- if ($this->Breadth!=NULL)
- ImageLine($this->Canvas,$StartPoint[0],$StartPoint[1]+$this->Breadth,$FinishPoint[0],$FinishPoint[1]+$this->Breadth,$ColorHandler);
- }
-
- if ($this->UseAntialias=="Yes")
- ImageAntialias($this->Canvas,0);
- }
-
- /**
- *Draws a filled with color line
- *@access public
- *@return void
- *@param string $StartColor
- *@param string $FinishColor
- *@param integer 0-127 $Alpha
- */
- public function draw_Filled($StartColor,$FinishColor,$Alpha) {
- $ColorHandler=$this->ColorAllocator->Allocate($this->Canvas,$StartColor,$FinishColor,$Alpha,$this->Breadth);
-
- if (is_array($ColorHandler))
- $this->draw_GradientLine($ColorHandler);
- else
- $this->draw_NormalLine($ColorHandler);
-
- }
-
- /**
- *Draws a gradient color line with breadth=$this->Breadth
- *@access private
- *@return void
- *@param mixed $ColorHandler
- */
- private function draw_GradientLine($ColorHandler) {
-
- for ($i=0;$i<count($this->Points);$i++) {
-
- $current=$i;
-
- if ($current==count($this->Points)-1)
- $next=$current;
- else
- $next=$i+1;
-
- $StartPoint=explode(",",$this->Points[$current]);
- $FinishPoint=explode(",",$this->Points[$next]);
-
- for ($breadth=0;$breadth<$this->Breadth;$breadth++)
- ImageLine($this->Canvas,$StartPoint[0],$StartPoint[1]+$breadth,$FinishPoint[0],$FinishPoint[1]+$breadth,$ColorHandler[$breadth]);
- }
-
- }
-
- /**
- *Draws a uniform color line with breadth=$this->Breadth
- *@access private
- *@return void
- *@param mixed $ColorHandler
- */
- private function draw_NormalLine($ColorHandler) {
- for ($i=0;$i<count($this->Points);$i++) {
-
- $current=$i;
-
- if ($current==count($this->Points)-1)
- $next=$current;
- else
- $next=$i+1;
-
- $StartPoint=explode(",",$this->Points[$current]);
- $FinishPoint=explode(",",$this->Points[$next]);
-
- for ($breadth=0;$breadth<$this->Breadth;$breadth++)
- ImageLine($this->Canvas,$StartPoint[0],$StartPoint[1]+$breadth,$FinishPoint[0],$FinishPoint[1]+$breadth,$ColorHandler);
- }
- }
-
- }
-
- ?>