Commit 85298eab authored by wjf's avatar wjf

l

parent eb22fbd4
# project ignores # project ignores
node_modules node_modules
jsconfig111111.json
\ No newline at end of file
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -9,21 +9,32 @@ ...@@ -9,21 +9,32 @@
*/ */
export const VERSION = "1.0"; export const VERSION = "1.0";
/** /**
* 有问题 * 判读window,标记浏览器环境,到时万一淘宝小程序内也有window,再改
*/ */
//@ts-ignore //@ts-ignore
export const sysInfo = my.getSystemInfoSync(); export const devicePixelRatio: number = window && (window.devicePixelRatio || 1) || my.getSystemInfoSync().pixelRatio;
/**
* 有问题
*/
export const devicePixelRatio: number = sysInfo.pixelRatio //window.devicePixelRatio || 1;
/** /**
* 获取设备号iOS Android * 获取设备号iOS Android
* 先判断浏览器环境设备号,没有就是小程序环境
*/ */
export const osType: "ios" | "android" = sysInfo.platform.toLowerCase() export const osType: "ios" | "android" | "pc" = navigator && navigator.userAgent && (function () {
let n = navigator.userAgent.toLocaleLowerCase();
let reg1 = /android/;
let reg2 = /iphone|ipod|ipad/;
if (reg1.test(n)) {
return "android";
} else if (reg2.test(n)) {
return "ios"
} else {
return "pc";
}
})()
//@ts-ignore
|| my.getSystemInfoSync().platform.toLowerCase()
let PI: number = Math.PI; let PI: number = Math.PI;
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
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';
/** /**
...@@ -49,7 +49,7 @@ export default class Container extends DisplayObject { ...@@ -49,7 +49,7 @@ export default class Container extends DisplayObject {
* @param {DisplayObject} child * @param {DisplayObject} child
* @return {DisplayObject} * @return {DisplayObject}
*/ */
addChild(child: DisplayObject): DisplayObject { addChild<T extends DisplayObject>(child: T): T {
//默认添加在最顶层 //默认添加在最顶层
this.addChildAt(child, this.children.length); this.addChildAt(child, this.children.length);
return child; return child;
...@@ -61,7 +61,7 @@ export default class Container extends DisplayObject { ...@@ -61,7 +61,7 @@ export default class Container extends DisplayObject {
* @param {number} index - The index to place the child in * @param {number} index - The index to place the child in
* @return {DisplayObject} The child that was added. * @return {DisplayObject} The child that was added.
*/ */
addChildAt(child: DisplayObject, index: number): DisplayObject { addChildAt<T extends DisplayObject>(child: T, index: number): T {
if (!child) return; if (!child) return;
let s = this; let s = this;
......
...@@ -342,8 +342,8 @@ export class Stage extends Container { ...@@ -342,8 +342,8 @@ export class Stage extends Container {
} else { } else {
cp = new Point(); cp = new Point();
} }
cp.x = (points[o].x || points[o].b) * s.dpi// devicePixelRatio; cp.x = (points[o].pageX || points[o].x || points[o].b) * s.dpi// devicePixelRatio;
cp.y = (points[o].y || points[o].c) * s.dpi// devicePixelRatio; cp.y = (points[o].pageY || points[o].y || points[o].c) * s.dpi// devicePixelRatio;
// my.alert({ // my.alert({
// title: JSON.stringify(points[o]) // title: JSON.stringify(points[o])
// }); // });
......
...@@ -73,7 +73,7 @@ export class EventDispatcher extends HashObject { ...@@ -73,7 +73,7 @@ export class EventDispatcher extends HashObject {
* @example * @example
* this.addEventListener(Event.ADD_TO_STAGE,function(e){trace(this);},this); * this.addEventListener(Event.ADD_TO_STAGE,function(e){trace(this);},this);
*/ */
public addEventListener(type: string, listener: Function, context?: any, useCapture: boolean = true): void { public addEventListener(type: string, listener: Function, context?: any, useCapture: boolean = true): this {
if (!type) { if (!type) {
throw new Error("添加侦听的type值为undefined"); throw new Error("添加侦听的type值为undefined");
} }
...@@ -99,14 +99,14 @@ export class EventDispatcher extends HashObject { ...@@ -99,14 +99,14 @@ export class EventDispatcher extends HashObject {
let ee: EE = eventTypes[type][i] let ee: EE = eventTypes[type][i]
if (ee.fn === listener && ee.context === context) { if (ee.fn === listener && ee.context === context) {
console.log("已添加过该事件") console.log("已添加过该事件")
return return s
} }
} }
eventTypes[type].unshift(new EE(listener, context || s)); eventTypes[type].unshift(new EE(listener, context || s));
if (type.indexOf("onMouse") == 0) { if (type.indexOf("onMouse") == 0) {
s._changeMouseCount(type, true); s._changeMouseCount(type, true);
} }
return s
} }
/** /**
...@@ -116,7 +116,7 @@ export class EventDispatcher extends HashObject { ...@@ -116,7 +116,7 @@ export class EventDispatcher extends HashObject {
* @param context * @param context
* @param useCapture * @param useCapture
*/ */
public once(type: string, listener: Function, context?: any, useCapture: boolean = true): void { public once(type: string, listener: Function, context?: any, useCapture: boolean = true): this {
if (!type) { if (!type) {
throw new Error("添加侦听的type值为undefined"); throw new Error("添加侦听的type值为undefined");
} }
...@@ -136,6 +136,7 @@ export class EventDispatcher extends HashObject { ...@@ -136,6 +136,7 @@ export class EventDispatcher extends HashObject {
if (type.indexOf("onMouse") == 0) { if (type.indexOf("onMouse") == 0) {
s._changeMouseCount(type, true); s._changeMouseCount(type, true);
} }
return s
} }
/** /**
...@@ -255,7 +256,7 @@ export class EventDispatcher extends HashObject { ...@@ -255,7 +256,7 @@ export class EventDispatcher extends HashObject {
* @param context listener和context都相等的才移除,默认自身 * @param context listener和context都相等的才移除,默认自身
* @param {boolean} useCapture true 捕获阶段 false 冒泡阶段 默认 true * @param {boolean} useCapture true 捕获阶段 false 冒泡阶段 默认 true
*/ */
public removeEventListener(type: string, listener: Function, context?: any, useCapture: boolean = true): void { public removeEventListener(type: string, listener: Function, context?: any, useCapture: boolean = true): this {
let s = this; let s = this;
let listeners: EE[] = s.eventTypes[type]; let listeners: EE[] = s.eventTypes[type];
if (!useCapture) { if (!useCapture) {
...@@ -279,6 +280,7 @@ export class EventDispatcher extends HashObject { ...@@ -279,6 +280,7 @@ export class EventDispatcher extends HashObject {
// } // }
} }
} }
return s
} }
/** /**
......
...@@ -8,7 +8,7 @@ import { sign, string2hex, hex2rgb } from '../utils'; ...@@ -8,7 +8,7 @@ import { sign, string2hex, hex2rgb } from '../utils';
import { SHAPES, PI_2, SCALE_MODES, WRAP_MODES, BLEND_MODES } from '../const'; import { SHAPES, PI_2, SCALE_MODES, WRAP_MODES, BLEND_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 { Event } from "../events/Event"
import { WebglRenderer } from '../renderers/WebglRenderer'; import { WebglRenderer } from '../renderers/WebglRenderer';
import buildPoly from './geomBuild/buildPoly'; import buildPoly from './geomBuild/buildPoly';
...@@ -20,7 +20,7 @@ import FillStyle from './styles/FillStyle'; ...@@ -20,7 +20,7 @@ import FillStyle from './styles/FillStyle';
import LineStyle from './styles/LineStyle'; import LineStyle from './styles/LineStyle';
import { GRAPHICS_CURVES, quadraticCurveLength, bezierCurveLength, bezierCurveTo } from './utils'; import { GRAPHICS_CURVES, quadraticCurveLength, bezierCurveLength, bezierCurveTo } from './utils';
import Container from '../display/Container'; import Container from '../display/Container';
let canvasRenderer: CanvasRenderer;
const tempMatrix = new Matrix(); const tempMatrix = new Matrix();
const tempPoint = new Point(); const tempPoint = new Point();
const tempColor1 = new Float32Array(4); const tempColor1 = new Float32Array(4);
...@@ -1353,39 +1353,39 @@ export default class Graphics extends Container { ...@@ -1353,39 +1353,39 @@ export default class Graphics extends Container {
* @return {Texture} The new texture. * @return {Texture} The new texture.
*/ */
private generateCanvasTexture(scaleMode: number = SCALE_MODES.LINEAR): Texture { private generateCanvasTexture(scaleMode: number = SCALE_MODES.LINEAR): Texture {
// this.updateLocalBoundsSelf(); this.updateLocalBoundsSelf();
// const bounds = this._localBoundsSelf; const bounds = this._localBoundsSelf;
// if (!this._canvasBuffer) { if (!this._canvasBuffer) {
// this._canvasBuffer = RenderTexture.create(bounds.width, bounds.height, scaleMode); this._canvasBuffer = RenderTexture.create(bounds.width, bounds.height, scaleMode);
// } else { } else {
// this._canvasBuffer.resize(bounds.width, bounds.height) this._canvasBuffer.resize(bounds.width, bounds.height)
// } }
// if (!canvasRenderer) { if (!canvasRenderer) {
// canvasRenderer = new CanvasRenderer({}); canvasRenderer = new CanvasRenderer(null, 0, 0);
// } }
// this.transform.updateLocalMatrix(); this.transform.updateLocalMatrix();
// tempMatrix.copy(this.transform.localMatrix); tempMatrix.copy(this.transform.localMatrix);
// tempMatrix.invert(); tempMatrix.invert();
// tempMatrix.tx -= bounds.x; tempMatrix.tx -= bounds.x;
// tempMatrix.ty -= bounds.y; tempMatrix.ty -= bounds.y;
// canvasRenderer.render(this, this._canvasBuffer, tempMatrix); canvasRenderer.render(this, this._canvasBuffer, tempMatrix);
// // document.body.appendChild(this._canvasBuffer.baseTexture["_canvasRenderTarget"].canvas) // document.body.appendChild(this._canvasBuffer.baseTexture["_canvasRenderTarget"].canvas)
// if (!this._texture) { if (!this._texture) {
// this._texture = Texture.fromCanvas(this._canvasBuffer.baseTexture["_canvasRenderTarget"].canvas, scaleMode, 'graphics'); this._texture = Texture.fromCanvas(this._canvasBuffer.baseTexture["_canvasRenderTarget"].canvas, 'graphics');
// this._texture.baseTexture.update(); this._texture.baseTexture.update();
// } else { } else {
// this._texture.baseTexture.update(); this._texture.baseTexture.update();
// } }
// //可能需要更改_texture,this._texture.baseTexture尺寸 //可能需要更改_texture,this._texture.baseTexture尺寸
// this.offsetX = bounds.x; this.offsetX = bounds.x;
// this.offsetY = bounds.y; this.offsetY = bounds.y;
// return this._texture; return this._texture;
return // return
} }
/** /**
......
...@@ -74,7 +74,8 @@ export class Loader extends EventDispatcher { ...@@ -74,7 +74,8 @@ export class Loader extends EventDispatcher {
// }) // })
} }
loadJson(callback, url) { loadJson(callback, url) {
window["my"].request({ //@ts-ignore
my.request({
url: url, url: url,
dataType: "json", dataType: "json",
success: (res) => { success: (res) => {
......
...@@ -15,6 +15,13 @@ import { mapCanvasBlendModes } from "../utils"; ...@@ -15,6 +15,13 @@ import { mapCanvasBlendModes } from "../utils";
* 暂时不用,用时再说 * 暂时不用,用时再说
*/ */
export class CanvasRenderer extends SystemRenderer { export class CanvasRenderer extends SystemRenderer {
/**
* 主屏幕渲染上下文
*/
rootContext: CanvasRenderingContext2D;
/**
* 当前使用的上下文
*/
context: CanvasRenderingContext2D; context: CanvasRenderingContext2D;
/** /**
* 遮罩管理类 * 遮罩管理类
...@@ -43,7 +50,7 @@ export class CanvasRenderer extends SystemRenderer { ...@@ -43,7 +50,7 @@ export class CanvasRenderer extends SystemRenderer {
this.type = RENDERER_TYPE.CANVAS this.type = RENDERER_TYPE.CANVAS
this._instanceType = "CanvasRenderer"; this._instanceType = "CanvasRenderer";
this.context = context; this.rootContext = context;
this.maskManager = new CanvasMaskManager(this); this.maskManager = new CanvasMaskManager(this);
...@@ -73,8 +80,7 @@ export class CanvasRenderer extends SystemRenderer { ...@@ -73,8 +80,7 @@ export class CanvasRenderer extends SystemRenderer {
//渲染开始前触发 //渲染开始前触发
this.dispatchEvent('prerender'); this.dispatchEvent('prerender');
//
let context = this.context;
//是否渲染到主屏幕 //是否渲染到主屏幕
let renderingToScreen = !renderTexture; let renderingToScreen = !renderTexture;
if (renderTexture) { if (renderTexture) {
...@@ -92,9 +98,14 @@ export class CanvasRenderer extends SystemRenderer { ...@@ -92,9 +98,14 @@ export class CanvasRenderer extends SystemRenderer {
renderTexture._canvasRenderTarget.resize(renderTexture.width, renderTexture.height); renderTexture._canvasRenderTarget.resize(renderTexture.width, renderTexture.height);
} }
//当前上下文要修改成离屏的 //当前上下文要修改成离屏的
context = renderTexture._canvasRenderTarget.context; this.context = renderTexture._canvasRenderTarget.context;
} else {
//当前上下文就是根节点的
this.context = this.rootContext;
} }
const context = this.context;
if (!renderTexture) { if (!renderTexture) {
this._lastObjectRendered = displayObject; this._lastObjectRendered = displayObject;
} }
......
...@@ -21,10 +21,10 @@ export default class CanvasRenderTarget { ...@@ -21,10 +21,10 @@ export default class CanvasRenderTarget {
constructor(width: number, height: number) { constructor(width: number, height: number) {
this.canvas =createCanvas() //document.createElement('canvas'); this.canvas =createCanvas() //document.createElement('canvas');
// console.log("rd1",this.canvas)
this.resize(width, height);//要先设置尺寸?
this.context = this.canvas.getContext('2d'); this.context = this.canvas.getContext('2d');
// console.log("rd",this.context)
this.resize(width, height); this.resize(width, height);
} }
......
...@@ -33,33 +33,39 @@ export class TextField extends Sprite { ...@@ -33,33 +33,39 @@ export class TextField extends Sprite {
super(); super();
this._instanceType = "TextField"; this._instanceType = "TextField";
//ios直接 //ios直接
// if (osType == "ios") {
var canvas = createCanvas()
// canvas.width = 3;
// canvas.height = 3;
if (osType == "ios") { if (osType == "ios") {
var canvas = createCanvas() canvas.width = canvas.height = 3;
canvas.width = 3; } else {//现在只能用canvas2d渲染,所以不能用imageData了,等修复了安卓canvas尺寸问题再改
canvas.height = 3; canvas.width = 300;
this.texture = Texture.fromCanvas(canvas, "textCanvas"); canvas.height = 150;
this.canvas = canvas;
this.context = canvas.getContext("2d");
} }
//安卓的不能改变离屏canvas的尺寸,所以用750*750的,取imageData this.texture = Texture.fromCanvas(canvas, "textCanvas");
else { this.canvas = canvas;
if (!TextField.shareCanvas) { this.context = canvas.getContext("2d");
TextField.shareCanvas = createCanvas(); // }
TextField.shareCanvas.width = TextField.shareCanvas.height = 750; // //安卓的不能改变离屏canvas的尺寸,所以用750*750的,取imageData
TextField.shareContext = TextField.shareCanvas.getContext("2d"); // else {
} // if (!TextField.shareCanvas) {
var baseTexture = new BaseTexture({ // TextField.shareCanvas = createCanvas();
data: [], // TextField.shareCanvas.width = TextField.shareCanvas.height = 750;
width: 0, // TextField.shareContext = TextField.shareCanvas.getContext("2d");
height: 0, // }
type: "text", // var baseTexture = new BaseTexture({
path: null // data: [],
}); // width: 0,
this.texture = new Texture(baseTexture); // height: 0,
// type: "text",
// path: null
// });
// this.texture = new Texture(baseTexture);
this.canvas = TextField.shareCanvas; // this.canvas = TextField.shareCanvas;
this.context = TextField.shareContext; // this.context = TextField.shareContext;
} // }
//baseTexture已自动缓存,把texture也缓存,key textCanvas+num 和baseTexture的一致 //baseTexture已自动缓存,把texture也缓存,key textCanvas+num 和baseTexture的一致
Texture.addToCache(this.texture, this.texture.baseTexture.textureCacheIds[0]); Texture.addToCache(this.texture, this.texture.baseTexture.textureCacheIds[0]);
...@@ -488,7 +494,7 @@ export class TextField extends Sprite { ...@@ -488,7 +494,7 @@ export class TextField extends Sprite {
if (osType == "ios") { if (osType == "ios") {
s.canvas.width = 0; s.canvas.width = 0;
s.canvas.height = 0; s.canvas.height = 0;
} else { } else {//暂时不能用sourceData形式,所以和上面效果一样
s.texture.baseTexture.source.width = 0; s.texture.baseTexture.source.width = 0;
s.texture.baseTexture.source.height = 0; s.texture.baseTexture.source.height = 0;
} }
...@@ -598,33 +604,36 @@ export class TextField extends Sprite { ...@@ -598,33 +604,36 @@ export class TextField extends Sprite {
} }
} }
for (let i = 0; i < realLines.length; i++) { for (let i = 0; i < realLines.length; i++) {
let ox = 0;
//@ts-ignore 现在貌似小程序的textAlign有点问题,如果修复了再说
if (my) ox = - tx;//移回去
if (s.stroke) { if (s.stroke) {
ctx.strokeStyle = s.strokeColor; ctx.strokeStyle = s.strokeColor;
ctx.lineWidth = s.stroke * 2; ctx.lineWidth = s.stroke * 2;
ctx.strokeText(realLines[i], 0, upY + i * lineH, maxW); ctx.strokeText(realLines[i], ox, upY + i * lineH, maxW);
} }
ctx.fillText(realLines[i], 0, upY + i * lineH, maxW); ctx.fillText(realLines[i], ox, upY + i * lineH, maxW);
} }
//offset用_anchorTexture代替 //offset用_anchorTexture代替
s.offsetX = -padding; s.offsetX = -padding;
s.offsetY = -padding; s.offsetY = -padding;
// console.log(can) // console.log(can)
this.anchorTexture = { x: (padding + 0.5) / canWidth, y: padding / canHeight } this.anchorTexture = { x: (padding + 0.5) / canWidth, y: padding / canHeight }
if (osType == "ios") { // if (osType == "ios") {
s.texture.update(); s.texture.update();
s._onTextureUpdate(); s._onTextureUpdate();
} else { // } else {
var imgData = ctx.getImageData(0, 0, canWidth, canHeight) // var imgData = ctx.getImageData(0, 0, canWidth, canHeight)
var data = { // var data = {
data: new Uint8Array(imgData.data), // data: new Uint8Array(imgData.data),
width: canWidth, // width: canWidth,
height: canHeight, // height: canHeight,
type: "text", // type: "text",
path: null // path: null
} // }
s.texture.baseTexture._sourceChange(data); // s.texture.baseTexture._sourceChange(data);
s._onTextureUpdate(); // s._onTextureUpdate();
} // }
} }
......
...@@ -142,7 +142,7 @@ export default class Texture extends EventDispatcher { ...@@ -142,7 +142,7 @@ export default class Texture extends EventDispatcher {
this._rotate = Number(rotate || 0); this._rotate = Number(rotate || 0);
if (baseTexture.hasLoaded) { if (baseTexture.hasLoaded) {//对于canvas形式的判断hasLoaded有问题,导致不能监听update,到时改
if (this.noFrame) { if (this.noFrame) {
frame = new Rectangle(0, 0, baseTexture.width, baseTexture.height); frame = new Rectangle(0, 0, baseTexture.width, baseTexture.height);
// if there is no frame we should monitor for any base texture changes.. // if there is no frame we should monitor for any base texture changes..
......
/**
* ios还有问题,先别用
*/
export function createCanvas(): HTMLCanvasElement { export function createCanvas(): HTMLCanvasElement {
//@ts-ignore //@ts-ignore
return my && my._createOffscreenCanvas() || document.createElement("canvas") return document && document.createElement("canvas") || my._createOffscreenCanvas() || document.createElement("canvas")
} }
//每次都要重置 //每次都要重置
let backupCanvasContext: CanvasRenderingContext2D let backupCanvasContext: CanvasRenderingContext2D
...@@ -48,8 +46,8 @@ export function getCreateImage() { ...@@ -48,8 +46,8 @@ export function getCreateImage() {
return contentByCanvas && contentByCanvas.createImage || (() => { return new Image() }) return contentByCanvas && contentByCanvas.createImage || (() => { return new Image() })
} }
export function getRequestAnimationFrame() { export function getRequestAnimationFrame() {
return contentByCanvas && contentByCanvas.requestAnimationFrame || window.requestAnimationFrame return contentByCanvas && contentByCanvas.requestAnimationFrame || window.requestAnimationFrame.bind(window)
} }
export function getCancelAnimationFrame() { export function getCancelAnimationFrame() {
return contentByCanvas && contentByCanvas.cancelAnimationFrame || window.cancelAnimationFrame return contentByCanvas && contentByCanvas.cancelAnimationFrame || window.cancelAnimationFrame.bind(window)
} }
...@@ -2,6 +2,7 @@ import { CanvasRenderer } from "../renderers/CanvasRenderer"; ...@@ -2,6 +2,7 @@ import { CanvasRenderer } from "../renderers/CanvasRenderer";
import RenderTexture from "../texture/RenderTexture"; import RenderTexture from "../texture/RenderTexture";
import { Matrix, Rectangle } from "../math"; import { Matrix, Rectangle } from "../math";
import { DisplayObject } from "../display/DisplayObject"; import { DisplayObject } from "../display/DisplayObject";
import { createCanvas } from "./tbminiAdapte";
// 作为将显示对象导出成图片的render渲染器 // 作为将显示对象导出成图片的render渲染器
let _dRender: CanvasRenderer = null; let _dRender: CanvasRenderer = null;
...@@ -37,7 +38,7 @@ export default function toDisplayDataURL(obj: DisplayObject, rect: Rectangle = n ...@@ -37,7 +38,7 @@ export default function toDisplayDataURL(obj: DisplayObject, rect: Rectangle = n
let x: number = rect ? rect.x : bounds.x; let x: number = rect ? rect.x : bounds.x;
let y: number = rect ? rect.y : bounds.y; let y: number = rect ? rect.y : bounds.y;
if (!_dRender) { if (!_dRender) {
var canvas: HTMLCanvasElement = window["my"].createOffscreenCanvas(); var canvas: HTMLCanvasElement = createCanvas();
canvas.width = w; canvas.width = w;
canvas.height = h; canvas.height = h;
_dCanvas = canvas _dCanvas = canvas
......
...@@ -34,7 +34,7 @@ var Stats = function (canvasId) { ...@@ -34,7 +34,7 @@ var Stats = function (canvasId) {
//@ts-ignore //@ts-ignore
Stats.Panel = function (canvasId, name, fg, bg) { Stats.Panel = function (canvasId, name, fg, bg) {
var min = Infinity, max = 0, round = Math.round; var min = Infinity, max = 0, round = Math.round;
var PR = 1; var PR = 3;
var WIDTH = 80 * PR, HEIGHT = 48 * PR, var WIDTH = 80 * PR, HEIGHT = 48 * PR,
TEXT_X = 3 * PR, TEXT_Y = 2 * PR, TEXT_X = 3 * PR, TEXT_Y = 2 * PR,
...@@ -44,13 +44,21 @@ Stats.Panel = function (canvasId, name, fg, bg) { ...@@ -44,13 +44,21 @@ Stats.Panel = function (canvasId, name, fg, bg) {
var GRAPH_SIZE = GRAPH_WIDTH / PR; var GRAPH_SIZE = GRAPH_WIDTH / PR;
var items = []; var items = [];
var context //= my.createCanvasContext(canvasId);
//@ts-ignore //@ts-ignore
var context = my.createCanvasContext(canvasId); my.createCanvas({
context.font = 'bold ' + (9 * PR) + 'px Helvetica,Arial,sans-serif'; id: canvasId,
context.setTextBaseline('top'); success: (ccc) => {
context = ccc.getContext("2d")
context.font = 'bold ' + (9 * PR) + 'px Helvetica,Arial,sans-serif';
// context.setTextBaseline('top');
context.textBaseline = 'top'
drawWithoutGraph(name);
// context.draw();
}
})
drawWithoutGraph(name);
context.draw();
return { return {
update: function (value, maxValue) { update: function (value, maxValue) {
...@@ -68,33 +76,42 @@ Stats.Panel = function (canvasId, name, fg, bg) { ...@@ -68,33 +76,42 @@ Stats.Panel = function (canvasId, name, fg, bg) {
for (var i = 0; i < items.length; i++) { for (var i = 0; i < items.length; i++) {
var startPos = GRAPH_X + (i + GRAPH_SIZE - items.length) * PR; var startPos = GRAPH_X + (i + GRAPH_SIZE - items.length) * PR;
context.setFillStyle(fg); // context.setFillStyle(fg);
context.setGlobalAlpha(1); // context.setGlobalAlpha(1);
context.fillStyle = fg;
context.globalAlpha = 1;
context.fillRect(startPos, GRAPH_Y, PR, GRAPH_HEIGHT); context.fillRect(startPos, GRAPH_Y, PR, GRAPH_HEIGHT);
context.setFillStyle(bg); // context.setFillStyle(bg);
context.setGlobalAlpha(0.9); // context.setGlobalAlpha(0.9);
context.fillStyle = bg;
context.globalAlpha = 0.9;
context.fillRect(startPos, GRAPH_Y, PR, round((1 - (items[i] / maxValue)) * GRAPH_HEIGHT)); context.fillRect(startPos, GRAPH_Y, PR, round((1 - (items[i] / maxValue)) * GRAPH_HEIGHT));
} }
context.draw(); // context.draw();
} }
}; };
function drawWithoutGraph(text) { function drawWithoutGraph(text) {
// bg // bg
context.setFillStyle(bg); // context.setFillStyle(bg);
context.setGlobalAlpha(1); // context.setGlobalAlpha(1);
context.fillStyle = bg;
context.globalAlpha = 1;
context.fillRect(0, 0, WIDTH, HEIGHT); context.fillRect(0, 0, WIDTH, HEIGHT);
// text // text
context.setFillStyle(fg); // context.setFillStyle(fg);
context.fillStyle = fg;
context.fillText(text, TEXT_X, TEXT_Y); context.fillText(text, TEXT_X, TEXT_Y);
// graph bg // graph bg
context.fillRect(GRAPH_X, GRAPH_Y, GRAPH_WIDTH, GRAPH_HEIGHT); context.fillRect(GRAPH_X, GRAPH_Y, GRAPH_WIDTH, GRAPH_HEIGHT);
context.setFillStyle(bg); // context.setFillStyle(bg);
context.setGlobalAlpha(0.9); // context.setGlobalAlpha(0.9);
context.fillStyle = bg;
context.globalAlpha = 0.9;
context.fillRect(GRAPH_X, GRAPH_Y, GRAPH_WIDTH, GRAPH_HEIGHT); context.fillRect(GRAPH_X, GRAPH_Y, GRAPH_WIDTH, GRAPH_HEIGHT);
} }
}; };
......
/**
* @author mrdoob / http://mrdoob.com/
*/
var Stats = function (canvasId) {
var beginTime = Date.now(), prevTime = beginTime, frames = 0;
//@ts-ignore
var fpsPanel = new Stats.Panel(canvasId, 'FPS', '#0ff', '#002');
return {
begin: function () {
beginTime = Date.now();
},
end: function () {
frames++;
var time = Date.now();
if (time >= prevTime + 1000) {
fpsPanel.update((frames * 1000) / (time - prevTime), 100.0);
prevTime = time;
frames = 0;
}
return time;
},
update: function () {
beginTime = this.end();
},
};
};
//@ts-ignore
Stats.Panel = function (canvasId, name, fg, bg) {
var min = Infinity, max = 0, round = Math.round;
var PR = 1;
var WIDTH = 80 * PR, HEIGHT = 48 * PR,
TEXT_X = 3 * PR, TEXT_Y = 2 * PR,
GRAPH_X = 3 * PR, GRAPH_Y = 15 * PR,
GRAPH_WIDTH = 74 * PR, GRAPH_HEIGHT = 30 * PR;
var GRAPH_SIZE = GRAPH_WIDTH / PR;
var items = [];
//@ts-ignore
var context = my.createCanvasContext(canvasId);
context.font = 'bold ' + (9 * PR) + 'px Helvetica,Arial,sans-serif';
context.setTextBaseline('top');
drawWithoutGraph(name);
context.draw();
return {
update: function (value, maxValue) {
items.push(value);
while (items.length > GRAPH_SIZE) {
items.shift();
}
min = Math.min(min, value);
max = Math.max(max, value);
drawWithoutGraph(round(value) + ' ' + name + ' (' + round(min) + '-' + round(max) + ')');
// graph inner
for (var i = 0; i < items.length; i++) {
var startPos = GRAPH_X + (i + GRAPH_SIZE - items.length) * PR;
context.setFillStyle(fg);
context.setGlobalAlpha(1);
context.fillRect(startPos, GRAPH_Y, PR, GRAPH_HEIGHT);
context.setFillStyle(bg);
context.setGlobalAlpha(0.9);
context.fillRect(startPos, GRAPH_Y, PR, round((1 - (items[i] / maxValue)) * GRAPH_HEIGHT));
}
context.draw();
}
};
function drawWithoutGraph(text) {
// bg
context.setFillStyle(bg);
context.setGlobalAlpha(1);
context.fillRect(0, 0, WIDTH, HEIGHT);
// text
context.setFillStyle(fg);
context.fillText(text, TEXT_X, TEXT_Y);
// graph bg
context.fillRect(GRAPH_X, GRAPH_Y, GRAPH_WIDTH, GRAPH_HEIGHT);
context.setFillStyle(bg);
context.setGlobalAlpha(0.9);
context.fillRect(GRAPH_X, GRAPH_Y, GRAPH_WIDTH, GRAPH_HEIGHT);
}
};
export { Stats /*as default*/ };
...@@ -37,6 +37,7 @@ export * from "./sound" ...@@ -37,6 +37,7 @@ export * from "./sound"
export * from "./tween"; export * from "./tween";
if(window)window["my"]=null
// export * from "./Stats"; // export * from "./Stats";
/** /**
......
...@@ -111,7 +111,7 @@ export class SoundChannel extends EventDispatcher { ...@@ -111,7 +111,7 @@ export class SoundChannel extends EventDispatcher {
let url = this.$url; let url = this.$url;
//延迟一定时间再停止,规避chrome报错 //延迟一定时间再停止,规避chrome报错
window.setTimeout(function () { setTimeout(function () {
audio.pause(); audio.pause();
Sound.$recycle(url, audio); Sound.$recycle(url, audio);
}, 200); }, 200);
......
...@@ -1227,7 +1227,7 @@ export class EventDispatcher extends HashObject { ...@@ -1227,7 +1227,7 @@ export class EventDispatcher extends HashObject {
* @example * @example
* this.addEventListener(Event.ADD_TO_STAGE,function(e){trace(this);},this); * this.addEventListener(Event.ADD_TO_STAGE,function(e){trace(this);},this);
*/ */
addEventListener(type: string, listener: Function, context?: any, useCapture?: boolean): void; addEventListener(type: string, listener: Function, context?: any, useCapture?: boolean): this;
/** /**
* 监听一次 * 监听一次
* @param type * @param type
...@@ -1235,7 +1235,7 @@ export class EventDispatcher extends HashObject { ...@@ -1235,7 +1235,7 @@ export class EventDispatcher extends HashObject {
* @param context * @param context
* @param useCapture * @param useCapture
*/ */
once(type: string, listener: Function, context?: any, useCapture?: boolean): void; once(type: string, listener: Function, context?: any, useCapture?: boolean): this;
/** /**
* 增加或删除相应mouse或touch侦听记数 * 增加或删除相应mouse或touch侦听记数
* @method _changeMouseCount * @method _changeMouseCount
...@@ -1285,7 +1285,7 @@ export class EventDispatcher extends HashObject { ...@@ -1285,7 +1285,7 @@ export class EventDispatcher extends HashObject {
* @param context listener和context都相等的才移除,默认自身 * @param context listener和context都相等的才移除,默认自身
* @param {boolean} useCapture true 捕获阶段 false 冒泡阶段 默认 true * @param {boolean} useCapture true 捕获阶段 false 冒泡阶段 默认 true
*/ */
removeEventListener(type: string, listener: Function, context?: any, useCapture?: boolean): void; removeEventListener(type: string, listener: Function, context?: any, useCapture?: boolean): this;
/** /**
* 移除对象中所有的侦听 * 移除对象中所有的侦听
* @method removeAllEventListener * @method removeAllEventListener
...@@ -1336,11 +1336,9 @@ export class Point extends HashObject { ...@@ -1336,11 +1336,9 @@ export class Point extends HashObject {
export const VERSION = "1.0"; export const VERSION = "1.0";
export const sysInfo: any;
export const devicePixelRatio: number; export const devicePixelRatio: number;
export const osType: "ios" | "android"; export const osType: "ios" | "android" | "pc";
export function cos(angle: number): number; export function cos(angle: number): number;
...@@ -2206,9 +2204,9 @@ export function destroyCanvasContent(): void; ...@@ -2206,9 +2204,9 @@ export function destroyCanvasContent(): void;
export function getCreateImage(): () => HTMLImageElement; export function getCreateImage(): () => HTMLImageElement;
export function getRequestAnimationFrame(): (fun: Function) => number; export function getRequestAnimationFrame(): any;
export function getCancelAnimationFrame(): (id: any) => void; export function getCancelAnimationFrame(): any;
export const INT_BITS1 = 32; export const INT_BITS1 = 32;
...@@ -4633,6 +4631,13 @@ export class CanvasRenderTarget { ...@@ -4633,6 +4631,13 @@ export class CanvasRenderTarget {
} }
export class CanvasRenderer extends SystemRenderer { export class CanvasRenderer extends SystemRenderer {
/**
* 主屏幕渲染上下文
*/
rootContext: CanvasRenderingContext2D;
/**
* 当前使用的上下文
*/
context: CanvasRenderingContext2D; context: CanvasRenderingContext2D;
/** /**
* 遮罩管理类 * 遮罩管理类
...@@ -4901,17 +4906,25 @@ export class BaseTexture extends EventDispatcher { ...@@ -4901,17 +4906,25 @@ export class BaseTexture extends EventDispatcher {
*/ */
dispose(): void; dispose(): void;
/** /**
* * 根据路径
* @param {string} url 路径 * @param {string} url 路径
*/ */
static fromUrl(url: string): any; static fromUrl(url: string): any;
static fromSource(source: any): BaseTexture; /**
* 随便啥形式的,比如data,
* @param data
*/
static fromData(data: any): BaseTexture;
/** /**
* 从离屏canvas创建的 * 从离屏canvas创建的
*/ */
static fromCanvas(canvas: HTMLCanvasElement, origin?: string): any; static fromCanvas(canvas: HTMLCanvasElement, origin?: string): any;
static fromImage(image: HTMLImageElement): BaseTexture; /**
static from(anyThing: string | HTMLCanvasElement | HTMLImageElement): any; * 根据图片
* @param image
*/
static fromImage(image: HTMLImageElement): any;
static from(anything: string | HTMLCanvasElement | HTMLImageElement): any;
/** /**
* 加入缓存 * 加入缓存
* @static * @static
...@@ -5109,9 +5122,9 @@ export class Texture extends EventDispatcher { ...@@ -5109,9 +5122,9 @@ export class Texture extends EventDispatcher {
*/ */
static fromUrl(url: string): any; static fromUrl(url: string): any;
static fromCanvas(canvas: HTMLCanvasElement, origin?: string): Texture; static fromCanvas(canvas: HTMLCanvasElement, origin?: string): Texture;
static fromSource(source: any): Texture; static fromData(data: any): Texture;
static fromImage(image: HTMLImageElement): Texture; static fromImage(image: HTMLImageElement): Texture;
static from(anyThing: string | HTMLCanvasElement | HTMLImageElement): any; static from(anything: string | HTMLCanvasElement | HTMLImageElement): any;
/** /**
* 加入全局缓存,TextureCache[name]调用 * 加入全局缓存,TextureCache[name]调用
* @static * @static
...@@ -5987,14 +6000,14 @@ export class Container extends DisplayObject { ...@@ -5987,14 +6000,14 @@ export class Container extends DisplayObject {
* @param {DisplayObject} child * @param {DisplayObject} child
* @return {DisplayObject} * @return {DisplayObject}
*/ */
addChild(child: DisplayObject): DisplayObject; addChild<T extends DisplayObject>(child: T): T;
/** /**
* 在相应index处添加child * 在相应index处添加child
* @param {DisplayObject} child - The child to add * @param {DisplayObject} child - The child to add
* @param {number} index - The index to place the child in * @param {number} index - The index to place the child in
* @return {DisplayObject} The child that was added. * @return {DisplayObject} The child that was added.
*/ */
addChildAt(child: DisplayObject, index: number): DisplayObject; addChildAt<T extends DisplayObject>(child: T, index: number): T;
/** /**
* 只用于交换索引 * 只用于交换索引
* @param {DisplayObject} child - First display object to swap * @param {DisplayObject} child - First display object to swap
...@@ -7405,5 +7418,124 @@ export class ShowWord extends TextField { ...@@ -7405,5 +7418,124 @@ export class ShowWord extends TextField {
* @param callback 播放完后的回调 * @param callback 播放完后的回调
*/ */
playWords(text: string, deltaTime?: number, callback?: Function): void; playWords(text: string, deltaTime?: number, callback?: Function): void;
}
export interface InnerAudioContext {
src: string;
startTime: number;
autoplay: boolean;
loop: boolean;
obeyMuteSwitch: boolean;
duration: number;
currentTime: number;
paused: boolean;
buffered: number;
volume: number;
isRecordAudioPlayState: boolean;
play: () => void;
pause: () => void;
stop: void;
seek: (postion: number) => void;
destroy: void;
onCanplay: (fun: () => void) => void;
onPlay: (fun: () => void) => void;
onPause: (fun: () => void) => void;
onStop: (fun: () => void) => void;
onEnded: (fun: () => void) => void;
onTimeUpdate: (fun: () => void) => void;
onError: (fun: () => void) => void;
onWaiting: (fun: () => void) => void;
onSeeking: (fun: () => void) => void;
onSeeked: (fun: () => void) => void;
}
export function $pushSoundChannel(channel: SoundChannel): void;
export function $popSoundChannel(channel: SoundChannel): boolean;
export class Sound extends EventDispatcher {
/**
* 记录的路径
*/
private url;
/**
* 有url了,貌似就没必要了
*/
private originAudio;
/**
* @private
*/
private loaded;
constructor();
readonly length: number;
load(url: string): void;
/**
* @inheritDoc
*/
play(startTime?: number, loops?: number): SoundChannel;
/**
* @inheritDoc
*/
close(): void;
/**
* @private
*/
private static audios;
private static clearAudios;
static $clear(url: string): void;
static $pop(url: string): InnerAudioContext;
static $recycle(url: string, audio: InnerAudioContext): void;
}
export class SoundChannel extends EventDispatcher {
/**
* @private
*/
$url: string;
/**
* @private
*/
$loops: number;
/**
* @private
*/
$startTime: number;
/**
* @private
*/
private audio;
private isStopped;
/**
* @private
*/
constructor(audio: InnerAudioContext);
private canPlay;
$play(): void;
/**
* @private
*/
private onPlayEnd;
/**
* @private
* @inheritDoc
*/
stop(): void;
/**
* @private
*/
private _volume;
/**
* @private
* @inheritDoc
*/
/**
* @inheritDoc
*/
volume: number;
/**
* @private
* @inheritDoc
*/
readonly position: number;
}} }}
declare module "fyge" {export = FYGE;} declare module "fyge" {export = FYGE;}
\ No newline at end of file
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