UNPKG

starling-framework

Version:

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

281 lines (265 loc) 9.15 kB
// Class: starling.styles.MeshStyle 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 $bind = require("./../../bind_stub").default; var $extend = require("./../../extend_stub").default; function starling_events_EventDispatcher() {return require("./../../starling/events/EventDispatcher");} function Type() {return require("./../../Type");} function starling_rendering_MeshEffect() {return require("./../../starling/rendering/MeshEffect");} function openfl_geom_Point() {return $import(require("openfl/geom/Point"));} // Constructor var MeshStyle = function() { (starling_events_EventDispatcher().default).call(this); this._textureSmoothing = "bilinear"; this._type = (Type().default).getClass(this); } // Meta MeshStyle.__name__ = "starling.styles.MeshStyle"; MeshStyle.__isInterface__ = false; MeshStyle.__super__ = (starling_events_EventDispatcher().default); MeshStyle.prototype = $extend((starling_events_EventDispatcher().default).prototype, { copyFrom: function(meshStyle) { this._texture = meshStyle._texture; this._textureRoot = meshStyle._textureRoot; this._textureRepeat = meshStyle._textureRepeat; this._textureSmoothing = meshStyle._textureSmoothing; }, clone: function() { var clone = (Type().default).createInstance(this._type,[]); clone.copyFrom(this); return clone; }, createEffect: function() { return new (starling_rendering_MeshEffect().default)(); }, updateEffect: function(effect,state) { effect.set_texture(this._texture); effect.set_textureRepeat(this._textureRepeat); effect.set_textureSmoothing(this._textureSmoothing); effect.set_mvpMatrix3D(state.get_mvpMatrix3D()); effect.set_alpha(state.get_alpha()); effect.set_tinted(this._vertexData.get_tinted()); }, canBatchWith: function(meshStyle) { if(this._type == meshStyle._type) { var newTexture = meshStyle._texture; if(this._texture == null && newTexture == null) { return true; } else if(this._texture != null && newTexture != null) { if(this._textureRoot == meshStyle._textureRoot && this._textureSmoothing == meshStyle._textureSmoothing) { return this._textureRepeat == meshStyle._textureRepeat; } else { return false; } } else { return false; } } else { return false; } }, batchVertexData: function(targetStyle,targetVertexID,matrix,vertexID,numVertices) { if(numVertices == null) { numVertices = -1; } if(vertexID == null) { vertexID = 0; } if(targetVertexID == null) { targetVertexID = 0; } this._vertexData.copyTo(targetStyle._vertexData,targetVertexID,matrix,vertexID,numVertices); }, batchIndexData: function(targetStyle,targetIndexID,offset,indexID,numIndices) { if(numIndices == null) { numIndices = -1; } if(indexID == null) { indexID = 0; } if(offset == null) { offset = 0; } if(targetIndexID == null) { targetIndexID = 0; } this._indexData.copyTo(targetStyle._indexData,targetIndexID,offset,indexID,numIndices); }, setRequiresRedraw: function() { if(this._target != null) { this._target.setRequiresRedraw(); } }, setVertexDataChanged: function() { if(this._target != null) { this._target.setVertexDataChanged(); } }, setIndexDataChanged: function() { if(this._target != null) { this._target.setIndexDataChanged(); } }, onTargetAssigned: function(target) { }, addEventListener: function(type,listener) { if(type == "enterFrame" && this._target != null) { this._target.addEventListener("enterFrame",$bind(this,this.onEnterFrame)); } (starling_events_EventDispatcher().default).prototype.addEventListener.call(this,type,listener); }, removeEventListener: function(type,listener) { if(type == "enterFrame" && this._target != null) { this._target.removeEventListener(type,$bind(this,this.onEnterFrame)); } (starling_events_EventDispatcher().default).prototype.removeEventListener.call(this,type,listener); }, onEnterFrame: function(event) { this.dispatchEvent(event); }, setTarget: function(target,vertexData,indexData) { if(this._target != target) { if(this._target != null) { this._target.removeEventListener("enterFrame",$bind(this,this.onEnterFrame)); } if(vertexData != null) { vertexData.set_format(this.get_vertexFormat()); } this._target = target; this._vertexData = vertexData; this._indexData = indexData; if(target != null) { if(this.hasEventListener("enterFrame")) { target.addEventListener("enterFrame",$bind(this,this.onEnterFrame)); } this.onTargetAssigned(target); } } }, getVertexPosition: function(vertexID,out) { return this._vertexData.getPoint(vertexID,"position",out); }, setVertexPosition: function(vertexID,x,y) { this._vertexData.setPoint(vertexID,"position",x,y); this.setVertexDataChanged(); }, getVertexAlpha: function(vertexID) { return this._vertexData.getAlpha(vertexID); }, setVertexAlpha: function(vertexID,alpha) { this._vertexData.setAlpha(vertexID,"color",alpha); this.setVertexDataChanged(); }, getVertexColor: function(vertexID) { return this._vertexData.getColor(vertexID); }, setVertexColor: function(vertexID,color) { this._vertexData.setColor(vertexID,"color",color); this.setVertexDataChanged(); }, getTexCoords: function(vertexID,out) { if(this._texture != null) { return this._texture.getTexCoords(this._vertexData,vertexID,"texCoords",out); } else { return this._vertexData.getPoint(vertexID,"texCoords",out); } }, setTexCoords: function(vertexID,u,v) { if(this._texture != null) { this._texture.setTexCoords(this._vertexData,vertexID,"texCoords",u,v); } else { this._vertexData.setPoint(vertexID,"texCoords",u,v); } this.setVertexDataChanged(); }, get_vertexData: function() { return this._vertexData; }, get_indexData: function() { return this._indexData; }, get_type: function() { return this._type; }, get_color: function() { if(this._vertexData.get_numVertices() > 0) { return this._vertexData.getColor(0); } else { return 0; } }, set_color: function(value) { var i; var numVertices = this._vertexData.get_numVertices(); var _g = 0; var _g1 = numVertices; while(_g < _g1) { var i1 = _g++; this._vertexData.setColor(i1,"color",value); } if(value == 16777215 && this._vertexData.get_tinted()) { this._vertexData.updateTinted(); } this.setVertexDataChanged(); return value; }, get_vertexFormat: function() { return MeshStyle.VERTEX_FORMAT; }, get_texture: function() { return this._texture; }, set_texture: function(value) { if(value != this._texture) { if(value != null) { var i; var numVertices = this._vertexData != null ? this._vertexData.get_numVertices() : 0; var _g = 0; var _g1 = numVertices; while(_g < _g1) { var i1 = _g++; this.getTexCoords(i1,MeshStyle.sPoint); value.setTexCoords(this._vertexData,i1,"texCoords",MeshStyle.sPoint.x,MeshStyle.sPoint.y); } this.setVertexDataChanged(); } else { this.setRequiresRedraw(); } this._texture = value; this._textureRoot = value != null ? value.get_root() : null; } return value; }, get_textureSmoothing: function() { return this._textureSmoothing; }, set_textureSmoothing: function(value) { if(value != this._textureSmoothing) { this._textureSmoothing = value; this.setRequiresRedraw(); } return value; }, get_textureRepeat: function() { return this._textureRepeat; }, set_textureRepeat: function(value) { return this._textureRepeat = value; }, get_target: function() { return this._target; } }); MeshStyle.prototype.__class__ = MeshStyle.prototype.constructor = $hxClasses["starling.styles.MeshStyle"] = MeshStyle; // Init Object.defineProperties(MeshStyle.prototype,{ vertexData : { get : function () { return this.get_vertexData (); }}, indexData : { get : function () { return this.get_indexData (); }}, type : { get : function () { return this.get_type (); }}, color : { get : function () { return this.get_color (); }, set : function (v) { return this.set_color (v); }}, vertexFormat : { get : function () { return this.get_vertexFormat (); }}, texture : { get : function () { return this.get_texture (); }, set : function (v) { return this.set_texture (v); }}, textureSmoothing : { get : function () { return this.get_textureSmoothing (); }, set : function (v) { return this.set_textureSmoothing (v); }}, textureRepeat : { get : function () { return this.get_textureRepeat (); }, set : function (v) { return this.set_textureRepeat (v); }}, target : { get : function () { return this.get_target (); }}}); // Statics MeshStyle.VERTEX_FORMAT = (starling_rendering_MeshEffect().default).VERTEX_FORMAT MeshStyle.sPoint = new (openfl_geom_Point().default)() // Export exports.default = MeshStyle;