package { import flash.display.Bitmap; import flash.display.BitmapData; import flash.display.Sprite; import flash.events.TimerEvent; import flash.geom.Rectangle; import flash.utils.Timer;
/** * 선택 영역 효과 레이어. * * @author http://www.as3.kr * @author Wooyaggo ( victim4@gmail.com ) * */ public class SelectionLayer extends Sprite { private var bitmap: Bitmap; private var bitmapData: BitmapData; private var timer: Timer; public function SelectionLayer() { this.bitmapData = new BitmapData( 10, 10, true, 0 ); this.bitmap = new Bitmap( this.bitmapData ); this.addChild( this.bitmap ); this.timer = new Timer( 50 ); this.timer.addEventListener( TimerEvent.TIMER, onTimer ); } private var padding: int = 0; private const GAP: int = 4; public function draw( selection: Rectangle ): void { // reset this.bitmapData.dispose(); this.bitmapData = new BitmapData( selection.width, selection.height, true, 0 ); this.bitmap.bitmapData = this.bitmapData; this.bitmap.x = selection.x; this.bitmap.y = selection.y; this.drawLine(); this.timer.start(); } private function onTimer( e: TimerEvent ): void { this.repeat(); } public function repeat(): void { this.padding++; this.padding %= 2 * GAP; this.drawLine(); } private var lineColor: Number = 0xFF000000; private var lineColor2: Number = 0xFFFFFFFF; private function drawLine(): void { this.bitmapData.fillRect( this.bitmapData.rect, 0 ); var rect: Rectangle; var loop: int; rect = new Rectangle( padding - ( 2 * GAP ), 0, GAP, 1 ); loop = 1 + this.bitmapData.width / ( GAP * 2 ); do { this.bitmapData.fillRect( rect, lineColor ); rect.x += GAP; this.bitmapData.fillRect( rect, lineColor2 ); rect.x += GAP; }while( loop-- ) rect = new Rectangle( 0, padding - ( 2 * GAP ), 1, GAP ); loop = 1 + this.bitmapData.height / ( GAP * 2 ); while( loop-- ) { this.bitmapData.fillRect( rect, lineColor ); rect.y += GAP; this.bitmapData.fillRect( rect, lineColor2 ); rect.y += GAP; } var margin: int; margin = padding - ( this.bitmapData.width % ( 2 * GAP ) ) + 1; rect = new Rectangle( margin - ( 2 * GAP ), this.bitmapData.height - 1, GAP, 1 ); loop = 1 + this.bitmapData.width / ( GAP * 2 ); do { this.bitmapData.fillRect( rect, lineColor ); rect.x += GAP; this.bitmapData.fillRect( rect, lineColor2 ); rect.x += GAP; }while( loop-- ) margin = padding - ( this.bitmapData.height % ( 2 * GAP ) ) + 1; rect = new Rectangle( this.bitmapData.width - 1, margin - ( 2 * GAP ), 1, GAP ); loop = 1 + this.bitmapData.height / ( GAP * 2 ); while( loop-- ) { this.bitmapData.fillRect( rect, lineColor ); rect.y += GAP; this.bitmapData.fillRect( rect, lineColor2 ); rect.y += GAP; } } } } | |