Commit f4456b7c authored by rockyl's avatar rockyl

修复

parent b804b07c
...@@ -738,10 +738,14 @@ export default class Container extends DisplayObject { ...@@ -738,10 +738,14 @@ export default class Container extends DisplayObject {
// this.scale.x = 1; // this.scale.x = 1;
// } // }
if (this._width !== value) { if (this._width !== value) {
//子类有用,有_width,才需设置scaleX if (!value && value != 0) {
this._width = value; this._width = undefined;
this._localBoundsSelf.width = value; } else {
//if (this.stage) this.stage.layoutInvalid = true; //子类有用,有_width,才需设置scaleX
this._width = value;
this._localBoundsSelf.width = value;
//if (this.stage) this.stage.layoutInvalid = true;
}
this.dispatchEvent(Event.RESIZE); this.dispatchEvent(Event.RESIZE);
} }
} }
...@@ -762,10 +766,14 @@ export default class Container extends DisplayObject { ...@@ -762,10 +766,14 @@ export default class Container extends DisplayObject {
// } else { // } else {
// this.scale.y = 1; // this.scale.y = 1;
// } // }
if (this._height !== value) { if (!value && value != 0) {
this._height = value; this._height = undefined;
this._localBoundsSelf.height = value; } else {
//if (this.stage) this.stage.layoutInvalid = true; if (this._height !== value) {
this._height = value;
this._localBoundsSelf.height = value;
//if (this.stage) this.stage.layoutInvalid = true;
}
this.dispatchEvent(Event.RESIZE); this.dispatchEvent(Event.RESIZE);
} }
} }
......
...@@ -94,9 +94,9 @@ export default class Sprite extends Container { ...@@ -94,9 +94,9 @@ export default class Sprite extends Container {
this._texture = null; this._texture = null;
this._width = 0; //this._width = 0;
this._height = 0; //this._height = 0;
this._tint = null; this._tint = null;
this._tintRGB = null; this._tintRGB = null;
...@@ -391,14 +391,21 @@ export default class Sprite extends Container { ...@@ -391,14 +391,21 @@ export default class Sprite extends Container {
* @member {number} * @member {number}
*/ */
get width() { get width() {
return Math.abs(this.scale.x) * this._texture.orig.width; return this._width || Math.abs(this.scale.x) * this._texture.orig.width;
} }
set width(value) { set width(value) {
const s = sign(this.scale.x) || 1; if (this._width !== value) {
if (!value && value != 0) {
this.scale.x = 1
} else {
const s = sign(this.scale.x) || 1;
this.scale.x = s * value / this._texture.orig.width; this.scale.x = s * value / this._texture.orig.width;
this._width = value; }
this._width = value;
this.dispatchEvent(Event.RESIZE);
}
} }
/** /**
...@@ -406,13 +413,22 @@ export default class Sprite extends Container { ...@@ -406,13 +413,22 @@ export default class Sprite extends Container {
* @member {number} * @member {number}
*/ */
get height() { get height() {
return Math.abs(this.scale.y) * this._texture.orig.height; return this._height || Math.abs(this.scale.y) * this._texture.orig.height;
} }
set height(value) { set height(value) {
const s = sign(this.scale.y) || 1; if (!value && value != 0) {
this.scale.y = s * value / this._texture.orig.height; this._height = undefined;
this._height = value; } else {
if (!value && value != 0) {
this.scale.y = 1
} else {
const s = sign(this.scale.y) || 1;
this.scale.y = s * value / this._texture.orig.height;
}
this._height = value;
this.dispatchEvent(Event.RESIZE);
}
} }
/** /**
......
...@@ -169,28 +169,42 @@ export class TextField extends Sprite { ...@@ -169,28 +169,42 @@ export class TextField extends Sprite {
// private _textHeight: number = 0; // private _textHeight: number = 0;
get width(): number { get width(): number {
if (this._width) return this._width; if (!this._width && this._width != 0) {
this.updateText(); this.updateText();
return this.scale.x * this.getLocalBounds().width; return this.scale.x * this.getLocalBounds().width;
} else {
return this._width;
}
} }
set width(value: number) { set width(value: number) {
if (this._width !== value) { if (this._width !== value) {
this._width = value; if (!value && value != 0) {
this._width = undefined;
} else {
this._width = value;
}
this.dirty = true; this.dirty = true;
this.dispatchEvent(Event.RESIZE); this.dispatchEvent(Event.RESIZE);
} }
} }
get height(): number { get height(): number {
if (this._height) return this._height; if (!this._height && this._height != 0) {
this.updateText(); this.updateText();
return this.scale.y * this.getLocalBounds().height; return this.scale.y * this.getLocalBounds().height;
} else {
return this._height;
}
} }
set height(value: number) { set height(value: number) {
if (this._height !== value) { if (this._height !== value) {
this._height = value; if (!value && value != 0) {
this._height = undefined;
} else {
this._height = value;
}
this.dirty = true; this.dirty = true;
this.dispatchEvent(Event.RESIZE); this.dispatchEvent(Event.RESIZE);
} }
...@@ -588,7 +602,7 @@ export class TextField extends Sprite { ...@@ -588,7 +602,7 @@ export class TextField extends Sprite {
if (!text) { if (!text) {
s.canvas.width = 0; s.canvas.width = 0;
s.canvas.height = 0; s.canvas.height = 0;
if(!this._width && !this._height){ if (!this._width && !this._height) {
s._localBoundsSelf.clear(); s._localBoundsSelf.clear();
} }
this.anchorTexture = {x: 0, y: 0}; this.anchorTexture = {x: 0, y: 0};
...@@ -611,7 +625,7 @@ export class TextField extends Sprite { ...@@ -611,7 +625,7 @@ export class TextField extends Sprite {
s.realLines = realLines; s.realLines = realLines;
s._prepContext(ctx); s._prepContext(ctx);
let textWidth = s._width; let textWidth = !s._width && s._width != 0 ? 0 : s._width;
// let lineH = s._lineSpacing + s.size; // let lineH = s._lineSpacing + s.size;
//单行文本时 //单行文本时
if (isPureText && text.indexOf("\n") < 0 && s.lineType == TEXT_lINETYPE.SINGLE) { if (isPureText && text.indexOf("\n") < 0 && s.lineType == TEXT_lINETYPE.SINGLE) {
...@@ -639,7 +653,7 @@ export class TextField extends Sprite { ...@@ -639,7 +653,7 @@ export class TextField extends Sprite {
} }
} else { } else {
//textWidth取每行最大值,如果没设置过textWidth //textWidth取每行最大值,如果没设置过textWidth
const shouldMeasureTextWidth = !textWidth; const shouldMeasureTextWidth = !s._width && s._width != 0 ? true : false;
let index = 0; let index = 0;
for (let i = 0, l = hardLines.length; i < l; i++) { for (let i = 0, l = hardLines.length; i < l; i++) {
let str = hardLines[i]; let str = hardLines[i];
......
...@@ -10,8 +10,9 @@ import {devicePixelRatio} from "../../2d/const"; ...@@ -10,8 +10,9 @@ import {devicePixelRatio} from "../../2d/const";
import {Point} from "../../2d/math/Point"; import {Point} from "../../2d/math/Point";
const propPrefixFilter = ['_', '__', '$']; const propPrefixFilter = ['_', '__', '$'];
const includeProps = ['_width', '_height']; const includeProps = ['_width', '_height', 'worldMatrix'];
const propTypeFilter = ['function']; const excludeProps = ['eventTypes', 'eventTypes1', 'tempDisplayObjectParent', 'renderable', 'destroyed', 'children', 'start', 'pluginName', 'isUI', 'crossOrigin'];
const propTypeFilter = ['function', 'object'];
const offsetPrefix = 'offset_'; const offsetPrefix = 'offset_';
const absValueMapping = { const absValueMapping = {
x: 'a', x: 'a',
...@@ -63,26 +64,38 @@ export class EditorStage extends Node { ...@@ -63,26 +64,38 @@ export class EditorStage extends Node {
let node2 = {}; let node2 = {};
for (let key in node) { for (let key in node) {
let pass = false; let pass = false;
for (let prefix of propPrefixFilter) { if(excludeProps.indexOf(key) >= 0){
if (key.indexOf(prefix) >= 0) { pass = true;
pass = true; }
break; if(!pass){
for (let prefix of propPrefixFilter) {
if (key.indexOf(prefix) >= 0) {
pass = true;
break;
}
} }
} }
if (pass && includeProps.indexOf(key) > 0) {
if(key === 'width'){
//debugger
}
let v = node[key];
if (propTypeFilter.indexOf(typeof v) >= 0) {
pass = true;
}
if (includeProps.indexOf(key) >= 0) {
pass = false; pass = false;
} }
if (pass) { if (pass) {
continue; continue;
} }
let v = node[key];
if (propTypeFilter.indexOf(typeof v) < 0) { if (typeof v === 'object') {
if (typeof v === 'object') { v = objClone(v);
v = objClone(v);
}
node2[key] = v;
} }
node2[key] = v;
} }
return node2; return node2;
} }
...@@ -100,9 +113,9 @@ export class EditorStage extends Node { ...@@ -100,9 +113,9 @@ export class EditorStage extends Node {
for (let key in props) { for (let key in props) {
let v = props[key]; let v = props[key];
if (key.indexOf(offsetPrefix) < 0) { if (key.indexOf(offsetPrefix) < 0) {
if (emptyProps.indexOf(key) >= 0) { /*if(!v && v != 0 && emptyProps.indexOf(key) >= 0) {
key = '_' + key; key = '_' + key;
} }*/
node[key] = v; node[key] = v;
} else { } else {
key = key.replace(offsetPrefix, ''); key = key.replace(offsetPrefix, '');
......
...@@ -32,9 +32,11 @@ class ShapeBase extends Graphics implements IUIComponent { ...@@ -32,9 +32,11 @@ class ShapeBase extends Graphics implements IUIComponent {
private onResize(e) { private onResize(e) {
this.__fieldDirty = true; this.__fieldDirty = true;
//this.onEnterFrame();
} }
private onEnterFrame(e) { private onEnterFrame(e = null) {
if (this.__fieldDirty) { if (this.__fieldDirty) {
this.__fieldDirty = false; this.__fieldDirty = false;
......
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