Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 24 additions & 20 deletions Extensions/BBText/JsExtension.js
Original file line number Diff line number Diff line change
Expand Up @@ -666,7 +666,9 @@ module.exports = {
this._pixiObject.dirty = true;
}

if (this._instance.hasCustomSize() && this._pixiObject.width !== 0) {
const renderedWidth = this._pixiObject.width;
const centerX = this.getCenterX();
if (this._instance.hasCustomSize() && renderedWidth !== 0) {
const alignmentX =
object.content.align === 'right'
? 1
Expand All @@ -675,28 +677,22 @@ module.exports = {
: 0;

const width = this.getCustomWidth();
const leftOffset = (width - renderedWidth) * alignmentX;

// A vector from the custom size center to the renderer center.
const centerToCenterX =
(width - this._pixiObject.width) * (alignmentX - 0.5);

this._pixiObject.position.x = this._instance.getX() + width / 2;
this._pixiObject.anchor.x =
0.5 - centerToCenterX / this._pixiObject.width;
this._pixiObject.position.x = this._instance.getX();
this._pixiObject.anchor.x = (centerX - leftOffset) / renderedWidth;
} else if (renderedWidth !== 0) {
this._pixiObject.position.x = this._instance.getX();
this._pixiObject.anchor.x = centerX / renderedWidth;
} else {
this._pixiObject.position.x =
this._instance.getX() + this._pixiObject.width / 2;
this._pixiObject.anchor.x = 0.5;
this._pixiObject.position.x = this._instance.getX();
this._pixiObject.anchor.x = 0;
}
const alignmentY =
object.content.verticalTextAlignment === 'bottom'
? 1
: object.content.verticalTextAlignment === 'center'
? 0.5
: 0;
this._pixiObject.position.y =
this._instance.getY() + this._pixiObject.height * (0.5 - alignmentY);
this._pixiObject.anchor.y = 0.5;
const renderedHeight = this._pixiObject.height;
const centerY = this.getCenterY();
this._pixiObject.position.y = this._instance.getY();
this._pixiObject.anchor.y =
renderedHeight !== 0 ? centerY / renderedHeight : 0;

this._pixiObject.rotation = RenderedInstance.toRad(
this._instance.getAngle()
Expand Down Expand Up @@ -736,6 +732,14 @@ module.exports = {
? height / 2
: 0;
}

getCenterX() {
return 0;
}

getCenterY() {
return this.getOriginY();
}
}

objectsRenderingService.registerInstanceRenderer(
Expand Down
37 changes: 17 additions & 20 deletions Extensions/BBText/bbtextruntimeobject-pixi-renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,10 @@ namespace gdjs {
}

updatePosition(): void {
if (this._object.isWrapping() && this._pixiObject.width !== 0) {
const renderedWidth = this._pixiObject.width;
const centerX = this._object.getCenterX();

if (this._object.isWrapping() && renderedWidth !== 0) {
const alignmentX =
this._object._textAlign === 'right'
? 1
Expand All @@ -134,29 +137,23 @@ namespace gdjs {
: 0;

const width = this._object.getWrappingWidth();
const leftOffset = (width - renderedWidth) * alignmentX;

// A vector from the custom size center to the renderer center.
const centerToCenterX =
(width - this._pixiObject.width) * (alignmentX - 0.5);

this._pixiObject.position.x = this._object.x + width / 2;
this._pixiObject.anchor.x =
0.5 - centerToCenterX / this._pixiObject.width;
this._pixiObject.position.x = this._object.getDrawableX() + centerX;
this._pixiObject.anchor.x = (centerX - leftOffset) / renderedWidth;
} else if (renderedWidth !== 0) {
this._pixiObject.position.x = this._object.getDrawableX() + centerX;
this._pixiObject.anchor.x = centerX / renderedWidth;
} else {
this._pixiObject.position.x =
this._object.x + this._pixiObject.width / 2;
this._pixiObject.anchor.x = 0.5;
this._pixiObject.position.x = this._object.getDrawableX() + centerX;
this._pixiObject.anchor.x = 0;
}

const alignmentY =
this._object._verticalTextAlignment === 'bottom'
? 1
: this._object._verticalTextAlignment === 'center'
? 0.5
: 0;
this._pixiObject.position.y =
this._object.y + this._pixiObject.height * (0.5 - alignmentY);
this._pixiObject.anchor.y = 0.5;
const renderedHeight = this._pixiObject.height;
const centerY = this._object.getCenterY();
this._pixiObject.position.y = this._object.getDrawableY() + centerY;
this._pixiObject.anchor.y =
renderedHeight !== 0 ? centerY / renderedHeight : 0;
}

updateAngle(): void {
Expand Down
12 changes: 12 additions & 0 deletions Extensions/BBText/bbtextruntimeobject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,18 @@ namespace gdjs {
this.setWrappingWidth(width);
}

override getCenterX(): float {
return 0;
}

override getCenterY(): float {
return this._verticalTextAlignment === 'bottom'
? this.getHeight()
: this._verticalTextAlignment === 'center'
? this.getHeight() / 2
: 0;
}

override getDrawableY(): float {
return (
this.getY() -
Expand Down
43 changes: 24 additions & 19 deletions Extensions/BitmapText/JsExtension.js
Original file line number Diff line number Diff line change
Expand Up @@ -789,7 +789,9 @@ module.exports = {
this._pixiObject.dirty = true;
}

if (this._instance.hasCustomSize() && this.getDefaultWidth() !== 0) {
const renderedWidth = this.getDefaultWidth();
const centerX = this.getCenterX();
if (this._instance.hasCustomSize() && renderedWidth !== 0) {
const alignmentX =
object.content.align === 'right'
? 1
Expand All @@ -798,27 +800,22 @@ module.exports = {
: 0;

const width = this.getCustomWidth();
const renderedWidth = this.getDefaultWidth();
const leftOffset = (width - renderedWidth) * alignmentX;

// A vector from the custom size center to the renderer center.
const centerToCenterX = (width - renderedWidth) * (alignmentX - 0.5);

this._pixiObject.position.x = this._instance.getX() + width / 2;
this._pixiObject.anchor.x = 0.5 - centerToCenterX / renderedWidth;
this._pixiObject.position.x = this._instance.getX();
this._pixiObject.anchor.x = (centerX - leftOffset) / renderedWidth;
} else if (renderedWidth !== 0) {
this._pixiObject.position.x = this._instance.getX();
this._pixiObject.anchor.x = centerX / renderedWidth;
} else {
this._pixiObject.position.x =
this._instance.getX() + this.getDefaultWidth() / 2;
this._pixiObject.anchor.x = 0.5;
this._pixiObject.position.x = this._instance.getX();
this._pixiObject.anchor.x = 0;
}
const alignmentY =
object.content.verticalTextAlignment === 'bottom'
? 1
: object.content.verticalTextAlignment === 'center'
? 0.5
: 0;
this._pixiObject.position.y =
this._instance.getY() + this.getDefaultHeight() * (0.5 - alignmentY);
this._pixiObject.anchor.y = 0.5;
const renderedHeight = this.getDefaultHeight();
const centerY = this.getCenterY();
this._pixiObject.position.y = this._instance.getY();
this._pixiObject.anchor.y =
renderedHeight !== 0 ? centerY / renderedHeight : 0;

this._pixiObject.rotation = RenderedInstance.toRad(
this._instance.getAngle()
Expand Down Expand Up @@ -867,6 +864,14 @@ module.exports = {
? height / 2
: 0;
}

getCenterX() {
return 0;
}

getCenterY() {
return this.getOriginY();
}
}

objectsRenderingService.registerInstanceRenderer(
Expand Down
35 changes: 17 additions & 18 deletions Extensions/BitmapText/bitmaptextruntimeobject-pixi-renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,10 @@ namespace gdjs {
}

updatePosition(): void {
if (this._object.isWrapping() && this.getWidth() !== 0) {
const renderedWidth = this.getWidth();
const centerX = this._object.getCenterX();

if (this._object.isWrapping() && renderedWidth !== 0) {
const alignmentX =
this._object._textAlign === 'right'
? 1
Expand All @@ -165,27 +168,23 @@ namespace gdjs {
: 0;

const width = this._object.getWrappingWidth();
const renderedWidth = this.getWidth();

// A vector from the custom size center to the renderer center.
const centerToCenterX = (width - renderedWidth) * (alignmentX - 0.5);
const leftOffset = (width - renderedWidth) * alignmentX;

this._pixiObject.position.x = this._object.x + width / 2;
this._pixiObject.anchor.x = 0.5 - centerToCenterX / renderedWidth;
this._pixiObject.position.x = this._object.getDrawableX() + centerX;
this._pixiObject.anchor.x = (centerX - leftOffset) / renderedWidth;
} else if (renderedWidth !== 0) {
this._pixiObject.position.x = this._object.getDrawableX() + centerX;
this._pixiObject.anchor.x = centerX / renderedWidth;
} else {
this._pixiObject.position.x = this._object.x + this.getWidth() / 2;
this._pixiObject.anchor.x = 0.5;
this._pixiObject.position.x = this._object.getDrawableX() + centerX;
this._pixiObject.anchor.x = 0;
}

const alignmentY =
this._object._verticalTextAlignment === 'bottom'
? 1
: this._object._verticalTextAlignment === 'center'
? 0.5
: 0;
this._pixiObject.position.y =
this._object.y + this.getHeight() * (0.5 - alignmentY);
this._pixiObject.anchor.y = 0.5;
const renderedHeight = this.getHeight();
const centerY = this._object.getCenterY();
this._pixiObject.position.y = this._object.getDrawableY() + centerY;
this._pixiObject.anchor.y =
renderedHeight !== 0 ? centerY / renderedHeight : 0;
}

updateAngle(): void {
Expand Down
12 changes: 12 additions & 0 deletions Extensions/BitmapText/bitmaptextruntimeobject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,18 @@ namespace gdjs {
this.setWrappingWidth(width);
}

override getCenterX(): float {
return 0;
}

override getCenterY(): float {
return this._verticalTextAlignment === 'bottom'
? this.getHeight()
: this._verticalTextAlignment === 'center'
? this.getHeight() / 2
: 0;
}

override getDrawableY(): float {
return (
this.getY() -
Expand Down
33 changes: 16 additions & 17 deletions Extensions/TextObject/textruntimeobject-pixi-renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,10 @@ namespace gdjs {
}

updatePosition(): void {
if (this._object.isWrapping() && this._text.width !== 0) {
const renderedWidth = this._text.width;
const centerX = this._object.getCenterX();

if (this._object.isWrapping() && renderedWidth !== 0) {
const alignmentX =
this._object._textAlign === 'right'
? 1
Expand All @@ -108,26 +111,22 @@ namespace gdjs {
: 0;

const width = this._object.getWrappingWidth();
const leftOffset = (width - renderedWidth) * alignmentX;

// A vector from the custom size center to the renderer center.
const centerToCenterX = (width - this._text.width) * (alignmentX - 0.5);

this._text.position.x = this._object.x + width / 2;
this._text.anchor.x = 0.5 - centerToCenterX / this._text.width;
this._text.position.x = this._object.getDrawableX() + centerX;
this._text.anchor.x = (centerX - leftOffset) / renderedWidth;
} else if (renderedWidth !== 0) {
this._text.position.x = this._object.getDrawableX() + centerX;
this._text.anchor.x = centerX / renderedWidth;
} else {
this._text.position.x = this._object.x + this._text.width / 2;
this._text.anchor.x = 0.5;
this._text.position.x = this._object.getDrawableX() + centerX;
this._text.anchor.x = 0;
}

const alignmentY =
this._object._verticalTextAlignment === 'bottom'
? 1
: this._object._verticalTextAlignment === 'center'
? 0.5
: 0;
this._text.position.y =
this._object.y + this._text.height * (0.5 - alignmentY);
this._text.anchor.y = 0.5;
const renderedHeight = this._text.height;
const centerY = this._object.getCenterY();
this._text.position.y = this._object.getDrawableY() + centerY;
this._text.anchor.y = renderedHeight !== 0 ? centerY / renderedHeight : 0;
}

updateAngle(): void {
Expand Down
12 changes: 12 additions & 0 deletions Extensions/TextObject/textruntimeobject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -725,6 +725,18 @@ namespace gdjs {
this.setWrappingWidth(width);
}

override getCenterX(): float {
return 0;
}

override getCenterY(): float {
return this._verticalTextAlignment === 'bottom'
? this.getHeight()
: this._verticalTextAlignment === 'center'
? this.getHeight() / 2
: 0;
}

override getDrawableY(): float {
return (
this.getY() -
Expand Down
Loading