function pDraw::drawRoundedRectangle

5.x pDraw.class.php pDraw::drawRoundedRectangle($X1, $Y1, $X2, $Y2, $Radius, $Format = "")
2 calls to pDraw::drawRoundedRectangle()

File

inc/pchart/pchart/class/pDraw.class.php, line 217

Class

pDraw

Code

function drawRoundedRectangle($X1, $Y1, $X2, $Y2, $Radius, $Format = "") 
 {
  $R = isset($Format ["R"]) ? $Format ["R"] : 0;
  $G = isset($Format ["G"]) ? $Format ["G"] : 0;
  $B = isset($Format ["B"]) ? $Format ["B"] : 0;
  $Alpha = isset($Format ["Alpha"]) ? $Format ["Alpha"] : 100;

  list($X1, $Y1, $X2, $Y2) = $this->fixBoxCoordinates($X1, $Y1, $X2, $Y2);

  if ($X2 - $X1 < $Radius) {
    $Radius = floor((($X2 -$X1)) / 2);
  }
  if ($Y2 - $Y1 < $Radius) {
    $Radius = floor((($Y2 -$Y1)) / 2);
  }

  $Color = array("R" => $R, "G" => $G, "B" => $B, "Alpha" => $Alpha, "NoBorder" => TRUE);

  if ($Radius <= 0) {
    $this->drawRectangle($X1, $Y1, $X2, $Y2, $Color);
    return (0);
  }

  if ($this->Antialias) 
   {
    $this->drawLine($X1 + $Radius, $Y1, $X2 -$Radius, $Y1, $Color);
    $this->drawLine($X2, $Y1 + $Radius, $X2, $Y2 -$Radius, $Color);
    $this->drawLine($X2 -$Radius, $Y2, $X1 + $Radius, $Y2, $Color);
    $this->drawLine($X1, $Y1 + $Radius, $X1, $Y2 -$Radius, $Color);
  }
  else 
   {
    $Color = $this->allocateColor($this->Picture, $R, $G, $B, $Alpha);
    imageline($this->Picture, $X1 + $Radius, $Y1, $X2 -$Radius, $Y1, $Color);
    imageline($this->Picture, $X2, $Y1 + $Radius, $X2, $Y2 -$Radius, $Color);
    imageline($this->Picture, $X2 -$Radius, $Y2, $X1 + $Radius, $Y2, $Color);
    imageline($this->Picture, $X1, $Y1 + $Radius, $X1, $Y2 -$Radius, $Color);
  }

  $Step = 360 / (2 * PI * $Radius);
  for ($i = 0; $i <= 90; $i = $i + $Step) 
   {
    $X = cos(($i + 180) * PI / 180) * $Radius + $X1 + $Radius;
    $Y = sin(($i + 180) * PI / 180) * $Radius + $Y1 + $Radius;
    $this->drawAntialiasPixel($X, $Y, array("R" => $R, "G" => $G, "B" => $B, "Alpha" => $Alpha));

    $X = cos(($i + 90) * PI / 180) * $Radius + $X1 + $Radius;
    $Y = sin(($i + 90) * PI / 180) * $Radius + $Y2 - $Radius;
    $this->drawAntialiasPixel($X, $Y, array("R" => $R, "G" => $G, "B" => $B, "Alpha" => $Alpha));

    $X = cos($i * PI / 180) * $Radius + $X2 - $Radius;
    $Y = sin($i * PI / 180) * $Radius + $Y2 - $Radius;
    $this->drawAntialiasPixel($X, $Y, array("R" => $R, "G" => $G, "B" => $B, "Alpha" => $Alpha));

    $X = cos(($i + 270) * PI / 180) * $Radius + $X2 - $Radius;
    $Y = sin(($i + 270) * PI / 180) * $Radius + $Y1 + $Radius;
    $this->drawAntialiasPixel($X, $Y, array("R" => $R, "G" => $G, "B" => $B, "Alpha" => $Alpha));
  }
}