[ 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("SHADOW_LEFT_TOP", 1); 15 define("SHADOW_LEFT_BOTTOM", 2); 16 define("SHADOW_RIGHT_TOP", 3); 17 define("SHADOW_RIGHT_BOTTOM", 4); 18 19 define("SHADOW_IN", 1); 20 define("SHADOW_OUT", 2); 21 22 /* </php4> */ 23 24 /** 25 * Draw shadows 26 * 27 */ 28 class awShadow { 29 30 /** 31 * Shadow on left and top sides 32 * 33 * @var int 34 */ 35 const LEFT_TOP = 1; 36 37 /** 38 * Shadow on left and bottom sides 39 * 40 * @var int 41 */ 42 const LEFT_BOTTOM = 2; 43 44 45 /** 46 * Shadow on right and top sides 47 * 48 * @var int 49 */ 50 const RIGHT_TOP = 3; 51 52 /** 53 * Shadow on right and bottom sides 54 * 55 * @var int 56 */ 57 const RIGHT_BOTTOM = 4; 58 59 /** 60 * In mode 61 * 62 * @var int 63 */ 64 const IN = 1; 65 66 /** 67 * Out mode 68 * 69 * @var int 70 */ 71 const OUT = 2; 72 73 /** 74 * Shadow size 75 * 76 * @var int 77 */ 78 private $size = 0; 79 80 /** 81 * Hide shadow ? 82 * 83 * @var bool 84 */ 85 protected $hide = FALSE; 86 87 /** 88 * Shadow color 89 * 90 * @var Color 91 */ 92 private $color; 93 94 /** 95 * Shadow position 96 * 97 * @var int 98 */ 99 private $position; 100 101 /** 102 * Smooth shadow ? 103 * 104 * @var bool 105 */ 106 private $smooth = FALSE; 107 108 /** 109 * Shadow constructor 110 * 111 * @param int $position Shadow position 112 */ 113 public function __construct($position) { 114 $this->setPosition($position); 115 } 116 117 /** 118 * Hide shadow ? 119 * 120 * @param bool $hide 121 */ 122 public function hide($hide = TRUE) { 123 $this->hide = (bool)$hide; 124 } 125 126 /** 127 * Show shadow ? 128 * 129 * @param bool $show 130 */ 131 public function show($show = TRUE) { 132 $this->hide = (bool)!$show; 133 } 134 135 /** 136 * Change shadow size 137 * 138 * @param int $size 139 * @param bool $smooth Smooth the shadow (facultative argument) 140 */ 141 public function setSize($size, $smooth = NULL) { 142 $this->size = (int)$size; 143 if($smooth !== NULL) { 144 $this->smooth($smooth); 145 } 146 } 147 148 /** 149 * Change shadow color 150 * 151 * @param awColor $color 152 */ 153 public function setColor(awColor $color) { 154 $this->color = $color; 155 } 156 157 /** 158 * Change shadow position 159 * 160 * @param int $position 161 */ 162 public function setPosition($position) { 163 $this->position = (int)$position; 164 } 165 166 /** 167 * Smooth shadow ? 168 * 169 * @param bool $smooth 170 */ 171 public function smooth($smooth) { 172 $this->smooth = (bool)$smooth; 173 } 174 175 /** 176 * Get the space taken by the shadow 177 * 178 * @return Side 179 */ 180 public function getSpace() { 181 182 return new awSide( 183 ($this->position === awShadow::LEFT_TOP or $this->position === awShadow::LEFT_BOTTOM) ? $this->size : 0, 184 ($this->position === awShadow::RIGHT_TOP or $this->position === awShadow::RIGHT_BOTTOM) ? $this->size : 0, 185 ($this->position === awShadow::LEFT_TOP or $this->position === awShadow::RIGHT_TOP) ? $this->size : 0, 186 ($this->position === awShadow::LEFT_BOTTOM or $this->position === awShadow::RIGHT_BOTTOM) ? $this->size : 0 187 ); 188 189 } 190 191 /** 192 * Draw shadow 193 * 194 * @param awDrawer $drawer 195 * @param awPoint $p1 Top-left point 196 * @param awPoint $p2 Right-bottom point 197 * @param int Drawing mode 198 */ 199 public function draw(awDrawer $drawer, awPoint $p1, awPoint $p2, $mode) { 200 201 if($this->hide) { 202 return; 203 } 204 205 if($this->size <= 0) { 206 return; 207 } 208 209 $drawer = clone $drawer; 210 211 $color = ($this->color instanceof awColor) ? $this->color : new awColor(125, 125, 125); 212 213 switch($this->position) { 214 215 case awShadow::RIGHT_BOTTOM : 216 217 if($mode === awShadow::OUT) { 218 $t1 = $p1->move(0, 0); 219 $t2 = $p2->move($this->size + 1, $this->size + 1); 220 } else { // PHP 4 compatibility 221 $t1 = $p1->move(0, 0); 222 $t2 = $p2->move(0, 0); 223 } 224 225 $width = $t2->x - $t1->x; 226 $height = $t2->y - $t1->y; 227 228 $drawer->setAbsPosition($t1->x + $drawer->x, $t1->y + $drawer->y); 229 230 $drawer->filledRectangle( 231 $color, 232 new awLine( 233 new awPoint($width - $this->size, $this->size), 234 new awPoint($width - 1, $height - 1) 235 ) 236 ); 237 238 $drawer->filledRectangle( 239 $color, 240 new awLine( 241 new awPoint($this->size, $height - $this->size), 242 new awPoint($width - $this->size - 1, $height - 1) 243 ) 244 ); 245 246 $this->smoothPast($drawer, $color, $width, $height); 247 248 break; 249 250 case awShadow::LEFT_TOP : 251 252 if($mode === awShadow::OUT) { 253 $t1 = $p1->move(- $this->size, - $this->size); 254 $t2 = $p2->move(0, 0); 255 } else { // PHP 4 compatibility 256 $t1 = $p1->move(0, 0); 257 $t2 = $p2->move(0, 0); 258 } 259 260 $width = $t2->x - $t1->x; 261 $height = $t2->y - $t1->y; 262 263 $drawer->setAbsPosition($t1->x + $drawer->x, $t1->y + $drawer->y); 264 265 $height = max($height + 1, $this->size); 266 267 $drawer->filledRectangle( 268 $color, 269 new awLine( 270 new awPoint(0, 0), 271 new awPoint($this->size - 1, $height - $this->size - 1) 272 ) 273 ); 274 275 $drawer->filledRectangle( 276 $color, 277 new awLine( 278 new awPoint($this->size, 0), 279 new awPoint($width - $this->size - 1, $this->size - 1) 280 ) 281 ); 282 283 $this->smoothPast($drawer, $color, $width, $height); 284 285 break; 286 287 case awShadow::RIGHT_TOP : 288 289 if($mode === awShadow::OUT) { 290 $t1 = $p1->move(0, - $this->size); 291 $t2 = $p2->move($this->size + 1, 0); 292 } else { // PHP 4 compatibility 293 $t1 = $p1->move(0, 0); 294 $t2 = $p2->move(0, 0); 295 } 296 297 $width = $t2->x - $t1->x; 298 $height = $t2->y - $t1->y; 299 300 $drawer->setAbsPosition($t1->x + $drawer->x, $t1->y + $drawer->y); 301 302 $height = max($height + 1, $this->size); 303 304 $drawer->filledRectangle( 305 $color, 306 new awLine( 307 new awPoint($width - $this->size, 0), 308 new awPoint($width - 1, $height - $this->size - 1) 309 ) 310 ); 311 312 $drawer->filledRectangle( 313 $color, 314 new awLine( 315 new awPoint($this->size, 0), 316 new awPoint($width - $this->size - 1, $this->size - 1) 317 ) 318 ); 319 320 $this->smoothFuture($drawer, $color, $width, $height); 321 322 break; 323 324 case awShadow::LEFT_BOTTOM : 325 326 if($mode === awShadow::OUT) { 327 $t1 = $p1->move(- $this->size, 0); 328 $t2 = $p2->move(0, $this->size + 1); 329 } else { // PHP 4 compatibility 330 $t1 = $p1->move(0, 0); 331 $t2 = $p2->move(0, 0); 332 } 333 334 $width = $t2->x - $t1->x; 335 $height = $t2->y - $t1->y; 336 337 $drawer->setAbsPosition($t1->x + $drawer->x, $t1->y + $drawer->y); 338 339 $drawer->filledRectangle( 340 $color, 341 new awLine( 342 new awPoint(0, $this->size), 343 new awPoint($this->size - 1, $height - 1) 344 ) 345 ); 346 347 $drawer->filledRectangle( 348 $color, 349 new awLine( 350 new awPoint($this->size, $height - $this->size), 351 new awPoint($width - $this->size - 1, $height - 1) 352 ) 353 ); 354 355 $this->smoothFuture($drawer, $color, $width, $height); 356 357 break; 358 359 } 360 361 } 362 363 private function smoothPast(awDrawer $drawer, awColor $color, $width, $height) { 364 365 if($this->smooth) { 366 367 for($i = 0; $i < $this->size; $i++) { 368 for($j = 0; $j <= $i; $j++) { 369 $drawer->point( 370 $color, 371 new awPoint($i, $j + $height - $this->size) 372 ); 373 } 374 } 375 376 for($i = 0; $i < $this->size; $i++) { 377 for($j = 0; $j <= $i; $j++) { 378 $drawer->point( 379 $color, 380 new awPoint($width - $this->size + $j, $i) 381 ); 382 } 383 } 384 385 } 386 387 } 388 389 private function smoothFuture(awDrawer $drawer, awColor $color, $width, $height) { 390 391 if($this->smooth) { 392 393 for($i = 0; $i < $this->size; $i++) { 394 for($j = 0; $j <= $i; $j++) { 395 $drawer->point( 396 $color, 397 new awPoint($i, $this->size - $j - 1) 398 ); 399 } 400 } 401 402 for($i = 0; $i < $this->size; $i++) { 403 for($j = 0; $j <= $i; $j++) { 404 $drawer->point( 405 $color, 406 new awPoint($width - $this->size + $j, $height - $i - 1) 407 ); 408 } 409 } 410 411 } 412 } 413 414 } 415 416 registerClass('Shadow'); 417 ?>
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 |