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

196 lines
4.0 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)
*
2014-05-16 22:44:22 +02:00
* @author steeffeen
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 Gauge extends Control implements Styleable {
2014-01-21 20:30:40 +01:00
/*
* Constants
*/
2014-05-16 22:44:22 +02:00
const STYLE_BgCard = 'BgCard';
const STYLE_EnergyBar = 'EnergyBar';
const STYLE_ProgressBar = 'ProgressBar';
2014-01-21 20:30:40 +01:00
const STYLE_ProgressBarSmall = 'ProgressBarSmall';
2014-05-16 22:44:22 +02:00
2014-01-21 20:30:40 +01:00
/*
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-05-16 22:44:22 +02:00
/**
* Construct a new Gauge Control
*
* @param string $id (optional) Control Id
*/
public function __construct($id = null) {
parent::__construct($id);
$this->tagName = 'gauge';
}
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;
}
/**
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 'CMlGauge';
}
/**
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-05-16 22:44:22 +02: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-05-16 22:44:22 +02: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-05-16 22:44:22 +02: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-05-16 22:44:22 +02: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-05-16 22:44:22 +02: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()
*/
public function setStyle($style) {
2014-05-16 22:44:22 +02: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;
}
}