mirror of
https://github.com/4ian/GDevelop.git
synced 2025-10-15 10:19:04 +00:00
Compare commits
5 Commits
shape-pain
...
add-line-h
Author | SHA1 | Date | |
---|---|---|---|
![]() |
3ef2e4167e | ||
![]() |
71ea1995dd | ||
![]() |
d7248cb48e | ||
![]() |
a08441eb9f | ||
![]() |
8014a59ea3 |
@@ -449,6 +449,16 @@ void DeclareTextObjectExtension(gd::PlatformExtension& extension) {
|
|||||||
.AddParameter("object", _("Object"), "Text")
|
.AddParameter("object", _("Object"), "Text")
|
||||||
.UseStandardParameters("number", gd::ParameterOptions::MakeNewOptions());
|
.UseStandardParameters("number", gd::ParameterOptions::MakeNewOptions());
|
||||||
|
|
||||||
|
obj.AddExpressionAndConditionAndAction("number",
|
||||||
|
"LineHeight",
|
||||||
|
_("Line height"),
|
||||||
|
_("the line height of a text object"),
|
||||||
|
_("the line height"),
|
||||||
|
"",
|
||||||
|
"res/actions/font24.png")
|
||||||
|
.AddParameter("object", _("Object"), "Text")
|
||||||
|
.UseStandardParameters("number", gd::ParameterOptions::MakeNewOptions());
|
||||||
|
|
||||||
// Support for deprecated "Size" actions/conditions:
|
// Support for deprecated "Size" actions/conditions:
|
||||||
obj.AddDuplicatedAction("Size", "Text::SetFontSize").SetHidden();
|
obj.AddDuplicatedAction("Size", "Text::SetFontSize").SetHidden();
|
||||||
obj.AddDuplicatedCondition("Size", "Text::FontSize").SetHidden();
|
obj.AddDuplicatedCondition("Size", "Text::FontSize").SetHidden();
|
||||||
|
@@ -96,6 +96,14 @@ class TextObjectJsExtension : public gd::PlatformExtension {
|
|||||||
.SetFunctionName("setOutlineThickness")
|
.SetFunctionName("setOutlineThickness")
|
||||||
.SetGetter("getOutlineThickness");
|
.SetGetter("getOutlineThickness");
|
||||||
|
|
||||||
|
GetAllExpressionsForObject("TextObject::Text")["LineHeight"]
|
||||||
|
.SetFunctionName("getLineHeight");
|
||||||
|
GetAllConditionsForObject("TextObject::Text")["TextObject::Text::LineHeight"]
|
||||||
|
.SetFunctionName("getLineHeight");
|
||||||
|
GetAllActionsForObject("TextObject::Text")["TextObject::Text::SetLineHeight"]
|
||||||
|
.SetFunctionName("setLineHeight")
|
||||||
|
.SetGetter("getLineHeight");
|
||||||
|
|
||||||
GetAllActionsForObject("TextObject::Text")["TextObject::ShowShadow"]
|
GetAllActionsForObject("TextObject::Text")["TextObject::ShowShadow"]
|
||||||
.SetFunctionName("showShadow");
|
.SetFunctionName("showShadow");
|
||||||
GetAllConditionsForObject("TextObject::Text")["TextObject::Text::IsShadowEnabled"]
|
GetAllConditionsForObject("TextObject::Text")["TextObject::Text::IsShadowEnabled"]
|
||||||
|
@@ -20,6 +20,7 @@ using namespace std;
|
|||||||
TextObject::TextObject()
|
TextObject::TextObject()
|
||||||
: text("Text"),
|
: text("Text"),
|
||||||
characterSize(20),
|
characterSize(20),
|
||||||
|
lineHeight(0),
|
||||||
fontName(""),
|
fontName(""),
|
||||||
smoothed(true),
|
smoothed(true),
|
||||||
bold(false),
|
bold(false),
|
||||||
@@ -50,6 +51,10 @@ bool TextObject::UpdateProperty(const gd::String& propertyName,
|
|||||||
characterSize = newValue.To<double>();
|
characterSize = newValue.To<double>();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
if (propertyName == "lineHeight") {
|
||||||
|
lineHeight = newValue.To<double>();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
if (propertyName == "font") {
|
if (propertyName == "font") {
|
||||||
fontName = newValue;
|
fontName = newValue;
|
||||||
return true;
|
return true;
|
||||||
@@ -129,6 +134,13 @@ std::map<gd::String, gd::PropertyDescriptor> TextObject::GetProperties() const {
|
|||||||
.SetMeasurementUnit(gd::MeasurementUnit::GetPixel())
|
.SetMeasurementUnit(gd::MeasurementUnit::GetPixel())
|
||||||
.SetGroup(_("Font"));
|
.SetGroup(_("Font"));
|
||||||
|
|
||||||
|
objectProperties["lineHeight"]
|
||||||
|
.SetValue(gd::String::From(lineHeight))
|
||||||
|
.SetType("number")
|
||||||
|
.SetLabel(_("Line height"))
|
||||||
|
.SetMeasurementUnit(gd::MeasurementUnit::GetPixel())
|
||||||
|
.SetGroup(_("Font"));
|
||||||
|
|
||||||
objectProperties["font"]
|
objectProperties["font"]
|
||||||
.SetValue(fontName)
|
.SetValue(fontName)
|
||||||
.SetType("resource")
|
.SetType("resource")
|
||||||
@@ -271,6 +283,7 @@ void TextObject::DoUnserializeFrom(gd::Project& project,
|
|||||||
SetCharacterSize(content.GetChild("characterSize", 0, "CharacterSize")
|
SetCharacterSize(content.GetChild("characterSize", 0, "CharacterSize")
|
||||||
.GetValue()
|
.GetValue()
|
||||||
.GetInt());
|
.GetInt());
|
||||||
|
SetLineHeight(content.GetDoubleAttribute("lineHeight", 0));
|
||||||
smoothed = content.GetBoolAttribute("smoothed");
|
smoothed = content.GetBoolAttribute("smoothed");
|
||||||
bold = content.GetBoolAttribute("bold");
|
bold = content.GetBoolAttribute("bold");
|
||||||
italic = content.GetBoolAttribute("italic");
|
italic = content.GetBoolAttribute("italic");
|
||||||
@@ -339,6 +352,7 @@ void TextObject::DoSerializeTo(gd::SerializerElement& element) const {
|
|||||||
content.AddChild("textAlignment").SetValue(GetTextAlignment());
|
content.AddChild("textAlignment").SetValue(GetTextAlignment());
|
||||||
content.AddChild("verticalTextAlignment").SetValue(GetVerticalTextAlignment());
|
content.AddChild("verticalTextAlignment").SetValue(GetVerticalTextAlignment());
|
||||||
content.AddChild("characterSize").SetValue(GetCharacterSize());
|
content.AddChild("characterSize").SetValue(GetCharacterSize());
|
||||||
|
content.AddChild("lineHeight").SetValue(GetLineHeight());
|
||||||
content.AddChild("color").SetValue(GetColor());
|
content.AddChild("color").SetValue(GetColor());
|
||||||
|
|
||||||
content.SetAttribute("smoothed", smoothed);
|
content.SetAttribute("smoothed", smoothed);
|
||||||
|
@@ -49,6 +49,12 @@ class GD_EXTENSION_API TextObject : public gd::ObjectConfiguration {
|
|||||||
*/
|
*/
|
||||||
inline double GetCharacterSize() const { return characterSize; };
|
inline double GetCharacterSize() const { return characterSize; };
|
||||||
|
|
||||||
|
/** \brief Change the line height. */
|
||||||
|
inline void SetLineHeight(double value) { lineHeight = value; };
|
||||||
|
|
||||||
|
/** \brief Get the line height. */
|
||||||
|
inline double GetLineHeight() const { return lineHeight; };
|
||||||
|
|
||||||
/** \brief Return the name of the font resource used for the text.
|
/** \brief Return the name of the font resource used for the text.
|
||||||
*/
|
*/
|
||||||
inline const gd::String& GetFontName() const { return fontName; };
|
inline const gd::String& GetFontName() const { return fontName; };
|
||||||
@@ -120,6 +126,7 @@ class GD_EXTENSION_API TextObject : public gd::ObjectConfiguration {
|
|||||||
|
|
||||||
gd::String text;
|
gd::String text;
|
||||||
double characterSize;
|
double characterSize;
|
||||||
|
double lineHeight;
|
||||||
gd::String fontName;
|
gd::String fontName;
|
||||||
bool smoothed;
|
bool smoothed;
|
||||||
bool bold, italic, underlined;
|
bool bold, italic, underlined;
|
||||||
|
@@ -86,6 +86,7 @@ namespace gdjs {
|
|||||||
? style.dropShadowDistance + style.dropShadowBlur
|
? style.dropShadowDistance + style.dropShadowBlur
|
||||||
: 0;
|
: 0;
|
||||||
style.padding = Math.ceil(this._object._padding + extraPaddingForShadow);
|
style.padding = Math.ceil(this._object._padding + extraPaddingForShadow);
|
||||||
|
style.lineHeight = this._object._lineHeight;
|
||||||
|
|
||||||
// Prevent spikey outlines by adding a miter limit
|
// Prevent spikey outlines by adding a miter limit
|
||||||
style.miterLimit = 3;
|
style.miterLimit = 3;
|
||||||
|
@@ -22,6 +22,8 @@ namespace gdjs {
|
|||||||
text: string;
|
text: string;
|
||||||
textAlignment: string;
|
textAlignment: string;
|
||||||
verticalTextAlignment: string;
|
verticalTextAlignment: string;
|
||||||
|
/** The line height */
|
||||||
|
lineHeight: float;
|
||||||
|
|
||||||
isOutlineEnabled: boolean;
|
isOutlineEnabled: boolean;
|
||||||
outlineThickness: float;
|
outlineThickness: float;
|
||||||
@@ -62,6 +64,7 @@ namespace gdjs {
|
|||||||
sha: float;
|
sha: float;
|
||||||
shb: float;
|
shb: float;
|
||||||
pad: integer;
|
pad: integer;
|
||||||
|
lh: float;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type TextObjectNetworkSyncData = ObjectNetworkSyncData &
|
export type TextObjectNetworkSyncData = ObjectNetworkSyncData &
|
||||||
@@ -101,6 +104,8 @@ namespace gdjs {
|
|||||||
_shadowAngle: float;
|
_shadowAngle: float;
|
||||||
_shadowBlur: float;
|
_shadowBlur: float;
|
||||||
|
|
||||||
|
_lineHeight: float;
|
||||||
|
|
||||||
_padding: integer = 5;
|
_padding: integer = 5;
|
||||||
_str: string;
|
_str: string;
|
||||||
_renderer: gdjs.TextRuntimeObjectRenderer;
|
_renderer: gdjs.TextRuntimeObjectRenderer;
|
||||||
@@ -139,6 +144,7 @@ namespace gdjs {
|
|||||||
this._shadowDistance = content.shadowDistance;
|
this._shadowDistance = content.shadowDistance;
|
||||||
this._shadowBlur = content.shadowBlurRadius;
|
this._shadowBlur = content.shadowBlurRadius;
|
||||||
this._shadowAngle = content.shadowAngle;
|
this._shadowAngle = content.shadowAngle;
|
||||||
|
this._lineHeight = content.lineHeight || 0;
|
||||||
|
|
||||||
this._renderer = new gdjs.TextRuntimeObjectRenderer(
|
this._renderer = new gdjs.TextRuntimeObjectRenderer(
|
||||||
this,
|
this,
|
||||||
@@ -211,6 +217,9 @@ namespace gdjs {
|
|||||||
if (oldContent.shadowBlurRadius !== newContent.shadowBlurRadius) {
|
if (oldContent.shadowBlurRadius !== newContent.shadowBlurRadius) {
|
||||||
this.setShadowBlurRadius(newContent.shadowBlurRadius);
|
this.setShadowBlurRadius(newContent.shadowBlurRadius);
|
||||||
}
|
}
|
||||||
|
if ((oldContent.lineHeight || 0) !== (newContent.lineHeight || 0)) {
|
||||||
|
this.setLineHeight(newContent.lineHeight || 0);
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -238,6 +247,7 @@ namespace gdjs {
|
|||||||
shd: this._shadowDistance,
|
shd: this._shadowDistance,
|
||||||
sha: this._shadowAngle,
|
sha: this._shadowAngle,
|
||||||
shb: this._shadowBlur,
|
shb: this._shadowBlur,
|
||||||
|
lh: this._lineHeight,
|
||||||
pad: this._padding,
|
pad: this._padding,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -312,6 +322,9 @@ namespace gdjs {
|
|||||||
if (networkSyncData.shb !== undefined) {
|
if (networkSyncData.shb !== undefined) {
|
||||||
this.setShadowBlurRadius(networkSyncData.shb);
|
this.setShadowBlurRadius(networkSyncData.shb);
|
||||||
}
|
}
|
||||||
|
if (networkSyncData.lh !== undefined) {
|
||||||
|
this.setLineHeight(networkSyncData.lh);
|
||||||
|
}
|
||||||
if (networkSyncData.pad !== undefined) {
|
if (networkSyncData.pad !== undefined) {
|
||||||
this.setPadding(networkSyncData.pad);
|
this.setPadding(networkSyncData.pad);
|
||||||
}
|
}
|
||||||
@@ -444,6 +457,22 @@ namespace gdjs {
|
|||||||
this._renderer.updateStyle();
|
this._renderer.updateStyle();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the line height of the text.
|
||||||
|
*/
|
||||||
|
getLineHeight(): float {
|
||||||
|
return this._lineHeight;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the line height of the text.
|
||||||
|
* @param value The new line height for the text.
|
||||||
|
*/
|
||||||
|
setLineHeight(value: float): void {
|
||||||
|
this._lineHeight = value;
|
||||||
|
this._renderer.updateStyle();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the name of the resource to use for the font.
|
* Set the name of the resource to use for the font.
|
||||||
* @param fontResourceName The name of the font resource.
|
* @param fontResourceName The name of the font resource.
|
||||||
|
@@ -3728,6 +3728,8 @@ interface TextObject {
|
|||||||
[Const, Ref] DOMString GetText();
|
[Const, Ref] DOMString GetText();
|
||||||
void SetCharacterSize(double size);
|
void SetCharacterSize(double size);
|
||||||
double GetCharacterSize();
|
double GetCharacterSize();
|
||||||
|
void SetLineHeight(double value);
|
||||||
|
double GetLineHeight();
|
||||||
void SetFontName([Const] DOMString string);
|
void SetFontName([Const] DOMString string);
|
||||||
[Const, Ref] DOMString GetFontName();
|
[Const, Ref] DOMString GetFontName();
|
||||||
boolean IsBold();
|
boolean IsBold();
|
||||||
|
2
GDevelop.js/types.d.ts
vendored
2
GDevelop.js/types.d.ts
vendored
@@ -2758,6 +2758,8 @@ export class TextObject extends ObjectConfiguration {
|
|||||||
getText(): string;
|
getText(): string;
|
||||||
setCharacterSize(size: number): void;
|
setCharacterSize(size: number): void;
|
||||||
getCharacterSize(): number;
|
getCharacterSize(): number;
|
||||||
|
setLineHeight(value: number): void;
|
||||||
|
getLineHeight(): number;
|
||||||
setFontName(string: string): void;
|
setFontName(string: string): void;
|
||||||
getFontName(): string;
|
getFontName(): string;
|
||||||
isBold(): boolean;
|
isBold(): boolean;
|
||||||
|
@@ -5,6 +5,8 @@ declare class gdTextObject extends gdObjectConfiguration {
|
|||||||
getText(): string;
|
getText(): string;
|
||||||
setCharacterSize(size: number): void;
|
setCharacterSize(size: number): void;
|
||||||
getCharacterSize(): number;
|
getCharacterSize(): number;
|
||||||
|
setLineHeight(value: number): void;
|
||||||
|
getLineHeight(): number;
|
||||||
setFontName(string: string): void;
|
setFontName(string: string): void;
|
||||||
getFontName(): string;
|
getFontName(): string;
|
||||||
isBold(): boolean;
|
isBold(): boolean;
|
||||||
|
@@ -371,6 +371,21 @@ export default class TextEditor extends React.Component<EditorProps, void> {
|
|||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</Column>
|
</Column>
|
||||||
|
<Text size="block-title" noMargin>
|
||||||
|
<Trans>Multiline</Trans>
|
||||||
|
</Text>
|
||||||
|
<Line noMargin>
|
||||||
|
<SemiControlledTextField
|
||||||
|
floatingLabelText={<Trans>Line height</Trans>}
|
||||||
|
type="number"
|
||||||
|
fullWidth
|
||||||
|
value={textObjectConfiguration.getLineHeight()}
|
||||||
|
onChange={value => {
|
||||||
|
textObjectConfiguration.setLineHeight(parseFloat(value) || 0);
|
||||||
|
this.forceUpdate();
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</Line>
|
||||||
</ColumnStackLayout>
|
</ColumnStackLayout>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@@ -32,6 +32,7 @@ export default class RenderedTextInstance extends RenderedInstance {
|
|||||||
_shadowColor = '0;0;0';
|
_shadowColor = '0;0;0';
|
||||||
_shadowOpacity = 127;
|
_shadowOpacity = 127;
|
||||||
_shadowBlurRadius = 2;
|
_shadowBlurRadius = 2;
|
||||||
|
_lineHeight = 0;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
project: gdProject,
|
project: gdProject,
|
||||||
@@ -97,6 +98,7 @@ export default class RenderedTextInstance extends RenderedInstance {
|
|||||||
textObjectConfiguration.isItalic() !== this._isItalic ||
|
textObjectConfiguration.isItalic() !== this._isItalic ||
|
||||||
textObjectConfiguration.isBold() !== this._isBold ||
|
textObjectConfiguration.isBold() !== this._isBold ||
|
||||||
textObjectConfiguration.getCharacterSize() !== this._characterSize ||
|
textObjectConfiguration.getCharacterSize() !== this._characterSize ||
|
||||||
|
textObjectConfiguration.getLineHeight() !== this._lineHeight ||
|
||||||
textObjectConfiguration.getTextAlignment() !== this._textAlignment ||
|
textObjectConfiguration.getTextAlignment() !== this._textAlignment ||
|
||||||
textObjectConfiguration.getVerticalTextAlignment() !==
|
textObjectConfiguration.getVerticalTextAlignment() !==
|
||||||
this._verticalTextAlignment ||
|
this._verticalTextAlignment ||
|
||||||
@@ -118,6 +120,7 @@ export default class RenderedTextInstance extends RenderedInstance {
|
|||||||
this._isItalic = textObjectConfiguration.isItalic();
|
this._isItalic = textObjectConfiguration.isItalic();
|
||||||
this._isBold = textObjectConfiguration.isBold();
|
this._isBold = textObjectConfiguration.isBold();
|
||||||
this._characterSize = textObjectConfiguration.getCharacterSize();
|
this._characterSize = textObjectConfiguration.getCharacterSize();
|
||||||
|
this._lineHeight = textObjectConfiguration.getLineHeight();
|
||||||
this._textAlignment = textObjectConfiguration.getTextAlignment();
|
this._textAlignment = textObjectConfiguration.getTextAlignment();
|
||||||
this._verticalTextAlignment = textObjectConfiguration.getVerticalTextAlignment();
|
this._verticalTextAlignment = textObjectConfiguration.getVerticalTextAlignment();
|
||||||
this._color = textObjectConfiguration.getColor();
|
this._color = textObjectConfiguration.getColor();
|
||||||
@@ -167,6 +170,7 @@ export default class RenderedTextInstance extends RenderedInstance {
|
|||||||
style.fontSize = Math.max(1, this._characterSize);
|
style.fontSize = Math.max(1, this._characterSize);
|
||||||
style.fontStyle = this._isItalic ? 'italic' : 'normal';
|
style.fontStyle = this._isItalic ? 'italic' : 'normal';
|
||||||
style.fontWeight = this._isBold ? 'bold' : 'normal';
|
style.fontWeight = this._isBold ? 'bold' : 'normal';
|
||||||
|
style.lineHeight = this._lineHeight !== 0 ? this._lineHeight : undefined;
|
||||||
style.fill = rgbStringToHexNumber(this._color);
|
style.fill = rgbStringToHexNumber(this._color);
|
||||||
style.wordWrap = this._wrapping;
|
style.wordWrap = this._wrapping;
|
||||||
style.wordWrapWidth = this._wrappingWidth <= 1 ? 1 : this._wrappingWidth;
|
style.wordWrapWidth = this._wrappingWidth <= 1 ? 1 : this._wrappingWidth;
|
||||||
|
Reference in New Issue
Block a user