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); } } } } }
/** * Draw a polygon * * @param $color Polygon color * @param Polygon A polygon */ function polygon($color, &$polygon) { $points = $polygon->all(); $count = count($points); if ($count > 1) { $side = new awLine(); $side->setStyle($polygon->getStyle()); $side->setThickness($polygon->getThickness()); $prev = $points[0]; for ($i = 1; $i < $count; $i++) { $current = $points[$i]; $side->setLocation($prev, $current); $this->line($color, $side); $prev = $current; } // Close the polygon $side->setLocation($prev, $points[0]); $this->line($color, $side); } }
/** * Draw border as a rectangle * * @param $driver * @param $p1 Top-left corner * @param $p2 Bottom-right corner */ function rectangle($driver, $p1, $p2) { // Border is hidden if ($this->hide) { return; } $line = new awLine(); $line->setStyle($this->style); $line->setLocation($p1, $p2); $driver->rectangle($this->color, $line); }
/** * 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]); } }
/** * 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(); }
/** * Draw border as a rectangle * * @param awDrawer $drawer * @param awPoint $p1 Top-left corner * @param awPoint $p2 Bottom-right corner */ public function rectangle(awDrawer $drawer, awPoint $p1, awPoint $p2) { // Border is hidden if ($this->hide) { return; } $line = new awLine(); $line->setStyle($this->style); $line->setLocation($p1, $p2); $drawer->rectangle($this->color, $line); }