175 lines
7.2 KiB
ActionScript
175 lines
7.2 KiB
ActionScript
package com.common
|
|
{
|
|
import flash.display.Bitmap;
|
|
import flash.display.BitmapData;
|
|
import flash.display.DisplayObject;
|
|
import flash.display.Sprite;
|
|
import flash.geom.Point;
|
|
import flash.geom.Rectangle;
|
|
|
|
public class Scale9Grid extends Sprite
|
|
{
|
|
|
|
private var _bgMc:Sprite;
|
|
|
|
private var _mcRect:Rectangle;
|
|
|
|
private var _bgBitmap:Bitmap;
|
|
|
|
private var _graphics:BitmapData;
|
|
|
|
private var _slicingGrapincs:Array;
|
|
|
|
private var _width:Number;
|
|
|
|
private var _height:Number;
|
|
|
|
private var _cornerWidth:Number;
|
|
|
|
private var _cornerHeight:Number;
|
|
|
|
private const UP_LEFT:uint = 0;
|
|
|
|
private const UP:uint = 1;
|
|
|
|
private const UP_RIGHT:uint = 2;
|
|
|
|
private const LEFT:uint = 3;
|
|
|
|
private const CENTER:uint = 4;
|
|
|
|
private const RIGHT:uint = 5;
|
|
|
|
private const DOWN_LEFT:uint = 6;
|
|
|
|
private const DOWN:uint = 7;
|
|
|
|
private const DOWN_RIGHT:uint = 8;
|
|
|
|
public function Scale9Grid(param1:Sprite, param2:Number, param3:Number)
|
|
{
|
|
super();
|
|
this._bgMc = param1;
|
|
this._mcRect = param1.scale9Grid;
|
|
this._bgBitmap = this.drawBitmap(param1);
|
|
this._graphics = this._bgBitmap.bitmapData;
|
|
this._height = param3;
|
|
this._width = param2;
|
|
this._cornerWidth = this._mcRect.x;
|
|
this._cornerHeight = this._mcRect.y;
|
|
this._slicingGrapincs = new Array();
|
|
this.splicegraphic();
|
|
this.setSize(this._width,this._height);
|
|
}
|
|
|
|
private function splicegraphic() : void
|
|
{
|
|
var _loc1_:BitmapData = null;
|
|
var _loc2_:Rectangle = null;
|
|
var _loc4_:Number = NaN;
|
|
var _loc5_:Number = NaN;
|
|
var _loc3_:Point = new Point();
|
|
_loc2_ = new Rectangle(0,0,this._cornerWidth,this._cornerHeight);
|
|
_loc1_ = new BitmapData(this._cornerWidth,this._cornerHeight);
|
|
_loc1_.copyPixels(this._graphics,_loc2_,_loc3_);
|
|
this._slicingGrapincs.push(new Bitmap(_loc1_));
|
|
_loc2_ = new Rectangle(this._cornerWidth,0,this._mcRect.width,this._cornerHeight);
|
|
_loc1_ = new BitmapData(this._mcRect.width,this._cornerHeight);
|
|
_loc1_.copyPixels(this._graphics,_loc2_,_loc3_);
|
|
this._slicingGrapincs.push(new Bitmap(_loc1_));
|
|
_loc2_ = new Rectangle(this._cornerWidth + this._mcRect.width,0,this._bgMc.width - this._cornerWidth - this._mcRect.width,this._cornerHeight);
|
|
_loc1_ = new BitmapData(this._bgMc.width - this._cornerWidth - this._mcRect.width,this._cornerHeight);
|
|
_loc1_.copyPixels(this._graphics,_loc2_,_loc3_);
|
|
this._slicingGrapincs.push(new Bitmap(_loc1_));
|
|
_loc2_ = new Rectangle(0,this._cornerHeight,this._cornerWidth,this._mcRect.height);
|
|
_loc1_ = new BitmapData(this._cornerWidth,this._mcRect.height);
|
|
_loc1_.copyPixels(this._graphics,_loc2_,_loc3_);
|
|
this._slicingGrapincs.push(new Bitmap(_loc1_));
|
|
_loc2_ = new Rectangle(this._cornerWidth,this._cornerHeight,this._mcRect.width,this._mcRect.height);
|
|
_loc1_ = new BitmapData(this._mcRect.width,this._mcRect.height);
|
|
_loc1_.copyPixels(this._graphics,_loc2_,_loc3_);
|
|
this._slicingGrapincs.push(new Bitmap(_loc1_));
|
|
_loc2_ = new Rectangle(this._cornerWidth + this._mcRect.width,this._cornerHeight,this._bgMc.width - this._cornerWidth - this._mcRect.width,this._mcRect.height);
|
|
_loc1_ = new BitmapData(this._bgMc.width - this._cornerWidth - this._mcRect.width,this._mcRect.height);
|
|
_loc1_.copyPixels(this._graphics,_loc2_,_loc3_);
|
|
this._slicingGrapincs.push(new Bitmap(_loc1_));
|
|
_loc2_ = new Rectangle(0,this._cornerHeight + this._mcRect.height,this._cornerWidth,this._bgMc.height - this._cornerHeight - this._mcRect.height);
|
|
_loc1_ = new BitmapData(this._cornerWidth,this._bgMc.height - this._cornerHeight - this._mcRect.height);
|
|
_loc1_.copyPixels(this._graphics,_loc2_,_loc3_);
|
|
this._slicingGrapincs.push(new Bitmap(_loc1_));
|
|
_loc2_ = new Rectangle(this._cornerWidth,this._cornerHeight + this._mcRect.height,this._mcRect.width,this._bgMc.height - this._cornerHeight - this._mcRect.height);
|
|
_loc1_ = new BitmapData(this._mcRect.width,this._bgMc.height - this._cornerHeight - this._mcRect.height);
|
|
_loc1_.copyPixels(this._graphics,_loc2_,_loc3_);
|
|
this._slicingGrapincs.push(new Bitmap(_loc1_));
|
|
_loc2_ = new Rectangle(this._cornerWidth + this._mcRect.width,this._cornerHeight + this._mcRect.height,this._bgMc.width - this._cornerWidth - this._mcRect.width,this._bgMc.height - this._cornerHeight - this._mcRect.height);
|
|
_loc1_ = new BitmapData(this._bgMc.width - this._cornerWidth - this._mcRect.width,this._bgMc.height - this._cornerHeight - this._mcRect.height);
|
|
_loc1_.copyPixels(this._graphics,_loc2_,_loc3_);
|
|
this._slicingGrapincs.push(new Bitmap(_loc1_));
|
|
var _loc6_:int = 0;
|
|
while(_loc6_ < this._slicingGrapincs.length)
|
|
{
|
|
addChild(this._slicingGrapincs[_loc6_]);
|
|
_loc6_++;
|
|
}
|
|
}
|
|
|
|
public function setSize(param1:Number, param2:Number) : void
|
|
{
|
|
var _loc3_:Bitmap = null;
|
|
_loc3_ = this.getSlice(this.UP_LEFT);
|
|
_loc3_.x = 0;
|
|
_loc3_.y = 0;
|
|
_loc3_ = this.getSlice(this.UP);
|
|
_loc3_.x = this._cornerWidth;
|
|
_loc3_.y = 0;
|
|
_loc3_.width = param1;
|
|
_loc3_ = this.getSlice(this.UP_RIGHT);
|
|
_loc3_.x = this._cornerWidth + param1;
|
|
_loc3_.y = 0;
|
|
_loc3_ = this.getSlice(this.LEFT);
|
|
_loc3_.x = 0;
|
|
_loc3_.y = this._cornerHeight;
|
|
_loc3_.height = param2;
|
|
_loc3_ = this.getSlice(this.CENTER);
|
|
_loc3_.x = this._cornerWidth;
|
|
_loc3_.y = this._cornerHeight;
|
|
_loc3_.width = param1;
|
|
_loc3_.height = param2;
|
|
_loc3_ = this.getSlice(this.RIGHT);
|
|
_loc3_.x = this._cornerWidth + param1;
|
|
_loc3_.y = this._cornerHeight;
|
|
_loc3_.height = param2;
|
|
_loc3_ = this.getSlice(this.DOWN_LEFT);
|
|
_loc3_.x = 0;
|
|
_loc3_.y = param2 + this._cornerHeight;
|
|
_loc3_ = this.getSlice(this.DOWN);
|
|
_loc3_.x = this._cornerWidth;
|
|
_loc3_.y = param2 + this._cornerHeight;
|
|
_loc3_.width = param1;
|
|
_loc3_ = this.getSlice(this.DOWN_RIGHT);
|
|
_loc3_.x = param1 + this._cornerWidth;
|
|
_loc3_.y = param2 + this._cornerHeight;
|
|
}
|
|
|
|
private function getSlice(param1:uint) : Bitmap
|
|
{
|
|
return this._slicingGrapincs[param1];
|
|
}
|
|
|
|
private function drawScale9Grid() : void
|
|
{
|
|
addChild(this._bgMc);
|
|
this._bgMc.width = this._width;
|
|
this._bgMc.height = this._height;
|
|
}
|
|
|
|
private function drawBitmap(param1:DisplayObject) : Bitmap
|
|
{
|
|
var _loc2_:BitmapData = new BitmapData(param1.width,param1.height,true,16777215);
|
|
_loc2_.draw(param1);
|
|
return new Bitmap(_loc2_);
|
|
}
|
|
}
|
|
}
|
|
|