Subversion Repositories Applications.gtt

Rev

Rev 61 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
60 jpm 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
/**
13
 * Draw border
14
 *
15
 * @package Artichow
16
 */
17
class awBorder {
18
 
19
	/**
20
	 * Border color
21
	 *
22
	 * @var Color
23
	 */
24
	protected $color;
25
 
26
	/**
27
	 * Hide border ?
28
	 *
29
	 * @var bool
30
	 */
31
	protected $hide = FALSE;
32
 
33
	/**
34
	 * Border line style
35
	 *
36
	 * @var int
37
	 */
38
	protected $style;
39
 
40
	/**
41
	 * Build the border
42
	 *
43
	 * @param awColor $color Border color
44
	 * @param int $style Border style
45
	 */
46
	public function __construct($color = NULL, $style = awLine::SOLID) {
47
 
48
		$this->setStyle($style);
49
 
50
		if($color instanceof awColor) {
51
			$this->setColor($color);
52
		} else {
53
			$this->setColor(new awBlack);
54
		}
55
 
56
	}
57
 
58
	/**
59
	 * Change border color
60
	 * This method automatically shows the border if it is hidden
61
	 *
62
	 * @param awColor $color
63
	 */
64
	public function setColor(awColor $color) {
65
		$this->color = $color;
66
		$this->show();
67
	}
68
 
69
	/**
70
	 * Change border style
71
	 *
72
	 * @param int $style
73
	 */
74
	public function setStyle($style) {
75
		$this->style = (int)$style;
76
	}
77
 
78
	/**
79
	 * Hide border ?
80
	 *
81
	 * @param bool $hide
82
	 */
83
	public function hide($hide = TRUE) {
84
		$this->hide = (bool)$hide;
85
	}
86
 
87
	/**
88
	 * Show border ?
89
	 *
90
	 * @param bool $show
91
	 */
92
	public function show($show = TRUE) {
93
		$this->hide = (bool)!$show;
94
	}
95
 
96
	/**
97
	 * Is the border visible ?
98
	 *
99
	 * @return bool
100
	 */
101
	public function visible() {
102
		return !$this->hide;
103
	}
104
 
105
	/**
106
	 * Draw border as a rectangle
107
	 *
108
	 * @param awDriver $driver
109
	 * @param awPoint $p1 Top-left corner
110
	 * @param awPoint $p2 Bottom-right corner
111
	 */
112
	public function rectangle(awDriver $driver, awPoint $p1, awPoint $p2) {
113
 
114
		// Border is hidden
115
		if($this->hide) {
116
			return;
117
		}
118
 
119
		$line = new awLine;
120
		$line->setStyle($this->style);
121
		$line->setLocation($p1, $p2);
122
 
123
		$driver->rectangle($this->color, $line);
124
 
125
	}
126
 
127
	/**
128
	 * Draw border as an ellipse
129
	 *
130
	 * @param awDriver $driver
131
	 * @param awPoint $center Ellipse center
132
	 * @param int $width Ellipse width
133
	 * @param int $height Ellipse height
134
	 */
135
	public function ellipse(awDriver $driver, awPoint $center, $width, $height) {
136
 
137
		// Border is hidden
138
		if($this->hide) {
139
			return;
140
		}
141
 
142
		switch($this->style) {
143
 
144
			case awLine::SOLID :
145
				$driver->ellipse($this->color, $center, $width, $height);
146
				break;
147
 
148
			default :
149
				awImage::drawError("Class Border: Dashed and dotted borders and not yet implemented on ellipses.");
150
				break;
151
 
152
		}
153
 
154
 
155
	}
156
 
157
	/**
158
	 * Draw border as a polygon
159
	 *
160
	 * @param awDriver $driver A Driver object
161
	 * @param awPolygon $polygon A Polygon object
162
	 */
163
	public function polygon(awDriver $driver, awPolygon $polygon) {
164
 
165
		// Border is hidden
166
		if($this->hide) {
167
			return;
168
		}
169
 
170
		$polygon->setStyle($this->style);
171
		$driver->polygon($this->color, $polygon);
172
 
173
		// In case of Line::SOLID, Driver::polygon() uses imagepolygon()
174
		// which automatically closes the shape. In any other case,
175
		// we have to do it manually here.
176
		if($this->style !== Line::SOLID) {
177
			$this->closePolygon($driver, $polygon);
178
		}
179
	}
180
 
181
	/**
182
	 * Draws the last line of a Polygon, between the first and last point
183
	 *
184
	 * @param awDriver $driver A Driver object
185
	 * @param awPolygon $polygon The polygon object to close
186
	 */
187
	private function closePolygon(awDriver $driver, awPolygon $polygon) {
188
		$first = $polygon->get(0);
189
		$last  = $polygon->get($polygon->count() - 1);
190
 
191
		$line = new awLine($first, $last, $this->style, $polygon->getThickness());
192
		$driver->line($this->color, $line);
193
	}
194
 
195
}
196
 
197
registerClass('Border');
198
?>