Ejemplo n.º 1
0
 protected function polygonLinearGradient(awLinearGradient $gradient, awPolygon $polygon)
 {
     $count = $polygon->count();
     if ($count >= 4) {
         $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->driver->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);
                     $gradientDriver = new awGDGradientDriver($this->driver);
                     $gradientDriver->drawFilledFlatTriangle($gradient, new awPoint($prev->x, min($prev->y, $current->y)), $top, new awPoint($current->x, min($prev->y, $current->y)));
                     unset($gradientDriver);
                     $sum += $current->x - $prev->x;
                 }
                 $prev = $current;
                 $prev->x += $interval;
             }
         } elseif ($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->driver->filledRectangle($color, awLine::build($x, $y1, $x, $y2));
                 unset($color);
                 // Jump to next point
                 if ($next->x == $i + $left->x) {
                     $this->next($polygon, $pos, $prev, $next);
                 }
             }
         }
     } elseif ($count === 3) {
         $this->drawFilledTriangle($gradient, $polygon);
     }
 }
Ejemplo n.º 2
0
 /**
  * Draws the last line of a Polygon, between the first and last point
  * 
  * @param awDriver $driver A Driver object
  * @param awPolygon $polygon The polygon object to close
  */
 private function closePolygon(awDriver $driver, awPolygon $polygon)
 {
     $first = $polygon->get(0);
     $last = $polygon->get($polygon->count() - 1);
     $line = new awLine($first, $last, $this->style, $polygon->getThickness());
     $driver->line($this->color, $line);
 }