1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11:
12:
13: namespace ManiaLib\Gui;
14:
15: abstract class Component
16: {
17:
18: protected $id;
19: protected $visible = true;
20: protected $posX = 0;
21: protected $posY = 0;
22: protected $posZ = 0;
23: protected $sizeX;
24: protected $sizeY;
25: protected $scale;
26: protected $valign;
27: protected $halign;
28: protected $relativeHalign;
29: protected $relativeValign;
30: protected $scriptEvents;
31:
32: 33: 34:
35: protected $parentNode = false;
36:
37: 38: 39:
40: protected $parentLayout = false;
41:
42: 43: 44:
45: protected $parentFrame = false;
46:
47: 48: 49: 50:
51: function setId($id)
52: {
53: $this->id = $id;
54: }
55:
56: 57: 58: 59:
60: function setPositionX($posX)
61: {
62: $oldX = $this->posX;
63: $this->posX = $posX;
64: $this->onMove($oldX, $this->posY, $this->posZ);
65: }
66:
67: 68: 69: 70:
71: function setPositionY($posY)
72: {
73: $oldY = $this->posY;
74: $this->posY = $posY;
75: $this->onMove($this->posX, $oldY, $this->posZ);
76: }
77:
78: 79: 80: 81:
82: function setPositionZ($posZ)
83: {
84: $oldZ = $this->posZ;
85: $this->posZ = $posZ;
86: $this->onMove($this->posX, $this->posY, $oldZ);
87: }
88:
89: 90: 91: 92:
93: function setPosX($posX)
94: {
95: $oldX = $this->posX;
96: $this->posX = $posX;
97: $this->onMove($oldX, $this->posY, $this->posZ);
98: }
99:
100: 101: 102: 103:
104: function setPosY($posY)
105: {
106: $oldY = $this->posY;
107: $this->posY = $posY;
108: $this->onMove($this->posX, $oldY, $this->posZ);
109: }
110:
111: 112: 113: 114:
115: function setPosZ($posZ)
116: {
117: $oldZ = $this->posZ;
118: $this->posZ = $posZ;
119: $this->onMove($this->posX, $this->posY, $oldZ);
120: }
121:
122: 123: 124: 125:
126: function incPosX($posX)
127: {
128: $oldX = $this->posX;
129: $this->posX += $posX;
130: $this->onMove($oldX, $this->posY, $this->posZ);
131: }
132:
133: 134: 135: 136:
137: function incPosY($posY)
138: {
139: $oldY = $this->posY;
140: $this->posY += $posY;
141: $this->onMove($this->posX, $oldY, $this->posZ);
142: }
143:
144: 145: 146: 147:
148: function incPosZ($posZ)
149: {
150: $oldZ = $this->posZ;
151: $this->posZ += $posZ;
152: $this->onMove($this->posX, $this->posY, $oldZ);
153: }
154:
155: 156: 157: 158: 159: 160:
161: function setPosition()
162: {
163: $oldX = $this->posX;
164: $oldY = $this->posY;
165: $oldZ = $this->posZ;
166:
167: $args = func_get_args();
168:
169: if(!empty($args)) $this->posX = array_shift($args);
170:
171: if(!empty($args)) $this->posY = array_shift($args);
172:
173: if(!empty($args)) $this->posZ = array_shift($args);
174:
175: $this->onMove($oldX, $oldY, $oldZ);
176: }
177:
178: 179: 180: 181: 182:
183: function setScale($scale)
184: {
185: $oldScale = $this->scale;
186: $this->scale = $scale;
187: $this->onScale($oldScale);
188: }
189:
190: 191: 192: 193: 194:
195: function setVisibility($visible)
196: {
197: $this->visible = $visible;
198: }
199:
200: function getId()
201: {
202: return $this->id;
203: }
204:
205: 206: 207: 208:
209: function getPosX()
210: {
211: return $this->posX;
212: }
213:
214: 215: 216: 217:
218: function getPosY()
219: {
220: return $this->posY;
221: }
222:
223: 224: 225: 226:
227: function getPosZ()
228: {
229: return $this->posZ;
230: }
231:
232: 233: 234: 235:
236: function getScale()
237: {
238: return $this->scale;
239: }
240:
241: 242: 243: 244: 245:
246: function isVisible()
247: {
248: return $this->visible;
249: }
250:
251: 252: 253: 254: 255:
256: function setValign($valign)
257: {
258: $old = $this->valign;
259: $this->valign = $valign;
260: $this->onAlign($this->halign, $old);
261: }
262:
263: 264: 265: 266: 267:
268: function setHalign($halign)
269: {
270: $old = $this->halign;
271: $this->halign = $halign;
272: $this->onAlign($old, $this->valign);
273: }
274:
275: 276: 277: 278: 279: 280: 281:
282: function setAlign($halign = null, $valign = null)
283: {
284: $oldHalign = $this->halign;
285: $oldValign = $this->valign;
286: $this->valign = $valign;
287: $this->halign = $halign;
288: $this->onAlign($oldHalign, $oldValign);
289: }
290:
291: function setRelativeHalign($halign)
292: {
293: $this->relativeHalign = $halign;
294: }
295:
296: function setRelativeValign($valign)
297: {
298: $this->relativeValign = $valign;
299: }
300:
301: function setRelativeAlign($halign = null, $valign = null)
302: {
303: $this->relativeHalign = $halign;
304: $this->relativeValign = $valign;
305: }
306:
307: 308: 309: 310:
311: function setSizeX($sizeX)
312: {
313: $oldX = $this->sizeX;
314: $this->sizeX = $sizeX;
315: $this->onResize($oldX, $this->sizeY);
316: }
317:
318: 319: 320: 321:
322: function setSizeY($sizeY)
323: {
324: $oldY = $this->sizeY;
325: $this->sizeY = $sizeY;
326: $this->onResize($this->sizeX, $oldY);
327: }
328:
329: 330: 331: 332: 333:
334: function setSize()
335: {
336: $oldX = $this->sizeX;
337: $oldY = $this->sizeY;
338:
339: $args = func_get_args();
340:
341: if(!empty($args)) $this->sizeX = array_shift($args);
342:
343: if(!empty($args)) $this->sizeY = array_shift($args);
344:
345: $this->onResize($oldX, $oldY);
346: }
347:
348: 349: 350: 351:
352: function setScriptEvents($scriptEvent = true)
353: {
354: $this->scriptEvents = $scriptEvent;
355: }
356:
357: 358: 359: 360:
361: function getSizeX()
362: {
363: return $this->sizeX;
364: }
365:
366: 367: 368: 369:
370: function getSizeY()
371: {
372: return $this->sizeY;
373: }
374:
375: 376: 377: 378: 379:
380: function getRealSizeX()
381: {
382: return $this->sizeX * ($this->scale ? $this->scale : 1);
383: }
384:
385: 386: 387: 388: 389:
390: function getRealSizeY()
391: {
392: return $this->sizeY * ($this->scale ? $this->scale : 1);
393: }
394:
395: 396: 397: 398:
399: function getBorderLeft()
400: {
401: return $this->getPosX();
402: }
403:
404: 405: 406: 407:
408: function getBorderRight()
409: {
410: return $this->getPosX() + $this->getRealSizeX();
411: }
412:
413: 414: 415: 416:
417: function getBorderTop()
418: {
419: return $this->getPosY();
420: }
421:
422: 423: 424: 425:
426: function getBorderBottom()
427: {
428: return $this->getPosY() + $this->getRealSizeY();
429: }
430:
431: 432: 433: 434:
435: function getHalign($default = null)
436: {
437: return $this->halign ? : $default;
438: }
439:
440: 441: 442: 443:
444: function getValign($default = null)
445: {
446: return $this->valign ? : $default;
447: }
448:
449: function getRelativeHalign($default = null)
450: {
451: return $this->relativeHalign ? : $default;
452: }
453:
454: function getRelativeValign($default = null)
455: {
456: return $this->relativeValign ? : $default;
457: }
458:
459: function getScriptEvents()
460: {
461: return $this->scriptEvents;
462: }
463:
464: function setParentNode(\DOMNode $node)
465: {
466: $this->parentNode = $node;
467: }
468:
469: function setParentLayout($layout)
470: {
471: $this->parentLayout = $layout;
472: }
473:
474: function setParentFrame(Elements\Frame $frame)
475: {
476: $this->parentFrame = $frame;
477: }
478:
479: 480: 481:
482: function getParentNode()
483: {
484: return $this->parentNode !== false ? $this->parentNode : end(Manialink::$parentNodes);
485: }
486:
487: 488: 489:
490: function getParentLayout()
491: {
492: return $this->parentLayout !== false ? $this->parentLayout : end(Manialink::$parentLayouts);
493: }
494:
495: 496: 497:
498: function getParentFrame()
499: {
500: return $this->parentFrame !== false ? $this->parentFrame : end(Manialink::$parentFrames);
501: }
502:
503: 504: 505:
506: protected function onResize($oldX, $oldY)
507: {
508:
509: }
510:
511: 512: 513:
514: protected function onAlign($oldHalign, $oldValign)
515: {
516:
517: }
518:
519: 520: 521:
522: protected function onMove($oldX, $oldY, $oldZ)
523: {
524:
525: }
526:
527: 528: 529:
530: protected function onScale($oldScale)
531: {
532:
533: }
534:
535: }
536:
537: ?>