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