Exemplo n.º 1
0
	/**
	 * Draw a colored line
	 *
	 * @param awColor $color Line color
	 * @param awLine $line
	 * @param int $thickness Line tickness
	 */
	public function line(awColor $color, awLine $line) {
	
		if($line->thickness > 0 and $line->isHidden() === FALSE) {
	
			$rgb = $color->getColor($this->resource);
			$thickness = $line->thickness;
			
			list($p1, $p2) = $line->getLocation();
			
			$this->startThickness($thickness);
			
			switch($line->getStyle()) {
			
				case awLine::SOLID :
					imageline($this->resource, $this->x + round($p1->x), $this->y + round($p1->y), $this->x + round($p2->x), $this->y + round($p2->y), $rgb);
					break;
					
				case awLine::DOTTED :
					$size = sqrt(pow($p2->y - $p1->y, 2) + pow($p2->x - $p1->x, 2));
					$cos = ($p2->x - $p1->x) / $size;
					$sin = ($p2->y - $p1->y) / $size;
					for($i = 0; $i <= $size; $i += 2) {
						$p = new awPoint(
							round($i * $cos + $p1->x),
							round($i * $sin + $p1->y)
						);
						$this->point($color, $p);
					}
					break;
					
				case awLine::DASHED :
					$width = $p2->x - $p1->x;
					$height = $p2->y - $p1->y;
					$size = sqrt(pow($height, 2) + pow($width, 2));
					
					if($size == 0) {
						return;
					}
					
					$cos = $width / $size;
					$sin = $height / $size;
					
					for($i = 0; $i <= $size; $i += 6) {
						
						$t1 = new awPoint(
							round($i * $cos + $p1->x),
							round($i * $sin + $p1->y)
						);
						
						$function = ($height > 0) ? 'min' : 'max';
						$t2 = new awPoint(
							round(min(($i + 3) * $cos, $width) + $p1->x),
							round($function(($i + 3) * $sin, $height) + $p1->y)
						);
						
						$this->line($color, new awLine($t1, $t2));
						
					}
					break;
			
			}
			
			$this->stopThickness($thickness);
			
		}
		
	}
Exemplo n.º 2
0
 public function rectangle(awColor $color, awLine $line)
 {
     list($p1, $p2) = $line->getLocation();
     switch ($line->getStyle()) {
         case awLine::SOLID:
             $thickness = $line->getThickness();
             $this->startThickness($thickness);
             $rgb = $this->getColor($color);
             imagerectangle($this->resource, $this->x + $p1->x, $this->y + $p1->y, $this->x + $p2->x, $this->y + $p2->y, $rgb);
             $this->stopThickness($thickness);
             break;
         default:
             $side = clone $line;
             // Top side
             $side->setLocation(new awPoint($p1->x, $p1->y), new awPoint($p2->x, $p1->y));
             $this->line($color, $side);
             // Right side
             $side->setLocation(new awPoint($p2->x, $p1->y), new awPoint($p2->x, $p2->y));
             $this->line($color, $side);
             // Bottom side
             $side->setLocation(new awPoint($p1->x, $p2->y), new awPoint($p2->x, $p2->y));
             $this->line($color, $side);
             // Left side
             $side->setLocation(new awPoint($p1->x, $p1->y), new awPoint($p1->x, $p2->y));
             $this->line($color, $side);
             break;
     }
 }
Exemplo n.º 3
0
 /**
  * Draw a rectangle with a background
  *
  * @param mixed $background Background (can be a color or a gradient)
  * @param awLine $line Rectangle diagonale
  */
 public function filledRectangle($background, awLine $line)
 {
     list($p1, $p2) = $line->getLocation();
     // Common shape settings
     $shape = new SWFShape();
     $shape->setLine(0);
     if ($background instanceof awColor) {
         // Get the Red, Green, Blue and Alpha values
         list($r, $g, $b, $a) = $this->getColor($background);
         $shape->setRightFill($r, $g, $b, $a);
     } else {
         if ($background instanceof awGradient) {
             // Get the Gradient object as an SWFGradient one
             list($flashGradient, $style) = $this->getGradient($background);
             $fill = $shape->addFill($flashGradient, $style);
             // Angles between Artichow and Ming don't match.
             // Don't use abs() or vertical gradients get inverted.
             $angle = $background->angle - 90;
             $fill->rotateTo($angle);
             // Move the gradient based on the position of the rectangle we're drawing
             $centerX = min($p1->x, $p2->y) + abs($p1->x - $p2->x) / 2;
             $centerY = min($p1->y, $p2->y) + abs($p1->y - $p2->y) / 2;
             $fill->moveTo($centerX, $centerY);
             // Ming draws its gradients on a 1600x1600 image,
             // so we have to resize it.
             if ($angle === -90) {
                 $ratio = abs($p1->y - $p2->y) / 1600;
             } else {
                 $ratio = abs($p1->x - $p2->x) / 1600;
             }
             $fill->scaleTo($ratio);
             $shape->setRightFill($fill);
         }
     }
     // Set starting position
     $shape->movePenTo($this->x + round($p1->x), $this->y + round($p1->y));
     // Depending on the points' relative positions,
     // we have two drawing possibilities
     if ($p1->x <= $p2->x and $p1->y <= $p2->y or $p1->x >= $p2->x and $p1->y >= $p2->y) {
         $shape->drawLineTo($this->x + round($p2->x), $this->y + round($p1->y));
         $shape->drawLineTo($this->x + round($p2->x), $this->y + round($p2->y));
         $shape->drawLineTo($this->x + round($p1->x), $this->y + round($p2->y));
         $shape->drawLineTo($this->x + round($p1->x), $this->y + round($p1->y));
     } else {
         $shape->drawLineTo($this->x + round($p1->x), $this->y + round($p2->y));
         $shape->drawLineTo($this->x + round($p2->x), $this->y + round($p2->y));
         $shape->drawLineTo($this->x + round($p2->x), $this->y + round($p1->y));
         $shape->drawLineTo($this->x + round($p1->x), $this->y + round($p1->y));
     }
     $this->movie->add($shape);
 }