TeeChartPHP
[ class tree: TeeChartPHP ] [ index: TeeChartPHP ] [ all elements ]

Source for file ChartBrush.php

Documentation is available at ChartBrush.php

  1. <?php
  2.  
  3.  /**
  4.  * ChartBrush class
  5.  *
  6.  * Description: Common Chart Brush (pattern) used to fill polygons and
  7.  * rectangles
  8.  *
  9.  * @author
  10.  * @copyright (c) 1995-2008 by Steema Software SL. All Rights Reserved. <info@steema.com>
  11.  * @version 1.0
  12.  * @package TeeChartPHP
  13.  * @subpackage drawing
  14.  * @link http://www.steema.com
  15.  */
  16.  
  17. class ChartBrush extends TeeBase {
  18.  
  19.     private $image;
  20.     private $hatchImage;
  21.     private $foregroundColor;
  22.     private $gradient;
  23.     private $imageMode;
  24.     private $imageTransparent;
  25.     private $solid true;
  26.     private $style;
  27.     private $wrapTile true;
  28.  
  29.     protected $internalTransparency;
  30.     protected $defaultColor;
  31.     protected $defaultVisible;
  32.     protected $visible = true;
  33.     protected $color;
  34.  
  35.  
  36.     // Interceptors
  37.     function __get$property {
  38.       $method ="get{$property}";
  39.       if method_exists$this$method ) ) {
  40.         return $this->$method();
  41.       }
  42.     }
  43.  
  44.     function __set $property,$value {
  45.       $method ="set{$property}";
  46.       if method_exists$this$method ) ) {
  47.         return $this->$method($value);
  48.       }
  49.     }
  50.  
  51.     public function ChartBrush($c$aColor=null$startVisible=true{
  52.  
  53.         if($aColor==null)
  54.         {
  55.             $aColor=new Color(255,255,255);
  56.         }
  57.  
  58.         $this->imageMode=ImageMode::$STRETCH;
  59.         $this->style=HatchStyle::$BACKWARDDIAGONAL;
  60.  
  61.         parent::__construct($c);
  62.  
  63.         $this->internalTransparency = 0;
  64.         $this->color = $aColor;
  65.         $this->defaultColor = $this->color;
  66.         $this->visible = $startVisible;
  67.         $this->defaultVisible = $this->visible;
  68.         $this->foregroundColor new Color (220,220,220);  // Silver
  69.     }
  70.  
  71.     public function reset({
  72.         $this->setColor(new Color(255,255,255));  // White
  73.         $this->setSolid(true);
  74.         $this->setTransparency(0);
  75.         $this->setForegroundColor(new Color(220,220,220))// Silver
  76.         $this->setStyle(HatchStyle::$BACKWARDDIAGONAL);
  77.     }
  78.  
  79.     private function bufferedFrom($image{
  80.         return $this->chart->getGraphics3D()->bufferedFrom($image$this->getForegroundColor());
  81.     }
  82.  
  83.     public function getHatchTexture({
  84.  
  85.         $this->hatchImage $this->bufferedFrom($this->style->getImage(($this->getChart()->getParent())));
  86.  
  87.         $r new Rectangle(00$this->hatchImage->getWidth(null),
  88.                                     $this->hatchImage->getHeight(null));
  89.  
  90.         return new TexturePaint($this->hatchImage$r);
  91.     }
  92.  
  93.     public function getTexture($rect{
  94.         $tileRect $rect;
  95.         if ($this->imageMode != ImageMode::$STRETCH{
  96.             $tileRect $this->getImageRect();
  97.         }
  98.         return new TexturePaint($this->bufferedFrom($image)$tileRect);
  99.     }
  100.  
  101.     public function assign($b{
  102.         $this->foregroundColor $b->foregroundColor;
  103.         $this->color = $b->color;
  104.         $this->visible = $b->visible;
  105.         $this->style $b->style;
  106.         $this->image $b->image;
  107.         $this->imageTransparent $b->imageTransparent;
  108.         $this->solid $b->solid;
  109.         $this->wrapTile $b->wrapTile;
  110.         $this->imageMode $b->imageMode;
  111.         $this->internalTransparency = $b->internalTransparency;
  112.  
  113.         //CDI chart cannot be null
  114.         if($this->chart == null{
  115.             $this->chart = $b->chart;
  116.         }
  117.  
  118.         // chart = b.chart;  <-- problem, when assigning brush from another chart
  119.  
  120.         if ($b->gradient != null{
  121.             $this->getGradient()->assign($b->gradient);
  122.         else {
  123.             $this->gradient null;
  124.         }
  125.  
  126.         $this->setNullHandle();
  127.     }
  128.  
  129.     private function setNullHandle({
  130.         if ($this->chart != null{
  131.             $this->chart->doChangedBrush($this);
  132.         }
  133.     }
  134.  
  135.     public function setDefaultColor($value{
  136.         $this->defaultColor = $value;
  137.         $this->color = $value;
  138.     }
  139.  
  140.     public function setChart($c{
  141.         parent::setChart($c);
  142.         if ($this->gradient != null{
  143.             $this->gradient->setChart($this->chart);
  144.         }
  145.     }
  146.  
  147.     /**
  148.      * The Transparency level from 0 to 100%.<br>
  149.      * Transparency is a value between 0 and 100 which sets the transparency
  150.      * percentage with respect to foreground versus background.<br>
  151.      * Default value: 0
  152.  
  153.      * @return int 
  154.      */
  155.     public function getTransparency({    
  156.         return (127*$this->internalTransparency/100);
  157.     }
  158.  
  159.     /**
  160.      * Sets Transparency level from 0 to 100%.<br>
  161.      * Default value: 0
  162.      *
  163.      * @param value int
  164.      */
  165.     public function setTransparency($value{
  166.         if ($this->internalTransparency != $value{
  167.             $this->internalTransparency = $value;
  168.  
  169.             if ($this->gradient != null{
  170.                 $this->gradient->setTransparency($value);
  171.             }
  172.         }
  173.     }
  174.  
  175.     /**
  176.      * Fills using Color only. Does not use Foreground color.<br>
  177.      * Default value: true
  178.      *
  179.      * @return boolean 
  180.      */
  181.     public function getSolid({
  182.         return $this->solid;
  183.     }
  184.  
  185.     /**
  186.      * Fills using Color only. Does not use Foreground color.<br>
  187.      * Default value: true
  188.      *
  189.      * @param value boolean
  190.      */
  191.     public function setSolid($value{
  192.         $this->solid $this->setBooleanProperty($this->solid$value);
  193.     }
  194.  
  195.     /**
  196.      * The Brush image will be Transparent when true.<br>
  197.      * Default value: false
  198.      *
  199.      * @return boolean 
  200.      */
  201.     public function getImageTransparent({
  202.         return $this->imageTransparent;
  203.     }
  204.  
  205.     /**
  206.      * Sets the Brush image to Transparent.<br>
  207.      * Default value: false
  208.      *
  209.      * @param value boolean
  210.      */
  211.     public function setImageTransparent($value{
  212.         $this->imageTransparent $this->setBooleanProperty($this->imageTransparent$value);
  213.     }
  214.  
  215.     public function getGradientVisible({
  216.         return ($this->gradient != null&& $this->gradient->visible;
  217.     }
  218.  
  219.     /**
  220.      * Fill Gradient.<br>
  221.      * Gradient specifies the colors used to fill a zone.
  222.      * The zone is filled using these three colors: StartColor, MidColor and
  223.      * EndColor. You can control the drawing output by setting
  224.      * Gradient.Direction.<br>
  225.      * Use the Visible property to show / hide filling. <br>
  226.      * Default value: null
  227.      *
  228.      * @return Gradient 
  229.      */
  230.     public function getGradient({
  231.         if ($this->gradient == null{
  232.             $this->gradient new Gradient($this->chart);
  233.         }
  234.         return $this->gradient;
  235.     }
  236.  
  237.     /**
  238.      * Sets the Gradient fill.<br>
  239.      * Default value: null
  240.      *
  241.      * @param value Gradient
  242.      */
  243.     public function setGradient($value{
  244.         if ($value == null{
  245.             $this->gradient null;
  246.         else {
  247.             $this->getGradient()->assign($value);
  248.         }
  249.     }
  250.  
  251.     /**
  252.      * Use invalidate when the entire canvas needs to be repainted.<br>
  253.      * When more than one region within the canvas needs repainting, Invalidate
  254.      * will cause the entire window to be repainted in a single pass, aing
  255.      * flicker caused by redundant repaints. There is no performance penalty
  256.      * for calling Invalidate multiple times before the control is actually
  257.      * repainted.
  258.      */
  259.     public function invalidate({
  260.         $this->setNullHandle();
  261.         parent::invalidate();
  262.     }
  263.  
  264.     /**
  265.      * Drawing Brush Image Style.<br>
  266.      * Default value: Stretch
  267.      *
  268.      * @return ImageMode 
  269.      */
  270.     public function getImageMode({
  271.         return $this->imageMode;
  272.     }
  273.  
  274.     /**
  275.      * Drawing Brush Image Style.<br>
  276.      * Default value: Stretch
  277.      *
  278.      * @param value ImageMode
  279.      */
  280.     public function setImageMode($value{
  281.         if ($this->imageMode != $value{
  282.             $this->imageMode $value;
  283.             $this->invalidate();
  284.         }
  285.     }
  286.  
  287.     public function getImageRect({
  288.         if ($this->image !=  null{
  289.             return new Rectangle(0,0$this->image->getWidth(null)$this->image->getHeight(null));
  290.         else {
  291.             return null;
  292.         }
  293.     }
  294.  
  295.     /**
  296.      * Drawing Brush Image Style.<br>
  297.      * Default value: Tile
  298.      *
  299.      * @return boolean 
  300.      */
  301.     public function getWrapTile({
  302.         return $this->wrapTile;
  303.     }
  304.  
  305.     /**
  306.      * Drawing Brush Image Style.<br>
  307.      * Default value: Tile
  308.      *
  309.      * @param value boolean
  310.      */
  311.     public function setWrapTile($value{
  312.         if ($this->wrapTile != $value{
  313.             $this->wrapTile $value;
  314.             $this->invalidate();
  315.         }
  316.     }
  317.  
  318.     /**
  319.      * Color to fill inner portions of Brush, when Solid is false.<br>
  320.      * Default value: SILVER
  321.      *
  322.      *
  323.      * @return Color 
  324.      */
  325.     public function getForegroundColor({
  326.         return $this->foregroundColor;
  327.     }
  328.  
  329.     /**
  330.      * Specifies the Color to fill inner portions of Brush, when Solid is false.
  331.      * <br>
  332.      * Default value: SILVER
  333.      *
  334.      *
  335.      * @param value Color
  336.      */
  337.     public function setForegroundColor($value{
  338.         $this->foregroundColor $this->setColorProperty($this->foregroundColor$value);
  339.     }
  340.  
  341.     public function _applyDark($c$quantity{
  342.         $this->color = $c;
  343.         $this->applyDark($quantity);
  344.     }
  345.  
  346.     public function applyDark($quantity{
  347.         $this->color = $this->color->applyDark($quantity);
  348.         $this->setNullHandle();
  349.     }
  350.  
  351.     /**
  352.      * Determines the color used to fill a zone.
  353.      *
  354.      * @return Color 
  355.      */
  356.     public function getColor({
  357.         return $this->color;
  358.     }
  359.  
  360.     /**
  361.      * Specifies the color used to fill a zone.
  362.      *
  363.      * @param value Color
  364.      */
  365.      public function setColor($value{         
  366.          $this->color = $value;
  367.      }
  368.  
  369.     /**
  370.      * Determines if the brush will draw lines or not.
  371.      *
  372.      * @return boolean 
  373.      */
  374.     public function getVisible({
  375.         return $this->visible;
  376.     }
  377.  
  378.     /**
  379.      * Determines if the brush will draw lines or not.
  380.      *
  381.      * @param value boolean
  382.      */
  383.     public function setVisible($value{
  384.         $this->visible = $this->setBooleanProperty($this->visible$value);
  385.     }
  386.  
  387.     /**
  388.      * Determines the style in which the zone is filled or patterned using both
  389.      * Color and ForegroundColor.<br>
  390.      * Default value: HatchStyle.BackwardDiagonal
  391.      *
  392.      * @return HatchStyle 
  393.      */
  394.     public function getStyle({
  395.         return $this->style;
  396.     }
  397.  
  398.     /**
  399.      * Determines the style in which the zone is filled or patterned using both
  400.      * Color and ForegroundColor.<br>
  401.      * Default value: HatchStyle.BackwardDiagonal
  402.      *
  403.      * @param value HatchStyle
  404.      */
  405.     public function setStyle($value{
  406.         if ($this->style != $value{
  407.             $this->style $value;
  408.             $this->solid false;
  409.             $this->hatchImage null;
  410.             $this->invalidate();
  411.         }
  412.     }
  413.  
  414.     /**
  415.      * Image to use for fill.<br>
  416.      * Default value: null
  417.      *
  418.      * @return Image 
  419.      */
  420.     public function getImage({
  421.         return $this->image;
  422.     }
  423.  
  424.     /**
  425.      * Image to use for fill.<br>
  426.      * Default value: null
  427.      *
  428.      * @param value Image
  429.      */
  430.     public function setImage($value{
  431.         $this->image $value;
  432.         $this->solid $this->image == null;
  433.         $this->invalidate();
  434.     }
  435.  
  436.     /**
  437.      * Loads a bitmap into a ChartBrush element from the specified path.
  438.      *
  439.      * @param fileName String
  440.      */
  441.     public function loadImageFromFile($fileName{
  442.         $this->clearImage();
  443.         $this->setImage(ImageUtils::getImage($fileName($this->getChart()->getParent())));
  444.     }
  445.  
  446.     /**
  447.      * Loads a bitmap into a ChartBrush element from the specified URL.
  448.      *
  449.      * @param location URL
  450.      */
  451. /* todo    public function loadImage($location) {
  452.         $this->clearImage();
  453.         $this->setImage(ImageUtils->getImage($location, ($this->getChart()->getParent())));
  454.     }  */
  455.  
  456.     /**
  457.      * Clears the ChartBrush element from all associated bitmap images.
  458.      */
  459.     public function clearImage({
  460.         $this->setImage(null);
  461.     }
  462.  
  463. /* todo    private function writeObject($stream) {
  464.         $stream->defaultWriteObject();
  465.  
  466.         $gd= ($this->chart==null) ? null : $this->chart->getGraphics3D();
  467.  
  468.         ImageUtils->writeImage($stream, $this->image, $gd);
  469.         ImageUtils->writeImage($stream, $this->hatchImage, $gd);
  470.     }
  471.  
  472.     private readObject($stream) {
  473.         $stream->defaultReadObject();
  474.  
  475.         $tmp = ImageUtils->readImage($stream);
  476.  
  477.         if ($tmp != null) {
  478.             $this->image = $tmp;
  479.         }
  480.  
  481.         $tmp2 = ImageUtils->readImage($stream);
  482.  
  483.         if ($tmp2 != null) {
  484.             $this->hatchImage = $tmp2;
  485.         }
  486.     }  */
  487. }
  488. ?>

Documentation generated on Wed, 16 Jun 2010 12:04:14 +0200 by phpDocumentor 1.4.1