※現在、「wonderfl build flash online」求人コンテンツ制作に関してのアンケートを実施中です!みなさまのお力添えを頂いて、続々とアンケート結果が集まっていますが、まだまだ募集しております。ご協力のほど、どうぞよろしくお願いいたします!
wonderfl運営事務局
→アンケートページ(※ログインしてからお答えいただけるようになっています。)
[Sample] BoundaryResizer Demo forked from: [Sample] BoundaryResizer Demo
- // forked from alumican_net's [Sample] BoundaryResizer Demo
- /**
- * 目的が似たクラス(FViewBox)があったので便乗しますた。
- * 描画目的なので出力がMatrixです。なので80行目あたりが主なあれです。
- * ※このクラスはあまり最適化はされてないです。これだけじゃないけど…
- * alumican.netさんに感謝。
- */
- /**
- * フォーク元:
- * BoundaryResizerクラスを利用したリサイズ
- *
- * このswfは下記URLで紹介している自作クラスのサンプルコードです
- * @see http://blog.alumican.net/2009/10/07_225251
- *
- * @author alumican.net<Yukiya Okuda>
- */
- package
- {
- import flash.display.Bitmap;
- import flash.display.BitmapData;
- import flash.display.Graphics;
- import flash.display.Loader;
- import flash.display.LoaderInfo;
- import flash.display.PixelSnapping;
- import flash.display.Sprite;
- import flash.events.Event;
- import flash.geom.Matrix;
- import flash.geom.Rectangle;
- import flash.net.URLRequest;
- import com.bit101.components.Label;
- import com.bit101.components.RadioButton;
- import com.bit101.components.PushButton;
- import flash.system.Security;
- import frocessing.geom.FViewBox;
- [SWF(width = 465, height = 465, backgroundColor = 0xffffff, frameRate = 30)]
- public class BoundaryResizerDemo extends Sprite
- {
- //----------------------------------------
- //CLASS CONSTANTS
- private const W:uint = 465;
- private const H:uint = 465;
- //----------------------------------------
- //VARIABLES
- private var _picture:Bitmap;
- private var _border:Sprite;
- private var viewbox:FViewBox;
- //----------------------------------------
- //METHODS
- private function _resize():void
- {
- //USE VIEW BOX
- _picture.transform.matrix = viewbox.getTransformMatrix( _border.x, _border.y, _border.width, _border.height );
- }
- public function BoundaryResizerDemo():void
- {
- Security.loadPolicyFile("http://swf.wonderfl.net/crossdomain.xml");
- var vBmd:BitmapData, hBmd:BitmapData;
- _picture = addChild(new Bitmap()) as Bitmap;
- var loader:Loader = new Loader();
- loader.contentLoaderInfo.addEventListener(Event.COMPLETE, function(e:Event):void
- {
- var bmd:BitmapData = new BitmapData(W, H, true, 0x00000000);
- bmd.draw(loader);
- var rect:Rectangle = bmd.getColorBoundsRect(0xffffffff, 0x00000000, false);
- var vb:FViewBox = new FViewBox( rect.x, rect.y, rect.width, rect.height );
- vb.scaleMode = FViewBox.SHOW_ALL;
- vBmd = new BitmapData(rect.width - 40, rect.height + 40, true, 0xff80ff80);
- vBmd.draw(bmd, vb.getTransformMatrix(0,0,vBmd.width,vBmd.height), null, null, null, true);
- hBmd = new BitmapData(rect.width + 100, rect.height - 80, true, 0xff80ff80);
- hBmd.draw(bmd, vb.getTransformMatrix(0,0,hBmd.width,hBmd.height), null, null, null, true);
- _picture.bitmapData = vBmd;
- _picture.smoothing = true;
- viewbox = new FViewBox( 0, 0, vBmd.width, vBmd.height );
- e.target.removeEventListener(e.type, arguments.callee);
- loader = null;
- _resize();
- } );
- loader.load(new URLRequest("http://swf.wonderfl.net/static/assets/checkmate04/AmateurAssets.swf"));
- _border = addChild(new Sprite()) as Sprite;
- var g:Graphics = _border.graphics;
- g.lineStyle(2, 0xff0000);
- g.drawRect(0, 0, 290, 290);
- _border.x = int((W - _border.width) / 2);
- _border.y = 60;
- var title:Label = new Label(this, 0, -8, "FViewBox Demo");
- title.scaleX = title.scaleY = 2;
- new PushButton(this, W - 99 - 10, 19 * 0 + 10, "Vertical Image" , function():void { _picture.bitmapData = vBmd; _picture.smoothing = true; viewbox.width=vBmd.width; viewbox.height=vBmd.height; _resize(); } );
- new PushButton(this, W - 99 - 10, 19 * 1 + 10, "Horizontal Image", function():void { _picture.bitmapData = hBmd; _picture.smoothing = true; viewbox.width=hBmd.width; viewbox.height=hBmd.height; _resize(); } );
- var label0:Label = new Label(this, 10, H - 19 * 5 - 10, "scaleMode : NO_SCALE");
- new PushButton(this, 10, H - 19 * 4 - 10, "EXACT_FIT", function():void { viewbox.scaleMode = FViewBox.EXACT_FIT; _resize(); label0.text = "scaleMode : EXACT_FIT"; } );
- new PushButton(this, 10, H - 19 * 3 - 10, "SHOW_ALL" , function():void { viewbox.scaleMode = FViewBox.SHOW_ALL; _resize(); label0.text = "scaleMode : SHOW_ALL"; } );
- new PushButton(this, 10, H - 19 * 2 - 10, "NO_BORDER", function():void { viewbox.scaleMode = FViewBox.NO_BORDER; _resize(); label0.text = "scaleMode : NO_BORDER"; } );
- new PushButton(this, 10, H - 19 * 1 - 10, "NO_SCALE" , function():void { viewbox.scaleMode = FViewBox.NO_SCALE; _resize(); label0.text = "scaleMode : NO_SCALE"; } );
- var label1:Label = new Label(this, W - 99 * 3 - 10, H - 19 * 4 - 10, "align : CENTER");
- new PushButton(this, W - 99 * 3 - 10, H - 19 * 3 - 10, "TOP_LEFT" , function():void { viewbox.align = FViewBox.TOP_LEFT; _resize(); label1.text = "align : TOP_LEFT"; } );
- new PushButton(this, W - 99 * 2 - 10, H - 19 * 3 - 10, "TOP" , function():void { viewbox.align = FViewBox.TOP; _resize(); label1.text = "align : TOP"; } );
- new PushButton(this, W - 99 * 1 - 10, H - 19 * 3 - 10, "TOP_RIGHT" , function():void { viewbox.align = FViewBox.TOP_RIGHT; _resize(); label1.text = "align : TOP_RIGHT"; } );
- new PushButton(this, W - 99 * 3 - 10, H - 19 * 2 - 10, "LEFT" , function():void { viewbox.align = FViewBox.LEFT; _resize(); label1.text = "align : LEFT"; } );
- new PushButton(this, W - 99 * 2 - 10, H - 19 * 2 - 10, "CENTER" , function():void { viewbox.align = FViewBox.CENTER; _resize(); label1.text = "align : CENTER"; } );
- new PushButton(this, W - 99 * 1 - 10, H - 19 * 2 - 10, "RIGHT" , function():void { viewbox.align = FViewBox.RIGHT; _resize(); label1.text = "align : RIGHT"; } );
- new PushButton(this, W - 99 * 3 - 10, H - 19 * 1 - 10, "BOTTOM_LEFT" , function():void { viewbox.align = FViewBox.BOTTOM_LEFT; _resize(); label1.text = "align : BOTTOM_LEFT"; } );
- new PushButton(this, W - 99 * 2 - 10, H - 19 * 1 - 10, "BOTTOM" , function():void { viewbox.align = FViewBox.BOTTOM; _resize(); label1.text = "align : BOTTOM"; } );
- new PushButton(this, W - 99 * 1 - 10, H - 19 * 1 - 10, "BOTTOM_RIGHT", function():void { viewbox.align = FViewBox.BOTTOM_RIGHT; _resize(); label1.text = "align : BOTTOM_RIGHT"; } );
- }
- }
- }
[Sample] BoundaryResizer Demo forked from: [Sample] BoundaryResizer Demo
- // forked from alumican_net's [Sample] BoundaryResizer Demo
- /**
- * BoundaryResizerクラスを利用したリサイズ
- *
- * このswfは下記URLで紹介している自作クラスのサンプルコードです
- * @see http://blog.alumican.net/2009/10/07_225251
- *
- * @author alumican.net<Yukiya Okuda>
- */
- package
- {
- import flash.display.Bitmap;
- import flash.display.BitmapData;
- import flash.display.Graphics;
- import flash.display.Loader;
- import flash.display.LoaderInfo;
- import flash.display.PixelSnapping;
- import flash.display.Sprite;
- import flash.events.Event;
- import flash.geom.Matrix;
- import flash.geom.Rectangle;
- import flash.net.URLRequest;
- import com.bit101.components.Label;
- import com.bit101.components.RadioButton;
- import com.bit101.components.PushButton;
- import flash.system.Security;
- [SWF(width = 465, height = 465, backgroundColor = 0xffffff, frameRate = 30)]
- public class BoundaryResizerDemo extends Sprite
- {
- //----------------------------------------
- //CLASS CONSTANTS
- private const W:uint = 465;
- private const H:uint = 465;
- //----------------------------------------
- //VARIABLES
- private var _picture:Bitmap;
- private var _border:Sprite;
- private var _scaleMode:String = BoundaryResizer.NO_SCALE;
- private var _align:String = BoundaryResizer.CENTER;
- //----------------------------------------
- //METHODS
- private function _resize():void
- {
- var boundary:Rectangle = _border.getRect(this);
- var target:Rectangle = _picture.bitmapData.rect;
- //IMPORTANT HERE--------------------------
- var resized:Rectangle = BoundaryResizer.resize(target, boundary, _scaleMode, _align);
- //----------------------------------------
- _picture.x = resized.x;
- _picture.y = resized.y;
- _picture.width = resized.width;
- _picture.height = resized.height;
- }
- public function BoundaryResizerDemo():void
- {
- Security.loadPolicyFile("http://swf.wonderfl.net/crossdomain.xml");
- _picture = addChild(new Bitmap()) as Bitmap;
- var loader:Loader = new Loader();
- loader.contentLoaderInfo.addEventListener(Event.COMPLETE, function(e:Event):void
- {
- var bmd:BitmapData = new BitmapData(W, H, true, 0x00000000);
- bmd.draw(loader);
- var rect:Rectangle = bmd.getColorBoundsRect(0xffffffff, 0x00000000, false);
- var trim:BitmapData = new BitmapData(rect.width, rect.height + 20, true, 0xff80ff80);
- trim.draw(bmd, new Matrix(1, 0, 0, 1, -rect.x, -rect.y + 10));
- _picture.bitmapData = trim;
- _picture.smoothing = true;
- e.target.removeEventListener(e.type, arguments.callee);
- loader = null;
- _resize();
- } );
- loader.load(new URLRequest("http://swf.wonderfl.net/static/assets/checkmate04/AmateurAssets.swf"));
- _border = addChild(new Sprite()) as Sprite;
- var g:Graphics = _border.graphics;
- g.lineStyle(2, 0xff0000);
- g.drawRect(0, 0, 290, 290);
- _border.x = int((W - _border.width) / 2);
- _border.y = 50;
- var title:Label = new Label(this, 0, -8, "BoundaryResizer Demo");
- title.scaleX = title.scaleY = 2;
- var label0:Label = new Label(this, 10, H - 19 * 5 - 10, "scaleMode : NO_SCALE");
- new PushButton(this, 10, H - 19 * 4 - 10, "EXACT_FIT", function():void { _scaleMode = BoundaryResizer.EXACT_FIT; _resize(); label0.text = "scaleMode : EXACT_FIT"; } );
- new PushButton(this, 10, H - 19 * 3 - 10, "SHOW_ALL" , function():void { _scaleMode = BoundaryResizer.SHOW_ALL; _resize(); label0.text = "scaleMode : SHOW_ALL"; } );
- new PushButton(this, 10, H - 19 * 2 - 10, "NO_BORDER", function():void { _scaleMode = BoundaryResizer.NO_BORDER; _resize(); label0.text = "scaleMode : NO_BORDER"; } );
- new PushButton(this, 10, H - 19 * 1 - 10, "NO_SCALE" , function():void { _scaleMode = BoundaryResizer.NO_SCALE; _resize(); label0.text = "scaleMode : NO_SCALE"; } );
- var label1:Label = new Label(this, W - 99 * 3 - 10, H - 19 * 4 - 10, "align : CENTER");
- new PushButton(this, W - 99 * 3 - 10, H - 19 * 3 - 10, "TOP_LEFT" , function():void { _align = BoundaryResizer.TOP_LEFT; _resize(); label1.text = "align : TOP_LEFT"; } );
- new PushButton(this, W - 99 * 2 - 10, H - 19 * 3 - 10, "TOP" , function():void { _align = BoundaryResizer.TOP; _resize(); label1.text = "align : TOP"; } );
- new PushButton(this, W - 99 * 1 - 10, H - 19 * 3 - 10, "TOP_RIGHT" , function():void { _align = BoundaryResizer.TOP_RIGHT; _resize(); label1.text = "align : TOP_RIGHT"; } );
- new PushButton(this, W - 99 * 3 - 10, H - 19 * 2 - 10, "LEFT" , function():void { _align = BoundaryResizer.LEFT; _resize(); label1.text = "align : LEFT"; } );
- new PushButton(this, W - 99 * 2 - 10, H - 19 * 2 - 10, "CENTER" , function():void { _align = BoundaryResizer.CENTER; _resize(); label1.text = "align : CENTER"; } );
- new PushButton(this, W - 99 * 1 - 10, H - 19 * 2 - 10, "RIGHT" , function():void { _align = BoundaryResizer.RIGHT; _resize(); label1.text = "align : RIGHT"; } );
- new PushButton(this, W - 99 * 3 - 10, H - 19 * 1 - 10, "BOTTOM_LEFT" , function():void { _align = BoundaryResizer.BOTTOM_LEFT; _resize(); label1.text = "align : BOTTOM_LEFT"; } );
- new PushButton(this, W - 99 * 2 - 10, H - 19 * 1 - 10, "BOTTOM" , function():void { _align = BoundaryResizer.BOTTOM; _resize(); label1.text = "align : BOTTOM"; } );
- new PushButton(this, W - 99 * 1 - 10, H - 19 * 1 - 10, "BOTTOM_RIGHT", function():void { _align = BoundaryResizer.BOTTOM_RIGHT; _resize(); label1.text = "align : BOTTOM_RIGHT"; } );
- //\(^o^)/
- //RadioButton.as : Currently only one group can be created.
- /*
- var scaleModeGroup:Sprite = addChild(new Sprite()) as Sprite;
- scaleModeGroup.x = 10;
- scaleModeGroup.y = H - 16 * 5 - 10;
- new Label(scaleModeGroup, 0, 0, "scaleMode");
- new RadioButton(scaleModeGroup, 0, 16 * 1 + 5, "EXACT_FIT", false, function():void { _scaleMode = BoundaryResizer.EXACT_FIT; _resize(); } );
- new RadioButton(scaleModeGroup, 0, 16 * 2 + 5, "SHOW_ALL" , false, function():void { _scaleMode = BoundaryResizer.SHOW_ALL; _resize(); } );
- new RadioButton(scaleModeGroup, 0, 16 * 3 + 5, "NO_BORDER", false, function():void { _scaleMode = BoundaryResizer.NO_BORDER; _resize(); } );
- new RadioButton(scaleModeGroup, 0, 16 * 4 + 5, "NO_SCALE" , true , function():void { _scaleMode = BoundaryResizer.NO_SCALE; _resize(); } );
- var alignGroup:Sprite = addChild(new Sprite()) as Sprite;
- alignGroup.x = W - 80 * 3 - 10;
- alignGroup.y = H - 16 * 4 - 10;
- new Label(alignGroup, 0, 0, "align");
- new RadioButton(alignGroup, 80 * 0, 16 * 1 + 5, "TOP_LEFT" , false, function():void { _align = BoundaryResizer.TOP_LEFT; _resize(); } );
- new RadioButton(alignGroup, 80 * 1, 16 * 1 + 5, "TOP" , false, function():void { _align = BoundaryResizer.TOP; _resize(); } );
- new RadioButton(alignGroup, 80 * 2, 16 * 1 + 5, "TOP_RIGHT" , false, function():void { _align = BoundaryResizer.TOP_RIGHT; _resize(); } );
- new RadioButton(alignGroup, 80 * 0, 16 * 2 + 5, "LEFT" , false, function():void { _align = BoundaryResizer.LEFT; _resize(); } );
- new RadioButton(alignGroup, 80 * 1, 16 * 2 + 5, "CENTER" , true , function():void { _align = BoundaryResizer.CENTER; _resize(); } );
- new RadioButton(alignGroup, 80 * 2, 16 * 2 + 5, "RIGHT" , false, function():void { _align = BoundaryResizer.RIGHT; _resize(); } );
- new RadioButton(alignGroup, 80 * 0, 16 * 3 + 5, "BOTTOM_LEFT" , false, function():void { _align = BoundaryResizer.BOTTOM_LEFT; _resize(); } );
- new RadioButton(alignGroup, 80 * 1, 16 * 3 + 5, "BOTTOM" , false, function():void { _align = BoundaryResizer.BOTTOM; _resize(); } );
- new RadioButton(alignGroup, 80 * 2, 16 * 3 + 5, "BOTTOM_RIGHT", false, function():void { _align = BoundaryResizer.BOTTOM_RIGHT; _resize(); } );
- */
- }
- }
- }
- import flash.display.StageAlign;
- import flash.display.StageScaleMode;
- import flash.geom.Rectangle;
- /**
- * BoundaryResizer
- * 様々なリサイズをRectangleベースで実行するクラスです.
- * @see http://blog.alumican.net/2009/10/07_225251
- * @author alumican.net<Yukiya Okuda>
- */
- internal class BoundaryResizer
- {
- //-------------------------------------
- //CLASS CONSTANTS
- /**
- * scaleMode
- * リサイズ方法を操作するscaleModeには以下の定数を指定できます.
- */
- static public const EXACT_FIT:String = StageScaleMode.EXACT_FIT; // targetとboundaryが完全に一致するようにリサイズされます.多くの場合,targetの縦横比は保たれません.
- static public const SHOW_ALL:String = StageScaleMode.SHOW_ALL; // targetが縦横比を保ち,かつtargetがboundaryの内側にフィットするようにリサイズされます.targetがトリミングされることはありませんが,上下または左右に隙間ができることがあります.
- static public const NO_BORDER:String = StageScaleMode.NO_BORDER; // targetが縦横比を保ち,かつboundaryがtargetの内側にフィットするようにリサイズされます.targetとboundaryの間に隙間ができることはありませんが,targetがトリミングされることがあります.
- static public const NO_SCALE:String = StageScaleMode.NO_SCALE; // リサイズがおこなわれず,alignによる基準点合わせのみがおこなわれます.
- /**
- * align
- * リサイズ後のオブジェクトの基準点を操作するalignには以下の定数を指定できます.
- */
- static public const TOP_LEFT:String = StageAlign.TOP_LEFT; // x軸方向:左 , y軸方向:上
- static public const TOP:String = StageAlign.TOP; // x軸方向:中央, y軸方向:上
- static public const TOP_RIGHT:String = StageAlign.TOP_RIGHT; // x軸方向:右 , y軸方向:上
- static public const LEFT:String = StageAlign.LEFT; // x軸方向:左 , y軸方向:中央
- static public const CENTER:String = ""; // x軸方向:中央, y軸方向:中央
- static public const RIGHT:String = StageAlign.RIGHT; // x軸方向:右 , y軸方向:中央
- static public const BOTTOM_LEFT:String = StageAlign.BOTTOM_LEFT; // x軸方向:左 , y軸方向:下
- static public const BOTTOM:String = StageAlign.BOTTOM; // x軸方向:中央, y軸方向:下
- static public const BOTTOM_RIGHT:String = StageAlign.BOTTOM_RIGHT; // x軸方向:右 , y軸方向:下
- //-------------------------------------
- //METHODS
- /**
- * targetをboundaryに合わせてリサイズした矩形を返します.
- * リサイズ方法と基準点をscaleMode,alignで指定できます.
- * @param target リサイズ対象オブジェクトの矩形を指定します.(例)リサイズしたい画像の矩形
- * @param boundary リサイズの基準となる矩形を指定します.(例)リサイズ後の画像を収める枠
- * @param scaleMode リサイズ時のスケールモードを指定します.このパラメータはStageScaleModeと互換性があります.このパラメータを省略した場合はBoundaryResizer.NO_SCALEとなり,リサイズはおこなわれません.
- * @param align boundaryに対するtargetの基準位置を指定します.このパラメータはStageAlignと互換性があります.このパラメータを省略した場合はBoundaryResizer.CENTERとなり,縦横ともに中央揃えとなります.
- * @return リサイズ後の矩形が返されます.target及びboundaryは変更しません.
- */
- static public function resize(target:Rectangle, boundary:Rectangle, scaleMode:String = "noScale", align:String = ""):Rectangle
- {
- var tx:Number = target.x,
- ty:Number = target.y,
- tw:Number = target.width,
- th:Number = target.height,
- bx:Number = boundary.x,
- by:Number = boundary.y,
- bw:Number = boundary.width,
- bh:Number = boundary.height,
- rx:Number,
- ry:Number,
- rw:Number,
- rh:Number;
- switch (scaleMode)
- {
- case SHOW_ALL:
- case NO_BORDER:
- var ratioW:Number = bw / tw,
- ratioH:Number = bh / th,
- ratio:Number = (scaleMode == SHOW_ALL) ? ( (ratioW < ratioH) ? ratioW : ratioH ) :
- ( (ratioW > ratioH) ? ratioW : ratioH ) ;
- rw = ratio * tw;
- rh = ratio * th;
- break;
- case EXACT_FIT:
- return new Rectangle(bx, by, bw, bh);
- default:
- rw = tw;
- rh = th;
- break;
- }
- rx = bx + ( (align == TOP_LEFT || align == LEFT || align == BOTTOM_LEFT ) ? 0 :
- (align == TOP_RIGHT || align == RIGHT || align == BOTTOM_RIGHT) ? (bw - rw) :
- (bw - rw) / 2 ) ;
- ry = by + ( (align == TOP_LEFT || align == TOP || align == TOP_RIGHT ) ? 0 :
- (align == BOTTOM_LEFT || align == BOTTOM || align == BOTTOM_RIGHT) ? (bh - rh) :
- (bh - rh) / 2 ) ;
- return new Rectangle(rx, ry, rw, rh);
- }
- }
notice:



