[ Index ] |
|
Code source de phpMyVisites 2.3 |
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 /** 11 * Grid 12 * 13 * @package Artichow 14 */ 15 class awGrid { 16 17 /** 18 * Vertical lines of the grid 19 * 20 * @var array 21 */ 22 private $xgrid = array(); 23 24 /** 25 * Horizontal lines of the grid 26 * 27 * @var array 28 */ 29 private $ygrid = array(); 30 31 /** 32 * Is the component grid hidden ? 33 * 34 * @var bool 35 */ 36 private $hide = FALSE; 37 38 /** 39 * Are horizontal lines hidden ? 40 * 41 * @var bool 42 */ 43 private $hideHorizontal = FALSE; 44 45 /** 46 * Are vertical lines hidden ? 47 * 48 * @var bool 49 */ 50 private $hideVertical = FALSE; 51 52 /** 53 * Grid color 54 * 55 * @var Color 56 */ 57 private $color; 58 59 /** 60 * Grid space 61 * 62 * @var int 63 */ 64 private $space; 65 66 /** 67 * Line type 68 * 69 * @var int 70 */ 71 private $type = awLine::SOLID; 72 73 /** 74 * Grid interval 75 * 76 * @var int 77 */ 78 private $interval = array(1, 1); 79 80 /** 81 * Grid background color 82 * 83 * @var Color 84 */ 85 private $background; 86 87 /** 88 * Build the factory 89 */ 90 public function __construct() { 91 92 // Set a grid default color 93 $this->color = new awColor(210, 210, 210); 94 $this->background = new awColor(255, 255, 255, 100); 95 96 } 97 98 /** 99 * Hide grid ? 100 * 101 * @param bool $hide 102 */ 103 public function hide($hide = TRUE) { 104 $this->hide = (bool)$hide; 105 } 106 107 /** 108 * Hide horizontal lines ? 109 * 110 * @param bool $hideHorizontal 111 */ 112 public function hideHorizontal($hide = TRUE) { 113 $this->hideHorizontal = (bool)$hide; 114 } 115 116 /** 117 * Hide vertical lines ? 118 * 119 * @param bool $hideVertical 120 */ 121 public function hideVertical($hide = TRUE) { 122 $this->hideVertical = (bool)$hide; 123 } 124 125 /** 126 * Change grid color 127 * 128 * @param awColor $color 129 */ 130 public function setColor(awColor $color) { 131 $this->color = $color; 132 } 133 134 /** 135 * Remove grid background 136 */ 137 public function setNoBackground() { 138 $this->background = NULL; 139 } 140 141 /** 142 * Change grid background color 143 * 144 * @param awColor $color 145 */ 146 public function setBackgroundColor(awColor $color) { 147 $this->background = $color; 148 } 149 150 /** 151 * Change line type 152 * 153 * @param int $type 154 */ 155 public function setType($type) { 156 $this->type = (int)$type; 157 } 158 159 /** 160 * Change grid interval 161 * 162 * @param int $hInterval 163 * @param int $vInterval 164 */ 165 public function setInterval($hInterval, $vInterval) { 166 $this->interval = array((int)$hInterval, (int)$vInterval); 167 } 168 169 /** 170 * Set grid space 171 * 172 * @param int $left Left space in pixels 173 * @param int $right Right space in pixels 174 * @param int $top Top space in pixels 175 * @param int $bottom Bottom space in pixels 176 */ 177 public function setSpace($left, $right, $top, $bottom) { 178 $this->space = array((int)$left, (int)$right, (int)$top, (int)$bottom); 179 } 180 181 /** 182 * Change the current grid 183 * 184 * @param array $xgrid Vertical lines 185 * @param array $ygrid Horizontal lines 186 */ 187 public function setGrid($xgrid, $ygrid) { 188 189 $this->xgrid = $xgrid; 190 $this->ygrid = $ygrid; 191 192 } 193 194 /** 195 * Draw grids 196 * 197 * @param awDrawer $drawer A drawer object 198 * @param int $x1 199 * @param int $y1 200 * @param int $x2 201 * @param int $y2 202 */ 203 public function draw(awDrawer $drawer, $x1, $y1, $x2, $y2) { 204 205 if($this->background instanceof awColor) { 206 207 // Draw background color 208 $drawer->filledRectangle( 209 $this->background, 210 awLine::build($x1, $y1, $x2, $y2) 211 ); 212 213 $this->background->free(); 214 215 } 216 217 if($this->hide === FALSE) { 218 219 $this->drawGrid( 220 $drawer, 221 $this->color, 222 $this->hideVertical ? array() : $this->xgrid, 223 $this->hideHorizontal ? array() : $this->ygrid, 224 $x1, $y1, $x2, $y2, 225 $this->type, 226 $this->space, 227 $this->interval[0], 228 $this->interval[1] 229 ); 230 231 } 232 233 $this->color->free(); 234 235 } 236 237 private function drawGrid( 238 awDrawer $drawer, awColor $color, 239 $nx, $ny, $x1, $y1, $x2, $y2, 240 $type, $space, $hInterval, $vInterval 241 ) { 242 243 list($left, $right, $top, $bottom) = $space; 244 245 $width = $x2 - $x1 - $left - $right; 246 $height = $y2 - $y1 - $top - $bottom; 247 248 foreach($nx as $key => $n) { 249 250 if(($key % $vInterval) === 0) { 251 252 $pos = (int)round($x1 + $left + $n * $width); 253 $drawer->line( 254 $color, 255 new awLine( 256 new awPoint($pos, $y1), 257 new awPoint($pos, $y2), 258 $type 259 ) 260 ); 261 262 } 263 264 } 265 266 foreach($ny as $key => $n) { 267 268 if(($key % $hInterval) === 0) { 269 270 $pos = (int)round($y1 + $top + $n * $height); 271 $drawer->line( 272 $color, 273 new awLine( 274 new awPoint($x1, $pos), 275 new awPoint($x2, $pos), 276 $type 277 ) 278 ); 279 280 } 281 282 } 283 284 } 285 286 } 287 288 registerClass('Grid'); 289 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Mon Nov 26 14:10:01 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |