예제 #1
0
	 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);
						
					}
				
				}
	
			}
			
		}
	
	}
예제 #2
0
 /**
  * Draw grids
  *
  * @param awDriver $driver A driver object
  * @param int $x1
  * @param int $y1
  * @param int $x2
  * @param int $y2
  */
 public function draw(awDriver $driver, $x1, $y1, $x2, $y2)
 {
     if ($this->background instanceof awColor) {
         // Draw background color
         $driver->filledRectangle($this->background, awLine::build($x1, $y1, $x2, $y2));
     }
     if ($this->hide === FALSE) {
         $this->drawGrid($driver, $this->color, $this->hideVertical ? array() : $this->xgrid, $this->hideHorizontal ? array() : $this->ygrid, $x1, $y1, $x2, $y2, $this->type, $this->space, $this->interval[0], $this->interval[1]);
     }
 }
예제 #3
0
파일: ming.class.php 프로젝트: rhertzog/lcs
 /**
  * Draw a string
  *
  * @var &$text Text to print
  * @param $point Draw the text at this point
  * @param int $width Text max width
  */
 function string(&$text, $point, $width = NULL)
 {
     $font = $text->getFont();
     // Can we deal with that font?
     if ($this->isCompatibleWithFont($font) === FALSE) {
         awImage::drawError('Class MingDriver: Incompatible font type (\'' . get_class($font) . '\')');
     }
     // Ming can only work with awFileFont objects for now
     // (i.e. awFDBFont, or awTuffy et al.)
     $fontDriver = $this->fileFontDriver;
     if ($text->getBackground() !== NULL or $text->border->visible()) {
         list($left, $right, $top, $bottom) = $text->getPadding();
         $textWidth = $fontDriver->getTextWidth($text, $this);
         $textHeight = $fontDriver->getTextHeight($text, $this);
         $x1 = floor($point->x - $left);
         $y1 = floor($point->y - $top);
         $x2 = $x1 + $textWidth + $left + $right;
         $y2 = $y1 + $textHeight + $top + $bottom;
         $this->filledRectangle($text->getBackground(), awLine::build($x1, $y1, $x2, $y2));
         $text->border->rectangle($this, new awPoint($x1 - 1, $y1 - 1), new awPoint($x2 + 1, $y2 + 1));
     }
     $fontDriver->string($this, $text, $point, $width);
 }
예제 #4
0
 /**
  * Draw grids
  *
  * @param $drawer A drawer object
  * @param int $x1
  * @param int $y1
  * @param int $x2
  * @param int $y2
  */
 function draw($drawer, $x1, $y1, $x2, $y2)
 {
     if (is_a($this->background, 'awColor')) {
         // Draw background color
         $drawer->filledRectangle($this->background, awLine::build($x1, $y1, $x2, $y2));
         $this->background->free();
     }
     if ($this->hide === FALSE) {
         $this->drawGrid($drawer, $this->color, $this->hideVertical ? array() : $this->xgrid, $this->hideHorizontal ? array() : $this->ygrid, $x1, $y1, $x2, $y2, $this->type, $this->space, $this->interval[0], $this->interval[1]);
     }
     $this->color->free();
 }