コード例 #1
0
ファイル: SWF.php プロジェクト: roojs/pear
 /**
  * Draw a line end
  *
  * Parameter array:
  * 'x'     : int X point
  * 'y'     : int Y point
  * 'end'   : string The end type of the end
  * 'size'  : int The size of the end
  * 'color' : string The color of the end
  * 'angle' : int [optional] The angle with which to draw the end
  * 'url'   : string [optional] Target URL
  *
  * @param array $params Parameter array
  *
  * @return void
  */
 function drawEnd($params)
 {
     $x = $this->_getX($params['x']);
     $y = $this->_getY($params['y']);
     $size = $params['size'];
     $angle = deg2rad(isset($params['angle']) ? $params['angle'] : 0);
     $pi2 = pi() / 2;
     switch ($params['end']) {
         case 'lollipop':
         case 'circle':
             if (($fill = $this->_getFillStyle($params['color'])) !== false) {
                 $shapeObj = new SWFShape();
                 $shapeObj->setRightFill($fill[0], $fill[1], $fill[2]);
                 $shapeObj->movePenTo($x + $size / 2, $y);
                 $shapeObj->drawCircle($size / 2);
                 if (isset($params['url'])) {
                     $button = new SWFButton();
                     $button->addShape($shapeObj, SWFBUTTON_HIT | SWFBUTTON_UP | SWFBUTTON_DOWN | SWFBUTTON_OVER);
                     $button->addAction(new SWFAction("getURL('{$params['url']}');"), SWFBUTTON_MOUSEUP);
                     $this->_canvas->add($button);
                 } else {
                     $this->_canvas->add($shapeObj);
                 }
                 parent::drawEnd($params);
             }
             break;
         case 'diamond':
             $x0 = round($params['x'] + cos($angle) * $size * 0.65);
             $y0 = round($params['y'] - sin($angle) * $size * 0.65);
             $shape = array(array($x0 + round(cos($angle) * $size * 0.65), $y0 - round(sin($angle) * $size * 0.65)), array($x0 + round(cos($angle + $pi2) * $size * 0.65), $y0 - round(sin($angle + $pi2) * $size * 0.65)), array($x0 + round(cos($angle + pi()) * $size * 0.65), $y0 - round(sin($angle + pi()) * $size * 0.65)), array($x0 + round(cos($angle + 3 * $pi2) * $size * 0.65), $y0 - round(sin($angle + 3 * $pi2) * $size * 0.65)));
             break;
         case 'line':
             $shape = array(array($x + round(cos($angle + $pi2) * $size / 2), $y - round(sin($angle + $pi2) * $size / 2)), array($x + round(cos($angle + 3 * $pi2) * $size / 2), $y - round(sin($angle + 3 * $pi2) * $size / 2)));
             break;
         case 'box':
         case 'rectangle':
             $x0 = round($params['x'] + cos($angle) * $size / 2);
             $y0 = round($params['y'] - sin($angle) * $size / 2);
             $pi4 = pi() / 4;
             $shape = array(array($x0 + round(cos($angle + $pi4) * $size / 2), $y0 - round(sin($angle + $pi4) * $size / 2)), array($x0 + round(cos($angle + $pi2 + $pi4) * $size / 2), $y0 - round(sin($angle + $pi2 + $pi4) * $size / 2)), array($x0 + round(cos($angle + pi() + $pi4) * $size / 2), $y0 - round(sin($angle + pi() + $pi4) * $size / 2)), array($x0 + round(cos($angle + 3 * $pi2 + $pi4) * $size / 2), $y0 - round(sin($angle + 3 * $pi2 + $pi4) * $size / 2)));
             break;
         case 'arrow':
             $shape = array(array($x + cos($angle) * $size, $y - sin($angle) * $size), array($x + cos($angle + $pi2) * $size * 0.4, $y - sin($angle + $pi2) * $size * 0.4), array($x + cos($angle + 3 * $pi2) * $size * 0.4, $y - sin($angle + 3 * $pi2) * $size * 0.4));
             break;
         case 'arrow2':
             $shape = array(array($x + round(cos($angle) * $size), $y - round(sin($angle) * $size)), array($x + round(cos($angle + $pi2 + deg2rad(45)) * $size), $y - round(sin($angle + $pi2 + deg2rad(45)) * $size)), array($x, $y), array($x + round(cos($angle + 3 * $pi2 - deg2rad(45)) * $size), $y - round(sin($angle + 3 * $pi2 - deg2rad(45)) * $size)));
             break;
     }
     if (isset($shape)) {
         // output the shape
         if (($fill = $this->_getFillStyle($params['color'])) !== false) {
             $shapeObj = new SWFShape();
             $shapeObj->setRightFill($fill[0], $fill[1], $fill[2]);
             $shapeObj->setLine(0, $fill[0], $fill[1], $fill[2]);
             $shapeObj->movePenTo($shape[0][0], $shape[0][1]);
             for ($count = count($shape); $count--; $count > 0) {
                 $shapeObj->drawLineTo($shape[$count][0], $shape[$count][1]);
             }
             if (isset($params['url'])) {
                 $button = new SWFButton();
                 $button->addShape($shapeObj, SWFBUTTON_HIT | SWFBUTTON_UP | SWFBUTTON_DOWN | SWFBUTTON_OVER);
                 $button->addAction(new SWFAction("getURL('{$params['url']}');"), SWFBUTTON_MOUSEUP);
                 $this->_canvas->add($button);
             } else {
                 $this->_canvas->add($shapeObj);
             }
         }
     }
     parent::drawEnd($params);
 }