Skip to content

Instantly share code, notes, and snippets.

@npretto
Last active December 29, 2015 03:29
Show Gist options
  • Select an option

  • Save npretto/7607710 to your computer and use it in GitHub Desktop.

Select an option

Save npretto/7607710 to your computer and use it in GitHub Desktop.
9path/slice9 class for flambe
package tools;
import flambe.display.ImageSprite;
import flambe.display.Texture;
import flambe.System;
/**
* ...
* @author lordkryss
*/
enum SliceKind {
Scale;
Pattern;
}
class Slice9 extends ImageSprite
{
public function new(slide9:Texture,width:Int,height:Int,?kind:SliceKind)
{
if (kind == null)
{
kind = SliceKind.Pattern;
}
var texture:Texture = System.createTexture(width, height);
var width3:Float = slide9.width / 3;
var height3:Float = slide9.height / 3;
var destWidth,destHeight:Int;
var destX,destY:Int;
var subText:Texture;
for (x in 0...3)
for (y in 0...3)
{
destWidth = Math.ceil((x == 1) ? width - 2 * width3 : width3);
destHeight = Math.ceil((y == 1) ? height - 2 * height3 : height3);
if (kind == Pattern)
{
subText = System.createTexture(Std.int(width3), Std.int(height3));
subText.graphics.drawSubImage(slide9, 0, 0, x * width3, y * height3, width3, height3);
}else
{
subText = System.createTexture(destWidth, destHeight);
subText.graphics.save();
subText.graphics.scale(destWidth/width3,destHeight/height3);
subText.graphics.drawSubImage(slide9, 0, 0, x * width3, y * height3, width3, height3);
subText.graphics.restore();
}
destX = Math.round((x == 2) ? (width - width3) : x * width3);
destY = Math.round((y == 2) ? (height - height3) : y * height3);
texture.graphics.drawPattern(subText, destX, destY, destWidth,destHeight);
}
super(texture);
}
}
@npretto
Copy link
Copy Markdown
Author

npretto commented Nov 22, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment