Skip to content

Commit 899bc7b

Browse files
committed
Added support for F/BG colors for text node
1 parent ff5b0bd commit 899bc7b

File tree

4 files changed

+39
-8
lines changed

4 files changed

+39
-8
lines changed

addons/material_maker/engine/nodes/gen_text.gd

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ func get_parameter_defs() -> Array:
2727
return [
2828
{ name="text", label="Text", type="string", default="Text" },
2929
{ name="font", label="Font", type="file", filters=[ "*.otf,*.ttf,*.fnt;Font file" ], default="" },
30+
{ name="fg", label="Foreground", type="color", default={ r=1.0, g=0.0, b=1.0, a=1.0} },
31+
{ name="bg", label="Background", type="color", default={ r=0.0, g=0.0, b=0.0, a=1.0} },
3032
{ name="font_size", label="Font size", type="float", min=0, max=128, step=1, default=32 },
3133
{ name="center", label="Center", type="boolean", default=false },
3234
{ name="x", label="X", type="float", min=-0.5, max=0.5, step=0.001, default=0.1, control="P1.x" },
@@ -63,7 +65,16 @@ func update_buffer() -> void:
6365
var renderer = await mm_renderer.request(self)
6466
while update_again:
6567
update_again = false
66-
renderer = await renderer.render_text(self, get_parameter("text"), get_parameter("font"), int(calculate_float_param("font_size", 64)), calculate_float_param("x"), calculate_float_param("y"), get_parameter("center"))
68+
renderer = await renderer.render_text(
69+
self,
70+
get_parameter("text"),
71+
get_parameter("font"),
72+
int(calculate_float_param("font_size", 64)),
73+
calculate_float_param("x"),
74+
calculate_float_param("y"),
75+
get_parameter("fg"),
76+
get_parameter("bg"),
77+
get_parameter("center"))
6778
var image_texture : ImageTexture = ImageTexture.new()
6879
renderer.copy_to_texture(image_texture)
6980
renderer.release(self)

addons/material_maker/engine/renderer.gd

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,16 @@ func request(object : Object) -> Object:
1616
return self
1717

1818
var current_font : String = ""
19-
func render_text(object : Object, text : String, font_path : String, font_size : int, x : float, y : float, center : bool = false) -> Object:
19+
func render_text(object : Object, text : String, font_path : String, font_size : int, x : float, y : float, fg : Color, bg : Color, center : bool = false) -> Object:
2020
assert(render_owner == object)
2121
size = Vector2(2048, 2048)
2222
$Font.visible = true
2323
$Font.position = Vector2(0, 0)
2424
$Font.size = size
2525
$Font/Label.text = text
2626
$Font/Label.position = Vector2(2048*(0.5+x), 2048*(0.5+y))
27+
$Font/Label.modulate = fg
28+
$Font.color = bg
2729
var font : Font = FontFile.new()
2830
if font.load_dynamic_font(font_path) == OK:
2931
pass

material_maker/doc/node_simple_text.rst

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,21 @@ Parameters
2121

2222
The text node accepts the following parameters:
2323

24-
* the string to be displayed
24+
* String to be displayed
2525

26-
* the font (both TTF and OTF formats are supported)
26+
* Font (both TTF and OTF formats are supported)
2727

28-
* the font size
28+
* Font size
2929

30-
* whether the text is centered
30+
* X and Y coordinates of the location of the text in the generated image
3131

32-
* the X and Y coordinates of the location of the text in the generated image
32+
* Text color
33+
34+
* Background color
35+
36+
* Whether the text is centered
3337

3438
Notes
3539
+++++
3640

37-
The text node can render any unicode character, including emojis.
41+
The text node can render any unicode character, including emojis.

material_maker/library/base.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,20 @@
115115
"parameters": {
116116
"font": "",
117117
"font_size": 64.0,
118+
"fg": {
119+
"r": 1.0,
120+
"g": 1.0,
121+
"b": 1.0,
122+
"a": 1.0,
123+
"type": "Color"
124+
},
125+
"bg": {
126+
"r": 0.0,
127+
"g": 0.0,
128+
"b": 0.0,
129+
"a": 1.0,
130+
"type": "Color"
131+
},
118132
"text": "Text",
119133
"x": -0.4,
120134
"y": -0.4

0 commit comments

Comments
 (0)