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