[client] update haxework. ep6
This commit is contained in:
44
src/client/haxe/ru/m/skin/ButtonSVGSkin.hx
Normal file
44
src/client/haxe/ru/m/skin/ButtonSVGSkin.hx
Normal file
@@ -0,0 +1,44 @@
|
||||
package ru.m.skin;
|
||||
|
||||
import haxework.color.ColorUtil;
|
||||
import haxework.color.Color;
|
||||
import haxework.gui.ButtonView;
|
||||
import format.SVG;
|
||||
import haxework.gui.skin.ISkin;
|
||||
|
||||
class ButtonSVGSkin implements ISkin<ButtonView> {
|
||||
|
||||
private var svg:String;
|
||||
private var color:Color;
|
||||
|
||||
private var svgs:Map<ButtonState, SVG>;
|
||||
|
||||
public function new(svg:String, color:Color) {
|
||||
this.svg = svg;
|
||||
this.color = color;
|
||||
init();
|
||||
}
|
||||
|
||||
private inline function buildSVG(color:Color):SVG {
|
||||
return new SVG(StringTools.replace(svg, "currentColor", '#${StringTools.hex(color)}'));
|
||||
}
|
||||
|
||||
private function init():Void {
|
||||
svgs = new Map<ButtonState, SVG>();
|
||||
svgs.set(ButtonState.UP, buildSVG(color));
|
||||
svgs.set(ButtonState.DOWN, buildSVG(ColorUtil.diff(color, -24)));
|
||||
svgs.set(ButtonState.OVER, buildSVG(ColorUtil.diff(color, 24)));
|
||||
}
|
||||
|
||||
public function draw(view:ButtonView):Void {
|
||||
var svg = svgs.get(view.state);
|
||||
var graphics = view.content.graphics;
|
||||
graphics.beginFill(0, 0);
|
||||
graphics.drawRect(0, 0, view.width, view.height);
|
||||
graphics.beginFill(color);
|
||||
graphics.lineStyle(2, ColorUtil.multiply(color, 1.5));
|
||||
svg.render(graphics, 0, 0, Std.int(view.width * 0.8), Std.int(view.height * 0.8));
|
||||
graphics.lineStyle();
|
||||
graphics.endFill();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user