|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace eXpansion\Framework\Gui\Components; |
|
4
|
|
|
|
|
5
|
|
|
use FML\Controls\Quad; |
|
6
|
|
|
use FML\Script\Script; |
|
7
|
|
|
|
|
8
|
|
|
class uiLine extends abstractUiElement |
|
9
|
|
|
{ |
|
10
|
|
|
public $length = 0; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* @var float |
|
14
|
|
|
*/ |
|
15
|
|
|
private $x; |
|
16
|
|
|
/** |
|
17
|
|
|
* @var float |
|
18
|
|
|
*/ |
|
19
|
|
|
private $y; |
|
20
|
|
|
/** |
|
21
|
|
|
* @var float |
|
22
|
|
|
*/ |
|
23
|
|
|
private $tx; |
|
24
|
|
|
/** |
|
25
|
|
|
* @var float |
|
26
|
|
|
*/ |
|
27
|
|
|
private $ty; |
|
28
|
|
|
|
|
29
|
|
|
private $color = "f00"; |
|
30
|
|
|
|
|
31
|
|
|
private $stoke = 0.25; |
|
32
|
|
|
|
|
33
|
|
|
private $to = false; |
|
34
|
|
|
|
|
35
|
|
|
private $rotate = 0; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* uiLine constructor. |
|
39
|
|
|
* @param float $x |
|
40
|
|
|
* @param float $y |
|
41
|
|
|
*/ |
|
42
|
1 |
|
public function __construct($x, $y) |
|
43
|
|
|
{ |
|
44
|
|
|
|
|
45
|
1 |
|
$this->x = $x + 180.; |
|
46
|
1 |
|
$this->y = $y + 90.; |
|
47
|
1 |
|
} |
|
48
|
|
|
|
|
49
|
|
|
public function to($tx, $ty) |
|
50
|
|
|
{ |
|
51
|
|
|
$this->tx = $tx + 180.; |
|
52
|
|
|
$this->ty = $ty + 90.; |
|
53
|
|
|
$this->to = true; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* Prepare the given Script for rendering by adding the needed Labels, etc. |
|
58
|
|
|
* |
|
59
|
|
|
* @param Script $script Script to prepare |
|
60
|
|
|
* @return static |
|
61
|
|
|
*/ |
|
62
|
|
|
public function prepare(Script $script) |
|
63
|
|
|
{ |
|
64
|
|
|
// TODO: Implement prepare() method. |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* Render the XML element |
|
69
|
|
|
* |
|
70
|
|
|
* @param \DOMDocument $domDocument DOMDocument for which the XML element should be rendered |
|
71
|
|
|
* @return \DOMElement |
|
72
|
|
|
*/ |
|
73
|
1 |
|
public function render(\DOMDocument $domDocument) |
|
74
|
|
|
{ |
|
75
|
1 |
|
$quad = new Quad(); |
|
76
|
1 |
|
$quad->setPosition($this->x - 180, $this->y - 90); |
|
77
|
1 |
|
$quad->setBackgroundColor($this->color); |
|
78
|
1 |
|
if ($this->to) { |
|
79
|
|
|
$quad->setWidth($this->calcLength())->setHeight($this->stoke); |
|
80
|
|
|
$quad->setRotation($this->calcAngle()); |
|
81
|
|
|
} else { |
|
82
|
1 |
|
$quad->setWidth($this->length)->setHeight($this->stoke); |
|
83
|
1 |
|
$quad->setRotation($this->rotate); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
1 |
|
return $quad->render($domDocument); |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
public function calcLength() |
|
90
|
|
|
{ |
|
91
|
|
|
|
|
92
|
|
|
$vx = $this->tx - $this->x; |
|
93
|
|
|
$vy = $this->ty - $this->y; |
|
94
|
|
|
|
|
95
|
|
|
return sqrt(($vx * $vx) + ($vy * $vy)); |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
public function calcAngle() |
|
99
|
|
|
{ |
|
100
|
|
|
$angle = (float)(atan2($this->x - $this->tx, $this->y - $this->ty)); |
|
101
|
|
|
$angle += pi() / 2.0; |
|
102
|
|
|
|
|
103
|
|
|
return rad2deg($angle); |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
/** |
|
107
|
|
|
* @return float |
|
108
|
|
|
*/ |
|
109
|
|
|
public function getStoke() |
|
110
|
|
|
{ |
|
111
|
|
|
return $this->stoke; |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
/** |
|
115
|
|
|
* @param float $stoke |
|
116
|
|
|
*/ |
|
117
|
|
|
public function setStoke($stoke) |
|
118
|
|
|
{ |
|
119
|
|
|
$this->stoke = $stoke; |
|
120
|
|
|
|
|
121
|
|
|
return $this; |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
/** |
|
125
|
|
|
* @return string |
|
126
|
|
|
*/ |
|
127
|
|
|
public function getColor() |
|
128
|
|
|
{ |
|
129
|
|
|
return $this->color; |
|
130
|
|
|
} |
|
131
|
|
|
|
|
132
|
|
|
/** |
|
133
|
|
|
* @param string $color |
|
134
|
|
|
*/ |
|
135
|
|
|
public function setColor($color) |
|
136
|
|
|
{ |
|
137
|
|
|
$this->color = $color; |
|
138
|
|
|
|
|
139
|
|
|
return $this; |
|
140
|
|
|
} |
|
141
|
|
|
|
|
142
|
|
|
/** |
|
143
|
|
|
* @return int |
|
144
|
|
|
*/ |
|
145
|
|
|
public function getRotate() |
|
146
|
|
|
{ |
|
147
|
|
|
return $this->rotate; |
|
148
|
|
|
} |
|
149
|
|
|
|
|
150
|
|
|
/** |
|
151
|
|
|
* @param int $rotate |
|
152
|
|
|
*/ |
|
153
|
|
|
public function setRotate($rotate) |
|
154
|
|
|
{ |
|
155
|
|
|
$this->rotate = $rotate; |
|
156
|
|
|
|
|
157
|
|
|
return $this; |
|
158
|
|
|
} |
|
159
|
|
|
|
|
160
|
|
|
/** |
|
161
|
|
|
* @return int |
|
162
|
|
|
*/ |
|
163
|
|
|
public function getLength() |
|
164
|
|
|
{ |
|
165
|
|
|
return $this->length; |
|
166
|
|
|
} |
|
167
|
|
|
|
|
168
|
|
|
/** |
|
169
|
|
|
* @param int $length |
|
170
|
|
|
*/ |
|
171
|
|
|
public function setLength($length) |
|
172
|
|
|
{ |
|
173
|
|
|
$this->length = $length; |
|
174
|
|
|
|
|
175
|
|
|
return $this; |
|
176
|
|
|
} |
|
177
|
|
|
|
|
178
|
|
|
} |
|
179
|
|
|
|