TrackManiaControl/libs/FML/Models/CheckBoxDesign.php

130 lines
2.9 KiB
PHP
Raw Normal View History

2014-05-14 23:24:00 +02:00
<?php
namespace FML\Models;
use FML\Controls\Quad;
use FML\Controls\Quads\Quad_Icons64x64_1;
use FML\Script\Builder;
use FML\Types\Styleable;
use FML\Types\SubStyleable;
/**
* Class representing CheckBox Design
*
2014-05-20 15:44:45 +02:00
* @author steeffeen <mail@steeffeen.com>
2014-05-14 23:24:00 +02:00
* @copyright FancyManiaLinks Copyright © 2014 Steffen Schröder
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
*/
class CheckBoxDesign implements Styleable, SubStyleable {
/*
2014-06-21 03:18:21 +02:00
* Protected properties
2014-05-14 23:24:00 +02:00
*/
protected $url = null;
protected $style = null;
protected $subStyle = null;
/**
2014-06-21 03:18:21 +02:00
* Create the default enabled Design
2014-05-14 23:24:00 +02:00
*
2014-07-03 22:34:47 +02:00
* @return static
2014-05-14 23:24:00 +02:00
*/
public static function defaultEnabledDesign() {
2014-06-21 03:18:21 +02:00
return new static(Quad_Icons64x64_1::STYLE, Quad_Icons64x64_1::SUBSTYLE_Check);
2014-05-14 23:24:00 +02:00
}
/**
2014-06-21 03:18:21 +02:00
* Create the default disabled Design
2014-05-14 23:24:00 +02:00
*
2014-07-03 22:34:47 +02:00
* @return static
2014-05-14 23:24:00 +02:00
*/
public static function defaultDisabledDesign() {
2014-06-21 03:18:21 +02:00
return new static(Quad_Icons64x64_1::STYLE, Quad_Icons64x64_1::SUBSTYLE_Check);
2014-05-14 23:24:00 +02:00
}
/**
2014-06-21 03:18:21 +02:00
* Construct a new CheckBox Design object
2014-05-14 23:24:00 +02:00
*
2014-06-21 03:18:21 +02:00
* @param string $style Style name or image url
* @param string $subStyle (optional) SubStyle name
2014-05-14 23:24:00 +02:00
*/
public function __construct($style, $subStyle = null) {
2014-08-11 23:15:53 +02:00
if ($subStyle === null) {
2014-05-14 23:24:00 +02:00
$this->setImageUrl($style);
} else {
$this->setStyle($style);
$this->setSubStyle($subStyle);
}
}
/**
2014-06-21 03:18:21 +02:00
* Set the image url
2014-05-14 23:24:00 +02:00
*
2014-06-21 03:18:21 +02:00
* @param string $url Image url
2014-07-03 22:34:47 +02:00
* @return static
2014-05-14 23:24:00 +02:00
*/
public function setImageUrl($url) {
$this->url = (string)$url;
$this->style = null;
$this->subStyle = null;
return $this;
}
/**
* @see \FML\Types\Styleable::setStyle()
*/
public function setStyle($style) {
$this->style = (string)$style;
$this->url = null;
return $this;
}
/**
* @see \FML\Types\SubStyleable::setSubStyle()
*/
public function setSubStyle($subStyle) {
$this->subStyle = (string)$subStyle;
$this->url = null;
return $this;
}
/**
* @see \FML\Types\SubStyleable::setStyles()
*/
public function setStyles($style, $subStyle) {
$this->setStyle($style);
$this->setSubStyle($subStyle);
return $this;
}
/**
* Apply the Design to the given Quad
*
* @param Quad $quad CheckBox Quad
2014-07-03 22:34:47 +02:00
* @return static
2014-05-14 23:24:00 +02:00
*/
public function applyToQuad(Quad $quad) {
$quad->setImage($this->url);
$quad->setStyles($this->style, $this->subStyle);
return $this;
}
/**
2014-06-21 03:18:21 +02:00
* Get the CheckBox Design string
2014-05-14 23:24:00 +02:00
*
2014-06-21 03:18:21 +02:00
* @param bool $escaped (optional) Whether the string should be escaped for the Script
* @param bool $addApostrophes (optional) Whether to add apostrophes before and after the text
2014-05-14 23:24:00 +02:00
* @return string
*/
2014-06-21 03:18:21 +02:00
public function getDesignString($escaped = true, $addApostrophes = true) {
2014-08-11 23:15:53 +02:00
if ($this->url !== null) {
2014-05-14 23:24:00 +02:00
$string = $this->url;
} else {
$string = $this->style . '|' . $this->subStyle;;
}
2014-05-16 22:44:22 +02:00
if ($escaped) {
2014-06-21 03:18:21 +02:00
return Builder::escapeText($string, $addApostrophes);
2014-05-16 22:44:22 +02:00
}
return $string;
2014-05-14 23:24:00 +02:00
}
}