TrackManiaControl/libs/FML/Controls/Label.php

318 lines
7.1 KiB
PHP
Raw Normal View History

<?php
namespace FML\Controls;
2014-05-16 22:44:22 +02:00
use FML\Script\Features\Clock;
use FML\Types\Actionable;
use FML\Types\Linkable;
use FML\Types\NewLineable;
use FML\Types\Scriptable;
use FML\Types\Styleable;
use FML\Types\TextFormatable;
/**
2014-01-19 19:30:21 +01:00
* Label Control
2014-01-12 00:51:46 +01:00
* (CMlLabel)
*
2014-05-20 15:44:45 +02:00
* @author steeffeen <mail@steeffeen.com>
2014-04-13 18:21:40 +02:00
* @copyright FancyManiaLinks Copyright © 2014 Steffen Schröder
2014-05-16 22:44:22 +02:00
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
*/
class Label extends Control implements Actionable, Linkable, NewLineable, Scriptable, Styleable, TextFormatable {
2014-01-21 20:30:40 +01:00
/*
2014-06-21 03:18:21 +02:00
* Protected properties
*/
2014-06-21 03:18:21 +02:00
protected $tagName = 'label';
protected $text = null;
protected $textId = null;
protected $textPrefix = null;
protected $textEmboss = null;
protected $translate = null;
2014-01-12 00:51:46 +01:00
protected $maxLines = -1;
2014-06-21 03:18:21 +02:00
protected $opacity = 1.;
protected $action = null;
2014-01-12 00:51:46 +01:00
protected $actionKey = -1;
2014-06-21 03:18:21 +02:00
protected $url = null;
protected $urlId = null;
protected $manialink = null;
protected $manialinkId = null;
protected $autoNewLine = null;
protected $scriptEvents = null;
protected $style = null;
protected $textSize = -1;
2014-07-04 23:50:43 +02:00
protected $textFont = null;
2014-06-21 03:18:21 +02:00
protected $textColor = null;
protected $focusAreaColor1 = null;
protected $focusAreaColor2 = null;
/**
2014-05-16 22:44:22 +02:00
* @see \FML\Controls\Control::getManiaScriptClass()
*/
2014-05-16 22:44:22 +02:00
public function getManiaScriptClass() {
return 'CMlLabel';
}
/**
2014-06-21 03:18:21 +02:00
* Set text
*
2014-06-21 03:18:21 +02:00
* @param string $text Text value
2014-07-03 22:34:47 +02:00
* @return static
*/
public function setText($text) {
2014-05-16 22:44:22 +02:00
$this->text = (string)$text;
return $this;
}
2014-01-19 19:30:21 +01:00
/**
2014-06-21 03:18:21 +02:00
* Set text id to use from Dico
2014-01-19 19:30:21 +01:00
*
2014-06-21 03:18:21 +02:00
* @param string $textId Text id
2014-07-03 22:34:47 +02:00
* @return static
2014-01-19 19:30:21 +01:00
*/
public function setTextId($textId) {
2014-05-16 22:44:22 +02:00
$this->textId = (string)$textId;
2014-01-19 19:30:21 +01:00
return $this;
}
/**
2014-06-21 03:18:21 +02:00
* Set text prefix
*
2014-06-21 03:18:21 +02:00
* @param string $textPrefix Text prefix
2014-07-03 22:34:47 +02:00
* @return static
*/
public function setTextPrefix($textPrefix) {
2014-05-16 22:44:22 +02:00
$this->textPrefix = (string)$textPrefix;
return $this;
}
/**
2014-06-21 03:18:21 +02:00
* Set text emboss
*
2014-06-21 03:18:21 +02:00
* @param bool $textEmboss Whether the text should be embossed
2014-07-03 22:34:47 +02:00
* @return static
*/
public function setTextEmboss($textEmboss) {
$this->textEmboss = ($textEmboss ? 1 : 0);
return $this;
}
/**
2014-06-21 03:18:21 +02:00
* Set translate
*
2014-06-21 03:18:21 +02:00
* @param bool $translate Whether the text should be translated
2014-07-03 22:34:47 +02:00
* @return static
*/
public function setTranslate($translate) {
$this->translate = ($translate ? 1 : 0);
return $this;
}
/**
2014-06-21 03:18:21 +02:00
* Set max lines count
*
2014-06-21 03:18:21 +02:00
* @param int $maxLines Max lines count
2014-07-03 22:34:47 +02:00
* @return static
*/
public function setMaxLines($maxLines) {
2014-05-16 22:44:22 +02:00
$this->maxLines = (int)$maxLines;
return $this;
}
/**
2014-05-16 22:44:22 +02:00
* @see \FML\Types\Actionable::getAction()
*/
2014-05-16 22:44:22 +02:00
public function getAction() {
return $this->action;
2014-01-12 00:51:46 +01:00
}
2014-01-21 20:30:40 +01:00
/**
2014-05-16 22:44:22 +02:00
* @see \FML\Types\Actionable::setAction()
2014-01-21 20:30:40 +01:00
*/
2014-05-16 22:44:22 +02:00
public function setAction($action) {
$this->action = (string)$action;
return $this;
2014-01-21 20:30:40 +01:00
}
2014-01-12 00:51:46 +01:00
/**
* @see \FML\Types\Actionable::setActionKey()
*/
public function setActionKey($actionKey) {
2014-05-16 22:44:22 +02:00
$this->actionKey = (int)$actionKey;
return $this;
}
/**
* @see \FML\Types\Linkable::setUrl()
*/
public function setUrl($url) {
2014-05-16 22:44:22 +02:00
$this->url = (string)$url;
return $this;
}
2014-01-19 19:30:21 +01:00
/**
* @see \FML\Types\Linkable::setUrlId()
*/
public function setUrlId($urlId) {
2014-05-16 22:44:22 +02:00
$this->urlId = (string)$urlId;
2014-01-19 19:30:21 +01:00
return $this;
}
/**
* @see \FML\Types\Linkable::setManialink()
*/
public function setManialink($manialink) {
2014-05-16 22:44:22 +02:00
$this->manialink = (string)$manialink;
return $this;
}
2014-01-19 19:30:21 +01:00
/**
* @see \FML\Types\Linkable::setManialinkId()
*/
public function setManialinkId($manialinkId) {
2014-05-16 22:44:22 +02:00
$this->manialinkId = (string)$manialinkId;
2014-01-19 19:30:21 +01:00
return $this;
}
/**
* @see \FML\Types\NewLineable::setAutoNewLine()
*/
public function setAutoNewLine($autoNewLine) {
$this->autoNewLine = ($autoNewLine ? 1 : 0);
return $this;
}
/**
* @see \FML\Types\Scriptable::setScriptEvents()
*/
public function setScriptEvents($scriptEvents) {
$this->scriptEvents = ($scriptEvents ? 1 : 0);
return $this;
}
/**
* @see \FML\Types\Styleable::setStyle()
*/
public function setStyle($style) {
2014-05-16 22:44:22 +02:00
$this->style = (string)$style;
return $this;
}
/**
* @see \FML\Types\TextFormatable::setTextSize()
*/
public function setTextSize($textSize) {
2014-05-16 22:44:22 +02:00
$this->textSize = (int)$textSize;
return $this;
}
2014-07-04 23:50:43 +02:00
/**
* @see \FML\Types\TextFormatable::setTextFont()
*/
public function setTextFont($textFont) {
$this->textFont = (string)$textFont;
return $this;
}
/**
* @see \FML\Types\TextFormatable::setTextColor()
*/
public function setTextColor($textColor) {
2014-05-16 22:44:22 +02:00
$this->textColor = (string)$textColor;
return $this;
}
/**
* @see \FML\Types\TextFormatable::setAreaColor()
*/
public function setAreaColor($areaColor) {
2014-05-16 22:44:22 +02:00
$this->focusAreaColor1 = (string)$areaColor;
return $this;
}
/**
* @see \FML\Types\TextFormatable::setAreaFocusColor()
*/
public function setAreaFocusColor($areaFocusColor) {
2014-05-16 22:44:22 +02:00
$this->focusAreaColor2 = (string)$areaFocusColor;
return $this;
}
2014-04-27 14:44:40 +02:00
/**
2014-06-21 03:18:21 +02:00
* Add a dynamic Feature showing the current time
2014-04-27 14:44:40 +02:00
*
2014-06-21 03:18:21 +02:00
* @param bool $showSeconds (optional) Whether the seconds should be shown
* @param bool $showFullDate (optional) Whether the date should be shown
2014-07-03 22:34:47 +02:00
* @return static
2014-04-27 14:44:40 +02:00
*/
public function addClockFeature($showSeconds = true, $showFullDate = false) {
$clock = new Clock($this, $showSeconds, $showFullDate);
2014-05-14 23:24:00 +02:00
$this->addScriptFeature($clock);
2014-04-27 14:44:40 +02:00
return $this;
}
/**
2014-06-21 03:18:21 +02:00
* @see \FML\Types\Renderable::render()
*/
public function render(\DOMDocument $domDocument) {
2014-01-12 00:51:46 +01:00
$xmlElement = parent::render($domDocument);
2014-01-21 20:30:40 +01:00
if (strlen($this->text) > 0) {
2014-01-12 00:51:46 +01:00
$xmlElement->setAttribute('text', $this->text);
}
2014-01-19 19:30:21 +01:00
if ($this->textId) {
$xmlElement->setAttribute('textid', $this->textId);
}
if ($this->textPrefix) {
2014-01-12 00:51:46 +01:00
$xmlElement->setAttribute('textprefix', $this->textPrefix);
}
if ($this->textEmboss) {
2014-01-12 00:51:46 +01:00
$xmlElement->setAttribute('textemboss', $this->textEmboss);
}
if ($this->translate) {
2014-01-12 00:51:46 +01:00
$xmlElement->setAttribute('translate', $this->translate);
}
2014-01-12 00:51:46 +01:00
if ($this->maxLines >= 0) {
$xmlElement->setAttribute('maxlines', $this->maxLines);
}
2014-06-21 03:18:21 +02:00
if ($this->opacity != 1.) {
$xmlElement->setAttribute('opacity', $this->opacity);
}
2014-01-21 20:30:40 +01:00
if (strlen($this->action) > 0) {
2014-01-12 00:51:46 +01:00
$xmlElement->setAttribute('action', $this->action);
}
if ($this->actionKey >= 0) {
$xmlElement->setAttribute('actionkey', $this->actionKey);
}
if ($this->url) {
2014-01-12 00:51:46 +01:00
$xmlElement->setAttribute('url', $this->url);
}
if ($this->manialink) {
2014-01-12 00:51:46 +01:00
$xmlElement->setAttribute('manialink', $this->manialink);
}
if ($this->autoNewLine) {
2014-01-12 00:51:46 +01:00
$xmlElement->setAttribute('autonewline', $this->autoNewLine);
}
if ($this->scriptEvents) {
2014-01-12 00:51:46 +01:00
$xmlElement->setAttribute('scriptevents', $this->scriptEvents);
}
if ($this->style) {
2014-01-12 00:51:46 +01:00
$xmlElement->setAttribute('style', $this->style);
}
if ($this->textSize >= 0) {
2014-01-12 00:51:46 +01:00
$xmlElement->setAttribute('textsize', $this->textSize);
}
2014-07-04 23:50:43 +02:00
if ($this->textFont) {
$xmlElement->setAttribute('textfont', $this->textFont);
}
if ($this->textColor) {
2014-01-12 00:51:46 +01:00
$xmlElement->setAttribute('textcolor', $this->textColor);
}
2014-01-19 19:30:21 +01:00
if ($this->focusAreaColor1) {
$xmlElement->setAttribute('focusareacolor1', $this->focusAreaColor1);
}
2014-01-19 19:30:21 +01:00
if ($this->focusAreaColor2) {
$xmlElement->setAttribute('focusareacolor2', $this->focusAreaColor2);
}
2014-01-12 00:51:46 +01:00
return $xmlElement;
}
}