mirror of
https://github.com/wbbaddons/Tims-Chat.git
synced 2025-01-09 00:20:08 +00:00
Moving gradient into ChatUtil
This commit is contained in:
parent
ac5ef926e3
commit
b8c85813b0
@ -66,18 +66,11 @@ public function getFormattedMessage() {
|
|||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function getFormattedUsername() {
|
public function getFormattedUsername() {
|
||||||
if ($this->type == self::TYPE_INFORMATION) return '<strong>'.$this->getUsername().'</strong>';
|
$username = $this->getUsername();
|
||||||
|
|
||||||
$string = str_split($this->getUsername());
|
if ($this->type != self::TYPE_INFORMATION) $username = \wcf\util\ChatUtil::gradient($username, $this->color1, $this->color2);
|
||||||
$r = (int) (($this->color1 >> 16 & 255) - ($this->color2 >> 16 & 255)) / (count($string) - 1);
|
|
||||||
$g = (int) (($this->color1 >> 8 & 255) - ($this->color2 >> 8 & 255)) / (count($string) - 1);
|
|
||||||
$b = (int) (($this->color1 & 255) - ($this->color2 & 255)) / (count($string) - 1);
|
|
||||||
$result = '';
|
|
||||||
for ($i = 0, $max = count($string); $i < $max; $i++) {
|
|
||||||
$result .= '<span style="color:rgb('.(($this->color1 >> 16 & 255) - $i * $r).', '.(($this->color1 >> 8 & 255) - $i * $g).', '.(($this->color1 & 255) - $i * $b).')">'.$string[$i].'</span>';
|
|
||||||
}
|
|
||||||
|
|
||||||
return '<strong>'.$result.'</strong>';
|
return '<strong>'.$username.'</strong>';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
37
file/lib/util/ChatUtil.class.php
Normal file
37
file/lib/util/ChatUtil.class.php
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
<?php
|
||||||
|
namespace \wcf\util;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Chat utilities
|
||||||
|
*
|
||||||
|
* @author Tim Düsterhus
|
||||||
|
* @copyright 2010-2011 Tim Düsterhus
|
||||||
|
* @license Creative Commons Attribution-NonCommercial-ShareAlike <http://creativecommons.org/licenses/by-nc-sa/3.0/legalcode>
|
||||||
|
* @package timwolla.wcf.chat
|
||||||
|
* @subpackage util
|
||||||
|
*/
|
||||||
|
class ChatUtil {
|
||||||
|
/**
|
||||||
|
* Creates a gradient out of two colors represented by an integer.
|
||||||
|
* The first byte is red, the second byte is green, the third one is blue.
|
||||||
|
* The numbers can be easily expressed in hexadecimal notation: 0xFF0000 being red.
|
||||||
|
*
|
||||||
|
* @param string $string
|
||||||
|
* @param integer $start
|
||||||
|
* @param integer $end
|
||||||
|
* @returen string
|
||||||
|
*/
|
||||||
|
public static function gradient($string, $start, $end) {
|
||||||
|
$string = str_split($string);
|
||||||
|
$r = (int) ((($start >> 16 & 255) - ($end >> 16 & 255)) / (count($string) - 1));
|
||||||
|
$g = (int) ((($start >> 8 & 255) - ($end >> 8 & 255)) / (count($string) - 1));
|
||||||
|
$b = (int) ((($start & 255) - ($end & 255)) / (count($string) - 1));
|
||||||
|
|
||||||
|
$result = '';
|
||||||
|
for ($i = 0, $max = count($string); $i < $max; $i++) {
|
||||||
|
$result .= '<span style="color:rgb('.(($start >> 16 & 255) - $i * $r).','.(($start >> 8 & 255) - $i * $g).','.(($start & 255) - $i * $b).')">'.$string[$i].'</span>';
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user