-
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4fe474c
commit 561a3b1
Showing
93 changed files
with
1,849 additions
and
1,755 deletions.
There are no files selected for viewing
Empty file.
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 |
---|---|---|
@@ -1,14 +1,14 @@ | ||
package haxe.ui.backend; | ||
|
||
import flixel.FlxGame; | ||
import haxe.ui.backend.flixel.FlxHaxeUIState; | ||
import haxe.ui.backend.flixel.FlxHaxeUIAppState; | ||
import openfl.Lib; | ||
|
||
class AppImpl extends AppBase { | ||
public function new() { | ||
} | ||
|
||
private override function build() { | ||
Lib.current.stage.addChild(new FlxGame(0, 0, FlxHaxeUIState, 1, 60, 60, true)); | ||
Lib.current.stage.addChild(new FlxGame(0, 0, FlxHaxeUIAppState, 1, 60, 60, true)); | ||
} | ||
} |
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 |
---|---|---|
@@ -1,109 +1,92 @@ | ||
package haxe.ui.backend; | ||
|
||
import flash.display.Bitmap; | ||
import flash.display.Loader; | ||
import flash.events.Event; | ||
import flash.utils.ByteArray; | ||
import flixel.graphics.FlxGraphic; | ||
import flixel.graphics.frames.FlxFrame; | ||
import flixel.graphics.frames.FlxFramesCollection; | ||
import flixel.graphics.frames.FlxImageFrame; | ||
import haxe.io.Bytes; | ||
import haxe.ui.assets.FontInfo; | ||
import haxe.ui.assets.ImageInfo; | ||
import haxe.ui.util.ByteConverter; | ||
import openfl.Assets; | ||
import openfl.display.Bitmap; | ||
import openfl.display.Loader; | ||
import openfl.events.Event; | ||
import openfl.utils.AssetType; | ||
import openfl.utils.ByteArray; | ||
|
||
class AssetsImpl extends AssetsBase { | ||
|
||
var frames(get, never):FlxFramesCollection; | ||
|
||
function get_frames():FlxFramesCollection { | ||
if (Toolkit.assets.options != null && Toolkit.assets.options.spritesheet != null) return Toolkit.assets.options.spritesheet; | ||
return null; | ||
} | ||
|
||
override function getImageInternal(resourceId:String, callback:ImageInfo->Void):Void { | ||
|
||
private override function getImageInternal(resourceId:String, callback:ImageInfo->Void):Void { | ||
var graphic:FlxGraphic = null; | ||
var frame:FlxFrame = null; | ||
|
||
if (Assets.exists(resourceId)) { | ||
graphic = FlxGraphic.fromAssetKey(resourceId); | ||
} | ||
|
||
if (graphic == null) { | ||
var fr = frames; | ||
if (fr != null && fr.framesHash.exists(resourceId)) frame = fr.getByName(resourceId); | ||
} | ||
|
||
else { | ||
frame = FlxImageFrame.fromGraphic(graphic).frame; | ||
} | ||
|
||
if (frame != null) { | ||
|
||
if (Assets.exists(resourceId)) { | ||
graphic = FlxGraphic.fromAssetKey(resourceId); | ||
frame = FlxImageFrame.fromGraphic(graphic).frame; | ||
} | ||
|
||
if (frame != null) { | ||
frame.parent.persist = true; | ||
frame.parent.destroyOnNoUse = false; | ||
callback( { data : frame, width : Std.int(frame.sourceSize.x), height : Std.int(frame.sourceSize.y) } ); | ||
} | ||
|
||
else callback(null); | ||
} | ||
|
||
override function getImageFromHaxeResource(resourceId:String, callback:String->ImageInfo->Void):Void { | ||
var bytes = Resource.getBytes(resourceId); | ||
imageFromBytes(bytes, callback.bind(resourceId)); | ||
} | ||
|
||
public override function imageFromBytes(bytes:Bytes, callback:ImageInfo->Void):Void { | ||
|
||
callback({ | ||
data : frame, | ||
width : Std.int(frame.sourceSize.x), | ||
height : Std.int(frame.sourceSize.y) | ||
}); | ||
} else { | ||
callback(null); | ||
} | ||
} | ||
|
||
private override function getImageFromHaxeResource(resourceId:String, callback:String->ImageInfo->Void):Void { | ||
if (Resource.listNames().indexOf(resourceId) == -1) { | ||
callback(resourceId, null); | ||
} else { | ||
var bytes = Resource.getBytes(resourceId); | ||
imageFromBytes(bytes, callback.bind(resourceId)); | ||
} | ||
} | ||
|
||
public override function imageFromBytes(bytes:Bytes, callback:ImageInfo->Void):Void { | ||
var ba:ByteArray = ByteConverter.fromHaxeBytes(bytes); | ||
|
||
var loader:Loader = new Loader(); | ||
|
||
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, function(e) { | ||
|
||
if (loader.content != null) { | ||
var frame = FlxImageFrame.fromImage(cast(loader.content, Bitmap).bitmapData).frame; | ||
frame.parent.persist = true; // these two booleans will screw up the UI unless changed from the default values | ||
frame.parent.destroyOnNoUse = false; | ||
callback( { data : frame, width : Std.int(frame.sourceSize.x), height : Std.int(frame.sourceSize.y) } ); | ||
} | ||
}); | ||
|
||
loader.loadBytes(ba); | ||
} | ||
|
||
override function getFontInternal(resourceId:String, callback:FontInfo->Void):Void { | ||
|
||
var loader:Loader = new Loader(); | ||
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, function(e) { | ||
if (loader.content != null) { | ||
var frame = FlxImageFrame.fromImage(cast(loader.content, Bitmap).bitmapData).frame; | ||
frame.parent.persist = true; // these two booleans will screw up the UI unless changed from the default values | ||
frame.parent.destroyOnNoUse = false; | ||
callback({ | ||
data : frame, | ||
width : Std.int(frame.sourceSize.x), | ||
height : Std.int(frame.sourceSize.y) | ||
}); | ||
} else { | ||
callback(null); | ||
} | ||
}); | ||
|
||
loader.loadBytes(ba); | ||
} | ||
|
||
private override function getFontInternal(resourceId:String, callback:FontInfo->Void):Void { | ||
var fontName:String = null; | ||
|
||
if (isEmbeddedFont(resourceId) && Assets.exists(resourceId, AssetType.FONT)) { | ||
fontName = Assets.getFont(resourceId).fontName; | ||
} | ||
|
||
else { | ||
} else { | ||
fontName = resourceId; | ||
} | ||
|
||
callback( { data : fontName } ); | ||
} | ||
|
||
override function getFontFromHaxeResource(resourceId:String, callback:String->FontInfo->Void):Void { | ||
callback(resourceId, null); | ||
callback({ | ||
data : fontName | ||
}); | ||
} | ||
|
||
override function getTextDelegate(resourceId:String):String { | ||
|
||
|
||
private override function getTextDelegate(resourceId:String):String { | ||
if (Assets.exists(resourceId)) { | ||
return Assets.getText(resourceId); | ||
} | ||
|
||
return null; | ||
} | ||
static inline function isEmbeddedFont(fontName:String):Bool { | ||
private static inline function isEmbeddedFont(fontName:String):Bool { | ||
return fontName != "_sans" && fontName != "_serif" && fontName != "_typewriter"; | ||
} | ||
} | ||
} |
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
Oops, something went wrong.