UNPKG

laya-coreui-es

Version:

laya核心库、ui库es版本,剔除了媒体、TTF等功能。基于 LayaAir-release_2.12.0 修改

169 lines (168 loc) 8.39 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.LayaGLQuickRunner = void 0; const Const_1 = require("../Const"); const SpriteConst_1 = require("../display/SpriteConst"); const Matrix_1 = require("../maths/Matrix"); class LayaGLQuickRunner { static __init__() { LayaGLQuickRunner.map[SpriteConst_1.SpriteConst.ALPHA | SpriteConst_1.SpriteConst.TRANSFORM | SpriteConst_1.SpriteConst.GRAPHICS] = LayaGLQuickRunner.alpha_transform_drawLayaGL; LayaGLQuickRunner.map[SpriteConst_1.SpriteConst.ALPHA | SpriteConst_1.SpriteConst.GRAPHICS] = LayaGLQuickRunner.alpha_drawLayaGL; LayaGLQuickRunner.map[SpriteConst_1.SpriteConst.TRANSFORM | SpriteConst_1.SpriteConst.GRAPHICS] = LayaGLQuickRunner.transform_drawLayaGL; LayaGLQuickRunner.map[SpriteConst_1.SpriteConst.TRANSFORM | SpriteConst_1.SpriteConst.CHILDS] = LayaGLQuickRunner.transform_drawNodes; LayaGLQuickRunner.map[SpriteConst_1.SpriteConst.ALPHA | SpriteConst_1.SpriteConst.TRANSFORM | SpriteConst_1.SpriteConst.TEXTURE] = LayaGLQuickRunner.alpha_transform_drawTexture; LayaGLQuickRunner.map[SpriteConst_1.SpriteConst.ALPHA | SpriteConst_1.SpriteConst.TEXTURE] = LayaGLQuickRunner.alpha_drawTexture; LayaGLQuickRunner.map[SpriteConst_1.SpriteConst.TRANSFORM | SpriteConst_1.SpriteConst.TEXTURE] = LayaGLQuickRunner.transform_drawTexture; LayaGLQuickRunner.map[SpriteConst_1.SpriteConst.GRAPHICS | SpriteConst_1.SpriteConst.CHILDS] = LayaGLQuickRunner.drawLayaGL_drawNodes; } static transform_drawTexture(sprite, context, x, y) { var style = sprite._style; var tex = sprite.texture; context.saveTransform(LayaGLQuickRunner.curMat); context.transformByMatrix(sprite.transform, x, y); var width = sprite._width || tex.sourceWidth; var height = sprite._height || tex.sourceHeight; var wRate = width / tex.sourceWidth; var hRate = height / tex.sourceHeight; width = tex.width * wRate; height = tex.height * hRate; if (width <= 0 || height <= 0) return null; var px = -sprite.pivotX + tex.offsetX * wRate; var py = -sprite.pivotY + tex.offsetY * hRate; context.drawTexture(tex, px, py, width, height); context.restoreTransform(LayaGLQuickRunner.curMat); } static alpha_drawTexture(sprite, context, x, y) { var style = sprite._style; var alpha; var tex = sprite.texture; if ((alpha = style.alpha) > 0.01 || sprite._needRepaint()) { var temp = context.globalAlpha; context.globalAlpha *= alpha; var width = sprite._width || tex.width; var height = sprite._height || tex.height; var wRate = width / tex.sourceWidth; var hRate = height / tex.sourceHeight; width = tex.width * wRate; height = tex.height * hRate; if (width <= 0 || height <= 0) return null; var px = x - style.pivotX + tex.offsetX * wRate; var py = y - style.pivotY + tex.offsetY * hRate; context.drawTexture(tex, px, py, width, height); context.globalAlpha = temp; } } static alpha_transform_drawTexture(sprite, context, x, y) { var style = sprite._style; var alpha; var tex = sprite.texture; if ((alpha = style.alpha) > 0.01 || sprite._needRepaint()) { var temp = context.globalAlpha; context.globalAlpha *= alpha; context.saveTransform(LayaGLQuickRunner.curMat); context.transformByMatrix(sprite.transform, x, y); var width = sprite._width || tex.sourceWidth; var height = sprite._height || tex.sourceHeight; var wRate = width / tex.sourceWidth; var hRate = height / tex.sourceHeight; width = tex.width * wRate; height = tex.height * hRate; if (width <= 0 || height <= 0) return null; var px = -style.pivotX + tex.offsetX * wRate; var py = -style.pivotY + tex.offsetY * hRate; context.drawTexture(tex, px, py, width, height); context.restoreTransform(LayaGLQuickRunner.curMat); context.globalAlpha = temp; } } static alpha_transform_drawLayaGL(sprite, context, x, y) { var style = sprite._style; var alpha; if ((alpha = style.alpha) > 0.01 || sprite._needRepaint()) { var temp = context.globalAlpha; context.globalAlpha *= alpha; context.saveTransform(LayaGLQuickRunner.curMat); context.transformByMatrix(sprite.transform, x, y); sprite._graphics && sprite._graphics._render(sprite, context, -style.pivotX, -style.pivotY); context.restoreTransform(LayaGLQuickRunner.curMat); context.globalAlpha = temp; } } static alpha_drawLayaGL(sprite, context, x, y) { var style = sprite._style; var alpha; if ((alpha = style.alpha) > 0.01 || sprite._needRepaint()) { var temp = context.globalAlpha; context.globalAlpha *= alpha; sprite._graphics && sprite._graphics._render(sprite, context, x - style.pivotX, y - style.pivotY); context.globalAlpha = temp; } } static transform_drawLayaGL(sprite, context, x, y) { var style = sprite._style; context.saveTransform(LayaGLQuickRunner.curMat); context.transformByMatrix(sprite.transform, x, y); sprite._graphics && sprite._graphics._render(sprite, context, -style.pivotX, -style.pivotY); context.restoreTransform(LayaGLQuickRunner.curMat); } static transform_drawNodes(sprite, context, x, y) { var textLastRender = sprite._getBit(Const_1.Const.DRAWCALL_OPTIMIZE) && context.drawCallOptimize(true); var style = sprite._style; context.saveTransform(LayaGLQuickRunner.curMat); context.transformByMatrix(sprite.transform, x, y); x = -style.pivotX; y = -style.pivotY; var childs = sprite._children, n = childs.length, ele; if (style.viewport) { var rect = style.viewport; var left = rect.x; var top = rect.y; var right = rect.right; var bottom = rect.bottom; var _x, _y; for (i = 0; i < n; ++i) { if ((ele = childs[i])._visible && ((_x = ele._x) < right && (_x + ele.width) > left && (_y = ele._y) < bottom && (_y + ele.height) > top)) { ele.render(context, x, y); } } } else { for (var i = 0; i < n; ++i) (ele = childs[i])._visible && ele.render(context, x, y); } context.restoreTransform(LayaGLQuickRunner.curMat); textLastRender && context.drawCallOptimize(false); } static drawLayaGL_drawNodes(sprite, context, x, y) { var textLastRender = sprite._getBit(Const_1.Const.DRAWCALL_OPTIMIZE) && context.drawCallOptimize(true); var style = sprite._style; x = x - style.pivotX; y = y - style.pivotY; sprite._graphics && sprite._graphics._render(sprite, context, x, y); var childs = sprite._children, n = childs.length, ele; if (style.viewport) { var rect = style.viewport; var left = rect.x; var top = rect.y; var right = rect.right; var bottom = rect.bottom; var _x, _y; for (i = 0; i < n; ++i) { if ((ele = childs[i])._visible && ((_x = ele._x) < right && (_x + ele.width) > left && (_y = ele._y) < bottom && (_y + ele.height) > top)) { ele.render(context, x, y); } } } else { for (var i = 0; i < n; ++i) (ele = childs[i])._visible && ele.render(context, x, y); } textLastRender && context.drawCallOptimize(false); } } exports.LayaGLQuickRunner = LayaGLQuickRunner; LayaGLQuickRunner.map = []; LayaGLQuickRunner.curMat = new Matrix_1.Matrix();