1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10:
11:
12: namespace ManiaLive\Gui\Controls;
13:
14: use ManiaLib\Gui\Elements\Bgs1;
15: use ManiaLib\Gui\Elements\Icons64x64_1;
16: use ManiaLib\Gui\Elements\Label;
17:
18: 19: 20: 21: 22: 23:
24: class PageNavigator extends \ManiaLive\Gui\Control
25: {
26: public $arrowNext;
27: public $arrowPrev;
28: public $arrowFastNext;
29: public $arrowFastPrev;
30: public $arrowLast;
31: public $arrowFirst;
32: public $text;
33: public $textBg;
34:
35: public $arrowNoneStyle = Icons64x64_1::ClipPause;
36: public $arrowNextStyle = Icons64x64_1::ArrowNext;
37: public $arrowPrevStyle = Icons64x64_1::ArrowPrev;
38: public $arrowFastNextStyle = Icons64x64_1::ArrowFastNext;
39: public $arrowFastPrevStyle = Icons64x64_1::ArrowFastPrev;
40: public $arrowFirstStyle = Icons64x64_1::ArrowFirst;
41: public $arrowLastStyle = Icons64x64_1::ArrowLast;
42:
43: protected $showLast;
44: protected $showFastNext;
45: protected $showText;
46: protected $pageNumber;
47: protected $currentPage;
48:
49: function __construct($iconSize=8)
50: {
51: $this->sizeX = $iconSize * 4.5;
52: $this->sizeY = $iconSize;
53:
54: $this->arrowNext = new Icons64x64_1($iconSize);
55: $this->arrowPrev = new Icons64x64_1($iconSize);
56: $this->arrowFastNext = new Icons64x64_1($iconSize);
57: $this->arrowFastPrev = new Icons64x64_1($iconSize);
58: $this->arrowLast = new Icons64x64_1($iconSize);
59: $this->arrowFirst = new Icons64x64_1($iconSize);
60: $this->text = new Label(2*$iconSize - 2);
61: $this->textBg = new Bgs1(2*$iconSize, $iconSize-2);
62:
63: $this->showLast = false;
64: $this->showFastNext = false;
65: $this->showText = true;
66:
67: $this->arrowNext->setSubStyle($this->arrowNoneStyle);
68: $this->arrowPrev->setSubStyle($this->arrowNoneStyle);
69: $this->arrowFastNext->setSubStyle($this->arrowNoneStyle);
70: $this->arrowFastPrev->setSubStyle($this->arrowNoneStyle);
71: $this->arrowLast->setSubStyle($this->arrowNoneStyle);
72: $this->arrowFirst->setSubStyle($this->arrowNoneStyle);
73:
74: $this->addComponent($this->arrowNext);
75: $this->addComponent($this->arrowPrev);
76: $this->addComponent($this->arrowFastNext);
77: $this->addComponent($this->arrowFastPrev);
78: $this->addComponent($this->arrowLast);
79: $this->addComponent($this->arrowFirst);
80: $this->addComponent($this->textBg);
81: $this->addComponent($this->text);
82: }
83:
84: 85: 86:
87: function setSize($iconSize = 8)
88: {
89: $this->sizeX = $iconSize * 4.5;
90: $this->sizeY = $iconSize;
91:
92: $this->arrowNext->setSize($iconSize, $iconSize);
93: $this->arrowPrev->setSize($iconSize, $iconSize);
94: $this->arrowFastNext->setSize($iconSize, $iconSize);
95: $this->arrowFastPrev->setSize($iconSize, $iconSize);
96: $this->arrowLast->setSize($iconSize, $iconSize);
97: $this->arrowFirst->setSize($iconSize, $iconSize);
98: $this->text = new Label(2*$iconSize - 2);
99: $this->textBg = new Bgs1(2*$iconSize, $iconSize-2);
100: }
101:
102: 103: 104:
105: function setPageNumber($pageNumber)
106: {
107: $this->pageNumber = $pageNumber;
108: }
109:
110: 111: 112:
113: function setCurrentPage($currentPage)
114: {
115: $this->currentPage = $currentPage;
116: }
117:
118: 119: 120:
121: function showLast($show = true)
122: {
123: $this->showLast = $show;
124: }
125:
126: 127: 128:
129: function isLastShown()
130: {
131: return $this->showLast;
132: }
133:
134: 135: 136:
137: function showFastNext($show = true)
138: {
139: $this->showFastNext = $show;
140: }
141:
142: 143: 144:
145: function isFastNextShown()
146: {
147: return $this->showFastNext;
148: }
149:
150: 151: 152: 153:
154: function showText($show = true)
155: {
156: $this->showText = $show;
157: }
158:
159: 160: 161:
162: function isTextShown()
163: {
164: return $this->showText;
165: }
166:
167: 168: 169:
170: function onDraw()
171: {
172:
173: if(!$this->currentPage || !$this->pageNumber)
174: {
175: $this->showText(false);
176: }
177:
178:
179: if($this->arrowFirst->hasLink() || $this->arrowLast->hasLink() )
180: {
181: $this->showLast();
182: }
183: if($this->arrowFastNext->hasLink() || $this->arrowFastPrev->hasLink() )
184: {
185: $this->showFastNext();
186: }
187:
188:
189: if($this->arrowNext->hasLink())
190: {
191: $this->arrowNext->setSubStyle($this->arrowNextStyle);
192: }
193: if($this->arrowPrev->hasLink())
194: {
195: $this->arrowPrev->setSubStyle($this->arrowPrevStyle);
196: }
197: if($this->arrowNext->hasLink() && $this->arrowFastNext->hasLink())
198: {
199: $this->arrowFastNext->setSubStyle($this->arrowFastNextStyle);
200: }
201: else
202: {
203: $this->arrowFastNext->setManialink(null);
204: }
205: if($this->arrowPrev->hasLink() && $this->arrowFastPrev->hasLink())
206: {
207: $this->arrowFastPrev->setSubStyle($this->arrowFastPrevStyle);
208: }
209: else
210: {
211: $this->arrowFastPrev->setManialink(null);
212: }
213: if($this->arrowNext->hasLink() && $this->arrowLast->hasLink())
214: {
215: $this->arrowLast->setSubStyle($this->arrowLastStyle);
216: }
217: else
218: {
219: $this->arrowLast->setManialink(null);
220: }
221: if($this->arrowPrev->hasLink() && $this->arrowFirst->hasLink())
222: {
223: $this->arrowFirst->setSubStyle($this->arrowFirstStyle);
224: }
225: else
226: {
227: $this->arrowFirst->setManialink(null);
228: }
229:
230:
231: $this->text->setStyle(Label::TextValueSmall);
232: $this->text->setText($this->currentPage . ' / ' . $this->pageNumber);
233:
234:
235: $this->text->setAlign('center', 'center2');
236: $this->text->setPosZ(1);
237:
238: $this->textBg->setSubStyle(Bgs1::BgPager);
239: $this->textBg->setAlign('center', 'center');
240:
241: $this->arrowNext->setValign('center');
242: $this->arrowFastNext->setValign('center');
243: $this->arrowLast->setValign('center');
244:
245: $this->arrowNext->setPosition(($this->text->getSizeX() / 2) + 1, 0);
246: $this->arrowFastNext->setPosition($this->arrowNext->getPosX() + $this->arrowNext->getSizeX(), 0);
247: $this->arrowLast->setPosition(
248: $this->arrowNext->getPosX() +
249: (int)$this->showFastNext*$this->arrowFastNext->getSizeX() +
250: $this->arrowNext->getSizeX(),
251: 0);
252:
253: $this->arrowPrev->setAlign('right', 'center');
254: $this->arrowFastPrev->setAlign('right', 'center');
255: $this->arrowFirst->setAlign('right', 'center');
256:
257: $this->arrowPrev->setPosition(-($this->text->getSizeX()/2) - 1, 0);
258: $this->arrowFastPrev->setPosition($this->arrowPrev->getPosX() - $this->arrowPrev->getSizeX(), 0);
259: $this->arrowFirst->setPosition(
260: $this->arrowPrev->getPosX() -
261: (int)$this->showFastNext*$this->arrowFastPrev->getSizeX() -
262: $this->arrowPrev->getSizeX(),
263: 0);
264: }
265: }
266:
267: ?>