1: <?php
2: /**
3: * @copyright Copyright (c) 2009-2011 NADEO (http://www.nadeo.com)
4: * @license http://www.gnu.org/licenses/lgpl.html LGPL License 3
5: * @version $Revision: 309 $:
6: * @author $Author: martin.gwendal $:
7: * @date $Date: 2011-12-20 18:57:55 +0100 (mar., 20 déc. 2011) $:
8: */
9:
10: namespace ManiaLive\Gui;
11:
12: use ManiaLib\Gui\Elements\Icons128x32_1;
13: use ManiaLib\Gui\Elements\Label;
14: use ManiaLive\Event\Dispatcher;
15:
16: /**
17: * This window will be managed by the windowing system.
18: * if there is more than one window displayed at a time,
19: * then it will put the oldest ones into a "taskbar".
20: */
21: class ManagedWindow extends Panel
22: {
23: private $maximized;
24: private $oldSizeX;
25: private $oldSizeY;
26:
27: private $buttonMin;
28: private $buttonMax;
29:
30: /**
31: * This will create a new instance of the window
32: * that extends this class.
33: * @param string $recipient
34: * @param bool $singleton
35: * @return \ManiaLive\Gui\Windowing\ManagedWindow
36: * @throws \Exception
37: */
38: static function Create($recipient = null, $singleton = true)
39: {
40: if($recipient == null || $recipient instanceof Group)
41: throw new \Exception('You can not send a window instance of ManagedWindow to more than one player!');
42:
43: return parent::Create($recipient, $singleton);
44: }
45:
46: /**
47: * Buzz all windows of the given type.
48: * Will inform players that this window has got some
49: * new information for them.
50: */
51: static function Buzz()
52: {
53: foreach(self::GetAll() as $window)
54: {
55: $thumbnail = GuiHandler::getInstance()->getThumbnail($window);
56: if($thumbnail)
57: $thumbnail->enableHighlight();
58: }
59: }
60:
61: /**
62: * Redraws all window instances that are
63: * currently shown on player screens and
64: * send buzz signal if a window is minimized.
65: */
66: static function RedrawAll()
67: {
68: foreach(self::GetAll() as $window)
69: {
70: if($window->isVisible())
71: $window->show();
72: else
73: {
74: $thumbnail = GuiHandler::getInstance()->getThumbnail($window);
75: if($thumbnail)
76: $thumbnail->enableHighlight();
77: }
78: }
79: }
80:
81: /**
82: * Use the static Create method to instanciate
83: * a new object of that class.
84: */
85: protected function onConstruct()
86: {
87: parent::onConstruct();
88: $this->oldSizeX = null;
89: $this->oldSizeY = null;
90:
91: // create minimize button ...
92: $this->buttonMin = new Label();
93: $this->buttonMin->setStyle(Label::TextCardRaceRank);
94: $this->buttonMin->setPosY(-2.5);
95: $this->buttonMin->setText('$000_');
96: $this->buttonMin->setAction(ActionHandler::getInstance()->createAction(array(GuiHandler::getInstance(), 'sendToTaskbar')));
97: $this->addComponent($this->buttonMin);
98:
99: $this->buttonMax = new Icons128x32_1(8);
100: $this->buttonMax->setSubStyle(Icons128x32_1::Windowed);
101: $this->buttonMax->setPosition(9, -2.5);
102: $this->buttonMax->setAction($this->createAction(array($this, 'maximize')));
103: $this->addComponent($this->buttonMax);
104:
105: $this->setMaximizable(false);
106: }
107:
108: /**
109: * Whether this window is currently maximized.
110: * @return bool
111: */
112: final function isMaximized()
113: {
114: return $this->maximized;
115: }
116:
117: /**
118: * Set this window maximized and redraw
119: * it onto the screen.
120: */
121: final function maximize()
122: {
123: $this->maximized = !$this->maximized;
124: if($this->maximized)
125: $this->posZ = self::Z_MAXIMIZED;
126: $this->redraw();
127: }
128:
129: /**
130: * Show or hide the maximize button.
131: * @param bool $maximizable
132: */
133: function setMaximizable($maximizable = true)
134: {
135: $this->buttonMax->setVisibility($maximizable);
136: $this->buttonMin->setPosX($maximizable ? 18 : 9);
137: }
138:
139: function onDraw()
140: {
141: if($this->maximized)
142: {
143: if(!$this->oldSizeX && !$this->oldSizeY)
144: {
145: $this->oldSizeX = $this->sizeX;
146: $this->oldSizeY = $this->sizeY;
147: }
148: $this->setSize(320, 180);
149: $this->centerOnScreen();
150: }
151: else
152: {
153: if($this->oldSizeX || $this->oldSizeY)
154: {
155: $this->setSize($this->oldSizeX, $this->oldSizeY);
156: $this->centerOnScreen();
157: $this->oldSizeX = null;
158: $this->oldSizeY = null;
159: }
160: }
161: }
162:
163: /**
164: * Unmaximize window if needed
165: */
166: protected function onHide()
167: {
168: if($this->maximized)
169: {
170: if ($this->oldSizeX || $this->oldSizeY)
171: {
172: $this->setSize($this->oldSizeX, $this->oldSizeY);
173: $this->centerOnScreen();
174: $this->oldSizeX = null;
175: $this->oldSizeY = null;
176: }
177: $this->maximized = false;
178: }
179: }
180:
181: function destroy()
182: {
183: parent::destroy();
184:
185: $this->buttonMin = null;
186: $this->buttonMax = null;
187:
188: $thumbnail = GuiHandler::getInstance()->getThumbnail($this);
189: if($thumbnail)
190: $thumbnail->destroy();
191: }
192: }
193:
194: ?>