[update] :-)

This commit is contained in:
2020-02-07 17:06:46 +03:00
parent 079b1ef72a
commit 75fcf986d0
28 changed files with 176 additions and 38 deletions

View File

@@ -0,0 +1,56 @@
package ru.m.skin;
import format.SVG;
import haxework.color.Color;
import haxework.view.form.ButtonView;
import haxework.view.skin.ISkin;
using StringTools;
using haxework.color.ColorUtil;
@:style class ButtonSVGSkin implements ISkin<ButtonView> {
@:style(null) public var svg:String;
@:style(0) public var color:Null<Color>;
@:style(false) public var solid:Null<Bool>;
private var svgs:Map<ButtonState, SVG>;
public function new(?svg:String, ?color:Color, ?solid:Bool) {
this.svg = svg;
this.color = color;
this.solid = solid;
init(solid);
}
private inline function buildSVG(color:Color):SVG {
return new SVG(svg.replace("currentColor", '#${color}'));
}
private function init(solid:Bool):Void {
var color = color;
if (solid) {
color = color.multiply(1.5);
}
svgs = new Map();
svgs.set(UP, buildSVG(color));
svgs.set(DOWN, buildSVG(color.diff(-24)));
svgs.set(OVER, buildSVG(color.diff(24)));
svgs.set(DISABLED, buildSVG(color.grey()));
}
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);
if (!solid) {
graphics.lineStyle(2, color.multiply(1.5));
}
// ToDo: padding
svg.render(graphics, 0, 0, Std.int(view.width * 0.8), Std.int(view.height * 0.8));
graphics.lineStyle();
graphics.endFill();
}
}