UNPKG

starling-framework

Version:

A fast, productive library for 2D cross-platform development.

175 lines (159 loc) 5.76 kB
// Class: starling.textures.SubTexture var $global = typeof window != "undefined" ? window : typeof global != "undefined" ? global : typeof self != "undefined" ? self : this $global.Object.defineProperty(exports, "__esModule", {value: true}); var __map_reserved = {}; // Imports var $hxClasses = require("./../../hxClasses_stub").default; var $hxEnums = require("./../../hxEnums_stub").default; var $import = require("./../../import_stub").default; var $extend = require("./../../extend_stub").default; function starling_textures_Texture() {return require("./../../starling/textures/Texture");} function openfl_geom_Rectangle() {return $import(require("openfl/geom/Rectangle"));} function openfl_system_Capabilities() {return $import(require("openfl/system/Capabilities"));} function haxe_Log() {return require("./../../haxe/Log");} function openfl_geom_Matrix() {return $import(require("openfl/geom/Matrix"));} // Constructor var SubTexture = function(parent,region,ownsParent,frame,rotated,scaleModifier) { if(scaleModifier == null) { scaleModifier = 1; } if(rotated == null) { rotated = false; } if(ownsParent == null) { ownsParent = false; } (starling_textures_Texture().default).call(this); this.setTo(parent,region,ownsParent,frame,rotated,scaleModifier); } // Meta SubTexture.__name__ = "starling.textures.SubTexture"; SubTexture.__isInterface__ = false; SubTexture.__super__ = (starling_textures_Texture().default); SubTexture.prototype = $extend((starling_textures_Texture().default).prototype, { setTo: function(parent,region,ownsParent,frame,rotated,scaleModifier) { if(scaleModifier == null) { scaleModifier = 1; } if(rotated == null) { rotated = false; } if(ownsParent == null) { ownsParent = false; } if(this._region == null) { this._region = new (openfl_geom_Rectangle().default)(); } if(region != null) { this._region.copyFrom(region); } else { this._region.setTo(0,0,parent.get_width(),parent.get_height()); } if(frame != null) { if(this._frame != null) { this._frame.copyFrom(frame); } else { this._frame = frame.clone(); } } else { this._frame = null; } this._parent = parent; this._ownsParent = ownsParent; this._rotated = rotated; this._width = (rotated ? this._region.height : this._region.width) / scaleModifier; this._height = (rotated ? this._region.width : this._region.height) / scaleModifier; this._scale = this._parent.get_scale() * scaleModifier; if((openfl_system_Capabilities().default).isDebugger && this._frame != null && (this._frame.x > 0 || this._frame.y > 0 || this._frame.get_right() + 0.000001 < this._width || this._frame.get_bottom() + 0.000001 < this._height)) { (haxe_Log().default).trace("[Starling] Warning: frames inside the texture's region are unsupported.",{ fileName : "../src/starling/textures/SubTexture.hx", lineNumber : 106, className : "starling.textures.SubTexture", methodName : "setTo"}); } this.updateMatrices(); }, updateMatrices: function() { if(this._transformationMatrix != null) { this._transformationMatrix.identity(); } else { this._transformationMatrix = new (openfl_geom_Matrix().default)(); } if(this._transformationMatrixToRoot != null) { this._transformationMatrixToRoot.identity(); } else { this._transformationMatrixToRoot = new (openfl_geom_Matrix().default)(); } if(this._rotated) { this._transformationMatrix.translate(0,-1); this._transformationMatrix.rotate(Math.PI / 2.0); } this._transformationMatrix.scale(this._region.width / this._parent.get_width(),this._region.height / this._parent.get_height()); this._transformationMatrix.translate(this._region.x / this._parent.get_width(),this._region.y / this._parent.get_height()); var texture = this; while(texture != null) { this._transformationMatrixToRoot.concat(texture._transformationMatrix); texture = ((texture.get_parent()) instanceof SubTexture) ? texture.get_parent() : null; } }, dispose: function() { if(this._ownsParent) { this._parent.dispose(); } (starling_textures_Texture().default).prototype.dispose.call(this); }, get_parent: function() { return this._parent; }, get_ownsParent: function() { return this._ownsParent; }, get_rotated: function() { return this._rotated; }, get_region: function() { return this._region; }, get_transformationMatrix: function() { return this._transformationMatrix; }, get_transformationMatrixToRoot: function() { return this._transformationMatrixToRoot; }, get_base: function() { return this._parent.get_base(); }, get_root: function() { return this._parent.get_root(); }, get_format: function() { return this._parent.get_format(); }, get_width: function() { return this._width; }, get_height: function() { return this._height; }, get_nativeWidth: function() { return this._width * this._scale; }, get_nativeHeight: function() { return this._height * this._scale; }, get_mipMapping: function() { return this._parent.get_mipMapping(); }, get_premultipliedAlpha: function() { return this._parent.get_premultipliedAlpha(); }, get_scale: function() { return this._scale; }, get_frame: function() { return this._frame; } }); SubTexture.prototype.__class__ = SubTexture.prototype.constructor = $hxClasses["starling.textures.SubTexture"] = SubTexture; // Init Object.defineProperties(SubTexture.prototype,{ parent : { get : function () { return this.get_parent (); }}, ownsParent : { get : function () { return this.get_ownsParent (); }}, rotated : { get : function () { return this.get_rotated (); }}, region : { get : function () { return this.get_region (); }}}); // Statics SubTexture.E = 0.000001 // Export exports.default = SubTexture;