TrackManiaControl/libs/FML/Controls/Gauge.php

161 lines
3.2 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-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 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
/*
2014-06-21 03:18:21 +02:00
* Protected properties
*/
2014-06-21 03:18:21 +02:00
protected $tagName = 'gauge';
2014-01-19 19:30:21 +01:00
protected $ratio = 0.;
protected $grading = 1.;
2014-06-21 03:18:21 +02:00
protected $color = null;
protected $centered = null;
protected $clan = null;
protected $drawBg = 1;
protected $drawBlockBg = 1;
2014-06-21 03:18:21 +02:00
protected $style = null;
2014-01-19 19:30:21 +01:00
/**
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';
}
/**
2014-06-21 03:18:21 +02:00
* Set ratio
*
2014-06-21 03:18:21 +02:00
* @param float $ratio Ratio value
2014-07-03 22:34:47 +02:00
* @return static
*/
public function setRatio($ratio) {
2014-05-16 22:44:22 +02:00
$this->ratio = (float)$ratio;
return $this;
}
/**
2014-06-21 03:18:21 +02:00
* Set grading
*
2014-06-21 03:18:21 +02:00
* @param float $grading Grading value
2014-07-03 22:34:47 +02:00
* @return static
*/
public function setGrading($grading) {
2014-05-16 22:44:22 +02:00
$this->grading = (float)$grading;
return $this;
}
/**
2014-06-21 03:18:21 +02:00
* Set color
*
2014-06-21 03:18:21 +02:00
* @param string $color Gauge color
2014-07-03 22:34:47 +02:00
* @return static
*/
public function setColor($color) {
2014-05-16 22:44:22 +02:00
$this->color = (string)$color;
return $this;
}
/**
2014-06-21 03:18:21 +02:00
* Set centered
*
2014-06-21 03:18:21 +02:00
* @param bool $centered Whether the Gauge is centered
2014-07-03 22:34:47 +02:00
* @return static
*/
public function setCentered($centered) {
$this->centered = ($centered ? 1 : 0);
return $this;
}
/**
2014-06-21 03:18:21 +02:00
* Set clan
*
2014-01-12 00:51:46 +01:00
* @param int $clan Clan number
2014-07-03 22:34:47 +02:00
* @return static
*/
public function setClan($clan) {
2014-05-16 22:44:22 +02:00
$this->clan = (int)$clan;
return $this;
}
/**
2014-06-21 03:18:21 +02:00
* Set draw background
*
2014-06-21 03:18:21 +02:00
* @param bool $drawBg Whether the Gauges background should be drawn
2014-07-03 22:34:47 +02:00
* @return static
*/
public function setDrawBg($drawBg) {
$this->drawBg = ($drawBg ? 1 : 0);
return $this;
}
/**
2014-06-21 03:18:21 +02:00
* Set draw block background
*
2014-06-21 03:18:21 +02:00
* @param bool $drawBlockBg Whether the Gauges block background should be drawn
2014-07-03 22:34:47 +02:00
* @return static
*/
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->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;
}
}