Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scale9tiled #930

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -1,11 +1,14 @@
package feathers.examples.displayObjects.screens
{
import feathers.controls.Button;
import feathers.controls.Check;
import feathers.controls.Header;
import feathers.controls.Screen;
import feathers.display.Scale3Image;
import feathers.textures.Scale3Textures;

import starling.events.Event;

import starling.events.Touch;
import starling.events.TouchEvent;
import starling.events.TouchPhase;
Expand All @@ -16,6 +19,15 @@ package feathers.examples.displayObjects.screens
[Embed(source="/../assets/images/scale3.png")]
private static const SCALE_3_TEXTURE:Class;

[Embed(source="/../assets/images/scale3-tile-pattern.png")]
private static const SCALE_3_TILED_TEXTURE:Class;

[Embed(source="/../assets/images/scale3-vertical.png")]
private static const SCALE_3_TEXTURE_VERTICAL:Class;

[Embed(source="/../assets/images/scale3-tile-pattern-vertical.png")]
private static const SCALE_3_TILED_TEXTURE_VERTICAL:Class;

public function Scale3ImageScreen()
{
}
Expand All @@ -24,6 +36,9 @@ package feathers.examples.displayObjects.screens
private var _image:Scale3Image;
private var _rightButton:Button;
private var _bottomButton:Button;
private var _gridCheckbox:Check;
private var _tiledCheckbox:Check;
private var _verticalCheckbox:Check;

private var _minDisplayObjectWidth:Number;
private var _minDisplayObjectHeight:Number;
Expand All @@ -36,19 +51,29 @@ package feathers.examples.displayObjects.screens
private var _rightTouchPointID:int = -1;
private var _bottomTouchPointID:int = -1;

private const texture:Texture = Texture.fromBitmap(new SCALE_3_TEXTURE(), false);
private const textures:Scale3Textures = new Scale3Textures(texture, 60, 80, Scale3Textures.DIRECTION_HORIZONTAL);

private const gridTexture:Texture = Texture.fromBitmap(new SCALE_3_TILED_TEXTURE(), false);
private const gridTextures:Scale3Textures = new Scale3Textures(gridTexture, 60, 120, Scale3Textures.DIRECTION_HORIZONTAL);

private const textureVertical:Texture = Texture.fromBitmap(new SCALE_3_TEXTURE_VERTICAL(), false);
private const texturesVertical:Scale3Textures = new Scale3Textures(textureVertical, 60, 80, Scale3Textures.DIRECTION_VERTICAL);

private const gridTextureVertical:Texture = Texture.fromBitmap(new SCALE_3_TILED_TEXTURE_VERTICAL(), false);
private const gridTexturesVertical:Scale3Textures = new Scale3Textures(gridTextureVertical, 60, 120, Scale3Textures.DIRECTION_VERTICAL);

override protected function initialize():void
{
this._header = new Header();
this._header.title = "Scale 3 Image";
this.addChild(this._header);

const texture:Texture = Texture.fromBitmap(new SCALE_3_TEXTURE(), false);
const textures:Scale3Textures = new Scale3Textures(texture, 60, 80, Scale3Textures.DIRECTION_HORIZONTAL);
this._image = new Scale3Image(textures, this.dpiScale);
this._image.width /= 2;
this._image.height /= 2;
this._minDisplayObjectWidth = this._image.width;
this._minDisplayObjectHeight = this._image.height;
this._minDisplayObjectWidth = 20 * this.dpiScale;
this._minDisplayObjectHeight = 20 * this.dpiScale;
this.addChild(this._image);

this._rightButton = new Button();
Expand All @@ -60,6 +85,21 @@ package feathers.examples.displayObjects.screens
this._bottomButton.nameList.add("bottom-grip");
this._bottomButton.addEventListener(TouchEvent.TOUCH, bottomButton_touchHandler);
this.addChild(this._bottomButton);

this._tiledCheckbox = new Check();
this._tiledCheckbox.label = "tiled";
this._tiledCheckbox.addEventListener(Event.CHANGE, onTiledChange);
this.addChild(this._tiledCheckbox);

this._gridCheckbox = new Check();
this._gridCheckbox.label = "show grid";
this._gridCheckbox.addEventListener(Event.CHANGE, onTextureChange);
this.addChild(this._gridCheckbox);

this._verticalCheckbox = new Check();
this._verticalCheckbox.label = "vertical";
this._verticalCheckbox.addEventListener(Event.CHANGE, onTextureChange);
this.addChild(this._verticalCheckbox);
}

override protected function draw():void
Expand All @@ -72,6 +112,18 @@ package feathers.examples.displayObjects.screens

this._rightButton.validate();
this._bottomButton.validate();
this._gridCheckbox.validate();
this._tiledCheckbox.validate();
this._verticalCheckbox.validate();

this._gridCheckbox.x = this.width - 30 * this.dpiScale - this._gridCheckbox.width;
this._gridCheckbox.y = this._header.height + 30 * this.dpiScale;

this._tiledCheckbox.x = this._gridCheckbox.x;
this._tiledCheckbox.y = this._header.height + this._gridCheckbox.height + 60 * this.dpiScale;

this._verticalCheckbox.x = this._gridCheckbox.x;
this._verticalCheckbox.y = this._header.height + this._gridCheckbox.height + this._tiledCheckbox.height + 90 * this.dpiScale;

this._maxDisplayObjectWidth = this.actualWidth - this._rightButton.width - this._image.x;
this._maxDisplayObjectHeight = this.actualHeight - this._bottomButton.height - this._image.y;
Expand Down Expand Up @@ -107,7 +159,7 @@ package feathers.examples.displayObjects.screens
}
else if(touch.phase == TouchPhase.MOVED)
{
this._image.width = Math.min(this._maxDisplayObjectWidth, Math.max(this._image.height, this._minDisplayObjectWidth, this._startWidth + touch.globalX - this._startX));
this._image.width = Math.min(this._maxDisplayObjectWidth, Math.max(this._minDisplayObjectWidth, this._startWidth + touch.globalX - this._startX));
this.layoutButtons()
}
else if(touch.phase == TouchPhase.ENDED)
Expand All @@ -132,13 +184,45 @@ package feathers.examples.displayObjects.screens
}
else if(touch.phase == TouchPhase.MOVED)
{
this._image.height = Math.min(this._image.width, this._maxDisplayObjectHeight, Math.max(this._minDisplayObjectHeight, this._startHeight + touch.globalY - this._startY));
this._image.height = Math.min(this._maxDisplayObjectHeight, Math.max(this._minDisplayObjectHeight, this._startHeight + touch.globalY - this._startY));
this.layoutButtons()
}
else if(touch.phase == TouchPhase.ENDED)
{
this._bottomTouchPointID = -1;
}
}

private function onTiledChange(event:Event):void
{
var check:Check = Check(event.currentTarget);
this._image.isTiled = check.isSelected;
}

private function onTextureChange(event:Event):void
{
if (_gridCheckbox.isSelected)
{
if (_verticalCheckbox.isSelected)
{
this._image.textures = gridTexturesVertical;
}
else
{
this._image.textures = gridTextures;
}
}
else
{
if (_verticalCheckbox.isSelected)
{
this._image.textures = texturesVertical;
}
else
{
this._image.textures = textures;
}
}
}
}
}
@@ -1,13 +1,16 @@
package feathers.examples.displayObjects.screens
{
import feathers.controls.Button;
import feathers.controls.Check;
import feathers.controls.Header;
import feathers.controls.Screen;
import feathers.display.Scale9Image;
import feathers.textures.Scale9Textures;

import flash.geom.Rectangle;

import starling.events.Event;

import starling.events.Touch;
import starling.events.TouchEvent;
import starling.events.TouchPhase;
Expand All @@ -18,6 +21,9 @@ package feathers.examples.displayObjects.screens
[Embed(source="/../assets/images/scale9.png")]
private static const SCALE_9_TEXTURE:Class;

[Embed(source="/../assets/images/scale9-tile-pattern.png")]
private static const SCALE_9_TILE_TEXTURE:Class;

public function Scale9ImageScreen()
{
}
Expand All @@ -26,6 +32,8 @@ package feathers.examples.displayObjects.screens
private var _image:Scale9Image;
private var _rightButton:Button;
private var _bottomButton:Button;
private var _gridCheckbox:Check;
private var _tiledCheckbox:Check;

private var _minDisplayObjectWidth:Number;
private var _minDisplayObjectHeight:Number;
Expand All @@ -38,17 +46,21 @@ package feathers.examples.displayObjects.screens
private var _rightTouchPointID:int = -1;
private var _bottomTouchPointID:int = -1;

private const texture:Texture = Texture.fromBitmap(new SCALE_9_TEXTURE(), false);
private const textures:Scale9Textures = new Scale9Textures(texture, new Rectangle(20, 20, 20, 20));

private const gridTexture:Texture = Texture.fromBitmap(new SCALE_9_TILE_TEXTURE(), false);
private const gridTextures:Scale9Textures = new Scale9Textures(gridTexture, new Rectangle(20, 20, 48, 48));

override protected function initialize():void
{
this._header = new Header();
this._header.title = "Scale 9 Image";
this.addChild(this._header);

const texture:Texture = Texture.fromBitmap(new SCALE_9_TEXTURE(), false);
const textures:Scale9Textures = new Scale9Textures(texture, new Rectangle(20, 20, 20, 20));
this._image = new Scale9Image(textures, this.dpiScale);
this._minDisplayObjectWidth = 40;
this._minDisplayObjectHeight = 40;
this._minDisplayObjectWidth = 20 * this.dpiScale;
this._minDisplayObjectHeight = 20 * this.dpiScale;
this.addChild(this._image);

this._rightButton = new Button();
Expand All @@ -60,6 +72,16 @@ package feathers.examples.displayObjects.screens
this._bottomButton.nameList.add("bottom-grip");
this._bottomButton.addEventListener(TouchEvent.TOUCH, bottomButton_touchHandler);
this.addChild(this._bottomButton);

this._tiledCheckbox = new Check();
this._tiledCheckbox.label = "tiled";
this._tiledCheckbox.addEventListener(Event.CHANGE, onTiledChange);
this.addChild(this._tiledCheckbox);

this._gridCheckbox = new Check();
this._gridCheckbox.label = "show grid";
this._gridCheckbox.addEventListener(Event.CHANGE, onShowGridChange);
this.addChild(this._gridCheckbox);
}

override protected function draw():void
Expand All @@ -72,6 +94,14 @@ package feathers.examples.displayObjects.screens

this._rightButton.validate();
this._bottomButton.validate();
this._gridCheckbox.validate();
this._tiledCheckbox.validate();

this._gridCheckbox.x = this.width - 30 * this.dpiScale - this._gridCheckbox.width;
this._gridCheckbox.y = this._header.height + 30 * this.dpiScale;

this._tiledCheckbox.x = this._gridCheckbox.x;
this._tiledCheckbox.y = this._header.height + this._gridCheckbox.height + 60 * this.dpiScale;

this._maxDisplayObjectWidth = this.actualWidth - this._rightButton.width - this._image.x;
this._maxDisplayObjectHeight = this.actualHeight - this._bottomButton.height - this._image.y;;
Expand Down Expand Up @@ -140,5 +170,17 @@ package feathers.examples.displayObjects.screens
this._bottomTouchPointID = -1;
}
}

private function onTiledChange(event:Event):void
{
var check:Check = Check(event.currentTarget);
this._image.isTiled = check.isSelected;
}

private function onShowGridChange(event:Event):void
{
var check:Check = Check(event.currentTarget);
this._image.textures = check.isSelected ? gridTextures : textures;
}
}
}