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; } }
/** * 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->getThickness() > 0 and $line->isHidden() === FALSE) { list($red, $green, $blue, $alpha) = $this->getColor($color); $mingLine = new SWFShape(); $mingLine->setLine($line->getThickness(), $red, $green, $blue, $alpha); list($p1, $p2) = $line->getLocation(); $mingLine->movePenTo($this->x + round($p1->x), $this->y + round($p1->y)); switch ($line->getStyle()) { case awLine::SOLID: $mingLine->drawLineTo($this->x + round($p2->x), $this->y + round($p2->y)); $this->movie->add($mingLine); 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; $functionX = $width > 0 ? 'min' : 'max'; $functionY = $height > 0 ? 'min' : 'max'; for ($i = 0; $i <= $size; $i += 6) { $t1 = new awPoint(round($i * $cos + $p1->x), round($i * $sin + $p1->y)); $t2 = new awPoint(round($functionX(($i + 3) * $cos, $width) + $p1->x), round($functionY(($i + 3) * $sin, $height) + $p1->y)); $this->line($color, new awLine($t1, $t2)); } break; } } }