TrackManiaControl/application/core/FML/Controls/Gauge.php

183 lines
3.6 KiB
PHP
Raw Normal View History

<?php
namespace FML\Controls;
use FML\Types\Styleable;
/**
2014-01-19 19:30:21 +01:00
* Gauge Control
2014-01-12 00:51:46 +01:00
* (CMlGauge)
*
* @author steeffeen
*/
2014-01-19 19:30:21 +01:00
// TODO: gauge styles
class Gauge extends Control implements Styleable {
/**
2013-12-31 02:55:19 +01:00
* Protected Properties
*/
2014-01-19 19:30:21 +01:00
protected $ratio = 0.;
protected $grading = 1.;
protected $color = '';
protected $rotation = 0.;
protected $centered = 0;
protected $clan = 0;
protected $drawBg = 1;
protected $drawBlockBg = 1;
protected $style = '';
2014-01-19 19:30:21 +01:00
/**
* Create a new Gauge Control
*
* @param string $id (optional) Control Id
* @return \FML\Controls\Gauge
*/
public static function create($id = null) {
$gauge = new Gauge($id);
return $gauge;
}
/**
2013-12-31 02:55:19 +01:00
* Construct a new Gauge Control
*
2014-01-12 00:51:46 +01:00
* @param string $id (optional) Control Id
*/
public function __construct($id = null) {
parent::__construct($id);
$this->tagName = 'gauge';
}
/**
2013-12-31 02:55:19 +01:00
* Set Ratio
*
2014-01-12 00:51:46 +01:00
* @param float $ratio Ratio Value
* @return \FML\Controls\Gauge
*/
public function setRatio($ratio) {
2014-01-12 00:51:46 +01:00
$this->ratio = (float) $ratio;
return $this;
}
/**
2013-12-31 02:55:19 +01:00
* Set Grading
*
2014-01-12 00:51:46 +01:00
* @param float $grading Grading Value
* @return \FML\Controls\Gauge
*/
public function setGrading($grading) {
2014-01-12 00:51:46 +01:00
$this->grading = (float) $grading;
return $this;
}
/**
2013-12-31 02:55:19 +01:00
* Set Color
*
2014-01-12 00:51:46 +01:00
* @param string $color Gauge Color
* @return \FML\Controls\Gauge
*/
public function setColor($color) {
2014-01-12 00:51:46 +01:00
$this->color = (string) $color;
return $this;
}
/**
2013-12-31 02:55:19 +01:00
* Set Rotation
*
2014-01-12 00:51:46 +01:00
* @param float $rotation Gauge Rotation
* @return \FML\Controls\Gauge
*/
public function setRotation($rotation) {
2014-01-12 00:51:46 +01:00
$this->rotation = (float) $rotation;
return $this;
}
/**
2013-12-31 02:55:19 +01:00
* Set Centered
*
2014-01-12 00:51:46 +01:00
* @param bool $centered Whether Gauge is centered
* @return \FML\Controls\Gauge
*/
public function setCentered($centered) {
$this->centered = ($centered ? 1 : 0);
return $this;
}
/**
2013-12-31 02:55:19 +01:00
* Set Clan
*
2014-01-12 00:51:46 +01:00
* @param int $clan Clan number
* @return \FML\Controls\Gauge
*/
public function setClan($clan) {
2014-01-12 00:51:46 +01:00
$this->clan = (int) $clan;
return $this;
}
/**
2013-12-31 02:55:19 +01:00
* Set Draw Background
*
2014-01-12 00:51:46 +01:00
* @param bool $drawBg Whether Gauge Background should be drawn
* @return \FML\Controls\Gauge
*/
public function setDrawBg($drawBg) {
$this->drawBg = ($drawBg ? 1 : 0);
return $this;
}
/**
2013-12-31 02:55:19 +01:00
* Set Draw Block Background
*
2014-01-12 00:51:46 +01:00
* @param bool $drawBlockBg Whether Gauge Block Background should be drawn
* @return \FML\Controls\Gauge
*/
public function setDrawBlockBg($drawBlockBg) {
$this->drawBlockBg = ($drawBlockBg ? 1 : 0);
return $this;
}
/**
*
* @see \FML\Types\Styleable::setStyle()
2013-12-31 02:55:19 +01:00
* @return \FML\Controls\Gauge
*/
public function setStyle($style) {
2014-01-12 00:51:46 +01:00
$this->style = (string) $style;
return $this;
}
/**
*
* @see \FML\Control::render()
*/
public function render(\DOMDocument $domDocument) {
2014-01-12 00:51:46 +01:00
$xmlElement = parent::render($domDocument);
2014-01-19 19:30:21 +01:00
if ($this->ratio) {
$xmlElement->setAttribute('ratio', $this->ratio);
}
if ($this->grading != 1.) {
$xmlElement->setAttribute('grading', $this->grading);
}
if ($this->color) {
2014-01-12 00:51:46 +01:00
$xmlElement->setAttribute('color', $this->color);
}
if ($this->rotation) {
2014-01-12 00:51:46 +01:00
$xmlElement->setAttribute('rotation', $this->rotation);
}
if ($this->centered) {
2014-01-12 00:51:46 +01:00
$xmlElement->setAttribute('centered', $this->centered);
}
if ($this->clan) {
2014-01-12 00:51:46 +01:00
$xmlElement->setAttribute('clan', $this->clan);
}
2014-01-19 19:30:21 +01:00
if (!$this->drawBg) {
$xmlElement->setAttribute('drawbg', $this->drawBg);
}
if (!$this->drawBlockBg) {
$xmlElement->setAttribute('drawblockbg', $this->drawBlockBg);
}
if ($this->style) {
2014-01-12 00:51:46 +01:00
$xmlElement->setAttribute('style', $this->style);
}
2014-01-12 00:51:46 +01:00
return $xmlElement;
}
}