mirror of
https://github.com/cocos/cocos4.git
synced 2026-12-01 15:52:40 +08:00
Merge pull request #2482 from 2youyou2/next
support canvas label&graphics
This commit is contained in:
@@ -764,8 +764,7 @@ var game = {
|
||||
if (!this._renderContext) {
|
||||
game.renderType = game.RENDER_TYPE_CANVAS;
|
||||
// Could be ignored by module settings
|
||||
var canvasRenderer = require('./renderer/canvas');
|
||||
renderer.initCanvas(localCanvas, canvasRenderer);
|
||||
renderer.initCanvas(localCanvas);
|
||||
this._renderContext = renderer.device._ctx;
|
||||
}
|
||||
cc.renderer = renderer;
|
||||
|
||||
@@ -147,6 +147,31 @@ function debounce (func, wait, immediate) {
|
||||
};
|
||||
}
|
||||
|
||||
let _canvasPool = {
|
||||
pool: [],
|
||||
get () {
|
||||
let data = this.pool.pop();
|
||||
|
||||
if (!data) {
|
||||
let canvas = document.createElement("canvas");
|
||||
let context = canvas.getContext("2d");
|
||||
data = {
|
||||
_canvas: canvas,
|
||||
_context: context
|
||||
}
|
||||
}
|
||||
|
||||
data.width = data.height = 1;
|
||||
return data;
|
||||
},
|
||||
put (canvas) {
|
||||
if (this.pool.length >= 32) {
|
||||
return;
|
||||
}
|
||||
this.pool.push(canvas);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* !#en The Label Component.
|
||||
@@ -164,6 +189,7 @@ var Label = cc.Class({
|
||||
}
|
||||
|
||||
this._actualFontSize = 0;
|
||||
this._assemblerData = null;
|
||||
},
|
||||
|
||||
editor: CC_EDITOR && {
|
||||
@@ -356,6 +382,7 @@ var Label = cc.Class({
|
||||
}
|
||||
this._fontAtlas = null;
|
||||
this._material = null;
|
||||
this._updateAssembler();
|
||||
this._activateMaterial();
|
||||
this._updateRenderData();
|
||||
},
|
||||
@@ -441,12 +468,41 @@ var Label = cc.Class({
|
||||
|
||||
onEnable: function () {
|
||||
this._super();
|
||||
|
||||
this._updateAssembler();
|
||||
this._activateMaterial();
|
||||
},
|
||||
|
||||
onDestroy () {
|
||||
this._resetAssemblerData();
|
||||
},
|
||||
|
||||
_resetAssemblerData () {
|
||||
if (this._assemblerData) {
|
||||
_canvasPool.put(this._assemblerData);
|
||||
}
|
||||
this._assemblerData = null;
|
||||
},
|
||||
|
||||
_updateAssembler () {
|
||||
let assembler = Label._assembler.getAssembler(this);
|
||||
|
||||
if (this._assembler !== assembler) {
|
||||
this._assembler = assembler;
|
||||
this._renderData = null;
|
||||
}
|
||||
|
||||
if (!this._renderData) {
|
||||
this._renderData = this._assembler.createData(this);
|
||||
this._renderData.worldMatDirty = true;
|
||||
}
|
||||
},
|
||||
|
||||
_activateMaterial: function () {
|
||||
if (this._material) return;
|
||||
|
||||
this._resetAssemblerData();
|
||||
|
||||
let material;
|
||||
let font = this.font;
|
||||
if (font instanceof cc.BitmapFont) {
|
||||
@@ -458,21 +514,23 @@ var Label = cc.Class({
|
||||
|
||||
material = new SpriteMaterial();
|
||||
// TODO: old texture in material have been released by loader
|
||||
material.texture = spriteFrame.getTexture();
|
||||
material.texture = this._texture = spriteFrame._texture;
|
||||
}
|
||||
else {
|
||||
material = new SpriteMaterial();
|
||||
this._texture = new cc.Texture2D();
|
||||
this._canvas = document.createElement("canvas");
|
||||
// create canvas with size so that the default texture impl can be created and don't need activate material again
|
||||
this._canvas.width = this._canvas.height = 1;
|
||||
this._texture.initWithElement(this._canvas);
|
||||
this._texture.handleLoadedTexture();
|
||||
this._context = this._canvas.getContext("2d");
|
||||
this._assemblerData = _canvasPool.get();
|
||||
|
||||
this._texture = new cc.Texture2D();
|
||||
this._texture.initWithElement(this._assemblerData._canvas);
|
||||
this._texture.handleLoadedTexture();
|
||||
|
||||
material = new SpriteMaterial();
|
||||
material.texture = this._texture;
|
||||
}
|
||||
|
||||
if (cc.game.renderType === cc.game.RENDER_TYPE_CANVAS) {
|
||||
this._texture.url = this.uuid + '_texture';
|
||||
}
|
||||
|
||||
this.setMaterial(material);
|
||||
},
|
||||
|
||||
|
||||
@@ -24,9 +24,9 @@
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
const RenderComponent = require('../core/components/CCRenderComponent');
|
||||
const renderer = require('../core/renderer');
|
||||
const renderEngine = require('../core/renderer/render-engine');
|
||||
const RenderComponent = require('../components/CCRenderComponent');
|
||||
const renderer = require('../renderer');
|
||||
const renderEngine = require('../renderer/render-engine');
|
||||
const SpriteMaterial = renderEngine.SpriteMaterial;
|
||||
|
||||
/**
|
||||
@@ -480,12 +480,6 @@ var Sprite = cc.Class({
|
||||
this._super();
|
||||
|
||||
this._updateAssembler();
|
||||
|
||||
let renderData = this._renderData;
|
||||
if (!renderData) {
|
||||
renderData = this._renderData = Sprite._assembler.createData(this);
|
||||
renderData.worldMatDirty = true;
|
||||
}
|
||||
|
||||
this._activateMaterial();
|
||||
|
||||
@@ -515,7 +509,17 @@ var Sprite = cc.Class({
|
||||
},
|
||||
|
||||
_updateAssembler: function () {
|
||||
this._assembler = Sprite._assembler.getAssembler(this);
|
||||
let assembler = Sprite._assembler.getAssembler(this);
|
||||
|
||||
if (this._assembler !== assembler) {
|
||||
this._assembler = assembler;
|
||||
this._renderData = null;
|
||||
}
|
||||
|
||||
if (!this._renderData) {
|
||||
this._renderData = this._assembler.createData(this);
|
||||
this._renderData.worldMatDirty = true;
|
||||
}
|
||||
},
|
||||
|
||||
_activateMaterial: function () {
|
||||
|
||||
@@ -51,9 +51,7 @@ var components = [
|
||||
require('./CCToggleGroup'),
|
||||
require('./CCToggle'),
|
||||
require('./CCBlockInputEvents'),
|
||||
require('./CCMotionStreak')
|
||||
];
|
||||
|
||||
// Delay require render components assemblers
|
||||
require('../renderer/assemblers');
|
||||
|
||||
module.exports = components;
|
||||
@@ -33,41 +33,6 @@ const Helper = require('./helper');
|
||||
const Types = require('./types');
|
||||
const LineCap = Types.LineCap;
|
||||
const LineJoin = Types.LineJoin;
|
||||
const PointFlags = Types.PointFlags;
|
||||
|
||||
// Point
|
||||
function Point (x, y) {
|
||||
cc.Vec2.call(this, x, y);
|
||||
this.reset();
|
||||
}
|
||||
cc.js.extend(Point, cc.Vec2);
|
||||
|
||||
Point.prototype.reset = function () {
|
||||
this.dx = 0;
|
||||
this.dy = 0;
|
||||
this.dmx = 0;
|
||||
this.dmy = 0;
|
||||
this.flags = 0;
|
||||
this.len = 0;
|
||||
};
|
||||
|
||||
// Path
|
||||
function Path () {
|
||||
this.reset();
|
||||
}
|
||||
Path.prototype.reset = function () {
|
||||
this.closed = false;
|
||||
this.nbevel = 0;
|
||||
this.complex = true;
|
||||
|
||||
if (this.points) {
|
||||
this.points.length = 0;
|
||||
}
|
||||
else {
|
||||
this.points = [];
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @class Graphics
|
||||
@@ -82,25 +47,7 @@ let Graphics = cc.Class({
|
||||
},
|
||||
|
||||
ctor () {
|
||||
// inner properties
|
||||
this._tessTol = 0.25;
|
||||
this._distTol = 0.01;
|
||||
this._updatePathOffset = false;
|
||||
|
||||
this._paths = null;
|
||||
this._pathLength = 0;
|
||||
this._pathOffset = 0;
|
||||
|
||||
this._points = null;
|
||||
this._pointsOffset = 0;
|
||||
|
||||
this._commandx = 0;
|
||||
this._commandy = 0;
|
||||
|
||||
this._paths = [];
|
||||
this._points = [];
|
||||
|
||||
this._renderDatas = [];
|
||||
this._impl = Graphics._assembler.createImpl();
|
||||
},
|
||||
|
||||
properties: {
|
||||
@@ -125,6 +72,7 @@ let Graphics = cc.Class({
|
||||
},
|
||||
set (value) {
|
||||
this._lineWidth = value;
|
||||
this._impl.lineWidth = value;
|
||||
}
|
||||
},
|
||||
|
||||
@@ -142,6 +90,7 @@ let Graphics = cc.Class({
|
||||
},
|
||||
set (value) {
|
||||
this._lineJoin = value;
|
||||
this._impl.lineJoin = value;
|
||||
},
|
||||
type: LineJoin
|
||||
},
|
||||
@@ -160,6 +109,7 @@ let Graphics = cc.Class({
|
||||
},
|
||||
set (value) {
|
||||
this._lineCap = value;
|
||||
this._impl.lineCap = value;
|
||||
},
|
||||
type: LineCap
|
||||
},
|
||||
@@ -178,6 +128,7 @@ let Graphics = cc.Class({
|
||||
},
|
||||
set (value) {
|
||||
this._strokeColor = cc.color(value);
|
||||
this._impl.strokeColor = value;
|
||||
}
|
||||
},
|
||||
|
||||
@@ -195,6 +146,7 @@ let Graphics = cc.Class({
|
||||
},
|
||||
set (value) {
|
||||
this._fillColor = cc.color(value);
|
||||
this._impl.fillColor = value;
|
||||
}
|
||||
},
|
||||
|
||||
@@ -212,6 +164,7 @@ let Graphics = cc.Class({
|
||||
},
|
||||
set (value) {
|
||||
this._miterLimit = value;
|
||||
this._impl.miterLimit = value;
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -228,8 +181,7 @@ let Graphics = cc.Class({
|
||||
|
||||
onDestroy () {
|
||||
this._super();
|
||||
// all requested render data will be destroyed by RenderComponent
|
||||
this._renderDatas.length = 0;
|
||||
this._impl = null;
|
||||
},
|
||||
|
||||
_activateMaterial () {
|
||||
@@ -248,16 +200,7 @@ let Graphics = cc.Class({
|
||||
* @param {Number} [y] The y axis of the coordinate for the end point.
|
||||
*/
|
||||
moveTo (x, y) {
|
||||
if (this._updatePathOffset) {
|
||||
this._pathOffset = this._pathLength;
|
||||
this._updatePathOffset = false;
|
||||
}
|
||||
|
||||
this._addPath();
|
||||
this._addPoint(x, y, PointFlags.PT_CORNER);
|
||||
|
||||
this._commandx = x;
|
||||
this._commandy = y;
|
||||
this._impl.moveTo(x, y);
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -268,10 +211,7 @@ let Graphics = cc.Class({
|
||||
* @param {Number} [y] The y axis of the coordinate for the end point.
|
||||
*/
|
||||
lineTo (x, y) {
|
||||
this._addPoint(x, y, PointFlags.PT_CORNER);
|
||||
|
||||
this._commandx = x;
|
||||
this._commandy = y;
|
||||
this._impl.lineTo(x, y);
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -286,18 +226,7 @@ let Graphics = cc.Class({
|
||||
* @param {Number} [y] The y axis of the coordinate for the end point.
|
||||
*/
|
||||
bezierCurveTo (c1x, c1y, c2x, c2y, x, y) {
|
||||
var path = this._curPath;
|
||||
var last = path.points[path.points.length - 1];
|
||||
|
||||
if (last.x === c1x && last.y === c1y && c2x === x && c2y === y) {
|
||||
this.lineTo(x, y);
|
||||
return;
|
||||
}
|
||||
|
||||
Helper.tesselateBezier(this, last.x, last.y, c1x, c1y, c2x, c2y, x, y, 0, PointFlags.PT_CORNER);
|
||||
|
||||
this._commandx = x;
|
||||
this._commandy = y;
|
||||
this._impl.bezierCurveTo(c1x, c1y, c2x, c2y, x, y);
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -310,9 +239,7 @@ let Graphics = cc.Class({
|
||||
* @param {Number} [y] The y axis of the coordinate for the end point.
|
||||
*/
|
||||
quadraticCurveTo (cx, cy, x, y) {
|
||||
var x0 = this._commandx;
|
||||
var y0 = this._commandy;
|
||||
this.bezierCurveTo(x0 + 2.0 / 3.0 * (cx - x0), y0 + 2.0 / 3.0 * (cy - y0), x + 2.0 / 3.0 * (cx - x), y + 2.0 / 3.0 * (cy - y), x, y);
|
||||
this._impl.quadraticCurveTo(cx, cy, x, y);
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -327,7 +254,7 @@ let Graphics = cc.Class({
|
||||
* @param {Number} [counterclockwise] An optional Boolean which, if true, causes the arc to be drawn counter-clockwise between the two angles. By default it is drawn clockwise.
|
||||
*/
|
||||
arc (cx, cy, r, startAngle, endAngle, counterclockwise) {
|
||||
Helper.arc(this, cx, cy, r, startAngle, endAngle, counterclockwise);
|
||||
this._impl.arc(cx, cy, r, startAngle, endAngle, counterclockwise);
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -340,8 +267,7 @@ let Graphics = cc.Class({
|
||||
* @param {Number} [ry] The ellipse's y-axis radius.
|
||||
*/
|
||||
ellipse (cx, cy, rx, ry) {
|
||||
Helper.ellipse(this, cx, cy, rx, ry);
|
||||
this._curPath.complex = false;
|
||||
this._impl.ellipse(cx, cy, rx, ry);
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -353,8 +279,7 @@ let Graphics = cc.Class({
|
||||
* @param {Number} [r] The circle's radius.
|
||||
*/
|
||||
circle (cx, cy, r) {
|
||||
Helper.ellipse(this, cx, cy, r, r);
|
||||
this._curPath.complex = false;
|
||||
this._impl.circle(cx, cy, r);
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -367,12 +292,7 @@ let Graphics = cc.Class({
|
||||
* @param {Number} [h] The rectangle's height.
|
||||
*/
|
||||
rect (x, y, w, h) {
|
||||
this.moveTo(x, y);
|
||||
this.lineTo(x, y + h);
|
||||
this.lineTo(x + w, y + h);
|
||||
this.lineTo(x + w, y);
|
||||
this.close();
|
||||
this._curPath.complex = false;
|
||||
this._impl.rect(x, y, w, h);
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -386,8 +306,7 @@ let Graphics = cc.Class({
|
||||
* @param {Number} [r] The radius of the rectangle.
|
||||
*/
|
||||
roundRect (x, y, w, h, r) {
|
||||
Helper.roundRect(this, x, y, w, h, r);
|
||||
this._curPath.complex = false;
|
||||
this._impl.roundRect(x, y, w, h, r);
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -411,29 +330,7 @@ let Graphics = cc.Class({
|
||||
* @param {Boolean} [clean] Whether to clean the graphics inner cache.
|
||||
*/
|
||||
clear (clean) {
|
||||
this._pathLength = 0;
|
||||
this._pathOffset = 0;
|
||||
this._pointsOffset = 0;
|
||||
|
||||
this._curPath = null;
|
||||
|
||||
let datas = this._renderDatas;
|
||||
if (clean) {
|
||||
this._paths.length = 0;
|
||||
this._points.length = 0;
|
||||
// manually destroy render datas
|
||||
for (let i = 0, l = datas.length; i < l; i++) {
|
||||
this.destroyRenderData(datas[i]);
|
||||
}
|
||||
datas.length = 0;
|
||||
}
|
||||
else {
|
||||
for (let i = 0, l = datas.length; i < l; i++) {
|
||||
let data = datas[i];
|
||||
data.vertexCount = data.indiceCount = data.dataLength = 0;
|
||||
data._indices.length = 0;
|
||||
}
|
||||
}
|
||||
this._impl.clear(this, clean);
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -442,7 +339,7 @@ let Graphics = cc.Class({
|
||||
* @method close
|
||||
*/
|
||||
close () {
|
||||
this._curPath.closed = true;
|
||||
this._impl.close();
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -461,47 +358,6 @@ let Graphics = cc.Class({
|
||||
*/
|
||||
fill () {
|
||||
Graphics._assembler.fill(this);
|
||||
},
|
||||
|
||||
_addPath () {
|
||||
var offset = this._pathLength;
|
||||
var path = this._paths[offset];
|
||||
|
||||
if (!path) {
|
||||
path = new Path();
|
||||
|
||||
this._paths.push(path);
|
||||
} else {
|
||||
path.reset();
|
||||
}
|
||||
|
||||
this._pathLength++;
|
||||
this._curPath = path;
|
||||
|
||||
return path;
|
||||
},
|
||||
|
||||
_addPoint (x, y, flags) {
|
||||
var path = this._curPath;
|
||||
if (!path) return;
|
||||
|
||||
var pt;
|
||||
var points = this._points;
|
||||
var pathPoints = path.points;
|
||||
|
||||
var offset = this._pointsOffset++;
|
||||
pt = points[offset];
|
||||
|
||||
if (!pt) {
|
||||
pt = new Point(x, y);
|
||||
points.push(pt);
|
||||
} else {
|
||||
pt.x = x;
|
||||
pt.y = y;
|
||||
}
|
||||
|
||||
pt.flags = flags;
|
||||
pathPoints.push(pt);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -0,0 +1,208 @@
|
||||
|
||||
const Helper = require('../../../graphics/helper');
|
||||
const PointFlags = require('../../../graphics/types').PointFlags;
|
||||
|
||||
class Point extends cc.Vec2 {
|
||||
constructor (x, y) {
|
||||
super(x, y);
|
||||
this.reset();
|
||||
}
|
||||
|
||||
reset () {
|
||||
this.dx = 0;
|
||||
this.dy = 0;
|
||||
this.dmx = 0;
|
||||
this.dmy = 0;
|
||||
this.flags = 0;
|
||||
this.len = 0;
|
||||
}
|
||||
}
|
||||
|
||||
class Path {
|
||||
constructor () {
|
||||
this.reset();
|
||||
}
|
||||
|
||||
reset () {
|
||||
this.closed = false;
|
||||
this.nbevel = 0;
|
||||
this.complex = true;
|
||||
|
||||
if (this.points) {
|
||||
this.points.length = 0;
|
||||
}
|
||||
else {
|
||||
this.points = [];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class Impl {
|
||||
constructor () {
|
||||
// inner properties
|
||||
this._tessTol = 0.25;
|
||||
this._distTol = 0.01;
|
||||
this._updatePathOffset = false;
|
||||
|
||||
this._paths = null;
|
||||
this._pathLength = 0;
|
||||
this._pathOffset = 0;
|
||||
|
||||
this._points = null;
|
||||
this._pointsOffset = 0;
|
||||
|
||||
this._commandx = 0;
|
||||
this._commandy = 0;
|
||||
|
||||
this._paths = [];
|
||||
this._points = [];
|
||||
|
||||
this._renderDatas = [];
|
||||
|
||||
this._dataOffset = 0;
|
||||
}
|
||||
|
||||
moveTo (x, y) {
|
||||
if (this._updatePathOffset) {
|
||||
this._pathOffset = this._pathLength;
|
||||
this._updatePathOffset = false;
|
||||
}
|
||||
|
||||
this._addPath();
|
||||
this._addPoint(x, y, PointFlags.PT_CORNER);
|
||||
|
||||
this._commandx = x;
|
||||
this._commandy = y;
|
||||
}
|
||||
|
||||
lineTo (x, y) {
|
||||
this._addPoint(x, y, PointFlags.PT_CORNER);
|
||||
|
||||
this._commandx = x;
|
||||
this._commandy = y;
|
||||
}
|
||||
|
||||
bezierCurveTo (c1x, c1y, c2x, c2y, x, y) {
|
||||
var path = this._curPath;
|
||||
var last = path.points[path.points.length - 1];
|
||||
|
||||
if (last.x === c1x && last.y === c1y && c2x === x && c2y === y) {
|
||||
this.lineTo(x, y);
|
||||
return;
|
||||
}
|
||||
|
||||
Helper.tesselateBezier(this, last.x, last.y, c1x, c1y, c2x, c2y, x, y, 0, PointFlags.PT_CORNER);
|
||||
|
||||
this._commandx = x;
|
||||
this._commandy = y;
|
||||
}
|
||||
|
||||
quadraticCurveTo (cx, cy, x, y) {
|
||||
var x0 = this._commandx;
|
||||
var y0 = this._commandy;
|
||||
this.bezierCurveTo(x0 + 2.0 / 3.0 * (cx - x0), y0 + 2.0 / 3.0 * (cy - y0), x + 2.0 / 3.0 * (cx - x), y + 2.0 / 3.0 * (cy - y), x, y);
|
||||
}
|
||||
|
||||
arc (cx, cy, r, startAngle, endAngle, counterclockwise) {
|
||||
Helper.arc(this, cx, cy, r, startAngle, endAngle, counterclockwise);
|
||||
}
|
||||
|
||||
ellipse (cx, cy, rx, ry) {
|
||||
Helper.ellipse(this, cx, cy, rx, ry);
|
||||
this._curPath.complex = false;
|
||||
}
|
||||
|
||||
circle (cx, cy, r) {
|
||||
Helper.ellipse(this, cx, cy, r, r);
|
||||
this._curPath.complex = false;
|
||||
}
|
||||
|
||||
rect (x, y, w, h) {
|
||||
this.moveTo(x, y);
|
||||
this.lineTo(x, y + h);
|
||||
this.lineTo(x + w, y + h);
|
||||
this.lineTo(x + w, y);
|
||||
this.close();
|
||||
this._curPath.complex = false;
|
||||
}
|
||||
|
||||
roundRect (x, y, w, h, r) {
|
||||
Helper.roundRect(this, x, y, w, h, r);
|
||||
this._curPath.complex = false;
|
||||
}
|
||||
|
||||
clear (comp, clean) {
|
||||
this._pathLength = 0;
|
||||
this._pathOffset = 0;
|
||||
this._pointsOffset = 0;
|
||||
|
||||
this._dataOffset = 0;
|
||||
|
||||
this._curPath = null;
|
||||
|
||||
let datas = this._renderDatas;
|
||||
if (clean) {
|
||||
this._paths.length = 0;
|
||||
this._points.length = 0;
|
||||
// manually destroy render datas
|
||||
for (let i = 0, l = datas.length; i < l; i++) {
|
||||
comp.destroyRenderData(datas[i]);
|
||||
}
|
||||
datas.length = 0;
|
||||
}
|
||||
else {
|
||||
for (let i = 0, l = datas.length; i < l; i++) {
|
||||
let data = datas[i];
|
||||
data.indiceCount = data._indices.length = 0;
|
||||
data.vertexCount = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
close () {
|
||||
this._curPath.closed = true;
|
||||
}
|
||||
|
||||
_addPath () {
|
||||
var offset = this._pathLength;
|
||||
var path = this._paths[offset];
|
||||
|
||||
if (!path) {
|
||||
path = new Path();
|
||||
|
||||
this._paths.push(path);
|
||||
} else {
|
||||
path.reset();
|
||||
}
|
||||
|
||||
this._pathLength++;
|
||||
this._curPath = path;
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
_addPoint (x, y, flags) {
|
||||
var path = this._curPath;
|
||||
if (!path) return;
|
||||
|
||||
var pt;
|
||||
var points = this._points;
|
||||
var pathPoints = path.points;
|
||||
|
||||
var offset = this._pointsOffset++;
|
||||
pt = points[offset];
|
||||
|
||||
if (!pt) {
|
||||
pt = new Point(x, y);
|
||||
points.push(pt);
|
||||
} else {
|
||||
pt.x = x;
|
||||
pt.y = y;
|
||||
}
|
||||
|
||||
pt.flags = flags;
|
||||
pathPoints.push(pt);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Impl;
|
||||
+65
-38
@@ -28,6 +28,7 @@ const PointFlags = require('../../../graphics/types').PointFlags;
|
||||
const LineJoin = Graphics.LineJoin;
|
||||
const LineCap = Graphics.LineCap;
|
||||
const Earcut = require('./earcut');
|
||||
const Impl = require('./impl');
|
||||
|
||||
const macro = require('../../../platform/CCMacro');
|
||||
const MAX_VERTEX = macro.BATCH_VERTEX_COUNT;
|
||||
@@ -50,6 +51,7 @@ const abs = Math.abs;
|
||||
|
||||
let _matrix = math.mat4.create();
|
||||
let _renderData = null;
|
||||
let _impl = null;
|
||||
let _curColor = 0;
|
||||
|
||||
function curveDivs (r, arc, tol) {
|
||||
@@ -68,8 +70,12 @@ function clamp (v, min, max) {
|
||||
}
|
||||
|
||||
let graphicsAssembler = js.addon({
|
||||
createImpl () {
|
||||
return new Impl();
|
||||
},
|
||||
|
||||
updateRenderData (graphics) {
|
||||
let datas = graphics._renderDatas;
|
||||
let datas = graphics._impl._renderDatas;
|
||||
if (datas.length === 0) {
|
||||
datas.push(graphics.requestRenderData());
|
||||
}
|
||||
@@ -98,7 +104,7 @@ let graphicsAssembler = js.addon({
|
||||
nodeG = nodeColor.g / 255,
|
||||
nodeB = nodeColor.b / 255,
|
||||
nodeA = nodeColor.a / 255;
|
||||
for (let i = 0, l = data.length; i < l; i++) {
|
||||
for (let i = 0, l = renderData.vertexCount; i < l; i++) {
|
||||
vbuf[offset++] = data[i].x * a + data[i].y * c + tx;
|
||||
vbuf[offset++] = data[i].x * b + data[i].y * d + ty;
|
||||
vbuf[offset++] = z;
|
||||
@@ -122,38 +128,55 @@ let graphicsAssembler = js.addon({
|
||||
},
|
||||
|
||||
genRenderData (graphics, cverts) {
|
||||
let renderDatas = graphics._renderDatas;
|
||||
let renderData = renderDatas[renderDatas.length - 1];
|
||||
let maxVertsCount = renderData.dataLength + cverts;
|
||||
let renderDatas = _impl._renderDatas;
|
||||
let renderData = renderDatas[_impl._dataOffset];
|
||||
|
||||
let maxVertsCount = renderData.vertexCount + cverts;
|
||||
if (maxVertsCount > MAX_VERTEX ||
|
||||
maxVertsCount * 3 > MAX_INDICE) {
|
||||
renderData = graphics.requestRenderData();
|
||||
++_impl._dataOffset;
|
||||
maxVertsCount = cverts;
|
||||
|
||||
if (_impl._dataOffset < renderDatas.length) {
|
||||
renderData = renderDatas[_impl._dataOffset];
|
||||
}
|
||||
else {
|
||||
renderData = graphics.requestRenderData();
|
||||
renderDatas[_impl._dataOffset] = renderData;
|
||||
}
|
||||
}
|
||||
|
||||
if (maxVertsCount > renderData.dataLength) {
|
||||
renderData.dataLength = maxVertsCount;
|
||||
}
|
||||
|
||||
return renderData;
|
||||
},
|
||||
|
||||
stroke (graphics) {
|
||||
if (graphics._renderDatas.length === 0) {
|
||||
graphics._renderDatas.push(graphics.requestRenderData());
|
||||
let renderDatas = graphics._impl._renderDatas;
|
||||
if (renderDatas.length === 0) {
|
||||
renderDatas.push(graphics.requestRenderData());
|
||||
}
|
||||
|
||||
_curColor = graphics._strokeColor._val;
|
||||
|
||||
this._flattenPaths(graphics);
|
||||
this._flattenPaths(graphics._impl);
|
||||
this._expandStroke(graphics);
|
||||
|
||||
graphics._updatePathOffset = true;
|
||||
graphics._impl._updatePathOffset = true;
|
||||
},
|
||||
|
||||
fill (graphics) {
|
||||
if (graphics._renderDatas.length === 0) {
|
||||
graphics._renderDatas.push(graphics.requestRenderData());
|
||||
let renderDatas = graphics._impl._renderDatas;
|
||||
if (renderDatas.length === 0) {
|
||||
renderDatas.push(graphics.requestRenderData());
|
||||
}
|
||||
|
||||
_curColor = graphics._fillColor._val;
|
||||
|
||||
this._expandFill(graphics);
|
||||
this._updatePathOffset = true;
|
||||
graphics._impl._updatePathOffset = true;
|
||||
},
|
||||
|
||||
_expandStroke (graphics) {
|
||||
@@ -161,16 +184,18 @@ let graphicsAssembler = js.addon({
|
||||
lineCap = graphics.lineCap,
|
||||
lineJoin = graphics.lineJoin,
|
||||
miterLimit = graphics.miterLimit;
|
||||
|
||||
_impl = graphics._impl;
|
||||
|
||||
let ncap = curveDivs(w, PI, graphics._tessTol);
|
||||
let ncap = curveDivs(w, PI, _impl._tessTol);
|
||||
|
||||
this._calculateJoins(graphics, w, lineJoin, miterLimit);
|
||||
this._calculateJoins(_impl, w, lineJoin, miterLimit);
|
||||
|
||||
let paths = graphics._paths;
|
||||
let paths = _impl._paths;
|
||||
|
||||
// Calculate max vertex usage.
|
||||
let cverts = 0;
|
||||
for (let i = graphics._pathOffset, l = graphics._pathLength; i < l; i++) {
|
||||
for (let i = _impl._pathOffset, l = _impl._pathLength; i < l; i++) {
|
||||
let path = paths[i];
|
||||
let pointsLength = path.points.length;
|
||||
|
||||
@@ -186,16 +211,16 @@ let graphicsAssembler = js.addon({
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
let renderData = _renderData = this.genRenderData(graphics, cverts),
|
||||
data = renderData._data,
|
||||
indicesBuffer = renderData._indices;
|
||||
|
||||
for (let i = graphics._pathOffset, l = graphics._pathLength; i < l; i++) {
|
||||
for (let i = _impl._pathOffset, l = _impl._pathLength; i < l; i++) {
|
||||
let path = paths[i];
|
||||
let pts = path.points;
|
||||
let pointsLength = pts.length;
|
||||
let offset = data.length;
|
||||
let offset = renderData.vertexCount;
|
||||
|
||||
let p0, p1;
|
||||
let start, end, loop;
|
||||
@@ -268,25 +293,27 @@ let graphicsAssembler = js.addon({
|
||||
|
||||
// stroke indices
|
||||
let indicesOffset = indicesBuffer.length;
|
||||
for (let start = offset+2, end = data.length; start < end; start++) {
|
||||
for (let start = offset+2, end = renderData.vertexCount; start < end; start++) {
|
||||
indicesBuffer[indicesOffset++] = start - 2;
|
||||
indicesBuffer[indicesOffset++] = start - 1;
|
||||
indicesBuffer[indicesOffset++] = start;
|
||||
}
|
||||
}
|
||||
|
||||
renderData.vertexCount = data.length;
|
||||
renderData.indiceCount = indicesBuffer.length;
|
||||
|
||||
_renderData = null;
|
||||
_impl = null;
|
||||
},
|
||||
|
||||
_expandFill (graphics) {
|
||||
let paths = graphics._paths;
|
||||
_impl = graphics._impl;
|
||||
|
||||
let paths = _impl._paths;
|
||||
|
||||
// Calculate max vertex usage.
|
||||
let cverts = 0;
|
||||
for (let i = graphics._pathOffset, l = graphics._pathLength; i < l; i++) {
|
||||
for (let i = _impl._pathOffset, l = _impl._pathLength; i < l; i++) {
|
||||
let path = paths[i];
|
||||
let pointsLength = path.points.length;
|
||||
|
||||
@@ -297,7 +324,7 @@ let graphicsAssembler = js.addon({
|
||||
data = renderData._data,
|
||||
indicesBuffer = renderData._indices;
|
||||
|
||||
for (let i = graphics._pathOffset, l = graphics._pathLength; i < l; i++) {
|
||||
for (let i = _impl._pathOffset, l = _impl._pathLength; i < l; i++) {
|
||||
let path = paths[i];
|
||||
let pts = path.points;
|
||||
let pointsLength = pts.length;
|
||||
@@ -307,7 +334,7 @@ let graphicsAssembler = js.addon({
|
||||
}
|
||||
|
||||
// Calculate shape vertices.
|
||||
let offset = data.length;
|
||||
let offset = renderData.vertexCount;
|
||||
|
||||
for (let j = 0; j < pointsLength; ++j) {
|
||||
this._vset(pts[j].x, pts[j].y);
|
||||
@@ -317,7 +344,7 @@ let graphicsAssembler = js.addon({
|
||||
|
||||
if (path.complex) {
|
||||
let earcutData = [];
|
||||
for (let j = offset, end = data.length; j < end; j++) {
|
||||
for (let j = offset, end = renderData.vertexCount; j < end; j++) {
|
||||
earcutData.push(data[j].x);
|
||||
earcutData.push(data[j].y);
|
||||
}
|
||||
@@ -334,7 +361,7 @@ let graphicsAssembler = js.addon({
|
||||
}
|
||||
else {
|
||||
let first = offset;
|
||||
for (let start = offset+2, end = data.length; start < end; start++) {
|
||||
for (let start = offset+2, end = renderData.vertexCount; start < end; start++) {
|
||||
indicesBuffer[indicesOffset++] = first;
|
||||
indicesBuffer[indicesOffset++] = start - 1;
|
||||
indicesBuffer[indicesOffset++] = start;
|
||||
@@ -342,13 +369,13 @@ let graphicsAssembler = js.addon({
|
||||
}
|
||||
}
|
||||
|
||||
renderData.vertexCount = data.length;
|
||||
renderData.indiceCount = indicesBuffer.length;
|
||||
|
||||
_renderData = null;
|
||||
_impl = null;
|
||||
},
|
||||
|
||||
_calculateJoins (graphics, w, lineJoin, miterLimit) {
|
||||
_calculateJoins (impl, w, lineJoin, miterLimit) {
|
||||
let iw = 0.0;
|
||||
|
||||
if (w > 0.0) {
|
||||
@@ -356,8 +383,8 @@ let graphicsAssembler = js.addon({
|
||||
}
|
||||
|
||||
// Calculate which joins needs extra vertices to append, and gather vertex count.
|
||||
let paths = graphics._paths;
|
||||
for (let i = graphics._pathOffset, l = graphics._pathLength; i < l; i++) {
|
||||
let paths = impl._paths;
|
||||
for (let i = impl._pathOffset, l = impl._pathLength; i < l; i++) {
|
||||
let path = paths[i];
|
||||
|
||||
let pts = path.points;
|
||||
@@ -420,9 +447,9 @@ let graphicsAssembler = js.addon({
|
||||
}
|
||||
},
|
||||
|
||||
_flattenPaths (graphics) {
|
||||
let paths = graphics._paths;
|
||||
for (let i = graphics._pathOffset, l = graphics._pathLength; i < l; i++) {
|
||||
_flattenPaths (impl) {
|
||||
let paths = impl._paths;
|
||||
for (let i = impl._pathOffset, l = impl._pathLength; i < l; i++) {
|
||||
let path = paths[i];
|
||||
let pts = path.points;
|
||||
|
||||
@@ -613,13 +640,13 @@ let graphicsAssembler = js.addon({
|
||||
|
||||
_vset (x, y) {
|
||||
let data = _renderData._data;
|
||||
|
||||
let offset = data.length;
|
||||
_renderData.dataLength = offset + 1;
|
||||
let offset = _renderData.vertexCount;
|
||||
|
||||
data[offset].x = x;
|
||||
data[offset].y = y;
|
||||
data[offset].color = _curColor;
|
||||
|
||||
_renderData.vertexCount ++;
|
||||
}
|
||||
}, assembler);
|
||||
|
||||
@@ -23,7 +23,8 @@
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
require('./sprite/sprite-assembler');
|
||||
require('./sprite');
|
||||
require('./mask-assembler');
|
||||
require('./graphics/graphics-assembler');
|
||||
require('./label/label-assembler');
|
||||
require('./graphics');
|
||||
require('./label');
|
||||
require('./motion-streak');
|
||||
|
||||
@@ -0,0 +1,135 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
const macro = require('../../../platform/CCMacro');
|
||||
const renderEngine = require('../../render-engine');
|
||||
|
||||
const js = require('../../../platform/js');
|
||||
const bmfontUtls = require('../../utils/label/bmfont');
|
||||
|
||||
module.exports = js.addon({
|
||||
createData (comp) {
|
||||
return comp.requestRenderData();
|
||||
},
|
||||
|
||||
fillVertexBuffer (comp, off, vbuf, uintbuf) {
|
||||
let node = comp.node;
|
||||
let renderData = comp._renderData;
|
||||
let data = renderData._data;
|
||||
let z = node._position.z;
|
||||
let color = node.color._val;
|
||||
|
||||
node._updateWorldMatrix();
|
||||
let matrix = node._worldMatrix;
|
||||
let a = matrix.m00,
|
||||
b = matrix.m01,
|
||||
c = matrix.m04,
|
||||
d = matrix.m05,
|
||||
tx = matrix.m12,
|
||||
ty = matrix.m13;
|
||||
|
||||
let vert;
|
||||
let length = renderData.dataLength;
|
||||
for (let i = 0; i < length; i++) {
|
||||
vert = data[i];
|
||||
vbuf[off + 0] = vert.x * a + vert.y * c + tx;
|
||||
vbuf[off + 1] = vert.x * b + vert.y * d + ty;
|
||||
vbuf[off + 2] = z;
|
||||
vbuf[off + 4] = vert.u;
|
||||
vbuf[off + 5] = vert.v;
|
||||
uintbuf[off + 3] = color;
|
||||
off += 6;
|
||||
}
|
||||
},
|
||||
|
||||
fillIndexBuffer (comp, offset, vertexId, ibuf) {
|
||||
let renderData = comp._renderData;
|
||||
let length = renderData.indiceCount;
|
||||
for (let i = 0; i < length; i+=6) {
|
||||
ibuf[offset++] = vertexId;
|
||||
ibuf[offset++] = vertexId+1;
|
||||
ibuf[offset++] = vertexId+2;
|
||||
ibuf[offset++] = vertexId+1;
|
||||
ibuf[offset++] = vertexId+3;
|
||||
ibuf[offset++] = vertexId+2;
|
||||
vertexId += 4;
|
||||
}
|
||||
},
|
||||
|
||||
appendQuad (renderData, texture, rect, rotated, x, y, scale) {
|
||||
let dataOffset = renderData.dataLength;
|
||||
|
||||
renderData.dataLength += 4;
|
||||
renderData.vertexCount = renderData.dataLength;
|
||||
renderData.indiceCount = renderData.dataLength / 2 * 3;
|
||||
|
||||
let data = renderData._data;
|
||||
let texw = texture.width,
|
||||
texh = texture.height;
|
||||
|
||||
let rectWidth = rect.width,
|
||||
rectHeight = rect.height;
|
||||
|
||||
let l, b, r, t;
|
||||
if (!rotated) {
|
||||
l = (rect.x) / texw;
|
||||
r = (rect.x + rectWidth) / texw;
|
||||
b = (rect.y + rectHeight) / texh;
|
||||
t = (rect.y) / texh;
|
||||
|
||||
data[dataOffset].u = l;
|
||||
data[dataOffset].v = b;
|
||||
data[dataOffset+1].u = r;
|
||||
data[dataOffset+1].v = b;
|
||||
data[dataOffset+2].u = l;
|
||||
data[dataOffset+2].v = t;
|
||||
data[dataOffset+3].u = r;
|
||||
data[dataOffset+3].v = t;
|
||||
} else {
|
||||
l = (rect.x) / texw;
|
||||
r = (rect.x + rectHeight) / texw;
|
||||
b = (rect.y + rectWidth) / texh;
|
||||
t = (rect.y) / texh;
|
||||
|
||||
data[dataOffset].u = l;
|
||||
data[dataOffset].v = t;
|
||||
data[dataOffset+1].u = l;
|
||||
data[dataOffset+1].v = b;
|
||||
data[dataOffset+2].u = r;
|
||||
data[dataOffset+2].v = t;
|
||||
data[dataOffset+3].u = r;
|
||||
data[dataOffset+3].v = b;
|
||||
}
|
||||
|
||||
data[dataOffset].x = x;
|
||||
data[dataOffset].y = y - rectHeight * scale;
|
||||
data[dataOffset+1].x = x + rectWidth * scale;
|
||||
data[dataOffset+1].y = y - rectHeight * scale;
|
||||
data[dataOffset+2].x = x;
|
||||
data[dataOffset+2].y = y;
|
||||
data[dataOffset+3].x = x + rectWidth * scale;
|
||||
data[dataOffset+3].y = y;
|
||||
},
|
||||
}, bmfontUtls);
|
||||
+32
-36
@@ -26,57 +26,53 @@
|
||||
const js = require('../../../platform/js');
|
||||
const assembler = require('../assembler');
|
||||
const Label = require('../../../components/CCLabel');
|
||||
const ttfAssembler = require('./ttf-assembler');
|
||||
const bmfontAssembler = require('./bmfont-assembler');
|
||||
const ttfAssembler = require('./ttf');
|
||||
const bmfontAssembler = require('./bmfont');
|
||||
|
||||
var labelAssembler = js.addon({
|
||||
|
||||
getAssembler (comp) {
|
||||
let assembler = ttfAssembler;
|
||||
|
||||
if (comp.font instanceof cc.BitmapFont) {
|
||||
assembler = bmfontAssembler;
|
||||
}
|
||||
|
||||
return assembler;
|
||||
},
|
||||
|
||||
updateRenderData (comp) {
|
||||
this.datas.length = 0;
|
||||
if (comp.string !== undefined && comp.string !== null && comp.string !== "") {
|
||||
let assembler;
|
||||
if (comp.font instanceof cc.BitmapFont) {
|
||||
assembler = bmfontAssembler;
|
||||
}
|
||||
else {
|
||||
assembler = ttfAssembler;
|
||||
}
|
||||
|
||||
let renderData = comp._renderData;
|
||||
if (!renderData) {
|
||||
renderData = comp._renderData = assembler.createData(comp);
|
||||
}
|
||||
if (comp.string === undefined ||
|
||||
comp.string === null ||
|
||||
comp.string === "" ||
|
||||
!comp._assembler) {
|
||||
return this.datas;
|
||||
}
|
||||
|
||||
let size = comp.node._contentSize;
|
||||
let anchor = comp.node._anchorPoint;
|
||||
renderData.updateSizeNPivot(size.width, size.height, anchor.x, anchor.y);
|
||||
let renderData = comp._renderData;
|
||||
|
||||
assembler.update(comp);
|
||||
// let size = comp.node._contentSize;
|
||||
// let anchor = comp.node._anchorPoint;
|
||||
// renderData.updateSizeNPivot(size.width, size.height, anchor.x, anchor.y);
|
||||
|
||||
renderData.material = comp.getMaterial();
|
||||
this.datas.push(renderData);
|
||||
}
|
||||
comp._assembler.update(comp);
|
||||
|
||||
renderData.material = comp.getMaterial();
|
||||
this.datas.push(renderData);
|
||||
return this.datas;
|
||||
},
|
||||
|
||||
fillBuffers (comp, batchData, vertexId, vbuf, uintbuf, ibuf) {
|
||||
let assembler = comp._assembler;
|
||||
if (!assembler) return;
|
||||
|
||||
let vertexOffset = batchData.byteOffset / 4,
|
||||
indiceOffset = batchData.indiceOffset;
|
||||
|
||||
// vertex buffer
|
||||
if (comp.font instanceof cc.BitmapFont) {
|
||||
bmfontAssembler.fillVertexBuffer(comp, vertexOffset, vbuf, uintbuf);
|
||||
}
|
||||
else {
|
||||
ttfAssembler.fillVertexBuffer(comp, vertexOffset, vbuf, uintbuf);
|
||||
}
|
||||
|
||||
// index buffer
|
||||
if (comp.font instanceof cc.BitmapFont) {
|
||||
bmfontAssembler.fillIndexBuffer(comp, indiceOffset, vertexId, ibuf);
|
||||
}
|
||||
else {
|
||||
ttfAssembler.fillIndexBuffer(comp, indiceOffset, vertexId, ibuf);
|
||||
}
|
||||
assembler.fillVertexBuffer(comp, vertexOffset, vbuf, uintbuf);
|
||||
assembler.fillIndexBuffer(comp, indiceOffset, vertexId, ibuf);
|
||||
}
|
||||
}, assembler);
|
||||
|
||||
@@ -0,0 +1,110 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
const macro = require('../../../platform/CCMacro');
|
||||
const renderEngine = require('../../render-engine');
|
||||
|
||||
const js = require('../../../platform/js');
|
||||
const ttfUtls = require('../../utils/label/ttf');
|
||||
|
||||
module.exports = js.addon({
|
||||
createData (comp) {
|
||||
let renderData = comp.requestRenderData();
|
||||
|
||||
renderData.dataLength = 4;
|
||||
renderData.vertexCount = 4;
|
||||
renderData.indiceCount = 6;
|
||||
|
||||
let data = renderData._data;
|
||||
data[0].u = 0;
|
||||
data[0].v = 1;
|
||||
data[1].u = 1;
|
||||
data[1].v = 1;
|
||||
data[2].u = 0;
|
||||
data[2].v = 0;
|
||||
data[3].u = 1;
|
||||
data[3].v = 0;
|
||||
return renderData;
|
||||
},
|
||||
|
||||
fillVertexBuffer (comp, off, vbuf, uintbuf) {
|
||||
let node = comp.node;
|
||||
let renderData = comp._renderData;
|
||||
let data = renderData._data;
|
||||
let z = node._position.z;
|
||||
let color = cc.Color.WHITE._val;
|
||||
|
||||
node._updateWorldMatrix();
|
||||
let matrix = node._worldMatrix;
|
||||
let a = matrix.m00,
|
||||
b = matrix.m01,
|
||||
c = matrix.m04,
|
||||
d = matrix.m05,
|
||||
tx = matrix.m12,
|
||||
ty = matrix.m13;
|
||||
|
||||
let vert;
|
||||
let length = renderData.dataLength;
|
||||
for (let i = 0; i < length; i++) {
|
||||
vert = data[i];
|
||||
vbuf[off + 0] = vert.x * a + vert.y * c + tx;
|
||||
vbuf[off + 1] = vert.x * b + vert.y * d + ty;
|
||||
vbuf[off + 2] = z;
|
||||
vbuf[off + 4] = vert.u;
|
||||
vbuf[off + 5] = vert.v;
|
||||
uintbuf[off + 3] = color;
|
||||
off += 6;
|
||||
}
|
||||
},
|
||||
|
||||
fillIndexBuffer (comp, offset, vertexId, ibuf) {
|
||||
ibuf[offset + 0] = vertexId;
|
||||
ibuf[offset + 1] = vertexId + 1;
|
||||
ibuf[offset + 2] = vertexId + 2;
|
||||
ibuf[offset + 3] = vertexId + 1;
|
||||
ibuf[offset + 4] = vertexId + 3;
|
||||
ibuf[offset + 5] = vertexId + 2;
|
||||
},
|
||||
|
||||
_updateVerts (comp) {
|
||||
let renderData = comp._renderData;
|
||||
|
||||
let node = comp.node,
|
||||
width = node.width,
|
||||
height = node.height,
|
||||
appx = node.anchorX * width,
|
||||
appy = node.anchorY * height;
|
||||
|
||||
let data = renderData._data;
|
||||
data[0].x = -appx;
|
||||
data[0].y = -appy;
|
||||
data[1].x = width - appx;
|
||||
data[1].y = -appy;
|
||||
data[2].x = -appx;
|
||||
data[2].y = height - appy;
|
||||
data[3].x = width - appx;
|
||||
data[3].y = height - appy;
|
||||
}
|
||||
}, ttfUtls);
|
||||
@@ -32,7 +32,7 @@ const js = require('../../platform/js');
|
||||
const assembler = require('./assembler');
|
||||
const spriteAssembler = require('./sprite/simple');
|
||||
const Graphics = require('../../graphics/graphics');
|
||||
const graphicsAssembler = require('./graphics/graphics-assembler');
|
||||
const graphicsAssembler = require('./graphics');
|
||||
|
||||
let _stencilMgr = StencilManager.sharedManager;
|
||||
let _color = cc.color(255, 255, 255, 0);
|
||||
@@ -149,7 +149,7 @@ let maskEndAssembler = js.addon({
|
||||
datas = mask._renderDatas;
|
||||
}
|
||||
else {
|
||||
datas = mask._graphics._renderDatas;
|
||||
datas = mask._graphics._impl._renderDatas;
|
||||
}
|
||||
let material = mask.getMaterial();
|
||||
for (let i = 0; i < datas.length; i++) {
|
||||
|
||||
+5
-4
@@ -23,10 +23,11 @@
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
const js = require('../core/platform/js');
|
||||
const assembler = require('../core/renderer/assemblers/assembler');
|
||||
const MotionStreak = require('./CCMotionStreak');
|
||||
const renderEngine = require('../core/renderer/render-engine');
|
||||
const js = require('../../platform/js');
|
||||
const assembler = require('../../renderer/assemblers/assembler');
|
||||
const renderEngine = require('../../renderer/render-engine');
|
||||
|
||||
const MotionStreak = require('../../components/CCMotionStreak');
|
||||
|
||||
function Point (point, dir) {
|
||||
this.point = point || cc.v2();
|
||||
-4
@@ -63,10 +63,6 @@ let spriteAssembler = js.addon({
|
||||
return util;
|
||||
},
|
||||
|
||||
createData (sprite) {
|
||||
return sprite._assembler.createData(sprite);
|
||||
},
|
||||
|
||||
updateRenderData (sprite) {
|
||||
let datas = sprite.__allocedDatas;
|
||||
if (!sprite.spriteFrame) {
|
||||
@@ -25,8 +25,6 @@
|
||||
|
||||
const js = require('../../platform/js');
|
||||
const renderers = require('./renderers');
|
||||
const rendererMap = renderers.map;
|
||||
const postRendererMap = renderers.postMap;
|
||||
|
||||
let RenderComponentWalker = function (device, defaultCamera) {
|
||||
this._device = device;
|
||||
@@ -50,18 +48,18 @@ RenderComponentWalker.prototype = {
|
||||
|
||||
let comp = node._renderComponent;
|
||||
let opacity = node.opacity;
|
||||
let compName = js.getClassName(comp);
|
||||
if (opacity && compName && rendererMap[compName]) {
|
||||
this._render(comp, rendererMap[compName]);
|
||||
let assembler = comp && comp.constructor._assembler;
|
||||
if (opacity && assembler) {
|
||||
this._render(comp, assembler);
|
||||
}
|
||||
},
|
||||
|
||||
_postHandleRender (node) {
|
||||
let comp = node._renderComponent;
|
||||
let opacity = node.opacity;
|
||||
let compName = js.getClassName(comp);
|
||||
if (opacity && compName && postRendererMap[compName]) {
|
||||
this._render(comp, postRendererMap[compName]);
|
||||
let postAssembler = comp && comp.constructor._postAssembler;
|
||||
if (opacity && postAssembler) {
|
||||
this._render(comp, postAssembler);
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
@@ -0,0 +1,131 @@
|
||||
|
||||
const Helper = require('../../../../graphics/helper');
|
||||
const Types = require('../../../../graphics/types');
|
||||
const PointFlags = Types.PointFlags;
|
||||
const LineJoin = Types.LineJoin;
|
||||
const LineCap = Types.LineCap;
|
||||
|
||||
class Impl {
|
||||
constructor () {
|
||||
this.cmds = [];
|
||||
|
||||
this.style = {
|
||||
strokeStyle: 'black',
|
||||
fillStyle: 'white',
|
||||
lineCap: 'butt',
|
||||
lineJoin: 'miter',
|
||||
miterLimit: 10
|
||||
};
|
||||
}
|
||||
|
||||
set strokeColor (v) {
|
||||
var strokeStyle = 'rgba(' + (0 | v.r) + ',' + (0 | v.g) + ',' + (0 | v.b) + ',' + v.a / 255 + ')';
|
||||
this.cmds.push(['strokeStyle', strokeStyle]);
|
||||
this.style.strokeStyle = strokeStyle;
|
||||
}
|
||||
|
||||
set fillColor (v) {
|
||||
var fillStyle = 'rgba(' + (0 | v.r) + ',' + (0 | v.g) + ',' + (0 | v.b) + ',' + v.a / 255 + ')';
|
||||
this.cmds.push(['fillStyle', fillStyle]);
|
||||
this.style.fillStyle = fillStyle;
|
||||
}
|
||||
|
||||
set lineWidth (v) {
|
||||
this.cmds.push(['lineWidth', v]);
|
||||
this.style.lineWidth = v;
|
||||
}
|
||||
|
||||
set lineCap (v) {
|
||||
var lineCap = 'butt';
|
||||
if (v === LineCap.BUTT) {
|
||||
lineCap = 'butt';
|
||||
}
|
||||
else if (v === LineCap.ROUND) {
|
||||
lineCap = 'round';
|
||||
}
|
||||
else if (v === LineCap.SQUARE) {
|
||||
lineCap = 'square';
|
||||
}
|
||||
this.cmds.push(['lineCap', lineCap]);
|
||||
this.style.lineCap = lineCap;
|
||||
}
|
||||
|
||||
set lineJoin (v) {
|
||||
var lineJoin = 'bevel';
|
||||
if (v === LineJoin.BEVEL) {
|
||||
lineJoin = 'bevel';
|
||||
}
|
||||
else if (v === LineJoin.ROUND) {
|
||||
lineJoin = 'round';
|
||||
}
|
||||
else if (v === LineJoin.MITER) {
|
||||
lineJoin = 'miter';
|
||||
}
|
||||
|
||||
this.cmds.push(['lineJoin', lineJoin]);
|
||||
this.style.lineJoin = lineJoin;
|
||||
}
|
||||
|
||||
set miterLimit (v) {
|
||||
this.cmds.push(['miterLimit', v]);
|
||||
this.style.miterLimit = v;
|
||||
}
|
||||
|
||||
moveTo (x, y) {
|
||||
this.cmds.push(['moveTo', [x, y]]);
|
||||
}
|
||||
|
||||
lineTo (x, y) {
|
||||
this.cmds.push(['lineTo', [x, y]]);
|
||||
}
|
||||
|
||||
bezierCurveTo (c1x, c1y, c2x, c2y, x, y) {
|
||||
this.cmds.push(['bezierCurveTo', [c1x, c1y, c2x, c2y, x, y]]);
|
||||
}
|
||||
|
||||
quadraticCurveTo (cx, cy, x, y) {
|
||||
this.cmds.push(['quadraticCurveTo', [cx, cy, x, y]]);
|
||||
}
|
||||
|
||||
arc (cx, cy, r, startAngle, endAngle, counterclockwise) {
|
||||
Helper.arc(this, cx, cy, r, startAngle, endAngle, counterclockwise);
|
||||
}
|
||||
|
||||
ellipse (cx, cy, rx, ry) {
|
||||
Helper.ellipse(this, cx, cy, rx, ry);
|
||||
}
|
||||
|
||||
circle (cx, cy, r) {
|
||||
Helper.ellipse(this, cx, cy, r, r);
|
||||
}
|
||||
|
||||
rect (x, y, w, h) {
|
||||
this.moveTo(x, y);
|
||||
this.lineTo(x, y + h);
|
||||
this.lineTo(x + w, y + h);
|
||||
this.lineTo(x + w, y);
|
||||
this.close();
|
||||
}
|
||||
|
||||
roundRect (x, y, w, h, r) {
|
||||
Helper.roundRect(this, x, y, w, h, r);
|
||||
}
|
||||
|
||||
clear (comp, clean) {
|
||||
this.cmds.length = 0;
|
||||
}
|
||||
|
||||
close () {
|
||||
this.cmds.push(['closePath', []]);
|
||||
}
|
||||
|
||||
stroke () {
|
||||
this.cmds.push(['stroke', []]);
|
||||
}
|
||||
|
||||
fill () {
|
||||
this.cmds.push(['fill', []]);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Impl;
|
||||
@@ -0,0 +1,65 @@
|
||||
const Impl = require('./impl');
|
||||
|
||||
module.exports = {
|
||||
createImpl () {
|
||||
return new Impl();
|
||||
},
|
||||
|
||||
draw (ctx, comp) {
|
||||
let node = comp.node;
|
||||
// Transform
|
||||
let matrix = node._worldMatrix;
|
||||
let a = matrix.m00, b = matrix.m01, c = matrix.m04, d = matrix.m05,
|
||||
tx = matrix.m12, ty = matrix.m13;
|
||||
ctx.transform(a, b, c, d, tx, -ty);
|
||||
|
||||
ctx.save();
|
||||
ctx.scale(1, -1);
|
||||
|
||||
// TODO: handle blend function
|
||||
|
||||
// opacity
|
||||
ctx.glphaAlpha = node.opacity / 255;
|
||||
|
||||
let style = comp._impl.style;
|
||||
ctx.strokeStyle = style.strokeStyle;
|
||||
ctx.fillStyle = style.fillStyle;
|
||||
ctx.lineWidth = style.lineWidth;
|
||||
ctx.lineJoin = style.lineJoin;
|
||||
ctx.miterLimit = style.miterLimit;
|
||||
|
||||
let endPath = true;
|
||||
let cmds = comp._impl.cmds;
|
||||
for (let i = 0, l = cmds.length; i < l; i++) {
|
||||
let cmd = cmds[i];
|
||||
let ctxCmd = cmd[0], args = cmd[1];
|
||||
|
||||
if (ctxCmd === 'moveTo' && endPath) {
|
||||
ctx.beginPath();
|
||||
endPath = false;
|
||||
}
|
||||
else if (ctxCmd === 'fill' || ctxCmd === 'stroke' || ctxCmd === 'fillRect') {
|
||||
endPath = true;
|
||||
}
|
||||
|
||||
if (typeof ctx[ctxCmd] === 'function') {
|
||||
ctx[ctxCmd].apply(ctx, args);
|
||||
}
|
||||
else {
|
||||
ctx[ctxCmd] = args;
|
||||
}
|
||||
}
|
||||
|
||||
ctx.restore();
|
||||
|
||||
return 1;
|
||||
},
|
||||
|
||||
stroke (comp) {
|
||||
comp._impl.stroke();
|
||||
},
|
||||
|
||||
fill (comp) {
|
||||
comp._impl.fill();
|
||||
}
|
||||
}
|
||||
@@ -30,13 +30,15 @@ let Label = require('../../../components/CCLabel');
|
||||
let Mask = require('../../../components/CCMask');
|
||||
let RichText = require('../../../components/CCRichText');
|
||||
// the following should be placed into their own module folder
|
||||
// let Graphics = require('../../../graphics/graphics');
|
||||
let Graphics = require('../../../graphics/graphics');
|
||||
// let ParticleSystem = require('../../../../particle/CCParticleSystem');
|
||||
// let TiledLayer = require('../../../../tilemap/CCTiledLayer');
|
||||
// let Skeleton = require('../../../../../extensions/spine/Skeleton');
|
||||
// let Armature = require('../../../../../extensions/dragonbones/ArmatureDisplay');
|
||||
|
||||
let spriteRenderer = require('./sprite/');
|
||||
let spriteRenderer = require('./sprite');
|
||||
let labelRenderer = require('./label');
|
||||
let graphicsRenderer = require('./graphics');
|
||||
|
||||
let map = {};
|
||||
let postMap = {};
|
||||
@@ -48,13 +50,14 @@ function addRenderer (Component, handler, postHandler) {
|
||||
postMap[name] = postHandler;
|
||||
}
|
||||
Component._assembler = handler;
|
||||
Component._postAssembler = handler;
|
||||
Component._postAssembler = postHandler;
|
||||
}
|
||||
|
||||
addRenderer(Sprite, spriteRenderer);
|
||||
addRenderer(Label, null);
|
||||
addRenderer(Label, labelRenderer);
|
||||
addRenderer(Mask, null);
|
||||
addRenderer(RichText, null);
|
||||
addRenderer(Graphics, graphicsRenderer);
|
||||
|
||||
module.exports = {
|
||||
map,
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
const bmfontUtils = require('../../../utils/label/bmfont')
|
||||
const js = require('../../../../platform/js');
|
||||
const utils = require('../utils');
|
||||
|
||||
module.exports = js.addon({
|
||||
createData (comp) {
|
||||
return comp.requestRenderData();
|
||||
},
|
||||
|
||||
appendQuad (renderData, texture, rect, rotated, x, y, scale) {
|
||||
let dataOffset = renderData.dataLength;
|
||||
|
||||
renderData.dataLength += 2;
|
||||
|
||||
let data = renderData._data;
|
||||
let texw = texture.width,
|
||||
texh = texture.height;
|
||||
|
||||
let rectWidth = rect.width,
|
||||
rectHeight = rect.height;
|
||||
|
||||
let l, b, r, t;
|
||||
if (!rotated) {
|
||||
l = rect.x;
|
||||
r = rect.x + rectWidth;
|
||||
b = rect.y;
|
||||
t = rect.y + rectHeight;
|
||||
|
||||
data[dataOffset].u = l;
|
||||
data[dataOffset].v = b;
|
||||
data[dataOffset+1].u = r;
|
||||
data[dataOffset+1].v = t;
|
||||
} else {
|
||||
l = rect.x;
|
||||
r = rect.x + rectHeight;
|
||||
b = rect.y;
|
||||
t = rect.y + rectWidth;
|
||||
|
||||
data[dataOffset].u = l;
|
||||
data[dataOffset].v = t;
|
||||
data[dataOffset+1].u = l;
|
||||
data[dataOffset+1].v = b;
|
||||
}
|
||||
|
||||
data[dataOffset].x = x;
|
||||
data[dataOffset].y = y - rectHeight * scale;
|
||||
data[dataOffset+1].x = x + rectWidth * scale;
|
||||
data[dataOffset+1].y = y;
|
||||
},
|
||||
|
||||
draw (ctx, comp) {
|
||||
let node = comp.node;
|
||||
// Transform
|
||||
let matrix = node._worldMatrix;
|
||||
let a = matrix.m00, b = matrix.m01, c = matrix.m04, d = matrix.m05,
|
||||
tx = matrix.m12, ty = matrix.m13;
|
||||
ctx.transform(a, b, c, d, tx, -ty);
|
||||
|
||||
// TODO: handle blend function
|
||||
|
||||
// opacity
|
||||
ctx.glphaAlpha = node.opacity / 255;
|
||||
|
||||
let tex = comp._texture,
|
||||
data = comp._renderData._data;
|
||||
|
||||
let image = utils.getColorizedImage(tex, node.color);
|
||||
|
||||
for (let i = 0, l = data.length; i < l; i+=2) {
|
||||
let x = data[i].x;
|
||||
let y = data[i].y;
|
||||
let w = data[i+1].x - x;
|
||||
let h = data[i+1].y - y;
|
||||
y = - y - h;
|
||||
|
||||
let sx = data[i].u;
|
||||
let sy = data[i].v;
|
||||
let sw = data[i+1].u - sx;
|
||||
let sh = data[i+1].v - sy;
|
||||
|
||||
ctx.drawImage(image,
|
||||
sx, sy, sw, sh,
|
||||
x, y, w, h);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
}, bmfontUtils);
|
||||
+33
-4
@@ -2,7 +2,7 @@
|
||||
Copyright (c) 2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
@@ -13,7 +13,7 @@
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
@@ -23,5 +23,34 @@
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
require('./CCMotionStreak');
|
||||
require('./motion-streak-assembler');
|
||||
const ttf = require('./ttf');
|
||||
const bmfont = require('./bmfont');
|
||||
|
||||
module.exports = {
|
||||
getAssembler (comp) {
|
||||
let assembler = ttf;
|
||||
|
||||
if (comp.font instanceof cc.BitmapFont) {
|
||||
assembler = bmfont;
|
||||
}
|
||||
|
||||
return assembler;
|
||||
},
|
||||
|
||||
createData (comp) {
|
||||
return comp._assembler.createData(comp);
|
||||
},
|
||||
|
||||
draw (ctx, comp) {
|
||||
// Check whether need to render
|
||||
if (!comp._texture) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
let assembler = comp._assembler;
|
||||
if (!assembler) return 0;
|
||||
|
||||
assembler.update(comp);
|
||||
return assembler.draw(ctx, comp);
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,61 @@
|
||||
const ttfUtils = require('../../../utils/label/ttf')
|
||||
const js = require('../../../../platform/js');
|
||||
const utils = require('../utils');
|
||||
|
||||
module.exports = js.addon({
|
||||
createData (sprite) {
|
||||
let renderData = sprite.requestRenderData();
|
||||
// 0 for bottom left, 1 for top right
|
||||
renderData.dataLength = 2;
|
||||
return renderData;
|
||||
},
|
||||
|
||||
_updateVerts (comp) {
|
||||
let renderData = comp._renderData;
|
||||
|
||||
let node = comp.node,
|
||||
width = node.width,
|
||||
height = node.height,
|
||||
appx = node.anchorX * width,
|
||||
appy = node.anchorY * height;
|
||||
|
||||
let data = renderData._data;
|
||||
data[0].x = -appx;
|
||||
data[0].y = -appy;
|
||||
data[1].x = width - appx;
|
||||
data[1].y = height - appy;
|
||||
},
|
||||
|
||||
_updateTexture (comp) {
|
||||
ttfUtils._updateTexture(comp);
|
||||
utils.dropColorizedImage(comp._texture, comp.node.color);
|
||||
},
|
||||
|
||||
draw (ctx, comp) {
|
||||
let node = comp.node;
|
||||
// Transform
|
||||
let matrix = node._worldMatrix;
|
||||
let a = matrix.m00, b = matrix.m01, c = matrix.m04, d = matrix.m05,
|
||||
tx = matrix.m12, ty = matrix.m13;
|
||||
ctx.transform(a, b, c, d, tx, -ty);
|
||||
|
||||
// TODO: handle blend function
|
||||
|
||||
// opacity
|
||||
ctx.glphaAlpha = node.opacity / 255;
|
||||
|
||||
let tex = comp._texture,
|
||||
data = comp._renderData._data;
|
||||
|
||||
let image = utils.getColorizedImage(tex, node.color);
|
||||
|
||||
let x = data[0].x;
|
||||
let y = data[0].y;
|
||||
let w = data[1].x - x;
|
||||
let h = data[1].y - y;
|
||||
y = - y - h;
|
||||
|
||||
ctx.drawImage(image, x, y, w, h);
|
||||
return 1;
|
||||
}
|
||||
}, ttfUtils);
|
||||
@@ -35,7 +35,7 @@ function colorizedFrame (canvas, texture, color, sx, sy, sw, sh) {
|
||||
|
||||
// Draw color
|
||||
ctx.globalCompositeOperation = 'source-over';
|
||||
ctx.fillStyle = 'rgba(' + color.r + ',' + color.g + ',' + color.b + ')';
|
||||
ctx.fillStyle = 'rgb(' + color.r + ',' + color.g + ',' + color.b + ')';
|
||||
ctx.fillRect(0, 0, sw, sh);
|
||||
|
||||
// Multiply color with texture
|
||||
@@ -97,12 +97,11 @@ let canvasMgr = {
|
||||
}
|
||||
},
|
||||
|
||||
// dropImage (texture, color) {
|
||||
// let key = texture.url + (color._val & 0x00ffffff);
|
||||
// if (this.canvasMap[key]) {
|
||||
// delete this.canvasMap[key];
|
||||
// }
|
||||
// }
|
||||
dropImage (key) {
|
||||
if (this.canvasMap[key]) {
|
||||
delete this.canvasMap[key];
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
@@ -156,5 +155,10 @@ module.exports = {
|
||||
canvasMgr.cacheCanvas(cache, key);
|
||||
}
|
||||
return cache;
|
||||
},
|
||||
|
||||
dropColorizedImage (texture, color) {
|
||||
let key = texture.url + (color._val & 0x00ffffff);
|
||||
canvasMgr.dropImage(key);
|
||||
}
|
||||
};
|
||||
@@ -61,6 +61,8 @@ module.exports = {
|
||||
_forward: null,
|
||||
|
||||
initWebGL (canvas, opts) {
|
||||
require('./assemblers');
|
||||
|
||||
this.Texture2D = renderEngine.Texture2D;
|
||||
|
||||
this.canvas = canvas;
|
||||
@@ -103,7 +105,9 @@ module.exports = {
|
||||
this._forward = new renderEngine.ForwardRenderer(this.device, builtins);
|
||||
},
|
||||
|
||||
initCanvas (canvas, canvasRenderer) {
|
||||
initCanvas (canvas) {
|
||||
let canvasRenderer = require('./canvas');
|
||||
|
||||
this.Texture2D = renderEngine.canvas.Texture2D;
|
||||
|
||||
this.canvas = canvas;
|
||||
|
||||
-102
@@ -31,8 +31,6 @@ const Overflow = Label.Overflow;
|
||||
|
||||
const TextUtils = require('../../../utils/text-utils').TextUtils;
|
||||
|
||||
const ttf = require('./ttf-assembler');
|
||||
|
||||
let FontLetterDefinition = function() {
|
||||
this._u = 0;
|
||||
this._v = 0;
|
||||
@@ -136,10 +134,6 @@ let _labelHeight = 0;
|
||||
let _maxLineWidth = 0;
|
||||
|
||||
module.exports = {
|
||||
createData (comp) {
|
||||
return comp.requestRenderData();
|
||||
},
|
||||
|
||||
update (comp) {
|
||||
if (!comp._renderData.vertDirty) return;
|
||||
|
||||
@@ -158,50 +152,6 @@ module.exports = {
|
||||
this._resetProperties();
|
||||
},
|
||||
|
||||
fillVertexBuffer (comp, off, vbuf, uintbuf) {
|
||||
let node = comp.node;
|
||||
let renderData = comp._renderData;
|
||||
let data = renderData._data;
|
||||
let z = node._position.z;
|
||||
let color = node.color._val;
|
||||
|
||||
node._updateWorldMatrix();
|
||||
let matrix = node._worldMatrix;
|
||||
let a = matrix.m00,
|
||||
b = matrix.m01,
|
||||
c = matrix.m04,
|
||||
d = matrix.m05,
|
||||
tx = matrix.m12,
|
||||
ty = matrix.m13;
|
||||
|
||||
let vert;
|
||||
let length = renderData.dataLength;
|
||||
for (let i = 0; i < length; i++) {
|
||||
vert = data[i];
|
||||
vbuf[off + 0] = vert.x * a + vert.y * c + tx;
|
||||
vbuf[off + 1] = vert.x * b + vert.y * d + ty;
|
||||
vbuf[off + 2] = z;
|
||||
vbuf[off + 4] = vert.u;
|
||||
vbuf[off + 5] = vert.v;
|
||||
uintbuf[off + 3] = color;
|
||||
off += 6;
|
||||
}
|
||||
},
|
||||
|
||||
fillIndexBuffer (comp, offset, vertexId, ibuf) {
|
||||
let renderData = comp._renderData;
|
||||
let length = renderData.indiceCount;
|
||||
for (let i = 0; i < length; i+=6) {
|
||||
ibuf[offset++] = vertexId;
|
||||
ibuf[offset++] = vertexId+1;
|
||||
ibuf[offset++] = vertexId+2;
|
||||
ibuf[offset++] = vertexId+1;
|
||||
ibuf[offset++] = vertexId+3;
|
||||
ibuf[offset++] = vertexId+2;
|
||||
vertexId += 4;
|
||||
}
|
||||
},
|
||||
|
||||
_updateFontScale () {
|
||||
_bmfontScale = _fontSize / _originFontSize;
|
||||
},
|
||||
@@ -724,58 +674,6 @@ module.exports = {
|
||||
},
|
||||
|
||||
appendQuad (renderData, texture, rect, rotated, x, y, scale) {
|
||||
let dataOffset = renderData.dataLength;
|
||||
|
||||
renderData.dataLength += 4;
|
||||
renderData.vertexCount = renderData.dataLength;
|
||||
renderData.indiceCount = renderData.dataLength / 2 * 3;
|
||||
|
||||
let data = renderData._data;
|
||||
let texw = texture.width,
|
||||
texh = texture.height;
|
||||
|
||||
let rectWidth = rect.width,
|
||||
rectHeight = rect.height;
|
||||
|
||||
let l, b, r, t;
|
||||
if (!rotated) {
|
||||
l = (rect.x) / texw;
|
||||
r = (rect.x + rectWidth) / texw;
|
||||
b = (rect.y + rectHeight) / texh;
|
||||
t = (rect.y) / texh;
|
||||
|
||||
data[dataOffset].u = l;
|
||||
data[dataOffset].v = b;
|
||||
data[dataOffset+1].u = r;
|
||||
data[dataOffset+1].v = b;
|
||||
data[dataOffset+2].u = l;
|
||||
data[dataOffset+2].v = t;
|
||||
data[dataOffset+3].u = r;
|
||||
data[dataOffset+3].v = t;
|
||||
} else {
|
||||
l = (rect.x) / texw;
|
||||
r = (rect.x + rectHeight) / texw;
|
||||
b = (rect.y + rectWidth) / texh;
|
||||
t = (rect.y) / texh;
|
||||
|
||||
data[dataOffset].u = l;
|
||||
data[dataOffset].v = t;
|
||||
data[dataOffset+1].u = l;
|
||||
data[dataOffset+1].v = b;
|
||||
data[dataOffset+2].u = r;
|
||||
data[dataOffset+2].v = t;
|
||||
data[dataOffset+3].u = r;
|
||||
data[dataOffset+3].v = b;
|
||||
}
|
||||
|
||||
data[dataOffset].x = x;
|
||||
data[dataOffset].y = y - rectHeight * scale;
|
||||
data[dataOffset+1].x = x + rectWidth * scale;
|
||||
data[dataOffset+1].y = y - rectHeight * scale;
|
||||
data[dataOffset+2].x = x;
|
||||
data[dataOffset+2].y = y;
|
||||
data[dataOffset+3].x = x + rectWidth * scale;
|
||||
data[dataOffset+3].y = y;
|
||||
},
|
||||
|
||||
_computeAlignmentOffset: function() {
|
||||
+8
-83
@@ -33,8 +33,6 @@ const Overflow = Label.Overflow;
|
||||
const TextUtils = utils.TextUtils;
|
||||
const CustomFontLoader = utils.CustomFontLoader;
|
||||
|
||||
const spriteAssembler = require('../sprite/simple');
|
||||
|
||||
let _comp = null;
|
||||
|
||||
let _context = null;
|
||||
@@ -72,64 +70,6 @@ let _isItalic = false;
|
||||
let _isUnderline = false;
|
||||
|
||||
module.exports = {
|
||||
createData (comp) {
|
||||
let renderData = comp.requestRenderData();
|
||||
|
||||
renderData.dataLength = 4;
|
||||
renderData.vertexCount = 4;
|
||||
renderData.indiceCount = 6;
|
||||
|
||||
let data = renderData._data;
|
||||
data[0].u = 0;
|
||||
data[0].v = 1;
|
||||
data[1].u = 1;
|
||||
data[1].v = 1;
|
||||
data[2].u = 0;
|
||||
data[2].v = 0;
|
||||
data[3].u = 1;
|
||||
data[3].v = 0;
|
||||
return renderData;
|
||||
},
|
||||
|
||||
fillVertexBuffer (comp, off, vbuf, uintbuf) {
|
||||
let node = comp.node;
|
||||
let renderData = comp._renderData;
|
||||
let data = renderData._data;
|
||||
let z = node._position.z;
|
||||
let color = cc.Color.WHITE._val;
|
||||
|
||||
node._updateWorldMatrix();
|
||||
let matrix = node._worldMatrix;
|
||||
let a = matrix.m00,
|
||||
b = matrix.m01,
|
||||
c = matrix.m04,
|
||||
d = matrix.m05,
|
||||
tx = matrix.m12,
|
||||
ty = matrix.m13;
|
||||
|
||||
let vert;
|
||||
let length = renderData.dataLength;
|
||||
for (let i = 0; i < length; i++) {
|
||||
vert = data[i];
|
||||
vbuf[off + 0] = vert.x * a + vert.y * c + tx;
|
||||
vbuf[off + 1] = vert.x * b + vert.y * d + ty;
|
||||
vbuf[off + 2] = z;
|
||||
vbuf[off + 4] = vert.u;
|
||||
vbuf[off + 5] = vert.v;
|
||||
uintbuf[off + 3] = color;
|
||||
off += 6;
|
||||
}
|
||||
},
|
||||
|
||||
fillIndexBuffer (comp, offset, vertexId, ibuf) {
|
||||
ibuf[offset + 0] = vertexId;
|
||||
ibuf[offset + 1] = vertexId + 1;
|
||||
ibuf[offset + 2] = vertexId + 2;
|
||||
ibuf[offset + 3] = vertexId + 1;
|
||||
ibuf[offset + 4] = vertexId + 3;
|
||||
ibuf[offset + 5] = vertexId + 2;
|
||||
},
|
||||
|
||||
update (comp) {
|
||||
if (!comp._renderData.vertDirty) return;
|
||||
|
||||
@@ -141,13 +81,13 @@ module.exports = {
|
||||
this._calculateSplitedStrings();
|
||||
this._updateLabelDimensions();
|
||||
this._calculateTextBaseline();
|
||||
this._updateTexture();
|
||||
|
||||
this._updateVerts();
|
||||
|
||||
this._updateTexture(_comp);
|
||||
|
||||
_comp._actualFontSize = _fontSize;
|
||||
_comp.node.setContentSize(_canvasSize);
|
||||
|
||||
this._updateVerts(_comp);
|
||||
|
||||
_comp._renderData.vertDirty = _comp._renderData.uvDirty = false;
|
||||
|
||||
_context = null;
|
||||
@@ -159,22 +99,6 @@ module.exports = {
|
||||
},
|
||||
|
||||
_updateVerts () {
|
||||
let renderData = _comp._renderData;
|
||||
|
||||
let width = _canvasSize.width,
|
||||
height = _canvasSize.height,
|
||||
appx = renderData._pivotX * width,
|
||||
appy = renderData._pivotY * height;
|
||||
|
||||
let data = renderData._data;
|
||||
data[0].x = -appx;
|
||||
data[0].y = -appy;
|
||||
data[1].x = width - appx;
|
||||
data[1].y = -appy;
|
||||
data[2].x = -appx;
|
||||
data[2].y = height - appy;
|
||||
data[3].x = width - appx;
|
||||
data[3].y = height - appy;
|
||||
},
|
||||
|
||||
_updateFontFamly () {
|
||||
@@ -197,8 +121,9 @@ module.exports = {
|
||||
},
|
||||
|
||||
_updateProperties () {
|
||||
_context = _comp._context;
|
||||
_canvas = _comp._canvas;
|
||||
let assemblerData = _comp._assemblerData;
|
||||
_context = assemblerData._context;
|
||||
_canvas = assemblerData._canvas;
|
||||
_texture = _comp._texture;
|
||||
|
||||
_string = _comp.string.toString();
|
||||
@@ -267,7 +192,7 @@ module.exports = {
|
||||
return cc.v2(labelX, firstLinelabelY);
|
||||
},
|
||||
|
||||
_updateTexture () {
|
||||
_updateTexture (comp) {
|
||||
_context.clearRect(0, 0, _canvas.width, _canvas.height);
|
||||
_context.font = _fontDesc;
|
||||
|
||||
@@ -36,7 +36,6 @@ else {
|
||||
require('./cocos2d/tilemap');
|
||||
require('./cocos2d/videoplayer/CCVideoPlayer');
|
||||
require('./cocos2d/webview/CCWebView');
|
||||
require('./cocos2d/motion-streak');
|
||||
require('./cocos2d/core/components/CCStudioComponent');
|
||||
require('./extensions/ccpool/CCNodePool');
|
||||
require('./cocos2d/actions');
|
||||
|
||||
+2
-1
@@ -172,7 +172,8 @@
|
||||
{
|
||||
"name": "MotionStreak",
|
||||
"entries": [
|
||||
"./cocos2d/motion-streak/index.js"
|
||||
"./cocos2d/core/components/motion-streak/CCMotionStreak.js",
|
||||
"./cocos2d/core/renderer/assemblers/motion-streak.js"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user