2013-11-25 00:02:07 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace FML\Controls;
|
|
|
|
|
2017-03-25 18:40:15 +01:00
|
|
|
use FML\Types\Colorable;
|
2013-11-28 01:12:52 +01:00
|
|
|
use FML\Types\Styleable;
|
|
|
|
|
2013-11-25 00:02:07 +01:00
|
|
|
/**
|
2014-01-19 19:30:21 +01:00
|
|
|
* Gauge Control
|
2014-01-12 00:51:46 +01:00
|
|
|
* (CMlGauge)
|
2013-11-25 00:02:07 +01:00
|
|
|
*
|
2014-05-20 15:44:45 +02:00
|
|
|
* @author steeffeen <mail@steeffeen.com>
|
2017-03-25 18:40:15 +01:00
|
|
|
* @copyright FancyManiaLinks Copyright © 2017 Steffen Schröder
|
2014-05-16 22:44:22 +02:00
|
|
|
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
2013-11-25 00:02:07 +01:00
|
|
|
*/
|
2017-03-25 18:40:15 +01:00
|
|
|
class Gauge extends Control implements Colorable, Styleable
|
|
|
|
{
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Constants
|
|
|
|
*/
|
|
|
|
const STYLE_BgCard = "BgCard";
|
|
|
|
const STYLE_EnergyBar = "EnergyBar";
|
|
|
|
const STYLE_ProgressBar = "ProgressBar";
|
|
|
|
const STYLE_ProgressBarSmall = "ProgressBarSmall";
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var float $ratio Ratio
|
|
|
|
*/
|
|
|
|
protected $ratio = 0.0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var float $grading Grading
|
|
|
|
*/
|
|
|
|
protected $grading = 1.;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var string $color Color
|
|
|
|
*/
|
|
|
|
protected $color = null;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var bool $centered Centered
|
|
|
|
*/
|
|
|
|
protected $centered = null;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var int $clan Clan number
|
|
|
|
*/
|
|
|
|
protected $clan = null;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var bool $drawBackground Draw background
|
|
|
|
*/
|
|
|
|
protected $drawBackground = true;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var bool $drawBlockBackground Draw block background
|
|
|
|
*/
|
|
|
|
protected $drawBlockBackground = true;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var string $style Style
|
|
|
|
*/
|
|
|
|
protected $style = null;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the ratio
|
|
|
|
*
|
|
|
|
* @api
|
|
|
|
* @return float
|
|
|
|
*/
|
|
|
|
public function getRatio()
|
|
|
|
{
|
|
|
|
return $this->ratio;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the ratio
|
|
|
|
*
|
|
|
|
* @api
|
|
|
|
* @param float $ratio Ratio value
|
|
|
|
* @return static
|
|
|
|
*/
|
|
|
|
public function setRatio($ratio)
|
|
|
|
{
|
|
|
|
$this->ratio = (float)$ratio;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the grading
|
|
|
|
*
|
|
|
|
* @api
|
|
|
|
* @return float
|
|
|
|
*/
|
|
|
|
public function getGrading()
|
|
|
|
{
|
|
|
|
return $this->grading;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the grading
|
|
|
|
*
|
|
|
|
* @api
|
|
|
|
* @param float $grading Grading value
|
|
|
|
* @return static
|
|
|
|
*/
|
|
|
|
public function setGrading($grading)
|
|
|
|
{
|
|
|
|
$this->grading = (float)$grading;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @see Colorable::getColor
|
|
|
|
*/
|
|
|
|
public function getColor()
|
|
|
|
{
|
|
|
|
return $this->color;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @see Colorable::setColor
|
|
|
|
*/
|
|
|
|
public function setColor($color)
|
|
|
|
{
|
|
|
|
$this->color = (string)$color;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get centered
|
|
|
|
*
|
|
|
|
* @api
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function getCentered()
|
|
|
|
{
|
|
|
|
return $this->centered;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set centered
|
|
|
|
*
|
|
|
|
* @api
|
|
|
|
* @param bool $centered If the Gauge should be centered
|
|
|
|
* @return static
|
|
|
|
*/
|
|
|
|
public function setCentered($centered)
|
|
|
|
{
|
|
|
|
$this->centered = (bool)$centered;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the clan
|
|
|
|
*
|
|
|
|
* @api
|
|
|
|
* @return int
|
|
|
|
*/
|
|
|
|
public function getClan()
|
|
|
|
{
|
|
|
|
return $this->clan;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the clan
|
|
|
|
*
|
|
|
|
* @api
|
|
|
|
* @param int $clan Clan number
|
|
|
|
* @return static
|
|
|
|
*/
|
|
|
|
public function setClan($clan)
|
|
|
|
{
|
|
|
|
$this->clan = (int)$clan;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get draw background
|
|
|
|
*
|
|
|
|
* @api
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function getDrawBackground()
|
|
|
|
{
|
|
|
|
return $this->drawBackground;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set draw background
|
|
|
|
*
|
|
|
|
* @api
|
2017-04-02 16:32:57 +02:00
|
|
|
* @param bool $drawBackground If the Gauge background should be drawn
|
2017-03-25 18:40:15 +01:00
|
|
|
* @return static
|
2017-04-02 16:32:57 +02:00
|
|
|
* @deprecated Use setDrawBackground()
|
|
|
|
* @see Gauge::setDrawBackground()
|
2017-03-25 18:40:15 +01:00
|
|
|
*/
|
|
|
|
public function setDrawBg($drawBackground)
|
|
|
|
{
|
|
|
|
return $this->setDrawBackground($drawBackground);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set draw background
|
|
|
|
*
|
|
|
|
* @api
|
2017-04-02 16:32:57 +02:00
|
|
|
* @param bool $drawBackground If the Gauge background should be drawn
|
2017-03-25 18:40:15 +01:00
|
|
|
* @return static
|
|
|
|
*/
|
|
|
|
public function setDrawBackground($drawBackground)
|
|
|
|
{
|
|
|
|
$this->drawBackground = (bool)$drawBackground;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get draw block background
|
|
|
|
*
|
|
|
|
* @api
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function getDrawBlockBackground()
|
|
|
|
{
|
|
|
|
return $this->drawBlockBackground;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set draw block background
|
|
|
|
*
|
|
|
|
* @api
|
2017-04-02 16:32:57 +02:00
|
|
|
* @param bool $drawBlockBackground If the Gauge block background should be drawn
|
2017-03-25 18:40:15 +01:00
|
|
|
* @return static
|
|
|
|
*/
|
|
|
|
public function setDrawBlockBackground($drawBlockBackground)
|
|
|
|
{
|
|
|
|
$this->drawBlockBackground = (bool)$drawBlockBackground;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @see Styleable::getStyle()
|
|
|
|
*/
|
|
|
|
public function getStyle()
|
|
|
|
{
|
|
|
|
return $this->style;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @see Styleable::setStyle()
|
|
|
|
*/
|
|
|
|
public function setStyle($style)
|
|
|
|
{
|
|
|
|
$this->style = (string)$style;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @see Control::getTagName()
|
|
|
|
*/
|
|
|
|
public function getTagName()
|
|
|
|
{
|
|
|
|
return "gauge";
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @see Control::getManiaScriptClass()
|
|
|
|
*/
|
|
|
|
public function getManiaScriptClass()
|
|
|
|
{
|
|
|
|
return "CMlGauge";
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @see Control::render()
|
|
|
|
*/
|
|
|
|
public function render(\DOMDocument $domDocument)
|
|
|
|
{
|
|
|
|
$domElement = parent::render($domDocument);
|
|
|
|
if ($this->ratio) {
|
|
|
|
$domElement->setAttribute("ratio", $this->ratio);
|
|
|
|
}
|
2017-04-02 16:32:57 +02:00
|
|
|
if ($this->grading !== 1.) {
|
2017-03-25 18:40:15 +01:00
|
|
|
$domElement->setAttribute("grading", $this->grading);
|
|
|
|
}
|
|
|
|
if ($this->color) {
|
|
|
|
$domElement->setAttribute("color", $this->color);
|
|
|
|
}
|
|
|
|
if ($this->centered) {
|
|
|
|
$domElement->setAttribute("centered", 1);
|
|
|
|
}
|
|
|
|
if ($this->clan) {
|
|
|
|
$domElement->setAttribute("clan", $this->clan);
|
|
|
|
}
|
|
|
|
if (!$this->drawBackground) {
|
|
|
|
$domElement->setAttribute("drawbg", 0);
|
|
|
|
}
|
|
|
|
if (!$this->drawBlockBackground) {
|
|
|
|
$domElement->setAttribute("drawblockbg", 0);
|
|
|
|
}
|
|
|
|
if ($this->style) {
|
|
|
|
$domElement->setAttribute("style", $this->style);
|
|
|
|
}
|
|
|
|
return $domElement;
|
|
|
|
}
|
|
|
|
|
2013-11-25 00:02:07 +01:00
|
|
|
}
|