[ Index ]
 

Code source de phpMyVisites 2.3

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/libs/artichow/php5/inc/ -> Mark.class.php (source)

   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  /* <php4> */
  11  
  12  define("MARK_CIRCLE", 1);
  13  define("MARK_SQUARE", 2);
  14  define("MARK_IMAGE", 3);
  15  define("MARK_STAR", 4);
  16  define("MARK_PAPERCLIP", 5);
  17  define("MARK_BOOK", 6);
  18  
  19  /* </php4> */
  20   
  21  /**
  22   * Draw marks
  23   *
  24   * @package Artichow
  25   */
  26  class awMark {
  27  
  28      /**
  29       * Circle mark
  30       *
  31       * @var int
  32       */
  33      const CIRCLE = 1;
  34  
  35      /**
  36       * Quare mark
  37       *
  38       * @var int
  39       */
  40      const SQUARE = 2;
  41  
  42      /**
  43       * Image mark
  44       *
  45       * @var int
  46       */
  47      const IMAGE = 3;
  48  
  49      /**
  50       * Star mark
  51       *
  52       * @var int
  53       */
  54      const STAR = 4;
  55  
  56      /**
  57       * Paperclip mark
  58       *
  59       * @var int
  60       */
  61      const PAPERCLIP = 5;
  62  
  63      /**
  64       * Book mark
  65       *
  66       * @var int
  67       */
  68      const BOOK = 6;
  69  
  70      /**
  71       * Must marks be hidden ?
  72       *
  73       * @var bool
  74       */
  75      protected $hide;
  76  
  77      /**
  78       * Mark type
  79       *
  80       * @var int
  81       */
  82      protected $type;
  83  
  84      /**
  85       * Mark size
  86       *
  87       * @var int
  88       */
  89      protected $size = 8;
  90  
  91      /**
  92       * Fill mark
  93       *
  94       * @var Color, Gradient
  95       */
  96      protected $fill;
  97  
  98      /**
  99       * Mark image
 100       *
 101       * @var Image
 102       */
 103      protected $image;
 104  
 105      /**
 106       * To draw marks
 107       *
 108       * @var Drawer
 109       */
 110      protected $drawer;
 111  
 112      /**
 113       * Move position from this vector
 114       *
 115       * @var Point
 116       */
 117      protected $move;
 118      
 119      /**
 120       * Marks border
 121       *
 122       * @var Border
 123       */
 124      public $border;
 125  
 126      /**
 127       * Build the mark
 128       */
 129  	public function __construct() {
 130          
 131          $this->fill = new awColor(255, 0, 0, 0);
 132          $this->border = new awBorder;
 133          $this->border->hide();
 134          
 135          $this->move = new awPoint(0, 0);
 136      
 137      }
 138      
 139      /**
 140       * Change mark position
 141       *
 142       * @param int $x Add this interval to X coord
 143       * @param int $y Add this interval to Y coord
 144       */
 145  	public function move($x, $y) {
 146      
 147          $this->move = $this->move->move($x, $y);
 148      
 149      }
 150      
 151      /**
 152       * Hide marks ?
 153       *
 154       * @param bool $hide TRUE to hide marks, FALSE otherwise
 155       */
 156  	public function hide($hide = TRUE) {
 157          $this->hide = (bool)$hide;
 158      }
 159      
 160      /**
 161       * Show marks ?
 162       *
 163       * @param bool $show
 164       */
 165  	public function show($show = TRUE) {
 166          $this->hide = (bool)!$show;
 167      }
 168      
 169      /**
 170       * Change mark type
 171       *
 172       * @param int $size Size in pixels
 173       */
 174  	public function setSize($size) {
 175          $this->size = (int)$size;
 176      }
 177      
 178      /**
 179       * Change mark type
 180       *
 181       * @param int $type New mark type
 182       * @param int $size Mark size (can be NULL)
 183       */
 184  	public function setType($type, $size = NULL) {
 185          $this->type = (int)$type;
 186          if($size !== NULL) {
 187              $this->setSize($size);
 188          }
 189      }
 190      
 191      /**
 192       * Fill the mark with a color or a gradient
 193       *
 194       * @param mixed $fill A color or a gradient
 195       */
 196  	public function setFill($fill) {
 197          if($fill instanceof awColor or $fill instanceof awGradient) {
 198              $this->fill = $fill;
 199          }
 200      }
 201      
 202      /**
 203       * Set an image
 204       * Only for awMark::IMAGE type.
 205       *
 206       * @param Image An image
 207       */
 208  	public function setImage(awImage $image) {
 209          $this->image = $image;
 210      }
 211      
 212      /**
 213       * Draw the mark
 214       *
 215       * @param awDrawer $drawer
 216       * @param awPoint $point Mark center
 217       */
 218  	public function draw(awDrawer $drawer, awPoint $point) {
 219      
 220          // Hide marks ?
 221          if($this->hide) {
 222              return;
 223          }
 224      
 225          // Check if we can print marks
 226          if($this->type !== NULL) {
 227          
 228              $this->drawer = $drawer;
 229              $realPoint = $this->move->move($point->x, $point->y);
 230          
 231              switch($this->type) {
 232              
 233                  case awMark::CIRCLE :
 234                      $this->drawCircle($realPoint);
 235                      break;
 236              
 237                  case awMark::SQUARE :
 238                      $this->drawSquare($realPoint);
 239                      break;
 240              
 241                  case awMark::IMAGE :
 242                      $this->drawImage($realPoint);
 243                      break;
 244                      
 245                  case awMark::STAR :
 246                      $this->changeType('star');
 247                      $this->draw($drawer, $point);
 248                      break;
 249                      
 250                  case awMark::PAPERCLIP :
 251                      $this->changeType('paperclip');
 252                      $this->draw($drawer, $point);
 253                      break;
 254                      
 255                  case awMark::BOOK :
 256                      $this->changeType('book');
 257                      $this->draw($drawer, $point);
 258                      break;
 259                      
 260              }
 261          
 262          }
 263      
 264      }
 265      
 266  	protected function changeType($image) {
 267          $this->setType(awMARK::IMAGE);
 268          $this->setImage(new awFileImage(ARTICHOW_IMAGE.DIRECTORY_SEPARATOR.$image.'.png'));
 269      }
 270      
 271  	protected function drawCircle(awPoint $point) {
 272          
 273          $this->drawer->filledEllipse(
 274              $this->fill,
 275              $point,
 276              $this->size, $this->size
 277          );
 278      
 279          $this->border->ellipse(
 280              $this->drawer,
 281              $point,
 282              $this->size, $this->size
 283          );
 284      
 285      }
 286      
 287  	protected function drawSquare(awPoint $point) {
 288      
 289          list($x, $y) = $point->getLocation();
 290      
 291          $x1 = (int)($x - $this->size / 2);
 292          $x2 = $x1 + $this->size;
 293          $y1 = (int)($y - $this->size / 2);
 294          $y2 = $y1 + $this->size;
 295          
 296          $this->border->rectangle($this->drawer, new awPoint($x1, $y1), new awPoint($x2, $y2));
 297          
 298          $size = $this->border->visible() ? 1 : 0;
 299          
 300          $this->drawer->filledRectangle(
 301              $this->fill,
 302              new awLine(
 303                  new awPoint($x1 + $size, $y1 + $size),
 304                  new awPoint($x2 - $size, $y2 - $size)
 305              )
 306          );
 307      
 308      }
 309      
 310  	protected function drawImage(awPoint $point) {
 311          
 312          if($this->image instanceof awImage) {
 313          
 314              $width = $this->image->width;
 315              $height = $this->image->height;
 316      
 317              list($x, $y) = $point->getLocation();
 318          
 319              $x1 = (int)($x - $width / 2);
 320              $x2 = $x1 + $width;
 321              $y1 = (int)($y - $width / 2);
 322              $y2 = $y1 + $height;
 323          
 324              $this->border->rectangle($this->drawer, new awPoint($x1 - 1, $y1 - 1), new awPoint($x2 + 1, $y2 + 1));
 325              
 326              $this->drawer->copyImage($this->image, new awPoint($x1, $y1), new awPoint($x2, $y2));
 327              
 328          }
 329      
 330      }
 331  
 332  }
 333  
 334  registerClass('Mark');
 335  ?>


Généré le : Mon Nov 26 14:10:01 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics