68 lines
1.9 KiB
Haxe
68 lines
1.9 KiB
Haxe
package components;
|
|
|
|
import feathers.controls.ToggleButton;
|
|
import feathers.skins.RectangleSkin;
|
|
import feathers.text.TextFormat;
|
|
import format.SVG;
|
|
import model.Constants;
|
|
import openfl.display.Shape;
|
|
import openfl.events.Event;
|
|
import openfl.geom.ColorTransform;
|
|
import openfl.text.Font;
|
|
import openfl.utils.Assets;
|
|
|
|
class ToolbarToggleButton extends ToggleButton {
|
|
|
|
private var svgIconPath:String;
|
|
private var svgIcon:Shape;
|
|
private var unselectedColor:Int;
|
|
private var selectedColor:Int;
|
|
|
|
public function new(pSvgIconPath:String = null, pUnselectedColor:Int = 0x00FF00, pSelectedColor:Int = 0x000000) {
|
|
super();
|
|
|
|
svgIconPath = pSvgIconPath;
|
|
unselectedColor = pSelectedColor;
|
|
selectedColor = pUnselectedColor;
|
|
}
|
|
|
|
override private function initialize():Void {
|
|
super.initialize();
|
|
|
|
iconPosition = TOP;
|
|
embedFonts = true;
|
|
backgroundSkin = new RectangleSkin(SolidColor( 0xFF0000, 0));
|
|
|
|
// icon
|
|
if(svgIconPath != null){
|
|
svgIcon = new Shape();
|
|
colorizeIcon(unselectedColor);
|
|
new SVG(svgIconPath).render(svgIcon.graphics);
|
|
icon = svgIcon;
|
|
icon.width = icon.height = 40;
|
|
|
|
iconOffsetY = 0;
|
|
}
|
|
|
|
// text
|
|
var fnt:Font = Assets.getFont(Constants.MONTSERRAT_REGULAR_400);
|
|
textFormat = new TextFormat(fnt.fontName, 16, unselectedColor);
|
|
selectedTextFormat = new TextFormat(fnt.fontName, 16, selectedColor);
|
|
|
|
addEventListener(Event.CHANGE, onButtonStateChange);
|
|
|
|
}
|
|
|
|
private function colorizeIcon(pColor:Int) {
|
|
|
|
var ct = new ColorTransform();
|
|
ct.color = pColor;
|
|
svgIcon.transform.colorTransform = ct;
|
|
}
|
|
|
|
private function onButtonStateChange(e:Event):Void {
|
|
selected ? colorizeIcon(selectedColor) : colorizeIcon(unselectedColor);
|
|
}
|
|
|
|
}
|