Commit 81c8fc27 authored by rockyl's avatar rockyl

代码格式化

parent a3ab12b1
This diff is collapsed.
This diff is collapsed.
<!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 @@ ...@@ -2,8 +2,8 @@
* Created by rockyl on 2018/11/5. * Created by rockyl on 2018/11/5.
*/ */
import { HashObject } from "../HashObject"; import {HashObject} from "../HashObject";
import { DisplayObject } from "../display/DisplayObject"; import {DisplayObject} from "../display/DisplayObject";
/** /**
* 组件基类 * 组件基类
......
//这里都是一些常量 //这里都是一些常量
/** /**
* 版本号 * 版本号
...@@ -72,6 +71,7 @@ console.log(devicePixelRatio, osType) ...@@ -72,6 +71,7 @@ console.log(devicePixelRatio, osType)
let PI: number = Math.PI; let PI: number = Math.PI;
let HalfPI: number = PI >> 1; let HalfPI: number = PI >> 1;
let PacPI: number = PI + HalfPI; let PacPI: number = PI + HalfPI;
/** /**
* @method cos * @method cos
* @private * @private
...@@ -114,6 +114,7 @@ export function sin(angle: number): number { ...@@ -114,6 +114,7 @@ export function sin(angle: number): number {
return Math.sin(angle); return Math.sin(angle);
} }
} }
/** /**
* Two Pi. * Two Pi.
* *
......
import {DisplayObject} from './DisplayObject';
import { DisplayObject } from './DisplayObject'; import {Rectangle} from "../math/Rectangle";
import { Rectangle } from "../math/Rectangle"; import {Point} from '../math';
import { Point } from '../math';
import CanvasRenderer from '../renderers/CanvasRenderer'; import CanvasRenderer from '../renderers/CanvasRenderer';
import { Event } from "../events/Event" import {Event} from "../events/Event"
import { WebglRenderer } from '../renderers/WebglRenderer'; import {WebglRenderer} from '../renderers/WebglRenderer';
/** /**
* 容器类 * 容器类
* @class * @class
...@@ -33,6 +33,11 @@ export default class Container extends DisplayObject { ...@@ -33,6 +33,11 @@ export default class Container extends DisplayObject {
super(); super();
this._instanceType = "Container"; this._instanceType = "Container";
this.children = []; this.children = [];
this.afterConstructor();
}
afterConstructor() {
} }
/** /**
...@@ -284,8 +289,7 @@ export default class Container extends DisplayObject { ...@@ -284,8 +289,7 @@ export default class Container extends DisplayObject {
} }
return removed; return removed;
} } else if (range === 0 && this.children.length === 0) {
else if (range === 0 && this.children.length === 0) {
return []; return [];
} }
...@@ -341,8 +345,7 @@ export default class Container extends DisplayObject { ...@@ -341,8 +345,7 @@ export default class Container extends DisplayObject {
child._bounds.height = child._mask._bounds.height; child._bounds.height = child._mask._bounds.height;
} }
Rectangle.createFromRects(this._bounds, child._bounds); Rectangle.createFromRects(this._bounds, child._bounds);
} } else {
else {
Rectangle.createFromRects(this._bounds, child._bounds); Rectangle.createFromRects(this._bounds, child._bounds);
} }
} }
...@@ -394,8 +397,7 @@ export default class Container extends DisplayObject { ...@@ -394,8 +397,7 @@ export default class Container extends DisplayObject {
//是否有遮罩。到时如果有滤镜, //是否有遮罩。到时如果有滤镜,
if (this.mask) { if (this.mask) {
this.renderAdvancedWebGL(renderer); this.renderAdvancedWebGL(renderer);
} } else {
else {
//自身先渲染 //自身先渲染
this._renderWebGL(renderer); this._renderWebGL(renderer);
//遍历children //遍历children
...@@ -544,8 +546,7 @@ export default class Container extends DisplayObject { ...@@ -544,8 +546,7 @@ export default class Container extends DisplayObject {
if (width !== 0) { if (width !== 0) {
this.scale.x = value / width; this.scale.x = value / width;
} } else {
else {
this.scale.x = 1; this.scale.x = 1;
} }
//子类有用,有_width,才需设置scaleX //子类有用,有_width,才需设置scaleX
...@@ -565,8 +566,7 @@ export default class Container extends DisplayObject { ...@@ -565,8 +566,7 @@ export default class Container extends DisplayObject {
if (height !== 0) { if (height !== 0) {
this.scale.y = value / height; this.scale.y = value / height;
} } else {
else {
this.scale.y = 1; this.scale.y = 1;
} }
......
import { EventDispatcher } from '../events/EventDispatcher'; import {EventDispatcher} from '../events/EventDispatcher';
import Transform from '../math/Transform'; import Transform from '../math/Transform';
import { Rectangle } from '../math/Rectangle'; import {Rectangle} from '../math/Rectangle';
import { Point } from "../math/Point"; import {Point} from "../math/Point";
import { Event } from "../events/Event"; import {Event} from "../events/Event";
import { Component } from '../component/Component'; import {Component} from '../component/Component';
import Graphics from '../graphics/Graphics'; import Graphics from '../graphics/Graphics';
import { RAD_TO_DEG, DEG_TO_RAD } from '../const'; import {DEG_TO_RAD, RAD_TO_DEG} from '../const';
/** /**
* 基础显示对象抽象类 * 基础显示对象抽象类
* @class * @class
......
import { Event } from "../events/Event"; import {Event} from "../events/Event";
import { DisplayObject } from "./DisplayObject"; import {DisplayObject} from "./DisplayObject";
import { devicePixelRatio } from "../const"; import {devicePixelRatio} from "../const";
/** /**
* 此类对于需要在canvas上放置html其他类型元素的时候非常有用<br/> * 此类对于需要在canvas上放置html其他类型元素的时候非常有用<br/>
* 比如有时候我们需要放置一个注册,登录或者其他的内容.这些内容包含了输入框<br/> * 比如有时候我们需要放置一个注册,登录或者其他的内容.这些内容包含了输入框<br/>
...@@ -35,6 +36,7 @@ export class FloatDisplay extends DisplayObject { ...@@ -35,6 +36,7 @@ export class FloatDisplay extends DisplayObject {
* 记录是否需要修改位置矩阵 * 记录是否需要修改位置矩阵
*/ */
private _transformID: number; private _transformID: number;
/** /**
* 构造函数 * 构造函数
* @method FloatDisplay * @method FloatDisplay
...@@ -153,6 +155,7 @@ export class FloatDisplay extends DisplayObject { ...@@ -153,6 +155,7 @@ export class FloatDisplay extends DisplayObject {
} }
return null; return null;
} }
/** /**
* @method updateStyle * @method updateStyle
* @public * @public
...@@ -194,6 +197,7 @@ export class FloatDisplay extends DisplayObject { ...@@ -194,6 +197,7 @@ export class FloatDisplay extends DisplayObject {
} }
} }
} }
public destroy(): void { public destroy(): void {
//清除相应的数据引用 //清除相应的数据引用
let s = this; let s = this;
......
import { Point, ObservablePoint, Rectangle } from '../math'; import {ObservablePoint, Point, Rectangle} from '../math';
import { sign, TextureCache, hex2rgb } from '../utils'; import {sign, TextureCache} from '../utils';
// import { BLEND_MODES } from '../const'; // import { BLEND_MODES } from '../const';
import Texture from '../texture/Texture'; import Texture from '../texture/Texture';
import Container from './Container'; import Container from './Container';
import { DisplayObject } from "./DisplayObject"; import {DisplayObject} from "./DisplayObject";
import CanvasRenderer from '../renderers/CanvasRenderer'; import CanvasRenderer from '../renderers/CanvasRenderer';
import { SCALE_MODES } from '../const'; import {SCALE_MODES} from '../const';
import { WebglRenderer } from '../renderers/WebglRenderer'; import {WebglRenderer} from '../renderers/WebglRenderer';
const indices = new Uint16Array([0, 1, 2, 0, 2, 3]); const indices = new Uint16Array([0, 1, 2, 0, 2, 3]);
/** /**
...@@ -193,8 +193,7 @@ export default class Sprite extends Container { ...@@ -193,8 +193,7 @@ export default class Sprite extends Container {
h1 = trim.y - (anchor._y * orig.height); h1 = trim.y - (anchor._y * orig.height);
h0 = h1 + trim.height; h0 = h1 + trim.height;
} } else {
else {
w1 = -anchor._x * orig.width; w1 = -anchor._x * orig.width;
w0 = w1 + orig.width; w0 = w1 + orig.width;
...@@ -226,8 +225,7 @@ export default class Sprite extends Container { ...@@ -226,8 +225,7 @@ export default class Sprite extends Container {
calculateTrimmedVertices() { calculateTrimmedVertices() {
if (!this.vertexTrimmedData) { if (!this.vertexTrimmedData) {
this.vertexTrimmedData = new Float32Array(8); 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; return;
} }
...@@ -304,8 +302,7 @@ export default class Sprite extends Container { ...@@ -304,8 +302,7 @@ export default class Sprite extends Container {
if (!trim || (trim.width === orig.width && trim.height === orig.height)) { if (!trim || (trim.width === orig.width && trim.height === orig.height)) {
this.calculateVertices(); this.calculateVertices();
Rectangle.createFromVertexData(this._bounds, this.vertexData); Rectangle.createFromVertexData(this._bounds, this.vertexData);
} } else {
else {
//计算trimmed bounds... //计算trimmed bounds...
this.calculateTrimmedVertices(); this.calculateTrimmedVertices();
Rectangle.createFromVertexData(this._bounds, this.vertexTrimmedData); Rectangle.createFromVertexData(this._bounds, this.vertexTrimmedData);
...@@ -354,7 +351,6 @@ export default class Sprite extends Container { ...@@ -354,7 +351,6 @@ export default class Sprite extends Container {
} }
/** /**
* 销毁 * 销毁
*/ */
...@@ -434,8 +430,7 @@ export default class Sprite extends Container { ...@@ -434,8 +430,7 @@ export default class Sprite extends Container {
if (value) { if (value) {
if (value.baseTexture.hasLoaded) { if (value.baseTexture.hasLoaded) {
this._onTextureUpdate(); this._onTextureUpdate();
} } else {
else {
value.once('update', this._onTextureUpdate); value.once('update', this._onTextureUpdate);
} }
} }
......
import Container from "./Container"; 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 SystemRenderer from "../renderers/SystemRenderer";
import { Rectangle, Point } from "../math"; import {Point, Rectangle} from "../math";
import { EventDispatcher } from "../events/EventDispatcher"; import {EventDispatcher} from "../events/EventDispatcher";
import { Event } from "../events/Event"; import {Event} from "../events/Event";
import { FloatDisplay } from "./FloatDisplay"; import {FloatDisplay} from "./FloatDisplay";
import { DisplayObject } from "./DisplayObject"; import {DisplayObject} from "./DisplayObject";
import { MouseEvent } from "../events/MouseEvent"; import {MouseEvent} from "../events/MouseEvent";
import { WebglRenderer } from "../renderers/WebglRenderer"; import {WebglRenderer} from "../renderers/WebglRenderer";
import { GDispatcher } from "../events/GDispatcher"; import {GDispatcher} from "../events/GDispatcher";
import CanvasRenderer from "../renderers/CanvasRenderer"; import CanvasRenderer from "../renderers/CanvasRenderer";
import { isWebGLSupported, GlobalPro } from "../utils"; import {GlobalPro, isWebGLSupported} from "../utils";
//如果以后还出现帧率问题,使用ticker; //如果以后还出现帧率问题,使用ticker;
//兼容requestAnimationFrame //兼容requestAnimationFrame
...@@ -113,6 +113,7 @@ export class Stage extends Container { ...@@ -113,6 +113,7 @@ export class Stage extends Container {
* @private * @private
*/ */
private static _stageList: any = {}; private static _stageList: any = {};
/** /**
* 是否暂停 * 是否暂停
* @property pause * @property pause
...@@ -125,11 +126,12 @@ export class Stage extends Container { ...@@ -125,11 +126,12 @@ export class Stage extends Container {
static get pause(): boolean { static get pause(): boolean {
return this._pause; return this._pause;
} }
static set pause(value: boolean) { static set pause(value: boolean) {
this._pause = value; this._pause = value;
if (value != this._pause) { if (value != this._pause) {
//触发事件 //触发事件
GDispatcher.dispatchEvent("onStagePause", { pause: value }); GDispatcher.dispatchEvent("onStagePause", {pause: value});
} }
} }
...@@ -226,6 +228,7 @@ export class Stage extends Container { ...@@ -226,6 +228,7 @@ export class Stage extends Container {
public get bgColor(): number { public get bgColor(): number {
return this._bgColor; return this._bgColor;
} }
/** /**
* 设置颜色,即改变渲染器颜色 * 设置颜色,即改变渲染器颜色
*/ */
...@@ -274,6 +277,7 @@ export class Stage extends Container { ...@@ -274,6 +277,7 @@ export class Stage extends Container {
s.setAlign(); s.setAlign();
} }
} }
private _scaleMode: string = "onScale"; private _scaleMode: string = "onScale";
/** /**
...@@ -570,7 +574,7 @@ export class Stage extends Container { ...@@ -570,7 +574,7 @@ export class Stage extends Container {
vH *= ih / 100; vH *= ih / 100;
} }
} }
return { w: vW, h: vH }; return {w: vW, h: vH};
} }
/** /**
...@@ -900,6 +904,7 @@ export class Stage extends Container { ...@@ -900,6 +904,7 @@ export class Stage extends Container {
s.rotation = 0; s.rotation = 0;
} }
}; };
/** /**
* 当舞台尺寸发生改变时,如果stage autoResize 为 true,则此方法会自己调用; * 当舞台尺寸发生改变时,如果stage autoResize 为 true,则此方法会自己调用;
* 如果设置stage autoResize 为 false 你需要手动调用此方法以更新界面. * 如果设置stage autoResize 为 false 你需要手动调用此方法以更新界面.
......
export {default as Container} from './Container';
export { default as Container } from './Container'; export {DisplayObject} from './DisplayObject';
export { DisplayObject } from './DisplayObject'; export {FloatDisplay} from "./FloatDisplay";
export { FloatDisplay } from "./FloatDisplay"; export {default as Sprite} from "./Sprite";
export { default as Sprite } from "./Sprite"; export {Stage} from "./Stage";
export { Stage } from "./Stage"; \ No newline at end of file
\ No newline at end of file
import { HashObject } from "../HashObject"; import {HashObject} from "../HashObject";
/** /**
* 事件类,引擎中一切事件的基类 * 事件类,引擎中一切事件的基类
* @class Event * @class Event
...@@ -218,6 +219,7 @@ export class Event extends HashObject { ...@@ -218,6 +219,7 @@ export class Event extends HashObject {
this._instanceType = "Event"; this._instanceType = "Event";
this.type = type; this.type = type;
} }
/** /**
* 防止对事件流中当前节点中和所有后续节点中的事件侦听器进行处理。 * 防止对事件流中当前节点中和所有后续节点中的事件侦听器进行处理。
* @method stopImmediatePropagation * @method stopImmediatePropagation
...@@ -239,6 +241,7 @@ export class Event extends HashObject { ...@@ -239,6 +241,7 @@ export class Event extends HashObject {
public stopPropagation(): void { public stopPropagation(): void {
this._bpd = true; this._bpd = true;
} }
private _bpd: boolean = false; private _bpd: boolean = false;
/** /**
* 是否阻止事件向下冒泡 * 是否阻止事件向下冒泡
......
import {HashObject} from "../HashObject";
import {Event} from "./Event";
import { HashObject } from "../HashObject";
import { Event } from "./Event";
/** /**
* 事件触发基类 功能简单,如果需全能的,到时用EventEmitter3,现成库,事件名,事件,once否集合成实例 * 事件触发基类 功能简单,如果需全能的,到时用EventEmitter3,现成库,事件名,事件,once否集合成实例
* @class EventDispatcher * @class EventDispatcher
...@@ -319,6 +319,7 @@ class EE { ...@@ -319,6 +319,7 @@ class EE {
fn: Function; fn: Function;
context: any; context: any;
once: boolean; once: boolean;
constructor(fn: Function, context: any, once: boolean = false) { constructor(fn: Function, context: any, once: boolean = false) {
this.fn = fn; this.fn = fn;
this.context = context; this.context = context;
......
import { Event } from "./Event"; import {Event} from "./Event";
import { DisplayObject } from "../display/DisplayObject"; import {DisplayObject} from "../display/DisplayObject";
/** /**
* 鼠标事件类,电脑端鼠标,移动设备端的触摸都使用此事件来监听 * 鼠标事件类,电脑端鼠标,移动设备端的触摸都使用此事件来监听
* @class MouseEvent * @class MouseEvent
...@@ -127,6 +128,7 @@ export class MouseEvent extends Event { ...@@ -127,6 +128,7 @@ export class MouseEvent extends Event {
* @public * @public
*/ */
public identifier: any = 0; public identifier: any = 0;
/** /**
* @method MouseEvent * @method MouseEvent
* @public * @public
...@@ -137,6 +139,7 @@ export class MouseEvent extends Event { ...@@ -137,6 +139,7 @@ export class MouseEvent extends Event {
super(type); super(type);
this._instanceType = "MouseEvent"; this._instanceType = "MouseEvent";
} }
/** /**
* 事件后立即更新显示列表状态 * 事件后立即更新显示列表状态
* @method updateAfterEvent * @method updateAfterEvent
...@@ -146,6 +149,7 @@ export class MouseEvent extends Event { ...@@ -146,6 +149,7 @@ export class MouseEvent extends Event {
public updateAfterEvent() { public updateAfterEvent() {
this.target.stage._cp = true; this.target.stage._cp = true;
} }
public destroy(): void { public destroy(): void {
//清除相应的数据引用 //清除相应的数据引用
let s = this; 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 GraphicsData from './GraphicsData';
import RenderTexture from "../texture/RenderTexture"; import RenderTexture from "../texture/RenderTexture";
import { Matrix, Point, Rectangle } from '../math'; import {Matrix, Point, Rectangle} from '../math';
import { RoundedRectangle, Ellipse, Polygon, Circle } from "./shapes" import {Circle, Ellipse, Polygon, RoundedRectangle} from "./shapes"
import { sign, string2hex, hex2rgb } from '../utils'; import {hex2rgb, sign, string2hex} from '../utils';
import { SHAPES, PI_2, SCALE_MODES, WRAP_MODES } from '../const'; import {PI_2, SCALE_MODES, SHAPES, WRAP_MODES} from '../const';
import { DisplayObject } from '../display/DisplayObject'; import {DisplayObject} from '../display/DisplayObject';
import Texture from '../texture/Texture'; import Texture from '../texture/Texture';
import CanvasRenderer from '../renderers/CanvasRenderer'; 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 buildPoly from './geomBuild/buildPoly';
import buildCircle from './geomBuild/buildCircle'; import buildCircle from './geomBuild/buildCircle';
import buildRectangle from './geomBuild/buildRectangle'; import buildRectangle from './geomBuild/buildRectangle';
...@@ -18,8 +15,9 @@ import buildRoundedRectangle from './geomBuild/buildRoundedRectangle'; ...@@ -18,8 +15,9 @@ import buildRoundedRectangle from './geomBuild/buildRoundedRectangle';
import buildLine from './geomBuild/buildLine'; import buildLine from './geomBuild/buildLine';
import FillStyle from './styles/FillStyle'; import FillStyle from './styles/FillStyle';
import LineStyle from './styles/LineStyle'; 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'; import Container from '../display/Container';
let canvasRenderer: CanvasRenderer; let canvasRenderer: CanvasRenderer;
const tempMatrix = new Matrix(); const tempMatrix = new Matrix();
const tempPoint = new Point(); const tempPoint = new Point();
...@@ -56,6 +54,7 @@ export default class Graphics extends Container { ...@@ -56,6 +54,7 @@ export default class Graphics extends Container {
* @member {LineStyle} * @member {LineStyle}
*/ */
private _lineStyle: LineStyle; private _lineStyle: LineStyle;
/** /**
* @member {FillStyle} * @member {FillStyle}
* @readonly * @readonly
...@@ -71,6 +70,7 @@ export default class Graphics extends Container { ...@@ -71,6 +70,7 @@ export default class Graphics extends Container {
get line() { get line() {
return this._lineStyle; return this._lineStyle;
} }
/** /**
* 图形默认色调 * 图形默认色调
* 默认白色,不会有任何影响 * 默认白色,不会有任何影响
...@@ -81,9 +81,11 @@ export default class Graphics extends Container { ...@@ -81,9 +81,11 @@ export default class Graphics extends Container {
get tint() { get tint() {
return this._tint; return this._tint;
} }
set tint(value) { set tint(value) {
this._tint = value; this._tint = value;
} }
/** /**
* 判断是否更新色值 * 判断是否更新色值
*/ */
...@@ -98,6 +100,7 @@ export default class Graphics extends Container { ...@@ -98,6 +100,7 @@ export default class Graphics extends Container {
get matrix() { get matrix() {
return this._matrix; return this._matrix;
} }
set matrix(matrix: Matrix) { set matrix(matrix: Matrix) {
//暂时不用 //暂时不用
// this._matrix = matrix; // this._matrix = matrix;
...@@ -181,6 +184,7 @@ export default class Graphics extends Container { ...@@ -181,6 +184,7 @@ export default class Graphics extends Container {
private vertexData; private vertexData;
private shapeIndex;//为了在不clear情况下继续画,不用重复计算前面的batch private shapeIndex;//为了在不clear情况下继续画,不用重复计算前面的batch
private _transformID; private _transformID;
constructor() { constructor() {
super(); super();
this._instanceType = "Graphics" this._instanceType = "Graphics"
...@@ -263,6 +267,7 @@ export default class Graphics extends Container { ...@@ -263,6 +267,7 @@ export default class Graphics extends Container {
return this; return this;
} }
lineTextureStyle( lineTextureStyle(
width = 0, width = 0,
texture = Texture.WHITE, texture = Texture.WHITE,
...@@ -278,8 +283,7 @@ export default class Graphics extends Container { ...@@ -278,8 +283,7 @@ export default class Graphics extends Container {
if (!visible) { if (!visible) {
this._lineStyle.reset(); this._lineStyle.reset();
} } else {
else {
if (matrix) { if (matrix) {
matrix = matrix.clone(); matrix = matrix.clone();
matrix.invert(); matrix.invert();
...@@ -305,6 +309,7 @@ export default class Graphics extends Container { ...@@ -305,6 +309,7 @@ export default class Graphics extends Container {
} }
return this; return this;
} }
private startPoly() { private startPoly() {
if (this._currentPath) { if (this._currentPath) {
const points = this._currentPath.points; const points = this._currentPath.points;
...@@ -315,19 +320,18 @@ export default class Graphics extends Container { ...@@ -315,19 +320,18 @@ export default class Graphics extends Container {
this._currentPath.closed = false; this._currentPath.closed = false;
this._currentPath.points.push(points[len - 2], points[len - 1]); this._currentPath.points.push(points[len - 2], points[len - 1]);
} }
} } else {
else {
this._currentPath = new Polygon(); this._currentPath = new Polygon();
this._currentPath.closed = false; this._currentPath.closed = false;
} }
} }
private finishPoly() { private finishPoly() {
if (this._currentPath) { if (this._currentPath) {
if (this._currentPath.points.length > 2) { if (this._currentPath.points.length > 2) {
this.drawShape(this._currentPath); this.drawShape(this._currentPath);
this._currentPath = null; this._currentPath = null;
} } else {
else {
this._currentPath.points.length = 0; this._currentPath.points.length = 0;
} }
} }
...@@ -354,6 +358,7 @@ export default class Graphics extends Container { ...@@ -354,6 +358,7 @@ export default class Graphics extends Container {
} }
return this; return this;
} }
/** /**
* 初始化曲线 * 初始化曲线
* @param x * @param x
...@@ -364,8 +369,7 @@ export default class Graphics extends Container { ...@@ -364,8 +369,7 @@ export default class Graphics extends Container {
if (this._currentPath.points.length === 0) { if (this._currentPath.points.length === 0) {
this._currentPath.points = [x, y]; this._currentPath.points = [x, y];
} }
} } else {
else {
this.moveTo(x, y); this.moveTo(x, y);
} }
} }
...@@ -466,8 +470,7 @@ export default class Graphics extends Container { ...@@ -466,8 +470,7 @@ export default class Graphics extends Container {
if (points[points.length - 2] !== x1 || points[points.length - 1] !== y1) { if (points[points.length - 2] !== x1 || points[points.length - 1] !== y1) {
points.push(x1, y1); points.push(x1, y1);
} }
} } else {
else {
const dd = (a1 * a1) + (b1 * b1); const dd = (a1 * a1) + (b1 * b1);
const cc = (a2 * a2) + (b2 * b2); const cc = (a2 * a2) + (b2 * b2);
const tt = (a1 * a2) + (b1 * b2); const tt = (a1 * a2) + (b1 * b2);
...@@ -510,8 +513,7 @@ export default class Graphics extends Container { ...@@ -510,8 +513,7 @@ export default class Graphics extends Container {
if (!anticlockwise && endAngle <= startAngle) { if (!anticlockwise && endAngle <= startAngle) {
endAngle += PI_2; endAngle += PI_2;
} } else if (anticlockwise && startAngle <= endAngle) {
else if (anticlockwise && startAngle <= endAngle) {
startAngle += PI_2; startAngle += PI_2;
} }
...@@ -535,12 +537,10 @@ export default class Graphics extends Container { ...@@ -535,12 +537,10 @@ export default class Graphics extends Container {
if (xDiff < 0.001 && yDiff < 0.001) { if (xDiff < 0.001 && yDiff < 0.001) {
// If the point is very close, we don't add it, since this would lead to artifacts // If the point is very close, we don't add it, since this would lead to artifacts
// during tesselation due to floating point imprecision. // during tesselation due to floating point imprecision.
} } else {
else {
points.push(startX, startY); points.push(startX, startY);
} }
} } else {
else {
this.moveTo(startX, startY); this.moveTo(startX, startY);
points = this._currentPath.points; points = this._currentPath.points;
} }
...@@ -601,8 +601,7 @@ export default class Graphics extends Container { ...@@ -601,8 +601,7 @@ export default class Graphics extends Container {
this._fillStyle.reset(); this._fillStyle.reset();
//需要额外加参数 //需要额外加参数
this._fillStyle.alphaBlock = true; this._fillStyle.alphaBlock = true;
} } else {
else {
if (matrix) { if (matrix) {
//暂时不用 //暂时不用
// matrix = matrix.clone(); // matrix = matrix.clone();
...@@ -646,6 +645,7 @@ export default class Graphics extends Container { ...@@ -646,6 +645,7 @@ export default class Graphics extends Container {
if (this._currentPath) _currentPath.close(); if (this._currentPath) _currentPath.close();
return this; return this;
} }
/** /**
* 开始画洞 * 开始画洞
*/ */
...@@ -654,6 +654,7 @@ export default class Graphics extends Container { ...@@ -654,6 +654,7 @@ export default class Graphics extends Container {
this._holeMode = true; this._holeMode = true;
return this; return this;
} }
/** /**
* 结束画洞 * 结束画洞
*/ */
...@@ -801,8 +802,7 @@ export default class Graphics extends Container { ...@@ -801,8 +802,7 @@ export default class Graphics extends Container {
); );
this.graphicsData.push(data); this.graphicsData.push(data);
this.dirty++; this.dirty++;
} } else {
else {
if (!this.graphicsData.length) return this; if (!this.graphicsData.length) return this;
const data = new GraphicsData(shape, null, null, this._matrix); const data = new GraphicsData(shape, null, null, this._matrix);
const lastShape = this.graphicsData[this.graphicsData.length - 1]; const lastShape = this.graphicsData[this.graphicsData.length - 1];
...@@ -950,8 +950,7 @@ export default class Graphics extends Container { ...@@ -950,8 +950,7 @@ export default class Graphics extends Container {
if (data.holes.length) { if (data.holes.length) {
this.proccessHoles(data.holes); this.proccessHoles(data.holes);
buildPoly.triangulate(data, this); buildPoly.triangulate(data, this);
} } else {
else {
command.triangulate(data, this); command.triangulate(data, this);
} }
} else { } else {
...@@ -1036,6 +1035,7 @@ export default class Graphics extends Container { ...@@ -1036,6 +1035,7 @@ export default class Graphics extends Container {
} }
} }
} }
/** /**
* If there's a transform update or a change to the shape of the * If there's a transform update or a change to the shape of the
* geometry, recaculate the vertices. * geometry, recaculate the vertices.
...@@ -1214,8 +1214,7 @@ export default class Graphics extends Container { ...@@ -1214,8 +1214,7 @@ export default class Graphics extends Container {
lineWidth = lineStyle.width; lineWidth = lineStyle.width;
if (type === SHAPES.POLY) { if (type === SHAPES.POLY) {
lineWidth = lineWidth * (0.5 + Math.abs(0.5 - alignment)); lineWidth = lineWidth * (0.5 + Math.abs(0.5 - alignment));
} } else {
else {
lineWidth = lineWidth * Math.max(0, alignment); lineWidth = lineWidth * Math.max(0, alignment);
} }
} }
...@@ -1233,8 +1232,7 @@ export default class Graphics extends Container { ...@@ -1233,8 +1232,7 @@ export default class Graphics extends Container {
minY = y < minY ? y : minY; minY = y < minY ? y : minY;
maxY = y + h > maxY ? y + h : maxY; maxY = y + h > maxY ? y + h : maxY;
} } else if (type === SHAPES.CIRC) {
else if (type === SHAPES.CIRC) {
x = shape.x; x = shape.x;
y = shape.y; y = shape.y;
w = shape.radius + (lineWidth / 2); w = shape.radius + (lineWidth / 2);
...@@ -1245,8 +1243,7 @@ export default class Graphics extends Container { ...@@ -1245,8 +1243,7 @@ export default class Graphics extends Container {
minY = y - h < minY ? y - h : minY; minY = y - h < minY ? y - h : minY;
maxY = y + h > maxY ? y + h : maxY; maxY = y + h > maxY ? y + h : maxY;
} } else if (type === SHAPES.ELIP) {
else if (type === SHAPES.ELIP) {
x = shape.x; x = shape.x;
y = shape.y; y = shape.y;
w = shape.width + (lineWidth / 2); w = shape.width + (lineWidth / 2);
...@@ -1257,8 +1254,7 @@ export default class Graphics extends Container { ...@@ -1257,8 +1254,7 @@ export default class Graphics extends Container {
minY = y - h < minY ? y - h : minY; minY = y - h < minY ? y - h : minY;
maxY = y + h > maxY ? y + h : maxY; maxY = y + h > maxY ? y + h : maxY;
} } else {
else {
// POLY // POLY
const points = shape.points; const points = shape.points;
let x2 = 0; let x2 = 0;
...@@ -1297,8 +1293,7 @@ export default class Graphics extends Container { ...@@ -1297,8 +1293,7 @@ export default class Graphics extends Container {
} }
} }
} }
} } else {
else {
minX = 0; minX = 0;
maxX = 0; maxX = 0;
minY = 0; minY = 0;
...@@ -1429,6 +1424,7 @@ export default class Graphics extends Container { ...@@ -1429,6 +1424,7 @@ export default class Graphics extends Container {
} }
} }
/** /**
* Generates the UVs for a shape. * Generates the UVs for a shape.
* 不支持纹理填充,所以uv都时0 * 不支持纹理填充,所以uv都时0
...@@ -1466,6 +1462,7 @@ export default class Graphics extends Container { ...@@ -1466,6 +1462,7 @@ export default class Graphics extends Container {
this.adjustUvs(uvs, texture, uvsStart, size); this.adjustUvs(uvs, texture, uvsStart, size);
} }
} }
/** /**
* Modify uvs array according to position of texture region * Modify uvs array according to position of texture region
* Does not work with rotated or trimmed textures * Does not work with rotated or trimmed textures
...@@ -1500,9 +1497,6 @@ export default class Graphics extends Container { ...@@ -1500,9 +1497,6 @@ export default class Graphics extends Container {
} }
/** /**
* A little internal structure to hold interim batch objects. * A little internal structure to hold interim batch objects.
* *
...@@ -1514,6 +1508,7 @@ class geoBatchPart { ...@@ -1514,6 +1508,7 @@ class geoBatchPart {
start: number; start: number;
attribStart: number; attribStart: number;
attribSize: number; attribSize: number;
constructor() { constructor() {
this.style = null this.style = null
this.size = 0; this.size = 0;
......
import Circle from "./shapes/Circle"; import Circle from "./shapes/Circle";
import { Rectangle, Matrix } from "../math"; import {Matrix, Rectangle} from "../math";
import Ellipse from "./shapes/Ellipse"; import Ellipse from "./shapes/Ellipse";
import Polygon from "./shapes/Polygon"; import Polygon from "./shapes/Polygon";
import RoundedRectangle from "./shapes/RoundedRectangle"; import RoundedRectangle from "./shapes/RoundedRectangle";
import { HashObject } from "../HashObject"; import {HashObject} from "../HashObject";
import LineStyle from "./styles/LineStyle"; import LineStyle from "./styles/LineStyle";
import FillStyle from "./styles/FillStyle"; import FillStyle from "./styles/FillStyle";
...@@ -32,6 +32,7 @@ export default class GraphicsData extends HashObject { ...@@ -32,6 +32,7 @@ export default class GraphicsData extends HashObject {
* 存下shape的点数据,因为如果shape不是poly不会特意存下points * 存下shape的点数据,因为如果shape不是poly不会特意存下points
*/ */
points: number[] points: number[]
/** /**
* *
*/ */
......
import Texture from "../texture/Texture"; import Texture from "../texture/Texture";
import { SCALE_MODES, LINE_CAP, LINE_JOIN } from "../const"; import {LINE_CAP, LINE_JOIN, SCALE_MODES} from "../const";
import { Rectangle, Point } from "../math"; import {Point, Rectangle} from "../math";
import { DisplayObject } from "../display/DisplayObject"; import {DisplayObject} from "../display/DisplayObject";
import { hex2string, getRGBA, getGradientColor, backupCanvas, getCanvasBitmapStyle } from "../utils"; import {backupCanvas, getCanvasBitmapStyle, getGradientColor, getRGBA, hex2string} from "../utils";
import Sprite from "../display/Sprite"; import Sprite from "../display/Sprite";
/** /**
...@@ -24,6 +24,7 @@ export class Shape extends Sprite { ...@@ -24,6 +24,7 @@ export class Shape extends Sprite {
dirty: boolean; dirty: boolean;
offsetX: number; offsetX: number;
offsetY: number; offsetY: number;
constructor() { constructor() {
super(); super();
this._instanceType = "ShapeNode"; this._instanceType = "ShapeNode";
...@@ -446,6 +447,7 @@ export class Shape extends Sprite { ...@@ -446,6 +447,7 @@ export class Shape extends Sprite {
) { ) {
this._stroke(getGradientColor(points, colors), lineWidth, cap, join, miter); this._stroke(getGradientColor(points, colors), lineWidth, cap, join, miter);
}; };
/** /**
* 线条位图填充 一般给Flash2x用 * 线条位图填充 一般给Flash2x用
* @method beginBitmapStroke * @method beginBitmapStroke
...@@ -512,6 +514,7 @@ export class Shape extends Sprite { ...@@ -512,6 +514,7 @@ export class Shape extends Sprite {
s._isBitmapFill = null; s._isBitmapFill = null;
} }
} }
// protected isUsedToMask: boolean = false; // protected isUsedToMask: boolean = false;
/** /**
* 结束画线 * 结束画线
...@@ -670,14 +673,14 @@ export class Shape extends Sprite { ...@@ -670,14 +673,14 @@ export class Shape extends Sprite {
ctx.setTransform(1, 0, 0, 1, -leftX, -leftY); ctx.setTransform(1, 0, 0, 1, -leftX, -leftY);
s._drawShape(ctx); s._drawShape(ctx);
//贴图锚点修改 //贴图锚点修改
this.anchorTexture = { x: -leftX / w, y: -leftY / h }; this.anchorTexture = {x: -leftX / w, y: -leftY / h};
} else { } else {
s.canvas.width = 0; s.canvas.width = 0;
s.canvas.height = 0; s.canvas.height = 0;
s.offsetX = 0; s.offsetX = 0;
s.offsetY = 0; s.offsetY = 0;
s._localBoundsSelf.clear(); s._localBoundsSelf.clear();
this.anchorTexture = { x: 0, y: 0 }; this.anchorTexture = {x: 0, y: 0};
} }
//更新贴图 //更新贴图
this.updateTexture(); this.updateTexture();
...@@ -827,6 +830,7 @@ export class Shape extends Sprite { ...@@ -827,6 +830,7 @@ export class Shape extends Sprite {
this.updateShape(); this.updateShape();
super._renderCanvas(renderer); super._renderCanvas(renderer);
} }
_renderWebGL(renderer) { _renderWebGL(renderer) {
this.updateShape(); this.updateShape();
super._renderWebGL(renderer) super._renderWebGL(renderer)
......
import { SHAPES } from "../../const"; import {SHAPES} from "../../const";
import GraphicsData from "../GraphicsData"; import GraphicsData from "../GraphicsData";
import Graphics from "../Graphics"; import Graphics from "../Graphics";
/** /**
* Builds a circle to draw * Builds a circle to draw
* *
...@@ -32,8 +31,7 @@ export default { ...@@ -32,8 +31,7 @@ export default {
if (graphicsData.type === SHAPES.CIRC) { if (graphicsData.type === SHAPES.CIRC) {
width = circleData.radius; width = circleData.radius;
height = circleData.radius; height = circleData.radius;
} } else {
else {
width = circleData.width; width = circleData.width;
height = circleData.height; height = circleData.height;
} }
...@@ -62,7 +60,7 @@ export default { ...@@ -62,7 +60,7 @@ export default {
); );
}, },
triangulate(graphicsData, graphicsGeometry:Graphics) { triangulate(graphicsData, graphicsGeometry: Graphics) {
const points = graphicsData.points; const points = graphicsData.points;
const verts = graphicsGeometry.verts; const verts = graphicsGeometry.verts;
const indices = graphicsGeometry.indices; const indices = graphicsGeometry.indices;
......
import GraphicsData from "../GraphicsData"; import GraphicsData from "../GraphicsData";
import Graphics from "../Graphics"; import Graphics from "../Graphics";
import { Point } from "../../math"; import {Point} from "../../math";
import { SHAPES } from "../../const"; import {SHAPES} from "../../const";
/** /**
...@@ -36,7 +36,7 @@ export default function (graphicsData: GraphicsData, graphicsGeometry: Graphics) ...@@ -36,7 +36,7 @@ export default function (graphicsData: GraphicsData, graphicsGeometry: Graphics)
* @param {GraphicsData} graphicsData - The graphics object containing all the necessary properties * @param {GraphicsData} graphicsData - The graphics object containing all the necessary properties
* @param {GraphicsGeometry} graphicsGeometry - Geometry where to append output * @param {GraphicsGeometry} graphicsGeometry - Geometry where to append output
*/ */
function buildLine(graphicsData:GraphicsData, graphicsGeometry:Graphics) { function buildLine(graphicsData: GraphicsData, graphicsGeometry: Graphics) {
const shape = graphicsData.shape; const shape = graphicsData.shape;
let points = graphicsData.points || shape.points.slice(); let points = graphicsData.points || shape.points.slice();
...@@ -193,8 +193,7 @@ function buildLine(graphicsData:GraphicsData, graphicsGeometry:Graphics) { ...@@ -193,8 +193,7 @@ function buildLine(graphicsData:GraphicsData, graphicsGeometry:Graphics) {
verts.push(p2x - (perp3x * r2 * r1), p2y - (perp3y * r1)); verts.push(p2x - (perp3x * r2 * r1), p2y - (perp3y * r1));
indexCount++; indexCount++;
} } else {
else {
verts.push(p2x + ((px - p2x) * r1), p2y + ((py - p2y) * r1)); verts.push(p2x + ((px - p2x) * r1), p2y + ((py - p2y) * r1));
verts.push(p2x - ((px - p2x) * r2), p2y - ((py - p2y) * r2)); verts.push(p2x - ((px - p2x) * r2), p2y - ((py - p2y) * r2));
......
import { earcut } from "./earcut"; import {earcut} from "./earcut";
import Graphics from "../Graphics"; import Graphics from "../Graphics";
import GraphicsData from "../GraphicsData"; import GraphicsData from "../GraphicsData";
...@@ -19,7 +19,7 @@ export default { ...@@ -19,7 +19,7 @@ export default {
graphicsData.points = graphicsData.shape.points.slice(); graphicsData.points = graphicsData.shape.points.slice();
}, },
triangulate(graphicsData:GraphicsData, graphicsGeometry:Graphics) { triangulate(graphicsData: GraphicsData, graphicsGeometry: Graphics) {
let points = graphicsData.points; let points = graphicsData.points;
const holes = graphicsData.holes; const holes = graphicsData.holes;
const verts = graphicsGeometry.verts; const verts = graphicsGeometry.verts;
......
import { earcut } from "./earcut"
import GraphicsData from "../GraphicsData"; import GraphicsData from "../GraphicsData";
import Graphics from "../Graphics"; import Graphics from "../Graphics";
...@@ -16,7 +15,7 @@ import Graphics from "../Graphics"; ...@@ -16,7 +15,7 @@ import Graphics from "../Graphics";
export default { export default {
//计算点points //计算点points
build(graphicsData:GraphicsData) { build(graphicsData: GraphicsData) {
// --- // // --- //
// need to convert points to a nice regular data // need to convert points to a nice regular data
// //
...@@ -37,7 +36,7 @@ export default { ...@@ -37,7 +36,7 @@ export default {
}, },
//计算顶点和索引 //计算顶点和索引
triangulate(graphicsData:GraphicsData, graphics: Graphics) { triangulate(graphicsData: GraphicsData, graphics: Graphics) {
const points = graphicsData.points; const points = graphicsData.points;
//graphics之前可能已经有点 //graphics之前可能已经有点
......
import { earcut } from "./earcut" import {earcut} from "./earcut"
import GraphicsData from "../GraphicsData"; import GraphicsData from "../GraphicsData";
import Graphics from "../Graphics"; import Graphics from "../Graphics";
...@@ -15,8 +15,7 @@ import Graphics from "../Graphics"; ...@@ -15,8 +15,7 @@ import Graphics from "../Graphics";
*/ */
export default { export default {
build(graphicsData:GraphicsData) build(graphicsData: GraphicsData) {
{
const rrectData = graphicsData.shape; const rrectData = graphicsData.shape;
const points = graphicsData.points; const points = graphicsData.points;
const x = rrectData.x; const x = rrectData.x;
...@@ -38,8 +37,7 @@ export default { ...@@ -38,8 +37,7 @@ export default {
// TODO - fix this properly, this is not very elegant.. but it works for now. // 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 points = graphicsData.points;
const verts = graphicsGeometry.verts; const verts = graphicsGeometry.verts;
...@@ -49,8 +47,7 @@ export default { ...@@ -49,8 +47,7 @@ export default {
const triangles = earcut(points, null, 2); 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] + vecPos); // indices.push(triangles[i] + vecPos);
indices.push(triangles[i + 1] + vecPos); indices.push(triangles[i + 1] + vecPos);
...@@ -58,8 +55,7 @@ export default { ...@@ -58,8 +55,7 @@ export default {
indices.push(triangles[i + 2] + vecPos); 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]); verts.push(points[i], points[++i]);
} }
}, },
...@@ -78,8 +74,7 @@ export default { ...@@ -78,8 +74,7 @@ export default {
* @return {number} the result * @return {number} the result
* *
*/ */
function getPt(n1, n2, perc) function getPt(n1, n2, perc) {
{
const diff = n2 - n1; const diff = n2 - n1;
return n1 + (diff * perc); return n1 + (diff * perc);
...@@ -102,8 +97,7 @@ function getPt(n1, n2, 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. * @param {number[]} [out=[]] - The output array to add points into. If not passed, a new array is created.
* @return {number[]} an array of points * @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 n = 20;
const points = out; const points = out;
...@@ -114,8 +108,7 @@ function quadraticBezierCurve(fromX, fromY, cpX, cpY, toX, toY, out = []) ...@@ -114,8 +108,7 @@ function quadraticBezierCurve(fromX, fromY, cpX, cpY, toX, toY, out = [])
let x = 0; let x = 0;
let y = 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; j = i / n;
// The Green Line // The Green Line
......
export function earcut(data, holeIndices, dim) { export function earcut(data, holeIndices, dim) {
dim = dim || 2; dim = dim || 2;
......
import { Rectangle, Point } from '../../math'; import {Point, Rectangle} from '../../math';
import { SHAPES } from '../../const'; import {SHAPES} from '../../const';
/** /**
* 圆形 * 圆形
...@@ -28,6 +28,7 @@ export default class Circle { ...@@ -28,6 +28,7 @@ export default class Circle {
* @see SHAPES * @see SHAPES
*/ */
type: number; type: number;
/** /**
* @param {number} [x=0] - The X coordinate of the center of this circle * @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 * @param {number} [y=0] - The Y coordinate of the center of this circle
...@@ -45,7 +46,7 @@ export default class Circle { ...@@ -45,7 +46,7 @@ export default class Circle {
* *
* @return {Circle} a copy of the Circle * @return {Circle} a copy of the Circle
*/ */
clone():Circle { clone(): Circle {
return new Circle(this.x, this.y, this.radius); return new Circle(this.x, this.y, this.radius);
} }
...@@ -53,7 +54,7 @@ export default class Circle { ...@@ -53,7 +54,7 @@ export default class Circle {
* @param {Point} point - The point to test * @param {Point} point - The point to test
* @return {boolean} Whether the x/y coordinates are within this Circle * @return {boolean} Whether the x/y coordinates are within this Circle
*/ */
isPointIn(point:Point):boolean { isPointIn(point: Point): boolean {
if (this.radius <= 0) { if (this.radius <= 0) {
return false; return false;
} }
...@@ -72,7 +73,7 @@ export default class Circle { ...@@ -72,7 +73,7 @@ export default class Circle {
* *
* @return {Rectangle} the framing rectangle * @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); return new Rectangle(this.x - this.radius, this.y - this.radius, this.radius * 2, this.radius * 2);
} }
} }
import { Rectangle, Point } from '../../math'; import {Point, Rectangle} from '../../math';
import { SHAPES } from '../../const'; import {SHAPES} from '../../const';
/** /**
* The Ellipse object can be used to specify a hit area for displayObjects * The Ellipse object can be used to specify a hit area for displayObjects
...@@ -35,6 +35,7 @@ export default class Ellipse { ...@@ -35,6 +35,7 @@ export default class Ellipse {
* @see SHAPES * @see SHAPES
*/ */
type: number; type: number;
/** /**
* @param {number} [x=0] - The X coordinate of the center of this circle * @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 * @param {number} [y=0] - The Y coordinate of the center of this circle
...@@ -54,7 +55,7 @@ export default class Ellipse { ...@@ -54,7 +55,7 @@ export default class Ellipse {
* *
* @return {Ellipse} a copy of the ellipse * @return {Ellipse} a copy of the ellipse
*/ */
clone():Ellipse { clone(): Ellipse {
return new Ellipse(this.x, this.y, this.width, this.height); return new Ellipse(this.x, this.y, this.width, this.height);
} }
...@@ -64,7 +65,7 @@ export default class Ellipse { ...@@ -64,7 +65,7 @@ export default class Ellipse {
* @param {Point} point - The point to test * @param {Point} point - The point to test
* @return {boolean} Whether the x/y coords are within this ellipse * @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) { if (this.width <= 0 || this.height <= 0) {
return false; return false;
} }
...@@ -84,7 +85,7 @@ export default class Ellipse { ...@@ -84,7 +85,7 @@ export default class Ellipse {
* *
* @return {Rectangle} the framing rectangle * @return {Rectangle} the framing rectangle
*/ */
getBounds():Rectangle { getBounds(): Rectangle {
return new Rectangle(this.x - this.width, this.y - this.height, this.width, this.height); return new Rectangle(this.x - this.width, this.y - this.height, this.width, this.height);
} }
} }
import { Point } from '../../math/Point'; import {Point} from '../../math/Point';
import { SHAPES } from '../../const'; import {SHAPES} from '../../const';
/** /**
* *
...@@ -25,6 +25,7 @@ export default class Polygon { ...@@ -25,6 +25,7 @@ export default class Polygon {
* @see SHAPES * @see SHAPES
*/ */
type: number; type: number;
/** /**
* new Polygon(new Point(), new Point(), ...) * new Polygon(new Point(), new Point(), ...)
* *
......
import { SHAPES } from '../../const'; import {SHAPES} from '../../const';
import { Point } from '../../math'; import {Point} from '../../math';
/** /**
* The Rounded Rectangle object is an area that has nice rounded corners, as indicated by its * The Rounded Rectangle object is an area that has nice rounded corners, as indicated by its
...@@ -18,6 +18,7 @@ export default class RoundedRectangle { ...@@ -18,6 +18,7 @@ export default class RoundedRectangle {
*/ */
radius: number; radius: number;
type: number; type: number;
/** /**
* @param {number} [x=0] - The X coordinate of the upper-left corner of the rounded rectangle * @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 * @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 Circle} from './Circle';
export {default as Ellipse} from './Ellipse'; export {default as Ellipse} from './Ellipse';
......
import Texture from "../../texture/Texture"; import Texture from "../../texture/Texture";
import { Matrix } from "../../math"; import {Matrix} from "../../math";
/** /**
* 图形的填充形式 * 图形的填充形式
...@@ -35,6 +35,7 @@ export default class FillStyle { ...@@ -35,6 +35,7 @@ export default class FillStyle {
* 用于设置alpha为0做点击触发用 * 用于设置alpha为0做点击触发用
*/ */
alphaBlock: boolean; alphaBlock: boolean;
constructor() { constructor() {
this.reset(); this.reset();
} }
......
import FillStyle from './FillStyle'; import FillStyle from './FillStyle';
import { LINE_ALIGNMENT } from '../../const'; import {LINE_ALIGNMENT} from '../../const';
/** /**
* 图形的画线模式 * 图形的画线模式
...@@ -21,13 +21,14 @@ export default class LineStyle extends FillStyle { ...@@ -21,13 +21,14 @@ export default class LineStyle extends FillStyle {
* 默认LINE_ALIGNMENT.middle 0.5 * 默认LINE_ALIGNMENT.middle 0.5
*/ */
alignment: LINE_ALIGNMENT; alignment: LINE_ALIGNMENT;
/** /**
* Clones the object * Clones the object
* *
* @return {LineStyle} * @return {LineStyle}
*/ */
clone():LineStyle { clone(): LineStyle {
const obj:LineStyle = new LineStyle(); const obj: LineStyle = new LineStyle();
obj.color = this.color; obj.color = this.color;
obj.alpha = this.alpha; obj.alpha = this.alpha;
obj.texture = this.texture; obj.texture = this.texture;
...@@ -38,6 +39,7 @@ export default class LineStyle extends FillStyle { ...@@ -38,6 +39,7 @@ export default class LineStyle extends FillStyle {
obj.native = this.native; obj.native = this.native;
return obj; return obj;
} }
/** /**
* 重置 * 重置
*/ */
......
...@@ -6,7 +6,7 @@ export function bezierCurveControlPoint(points) { ...@@ -6,7 +6,7 @@ export function bezierCurveControlPoint(points) {
if (points.length > 2) { if (points.length > 2) {
var A = []; var A = [];
var B = []; 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); B[0] = returnBControl(points, 0);
A[points.length - 2] = returnAControl(points, points.length - 2); A[points.length - 2] = returnAControl(points, points.length - 2);
B[points.length - 2] = { B[points.length - 2] = {
...@@ -17,29 +17,31 @@ export function bezierCurveControlPoint(points) { ...@@ -17,29 +17,31 @@ export function bezierCurveControlPoint(points) {
A[i] = returnAControl(points, i); A[i] = returnAControl(points, i);
B[i] = returnBControl(points, i); B[i] = returnBControl(points, i);
} }
return { A: A, B: B }; return {A: A, B: B};
} }
} }
function returnAControl(points, i) { function returnAControl(points, i) {
var x = points[i].x + (points[i + 1].x - points[i - 1].x) / 4; 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; 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) { function returnBControl(points, i) {
var x = points[i + 1].x - (points[i + 2].x - points[i].x) / 4; 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; 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) { function setPath(ctx, type) {
var points = [ var points = [
{ x: 0, y: 0 }, {x: 0, y: 0},
{ x: 30, y: 0 }, {x: 30, y: 0},
{ x: 30, y: -30 }, {x: 30, y: -30},
{ x: 60, y: -30 }, {x: 60, y: -30},
{ x: 60, y: 0 }, {x: 60, y: 0},
{ x: 90, y: 0 }]; {x: 90, y: 0}];
var AB, A, B; var AB, A, B;
if (points.length > 2) { if (points.length > 2) {
AB = bezierCurveControlPoint(points); AB = bezierCurveControlPoint(points);
......
export {default as bezierCurveTo} from './bezierCurveTo';
export { default as bezierCurveTo } from './bezierCurveTo'; export {bezierCurveControlPoint} from "./bezierCurveControlPoint";
export { bezierCurveControlPoint } from "./bezierCurveControlPoint";
/** /**
* Graphics curves resolution settings. If `adaptive` flag is set to `true`, * 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. * 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 ...@@ -33,8 +32,7 @@ export const GRAPHICS_CURVES: { adaptive: boolean, maxLength: number, minSegment
if (result < this.minSegments) { if (result < this.minSegments) {
result = this.minSegments; result = this.minSegments;
} } else if (result > this.maxSegments) {
else if (result > this.maxSegments) {
result = this.maxSegments; result = this.maxSegments;
} }
return result; 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 { export class Loader extends EventDispatcher {
...@@ -16,6 +13,7 @@ export class Loader extends EventDispatcher { ...@@ -16,6 +13,7 @@ export class Loader extends EventDispatcher {
parser: Parser; parser: Parser;
_req: XMLHttpRequest = null; _req: XMLHttpRequest = null;
/** /**
* *
*/ */
...@@ -35,7 +33,7 @@ export class Loader extends EventDispatcher { ...@@ -35,7 +33,7 @@ export class Loader extends EventDispatcher {
if (suc) { if (suc) {
this.cache(pngFile, data); this.cache(pngFile, data);
if (this.caches[url]) { if (this.caches[url]) {
callback(true, { json: this.caches[url], img: data }) callback(true, {json: this.caches[url], img: data})
} }
} else { } else {
callback(false, data) callback(false, data)
...@@ -63,7 +61,7 @@ export class Loader extends EventDispatcher { ...@@ -63,7 +61,7 @@ export class Loader extends EventDispatcher {
// console.log(obj) // console.log(obj)
this.cache(url, _req.response); this.cache(url, _req.response);
if (this.caches[pngFile]) { 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 @@ ...@@ -2,7 +2,7 @@
* 二面体群,n=4,用于翻转四边形纹理,包括镜像 * 二面体群,n=4,用于翻转四边形纹理,包括镜像
* 暂时用于纹理的旋转90度 * 暂时用于纹理的旋转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 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]; const uy = [0, 1, 1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1];
...@@ -119,22 +119,19 @@ const GroupD8 = { ...@@ -119,22 +119,19 @@ const GroupD8 = {
} }
return GroupD8.N; return GroupD8.N;
} } else if (Math.abs(dy) * 2 <= Math.abs(dx)) {
else if (Math.abs(dy) * 2 <= Math.abs(dx)) {
if (dx > 0) { if (dx > 0) {
return GroupD8.E; return GroupD8.E;
} }
return GroupD8.W; return GroupD8.W;
} } else if (dy > 0) {
else if (dy > 0) {
if (dx > 0) { if (dx > 0) {
return GroupD8.SE; return GroupD8.SE;
} }
return GroupD8.SW; return GroupD8.SW;
} } else if (dx > 0) {
else if (dx > 0) {
return GroupD8.NE; return GroupD8.NE;
} }
......
import {Point} from "././Point";
import { Point } from "././Point"; import {HashObject} from "../HashObject";
import { HashObject } from "../HashObject"; import {cos, DEG_TO_RAD, RAD_TO_DEG, sin} from "../const";
import { DEG_TO_RAD, cos, sin, RAD_TO_DEG } from "../const";
/** /**
* 2维矩阵 * 2维矩阵
...@@ -57,6 +56,7 @@ export class Matrix extends HashObject { ...@@ -57,6 +56,7 @@ export class Matrix extends HashObject {
//数组形式 //数组形式
public array = null; public array = null;
/** /**
* 构造函数 * 构造函数
* @method Matrix * @method Matrix
...@@ -200,8 +200,7 @@ export class Matrix extends HashObject { ...@@ -200,8 +200,7 @@ export class Matrix extends HashObject {
if (b == 0 && c == 0) { if (b == 0 && c == 0) {
if (a == 0 || d == 0) { if (a == 0 || d == 0) {
s.a = s.d = s.tx = s.ty = 0; s.a = s.d = s.tx = s.ty = 0;
} } else {
else {
a = s.a = 1 / a; a = s.a = 1 / a;
d = s.d = 1 / d; d = s.d = 1 / d;
s.tx = -a * tx; s.tx = -a * tx;
...@@ -259,14 +258,14 @@ export class Matrix extends HashObject { ...@@ -259,14 +258,14 @@ export class Matrix extends HashObject {
if (skewX == skewY) { if (skewX == skewY) {
s.a = u * scaleX; s.a = u * scaleX;
s.b = v * scaleX; s.b = v * scaleX;
} } else {
else {
s.a = cos(skewY) * scaleX; s.a = cos(skewY) * scaleX;
s.b = sin(skewY) * scaleX; s.b = sin(skewY) * scaleX;
} }
s.c = -v * scaleY; s.c = -v * scaleY;
s.d = u * scaleY; s.d = u * scaleY;
}; }
;
s.tx = x + ax - (ax * s.a + ay * s.c); s.tx = x + ax - (ax * s.a + ay * s.c);
s.ty = y + ay - (ax * s.b + ay * s.d); s.ty = y + ay - (ax * s.b + ay * s.d);
} }
...@@ -296,6 +295,7 @@ export class Matrix extends HashObject { ...@@ -296,6 +295,7 @@ export class Matrix extends HashObject {
s.tx = a * tx1 + c * s.ty + tx; s.tx = a * tx1 + c * s.ty + tx;
s.ty = b * tx1 + d * s.ty + ty; s.ty = b * tx1 + d * s.ty + ty;
}; };
/** /**
* Appends the given Matrix to this Matrix. * Appends the given Matrix to this Matrix.
* *
...@@ -332,6 +332,7 @@ export class Matrix extends HashObject { ...@@ -332,6 +332,7 @@ export class Matrix extends HashObject {
public static isEqual(m1: Matrix, m2: Matrix): boolean { 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; 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 { public concat(mtx: Matrix): void {
let s = this; let s = this;
let a = s.a, b = s.b, c = s.c, d = s.d, let a = s.a, b = s.b, c = s.c, d = s.d,
...@@ -345,6 +346,7 @@ export class Matrix extends HashObject { ...@@ -345,6 +346,7 @@ export class Matrix extends HashObject {
s.tx = tx * ma + ty * mc + mx; s.tx = tx * ma + ty * mc + mx;
s.ty = tx * mb + ty * md + my; s.ty = tx * mb + ty * md + my;
} }
/** /**
* 对矩阵应用旋转转换。 * 对矩阵应用旋转转换。
* @method rotate * @method rotate
...@@ -382,6 +384,7 @@ export class Matrix extends HashObject { ...@@ -382,6 +384,7 @@ export class Matrix extends HashObject {
s.tx *= sx; s.tx *= sx;
s.ty *= sy; s.ty *= sy;
} }
/** /**
* 沿 x 和 y 轴平移矩阵,由 dx 和 dy 参数指定。 * 沿 x 和 y 轴平移矩阵,由 dx 和 dy 参数指定。
* @method translate * @method translate
......
import {Point} from "../math/Point";
import {HashObject} from "../HashObject";
import { Point } from "../math/Point";
import { HashObject } from "../HashObject";
/** /**
* 动态可监控ObservablePoint类 * 动态可监控ObservablePoint类
* @class * @class
...@@ -10,6 +10,7 @@ export class ObservablePoint extends HashObject { ...@@ -10,6 +10,7 @@ export class ObservablePoint extends HashObject {
_y: number; _y: number;
cb: any; cb: any;
scope: any; scope: any;
/** /**
* @param {Function} cb - 值改变时的回调 * @param {Function} cb - 值改变时的回调
* @param {object} scope - 回调里的上下文this * @param {object} scope - 回调里的上下文this
......
import { HashObject } from "../HashObject"; import {HashObject} from "../HashObject";
/** /**
* @class Point * @class Point
* @extends HashObject * @extends HashObject
...@@ -6,7 +7,9 @@ import { HashObject } from "../HashObject"; ...@@ -6,7 +7,9 @@ import { HashObject } from "../HashObject";
* @public * @public
*/ */
export class Point extends HashObject { export class Point extends HashObject {
public destroy(): void { } public destroy(): void {
}
/** /**
* 构造函数 * 构造函数
* @method Point * @method Point
...@@ -22,6 +25,7 @@ export class Point extends HashObject { ...@@ -22,6 +25,7 @@ export class Point extends HashObject {
s.x = x; s.x = x;
s.y = y; s.y = y;
} }
/** /**
* 水平坐标 * 水平坐标
* @property x * @property x
...@@ -38,6 +42,7 @@ export class Point extends HashObject { ...@@ -38,6 +42,7 @@ export class Point extends HashObject {
* @type {number} * @type {number}
*/ */
public y: number = 0; public y: number = 0;
/** /**
* 求两点之间的距离 * 求两点之间的距离
* @method distance * @method distance
......
import { HashObject } from "../HashObject"; import {HashObject} from "../HashObject";
import { Point } from "./Point"; import {Point} from "./Point";
import { SHAPES } from "../const"; import {SHAPES} from "../const";
/** /**
* *
* @class Rectangle * @class Rectangle
...@@ -14,6 +15,7 @@ export class Rectangle extends HashObject { ...@@ -14,6 +15,7 @@ export class Rectangle extends HashObject {
* 类型 * 类型
*/ */
type: number type: number
/** /**
* 构造函数 * 构造函数
* @method Rectangle * @method Rectangle
...@@ -191,6 +193,7 @@ export class Rectangle extends HashObject { ...@@ -191,6 +193,7 @@ export class Rectangle extends HashObject {
return rect; return rect;
} }
} }
/** /**
* 通过一系列点来生成一个矩形 * 通过一系列点来生成一个矩形
* 返回包含所有给定的点的最小矩形 * 返回包含所有给定的点的最小矩形
...@@ -284,6 +287,7 @@ export class Rectangle extends HashObject { ...@@ -284,6 +287,7 @@ export class Rectangle extends HashObject {
rect.x = x, rect.y = y, rect.width = w - x, rect.height = h - y; rect.x = x, rect.y = y, rect.width = w - x, rect.height = h - y;
return rect; return rect;
} }
/** /**
* 判读两个矩形是否相交 * 判读两个矩形是否相交
* @method testRectCross * @method testRectCross
......
import { ObservablePoint } from './ObservablePoint'; import {ObservablePoint} from './ObservablePoint';
import { Matrix } from "./Matrix"; import {Matrix} from "./Matrix";
import { HashObject } from '../HashObject'; import {HashObject} from '../HashObject';
import { cos, sin } from '../const'; import {cos, sin} from '../const';
/** /**
* @class * @class
......
export {Matrix} from './Matrix';
export {Point} from './Point';
export { Matrix } from './Matrix'; export {ObservablePoint} from './ObservablePoint';
export { Point } from './Point'; export {Rectangle} from './Rectangle';
export { ObservablePoint } from './ObservablePoint';
export { Rectangle } from './Rectangle';
// export {default as Transform} from './Transform'; // export {default as Transform} from './Transform';
export { default as Transform } from './Transform'; export {default as Transform} from './Transform';
export { default as GroupD8 } from './GroupD8'; export {default as GroupD8} from './GroupD8';
\ No newline at end of file \ No newline at end of file
import SystemRenderer from './SystemRenderer'; import SystemRenderer from './SystemRenderer';
import CanvasMaskManager from './managers/CanvasMaskManager'; import CanvasMaskManager from './managers/CanvasMaskManager';
import CanvasRenderTarget from './renderTarget/CanvasRenderTarget'; import CanvasRenderTarget from './renderTarget/CanvasRenderTarget';
import { RENDERER_TYPE } from '../const'; import {RENDERER_TYPE} from '../const';
import { RendererOptions } from './RendererOptions'; import {RendererOptions} from './RendererOptions';
import RenderTexture from '../texture/RenderTexture'; import RenderTexture from '../texture/RenderTexture';
import { Matrix } from '../math'; import {Matrix} from '../math';
import { DisplayObject } from '../display/DisplayObject'; import {DisplayObject} from '../display/DisplayObject';
import CanvasSpriteRenderer from './plugins/CanvasSpriteRenderer'; 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 { ...@@ -41,7 +41,7 @@ export default class CanvasRenderer extends SystemRenderer {
super(options); super(options);
this._instanceType = "CanvasRenderer"; this._instanceType = "CanvasRenderer";
this.type = RENDERER_TYPE.CANVAS; 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.context = this.rootContext;
this.maskManager = new CanvasMaskManager(this); this.maskManager = new CanvasMaskManager(this);
...@@ -51,14 +51,11 @@ export default class CanvasRenderer extends SystemRenderer { ...@@ -51,14 +51,11 @@ export default class CanvasRenderer extends SystemRenderer {
if (this.rootContext && !this.rootContext.imageSmoothingEnabled) { if (this.rootContext && !this.rootContext.imageSmoothingEnabled) {
if (this.rootContext["webkitImageSmoothingEnabled"]) { if (this.rootContext["webkitImageSmoothingEnabled"]) {
this.smoothProperty = 'webkitImageSmoothingEnabled'; this.smoothProperty = 'webkitImageSmoothingEnabled';
} } else if (this.rootContext["mozImageSmoothingEnabled"]) {
else if (this.rootContext["mozImageSmoothingEnabled"]) {
this.smoothProperty = 'mozImageSmoothingEnabled'; this.smoothProperty = 'mozImageSmoothingEnabled';
} } else if (this.rootContext["oImageSmoothingEnabled"]) {
else if (this.rootContext["oImageSmoothingEnabled"]) {
this.smoothProperty = 'oImageSmoothingEnabled'; this.smoothProperty = 'oImageSmoothingEnabled';
} } else if (this.rootContext["msImageSmoothingEnabled"]) {
else if (this.rootContext["msImageSmoothingEnabled"]) {
this.smoothProperty = 'msImageSmoothingEnabled'; this.smoothProperty = 'msImageSmoothingEnabled';
} }
} }
...@@ -104,8 +101,7 @@ export default class CanvasRenderer extends SystemRenderer { ...@@ -104,8 +101,7 @@ export default class CanvasRenderer extends SystemRenderer {
} }
//当前上下文要修改成离屏的 //当前上下文要修改成离屏的
this.context = renderTexture._canvasRenderTarget.context; this.context = renderTexture._canvasRenderTarget.context;
} } else {
else {
//当前上下文就是根节点的 //当前上下文就是根节点的
this.context = this.rootContext; this.context = this.rootContext;
} }
...@@ -128,8 +124,7 @@ export default class CanvasRenderer extends SystemRenderer { ...@@ -128,8 +124,7 @@ export default class CanvasRenderer extends SystemRenderer {
tempWt.copy(transform); tempWt.copy(transform);
//标记要更新transform //标记要更新transform
this._tempDisplayObjectParent.transform._worldID = -1; this._tempDisplayObjectParent.transform._worldID = -1;
} } else {
else {
//没有就初始化 //没有就初始化
tempWt.identity(); tempWt.identity();
} }
...@@ -148,8 +143,7 @@ export default class CanvasRenderer extends SystemRenderer { ...@@ -148,8 +143,7 @@ export default class CanvasRenderer extends SystemRenderer {
if (this.renderingToScreen) { if (this.renderingToScreen) {
if (this.transparent) { if (this.transparent) {
context.clearRect(0, 0, this.htmlElement.width, this.htmlElement.height); context.clearRect(0, 0, this.htmlElement.width, this.htmlElement.height);
} } else {
else {
context.fillStyle = this._backgroundColorString; context.fillStyle = this._backgroundColorString;
context.fillRect(0, 0, this.htmlElement.width, this.htmlElement.height); context.fillRect(0, 0, this.htmlElement.width, this.htmlElement.height);
} }
...@@ -175,8 +169,7 @@ export default class CanvasRenderer extends SystemRenderer { ...@@ -175,8 +169,7 @@ export default class CanvasRenderer extends SystemRenderer {
if (!this.transparent && clearColor) { if (!this.transparent && clearColor) {
context.fillStyle = clearColor; context.fillStyle = clearColor;
context.fillRect(0, 0, this.htmlElement.width, this.htmlElement.height); context.fillRect(0, 0, this.htmlElement.width, this.htmlElement.height);
} } else {
else {
context.clearRect(0, 0, this.htmlElement.width, this.htmlElement.height); context.clearRect(0, 0, this.htmlElement.width, this.htmlElement.height);
} }
} }
......
import { hex2string, hex2rgb } from '../utils'; import {hex2rgb, hex2string} from '../utils';
import { Matrix, Rectangle } from '../math'; import {Matrix} from '../math';
import { RENDERER_TYPE, devicePixelRatio } from '../const'; import {devicePixelRatio, RENDERER_TYPE} from '../const';
import Container from '../display/Container'; import Container from '../display/Container';
import { EventDispatcher } from '../events/EventDispatcher'; import {EventDispatcher} from '../events/EventDispatcher';
import { DisplayObject } from "../display/DisplayObject"; import {DisplayObject} from "../display/DisplayObject";
import { RendererOptions } from "./RendererOptions"; import {RendererOptions} from "./RendererOptions";
const tempMatrix = new Matrix(); const tempMatrix = new Matrix();
......
import { EventDispatcher } from "../events/EventDispatcher";
import BatchRenderer from "./plugins/BatchRenderer"; import BatchRenderer from "./plugins/BatchRenderer";
import SystemRenderer from "./SystemRenderer"; import SystemRenderer from "./SystemRenderer";
import { RendererOptions } from "./RendererOptions"; import {RendererOptions} from "./RendererOptions";
import { RENDERER_TYPE } from "../const"; import {devicePixelRatio, RENDERER_TYPE, SCALE_MODES} from "../const";
import { createContext, GLShader, VertexArrayObject } from "../../glCore"; import {createContext, GLShader, VertexArrayObject} from "../../glCore";
import ObjectRenderer from "./webgl/ObjectRenderer";
import RenderTarget from "./renderTarget/RenderTarget"; import RenderTarget from "./renderTarget/RenderTarget";
import TextureManager from "./managers/TextureManager"; import TextureManager from "./managers/TextureManager";
import TextureGarbageCollector from "./managers/TextureGarbageCollector"; import TextureGarbageCollector from "./managers/TextureGarbageCollector";
import { SCALE_MODES, devicePixelRatio } from "../const";
import RenderTexture from "../texture/RenderTexture"; import RenderTexture from "../texture/RenderTexture";
import { Matrix } from "../math"; import {Matrix} from "../math";
import WebGLState from "./webgl/WebGLState"; import WebGLState from "./webgl/WebGLState";
import BatchManager from "./managers/BatchManager"; import BatchManager from "./managers/BatchManager";
import MaskManager from "./managers/MaskManager"; import MaskManager from "./managers/MaskManager";
import StencilManager from "./managers/StencilManager"; import StencilManager from "./managers/StencilManager";
import { DisplayObject } from "../display/DisplayObject"; import {DisplayObject} from "../display/DisplayObject";
let CONTEXT_UID = 0; let CONTEXT_UID = 0;
...@@ -288,8 +285,7 @@ export class WebglRenderer extends SystemRenderer { ...@@ -288,8 +285,7 @@ export class WebglRenderer extends SystemRenderer {
if (vao) { if (vao) {
vao.bind(); vao.bind();
} } else if (this._activeVao) {
else if (this._activeVao) {
// TODO this should always be true i think? // TODO this should always be true i think?
this._activeVao.unbind(); this._activeVao.unbind();
} }
...@@ -344,8 +340,7 @@ export class WebglRenderer extends SystemRenderer { ...@@ -344,8 +340,7 @@ export class WebglRenderer extends SystemRenderer {
renderTarget = baseTexture._glRenderTargets[this.CONTEXT_UID]; renderTarget = baseTexture._glRenderTargets[this.CONTEXT_UID];
renderTarget.setFrame(renderTexture.frame); renderTarget.setFrame(renderTexture.frame);
} } else {
else {
renderTarget = this.rootRenderTarget; renderTarget = this.rootRenderTarget;
} }
...@@ -426,7 +421,6 @@ export class WebglRenderer extends SystemRenderer { ...@@ -426,7 +421,6 @@ export class WebglRenderer extends SystemRenderer {
} }
/** /**
* webgl上下文恢复时 * webgl上下文恢复时
* @private * @private
...@@ -466,6 +460,7 @@ export class WebglRenderer extends SystemRenderer { ...@@ -466,6 +460,7 @@ export class WebglRenderer extends SystemRenderer {
} }
static __plugins; static __plugins;
/** /**
* Adds a plugin to the renderer. * Adds a plugin to the renderer.
* *
......
import ObjectRenderer from '../webgl/ObjectRenderer'; import ObjectRenderer from '../webgl/ObjectRenderer';
import { WebglRenderer } from '../WebglRenderer'; import {WebglRenderer} from '../WebglRenderer';
/** /**
* 批处理管理器,用于切换渲染插件 * 批处理管理器,用于切换渲染插件
......
import { SHAPES } from '../../const'; import {SHAPES} from '../../const';
import { HashObject } from '../../HashObject'; import {HashObject} from '../../HashObject';
import CanvasRenderer from '../CanvasRenderer'; import CanvasRenderer from '../CanvasRenderer';
import Graphics from '../../graphics/Graphics'; 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 { export default class CanvasMaskManager extends HashObject {
renderer renderer
/** /**
* @param {CanvasRenderer} renderer - The canvas renderer. * @param {CanvasRenderer} renderer - The canvas renderer.
*/ */
...@@ -82,15 +82,12 @@ export default class CanvasMaskManager extends HashObject { ...@@ -82,15 +82,12 @@ export default class CanvasMaskManager extends HashObject {
} else { } else {
context.closePath(); context.closePath();
} }
} } else if (data.type === SHAPES.RECT) {
else if (data.type === SHAPES.RECT) {
context.rect(shape.x, shape.y, shape.width, shape.height); 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! // TODO - need to be Undefined!
context.arc(shape.x, shape.y, shape.radius, 0, 2 * Math.PI); 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 // ellipse code taken from: http://stackoverflow.com/questions/2172798/how-to-draw-an-oval-in-html5-canvas
const w = shape.width * 2; const w = shape.width * 2;
...@@ -112,8 +109,7 @@ export default class CanvasMaskManager extends HashObject { ...@@ -112,8 +109,7 @@ export default class CanvasMaskManager extends HashObject {
context.bezierCurveTo(xm + ox, y, xe, ym - oy, xe, ym); context.bezierCurveTo(xm + ox, y, xe, ym - oy, xe, ym);
context.bezierCurveTo(xe, ym + oy, xm + ox, ye, xm, ye); context.bezierCurveTo(xe, ym + oy, xm + ox, ye, xm, ye);
context.bezierCurveTo(xm - ox, ye, x, ym + oy, x, ym); 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 rx = shape.x;
const ry = shape.y; const ry = shape.y;
const width = shape.width; const width = shape.width;
......
import Graphics from '../../graphics/Graphics'; import Graphics from '../../graphics/Graphics';
import { WebglRenderer } from '../WebglRenderer'; import {WebglRenderer} from '../WebglRenderer';
import RenderTarget from '../renderTarget/RenderTarget'; import RenderTarget from '../renderTarget/RenderTarget';
/** /**
...@@ -14,6 +13,7 @@ export default class MaskManager { ...@@ -14,6 +13,7 @@ export default class MaskManager {
enableScissor: boolean; enableScissor: boolean;
alphaMaskPool: any[]; alphaMaskPool: any[];
alphaMaskIndex: number; alphaMaskIndex: number;
/** /**
* - The renderer this manager works for. * - The renderer this manager works for.
*/ */
......
import {WebglRenderer} from '../WebglRenderer';
import { WebglRenderer } from '../WebglRenderer';
import Graphics from '../../graphics/Graphics'; import Graphics from '../../graphics/Graphics';
/** /**
...@@ -9,6 +8,7 @@ import Graphics from '../../graphics/Graphics'; ...@@ -9,6 +8,7 @@ import Graphics from '../../graphics/Graphics';
export default class StencilManager { export default class StencilManager {
renderer: WebglRenderer renderer: WebglRenderer
stencilMaskStack: Graphics[]; stencilMaskStack: Graphics[];
/** /**
* @param {WebGLRenderer} renderer - The renderer this manager works for. * @param {WebGLRenderer} renderer - The renderer this manager works for.
*/ */
...@@ -30,8 +30,7 @@ export default class StencilManager { ...@@ -30,8 +30,7 @@ export default class StencilManager {
if (stencilMaskStack.length === 0) { if (stencilMaskStack.length === 0) {
gl.disable(gl.STENCIL_TEST); gl.disable(gl.STENCIL_TEST);
} } else {
else {
gl.enable(gl.STENCIL_TEST); gl.enable(gl.STENCIL_TEST);
} }
} }
...@@ -82,8 +81,7 @@ export default class StencilManager { ...@@ -82,8 +81,7 @@ export default class StencilManager {
gl.disable(gl.STENCIL_TEST); gl.disable(gl.STENCIL_TEST);
gl.clear(gl.STENCIL_BUFFER_BIT); gl.clear(gl.STENCIL_BUFFER_BIT);
gl.clearStencil(0); gl.clearStencil(0);
} } else {
else {
// Decrement the refference stencil value where the popped mask overlaps with the other ones // Decrement the refference stencil value where the popped mask overlaps with the other ones
gl.colorMask(false, false, false, false); gl.colorMask(false, false, false, false);
gl.stencilOp(gl.KEEP, gl.KEEP, gl.DECR); gl.stencilOp(gl.KEEP, gl.KEEP, gl.DECR);
......
import { GC_MODES } from '../../const'; import {GC_MODES} from '../../const';
import { WebglRenderer } from '../WebglRenderer'; import {WebglRenderer} from '../WebglRenderer';
/** /**
* TextureGarbageCollector. This class manages the GPU and ensures that it does not get clogged * TextureGarbageCollector. This class manages the GPU and ensures that it does not get clogged
* up with textures that are no longer being used. * up with textures that are no longer being used.
...@@ -12,6 +13,7 @@ export default class TextureGarbageCollector { ...@@ -12,6 +13,7 @@ export default class TextureGarbageCollector {
maxIdle: number; maxIdle: number;
checkCountMax: number; checkCountMax: number;
mode: number; mode: number;
/** /**
* @param {WebGLRenderer} renderer - The renderer this manager works for. * @param {WebGLRenderer} renderer - The renderer this manager works for.
*/ */
......
import { GLTexture } from '../../../glCore'; import {GLTexture} from '../../../glCore';
import { WRAP_MODES, SCALE_MODES } from '../../const'; import {SCALE_MODES, WRAP_MODES} from '../../const';
import RenderTarget from '../renderTarget/RenderTarget'; import RenderTarget from '../renderTarget/RenderTarget';
import { removeItems } from '../../utils'; import {removeItems} from '../../utils';
import BaseTexture from '../../texture/BaseTexture'; import BaseTexture from '../../texture/BaseTexture';
import { WebglRenderer } from '../WebglRenderer'; import {WebglRenderer} from '../WebglRenderer';
/** /**
* Helper class to create a webGL Texture * Helper class to create a webGL Texture
...@@ -20,6 +20,7 @@ export default class TextureManager { ...@@ -20,6 +20,7 @@ export default class TextureManager {
* Track textures in the renderer so we can no longer listen to them on destruction. * Track textures in the renderer so we can no longer listen to them on destruction.
*/ */
_managedTextures: Array<any>; _managedTextures: Array<any>;
/** /**
* @param {WebGLRenderer} renderer - A reference to the current renderer * @param {WebGLRenderer} renderer - A reference to the current renderer
*/ */
...@@ -49,7 +50,7 @@ export default class TextureManager { ...@@ -49,7 +50,7 @@ export default class TextureManager {
// now lets fill up the textures with empty ones! // now lets fill up the textures with empty ones!
const emptyGLTexture = GLTexture.fromData(gl, null, 1, 1); const emptyGLTexture = GLTexture.fromData(gl, null, 1, 1);
const tempObj = { _glTextures: {} }; const tempObj = {_glTextures: {}};
tempObj._glTextures[this.renderer.CONTEXT_UID] = {}; tempObj._glTextures[this.renderer.CONTEXT_UID] = {};
...@@ -65,7 +66,6 @@ export default class TextureManager { ...@@ -65,7 +66,6 @@ export default class TextureManager {
} }
/** /**
* Binds the texture. This will return the location of the bound texture. * 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 * 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 { ...@@ -96,8 +96,7 @@ export default class TextureManager {
this._nextTextureLocation %= this.boundTextures.length; this._nextTextureLocation %= this.boundTextures.length;
location = this.boundTextures.length - this._nextTextureLocation - 1; location = this.boundTextures.length - this._nextTextureLocation - 1;
} }
} } else {
else {
location = location || 0; location = location || 0;
} }
...@@ -108,8 +107,7 @@ export default class TextureManager { ...@@ -108,8 +107,7 @@ export default class TextureManager {
if (!glTexture) { if (!glTexture) {
// this will also bind the texture.. // this will also bind the texture..
this.updateTexture(texture, location); this.updateTexture(texture, location);
} } else {
else {
// bind the current texture // bind the current texture
if (this.currentLocation !== location) { if (this.currentLocation !== location) {
this.currentLocation = location; this.currentLocation = location;
...@@ -123,6 +121,7 @@ export default class TextureManager { ...@@ -123,6 +121,7 @@ export default class TextureManager {
} }
return location; return location;
} }
/** /**
* Gets a texture. * Gets a texture.
* *
...@@ -140,10 +139,10 @@ export default class TextureManager { ...@@ -140,10 +139,10 @@ export default class TextureManager {
*/ */
updateTexture(texture: any, location?: number): GLTexture { updateTexture(texture: any, location?: number): GLTexture {
//如果是事件返回的 //如果是事件返回的
if(texture.instanceType==="Event"){ if (texture.instanceType === "Event") {
//选择它的target //选择它的target
texture=texture.target.baseTexture||texture.target texture = texture.target.baseTexture || texture.target
}else{ } else {
texture = texture.baseTexture || texture; texture = texture.baseTexture || texture;
} }
...@@ -195,8 +194,7 @@ export default class TextureManager { ...@@ -195,8 +194,7 @@ export default class TextureManager {
renderTarget.resize(texture.width, texture.height); renderTarget.resize(texture.width, texture.height);
texture._glRenderTargets[this.renderer.CONTEXT_UID] = renderTarget; texture._glRenderTargets[this.renderer.CONTEXT_UID] = renderTarget;
glTexture = renderTarget.texture; glTexture = renderTarget.texture;
} } else {
else {
glTexture = new GLTexture(this.gl, null, null, null, null); glTexture = new GLTexture(this.gl, null, null, null, null);
//之前已经active过了,upload里也有bind,这里也许不用执行 //之前已经active过了,upload里也有bind,这里也许不用执行
// glTexture.bind(location); // glTexture.bind(location);
...@@ -217,30 +215,25 @@ export default class TextureManager { ...@@ -217,30 +215,25 @@ export default class TextureManager {
} }
if (texture.wrapMode === WRAP_MODES.CLAMP) { if (texture.wrapMode === WRAP_MODES.CLAMP) {
glTexture.enableWrapClamp(); glTexture.enableWrapClamp();
} } else if (texture.wrapMode === WRAP_MODES.REPEAT) {
else if (texture.wrapMode === WRAP_MODES.REPEAT) {
glTexture.enableWrapRepeat(); glTexture.enableWrapRepeat();
} } else {
else {
glTexture.enableWrapMirrorRepeat(); glTexture.enableWrapMirrorRepeat();
} }
} } else {
else {
glTexture.enableWrapClamp(); glTexture.enableWrapClamp();
} }
if (texture.scaleMode === SCALE_MODES.NEAREST) { if (texture.scaleMode === SCALE_MODES.NEAREST) {
glTexture.enableNearestScaling(); glTexture.enableNearestScaling();
} } else {
else {
glTexture.enableLinearScaling(); glTexture.enableLinearScaling();
} }
} }
// the texture already exists so we only need to update it.. // the texture already exists so we only need to update it..
else if (isRenderTexture) { else if (isRenderTexture) {
texture._glRenderTargets[this.renderer.CONTEXT_UID].resize(texture.width, texture.height); texture._glRenderTargets[this.renderer.CONTEXT_UID].resize(texture.width, texture.height);
} } else {
else {
glTexture.upload(texture.source); glTexture.upload(texture.source);
} }
......
import BatchDrawCall from '../webgl/BatchDrawCall'; import BatchDrawCall from '../webgl/BatchDrawCall';
import { osType } from "../../const" import {osType} from "../../const"
// import State from '../state/State'; // import State from '../state/State';
import ObjectRenderer from '../webgl/ObjectRenderer'; import ObjectRenderer from '../webgl/ObjectRenderer';
import { checkMaxIfStatementsInShader } from '../../../glCore/checkMaxIfStatementsInShader'; import {checkMaxIfStatementsInShader} from '../../../glCore/checkMaxIfStatementsInShader';
import { BatchBuffer } from '../webgl/BatchBuffer'; import {BatchBuffer} from '../webgl/BatchBuffer';
import { generateMultiTextureShader } from '../webgl/generateMultiTextureShader'; import {generateMultiTextureShader} from '../webgl/generateMultiTextureShader';
import { WebglRenderer } from '../WebglRenderer'; import {WebglRenderer} from '../WebglRenderer';
import { GLShader, GLBuffer, VertexArrayObject } from '../../../glCore'; import {GLBuffer, GLShader, VertexArrayObject} from '../../../glCore';
import { nextPow2, log2, premultiplyTint } from '../../utils'; import {log2, nextPow2, premultiplyTint} from '../../utils';
import { DisplayObject } from '../../display/DisplayObject';
let TICK = 0; let TICK = 0;
...@@ -133,8 +132,7 @@ export default class BatchRenderer extends ObjectRenderer { ...@@ -133,8 +132,7 @@ export default class BatchRenderer extends ObjectRenderer {
if (false /*传统方式*/) { if (false /*传统方式*/) {
this.MAX_TEXTURES = 1; this.MAX_TEXTURES = 1;
} } else {
else {
// step 1: first check max textures the GPU can handle. // step 1: first check max textures the GPU can handle.
this.MAX_TEXTURES = Math.min(gl.getParameter(gl.MAX_TEXTURE_IMAGE_UNITS), 16); this.MAX_TEXTURES = Math.min(gl.getParameter(gl.MAX_TEXTURE_IMAGE_UNITS), 16);
...@@ -390,8 +388,7 @@ export default class BatchRenderer extends ObjectRenderer { ...@@ -390,8 +388,7 @@ export default class BatchRenderer extends ObjectRenderer {
this.vertexCount++; this.vertexCount++;
} } else {
else {
// lets use the faster option, always use buffer number 0 // lets use the faster option, always use buffer number 0
this.vertexBuffers[this.vertexCount].upload(buffer.vertices, 0, true); this.vertexBuffers[this.vertexCount].upload(buffer.vertices, 0, true);
...@@ -462,6 +459,7 @@ export default class BatchRenderer extends ObjectRenderer { ...@@ -462,6 +459,7 @@ export default class BatchRenderer extends ObjectRenderer {
indexBuffer[indexCount++] = p + indicies[i]; indexBuffer[indexCount++] = p + indicies[i];
} }
} }
/* /*
renderQuad(vertexData, uvs, argb, textureId, float32View, uint32View, indexBuffer, index, indexCount) renderQuad(vertexData, uvs, argb, textureId, float32View, uint32View, indexBuffer, index, indexCount)
{ {
......
import CanvasRenderer from '../CanvasRenderer'; import CanvasRenderer from '../CanvasRenderer';
import { SHAPES } from '../../const'; import {SHAPES} from '../../const';
import Graphics from '../../graphics/Graphics'; import Graphics from '../../graphics/Graphics';
import GraphicsData from '../../graphics/GraphicsData'; import GraphicsData from '../../graphics/GraphicsData';
...@@ -11,6 +11,7 @@ import GraphicsData from '../../graphics/GraphicsData'; ...@@ -11,6 +11,7 @@ import GraphicsData from '../../graphics/GraphicsData';
*/ */
export class CanvasGraphicsRenderer { export class CanvasGraphicsRenderer {
renderer: CanvasRenderer; renderer: CanvasRenderer;
/** /**
* @param {CanvasRenderer} renderer - The current renderer. * @param {CanvasRenderer} renderer - The current renderer.
*/ */
...@@ -61,8 +62,7 @@ export class CanvasGraphicsRenderer { ...@@ -61,8 +62,7 @@ export class CanvasGraphicsRenderer {
context.lineTo(points[m * 2], points[(m * 2) + 1]); context.lineTo(points[m * 2], points[(m * 2) + 1]);
} }
ccw = !judgeCcw(points) ccw = !judgeCcw(points)
} } else if (data.type === SHAPES.RECT) {
else if (data.type === SHAPES.RECT) {
if (data.holes.length) { if (data.holes.length) {
context.beginPath(); context.beginPath();
context.moveTo(shape.x, shape.y); context.moveTo(shape.x, shape.y);
...@@ -84,14 +84,12 @@ export class CanvasGraphicsRenderer { ...@@ -84,14 +84,12 @@ export class CanvasGraphicsRenderer {
} }
continue continue
} }
} } else if (data.type === SHAPES.CIRC) {
else if (data.type === SHAPES.CIRC) {
//https://www.w3school.com.cn/tags/canvas_arc.asp //https://www.w3school.com.cn/tags/canvas_arc.asp
//默认顺时针 counterclockwise= false //默认顺时针 counterclockwise= false
context.beginPath(); context.beginPath();
context.arc(shape.x, shape.y, shape.radius, 0, 2 * Math.PI, false); 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 // ellipse code taken from: http://stackoverflow.com/questions/2172798/how-to-draw-an-oval-in-html5-canvas
const w = shape.width * 2; const w = shape.width * 2;
...@@ -115,8 +113,7 @@ export class CanvasGraphicsRenderer { ...@@ -115,8 +113,7 @@ export class CanvasGraphicsRenderer {
context.bezierCurveTo(xm + ox, y, xe, ym - oy, xe, ym); context.bezierCurveTo(xm + ox, y, xe, ym - oy, xe, ym);
context.bezierCurveTo(xe, ym + oy, xm + ox, ye, xm, ye); context.bezierCurveTo(xe, ym + oy, xm + ox, ye, xm, ye);
context.bezierCurveTo(xm - ox, ye, x, ym + oy, x, ym); 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 rx = shape.x;
const ry = shape.y; const ry = shape.y;
const width = shape.width; const width = shape.width;
...@@ -162,7 +159,6 @@ export class CanvasGraphicsRenderer { ...@@ -162,7 +159,6 @@ export class CanvasGraphicsRenderer {
} }
/** /**
* destroy graphics object * destroy graphics object
* *
......
import CanvasRenderer from '../CanvasRenderer'; import CanvasRenderer from '../CanvasRenderer';
import { SCALE_MODES } from '../../const'; import {SCALE_MODES} from '../../const';
import { Matrix, GroupD8 } from '../../math'; import {GroupD8, Matrix} from '../../math';
import Sprite from '../../display/Sprite'; import Sprite from '../../display/Sprite';
import { DisplayObject } from '../../display/DisplayObject';
import Graphics from '../../graphics/Graphics';
const canvasRenderWorldTransform = new Matrix(); const canvasRenderWorldTransform = new Matrix();
...@@ -16,6 +14,7 @@ const canvasRenderWorldTransform = new Matrix(); ...@@ -16,6 +14,7 @@ const canvasRenderWorldTransform = new Matrix();
*/ */
export default class CanvasSpriteRenderer { export default class CanvasSpriteRenderer {
renderer: CanvasRenderer; renderer: CanvasRenderer;
/** /**
* @param {CanvasRenderer} renderer -The renderer sprite this batch works for. * @param {CanvasRenderer} renderer -The renderer sprite this batch works for.
*/ */
...@@ -50,7 +49,6 @@ export default class CanvasSpriteRenderer { ...@@ -50,7 +49,6 @@ export default class CanvasSpriteRenderer {
renderer.context.globalAlpha = sprite.worldAlpha; renderer.context.globalAlpha = sprite.worldAlpha;
// If smoothingEnabled is supported and we need to change the smoothing property for sprite texture // If smoothingEnabled is supported and we need to change the smoothing property for sprite texture
const smoothingEnabled = texture.baseTexture.scaleMode === SCALE_MODES.LINEAR; const smoothingEnabled = texture.baseTexture.scaleMode === SCALE_MODES.LINEAR;
...@@ -62,8 +60,7 @@ export default class CanvasSpriteRenderer { ...@@ -62,8 +60,7 @@ export default class CanvasSpriteRenderer {
if (texture.trim) { if (texture.trim) {
dx = (texture.trim.width / 2) + texture.trim.x - (sprite._anchorTexture.x * texture.orig.width); 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); 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; dx = (0.5 - sprite._anchorTexture.x) * texture.orig.width;
dy = (0.5 - sprite._anchorTexture.y) * texture.orig.height; dy = (0.5 - sprite._anchorTexture.y) * texture.orig.height;
......
/** /**
* Creates a Canvas element of the given size. * Creates a Canvas element of the given size.
* 其实就是一个离屏canvas,webgl模式不需要建canvas,因为可以用帧缓存 * 其实就是一个离屏canvas,webgl模式不需要建canvas,因为可以用帧缓存
......
import { Rectangle, Matrix } from '../../math'; import {Matrix, Rectangle} from '../../math';
import { SCALE_MODES } from '../../const'; import {SCALE_MODES} from '../../const';
// import settings from '../../../settings'; // import settings from '../../../settings';
import { GLFramebuffer, GLTexture, GLBuffer } from '../../../glCore'; import {GLBuffer, GLFramebuffer, GLTexture} from '../../../glCore';
import Graphics from '../../graphics/Graphics'; import Graphics from '../../graphics/Graphics';
...@@ -63,6 +63,7 @@ export default class RenderTarget { ...@@ -63,6 +63,7 @@ export default class RenderTarget {
* Whether this object is the root element or not * Whether this object is the root element or not
*/ */
root: boolean; root: boolean;
/** /**
* @param {WebGLRenderingContext} gl - The current WebGL drawing context * @param {WebGLRenderingContext} gl - The current WebGL drawing context
* @param {number} [width=0] - the horizontal range of the filter * @param {number} [width=0] - the horizontal range of the filter
...@@ -111,8 +112,7 @@ export default class RenderTarget { ...@@ -111,8 +112,7 @@ export default class RenderTarget {
if (this.scaleMode === SCALE_MODES.NEAREST) { if (this.scaleMode === SCALE_MODES.NEAREST) {
this.frameBuffer.texture.enableNearestScaling(); this.frameBuffer.texture.enableNearestScaling();
} } else {
else {
this.frameBuffer.texture.enableLinearScaling(); this.frameBuffer.texture.enableLinearScaling();
} }
/* /*
...@@ -122,8 +122,7 @@ export default class RenderTarget { ...@@ -122,8 +122,7 @@ export default class RenderTarget {
// this is used by the base texture // this is used by the base texture
this.texture = this.frameBuffer.texture; this.texture = this.frameBuffer.texture;
} } else {
else {
// make it a null framebuffer.. // make it a null framebuffer..
this.frameBuffer = new GLFramebuffer(gl, 100, 100); this.frameBuffer = new GLFramebuffer(gl, 100, 100);
//帧缓存为空,gltexture也是空 //帧缓存为空,gltexture也是空
...@@ -197,8 +196,7 @@ export default class RenderTarget { ...@@ -197,8 +196,7 @@ export default class RenderTarget {
this.destinationFrame.width | 0, this.destinationFrame.width | 0,
this.destinationFrame.height | 0 this.destinationFrame.height | 0
); );
} } else {
else {
gl.disable(gl.SCISSOR_TEST); gl.disable(gl.SCISSOR_TEST);
} }
...@@ -217,7 +215,7 @@ export default class RenderTarget { ...@@ -217,7 +215,7 @@ export default class RenderTarget {
* @param {Rectangle} destinationFrame - The destination frame. * @param {Rectangle} destinationFrame - The destination frame.
* @param {Rectangle} sourceFrame - The source frame. * @param {Rectangle} sourceFrame - The source frame.
*/ */
calculateProjection(destinationFrame:Rectangle, sourceFrame?:Rectangle) { calculateProjection(destinationFrame: Rectangle, sourceFrame?: Rectangle) {
const pm = this.projectionMatrix; const pm = this.projectionMatrix;
// console.log(destinationFrame) // console.log(destinationFrame)
sourceFrame = sourceFrame || destinationFrame; sourceFrame = sourceFrame || destinationFrame;
...@@ -231,8 +229,7 @@ export default class RenderTarget { ...@@ -231,8 +229,7 @@ export default class RenderTarget {
pm.tx = -1 - (sourceFrame.x * pm.a); pm.tx = -1 - (sourceFrame.x * pm.a);
pm.ty = -1 - (sourceFrame.y * pm.d); pm.ty = -1 - (sourceFrame.y * pm.d);
} } else {
else {
pm.a = 1 / destinationFrame.width * 2; pm.a = 1 / destinationFrame.width * 2;
pm.d = -1 / destinationFrame.height * 2; pm.d = -1 / destinationFrame.height * 2;
......
/** /**
* 批处理用buffer数据 * 批处理用buffer数据
*/ */
...@@ -25,6 +24,7 @@ export class BatchBuffer { ...@@ -25,6 +24,7 @@ export class BatchBuffer {
positions: any; positions: any;
uvs: any; uvs: any;
colors: any; colors: any;
/** /**
* @param {number} size - The size of the buffer in bytes. * @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"; import BaseTexture from "../../texture/BaseTexture";
/** /**
...@@ -26,6 +26,7 @@ export default class BatchDrawCall { ...@@ -26,6 +26,7 @@ export default class BatchDrawCall {
* 绘制类型 * 绘制类型
*/ */
type: number; type: number;
constructor() { constructor() {
this.textures = []; this.textures = [];
// this.ids = []; // this.ids = [];
......
import { DisplayObject } from "../../display/DisplayObject"; import {DisplayObject} from "../../display/DisplayObject";
import { WebglRenderer } from "../WebglRenderer"; import {WebglRenderer} from "../WebglRenderer";
/** /**
* Base for a common object renderer that can be used as a system renderer plugin. * Base for a common object renderer that can be used as a system renderer plugin.
...@@ -12,6 +12,7 @@ export default class ObjectRenderer { ...@@ -12,6 +12,7 @@ export default class ObjectRenderer {
* @member {Renderer} * @member {Renderer}
*/ */
renderer: WebglRenderer renderer: WebglRenderer
constructor(renderer: WebglRenderer) { constructor(renderer: WebglRenderer) {
this.renderer = renderer; this.renderer = renderer;
...@@ -29,6 +30,7 @@ export default class ObjectRenderer { ...@@ -29,6 +30,7 @@ export default class ObjectRenderer {
onContextChange() { onContextChange() {
// do some codes init! // do some codes init!
} }
/** /**
* Starts the renderer and sets the shader * Starts the renderer and sets the shader
* *
...@@ -60,6 +62,7 @@ export default class ObjectRenderer { ...@@ -60,6 +62,7 @@ export default class ObjectRenderer {
render(object: DisplayObject) { render(object: DisplayObject) {
// render the object // render the object
} }
/** /**
* Generic destroy methods to be overridden by the subclass * Generic destroy methods to be overridden by the subclass
*/ */
......
import { mapWebGLBlendModesToPixi } from '../../utils'; import {mapWebGLBlendModesToPixi} from '../../utils';
const BLEND = 0; const BLEND = 0;
const DEPTH_TEST = 1; const DEPTH_TEST = 1;
...@@ -28,6 +28,7 @@ export default class WebGLState { ...@@ -28,6 +28,7 @@ export default class WebGLState {
maxAttribs: any; maxAttribs: any;
attribState: { tempAttribState: any[]; attribState: any[]; }; attribState: { tempAttribState: any[]; attribState: any[]; };
nativeVaoExtension: any; nativeVaoExtension: any;
/** /**
* @param {WebGLRenderingContext} gl - The current WebGL rendering context * @param {WebGLRenderingContext} gl - The current WebGL rendering context
*/ */
...@@ -105,8 +106,7 @@ export default class WebGLState { ...@@ -105,8 +106,7 @@ export default class WebGLState {
if (mode.length === 2) { if (mode.length === 2) {
this.gl.blendFunc(mode[0], mode[1]); this.gl.blendFunc(mode[0], mode[1]);
} } else {
else {
this.gl.blendFuncSeparate(mode[0], mode[1], mode[2], mode[3]); this.gl.blendFuncSeparate(mode[0], mode[1], mode[2], mode[3]);
} }
} }
......
import { GLShader } from '../../../glCore'; import {GLShader} from '../../../glCore';
//顶点着色器程序 //顶点着色器程序
const VSHADER_SOURCE = const VSHADER_SOURCE =
"precision highp float;" + "precision highp float;" +
......
import Container from "../display/Container"; import Container from "../display/Container";
import { VideoEntity } from "./VideoEntity"; import {VideoEntity} from "./VideoEntity";
import Texture from "../texture/Texture"; import Texture from "../texture/Texture";
import Sprite from "../display/Sprite"; import Sprite from "../display/Sprite";
import { Event } from "../events/Event"; import {Event} from "../events/Event";
import Graphics from "../graphics/Graphics"; import {GlobalPro, TextureCache} from "../utils";
import { GlobalPro, TextureCache } from "../utils"; import {RAD_TO_DEG, RENDERER_TYPE} from "../const";
import { RENDERER_TYPE, RAD_TO_DEG } from "../const"; import {DrawAllToCanvas} from "../utils/DrawAllToCanvas";
import { DrawAllToCanvas } from "../utils/DrawAllToCanvas"; import {Button} from "../ui/Button";
import { Button } from "../ui/Button"; import {TextField} from "../text/TextField";
import { TextField } from "../text/TextField"; import {Matrix} from "../math";
import { Matrix } from "../math";
/** /**
* 用于播放动画 * 用于播放动画
...@@ -38,6 +37,7 @@ export class MovieClip extends Container { ...@@ -38,6 +37,7 @@ export class MovieClip extends Container {
* 锁步将按时间间隔来执行动画 * 锁步将按时间间隔来执行动画
*/ */
public lockStep: boolean = false; public lockStep: boolean = false;
/** /**
* mc的当前帧,从1开始 * mc的当前帧,从1开始
* @property currentFrame * @property currentFrame
...@@ -134,6 +134,7 @@ export class MovieClip extends Container { ...@@ -134,6 +134,7 @@ export class MovieClip extends Container {
* 中间帧计时 * 中间帧计时
*/ */
private frameCount: number = 0; private frameCount: number = 0;
/** /**
* 构造函数 * 构造函数
* @method MovieClip * @method MovieClip
...@@ -206,8 +207,7 @@ export class MovieClip extends Container { ...@@ -206,8 +207,7 @@ export class MovieClip extends Container {
let backCanvas; let backCanvas;
if (bitmap.indexOf("iVBO") === 0 || bitmap.indexOf("/9j/2w") === 0) { if (bitmap.indexOf("iVBO") === 0 || bitmap.indexOf("/9j/2w") === 0) {
imgTag.src = 'data:image/png;base64,' + bitmap; imgTag.src = 'data:image/png;base64,' + bitmap;
} } else {
else {
imgTag.src = bitmap; imgTag.src = bitmap;
//这里有问题,再说 //这里有问题,再说
// if (frames[0] && frames[0].layout) { // if (frames[0] && frames[0].layout) {
...@@ -586,6 +586,7 @@ export class MovieClip extends Container { ...@@ -586,6 +586,7 @@ export class MovieClip extends Container {
private _endMark: boolean private _endMark: boolean
commonDeltaTime = 1000 / 60; commonDeltaTime = 1000 / 60;
updateFrame() { updateFrame() {
var s = this; var s = this;
//1帧的时候也有相应的frameCount,无用,return //1帧的时候也有相应的frameCount,无用,return
...@@ -713,6 +714,7 @@ export class MovieClip extends Container { ...@@ -713,6 +714,7 @@ export class MovieClip extends Container {
this._lastFrame = this._curFrame; this._lastFrame = this._curFrame;
return true return true
} }
/** /**
* 重写刷新 * 重写刷新
* @method update * @method update
...@@ -727,7 +729,6 @@ export class MovieClip extends Container { ...@@ -727,7 +729,6 @@ export class MovieClip extends Container {
} }
public destroy(): void { public destroy(): void {
//todo-清除相应的数据引用 //todo-清除相应的数据引用
......
import { SpriteEntity } from './spriteEntity' import {SpriteEntity} from './spriteEntity'
import { ProtoMovieEntity } from "./proto"; import {ProtoMovieEntity} from "./proto";
import { HashObject } from '../HashObject'; import {HashObject} from '../HashObject';
export class VideoEntity extends HashObject { export class VideoEntity extends HashObject {
...@@ -35,12 +35,12 @@ export class VideoEntity extends HashObject { ...@@ -35,12 +35,12 @@ export class VideoEntity extends HashObject {
/** /**
* 图片是否已被缓存,缓存全局,注意名字覆盖 * 图片是否已被缓存,缓存全局,注意名字覆盖
*/ */
hasBeenCached:boolean=false; hasBeenCached: boolean = false;
/** /**
* SpriteEntity[] * SpriteEntity[]
*/ */
sprites:SpriteEntity[] = [] sprites: SpriteEntity[] = []
/** /**
* AudioEntity[] * AudioEntity[]
...@@ -49,7 +49,7 @@ export class VideoEntity extends HashObject { ...@@ -49,7 +49,7 @@ export class VideoEntity extends HashObject {
constructor(spec, images) { constructor(spec, images) {
super(); super();
this._instanceType="VideoEntity"; this._instanceType = "VideoEntity";
if (typeof spec === "object" && spec.$type == ProtoMovieEntity) { if (typeof spec === "object" && spec.$type == ProtoMovieEntity) {
if (typeof spec.params === "object") { if (typeof spec.params === "object") {
...@@ -61,8 +61,7 @@ export class VideoEntity extends HashObject { ...@@ -61,8 +61,7 @@ export class VideoEntity extends HashObject {
} }
this.resetSprites(spec) this.resetSprites(spec)
this.audios = spec.audios this.audios = spec.audios
} } else if (spec) {
else if (spec) {
if (spec.movie) { if (spec.movie) {
if (spec.movie.viewBox) { if (spec.movie.viewBox) {
this.videoSize.width = parseFloat(spec.movie.viewBox.width) || 0.0; this.videoSize.width = parseFloat(spec.movie.viewBox.width) || 0.0;
...@@ -87,7 +86,7 @@ export class VideoEntity extends HashObject { ...@@ -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 { export class EllipsePath extends BezierPath {
......
import { BezierPath } from './bezierPath' import {BezierPath} from './bezierPath'
export class FrameEntity { export class FrameEntity {
...@@ -51,7 +51,7 @@ export class FrameEntity { ...@@ -51,7 +51,7 @@ export class FrameEntity {
this.transform.ty = parseFloat(spec.transform.ty) || 0.0; this.transform.ty = parseFloat(spec.transform.ty) || 0.0;
} }
if (spec.clipPath && spec.clipPath.length > 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) {
if (spec.shapes instanceof Array) { if (spec.shapes instanceof Array) {
...@@ -92,12 +92,17 @@ export class FrameEntity { ...@@ -92,12 +92,17 @@ export class FrameEntity {
lineDash.push(shape.styles.lineDashI) lineDash.push(shape.styles.lineDashI)
} }
if (shape.styles.lineDashII > 0) { 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(shape.styles.lineDashII)
lineDash.push(0) lineDash.push(0)
} }
if (shape.styles.lineDashIII > 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 lineDash[2] = shape.styles.lineDashIII
} }
shape.styles.lineDash = lineDash shape.styles.lineDash = lineDash
...@@ -130,8 +135,7 @@ export class FrameEntity { ...@@ -130,8 +135,7 @@ export class FrameEntity {
} }
if (spec.shapes[0] && spec.shapes[0].type === "keep") { if (spec.shapes[0] && spec.shapes[0].type === "keep") {
this.shapes = FrameEntity.lastShapes; this.shapes = FrameEntity.lastShapes;
} } else {
else {
this.shapes = spec.shapes this.shapes = spec.shapes
FrameEntity.lastShapes = spec.shapes; FrameEntity.lastShapes = spec.shapes;
} }
...@@ -147,5 +151,6 @@ export class FrameEntity { ...@@ -147,5 +151,6 @@ export class FrameEntity {
this.nx = Math.min(Math.min(lbx, rbx), Math.min(llx, lrx)); this.nx = Math.min(Math.min(lbx, rbx), Math.min(llx, lrx));
this.ny = Math.min(Math.min(lby, rby), Math.min(lly, lry)); this.ny = Math.min(Math.min(lby, rby), Math.min(lly, lry));
} }
static lastShapes static lastShapes
} }
\ No newline at end of file
export { VideoEntity } from "./VideoEntity"; export {VideoEntity} from "./VideoEntity";
export { MovieClip } from "./MovieClip"; export {MovieClip} from "./MovieClip";
\ No newline at end of file \ No newline at end of file
...@@ -3,9 +3,10 @@ ...@@ -3,9 +3,10 @@
*/ */
import { ProtoMovieEntity } from "./proto"; import {ProtoMovieEntity} from "./proto";
import { utils } from './pako/utils/common'; import {utils} from './pako/utils/common';
import inflate from "./pako/inflate"; import inflate from "./pako/inflate";
const pako = {} const pako = {}
utils.assign(pako, inflate); utils.assign(pako, inflate);
...@@ -62,8 +63,7 @@ const actions = { ...@@ -62,8 +63,7 @@ const actions = {
images[key] = btoa(value) images[key] = btoa(value)
} }
} }
} } else {
else {
for (const key in movieData.images) { for (const key in movieData.images) {
if (movieData.images.hasOwnProperty(key)) { if (movieData.images.hasOwnProperty(key)) {
const element = movieData.images[key]; const element = movieData.images[key];
...@@ -81,8 +81,7 @@ const actions = { ...@@ -81,8 +81,7 @@ const actions = {
} }
} }
finished && imagesLoadedBlock.call(this) finished && imagesLoadedBlock.call(this)
} } else {
else {
var finished = true; var finished = true;
for (var key in movieData.images) { for (var key in movieData.images) {
if (movieData.images.hasOwnProperty(key)) { if (movieData.images.hasOwnProperty(key)) {
......
'use strict'; 'use strict';
import { strings } from "./utils/strings" import {strings} from "./utils/strings"
import { utils } from "./utils/common" import {utils} from "./utils/common"
import zlib_inflate from './zlib/inflate'; import zlib_inflate from './zlib/inflate';
import c from './zlib/constants'; import c from './zlib/constants';
...@@ -105,7 +105,9 @@ function Inflate(options) { ...@@ -105,7 +105,9 @@ function Inflate(options) {
// because we have no header for autodetect. // because we have no header for autodetect.
if (opt.raw && (opt.windowBits >= 0) && (opt.windowBits < 16)) { if (opt.raw && (opt.windowBits >= 0) && (opt.windowBits < 16)) {
opt.windowBits = -opt.windowBits; 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 // If `windowBits` not defined (and mode not raw) - set autodetect flag for gzip/deflate
...@@ -201,7 +203,9 @@ Inflate.prototype.push = function (data, mode) { ...@@ -201,7 +203,9 @@ Inflate.prototype.push = function (data, mode) {
// when we check that all output data was flushed. // when we check that all output data was flushed.
var allowBufError = false; 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); _mode = (mode === ~~mode) ? mode : ((mode === true) ? c.Z_FINISH : c.Z_NO_FLUSH);
// Convert data if needed // Convert data if needed
...@@ -254,7 +258,9 @@ Inflate.prototype.push = function (data, mode) { ...@@ -254,7 +258,9 @@ Inflate.prototype.push = function (data, mode) {
// move tail // move tail
strm.next_out = tail; strm.next_out = tail;
strm.avail_out = chunkSize - 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); this.onData(utf8str);
...@@ -386,7 +392,9 @@ function inflate(input, options) { ...@@ -386,7 +392,9 @@ function inflate(input, options) {
inflator.push(input, true); inflator.push(input, true);
// That will never happens, if you don't cheat with options :) // 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; return inflator.result;
} }
...@@ -422,4 +430,4 @@ function inflateRaw(input, options) { ...@@ -422,4 +430,4 @@ function inflateRaw(input, options) {
// exports.inflateRaw = inflateRaw; // exports.inflateRaw = inflateRaw;
// exports.ungzip = inflate; // exports.ungzip = inflate;
export default { inflate } export default {inflate}
...@@ -37,8 +37,12 @@ function assign(obj, objO) { ...@@ -37,8 +37,12 @@ function assign(obj, objO) {
// reduce buffer size, avoiding mem copy // reduce buffer size, avoiding mem copy
function shrinkBuf(buf, size) { function shrinkBuf(buf, size) {
if (buf.length === size) { return buf; } if (buf.length === size) {
if (buf.subarray) { return buf.subarray(0, size); } return buf;
}
if (buf.subarray) {
return buf.subarray(0, size);
}
buf.length = size; buf.length = size;
return buf; return buf;
}; };
...@@ -109,7 +113,6 @@ if (TYPED_OK) { ...@@ -109,7 +113,6 @@ if (TYPED_OK) {
} }
export const utils = { export const utils = {
assign, assign,
shrinkBuf, shrinkBuf,
......
// String encode/decode helpers // String encode/decode helpers
'use strict'; 'use strict';
import {utils}from "./common" import {utils} from "./common"
// Quick check if we can use fast array to bin string conversion // Quick check if we can use fast array to bin string conversion
// //
...@@ -11,8 +11,16 @@ import {utils}from "./common" ...@@ -11,8 +11,16 @@ import {utils}from "./common"
var STR_APPLY_OK = true; var STR_APPLY_OK = true;
var STR_APPLY_UIA_OK = true; var STR_APPLY_UIA_OK = true;
try { String.fromCharCode.apply(null, [0]); } catch (__) { STR_APPLY_OK = false; } try {
try { String.fromCharCode.apply(null, new Uint8Array(1)); } catch (__) { STR_APPLY_UIA_OK = false; } 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) // Table with utf8 lengths (calculated by first byte of sequence)
...@@ -121,11 +129,18 @@ function buf2string(buf, max) { ...@@ -121,11 +129,18 @@ function buf2string(buf, max) {
for (out = 0, i = 0; i < len;) { for (out = 0, i = 0; i < len;) {
c = buf[i++]; c = buf[i++];
// quick process ascii // quick process ascii
if (c < 0x80) { utf16buf[out++] = c; continue; } if (c < 0x80) {
utf16buf[out++] = c;
continue;
}
c_len = _utf8len[c]; c_len = _utf8len[c];
// skip 5 & 6 byte codes // 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 // apply mask on first byte
c &= c_len === 2 ? 0x1f : c_len === 3 ? 0x0f : 0x07; c &= c_len === 2 ? 0x1f : c_len === 3 ? 0x0f : 0x07;
...@@ -136,7 +151,10 @@ function buf2string(buf, max) { ...@@ -136,7 +151,10 @@ function buf2string(buf, max) {
} }
// terminated by end of string? // terminated by end of string?
if (c_len > 1) { utf16buf[out++] = 0xfffd; continue; } if (c_len > 1) {
utf16buf[out++] = 0xfffd;
continue;
}
if (c < 0x10000) { if (c < 0x10000) {
utf16buf[out++] = c; utf16buf[out++] = c;
...@@ -161,24 +179,32 @@ function utf8border(buf, max) { ...@@ -161,24 +179,32 @@ function utf8border(buf, max) {
var pos; var pos;
max = max || buf.length; 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 // go back from last position, until start of sequence found
pos = max - 1; pos = max - 1;
while (pos >= 0 && (buf[pos] & 0xC0) === 0x80) { pos--; } while (pos >= 0 && (buf[pos] & 0xC0) === 0x80) {
pos--;
}
// Very small and broken sequence, // Very small and broken sequence,
// return max, because we should return something anyway. // 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, // If we came to start of buffer - that means buffer is too small,
// return max too. // return max too.
if (pos === 0) { return max; } if (pos === 0) {
return max;
}
return (pos + _utf8len[buf[pos]] > max) ? pos : max; return (pos + _utf8len[buf[pos]] > max) ? pos : max;
}; };
export const strings= { export const strings = {
utf8border, utf8border,
buf2string, buf2string,
binstring2buf, binstring2buf,
......
...@@ -24,8 +24,8 @@ ...@@ -24,8 +24,8 @@
// 3. This notice may not be removed or altered from any source distribution. // 3. This notice may not be removed or altered from any source distribution.
function adler32(adler, buf, len, pos) { function adler32(adler, buf, len, pos) {
var s1 = (adler & 0xffff) |0, var s1 = (adler & 0xffff) | 0,
s2 = ((adler >>> 16) & 0xffff) |0, s2 = ((adler >>> 16) & 0xffff) | 0,
n = 0; n = 0;
while (len !== 0) { while (len !== 0) {
...@@ -36,15 +36,15 @@ function adler32(adler, buf, len, pos) { ...@@ -36,15 +36,15 @@ function adler32(adler, buf, len, pos) {
len -= n; len -= n;
do { do {
s1 = (s1 + buf[pos++]) |0; s1 = (s1 + buf[pos++]) | 0;
s2 = (s2 + s1) |0; s2 = (s2 + s1) | 0;
} while (--n); } while (--n);
s1 %= 65521; s1 %= 65521;
s2 %= 65521; s2 %= 65521;
} }
return (s1 | (s2 << 16)) |0; return (s1 | (s2 << 16)) | 0;
} }
......
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
// misrepresented as being the original software. // misrepresented as being the original software.
// 3. This notice may not be removed or altered from any source distribution. // 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 trees from './trees';
import adler32 from './adler32'; import adler32 from './adler32';
...@@ -132,7 +132,12 @@ function rank(f) { ...@@ -132,7 +132,12 @@ function rank(f) {
return ((f) << 1) - ((f) > 4 ? 9 : 0); 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) { ...@@ -149,7 +154,9 @@ function flush_pending(strm) {
if (len > strm.avail_out) { if (len > strm.avail_out) {
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); utils.arraySet(strm.output, s.pending_buf, s.pending_out, len, strm.next_out);
strm.next_out += len; strm.next_out += len;
...@@ -198,8 +205,12 @@ function putShortMSB(s, b) { ...@@ -198,8 +205,12 @@ function putShortMSB(s, b) {
function read_buf(strm, buf, start, size) { function read_buf(strm, buf, start, size) {
var len = strm.avail_in; var len = strm.avail_in;
if (len > size) { len = size; } if (len > size) {
if (len === 0) { return 0; } len = size;
}
if (len === 0) {
return 0;
}
strm.avail_in -= len; strm.avail_in -= len;
...@@ -207,9 +218,7 @@ function read_buf(strm, buf, start, size) { ...@@ -207,9 +218,7 @@ function read_buf(strm, buf, start, size) {
utils.arraySet(buf, strm.input, strm.next_in, len, start); utils.arraySet(buf, strm.input, strm.next_in, len, start);
if (strm.state.wrap === 1) { if (strm.state.wrap === 1) {
strm.adler = adler32(strm.adler, buf, len, start); 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); strm.adler = crc32(strm.adler, buf, len, start);
} }
...@@ -264,7 +273,9 @@ function longest_match(s, cur_match) { ...@@ -264,7 +273,9 @@ function longest_match(s, cur_match) {
/* Do not look for matches beyond the end of the input. This is necessary /* Do not look for matches beyond the end of the input. This is necessary
* to make deflate deterministic. * 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"); // Assert((ulg)s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead");
...@@ -741,7 +752,9 @@ function deflate_slow(s, flush) { ...@@ -741,7 +752,9 @@ function deflate_slow(s, flush) {
if (s.lookahead < MIN_LOOKAHEAD && flush === Z_NO_FLUSH) { if (s.lookahead < MIN_LOOKAHEAD && flush === Z_NO_FLUSH) {
return BS_NEED_MORE; 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 /* Insert the string window[strstart .. strstart+2] in the
...@@ -902,7 +915,9 @@ function deflate_rle(s, flush) { ...@@ -902,7 +915,9 @@ function deflate_rle(s, flush) {
if (s.lookahead <= MAX_MATCH && flush === Z_NO_FLUSH) { if (s.lookahead <= MAX_MATCH && flush === Z_NO_FLUSH) {
return BS_NEED_MORE; 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 */ /* See how many times the previous byte repeats */
...@@ -1317,8 +1332,12 @@ function deflateReset(strm) { ...@@ -1317,8 +1332,12 @@ function deflateReset(strm) {
function deflateSetHeader(strm, head) { function deflateSetHeader(strm, head) {
if (!strm || !strm.state) { return Z_STREAM_ERROR; } if (!strm || !strm.state) {
if (strm.state.wrap !== 2) { return Z_STREAM_ERROR; } return Z_STREAM_ERROR;
}
if (strm.state.wrap !== 2) {
return Z_STREAM_ERROR;
}
strm.state.gzhead = head; strm.state.gzhead = head;
return Z_OK; return Z_OK;
} }
...@@ -1337,9 +1356,7 @@ function deflateInit2(strm, level, method, windowBits, memLevel, strategy) { ...@@ -1337,9 +1356,7 @@ function deflateInit2(strm, level, method, windowBits, memLevel, strategy) {
if (windowBits < 0) { /* suppress zlib wrapper */ if (windowBits < 0) { /* suppress zlib wrapper */
wrap = 0; wrap = 0;
windowBits = -windowBits; windowBits = -windowBits;
} } else if (windowBits > 15) {
else if (windowBits > 15) {
wrap = 2; /* write gzip wrapper instead */ wrap = 2; /* write gzip wrapper instead */
windowBits -= 16; windowBits -= 16;
} }
...@@ -1447,8 +1464,7 @@ function deflate(strm, flush) { ...@@ -1447,8 +1464,7 @@ function deflate(strm, flush) {
4 : 0)); 4 : 0));
put_byte(s, OS_CODE); put_byte(s, OS_CODE);
s.status = BUSY_STATE; s.status = BUSY_STATE;
} } else {
else {
put_byte(s, (s.gzhead.text ? 1 : 0) + put_byte(s, (s.gzhead.text ? 1 : 0) +
(s.gzhead.hcrc ? 2 : 0) + (s.gzhead.hcrc ? 2 : 0) +
(!s.gzhead.extra ? 0 : 4) + (!s.gzhead.extra ? 0 : 4) +
...@@ -1473,8 +1489,7 @@ function deflate(strm, flush) { ...@@ -1473,8 +1489,7 @@ function deflate(strm, flush) {
s.gzindex = 0; s.gzindex = 0;
s.status = EXTRA_STATE; s.status = EXTRA_STATE;
} }
} } else // DEFLATE header
else // DEFLATE header
{ {
var header = (Z_DEFLATED + ((s.w_bits - 8) << 4)) << 8; var header = (Z_DEFLATED + ((s.w_bits - 8) << 4)) << 8;
var level_flags = -1; var level_flags = -1;
...@@ -1489,7 +1504,9 @@ function deflate(strm, flush) { ...@@ -1489,7 +1504,9 @@ function deflate(strm, flush) {
level_flags = 3; level_flags = 3;
} }
header |= (level_flags << 6); header |= (level_flags << 6);
if (s.strstart !== 0) { header |= PRESET_DICT; } if (s.strstart !== 0) {
header |= PRESET_DICT;
}
header += 31 - (header % 31); header += 31 - (header % 31);
s.status = BUSY_STATE; s.status = BUSY_STATE;
...@@ -1530,8 +1547,7 @@ function deflate(strm, flush) { ...@@ -1530,8 +1547,7 @@ function deflate(strm, flush) {
s.gzindex = 0; s.gzindex = 0;
s.status = NAME_STATE; s.status = NAME_STATE;
} }
} } else {
else {
s.status = NAME_STATE; s.status = NAME_STATE;
} }
} }
...@@ -1568,8 +1584,7 @@ function deflate(strm, flush) { ...@@ -1568,8 +1584,7 @@ function deflate(strm, flush) {
s.gzindex = 0; s.gzindex = 0;
s.status = COMMENT_STATE; s.status = COMMENT_STATE;
} }
} } else {
else {
s.status = COMMENT_STATE; s.status = COMMENT_STATE;
} }
} }
...@@ -1605,8 +1620,7 @@ function deflate(strm, flush) { ...@@ -1605,8 +1620,7 @@ function deflate(strm, flush) {
if (val === 0) { if (val === 0) {
s.status = HCRC_STATE; s.status = HCRC_STATE;
} }
} } else {
else {
s.status = HCRC_STATE; s.status = HCRC_STATE;
} }
} }
...@@ -1621,8 +1635,7 @@ function deflate(strm, flush) { ...@@ -1621,8 +1635,7 @@ function deflate(strm, flush) {
strm.adler = 0; //crc32(0L, Z_NULL, 0); strm.adler = 0; //crc32(0L, Z_NULL, 0);
s.status = BUSY_STATE; s.status = BUSY_STATE;
} }
} } else {
else {
s.status = BUSY_STATE; s.status = BUSY_STATE;
} }
} }
...@@ -1684,8 +1697,7 @@ function deflate(strm, flush) { ...@@ -1684,8 +1697,7 @@ function deflate(strm, flush) {
if (bstate === BS_BLOCK_DONE) { if (bstate === BS_BLOCK_DONE) {
if (flush === Z_PARTIAL_FLUSH) { if (flush === Z_PARTIAL_FLUSH) {
trees._tr_align(s); 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); trees._tr_stored_block(s, 0, 0, false);
/* For a full flush, this empty block will be recognized /* For a full flush, this empty block will be recognized
...@@ -1712,8 +1724,12 @@ function deflate(strm, flush) { ...@@ -1712,8 +1724,12 @@ function deflate(strm, flush) {
//Assert(strm->avail_out > 0, "bug2"); //Assert(strm->avail_out > 0, "bug2");
//if (strm.avail_out <= 0) { throw new Error("bug2");} //if (strm.avail_out <= 0) { throw new Error("bug2");}
if (flush !== Z_FINISH) { return Z_OK; } if (flush !== Z_FINISH) {
if (s.wrap <= 0) { return Z_STREAM_END; } return Z_OK;
}
if (s.wrap <= 0) {
return Z_STREAM_END;
}
/* Write the trailer */ /* Write the trailer */
if (s.wrap === 2) { if (s.wrap === 2) {
...@@ -1725,8 +1741,7 @@ function deflate(strm, flush) { ...@@ -1725,8 +1741,7 @@ function deflate(strm, flush) {
put_byte(s, (strm.total_in >> 8) & 0xff); put_byte(s, (strm.total_in >> 8) & 0xff);
put_byte(s, (strm.total_in >> 16) & 0xff); put_byte(s, (strm.total_in >> 16) & 0xff);
put_byte(s, (strm.total_in >> 24) & 0xff); put_byte(s, (strm.total_in >> 24) & 0xff);
} } else {
else {
putShortMSB(s, strm.adler >>> 16); putShortMSB(s, strm.adler >>> 16);
putShortMSB(s, strm.adler & 0xffff); putShortMSB(s, strm.adler & 0xffff);
} }
...@@ -1735,7 +1750,9 @@ function deflate(strm, flush) { ...@@ -1735,7 +1750,9 @@ function deflate(strm, flush) {
/* If avail_out is zero, the application will call deflate again /* If avail_out is zero, the application will call deflate again
* to flush the rest. * 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! */ /* write the trailer only once! */
return s.pending !== 0 ? Z_OK : Z_STREAM_END; return s.pending !== 0 ? Z_OK : Z_STREAM_END;
} }
...@@ -1851,7 +1868,8 @@ function deflateSetDictionary(strm, dictionary) { ...@@ -1851,7 +1868,8 @@ function deflateSetDictionary(strm, dictionary) {
s.wrap = wrap; s.wrap = wrap;
return Z_OK; return Z_OK;
} }
const deflateInfo= 'pako deflate (from Nodeca project)';
const deflateInfo = 'pako deflate (from Nodeca project)';
export default { export default {
deflateInit, deflateInit,
......
...@@ -130,7 +130,7 @@ export default function inflate_fast(strm, start) { ...@@ -130,7 +130,7 @@ export default function inflate_fast(strm, start) {
here = lcode[hold & lmask]; here = lcode[hold & lmask];
dolen: dolen:
for (;;) { // Goto emulation for (; ;) { // Goto emulation
op = here >>> 24/*here.bits*/; op = here >>> 24/*here.bits*/;
hold >>>= op; hold >>>= op;
bits -= op; bits -= op;
...@@ -140,8 +140,7 @@ export default function inflate_fast(strm, start) { ...@@ -140,8 +140,7 @@ export default function inflate_fast(strm, start) {
// "inflate: literal '%c'\n" : // "inflate: literal '%c'\n" :
// "inflate: literal 0x%02x\n", here.val)); // "inflate: literal 0x%02x\n", here.val));
output[_out++] = here & 0xffff/*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*/; len = here & 0xffff/*here.val*/;
op &= 15; /* number of extra bits */ op &= 15; /* number of extra bits */
if (op) { if (op) {
...@@ -163,7 +162,7 @@ export default function inflate_fast(strm, start) { ...@@ -163,7 +162,7 @@ export default function inflate_fast(strm, start) {
here = dcode[hold & dmask]; here = dcode[hold & dmask];
dodist: dodist:
for (;;) { // goto emulation for (; ;) { // goto emulation
op = here >>> 24/*here.bits*/; op = here >>> 24/*here.bits*/;
hold >>>= op; hold >>>= op;
bits -= op; bits -= op;
...@@ -235,8 +234,7 @@ export default function inflate_fast(strm, start) { ...@@ -235,8 +234,7 @@ export default function inflate_fast(strm, start) {
from = _out - dist; /* rest from output */ from = _out - dist; /* rest from output */
from_source = output; from_source = output;
} }
} } else if (wnext < op) { /* wrap around window */
else if (wnext < op) { /* wrap around window */
from += wsize + wnext - op; from += wsize + wnext - op;
op -= wnext; op -= wnext;
if (op < len) { /* some from end of window */ if (op < len) { /* some from end of window */
...@@ -255,8 +253,7 @@ export default function inflate_fast(strm, start) { ...@@ -255,8 +253,7 @@ export default function inflate_fast(strm, start) {
from_source = output; from_source = output;
} }
} }
} } else { /* contiguous in window */
else { /* contiguous in window */
from += wnext - op; from += wnext - op;
if (op < len) { /* some from window */ if (op < len) { /* some from window */
len -= op; len -= op;
...@@ -279,8 +276,7 @@ export default function inflate_fast(strm, start) { ...@@ -279,8 +276,7 @@ export default function inflate_fast(strm, start) {
output[_out++] = from_source[from++]; output[_out++] = from_source[from++];
} }
} }
} } else {
else {
from = _out - dist; /* copy direct from output */ from = _out - dist; /* copy direct from output */
do { /* minimum length is three */ do { /* minimum length is three */
output[_out++] = output[from++]; output[_out++] = output[from++];
...@@ -295,12 +291,10 @@ export default function inflate_fast(strm, start) { ...@@ -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))]; here = dcode[(here & 0xffff)/*here.val*/ + (hold & ((1 << op) - 1))];
continue dodist; continue dodist;
} } else {
else {
strm.msg = 'invalid distance code'; strm.msg = 'invalid distance code';
state.mode = BAD; state.mode = BAD;
break top; break top;
...@@ -308,17 +302,14 @@ export default function inflate_fast(strm, start) { ...@@ -308,17 +302,14 @@ export default function inflate_fast(strm, start) {
break; // need to emulate goto via "continue" 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))]; here = lcode[(here & 0xffff)/*here.val*/ + (hold & ((1 << op) - 1))];
continue dolen; continue dolen;
} } else if (op & 32) { /* end-of-block */
else if (op & 32) { /* end-of-block */
//Tracevv((stderr, "inflate: end of block\n")); //Tracevv((stderr, "inflate: end of block\n"));
state.mode = TYPE; state.mode = TYPE;
break top; break top;
} } else {
else {
strm.msg = 'invalid literal/length code'; strm.msg = 'invalid literal/length code';
state.mode = BAD; state.mode = BAD;
break top; break top;
......
This diff is collapsed.
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
// misrepresented as being the original software. // misrepresented as being the original software.
// 3. This notice may not be removed or altered from any source distribution. // 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 MAXBITS = 15;
var ENOUGH_LENS = 852; var ENOUGH_LENS = 852;
...@@ -123,7 +123,9 @@ export default function inflate_table(type, lens, lens_index, codes, table, tabl ...@@ -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 */ /* bound code lengths, force root to be within code lengths */
root = bits; root = bits;
for (max = MAXBITS; max >= 1; max--) { for (max = MAXBITS; max >= 1; max--) {
if (count[max] !== 0) { break; } if (count[max] !== 0) {
break;
}
} }
if (root > max) { if (root > max) {
root = max; root = max;
...@@ -144,7 +146,9 @@ export default function inflate_table(type, lens, lens_index, codes, table, tabl ...@@ -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 */ return 0; /* no symbols, but wait for decoding to report error */
} }
for (min = 1; min < max; min++) { for (min = 1; min < max; min++) {
if (count[min] !== 0) { break; } if (count[min] !== 0) {
break;
}
} }
if (root < min) { if (root < min) {
root = min; root = min;
...@@ -251,12 +255,10 @@ export default function inflate_table(type, lens, lens_index, codes, table, tabl ...@@ -251,12 +255,10 @@ export default function inflate_table(type, lens, lens_index, codes, table, tabl
if (work[sym] < end) { if (work[sym] < end) {
here_op = 0; here_op = 0;
here_val = work[sym]; here_val = work[sym];
} } else if (work[sym] > end) {
else if (work[sym] > end) {
here_op = extra[extra_index + work[sym]]; here_op = extra[extra_index + work[sym]];
here_val = base[base_index + work[sym]]; here_val = base[base_index + work[sym]];
} } else {
else {
here_op = 32 + 64; /* end of block */ here_op = 32 + 64; /* end of block */
here_val = 0; here_val = 0;
} }
...@@ -285,7 +287,9 @@ export default function inflate_table(type, lens, lens_index, codes, table, tabl ...@@ -285,7 +287,9 @@ export default function inflate_table(type, lens, lens_index, codes, table, tabl
/* go to next symbol, update count, len */ /* go to next symbol, update count, len */
sym++; sym++;
if (--count[len] === 0) { if (--count[len] === 0) {
if (len === max) { break; } if (len === max) {
break;
}
len = lens[lens_index + work[sym]]; len = lens[lens_index + work[sym]];
} }
...@@ -304,7 +308,9 @@ export default function inflate_table(type, lens, lens_index, codes, table, tabl ...@@ -304,7 +308,9 @@ export default function inflate_table(type, lens, lens_index, codes, table, tabl
left = 1 << curr; left = 1 << curr;
while (curr + drop < max) { while (curr + drop < max) {
left -= count[curr + drop]; left -= count[curr + drop];
if (left <= 0) { break; } if (left <= 0) {
break;
}
curr++; curr++;
left <<= 1; left <<= 1;
} }
......
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
/* eslint-disable space-unary-ops */ /* eslint-disable space-unary-ops */
import { utils } from '../utils/common'; import {utils} from '../utils/common';
/* Public constants ==========================================================*/ /* Public constants ==========================================================*/
/* ===========================================================================*/ /* ===========================================================================*/
...@@ -42,7 +42,12 @@ var Z_UNKNOWN = 2; ...@@ -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 // From zutil.h
...@@ -106,16 +111,16 @@ var REPZ_11_138 = 18; ...@@ -106,16 +111,16 @@ var REPZ_11_138 = 18;
/* eslint-disable comma-spacing,array-bracket-spacing */ /* eslint-disable comma-spacing,array-bracket-spacing */
var extra_lbits = /* extra bits for each length code */ 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 */ 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 */ 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 = 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 */ /* eslint-enable comma-spacing,array-bracket-spacing */
/* The lengths of the bit length codes are sent in order of decreasing /* The lengths of the bit length codes are sent in order of decreasing
...@@ -162,6 +167,7 @@ zero(base_length); ...@@ -162,6 +167,7 @@ zero(base_length);
var base_dist = new Array(D_CODES); var base_dist = new Array(D_CODES);
zero(base_dist); zero(base_dist);
/* First normalized distance for each code (0 = distance of 1) */ /* First normalized distance for each code (0 = distance of 1) */
...@@ -190,7 +196,6 @@ function TreeDesc(dyn_tree, stat_desc) { ...@@ -190,7 +196,6 @@ function TreeDesc(dyn_tree, stat_desc) {
} }
function d_code(dist) { function d_code(dist) {
return dist < 256 ? _dist_code[dist] : _dist_code[256 + (dist >>> 7)]; return dist < 256 ? _dist_code[dist] : _dist_code[256 + (dist >>> 7)];
} }
...@@ -310,7 +315,9 @@ function gen_bitlen(s, desc) ...@@ -310,7 +315,9 @@ function gen_bitlen(s, desc)
tree[n * 2 + 1]/*.Len*/ = bits; tree[n * 2 + 1]/*.Len*/ = bits;
/* We overwrite tree[n].Dad which is no longer needed */ /* 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]++; s.bl_count[bits]++;
xbits = 0; xbits = 0;
...@@ -323,7 +330,9 @@ function gen_bitlen(s, desc) ...@@ -323,7 +330,9 @@ function gen_bitlen(s, desc)
s.static_len += f * (stree[n * 2 + 1]/*.Len*/ + xbits); s.static_len += f * (stree[n * 2 + 1]/*.Len*/ + xbits);
} }
} }
if (overflow === 0) { return; } if (overflow === 0) {
return;
}
// Trace((stderr,"\nbit length overflow\n")); // Trace((stderr,"\nbit length overflow\n"));
/* This happens for example on obj2 and pic of the Calgary corpus */ /* This happens for example on obj2 and pic of the Calgary corpus */
...@@ -331,7 +340,9 @@ function gen_bitlen(s, desc) ...@@ -331,7 +340,9 @@ function gen_bitlen(s, desc)
/* Find the first bit length which could increase: */ /* Find the first bit length which could increase: */
do { do {
bits = max_length - 1; 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]--; /* move one leaf down the tree */
s.bl_count[bits + 1] += 2; /* move one overflow item as its brother */ s.bl_count[bits + 1] += 2; /* move one overflow item as its brother */
s.bl_count[max_length]--; s.bl_count[max_length]--;
...@@ -350,7 +361,9 @@ function gen_bitlen(s, desc) ...@@ -350,7 +361,9 @@ function gen_bitlen(s, desc)
n = s.bl_count[bits]; n = s.bl_count[bits];
while (n !== 0) { while (n !== 0) {
m = s.heap[--h]; m = s.heap[--h];
if (m > max_code) { continue; } if (m > max_code) {
continue;
}
if (tree[m * 2 + 1]/*.Len*/ !== bits) { if (tree[m * 2 + 1]/*.Len*/ !== bits) {
// Trace((stderr,"code %d bits %d->%d\n", m, tree[m].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*/; 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) ...@@ -395,7 +408,9 @@ function gen_codes(tree, max_code, bl_count)
for (n = 0; n <= max_code; n++) { for (n = 0; n <= max_code; n++) {
var len = tree[n * 2 + 1]/*.Len*/; var len = tree[n * 2 + 1]/*.Len*/;
if (len === 0) { continue; } if (len === 0) {
continue;
}
/* Now reverse the bits */ /* Now reverse the bits */
tree[n * 2]/*.Code*/ = bi_reverse(next_code[len]++, len); tree[n * 2]/*.Code*/ = bi_reverse(next_code[len]++, len);
...@@ -421,13 +436,13 @@ function tr_static_init() { ...@@ -421,13 +436,13 @@ function tr_static_init() {
//if (static_init_done) return; //if (static_init_done) return;
/* For some embedded targets, global variables are not initialized: */ /* 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.static_tree = static_ltree;
static_l_desc.extra_bits = extra_lbits; static_l_desc.extra_bits = extra_lbits;
static_d_desc.static_tree = static_dtree; static_d_desc.static_tree = static_dtree;
static_d_desc.extra_bits = extra_dbits; static_d_desc.extra_bits = extra_dbits;
static_bl_desc.extra_bits = extra_blbits; static_bl_desc.extra_bits = extra_blbits;
#endif*/ #endif*/
/* Initialize the mapping length (0..255) -> length code (0..28) */ /* Initialize the mapping length (0..255) -> length code (0..28) */
length = 0; length = 0;
...@@ -516,9 +531,15 @@ function init_block(s) { ...@@ -516,9 +531,15 @@ function init_block(s) {
var n; /* iterates over tree elements */ var n; /* iterates over tree elements */
/* Initialize the trees. */ /* Initialize the trees. */
for (n = 0; n < L_CODES; n++) { s.dyn_ltree[n * 2]/*.Freq*/ = 0; } for (n = 0; n < L_CODES; n++) {
for (n = 0; n < D_CODES; n++) { s.dyn_dtree[n * 2]/*.Freq*/ = 0; } s.dyn_ltree[n * 2]/*.Freq*/ = 0;
for (n = 0; n < BL_CODES; n++) { s.bl_tree[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.dyn_ltree[END_BLOCK * 2]/*.Freq*/ = 1;
s.opt_len = s.static_len = 0; s.opt_len = s.static_len = 0;
...@@ -529,8 +550,7 @@ function init_block(s) { ...@@ -529,8 +550,7 @@ function init_block(s) {
/* =========================================================================== /* ===========================================================================
* Flush the bit buffer and align the output on a byte boundary * 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) { if (s.bi_valid > 8) {
put_short(s, s.bi_buf); put_short(s, s.bi_buf);
} else if (s.bi_valid > 0) { } else if (s.bi_valid > 0) {
...@@ -595,7 +615,9 @@ function pqdownheap(s, tree, k) ...@@ -595,7 +615,9 @@ function pqdownheap(s, tree, k)
j++; j++;
} }
/* Exit if v is smaller than both sons */ /* 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 */ /* Exchange v with the smallest son */
s.heap[k] = s.heap[j]; s.heap[k] = s.heap[j];
...@@ -724,7 +746,9 @@ function build_tree(s, desc) ...@@ -724,7 +746,9 @@ function build_tree(s, desc)
/* The elements heap[heap_len/2+1 .. heap_len] are leaves of the tree, /* The elements heap[heap_len/2+1 .. heap_len] are leaves of the tree,
* establish sub-heaps of increasing lengths: * 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 /* Construct the Huffman tree by repeatedly combining the least two
* frequent nodes. * frequent nodes.
...@@ -803,7 +827,9 @@ function scan_tree(s, tree, max_code) ...@@ -803,7 +827,9 @@ function scan_tree(s, tree, max_code)
} else if (curlen !== 0) { } 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*/++; s.bl_tree[REP_3_6 * 2]/*.Freq*/++;
} else if (count <= 10) { } else if (count <= 10) {
...@@ -865,7 +891,9 @@ function send_tree(s, tree, max_code) ...@@ -865,7 +891,9 @@ function send_tree(s, tree, max_code)
continue; continue;
} else if (count < min_count) { } 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) { } else if (curlen !== 0) {
if (curlen !== prevlen) { if (curlen !== prevlen) {
...@@ -1021,8 +1049,7 @@ var static_init_done = false; ...@@ -1021,8 +1049,7 @@ var static_init_done = false;
/* =========================================================================== /* ===========================================================================
* Initialize the tree data structures for a new zlib stream. * Initialize the tree data structures for a new zlib stream.
*/ */
function _tr_init(s) function _tr_init(s) {
{
if (!static_init_done) { if (!static_init_done) {
tr_static_init(); tr_static_init();
...@@ -1112,7 +1139,9 @@ function _tr_flush_block(s, buf, stored_len, last) ...@@ -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, // opt_lenb, s->opt_len, static_lenb, s->static_len, stored_len,
// s->last_lit)); // s->last_lit));
if (static_lenb <= opt_lenb) { opt_lenb = static_lenb; } if (static_lenb <= opt_lenb) {
opt_lenb = static_lenb;
}
} else { } else {
// Assert(buf != (char*)0, "lost buf"); // Assert(buf != (char*)0, "lost buf");
...@@ -1214,6 +1243,7 @@ function _tr_tally(s, dist, lc) ...@@ -1214,6 +1243,7 @@ function _tr_tally(s, dist, lc)
* 64K-1 bytes. * 64K-1 bytes.
*/ */
} }
export default { export default {
_tr_init, _tr_init,
_tr_stored_block, _tr_stored_block,
......
import { VideoEntity } from './VideoEntity' import {VideoEntity} from './VideoEntity'
import MockWorker from './mockWorker' import MockWorker from './mockWorker'
export class Parser { export class Parser {
......
import { BezierPath } from './bezierPath' import {BezierPath} from './bezierPath'
export class RectPath extends BezierPath { export class RectPath extends BezierPath {
......
import { FrameEntity } from './frameEntity' import {FrameEntity} from './frameEntity'
import { BezierPath } from './bezierPath'
import { RectPath } from './rectPath'
import { EllipsePath } from './ellipsePath'
export class SpriteEntity { export class SpriteEntity {
......
import { osType, TEXT_lINETYPE, devicePixelRatio, TEXT_ALIGN } from "../const"; import {devicePixelRatio, TEXT_ALIGN} from "../const";
import { Event } from "../events/Event"; import {Event} from "../events/Event";
import { MouseEvent } from "../events/MouseEvent"; import {MouseEvent} from "../events/MouseEvent";
import { FloatDisplay } from "../display/FloatDisplay"; import {TextField} from "./TextField";
import { TextField } from "./TextField"; import {InputText} from "./InputText";
import { InputText } from "./InputText";
/** /**
* 可编辑文本,继承TextFieldNode * 可编辑文本,继承TextFieldNode
...@@ -21,6 +20,7 @@ export class EditableText extends TextField { ...@@ -21,6 +20,7 @@ export class EditableText extends TextField {
get prompt() { get prompt() {
return this._prompt return this._prompt
} }
set prompt(value: string) { set prompt(value: string) {
if (this._prompt != value) { if (this._prompt != value) {
this._prompt = value; this._prompt = value;
...@@ -31,10 +31,12 @@ export class EditableText extends TextField { ...@@ -31,10 +31,12 @@ export class EditableText extends TextField {
} }
} }
} }
private _promptColor: string = "#eeeeee"; private _promptColor: string = "#eeeeee";
get promptColor() { get promptColor() {
return this._promptColor return this._promptColor
} }
set promptColor(value: string) { set promptColor(value: string) {
if (this._promptColor != value) { if (this._promptColor != value) {
this._promptColor = value; this._promptColor = value;
...@@ -50,6 +52,7 @@ export class EditableText extends TextField { ...@@ -50,6 +52,7 @@ export class EditableText extends TextField {
get textColor() { get textColor() {
return this._textColor return this._textColor
} }
set textColor(value: string) { set textColor(value: string) {
if (this._textColor != value) { if (this._textColor != value) {
this._textColor = value; this._textColor = value;
......
import { osType, TEXT_lINETYPE } from "../const"; import {osType, TEXT_lINETYPE} from "../const";
import { Event } from "../events/Event"; import {Event} from "../events/Event";
import { MouseEvent } from "../events/MouseEvent"; import {MouseEvent} from "../events/MouseEvent";
import { FloatDisplay } from "../display/FloatDisplay"; import {FloatDisplay} from "../display/FloatDisplay";
import { TextField } from "./TextField"; import {TextField} from "./TextField";
/** /**
* 输入文本,待测试 * 输入文本,待测试
...@@ -42,6 +42,7 @@ export class InputText extends FloatDisplay { ...@@ -42,6 +42,7 @@ export class InputText extends FloatDisplay {
* @since 2.0.0 * @since 2.0.0
*/ */
private static _inputTypeList: Array<string> = ["input", "password", "textarea"]; private static _inputTypeList: Array<string> = ["input", "password", "textarea"];
/** /**
* @method InputText * @method InputText
* @public * @public
...@@ -97,6 +98,7 @@ export class InputText extends FloatDisplay { ...@@ -97,6 +98,7 @@ export class InputText extends FloatDisplay {
s.htmlElement.style.borderWidth = "thin"; s.htmlElement.style.borderWidth = "thin";
s.htmlElement.style.borderColor = "#000"; s.htmlElement.style.borderColor = "#000";
} }
/** /**
* 被始化输入文件的一些属性 * 被始化输入文件的一些属性
* @method initInfo * @method initInfo
...@@ -145,9 +147,11 @@ export class InputText extends FloatDisplay { ...@@ -145,9 +147,11 @@ export class InputText extends FloatDisplay {
public set lineSpacing(value: number) { public set lineSpacing(value: number) {
this.htmlElement.style.lineHeight = value + "px"; this.htmlElement.style.lineHeight = value + "px";
} }
public get lineSpacing(): number { public get lineSpacing(): number {
return parseInt(this.htmlElement.style.lineHeight); return parseInt(this.htmlElement.style.lineHeight);
} }
/** /**
* 设置文本是否为粗体 * 设置文本是否为粗体
* @property bold * @property bold
...@@ -187,6 +191,7 @@ export class InputText extends FloatDisplay { ...@@ -187,6 +191,7 @@ export class InputText extends FloatDisplay {
public get italic(): boolean { public get italic(): boolean {
return this.htmlElement.style.fontStyle == "italic" return this.htmlElement.style.fontStyle == "italic"
} }
/** /**
* 文本的行高 * 文本的行高
* @property textHeight * @property textHeight
...@@ -202,6 +207,7 @@ export class InputText extends FloatDisplay { ...@@ -202,6 +207,7 @@ export class InputText extends FloatDisplay {
public get textHeight(): number { public get textHeight(): number {
return parseInt(this.htmlElement.style.height); return parseInt(this.htmlElement.style.height);
} }
/** /**
* 文本的宽 * 文本的宽
* @property textWidth * @property textWidth
...@@ -217,6 +223,7 @@ export class InputText extends FloatDisplay { ...@@ -217,6 +223,7 @@ export class InputText extends FloatDisplay {
public get textWidth(): number { public get textWidth(): number {
return parseInt(this.htmlElement.style.width); return parseInt(this.htmlElement.style.width);
} }
/** /**
* 设置文本颜色 * 设置文本颜色
* @property color * @property color
...@@ -292,6 +299,7 @@ export class InputText extends FloatDisplay { ...@@ -292,6 +299,7 @@ export class InputText extends FloatDisplay {
return l; return l;
} }
} }
public set maxCharacters(value: number) { public set maxCharacters(value: number) {
this.htmlElement.setAttribute("maxlength", value); 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 Texture from "../texture/Texture";
import { getRGBA } from "../utils"; import {getRGBA} from "../utils";
import { Rectangle } from "../math"; import {Rectangle} from "../math";
import Sprite from "../display/Sprite"; import Sprite from "../display/Sprite";
//文本canvas上xy的偏移量 //文本canvas上xy的偏移量
const padding = 10; const padding = 10;
/** /**
* *
* 继承Sprite,暂时发现,只需要切换bitmap和Sprite,TextField永远都是最新的,到时替换 * 继承Sprite,暂时发现,只需要切换bitmap和Sprite,TextField永远都是最新的,到时替换
...@@ -26,6 +27,7 @@ export class TextField extends Sprite { ...@@ -26,6 +27,7 @@ export class TextField extends Sprite {
offsetX: number; offsetX: number;
offsetY: number; offsetY: number;
constructor() { constructor() {
super(); super();
this._instanceType = "TextFieldNode"; this._instanceType = "TextFieldNode";
...@@ -59,6 +61,7 @@ export class TextField extends Sprite { ...@@ -59,6 +61,7 @@ export class TextField extends Sprite {
public get textAlpha(): number { public get textAlpha(): number {
return this._textAlpha; return this._textAlpha;
} }
private _textAlpha: number = 1; private _textAlpha: number = 1;
/** /**
...@@ -80,6 +83,7 @@ export class TextField extends Sprite { ...@@ -80,6 +83,7 @@ export class TextField extends Sprite {
public get textAlign(): TEXT_ALIGN { public get textAlign(): TEXT_ALIGN {
return this._textAlign; return this._textAlign;
} }
private _textAlign: TEXT_ALIGN = TEXT_ALIGN.LEFT; private _textAlign: TEXT_ALIGN = TEXT_ALIGN.LEFT;
/** /**
...@@ -96,6 +100,7 @@ export class TextField extends Sprite { ...@@ -96,6 +100,7 @@ export class TextField extends Sprite {
public get verticalAlign(): VERTICAL_ALIGN { public get verticalAlign(): VERTICAL_ALIGN {
return this._verticalAlign; return this._verticalAlign;
} }
private _verticalAlign: VERTICAL_ALIGN = VERTICAL_ALIGN.UP; private _verticalAlign: VERTICAL_ALIGN = VERTICAL_ALIGN.UP;
/** /**
...@@ -110,8 +115,10 @@ export class TextField extends Sprite { ...@@ -110,8 +115,10 @@ export class TextField extends Sprite {
if (this._textWidth != value) { if (this._textWidth != value) {
this._textWidth = value; this._textWidth = value;
this.dirty = true; this.dirty = true;
};
} }
;
}
public get textWidth(): number { public get textWidth(): number {
if (this._textWidth) { if (this._textWidth) {
//有就这个 //有就这个
...@@ -122,6 +129,7 @@ export class TextField extends Sprite { ...@@ -122,6 +129,7 @@ export class TextField extends Sprite {
return this.width - padding * 2; return this.width - padding * 2;
} }
} }
private _textWidth: number = 0; private _textWidth: number = 0;
/** /**
...@@ -150,6 +158,7 @@ export class TextField extends Sprite { ...@@ -150,6 +158,7 @@ export class TextField extends Sprite {
return this.height - padding * 2 return this.height - padding * 2
} }
} }
private _textHeight: number = 0; private _textHeight: number = 0;
/** /**
...@@ -163,11 +172,14 @@ export class TextField extends Sprite { ...@@ -163,11 +172,14 @@ export class TextField extends Sprite {
if (this._lineSpacing != value) { if (this._lineSpacing != value) {
this._lineSpacing = value; this._lineSpacing = value;
this.dirty = true; this.dirty = true;
};
} }
;
}
public get lineSpacing(): number { public get lineSpacing(): number {
return this._lineSpacing; return this._lineSpacing;
} }
private _lineSpacing: number = 14; private _lineSpacing: number = 14;
/** /**
...@@ -182,12 +194,16 @@ export class TextField extends Sprite { ...@@ -182,12 +194,16 @@ export class TextField extends Sprite {
if (this._lineType != value) { if (this._lineType != value) {
this._lineType = value; this._lineType = value;
this.dirty = true; this.dirty = true;
};
} }
;
}
public get lineType(): TEXT_lINETYPE { public get lineType(): TEXT_lINETYPE {
return this._lineType; return this._lineType;
} }
private _lineType: TEXT_lINETYPE = TEXT_lINETYPE.SINGLE; private _lineType: TEXT_lINETYPE = TEXT_lINETYPE.SINGLE;
/** /**
* 文本内容 * 文本内容
* @property text * @property text
...@@ -200,13 +216,16 @@ export class TextField extends Sprite { ...@@ -200,13 +216,16 @@ export class TextField extends Sprite {
if (this._text != value) { if (this._text != value) {
this._text = value; this._text = value;
this.dirty = true; this.dirty = true;
}; }
;
} }
public get text(): string { public get text(): string {
return this._text; return this._text;
} }
private _text: string = ""; private _text: string = "";
/** /**
* 文本的css字体样式 * 文本的css字体样式
* @property font * @property font
...@@ -219,13 +238,16 @@ export class TextField extends Sprite { ...@@ -219,13 +238,16 @@ export class TextField extends Sprite {
if (this._font != value) { if (this._font != value) {
this._font = value; this._font = value;
this.dirty = true; this.dirty = true;
}; }
;
} }
public get font(): string { public get font(): string {
return this._font; return this._font;
} }
private _font: string = "Arial"; private _font: string = "Arial";
/** /**
* 文本的size * 文本的size
* @property size * @property size
...@@ -238,13 +260,16 @@ export class TextField extends Sprite { ...@@ -238,13 +260,16 @@ export class TextField extends Sprite {
if (this._size != value) { if (this._size != value) {
this._size = value; this._size = value;
this.dirty = true; this.dirty = true;
}; }
;
} }
public get size(): number { public get size(): number {
return this._size; return this._size;
} }
private _size: number = 12; private _size: number = 12;
/** /**
* 文本的填充颜色值 * 文本的填充颜色值
* @property fillColor * @property fillColor
...@@ -257,12 +282,14 @@ export class TextField extends Sprite { ...@@ -257,12 +282,14 @@ export class TextField extends Sprite {
if (this._fillColor != value) { if (this._fillColor != value) {
this._fillColor = value; this._fillColor = value;
this.dirty = true; this.dirty = true;
}; }
;
} }
public get fillColor(): string { public get fillColor(): string {
return this._fillColor; return this._fillColor;
} }
private _fillColor: string = "#ffffff"; private _fillColor: string = "#ffffff";
/** /**
...@@ -277,13 +304,16 @@ export class TextField extends Sprite { ...@@ -277,13 +304,16 @@ export class TextField extends Sprite {
if (this._strokeColor != value) { if (this._strokeColor != value) {
this._strokeColor = value; this._strokeColor = value;
this.dirty = true; this.dirty = true;
}; }
;
} }
public get strokeColor(): string { public get strokeColor(): string {
return this._strokeColor; return this._strokeColor;
} }
private _strokeColor: string = "#ffffff"; private _strokeColor: string = "#ffffff";
/** /**
* 文本描边宽度,为0则不描边 * 文本描边宽度,为0则不描边
* @property stroke * @property stroke
...@@ -296,12 +326,14 @@ export class TextField extends Sprite { ...@@ -296,12 +326,14 @@ export class TextField extends Sprite {
if (this._stroke != value) { if (this._stroke != value) {
this._stroke = value; this._stroke = value;
this.dirty = true; this.dirty = true;
}; }
;
} }
public get stroke(): number { public get stroke(): number {
return this._stroke; return this._stroke;
} }
private _stroke: number = 0; private _stroke: number = 0;
/** /**
...@@ -316,13 +348,16 @@ export class TextField extends Sprite { ...@@ -316,13 +348,16 @@ export class TextField extends Sprite {
if (this._italic != value) { if (this._italic != value) {
this._italic = value; this._italic = value;
this.dirty = true; this.dirty = true;
}; }
;
} }
public get italic(): boolean { public get italic(): boolean {
return this._italic; return this._italic;
} }
private _italic: boolean = false; private _italic: boolean = false;
/** /**
* 文本是否加粗 * 文本是否加粗
* @property bold * @property bold
...@@ -335,12 +370,16 @@ export class TextField extends Sprite { ...@@ -335,12 +370,16 @@ export class TextField extends Sprite {
if (this._bold != value) { if (this._bold != value) {
this._bold = value; this._bold = value;
this.dirty = true; this.dirty = true;
};
} }
;
}
public get bold(): boolean { public get bold(): boolean {
return this._bold; return this._bold;
} }
public _bold: boolean = false; public _bold: boolean = false;
/** /**
* 设置或获取是否有边框 * 设置或获取是否有边框
* @property property * @property property
...@@ -352,12 +391,14 @@ export class TextField extends Sprite { ...@@ -352,12 +391,14 @@ export class TextField extends Sprite {
if (this._border != value) { if (this._border != value) {
this._border = value; this._border = value;
this.dirty = true; this.dirty = true;
}; }
;
} }
public get border(): boolean { public get border(): boolean {
return this._border; return this._border;
} }
private _border: boolean = false; private _border: boolean = false;
/** /**
...@@ -385,6 +426,7 @@ export class TextField extends Sprite { ...@@ -385,6 +426,7 @@ export class TextField extends Sprite {
ctx.textBaseline = "top"; ctx.textBaseline = "top";
ctx.fillStyle = getRGBA(s._fillColor, s._textAlpha) ctx.fillStyle = getRGBA(s._fillColor, s._textAlpha)
} }
/** /**
* 获取当前文本中单行文字的宽,注意是文字的不是文本框的宽 * 获取当前文本中单行文字的宽,注意是文字的不是文本框的宽
* @method getTextWidth * @method getTextWidth
...@@ -401,6 +443,7 @@ export class TextField extends Sprite { ...@@ -401,6 +443,7 @@ export class TextField extends Sprite {
let obj: any = ctx.measureText(s.realLines[lineIndex]); let obj: any = ctx.measureText(s.realLines[lineIndex]);
return obj.width; return obj.width;
} }
/** /**
* @property _lines 获取当前文本行数 * @property _lines 获取当前文本行数
* @type {number} * @type {number}
...@@ -411,6 +454,7 @@ export class TextField extends Sprite { ...@@ -411,6 +454,7 @@ export class TextField extends Sprite {
get lines(): number { get lines(): number {
return this.realLines.length; return this.realLines.length;
} }
/** /**
* 获取文本宽 * 获取文本宽
* @method _getMeasuredWidth * @method _getMeasuredWidth
...@@ -426,7 +470,9 @@ export class TextField extends Sprite { ...@@ -426,7 +470,9 @@ export class TextField extends Sprite {
//ctx.restore(); //ctx.restore();
return w; return w;
} }
private realLines: any = []; private realLines: any = [];
/** /**
* 更新文本,主要重画canvas * 更新文本,主要重画canvas
*/ */
...@@ -437,7 +483,7 @@ export class TextField extends Sprite { ...@@ -437,7 +483,7 @@ export class TextField extends Sprite {
s.canvas.width = 0; s.canvas.width = 0;
s.canvas.height = 0; s.canvas.height = 0;
s._localBoundsSelf.clear(); s._localBoundsSelf.clear();
this.anchorTexture = { x: 0, y: 0 }; this.anchorTexture = {x: 0, y: 0};
this.updateTexture(); this.updateTexture();
return return
} }
...@@ -552,7 +598,7 @@ export class TextField extends Sprite { ...@@ -552,7 +598,7 @@ export class TextField extends Sprite {
s.offsetX = -padding; s.offsetX = -padding;
s.offsetY = -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) // document.body.appendChild(can)
// s._bounds.height = maxH; // s._bounds.height = maxH;
...@@ -563,6 +609,7 @@ export class TextField extends Sprite { ...@@ -563,6 +609,7 @@ export class TextField extends Sprite {
//修改texture及baseTexture属性 //修改texture及baseTexture属性
s.updateTexture() s.updateTexture()
} }
/** /**
* 更新texture及baseTexture属性 * 更新texture及baseTexture属性
* 不考虑trim, * 不考虑trim,
...@@ -584,11 +631,11 @@ export class TextField extends Sprite { ...@@ -584,11 +631,11 @@ export class TextField extends Sprite {
} }
_renderCanvas(renderer) { _renderCanvas(renderer) {
this.updateText(); this.updateText();
super._renderCanvas(renderer); super._renderCanvas(renderer);
} }
_renderWebGL(renderer) { _renderWebGL(renderer) {
this.updateText(); this.updateText();
super._renderWebGL(renderer) super._renderWebGL(renderer)
......
export { TextField } from "./TextField"; export {TextField} from "./TextField";
export { InputText } from "./InputText"; export {InputText} from "./InputText";
export { EditableText } from "./EditableText"; export {EditableText} from "./EditableText";
\ No newline at end of file \ No newline at end of file
import BaseTexture from './BaseTexture'; import BaseTexture from './BaseTexture';
import { SCALE_MODES } from '../const'; import {SCALE_MODES} from '../const';
/** /**
* 将显示对象画在上面的贴图 * 将显示对象画在上面的贴图
...@@ -59,6 +59,7 @@ export default class BaseRenderTexture extends BaseTexture { ...@@ -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. * This will let the renderer know if the texture is valid. If it's not then it cannot be rendered.
*/ */
valid: boolean; valid: boolean;
/** /**
* @param {number} [width=100] - The width of the base render texture * @param {number} [width=100] - The width of the base render texture
* @param {number} [height=100] - The height of the base render texture * @param {number} [height=100] - The height of the base render texture
......
import { EventDispatcher } from '../events/EventDispatcher'; import {EventDispatcher} from '../events/EventDispatcher';
import { decomposeDataUri, getUrlFileExtension, isPow2, BaseTextureCache, TextureCache, uid } from '../utils'; import {BaseTextureCache, decomposeDataUri, getUrlFileExtension, isPow2, TextureCache, uid} from '../utils';
import { SCALE_MODES, WRAP_MODES } from "../const" import {SCALE_MODES, WRAP_MODES} from "../const"
/** /**
* 每个texture都有一个BaseTexture,多数用于图集,texture可自身设置属性 * 每个texture都有一个BaseTexture,多数用于图集,texture可自身设置属性
...@@ -99,6 +99,7 @@ export default class BaseTexture extends EventDispatcher { ...@@ -99,6 +99,7 @@ export default class BaseTexture extends EventDispatcher {
* @member {string[]} * @member {string[]}
*/ */
textureCacheIds: string[]; textureCacheIds: string[];
/** /**
* @param {HTMLImageElement|HTMLCanvasElement} [source] - the source object of the texture. * @param {HTMLImageElement|HTMLCanvasElement} [source] - the source object of the texture.
* @param {number} [scaleMode=settings.SCALE_MODE] - possible values * @param {number} [scaleMode=settings.SCALE_MODE] - possible values
...@@ -246,8 +247,7 @@ export default class BaseTexture extends EventDispatcher { ...@@ -246,8 +247,7 @@ export default class BaseTexture extends EventDispatcher {
if (!imageType) { if (!imageType) {
throw new Error('Invalid image type in data URI.'); throw new Error('Invalid image type in data URI.');
} }
} } else {
else {
imageType = getUrlFileExtension(this.imageUrl); imageType = getUrlFileExtension(this.imageUrl);
if (!imageType) { if (!imageType) {
...@@ -257,6 +257,7 @@ export default class BaseTexture extends EventDispatcher { ...@@ -257,6 +257,7 @@ export default class BaseTexture extends EventDispatcher {
this.imageType = imageType; this.imageType = imageType;
} }
/** /**
* 加载完成后执行 * 加载完成后执行
* @private * @private
...@@ -368,8 +369,7 @@ export default class BaseTexture extends EventDispatcher { ...@@ -368,8 +369,7 @@ export default class BaseTexture extends EventDispatcher {
if (typeof source === 'string') { if (typeof source === 'string') {
//图片路径 //图片路径
return BaseTexture.fromImage(source, undefined, scaleMode); return BaseTexture.fromImage(source, undefined, scaleMode);
} } else if (source instanceof HTMLImageElement) {
else if (source instanceof HTMLImageElement) {
//图片标签 //图片标签
const imageUrl = source.src; const imageUrl = source.src;
let baseTexture = BaseTextureCache[imageUrl]; let baseTexture = BaseTextureCache[imageUrl];
...@@ -380,8 +380,7 @@ export default class BaseTexture extends EventDispatcher { ...@@ -380,8 +380,7 @@ export default class BaseTexture extends EventDispatcher {
if (imageUrl.indexOf('data:') !== 0) BaseTexture.addToCache(baseTexture, imageUrl); if (imageUrl.indexOf('data:') !== 0) BaseTexture.addToCache(baseTexture, imageUrl);
} }
return baseTexture; return baseTexture;
} } else if (source instanceof HTMLCanvasElement) {
else if (source instanceof HTMLCanvasElement) {
//canvas标签 //canvas标签
return BaseTexture.fromCanvas(source, scaleMode); return BaseTexture.fromCanvas(source, scaleMode);
} }
...@@ -426,8 +425,7 @@ export default class BaseTexture extends EventDispatcher { ...@@ -426,8 +425,7 @@ export default class BaseTexture extends EventDispatcher {
delete BaseTextureCache[baseTexture]; delete BaseTextureCache[baseTexture];
return baseTextureFromCache; return baseTextureFromCache;
} }
} } else if (baseTexture && baseTexture.textureCacheIds) {
else if (baseTexture && baseTexture.textureCacheIds) {
for (let i = 0; i < baseTexture.textureCacheIds.length; ++i) { for (let i = 0; i < baseTexture.textureCacheIds.length; ++i) {
delete BaseTextureCache[baseTexture.textureCacheIds[i]]; delete BaseTextureCache[baseTexture.textureCacheIds[i]];
} }
......
import BaseRenderTexture from './BaseRenderTexture'; import BaseRenderTexture from './BaseRenderTexture';
import Texture from './Texture'; import Texture from './Texture';
import { Rectangle } from '../math'; import {Rectangle} from '../math';
import { SCALE_MODES } from '../const'; import {SCALE_MODES} from '../const';
/** /**
* A RenderTexture is a special texture that allows any display object to be rendered to it. * 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 { ...@@ -70,7 +70,7 @@ export default class RenderTexture extends Texture {
* @param {number} height - The height to resize to. * @param {number} height - The height to resize to.
* @param {boolean} doNotResizeBaseTexture - Should the baseTexture.width and height values be resized as well? * @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); width = Math.ceil(width);
height = Math.ceil(height); height = Math.ceil(height);
......
import BaseTexture from './BaseTexture'; import BaseTexture from './BaseTexture';
import TextureUvs from './TextureUvs'; import TextureUvs from './TextureUvs';
import { EventDispatcher } from '../events/EventDispatcher'; import {EventDispatcher} from '../events/EventDispatcher';
import { Event } from "../events/Event"; import {Event} from "../events/Event";
import { Rectangle, Point } from '../math'; import {Point, Rectangle} from '../math';
import { TextureCache } from '../utils'; import {TextureCache} from '../utils';
import { SCALE_MODES } from '../const'; import {SCALE_MODES} from '../const';
/** /**
* 一张图片或图集的一部分,如果没有frame。默认整张图片 * 一张图片或图集的一部分,如果没有frame。默认整张图片
...@@ -95,6 +95,7 @@ export default class Texture extends EventDispatcher { ...@@ -95,6 +95,7 @@ export default class Texture extends EventDispatcher {
* 白贴图 * 白贴图
*/ */
static WHITE: Texture; static WHITE: Texture;
/** /**
* @param {BaseTexture} baseTexture - The base texture source to create the texture from * @param {BaseTexture} baseTexture - The base texture source to create the texture from
* @param {Rectangle} [frame] - The rectangle frame of the texture to show * @param {Rectangle} [frame] - The rectangle frame of the texture to show
...@@ -147,8 +148,7 @@ export default class Texture extends EventDispatcher { ...@@ -147,8 +148,7 @@ export default class Texture extends EventDispatcher {
baseTexture.addEventListener('update', this.onBaseTextureUpdated); baseTexture.addEventListener('update', this.onBaseTextureUpdated);
} }
this.frame = frame; this.frame = frame;
} } else {
else {
baseTexture.once('loaded', this.onBaseTextureLoaded); baseTexture.once('loaded', this.onBaseTextureLoaded);
} }
...@@ -182,8 +182,7 @@ export default class Texture extends EventDispatcher { ...@@ -182,8 +182,7 @@ export default class Texture extends EventDispatcher {
// TODO this code looks confusing.. boo to abusing getters and setters! // TODO this code looks confusing.. boo to abusing getters and setters!
if (this.noFrame) { if (this.noFrame) {
this.frame = new Rectangle(0, 0, baseTexture.width, baseTexture.height); this.frame = new Rectangle(0, 0, baseTexture.width, baseTexture.height);
} } else {
else {
this.frame = this._frame; this.frame = this._frame;
} }
this.baseTexture.addEventListener('update', this.onBaseTextureUpdated); this.baseTexture.addEventListener('update', this.onBaseTextureUpdated);
...@@ -274,7 +273,7 @@ export default class Texture extends EventDispatcher { ...@@ -274,7 +273,7 @@ export default class Texture extends EventDispatcher {
this.noFrame = false; this.noFrame = false;
const { x, y, width, height } = frame; const {x, y, width, height} = frame;
const xNotFit = x + width > this.baseTexture.width; const xNotFit = x + width > this.baseTexture.width;
const yNotFit = y + height > this.baseTexture.height; const yNotFit = y + height > this.baseTexture.height;
...@@ -298,6 +297,7 @@ export default class Texture extends EventDispatcher { ...@@ -298,6 +297,7 @@ export default class Texture extends EventDispatcher {
this._updateUvs(); this._updateUvs();
} }
} }
/** /**
* Indicates whether the texture is rotated inside the atlas * Indicates whether the texture is rotated inside the atlas
* set to 2 to compensate for texture packer rotation * set to 2 to compensate for texture packer rotation
...@@ -406,14 +406,11 @@ export default class Texture extends EventDispatcher { ...@@ -406,14 +406,11 @@ export default class Texture extends EventDispatcher {
return Texture.fromImage(source); return Texture.fromImage(source);
} }
return texture; return texture;
} } else if (source instanceof HTMLImageElement) {
else if (source instanceof HTMLImageElement) {
return new Texture(BaseTexture.from(source)); return new Texture(BaseTexture.from(source));
} } else if (source instanceof HTMLCanvasElement) {
else if (source instanceof HTMLCanvasElement) {
return Texture.fromCanvas(source, SCALE_MODES.LINEAR, 'canvas'); return Texture.fromCanvas(source, SCALE_MODES.LINEAR, 'canvas');
} } else if (source instanceof BaseTexture) {
else if (source instanceof BaseTexture) {
return new Texture(source); return new Texture(source);
} }
...@@ -461,8 +458,7 @@ export default class Texture extends EventDispatcher { ...@@ -461,8 +458,7 @@ export default class Texture extends EventDispatcher {
return textureFromCache; return textureFromCache;
} }
} } else if (texture && texture.textureCacheIds) {
else if (texture && texture.textureCacheIds) {
for (let i = 0; i < texture.textureCacheIds.length; ++i) { for (let i = 0; i < texture.textureCacheIds.length; ++i) {
// Check that texture matches the one being passed in before deleting it from the cache. // Check that texture matches the one being passed in before deleting it from the cache.
if (TextureCache[texture.textureCacheIds[i]] === texture) { if (TextureCache[texture.textureCacheIds[i]] === texture) {
...@@ -494,10 +490,14 @@ function createWhiteTexture() { ...@@ -494,10 +490,14 @@ function createWhiteTexture() {
//将事件置空 //将事件置空
function removeAllHandlers(tex) { function removeAllHandlers(tex) {
tex.destroy = function _emptyDestroy() { /* empty */ }; tex.destroy = function _emptyDestroy() { /* empty */
tex.addEventListener = function _emptyOn() { /* empty */ }; };
tex.once = function _emptyOnce() { /* empty */ }; tex.addEventListener = function _emptyOn() { /* empty */
tex.dispatchEvent = function _emptyEmit() { /* empty */ }; };
tex.once = function _emptyOnce() { /* empty */
};
tex.dispatchEvent = function _emptyEmit() { /* empty */
};
} }
/** /**
......
import Texture from "./Texture" import Texture from "./Texture"
import BaseTexture from './BaseTexture'; import BaseTexture from './BaseTexture';
import { Rectangle } from "../math"; import {Rectangle} from "../math";
/** /**
* 简单点来说,就是用来拆图集的 * 简单点来说,就是用来拆图集的
* Utility class for maintaining reference to a collection * Utility class for maintaining reference to a collection
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
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