You are here

function pDraw::drawPolygon in Visitors 7

Same name and namespace in other branches
  1. 7.2 pChart/class/pDraw.class.php \pDraw::drawPolygon()
5 calls to pDraw::drawPolygon()
pDraw::drawFilledStepChart in pChart/class/pDraw.class.php
pDraw::drawLabelBox in pChart/class/pDraw.class.php
pDraw::drawLine in pChart/class/pDraw.class.php
pDraw::drawShape in pChart/class/pDraw.class.php
pDraw::drawStackedAreaChart in pChart/class/pDraw.class.php

File

pChart/class/pDraw.class.php, line 127

Class

pDraw

Code

function drawPolygon($Points, $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;
  $NoFill = isset($Format["NoFill"]) ? $Format["NoFill"] : FALSE;
  $NoBorder = isset($Format["NoBorder"]) ? $Format["NoBorder"] : FALSE;
  $BorderR = isset($Format["BorderR"]) ? $Format["BorderR"] : $R;
  $BorderG = isset($Format["BorderG"]) ? $Format["BorderG"] : $G;
  $BorderB = isset($Format["BorderB"]) ? $Format["BorderB"] : $B;
  $BorderAlpha = isset($Format["Alpha"]) ? $Format["Alpha"] : $Alpha / 2;
  $Surrounding = isset($Format["Surrounding"]) ? $Format["Surrounding"] : NULL;
  $SkipX = isset($Format["SkipX"]) ? $Format["SkipX"] : OUT_OF_SIGHT;
  $SkipY = isset($Format["SkipY"]) ? $Format["SkipY"] : OUT_OF_SIGHT;

  /* Calling the ImageFilledPolygon() function over the $Points array will round it */
  $Backup = $Points;
  if ($Surrounding != NULL) {
    $BorderR = $R + $Surrounding;
    $BorderG = $G + $Surrounding;
    $BorderB = $B + $Surrounding;
  }
  if ($SkipX != OUT_OF_SIGHT) {
    $SkipX = floor($SkipX);
  }
  if ($SkipY != OUT_OF_SIGHT) {
    $SkipY = floor($SkipY);
  }
  $RestoreShadow = $this->Shadow;
  if (!$NoFill) {
    if ($this->Shadow && $this->ShadowX != 0 && $this->ShadowY != 0) {
      $this->Shadow = FALSE;
      for ($i = 0; $i <= count($Points) - 1; $i = $i + 2) {
        $Shadow[] = $Points[$i] + $this->ShadowX;
        $Shadow[] = $Points[$i + 1] + $this->ShadowY;
      }
      $this
        ->drawPolygon($Shadow, array(
        "R" => $this->ShadowR,
        "G" => $this->ShadowG,
        "B" => $this->ShadowB,
        "Alpha" => $this->Shadowa,
        "NoBorder" => TRUE,
      ));
    }
    $FillColor = $this
      ->allocateColor($this->Picture, $R, $G, $B, $Alpha);
    if (count($Points) >= 6) {
      ImageFilledPolygon($this->Picture, $Points, count($Points) / 2, $FillColor);
    }
  }
  if (!$NoBorder) {
    $Points = $Backup;
    if ($NoFill) {
      $BorderSettings = array(
        "R" => $R,
        "G" => $G,
        "B" => $B,
        "Alpha" => $Alpha,
      );
    }
    else {
      $BorderSettings = array(
        "R" => $BorderR,
        "G" => $BorderG,
        "B" => $BorderB,
        "Alpha" => $BorderAlpha,
      );
    }
    for ($i = 0; $i <= count($Points) - 1; $i = $i + 2) {
      if (isset($Points[$i + 2])) {
        if (!($Points[$i] == $Points[$i + 2] && $Points[$i] == $SkipX) && !($Points[$i + 1] == $Points[$i + 3] && $Points[$i + 1] == $SkipY)) {
          $this
            ->drawLine($Points[$i], $Points[$i + 1], $Points[$i + 2], $Points[$i + 3], $BorderSettings);
        }
      }
      else {
        if (!($Points[$i] == $Points[0] && $Points[$i] == $SkipX) && !($Points[$i + 1] == $Points[1] && $Points[$i + 1] == $SkipY)) {
          $this
            ->drawLine($Points[$i], $Points[$i + 1], $Points[0], $Points[1], $BorderSettings);
        }
      }
    }
  }
  $this->Shadow = $RestoreShadow;
}