/**
* Copyright zahir ( http://wonderfl.net/user/zahir )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/a2sY
*/
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" width="465" height="465" backgroundGradientColors="[0xEEEEEE,0xDDDDDD]"
creationComplete="init()">
<mx:Script>
<![CDATA[
//なんとなく作ってみた
import mx.graphics.codec.PNGEncoder;
import mx.collections.ArrayCollection;
private var t:TextField;
private var s:Sprite;
private var g:Graphics;
private var m:Matrix;
private function init():void{
(container.addChild( (s = new Sprite()) ) as Sprite ).addChild( (t = new TextField() ) );
t.autoSize = "left";
g = s.graphics;
g_type.dataProvider = new ArrayCollection(["linear","radial"]);
fonts.dataProvider = setFonts();
draw();
setTxt();
setFilter();
s.x = (canvas.width - 128) >> 1;
s.y = (canvas.height - 128) >> 1;
}
private function setTxt():void{
t.text = txt.text;
t.cacheAsBitmap = true;
t.setTextFormat( new TextFormat(fonts.selectedItem.toString(),
72,t_color.selectedColor, true) );
t.x = (128 - t.textWidth)>>1;
t.y = (128 - t.textHeight)>>1;
t.y += h_pos.value;
}
private function setFilter():void{
if(u_f.selected == false){ t.filters = []; return;}
var s1:DropShadowFilter = new DropShadowFilter(1,45, f_shadow.selectedColor ,0.4,2,2,2,3,true);
var s2:DropShadowFilter = new DropShadowFilter(1,45, f_light.selectedColor,0.4,2,2,1.5,3);
t.filters = [s1,s2];
}
private function setFonts():ArrayCollection{
var allFonts:Array = Font.enumerateFonts(true);
var _arr:Array = new Array();
allFonts.sortOn("fontName", Array.CASEINSENSITIVE);
for(var i:int=0;i<allFonts.length;i++) _arr[i] = String( allFonts[i].fontName );
return new ArrayCollection(_arr);
}
private function draw():void{
m = new Matrix();
m.createGradientBox(w.value, h.value, 0.017453 * rotate.value, tx.value, ty.value);
g.clear();
g.beginGradientFill(g_type.selectedItem as String, [c1.selectedColor, c2.selectedColor], [1,1], [ratios1.value, ratios2.value], m);
g.drawRoundRectComplex(0,0,128,128, tl.value, tr.value, bl.value, br.value);
g.endFill();
}
private function save():void{
var bd:BitmapData = new BitmapData(s.width,s.height);
bd.draw(s);
var png:PNGEncoder = new PNGEncoder();
var f:FileReference = new FileReference();
f.addEventListener(Event.SELECT, function(e:Event):void{});
f.save(png.encode(bd), txt.text + ".png");
bd.dispose();
}
]]>
</mx:Script>
<mx:Canvas x="0" y="0" width="465" height="45" backgroundColor="#111111" borderStyle="solid" borderColor="#000000" dropShadowEnabled="true">
<mx:Label text="Icon Generator" color="#FFFFFF" fontFamily="Times New Roman" fontWeight="bold" fontSize="28" height="38" y="5" x="8"/>
</mx:Canvas>
<mx:Canvas width="300" height="200" borderStyle="outset" backgroundColor="#FFFFFF" x="13" y="200" dropShadowEnabled="true" shadowDistance="3" shadowDirection="right" id="canvas">
<mx:UIComponent id="container" />
</mx:Canvas>
<mx:Label x="15" y="62" text="Text:"/>
<mx:TextInput x="47" y="60" width="40" id="txt" maxChars="3" text="Ig" change="setTxt();"/>
<mx:Label x="94" y="62" text="textColor:"/>
<mx:ColorPicker x="153" y="60" selectedColor="#CCCCCC" id="t_color" change="setTxt();"/>
<mx:Label x="15" y="100" text="TL:"/>
<mx:NumericStepper x="36" y="98" width="50" textAlign="right" id="tl" change="draw();" value="3" minimum="0" maximum="64"/>
<mx:Label x="90" y="100" text="TR:"/>
<mx:NumericStepper x="113" y="98" width="50" textAlign="right" id="tr" change="draw();" value="3" minimum="0" maximum="64"/>
<mx:Label x="167" y="100" text="BL:"/>
<mx:NumericStepper x="188" y="98" width="50" textAlign="right" id="bl" change="draw();" value="3" minimum="0" maximum="64"/>
<mx:Label x="242" y="100" text="BR:"/>
<mx:NumericStepper x="265" y="98" width="50" textAlign="right" id="br" change="draw();" value="3" minimum="0" maximum="64"/>
<mx:HRule x="15" y="90" width="300"/>
<mx:HRule x="15" y="126" width="300"/>
<mx:HRule x="15" y="159" width="300"/>
<mx:VRule x="323" y="53" height="402"/>
<mx:Label x="327" y="61" text="color1:"/>
<mx:ColorPicker x="369" y="59" id="c1" change="draw();" selectedColor="#666666"/>
<mx:Label x="395" y="61" text="color2:"/>
<mx:ColorPicker x="437" y="59" id="c2" change="draw();"/>
<mx:ComboBox x="328" y="89" width="130" dataProvider="" selectedIndex="0" id="g_type" change="draw();"></mx:ComboBox>
<mx:HSlider x="328" y="184" width="130" minimum="0" maximum="255" snapInterval="1" liveDragging="true" id="ratios2" value="255" tickValues="[0,255]" change="draw();"/>
<mx:HSlider x="328" y="144" width="130" minimum="0" maximum="255" snapInterval="1" liveDragging="true" id="ratios1" value="0" tickValues="[0,255]" change="draw();"/>
<mx:Label x="327" y="129" text="ratios1"/>
<mx:HSlider x="328" y="224" width="130" minimum="0" maximum="360" snapInterval="1" liveDragging="true" id="rotate" value="0" change="draw();"/>
<mx:HSlider x="328" y="264" width="130" minimum="128" maximum="256" snapInterval="1" liveDragging="true" id="w" value="128" change="draw();"/>
<mx:HSlider x="328" y="304" width="130" minimum="128" maximum="256" snapInterval="1" liveDragging="true" id="h" value="128" change="draw();"/>
<mx:HSlider x="328" y="344" width="130" minimum="-256" maximum="256" snapInterval="1" liveDragging="true" id="tx" value="0" change="draw();"/>
<mx:HSlider x="328" y="384" width="130" minimum="-256" maximum="256" snapInterval="1" liveDragging="true" id="ty" value="0" change="draw();"/>
<mx:Label x="328" y="370" text="ty"/>
<mx:Label x="328" y="330" text="tx"/>
<mx:Label x="328" y="290" text="height"/>
<mx:Label x="328" y="250" text="width"/>
<mx:Label x="327" y="169" text="ratios2"/>
<mx:Label x="328" y="210" text="rotation"/>
<mx:ComboBox x="183" y="60" width="132" id="fonts" change="setTxt();"></mx:ComboBox>
<mx:Label x="329" y="410" text="txt h pos"/>
<mx:HSlider id="h_pos" x="328" y="428" width="130" value="10" minimum="-30" maximum="30" change="setTxt();"/>
<mx:Button x="235" y="428" label="Save" click="save();" width="80"/>
<mx:CheckBox x="17" y="132" label="useFilter" id="u_f" selected="true" click="setFilter();"/>
<mx:Label x="94" y="134" text="shadow:"/>
<mx:Label x="174" y="134" text="light:"/>
<mx:ColorPicker x="206" y="132" selectedColor="#FFFFFF" change="setFilter();" id="f_light"/>
<mx:ColorPicker x="143" y="132" selectedColor="#000000" id="f_shadow" change="setFilter();"/>
</mx:Application>