flash.moe/lib/fmcolour.php
2020-07-30 00:55:37 +00:00

28 lines
790 B
PHP

<?php
class FmColour {
private $raw = null;
public function __construct(?int $raw) {
$this->raw = $raw;
}
public function hasColour(): bool {
return $this->raw !== null;
}
public function getRaw(): int {
return $this->raw ?? 0;
}
public function getRed(): int { return ($this->getRaw() >> 16) & 0xFF; }
public function getGreen(): int { return ($this->getRaw() >> 8) & 0xFF; }
public function getBlue(): int { return $this->getRaw() & 0xFF; }
public function getHex(): string { return str_pad(dechex($this->getRaw()), 6, '0'); }
public function getCSS(): string {
if(!$this->hasColour())
return 'inherit';
return '#' . $this->getHex();
}
}