1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11:
12:
13: namespace ManiaLib\Gui\Elements;
14:
15: use ManiaLib\Gui\Component;
16: use ManiaLib\Gui\Drawable;
17: use ManiaLib\Gui\Layouts\AbstractLayout;
18: use ManiaLib\Gui\Manialink;
19: use ManiaLib\Gui\Tools;
20:
21: class Frame extends Component implements Drawable
22: {
23:
24: protected $xml;
25:
26: 27: 28:
29: protected $layout;
30:
31: 32: 33:
34: protected $children;
35:
36: function __construct($sizeX = 0, $sizeY = 0)
37: {
38: $this->sizeX = $sizeX;
39: $this->sizeY = $sizeY;
40: $this->children = array();
41: }
42:
43: 44: 45:
46: function getLayout()
47: {
48: return $this->layout;
49: }
50:
51: function setLayout(AbstractLayout $layout)
52: {
53: $this->layout = $layout;
54: }
55:
56: function onResize($oldX, $oldY)
57: {
58: if($this->layout instanceof AbstractLayout)
59: {
60: $this->layout->setSize($this->sizeX, $this->sizeY);
61: }
62: }
63:
64: function onScale($oldScale)
65: {
66: if($this->layout instanceof AbstractLayout)
67: {
68: $this->layout->setScale($this->scale);
69: }
70: }
71:
72: function add(Component $component)
73: {
74: $this->children[] = $component;
75: }
76:
77: function remove(Component $component)
78: {
79: $key = array_search($component, $this->children);
80: if($key !== false)
81: {
82: unset($this->children[$key]);
83: }
84: }
85:
86: function preFilter()
87: {
88:
89: }
90:
91: function postFilter()
92: {
93:
94: }
95:
96: function buildXML()
97: {
98: if(!$this->xml)
99: {
100: $this->xml = Manialink::createElement('frame');
101: $this->getParentNode()->appendChild($this->xml);
102: }
103:
104: if($this->id !== null) $this->xml->setAttribute('id', $this->id);
105:
106: if($this->posX || $this->posY || $this->posZ)
107: {
108: $this->xml->setAttribute('posn', $this->posX.' '.$this->posY.' '.$this->posZ);
109: }
110: if($this->scale !== null) $this->xml->setAttribute('scale', $this->scale);
111: }
112:
113: function getDOMElement()
114: {
115: return $this->xml;
116: }
117:
118: final function save()
119: {
120: if($this->visible === false)
121: {
122: return;
123: }
124:
125: $this->preFilter();
126:
127: if($this->layout instanceof AbstractLayout)
128: {
129: $layout = $this->getParentLayout();
130: if($layout instanceof AbstractLayout)
131: {
132: $layout->preFilter($this->layout);
133: $layout->updateComponent($this);
134: }
135: }
136:
137: $frame = $this->getParentFrame();
138: if($frame instanceof Frame)
139: {
140: if($frame->getSizeX())
141: {
142: $x = Tools::getAlignedPosX(0, $frame->getSizeX(), $frame->getHalign('left'), $this->getRelativeHalign('left'));
143: $this->incPosX($x);
144: }
145: if($frame->getSizeY())
146: {
147: $y = Tools::getAlignedPosY(0, $frame->getSizeY(), $frame->getValign('top'), $this->getRelativeValign('top'));
148: $this->incPosY($y);
149: }
150: }
151:
152: $this->buildXML();
153:
154:
155: foreach($this->children as $child)
156: {
157: $child->setParentNode($this->xml);
158: $child->setParentLayout($this->layout);
159: $child->setParentFrame($this);
160: $child->incPosZ(0.1);
161: if($child instanceof Drawable)
162: {
163: $child->save();
164: }
165: }
166:
167: if($this->layout instanceof AbstractLayout)
168: {
169: if($layout instanceof AbstractLayout)
170: {
171: $layout->postFilter($this->layout);
172: }
173: }
174:
175: $this->postFilter();
176: }
177:
178: }
179:
180: ?>