This repository has been archived by the owner on Mar 20, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Scale3Image, Scale9Image, TiledImage: subclasses of starling.display.…
…Image that mimic the old classes in a simple way
- Loading branch information
1 parent
81b13fe
commit 792b62e
Showing
3 changed files
with
167 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* | ||
feathers-compat | ||
Copyright 2012-2016 Bowler Hat LLC. All Rights Reserved. | ||
This program is free software. You can redistribute and/or modify it in | ||
accordance with the terms of the accompanying license agreement. | ||
*/ | ||
package feathers.display | ||
{ | ||
import feathers.layout.Direction; | ||
import feathers.textures.Scale3Textures; | ||
|
||
import flash.geom.Rectangle; | ||
|
||
import starling.display.Image; | ||
|
||
/** | ||
* Scales an image like a "pill" shape with three regions, either | ||
* horizontally or vertically. The edge regions scale while maintaining | ||
* aspect ratio, and the middle region stretches to fill the remaining | ||
* space. | ||
*/ | ||
public class Scale3Image extends Image | ||
{ | ||
/** | ||
* Constructor. | ||
*/ | ||
public function Scale3Image(textures:Scale3Textures) | ||
{ | ||
super(textures.texture); | ||
this.textures = textures; | ||
} | ||
|
||
/** | ||
* @private | ||
*/ | ||
private var _textures:Scale3Textures; | ||
|
||
/** | ||
* The textures displayed by this image. | ||
* | ||
* <p>In the following example, the textures are changed:</p> | ||
* | ||
* <listing version="3.0"> | ||
* image.textures = new Scale3Textures( texture, firstRegionWidth, secondRegionWidth, Scale3Textures.DIRECTION_HORIZONTAL );</listing> | ||
*/ | ||
public function get textures():Scale3Textures | ||
{ | ||
return this._textures; | ||
} | ||
|
||
/** | ||
* @private | ||
*/ | ||
public function set textures(value:Scale3Textures):void | ||
{ | ||
if(this._textures === value) | ||
{ | ||
return; | ||
} | ||
this._textures = value; | ||
if(this._textures !== null) | ||
{ | ||
this.texture = this._textures.texture; | ||
if(this._textures.direction === Direction.VERTICAL) | ||
{ | ||
this.scale9Grid = new Rectangle(0, this._textures.firstRegionSize, | ||
this._textures.texture.frameWidth, this._textures.secondRegionSize); | ||
} | ||
else // horizontal | ||
{ | ||
this.scale9Grid = new Rectangle(this._textures.firstRegionSize, 0, | ||
this._textures.secondRegionSize, this._textures.texture.frameHeight); | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
feathers-compat | ||
Copyright 2012-2016 Bowler Hat LLC. All Rights Reserved. | ||
This program is free software. You can redistribute and/or modify it in | ||
accordance with the terms of the accompanying license agreement. | ||
*/ | ||
package feathers.display | ||
{ | ||
import feathers.textures.Scale9Textures; | ||
|
||
import starling.display.Image; | ||
|
||
/** | ||
* Scales an image with nine regions to maintain the aspect ratio of the | ||
* corners regions. The top and bottom regions stretch horizontally, and the | ||
* left and right regions scale vertically. The center region stretches in | ||
* both directions to fill the remaining space. | ||
*/ | ||
public class Scale9Image extends Image | ||
{ | ||
/** | ||
* Constructor. | ||
*/ | ||
public function Scale9Image(textures:Scale9Textures) | ||
{ | ||
super(textures.texture); | ||
this.textures = textures; | ||
} | ||
|
||
/** | ||
* @private | ||
*/ | ||
private var _textures:Scale9Textures; | ||
|
||
/** | ||
* The textures displayed by this image. | ||
* | ||
* <p>In the following example, the textures are changed:</p> | ||
* | ||
* <listing version="3.0"> | ||
* image.textures = new Scale9Textures( texture, scale9Grid );</listing> | ||
*/ | ||
public function get textures():Scale9Textures | ||
{ | ||
return this._textures; | ||
} | ||
|
||
/** | ||
* @private | ||
*/ | ||
public function set textures(value:Scale9Textures):void | ||
{ | ||
if(this._textures === value) | ||
{ | ||
return; | ||
} | ||
this._textures = value; | ||
if(this._textures !== null) | ||
{ | ||
this.texture = this._textures.texture; | ||
this.scale9Grid = this._textures.scale9Grid; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
feathers-compat | ||
Copyright 2012-2016 Bowler Hat LLC. All Rights Reserved. | ||
This program is free software. You can redistribute and/or modify it in | ||
accordance with the terms of the accompanying license agreement. | ||
*/ | ||
package feathers.display | ||
{ | ||
import flash.geom.Rectangle; | ||
|
||
import starling.display.Image; | ||
import starling.textures.Texture; | ||
|
||
public class TiledImage extends Image | ||
{ | ||
public function TiledImage(texture:Texture) | ||
{ | ||
super(texture); | ||
this.tileGrid = new Rectangle(); | ||
} | ||
} | ||
} |