Skip to content
This repository has been archived by the owner on Mar 20, 2021. It is now read-only.

Commit

Permalink
Scale3Image, Scale9Image, TiledImage: subclasses of starling.display.…
Browse files Browse the repository at this point in the history
…Image that mimic the old classes in a simple way
  • Loading branch information
joshtynjala committed Apr 22, 2016
1 parent 81b13fe commit 792b62e
Show file tree
Hide file tree
Showing 3 changed files with 167 additions and 0 deletions.
78 changes: 78 additions & 0 deletions source/feathers/display/Scale3Image.as
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);
}
}
}
}
}
66 changes: 66 additions & 0 deletions source/feathers/display/Scale9Image.as
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;
}
}
}
}
23 changes: 23 additions & 0 deletions source/feathers/display/TiledImage.as
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();
}
}
}

0 comments on commit 792b62e

Please sign in to comment.