1: <?php
2: /**
3: * ManiaLib - Lightweight PHP framework for Manialinks
4: *
5: * @see http://code.google.com/p/manialib/
6: * @copyright Copyright (c) 2009-2011 NADEO (http://www.nadeo.com)
7: * @license http://www.gnu.org/licenses/lgpl.html LGPL License 3
8: * @version $Revision: 590 $:
9: * @author $Author: maximeraoust $:
10: * @date $Date: 2011-12-27 19:40:38 +0100 (mar., 27 déc. 2011) $:
11: */
12:
13: namespace ManiaLib\Gui\Cards\Navigation;
14:
15: class Button extends \ManiaLib\Gui\Elements\Bgs1
16: {
17:
18: /**
19: * TrackMania formatting string appended to the text when a button
20: * is selected (default is just a light blue color)
21: */
22: static public $unselectedTextStyle = '$fff';
23:
24: /**
25: * @var \ManiaLib\Gui\Elements\Label
26: */
27: public $text;
28:
29: /**
30: * @var \ManiaLib\Gui\Elements\Icon
31: */
32: public $icon;
33: public $iconSizeMinimizer = 1.5;
34: public $textSizeMinimizer = 10;
35:
36: /**
37: * @var \ManiaLib\Gui\Elements\Icons64x64_1
38: */
39: protected $selectedIcon;
40: protected $isSelected = false;
41: protected $forceLinks = true;
42:
43: function __construct($sizeX = 69, $sizeY = 8.5)
44: {
45: parent::__construct($sizeX, $sizeY);
46:
47: $this->setSubStyle(\ManiaLib\Gui\Elements\Bgs1::BgEmpty);
48:
49: $this->cardElementsValign = 'center2';
50:
51: $this->text = new \ManiaLib\Gui\Elements\Label(45);
52: $this->text->setSizeY(0);
53: $this->text->setValign("center");
54: $this->text->setPosition(8);
55: $this->text->setStyle(\ManiaLib\Gui\Elements\Label::TextButtonNav);
56: $this->addCardElement($this->text);
57:
58: $this->icon = new \ManiaLib\Gui\Elements\Icons128x128_1($this->sizeY);
59: $this->icon->setValign("center");
60: $this->icon->setPosition(55, 0, 0.1);
61: $this->addCardElement($this->icon);
62: }
63:
64: /**
65: * Sets the button selected and change its styles accordingly
66: */
67: function setSelected()
68: {
69: $this->isSelected = true;
70:
71: $this->selectedIcon = new \ManiaLib\Gui\Elements\Icons64x64_1(11);
72: $this->selectedIcon->setSubStyle(\ManiaLib\Gui\Elements\Icons64x64_1::ShowRight);
73: $this->selectedIcon->setValign('center');
74: $this->selectedIcon->setPosX(71);
75: $this->addCardElement($this->selectedIcon);
76: }
77:
78: protected function preFilter()
79: {
80: if(!$this->isSelected && $this->text->getText())
81: {
82: $this->text->setText(self::$unselectedTextStyle.$this->text->getText());
83: }
84:
85: $this->text->addLink($this);
86: $this->icon->addLink($this);
87: }
88:
89: }
90:
91: ?>