Commit 81c8fc27 authored by rockyl's avatar rockyl

代码格式化

parent a3ab12b1
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<meta name="viewport"
content="width=device-width,initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=no"/>
<meta name="apple-mobile-web-app-capable" content="yes"/>
<meta name="full-screen" content="true"/>
<meta name="screen-orientation" content="portrait"/>
<meta name="x5-fullscreen" content="true"/>
<meta name="360-fullscreen" content="true"/>
<!-- <meta name="viewport" content="width=device-width,minimum-scale=1.0,user-scalable=no"> -->
<style>
html,
body {
padding: 0;
margin: 0;
border: 0;
width: 100%;
height: 100%;
overflow: hidden;
position: absolute;
background-color: white;
}
</style>
</head>
<body>
<script type="text/javascript" src="../build/render.min.js"></script>
<div id="cusEngine" style="line-height:0;font-size:0"></div>
<script src="game-stage.js"></script>
</body>
</html>
\ No newline at end of file
/**
* Created by rockyl on 2019-11-06.
*/
let stage = new render.Stage(
"cusEngine",
750,
1334,
60,
render.StageScaleMode.FIXED_WIDTH,
render.RENDERER_TYPE.WEBGL
);
//启动循环
render.Stage.flushAll();
let node = new render.Node();
node.width = 400;
console.log(node.width);
/*let gameStage = new render.GameStage(stage);
stage.addChild(gameStage);
let sceneEntry = new render.Container();
let bg = new render.Shape();
bg.beginFill(0xFF8888);
bg.drawRect(0, 0, 300, 300);
bg.endFill();
sceneEntry.addChild(bg);
gameStage.sceneContainer.push(sceneEntry);*/
/*let dialog = new render.Container();
let dbg = new render.Shape();
dbg.beginFill(0x8888ff);
dbg.drawRect(0, 0, 100, 100);
dbg.endFill();
dialog.addChild(dbg);
gameStage.popupContainer.push(dialog);*/
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Examples</title>
</head>
<body>
</body>
</html>
\ No newline at end of file
......@@ -2,8 +2,8 @@
* Created by rockyl on 2018/11/5.
*/
import { HashObject } from "../HashObject";
import { DisplayObject } from "../display/DisplayObject";
import {HashObject} from "../HashObject";
import {DisplayObject} from "../display/DisplayObject";
/**
* 组件基类
......
//这里都是一些常量
/**
* 版本号
......@@ -72,6 +71,7 @@ console.log(devicePixelRatio, osType)
let PI: number = Math.PI;
let HalfPI: number = PI >> 1;
let PacPI: number = PI + HalfPI;
/**
* @method cos
* @private
......@@ -114,6 +114,7 @@ export function sin(angle: number): number {
return Math.sin(angle);
}
}
/**
* Two Pi.
*
......
import { DisplayObject } from './DisplayObject';
import { Rectangle } from "../math/Rectangle";
import { Point } from '../math';
import {DisplayObject} from './DisplayObject';
import {Rectangle} from "../math/Rectangle";
import {Point} from '../math';
import CanvasRenderer from '../renderers/CanvasRenderer';
import { Event } from "../events/Event"
import { WebglRenderer } from '../renderers/WebglRenderer';
import {Event} from "../events/Event"
import {WebglRenderer} from '../renderers/WebglRenderer';
/**
* 容器类
* @class
......@@ -33,6 +33,11 @@ export default class Container extends DisplayObject {
super();
this._instanceType = "Container";
this.children = [];
this.afterConstructor();
}
afterConstructor() {
}
/**
......@@ -284,8 +289,7 @@ export default class Container extends DisplayObject {
}
return removed;
}
else if (range === 0 && this.children.length === 0) {
} else if (range === 0 && this.children.length === 0) {
return [];
}
......@@ -341,8 +345,7 @@ export default class Container extends DisplayObject {
child._bounds.height = child._mask._bounds.height;
}
Rectangle.createFromRects(this._bounds, child._bounds);
}
else {
} else {
Rectangle.createFromRects(this._bounds, child._bounds);
}
}
......@@ -394,8 +397,7 @@ export default class Container extends DisplayObject {
//是否有遮罩。到时如果有滤镜,
if (this.mask) {
this.renderAdvancedWebGL(renderer);
}
else {
} else {
//自身先渲染
this._renderWebGL(renderer);
//遍历children
......@@ -544,8 +546,7 @@ export default class Container extends DisplayObject {
if (width !== 0) {
this.scale.x = value / width;
}
else {
} else {
this.scale.x = 1;
}
//子类有用,有_width,才需设置scaleX
......@@ -565,8 +566,7 @@ export default class Container extends DisplayObject {
if (height !== 0) {
this.scale.y = value / height;
}
else {
} else {
this.scale.y = 1;
}
......
import { EventDispatcher } from '../events/EventDispatcher';
import {EventDispatcher} from '../events/EventDispatcher';
import Transform from '../math/Transform';
import { Rectangle } from '../math/Rectangle';
import { Point } from "../math/Point";
import { Event } from "../events/Event";
import { Component } from '../component/Component';
import {Rectangle} from '../math/Rectangle';
import {Point} from "../math/Point";
import {Event} from "../events/Event";
import {Component} from '../component/Component';
import Graphics from '../graphics/Graphics';
import { RAD_TO_DEG, DEG_TO_RAD } from '../const';
import {DEG_TO_RAD, RAD_TO_DEG} from '../const';
/**
* 基础显示对象抽象类
* @class
......
import { Event } from "../events/Event";
import { DisplayObject } from "./DisplayObject";
import { devicePixelRatio } from "../const";
import {Event} from "../events/Event";
import {DisplayObject} from "./DisplayObject";
import {devicePixelRatio} from "../const";
/**
* 此类对于需要在canvas上放置html其他类型元素的时候非常有用<br/>
* 比如有时候我们需要放置一个注册,登录或者其他的内容.这些内容包含了输入框<br/>
......@@ -35,6 +36,7 @@ export class FloatDisplay extends DisplayObject {
* 记录是否需要修改位置矩阵
*/
private _transformID: number;
/**
* 构造函数
* @method FloatDisplay
......@@ -153,6 +155,7 @@ export class FloatDisplay extends DisplayObject {
}
return null;
}
/**
* @method updateStyle
* @public
......@@ -194,6 +197,7 @@ export class FloatDisplay extends DisplayObject {
}
}
}
public destroy(): void {
//清除相应的数据引用
let s = this;
......
import { Point, ObservablePoint, Rectangle } from '../math';
import { sign, TextureCache, hex2rgb } from '../utils';
import {ObservablePoint, Point, Rectangle} from '../math';
import {sign, TextureCache} from '../utils';
// import { BLEND_MODES } from '../const';
import Texture from '../texture/Texture';
import Container from './Container';
import { DisplayObject } from "./DisplayObject";
import {DisplayObject} from "./DisplayObject";
import CanvasRenderer from '../renderers/CanvasRenderer';
import { SCALE_MODES } from '../const';
import { WebglRenderer } from '../renderers/WebglRenderer';
import {SCALE_MODES} from '../const';
import {WebglRenderer} from '../renderers/WebglRenderer';
const indices = new Uint16Array([0, 1, 2, 0, 2, 3]);
/**
......@@ -193,8 +193,7 @@ export default class Sprite extends Container {
h1 = trim.y - (anchor._y * orig.height);
h0 = h1 + trim.height;
}
else {
} else {
w1 = -anchor._x * orig.width;
w0 = w1 + orig.width;
......@@ -226,8 +225,7 @@ export default class Sprite extends Container {
calculateTrimmedVertices() {
if (!this.vertexTrimmedData) {
this.vertexTrimmedData = new Float32Array(8);
}
else if (this._transformTrimmedID === this.transform._worldID && this._textureTrimmedID === this._texture._updateID) {
} else if (this._transformTrimmedID === this.transform._worldID && this._textureTrimmedID === this._texture._updateID) {
return;
}
......@@ -304,8 +302,7 @@ export default class Sprite extends Container {
if (!trim || (trim.width === orig.width && trim.height === orig.height)) {
this.calculateVertices();
Rectangle.createFromVertexData(this._bounds, this.vertexData);
}
else {
} else {
//计算trimmed bounds...
this.calculateTrimmedVertices();
Rectangle.createFromVertexData(this._bounds, this.vertexTrimmedData);
......@@ -354,7 +351,6 @@ export default class Sprite extends Container {
}
/**
* 销毁
*/
......@@ -434,8 +430,7 @@ export default class Sprite extends Container {
if (value) {
if (value.baseTexture.hasLoaded) {
this._onTextureUpdate();
}
else {
} else {
value.once('update', this._onTextureUpdate);
}
}
......
import Container from "./Container";
import { osType, devicePixelRatio, RENDERER_TYPE, StageScaleMode } from "../const"
import {devicePixelRatio, osType, RENDERER_TYPE, StageScaleMode} from "../const"
import SystemRenderer from "../renderers/SystemRenderer";
import { Rectangle, Point } from "../math";
import { EventDispatcher } from "../events/EventDispatcher";
import { Event } from "../events/Event";
import { FloatDisplay } from "./FloatDisplay";
import { DisplayObject } from "./DisplayObject";
import { MouseEvent } from "../events/MouseEvent";
import { WebglRenderer } from "../renderers/WebglRenderer";
import { GDispatcher } from "../events/GDispatcher";
import {Point, Rectangle} from "../math";
import {EventDispatcher} from "../events/EventDispatcher";
import {Event} from "../events/Event";
import {FloatDisplay} from "./FloatDisplay";
import {DisplayObject} from "./DisplayObject";
import {MouseEvent} from "../events/MouseEvent";
import {WebglRenderer} from "../renderers/WebglRenderer";
import {GDispatcher} from "../events/GDispatcher";
import CanvasRenderer from "../renderers/CanvasRenderer";
import { isWebGLSupported, GlobalPro } from "../utils";
import {GlobalPro, isWebGLSupported} from "../utils";
//如果以后还出现帧率问题,使用ticker;
//兼容requestAnimationFrame
......@@ -113,6 +113,7 @@ export class Stage extends Container {
* @private
*/
private static _stageList: any = {};
/**
* 是否暂停
* @property pause
......@@ -125,11 +126,12 @@ export class Stage extends Container {
static get pause(): boolean {
return this._pause;
}
static set pause(value: boolean) {
this._pause = value;
if (value != this._pause) {
//触发事件
GDispatcher.dispatchEvent("onStagePause", { pause: value });
GDispatcher.dispatchEvent("onStagePause", {pause: value});
}
}
......@@ -226,6 +228,7 @@ export class Stage extends Container {
public get bgColor(): number {
return this._bgColor;
}
/**
* 设置颜色,即改变渲染器颜色
*/
......@@ -274,6 +277,7 @@ export class Stage extends Container {
s.setAlign();
}
}
private _scaleMode: string = "onScale";
/**
......@@ -570,7 +574,7 @@ export class Stage extends Container {
vH *= ih / 100;
}
}
return { w: vW, h: vH };
return {w: vW, h: vH};
}
/**
......@@ -900,6 +904,7 @@ export class Stage extends Container {
s.rotation = 0;
}
};
/**
* 当舞台尺寸发生改变时,如果stage autoResize 为 true,则此方法会自己调用;
* 如果设置stage autoResize 为 false 你需要手动调用此方法以更新界面.
......
export { default as Container } from './Container';
export { DisplayObject } from './DisplayObject';
export { FloatDisplay } from "./FloatDisplay";
export { default as Sprite } from "./Sprite";
export { Stage } from "./Stage";
\ No newline at end of file
export {default as Container} from './Container';
export {DisplayObject} from './DisplayObject';
export {FloatDisplay} from "./FloatDisplay";
export {default as Sprite} from "./Sprite";
export {Stage} from "./Stage";
\ No newline at end of file
import { HashObject } from "../HashObject";
import {HashObject} from "../HashObject";
/**
* 事件类,引擎中一切事件的基类
* @class Event
......@@ -218,6 +219,7 @@ export class Event extends HashObject {
this._instanceType = "Event";
this.type = type;
}
/**
* 防止对事件流中当前节点中和所有后续节点中的事件侦听器进行处理。
* @method stopImmediatePropagation
......@@ -239,6 +241,7 @@ export class Event extends HashObject {
public stopPropagation(): void {
this._bpd = true;
}
private _bpd: boolean = false;
/**
* 是否阻止事件向下冒泡
......
import {HashObject} from "../HashObject";
import {Event} from "./Event";
import { HashObject } from "../HashObject";
import { Event } from "./Event";
/**
* 事件触发基类 功能简单,如果需全能的,到时用EventEmitter3,现成库,事件名,事件,once否集合成实例
* @class EventDispatcher
......@@ -319,6 +319,7 @@ class EE {
fn: Function;
context: any;
once: boolean;
constructor(fn: Function, context: any, once: boolean = false) {
this.fn = fn;
this.context = context;
......
import { Event } from "./Event";
import { DisplayObject } from "../display/DisplayObject";
import {Event} from "./Event";
import {DisplayObject} from "../display/DisplayObject";
/**
* 鼠标事件类,电脑端鼠标,移动设备端的触摸都使用此事件来监听
* @class MouseEvent
......@@ -127,6 +128,7 @@ export class MouseEvent extends Event {
* @public
*/
public identifier: any = 0;
/**
* @method MouseEvent
* @public
......@@ -137,6 +139,7 @@ export class MouseEvent extends Event {
super(type);
this._instanceType = "MouseEvent";
}
/**
* 事件后立即更新显示列表状态
* @method updateAfterEvent
......@@ -146,6 +149,7 @@ export class MouseEvent extends Event {
public updateAfterEvent() {
this.target.stage._cp = true;
}
public destroy(): void {
//清除相应的数据引用
let s = this;
......
/**
* Created by rockyl on 2019-11-06.
*/
export * from './Event';
export * from './EventDispatcher';
export * from './GDispatcher';
export * from './MouseEvent';
import GraphicsData from './GraphicsData';
import RenderTexture from "../texture/RenderTexture";
import { Matrix, Point, Rectangle } from '../math';
import { RoundedRectangle, Ellipse, Polygon, Circle } from "./shapes"
import { sign, string2hex, hex2rgb } from '../utils';
import { SHAPES, PI_2, SCALE_MODES, WRAP_MODES } from '../const';
import { DisplayObject } from '../display/DisplayObject';
import {Matrix, Point, Rectangle} from '../math';
import {Circle, Ellipse, Polygon, RoundedRectangle} from "./shapes"
import {hex2rgb, sign, string2hex} from '../utils';
import {PI_2, SCALE_MODES, SHAPES, WRAP_MODES} from '../const';
import {DisplayObject} from '../display/DisplayObject';
import Texture from '../texture/Texture';
import CanvasRenderer from '../renderers/CanvasRenderer';
import { Event } from "../events/Event"
import { WebglRenderer } from '../renderers/WebglRenderer';
import {WebglRenderer} from '../renderers/WebglRenderer';
import buildPoly from './geomBuild/buildPoly';
import buildCircle from './geomBuild/buildCircle';
import buildRectangle from './geomBuild/buildRectangle';
......@@ -18,8 +15,9 @@ import buildRoundedRectangle from './geomBuild/buildRoundedRectangle';
import buildLine from './geomBuild/buildLine';
import FillStyle from './styles/FillStyle';
import LineStyle from './styles/LineStyle';
import { GRAPHICS_CURVES, quadraticCurveLength, bezierCurveLength, bezierCurveTo } from './utils';
import {bezierCurveLength, bezierCurveTo, GRAPHICS_CURVES, quadraticCurveLength} from './utils';
import Container from '../display/Container';
let canvasRenderer: CanvasRenderer;
const tempMatrix = new Matrix();
const tempPoint = new Point();
......@@ -56,6 +54,7 @@ export default class Graphics extends Container {
* @member {LineStyle}
*/
private _lineStyle: LineStyle;
/**
* @member {FillStyle}
* @readonly
......@@ -71,6 +70,7 @@ export default class Graphics extends Container {
get line() {
return this._lineStyle;
}
/**
* 图形默认色调
* 默认白色,不会有任何影响
......@@ -81,9 +81,11 @@ export default class Graphics extends Container {
get tint() {
return this._tint;
}
set tint(value) {
this._tint = value;
}
/**
* 判断是否更新色值
*/
......@@ -98,6 +100,7 @@ export default class Graphics extends Container {
get matrix() {
return this._matrix;
}
set matrix(matrix: Matrix) {
//暂时不用
// this._matrix = matrix;
......@@ -181,6 +184,7 @@ export default class Graphics extends Container {
private vertexData;
private shapeIndex;//为了在不clear情况下继续画,不用重复计算前面的batch
private _transformID;
constructor() {
super();
this._instanceType = "Graphics"
......@@ -263,6 +267,7 @@ export default class Graphics extends Container {
return this;
}
lineTextureStyle(
width = 0,
texture = Texture.WHITE,
......@@ -278,8 +283,7 @@ export default class Graphics extends Container {
if (!visible) {
this._lineStyle.reset();
}
else {
} else {
if (matrix) {
matrix = matrix.clone();
matrix.invert();
......@@ -305,6 +309,7 @@ export default class Graphics extends Container {
}
return this;
}
private startPoly() {
if (this._currentPath) {
const points = this._currentPath.points;
......@@ -315,19 +320,18 @@ export default class Graphics extends Container {
this._currentPath.closed = false;
this._currentPath.points.push(points[len - 2], points[len - 1]);
}
}
else {
} else {
this._currentPath = new Polygon();
this._currentPath.closed = false;
}
}
private finishPoly() {
if (this._currentPath) {
if (this._currentPath.points.length > 2) {
this.drawShape(this._currentPath);
this._currentPath = null;
}
else {
} else {
this._currentPath.points.length = 0;
}
}
......@@ -354,6 +358,7 @@ export default class Graphics extends Container {
}
return this;
}
/**
* 初始化曲线
* @param x
......@@ -364,8 +369,7 @@ export default class Graphics extends Container {
if (this._currentPath.points.length === 0) {
this._currentPath.points = [x, y];
}
}
else {
} else {
this.moveTo(x, y);
}
}
......@@ -466,8 +470,7 @@ export default class Graphics extends Container {
if (points[points.length - 2] !== x1 || points[points.length - 1] !== y1) {
points.push(x1, y1);
}
}
else {
} else {
const dd = (a1 * a1) + (b1 * b1);
const cc = (a2 * a2) + (b2 * b2);
const tt = (a1 * a2) + (b1 * b2);
......@@ -510,8 +513,7 @@ export default class Graphics extends Container {
if (!anticlockwise && endAngle <= startAngle) {
endAngle += PI_2;
}
else if (anticlockwise && startAngle <= endAngle) {
} else if (anticlockwise && startAngle <= endAngle) {
startAngle += PI_2;
}
......@@ -535,12 +537,10 @@ export default class Graphics extends Container {
if (xDiff < 0.001 && yDiff < 0.001) {
// If the point is very close, we don't add it, since this would lead to artifacts
// during tesselation due to floating point imprecision.
}
else {
} else {
points.push(startX, startY);
}
}
else {
} else {
this.moveTo(startX, startY);
points = this._currentPath.points;
}
......@@ -601,8 +601,7 @@ export default class Graphics extends Container {
this._fillStyle.reset();
//需要额外加参数
this._fillStyle.alphaBlock = true;
}
else {
} else {
if (matrix) {
//暂时不用
// matrix = matrix.clone();
......@@ -646,6 +645,7 @@ export default class Graphics extends Container {
if (this._currentPath) _currentPath.close();
return this;
}
/**
* 开始画洞
*/
......@@ -654,6 +654,7 @@ export default class Graphics extends Container {
this._holeMode = true;
return this;
}
/**
* 结束画洞
*/
......@@ -801,8 +802,7 @@ export default class Graphics extends Container {
);
this.graphicsData.push(data);
this.dirty++;
}
else {
} else {
if (!this.graphicsData.length) return this;
const data = new GraphicsData(shape, null, null, this._matrix);
const lastShape = this.graphicsData[this.graphicsData.length - 1];
......@@ -950,8 +950,7 @@ export default class Graphics extends Container {
if (data.holes.length) {
this.proccessHoles(data.holes);
buildPoly.triangulate(data, this);
}
else {
} else {
command.triangulate(data, this);
}
} else {
......@@ -1036,6 +1035,7 @@ export default class Graphics extends Container {
}
}
}
/**
* If there's a transform update or a change to the shape of the
* geometry, recaculate the vertices.
......@@ -1214,8 +1214,7 @@ export default class Graphics extends Container {
lineWidth = lineStyle.width;
if (type === SHAPES.POLY) {
lineWidth = lineWidth * (0.5 + Math.abs(0.5 - alignment));
}
else {
} else {
lineWidth = lineWidth * Math.max(0, alignment);
}
}
......@@ -1233,8 +1232,7 @@ export default class Graphics extends Container {
minY = y < minY ? y : minY;
maxY = y + h > maxY ? y + h : maxY;
}
else if (type === SHAPES.CIRC) {
} else if (type === SHAPES.CIRC) {
x = shape.x;
y = shape.y;
w = shape.radius + (lineWidth / 2);
......@@ -1245,8 +1243,7 @@ export default class Graphics extends Container {
minY = y - h < minY ? y - h : minY;
maxY = y + h > maxY ? y + h : maxY;
}
else if (type === SHAPES.ELIP) {
} else if (type === SHAPES.ELIP) {
x = shape.x;
y = shape.y;
w = shape.width + (lineWidth / 2);
......@@ -1257,8 +1254,7 @@ export default class Graphics extends Container {
minY = y - h < minY ? y - h : minY;
maxY = y + h > maxY ? y + h : maxY;
}
else {
} else {
// POLY
const points = shape.points;
let x2 = 0;
......@@ -1297,8 +1293,7 @@ export default class Graphics extends Container {
}
}
}
}
else {
} else {
minX = 0;
maxX = 0;
minY = 0;
......@@ -1429,6 +1424,7 @@ export default class Graphics extends Container {
}
}
/**
* Generates the UVs for a shape.
* 不支持纹理填充,所以uv都时0
......@@ -1466,6 +1462,7 @@ export default class Graphics extends Container {
this.adjustUvs(uvs, texture, uvsStart, size);
}
}
/**
* Modify uvs array according to position of texture region
* Does not work with rotated or trimmed textures
......@@ -1500,9 +1497,6 @@ export default class Graphics extends Container {
}
/**
* A little internal structure to hold interim batch objects.
*
......@@ -1514,6 +1508,7 @@ class geoBatchPart {
start: number;
attribStart: number;
attribSize: number;
constructor() {
this.style = null
this.size = 0;
......
import Circle from "./shapes/Circle";
import { Rectangle, Matrix } from "../math";
import {Matrix, Rectangle} from "../math";
import Ellipse from "./shapes/Ellipse";
import Polygon from "./shapes/Polygon";
import RoundedRectangle from "./shapes/RoundedRectangle";
import { HashObject } from "../HashObject";
import {HashObject} from "../HashObject";
import LineStyle from "./styles/LineStyle";
import FillStyle from "./styles/FillStyle";
......@@ -32,6 +32,7 @@ export default class GraphicsData extends HashObject {
* 存下shape的点数据,因为如果shape不是poly不会特意存下points
*/
points: number[]
/**
*
*/
......
import Texture from "../texture/Texture";
import { SCALE_MODES, LINE_CAP, LINE_JOIN } from "../const";
import { Rectangle, Point } from "../math";
import { DisplayObject } from "../display/DisplayObject";
import { hex2string, getRGBA, getGradientColor, backupCanvas, getCanvasBitmapStyle } from "../utils";
import {LINE_CAP, LINE_JOIN, SCALE_MODES} from "../const";
import {Point, Rectangle} from "../math";
import {DisplayObject} from "../display/DisplayObject";
import {backupCanvas, getCanvasBitmapStyle, getGradientColor, getRGBA, hex2string} from "../utils";
import Sprite from "../display/Sprite";
/**
......@@ -24,6 +24,7 @@ export class Shape extends Sprite {
dirty: boolean;
offsetX: number;
offsetY: number;
constructor() {
super();
this._instanceType = "ShapeNode";
......@@ -446,6 +447,7 @@ export class Shape extends Sprite {
) {
this._stroke(getGradientColor(points, colors), lineWidth, cap, join, miter);
};
/**
* 线条位图填充 一般给Flash2x用
* @method beginBitmapStroke
......@@ -512,6 +514,7 @@ export class Shape extends Sprite {
s._isBitmapFill = null;
}
}
// protected isUsedToMask: boolean = false;
/**
* 结束画线
......@@ -670,14 +673,14 @@ export class Shape extends Sprite {
ctx.setTransform(1, 0, 0, 1, -leftX, -leftY);
s._drawShape(ctx);
//贴图锚点修改
this.anchorTexture = { x: -leftX / w, y: -leftY / h };
this.anchorTexture = {x: -leftX / w, y: -leftY / h};
} else {
s.canvas.width = 0;
s.canvas.height = 0;
s.offsetX = 0;
s.offsetY = 0;
s._localBoundsSelf.clear();
this.anchorTexture = { x: 0, y: 0 };
this.anchorTexture = {x: 0, y: 0};
}
//更新贴图
this.updateTexture();
......@@ -827,6 +830,7 @@ export class Shape extends Sprite {
this.updateShape();
super._renderCanvas(renderer);
}
_renderWebGL(renderer) {
this.updateShape();
super._renderWebGL(renderer)
......
import { SHAPES } from "../../const";
import {SHAPES} from "../../const";
import GraphicsData from "../GraphicsData";
import Graphics from "../Graphics";
/**
* Builds a circle to draw
*
......@@ -32,8 +31,7 @@ export default {
if (graphicsData.type === SHAPES.CIRC) {
width = circleData.radius;
height = circleData.radius;
}
else {
} else {
width = circleData.width;
height = circleData.height;
}
......@@ -62,7 +60,7 @@ export default {
);
},
triangulate(graphicsData, graphicsGeometry:Graphics) {
triangulate(graphicsData, graphicsGeometry: Graphics) {
const points = graphicsData.points;
const verts = graphicsGeometry.verts;
const indices = graphicsGeometry.indices;
......
import GraphicsData from "../GraphicsData";
import Graphics from "../Graphics";
import { Point } from "../../math";
import { SHAPES } from "../../const";
import {Point} from "../../math";
import {SHAPES} from "../../const";
/**
......@@ -36,7 +36,7 @@ export default function (graphicsData: GraphicsData, graphicsGeometry: Graphics)
* @param {GraphicsData} graphicsData - The graphics object containing all the necessary properties
* @param {GraphicsGeometry} graphicsGeometry - Geometry where to append output
*/
function buildLine(graphicsData:GraphicsData, graphicsGeometry:Graphics) {
function buildLine(graphicsData: GraphicsData, graphicsGeometry: Graphics) {
const shape = graphicsData.shape;
let points = graphicsData.points || shape.points.slice();
......@@ -193,8 +193,7 @@ function buildLine(graphicsData:GraphicsData, graphicsGeometry:Graphics) {
verts.push(p2x - (perp3x * r2 * r1), p2y - (perp3y * r1));
indexCount++;
}
else {
} else {
verts.push(p2x + ((px - p2x) * r1), p2y + ((py - p2y) * r1));
verts.push(p2x - ((px - p2x) * r2), p2y - ((py - p2y) * r2));
......
import { earcut } from "./earcut";
import {earcut} from "./earcut";
import Graphics from "../Graphics";
import GraphicsData from "../GraphicsData";
......@@ -19,7 +19,7 @@ export default {
graphicsData.points = graphicsData.shape.points.slice();
},
triangulate(graphicsData:GraphicsData, graphicsGeometry:Graphics) {
triangulate(graphicsData: GraphicsData, graphicsGeometry: Graphics) {
let points = graphicsData.points;
const holes = graphicsData.holes;
const verts = graphicsGeometry.verts;
......
import { earcut } from "./earcut"
import GraphicsData from "../GraphicsData";
import Graphics from "../Graphics";
......@@ -16,7 +15,7 @@ import Graphics from "../Graphics";
export default {
//计算点points
build(graphicsData:GraphicsData) {
build(graphicsData: GraphicsData) {
// --- //
// need to convert points to a nice regular data
//
......@@ -37,7 +36,7 @@ export default {
},
//计算顶点和索引
triangulate(graphicsData:GraphicsData, graphics: Graphics) {
triangulate(graphicsData: GraphicsData, graphics: Graphics) {
const points = graphicsData.points;
//graphics之前可能已经有点
......
import { earcut } from "./earcut"
import {earcut} from "./earcut"
import GraphicsData from "../GraphicsData";
import Graphics from "../Graphics";
......@@ -15,8 +15,7 @@ import Graphics from "../Graphics";
*/
export default {
build(graphicsData:GraphicsData)
{
build(graphicsData: GraphicsData) {
const rrectData = graphicsData.shape;
const points = graphicsData.points;
const x = rrectData.x;
......@@ -38,8 +37,7 @@ export default {
// TODO - fix this properly, this is not very elegant.. but it works for now.
},
triangulate(graphicsData:GraphicsData, graphicsGeometry:Graphics)
{
triangulate(graphicsData: GraphicsData, graphicsGeometry: Graphics) {
const points = graphicsData.points;
const verts = graphicsGeometry.verts;
......@@ -49,8 +47,7 @@ export default {
const triangles = earcut(points, null, 2);
for (let i = 0, j = triangles.length; i < j; i += 3)
{
for (let i = 0, j = triangles.length; i < j; i += 3) {
indices.push(triangles[i] + vecPos);
// indices.push(triangles[i] + vecPos);
indices.push(triangles[i + 1] + vecPos);
......@@ -58,8 +55,7 @@ export default {
indices.push(triangles[i + 2] + vecPos);
}
for (let i = 0, j = points.length; i < j; i++)
{
for (let i = 0, j = points.length; i < j; i++) {
verts.push(points[i], points[++i]);
}
},
......@@ -78,8 +74,7 @@ export default {
* @return {number} the result
*
*/
function getPt(n1, n2, perc)
{
function getPt(n1, n2, perc) {
const diff = n2 - n1;
return n1 + (diff * perc);
......@@ -102,8 +97,7 @@ function getPt(n1, n2, perc)
* @param {number[]} [out=[]] - The output array to add points into. If not passed, a new array is created.
* @return {number[]} an array of points
*/
function quadraticBezierCurve(fromX, fromY, cpX, cpY, toX, toY, out = [])
{
function quadraticBezierCurve(fromX, fromY, cpX, cpY, toX, toY, out = []) {
const n = 20;
const points = out;
......@@ -114,8 +108,7 @@ function quadraticBezierCurve(fromX, fromY, cpX, cpY, toX, toY, out = [])
let x = 0;
let y = 0;
for (let i = 0, j = 0; i <= n; ++i)
{
for (let i = 0, j = 0; i <= n; ++i) {
j = i / n;
// The Green Line
......
export function earcut(data, holeIndices, dim) {
dim = dim || 2;
......
import { Rectangle, Point } from '../../math';
import { SHAPES } from '../../const';
import {Point, Rectangle} from '../../math';
import {SHAPES} from '../../const';
/**
* 圆形
......@@ -28,6 +28,7 @@ export default class Circle {
* @see SHAPES
*/
type: number;
/**
* @param {number} [x=0] - The X coordinate of the center of this circle
* @param {number} [y=0] - The Y coordinate of the center of this circle
......@@ -45,7 +46,7 @@ export default class Circle {
*
* @return {Circle} a copy of the Circle
*/
clone():Circle {
clone(): Circle {
return new Circle(this.x, this.y, this.radius);
}
......@@ -53,7 +54,7 @@ export default class Circle {
* @param {Point} point - The point to test
* @return {boolean} Whether the x/y coordinates are within this Circle
*/
isPointIn(point:Point):boolean {
isPointIn(point: Point): boolean {
if (this.radius <= 0) {
return false;
}
......@@ -72,7 +73,7 @@ export default class Circle {
*
* @return {Rectangle} the framing rectangle
*/
getBounds():Rectangle {
getBounds(): Rectangle {
return new Rectangle(this.x - this.radius, this.y - this.radius, this.radius * 2, this.radius * 2);
}
}
import { Rectangle, Point } from '../../math';
import { SHAPES } from '../../const';
import {Point, Rectangle} from '../../math';
import {SHAPES} from '../../const';
/**
* The Ellipse object can be used to specify a hit area for displayObjects
......@@ -35,6 +35,7 @@ export default class Ellipse {
* @see SHAPES
*/
type: number;
/**
* @param {number} [x=0] - The X coordinate of the center of this circle
* @param {number} [y=0] - The Y coordinate of the center of this circle
......@@ -54,7 +55,7 @@ export default class Ellipse {
*
* @return {Ellipse} a copy of the ellipse
*/
clone():Ellipse {
clone(): Ellipse {
return new Ellipse(this.x, this.y, this.width, this.height);
}
......@@ -64,7 +65,7 @@ export default class Ellipse {
* @param {Point} point - The point to test
* @return {boolean} Whether the x/y coords are within this ellipse
*/
isPointIn(point:Point):boolean {
isPointIn(point: Point): boolean {
if (this.width <= 0 || this.height <= 0) {
return false;
}
......@@ -84,7 +85,7 @@ export default class Ellipse {
*
* @return {Rectangle} the framing rectangle
*/
getBounds():Rectangle {
getBounds(): Rectangle {
return new Rectangle(this.x - this.width, this.y - this.height, this.width, this.height);
}
}
import { Point } from '../../math/Point';
import { SHAPES } from '../../const';
import {Point} from '../../math/Point';
import {SHAPES} from '../../const';
/**
*
......@@ -25,6 +25,7 @@ export default class Polygon {
* @see SHAPES
*/
type: number;
/**
* new Polygon(new Point(), new Point(), ...)
*
......
import { SHAPES } from '../../const';
import { Point } from '../../math';
import {SHAPES} from '../../const';
import {Point} from '../../math';
/**
* The Rounded Rectangle object is an area that has nice rounded corners, as indicated by its
......@@ -18,6 +18,7 @@ export default class RoundedRectangle {
*/
radius: number;
type: number;
/**
* @param {number} [x=0] - The X coordinate of the upper-left corner of the rounded rectangle
* @param {number} [y=0] - The Y coordinate of the upper-left corner of the rounded rectangle
......
export {default as Circle} from './Circle';
export {default as Ellipse} from './Ellipse';
......
import Texture from "../../texture/Texture";
import { Matrix } from "../../math";
import {Matrix} from "../../math";
/**
* 图形的填充形式
......@@ -35,6 +35,7 @@ export default class FillStyle {
* 用于设置alpha为0做点击触发用
*/
alphaBlock: boolean;
constructor() {
this.reset();
}
......
import FillStyle from './FillStyle';
import { LINE_ALIGNMENT } from '../../const';
import {LINE_ALIGNMENT} from '../../const';
/**
* 图形的画线模式
......@@ -21,13 +21,14 @@ export default class LineStyle extends FillStyle {
* 默认LINE_ALIGNMENT.middle 0.5
*/
alignment: LINE_ALIGNMENT;
/**
* Clones the object
*
* @return {LineStyle}
*/
clone():LineStyle {
const obj:LineStyle = new LineStyle();
clone(): LineStyle {
const obj: LineStyle = new LineStyle();
obj.color = this.color;
obj.alpha = this.alpha;
obj.texture = this.texture;
......@@ -38,6 +39,7 @@ export default class LineStyle extends FillStyle {
obj.native = this.native;
return obj;
}
/**
* 重置
*/
......
......@@ -6,7 +6,7 @@ export function bezierCurveControlPoint(points) {
if (points.length > 2) {
var A = [];
var B = [];
A[0] = { x: points[0].x + (points[1].x - points[0].x) / 4, y: points[0].y + (points[1].y - points[0].y) / 4 };
A[0] = {x: points[0].x + (points[1].x - points[0].x) / 4, y: points[0].y + (points[1].y - points[0].y) / 4};
B[0] = returnBControl(points, 0);
A[points.length - 2] = returnAControl(points, points.length - 2);
B[points.length - 2] = {
......@@ -17,29 +17,31 @@ export function bezierCurveControlPoint(points) {
A[i] = returnAControl(points, i);
B[i] = returnBControl(points, i);
}
return { A: A, B: B };
return {A: A, B: B};
}
}
function returnAControl(points, i) {
var x = points[i].x + (points[i + 1].x - points[i - 1].x) / 4;
var y = points[i].y + (points[i + 1].y - points[i - 1].y) / 4;
return { x: x, y: y };
return {x: x, y: y};
}
function returnBControl(points, i) {
var x = points[i + 1].x - (points[i + 2].x - points[i].x) / 4;
var y = points[i + 1].y - (points[i + 2].y - points[i].y) / 4;
return { x: x, y: y };
return {x: x, y: y};
}
//例子
function setPath(ctx, type) {
var points = [
{ x: 0, y: 0 },
{ x: 30, y: 0 },
{ x: 30, y: -30 },
{ x: 60, y: -30 },
{ x: 60, y: 0 },
{ x: 90, y: 0 }];
{x: 0, y: 0},
{x: 30, y: 0},
{x: 30, y: -30},
{x: 60, y: -30},
{x: 60, y: 0},
{x: 90, y: 0}];
var AB, A, B;
if (points.length > 2) {
AB = bezierCurveControlPoint(points);
......
export { default as bezierCurveTo } from './bezierCurveTo';
export { bezierCurveControlPoint } from "./bezierCurveControlPoint";
export {default as bezierCurveTo} from './bezierCurveTo';
export {bezierCurveControlPoint} from "./bezierCurveControlPoint";
/**
* Graphics curves resolution settings. If `adaptive` flag is set to `true`,
* the resolution is calculated based on the curve's length to ensure better visual quality.
......@@ -33,8 +32,7 @@ export const GRAPHICS_CURVES: { adaptive: boolean, maxLength: number, minSegment
if (result < this.minSegments) {
result = this.minSegments;
}
else if (result > this.maxSegments) {
} else if (result > this.maxSegments) {
result = this.maxSegments;
}
return result;
......
import { EventDispatcher } from "../events/EventDispatcher";
import { Parser } from "../svga/parser";
import { VideoEntity } from "../svga/VideoEntity";
import {EventDispatcher} from "../events/EventDispatcher";
import {Parser} from "../svga/parser";
import {VideoEntity} from "../svga/VideoEntity";
export class Loader extends EventDispatcher {
......@@ -16,6 +13,7 @@ export class Loader extends EventDispatcher {
parser: Parser;
_req: XMLHttpRequest = null;
/**
*
*/
......@@ -35,7 +33,7 @@ export class Loader extends EventDispatcher {
if (suc) {
this.cache(pngFile, data);
if (this.caches[url]) {
callback(true, { json: this.caches[url], img: data })
callback(true, {json: this.caches[url], img: data})
}
} else {
callback(false, data)
......@@ -63,7 +61,7 @@ export class Loader extends EventDispatcher {
// console.log(obj)
this.cache(url, _req.response);
if (this.caches[pngFile]) {
callback(true, { json: _req.response, img: this.caches[pngFile] })
callback(true, {json: _req.response, img: this.caches[pngFile]})
}
}
};
......
......@@ -2,7 +2,7 @@
* 二面体群,n=4,用于翻转四边形纹理,包括镜像
* 暂时用于纹理的旋转90度
*/
import { Matrix } from './Matrix';
import {Matrix} from './Matrix';
const ux = [1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1, 0, 1];
const uy = [0, 1, 1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1];
......@@ -119,22 +119,19 @@ const GroupD8 = {
}
return GroupD8.N;
}
else if (Math.abs(dy) * 2 <= Math.abs(dx)) {
} else if (Math.abs(dy) * 2 <= Math.abs(dx)) {
if (dx > 0) {
return GroupD8.E;
}
return GroupD8.W;
}
else if (dy > 0) {
} else if (dy > 0) {
if (dx > 0) {
return GroupD8.SE;
}
return GroupD8.SW;
}
else if (dx > 0) {
} else if (dx > 0) {
return GroupD8.NE;
}
......
import { Point } from "././Point";
import { HashObject } from "../HashObject";
import { DEG_TO_RAD, cos, sin, RAD_TO_DEG } from "../const";
import {Point} from "././Point";
import {HashObject} from "../HashObject";
import {cos, DEG_TO_RAD, RAD_TO_DEG, sin} from "../const";
/**
* 2维矩阵
......@@ -57,6 +56,7 @@ export class Matrix extends HashObject {
//数组形式
public array = null;
/**
* 构造函数
* @method Matrix
......@@ -200,8 +200,7 @@ export class Matrix extends HashObject {
if (b == 0 && c == 0) {
if (a == 0 || d == 0) {
s.a = s.d = s.tx = s.ty = 0;
}
else {
} else {
a = s.a = 1 / a;
d = s.d = 1 / d;
s.tx = -a * tx;
......@@ -259,14 +258,14 @@ export class Matrix extends HashObject {
if (skewX == skewY) {
s.a = u * scaleX;
s.b = v * scaleX;
}
else {
} else {
s.a = cos(skewY) * scaleX;
s.b = sin(skewY) * scaleX;
}
s.c = -v * scaleY;
s.d = u * scaleY;
};
}
;
s.tx = x + ax - (ax * s.a + ay * s.c);
s.ty = y + ay - (ax * s.b + ay * s.d);
}
......@@ -296,6 +295,7 @@ export class Matrix extends HashObject {
s.tx = a * tx1 + c * s.ty + tx;
s.ty = b * tx1 + d * s.ty + ty;
};
/**
* Appends the given Matrix to this Matrix.
*
......@@ -332,6 +332,7 @@ export class Matrix extends HashObject {
public static isEqual(m1: Matrix, m2: Matrix): boolean {
return m1.tx == m2.tx && m1.ty == m2.ty && m1.a == m2.a && m1.b == m2.b && m1.c == m2.c && m1.d == m2.d;
}
public concat(mtx: Matrix): void {
let s = this;
let a = s.a, b = s.b, c = s.c, d = s.d,
......@@ -345,6 +346,7 @@ export class Matrix extends HashObject {
s.tx = tx * ma + ty * mc + mx;
s.ty = tx * mb + ty * md + my;
}
/**
* 对矩阵应用旋转转换。
* @method rotate
......@@ -382,6 +384,7 @@ export class Matrix extends HashObject {
s.tx *= sx;
s.ty *= sy;
}
/**
* 沿 x 和 y 轴平移矩阵,由 dx 和 dy 参数指定。
* @method translate
......
import {Point} from "../math/Point";
import {HashObject} from "../HashObject";
import { Point } from "../math/Point";
import { HashObject } from "../HashObject";
/**
* 动态可监控ObservablePoint类
* @class
......@@ -10,6 +10,7 @@ export class ObservablePoint extends HashObject {
_y: number;
cb: any;
scope: any;
/**
* @param {Function} cb - 值改变时的回调
* @param {object} scope - 回调里的上下文this
......
import { HashObject } from "../HashObject";
import {HashObject} from "../HashObject";
/**
* @class Point
* @extends HashObject
......@@ -6,7 +7,9 @@ import { HashObject } from "../HashObject";
* @public
*/
export class Point extends HashObject {
public destroy(): void { }
public destroy(): void {
}
/**
* 构造函数
* @method Point
......@@ -22,6 +25,7 @@ export class Point extends HashObject {
s.x = x;
s.y = y;
}
/**
* 水平坐标
* @property x
......@@ -38,6 +42,7 @@ export class Point extends HashObject {
* @type {number}
*/
public y: number = 0;
/**
* 求两点之间的距离
* @method distance
......
import { HashObject } from "../HashObject";
import { Point } from "./Point";
import { SHAPES } from "../const";
import {HashObject} from "../HashObject";
import {Point} from "./Point";
import {SHAPES} from "../const";
/**
*
* @class Rectangle
......@@ -14,6 +15,7 @@ export class Rectangle extends HashObject {
* 类型
*/
type: number
/**
* 构造函数
* @method Rectangle
......@@ -191,6 +193,7 @@ export class Rectangle extends HashObject {
return rect;
}
}
/**
* 通过一系列点来生成一个矩形
* 返回包含所有给定的点的最小矩形
......@@ -284,6 +287,7 @@ export class Rectangle extends HashObject {
rect.x = x, rect.y = y, rect.width = w - x, rect.height = h - y;
return rect;
}
/**
* 判读两个矩形是否相交
* @method testRectCross
......
import { ObservablePoint } from './ObservablePoint';
import { Matrix } from "./Matrix";
import { HashObject } from '../HashObject';
import { cos, sin } from '../const';
import {ObservablePoint} from './ObservablePoint';
import {Matrix} from "./Matrix";
import {HashObject} from '../HashObject';
import {cos, sin} from '../const';
/**
* @class
......
export { Matrix } from './Matrix';
export { Point } from './Point';
export { ObservablePoint } from './ObservablePoint';
export { Rectangle } from './Rectangle';
export {Matrix} from './Matrix';
export {Point} from './Point';
export {ObservablePoint} from './ObservablePoint';
export {Rectangle} from './Rectangle';
// export {default as Transform} from './Transform';
export { default as Transform } from './Transform';
export { default as GroupD8 } from './GroupD8';
\ No newline at end of file
export {default as Transform} from './Transform';
export {default as GroupD8} from './GroupD8';
\ No newline at end of file
import SystemRenderer from './SystemRenderer';
import CanvasMaskManager from './managers/CanvasMaskManager';
import CanvasRenderTarget from './renderTarget/CanvasRenderTarget';
import { RENDERER_TYPE } from '../const';
import { RendererOptions } from './RendererOptions';
import {RENDERER_TYPE} from '../const';
import {RendererOptions} from './RendererOptions';
import RenderTexture from '../texture/RenderTexture';
import { Matrix } from '../math';
import { DisplayObject } from '../display/DisplayObject';
import {Matrix} from '../math';
import {DisplayObject} from '../display/DisplayObject';
import CanvasSpriteRenderer from './plugins/CanvasSpriteRenderer';
import { CanvasGraphicsRenderer } from './plugins/CanvasGraphicsRenderer';
import {CanvasGraphicsRenderer} from './plugins/CanvasGraphicsRenderer';
/**
......@@ -41,7 +41,7 @@ export default class CanvasRenderer extends SystemRenderer {
super(options);
this._instanceType = "CanvasRenderer";
this.type = RENDERER_TYPE.CANVAS;
this.rootContext = this.htmlElement ? this.htmlElement.getContext('2d', { alpha: this.transparent }) : null;
this.rootContext = this.htmlElement ? this.htmlElement.getContext('2d', {alpha: this.transparent}) : null;
this.context = this.rootContext;
this.maskManager = new CanvasMaskManager(this);
......@@ -51,14 +51,11 @@ export default class CanvasRenderer extends SystemRenderer {
if (this.rootContext && !this.rootContext.imageSmoothingEnabled) {
if (this.rootContext["webkitImageSmoothingEnabled"]) {
this.smoothProperty = 'webkitImageSmoothingEnabled';
}
else if (this.rootContext["mozImageSmoothingEnabled"]) {
} else if (this.rootContext["mozImageSmoothingEnabled"]) {
this.smoothProperty = 'mozImageSmoothingEnabled';
}
else if (this.rootContext["oImageSmoothingEnabled"]) {
} else if (this.rootContext["oImageSmoothingEnabled"]) {
this.smoothProperty = 'oImageSmoothingEnabled';
}
else if (this.rootContext["msImageSmoothingEnabled"]) {
} else if (this.rootContext["msImageSmoothingEnabled"]) {
this.smoothProperty = 'msImageSmoothingEnabled';
}
}
......@@ -104,8 +101,7 @@ export default class CanvasRenderer extends SystemRenderer {
}
//当前上下文要修改成离屏的
this.context = renderTexture._canvasRenderTarget.context;
}
else {
} else {
//当前上下文就是根节点的
this.context = this.rootContext;
}
......@@ -128,8 +124,7 @@ export default class CanvasRenderer extends SystemRenderer {
tempWt.copy(transform);
//标记要更新transform
this._tempDisplayObjectParent.transform._worldID = -1;
}
else {
} else {
//没有就初始化
tempWt.identity();
}
......@@ -148,8 +143,7 @@ export default class CanvasRenderer extends SystemRenderer {
if (this.renderingToScreen) {
if (this.transparent) {
context.clearRect(0, 0, this.htmlElement.width, this.htmlElement.height);
}
else {
} else {
context.fillStyle = this._backgroundColorString;
context.fillRect(0, 0, this.htmlElement.width, this.htmlElement.height);
}
......@@ -175,8 +169,7 @@ export default class CanvasRenderer extends SystemRenderer {
if (!this.transparent && clearColor) {
context.fillStyle = clearColor;
context.fillRect(0, 0, this.htmlElement.width, this.htmlElement.height);
}
else {
} else {
context.clearRect(0, 0, this.htmlElement.width, this.htmlElement.height);
}
}
......
import { hex2string, hex2rgb } from '../utils';
import { Matrix, Rectangle } from '../math';
import { RENDERER_TYPE, devicePixelRatio } from '../const';
import {hex2rgb, hex2string} from '../utils';
import {Matrix} from '../math';
import {devicePixelRatio, RENDERER_TYPE} from '../const';
import Container from '../display/Container';
import { EventDispatcher } from '../events/EventDispatcher';
import { DisplayObject } from "../display/DisplayObject";
import { RendererOptions } from "./RendererOptions";
import {EventDispatcher} from '../events/EventDispatcher';
import {DisplayObject} from "../display/DisplayObject";
import {RendererOptions} from "./RendererOptions";
const tempMatrix = new Matrix();
......
import { EventDispatcher } from "../events/EventDispatcher";
import BatchRenderer from "./plugins/BatchRenderer";
import SystemRenderer from "./SystemRenderer";
import { RendererOptions } from "./RendererOptions";
import { RENDERER_TYPE } from "../const";
import { createContext, GLShader, VertexArrayObject } from "../../glCore";
import ObjectRenderer from "./webgl/ObjectRenderer";
import {RendererOptions} from "./RendererOptions";
import {devicePixelRatio, RENDERER_TYPE, SCALE_MODES} from "../const";
import {createContext, GLShader, VertexArrayObject} from "../../glCore";
import RenderTarget from "./renderTarget/RenderTarget";
import TextureManager from "./managers/TextureManager";
import TextureGarbageCollector from "./managers/TextureGarbageCollector";
import { SCALE_MODES, devicePixelRatio } from "../const";
import RenderTexture from "../texture/RenderTexture";
import { Matrix } from "../math";
import {Matrix} from "../math";
import WebGLState from "./webgl/WebGLState";
import BatchManager from "./managers/BatchManager";
import MaskManager from "./managers/MaskManager";
import StencilManager from "./managers/StencilManager";
import { DisplayObject } from "../display/DisplayObject";
import {DisplayObject} from "../display/DisplayObject";
let CONTEXT_UID = 0;
......@@ -288,8 +285,7 @@ export class WebglRenderer extends SystemRenderer {
if (vao) {
vao.bind();
}
else if (this._activeVao) {
} else if (this._activeVao) {
// TODO this should always be true i think?
this._activeVao.unbind();
}
......@@ -344,8 +340,7 @@ export class WebglRenderer extends SystemRenderer {
renderTarget = baseTexture._glRenderTargets[this.CONTEXT_UID];
renderTarget.setFrame(renderTexture.frame);
}
else {
} else {
renderTarget = this.rootRenderTarget;
}
......@@ -426,7 +421,6 @@ export class WebglRenderer extends SystemRenderer {
}
/**
* webgl上下文恢复时
* @private
......@@ -466,6 +460,7 @@ export class WebglRenderer extends SystemRenderer {
}
static __plugins;
/**
* Adds a plugin to the renderer.
*
......
import ObjectRenderer from '../webgl/ObjectRenderer';
import { WebglRenderer } from '../WebglRenderer';
import {WebglRenderer} from '../WebglRenderer';
/**
* 批处理管理器,用于切换渲染插件
......
import { SHAPES } from '../../const';
import { HashObject } from '../../HashObject';
import {SHAPES} from '../../const';
import {HashObject} from '../../HashObject';
import CanvasRenderer from '../CanvasRenderer';
import Graphics from '../../graphics/Graphics';
import GraphicsData from '../../graphics/GraphicsData';
import { holePath, judgeCcw } from '../plugins/CanvasGraphicsRenderer';
import {holePath, judgeCcw} from '../plugins/CanvasGraphicsRenderer';
/**
*
*/
export default class CanvasMaskManager extends HashObject {
renderer
/**
* @param {CanvasRenderer} renderer - The canvas renderer.
*/
......@@ -82,15 +82,12 @@ export default class CanvasMaskManager extends HashObject {
} else {
context.closePath();
}
}
else if (data.type === SHAPES.RECT) {
} else if (data.type === SHAPES.RECT) {
context.rect(shape.x, shape.y, shape.width, shape.height);
}
else if (data.type === SHAPES.CIRC) {
} else if (data.type === SHAPES.CIRC) {
// TODO - need to be Undefined!
context.arc(shape.x, shape.y, shape.radius, 0, 2 * Math.PI);
}
else if (data.type === SHAPES.ELIP) {
} else if (data.type === SHAPES.ELIP) {
// ellipse code taken from: http://stackoverflow.com/questions/2172798/how-to-draw-an-oval-in-html5-canvas
const w = shape.width * 2;
......@@ -112,8 +109,7 @@ export default class CanvasMaskManager extends HashObject {
context.bezierCurveTo(xm + ox, y, xe, ym - oy, xe, ym);
context.bezierCurveTo(xe, ym + oy, xm + ox, ye, xm, ye);
context.bezierCurveTo(xm - ox, ye, x, ym + oy, x, ym);
}
else if (data.type === SHAPES.RREC) {
} else if (data.type === SHAPES.RREC) {
const rx = shape.x;
const ry = shape.y;
const width = shape.width;
......
import Graphics from '../../graphics/Graphics';
import { WebglRenderer } from '../WebglRenderer';
import {WebglRenderer} from '../WebglRenderer';
import RenderTarget from '../renderTarget/RenderTarget';
/**
......@@ -14,6 +13,7 @@ export default class MaskManager {
enableScissor: boolean;
alphaMaskPool: any[];
alphaMaskIndex: number;
/**
* - The renderer this manager works for.
*/
......
import { WebglRenderer } from '../WebglRenderer';
import {WebglRenderer} from '../WebglRenderer';
import Graphics from '../../graphics/Graphics';
/**
......@@ -9,6 +8,7 @@ import Graphics from '../../graphics/Graphics';
export default class StencilManager {
renderer: WebglRenderer
stencilMaskStack: Graphics[];
/**
* @param {WebGLRenderer} renderer - The renderer this manager works for.
*/
......@@ -30,8 +30,7 @@ export default class StencilManager {
if (stencilMaskStack.length === 0) {
gl.disable(gl.STENCIL_TEST);
}
else {
} else {
gl.enable(gl.STENCIL_TEST);
}
}
......@@ -82,8 +81,7 @@ export default class StencilManager {
gl.disable(gl.STENCIL_TEST);
gl.clear(gl.STENCIL_BUFFER_BIT);
gl.clearStencil(0);
}
else {
} else {
// Decrement the refference stencil value where the popped mask overlaps with the other ones
gl.colorMask(false, false, false, false);
gl.stencilOp(gl.KEEP, gl.KEEP, gl.DECR);
......
import { GC_MODES } from '../../const';
import { WebglRenderer } from '../WebglRenderer';
import {GC_MODES} from '../../const';
import {WebglRenderer} from '../WebglRenderer';
/**
* TextureGarbageCollector. This class manages the GPU and ensures that it does not get clogged
* up with textures that are no longer being used.
......@@ -12,6 +13,7 @@ export default class TextureGarbageCollector {
maxIdle: number;
checkCountMax: number;
mode: number;
/**
* @param {WebGLRenderer} renderer - The renderer this manager works for.
*/
......
import { GLTexture } from '../../../glCore';
import { WRAP_MODES, SCALE_MODES } from '../../const';
import {GLTexture} from '../../../glCore';
import {SCALE_MODES, WRAP_MODES} from '../../const';
import RenderTarget from '../renderTarget/RenderTarget';
import { removeItems } from '../../utils';
import {removeItems} from '../../utils';
import BaseTexture from '../../texture/BaseTexture';
import { WebglRenderer } from '../WebglRenderer';
import {WebglRenderer} from '../WebglRenderer';
/**
* Helper class to create a webGL Texture
......@@ -20,6 +20,7 @@ export default class TextureManager {
* Track textures in the renderer so we can no longer listen to them on destruction.
*/
_managedTextures: Array<any>;
/**
* @param {WebGLRenderer} renderer - A reference to the current renderer
*/
......@@ -49,7 +50,7 @@ export default class TextureManager {
// now lets fill up the textures with empty ones!
const emptyGLTexture = GLTexture.fromData(gl, null, 1, 1);
const tempObj = { _glTextures: {} };
const tempObj = {_glTextures: {}};
tempObj._glTextures[this.renderer.CONTEXT_UID] = {};
......@@ -65,7 +66,6 @@ export default class TextureManager {
}
/**
* Binds the texture. This will return the location of the bound texture.
* It may not be the same as the one you pass in. This is due to optimisation that prevents
......@@ -96,8 +96,7 @@ export default class TextureManager {
this._nextTextureLocation %= this.boundTextures.length;
location = this.boundTextures.length - this._nextTextureLocation - 1;
}
}
else {
} else {
location = location || 0;
}
......@@ -108,8 +107,7 @@ export default class TextureManager {
if (!glTexture) {
// this will also bind the texture..
this.updateTexture(texture, location);
}
else {
} else {
// bind the current texture
if (this.currentLocation !== location) {
this.currentLocation = location;
......@@ -123,6 +121,7 @@ export default class TextureManager {
}
return location;
}
/**
* Gets a texture.
*
......@@ -140,10 +139,10 @@ export default class TextureManager {
*/
updateTexture(texture: any, location?: number): GLTexture {
//如果是事件返回的
if(texture.instanceType==="Event"){
if (texture.instanceType === "Event") {
//选择它的target
texture=texture.target.baseTexture||texture.target
}else{
texture = texture.target.baseTexture || texture.target
} else {
texture = texture.baseTexture || texture;
}
......@@ -195,8 +194,7 @@ export default class TextureManager {
renderTarget.resize(texture.width, texture.height);
texture._glRenderTargets[this.renderer.CONTEXT_UID] = renderTarget;
glTexture = renderTarget.texture;
}
else {
} else {
glTexture = new GLTexture(this.gl, null, null, null, null);
//之前已经active过了,upload里也有bind,这里也许不用执行
// glTexture.bind(location);
......@@ -217,30 +215,25 @@ export default class TextureManager {
}
if (texture.wrapMode === WRAP_MODES.CLAMP) {
glTexture.enableWrapClamp();
}
else if (texture.wrapMode === WRAP_MODES.REPEAT) {
} else if (texture.wrapMode === WRAP_MODES.REPEAT) {
glTexture.enableWrapRepeat();
}
else {
} else {
glTexture.enableWrapMirrorRepeat();
}
}
else {
} else {
glTexture.enableWrapClamp();
}
if (texture.scaleMode === SCALE_MODES.NEAREST) {
glTexture.enableNearestScaling();
}
else {
} else {
glTexture.enableLinearScaling();
}
}
// the texture already exists so we only need to update it..
else if (isRenderTexture) {
texture._glRenderTargets[this.renderer.CONTEXT_UID].resize(texture.width, texture.height);
}
else {
} else {
glTexture.upload(texture.source);
}
......
import BatchDrawCall from '../webgl/BatchDrawCall';
import { osType } from "../../const"
import {osType} from "../../const"
// import State from '../state/State';
import ObjectRenderer from '../webgl/ObjectRenderer';
import { checkMaxIfStatementsInShader } from '../../../glCore/checkMaxIfStatementsInShader';
import {checkMaxIfStatementsInShader} from '../../../glCore/checkMaxIfStatementsInShader';
import { BatchBuffer } from '../webgl/BatchBuffer';
import { generateMultiTextureShader } from '../webgl/generateMultiTextureShader';
import { WebglRenderer } from '../WebglRenderer';
import { GLShader, GLBuffer, VertexArrayObject } from '../../../glCore';
import { nextPow2, log2, premultiplyTint } from '../../utils';
import { DisplayObject } from '../../display/DisplayObject';
import {BatchBuffer} from '../webgl/BatchBuffer';
import {generateMultiTextureShader} from '../webgl/generateMultiTextureShader';
import {WebglRenderer} from '../WebglRenderer';
import {GLBuffer, GLShader, VertexArrayObject} from '../../../glCore';
import {log2, nextPow2, premultiplyTint} from '../../utils';
let TICK = 0;
......@@ -133,8 +132,7 @@ export default class BatchRenderer extends ObjectRenderer {
if (false /*传统方式*/) {
this.MAX_TEXTURES = 1;
}
else {
} else {
// step 1: first check max textures the GPU can handle.
this.MAX_TEXTURES = Math.min(gl.getParameter(gl.MAX_TEXTURE_IMAGE_UNITS), 16);
......@@ -390,8 +388,7 @@ export default class BatchRenderer extends ObjectRenderer {
this.vertexCount++;
}
else {
} else {
// lets use the faster option, always use buffer number 0
this.vertexBuffers[this.vertexCount].upload(buffer.vertices, 0, true);
......@@ -462,6 +459,7 @@ export default class BatchRenderer extends ObjectRenderer {
indexBuffer[indexCount++] = p + indicies[i];
}
}
/*
renderQuad(vertexData, uvs, argb, textureId, float32View, uint32View, indexBuffer, index, indexCount)
{
......
import CanvasRenderer from '../CanvasRenderer';
import { SHAPES } from '../../const';
import {SHAPES} from '../../const';
import Graphics from '../../graphics/Graphics';
import GraphicsData from '../../graphics/GraphicsData';
......@@ -11,6 +11,7 @@ import GraphicsData from '../../graphics/GraphicsData';
*/
export class CanvasGraphicsRenderer {
renderer: CanvasRenderer;
/**
* @param {CanvasRenderer} renderer - The current renderer.
*/
......@@ -61,8 +62,7 @@ export class CanvasGraphicsRenderer {
context.lineTo(points[m * 2], points[(m * 2) + 1]);
}
ccw = !judgeCcw(points)
}
else if (data.type === SHAPES.RECT) {
} else if (data.type === SHAPES.RECT) {
if (data.holes.length) {
context.beginPath();
context.moveTo(shape.x, shape.y);
......@@ -84,14 +84,12 @@ export class CanvasGraphicsRenderer {
}
continue
}
}
else if (data.type === SHAPES.CIRC) {
} else if (data.type === SHAPES.CIRC) {
//https://www.w3school.com.cn/tags/canvas_arc.asp
//默认顺时针 counterclockwise= false
context.beginPath();
context.arc(shape.x, shape.y, shape.radius, 0, 2 * Math.PI, false);
}
else if (data.type === SHAPES.ELIP) {
} else if (data.type === SHAPES.ELIP) {
// ellipse code taken from: http://stackoverflow.com/questions/2172798/how-to-draw-an-oval-in-html5-canvas
const w = shape.width * 2;
......@@ -115,8 +113,7 @@ export class CanvasGraphicsRenderer {
context.bezierCurveTo(xm + ox, y, xe, ym - oy, xe, ym);
context.bezierCurveTo(xe, ym + oy, xm + ox, ye, xm, ye);
context.bezierCurveTo(xm - ox, ye, x, ym + oy, x, ym);
}
else if (data.type === SHAPES.RREC) {
} else if (data.type === SHAPES.RREC) {
const rx = shape.x;
const ry = shape.y;
const width = shape.width;
......@@ -162,7 +159,6 @@ export class CanvasGraphicsRenderer {
}
/**
* destroy graphics object
*
......
import CanvasRenderer from '../CanvasRenderer';
import { SCALE_MODES } from '../../const';
import { Matrix, GroupD8 } from '../../math';
import {SCALE_MODES} from '../../const';
import {GroupD8, Matrix} from '../../math';
import Sprite from '../../display/Sprite';
import { DisplayObject } from '../../display/DisplayObject';
import Graphics from '../../graphics/Graphics';
const canvasRenderWorldTransform = new Matrix();
......@@ -16,6 +14,7 @@ const canvasRenderWorldTransform = new Matrix();
*/
export default class CanvasSpriteRenderer {
renderer: CanvasRenderer;
/**
* @param {CanvasRenderer} renderer -The renderer sprite this batch works for.
*/
......@@ -50,7 +49,6 @@ export default class CanvasSpriteRenderer {
renderer.context.globalAlpha = sprite.worldAlpha;
// If smoothingEnabled is supported and we need to change the smoothing property for sprite texture
const smoothingEnabled = texture.baseTexture.scaleMode === SCALE_MODES.LINEAR;
......@@ -62,8 +60,7 @@ export default class CanvasSpriteRenderer {
if (texture.trim) {
dx = (texture.trim.width / 2) + texture.trim.x - (sprite._anchorTexture.x * texture.orig.width);
dy = (texture.trim.height / 2) + texture.trim.y - (sprite._anchorTexture.y * texture.orig.height);
}
else {
} else {
dx = (0.5 - sprite._anchorTexture.x) * texture.orig.width;
dy = (0.5 - sprite._anchorTexture.y) * texture.orig.height;
......
/**
* Creates a Canvas element of the given size.
* 其实就是一个离屏canvas,webgl模式不需要建canvas,因为可以用帧缓存
......
import { Rectangle, Matrix } from '../../math';
import { SCALE_MODES } from '../../const';
import {Matrix, Rectangle} from '../../math';
import {SCALE_MODES} from '../../const';
// import settings from '../../../settings';
import { GLFramebuffer, GLTexture, GLBuffer } from '../../../glCore';
import {GLBuffer, GLFramebuffer, GLTexture} from '../../../glCore';
import Graphics from '../../graphics/Graphics';
......@@ -63,6 +63,7 @@ export default class RenderTarget {
* Whether this object is the root element or not
*/
root: boolean;
/**
* @param {WebGLRenderingContext} gl - The current WebGL drawing context
* @param {number} [width=0] - the horizontal range of the filter
......@@ -111,8 +112,7 @@ export default class RenderTarget {
if (this.scaleMode === SCALE_MODES.NEAREST) {
this.frameBuffer.texture.enableNearestScaling();
}
else {
} else {
this.frameBuffer.texture.enableLinearScaling();
}
/*
......@@ -122,8 +122,7 @@ export default class RenderTarget {
// this is used by the base texture
this.texture = this.frameBuffer.texture;
}
else {
} else {
// make it a null framebuffer..
this.frameBuffer = new GLFramebuffer(gl, 100, 100);
//帧缓存为空,gltexture也是空
......@@ -197,8 +196,7 @@ export default class RenderTarget {
this.destinationFrame.width | 0,
this.destinationFrame.height | 0
);
}
else {
} else {
gl.disable(gl.SCISSOR_TEST);
}
......@@ -217,7 +215,7 @@ export default class RenderTarget {
* @param {Rectangle} destinationFrame - The destination frame.
* @param {Rectangle} sourceFrame - The source frame.
*/
calculateProjection(destinationFrame:Rectangle, sourceFrame?:Rectangle) {
calculateProjection(destinationFrame: Rectangle, sourceFrame?: Rectangle) {
const pm = this.projectionMatrix;
// console.log(destinationFrame)
sourceFrame = sourceFrame || destinationFrame;
......@@ -231,8 +229,7 @@ export default class RenderTarget {
pm.tx = -1 - (sourceFrame.x * pm.a);
pm.ty = -1 - (sourceFrame.y * pm.d);
}
else {
} else {
pm.a = 1 / destinationFrame.width * 2;
pm.d = -1 / destinationFrame.height * 2;
......
/**
* 批处理用buffer数据
*/
......@@ -25,6 +24,7 @@ export class BatchBuffer {
positions: any;
uvs: any;
colors: any;
/**
* @param {number} size - The size of the buffer in bytes.
*/
......
import { DRAW_MODES } from "../../const";
import {DRAW_MODES} from "../../const";
import BaseTexture from "../../texture/BaseTexture";
/**
......@@ -26,6 +26,7 @@ export default class BatchDrawCall {
* 绘制类型
*/
type: number;
constructor() {
this.textures = [];
// this.ids = [];
......
import { DisplayObject } from "../../display/DisplayObject";
import { WebglRenderer } from "../WebglRenderer";
import {DisplayObject} from "../../display/DisplayObject";
import {WebglRenderer} from "../WebglRenderer";
/**
* Base for a common object renderer that can be used as a system renderer plugin.
......@@ -12,6 +12,7 @@ export default class ObjectRenderer {
* @member {Renderer}
*/
renderer: WebglRenderer
constructor(renderer: WebglRenderer) {
this.renderer = renderer;
......@@ -29,6 +30,7 @@ export default class ObjectRenderer {
onContextChange() {
// do some codes init!
}
/**
* Starts the renderer and sets the shader
*
......@@ -60,6 +62,7 @@ export default class ObjectRenderer {
render(object: DisplayObject) {
// render the object
}
/**
* Generic destroy methods to be overridden by the subclass
*/
......
import { mapWebGLBlendModesToPixi } from '../../utils';
import {mapWebGLBlendModesToPixi} from '../../utils';
const BLEND = 0;
const DEPTH_TEST = 1;
......@@ -28,6 +28,7 @@ export default class WebGLState {
maxAttribs: any;
attribState: { tempAttribState: any[]; attribState: any[]; };
nativeVaoExtension: any;
/**
* @param {WebGLRenderingContext} gl - The current WebGL rendering context
*/
......@@ -105,8 +106,7 @@ export default class WebGLState {
if (mode.length === 2) {
this.gl.blendFunc(mode[0], mode[1]);
}
else {
} else {
this.gl.blendFuncSeparate(mode[0], mode[1], mode[2], mode[3]);
}
}
......
import { GLShader } from '../../../glCore';
import {GLShader} from '../../../glCore';
//顶点着色器程序
const VSHADER_SOURCE =
"precision highp float;" +
......
import Container from "../display/Container";
import { VideoEntity } from "./VideoEntity";
import {VideoEntity} from "./VideoEntity";
import Texture from "../texture/Texture";
import Sprite from "../display/Sprite";
import { Event } from "../events/Event";
import Graphics from "../graphics/Graphics";
import { GlobalPro, TextureCache } from "../utils";
import { RENDERER_TYPE, RAD_TO_DEG } from "../const";
import { DrawAllToCanvas } from "../utils/DrawAllToCanvas";
import { Button } from "../ui/Button";
import { TextField } from "../text/TextField";
import { Matrix } from "../math";
import {Event} from "../events/Event";
import {GlobalPro, TextureCache} from "../utils";
import {RAD_TO_DEG, RENDERER_TYPE} from "../const";
import {DrawAllToCanvas} from "../utils/DrawAllToCanvas";
import {Button} from "../ui/Button";
import {TextField} from "../text/TextField";
import {Matrix} from "../math";
/**
* 用于播放动画
......@@ -38,6 +37,7 @@ export class MovieClip extends Container {
* 锁步将按时间间隔来执行动画
*/
public lockStep: boolean = false;
/**
* mc的当前帧,从1开始
* @property currentFrame
......@@ -134,6 +134,7 @@ export class MovieClip extends Container {
* 中间帧计时
*/
private frameCount: number = 0;
/**
* 构造函数
* @method MovieClip
......@@ -206,8 +207,7 @@ export class MovieClip extends Container {
let backCanvas;
if (bitmap.indexOf("iVBO") === 0 || bitmap.indexOf("/9j/2w") === 0) {
imgTag.src = 'data:image/png;base64,' + bitmap;
}
else {
} else {
imgTag.src = bitmap;
//这里有问题,再说
// if (frames[0] && frames[0].layout) {
......@@ -586,6 +586,7 @@ export class MovieClip extends Container {
private _endMark: boolean
commonDeltaTime = 1000 / 60;
updateFrame() {
var s = this;
//1帧的时候也有相应的frameCount,无用,return
......@@ -713,6 +714,7 @@ export class MovieClip extends Container {
this._lastFrame = this._curFrame;
return true
}
/**
* 重写刷新
* @method update
......@@ -727,7 +729,6 @@ export class MovieClip extends Container {
}
public destroy(): void {
//todo-清除相应的数据引用
......
import { SpriteEntity } from './spriteEntity'
import { ProtoMovieEntity } from "./proto";
import { HashObject } from '../HashObject';
import {SpriteEntity} from './spriteEntity'
import {ProtoMovieEntity} from "./proto";
import {HashObject} from '../HashObject';
export class VideoEntity extends HashObject {
......@@ -35,12 +35,12 @@ export class VideoEntity extends HashObject {
/**
* 图片是否已被缓存,缓存全局,注意名字覆盖
*/
hasBeenCached:boolean=false;
hasBeenCached: boolean = false;
/**
* SpriteEntity[]
*/
sprites:SpriteEntity[] = []
sprites: SpriteEntity[] = []
/**
* AudioEntity[]
......@@ -49,7 +49,7 @@ export class VideoEntity extends HashObject {
constructor(spec, images) {
super();
this._instanceType="VideoEntity";
this._instanceType = "VideoEntity";
if (typeof spec === "object" && spec.$type == ProtoMovieEntity) {
if (typeof spec.params === "object") {
......@@ -61,8 +61,7 @@ export class VideoEntity extends HashObject {
}
this.resetSprites(spec)
this.audios = spec.audios
}
else if (spec) {
} else if (spec) {
if (spec.movie) {
if (spec.movie.viewBox) {
this.videoSize.width = parseFloat(spec.movie.viewBox.width) || 0.0;
......@@ -87,7 +86,7 @@ export class VideoEntity extends HashObject {
}
}
destroy(){
destroy() {
}
}
\ No newline at end of file
import { BezierPath } from './bezierPath'
import {BezierPath} from './bezierPath'
export class EllipsePath extends BezierPath {
......
import { BezierPath } from './bezierPath'
import {BezierPath} from './bezierPath'
export class FrameEntity {
......@@ -51,7 +51,7 @@ export class FrameEntity {
this.transform.ty = parseFloat(spec.transform.ty) || 0.0;
}
if (spec.clipPath && spec.clipPath.length > 0) {
this.maskPath = new BezierPath(spec.clipPath, undefined, { fill: "#000000" });
this.maskPath = new BezierPath(spec.clipPath, undefined, {fill: "#000000"});
}
if (spec.shapes) {
if (spec.shapes instanceof Array) {
......@@ -92,12 +92,17 @@ export class FrameEntity {
lineDash.push(shape.styles.lineDashI)
}
if (shape.styles.lineDashII > 0) {
if (lineDash.length < 1) { lineDash.push(0) }
if (lineDash.length < 1) {
lineDash.push(0)
}
lineDash.push(shape.styles.lineDashII)
lineDash.push(0)
}
if (shape.styles.lineDashIII > 0) {
if (lineDash.length < 2) { lineDash.push(0); lineDash.push(0); }
if (lineDash.length < 2) {
lineDash.push(0);
lineDash.push(0);
}
lineDash[2] = shape.styles.lineDashIII
}
shape.styles.lineDash = lineDash
......@@ -130,8 +135,7 @@ export class FrameEntity {
}
if (spec.shapes[0] && spec.shapes[0].type === "keep") {
this.shapes = FrameEntity.lastShapes;
}
else {
} else {
this.shapes = spec.shapes
FrameEntity.lastShapes = spec.shapes;
}
......@@ -147,5 +151,6 @@ export class FrameEntity {
this.nx = Math.min(Math.min(lbx, rbx), Math.min(llx, lrx));
this.ny = Math.min(Math.min(lby, rby), Math.min(lly, lry));
}
static lastShapes
}
\ No newline at end of file
export { VideoEntity } from "./VideoEntity";
export { MovieClip } from "./MovieClip";
\ No newline at end of file
export {VideoEntity} from "./VideoEntity";
export {MovieClip} from "./MovieClip";
\ No newline at end of file
......@@ -3,9 +3,10 @@
*/
import { ProtoMovieEntity } from "./proto";
import { utils } from './pako/utils/common';
import {ProtoMovieEntity} from "./proto";
import {utils} from './pako/utils/common';
import inflate from "./pako/inflate";
const pako = {}
utils.assign(pako, inflate);
......@@ -62,8 +63,7 @@ const actions = {
images[key] = btoa(value)
}
}
}
else {
} else {
for (const key in movieData.images) {
if (movieData.images.hasOwnProperty(key)) {
const element = movieData.images[key];
......@@ -81,8 +81,7 @@ const actions = {
}
}
finished && imagesLoadedBlock.call(this)
}
else {
} else {
var finished = true;
for (var key in movieData.images) {
if (movieData.images.hasOwnProperty(key)) {
......
'use strict';
import { strings } from "./utils/strings"
import { utils } from "./utils/common"
import {strings} from "./utils/strings"
import {utils} from "./utils/common"
import zlib_inflate from './zlib/inflate';
import c from './zlib/constants';
......@@ -105,7 +105,9 @@ function Inflate(options) {
// because we have no header for autodetect.
if (opt.raw && (opt.windowBits >= 0) && (opt.windowBits < 16)) {
opt.windowBits = -opt.windowBits;
if (opt.windowBits === 0) { opt.windowBits = -15; }
if (opt.windowBits === 0) {
opt.windowBits = -15;
}
}
// If `windowBits` not defined (and mode not raw) - set autodetect flag for gzip/deflate
......@@ -201,7 +203,9 @@ Inflate.prototype.push = function (data, mode) {
// when we check that all output data was flushed.
var allowBufError = false;
if (this.ended) { return false; }
if (this.ended) {
return false;
}
_mode = (mode === ~~mode) ? mode : ((mode === true) ? c.Z_FINISH : c.Z_NO_FLUSH);
// Convert data if needed
......@@ -254,7 +258,9 @@ Inflate.prototype.push = function (data, mode) {
// move tail
strm.next_out = tail;
strm.avail_out = chunkSize - tail;
if (tail) { utils.arraySet(strm.output, strm.output, next_out_utf8, tail, 0); }
if (tail) {
utils.arraySet(strm.output, strm.output, next_out_utf8, tail, 0);
}
this.onData(utf8str);
......@@ -386,7 +392,9 @@ function inflate(input, options) {
inflator.push(input, true);
// That will never happens, if you don't cheat with options :)
if (inflator.err) { throw inflator.msg || msg[inflator.err]; }
if (inflator.err) {
throw inflator.msg || msg[inflator.err];
}
return inflator.result;
}
......@@ -422,4 +430,4 @@ function inflateRaw(input, options) {
// exports.inflateRaw = inflateRaw;
// exports.ungzip = inflate;
export default { inflate }
export default {inflate}
......@@ -37,8 +37,12 @@ function assign(obj, objO) {
// reduce buffer size, avoiding mem copy
function shrinkBuf(buf, size) {
if (buf.length === size) { return buf; }
if (buf.subarray) { return buf.subarray(0, size); }
if (buf.length === size) {
return buf;
}
if (buf.subarray) {
return buf.subarray(0, size);
}
buf.length = size;
return buf;
};
......@@ -109,7 +113,6 @@ if (TYPED_OK) {
}
export const utils = {
assign,
shrinkBuf,
......
// String encode/decode helpers
'use strict';
import {utils}from "./common"
import {utils} from "./common"
// Quick check if we can use fast array to bin string conversion
//
......@@ -11,8 +11,16 @@ import {utils}from "./common"
var STR_APPLY_OK = true;
var STR_APPLY_UIA_OK = true;
try { String.fromCharCode.apply(null, [0]); } catch (__) { STR_APPLY_OK = false; }
try { String.fromCharCode.apply(null, new Uint8Array(1)); } catch (__) { STR_APPLY_UIA_OK = false; }
try {
String.fromCharCode.apply(null, [0]);
} catch (__) {
STR_APPLY_OK = false;
}
try {
String.fromCharCode.apply(null, new Uint8Array(1));
} catch (__) {
STR_APPLY_UIA_OK = false;
}
// Table with utf8 lengths (calculated by first byte of sequence)
......@@ -121,11 +129,18 @@ function buf2string(buf, max) {
for (out = 0, i = 0; i < len;) {
c = buf[i++];
// quick process ascii
if (c < 0x80) { utf16buf[out++] = c; continue; }
if (c < 0x80) {
utf16buf[out++] = c;
continue;
}
c_len = _utf8len[c];
// skip 5 & 6 byte codes
if (c_len > 4) { utf16buf[out++] = 0xfffd; i += c_len - 1; continue; }
if (c_len > 4) {
utf16buf[out++] = 0xfffd;
i += c_len - 1;
continue;
}
// apply mask on first byte
c &= c_len === 2 ? 0x1f : c_len === 3 ? 0x0f : 0x07;
......@@ -136,7 +151,10 @@ function buf2string(buf, max) {
}
// terminated by end of string?
if (c_len > 1) { utf16buf[out++] = 0xfffd; continue; }
if (c_len > 1) {
utf16buf[out++] = 0xfffd;
continue;
}
if (c < 0x10000) {
utf16buf[out++] = c;
......@@ -161,24 +179,32 @@ function utf8border(buf, max) {
var pos;
max = max || buf.length;
if (max > buf.length) { max = buf.length; }
if (max > buf.length) {
max = buf.length;
}
// go back from last position, until start of sequence found
pos = max - 1;
while (pos >= 0 && (buf[pos] & 0xC0) === 0x80) { pos--; }
while (pos >= 0 && (buf[pos] & 0xC0) === 0x80) {
pos--;
}
// Very small and broken sequence,
// return max, because we should return something anyway.
if (pos < 0) { return max; }
if (pos < 0) {
return max;
}
// If we came to start of buffer - that means buffer is too small,
// return max too.
if (pos === 0) { return max; }
if (pos === 0) {
return max;
}
return (pos + _utf8len[buf[pos]] > max) ? pos : max;
};
export const strings= {
export const strings = {
utf8border,
buf2string,
binstring2buf,
......
......@@ -24,8 +24,8 @@
// 3. This notice may not be removed or altered from any source distribution.
function adler32(adler, buf, len, pos) {
var s1 = (adler & 0xffff) |0,
s2 = ((adler >>> 16) & 0xffff) |0,
var s1 = (adler & 0xffff) | 0,
s2 = ((adler >>> 16) & 0xffff) | 0,
n = 0;
while (len !== 0) {
......@@ -36,15 +36,15 @@ function adler32(adler, buf, len, pos) {
len -= n;
do {
s1 = (s1 + buf[pos++]) |0;
s2 = (s2 + s1) |0;
s1 = (s1 + buf[pos++]) | 0;
s2 = (s2 + s1) | 0;
} while (--n);
s1 %= 65521;
s2 %= 65521;
}
return (s1 | (s2 << 16)) |0;
return (s1 | (s2 << 16)) | 0;
}
......
......@@ -19,7 +19,7 @@
// misrepresented as being the original software.
// 3. This notice may not be removed or altered from any source distribution.
import { utils } from '../utils/common';
import {utils} from '../utils/common';
import trees from './trees';
import adler32 from './adler32';
......@@ -132,7 +132,12 @@ function rank(f) {
return ((f) << 1) - ((f) > 4 ? 9 : 0);
}
function zero(buf) { var len = buf.length; while (--len >= 0) { buf[len] = 0; } }
function zero(buf) {
var len = buf.length;
while (--len >= 0) {
buf[len] = 0;
}
}
/* =========================================================================
......@@ -149,7 +154,9 @@ function flush_pending(strm) {
if (len > strm.avail_out) {
len = strm.avail_out;
}
if (len === 0) { return; }
if (len === 0) {
return;
}
utils.arraySet(strm.output, s.pending_buf, s.pending_out, len, strm.next_out);
strm.next_out += len;
......@@ -198,8 +205,12 @@ function putShortMSB(s, b) {
function read_buf(strm, buf, start, size) {
var len = strm.avail_in;
if (len > size) { len = size; }
if (len === 0) { return 0; }
if (len > size) {
len = size;
}
if (len === 0) {
return 0;
}
strm.avail_in -= len;
......@@ -207,9 +218,7 @@ function read_buf(strm, buf, start, size) {
utils.arraySet(buf, strm.input, strm.next_in, len, start);
if (strm.state.wrap === 1) {
strm.adler = adler32(strm.adler, buf, len, start);
}
else if (strm.state.wrap === 2) {
} else if (strm.state.wrap === 2) {
strm.adler = crc32(strm.adler, buf, len, start);
}
......@@ -264,7 +273,9 @@ function longest_match(s, cur_match) {
/* Do not look for matches beyond the end of the input. This is necessary
* to make deflate deterministic.
*/
if (nice_match > s.lookahead) { nice_match = s.lookahead; }
if (nice_match > s.lookahead) {
nice_match = s.lookahead;
}
// Assert((ulg)s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead");
......@@ -741,7 +752,9 @@ function deflate_slow(s, flush) {
if (s.lookahead < MIN_LOOKAHEAD && flush === Z_NO_FLUSH) {
return BS_NEED_MORE;
}
if (s.lookahead === 0) { break; } /* flush the current block */
if (s.lookahead === 0) {
break;
} /* flush the current block */
}
/* Insert the string window[strstart .. strstart+2] in the
......@@ -902,7 +915,9 @@ function deflate_rle(s, flush) {
if (s.lookahead <= MAX_MATCH && flush === Z_NO_FLUSH) {
return BS_NEED_MORE;
}
if (s.lookahead === 0) { break; } /* flush the current block */
if (s.lookahead === 0) {
break;
} /* flush the current block */
}
/* See how many times the previous byte repeats */
......@@ -1317,8 +1332,12 @@ function deflateReset(strm) {
function deflateSetHeader(strm, head) {
if (!strm || !strm.state) { return Z_STREAM_ERROR; }
if (strm.state.wrap !== 2) { return Z_STREAM_ERROR; }
if (!strm || !strm.state) {
return Z_STREAM_ERROR;
}
if (strm.state.wrap !== 2) {
return Z_STREAM_ERROR;
}
strm.state.gzhead = head;
return Z_OK;
}
......@@ -1337,9 +1356,7 @@ function deflateInit2(strm, level, method, windowBits, memLevel, strategy) {
if (windowBits < 0) { /* suppress zlib wrapper */
wrap = 0;
windowBits = -windowBits;
}
else if (windowBits > 15) {
} else if (windowBits > 15) {
wrap = 2; /* write gzip wrapper instead */
windowBits -= 16;
}
......@@ -1447,8 +1464,7 @@ function deflate(strm, flush) {
4 : 0));
put_byte(s, OS_CODE);
s.status = BUSY_STATE;
}
else {
} else {
put_byte(s, (s.gzhead.text ? 1 : 0) +
(s.gzhead.hcrc ? 2 : 0) +
(!s.gzhead.extra ? 0 : 4) +
......@@ -1473,8 +1489,7 @@ function deflate(strm, flush) {
s.gzindex = 0;
s.status = EXTRA_STATE;
}
}
else // DEFLATE header
} else // DEFLATE header
{
var header = (Z_DEFLATED + ((s.w_bits - 8) << 4)) << 8;
var level_flags = -1;
......@@ -1489,7 +1504,9 @@ function deflate(strm, flush) {
level_flags = 3;
}
header |= (level_flags << 6);
if (s.strstart !== 0) { header |= PRESET_DICT; }
if (s.strstart !== 0) {
header |= PRESET_DICT;
}
header += 31 - (header % 31);
s.status = BUSY_STATE;
......@@ -1530,8 +1547,7 @@ function deflate(strm, flush) {
s.gzindex = 0;
s.status = NAME_STATE;
}
}
else {
} else {
s.status = NAME_STATE;
}
}
......@@ -1568,8 +1584,7 @@ function deflate(strm, flush) {
s.gzindex = 0;
s.status = COMMENT_STATE;
}
}
else {
} else {
s.status = COMMENT_STATE;
}
}
......@@ -1605,8 +1620,7 @@ function deflate(strm, flush) {
if (val === 0) {
s.status = HCRC_STATE;
}
}
else {
} else {
s.status = HCRC_STATE;
}
}
......@@ -1621,8 +1635,7 @@ function deflate(strm, flush) {
strm.adler = 0; //crc32(0L, Z_NULL, 0);
s.status = BUSY_STATE;
}
}
else {
} else {
s.status = BUSY_STATE;
}
}
......@@ -1684,8 +1697,7 @@ function deflate(strm, flush) {
if (bstate === BS_BLOCK_DONE) {
if (flush === Z_PARTIAL_FLUSH) {
trees._tr_align(s);
}
else if (flush !== Z_BLOCK) { /* FULL_FLUSH or SYNC_FLUSH */
} else if (flush !== Z_BLOCK) { /* FULL_FLUSH or SYNC_FLUSH */
trees._tr_stored_block(s, 0, 0, false);
/* For a full flush, this empty block will be recognized
......@@ -1712,8 +1724,12 @@ function deflate(strm, flush) {
//Assert(strm->avail_out > 0, "bug2");
//if (strm.avail_out <= 0) { throw new Error("bug2");}
if (flush !== Z_FINISH) { return Z_OK; }
if (s.wrap <= 0) { return Z_STREAM_END; }
if (flush !== Z_FINISH) {
return Z_OK;
}
if (s.wrap <= 0) {
return Z_STREAM_END;
}
/* Write the trailer */
if (s.wrap === 2) {
......@@ -1725,8 +1741,7 @@ function deflate(strm, flush) {
put_byte(s, (strm.total_in >> 8) & 0xff);
put_byte(s, (strm.total_in >> 16) & 0xff);
put_byte(s, (strm.total_in >> 24) & 0xff);
}
else {
} else {
putShortMSB(s, strm.adler >>> 16);
putShortMSB(s, strm.adler & 0xffff);
}
......@@ -1735,7 +1750,9 @@ function deflate(strm, flush) {
/* If avail_out is zero, the application will call deflate again
* to flush the rest.
*/
if (s.wrap > 0) { s.wrap = -s.wrap; }
if (s.wrap > 0) {
s.wrap = -s.wrap;
}
/* write the trailer only once! */
return s.pending !== 0 ? Z_OK : Z_STREAM_END;
}
......@@ -1851,7 +1868,8 @@ function deflateSetDictionary(strm, dictionary) {
s.wrap = wrap;
return Z_OK;
}
const deflateInfo= 'pako deflate (from Nodeca project)';
const deflateInfo = 'pako deflate (from Nodeca project)';
export default {
deflateInit,
......
......@@ -130,7 +130,7 @@ export default function inflate_fast(strm, start) {
here = lcode[hold & lmask];
dolen:
for (;;) { // Goto emulation
for (; ;) { // Goto emulation
op = here >>> 24/*here.bits*/;
hold >>>= op;
bits -= op;
......@@ -140,8 +140,7 @@ export default function inflate_fast(strm, start) {
// "inflate: literal '%c'\n" :
// "inflate: literal 0x%02x\n", here.val));
output[_out++] = here & 0xffff/*here.val*/;
}
else if (op & 16) { /* length base */
} else if (op & 16) { /* length base */
len = here & 0xffff/*here.val*/;
op &= 15; /* number of extra bits */
if (op) {
......@@ -163,7 +162,7 @@ export default function inflate_fast(strm, start) {
here = dcode[hold & dmask];
dodist:
for (;;) { // goto emulation
for (; ;) { // goto emulation
op = here >>> 24/*here.bits*/;
hold >>>= op;
bits -= op;
......@@ -235,8 +234,7 @@ export default function inflate_fast(strm, start) {
from = _out - dist; /* rest from output */
from_source = output;
}
}
else if (wnext < op) { /* wrap around window */
} else if (wnext < op) { /* wrap around window */
from += wsize + wnext - op;
op -= wnext;
if (op < len) { /* some from end of window */
......@@ -255,8 +253,7 @@ export default function inflate_fast(strm, start) {
from_source = output;
}
}
}
else { /* contiguous in window */
} else { /* contiguous in window */
from += wnext - op;
if (op < len) { /* some from window */
len -= op;
......@@ -279,8 +276,7 @@ export default function inflate_fast(strm, start) {
output[_out++] = from_source[from++];
}
}
}
else {
} else {
from = _out - dist; /* copy direct from output */
do { /* minimum length is three */
output[_out++] = output[from++];
......@@ -295,12 +291,10 @@ export default function inflate_fast(strm, start) {
}
}
}
}
else if ((op & 64) === 0) { /* 2nd level distance code */
} else if ((op & 64) === 0) { /* 2nd level distance code */
here = dcode[(here & 0xffff)/*here.val*/ + (hold & ((1 << op) - 1))];
continue dodist;
}
else {
} else {
strm.msg = 'invalid distance code';
state.mode = BAD;
break top;
......@@ -308,17 +302,14 @@ export default function inflate_fast(strm, start) {
break; // need to emulate goto via "continue"
}
}
else if ((op & 64) === 0) { /* 2nd level length code */
} else if ((op & 64) === 0) { /* 2nd level length code */
here = lcode[(here & 0xffff)/*here.val*/ + (hold & ((1 << op) - 1))];
continue dolen;
}
else if (op & 32) { /* end-of-block */
} else if (op & 32) { /* end-of-block */
//Tracevv((stderr, "inflate: end of block\n"));
state.mode = TYPE;
break top;
}
else {
} else {
strm.msg = 'invalid literal/length code';
state.mode = BAD;
break top;
......
......@@ -19,7 +19,7 @@
// misrepresented as being the original software.
// 3. This notice may not be removed or altered from any source distribution.
import { utils } from '../utils/common';
import {utils} from '../utils/common';
import adler32 from "./adler32"
import crc32 from './crc32';
......@@ -101,7 +101,6 @@ var SYNC = 32; /* looking for synchronization bytes to restart inflate() */
/* ===========================================================================*/
var ENOUGH_LENS = 852;
var ENOUGH_DISTS = 592;
//var ENOUGH = (ENOUGH_LENS+ENOUGH_DISTS);
......@@ -180,7 +179,9 @@ function InflateState() {
function inflateResetKeep(strm) {
var state;
if (!strm || !strm.state) { return Z_STREAM_ERROR; }
if (!strm || !strm.state) {
return Z_STREAM_ERROR;
}
state = strm.state;
strm.total_in = strm.total_out = state.total = 0;
strm.msg = ''; /*Z_NULL*/
......@@ -207,7 +208,9 @@ function inflateResetKeep(strm) {
function inflateReset(strm) {
var state;
if (!strm || !strm.state) { return Z_STREAM_ERROR; }
if (!strm || !strm.state) {
return Z_STREAM_ERROR;
}
state = strm.state;
state.wsize = 0;
state.whave = 0;
......@@ -221,15 +224,16 @@ function inflateReset2(strm, windowBits) {
var state;
/* get the state */
if (!strm || !strm.state) { return Z_STREAM_ERROR; }
if (!strm || !strm.state) {
return Z_STREAM_ERROR;
}
state = strm.state;
/* extract wrap request from windowBits parameter */
if (windowBits < 0) {
wrap = 0;
windowBits = -windowBits;
}
else {
} else {
wrap = (windowBits >> 4) + 1;
if (windowBits < 48) {
windowBits &= 15;
......@@ -254,7 +258,9 @@ function inflateInit2(strm, windowBits) {
var ret;
var state;
if (!strm) { return Z_STREAM_ERROR; }
if (!strm) {
return Z_STREAM_ERROR;
}
//strm.msg = Z_NULL; /* in case we return an error */
state = new InflateState();
......@@ -299,18 +305,28 @@ function fixedtables(state) {
/* literal/length table */
sym = 0;
while (sym < 144) { state.lens[sym++] = 8; }
while (sym < 256) { state.lens[sym++] = 9; }
while (sym < 280) { state.lens[sym++] = 7; }
while (sym < 288) { state.lens[sym++] = 8; }
while (sym < 144) {
state.lens[sym++] = 8;
}
while (sym < 256) {
state.lens[sym++] = 9;
}
while (sym < 280) {
state.lens[sym++] = 7;
}
while (sym < 288) {
state.lens[sym++] = 8;
}
inflate_table(LENS, state.lens, 0, 288, lenfix, 0, state.work, { bits: 9 });
inflate_table(LENS, state.lens, 0, 288, lenfix, 0, state.work, {bits: 9});
/* distance table */
sym = 0;
while (sym < 32) { state.lens[sym++] = 5; }
while (sym < 32) {
state.lens[sym++] = 5;
}
inflate_table(DISTS, state.lens, 0, 32, distfix, 0, state.work, { bits: 5 });
inflate_table(DISTS, state.lens, 0, 32, distfix, 0, state.work, {bits: 5});
/* do this just once */
virgin = false;
......@@ -355,8 +371,7 @@ function updatewindow(strm, src, end, copy) {
utils.arraySet(state.window, src, end - state.wsize, state.wsize, 0);
state.wnext = 0;
state.whave = state.wsize;
}
else {
} else {
dist = state.wsize - state.wnext;
if (dist > copy) {
dist = copy;
......@@ -369,11 +384,14 @@ function updatewindow(strm, src, end, copy) {
utils.arraySet(state.window, src, end - copy, copy, 0);
state.wnext = copy;
state.whave = state.wsize;
}
else {
} else {
state.wnext += dist;
if (state.wnext === state.wsize) { state.wnext = 0; }
if (state.whave < state.wsize) { state.whave += dist; }
if (state.wnext === state.wsize) {
state.wnext = 0;
}
if (state.whave < state.wsize) {
state.whave += dist;
}
}
}
return 0;
......@@ -412,7 +430,9 @@ function inflate(strm, flush) {
}
state = strm.state;
if (state.mode === TYPE) { state.mode = TYPEDO; } /* skip check */
if (state.mode === TYPE) {
state.mode = TYPEDO;
} /* skip check */
//--- LOAD() ---
......@@ -440,7 +460,9 @@ function inflate(strm, flush) {
}
//=== NEEDBITS(16);
while (bits < 16) {
if (have === 0) { break inf_leave; }
if (have === 0) {
break inf_leave;
}
have--;
hold += input[next++] << bits;
bits += 8;
......@@ -483,8 +505,7 @@ function inflate(strm, flush) {
len = (hold & 0x0f)/*BITS(4)*/ + 8;
if (state.wbits === 0) {
state.wbits = len;
}
else if (len > state.wbits) {
} else if (len > state.wbits) {
strm.msg = 'invalid window size';
state.mode = BAD;
break;
......@@ -501,7 +522,9 @@ function inflate(strm, flush) {
case FLAGS:
//=== NEEDBITS(16); */
while (bits < 16) {
if (have === 0) { break inf_leave; }
if (have === 0) {
break inf_leave;
}
have--;
hold += input[next++] << bits;
bits += 8;
......@@ -537,7 +560,9 @@ function inflate(strm, flush) {
case TIME:
//=== NEEDBITS(32); */
while (bits < 32) {
if (have === 0) { break inf_leave; }
if (have === 0) {
break inf_leave;
}
have--;
hold += input[next++] << bits;
bits += 8;
......@@ -564,7 +589,9 @@ function inflate(strm, flush) {
case OS:
//=== NEEDBITS(16); */
while (bits < 16) {
if (have === 0) { break inf_leave; }
if (have === 0) {
break inf_leave;
}
have--;
hold += input[next++] << bits;
bits += 8;
......@@ -591,7 +618,9 @@ function inflate(strm, flush) {
if (state.flags & 0x0400) {
//=== NEEDBITS(16); */
while (bits < 16) {
if (have === 0) { break inf_leave; }
if (have === 0) {
break inf_leave;
}
have--;
hold += input[next++] << bits;
bits += 8;
......@@ -612,8 +641,7 @@ function inflate(strm, flush) {
hold = 0;
bits = 0;
//===//
}
else if (state.head) {
} else if (state.head) {
state.head.extra = null/*Z_NULL*/;
}
state.mode = EXTRA;
......@@ -621,7 +649,9 @@ function inflate(strm, flush) {
case EXTRA:
if (state.flags & 0x0400) {
copy = state.length;
if (copy > have) { copy = have; }
if (copy > have) {
copy = have;
}
if (copy) {
if (state.head) {
len = state.head.extra_len - state.length;
......@@ -650,14 +680,18 @@ function inflate(strm, flush) {
next += copy;
state.length -= copy;
}
if (state.length) { break inf_leave; }
if (state.length) {
break inf_leave;
}
}
state.length = 0;
state.mode = NAME;
/* falls through */
case NAME:
if (state.flags & 0x0800) {
if (have === 0) { break inf_leave; }
if (have === 0) {
break inf_leave;
}
copy = 0;
do {
// TODO: 2 or 1 bytes?
......@@ -674,9 +708,10 @@ function inflate(strm, flush) {
}
have -= copy;
next += copy;
if (len) { break inf_leave; }
if (len) {
break inf_leave;
}
else if (state.head) {
} else if (state.head) {
state.head.name = null;
}
state.length = 0;
......@@ -684,7 +719,9 @@ function inflate(strm, flush) {
/* falls through */
case COMMENT:
if (state.flags & 0x1000) {
if (have === 0) { break inf_leave; }
if (have === 0) {
break inf_leave;
}
copy = 0;
do {
len = input[next + copy++];
......@@ -699,9 +736,10 @@ function inflate(strm, flush) {
}
have -= copy;
next += copy;
if (len) { break inf_leave; }
if (len) {
break inf_leave;
}
else if (state.head) {
} else if (state.head) {
state.head.comment = null;
}
state.mode = HCRC;
......@@ -710,7 +748,9 @@ function inflate(strm, flush) {
if (state.flags & 0x0200) {
//=== NEEDBITS(16); */
while (bits < 16) {
if (have === 0) { break inf_leave; }
if (have === 0) {
break inf_leave;
}
have--;
hold += input[next++] << bits;
bits += 8;
......@@ -736,7 +776,9 @@ function inflate(strm, flush) {
case DICTID:
//=== NEEDBITS(32); */
while (bits < 32) {
if (have === 0) { break inf_leave; }
if (have === 0) {
break inf_leave;
}
have--;
hold += input[next++] << bits;
bits += 8;
......@@ -765,7 +807,9 @@ function inflate(strm, flush) {
state.mode = TYPE;
/* falls through */
case TYPE:
if (flush === Z_BLOCK || flush === Z_TREES) { break inf_leave; }
if (flush === Z_BLOCK || flush === Z_TREES) {
break inf_leave;
}
/* falls through */
case TYPEDO:
if (state.last) {
......@@ -778,7 +822,9 @@ function inflate(strm, flush) {
}
//=== NEEDBITS(3); */
while (bits < 3) {
if (have === 0) { break inf_leave; }
if (have === 0) {
break inf_leave;
}
have--;
hold += input[next++] << bits;
bits += 8;
......@@ -830,7 +876,9 @@ function inflate(strm, flush) {
//---//
//=== NEEDBITS(32); */
while (bits < 32) {
if (have === 0) { break inf_leave; }
if (have === 0) {
break inf_leave;
}
have--;
hold += input[next++] << bits;
bits += 8;
......@@ -849,7 +897,9 @@ function inflate(strm, flush) {
bits = 0;
//===//
state.mode = COPY_;
if (flush === Z_TREES) { break inf_leave; }
if (flush === Z_TREES) {
break inf_leave;
}
/* falls through */
case COPY_:
state.mode = COPY;
......@@ -857,9 +907,15 @@ function inflate(strm, flush) {
case COPY:
copy = state.length;
if (copy) {
if (copy > have) { copy = have; }
if (copy > left) { copy = left; }
if (copy === 0) { break inf_leave; }
if (copy > have) {
copy = have;
}
if (copy > left) {
copy = left;
}
if (copy === 0) {
break inf_leave;
}
//--- zmemcpy(put, next, copy); ---
utils.arraySet(output, input, next, copy, put);
//---//
......@@ -876,7 +932,9 @@ function inflate(strm, flush) {
case TABLE:
//=== NEEDBITS(14); */
while (bits < 14) {
if (have === 0) { break inf_leave; }
if (have === 0) {
break inf_leave;
}
have--;
hold += input[next++] << bits;
bits += 8;
......@@ -912,7 +970,9 @@ function inflate(strm, flush) {
while (state.have < state.ncode) {
//=== NEEDBITS(3);
while (bits < 3) {
if (have === 0) { break inf_leave; }
if (have === 0) {
break inf_leave;
}
have--;
hold += input[next++] << bits;
bits += 8;
......@@ -934,7 +994,7 @@ function inflate(strm, flush) {
state.lencode = state.lendyn;
state.lenbits = 7;
opts = { bits: state.lenbits };
opts = {bits: state.lenbits};
ret = inflate_table(CODES, state.lens, 0, 19, state.lencode, 0, state.work, opts);
state.lenbits = opts.bits;
......@@ -955,9 +1015,13 @@ function inflate(strm, flush) {
here_op = (here >>> 16) & 0xff;
here_val = here & 0xffff;
if ((here_bits) <= bits) { break; }
if ((here_bits) <= bits) {
break;
}
//--- PULLBYTE() ---//
if (have === 0) { break inf_leave; }
if (have === 0) {
break inf_leave;
}
have--;
hold += input[next++] << bits;
bits += 8;
......@@ -969,13 +1033,14 @@ function inflate(strm, flush) {
bits -= here_bits;
//---//
state.lens[state.have++] = here_val;
}
else {
} else {
if (here_val === 16) {
//=== NEEDBITS(here.bits + 2);
n = here_bits + 2;
while (bits < n) {
if (have === 0) { break inf_leave; }
if (have === 0) {
break inf_leave;
}
have--;
hold += input[next++] << bits;
bits += 8;
......@@ -996,12 +1061,13 @@ function inflate(strm, flush) {
hold >>>= 2;
bits -= 2;
//---//
}
else if (here_val === 17) {
} else if (here_val === 17) {
//=== NEEDBITS(here.bits + 3);
n = here_bits + 3;
while (bits < n) {
if (have === 0) { break inf_leave; }
if (have === 0) {
break inf_leave;
}
have--;
hold += input[next++] << bits;
bits += 8;
......@@ -1017,12 +1083,13 @@ function inflate(strm, flush) {
hold >>>= 3;
bits -= 3;
//---//
}
else {
} else {
//=== NEEDBITS(here.bits + 7);
n = here_bits + 7;
while (bits < n) {
if (have === 0) { break inf_leave; }
if (have === 0) {
break inf_leave;
}
have--;
hold += input[next++] << bits;
bits += 8;
......@@ -1051,7 +1118,9 @@ function inflate(strm, flush) {
}
/* handle error breaks in while */
if (state.mode === BAD) { break; }
if (state.mode === BAD) {
break;
}
/* check for end-of-block code (better have one) */
if (state.lens[256] === 0) {
......@@ -1065,7 +1134,7 @@ function inflate(strm, flush) {
concerning the ENOUGH constants, which depend on those values */
state.lenbits = 9;
opts = { bits: state.lenbits };
opts = {bits: state.lenbits};
ret = inflate_table(LENS, state.lens, 0, state.nlen, state.lencode, 0, state.work, opts);
// We have separate tables & no pointers. 2 commented lines below not needed.
// state.next_index = opts.table_index;
......@@ -1082,7 +1151,7 @@ function inflate(strm, flush) {
//state.distcode.copy(state.codes);
// Switch to use dynamic table
state.distcode = state.distdyn;
opts = { bits: state.distbits };
opts = {bits: state.distbits};
ret = inflate_table(DISTS, state.lens, state.nlen, state.ndist, state.distcode, 0, state.work, opts);
// We have separate tables & no pointers. 2 commented lines below not needed.
// state.next_index = opts.table_index;
......@@ -1096,7 +1165,9 @@ function inflate(strm, flush) {
}
//Tracev((stderr, 'inflate: codes ok\n'));
state.mode = LEN_;
if (flush === Z_TREES) { break inf_leave; }
if (flush === Z_TREES) {
break inf_leave;
}
/* falls through */
case LEN_:
state.mode = LEN;
......@@ -1135,9 +1206,13 @@ function inflate(strm, flush) {
here_op = (here >>> 16) & 0xff;
here_val = here & 0xffff;
if (here_bits <= bits) { break; }
if (here_bits <= bits) {
break;
}
//--- PULLBYTE() ---//
if (have === 0) { break inf_leave; }
if (have === 0) {
break inf_leave;
}
have--;
hold += input[next++] << bits;
bits += 8;
......@@ -1154,9 +1229,13 @@ function inflate(strm, flush) {
here_op = (here >>> 16) & 0xff;
here_val = here & 0xffff;
if ((last_bits + here_bits) <= bits) { break; }
if ((last_bits + here_bits) <= bits) {
break;
}
//--- PULLBYTE() ---//
if (have === 0) { break inf_leave; }
if (have === 0) {
break inf_leave;
}
have--;
hold += input[next++] << bits;
bits += 8;
......@@ -1200,7 +1279,9 @@ function inflate(strm, flush) {
//=== NEEDBITS(state.extra);
n = state.extra;
while (bits < n) {
if (have === 0) { break inf_leave; }
if (have === 0) {
break inf_leave;
}
have--;
hold += input[next++] << bits;
bits += 8;
......@@ -1224,9 +1305,13 @@ function inflate(strm, flush) {
here_op = (here >>> 16) & 0xff;
here_val = here & 0xffff;
if ((here_bits) <= bits) { break; }
if ((here_bits) <= bits) {
break;
}
//--- PULLBYTE() ---//
if (have === 0) { break inf_leave; }
if (have === 0) {
break inf_leave;
}
have--;
hold += input[next++] << bits;
bits += 8;
......@@ -1243,9 +1328,13 @@ function inflate(strm, flush) {
here_op = (here >>> 16) & 0xff;
here_val = here & 0xffff;
if ((last_bits + here_bits) <= bits) { break; }
if ((last_bits + here_bits) <= bits) {
break;
}
//--- PULLBYTE() ---//
if (have === 0) { break inf_leave; }
if (have === 0) {
break inf_leave;
}
have--;
hold += input[next++] << bits;
bits += 8;
......@@ -1276,7 +1365,9 @@ function inflate(strm, flush) {
//=== NEEDBITS(state.extra);
n = state.extra;
while (bits < n) {
if (have === 0) { break inf_leave; }
if (have === 0) {
break inf_leave;
}
have--;
hold += input[next++] << bits;
bits += 8;
......@@ -1300,7 +1391,9 @@ function inflate(strm, flush) {
state.mode = MATCH;
/* falls through */
case MATCH:
if (left === 0) { break inf_leave; }
if (left === 0) {
break inf_leave;
}
copy = _out - left;
if (state.offset > copy) { /* copy from window */
copy = state.offset - copy;
......@@ -1329,28 +1422,34 @@ function inflate(strm, flush) {
if (copy > state.wnext) {
copy -= state.wnext;
from = state.wsize - copy;
}
else {
} else {
from = state.wnext - copy;
}
if (copy > state.length) { copy = state.length; }
from_source = state.window;
if (copy > state.length) {
copy = state.length;
}
else { /* copy from output */
from_source = state.window;
} else { /* copy from output */
from_source = output;
from = put - state.offset;
copy = state.length;
}
if (copy > left) { copy = left; }
if (copy > left) {
copy = left;
}
left -= copy;
state.length -= copy;
do {
output[put++] = from_source[from++];
} while (--copy);
if (state.length === 0) { state.mode = LEN; }
if (state.length === 0) {
state.mode = LEN;
}
break;
case LIT:
if (left === 0) { break inf_leave; }
if (left === 0) {
break inf_leave;
}
output[put++] = state.length;
left--;
state.mode = LEN;
......@@ -1359,7 +1458,9 @@ function inflate(strm, flush) {
if (state.wrap) {
//=== NEEDBITS(32);
while (bits < 32) {
if (have === 0) { break inf_leave; }
if (have === 0) {
break inf_leave;
}
have--;
// Use '|' instead of '+' to make sure that result is signed
hold |= input[next++] << bits;
......@@ -1394,7 +1495,9 @@ function inflate(strm, flush) {
if (state.wrap && state.flags) {
//=== NEEDBITS(32);
while (bits < 32) {
if (have === 0) { break inf_leave; }
if (have === 0) {
break inf_leave;
}
have--;
hold += input[next++] << bits;
bits += 8;
......@@ -1489,9 +1592,13 @@ function inflateGetHeader(strm, head) {
var state;
/* check state */
if (!strm || !strm.state) { return Z_STREAM_ERROR; }
if (!strm || !strm.state) {
return Z_STREAM_ERROR;
}
state = strm.state;
if ((state.wrap & 2) === 0) { return Z_STREAM_ERROR; }
if ((state.wrap & 2) === 0) {
return Z_STREAM_ERROR;
}
/* save header structure */
state.head = head;
......@@ -1507,7 +1614,9 @@ function inflateSetDictionary(strm, dictionary) {
var ret;
/* check state */
if (!strm /* == Z_NULL */ || !strm.state /* == Z_NULL */) { return Z_STREAM_ERROR; }
if (!strm /* == Z_NULL */ || !strm.state /* == Z_NULL */) {
return Z_STREAM_ERROR;
}
state = strm.state;
if (state.wrap !== 0 && state.mode !== DICT) {
......@@ -1534,6 +1643,7 @@ function inflateSetDictionary(strm, dictionary) {
// Tracev((stderr, "inflate: dictionary set\n"));
return Z_OK;
}
const inflateInfo = 'pako inflate (from Nodeca project)';
export default {
inflateReset,
......
......@@ -19,7 +19,7 @@
// misrepresented as being the original software.
// 3. This notice may not be removed or altered from any source distribution.
import { utils } from '../utils/common';
import {utils} from '../utils/common';
var MAXBITS = 15;
var ENOUGH_LENS = 852;
......@@ -123,7 +123,9 @@ export default function inflate_table(type, lens, lens_index, codes, table, tabl
/* bound code lengths, force root to be within code lengths */
root = bits;
for (max = MAXBITS; max >= 1; max--) {
if (count[max] !== 0) { break; }
if (count[max] !== 0) {
break;
}
}
if (root > max) {
root = max;
......@@ -144,7 +146,9 @@ export default function inflate_table(type, lens, lens_index, codes, table, tabl
return 0; /* no symbols, but wait for decoding to report error */
}
for (min = 1; min < max; min++) {
if (count[min] !== 0) { break; }
if (count[min] !== 0) {
break;
}
}
if (root < min) {
root = min;
......@@ -251,12 +255,10 @@ export default function inflate_table(type, lens, lens_index, codes, table, tabl
if (work[sym] < end) {
here_op = 0;
here_val = work[sym];
}
else if (work[sym] > end) {
} else if (work[sym] > end) {
here_op = extra[extra_index + work[sym]];
here_val = base[base_index + work[sym]];
}
else {
} else {
here_op = 32 + 64; /* end of block */
here_val = 0;
}
......@@ -285,7 +287,9 @@ export default function inflate_table(type, lens, lens_index, codes, table, tabl
/* go to next symbol, update count, len */
sym++;
if (--count[len] === 0) {
if (len === max) { break; }
if (len === max) {
break;
}
len = lens[lens_index + work[sym]];
}
......@@ -304,7 +308,9 @@ export default function inflate_table(type, lens, lens_index, codes, table, tabl
left = 1 << curr;
while (curr + drop < max) {
left -= count[curr + drop];
if (left <= 0) { break; }
if (left <= 0) {
break;
}
curr++;
left <<= 1;
}
......
......@@ -21,7 +21,7 @@
/* eslint-disable space-unary-ops */
import { utils } from '../utils/common';
import {utils} from '../utils/common';
/* Public constants ==========================================================*/
/* ===========================================================================*/
......@@ -42,7 +42,12 @@ var Z_UNKNOWN = 2;
/*============================================================================*/
function zero(buf) { var len = buf.length; while (--len >= 0) { buf[len] = 0; } }
function zero(buf) {
var len = buf.length;
while (--len >= 0) {
buf[len] = 0;
}
}
// From zutil.h
......@@ -106,16 +111,16 @@ var REPZ_11_138 = 18;
/* eslint-disable comma-spacing,array-bracket-spacing */
var extra_lbits = /* extra bits for each length code */
[0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0];
[0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0];
var extra_dbits = /* extra bits for each distance code */
[0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13];
[0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13];
var extra_blbits = /* extra bits for each bit length code */
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7];
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 3, 7];
var bl_order =
[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15];
[16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15];
/* eslint-enable comma-spacing,array-bracket-spacing */
/* The lengths of the bit length codes are sent in order of decreasing
......@@ -162,6 +167,7 @@ zero(base_length);
var base_dist = new Array(D_CODES);
zero(base_dist);
/* First normalized distance for each code (0 = distance of 1) */
......@@ -190,7 +196,6 @@ function TreeDesc(dyn_tree, stat_desc) {
}
function d_code(dist) {
return dist < 256 ? _dist_code[dist] : _dist_code[256 + (dist >>> 7)];
}
......@@ -310,7 +315,9 @@ function gen_bitlen(s, desc)
tree[n * 2 + 1]/*.Len*/ = bits;
/* We overwrite tree[n].Dad which is no longer needed */
if (n > max_code) { continue; } /* not a leaf node */
if (n > max_code) {
continue;
} /* not a leaf node */
s.bl_count[bits]++;
xbits = 0;
......@@ -323,7 +330,9 @@ function gen_bitlen(s, desc)
s.static_len += f * (stree[n * 2 + 1]/*.Len*/ + xbits);
}
}
if (overflow === 0) { return; }
if (overflow === 0) {
return;
}
// Trace((stderr,"\nbit length overflow\n"));
/* This happens for example on obj2 and pic of the Calgary corpus */
......@@ -331,7 +340,9 @@ function gen_bitlen(s, desc)
/* Find the first bit length which could increase: */
do {
bits = max_length - 1;
while (s.bl_count[bits] === 0) { bits--; }
while (s.bl_count[bits] === 0) {
bits--;
}
s.bl_count[bits]--; /* move one leaf down the tree */
s.bl_count[bits + 1] += 2; /* move one overflow item as its brother */
s.bl_count[max_length]--;
......@@ -350,7 +361,9 @@ function gen_bitlen(s, desc)
n = s.bl_count[bits];
while (n !== 0) {
m = s.heap[--h];
if (m > max_code) { continue; }
if (m > max_code) {
continue;
}
if (tree[m * 2 + 1]/*.Len*/ !== bits) {
// Trace((stderr,"code %d bits %d->%d\n", m, tree[m].Len, bits));
s.opt_len += (bits - tree[m * 2 + 1]/*.Len*/) * tree[m * 2]/*.Freq*/;
......@@ -395,7 +408,9 @@ function gen_codes(tree, max_code, bl_count)
for (n = 0; n <= max_code; n++) {
var len = tree[n * 2 + 1]/*.Len*/;
if (len === 0) { continue; }
if (len === 0) {
continue;
}
/* Now reverse the bits */
tree[n * 2]/*.Code*/ = bi_reverse(next_code[len]++, len);
......@@ -421,13 +436,13 @@ function tr_static_init() {
//if (static_init_done) return;
/* For some embedded targets, global variables are not initialized: */
/*#ifdef NO_INIT_GLOBAL_POINTERS
/*#ifdef NO_INIT_GLOBAL_POINTERS
static_l_desc.static_tree = static_ltree;
static_l_desc.extra_bits = extra_lbits;
static_d_desc.static_tree = static_dtree;
static_d_desc.extra_bits = extra_dbits;
static_bl_desc.extra_bits = extra_blbits;
#endif*/
#endif*/
/* Initialize the mapping length (0..255) -> length code (0..28) */
length = 0;
......@@ -516,9 +531,15 @@ function init_block(s) {
var n; /* iterates over tree elements */
/* Initialize the trees. */
for (n = 0; n < L_CODES; n++) { s.dyn_ltree[n * 2]/*.Freq*/ = 0; }
for (n = 0; n < D_CODES; n++) { s.dyn_dtree[n * 2]/*.Freq*/ = 0; }
for (n = 0; n < BL_CODES; n++) { s.bl_tree[n * 2]/*.Freq*/ = 0; }
for (n = 0; n < L_CODES; n++) {
s.dyn_ltree[n * 2]/*.Freq*/ = 0;
}
for (n = 0; n < D_CODES; n++) {
s.dyn_dtree[n * 2]/*.Freq*/ = 0;
}
for (n = 0; n < BL_CODES; n++) {
s.bl_tree[n * 2]/*.Freq*/ = 0;
}
s.dyn_ltree[END_BLOCK * 2]/*.Freq*/ = 1;
s.opt_len = s.static_len = 0;
......@@ -529,8 +550,7 @@ function init_block(s) {
/* ===========================================================================
* Flush the bit buffer and align the output on a byte boundary
*/
function bi_windup(s)
{
function bi_windup(s) {
if (s.bi_valid > 8) {
put_short(s, s.bi_buf);
} else if (s.bi_valid > 0) {
......@@ -595,7 +615,9 @@ function pqdownheap(s, tree, k)
j++;
}
/* Exit if v is smaller than both sons */
if (smaller(tree, v, s.heap[j], s.depth)) { break; }
if (smaller(tree, v, s.heap[j], s.depth)) {
break;
}
/* Exchange v with the smallest son */
s.heap[k] = s.heap[j];
......@@ -724,7 +746,9 @@ function build_tree(s, desc)
/* The elements heap[heap_len/2+1 .. heap_len] are leaves of the tree,
* establish sub-heaps of increasing lengths:
*/
for (n = (s.heap_len >> 1/*int /2*/); n >= 1; n--) { pqdownheap(s, tree, n); }
for (n = (s.heap_len >> 1/*int /2*/); n >= 1; n--) {
pqdownheap(s, tree, n);
}
/* Construct the Huffman tree by repeatedly combining the least two
* frequent nodes.
......@@ -803,7 +827,9 @@ function scan_tree(s, tree, max_code)
} else if (curlen !== 0) {
if (curlen !== prevlen) { s.bl_tree[curlen * 2]/*.Freq*/++; }
if (curlen !== prevlen) {
s.bl_tree[curlen * 2]/*.Freq*/++;
}
s.bl_tree[REP_3_6 * 2]/*.Freq*/++;
} else if (count <= 10) {
......@@ -865,7 +891,9 @@ function send_tree(s, tree, max_code)
continue;
} else if (count < min_count) {
do { send_code(s, curlen, s.bl_tree); } while (--count !== 0);
do {
send_code(s, curlen, s.bl_tree);
} while (--count !== 0);
} else if (curlen !== 0) {
if (curlen !== prevlen) {
......@@ -1021,8 +1049,7 @@ var static_init_done = false;
/* ===========================================================================
* Initialize the tree data structures for a new zlib stream.
*/
function _tr_init(s)
{
function _tr_init(s) {
if (!static_init_done) {
tr_static_init();
......@@ -1112,7 +1139,9 @@ function _tr_flush_block(s, buf, stored_len, last)
// opt_lenb, s->opt_len, static_lenb, s->static_len, stored_len,
// s->last_lit));
if (static_lenb <= opt_lenb) { opt_lenb = static_lenb; }
if (static_lenb <= opt_lenb) {
opt_lenb = static_lenb;
}
} else {
// Assert(buf != (char*)0, "lost buf");
......@@ -1214,6 +1243,7 @@ function _tr_tally(s, dist, lc)
* 64K-1 bytes.
*/
}
export default {
_tr_init,
_tr_stored_block,
......
import { VideoEntity } from './VideoEntity'
import {VideoEntity} from './VideoEntity'
import MockWorker from './mockWorker'
export class Parser {
......
import { BezierPath } from './bezierPath'
import {BezierPath} from './bezierPath'
export class RectPath extends BezierPath {
......
import { FrameEntity } from './frameEntity'
import { BezierPath } from './bezierPath'
import { RectPath } from './rectPath'
import { EllipsePath } from './ellipsePath'
import {FrameEntity} from './frameEntity'
export class SpriteEntity {
......
import { osType, TEXT_lINETYPE, devicePixelRatio, TEXT_ALIGN } from "../const";
import { Event } from "../events/Event";
import { MouseEvent } from "../events/MouseEvent";
import { FloatDisplay } from "../display/FloatDisplay";
import { TextField } from "./TextField";
import { InputText } from "./InputText";
import {devicePixelRatio, TEXT_ALIGN} from "../const";
import {Event} from "../events/Event";
import {MouseEvent} from "../events/MouseEvent";
import {TextField} from "./TextField";
import {InputText} from "./InputText";
/**
* 可编辑文本,继承TextFieldNode
......@@ -21,6 +20,7 @@ export class EditableText extends TextField {
get prompt() {
return this._prompt
}
set prompt(value: string) {
if (this._prompt != value) {
this._prompt = value;
......@@ -31,10 +31,12 @@ export class EditableText extends TextField {
}
}
}
private _promptColor: string = "#eeeeee";
get promptColor() {
return this._promptColor
}
set promptColor(value: string) {
if (this._promptColor != value) {
this._promptColor = value;
......@@ -50,6 +52,7 @@ export class EditableText extends TextField {
get textColor() {
return this._textColor
}
set textColor(value: string) {
if (this._textColor != value) {
this._textColor = value;
......
import { osType, TEXT_lINETYPE } from "../const";
import { Event } from "../events/Event";
import { MouseEvent } from "../events/MouseEvent";
import { FloatDisplay } from "../display/FloatDisplay";
import { TextField } from "./TextField";
import {osType, TEXT_lINETYPE} from "../const";
import {Event} from "../events/Event";
import {MouseEvent} from "../events/MouseEvent";
import {FloatDisplay} from "../display/FloatDisplay";
import {TextField} from "./TextField";
/**
* 输入文本,待测试
......@@ -42,6 +42,7 @@ export class InputText extends FloatDisplay {
* @since 2.0.0
*/
private static _inputTypeList: Array<string> = ["input", "password", "textarea"];
/**
* @method InputText
* @public
......@@ -97,6 +98,7 @@ export class InputText extends FloatDisplay {
s.htmlElement.style.borderWidth = "thin";
s.htmlElement.style.borderColor = "#000";
}
/**
* 被始化输入文件的一些属性
* @method initInfo
......@@ -145,9 +147,11 @@ export class InputText extends FloatDisplay {
public set lineSpacing(value: number) {
this.htmlElement.style.lineHeight = value + "px";
}
public get lineSpacing(): number {
return parseInt(this.htmlElement.style.lineHeight);
}
/**
* 设置文本是否为粗体
* @property bold
......@@ -187,6 +191,7 @@ export class InputText extends FloatDisplay {
public get italic(): boolean {
return this.htmlElement.style.fontStyle == "italic"
}
/**
* 文本的行高
* @property textHeight
......@@ -202,6 +207,7 @@ export class InputText extends FloatDisplay {
public get textHeight(): number {
return parseInt(this.htmlElement.style.height);
}
/**
* 文本的宽
* @property textWidth
......@@ -217,6 +223,7 @@ export class InputText extends FloatDisplay {
public get textWidth(): number {
return parseInt(this.htmlElement.style.width);
}
/**
* 设置文本颜色
* @property color
......@@ -292,6 +299,7 @@ export class InputText extends FloatDisplay {
return l;
}
}
public set maxCharacters(value: number) {
this.htmlElement.setAttribute("maxlength", value);
}
......
import { SCALE_MODES, TEXT_ALIGN, TEXT_lINETYPE, VERTICAL_ALIGN } from "../const";
import {SCALE_MODES, TEXT_ALIGN, TEXT_lINETYPE, VERTICAL_ALIGN} from "../const";
import Texture from "../texture/Texture";
import { getRGBA } from "../utils";
import { Rectangle } from "../math";
import {getRGBA} from "../utils";
import {Rectangle} from "../math";
import Sprite from "../display/Sprite";
//文本canvas上xy的偏移量
const padding = 10;
/**
*
* 继承Sprite,暂时发现,只需要切换bitmap和Sprite,TextField永远都是最新的,到时替换
......@@ -26,6 +27,7 @@ export class TextField extends Sprite {
offsetX: number;
offsetY: number;
constructor() {
super();
this._instanceType = "TextFieldNode";
......@@ -59,6 +61,7 @@ export class TextField extends Sprite {
public get textAlpha(): number {
return this._textAlpha;
}
private _textAlpha: number = 1;
/**
......@@ -80,6 +83,7 @@ export class TextField extends Sprite {
public get textAlign(): TEXT_ALIGN {
return this._textAlign;
}
private _textAlign: TEXT_ALIGN = TEXT_ALIGN.LEFT;
/**
......@@ -96,6 +100,7 @@ export class TextField extends Sprite {
public get verticalAlign(): VERTICAL_ALIGN {
return this._verticalAlign;
}
private _verticalAlign: VERTICAL_ALIGN = VERTICAL_ALIGN.UP;
/**
......@@ -110,8 +115,10 @@ export class TextField extends Sprite {
if (this._textWidth != value) {
this._textWidth = value;
this.dirty = true;
};
}
;
}
public get textWidth(): number {
if (this._textWidth) {
//有就这个
......@@ -122,6 +129,7 @@ export class TextField extends Sprite {
return this.width - padding * 2;
}
}
private _textWidth: number = 0;
/**
......@@ -150,6 +158,7 @@ export class TextField extends Sprite {
return this.height - padding * 2
}
}
private _textHeight: number = 0;
/**
......@@ -163,11 +172,14 @@ export class TextField extends Sprite {
if (this._lineSpacing != value) {
this._lineSpacing = value;
this.dirty = true;
};
}
;
}
public get lineSpacing(): number {
return this._lineSpacing;
}
private _lineSpacing: number = 14;
/**
......@@ -182,12 +194,16 @@ export class TextField extends Sprite {
if (this._lineType != value) {
this._lineType = value;
this.dirty = true;
};
}
;
}
public get lineType(): TEXT_lINETYPE {
return this._lineType;
}
private _lineType: TEXT_lINETYPE = TEXT_lINETYPE.SINGLE;
/**
* 文本内容
* @property text
......@@ -200,13 +216,16 @@ export class TextField extends Sprite {
if (this._text != value) {
this._text = value;
this.dirty = true;
};
}
;
}
public get text(): string {
return this._text;
}
private _text: string = "";
/**
* 文本的css字体样式
* @property font
......@@ -219,13 +238,16 @@ export class TextField extends Sprite {
if (this._font != value) {
this._font = value;
this.dirty = true;
};
}
;
}
public get font(): string {
return this._font;
}
private _font: string = "Arial";
/**
* 文本的size
* @property size
......@@ -238,13 +260,16 @@ export class TextField extends Sprite {
if (this._size != value) {
this._size = value;
this.dirty = true;
};
}
;
}
public get size(): number {
return this._size;
}
private _size: number = 12;
/**
* 文本的填充颜色值
* @property fillColor
......@@ -257,12 +282,14 @@ export class TextField extends Sprite {
if (this._fillColor != value) {
this._fillColor = value;
this.dirty = true;
};
}
;
}
public get fillColor(): string {
return this._fillColor;
}
private _fillColor: string = "#ffffff";
/**
......@@ -277,13 +304,16 @@ export class TextField extends Sprite {
if (this._strokeColor != value) {
this._strokeColor = value;
this.dirty = true;
};
}
;
}
public get strokeColor(): string {
return this._strokeColor;
}
private _strokeColor: string = "#ffffff";
/**
* 文本描边宽度,为0则不描边
* @property stroke
......@@ -296,12 +326,14 @@ export class TextField extends Sprite {
if (this._stroke != value) {
this._stroke = value;
this.dirty = true;
};
}
;
}
public get stroke(): number {
return this._stroke;
}
private _stroke: number = 0;
/**
......@@ -316,13 +348,16 @@ export class TextField extends Sprite {
if (this._italic != value) {
this._italic = value;
this.dirty = true;
};
}
;
}
public get italic(): boolean {
return this._italic;
}
private _italic: boolean = false;
/**
* 文本是否加粗
* @property bold
......@@ -335,12 +370,16 @@ export class TextField extends Sprite {
if (this._bold != value) {
this._bold = value;
this.dirty = true;
};
}
;
}
public get bold(): boolean {
return this._bold;
}
public _bold: boolean = false;
/**
* 设置或获取是否有边框
* @property property
......@@ -352,12 +391,14 @@ export class TextField extends Sprite {
if (this._border != value) {
this._border = value;
this.dirty = true;
};
}
;
}
public get border(): boolean {
return this._border;
}
private _border: boolean = false;
/**
......@@ -385,6 +426,7 @@ export class TextField extends Sprite {
ctx.textBaseline = "top";
ctx.fillStyle = getRGBA(s._fillColor, s._textAlpha)
}
/**
* 获取当前文本中单行文字的宽,注意是文字的不是文本框的宽
* @method getTextWidth
......@@ -401,6 +443,7 @@ export class TextField extends Sprite {
let obj: any = ctx.measureText(s.realLines[lineIndex]);
return obj.width;
}
/**
* @property _lines 获取当前文本行数
* @type {number}
......@@ -411,6 +454,7 @@ export class TextField extends Sprite {
get lines(): number {
return this.realLines.length;
}
/**
* 获取文本宽
* @method _getMeasuredWidth
......@@ -426,7 +470,9 @@ export class TextField extends Sprite {
//ctx.restore();
return w;
}
private realLines: any = [];
/**
* 更新文本,主要重画canvas
*/
......@@ -437,7 +483,7 @@ export class TextField extends Sprite {
s.canvas.width = 0;
s.canvas.height = 0;
s._localBoundsSelf.clear();
this.anchorTexture = { x: 0, y: 0 };
this.anchorTexture = {x: 0, y: 0};
this.updateTexture();
return
}
......@@ -552,7 +598,7 @@ export class TextField extends Sprite {
s.offsetX = -padding;
s.offsetY = -padding;
this.anchorTexture = { x: (padding + 0.5) / can.width, y: padding / can.height }
this.anchorTexture = {x: (padding + 0.5) / can.width, y: padding / can.height}
// document.body.appendChild(can)
// s._bounds.height = maxH;
......@@ -563,6 +609,7 @@ export class TextField extends Sprite {
//修改texture及baseTexture属性
s.updateTexture()
}
/**
* 更新texture及baseTexture属性
* 不考虑trim,
......@@ -584,11 +631,11 @@ export class TextField extends Sprite {
}
_renderCanvas(renderer) {
this.updateText();
super._renderCanvas(renderer);
}
_renderWebGL(renderer) {
this.updateText();
super._renderWebGL(renderer)
......
export { TextField } from "./TextField";
export { InputText } from "./InputText";
export { EditableText } from "./EditableText";
\ No newline at end of file
export {TextField} from "./TextField";
export {InputText} from "./InputText";
export {EditableText} from "./EditableText";
\ No newline at end of file
import BaseTexture from './BaseTexture';
import { SCALE_MODES } from '../const';
import {SCALE_MODES} from '../const';
/**
* 将显示对象画在上面的贴图
......@@ -59,6 +59,7 @@ export default class BaseRenderTexture extends BaseTexture {
* This will let the renderer know if the texture is valid. If it's not then it cannot be rendered.
*/
valid: boolean;
/**
* @param {number} [width=100] - The width of the base render texture
* @param {number} [height=100] - The height of the base render texture
......
import { EventDispatcher } from '../events/EventDispatcher';
import { decomposeDataUri, getUrlFileExtension, isPow2, BaseTextureCache, TextureCache, uid } from '../utils';
import { SCALE_MODES, WRAP_MODES } from "../const"
import {EventDispatcher} from '../events/EventDispatcher';
import {BaseTextureCache, decomposeDataUri, getUrlFileExtension, isPow2, TextureCache, uid} from '../utils';
import {SCALE_MODES, WRAP_MODES} from "../const"
/**
* 每个texture都有一个BaseTexture,多数用于图集,texture可自身设置属性
......@@ -99,6 +99,7 @@ export default class BaseTexture extends EventDispatcher {
* @member {string[]}
*/
textureCacheIds: string[];
/**
* @param {HTMLImageElement|HTMLCanvasElement} [source] - the source object of the texture.
* @param {number} [scaleMode=settings.SCALE_MODE] - possible values
......@@ -246,8 +247,7 @@ export default class BaseTexture extends EventDispatcher {
if (!imageType) {
throw new Error('Invalid image type in data URI.');
}
}
else {
} else {
imageType = getUrlFileExtension(this.imageUrl);
if (!imageType) {
......@@ -257,6 +257,7 @@ export default class BaseTexture extends EventDispatcher {
this.imageType = imageType;
}
/**
* 加载完成后执行
* @private
......@@ -368,8 +369,7 @@ export default class BaseTexture extends EventDispatcher {
if (typeof source === 'string') {
//图片路径
return BaseTexture.fromImage(source, undefined, scaleMode);
}
else if (source instanceof HTMLImageElement) {
} else if (source instanceof HTMLImageElement) {
//图片标签
const imageUrl = source.src;
let baseTexture = BaseTextureCache[imageUrl];
......@@ -380,8 +380,7 @@ export default class BaseTexture extends EventDispatcher {
if (imageUrl.indexOf('data:') !== 0) BaseTexture.addToCache(baseTexture, imageUrl);
}
return baseTexture;
}
else if (source instanceof HTMLCanvasElement) {
} else if (source instanceof HTMLCanvasElement) {
//canvas标签
return BaseTexture.fromCanvas(source, scaleMode);
}
......@@ -426,8 +425,7 @@ export default class BaseTexture extends EventDispatcher {
delete BaseTextureCache[baseTexture];
return baseTextureFromCache;
}
}
else if (baseTexture && baseTexture.textureCacheIds) {
} else if (baseTexture && baseTexture.textureCacheIds) {
for (let i = 0; i < baseTexture.textureCacheIds.length; ++i) {
delete BaseTextureCache[baseTexture.textureCacheIds[i]];
}
......
import BaseRenderTexture from './BaseRenderTexture';
import Texture from './Texture';
import { Rectangle } from '../math';
import { SCALE_MODES } from '../const';
import {Rectangle} from '../math';
import {SCALE_MODES} from '../const';
/**
* A RenderTexture is a special texture that allows any display object to be rendered to it.
......@@ -70,7 +70,7 @@ export default class RenderTexture extends Texture {
* @param {number} height - The height to resize to.
* @param {boolean} doNotResizeBaseTexture - Should the baseTexture.width and height values be resized as well?
*/
resize(width: number, height: number, doNotResizeBaseTexture: boolean=false) {
resize(width: number, height: number, doNotResizeBaseTexture: boolean = false) {
width = Math.ceil(width);
height = Math.ceil(height);
......
import BaseTexture from './BaseTexture';
import TextureUvs from './TextureUvs';
import { EventDispatcher } from '../events/EventDispatcher';
import { Event } from "../events/Event";
import { Rectangle, Point } from '../math';
import { TextureCache } from '../utils';
import { SCALE_MODES } from '../const';
import {EventDispatcher} from '../events/EventDispatcher';
import {Event} from "../events/Event";
import {Point, Rectangle} from '../math';
import {TextureCache} from '../utils';
import {SCALE_MODES} from '../const';
/**
* 一张图片或图集的一部分,如果没有frame。默认整张图片
......@@ -95,6 +95,7 @@ export default class Texture extends EventDispatcher {
* 白贴图
*/
static WHITE: Texture;
/**
* @param {BaseTexture} baseTexture - The base texture source to create the texture from
* @param {Rectangle} [frame] - The rectangle frame of the texture to show
......@@ -147,8 +148,7 @@ export default class Texture extends EventDispatcher {
baseTexture.addEventListener('update', this.onBaseTextureUpdated);
}
this.frame = frame;
}
else {
} else {
baseTexture.once('loaded', this.onBaseTextureLoaded);
}
......@@ -182,8 +182,7 @@ export default class Texture extends EventDispatcher {
// TODO this code looks confusing.. boo to abusing getters and setters!
if (this.noFrame) {
this.frame = new Rectangle(0, 0, baseTexture.width, baseTexture.height);
}
else {
} else {
this.frame = this._frame;
}
this.baseTexture.addEventListener('update', this.onBaseTextureUpdated);
......@@ -274,7 +273,7 @@ export default class Texture extends EventDispatcher {
this.noFrame = false;
const { x, y, width, height } = frame;
const {x, y, width, height} = frame;
const xNotFit = x + width > this.baseTexture.width;
const yNotFit = y + height > this.baseTexture.height;
......@@ -298,6 +297,7 @@ export default class Texture extends EventDispatcher {
this._updateUvs();
}
}
/**
* Indicates whether the texture is rotated inside the atlas
* set to 2 to compensate for texture packer rotation
......@@ -406,14 +406,11 @@ export default class Texture extends EventDispatcher {
return Texture.fromImage(source);
}
return texture;
}
else if (source instanceof HTMLImageElement) {
} else if (source instanceof HTMLImageElement) {
return new Texture(BaseTexture.from(source));
}
else if (source instanceof HTMLCanvasElement) {
} else if (source instanceof HTMLCanvasElement) {
return Texture.fromCanvas(source, SCALE_MODES.LINEAR, 'canvas');
}
else if (source instanceof BaseTexture) {
} else if (source instanceof BaseTexture) {
return new Texture(source);
}
......@@ -461,8 +458,7 @@ export default class Texture extends EventDispatcher {
return textureFromCache;
}
}
else if (texture && texture.textureCacheIds) {
} else if (texture && texture.textureCacheIds) {
for (let i = 0; i < texture.textureCacheIds.length; ++i) {
// Check that texture matches the one being passed in before deleting it from the cache.
if (TextureCache[texture.textureCacheIds[i]] === texture) {
......@@ -494,10 +490,14 @@ function createWhiteTexture() {
//将事件置空
function removeAllHandlers(tex) {
tex.destroy = function _emptyDestroy() { /* empty */ };
tex.addEventListener = function _emptyOn() { /* empty */ };
tex.once = function _emptyOnce() { /* empty */ };
tex.dispatchEvent = function _emptyEmit() { /* empty */ };
tex.destroy = function _emptyDestroy() { /* empty */
};
tex.addEventListener = function _emptyOn() { /* empty */
};
tex.once = function _emptyOnce() { /* empty */
};
tex.dispatchEvent = function _emptyEmit() { /* empty */
};
}
/**
......
import Texture from "./Texture"
import BaseTexture from './BaseTexture';
import { Rectangle } from "../math";
import {Rectangle} from "../math";
/**
* 简单点来说,就是用来拆图集的
* Utility class for maintaining reference to a collection
......
import { Rectangle } from "../math";
import {Rectangle} from "../math";
import BaseTexture from "./BaseTexture";
import GroupD8 from "../math/GroupD8";
/**
* Texture的uv
* @class
......@@ -17,6 +18,7 @@ export default class TextureUvs {
y3: number;
uvsUint32: Uint32Array;
uvsFloat32: Float32Array;
/**
* 用于记录图片的uv
* 00.....10
......
import { TextureCache } from "../utils";
import {TextureCache} from "../utils";
export { default as Texture } from "./Texture";
export { default as BaseTexture } from "./BaseTexture";
export { default as TextureSheet } from "./TextureSheet";
export {default as Texture} from "./Texture";
export {default as BaseTexture} from "./BaseTexture";
export {default as TextureSheet} from "./TextureSheet";
export function getTexture(str: string) {
return TextureCache[str] || null
......
......@@ -22,12 +22,12 @@ export class BitmapNumber extends Sprite {
get num(): number {
return this._num
}
set num(value: number) {
if (value == this._num) return;
if (value > 9) {
this._num = 9;
}
else if (value < 0) {
} else if (value < 0) {
this._num = 0;
}
this.texture = this.textures[this._num];
......
import Container from "../display/Container";
import { TEXT_ALIGN } from "../const";
import {TEXT_ALIGN} from "../const";
import Texture from "../texture/Texture";
import { BitmapNumber } from "./BitmapNumber";
import {BitmapNumber} from "./BitmapNumber";
/**
* 单位图字缓存
......@@ -27,6 +27,7 @@ export class BitmapNumbers extends Container {
get num(): number {
return this._num
}
/**
* 尽量是整数
*/
......@@ -64,6 +65,7 @@ export class BitmapNumbers extends Container {
//适配
this.adaptate()
}
/**
*
* @param textures 0到9的贴图
......@@ -85,8 +87,7 @@ export class BitmapNumbers extends Container {
var right = len / 2 * w - w;
if (this.align == TEXT_ALIGN.LEFT) {
right += len / 2 * w
}
else if (this.align == TEXT_ALIGN.RIGHT) {
} else if (this.align == TEXT_ALIGN.RIGHT) {
right -= len / 2 * w
}
for (var i = 0; i < this.children.length; i++) {
......
import Container from "../display/Container";
import Sprite from "../display/Sprite";
import { Event } from "../events/Event";
import { MouseEvent } from "../events/MouseEvent";
import {MouseEvent} from "../events/MouseEvent";
import Texture from "../texture/Texture";
export class Button extends Sprite {
textureUp;
textureDown;
textureDisable;
constructor(tUp: Texture, tDown?: Texture, tDisable?: Texture) {
super(tUp);
this._instanceType = "Button";
......@@ -70,7 +69,7 @@ export class Button extends Sprite {
let s = this;
if (value != s._clicked) {
if (value) {
s._mouseEvent({ type: "onMouseDown" });
s._mouseEvent({type: "onMouseDown"});
}
s._clicked = value;
}
......
import Texture from "../texture/Texture";
import { Event } from "../events/Event";
import {Event} from "../events/Event";
import Sprite from "../display/Sprite";
/**
......@@ -30,11 +30,13 @@ export class FrameAni extends Sprite {
get frameRate() {
return this._frameRate
}
set frameRate(value: number) {
if (value == this._frameRate) return
this._frameRate = value;
this.allTime = this.texturesAll.length / this._frameRate * 1000;
}
/**
*
* @param texturesAll 所有的资源数组
......@@ -48,8 +50,10 @@ export class FrameAni extends Sprite {
this.addEventListener(Event.ENTER_FRAME, this.onEnterFrame, this)
this.frameRate = 30;
}
//需要做锁步
private count = 0;
onEnterFrame() {
if (!this.isPlay) {
// this.count = 0
......@@ -78,6 +82,7 @@ export class FrameAni extends Sprite {
this.changeTexture(this.currentFrame);
}
}
/**
* 从0开始播
* 回调是播放完后做回收用的
......@@ -89,6 +94,7 @@ export class FrameAni extends Sprite {
this.changeTexture(0);
this.callback = callback;
}
/**
* 重置为0
*/
......@@ -97,6 +103,7 @@ export class FrameAni extends Sprite {
this.currentFrame = 0;
this.changeTexture(0);
}
/**
* 改texture和居中
* @param index
......
import { ScrollPage } from "./ScrollPage";
import { DisplayObject } from "../display/DisplayObject";
import { Event } from "../events/Event";
import {ScrollPage} from "./ScrollPage";
import {DisplayObject} from "../display/DisplayObject";
import {Event} from "../events/Event";
/**
......
import Container from "../display/Container";
import Graphics from "../graphics/Graphics";
import { MouseEvent } from "../events/MouseEvent";
import { Event } from "../events/Event";
import {MouseEvent} from "../events/MouseEvent";
import {Event} from "../events/Event";
// import Tween from "../../tweenSimple/Tween";
/**
......@@ -143,6 +144,7 @@ export class ScrollPage extends Container {
private autoScroll: boolean = false;
public isSpringBack: boolean = true;
/**
* 构造函数
* @method ScrollPage
......@@ -187,8 +189,7 @@ export class ScrollPage extends Container {
s.isStop = true;
view[s.paramXY] = 0;
return;
}
else if (view[s.paramXY] < s.distance - s.maxDistance) {
} else if (view[s.paramXY] < s.distance - s.maxDistance) {
s.addSpeed = 0;
s.speed = 0;
s.isStop = true;
......@@ -248,6 +249,7 @@ export class ScrollPage extends Container {
}
})
}
/**
* 设置可见区域,可见区域的坐标始终在本地坐标中0,0点位置
* @method setViewRect
......@@ -297,7 +299,8 @@ export class ScrollPage extends Container {
s.speed = 0;
s.isMouseDownState = 1;
return;
};
}
;
if (s.isMouseDownState == 1) {
s.dispatchEvent(Event.ON_SCROLL_START);
}
......@@ -341,6 +344,7 @@ export class ScrollPage extends Container {
}
// }
}
/**
* 滚到指定的坐标位置
* @method scrollTo
......@@ -375,6 +379,7 @@ export class ScrollPage extends Container {
s.paramXY = -dis;
}
}
public destroy(): void {
let s = this;
s.maskObj.destroy();
......
import { TextField } from "../text/TextField";
import {TextField} from "../text/TextField";
/**
* 文字一个一个出现
......
//先只导出必要的吧
// export {BitmapNumber} from "./BitmapNumber";
// export {BitmapNumbers} from "./BitmapNumbers";
export { IScrollListItem } from "./ScrollList";
export { ScrollList } from "./ScrollList";
export { ScrollPage } from "./ScrollPage";
export { Button } from "./Button";
\ No newline at end of file
export {IScrollListItem} from "./ScrollList";
export {ScrollList} from "./ScrollList";
export {ScrollPage} from "./ScrollPage";
export {Button} from "./Button";
\ No newline at end of file
import Texture from "../texture/Texture";
import { Rectangle } from "../math";
import { nextPow2 } from "./twiddle";
import {Rectangle} from "../math";
import {nextPow2} from "./twiddle";
import BaseTexture from "../texture/BaseTexture";
const pool = [];
let padding = 2;
/**
* 用于优化webgl图集处理
* 将所有图片画于一张canvas,返回这些图片的texture
......@@ -45,8 +46,7 @@ function preLoad(images: any, callback: Function) {
let imgTag = new Image();
if (bitmap.indexOf("iVBO") === 0 || bitmap.indexOf("/9j/2w") === 0) {
imgTag.src = 'data:image/png;base64,' + bitmap;
}
else {
} else {
//如果是图片链接
imgTag.src = bitmap;
}
......@@ -91,6 +91,7 @@ function compare(name1, name2) {
}
}
}
/**
* 合图集核心,差一点,要不要考虑图片旋转,暂时没有,如需添加,texture底层需修改
* @param imagesAll
......@@ -188,6 +189,7 @@ class imageInfo {
image: any;
x: number;
y: number;
constructor(image: any, x: number = 0, y: number = 0) {
this.image = image;
this.x = x;
......
......@@ -2,18 +2,12 @@
* 记录的一些方法和设置
*/
import { DATA_URI, URL_FILE_EXTENSION } from "../const"
import { BLEND_MODES } from "../const";
import { RENDERER_TYPE } from "../const";
import { Rectangle, Matrix } from "../math";
import CanvasRenderer from "../renderers/CanvasRenderer";
import { DisplayObject } from "../display/DisplayObject";
import RenderTexture from "../texture/RenderTexture";
import {BLEND_MODES, DATA_URI, RENDERER_TYPE, URL_FILE_EXTENSION} from "../const"
export * from './twiddle';
export { default as toDisplayDataURL } from "./toDisplayDataURL";
export { default as determineCrossOrigin } from './determineCrossOrigin';
export {default as toDisplayDataURL} from "./toDisplayDataURL";
export {default as determineCrossOrigin} from './determineCrossOrigin';
let nextUid = 0;
......@@ -34,6 +28,7 @@ export function uid(): number {
*
*/
export const backupCanvas: HTMLCanvasElement = document.createElement("canvas")
export function getGradientColor(points: any, colors: any): any {
let colorObj: any;
let ctx = backupCanvas.getContext("2d");
......@@ -47,10 +42,12 @@ export function getGradientColor(points: any, colors: any): any {
}
return colorObj;
}
export function getCanvasBitmapStyle(image: any): any {
let ctx = backupCanvas.getContext("2d");
return ctx.createPattern(image, "repeat");
}
/**
* Converts a hex color number to an [R, G, B] array
* @function hex2rgb
......@@ -148,6 +145,7 @@ export function inputFeildIosEnable() {
});
}, 50)
}
// 解决苹果不回弹页面
function blurAdjust() {
setTimeout(() => {
......@@ -243,6 +241,7 @@ export function premultiplyTint(tint: number, alpha: number): number {
return (alpha * 255 << 24) + (R << 16) + (G << 8) + B;
}
/**
* 贴图缓存
* 对于链接网络图片,直接以url作为key,自动缓存
......@@ -320,7 +319,7 @@ export const GlobalPro = {
* @return {boolean} is webgl supported
*/
export function isWebGLSupported(): boolean {
const contextOptions = { stencil: true, failIfMajorPerformanceCaveat: true };
const contextOptions = {stencil: true, failIfMajorPerformanceCaveat: true};
try {
if (!window["WebGLRenderingContext"]) {
return false;
......@@ -336,8 +335,7 @@ export function isWebGLSupported(): boolean {
}
gl = null;
return success;
}
catch (e) {
} catch (e) {
return false;
}
}
......
import CanvasRenderer from "../renderers/CanvasRenderer";
import RenderTexture from "../texture/RenderTexture";
import { Matrix, Rectangle } from "../math";
import { DisplayObject } from "../display/DisplayObject";
import {Matrix, Rectangle} from "../math";
import {DisplayObject} from "../display/DisplayObject";
// 作为将显示对象导出成图片的render渲染器
let _dRender: CanvasRenderer = null;
......@@ -38,14 +37,14 @@ export default function toDisplayDataURL(obj: DisplayObject, rect: Rectangle = n
var canvas = document.createElement("canvas");
canvas.width = w;
canvas.height = h;
_dRender = new CanvasRenderer({ htmlElement: canvas, });
_dRender = new CanvasRenderer({htmlElement: canvas,});
} else {
_dRender.htmlElement.width = w;
_dRender.htmlElement.height = h;
}
if (!typeInfo) {
typeInfo = { type: "png" };
typeInfo = {type: "png"};
}
//透明底
if (typeInfo.type == "png") {
......
......@@ -40,10 +40,17 @@ export function isPow2(v) {
export function log2(v) {
//Ts报错,但实际可运行
var r, shift;
r = Number(v > 0xFFFF) << 4; v >>>= r;
shift = Number(v > 0xFF ) << 3; v >>>= shift; r |= shift;
shift = Number(v > 0xF ) << 2; v >>>= shift; r |= shift;
shift = Number(v > 0x3 ) << 1; v >>>= shift; r |= shift;
r = Number(v > 0xFFFF) << 4;
v >>>= r;
shift = Number(v > 0xFF) << 3;
v >>>= shift;
r |= shift;
shift = Number(v > 0xF) << 2;
v >>>= shift;
r |= shift;
shift = Number(v > 0x3) << 1;
v >>>= shift;
r |= shift;
return r | (v >> 1);
}
......
......@@ -50,6 +50,7 @@ export class GLBuffer {
* 更新ID
*/
_updateID: number;
constructor(gl, type?, data?, drawType?) {
this.gl = gl;
......@@ -76,7 +77,7 @@ export class GLBuffer {
* @param offset {Number} if only a subset of the data should be uploaded, this is the amount of data to subtract
* @param dontBind {Boolean} whether to bind the buffer before uploading it 是否不绑定buffer
*/
public upload(data, offset?:number, dontBind?:boolean) {
public upload(data, offset?: number, dontBind?: boolean) {
// todo - needed?
if (!dontBind) this.bind();
......@@ -87,8 +88,7 @@ export class GLBuffer {
if (this.data.byteLength >= data.byteLength) {
gl.bufferSubData(this.type, offset, data);
}
else {
} else {
gl.bufferData(this.type, data, this.drawType);
}
......@@ -104,6 +104,7 @@ export class GLBuffer {
var gl = this.gl;
gl.bindBuffer(this.type, this.buffer);
};
/**
* Destroys the buffer
*
......@@ -111,6 +112,7 @@ export class GLBuffer {
public destroy = function () {
this.gl.deleteBuffer(this.buffer);
};
/**
* 创建顶点缓存
* @param gl
......
import { GLTexture } from './GLTexture';
import {GLTexture} from './GLTexture';
/**
* Helper class to create a webGL Framebuffer
......@@ -18,6 +17,7 @@ export class GLFramebuffer {
texture: any;
width: any;
height: any;
constructor(gl, width, height) {
/**
* The current WebGL rendering context
......@@ -60,6 +60,7 @@ export class GLFramebuffer {
*/
this.height = height || 100;
};
/**
* Adds a texture to the frame buffer
* @param texture {glCore.GLTexture}
......@@ -128,6 +129,7 @@ export class GLFramebuffer {
var gl = this.gl;
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
};
/**
* Resizes the drawing area of the buffer to the given width and height
* @param width {Number} the new width
......
import { compileProgram } from './shader/compileProgram';
import { extractAttributes } from './shader/extractAttributes';
import { extractUniforms } from './shader/extractUniforms';
import { setPrecision } from './shader/setPrecision';
import { generateUniformAccessObject } from './shader/generateUniformAccessObject';
import {compileProgram} from './shader/compileProgram';
import {extractAttributes} from './shader/extractAttributes';
import {extractUniforms} from './shader/extractUniforms';
import {setPrecision} from './shader/setPrecision';
import {generateUniformAccessObject} from './shader/generateUniformAccessObject';
/**
* Helper class to create a webGL Shader
......@@ -52,10 +51,10 @@ export class GLShader {
uniforms: any;
constructor(
gl:WebGLRenderingContext,
vertexSrc:string,
fragmentSrc:string,
precision?:string,
gl: WebGLRenderingContext,
vertexSrc: string,
fragmentSrc: string,
precision?: string,
attributeLocations?) {
this.gl = gl;
......
/**
* Helper class to create a WebGL Texture
* 用于创建WebGL Texture
......@@ -45,6 +44,7 @@ export class GLTexture {
* 纹理类型,默认gl.UNSIGNED_BYTE //https://developer.mozilla.org/zh-CN/docs/Web/API/WebGLRenderingContext/texImage2D
*/
type: any;
constructor(gl: WebGLRenderingContext, width?: number, height?: number, format?, type?) {
this.gl = gl;
......@@ -96,8 +96,7 @@ export class GLTexture {
if (newHeight !== this.height || newWidth !== this.width) {
//https://developer.mozilla.org/zh-CN/docs/Web/API/WebGLRenderingContext/texImage2D
gl.texImage2D(gl.TEXTURE_2D, 0, this.format, this.format, this.type, source);
}
else {
} else {
//https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/texSubImage2D
gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, this.format, this.type, source);
}
......@@ -126,15 +125,13 @@ export class GLTexture {
if (ext) {
FLOATING_POINT_AVAILABLE = true;
}
else {
} else {
throw new Error('floating point textures not available');
}
}
this.type = gl.FLOAT;
}
else {
} else {
// TODO support for other types
this.type = this.type || gl.UNSIGNED_BYTE;
}
......@@ -145,8 +142,7 @@ export class GLTexture {
if (width !== this.width || height !== this.height) {
gl.texImage2D(gl.TEXTURE_2D, 0, this.format, width, height, 0, this.format, this.type, data || null);
}
else {
} else {
gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, width, height, this.format, this.type, data || null);
}
......@@ -192,8 +188,7 @@ export class GLTexture {
if (this.mipmap) {
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, linear ? gl.LINEAR_MIPMAP_LINEAR : gl.NEAREST_MIPMAP_NEAREST);
}
else {
} else {
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, linear ? gl.LINEAR : gl.NEAREST);
}
};
......@@ -267,6 +262,7 @@ export class GLTexture {
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.REPEAT);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.REPEAT);
};
/**
* 镜像形式重复
*/
......@@ -321,7 +317,6 @@ export class GLTexture {
}
var FLOATING_POINT_AVAILABLE = false;
......
// state object//
import { setVertexAttribArrays } from './setVertexAttribArrays';
import {setVertexAttribArrays} from './setVertexAttribArrays';
/**
* Helper class to work with WebGL VertexArrayObjects (vaos)
......@@ -33,6 +32,7 @@ export class VertexArrayObject {
* A boolean flag
*/
dirty: boolean;
constructor(gl: WebGLRenderingContext, state) {
this.nativeVaoExtension = null;
......@@ -82,8 +82,7 @@ export class VertexArrayObject {
if (this.indexBuffer) {
this.indexBuffer.bind();
}
}
else {
} else {
this.activate();
}
......@@ -211,8 +210,7 @@ export class VertexArrayObject {
if (this.indexBuffer) {
//有索引 https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/drawElements
gl.drawElements(type, size || this.indexBuffer.data.length, gl.UNSIGNED_SHORT, (start || 0) * 2);
}
else {
} else {
//无索引 https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/drawArrays
// TODO need a better way to calculate size..
gl.drawArrays(type, start || 0, size || this.getSize());
......
import { createContext } from './createContext';
import {createContext} from './createContext';
const fragTemplate = [
'precision mediump float;',
......@@ -14,7 +14,7 @@ const fragTemplate = [
* @param maxIfs
* @param gl
*/
export function checkMaxIfStatementsInShader(maxIfs:number, gl:WebGLRenderingContext) {
export function checkMaxIfStatementsInShader(maxIfs: number, gl: WebGLRenderingContext) {
const createTempContext = !gl;
// @if DEBUG
......@@ -43,8 +43,7 @@ export function checkMaxIfStatementsInShader(maxIfs:number, gl:WebGLRenderingCon
if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {
maxIfs = (maxIfs / 2) | 0;
}
else {
} else {
// valid!
break;
}
......
/**
* Helper class to create a webGL Context
* 创建webgl上下文
......@@ -7,7 +6,7 @@
* see https://developer.mozilla.org/en/docs/Web/API/HTMLCanvasElement/getContext for the options available
* @return {WebGLRenderingContext} the WebGL context
*/
export function createContext(canvas:HTMLCanvasElement, options?:any):WebGLRenderingContext {
export function createContext(canvas: HTMLCanvasElement, options?: any): WebGLRenderingContext {
var gl = canvas.getContext('webgl', options) ||
canvas.getContext('experimental-webgl', options);
......
// export { default as GroupD8 } from './GroupD8';
export { GLTexture } from './GLTexture';
export { GLBuffer } from './GLBuffer';
export { VertexArrayObject } from './VertexArrayObject';
export { GLFramebuffer } from "./GLFramebuffer";
export { GLShader } from "./GLShader";
export {GLTexture} from './GLTexture';
export {GLBuffer} from './GLBuffer';
export {VertexArrayObject} from './VertexArrayObject';
export {GLFramebuffer} from "./GLFramebuffer";
export {GLShader} from "./GLShader";
// export { BatchBuffer } from "./BatchBuffer";
export { createContext } from "./createContext";
export {createContext} from "./createContext";
// export { TextureUvs } from "./TextureUvs";
export { checkMaxIfStatementsInShader } from "./checkMaxIfStatementsInShader"
export {checkMaxIfStatementsInShader} from "./checkMaxIfStatementsInShader"
......@@ -27,15 +27,13 @@ export function setVertexAttribArrays(gl, attribs, state?) {
if (state.attribState[i]) {
gl.enableVertexAttribArray(i);
}
else {
} else {
gl.disableVertexAttribArray(i);
}
}
}
}
else {
} else {
for (i = 0; i < attribs.length; i++) {
var attrib = attribs[i];
gl.enableVertexAttribArray(attrib.attribute.location);
......
/**
* 编译着色器程序
* @param gl {WebGLRenderingContext} The current WebGL context {WebGLProgram}
......@@ -7,7 +6,7 @@
* @param attributeLocations {Object} An attribute location map that lets you manually set the attribute locations
* @return {WebGLProgram} the shader program 返回着色器程序
*/
export function compileProgram(gl:WebGLRenderingContext, vertexSrc:string, fragmentSrc:string, attributeLocations?:any):WebGLProgram {
export function compileProgram(gl: WebGLRenderingContext, vertexSrc: string, fragmentSrc: string, attributeLocations?: any): WebGLProgram {
var glVertShader = compileShader(gl, gl.VERTEX_SHADER, vertexSrc);
var glFragShader = compileShader(gl, gl.FRAGMENT_SHADER, fragmentSrc);
......@@ -56,7 +55,7 @@ export function compileProgram(gl:WebGLRenderingContext, vertexSrc:string, fragm
* @param vertexSrc {string|string[]} The vertex shader source as an array of strings.
* @return {WebGLShader} the shader
*/
var compileShader = function (gl:WebGLRenderingContext, type:number, src:string):WebGLShader {
var compileShader = function (gl: WebGLRenderingContext, type: number, src: string): WebGLShader {
var shader = gl.createShader(type);
gl.shaderSource(shader, src);
......
......@@ -4,7 +4,7 @@
* @param type {String} Type of value
* @param size {Number}
*/
export function defaultValue(type:string, size:number) {
export function defaultValue(type: string, size: number) {
switch (type) {
case 'float':
return 0;
......
import { mapType } from './mapType';
import { mapSize } from './mapSize';
import {mapType} from './mapType';
import {mapSize} from './mapSize';
/**
* Extracts the attributes获取attributes属性
......
import { mapType } from './mapType';
import { defaultValue } from './defaultValue';
import {mapType} from './mapType';
import {defaultValue} from './defaultValue';
/**
* Extracts the uniforms 获取uniforms属性
* @class
......@@ -21,7 +22,7 @@ export function extractUniforms(gl: WebGLRenderingContext, program: WebGLProgram
var totalUniforms = gl.getProgramParameter(program, gl.ACTIVE_UNIFORMS);
for (var i = 0; i < totalUniforms; i++) {
var uniformData:WebGLActiveInfo = gl.getActiveUniform(program, i);
var uniformData: WebGLActiveInfo = gl.getActiveUniform(program, i);
var name = uniformData.name.replace(/\[.*?\]/, "");
var type = mapType(gl, uniformData.type);
......
......@@ -6,10 +6,10 @@
* @param uniforms {Array} @mat ?
* @return attributes {Object}
*/
export function generateUniformAccessObject(gl:WebGLRenderingContext, uniformData) {
export function generateUniformAccessObject(gl: WebGLRenderingContext, uniformData) {
// this is the object we will be sending back.
// an object hierachy will be created for structs
var uniforms = { data: {} };
var uniforms = {data: {}};
uniforms["gl"] = gl;
......@@ -45,42 +45,100 @@ var generateGetter = function (name) {
};
var GLSL_SINGLE_SETTERS = {
float: function setSingleFloat(gl, location, value) { gl.uniform1f(location, value); },
vec2: function setSingleVec2(gl, location, value) { gl.uniform2f(location, value[0], value[1]); },
vec3: function setSingleVec3(gl, location, value) { gl.uniform3f(location, value[0], value[1], value[2]); },
vec4: function setSingleVec4(gl, location, value) { gl.uniform4f(location, value[0], value[1], value[2], value[3]); },
int: function setSingleInt(gl, location, value) { gl.uniform1i(location, value); },
ivec2: function setSingleIvec2(gl, location, value) { gl.uniform2i(location, value[0], value[1]); },
ivec3: function setSingleIvec3(gl, location, value) { gl.uniform3i(location, value[0], value[1], value[2]); },
ivec4: function setSingleIvec4(gl, location, value) { gl.uniform4i(location, value[0], value[1], value[2], value[3]); },
bool: function setSingleBool(gl, location, value) { gl.uniform1i(location, value); },
bvec2: function setSingleBvec2(gl, location, value) { gl.uniform2i(location, value[0], value[1]); },
bvec3: function setSingleBvec3(gl, location, value) { gl.uniform3i(location, value[0], value[1], value[2]); },
bvec4: function setSingleBvec4(gl, location, value) { gl.uniform4i(location, value[0], value[1], value[2], value[3]); },
mat2: function setSingleMat2(gl, location, value) { gl.uniformMatrix2fv(location, false, value); },
mat3: function setSingleMat3(gl, location, value) { gl.uniformMatrix3fv(location, false, value); },
mat4: function setSingleMat4(gl, location, value) { gl.uniformMatrix4fv(location, false, value); },
sampler2D: function setSingleSampler2D(gl, location, value) { gl.uniform1i(location, value); },
float: function setSingleFloat(gl, location, value) {
gl.uniform1f(location, value);
},
vec2: function setSingleVec2(gl, location, value) {
gl.uniform2f(location, value[0], value[1]);
},
vec3: function setSingleVec3(gl, location, value) {
gl.uniform3f(location, value[0], value[1], value[2]);
},
vec4: function setSingleVec4(gl, location, value) {
gl.uniform4f(location, value[0], value[1], value[2], value[3]);
},
int: function setSingleInt(gl, location, value) {
gl.uniform1i(location, value);
},
ivec2: function setSingleIvec2(gl, location, value) {
gl.uniform2i(location, value[0], value[1]);
},
ivec3: function setSingleIvec3(gl, location, value) {
gl.uniform3i(location, value[0], value[1], value[2]);
},
ivec4: function setSingleIvec4(gl, location, value) {
gl.uniform4i(location, value[0], value[1], value[2], value[3]);
},
bool: function setSingleBool(gl, location, value) {
gl.uniform1i(location, value);
},
bvec2: function setSingleBvec2(gl, location, value) {
gl.uniform2i(location, value[0], value[1]);
},
bvec3: function setSingleBvec3(gl, location, value) {
gl.uniform3i(location, value[0], value[1], value[2]);
},
bvec4: function setSingleBvec4(gl, location, value) {
gl.uniform4i(location, value[0], value[1], value[2], value[3]);
},
mat2: function setSingleMat2(gl, location, value) {
gl.uniformMatrix2fv(location, false, value);
},
mat3: function setSingleMat3(gl, location, value) {
gl.uniformMatrix3fv(location, false, value);
},
mat4: function setSingleMat4(gl, location, value) {
gl.uniformMatrix4fv(location, false, value);
},
sampler2D: function setSingleSampler2D(gl, location, value) {
gl.uniform1i(location, value);
},
};
var GLSL_ARRAY_SETTERS = {
float: function setFloatArray(gl, location, value) { gl.uniform1fv(location, value); },
vec2: function setVec2Array(gl, location, value) { gl.uniform2fv(location, value); },
vec3: function setVec3Array(gl, location, value) { gl.uniform3fv(location, value); },
vec4: function setVec4Array(gl, location, value) { gl.uniform4fv(location, value); },
int: function setIntArray(gl, location, value) { gl.uniform1iv(location, value); },
ivec2: function setIvec2Array(gl, location, value) { gl.uniform2iv(location, value); },
ivec3: function setIvec3Array(gl, location, value) { gl.uniform3iv(location, value); },
ivec4: function setIvec4Array(gl, location, value) { gl.uniform4iv(location, value); },
bool: function setBoolArray(gl, location, value) { gl.uniform1iv(location, value); },
bvec2: function setBvec2Array(gl, location, value) { gl.uniform2iv(location, value); },
bvec3: function setBvec3Array(gl, location, value) { gl.uniform3iv(location, value); },
bvec4: function setBvec4Array(gl, location, value) { gl.uniform4iv(location, value); },
sampler2D: function setSampler2DArray(gl, location, value) { gl.uniform1iv(location, value); },
float: function setFloatArray(gl, location, value) {
gl.uniform1fv(location, value);
},
vec2: function setVec2Array(gl, location, value) {
gl.uniform2fv(location, value);
},
vec3: function setVec3Array(gl, location, value) {
gl.uniform3fv(location, value);
},
vec4: function setVec4Array(gl, location, value) {
gl.uniform4fv(location, value);
},
int: function setIntArray(gl, location, value) {
gl.uniform1iv(location, value);
},
ivec2: function setIvec2Array(gl, location, value) {
gl.uniform2iv(location, value);
},
ivec3: function setIvec3Array(gl, location, value) {
gl.uniform3iv(location, value);
},
ivec4: function setIvec4Array(gl, location, value) {
gl.uniform4iv(location, value);
},
bool: function setBoolArray(gl, location, value) {
gl.uniform1iv(location, value);
},
bvec2: function setBvec2Array(gl, location, value) {
gl.uniform2iv(location, value);
},
bvec3: function setBvec3Array(gl, location, value) {
gl.uniform3iv(location, value);
},
bvec4: function setBvec4Array(gl, location, value) {
gl.uniform4iv(location, value);
},
sampler2D: function setSampler2DArray(gl, location, value) {
gl.uniform1iv(location, value);
},
};
function generateSetter(name, uniform) {
......@@ -89,8 +147,7 @@ function generateSetter(name, uniform) {
var location = this.data[name].location;
if (uniform.size === 1) {
GLSL_SINGLE_SETTERS[uniform.type](this.gl, location, value);
}
else {
} else {
// glslSetArray(gl, location, type, value) {
GLSL_ARRAY_SETTERS[uniform.type](this.gl, location, value);
}
......@@ -101,7 +158,7 @@ function getUniformGroup(nameTokens, uniform) {
var cur = uniform;
for (var i = 0; i < nameTokens.length - 1; i++) {
var o = cur[nameTokens[i]] || { data: {} };
var o = cur[nameTokens[i]] || {data: {}};
cur[nameTokens[i]] = o;
cur = o;
}
......
export { compileProgram } from './compileProgram';
export { defaultValue } from './defaultValue';
export { extractAttributes } from './extractAttributes';
export { extractUniforms } from './extractUniforms';
export { generateUniformAccessObject } from './generateUniformAccessObject';
export { setPrecision } from './setPrecision';
export { mapSize } from './mapSize';
export { mapType } from './mapType';
export {compileProgram} from './compileProgram';
export {defaultValue} from './defaultValue';
export {extractAttributes} from './extractAttributes';
export {extractUniforms} from './extractUniforms';
export {generateUniformAccessObject} from './generateUniformAccessObject';
export {setPrecision} from './setPrecision';
export {mapSize} from './mapSize';
export {mapType} from './mapType';
export function mapType(gl, type) {
if (!GL_TABLE) {
var typeNames = Object.keys(GL_TO_GLSL_TYPES);
......
......@@ -4,10 +4,7 @@ import * as constant from './2d/const';
export { Component } from "./2d/component/Component";
export * from "./2d/display";
export { Event } from "./2d/events/Event";
export { GDispatcher } from "./2d/events/GDispatcher";
export { MouseEvent } from "./2d/events/MouseEvent";
export * from "./2d/events";
export { default as Graphics } from "./2d/graphics/Graphics";
......@@ -36,6 +33,8 @@ export { inputFeildIosEnable } from "./2d/utils/index"
//常量及方法
export * from './2d/const'
export * from './zeroing'
......
/**
* Created by rockyl on 2019-11-05.
*/
import {Container, Stage} from "../2d/display";
import {Event} from "../2d/events";
import {StackContainer} from "./StackContainer";
/**
* 游戏舞台
*/
export class GameStage extends Container {
private _sceneContainer: StackContainer; //场景容器
private _popupContainer: StackContainer; //弹层容器
private _stage;
constructor(stage: Stage) {
super();
this._stage = stage;
stage.addEventListener(Event.RESIZE, this._onStageResize, this);
this.addChild(this._sceneContainer = new StackContainer());
this.addChild(this._popupContainer = new StackContainer());
}
/**
* 场景容器
*/
get sceneContainer(): StackContainer {
return this._sceneContainer;
}
/**
* 弹层容器
*/
get popupContainer(): StackContainer {
return this._popupContainer;
}
private _onStageResize(e) {
const {desWidth, desHeight} = this._stage;
this.width = this._sceneContainer.width = this._popupContainer.width = desWidth;
this.height = this._sceneContainer.height = this._popupContainer.height = desHeight;
}
}
/**
* Created by rockyl on 2019-11-05.
*/
import {Container, DisplayObject} from "../2d/display";
/**
* 栈式视图容器
*/
export class StackContainer extends Container {
/**
* 推入视图
* @param view
*/
push(view: DisplayObject) {
this.addChild(view);
}
/**
* 替换顶层视图
* @param view
*/
replace(view: DisplayObject) {
if (this.pop()) {
this.push(view);
}
}
/**
* 撤出视图
*/
pop() {
let len = this.children.length;
if (len == 0) {
return false;
}
this.removeChildAt(len - 1);
return true;
}
/**
* 撤出全部视图
* @param view
*/
popAll(view: DisplayObject) {
this.removeChildren();
this.push(view);
}
}
/**
* Created by rockyl on 2019-11-06.
*/
import {Event} from "../2d/events";
/**
* 自适应数据
*/
export class AdjustData {
left: number = NaN;
top: number = NaN;
right: number = NaN;
bottom: number = NaN;
horizonCenter: number = NaN;
verticalCenter: number = NaN;
}
/**
* 应用自适应
* @param ctor
*/
export function applyAutoAdjust(ctor: Function) {
let adjustData = new AdjustData();
ctor.prototype.afterConstructor = function () {
this.adjustData = adjustData;
this.addEventListener(Event.RESIZE, this.__onResize, this);
};
ctor.prototype.__onResize = function () {
console.log(this.width, this.height);
};
for (let key in adjustData)
Object.defineProperty(ctor.prototype, key, {
get: function () {
return this.adjustData[key];
},
set: function (v) {
this.adjustData[key] = v;
},
enumerable: true,
configurable: true
});
}
/**
* Created by rockyl on 2019-11-06.
*/
export * from './GameStage'
export * from './StackContainer'
export * from './nodes'
\ No newline at end of file
/**
* Created by rockyl on 2019-11-06.
*/
import {Container} from "../../2d/display";
import {applyAutoAdjust} from "../auto-adjust";
/**
* 节点
*/
@applyAutoAdjust
export class Node extends Container {
}
/**
* Created by rockyl on 2019-11-06.
*/
export * from './Node'
......@@ -5,11 +5,11 @@
"noImplicitAny": false,
"sourceMap": true,
"removeComments": true,
"noEmitOnError":true,
"noEmitOnError": true,
"declarationDir": "types",
"declaration": true,
"outDir":"dist",
/*"outFile": "./index.js",*/
"experimentalDecorators": true,
"outDir": "dist",
"lib": [
"es5",
"dom",
......
......@@ -7,6 +7,7 @@ export default class Container extends DisplayObject {
children: any[];
containerUpdateTransform: any;
constructor();
afterConstructor(): void;
onChildrenChange(index: any): void;
addChild(child: DisplayObject): DisplayObject;
addChildAt(child: DisplayObject, index: number): DisplayObject;
......
......@@ -50,21 +50,22 @@ export declare class DisplayObject extends EventDispatcher {
alpha: number;
x: number;
y: number;
readonly worldMatrix: import("../../../../../duibaGame/renderingengine/src/2d/math/Matrix").Matrix;
readonly localMatrix: import("../../../../../duibaGame/renderingengine/src/2d/math/Matrix").Matrix;
position: import("../../../../../duibaGame/renderingengine/src/2d/math/ObservablePoint").ObservablePoint;
scale: import("../../../../../duibaGame/renderingengine/src/2d/math/ObservablePoint").ObservablePoint;
readonly worldMatrix: import("../../../../../../../../Users/rockyl/WorkSpaces/VisualEditor/renderingengine/src/2d/math/Matrix").Matrix;
readonly localMatrix: import("../../../../../../../../Users/rockyl/WorkSpaces/VisualEditor/renderingengine/src/2d/math/Matrix").Matrix;
position: import("../../../../../../../../Users/rockyl/WorkSpaces/VisualEditor/renderingengine/src/2d/math/ObservablePoint").ObservablePoint;
scale: import("../../../../../../../../Users/rockyl/WorkSpaces/VisualEditor/renderingengine/src/2d/math/ObservablePoint").ObservablePoint;
scaleX: number;
scaleY: number;
anchor: import("../../../../../duibaGame/renderingengine/src/2d/math/ObservablePoint").ObservablePoint;
anchor: import("../../../../../../../../Users/rockyl/WorkSpaces/VisualEditor/renderingengine/src/2d/math/ObservablePoint").ObservablePoint;
anchorX: number;
anchorY: number;
skew: import("../../../../../duibaGame/renderingengine/src/2d/math/ObservablePoint").ObservablePoint;
skew: import("../../../../../../../../Users/rockyl/WorkSpaces/VisualEditor/renderingengine/src/2d/math/ObservablePoint").ObservablePoint;
rotation: number;
readonly worldVisible: boolean;
mask: Graphics;
width: number;
height: number;
protected dispatchResizeEvent(): void;
private _components;
update(): void;
addComponent(component: Component): void;
......
import Circle from "./shapes/Circle";
import { Rectangle, Matrix } from "../math";
import { Matrix, Rectangle } from "../math";
import Ellipse from "./shapes/Ellipse";
import Polygon from "./shapes/Polygon";
import RoundedRectangle from "./shapes/RoundedRectangle";
......
import { Rectangle, Point } from '../../math';
import { Point, Rectangle } from '../../math';
export default class Circle {
x: number;
y: number;
......
import { Rectangle, Point } from '../../math';
import { Point, Rectangle } from '../../math';
export default class Ellipse {
x: number;
y: number;
......
import BatchDrawCall from '../webgl/BatchDrawCall';
import ObjectRenderer from '../webgl/ObjectRenderer';
import { WebglRenderer } from '../WebglRenderer';
import { GLShader, GLBuffer, VertexArrayObject } from '../../../glCore';
import { GLBuffer, GLShader, VertexArrayObject } from '../../../glCore';
export default class BatchRenderer extends ObjectRenderer {
vertSize: number;
vertByteSize: number;
......
import { Rectangle, Matrix } from '../../math';
import { GLFramebuffer, GLTexture, GLBuffer } from '../../../glCore';
import { Matrix, Rectangle } from '../../math';
import { GLBuffer, GLFramebuffer, GLTexture } from '../../../glCore';
import Graphics from '../../graphics/Graphics';
export default class RenderTarget {
gl: WebGLRenderingContext;
......
......@@ -2,7 +2,7 @@ import BaseTexture from './BaseTexture';
import TextureUvs from './TextureUvs';
import { EventDispatcher } from '../events/EventDispatcher';
import { Event } from "../events/Event";
import { Rectangle, Point } from '../math';
import { Point, Rectangle } from '../math';
export default class Texture extends EventDispatcher {
noFrame: boolean;
baseTexture: BaseTexture;
......
export { Component } from "./2d/component/Component";
export * from "./2d/display";
export { Event } from "./2d/events/Event";
export { GDispatcher } from "./2d/events/GDispatcher";
export { MouseEvent } from "./2d/events/MouseEvent";
export * from "./2d/events";
export { default as Graphics } from "./2d/graphics/Graphics";
export { Shape } from "./2d/graphics/Shape";
export { Loader } from "./2d/loader/Loader";
......@@ -16,3 +14,4 @@ export * from "./2d/ui";
export { default as toDisplayDataURL } from "./2d/utils/toDisplayDataURL";
export { inputFeildIosEnable } from "./2d/utils/index";
export * from './2d/const';
export * from './zeroing';
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment