TrackManiaControl/application/libs/FML/Controls/Quad.php

340 lines
7.3 KiB
PHP
Raw Normal View History

<?php
namespace FML\Controls;
2014-05-14 23:24:00 +02:00
use FML\Models\CheckBoxDesign;
use FML\Types\Actionable;
use FML\Types\BgColorable;
use FML\Types\Linkable;
use FML\Types\Scriptable;
use FML\Types\Styleable;
use FML\Types\SubStyleable;
/**
2014-01-19 19:30:21 +01:00
* Quad Control
2014-01-12 00:51:46 +01:00
* (CMlQuad)
*
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-14 23:24:00 +02:00
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
*/
class Quad extends Control implements Actionable, BgColorable, Linkable, Scriptable, Styleable, SubStyleable {
2014-07-04 23:50:43 +02:00
/*
* Constants
*/
const KEEP_RATIO_INACTIVE = 'inactive';
const KEEP_RATIO_CLIP = 'Clip';
const KEEP_RATIO_FIT = 'Fit';
2014-01-21 20:30:40 +01:00
/*
2014-06-21 03:18:21 +02:00
* Protected properties
*/
protected $tagName = 'quad';
protected $image = null;
protected $imageId = null;
protected $imageFocus = null;
protected $imageFocusId = null;
protected $colorize = null;
protected $modulizeColor = null;
2014-01-12 00:51:46 +01:00
protected $autoScale = 1;
2014-07-04 23:50:43 +02:00
protected $keepRatio = null;
2014-06-21 03:18:21 +02:00
protected $action = null;
2014-01-12 00:51:46 +01:00
protected $actionKey = -1;
2014-06-21 03:18:21 +02:00
protected $bgColor = null;
protected $url = null;
protected $urlId = null;
protected $manialink = null;
protected $manialinkId = null;
protected $scriptEvents = null;
protected $style = null;
protected $subStyle = null;
2014-07-04 23:50:43 +02:00
protected $styleSelected = null;
protected $opacity = 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 'CMlQuad';
}
/**
2014-06-21 03:18:21 +02:00
* Set image url
*
2014-06-21 03:18:21 +02:00
* @param string $image Image url
2014-07-03 22:34:47 +02:00
* @return static
*/
public function setImage($image) {
2014-05-14 23:24:00 +02:00
$this->image = (string)$image;
return $this;
}
2014-01-19 19:30:21 +01:00
/**
2014-06-21 03:18:21 +02:00
* Set image id to use from Dico
2014-01-19 19:30:21 +01:00
*
2014-06-21 03:18:21 +02:00
* @param string $imageId Image id
2014-07-03 22:34:47 +02:00
* @return static
2014-01-19 19:30:21 +01:00
*/
public function setImageId($imageId) {
2014-05-14 23:24:00 +02:00
$this->imageId = (string)$imageId;
2014-01-19 19:30:21 +01:00
return $this;
}
/**
2014-06-21 03:18:21 +02:00
* Set focus image url
*
2014-06-21 03:18:21 +02:00
* @param string $imageFocus Focus image url
2014-07-03 22:34:47 +02:00
* @return static
*/
public function setImageFocus($imageFocus) {
2014-05-14 23:24:00 +02:00
$this->imageFocus = (string)$imageFocus;
return $this;
}
2014-01-19 19:30:21 +01:00
/**
2014-06-21 03:18:21 +02:00
* Set focus image id to use from Dico
2014-01-19 19:30:21 +01:00
*
2014-06-21 03:18:21 +02:00
* @param string $imageFocusId Focus image id
2014-07-03 22:34:47 +02:00
* @return static
2014-01-19 19:30:21 +01:00
*/
public function setImageFocusId($imageFocusId) {
2014-05-14 23:24:00 +02:00
$this->imageFocusId = (string)$imageFocusId;
2014-01-19 19:30:21 +01:00
return $this;
}
/**
2014-06-21 03:18:21 +02:00
* Set colorization
*
2014-06-21 03:18:21 +02:00
* @param string $colorize Colorize value
2014-07-03 22:34:47 +02:00
* @return static
*/
public function setColorize($colorize) {
2014-05-14 23:24:00 +02:00
$this->colorize = (string)$colorize;
return $this;
}
/**
2014-06-21 03:18:21 +02:00
* Set modulization
*
2014-06-21 03:18:21 +02:00
* @param string $modulizeColor Modulize value
2014-07-03 22:34:47 +02:00
* @return static
*/
public function setModulizeColor($modulizeColor) {
2014-05-14 23:24:00 +02:00
$this->modulizeColor = (string)$modulizeColor;
2014-01-12 00:51:46 +01:00
return $this;
}
/**
2014-06-21 03:18:21 +02:00
* Disable the automatic image scaling
2014-01-12 00:51:46 +01:00
*
2014-06-21 03:18:21 +02:00
* @param bool $autoScale Whether the image should scale automatically
2014-07-03 22:34:47 +02:00
* @return static
2014-01-12 00:51:46 +01:00
*/
public function setAutoScale($autoScale) {
$this->autoScale = ($autoScale ? 1 : 0);
return $this;
}
2014-07-04 23:50:43 +02:00
/**
* Set Keep Ratio Mode
*
* @param string $keepRatio Keep Ratio Mode
* @return static
*/
public function setKeepRatio($keepRatio) {
$this->keepRatio = (string)$keepRatio;
return $this;
}
/**
2014-05-16 22:44:22 +02:00
* @see \FML\Types\Actionable::getAction()
*/
2014-05-16 22:44:22 +02:00
public function getAction() {
return $this->action;
2014-01-12 00:51:46 +01:00
}
2014-01-21 20:30:40 +01:00
/**
2014-05-16 22:44:22 +02:00
* @see \FML\Types\Actionable::setAction()
2014-01-21 20:30:40 +01:00
*/
2014-05-16 22:44:22 +02:00
public function setAction($action) {
$this->action = (string)$action;
return $this;
2014-01-21 20:30:40 +01:00
}
2014-01-12 00:51:46 +01:00
/**
* @see \FML\Types\Actionable::setActionKey()
*/
public function setActionKey($actionKey) {
2014-05-14 23:24:00 +02:00
$this->actionKey = (int)$actionKey;
return $this;
}
/**
* @see \FML\Types\BgColorable::setBgColor()
*/
public function setBgColor($bgColor) {
2014-05-14 23:24:00 +02:00
$this->bgColor = (string)$bgColor;
return $this;
}
/**
* @see \FML\Types\Linkable::setUrl()
*/
public function setUrl($url) {
2014-05-14 23:24:00 +02:00
$this->url = (string)$url;
return $this;
}
2014-01-19 19:30:21 +01:00
/**
* @see \FML\Types\Linkable::setUrlId()
*/
public function setUrlId($urlId) {
2014-05-14 23:24:00 +02:00
$this->urlId = (string)$urlId;
2014-01-19 19:30:21 +01:00
return $this;
}
/**
* @see \FML\Types\Linkable::setManialink()
*/
public function setManialink($manialink) {
2014-05-14 23:24:00 +02:00
$this->manialink = (string)$manialink;
return $this;
}
2014-01-19 19:30:21 +01:00
/**
* @see \FML\Types\Linkable::setManialinkId()
*/
public function setManialinkId($manialinkId) {
2014-05-14 23:24:00 +02:00
$this->manialinkId = (string)$manialinkId;
2014-01-19 19:30:21 +01:00
return $this;
}
/**
* @see \FML\Types\Scriptable::setScriptEvents()
*/
public function setScriptEvents($scriptEvents) {
$this->scriptEvents = ($scriptEvents ? 1 : 0);
return $this;
}
2014-05-16 22:44:22 +02:00
/**
* @see \FML\Types\SubStyleable::setStyles()
*/
public function setStyles($style, $subStyle) {
$this->setStyle($style);
$this->setSubStyle($subStyle);
return $this;
}
/**
* @see \FML\Types\Styleable::setStyle()
*/
public function setStyle($style) {
2014-05-14 23:24:00 +02:00
$this->style = (string)$style;
return $this;
}
/**
* @see \FML\Types\SubStyleable::setSubStyle()
*/
public function setSubStyle($subStyle) {
2014-05-14 23:24:00 +02:00
$this->subStyle = (string)$subStyle;
return $this;
}
2014-07-04 23:50:43 +02:00
/**
* Set selected mode
*
* @param bool $styleSelected
* @return static
*/
public function setStyleSelected($styleSelected) {
$this->styleSelected = ($styleSelected ? 1 : 0);
return $this;
}
/**
* Set opacity
*
* @param float $opacity
* @return static
*/
public function setOpacity($opacity) {
$this->opacity = (float)$opacity;
return $this;
}
/**
2014-05-14 23:24:00 +02:00
* Apply the given CheckBox Design
*
2014-05-14 23:24:00 +02:00
* @param CheckBoxDesign $checkBoxDesign CheckBox Design
2014-07-03 22:34:47 +02:00
* @return static
2014-05-14 23:24:00 +02:00
*/
public function applyCheckBoxDesign(CheckBoxDesign $checkBoxDesign) {
$checkBoxDesign->applyToQuad($this);
return $this;
}
/**
2014-06-21 03:18:21 +02:00
* @see \FML\Types\Renderable::render()
*/
public function render(\DOMDocument $domDocument) {
2014-01-12 00:51:46 +01:00
$xmlElement = parent::render($domDocument);
if ($this->image) {
2014-01-12 00:51:46 +01:00
$xmlElement->setAttribute('image', $this->image);
}
2014-01-19 19:30:21 +01:00
if ($this->imageId) {
$xmlElement->setAttribute('imageid', $this->imageId);
}
if ($this->imageFocus) {
2014-01-12 00:51:46 +01:00
$xmlElement->setAttribute('imagefocus', $this->imageFocus);
}
2014-01-19 19:30:21 +01:00
if ($this->imageFocusId) {
$xmlElement->setAttribute('imagefocusid', $this->imageFocusId);
}
if ($this->colorize) {
2014-01-12 00:51:46 +01:00
$xmlElement->setAttribute('colorize', $this->colorize);
}
if ($this->modulizeColor) {
2014-01-12 00:51:46 +01:00
$xmlElement->setAttribute('modulizecolor', $this->modulizeColor);
}
if (!$this->autoScale) {
$xmlElement->setAttribute('autoscale', $this->autoScale);
}
2014-07-04 23:50:43 +02:00
if ($this->keepRatio) {
$xmlElement->setAttribute('keepratio', $this->keepRatio);
}
2014-01-21 20:30:40 +01:00
if (strlen($this->action) > 0) {
2014-01-12 00:51:46 +01:00
$xmlElement->setAttribute('action', $this->action);
}
if ($this->actionKey >= 0) {
$xmlElement->setAttribute('actionkey', $this->actionKey);
}
if ($this->bgColor) {
2014-01-12 00:51:46 +01:00
$xmlElement->setAttribute('bgcolor', $this->bgColor);
}
if ($this->url) {
2014-01-12 00:51:46 +01:00
$xmlElement->setAttribute('url', $this->url);
}
if ($this->manialink) {
2014-01-12 00:51:46 +01:00
$xmlElement->setAttribute('manialink', $this->manialink);
}
if ($this->scriptEvents) {
2014-01-12 00:51:46 +01:00
$xmlElement->setAttribute('scriptevents', $this->scriptEvents);
}
if ($this->style) {
2014-01-12 00:51:46 +01:00
$xmlElement->setAttribute('style', $this->style);
}
if ($this->subStyle) {
2014-01-12 00:51:46 +01:00
$xmlElement->setAttribute('substyle', $this->subStyle);
}
2014-07-04 23:50:43 +02:00
if ($this->styleSelected) {
$xmlElement->setAttribute('styleselected', $this->styleSelected);
}
if ($this->opacity !== 1.) {
$xmlElement->setAttribute('opacity', $this->opacity);
}
2014-01-12 00:51:46 +01:00
return $xmlElement;
}
}