mirror of
https://github.com/cocos/cocos4.git
synced 2026-12-02 00:22:43 +08:00
Merge branch '3d' of https://github.com/cocos-creator/engine into 3d
This commit is contained in:
@@ -23,15 +23,15 @@
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
import { ttfUtils } from './ttfUtils';
|
||||
import * as js from '../../../../core/utils/js';
|
||||
import { color4 } from '../../../../core/vmath';
|
||||
import { RenderData } from '../../../../renderer/ui/renderData';
|
||||
import { UI, IUIRenderData } from '../../../../renderer/ui/ui';
|
||||
import { IUIRenderData, UI } from '../../../../renderer/ui/ui';
|
||||
import { LabelComponent } from '../../components/label-component';
|
||||
import { MeshBuffer } from '../../mesh-buffer';
|
||||
import { IAssembler} from '../assembler';
|
||||
import { fillMeshVertices3D } from '../utils';
|
||||
import { MeshBuffer } from '../../mesh-buffer';
|
||||
import { color4 } from '../../../../core/vmath';
|
||||
import { ttfUtils } from './ttfUtils';
|
||||
|
||||
const WHITE = color4.create();
|
||||
|
||||
|
||||
@@ -23,13 +23,13 @@
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
import macro from '../../../../core/platform/CCMacro';
|
||||
import * as textUtils from '../../../../core/utils/text-utils';
|
||||
import { Component } from '../../../../components/component';
|
||||
import { LabelComponent } from '../../components/label-component';
|
||||
import { LabelOutline } from '../../../../2d/label/label-outline';
|
||||
import { SpriteFrame } from '../../../../assets/CCSpriteFrame';
|
||||
import { Size, Color } from '../../../../core/value-types';
|
||||
import { Component } from '../../../../components/component';
|
||||
import macro from '../../../../core/platform/CCMacro';
|
||||
import * as textUtils from '../../../../core/utils/text-utils';
|
||||
import { Color, Size } from '../../../../core/value-types';
|
||||
import { LabelComponent } from '../../components/label-component';
|
||||
|
||||
const Overflow = LabelComponent.Overflow;
|
||||
const WHITE = cc.Color.WHITE;
|
||||
@@ -44,7 +44,7 @@ let _string = '';
|
||||
let _fontSize = 0;
|
||||
let _drawFontsize = 0;
|
||||
let _splitedStrings: string[] = [];
|
||||
let _canvasSize = new Size();
|
||||
const _canvasSize = new Size();
|
||||
let _lineHeight = 0;
|
||||
let _hAlign = 0;
|
||||
let _vAlign = 0;
|
||||
@@ -67,52 +67,51 @@ let _isUnderline = false;
|
||||
|
||||
//
|
||||
interface ICanvasPool {
|
||||
pool: ISharedLabelData[],
|
||||
get(): ISharedLabelData,
|
||||
put(canvas: ISharedLabelData):void,
|
||||
pool: ISharedLabelData[];
|
||||
get (): ISharedLabelData;
|
||||
put (canvas: ISharedLabelData): void;
|
||||
}
|
||||
|
||||
let _canvasPool: ICanvasPool = {
|
||||
const _canvasPool: ICanvasPool = {
|
||||
pool: [],
|
||||
get() {
|
||||
get () {
|
||||
let data = this.pool.pop();
|
||||
|
||||
if (!data) {
|
||||
let canvas = document.createElement("canvas");
|
||||
let context = canvas.getContext("2d");
|
||||
const canvas = document.createElement('canvas');
|
||||
const context = canvas.getContext('2d');
|
||||
data = {
|
||||
canvas: canvas,
|
||||
context: context
|
||||
}
|
||||
canvas,
|
||||
context,
|
||||
};
|
||||
}
|
||||
|
||||
return data;
|
||||
},
|
||||
put(canvas: ISharedLabelData) {
|
||||
put (canvas: ISharedLabelData) {
|
||||
if (this.pool.length >= 32) {
|
||||
return;
|
||||
}
|
||||
this.pool.push(canvas);
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
export interface ISharedLabelData {
|
||||
canvas: HTMLCanvasElement,
|
||||
context: CanvasRenderingContext2D | null
|
||||
canvas: HTMLCanvasElement;
|
||||
context: CanvasRenderingContext2D | null;
|
||||
}
|
||||
|
||||
|
||||
export const ttfUtils = {
|
||||
getAssemblerData() {
|
||||
getAssemblerData () {
|
||||
// if (cc.game.renderType === cc.game.RENDER_TYPE_CANVAS) {
|
||||
// _sharedLabelData = _canvasPool.get();
|
||||
// }
|
||||
// else {
|
||||
// if (!_sharedLabelData) {
|
||||
let labelCanvas = document.createElement("canvas");
|
||||
let sharedLabelData = {
|
||||
const labelCanvas = document.createElement('canvas');
|
||||
const sharedLabelData = {
|
||||
canvas: labelCanvas,
|
||||
context: labelCanvas.getContext("2d")
|
||||
context: labelCanvas.getContext('2d'),
|
||||
};
|
||||
// }
|
||||
// }
|
||||
@@ -120,14 +119,14 @@ export const ttfUtils = {
|
||||
return sharedLabelData;
|
||||
},
|
||||
|
||||
resetAssemblerData(assemblerData: ISharedLabelData) {
|
||||
resetAssemblerData (assemblerData: ISharedLabelData) {
|
||||
if (cc.game.renderType === cc.game.RENDER_TYPE_CANVAS && assemblerData) {
|
||||
_canvasPool.put(assemblerData);
|
||||
}
|
||||
},
|
||||
|
||||
updateRenderData(comp: LabelComponent) {
|
||||
if (!comp.renderData||!comp.renderData.vertDirty) return;
|
||||
updateRenderData (comp: LabelComponent) {
|
||||
if (!comp.renderData || !comp.renderData.vertDirty) { return; }
|
||||
|
||||
this._updateFontFamly(comp);
|
||||
this._updateProperties(comp);
|
||||
@@ -149,17 +148,17 @@ export const ttfUtils = {
|
||||
_texture = null;
|
||||
},
|
||||
|
||||
updateVerts(comp: LabelComponent) {
|
||||
updateVerts (comp: LabelComponent) {
|
||||
},
|
||||
|
||||
_updateFontFamly(comp: LabelComponent) {
|
||||
_updateFontFamly (comp: LabelComponent) {
|
||||
if (!comp.useSystemFont) {
|
||||
if (comp.font) {
|
||||
if (comp.font._nativeAsset) {
|
||||
_fontFamily = comp.font._nativeAsset;
|
||||
}
|
||||
else {
|
||||
cc.loader.load(comp.font.nativeUrl, function (err, fontFamily) {
|
||||
cc.loader.load(comp.font.nativeUrl, (err, fontFamily) => {
|
||||
_fontFamily = fontFamily || 'Arial';
|
||||
comp.updateRenderData(true);
|
||||
});
|
||||
@@ -174,9 +173,9 @@ export const ttfUtils = {
|
||||
}
|
||||
},
|
||||
|
||||
_updateProperties(comp: LabelComponent) {
|
||||
let assemblerData = comp.assemblerData;
|
||||
if(!assemblerData){
|
||||
_updateProperties (comp: LabelComponent) {
|
||||
const assemblerData = comp.assemblerData;
|
||||
if (!assemblerData){
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -209,7 +208,7 @@ export const ttfUtils = {
|
||||
}
|
||||
|
||||
// outline
|
||||
let outline = OUTLINE_SUPPORTED && comp.getComponent(LabelOutline);
|
||||
const outline = OUTLINE_SUPPORTED && comp.getComponent(LabelOutline);
|
||||
if (outline && outline.enabled) {
|
||||
_isOutlined = true;
|
||||
_margin = _outlineWidth = outline.width;
|
||||
@@ -223,9 +222,9 @@ export const ttfUtils = {
|
||||
}
|
||||
},
|
||||
|
||||
_calculateFillTextStartPosition() {
|
||||
let lineHeight = this._getLineHeight();
|
||||
let lineCount = _splitedStrings.length;
|
||||
_calculateFillTextStartPosition () {
|
||||
const lineHeight = this._getLineHeight();
|
||||
const lineCount = _splitedStrings.length;
|
||||
let labelX;
|
||||
let firstLinelabelY;
|
||||
|
||||
@@ -252,7 +251,7 @@ export const ttfUtils = {
|
||||
return cc.v2(labelX, firstLinelabelY);
|
||||
},
|
||||
|
||||
_updateTexture() {
|
||||
_updateTexture () {
|
||||
if (!_context || !_canvas){
|
||||
return;
|
||||
}
|
||||
@@ -260,17 +259,17 @@ export const ttfUtils = {
|
||||
_context.clearRect(0, 0, _canvas.width, _canvas.height);
|
||||
_context.font = _fontDesc;
|
||||
|
||||
let startPosition = this._calculateFillTextStartPosition();
|
||||
let lineHeight = this._getLineHeight();
|
||||
//use round for line join to avoid sharp intersect point
|
||||
const startPosition = this._calculateFillTextStartPosition();
|
||||
const lineHeight = this._getLineHeight();
|
||||
// use round for line join to avoid sharp intersect point
|
||||
_context.lineJoin = 'round';
|
||||
_context.fillStyle = `rgba(${_color.r}, ${_color.g}, ${_color.b}, ${_color.a / 255})`;
|
||||
let underlineStartPosition;
|
||||
|
||||
//do real rendering
|
||||
// do real rendering
|
||||
for (let i = 0; i < _splitedStrings.length; ++i) {
|
||||
if (_isOutlined) {
|
||||
let strokeColor = _outlineColor || WHITE;
|
||||
const strokeColor = _outlineColor || WHITE;
|
||||
_context.strokeStyle = `rgba(${strokeColor.r}, ${strokeColor.g}, ${strokeColor.b}, ${strokeColor.a / 255})`;
|
||||
_context.lineWidth = _outlineWidth * 2;
|
||||
_context.strokeText(_splitedStrings[i], startPosition.x, startPosition.y + i * lineHeight);
|
||||
@@ -291,14 +290,15 @@ export const ttfUtils = {
|
||||
}
|
||||
|
||||
// _texture.handleLoadedTexture();
|
||||
if (_texture) {
|
||||
// hack
|
||||
if (_texture && _texture.image && _texture.image!.width !== 0 && _texture.image!.height !== 0) {
|
||||
_texture.mipmaps = [_texture.image!];
|
||||
}
|
||||
},
|
||||
|
||||
_calculateUnderlineStartPosition() {
|
||||
let lineHeight = this._getLineHeight();
|
||||
let lineCount = _splitedStrings.length;
|
||||
_calculateUnderlineStartPosition () {
|
||||
const lineHeight = this._getLineHeight();
|
||||
const lineCount = _splitedStrings.length;
|
||||
let labelX;
|
||||
let firstLinelabelY;
|
||||
|
||||
@@ -317,8 +317,8 @@ export const ttfUtils = {
|
||||
return cc.v2(labelX, firstLinelabelY);
|
||||
},
|
||||
|
||||
_updateLabelDimensions() {
|
||||
let paragraphedStrings = _string.split('\n');
|
||||
_updateLabelDimensions () {
|
||||
const paragraphedStrings = _string.split('\n');
|
||||
|
||||
if (_overflow === Overflow.RESIZE_HEIGHT) {
|
||||
_canvasSize.height = _splitedStrings.length * this._getLineHeight();
|
||||
@@ -327,8 +327,8 @@ export const ttfUtils = {
|
||||
_splitedStrings = paragraphedStrings;
|
||||
let canvasSizeX = 0;
|
||||
let canvasSizeY = 0;
|
||||
for (let i = 0; i < paragraphedStrings.length; ++i) {
|
||||
let paraLength = textUtils.safeMeasureText(_context, paragraphedStrings[i]);
|
||||
for (const para of paragraphedStrings) {
|
||||
const paraLength = textUtils.safeMeasureText(_context, para);
|
||||
canvasSizeX = canvasSizeX > paraLength ? canvasSizeX : paraLength;
|
||||
}
|
||||
canvasSizeY = _splitedStrings.length * this._getLineHeight();
|
||||
@@ -336,12 +336,12 @@ export const ttfUtils = {
|
||||
_canvasSize.width = parseFloat(canvasSizeX.toFixed(2)) + 2 * _margin;
|
||||
_canvasSize.height = parseFloat(canvasSizeY.toFixed(2));
|
||||
if (_isItalic) {
|
||||
//0.0174532925 = 3.141592653 / 180
|
||||
// 0.0174532925 = 3.141592653 / 180
|
||||
_canvasSize.width += _drawFontsize * Math.tan(12 * 0.0174532925);
|
||||
}
|
||||
}
|
||||
|
||||
if(!_canvas){
|
||||
if (!_canvas){
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -349,7 +349,7 @@ export const ttfUtils = {
|
||||
_canvas.height = _canvasSize.height;
|
||||
},
|
||||
|
||||
_calculateTextBaseline() {
|
||||
_calculateTextBaseline () {
|
||||
// let node = this._node;
|
||||
let hAlign;
|
||||
let vAlign;
|
||||
@@ -380,15 +380,15 @@ export const ttfUtils = {
|
||||
}
|
||||
},
|
||||
|
||||
_calculateSplitedStrings() {
|
||||
let paragraphedStrings = _string.split('\n');
|
||||
_calculateSplitedStrings () {
|
||||
const paragraphedStrings = _string.split('\n');
|
||||
|
||||
if (_isWrapText) {
|
||||
_splitedStrings = [];
|
||||
let canvasWidthNoMargin = _canvasSize.width - 2 * _margin;
|
||||
for (let i = 0; i < paragraphedStrings.length; ++i) {
|
||||
let allWidth = textUtils.safeMeasureText(_context, paragraphedStrings[i]);
|
||||
let textFragment = textUtils.fragmentText(paragraphedStrings[i],
|
||||
const canvasWidthNoMargin = _canvasSize.width - 2 * _margin;
|
||||
for (const para of paragraphedStrings) {
|
||||
const allWidth = textUtils.safeMeasureText(_context, para);
|
||||
const textFragment = textUtils.fragmentText(para,
|
||||
allWidth,
|
||||
canvasWidthNoMargin,
|
||||
this._measureText(_context!));
|
||||
@@ -401,17 +401,17 @@ export const ttfUtils = {
|
||||
|
||||
},
|
||||
|
||||
_getFontDesc() {
|
||||
_getFontDesc () {
|
||||
let fontDesc = _fontSize.toString() + 'px ';
|
||||
fontDesc = fontDesc + _fontFamily;
|
||||
if (_isBold) {
|
||||
fontDesc = "bold " + fontDesc;
|
||||
fontDesc = 'bold ' + fontDesc;
|
||||
}
|
||||
|
||||
return fontDesc;
|
||||
},
|
||||
|
||||
_getLineHeight() {
|
||||
_getLineHeight () {
|
||||
let nodeSpacingY = _lineHeight;
|
||||
if (nodeSpacingY === 0) {
|
||||
nodeSpacingY = _fontSize;
|
||||
@@ -422,25 +422,25 @@ export const ttfUtils = {
|
||||
return nodeSpacingY | 0;
|
||||
},
|
||||
|
||||
_calculateParagraphLength(paragraphedStrings: string[], ctx: CanvasRenderingContext2D) {
|
||||
let paragraphLength: number[] = [];
|
||||
_calculateParagraphLength (paragraphedStrings: string[], ctx: CanvasRenderingContext2D) {
|
||||
const paragraphLength: number[] = [];
|
||||
|
||||
for (let i = 0; i < paragraphedStrings.length; ++i) {
|
||||
let width: number = textUtils.safeMeasureText(ctx, paragraphedStrings[i]);
|
||||
for (const para of paragraphedStrings) {
|
||||
const width: number = textUtils.safeMeasureText(ctx, para);
|
||||
paragraphLength.push(width);
|
||||
}
|
||||
|
||||
return paragraphLength;
|
||||
},
|
||||
|
||||
_measureText(ctx: CanvasRenderingContext2D) {
|
||||
return function (string) {
|
||||
_measureText (ctx: CanvasRenderingContext2D) {
|
||||
return (string) => {
|
||||
return textUtils.safeMeasureText(ctx, string);
|
||||
};
|
||||
},
|
||||
|
||||
_calculateLabelFont() {
|
||||
if(!_context){
|
||||
_calculateLabelFont () {
|
||||
if (!_context){
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -448,8 +448,8 @@ export const ttfUtils = {
|
||||
_context.font = _fontDesc;
|
||||
|
||||
if (_overflow === Overflow.SHRINK) {
|
||||
let paragraphedStrings = _string.split('\n');
|
||||
let paragraphLength = this._calculateParagraphLength(paragraphedStrings, _context);
|
||||
const paragraphedStrings = _string.split('\n');
|
||||
const paragraphLength = this._calculateParagraphLength(paragraphedStrings, _context);
|
||||
|
||||
_splitedStrings = paragraphedStrings;
|
||||
let i = 0;
|
||||
@@ -457,8 +457,8 @@ export const ttfUtils = {
|
||||
let maxLength = 0;
|
||||
|
||||
if (_isWrapText) {
|
||||
let canvasWidthNoMargin = _canvasSize.width - 2 * _margin;
|
||||
let canvasHeightNoMargin = _canvasSize.height - 2 * _margin;
|
||||
const canvasWidthNoMargin = _canvasSize.width - 2 * _margin;
|
||||
const canvasHeightNoMargin = _canvasSize.height - 2 * _margin;
|
||||
if (canvasWidthNoMargin < 0 || canvasHeightNoMargin < 0) {
|
||||
_fontDesc = this._getFontDesc();
|
||||
_context.font = _fontDesc;
|
||||
@@ -467,7 +467,7 @@ export const ttfUtils = {
|
||||
totalHeight = canvasHeightNoMargin + 1;
|
||||
maxLength = canvasWidthNoMargin + 1;
|
||||
let actualFontSize = _fontSize + 1;
|
||||
let textFragment = "";
|
||||
let textFragment = '';
|
||||
let tryDivideByTwo = true;
|
||||
let startShrinkFontSize = actualFontSize | 0;
|
||||
|
||||
@@ -490,13 +490,13 @@ export const ttfUtils = {
|
||||
totalHeight = 0;
|
||||
for (i = 0; i < paragraphedStrings.length; ++i) {
|
||||
let j = 0;
|
||||
let allWidth = textUtils.safeMeasureText(_context, paragraphedStrings[i]);
|
||||
const allWidth = textUtils.safeMeasureText(_context, paragraphedStrings[i]);
|
||||
textFragment = textUtils.fragmentText(paragraphedStrings[i],
|
||||
allWidth,
|
||||
canvasWidthNoMargin,
|
||||
this._measureText(_context));
|
||||
while (j < textFragment.length) {
|
||||
let measureWidth = textUtils.safeMeasureText(_context, textFragment[j]);
|
||||
const measureWidth = textUtils.safeMeasureText(_context, textFragment[j]);
|
||||
maxLength = measureWidth;
|
||||
totalHeight += this._getLineHeight();
|
||||
++j;
|
||||
@@ -522,13 +522,13 @@ export const ttfUtils = {
|
||||
maxLength = paragraphLength[i];
|
||||
}
|
||||
}
|
||||
let scaleX = (_canvasSize.width - 2 * _margin) / maxLength;
|
||||
let scaleY = _canvasSize.height / totalHeight;
|
||||
const scaleX = (_canvasSize.width - 2 * _margin) / maxLength;
|
||||
const scaleY = _canvasSize.height / totalHeight;
|
||||
|
||||
_fontSize = (_drawFontsize * Math.min(1, scaleX, scaleY)) | 0;
|
||||
_fontDesc = this._getFontDesc();
|
||||
_context.font = _fontDesc;
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
@@ -27,13 +27,13 @@
|
||||
import { CameraComponent } from '../../../3d/framework/camera-component';
|
||||
import { Component } from '../../../components/component';
|
||||
import { ccclass, executeInEditMode, executionOrder, menu, property } from '../../../core/data/class-decorator';
|
||||
import { Color, Rect, Size, Vec3 } from '../../../core/value-types';
|
||||
import { GFXClearFlag } from '../../../gfx/define';
|
||||
import { Camera } from '../../../renderer/scene/camera';
|
||||
import { Node } from '../../../scene-graph/node';
|
||||
import { Color, Rect, Size, Vec3 } from '../../../core/value-types';
|
||||
|
||||
let _tempPos= new Vec3();
|
||||
let _worldPos = new Vec3();
|
||||
const _tempPos = new Vec3();
|
||||
const _worldPos = new Vec3();
|
||||
|
||||
/**
|
||||
* !#zh: 作为 UI 根节点,为所有子节点提供视窗四边的位置信息以供对齐,另外提供屏幕适配策略接口,方便从编辑器设置。
|
||||
@@ -128,7 +128,7 @@ export class CanvasComponent extends Component {
|
||||
// @property
|
||||
// private _priority = 0;
|
||||
|
||||
private _thisOnResized: ()=>void;
|
||||
private _thisOnResized: () => void;
|
||||
|
||||
private _camera: Camera | null = null;
|
||||
|
||||
@@ -143,7 +143,7 @@ export class CanvasComponent extends Component {
|
||||
constructor () {
|
||||
super();
|
||||
this._thisOnResized = this.alignWithScreen.bind(this);
|
||||
if(!CanvasComponent.instance){
|
||||
if (!CanvasComponent.instance){
|
||||
CanvasComponent.instance = this;
|
||||
}
|
||||
}
|
||||
@@ -155,7 +155,7 @@ export class CanvasComponent extends Component {
|
||||
}
|
||||
|
||||
public __preload () {
|
||||
let cameraNode = new Node('UICamera');
|
||||
const cameraNode = new Node('UICamera');
|
||||
cameraNode.setPosition(0, 0, 1000);
|
||||
this._camera = this._getRenderScene().createCamera({
|
||||
name: 'ui',
|
||||
@@ -237,7 +237,7 @@ export class CanvasComponent extends Component {
|
||||
}
|
||||
}
|
||||
|
||||
public alignWithScreen() {
|
||||
public alignWithScreen () {
|
||||
let nodeSize, designSize;
|
||||
if (CC_EDITOR) {
|
||||
// nodeSize = designSize = cc.engine.getDesignResolutionSize();
|
||||
|
||||
@@ -24,15 +24,15 @@
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
import Font from '../../../assets/CCFont';
|
||||
import { SpriteFrame } from '../../../assets/CCSpriteFrame';
|
||||
import { Font} from '../../../assets/font';
|
||||
import { ImageAsset } from '../../../assets/image-asset';
|
||||
import { ccclass, executionOrder, menu, property } from '../../../core/data/class-decorator';
|
||||
import macro from '../../../core/platform/CCMacro';
|
||||
import { ccenum } from '../../../core/value-types/enum';
|
||||
import { UIRenderComponent } from './ui-render-component';
|
||||
import { ISharedLabelData } from '../assembler/label/ttfUtils';
|
||||
import { UI } from '../../../renderer/ui/ui';
|
||||
import { ISharedLabelData } from '../assembler/label/ttfUtils';
|
||||
import { UIRenderComponent } from './ui-render-component';
|
||||
|
||||
/**
|
||||
* !#en Enum for text alignment.
|
||||
@@ -210,7 +210,10 @@ export class LabelComponent extends UIRenderComponent {
|
||||
* !#zh SHRINK 模式下面文本实际渲染的字体大小
|
||||
* @property {Number} actualFontSize
|
||||
*/
|
||||
@property
|
||||
@property({
|
||||
readonly: true,
|
||||
displayName: 'Actual Font Size',
|
||||
})
|
||||
get actualFontSize () {
|
||||
return this._actualFontSize;
|
||||
}
|
||||
@@ -431,7 +434,7 @@ export class LabelComponent extends UIRenderComponent {
|
||||
/**
|
||||
* !#en Whether the font is tilted or not.
|
||||
* !#zh 字体是否倾斜。
|
||||
* @property {Boolean} isBold
|
||||
* @property {Boolean} isItalic
|
||||
*/
|
||||
@property
|
||||
get isItalic () {
|
||||
@@ -449,7 +452,7 @@ export class LabelComponent extends UIRenderComponent {
|
||||
/**
|
||||
* !#en Whether the font is underlined.
|
||||
* !#zh 字体是否加下划线。
|
||||
* @property {Boolean} isBold
|
||||
* @property {Boolean} isUnderline
|
||||
*/
|
||||
@property
|
||||
get isUnderline () {
|
||||
@@ -468,7 +471,7 @@ export class LabelComponent extends UIRenderComponent {
|
||||
return this._texture;
|
||||
}
|
||||
|
||||
get assemblerData(){
|
||||
get assemblerData (){
|
||||
return this._assemblerData;
|
||||
}
|
||||
|
||||
@@ -564,14 +567,7 @@ export class LabelComponent extends UIRenderComponent {
|
||||
// this._super();
|
||||
}
|
||||
|
||||
public updateAssembler(render: UI) {
|
||||
if (!this._material || this.string.length <= 0) {
|
||||
return;
|
||||
}
|
||||
super.updateAssembler(render);
|
||||
}
|
||||
|
||||
public updateRenderData(force = false) {
|
||||
public updateRenderData (force = false) {
|
||||
const renderData = this._renderData;
|
||||
if (renderData) {
|
||||
renderData.vertDirty = true;
|
||||
@@ -585,6 +581,38 @@ export class LabelComponent extends UIRenderComponent {
|
||||
}
|
||||
}
|
||||
|
||||
protected _updateColor () {
|
||||
const font = this.font;
|
||||
if (font instanceof cc.BitmapFont) {
|
||||
// this._super();
|
||||
} else {
|
||||
this.updateRenderData(false);
|
||||
// this.node._renderFlag &= ~RenderFlow.FLAG_COLOR;
|
||||
}
|
||||
}
|
||||
|
||||
protected _canRender () {
|
||||
// let result = this._super();
|
||||
// TODO: use renderFlag
|
||||
let result = super._canRender();
|
||||
// if (result) {
|
||||
// const font = this._font;
|
||||
// if (font && font instanceof cc.BitmapFont) {
|
||||
// const spriteFrame = font.spriteFrame;
|
||||
// // cannot be activated if texture not loaded yet
|
||||
// if (!spriteFrame || !spriteFrame.textureLoaded()) {
|
||||
// result = false;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
if (result) {
|
||||
result = this._string.length > 0 ? true : false;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// private _canRender () {
|
||||
// // let result = this._super();
|
||||
// let result = this._enabled;
|
||||
@@ -619,16 +647,6 @@ export class LabelComponent extends UIRenderComponent {
|
||||
}
|
||||
}
|
||||
|
||||
protected _updateColor () {
|
||||
const font = this.font;
|
||||
if (font instanceof cc.BitmapFont) {
|
||||
// this._super();
|
||||
} else {
|
||||
this.updateRenderData(false);
|
||||
// this.node._renderFlag &= ~RenderFlow.FLAG_COLOR;
|
||||
}
|
||||
}
|
||||
|
||||
private _activateMaterial (force) {
|
||||
const material = this._material;
|
||||
// if (material && !force) {
|
||||
|
||||
@@ -24,15 +24,15 @@
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
// @ts-check
|
||||
import atlas from '../../../assets/CCSpriteAtlas';
|
||||
import { SpriteFrame } from '../../../assets/CCSpriteFrame';
|
||||
import { SpriteAtlas } from '../../../assets/sprite-atlas';
|
||||
import { ccclass, executionOrder, menu, property } from '../../../core/data/class-decorator';
|
||||
import { clampf } from '../../../core/utils/misc';
|
||||
import { Vec2 } from '../../../core/value-types';
|
||||
import { ccenum } from '../../../core/value-types/enum';
|
||||
import { UI } from '../../../renderer/ui/ui';
|
||||
import { UIRenderComponent } from './ui-render-component';
|
||||
import { EventType } from '../../../scene-graph/node-event-enum';
|
||||
import { UIRenderComponent } from './ui-render-component';
|
||||
|
||||
/**
|
||||
* !#en Enum for sprite type.
|
||||
@@ -125,8 +125,8 @@ enum SizeMode {
|
||||
* !#zh 自动适配为精灵原图尺寸
|
||||
* @property {Number} RAW
|
||||
*/
|
||||
RAW = 2
|
||||
};
|
||||
RAW = 2,
|
||||
}
|
||||
|
||||
ccenum(SizeMode);
|
||||
|
||||
@@ -267,7 +267,7 @@ export class SpriteComponent extends UIRenderComponent {
|
||||
return this._fillStart;
|
||||
}
|
||||
|
||||
set fillStart (value: number) {
|
||||
set fillStart (value) {
|
||||
this._fillStart = clampf(value, -1, 1);
|
||||
if (this._type === SpriteType.FILLED && this._renderData) {
|
||||
this.markForUpdateRenderData();
|
||||
@@ -289,7 +289,7 @@ export class SpriteComponent extends UIRenderComponent {
|
||||
get fillRange () {
|
||||
return this._fillRange;
|
||||
}
|
||||
set fillRange (value: number) {
|
||||
set fillRange (value) {
|
||||
// ??? -1 ~ 1
|
||||
// this._fillRange = cc.misc.clampf(value, -1, 1);
|
||||
this._fillRange = clampf(value, 0, 1);
|
||||
@@ -333,12 +333,12 @@ export class SpriteComponent extends UIRenderComponent {
|
||||
* sprite.sizeMode = cc.Sprite.SizeMode.CUSTOM;
|
||||
*/
|
||||
@property({
|
||||
type: SizeMode
|
||||
type: SizeMode,
|
||||
})
|
||||
get sizeMode() {
|
||||
get sizeMode () {
|
||||
return this._sizeMode;
|
||||
}
|
||||
set sizeMode(value) {
|
||||
set sizeMode (value) {
|
||||
this._sizeMode = value;
|
||||
if (value !== SizeMode.CUSTOM) {
|
||||
this._applySpriteSize();
|
||||
@@ -347,31 +347,31 @@ export class SpriteComponent extends UIRenderComponent {
|
||||
|
||||
public static FillType = FillType;
|
||||
public static Type = SpriteType;
|
||||
public static SizeMode = SizeMode;
|
||||
@property
|
||||
public _spriteFrame: SpriteFrame | null = null;
|
||||
private _spriteFrame: SpriteFrame | null = null;
|
||||
@property
|
||||
public _type: number = SpriteType.SIMPLE;
|
||||
private _type = SpriteType.SIMPLE;
|
||||
@property
|
||||
public _fillType: number = FillType.HORIZONTAL;
|
||||
private _fillType = FillType.HORIZONTAL;
|
||||
@property
|
||||
public _sizeMode = SizeMode.TRIMMED;
|
||||
private _sizeMode = SizeMode.TRIMMED;
|
||||
@property
|
||||
public _fillCenter: Vec2 = new Vec2(0, 0);
|
||||
private _fillCenter: Vec2 = new Vec2(0, 0);
|
||||
@property
|
||||
public _fillStart: number = 0;
|
||||
private _fillStart = 0;
|
||||
@property
|
||||
public _fillRange: number = 0;
|
||||
private _fillRange = 0;
|
||||
@property
|
||||
_isTrimmedMode = true;
|
||||
private _isTrimmedMode = true;
|
||||
// _state = 0;
|
||||
// TODO:
|
||||
@property
|
||||
public _atlas: atlas | null = null;
|
||||
public _spriteWidget = null;
|
||||
static SizeMode = SizeMode;
|
||||
private _atlas: SpriteAtlas | null = null;
|
||||
private _spriteWidget = null;
|
||||
// static State = State;
|
||||
|
||||
public __preload() {
|
||||
public __preload () {
|
||||
if (super.__preload) {
|
||||
super.__preload();
|
||||
}
|
||||
@@ -441,6 +441,85 @@ export class SpriteComponent extends UIRenderComponent {
|
||||
this.markForUpdateRenderData();
|
||||
}
|
||||
|
||||
// public markForUpdateRenderData (enable: boolean) {
|
||||
// if (enable /*&& this._canRender()*/) {
|
||||
// // this.node._renderFlag |= RenderFlow.FLAG_UPDATE_RENDER_DATA;
|
||||
|
||||
// const renderData = this._renderData;
|
||||
// if (renderData) {
|
||||
// renderData.uvDirty = true;
|
||||
// renderData.vertDirty = true;
|
||||
// }
|
||||
// }
|
||||
// // else if (!enable) {
|
||||
// // this.node._renderFlag &= ~RenderFlow.FLAG_UPDATE_RENDER_DATA;
|
||||
// // }
|
||||
// }
|
||||
|
||||
public _applySpriteSize () {
|
||||
if (this._spriteFrame) {
|
||||
if (SizeMode.RAW === this._sizeMode) {
|
||||
const size = this._spriteFrame.getOriginalSize();
|
||||
this.node.setContentSize(size);
|
||||
} else if (SizeMode.TRIMMED === this._sizeMode) {
|
||||
const rect = this._spriteFrame.getRect();
|
||||
this.node.setContentSize(rect.width, rect.height);
|
||||
}
|
||||
|
||||
this._activateMaterial();
|
||||
}
|
||||
}
|
||||
|
||||
public _resized () {
|
||||
if (!CC_EDITOR) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this._spriteFrame) {
|
||||
const actualSize = this.node.getContentSize();
|
||||
let expectedW = actualSize.width;
|
||||
let expectedH = actualSize.height;
|
||||
if (this._sizeMode === SizeMode.RAW) {
|
||||
const size = this._spriteFrame.getOriginalSize();
|
||||
expectedW = size.width;
|
||||
expectedH = size.height;
|
||||
} else if (this._sizeMode === SizeMode.TRIMMED) {
|
||||
const rect = this._spriteFrame.getRect();
|
||||
expectedW = rect.width;
|
||||
expectedH = rect.height;
|
||||
|
||||
}
|
||||
|
||||
if (expectedW !== actualSize.width || expectedH !== actualSize.height) {
|
||||
this._sizeMode = SizeMode.CUSTOM;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected _canRender () {
|
||||
// if (cc.game.renderType === cc.game.RENDER_TYPE_CANVAS) {
|
||||
// if (!this._enabled) { return false; }
|
||||
// } else {
|
||||
// if (!this._enabled || !this._material) { return false; }
|
||||
// }
|
||||
|
||||
// const spriteFrame = this._spriteFrame;
|
||||
// if (!spriteFrame || !spriteFrame.textureLoaded()) {
|
||||
// return false;
|
||||
// }
|
||||
// return true;
|
||||
let canRender = super._canRender();
|
||||
if (canRender) {
|
||||
const spriteFrame = this._spriteFrame;
|
||||
if (!spriteFrame || !spriteFrame.textureLoaded()) {
|
||||
canRender = false;
|
||||
}
|
||||
canRender = true;
|
||||
}
|
||||
|
||||
return canRender;
|
||||
}
|
||||
|
||||
private _flushAssembler () {
|
||||
const assembler = SpriteComponent.Assembler!.getAssembler(this);
|
||||
|
||||
@@ -509,49 +588,6 @@ export class SpriteComponent extends UIRenderComponent {
|
||||
}
|
||||
}
|
||||
|
||||
// private _canRender () {
|
||||
// if (cc.game.renderType === cc.game.RENDER_TYPE_CANVAS) {
|
||||
// if (!this._enabled) { return false; }
|
||||
// } else {
|
||||
// if (!this._enabled || !this._material) { return false; }
|
||||
// }
|
||||
|
||||
// const spriteFrame = this._spriteFrame;
|
||||
// if (!spriteFrame || !spriteFrame.textureLoaded()) {
|
||||
// return false;
|
||||
// }
|
||||
// return true;
|
||||
// }
|
||||
|
||||
// public markForUpdateRenderData (enable: boolean) {
|
||||
// if (enable /*&& this._canRender()*/) {
|
||||
// // this.node._renderFlag |= RenderFlow.FLAG_UPDATE_RENDER_DATA;
|
||||
|
||||
// const renderData = this._renderData;
|
||||
// if (renderData) {
|
||||
// renderData.uvDirty = true;
|
||||
// renderData.vertDirty = true;
|
||||
// }
|
||||
// }
|
||||
// // else if (!enable) {
|
||||
// // this.node._renderFlag &= ~RenderFlow.FLAG_UPDATE_RENDER_DATA;
|
||||
// // }
|
||||
// }
|
||||
|
||||
_applySpriteSize() {
|
||||
if (this._spriteFrame) {
|
||||
if (SizeMode.RAW === this._sizeMode) {
|
||||
const size = this._spriteFrame.getOriginalSize();
|
||||
this.node.setContentSize(size);
|
||||
} else if (SizeMode.TRIMMED === this._sizeMode) {
|
||||
const rect = this._spriteFrame.getRect();
|
||||
this.node.setContentSize(rect.width, rect.height);
|
||||
}
|
||||
|
||||
this._activateMaterial();
|
||||
}
|
||||
}
|
||||
|
||||
// _onTextureLoaded() {
|
||||
// if (!this.isValid) {
|
||||
// return;
|
||||
@@ -592,32 +628,6 @@ export class SpriteComponent extends UIRenderComponent {
|
||||
this._applyAtlas(spriteFrame);
|
||||
}
|
||||
}
|
||||
|
||||
_resized() {
|
||||
if (!CC_EDITOR) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this._spriteFrame) {
|
||||
const actualSize = this.node.getContentSize();
|
||||
let expectedW = actualSize.width;
|
||||
let expectedH = actualSize.height;
|
||||
if (this._sizeMode === SizeMode.RAW) {
|
||||
const size = this._spriteFrame.getOriginalSize();
|
||||
expectedW = size.width;
|
||||
expectedH = size.height;
|
||||
} else if (this._sizeMode === SizeMode.TRIMMED) {
|
||||
const rect = this._spriteFrame.getRect();
|
||||
expectedW = rect.width;
|
||||
expectedH = rect.height;
|
||||
|
||||
}
|
||||
|
||||
if (expectedW !== actualSize.width || expectedH !== actualSize.height) {
|
||||
this._sizeMode = SizeMode.CUSTOM;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cc.SpriteComponent = SpriteComponent;
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
import { Component } from '../../../components/component';
|
||||
import {
|
||||
ccclass,
|
||||
executeInEditMode,
|
||||
@@ -35,11 +36,11 @@ import { Color } from '../../../core/value-types/index';
|
||||
import { RenderData } from '../../../renderer/ui/renderData';
|
||||
import { UI } from '../../../renderer/ui/ui';
|
||||
import { EventType} from '../../../scene-graph/node-event-enum';
|
||||
import { IAssembler, IAssemblerManager } from '../assembler/assembler';
|
||||
import { CanvasComponent } from './canvas-component';
|
||||
import { Component } from '../../../components/component';
|
||||
import { Material } from '../../assets/material';
|
||||
import { RenderableComponent } from '../../framework/renderable-component';
|
||||
import { IAssembler, IAssemblerManager } from '../assembler/assembler';
|
||||
import { CanvasComponent } from './canvas-component';
|
||||
import { UITransformComponent } from './ui-transfrom-component';
|
||||
|
||||
/**
|
||||
* !#en
|
||||
@@ -52,7 +53,7 @@ import { RenderableComponent } from '../../framework/renderable-component';
|
||||
*/
|
||||
@ccclass('cc.UIRenderComponent')
|
||||
@executionOrder(100)
|
||||
@requireComponent(cc.UITransformComponent)
|
||||
@requireComponent(UITransformComponent)
|
||||
@executeInEditMode
|
||||
export class UIRenderComponent extends Component {
|
||||
|
||||
@@ -134,13 +135,13 @@ export class UIRenderComponent extends Component {
|
||||
* @property material
|
||||
*/
|
||||
@property({
|
||||
type: Material
|
||||
type: Material,
|
||||
})
|
||||
get sharedMaterial() {
|
||||
get sharedMaterial () {
|
||||
return this._sharedMaterial;
|
||||
}
|
||||
|
||||
set sharedMaterial(value) {
|
||||
set sharedMaterial (value) {
|
||||
if (this._sharedMaterial === value) {
|
||||
return;
|
||||
}
|
||||
@@ -161,11 +162,11 @@ export class UIRenderComponent extends Component {
|
||||
return this._renderData;
|
||||
}
|
||||
|
||||
get material() {
|
||||
get material () {
|
||||
return this._material;
|
||||
}
|
||||
|
||||
set material(value) {
|
||||
set material (value) {
|
||||
if (this._material === value) {
|
||||
return;
|
||||
}
|
||||
@@ -184,8 +185,6 @@ export class UIRenderComponent extends Component {
|
||||
@property
|
||||
protected _priority = 0;
|
||||
@property
|
||||
private _sharedMaterial: Material | null = null;
|
||||
@property
|
||||
protected _material: Material | null = null;
|
||||
|
||||
protected _assembler: IAssembler | null = null;
|
||||
@@ -193,6 +192,8 @@ export class UIRenderComponent extends Component {
|
||||
protected _renderDataPoolID = -1;
|
||||
protected _visibility = -1;
|
||||
protected _renderData: RenderData | null = null;
|
||||
@property
|
||||
private _sharedMaterial: Material | null = null;
|
||||
// _allocedDatas = [];
|
||||
// _vertexFormat = null;
|
||||
// _toPostHandle = false;
|
||||
@@ -203,7 +204,7 @@ export class UIRenderComponent extends Component {
|
||||
// this._postAssembler = this.constructor._postAssembler;
|
||||
}
|
||||
|
||||
public __preload(){
|
||||
public __preload (){
|
||||
this._instanceMaterial();
|
||||
}
|
||||
|
||||
@@ -251,10 +252,6 @@ export class UIRenderComponent extends Component {
|
||||
this._renderData = null;
|
||||
}
|
||||
|
||||
// _canRender() {
|
||||
// return this._enabled;
|
||||
// }
|
||||
|
||||
public markForUpdateRenderData (enable: boolean = true) {
|
||||
// if (enable && this._canRender()) {
|
||||
// this.node._renderFlag |= RenderFlow.FLAG_UPDATE_RENDER_DATA;
|
||||
@@ -272,7 +269,7 @@ export class UIRenderComponent extends Component {
|
||||
renderData.vertDirty = enable;
|
||||
for (const child of this.node.children) {
|
||||
const renderComp = child.getComponent(UIRenderComponent);
|
||||
if(renderComp){
|
||||
if (renderComp){
|
||||
renderComp.markForUpdateRenderData();
|
||||
}
|
||||
}
|
||||
@@ -329,13 +326,13 @@ export class UIRenderComponent extends Component {
|
||||
}
|
||||
|
||||
public updateAssembler (render: UI) {
|
||||
if (!this._assembler) {
|
||||
if (!this._canRender()) {
|
||||
return;
|
||||
}
|
||||
if (this._assembler.updateRenderData) {
|
||||
this._assembler.updateRenderData(this);
|
||||
if (this._assembler!.updateRenderData) {
|
||||
this._assembler!.updateRenderData!(this);
|
||||
}
|
||||
this._assembler.fillBuffers(this, render);
|
||||
this._assembler!.fillBuffers(this, render);
|
||||
}
|
||||
|
||||
public postUpdateAssembler () {
|
||||
@@ -347,6 +344,10 @@ export class UIRenderComponent extends Component {
|
||||
}
|
||||
}
|
||||
|
||||
protected _canRender () {
|
||||
return this._assembler !== null && this._material !== null;
|
||||
}
|
||||
|
||||
protected _updateColor () {
|
||||
const material = this.material;
|
||||
if (material) {
|
||||
@@ -378,7 +379,7 @@ export class UIRenderComponent extends Component {
|
||||
this.markForUpdateRenderData();
|
||||
}
|
||||
|
||||
private _instanceMaterial(){
|
||||
private _instanceMaterial (){
|
||||
if (this._sharedMaterial) {
|
||||
this._material = Material.getInstantiatedMaterial(this._sharedMaterial, new RenderableComponent(), CC_EDITOR ? true : false);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Component} from '../../../components/component';
|
||||
import { ccclass, executeInEditMode, executionOrder, menu, property } from '../../../core/data/class-decorator';
|
||||
import { Mat4, Vec3, Vec2, Size, Rect } from '../../../core/value-types';
|
||||
import { Mat4, Rect, Size, Vec2, Vec3 } from '../../../core/value-types';
|
||||
import * as math from '../../../core/vmath/index';
|
||||
import { EventType } from '../../../scene-graph/node-event-enum';
|
||||
import { MaskComponent } from './mask-component';
|
||||
@@ -51,7 +51,7 @@ export class UITransformComponent extends Component {
|
||||
}
|
||||
|
||||
set height (value) {
|
||||
if(this.contentSize.height === value){
|
||||
if (this.contentSize.height === value){
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -261,10 +261,10 @@ export class UITransformComponent extends Component {
|
||||
* @example
|
||||
* var newVec2 = node.convertToNodeSpace(cc.v3(100, 100));
|
||||
*/
|
||||
convertToNodeSpace(worldPoint: Vec3) {
|
||||
public convertToNodeSpace (worldPoint: Vec3) {
|
||||
this.node.getWorldMatrix(_worldMatrix);
|
||||
math.mat4.invert(_mat4_temp, _worldMatrix);
|
||||
let out = new Vec3();
|
||||
const out = new Vec3();
|
||||
math.vec3.transformMat4(out, worldPoint, _mat4_temp);
|
||||
out.x += this._anchorPoint.x * this._contentSize.width;
|
||||
out.y += this._anchorPoint.y * this._contentSize.height;
|
||||
@@ -282,12 +282,12 @@ export class UITransformComponent extends Component {
|
||||
* @example
|
||||
* var newVec3 = node.convertToWorldSpace(cc.v3(100, 100));
|
||||
*/
|
||||
convertToWorldSpace(nodePoint: Vec3) {
|
||||
public convertToWorldSpace (nodePoint: Vec3) {
|
||||
this.node.getWorldMatrix(_worldMatrix);
|
||||
let out = new Vec3(
|
||||
const out = new Vec3(
|
||||
nodePoint.x - this._anchorPoint.x * this._contentSize.width,
|
||||
nodePoint.y - this._anchorPoint.y * this._contentSize.height,
|
||||
0
|
||||
0,
|
||||
);
|
||||
return math.vec3.transformMat4(out, out, _worldMatrix);
|
||||
}
|
||||
@@ -303,7 +303,7 @@ export class UITransformComponent extends Component {
|
||||
* @example
|
||||
* var newVec2 = node.convertToNodeSpaceAR(cc.v2(100, 100));
|
||||
*/
|
||||
public convertToNodeSpaceAR(out: Vec3, worldPoint: Vec3) {
|
||||
public convertToNodeSpaceAR (out: Vec3, worldPoint: Vec3) {
|
||||
const matrix = new Mat4();
|
||||
this.node.getWorldMatrix(matrix);
|
||||
math.mat4.invert(_mat4_temp, matrix);
|
||||
@@ -325,7 +325,7 @@ export class UITransformComponent extends Component {
|
||||
* @example
|
||||
* var newVec2 = node.convertToWorldSpaceAR(cc.v2(100, 100));
|
||||
*/
|
||||
public convertToWorldSpaceAR(out: Vec3, nodePoint: Vec3) {
|
||||
public convertToWorldSpaceAR (out: Vec3, nodePoint: Vec3) {
|
||||
this.node.getWorldMatrix(_worldMatrix);
|
||||
if (!out) {
|
||||
out = new Vec3();
|
||||
@@ -344,11 +344,11 @@ export class UITransformComponent extends Component {
|
||||
* @example
|
||||
* var boundingBox = node.getBoundingBox();
|
||||
*/
|
||||
public getBoundingBox() {
|
||||
public getBoundingBox () {
|
||||
math.mat4.fromRTS(_matrix, this.node.getRotation(), this.node.getPosition(), this.node.getScale());
|
||||
let width = this._contentSize.width;
|
||||
let height = this._contentSize.height;
|
||||
let rect = new Rect(
|
||||
const width = this._contentSize.width;
|
||||
const height = this._contentSize.height;
|
||||
const rect = new Rect(
|
||||
-this._anchorPoint.x * width,
|
||||
-this._anchorPoint.y * height,
|
||||
width,
|
||||
@@ -368,7 +368,7 @@ export class UITransformComponent extends Component {
|
||||
* @example
|
||||
* var newRect = node.getBoundingBoxToWorld();
|
||||
*/
|
||||
public getBoundingBoxToWorld() {
|
||||
public getBoundingBoxToWorld () {
|
||||
if (this.node.parent) {
|
||||
this.node.parent.getWorldMatrix(_worldMatrix);
|
||||
return this.getBoundingBoxTo(_worldMatrix);
|
||||
@@ -377,11 +377,11 @@ export class UITransformComponent extends Component {
|
||||
}
|
||||
}
|
||||
|
||||
public getBoundingBoxTo(parentMat: Mat4) {
|
||||
public getBoundingBoxTo (parentMat: Mat4) {
|
||||
math.mat4.fromRTS(_matrix, this.node.getRotation(), this.node.getPosition(), this.node.getScale());
|
||||
let width = this._contentSize.width;
|
||||
let height = this._contentSize.height;
|
||||
let rect = new Rect(
|
||||
const width = this._contentSize.width;
|
||||
const height = this._contentSize.height;
|
||||
const rect = new Rect(
|
||||
-this._anchorPoint.x * width,
|
||||
-this._anchorPoint.y * height,
|
||||
width,
|
||||
@@ -390,18 +390,17 @@ export class UITransformComponent extends Component {
|
||||
math.mat4.mul(_worldMatrix, parentMat, _matrix);
|
||||
rect.transformMat4(rect, _worldMatrix);
|
||||
|
||||
//query child's BoundingBox
|
||||
// query child's BoundingBox
|
||||
if (!this.node.children) {
|
||||
return rect;
|
||||
}
|
||||
|
||||
var locChildren = this.node.children;
|
||||
for (var i = 0; i < locChildren.length; i++) {
|
||||
var child = locChildren[i];
|
||||
const locChildren = this.node.children;
|
||||
for (const child of locChildren) {
|
||||
if (child && child.active) {
|
||||
const uiTransform = child.getComponent(UITransformComponent);
|
||||
if (uiTransform) {
|
||||
var childRect = uiTransform.getBoundingBoxTo(parentMat);
|
||||
const childRect = uiTransform.getBoundingBoxTo(parentMat);
|
||||
if (childRect) {
|
||||
rect.union(rect, childRect);
|
||||
}
|
||||
|
||||
@@ -24,8 +24,8 @@
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
import { Asset } from './asset';
|
||||
import {ccclass} from '../core/data/class-decorator';
|
||||
import { Asset } from './asset';
|
||||
|
||||
/**
|
||||
* !#en Class for Font handling.
|
||||
@@ -34,7 +34,7 @@ import {ccclass} from '../core/data/class-decorator';
|
||||
* @extends Asset
|
||||
*/
|
||||
@ccclass('cc.Font')
|
||||
export default class Font extends Asset {
|
||||
export class Font extends Asset {
|
||||
}
|
||||
|
||||
cc.Font = Font;
|
||||
Reference in New Issue
Block a user