Skip to content

Commit 58cc001

Browse files
committed
Added interface fonts options
1 parent b4fcad0 commit 58cc001

37 files changed

Lines changed: 607 additions & 171 deletions

material_maker/globals.gd

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ const DEFAULT_CONFIG : Dictionary = {
6060
dialog_dim_background = true,
6161
node_minimize_button = false,
6262
node_close_button = false,
63+
ui_use_system_font = false,
64+
ui_font_size = 16,
65+
ui_code_font_size = 12,
66+
ui_font_enable_msdf = true
6367
}
6468

6569

@@ -228,3 +232,6 @@ func get_node_title_from_gen(generator : MMGenBase) -> String:
228232
var gnode : GraphNode = graph.get_node(node_path)
229233
return gnode.title.to_snake_case()
230234
return "unnamed"
235+
236+
func is_classic_theme() -> bool:
237+
return "classic" in mm_globals.main_window.theme.resource_path

material_maker/main_window.gd

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,11 @@ func _ready() -> void:
161161
if mm_globals.config.has_section_key("window", "size"):
162162
get_window().size = mm_globals.config.get_value("window", "size")
163163

164+
# Update fonts
165+
FontManager.rebuild_fonts()
166+
theme.default_font = FontManager.main_font
167+
theme.default_font_size = FontManager.ui_font_size
168+
164169
# Restore the theme
165170
var theme_name: String = "default dark"
166171
if mm_globals.config.has_section_key("window", "theme"):
@@ -620,14 +625,21 @@ func create_menu_set_theme(menu : MMMenuManager.MenuBase) -> void:
620625
func change_theme(theme_name) -> void:
621626
if not ResourceLoader.exists("res://material_maker/theme/"+theme_name+".tres"):
622627
theme_name = "default dark"
623-
var _theme = load("res://material_maker/theme/"+theme_name+".tres")
628+
var _theme : Theme = load("res://material_maker/theme/"+theme_name+".tres")
624629
if _theme == theme:
625630
return
626631
if _theme is EnhancedTheme:
627632
_theme.update()
628-
await get_tree().process_frame
629633
theme = _theme
634+
theme.default_font = FontManager.main_font
635+
theme.set_font("title_font", "TooltipPanel", FontManager.main_font)
636+
theme.set_font("font", "TooltipLabel", FontManager.main_font)
637+
630638
if "classic" in theme_name:
639+
if not FontManager.has_font_config("main_font"):
640+
theme.default_font = FontManager.classic_font
641+
theme.set_font("title_font", "TooltipPanel", FontManager.classic_font)
642+
theme.set_font("font", "TooltipLabel", FontManager.classic_font)
631643
RenderingServer.set_default_clear_color(Color(0.14, 0.17,0.23))
632644
else:
633645
RenderingServer.set_default_clear_color(

material_maker/nodes/base.gd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ func _draw() -> void:
229229
draw_style_box(get_theme_stylebox("node_highlight"), Rect2(Vector2.ZERO, size))
230230
if generator.rendering_time > 0:
231231
var time_color : Color = get_rendering_time_color(generator.rendering_time)
232-
var buffer_timing_font : Font = preload("res://material_maker/theme/font_rubik/Rubik-416.ttf")
232+
var buffer_timing_font : FontVariation = FontManager.medium_font
233233
@warning_ignore_start("narrowing_conversion")
234234
draw_string_outline(buffer_timing_font, Vector2i(0, size.y+12), str(generator.rendering_time)+"ms", HORIZONTAL_ALIGNMENT_CENTER, size.x, 12, 4, Color.BLACK)
235235
draw_string(buffer_timing_font, Vector2i(0, size.y+12), str(generator.rendering_time)+"ms", HORIZONTAL_ALIGNMENT_CENTER, size.x, 12, time_color)

material_maker/nodes/generic/generic.gd

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ func do_update_preview() -> void:
417417
func update_title() -> void:
418418
title = TranslationServer.translate(generator.get_type_name())
419419
if generator == null or generator.minimized:
420-
var font : Font = get_theme_font("default_font")
420+
var font : Font = FontManager.medium_font
421421
var max_title_width = 28
422422
if font.get_string_size(title).x > max_title_width:
423423
for i in range(1, title.length()-1):
@@ -438,6 +438,8 @@ func update_node() -> void:
438438
if mm_globals.get_config(SETTINGS_NODE_CLOSE_BUTTON) else false)
439439
# Rebuild node
440440
update_title()
441+
var title_label : Label = get_titlebar_hbox().get_child(0)
442+
title_label.add_theme_font_override("font", FontManager.medium_font)
441443
# Resize to minimum
442444
size = Vector2(0, 0)
443445
# Regex for labels

material_maker/nodes/minimal.gd

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ func _ready() -> void:
1919
buttons = HBoxContainer.new()
2020
var space : Control = Control.new()
2121
buttons.add_theme_constant_override("separation", 1)
22+
var title_label : Label = get_titlebar_hbox().get_child(0)
23+
title_label.add_theme_font_override("font", FontManager.medium_font)
2224
space.custom_minimum_size = Vector2(4, 0)
2325
buttons.add_child(space)
2426
get_titlebar_hbox().add_child(buttons)

material_maker/nodes/portal/portal.gd

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
extends MMGraphNodeMinimal
22
class_name MMGraphPortal
33

4-
const LABEL_FONT = preload("res://material_maker/theme/font_rubik/Rubik-416.ttf")
4+
var label_font : FontVariation = FontManager.medium_font
55

66
## Whether portal's link is being edited
77
## (i.e. its associated LineEdit is visible)
@@ -32,11 +32,11 @@ func _draw() -> void:
3232
var label_pos := size * 0.5
3333
var label_color : Color = generator.color
3434

35-
var label_size = LABEL_FONT.get_string_size(get_link(), HORIZONTAL_ALIGNMENT_CENTER, -1, label_font_size)
35+
var label_size = label_font.get_string_size(get_link(), HORIZONTAL_ALIGNMENT_CENTER, -1, label_font_size)
3636
var label_draw_pos := label_pos - Vector2(label_size.x * 0.5, label_y_offset)
3737
if not is_editing:
38-
draw_string_outline(LABEL_FONT, label_draw_pos, get_link(), HORIZONTAL_ALIGNMENT_CENTER, -1, label_font_size, 5, Color.BLACK)
39-
draw_string(LABEL_FONT, label_draw_pos, get_link(), HORIZONTAL_ALIGNMENT_CENTER, -1, label_font_size, label_color)
38+
draw_string_outline(label_font, label_draw_pos, get_link(), HORIZONTAL_ALIGNMENT_CENTER, -1, label_font_size, 5, Color.BLACK)
39+
draw_string(label_font, label_draw_pos, get_link(), HORIZONTAL_ALIGNMENT_CENTER, -1, label_font_size, label_color)
4040

4141
# label dragger
4242
%Dragger.mouse_filter = MOUSE_FILTER_IGNORE if is_editing else MOUSE_FILTER_PASS
@@ -274,7 +274,7 @@ func setup_portal_edit() -> void:
274274
var old_link := get_link()
275275
var graph : MMGraphEdit = get_parent()
276276
var edit := LineEdit.new()
277-
edit.add_theme_font_override("font", LABEL_FONT)
277+
edit.add_theme_font_override("font", label_font)
278278
edit.alignment = HORIZONTAL_ALIGNMENT_CENTER
279279
edit.max_length = 64
280280
edit.expand_to_text_length = true

material_maker/panels/graph_edit/graph_edit.gd

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ signal graph_changed
6969
signal view_updated
7070
signal preview_changed
7171

72-
7372
func _ready() -> void:
7473
OS.low_processor_usage_mode = true
7574
center_view()

material_maker/panels/graph_edit/graph_zoom_menu.gd

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,7 @@ func update_zoom() -> void:
4040
if graph_edit:
4141
graph_edit.zoom = zoom_level
4242
mm_globals.set_config(SETTING_GRAPH_ZOOM_LEVEL, zoom_level)
43+
44+
func _notification(what : int) -> void:
45+
if what == NOTIFICATION_THEME_CHANGED:
46+
%ZoomLabel.add_theme_font_override("font", FontManager.main_font)

material_maker/panels/library/library.gd

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ var category_buttons = {}
1313
@onready var filter_line_edit : LineEdit = %Filter
1414
@onready var item_menu : PopupMenu = %ItemMenu
1515

16-
var section_font = preload("res://material_maker/theme/font_rubik/Rubik-416.ttf")
17-
1816
const MINIMUM_ITEM_HEIGHT : int = 30
1917

2018
const MENU_CREATE_LIBRARY : int = 1000
@@ -68,8 +66,9 @@ func _notification(what: int) -> void:
6866
func update_theme() -> void:
6967
libraries_button.icon = get_theme_icon("settings", "MM_Icons")
7068

71-
var is_theme_classic : bool = "classic" in mm_globals.main_window.theme.resource_path
69+
var is_theme_classic : bool = mm_globals.is_classic_theme()
7270
library_manager.update_section_colors(is_theme_classic)
71+
update_tree()
7372

7473
func init_expanded_items() -> void:
7574
var f = FileAccess.open("user://expanded_items.bin", FileAccess.READ)
@@ -160,7 +159,7 @@ func update_tree() -> void:
160159

161160
for section : TreeItem in tree.get_root().get_children():
162161
if section.get_children().size():
163-
section.set_custom_font(0, section_font)
162+
section.set_custom_font(0, FontManager.medium_font)
164163
tree.queue_redraw()
165164

166165
func add_item(item, library_index : int, item_name : String, item_icon = null, item_parent = null, force_expand = false) -> TreeItem:

material_maker/panels/preview_2d/export_menu.gd

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ func _notification(what: int) -> void:
2424
%ExportFolderButton.icon = get_theme_icon("folder", "MM_Icons")
2525
%ExportFileResultLabel.add_theme_color_override("font_color", get_theme_color("font_color", "Label").lerp(Color.ORANGE, 0.5))
2626
%ExportNotificationLabel.add_theme_color_override("font_color", get_theme_color("font_color", "Label").lerp(get_theme_color("icon_pressed_color", "Button"), 0.5))
27+
%ExportFileResultLabel.add_theme_font_override("font",
28+
FontManager.create_italic_variation(FontManager.main_font))
2729

2830

2931
func _open() -> void:

0 commit comments

Comments
 (0)