コード例 #1
0
 /**
  * Create a new awimage
  */
 function create()
 {
     if ($this->resource === NULL) {
         // Create image
         $this->resource = imagecreatetruecolor($this->width, $this->height);
         if (!$this->resource) {
             trigger_error("Unable to create a graph", E_USER_ERROR);
         }
         imagealphablending($this->resource, TRUE);
         if ($this->antiAliasing and function_exists('imageantialias')) {
             imageantialias($this->resource, TRUE);
         }
         $this->drawer = new awDrawer($this->resource);
         $this->drawer->setImageSize($this->width, $this->height);
         // Original color
         $this->drawer->filledRectangle(new awWhite(), new awLine(new awPoint(0, 0), new awPoint($this->width, $this->height)));
         $shadow = $this->shadow->getSpace();
         $p1 = new awPoint($shadow->left, $shadow->top);
         $p2 = new awPoint($this->width - $shadow->right - 1, $this->height - $shadow->bottom - 1);
         // Draw image background
         $this->drawer->filledRectangle($this->background, new awLine($p1, $p2));
         $this->background->free();
         // Draw image border
         $this->border->rectangle($this->drawer, $p1, $p2);
     }
 }
コード例 #2
0
ファイル: Drawer.class.php プロジェクト: remyyounes/dolibarr
	 function polygonLinearGradient(&$gradient, &$polygon) {
	
		$count = $polygon->count();
		
		if($count >= 3) {
		
			$left = $polygon->get(0);
			$right = $polygon->get($count - 1);
			
			if($gradient->angle === 0) {
			
				// Get polygon maximum and minimum
				$offset = $polygon->get(0);
				$max = $min = $offset->y;
				for($i = 1; $i < $count - 1; $i++) {
					$offset = $polygon->get($i);
					$max = max($max, $offset->y);
					$min = min($min, $offset->y);
				}
				
				$this->init($gradient, $max - $min);
			
				$prev = $polygon->get(1);
				
				$sum = 0;
			
				for($i = 2; $i < $count - 1; $i++) {
				
					$current = $polygon->get($i);
					
					$interval = 1;
					
					if($i !== $count - 2) {
						$current->x -= $interval;
					}
					
					if($current->x - $prev->x > 0) {
				
						// Draw rectangle
						$x1 = $prev->x;
						$x2 = $current->x;
						$y1 = max($prev->y, $current->y);
						$y2 = $left->y;
						
						$gradient = new awLinearGradient(
							$this->color($max - $min - ($y2 - $y1)),
							$this->color($max - $min),
							0
						);
						
						if($y1 > $y2) {
							$y2 = $y1;
						}
						
						$this->drawer->filledRectangle(
							$gradient,
							awLine::build($x1, $y1, $x2, $y2)
						);
						
						$top = ($prev->y < $current->y) ? $current : $prev;
						$bottom = ($prev->y >= $current->y) ? $current : $prev;
						
						$gradient = new awLinearGradient(
							$this->color($bottom->y - $min),
							$this->color($max - $min - ($y2 - $y1)),
							0
						);
						
	
						$gradientDrawer = new awGradientDrawer($this->drawer);
						$gradientDrawer->drawFilledFlatTriangle(
							$gradient,
							new awPoint($prev->x, min($prev->y, $current->y)),
							$top,
							new awPoint($current->x, min($prev->y, $current->y))
						);
						unset($gradientDrawer);
						
						$sum += $current->x - $prev->x;
						
					}
					
					$prev = $current;
					$prev->x += $interval;
				
				}
			
			} else if($gradient->angle === 90) {
				
				$width = $right->x - $left->x;
				$this->init($gradient, $width);
				
				$pos = 1;
				$next = $polygon->get($pos++);
				
				$this->next($polygon, $pos, $prev, $next);
			
				for($i = 0; $i <= $width; $i++) {
				
					$x = $left->x + $i;
					
					$y1 = round($prev->y + ($next->y - $prev->y) * (($i + $left->x - $prev->x) / ($next->x - $prev->x)));
					$y2 = $left->y;
				
					// Draw line
					$color = $this->color($i);
					// YaPB : PHP does not handle alpha on lines
					$this->drawer->filledRectangle($color, awLine::build($x, $y1, $x, $y2));
					$color->free();
					unset($color);
					
					// Jump to next point
					if($next->x == $i + $left->x) {
					
						$this->next($polygon, $pos, $prev, $next);
						
					}
				
				}
	
			}
			
		}
	
	}
コード例 #3
0
 protected function drawSquare(awPoint $point)
 {
     list($x, $y) = $point->getLocation();
     $x1 = (int) ($x - $this->size / 2);
     $x2 = $x1 + $this->size;
     $y1 = (int) ($y - $this->size / 2);
     $y2 = $y1 + $this->size;
     $this->border->rectangle($this->drawer, new awPoint($x1, $y1), new awPoint($x2, $y2));
     $size = $this->border->visible() ? 1 : 0;
     $this->drawer->filledRectangle($this->fill, new awLine(new awPoint($x1 + $size, $y1 + $size), new awPoint($x2 - $size, $y2 - $size)));
 }