TrackManiaControl/libs/FML/Elements/Format.php

124 lines
2.8 KiB
PHP
Raw Normal View History

<?php
namespace FML\Elements;
2014-01-12 00:51:46 +01:00
use FML\Types\BgColorable;
use FML\Types\Renderable;
use FML\Types\Styleable;
use FML\Types\TextFormatable;
/**
2014-01-12 00:51:46 +01:00
* Format Element
*
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-18 19:45:50 +02:00
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
*/
class Format implements BgColorable, Renderable, Styleable, TextFormatable {
2014-01-21 20:30:40 +01:00
/*
2014-06-21 03:18:21 +02:00
* Protected properties
*/
protected $tagName = 'format';
2014-06-21 03:18:21 +02:00
protected $bgColor = null;
protected $style = null;
2014-01-12 00:51:46 +01:00
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-01-19 19:30:21 +01:00
/**
* Create a new Format Element
*
2014-07-03 22:34:47 +02:00
* @return static
2014-01-19 19:30:21 +01:00
*/
public static function create() {
2014-06-21 03:18:21 +02:00
return new static();
2014-01-19 19:30:21 +01:00
}
2014-01-12 00:51:46 +01:00
/**
* @see \FML\Types\BgColorable::setBgColor()
*/
public function setBgColor($bgColor) {
2014-05-18 19:45:50 +02:00
$this->bgColor = (string)$bgColor;
2014-01-12 00:51:46 +01:00
return $this;
}
/**
* @see \FML\Types\Styleable::setStyle()
*/
public function setStyle($style) {
2014-05-18 19:45:50 +02:00
$this->style = (string)$style;
2014-01-12 00:51:46 +01:00
return $this;
}
/**
* @see \FML\Types\TextFormatable::setTextSize()
*/
public function setTextSize($textSize) {
2014-05-18 19:45:50 +02:00
$this->textSize = (int)$textSize;
2014-01-12 00:51:46 +01:00
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;
}
2014-01-12 00:51:46 +01:00
/**
* @see \FML\Types\TextFormatable::setTextColor()
*/
public function setTextColor($textColor) {
2014-05-18 19:45:50 +02:00
$this->textColor = (string)$textColor;
2014-01-12 00:51:46 +01:00
return $this;
}
/**
* @see \FML\Types\TextFormatable::setAreaColor()
*/
public function setAreaColor($areaColor) {
2014-05-18 19:45:50 +02:00
$this->focusAreaColor1 = (string)$areaColor;
2014-01-12 00:51:46 +01:00
return $this;
}
/**
* @see \FML\Types\TextFormatable::setAreaFocusColor()
*/
public function setAreaFocusColor($areaFocusColor) {
2014-05-18 19:45:50 +02:00
$this->focusAreaColor2 = (string)$areaFocusColor;
2014-01-12 00:51:46 +01:00
return $this;
}
/**
2014-07-03 22:34:47 +02:00
* @see \FML\Types\Renderable::render()
*/
public function render(\DOMDocument $domDocument) {
2014-01-19 19:30:21 +01:00
$formatXmlElement = $domDocument->createElement($this->tagName);
2014-01-12 00:51:46 +01:00
if ($this->bgColor) {
2014-01-19 19:30:21 +01:00
$formatXmlElement->setAttribute('bgcolor', $this->bgColor);
2014-01-12 00:51:46 +01:00
}
if ($this->style) {
2014-01-19 19:30:21 +01:00
$formatXmlElement->setAttribute('style', $this->style);
2014-01-12 00:51:46 +01:00
}
if ($this->textSize >= 0) {
2014-01-19 19:30:21 +01:00
$formatXmlElement->setAttribute('textsize', $this->textSize);
2014-01-12 00:51:46 +01:00
}
2014-07-04 23:50:43 +02:00
if ($this->textFont) {
$formatXmlElement->setAttribute('textfont', $this->textFont);
}
2014-01-12 00:51:46 +01:00
if ($this->textColor) {
2014-01-19 19:30:21 +01:00
$formatXmlElement->setAttribute('textcolor', $this->textColor);
2014-01-12 00:51:46 +01:00
}
2014-01-19 19:30:21 +01:00
if ($this->focusAreaColor1) {
$formatXmlElement->setAttribute('focusareacolor1', $this->focusAreaColor1);
2014-01-12 00:51:46 +01:00
}
2014-01-19 19:30:21 +01:00
if ($this->focusAreaColor2) {
$formatXmlElement->setAttribute('focusareacolor2', $this->focusAreaColor2);
2014-01-12 00:51:46 +01:00
}
2014-01-19 19:30:21 +01:00
return $formatXmlElement;
}
}