linea21-externals
[ class tree: linea21-externals ] [ index: linea21-externals ] [ all elements ]

Source for file Mark.class.php

Documentation is available at Mark.class.php

  1. <?php
  2. /*
  3.  * This work is hereby released into the Public Domain.
  4.  * To view a copy of the public domain dedication,
  5.  * visit http://creativecommons.org/licenses/publicdomain/ or send a letter to
  6.  * Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
  7.  *
  8.  */
  9.  
  10. require_once dirname(__FILE__)."/../Graph.class.php";
  11.  
  12. /* <php4> */
  13.  
  14. define("MARK_CIRCLE"1);
  15. define("MARK_SQUARE"2);
  16. define("MARK_TRIANGLE"3);
  17. define("MARK_INVERTED_TRIANGLE"4);
  18. define("MARK_RHOMBUS"5);
  19. define("MARK_CROSS"6);
  20. define("MARK_PLUS"7);
  21. define("MARK_IMAGE"8);
  22. define("MARK_STAR"9);
  23. define("MARK_PAPERCLIP"10);
  24. define("MARK_BOOK"11);
  25.  
  26. /* </php4> */
  27.  
  28. /**
  29.  * Draw marks
  30.  *
  31.  * @package linea21.externals
  32.  * @subpackage artichow
  33.  */
  34. class awMark {
  35.  
  36.     /**
  37.      * Circle mark
  38.      *
  39.      * @var int 
  40.      */
  41.     const CIRCLE 1;
  42.  
  43.     /**
  44.      * Square mark
  45.      *
  46.      * @var int 
  47.      */
  48.     const SQUARE 2;
  49.  
  50.     /**
  51.      * Triangle mark
  52.      * 
  53.      * @var int 
  54.      */
  55.     const TRIANGLE 3;
  56.     
  57.     /**
  58.      * Inverted triangle mark
  59.      * 
  60.      * @var int 
  61.      */
  62.     const INVERTED_TRIANGLE 4;
  63.  
  64.     /**
  65.      * Rhombus mark
  66.      * 
  67.      * @var int 
  68.      */
  69.     const RHOMBUS 5;
  70.  
  71.     /**
  72.      * Cross (X) mark
  73.      * 
  74.      * @var int 
  75.      */
  76.     const CROSS 6;
  77.  
  78.     /**
  79.      * Plus mark
  80.      * 
  81.      * @var int 
  82.      */
  83.     const PLUS 7;
  84.  
  85.     /**
  86.      * Image mark
  87.      *
  88.      * @var int 
  89.      */
  90.     const IMAGE 8;
  91.  
  92.     /**
  93.      * Star mark
  94.      *
  95.      * @var int 
  96.      */
  97.     const STAR 9;
  98.  
  99.     /**
  100.      * Paperclip mark
  101.      *
  102.      * @var int 
  103.      */
  104.     const PAPERCLIP 10;
  105.  
  106.     /**
  107.      * Book mark
  108.      *
  109.      * @var int 
  110.      */
  111.     const BOOK 11;
  112.  
  113.     /**
  114.      * Must marks be hidden ?
  115.      *
  116.      * @var bool 
  117.      */
  118.     protected $hide;
  119.  
  120.     /**
  121.      * Mark type
  122.      *
  123.      * @var int 
  124.      */
  125.     protected $type;
  126.  
  127.     /**
  128.      * Mark size
  129.      *
  130.      * @var int 
  131.      */
  132.     protected $size = 8;
  133.  
  134.     /**
  135.      * Fill mark
  136.      *
  137.      * @var Color, Gradient
  138.      */
  139.     protected $fill;
  140.  
  141.     /**
  142.      * Mark image
  143.      *
  144.      * @var Image 
  145.      */
  146.     protected $image;
  147.  
  148.     /**
  149.      * To draw marks
  150.      *
  151.      * @var Driver 
  152.      */
  153.     protected $driver;
  154.  
  155.     /**
  156.      * Move position from this vector
  157.      *
  158.      * @var Point 
  159.      */
  160.     protected $move;
  161.     
  162.     /**
  163.      * Marks border
  164.      *
  165.      * @var Border 
  166.      */
  167.     public $border;
  168.  
  169.     /**
  170.      * Build the mark
  171.      */
  172.     public function __construct({
  173.         
  174.         $this->fill = new awColor(255000);
  175.         $this->border = new awBorder;
  176.         $this->border->hide();
  177.         
  178.         $this->move = new awPoint(00);
  179.     
  180.     }
  181.     
  182.     /**
  183.      * Change mark position
  184.      *
  185.      * @param int $x Add this interval to X coord
  186.      * @param int $y Add this interval to Y coord
  187.      */
  188.     public function move($x$y{
  189.     
  190.         $this->move = $this->move->move($x$y);
  191.     
  192.     }
  193.     
  194.     /**
  195.      * Hide marks ?
  196.      *
  197.      * @param bool $hide TRUE to hide marks, FALSE otherwise
  198.      */
  199.     public function hide($hide TRUE{
  200.         $this->hide = (bool)$hide;
  201.     }
  202.     
  203.     /**
  204.      * Show marks ?
  205.      *
  206.      * @param bool $show 
  207.      */
  208.     public function show($show TRUE{
  209.         $this->hide = (bool)!$show;
  210.     }
  211.     
  212.     /**
  213.      * Change mark type
  214.      *
  215.      * @param int $size Size in pixels
  216.      */
  217.     public function setSize($size{
  218.         $this->size = (int)$size;
  219.     }
  220.     
  221.     /**
  222.      * Change mark type
  223.      *
  224.      * @param int $type New mark type
  225.      * @param int $size Mark size (can be NULL)
  226.      */
  227.     public function setType($type$size NULL{
  228.         $this->type = (int)$type;
  229.         if($size !== NULL{
  230.             $this->setSize($size);
  231.         }
  232.     }
  233.     
  234.     /**
  235.      * Fill the mark with a color or a gradient
  236.      *
  237.      * @param mixed $fill A color or a gradient
  238.      */
  239.     public function setFill($fill{
  240.         if($fill instanceof awColor or $fill instanceof awGradient{
  241.             $this->fill = $fill;
  242.         }
  243.     }
  244.     
  245.     /**
  246.      * Set an image
  247.      * Only for awMark::IMAGE type.
  248.      *
  249.      * @param Image An image
  250.      */
  251.     public function setImage(awImage $image{
  252.         $this->image = $image;
  253.     }
  254.     
  255.     /**
  256.      * Draw the mark
  257.      *
  258.      * @param awDriver $driver 
  259.      * @param awPoint $point Mark center
  260.      */
  261.     public function draw(awDriver $driverawPoint $point{
  262.     
  263.         // Hide marks ?
  264.         if($this->hide{
  265.             return;
  266.         }
  267.     
  268.         // Check if we can print marks
  269.         if($this->type !== NULL{
  270.         
  271.             $this->driver = $driver;
  272.             $realPoint $this->move->move($point->x$point->y);
  273.         
  274.             switch($this->type{
  275.             
  276.                 case awMark::CIRCLE :
  277.                     $this->drawCircle($realPoint);
  278.                     break;
  279.             
  280.                 case awMark::SQUARE :
  281.                     $this->drawSquare($realPoint);
  282.                     break;
  283.                 
  284.                 case awMark::TRIANGLE :
  285.                     $this->drawTriangle($realPoint);
  286.                     break;
  287.  
  288.                 case awMark::INVERTED_TRIANGLE :
  289.                     $this->drawTriangle($realPointTRUE);
  290.                     break;
  291.                 
  292.                 case awMark::RHOMBUS :
  293.                     $this->drawRhombus($realPoint);
  294.                     break;
  295.  
  296.                 case awMark::CROSS :
  297.                     $this->drawCross($realPoint);
  298.                     break;
  299.                     
  300.                 case awMark::PLUS :
  301.                     $this->drawCross($realPointTRUE);
  302.                     break;
  303.             
  304.                 case awMark::IMAGE :
  305.                     $this->drawImage($realPoint);
  306.                     break;
  307.                     
  308.                 case awMark::STAR :
  309.                     $this->changeType('star');
  310.                     $this->draw($driver$point);
  311.                     break;
  312.                     
  313.                 case awMark::PAPERCLIP :
  314.                     $this->changeType('paperclip');
  315.                     $this->draw($driver$point);
  316.                     break;
  317.                     
  318.                 case awMark::BOOK :
  319.                     $this->changeType('book');
  320.                     $this->draw($driver$point);
  321.                     break;
  322.                     
  323.             }
  324.         
  325.         }
  326.     
  327.     }
  328.     
  329.     protected function changeType($image{
  330.         $this->setType(awMARK::IMAGE);
  331.         $this->setImage(new awFileImage(ARTICHOW_IMAGE.DIRECTORY_SEPARATOR.$image.'.png'));
  332.     }
  333.     
  334.     protected function drawCircle(awPoint $point{
  335.         
  336.         $this->driver->filledEllipse(
  337.             $this->fill,
  338.             $point,
  339.             $this->size$this->size
  340.         );
  341.     
  342.         $this->border->ellipse(
  343.             $this->driver,
  344.             $point,
  345.             $this->size$this->size
  346.         );
  347.     
  348.     }
  349.     
  350.     protected function drawSquare(awPoint $point{
  351.     
  352.         list($x$y$point->getLocation();
  353.     
  354.         $x1 = (int)($x $this->size / 2);
  355.         $x2 $x1 $this->size;
  356.         $y1 = (int)($y $this->size / 2);
  357.         $y2 $y1 $this->size;
  358.         
  359.         $this->border->rectangle($this->drivernew awPoint($x1$y1)new awPoint($x2$y2));
  360.         
  361.         $size $this->border->visible(0;
  362.         
  363.         $this->driver->filledRectangle(
  364.             $this->fill,
  365.             new awLine(
  366.                 new awPoint($x1 $size$y1 $size),
  367.                 new awPoint($x2 $size$y2 $size)
  368.             )
  369.         );
  370.     
  371.     }
  372.     
  373.     protected function drawTriangle(awPoint $point$inverted FALSE{
  374.         
  375.         list($x$y$point->getLocation();
  376.         
  377.         $size $this->size;
  378.         
  379.         $triangle new awPolygon;
  380.         // Set default style and thickness
  381.         $triangle->setStyle(awPolygon::SOLID);
  382.         $triangle->setThickness(1);
  383.         
  384.         if($inverted === TRUE{
  385.             // Bottom of the triangle
  386.             $triangle->append(new awPoint($x$y $size sqrt(3)));
  387.         
  388.             // Upper left corner
  389.             $triangle->append(new awPoint($x $size 2$y $size (sqrt(3))));
  390.  
  391.             // Upper right corner
  392.             $triangle->append(new awPoint($x $size 2$y $size (sqrt(3))));
  393.         else {
  394.             // Top of the triangle
  395.             $triangle->append(new awPoint($x$y $size sqrt(3)));
  396.             
  397.             // Lower left corner
  398.             $triangle->append(new awPoint($x $size 2$y $size (sqrt(3))));
  399.     
  400.             // Lower right corner
  401.             $triangle->append(new awPoint($x $size 2$y $size (sqrt(3))));
  402.         }
  403.  
  404.         $this->driver->filledPolygon($this->fill$triangle);
  405.         
  406.         if($this->border->visible()) {            
  407.             $this->border->polygon($this->driver$triangle);
  408.         }
  409.     }
  410.     
  411.     protected function drawRhombus(awPoint $point{
  412.     
  413.         list($x$y$point->getLocation();
  414.  
  415.         $rhombus new awPolygon;
  416.         // Set default style and thickness
  417.         $rhombus->setStyle(awPolygon::SOLID);
  418.         $rhombus->setThickness(1);
  419.         
  420.         // Top of the rhombus
  421.         $rhombus->append(new awPoint($x$y $this->size / 2));
  422.         
  423.         // Right of the rhombus
  424.         $rhombus->append(new awPoint($x $this->size / 2$y));
  425.         
  426.         // Bottom of the rhombus
  427.         $rhombus->append(new awPoint($x$y $this->size / 2));
  428.         
  429.         // Left of the rhombus
  430.         $rhombus->append(new awPoint($x $this->size / 2$y));
  431.         
  432.         $this->driver->filledPolygon($this->fill$rhombus);
  433.         
  434.         if($this->border->visible()) {            
  435.             $this->border->polygon($this->driver$rhombus);
  436.         }
  437.     }
  438.     
  439.     protected function drawCross(awPoint $point$upright FALSE{
  440.     
  441.         list($x$y$point->getLocation();
  442.  
  443.         if($upright === TRUE{
  444.             $x11 = (int)($x);
  445.             $y11 = (int)($y $this->size / 2);
  446.             $x12 = (int)($x);
  447.             $y12 = (int)($y $this->size / 2);
  448.     
  449.             $y21 = (int)($y);
  450.             $y22 = (int)($y);
  451.         else {
  452.             $x11 = (int)($x $this->size / 2);
  453.             $y11 = (int)($y $this->size / 2);
  454.             $x12 = (int)($x $this->size / 2);
  455.             $y12 = (int)($y $this->size / 2);
  456.  
  457.             $y21 = (int)($y $this->size / 2);
  458.             $y22 = (int)($y $this->size / 2);
  459.         }
  460.             
  461.         $x21 = (int)($x $this->size / 2);
  462.         $x22 = (int)($x $this->size / 2);
  463.         
  464.         $this->driver->line(
  465.             $this->fill,
  466.             new awLine(
  467.                 new awPoint($x11$y11),
  468.                 new awPoint($x12$y12)
  469.             )
  470.         );
  471.         
  472.         $this->driver->line(
  473.             $this->fill,
  474.             new awLine(
  475.                 new awPoint($x21$y21),
  476.                 new awPoint($x22$y22)
  477.             )
  478.         );
  479.     }
  480.  
  481.     protected function drawImage(awPoint $point{
  482.         
  483.         if($this->image instanceof awImage{
  484.         
  485.             $width $this->image->width;
  486.             $height $this->image->height;
  487.     
  488.             list($x$y$point->getLocation();
  489.         
  490.             $x1 = (int)($x $width 2);
  491.             $x2 $x1 $width;
  492.             $y1 = (int)($y $width 2);
  493.             $y2 $y1 $height;
  494.         
  495.             $this->border->rectangle($this->drivernew awPoint($x1 1$y1 1)new awPoint($x2 1$y2 1));
  496.             
  497.             $this->driver->copyImage($this->imagenew awPoint($x1$y1)new awPoint($x2$y2));
  498.             
  499.         }
  500.     
  501.     }
  502.  
  503. }
  504.  
  505. registerClass('Mark');
  506. ?>

Documentation generated on Fri, 16 Oct 2009 09:36:12 +0200 by phpDocumentor 1.4.1