Commit eb22fbd4 authored by wjf's avatar wjf

l

parent 6e24b57e
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.
...@@ -1429,14 +1429,12 @@ ...@@ -1429,14 +1429,12 @@
"balanced-match": { "balanced-match": {
"version": "1.0.0", "version": "1.0.0",
"bundled": true, "bundled": true,
"dev": true, "dev": true
"optional": true
}, },
"brace-expansion": { "brace-expansion": {
"version": "1.1.11", "version": "1.1.11",
"bundled": true, "bundled": true,
"dev": true, "dev": true,
"optional": true,
"requires": { "requires": {
"balanced-match": "^1.0.0", "balanced-match": "^1.0.0",
"concat-map": "0.0.1" "concat-map": "0.0.1"
...@@ -1451,20 +1449,17 @@ ...@@ -1451,20 +1449,17 @@
"code-point-at": { "code-point-at": {
"version": "1.1.0", "version": "1.1.0",
"bundled": true, "bundled": true,
"dev": true, "dev": true
"optional": true
}, },
"concat-map": { "concat-map": {
"version": "0.0.1", "version": "0.0.1",
"bundled": true, "bundled": true,
"dev": true, "dev": true
"optional": true
}, },
"console-control-strings": { "console-control-strings": {
"version": "1.1.0", "version": "1.1.0",
"bundled": true, "bundled": true,
"dev": true, "dev": true
"optional": true
}, },
"core-util-is": { "core-util-is": {
"version": "1.0.2", "version": "1.0.2",
...@@ -1581,8 +1576,7 @@ ...@@ -1581,8 +1576,7 @@
"inherits": { "inherits": {
"version": "2.0.4", "version": "2.0.4",
"bundled": true, "bundled": true,
"dev": true, "dev": true
"optional": true
}, },
"ini": { "ini": {
"version": "1.3.5", "version": "1.3.5",
...@@ -1594,7 +1588,6 @@ ...@@ -1594,7 +1588,6 @@
"version": "1.0.0", "version": "1.0.0",
"bundled": true, "bundled": true,
"dev": true, "dev": true,
"optional": true,
"requires": { "requires": {
"number-is-nan": "^1.0.0" "number-is-nan": "^1.0.0"
} }
...@@ -1609,7 +1602,6 @@ ...@@ -1609,7 +1602,6 @@
"version": "3.0.4", "version": "3.0.4",
"bundled": true, "bundled": true,
"dev": true, "dev": true,
"optional": true,
"requires": { "requires": {
"brace-expansion": "^1.1.7" "brace-expansion": "^1.1.7"
} }
...@@ -1617,14 +1609,12 @@ ...@@ -1617,14 +1609,12 @@
"minimist": { "minimist": {
"version": "1.2.5", "version": "1.2.5",
"bundled": true, "bundled": true,
"dev": true, "dev": true
"optional": true
}, },
"minipass": { "minipass": {
"version": "2.9.0", "version": "2.9.0",
"bundled": true, "bundled": true,
"dev": true, "dev": true,
"optional": true,
"requires": { "requires": {
"safe-buffer": "^5.1.2", "safe-buffer": "^5.1.2",
"yallist": "^3.0.0" "yallist": "^3.0.0"
...@@ -1643,7 +1633,6 @@ ...@@ -1643,7 +1633,6 @@
"version": "0.5.3", "version": "0.5.3",
"bundled": true, "bundled": true,
"dev": true, "dev": true,
"optional": true,
"requires": { "requires": {
"minimist": "^1.2.5" "minimist": "^1.2.5"
} }
...@@ -1705,8 +1694,7 @@ ...@@ -1705,8 +1694,7 @@
"npm-normalize-package-bin": { "npm-normalize-package-bin": {
"version": "1.0.1", "version": "1.0.1",
"bundled": true, "bundled": true,
"dev": true, "dev": true
"optional": true
}, },
"npm-packlist": { "npm-packlist": {
"version": "1.4.8", "version": "1.4.8",
...@@ -1734,8 +1722,7 @@ ...@@ -1734,8 +1722,7 @@
"number-is-nan": { "number-is-nan": {
"version": "1.0.1", "version": "1.0.1",
"bundled": true, "bundled": true,
"dev": true, "dev": true
"optional": true
}, },
"object-assign": { "object-assign": {
"version": "4.1.1", "version": "4.1.1",
...@@ -1747,7 +1734,6 @@ ...@@ -1747,7 +1734,6 @@
"version": "1.4.0", "version": "1.4.0",
"bundled": true, "bundled": true,
"dev": true, "dev": true,
"optional": true,
"requires": { "requires": {
"wrappy": "1" "wrappy": "1"
} }
...@@ -1861,7 +1847,6 @@ ...@@ -1861,7 +1847,6 @@
"version": "1.0.2", "version": "1.0.2",
"bundled": true, "bundled": true,
"dev": true, "dev": true,
"optional": true,
"requires": { "requires": {
"code-point-at": "^1.0.0", "code-point-at": "^1.0.0",
"is-fullwidth-code-point": "^1.0.0", "is-fullwidth-code-point": "^1.0.0",
...@@ -4147,4 +4132,4 @@ ...@@ -4147,4 +4132,4 @@
} }
} }
} }
} }
\ No newline at end of file
...@@ -24,4 +24,4 @@ ...@@ -24,4 +24,4 @@
"keywords": [ "keywords": [
"淘宝小程序,canvas" "淘宝小程序,canvas"
] ]
} }
\ No newline at end of file
...@@ -293,9 +293,9 @@ export class Stage extends Container { ...@@ -293,9 +293,9 @@ export class Stage extends Container {
* @private * @private
*/ */
private _mouseEventTypes: any = { private _mouseEventTypes: any = {
// touchstart: "onMouseDown", touchstart: "onMouseDown",
// touchmove: "onMouseMove", touchmove: "onMouseMove",
// touchend: "onMouseUp" touchend: "onMouseUp",
touchStart: "onMouseDown",//小程序返回的时间名是驼峰的 touchStart: "onMouseDown",//小程序返回的时间名是驼峰的
touchMove: "onMouseMove", touchMove: "onMouseMove",
touchEnd: "onMouseUp" touchEnd: "onMouseUp"
...@@ -581,7 +581,7 @@ export class Stage extends Container { ...@@ -581,7 +581,7 @@ export class Stage extends Container {
*/ */
public static addFPS(canvasId: string) { public static addFPS(canvasId: string) {
//@ts-ignore //@ts-ignore
Stage._stats = new Stats(canvasId); if (my) Stage._stats = new Stats(canvasId);
} }
/** /**
......
...@@ -504,7 +504,7 @@ export class TextField extends Sprite { ...@@ -504,7 +504,7 @@ export class TextField extends Sprite {
let hardLines: any = s._text.toString().split(/(?:\r\n|\r|\n)/); let hardLines: any = s._text.toString().split(/(?:\r\n|\r|\n)/);
let realLines: any = []; let realLines: any = [];
s.realLines = realLines; s.realLines = realLines;
// s._prepContext(ctx); s._prepContext(ctx);//因为不用canvas的api量文本宽度,所以这里执行不重要
let textWidth = s._textWidth; let textWidth = s._textWidth;
// let lineH = s._lineSpacing + s.size; // let lineH = s._lineSpacing + s.size;
...@@ -639,6 +639,8 @@ export class TextField extends Sprite { ...@@ -639,6 +639,8 @@ export class TextField extends Sprite {
} }
public destroy(): void { public destroy(): void {
this.canvas = null;
this.context = null;
super.destroy(); super.destroy();
//todo //todo
} }
......
...@@ -173,9 +173,9 @@ export default class BaseTexture extends EventDispatcher { ...@@ -173,9 +173,9 @@ export default class BaseTexture extends EventDispatcher {
_sourceChange(source) { _sourceChange(source) {
//赋值 //赋值
this.source = source; this.source = source;
//路径,暂时没用,需要时再处理 //路径,暂时没用,需要时再处理,先找src 再path(基本没有)
this.imageUrl = source.path || null; this.imageUrl = source.src || source.path || null;
//更新类型,暂时没用 //更新类型,暂时没用,也没做,需要是处理
this.imageType = this.source.type || null; this.imageType = this.source.type || null;
//加载完成 //加载完成
this.hasLoaded = true; this.hasLoaded = true;
...@@ -211,7 +211,7 @@ export default class BaseTexture extends EventDispatcher { ...@@ -211,7 +211,7 @@ export default class BaseTexture extends EventDispatcher {
//辅助静态方法 //辅助静态方法
/** /**
* * 根据路径
* @param {string} url 路径 * @param {string} url 路径
*/ */
static fromUrl(url: string) { static fromUrl(url: string) {
...@@ -227,8 +227,12 @@ export default class BaseTexture extends EventDispatcher { ...@@ -227,8 +227,12 @@ export default class BaseTexture extends EventDispatcher {
return baseTexture return baseTexture
} }
static fromSource(source) { /**
return new BaseTexture(source); * 随便啥形式的,比如data,
* @param data
*/
static fromData(data) {
return new BaseTexture(data);
} }
/** /**
...@@ -246,23 +250,38 @@ export default class BaseTexture extends EventDispatcher { ...@@ -246,23 +250,38 @@ export default class BaseTexture extends EventDispatcher {
} }
return baseTexture; return baseTexture;
} }
/**
* 根据图片
* @param image
*/
static fromImage(image: HTMLImageElement) { static fromImage(image: HTMLImageElement) {
return new BaseTexture(image); //图片标签
const imageUrl = image.src;
let baseTexture = BaseTextureCache[imageUrl];
if (!baseTexture) {
baseTexture = new BaseTexture(image);
//不缓存base64,如需要,设名字,手动缓存
if (imageUrl && imageUrl.indexOf('data:') !== 0) BaseTexture.addToCache(baseTexture, imageUrl);
}
return baseTexture;
} }
//不包括data形式 //不包括data形式,data用
static from(anyThing: string | HTMLCanvasElement | HTMLImageElement) { static from(anything: string | HTMLCanvasElement | HTMLImageElement) {
//路径 //路径
if (typeof anyThing === 'string') { if (typeof anything === 'string') {
return BaseTexture.fromUrl(anyThing); return BaseTexture.fromUrl(anything);
}
//@ts-ignore
else if (anything.data) {
return BaseTexture.fromData(anything);
} }
//@ts-ignore canvas //@ts-ignore canvas
else if (anyThing.getContext) { else if (anything.getContext) {
//@ts-ignore //@ts-ignore
return BaseTexture.fromCanvas(anyThing); return BaseTexture.fromCanvas(anything);
} else { } else {
//@ts-ignore //@ts-ignore
return BaseTexture.fromImage(anyThing); return BaseTexture.fromImage(anything);
} }
} }
......
...@@ -371,26 +371,36 @@ export default class Texture extends EventDispatcher { ...@@ -371,26 +371,36 @@ export default class Texture extends EventDispatcher {
return new Texture(BaseTexture.fromCanvas(canvas, origin)) return new Texture(BaseTexture.fromCanvas(canvas, origin))
} }
static fromSource(source) { static fromData(data) {
return new Texture(BaseTexture.fromSource(source)) return new Texture(BaseTexture.fromData(data))
} }
static fromImage(image: HTMLImageElement) { static fromImage(image: HTMLImageElement) {
return new Texture(BaseTexture.fromImage(image)); var imageUrl = image.src;
let texture: Texture = TextureCache[imageUrl];
if (!texture) {
texture = new Texture(BaseTexture.fromImage(image));
if (imageUrl && imageUrl.indexOf('data:') !== 0) Texture.addToCache(texture, imageUrl);
}
return texture;
} }
//不包括data形式 //不包括data形式
static from(anyThing: string | HTMLCanvasElement | HTMLImageElement) { static from(anything: string | HTMLCanvasElement | HTMLImageElement) {
//路径 //路径
if (typeof anyThing === 'string') { if (typeof anything === 'string') {
return Texture.fromUrl(anyThing); return Texture.fromUrl(anything);
}
//@ts-ignore
else if (anything.data) {
return Texture.fromData(anything);
} }
//@ts-ignore canvas //@ts-ignore canvas
else if (anyThing.getContext) { else if (anything.getContext) {
//@ts-ignore //@ts-ignore
return Texture.fromCanvas(anyThing); return Texture.fromCanvas(anything);
} else { } else {
//@ts-ignore //@ts-ignore
return Texture.fromImage(anyThing); return Texture.fromImage(anything);
} }
} }
......
/** /**
* ios还有问题,先别用 * ios还有问题,先别用
*/ */
export function createCanvas():HTMLCanvasElement { export function createCanvas(): HTMLCanvasElement {
//@ts-ignore //@ts-ignore
return my._createOffscreenCanvas() return my && my._createOffscreenCanvas() || document.createElement("canvas")
} }
//每次都要重置 //每次都要重置
let backupCanvasContext: CanvasRenderingContext2D let backupCanvasContext: CanvasRenderingContext2D
...@@ -36,18 +36,20 @@ export function initedByCanvas(canvas) { ...@@ -36,18 +36,20 @@ export function initedByCanvas(canvas) {
} }
} }
export function destroyCanvasContent() { export function destroyCanvasContent() {
contentByCanvas.createImage = null; if (contentByCanvas) {
contentByCanvas.requestAnimationFrame = null; contentByCanvas.createImage = null;
contentByCanvas.cancelAnimationFrame = null; contentByCanvas.requestAnimationFrame = null;
contentByCanvas = null contentByCanvas.cancelAnimationFrame = null;
contentByCanvas = null
}
} }
export function getCreateImage() { export function getCreateImage() {
return contentByCanvas && contentByCanvas.createImage return contentByCanvas && contentByCanvas.createImage || (() => { return new Image() })
} }
export function getRequestAnimationFrame() { export function getRequestAnimationFrame() {
return contentByCanvas && contentByCanvas.requestAnimationFrame return contentByCanvas && contentByCanvas.requestAnimationFrame || window.requestAnimationFrame
} }
export function getCancelAnimationFrame() { export function getCancelAnimationFrame() {
return contentByCanvas && contentByCanvas.cancelAnimationFrame return contentByCanvas && contentByCanvas.cancelAnimationFrame || window.cancelAnimationFrame
} }
...@@ -63,7 +63,8 @@ export * from "./tween"; ...@@ -63,7 +63,8 @@ export * from "./tween";
* 7、loader有大修改 * 7、loader有大修改
* 8、去掉了svga,到时能取外域文件再说 * 8、去掉了svga,到时能取外域文件再说
* 9、ios一帧多buffer绘制在小程序上有问题,先去掉了,原因在查,暂时应该无影响,有影响再说 * 9、ios一帧多buffer绘制在小程序上有问题,先去掉了,原因在查,暂时应该无影响,有影响再说
* 10、 * 10、安卓端createImage()返回的对象拿不到src属性,注意
* 11、
*/ */
// function aa(){ // function aa(){
......
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