package components;

import feathers.skins.RectangleSkin;
import feathers.controls.Button;
import format.SVG;
import openfl.display.Bitmap;
import openfl.display.BitmapData;
import openfl.display.Shape;
import openfl.geom.ColorTransform;

class IconButton extends Button {

    private var svgIconPath:String;
    private var svgIcon:Shape;
    private var upColor:Int;

	public function new(pSvgIconPath:String = null, pUpColor:Int = 0x000000) {
		super();

        svgIconPath = pSvgIconPath;
        upColor = pUpColor;
	}

    override private function initialize():Void {
        super.initialize();

        iconPosition = TOP;
        //backgroundSkin = new Bitmap(new BitmapData(10, 10, true, 0xFF00FF));
        backgroundSkin = new RectangleSkin(SolidColor( 0xFF0000, 0));

        // icon
        if(svgIconPath != null){
            svgIcon = new Shape();
            colorizeSvgIcon(upColor);
            new SVG(svgIconPath).render(svgIcon.graphics);
            icon = svgIcon;
            icon.width = icon.height = 40;
        }
    }

    private function colorizeSvgIcon(pColor:Int) {
        
        var ct = new ColorTransform();
        ct.color = pColor;
        svgIcon.transform.colorTransform = ct;
    }

}
