// forked from hacker_56_zqlyy's flash on 2009-7-20 package { import flash.display.Sprite; public class FlashTest extends Sprite { public function FlashTest() { // write as3 code here.. var test:String; } } } import flash.display.*; import flash.geom.* import flash.text.*; //Java風グラフィックスラッパー class JGraphics { //変数 private var bd:BitmapData; //BMPデータ private var color:uint; //色 private var label:TextField; //ラベル private var format:TextFormat; //フォーマット private var mtx:Matrix; private var line:Shape; private var rc:Rectangle; //コンストラクタ public function JGraphics( w:uint, h:uint ) { //BMPデータ bd = new BitmapData(w, h, false, 0xffffff); //色 color = 0x000000; //ラベル label = new TextField(); label.autoSize = TextFieldAutoSize.LEFT; //フォーマット format = new TextFormat(); format.font = "_等幅"; format.color = 0x000000; setFontSize(12); mtx = new Matrix(); line = new Shape(); rc = new Rectangle(0, 0, 0, 0); } //フォントサイズの指定(ピクセル単位) public function setFontSize( size:int ) : void { var i : uint; label.text = "■"; for (i = size+10; i>=1; i--) { format.size = i; label.setTextFormat(format); if (label.textWidth <= size) break; } } //文字列幅の取得 public function stringWidth( text:String ) : int { label.text = text; label.setTextFormat(format); return label.textWidth; } //文字列高さの取得 public function stringHeight( text:String ) : int { label.text = text; label.setTextFormat(format); return label.textHeight; } //BMPデータの取得 public function getBitmapData():BitmapData { return bd; } //色の取得 public function getColorOfRGB( r:uint, g:uint, b:uint ) : uint { return (r<<16)+(g<<8)+b; } //色の指定 public function setColor( color : uint ) : void { this.color = color; format.color = color; } //ラインの描画 public function drawLine( x0:int, y0:int, x1:int, y1:int ) : void { line.graphics.lineStyle( 0, color ); line.graphics.moveTo( x0, y0 ); line.graphics.lineTo( x1, y1 ); bd.draw( line ); } //矩形の描画 public function drawRect( x:int, y:int, w:int, h:int ) : void { line.graphics.lineStyle( 0, color ); line.graphics.moveTo( x, y ); line.graphics.lineTo( x+w, y ); line.graphics.lineTo( x+w, y+h ); line.graphics.lineTo( x, y+h ); line.graphics.lineTo( x, y ); bd.draw( line ); } //塗り潰し矩形の描画 public function fillRect( x:int, y:int, w:uint, h:uint ) : void { rc.x = x; rc.y = y; rc.width = w; rc.height = h; bd.fillRect( rc, color ); } //文字列の描画 public function drawString( text:String, x:int, y:int) : void { if (text == null) return; label.text = text; label.setTextFormat(format); mtx.tx = x-(label.width -label.textWidth)/2; mtx.ty = y-(label.height-label.textHeight)/2-label.textHeight; bd.draw( label, mtx ); } //イメージの描画 public function drawImage( source:IBitmapDrawable, x:int, y:int ) : void { if (source == null) return; mtx.tx = x; mtx.ty = y; bd.draw( source, mtx ); } //イメージの描画(幅指定) public function drawImageUV(source:BitmapData, x:int, y:int, tu:int, tv:int, tw:int, th:int): void { if (source == null) return; var src: BitmapData = source; var rc:Rectangle = new Rectangle(tu, tv, tw, th); var pt:Point = new Point(x, y); bd.copyPixels(src, rc, pt); } // フェードアウト public function fadeout(alpha:Number):void { var rect:Rectangle = new Rectangle(0, 0, bd.width, bd.height); var ctrfm:ColorTransform = new ColorTransform(); ctrfm.alphaMultiplier = alpha; bd.colorTransform(rect, ctrfm); } } forked from: flash on 2009-7-20