1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10:
11:
12: namespace ManiaLive\Gui\Controls;
13:
14: use ManiaLib\Gui\Layouts\Line;
15: use ManiaLib\Gui\Elements\Bgs1;
16: use ManiaLib\Gui\Elements\BgsPlayerCard;
17: use ManiaLib\Gui\Elements\Label;
18:
19: 20: 21: 22: 23: 24:
25: class TabbedPane extends \ManiaLive\Gui\Control
26: {
27: protected $panes;
28: protected $tabs;
29: protected $activeId;
30:
31: protected $background;
32: protected $tabsView;
33: protected $content;
34:
35: function __construct()
36: {
37: $this->panes = array();
38: $this->tabs = array();
39: $this->activeId = -1;
40:
41: $this->background = new BgsPlayerCard();
42: $this->background->setSubStyle(BgsPlayerCard::BgCardSystem);
43: $this->background->setPosition(0, -5);
44: $this->background->setSize($this->sizeX, $this->sizeY - 5);
45: $this->addComponent($this->background);
46:
47: $this->tabsView = new Frame(0, 0, new Line());
48: $this->addComponent($this->tabsView);
49:
50: $this->content = new Frame();
51: $this->content->setPosition(0.5, -5);
52: $this->addComponent($this->content);
53: }
54:
55: protected function onResize($oldX, $oldY)
56: {
57: $this->panes[$this->activeId]->setSize($this->sizeX - 1, $this->sizeY - 5.5);
58: $this->background->setSize($this->sizeX, $this->sizeY - 5);
59: }
60:
61: 62: 63: 64: 65:
66: function clickOnTab($login, $id)
67: {
68: if($id !== $this->activeId)
69: {
70: if(isset($this->panes[$this->activeId]))
71: {
72: $this->panes[$this->activeId]->onDeactivate();
73: if(isset($this->tabs[$this->activeId]))
74: $this->tabs[$this->activeId]->background->setSubStyle(Bgs1::NavButton);
75: }
76:
77: $this->activeId = $id;
78: if(isset($this->panes[$this->activeId]))
79: {
80: $this->panes[$this->activeId]->onActivate();
81: $this->panes[$this->activeId]->setSize($this->sizeX - 1, $this->sizeY - 5.5);
82: $this->content->clearComponents();
83: $this->content->addComponent($this->panes[$this->activeId]);
84: if(isset($this->tabs[$this->activeId]))
85: $this->tabs[$this->activeId]->background->setSubStyle(Bgs1::NavButtonBlink);
86: }
87:
88: $this->redraw();
89: }
90: }
91:
92: 93: 94: 95:
96: function addTab(Tabbable $pane)
97: {
98: $this->panes[] = $pane;
99:
100: $tab = new Tab();
101: $tab->setSize(25, 5);
102: $index = count($this->tabs);
103: $tab->background->setAction($this->createAction(array($this, 'clickOnTab'), $index));
104: $tab->label->setText($pane->getTitle());
105:
106: $this->tabs[] = $tab;
107: $this->tabsView->addComponent($tab);
108:
109: if($this->activeId == -1)
110: $this->clickOnTab(null, 0);
111: }
112:
113: 114: 115: 116: 117: 118:
119: function getTab($id)
120: {
121: if (isset($this->panes[$id]))
122: return $this->panes[$id];
123: }
124:
125: 126: 127: 128:
129: function getActiveTabId()
130: {
131: return $this->activeId;
132: }
133:
134: 135: 136: 137:
138: function destroy()
139: {
140: $this->tabsView->destroy();
141: $this->content->clearComponents();
142:
143: $this->content = null;
144: $this->tabs = array();
145: parent::destroy();
146: }
147: }
148:
149: class Tab extends Frame
150: {
151: public $background;
152: public $label;
153:
154: function __construct($sizeX=25, $sizeY=5)
155: {
156: $this->background = new Bgs1($sizeX, $sizeY);
157: $this->background->setSubStyle(Bgs1::NavButton);
158: $this->addComponent($this->background);
159:
160: $this->label = new Label($sizeX - 2, $sizeY);
161: $this->label->setPosition(1, -0.4);
162: $this->label->setTextSize(2);
163: $this->label->setTextColor('fff');
164: $this->addComponent($this->label);
165: }
166: }
167:
168: ?>