- Buttons changed to ToggleButtons
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
package components;
|
||||
|
||||
import feathers.controls.ToggleButton;
|
||||
import feathers.text.TextFormat;
|
||||
import format.SVG;
|
||||
import model.Constants;
|
||||
import openfl.display.Bitmap;
|
||||
import openfl.display.BitmapData;
|
||||
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 Bitmap(new BitmapData(10, 10, true, 0xFF00FF));
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user