1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163:
<?php
class ComponentXPBar extends Component
{
private $width;
private $height;
private $rounding;
private $hexColour;
public function __construct(
OsuSignature $signature,
$x = 0,
$y = 0,
$hexColour = "#ffa200",
$width = 0,
$height = 0,
$rounding = 1) {
parent::__construct($signature, $x, $y);
$this->width = $width;
$this->height = $height;
$this->rounding = $rounding;
$this->hexColour = $hexColour;
}
public function getWidth() {
return $this->width;
}
public function getHeight() {
return $this->height;
}
public function draw(OsuSignature $signature) {
if (empty($this->hexColour)) {
$this->hexColour = $signature->getHexColour();
}
$composite = new Imagick();
$composite->newPseudoImage($this->getWidth(), $this->getHeight(), "canvas:transparent");
$draw = new ImagickDraw();
$draw->setFillColor(new ImagickPixel("#555555"));
$draw->rectangle(0, 0, $this->getWidth(), $this->getHeight());
$composite->drawImage($draw);
$level = $signature->getUser()['level'];
$xp = $level - floor($level);
$draw = new ImagickDraw();
$draw->setFillColor(new ImagickPixel($this->hexColour));
$draw->rectangle(0, 0, $this->getWidth() * $xp, $this->getHeight());
$composite->drawImage($draw);
$draw = new ImagickDraw();
$draw->setFillColor(new ImagickPixel('#ffffff'));
$draw->setFillOpacity(0.35);
$draw->rectangle(($this->getWidth() * $xp) - $this->getHeight(), 0, $this->getWidth() * $xp, $this->getHeight());
$composite->drawImage($draw);
$textDraw = new ImagickDraw();
$textDraw->setFillColor(new ImagickPixel('#555555'));
$textDraw->setFontSize(12);
$textDraw->setFont(ComponentLabel::FONT_DIRECTORY . ComponentLabel::FONT_REGULAR);
$textDraw->setGravity(Imagick::GRAVITY_NORTHWEST);
$metrics = $composite->queryFontMetrics($textDraw, 'lv' . floor($level));
$draw = new ImagickDraw();
$draw->setFillColor(new ImagickPixel('#ffffff'));
$draw->rectangle(
($this->getWidth() - $metrics['textWidth']) / 2 - 2,
0,
($this->getWidth() + $metrics['textWidth']) / 2 + 1,
$this->getHeight());
$composite->drawImage($draw);
$roundMask = new Imagick();
$roundMask->newPseudoImage($this->getWidth(), $this->getHeight(), "canvas:transparent");
$draw = new ImagickDraw();
$draw->setFillColor(new ImagickPixel("black"));
$draw->roundRectangle(0, 0, $this->getWidth() - 1, $this->getHeight() - 1, $this->rounding, $this->rounding);
$roundMask->drawImage($draw);
$roundMask->setImageFormat('png');
$composite->compositeImage(
$roundMask,
Imagick::COMPOSITE_DSTIN,
0,
0,
Imagick::CHANNEL_ALPHA
);
$signature->getCanvas()->compositeImage($composite, Imagick::COMPOSITE_DEFAULT, $this->x, $this->y);
$signature->getCanvas()->annotateImage(
$textDraw,
$this->x + ($this->getWidth() - $metrics['textWidth']) / 2,
$this->y + ($this->getHeight() - $metrics['textHeight']) / 2 - 2,
0,
'lv' . floor($level));
}
}