From 765f404f2632595793b5754df598ea435ff1b7b2 Mon Sep 17 00:00:00 2001 From: Mounir Tohami Date: Fri, 20 Dec 2024 02:39:44 +0200 Subject: [PATCH] Add default theme customization --- scene/gui/control.cpp | 2 + scene/main/window.cpp | 4 +- scene/theme/SCsub | 7 +- scene/theme/icons/SCsub | 1 - scene/theme/icons/add.svg | 2 +- scene/theme/icons/arrow_down.svg | 2 +- scene/theme/icons/arrow_left.svg | 2 +- scene/theme/icons/arrow_right.svg | 2 +- scene/theme/icons/bookmark.svg | 2 +- scene/theme/icons/breakpoint.svg | 2 +- scene/theme/icons/checked.svg | 2 +- scene/theme/icons/checked_disabled.svg | 2 +- scene/theme/icons/close.svg | 2 +- scene/theme/icons/close_hl.svg | 2 +- scene/theme/icons/color_picker_bar_arrow.svg | 2 +- scene/theme/icons/color_picker_cursor.svg | 2 +- scene/theme/icons/color_picker_cursor_bg.svg | 1 + scene/theme/icons/color_picker_hex.svg | 1 + scene/theme/icons/color_picker_hex_code.svg | 1 + scene/theme/icons/color_picker_overbright.svg | 2 +- scene/theme/icons/color_picker_pipette.svg | 2 +- scene/theme/icons/error_icon.svg | 2 +- scene/theme/icons/file.svg | 2 +- scene/theme/icons/folder.svg | 2 +- scene/theme/icons/folder_create.svg | 2 +- scene/theme/icons/folder_up.svg | 2 +- scene/theme/icons/graph_port.svg | 2 +- scene/theme/icons/grid_layout.svg | 2 +- scene/theme/icons/grid_minimap.svg | 2 +- scene/theme/icons/grid_snap.svg | 2 +- scene/theme/icons/grid_toggle.svg | 2 +- scene/theme/icons/hslider_tick.svg | 2 +- scene/theme/icons/indeterminate.svg | 2 +- scene/theme/icons/indeterminate_disabled.svg | 2 +- scene/theme/icons/line_edit_clear.svg | 2 +- scene/theme/icons/mini_checkerboard.svg | 2 +- scene/theme/icons/option_button_arrow.svg | 2 +- scene/theme/icons/picker_shape_circle.svg | 2 +- scene/theme/icons/picker_shape_rectangle.svg | 2 +- .../icons/picker_shape_rectangle_wheel.svg | 2 +- scene/theme/icons/popup_menu_arrow_left.svg | 2 +- scene/theme/icons/popup_menu_arrow_right.svg | 2 +- scene/theme/icons/radio_checked.svg | 2 +- scene/theme/icons/radio_checked_disabled.svg | 2 +- scene/theme/icons/radio_unchecked.svg | 2 +- .../theme/icons/radio_unchecked_disabled.svg | 2 +- scene/theme/icons/region_folded.svg | 2 +- scene/theme/icons/region_unfolded.svg | 2 +- scene/theme/icons/reload.svg | 2 +- scene/theme/icons/resizer_nw.svg | 2 +- scene/theme/icons/resizer_se.svg | 2 +- scene/theme/icons/scroll_button_left.svg | 2 +- scene/theme/icons/scroll_button_left_hl.svg | 2 +- scene/theme/icons/scroll_button_right.svg | 2 +- scene/theme/icons/scroll_button_right_hl.svg | 2 +- scene/theme/icons/slider_grabber.svg | 2 +- scene/theme/icons/slider_grabber_disabled.svg | 2 +- scene/theme/icons/slider_grabber_hl.svg | 2 +- scene/theme/icons/tabs_menu.svg | 2 +- scene/theme/icons/tabs_menu_hl.svg | 2 +- scene/theme/icons/text_edit_ellipsis.svg | 2 +- scene/theme/icons/text_edit_space.svg | 2 +- scene/theme/icons/text_edit_tab.svg | 2 +- scene/theme/icons/toggle_off.svg | 2 +- scene/theme/icons/toggle_off_disabled.svg | 2 +- .../icons/toggle_off_disabled_mirrored.svg | 2 +- scene/theme/icons/toggle_off_mirrored.svg | 2 +- scene/theme/icons/toggle_on.svg | 2 +- scene/theme/icons/toggle_on_disabled.svg | 2 +- .../icons/toggle_on_disabled_mirrored.svg | 2 +- scene/theme/icons/toggle_on_mirrored.svg | 2 +- scene/theme/icons/unchecked.svg | 2 +- scene/theme/icons/unchecked_disabled.svg | 2 +- scene/theme/icons/updown.svg | 2 +- scene/theme/icons/value_down.svg | 2 +- scene/theme/icons/value_up.svg | 2 +- scene/theme/icons/visibility_visible.svg | 2 +- scene/theme/icons/vslider_tick.svg | 2 +- scene/theme/icons/zoom_less.svg | 2 +- scene/theme/icons/zoom_more.svg | 2 +- scene/theme/icons/zoom_reset.svg | 2 +- scene/theme/pixel_default_theme.cpp | 1637 +++++++++++++++++ scene/theme/pixel_default_theme.h | 74 + scene/theme/theme_db.cpp | 329 +++- scene/theme/theme_db.h | 58 + 85 files changed, 2181 insertions(+), 82 deletions(-) create mode 100644 scene/theme/icons/color_picker_cursor_bg.svg create mode 100644 scene/theme/icons/color_picker_hex.svg create mode 100644 scene/theme/icons/color_picker_hex_code.svg create mode 100644 scene/theme/pixel_default_theme.cpp create mode 100644 scene/theme/pixel_default_theme.h diff --git a/scene/gui/control.cpp b/scene/gui/control.cpp index 515c33a45477..cad999f8b2b2 100644 --- a/scene/gui/control.cpp +++ b/scene/gui/control.cpp @@ -449,9 +449,11 @@ void Control::_validate_property(PropertyInfo &p_property) const { // Only the default theme and the project theme are used for the list of options. // This is an imposed limitation to simplify the logic needed to leverage those options. ThemeDB::get_singleton()->get_default_theme()->get_type_variation_list(get_class_name(), &names); +#ifndef PIXEL_ENGINE if (ThemeDB::get_singleton()->get_project_theme().is_valid()) { ThemeDB::get_singleton()->get_project_theme()->get_type_variation_list(get_class_name(), &names); } +#endif // !PIXEL_ENGINE names.sort_custom(); Vector unique_names; diff --git a/scene/main/window.cpp b/scene/main/window.cpp index 1b6df652e31e..928b0af2e8c5 100644 --- a/scene/main/window.cpp +++ b/scene/main/window.cpp @@ -247,11 +247,11 @@ void Window::_validate_property(PropertyInfo &p_property) const { // Only the default theme and the project theme are used for the list of options. // This is an imposed limitation to simplify the logic needed to leverage those options. ThemeDB::get_singleton()->get_default_theme()->get_type_variation_list(get_class_name(), &names); -#ifdef TOOLS_ENABLED +#ifndef PIXEL_ENGINE if (ThemeDB::get_singleton()->get_project_theme().is_valid()) { ThemeDB::get_singleton()->get_project_theme()->get_type_variation_list(get_class_name(), &names); } -#endif // TOOLS_ENABLED +#endif // !PIXEL_ENGINE names.sort_custom(); Vector unique_names; diff --git a/scene/theme/SCsub b/scene/theme/SCsub index fb0914c0ee1a..12ef9a25669f 100644 --- a/scene/theme/SCsub +++ b/scene/theme/SCsub @@ -5,7 +5,12 @@ Import("env") import default_theme_builders -env.add_source_files(env.scene_sources, "*.cpp") +env.add_source_files(env.scene_sources, ["theme_db.cpp", "theme_owner.cpp"]) + +if env.pixel_engine: + env.add_source_files(env.scene_sources, "pixel_default_theme.cpp") +else: + env.add_source_files(env.scene_sources, "default_theme.cpp") SConscript("icons/SCsub") diff --git a/scene/theme/icons/SCsub b/scene/theme/icons/SCsub index 19aca74e57ce..1f3b7f6d1781 100644 --- a/scene/theme/icons/SCsub +++ b/scene/theme/icons/SCsub @@ -1,5 +1,4 @@ #!/usr/bin/env python -from misc.utility.scons_hints import * Import("env") diff --git a/scene/theme/icons/add.svg b/scene/theme/icons/add.svg index 2dead5ea71a9..c2e91905f635 100644 --- a/scene/theme/icons/add.svg +++ b/scene/theme/icons/add.svg @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/scene/theme/icons/arrow_down.svg b/scene/theme/icons/arrow_down.svg index a3e9464748ae..fa2e77cb6746 100644 --- a/scene/theme/icons/arrow_down.svg +++ b/scene/theme/icons/arrow_down.svg @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/scene/theme/icons/arrow_left.svg b/scene/theme/icons/arrow_left.svg index 96a3f605be8a..25f0caa5d606 100644 --- a/scene/theme/icons/arrow_left.svg +++ b/scene/theme/icons/arrow_left.svg @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/scene/theme/icons/arrow_right.svg b/scene/theme/icons/arrow_right.svg index 6fc0656522dc..aca0a03429df 100644 --- a/scene/theme/icons/arrow_right.svg +++ b/scene/theme/icons/arrow_right.svg @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/scene/theme/icons/bookmark.svg b/scene/theme/icons/bookmark.svg index c3919d38f850..1879be7cb0b9 100644 --- a/scene/theme/icons/bookmark.svg +++ b/scene/theme/icons/bookmark.svg @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/scene/theme/icons/breakpoint.svg b/scene/theme/icons/breakpoint.svg index 075166f6a402..164de5425ae1 100644 --- a/scene/theme/icons/breakpoint.svg +++ b/scene/theme/icons/breakpoint.svg @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/scene/theme/icons/checked.svg b/scene/theme/icons/checked.svg index 1ab415e7a14d..1f817f54b8d3 100644 --- a/scene/theme/icons/checked.svg +++ b/scene/theme/icons/checked.svg @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/scene/theme/icons/checked_disabled.svg b/scene/theme/icons/checked_disabled.svg index 8319e808fa89..60923bdfef38 100644 --- a/scene/theme/icons/checked_disabled.svg +++ b/scene/theme/icons/checked_disabled.svg @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/scene/theme/icons/close.svg b/scene/theme/icons/close.svg index 01236742310a..04767b7e0b4a 100644 --- a/scene/theme/icons/close.svg +++ b/scene/theme/icons/close.svg @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/scene/theme/icons/close_hl.svg b/scene/theme/icons/close_hl.svg index 6654df80e810..1de5b71769f5 100644 --- a/scene/theme/icons/close_hl.svg +++ b/scene/theme/icons/close_hl.svg @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/scene/theme/icons/color_picker_bar_arrow.svg b/scene/theme/icons/color_picker_bar_arrow.svg index 5612ecaadccd..621771dae945 100644 --- a/scene/theme/icons/color_picker_bar_arrow.svg +++ b/scene/theme/icons/color_picker_bar_arrow.svg @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/scene/theme/icons/color_picker_cursor.svg b/scene/theme/icons/color_picker_cursor.svg index 2eaad3c1285b..713b5abaae04 100644 --- a/scene/theme/icons/color_picker_cursor.svg +++ b/scene/theme/icons/color_picker_cursor.svg @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/scene/theme/icons/color_picker_cursor_bg.svg b/scene/theme/icons/color_picker_cursor_bg.svg new file mode 100644 index 000000000000..19b24ba1a248 --- /dev/null +++ b/scene/theme/icons/color_picker_cursor_bg.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/scene/theme/icons/color_picker_hex.svg b/scene/theme/icons/color_picker_hex.svg new file mode 100644 index 000000000000..64cb3db6e5ce --- /dev/null +++ b/scene/theme/icons/color_picker_hex.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/scene/theme/icons/color_picker_hex_code.svg b/scene/theme/icons/color_picker_hex_code.svg new file mode 100644 index 000000000000..eadfe6278334 --- /dev/null +++ b/scene/theme/icons/color_picker_hex_code.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/scene/theme/icons/color_picker_overbright.svg b/scene/theme/icons/color_picker_overbright.svg index 7acdca1c471d..b1ffad12ec5b 100644 --- a/scene/theme/icons/color_picker_overbright.svg +++ b/scene/theme/icons/color_picker_overbright.svg @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/scene/theme/icons/color_picker_pipette.svg b/scene/theme/icons/color_picker_pipette.svg index 3dae08eac07a..b31bf1bc1ec4 100644 --- a/scene/theme/icons/color_picker_pipette.svg +++ b/scene/theme/icons/color_picker_pipette.svg @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/scene/theme/icons/error_icon.svg b/scene/theme/icons/error_icon.svg index fef3d5f86efe..8c94290c0d56 100644 --- a/scene/theme/icons/error_icon.svg +++ b/scene/theme/icons/error_icon.svg @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/scene/theme/icons/file.svg b/scene/theme/icons/file.svg index e8890f3968fd..44e7a2d87618 100644 --- a/scene/theme/icons/file.svg +++ b/scene/theme/icons/file.svg @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/scene/theme/icons/folder.svg b/scene/theme/icons/folder.svg index 64dc9ab98b4a..7c1caba81481 100644 --- a/scene/theme/icons/folder.svg +++ b/scene/theme/icons/folder.svg @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/scene/theme/icons/folder_create.svg b/scene/theme/icons/folder_create.svg index 6c770d446b08..894d68e22797 100644 --- a/scene/theme/icons/folder_create.svg +++ b/scene/theme/icons/folder_create.svg @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/scene/theme/icons/folder_up.svg b/scene/theme/icons/folder_up.svg index 7db5de871d2f..128374eccc8d 100644 --- a/scene/theme/icons/folder_up.svg +++ b/scene/theme/icons/folder_up.svg @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/scene/theme/icons/graph_port.svg b/scene/theme/icons/graph_port.svg index 9d81bf1c5ba0..78dc830a35cf 100644 --- a/scene/theme/icons/graph_port.svg +++ b/scene/theme/icons/graph_port.svg @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/scene/theme/icons/grid_layout.svg b/scene/theme/icons/grid_layout.svg index 6015cd90687b..637e77550c27 100644 --- a/scene/theme/icons/grid_layout.svg +++ b/scene/theme/icons/grid_layout.svg @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/scene/theme/icons/grid_minimap.svg b/scene/theme/icons/grid_minimap.svg index a2d7c9c9bbb6..fe1b71208080 100644 --- a/scene/theme/icons/grid_minimap.svg +++ b/scene/theme/icons/grid_minimap.svg @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/scene/theme/icons/grid_snap.svg b/scene/theme/icons/grid_snap.svg index beb4ee7b2a89..d4e742965927 100644 --- a/scene/theme/icons/grid_snap.svg +++ b/scene/theme/icons/grid_snap.svg @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/scene/theme/icons/grid_toggle.svg b/scene/theme/icons/grid_toggle.svg index c4683aade1ee..fd5eb015014d 100644 --- a/scene/theme/icons/grid_toggle.svg +++ b/scene/theme/icons/grid_toggle.svg @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/scene/theme/icons/hslider_tick.svg b/scene/theme/icons/hslider_tick.svg index 6697632ae2a2..fb00a20f806b 100644 --- a/scene/theme/icons/hslider_tick.svg +++ b/scene/theme/icons/hslider_tick.svg @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/scene/theme/icons/indeterminate.svg b/scene/theme/icons/indeterminate.svg index f8edca3e526e..31c1f7f6ff4c 100644 --- a/scene/theme/icons/indeterminate.svg +++ b/scene/theme/icons/indeterminate.svg @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/scene/theme/icons/indeterminate_disabled.svg b/scene/theme/icons/indeterminate_disabled.svg index 7276625eadb7..952a632178e1 100644 --- a/scene/theme/icons/indeterminate_disabled.svg +++ b/scene/theme/icons/indeterminate_disabled.svg @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/scene/theme/icons/line_edit_clear.svg b/scene/theme/icons/line_edit_clear.svg index 01236742310a..2ebec8d0ee60 100644 --- a/scene/theme/icons/line_edit_clear.svg +++ b/scene/theme/icons/line_edit_clear.svg @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/scene/theme/icons/mini_checkerboard.svg b/scene/theme/icons/mini_checkerboard.svg index 2dd71a6addb7..6a8d39f05813 100644 --- a/scene/theme/icons/mini_checkerboard.svg +++ b/scene/theme/icons/mini_checkerboard.svg @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/scene/theme/icons/option_button_arrow.svg b/scene/theme/icons/option_button_arrow.svg index bdb27e0528d5..9e858af5aa51 100644 --- a/scene/theme/icons/option_button_arrow.svg +++ b/scene/theme/icons/option_button_arrow.svg @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/scene/theme/icons/picker_shape_circle.svg b/scene/theme/icons/picker_shape_circle.svg index de104121c897..a7fe33cdcbab 100644 --- a/scene/theme/icons/picker_shape_circle.svg +++ b/scene/theme/icons/picker_shape_circle.svg @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/scene/theme/icons/picker_shape_rectangle.svg b/scene/theme/icons/picker_shape_rectangle.svg index 642b9f789dcb..460dedac6a89 100644 --- a/scene/theme/icons/picker_shape_rectangle.svg +++ b/scene/theme/icons/picker_shape_rectangle.svg @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/scene/theme/icons/picker_shape_rectangle_wheel.svg b/scene/theme/icons/picker_shape_rectangle_wheel.svg index e46cc4140290..c81b42e8cafd 100644 --- a/scene/theme/icons/picker_shape_rectangle_wheel.svg +++ b/scene/theme/icons/picker_shape_rectangle_wheel.svg @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/scene/theme/icons/popup_menu_arrow_left.svg b/scene/theme/icons/popup_menu_arrow_left.svg index c5c1b32da8ba..03ad0ee65e9b 100644 --- a/scene/theme/icons/popup_menu_arrow_left.svg +++ b/scene/theme/icons/popup_menu_arrow_left.svg @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/scene/theme/icons/popup_menu_arrow_right.svg b/scene/theme/icons/popup_menu_arrow_right.svg index 8741f3a3871e..33d05975a1ea 100644 --- a/scene/theme/icons/popup_menu_arrow_right.svg +++ b/scene/theme/icons/popup_menu_arrow_right.svg @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/scene/theme/icons/radio_checked.svg b/scene/theme/icons/radio_checked.svg index 85a3d0c456f2..71270d8351b0 100644 --- a/scene/theme/icons/radio_checked.svg +++ b/scene/theme/icons/radio_checked.svg @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/scene/theme/icons/radio_checked_disabled.svg b/scene/theme/icons/radio_checked_disabled.svg index 30627c07cc43..89ccbd772670 100644 --- a/scene/theme/icons/radio_checked_disabled.svg +++ b/scene/theme/icons/radio_checked_disabled.svg @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/scene/theme/icons/radio_unchecked.svg b/scene/theme/icons/radio_unchecked.svg index f78b678c5133..e6ded80e2c05 100644 --- a/scene/theme/icons/radio_unchecked.svg +++ b/scene/theme/icons/radio_unchecked.svg @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/scene/theme/icons/radio_unchecked_disabled.svg b/scene/theme/icons/radio_unchecked_disabled.svg index 706aa68b84a4..f4c61d741e57 100644 --- a/scene/theme/icons/radio_unchecked_disabled.svg +++ b/scene/theme/icons/radio_unchecked_disabled.svg @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/scene/theme/icons/region_folded.svg b/scene/theme/icons/region_folded.svg index 99e20678c9b2..05ad83dd1c7f 100644 --- a/scene/theme/icons/region_folded.svg +++ b/scene/theme/icons/region_folded.svg @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/scene/theme/icons/region_unfolded.svg b/scene/theme/icons/region_unfolded.svg index 5186dd8afb4d..38aa4f572f99 100644 --- a/scene/theme/icons/region_unfolded.svg +++ b/scene/theme/icons/region_unfolded.svg @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/scene/theme/icons/reload.svg b/scene/theme/icons/reload.svg index 7f4cef5d97c5..abe8b991e41a 100644 --- a/scene/theme/icons/reload.svg +++ b/scene/theme/icons/reload.svg @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/scene/theme/icons/resizer_nw.svg b/scene/theme/icons/resizer_nw.svg index a8457b14265f..73d0a1d192d5 100644 --- a/scene/theme/icons/resizer_nw.svg +++ b/scene/theme/icons/resizer_nw.svg @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/scene/theme/icons/resizer_se.svg b/scene/theme/icons/resizer_se.svg index c3b8746314e8..6672b94de1fe 100644 --- a/scene/theme/icons/resizer_se.svg +++ b/scene/theme/icons/resizer_se.svg @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/scene/theme/icons/scroll_button_left.svg b/scene/theme/icons/scroll_button_left.svg index 2a3c0e3a4a37..6a8e8349d8d2 100644 --- a/scene/theme/icons/scroll_button_left.svg +++ b/scene/theme/icons/scroll_button_left.svg @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/scene/theme/icons/scroll_button_left_hl.svg b/scene/theme/icons/scroll_button_left_hl.svg index 659bf6b4c400..9655242bff14 100644 --- a/scene/theme/icons/scroll_button_left_hl.svg +++ b/scene/theme/icons/scroll_button_left_hl.svg @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/scene/theme/icons/scroll_button_right.svg b/scene/theme/icons/scroll_button_right.svg index 7736e1ef271b..333a53c2faae 100644 --- a/scene/theme/icons/scroll_button_right.svg +++ b/scene/theme/icons/scroll_button_right.svg @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/scene/theme/icons/scroll_button_right_hl.svg b/scene/theme/icons/scroll_button_right_hl.svg index b29e918253db..c1132cdb7322 100644 --- a/scene/theme/icons/scroll_button_right_hl.svg +++ b/scene/theme/icons/scroll_button_right_hl.svg @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/scene/theme/icons/slider_grabber.svg b/scene/theme/icons/slider_grabber.svg index ef0a1fea8cd8..6be6058391ce 100644 --- a/scene/theme/icons/slider_grabber.svg +++ b/scene/theme/icons/slider_grabber.svg @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/scene/theme/icons/slider_grabber_disabled.svg b/scene/theme/icons/slider_grabber_disabled.svg index 48326fea9fed..12b981e9959e 100644 --- a/scene/theme/icons/slider_grabber_disabled.svg +++ b/scene/theme/icons/slider_grabber_disabled.svg @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/scene/theme/icons/slider_grabber_hl.svg b/scene/theme/icons/slider_grabber_hl.svg index 046878c9b129..1bbbc2e99fef 100644 --- a/scene/theme/icons/slider_grabber_hl.svg +++ b/scene/theme/icons/slider_grabber_hl.svg @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/scene/theme/icons/tabs_menu.svg b/scene/theme/icons/tabs_menu.svg index 9a70151d3924..3da7a2217ad9 100644 --- a/scene/theme/icons/tabs_menu.svg +++ b/scene/theme/icons/tabs_menu.svg @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/scene/theme/icons/tabs_menu_hl.svg b/scene/theme/icons/tabs_menu_hl.svg index e55c1ad99eaf..ad50d3317c3b 100644 --- a/scene/theme/icons/tabs_menu_hl.svg +++ b/scene/theme/icons/tabs_menu_hl.svg @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/scene/theme/icons/text_edit_ellipsis.svg b/scene/theme/icons/text_edit_ellipsis.svg index a8e0a4e61539..15988f6617d7 100644 --- a/scene/theme/icons/text_edit_ellipsis.svg +++ b/scene/theme/icons/text_edit_ellipsis.svg @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/scene/theme/icons/text_edit_space.svg b/scene/theme/icons/text_edit_space.svg index 9f6a04ac50ba..ae455d7d10f0 100644 --- a/scene/theme/icons/text_edit_space.svg +++ b/scene/theme/icons/text_edit_space.svg @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/scene/theme/icons/text_edit_tab.svg b/scene/theme/icons/text_edit_tab.svg index e4bdf9058199..63d842662d1f 100644 --- a/scene/theme/icons/text_edit_tab.svg +++ b/scene/theme/icons/text_edit_tab.svg @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/scene/theme/icons/toggle_off.svg b/scene/theme/icons/toggle_off.svg index d58b6cdfe13b..bd8466966542 100644 --- a/scene/theme/icons/toggle_off.svg +++ b/scene/theme/icons/toggle_off.svg @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/scene/theme/icons/toggle_off_disabled.svg b/scene/theme/icons/toggle_off_disabled.svg index 85b6aad0ea75..a839242b8ad8 100644 --- a/scene/theme/icons/toggle_off_disabled.svg +++ b/scene/theme/icons/toggle_off_disabled.svg @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/scene/theme/icons/toggle_off_disabled_mirrored.svg b/scene/theme/icons/toggle_off_disabled_mirrored.svg index f65cbe60ae77..92eea095e40b 100644 --- a/scene/theme/icons/toggle_off_disabled_mirrored.svg +++ b/scene/theme/icons/toggle_off_disabled_mirrored.svg @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/scene/theme/icons/toggle_off_mirrored.svg b/scene/theme/icons/toggle_off_mirrored.svg index e24f24621c41..568b9d911328 100644 --- a/scene/theme/icons/toggle_off_mirrored.svg +++ b/scene/theme/icons/toggle_off_mirrored.svg @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/scene/theme/icons/toggle_on.svg b/scene/theme/icons/toggle_on.svg index 4db88f2dbb95..5999da211cc0 100644 --- a/scene/theme/icons/toggle_on.svg +++ b/scene/theme/icons/toggle_on.svg @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/scene/theme/icons/toggle_on_disabled.svg b/scene/theme/icons/toggle_on_disabled.svg index 622906bb2819..4d73bc151bb0 100644 --- a/scene/theme/icons/toggle_on_disabled.svg +++ b/scene/theme/icons/toggle_on_disabled.svg @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/scene/theme/icons/toggle_on_disabled_mirrored.svg b/scene/theme/icons/toggle_on_disabled_mirrored.svg index 0d444de6c4ee..2bc04d047981 100644 --- a/scene/theme/icons/toggle_on_disabled_mirrored.svg +++ b/scene/theme/icons/toggle_on_disabled_mirrored.svg @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/scene/theme/icons/toggle_on_mirrored.svg b/scene/theme/icons/toggle_on_mirrored.svg index bfed6dd2063f..2a40f7322af8 100644 --- a/scene/theme/icons/toggle_on_mirrored.svg +++ b/scene/theme/icons/toggle_on_mirrored.svg @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/scene/theme/icons/unchecked.svg b/scene/theme/icons/unchecked.svg index 354df8e8c98d..d066074d9c2c 100644 --- a/scene/theme/icons/unchecked.svg +++ b/scene/theme/icons/unchecked.svg @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/scene/theme/icons/unchecked_disabled.svg b/scene/theme/icons/unchecked_disabled.svg index 4d352d744ee5..3e2afff026e0 100644 --- a/scene/theme/icons/unchecked_disabled.svg +++ b/scene/theme/icons/unchecked_disabled.svg @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/scene/theme/icons/updown.svg b/scene/theme/icons/updown.svg index 4a48eb39a50a..d07c93898c7c 100644 --- a/scene/theme/icons/updown.svg +++ b/scene/theme/icons/updown.svg @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/scene/theme/icons/value_down.svg b/scene/theme/icons/value_down.svg index 57837d03fdb1..83472beefe7d 100644 --- a/scene/theme/icons/value_down.svg +++ b/scene/theme/icons/value_down.svg @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/scene/theme/icons/value_up.svg b/scene/theme/icons/value_up.svg index 53fb102fe2df..0a24361a80c4 100644 --- a/scene/theme/icons/value_up.svg +++ b/scene/theme/icons/value_up.svg @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/scene/theme/icons/visibility_visible.svg b/scene/theme/icons/visibility_visible.svg index cd826705361c..85ffb6c5b3e6 100644 --- a/scene/theme/icons/visibility_visible.svg +++ b/scene/theme/icons/visibility_visible.svg @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/scene/theme/icons/vslider_tick.svg b/scene/theme/icons/vslider_tick.svg index d1c5aa4dd695..64bedfdd943a 100644 --- a/scene/theme/icons/vslider_tick.svg +++ b/scene/theme/icons/vslider_tick.svg @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/scene/theme/icons/zoom_less.svg b/scene/theme/icons/zoom_less.svg index eea325db42bd..3573a1017f64 100644 --- a/scene/theme/icons/zoom_less.svg +++ b/scene/theme/icons/zoom_less.svg @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/scene/theme/icons/zoom_more.svg b/scene/theme/icons/zoom_more.svg index 441620e6e94a..7da58f1752b8 100644 --- a/scene/theme/icons/zoom_more.svg +++ b/scene/theme/icons/zoom_more.svg @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/scene/theme/icons/zoom_reset.svg b/scene/theme/icons/zoom_reset.svg index fd35fe3c74fc..c0de44c3ff21 100644 --- a/scene/theme/icons/zoom_reset.svg +++ b/scene/theme/icons/zoom_reset.svg @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/scene/theme/pixel_default_theme.cpp b/scene/theme/pixel_default_theme.cpp new file mode 100644 index 000000000000..226c89d6effd --- /dev/null +++ b/scene/theme/pixel_default_theme.cpp @@ -0,0 +1,1637 @@ +/**************************************************************************/ +/* pixel_default_theme.cpp */ +/**************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/**************************************************************************/ +/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ +/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/**************************************************************************/ + +/**************************************************************************/ +/* PIXEL ENGINE */ +/* Copyright (c) 2024-present Pixel Engine contributors (see AUTHORS.md). */ +/**************************************************************************/ +/* NOTICE: */ +/* This file contains modifications and additions specific to the Pixel */ +/* Engine project. While these changes are licensed under the MIT license */ +/* for compatibility, we request proper attribution if reused in any */ +/* derivative works, including meta-forks. */ +/**************************************************************************/ + +#include "pixel_default_theme.h" + +#include "core/os/os.h" +#include "default_font.gen.h" +#include "default_theme_icons.gen.h" +#include "scene/resources/font.h" +#include "scene/resources/gradient_texture.h" +#include "scene/resources/image_texture.h" +#include "scene/resources/style_box_flat.h" +#include "scene/resources/style_box_line.h" +#include "scene/resources/theme.h" +#include "scene/scene_string_names.h" +#include "scene/theme/theme_db.h" +#include "servers/text_server.h" + +#include "modules/modules_enabled.gen.h" // For svg. +#ifdef MODULE_SVG_ENABLED +#include "modules/svg/image_loader_svg.h" +#endif + +static Dictionary icons; + +static Ref panel_style; +static Ref popup_panel_style; +static Ref color_picker_popup_panel_style; +static Ref tab_panel_style; +static Ref color_sliders_panel_style; +static Ref tab_selected_style; +static Ref tab_unselected_style; +static Ref tab_hovered_style; +static Ref tab_disabled_style; +static Ref tab_focus_style; +static Ref button_normal_style; +static Ref button_hover_style; +static Ref button_pressed_style; +static Ref button_disabled_style; +static Ref button_focus_style; +static Ref color_button_normal_style; +static Ref color_button_hover_style; +static Ref color_button_pressed_style; +static Ref color_button_disabled_style; +static Ref color_button_focus_style; +static Ref menu_button_normal_style; +static Ref menu_button_hover_style; +static Ref menu_button_pressed_style; +static Ref menu_button_disabled_style; +static Ref menu_button_focus_style; +static Ref popup_hover_style; +static Ref progress_background_style; +static Ref progress_fill_style; +static Ref grabber_style; +static Ref grabber_highlight_style; +static Ref slider_style; +static Ref picker_slider_style; +static Ref h_scroll_style; +static Ref v_scroll_style; +static Ref foldable_panel_style; +static Ref foldable_title_style; +static Ref foldable_title_collapsed_style; +static Ref foldable_title_hover_style; +static Ref foldable_title_collapsed_hover_style; +static Ref swatches_foldable_panel_style; +static Ref swatches_foldable_title_style; +static Ref swatches_foldable_title_collapsed_style; +static Ref swatches_foldable_title_hover_style; +static Ref swatches_foldable_title_collapsed_hover_style; +static Ref h_separator_style; +static Ref v_separator_style; +static Ref flat_button_normal; +static Ref embedded_style; +static Ref embedded_unfocused_style; +static Ref graph_title_style; +static Ref graph_frame_title_style; +static Ref graph_frame_title_selected_style; +static Ref graph_title_selected_style; +static Ref graph_panel_style; +static Ref graph_panel_selected_style; +static Ref color_mode_button_normal_style; +static Ref color_mode_button_hovered_style; +static Ref color_mode_button_pressed_style; +static Ref color_picker_button_normal_style; +static Ref color_picker_button_hovered_style; +static Ref color_picker_button_pressed_style; +static Ref color_picker_button_disabled_style; + +static Ref fallback_font; +static Ref custom_font; +static Ref bold_font; +static Ref bold_italics_font; +static Ref italics_font; +static bool using_custom_font_variation = false; + +// See also `editor_generate_icon()` in `editor/themes/editor_icons.cpp`. +static Ref generate_icon(int p_index, float p_scale, Color p_font_color, Color p_accent_color) { + Ref img = memnew(Image); + +#ifdef MODULE_SVG_ENABLED + String svg = default_theme_icons_sources[p_index]; + svg = svg.replace("\"#fff\"", vformat("\"#%s\"", p_font_color.to_html(false))); + svg = svg.replace("\"#0f0\"", vformat("\"#%s\"", p_accent_color.to_html(false))); + + Error err = img->load_svg_from_string(svg, p_scale); + if (err == OK) { + img->fix_alpha_edges(); + } + ERR_FAIL_COND_V_MSG(err != OK, Ref(), "Failed generating icon, unsupported or invalid SVG data in default theme."); +#else + // If the SVG module is disabled, we can't really display the UI well, but at least we won't crash. + // 16 pixels is used as it's the most common base size for Godot icons. + img = Image::create_empty(Math::round(16 * p_scale), Math::round(16 * p_scale), false, Image::FORMAT_RGBA8); +#endif + + return img; +} + +void update_theme_icons(Ref &p_theme, Color p_font_color, Color p_accent_color) { + if (icons.is_empty()) { + Ref empty_icon = memnew(ImageTexture); + p_theme->set_icon("increment", "HScrollBar", empty_icon); + p_theme->set_icon("increment_highlight", "HScrollBar", empty_icon); + p_theme->set_icon("increment_pressed", "HScrollBar", empty_icon); + p_theme->set_icon("decrement", "HScrollBar", empty_icon); + p_theme->set_icon("decrement_highlight", "HScrollBar", empty_icon); + p_theme->set_icon("decrement_pressed", "HScrollBar", empty_icon); + p_theme->set_icon("increment", "VScrollBar", empty_icon); + p_theme->set_icon("increment_highlight", "VScrollBar", empty_icon); + p_theme->set_icon("increment_pressed", "VScrollBar", empty_icon); + p_theme->set_icon("decrement", "VScrollBar", empty_icon); + p_theme->set_icon("decrement_highlight", "VScrollBar", empty_icon); + p_theme->set_icon("decrement_pressed", "VScrollBar", empty_icon); + p_theme->set_icon("updown", "SpinBox", empty_icon); + { + const int precision = 7; + + Ref hue_gradient; + hue_gradient.instantiate(); + PackedFloat32Array offsets; + offsets.resize(precision); + PackedColorArray colors; + colors.resize(precision); + + for (int i = 0; i < precision; i++) { + float h = i / float(precision - 1); + offsets.write[i] = h; + colors.write[i] = Color::from_hsv(h, 1, 1); + } + hue_gradient->set_offsets(offsets); + hue_gradient->set_colors(colors); + + Ref hue_texture; + hue_texture.instantiate(); + hue_texture->set_width(512); + hue_texture->set_height(1); + hue_texture->set_gradient(hue_gradient); + + p_theme->set_icon("color_hue", "ColorPicker", hue_texture); + } + + { + const int precision = 7; + + Ref hue_gradient; + hue_gradient.instantiate(); + PackedFloat32Array offsets; + offsets.resize(precision); + PackedColorArray colors; + colors.resize(precision); + + for (int i = 0; i < precision; i++) { + float h = i / float(precision - 1); + offsets.write[i] = h; + colors.write[i] = Color::from_ok_hsl(h, 1, 0.5); + } + hue_gradient->set_offsets(offsets); + hue_gradient->set_colors(colors); + + Ref hue_texture; + hue_texture.instantiate(); + hue_texture->set_width(512); + hue_texture->set_height(1); + hue_texture->set_gradient(hue_gradient); + + p_theme->set_icon("color_okhsl_hue", "ColorPicker", hue_texture); + } + } + + const float scale = p_theme->get_default_base_scale(); + + for (int i = 0; i < default_theme_icons_count; i++) { + Ref img = generate_icon(i, scale, p_font_color, p_accent_color); + if (icons.has(default_theme_icons_names[i]) && ((Ref)icons[default_theme_icons_names[i]])->get_size() == (Vector2)img->get_size()) { + ((Ref)icons[default_theme_icons_names[i]])->update(img); + } else { + icons[default_theme_icons_names[i]] = ImageTexture::create_from_image(img); + } + } + + p_theme->set_icon("arrow", "OptionButton", icons["option_button_arrow"]); + p_theme->set_icon("checked", "CheckBox", icons["checked"]); + p_theme->set_icon("checked_disabled", "CheckBox", icons["checked_disabled"]); + p_theme->set_icon("unchecked", "CheckBox", icons["unchecked"]); + p_theme->set_icon("unchecked_disabled", "CheckBox", icons["unchecked_disabled"]); + p_theme->set_icon("radio_checked", "CheckBox", icons["radio_checked"]); + p_theme->set_icon("radio_checked_disabled", "CheckBox", icons["radio_checked_disabled"]); + p_theme->set_icon("radio_unchecked", "CheckBox", icons["radio_unchecked"]); + p_theme->set_icon("radio_unchecked_disabled", "CheckBox", icons["radio_unchecked_disabled"]); + p_theme->set_icon("checked", "CheckButton", icons["toggle_on"]); + p_theme->set_icon("checked_disabled", "CheckButton", icons["toggle_on_disabled"]); + p_theme->set_icon("unchecked", "CheckButton", icons["toggle_off"]); + p_theme->set_icon("unchecked_disabled", "CheckButton", icons["toggle_off_disabled"]); + p_theme->set_icon("checked_mirrored", "CheckButton", icons["toggle_on_mirrored"]); + p_theme->set_icon("checked_disabled_mirrored", "CheckButton", icons["toggle_on_disabled_mirrored"]); + p_theme->set_icon("unchecked_mirrored", "CheckButton", icons["toggle_off_mirrored"]); + p_theme->set_icon("unchecked_disabled_mirrored", "CheckButton", icons["toggle_off_disabled_mirrored"]); + p_theme->set_icon("clear", "LineEdit", icons["line_edit_clear"]); + p_theme->set_icon("tab", "TextEdit", icons["text_edit_tab"]); + p_theme->set_icon("space", "TextEdit", icons["text_edit_space"]); + p_theme->set_icon("tab", "CodeEdit", icons["text_edit_tab"]); + p_theme->set_icon("space", "CodeEdit", icons["text_edit_space"]); + p_theme->set_icon("breakpoint", "CodeEdit", icons["breakpoint"]); + p_theme->set_icon("bookmark", "CodeEdit", icons["bookmark"]); + p_theme->set_icon("executing_line", "CodeEdit", icons["arrow_right"]); + p_theme->set_icon("can_fold", "CodeEdit", icons["arrow_down"]); + p_theme->set_icon("folded", "CodeEdit", icons["arrow_right"]); + p_theme->set_icon("can_fold_code_region", "CodeEdit", icons["region_unfolded"]); + p_theme->set_icon("folded_code_region", "CodeEdit", icons["region_folded"]); + p_theme->set_icon("folded_eol_icon", "CodeEdit", icons["text_edit_ellipsis"]); + p_theme->set_icon("completion_color_bg", "CodeEdit", icons["mini_checkerboard"]); + p_theme->set_icon("grabber", "HSlider", icons["slider_grabber"]); + p_theme->set_icon("grabber_highlight", "HSlider", icons["slider_grabber_hl"]); + p_theme->set_icon("grabber_disabled", "HSlider", icons["slider_grabber_disabled"]); + p_theme->set_icon("tick", "HSlider", icons["hslider_tick"]); + p_theme->set_icon("grabber", "PickerHSlider", icons["color_picker_bar_arrow"]); + p_theme->set_icon("grabber_highlight", "PickerHSlider", icons["color_picker_bar_arrow"]); + p_theme->set_icon("grabber", "VSlider", icons["slider_grabber"]); + p_theme->set_icon("grabber_highlight", "VSlider", icons["slider_grabber_hl"]); + p_theme->set_icon("grabber_disabled", "VSlider", icons["slider_grabber_disabled"]); + p_theme->set_icon("tick", "VSlider", icons["vslider_tick"]); + p_theme->set_icon("up", "SpinBox", icons["value_up"]); + p_theme->set_icon("up_hover", "SpinBox", icons["value_up"]); + p_theme->set_icon("up_pressed", "SpinBox", icons["value_up"]); + p_theme->set_icon("up_disabled", "SpinBox", icons["value_up"]); + p_theme->set_icon("down", "SpinBox", icons["value_down"]); + p_theme->set_icon("down_hover", "SpinBox", icons["value_down"]); + p_theme->set_icon("down_pressed", "SpinBox", icons["value_down"]); + p_theme->set_icon("down_disabled", "SpinBox", icons["value_down"]); + p_theme->set_icon("close", "Window", icons["close"]); + p_theme->set_icon("close_pressed", "Window", icons["close_hl"]); + p_theme->set_icon("parent_folder", "FileDialog", icons["folder_up"]); + p_theme->set_icon("back_folder", "FileDialog", icons["arrow_left"]); + p_theme->set_icon("forward_folder", "FileDialog", icons["arrow_right"]); + p_theme->set_icon("reload", "FileDialog", icons["reload"]); + p_theme->set_icon("toggle_hidden", "FileDialog", icons["visibility_visible"]); + p_theme->set_icon("folder", "FileDialog", icons["folder"]); + p_theme->set_icon("file", "FileDialog", icons["file"]); + p_theme->set_icon("create_folder", "FileDialog", icons["folder_create"]); + p_theme->set_icon("checked", "PopupMenu", icons["checked"]); + p_theme->set_icon("checked_disabled", "PopupMenu", icons["checked_disabled"]); + p_theme->set_icon("unchecked", "PopupMenu", icons["unchecked"]); + p_theme->set_icon("unchecked_disabled", "PopupMenu", icons["unchecked_disabled"]); + p_theme->set_icon("radio_checked", "PopupMenu", icons["radio_checked"]); + p_theme->set_icon("radio_checked_disabled", "PopupMenu", icons["radio_checked_disabled"]); + p_theme->set_icon("radio_unchecked", "PopupMenu", icons["radio_unchecked"]); + p_theme->set_icon("radio_unchecked_disabled", "PopupMenu", icons["radio_unchecked_disabled"]); + p_theme->set_icon("submenu", "PopupMenu", icons["popup_menu_arrow_right"]); + p_theme->set_icon("submenu_mirrored", "PopupMenu", icons["popup_menu_arrow_left"]); + p_theme->set_icon("port", "GraphNode", icons["graph_port"]); + p_theme->set_icon("resizer", "GraphNode", icons["resizer_se"]); + p_theme->set_icon("resizer", "GraphFrame", icons["resizer_se"]); + p_theme->set_icon("checked", "Tree", icons["checked"]); + p_theme->set_icon("checked_disabled", "Tree", icons["checked_disabled"]); + p_theme->set_icon("unchecked", "Tree", icons["unchecked"]); + p_theme->set_icon("unchecked_disabled", "Tree", icons["unchecked_disabled"]); + p_theme->set_icon("indeterminate", "Tree", icons["indeterminate"]); + p_theme->set_icon("indeterminate_disabled", "Tree", icons["indeterminate_disabled"]); + p_theme->set_icon("updown", "Tree", icons["updown"]); + p_theme->set_icon("select_arrow", "Tree", icons["option_button_arrow"]); + p_theme->set_icon("arrow", "Tree", icons["arrow_down"]); + p_theme->set_icon("arrow_collapsed", "Tree", icons["arrow_right"]); + p_theme->set_icon("arrow_collapsed_mirrored", "Tree", icons["arrow_left"]); + p_theme->set_icon("increment", "TabContainer", icons["scroll_button_right"]); + p_theme->set_icon("increment_highlight", "TabContainer", icons["scroll_button_right_hl"]); + p_theme->set_icon("decrement", "TabContainer", icons["scroll_button_left"]); + p_theme->set_icon("decrement_highlight", "TabContainer", icons["scroll_button_left_hl"]); + p_theme->set_icon("menu", "TabContainer", icons["tabs_menu"]); + p_theme->set_icon("menu_highlight", "TabContainer", icons["tabs_menu_hl"]); + p_theme->set_icon("increment", "TabBar", icons["scroll_button_right"]); + p_theme->set_icon("increment_highlight", "TabBar", icons["scroll_button_right_hl"]); + p_theme->set_icon("decrement", "TabBar", icons["scroll_button_left"]); + p_theme->set_icon("decrement_highlight", "TabBar", icons["scroll_button_left_hl"]); + p_theme->set_icon("close", "TabBar", icons["close"]); + p_theme->set_icon("close", "Icons", icons["close"]); + p_theme->set_icon("error_icon", "Icons", icons["error_icon"]); + p_theme->set_icon("folded_arrow", "ColorPicker", icons["arrow_right"]); + p_theme->set_icon("expanded_arrow", "ColorPicker", icons["arrow_down"]); + p_theme->set_icon("screen_picker", "ColorPicker", icons["color_picker_pipette"]); + p_theme->set_icon("shape_circle", "ColorPicker", icons["picker_shape_circle"]); + p_theme->set_icon("shape_rect", "ColorPicker", icons["picker_shape_rectangle"]); + p_theme->set_icon("shape_rect_wheel", "ColorPicker", icons["picker_shape_rectangle_wheel"]); + p_theme->set_icon("add_preset", "ColorPicker", icons["add"]); + p_theme->set_icon("sample_bg", "ColorPicker", icons["mini_checkerboard"]); + p_theme->set_icon("sample_revert", "ColorPicker", icons["reload"]); + p_theme->set_icon("overbright_indicator", "ColorPicker", icons["color_picker_overbright"]); + p_theme->set_icon("picker_cursor", "ColorPicker", icons["color_picker_cursor"]); + p_theme->set_icon("picker_cursor_bg", "ColorPicker", icons["color_picker_cursor_bg"]); + p_theme->set_icon("hex_icon", "ColorPicker", icons["color_picker_hex"]); + p_theme->set_icon("hex_code_icon", "ColorPicker", icons["color_picker_hex_code"]); + p_theme->set_icon("bg", "ColorButton", icons["mini_checkerboard"]); + p_theme->set_icon("overbright_indicator", "ColorButton", icons["color_picker_overbright"]); + p_theme->set_icon("arrow", "FoldableContainer", icons["arrow_down"]); + p_theme->set_icon("arrow_collapsed", "FoldableContainer", icons["arrow_right"]); + p_theme->set_icon("arrow_collapsed_mirrored", "FoldableContainer", icons["arrow_left"]); + p_theme->set_icon("zoom_out", "GraphEdit", icons["zoom_less"]); + p_theme->set_icon("zoom_in", "GraphEdit", icons["zoom_more"]); + p_theme->set_icon("zoom_reset", "GraphEdit", icons["zoom_reset"]); + p_theme->set_icon("grid_toggle", "GraphEdit", icons["grid_toggle"]); + p_theme->set_icon("minimap_toggle", "GraphEdit", icons["grid_minimap"]); + p_theme->set_icon("snapping_toggle", "GraphEdit", icons["grid_snap"]); + p_theme->set_icon("layout", "GraphEdit", icons["grid_layout"]); + p_theme->set_icon("resizer", "GraphEditMinimap", icons["resizer_nw"]); + p_theme->set_icon("zoom_less", "ZoomWidget", icons["zoom_less"]); + p_theme->set_icon("zoom_more", "ZoomWidget", icons["zoom_more"]); + + p_theme->set_constant("grabber_offset", "PickerHSlider", Math::round(((Ref)icons["color_picker_bar_arrow"])->get_size().height * 0.5)); + ThemeDB::get_singleton()->set_fallback_icon(icons["error_icon"]); +} + +static Color contrast_color(Color p_color, float p_value) { + if (Math::is_equal_approx(p_value, 0.f)) { + return p_color; + } else if (p_value > 0.0) { + return p_color.lightened(p_value); + } else { + return p_color.darkened(p_value * -1.0); + } +} + +void update_font_color(Ref &p_theme, Color p_color) { + popup_panel_style->set_border_color(p_color); + color_picker_popup_panel_style->set_border_color(p_color); + h_separator_style->set_color(p_color); + v_separator_style->set_color(p_color); + panel_style->set_border_color(p_color); + graph_title_style->set_border_color(p_color); + graph_frame_title_style->set_border_color(p_color); + graph_panel_style->set_border_color(p_color); + color_button_pressed_style->set_border_color(p_color); + p_theme->set_color("font_hovered_color", "TabContainer", p_color); + p_theme->set_color("font_hovered_color", "TabBar", p_color); + p_theme->set_color("font_hover_color", "PopupMenu", p_color); + p_theme->set_color("font_selected_color", "LineEdit", p_color); + p_theme->set_color("font_selected_color", "TextEdit", p_color); + p_theme->set_color("font_selected_color", "RichTextLabel", p_color); + p_theme->set_color("font_selected_color", "CodeEdit", p_color); + p_theme->set_color("font_selected_color", "ItemList", p_color); + p_theme->set_color("font_selected_color", "TabContainer", p_color); + p_theme->set_color("font_selected_color", "TabBar", p_color); + p_theme->set_color("font_selected_color", "Tree", p_color); + p_theme->set_color("font_hovered_color", "Tree", p_color); + p_theme->set_color("caret_background_color", "TextEdit", p_color); + p_theme->set_color("caret_background_color", "CodeEdit", p_color); + p_theme->set_color("font_color", "ProgressBar", p_color); + p_theme->set_color("hover_font_color", "FoldableContainer", p_color); + p_theme->set_color("font_hover_color", "Button", p_color); + p_theme->set_color("font_hover_color", "LinkButton", p_color); + p_theme->set_color("icon_hover_color", "Button", p_color); + p_theme->set_color("font_hover_color", "MenuBar", p_color); + p_theme->set_color("font_hover_color", "LinkButton", p_color); + p_theme->set_color("font_hover_pressed_color", "MenuBar", p_color); + p_theme->set_color("font_hover_color", "OptionButton", p_color); + p_theme->set_color("font_hover_pressed_color", "OptionButton", p_color); + p_theme->set_color("font_hover_color", "MenuButton", p_color); + p_theme->set_color("font_hover_color", "CheckBox", p_color); + p_theme->set_color("font_hover_color", "CheckButton", p_color); + p_theme->set_color("drop_position_color", "Tree", p_color); + p_theme->set_color("font_hover_color", "ColorButton", p_color); + p_theme->set_color("up_hover_icon_modulate", "SpinBox", p_color); + p_theme->set_color("down_hover_icon_modulate", "SpinBox", p_color); + p_theme->set_color("font_hovered_color", "ItemList", p_color); + p_theme->set_color("connection_rim_color", "GraphEdit", p_color); + p_theme->set_color("button_icon_hovered", "FoldableContainer", p_color); + p_color.a = 0.9; + p_theme->set_color("parent_hl_line_color", "Tree", p_color); + p_theme->set_color("icon_focus_color", "Button", p_color); + p_theme->set_color("font_focus_color", "Button", p_color); + p_theme->set_color("font_focus_color", "LinkButton", p_color); + p_theme->set_color("font_focus_color", "MenuBar", p_color); + p_theme->set_color("title_color", "Window", p_color); + p_theme->set_color("font_focus_color", "OptionButton", p_color); + p_theme->set_color("font_focus_color", "MenuButton", p_color); + p_theme->set_color("font_focus_color", "CheckBox", p_color); + p_theme->set_color("font_focus_color", "CheckButton", p_color); + p_theme->set_color("custom_button_font_highlight", "Tree", p_color); + p_theme->set_color("font_focus_color", "ColorButton", p_color); + p_theme->set_color("resizer_color", "GraphEditMinimap", p_color); + p_theme->set_color("resizer_color", "GraphNode", p_color); + p_theme->set_color("resizer_color", "GraphFrame", p_color); + p_color.a = 0.8; + p_theme->set_color(SceneStringName(font_color), "Tree", p_color); + p_theme->set_color(SceneStringName(font_color), "LinkButton", p_color); + p_theme->set_color(SceneStringName(font_color), "Button", p_color); + p_theme->set_color(SceneStringName(font_color), "Label", p_color); + p_theme->set_color(SceneStringName(font_color), "LineEdit", p_color); + p_theme->set_color(SceneStringName(font_color), "TextEdit", p_color); + p_theme->set_color(SceneStringName(font_color), "CodeEdit", p_color); + p_theme->set_color(SceneStringName(font_color), "PopupMenu", p_color); + p_theme->set_color(SceneStringName(font_color), "FoldableContainer", p_color); + p_theme->set_color(SceneStringName(font_color), "MenuBar", p_color); + p_theme->set_color(SceneStringName(font_color), "OptionButton", p_color); + p_theme->set_color(SceneStringName(font_color), "MenuButton", p_color); + p_theme->set_color(SceneStringName(font_color), "CheckBox", p_color); + p_theme->set_color(SceneStringName(font_color), "CheckButton", p_color); + p_theme->set_color(SceneStringName(font_color), "GraphNodeTitleLabel", p_color); + p_theme->set_color(SceneStringName(font_color), "TooltipLabel", p_color); + p_theme->set_color(SceneStringName(font_color), "GraphFrameTitleLabel", p_color); + p_theme->set_color(SceneStringName(font_color), "ItemList", p_color); + p_theme->set_color(SceneStringName(font_color), "ColorButton", p_color); + p_theme->set_color("icon_normal_color", "Button", p_color); + p_theme->set_color("grabber_hovered", "SplitContainer", p_color); + p_theme->set_color("grabber_hovered", "HSplitContainer", p_color); + p_theme->set_color("grabber_hovered", "VSplitContainer", p_color); + p_theme->set_color("caret_color", "LineEdit", p_color); + p_theme->set_color("caret_color", "TextEdit", p_color); + p_theme->set_color("caret_color", "CodeEdit", p_color); + p_theme->set_color("clear_button_color", "LineEdit", p_color); + p_theme->set_color("font_unselected_color", "TabContainer", p_color); + p_theme->set_color("font_unselected_color", "TabBar", p_color); + p_theme->set_color("collapsed_font_color", "FoldableContainer", p_color); + p_theme->set_color("folder_icon_color", "FileDialog", p_color); + p_theme->set_color("file_icon_color", "FileDialog", p_color); + p_theme->set_color("title_button_color", "Tree", p_color); + p_theme->set_color("children_hl_line_color", "Tree", p_color); + p_theme->set_color("default_color", "RichTextLabel", p_color); + p_theme->set_color("up_icon_modulate", "SpinBox", p_color); + p_theme->set_color("down_icon_modulate", "SpinBox", p_color); + p_theme->set_color("button_icon_normal", "FoldableContainer", p_color); + p_color.a = 0.6; + grabber_style->set_bg_color(p_color); + p_theme->set_color("font_separator_color", "PopupMenu", p_color); + p_theme->set_color("font_accelerator_color", "PopupMenu", p_color); + p_theme->set_color("font_disabled_color", "PopupMenu", p_color); + p_theme->set_color("grabber_normal", "SplitContainer", p_color); + p_theme->set_color("grabber_normal", "HSplitContainer", p_color); + p_theme->set_color("grabber_normal", "VSplitContainer", p_color); + p_theme->set_color("font_uneditable_color", "LineEdit", p_color); + p_theme->set_color("font_readonly_color", "TextEdit", p_color); + p_theme->set_color("font_readonly_color", "CodeEdit", p_color); + p_theme->set_color("font_placeholder_color", "LineEdit", p_color); + p_theme->set_color("font_placeholder_color", "TextEdit", p_color); + p_theme->set_color("font_placeholder_color", "CodeEdit", p_color); + p_theme->set_color("relationship_line_color", "Tree", p_color); + p_theme->set_color("font_hovered_dimmed_color", "Tree", p_color); + p_color.a = 0.4; + p_theme->set_color("search_result_border_color", "TextEdit", p_color); + p_theme->set_color("search_result_border_color", "CodeEdit", p_color); + p_theme->set_color("guide_color", "Tree", p_color); + p_theme->set_color("guide_color", "ItemList", p_color); + p_theme->set_color("file_disabled_color", "FileDialog", p_color); + p_theme->set_color("font_disabled_color", "TabContainer", p_color); + p_theme->set_color("font_disabled_color", "TabBar", p_color); + p_theme->set_color("icon_disabled_color", "Button", p_color); + p_theme->set_color("font_disabled_color", "Button", p_color); + p_theme->set_color("font_disabled_color", "Tree", p_color); + p_theme->set_color("icon_disabled_color", "LinkButton", p_color); + p_theme->set_color("font_disabled_color", "MenuBar", p_color); + p_theme->set_color("font_disabled_color", "LinkButton", p_color); + p_theme->set_color("font_disabled_color", "OptionButton", p_color); + p_theme->set_color("font_disabled_color", "MenuButton", p_color); + p_theme->set_color("font_disabled_color", "CheckBox", p_color); + p_theme->set_color("font_disabled_color", "CheckButton", p_color); + p_theme->set_color("font_disabled_color", "ColorButton", p_color); + p_theme->set_color("up_disabled_icon_modulate", "SpinBox", p_color); + p_theme->set_color("down_disabled_icon_modulate", "SpinBox", p_color); + p_theme->set_color("selection_fill", "GraphEdit", p_color); + p_theme->set_color("completion_scroll_hovered_color", "CodeEdit", p_color); + p_theme->set_color("completion_scroll_color", "CodeEdit", p_color); + p_theme->set_color("button_icon_disabled", "FoldableContainer", p_color); +} + +void update_font_outline_color(Ref &p_theme, Color p_color) { + p_theme->set_color("font_separator_outline_color", "PopupMenu", p_color); + p_theme->set_color("font_outline_color", "RichTextLabel", p_color); + p_theme->set_color("font_outline_color", "FoldableContainer", p_color); + p_theme->set_color("font_outline_color", "TooltipLabel", p_color); + p_theme->set_color("font_outline_color", "ColorButton", p_color); + p_theme->set_color("font_outline_color", "TabBar", p_color); + p_theme->set_color("font_outline_color", "TabContainer", p_color); + p_theme->set_color("font_outline_color", "ItemList", p_color); + p_theme->set_color("font_outline_color", "Tree", p_color); + p_theme->set_color("font_outline_color", "GraphFrameTitleLabel", p_color); + p_theme->set_color("font_outline_color", "GraphNodeTitleLabel", p_color); + p_theme->set_color("font_outline_color", "PopupMenu", p_color); + p_theme->set_color("title_outline_modulate", "Window", p_color); + p_theme->set_color("font_outline_color", "CodeEdit", p_color); + p_theme->set_color("font_outline_color", "TextEdit", p_color); + p_theme->set_color("font_outline_color", "ProgressBar", p_color); + p_theme->set_color("font_outline_color", "LineEdit", p_color); + p_theme->set_color("font_outline_color", "Label", p_color); + p_theme->set_color("font_outline_color", "CheckButton", p_color); + p_theme->set_color("font_outline_color", "CheckBox", p_color); + p_theme->set_color("font_outline_color", "MenuButton", p_color); + p_theme->set_color("font_outline_color", "OptionButton", p_color); + p_theme->set_color("font_outline_color", "LinkButton", p_color); + p_theme->set_color("font_outline_color", "MenuBar", p_color); + p_theme->set_color("font_outline_color", "Button", p_color); +} + +void update_theme_margins(Ref &p_theme, int p_margin) { + int margin = p_margin * MAX(p_theme->get_default_base_scale(), 0.5); + + p_theme->set_constant("separation", "BoxContainer", margin); + p_theme->set_constant("separation", "HBoxContainer", margin); + p_theme->set_constant("separation", "VBoxContainer", margin); + p_theme->set_constant("h_separation", "Button", margin); + p_theme->set_constant("h_separation", "FoldableContainer", margin); + p_theme->set_constant("h_separation", "Tree", margin); + p_theme->set_constant("h_separation", "ScrollContainer", margin); + p_theme->set_constant("h_separation", "TabBar", margin); + p_theme->set_constant("h_separation", "OptionButton", margin); + p_theme->set_constant("h_separation", "MenuButton", margin); + p_theme->set_constant("h_separation", "CheckBox", margin); + p_theme->set_constant("h_separation", "CheckButton", margin); + p_theme->set_constant("h_separation", "FlowContainer", margin); + p_theme->set_constant("v_separation", "FlowContainer", margin); + p_theme->set_constant("h_separation", "HFlowContainer", margin); + p_theme->set_constant("v_separation", "HFlowContainer", margin); + p_theme->set_constant("h_separation", "VFlowContainer", margin); + p_theme->set_constant("v_separation", "VFlowContainer", margin); + p_theme->set_constant("v_separation", "ScrollContainer", margin); + p_theme->set_constant("button_margin", "Tree", margin); + p_theme->set_constant("inner_margin_left", "Tree", margin); + p_theme->set_constant("inner_margin_right", "Tree", margin); + p_theme->set_constant("separation", "HSeparator", margin); + p_theme->set_constant("separation", "VSeparator", margin); + p_theme->set_constant("scrollbar_h_separation", "Tree", margin); + p_theme->set_constant("scrollbar_v_separation", "Tree", margin); + p_theme->set_constant("h_separation", "ItemList", margin); + p_theme->set_constant("v_separation", "ItemList", margin); + p_theme->set_constant("icon_margin", "ItemList", margin); + p_theme->set_constant("h_separation", "ColorButton", margin); + p_theme->set_constant("h_separation", "GridContainer", margin); + p_theme->set_constant("v_separation", "GridContainer", margin); +} + +void update_theme_padding(Ref &p_theme, int p_padding) { + float base_scale = MAX(p_theme->get_default_base_scale(), 0.5); + int padding = p_padding * base_scale; + + tab_selected_style->set_content_margin_individual(padding, padding + base_scale * 2, padding, padding); + tab_unselected_style->set_content_margin_individual(padding, padding + base_scale * 2, padding, padding); + tab_hovered_style->set_content_margin_individual(padding, padding + base_scale * 2, padding, padding); + tab_disabled_style->set_content_margin_individual(padding, padding + base_scale * 2, padding, padding); + tab_panel_style->set_content_margin_all(padding); + progress_background_style->set_content_margin_all(padding); + graph_frame_title_style->set_content_margin_all(padding); + graph_frame_title_selected_style->set_content_margin_all(padding); + foldable_panel_style->set_content_margin_individual(12 * base_scale, padding, padding, padding); + graph_title_style->set_content_margin_individual(12 * base_scale, padding, padding, padding); + graph_title_selected_style->set_content_margin_individual(12 * base_scale, padding, padding, padding); + foldable_title_style->set_content_margin_all(padding); + foldable_title_hover_style->set_content_margin_all(padding); + foldable_title_collapsed_style->set_content_margin_all(padding); + foldable_title_collapsed_hover_style->set_content_margin_all(padding); + p_theme->set_constant("margin_left", "MarginContainer", padding); + p_theme->set_constant("margin_top", "MarginContainer", padding); + p_theme->set_constant("margin_right", "MarginContainer", padding); + p_theme->set_constant("margin_bottom", "MarginContainer", padding); + p_theme->set_constant("item_start_padding", "PopupMenu", padding); + p_theme->set_constant("item_end_padding", "PopupMenu", padding); +} + +void update_theme_corner_radius(Ref &p_theme, int p_corner_radius) { + float base_scale = MAX(p_theme->get_default_base_scale(), 0.5); + int corners = p_corner_radius * base_scale; + + panel_style->set_corner_radius_all(corners); + button_normal_style->set_corner_radius_all(corners); + button_hover_style->set_corner_radius_all(corners); + button_pressed_style->set_corner_radius_all(corners); + button_disabled_style->set_corner_radius_all(corners); + color_button_normal_style->set_corner_radius_all(corners); + color_button_hover_style->set_corner_radius_all(corners); + color_button_pressed_style->set_corner_radius_all(corners); + color_button_disabled_style->set_corner_radius_all(corners); + color_picker_button_hovered_style->set_corner_radius_all(corners); + color_picker_button_normal_style->set_corner_radius_all(corners); + color_picker_button_pressed_style->set_corner_radius_all(corners); + color_picker_button_disabled_style->set_corner_radius_all(corners); + grabber_style->set_corner_radius_all(corners); + grabber_highlight_style->set_corner_radius_all(corners); + slider_style->set_corner_radius_all(corners); + picker_slider_style->set_corner_radius_all(corners); + h_scroll_style->set_corner_radius_all(corners); + v_scroll_style->set_corner_radius_all(corners); + foldable_title_collapsed_style->set_corner_radius_all(corners); + swatches_foldable_title_collapsed_style->set_corner_radius_all(corners); + foldable_title_collapsed_hover_style->set_corner_radius_all(corners); + swatches_foldable_title_collapsed_hover_style->set_corner_radius_all(corners); + menu_button_normal_style->set_corner_radius_individual(corners, corners, 0, 0); + menu_button_hover_style->set_corner_radius_individual(corners, corners, 0, 0); + menu_button_pressed_style->set_corner_radius_individual(corners, corners, 0, 0); + menu_button_disabled_style->set_corner_radius_individual(corners, corners, 0, 0); + foldable_panel_style->set_corner_radius_individual(0, 0, corners, corners); + swatches_foldable_panel_style->set_corner_radius_individual(0, 0, corners, corners); + foldable_title_style->set_corner_radius_individual(corners, corners, 0, 0); + swatches_foldable_title_style->set_corner_radius_individual(corners, corners, 0, 0); + foldable_title_hover_style->set_corner_radius_individual(corners, corners, 0, 0); + swatches_foldable_title_hover_style->set_corner_radius_individual(corners, corners, 0, 0); + graph_panel_style->set_corner_radius_individual(0, 0, corners, corners); + graph_panel_selected_style->set_corner_radius_individual(0, 0, corners, corners); + graph_title_style->set_corner_radius_individual(corners, corners, 0, 0); + graph_frame_title_style->set_corner_radius_individual(corners, corners, 0, 0); + graph_title_selected_style->set_corner_radius_individual(corners, corners, 0, 0); + graph_frame_title_selected_style->set_corner_radius_individual(corners, corners, 0, 0); + + int focus_border = MAX(p_corner_radius - 2, 0) * base_scale; + button_focus_style->set_corner_radius_all(focus_border); + color_button_focus_style->set_corner_radius_all(focus_border); + menu_button_focus_style->set_corner_radius_individual(focus_border, focus_border, 0, 0); +} + +void update_theme_border_width(Ref &p_theme, int p_border_width) { + int border_width = p_border_width * MAX(p_theme->get_default_base_scale(), 0.5); + + panel_style->set_border_width_all(border_width); + popup_panel_style->set_content_margin_all(MAX(border_width, 1)); + button_focus_style->set_border_width_all(MAX(border_width, 1)); + menu_button_focus_style->set_border_width_all(MAX(border_width, 1)); +} + +void update_theme_border_padding(Ref &p_theme, int p_border_padding) { + int border_padding = p_border_padding * MAX(p_theme->get_default_base_scale(), 0.5); + + panel_style->set_content_margin_all(border_padding); + button_normal_style->set_content_margin_all(border_padding); + button_hover_style->set_content_margin_all(border_padding); + button_pressed_style->set_content_margin_all(border_padding); + button_disabled_style->set_content_margin_all(border_padding); + menu_button_normal_style->set_content_margin_all(border_padding); + menu_button_hover_style->set_content_margin_all(border_padding); + menu_button_pressed_style->set_content_margin_all(border_padding); + menu_button_disabled_style->set_content_margin_all(border_padding); + flat_button_normal->set_content_margin_all(border_padding); + p_theme->set_constant("arrow_margin", "OptionButton", border_padding); +} + +void update_font_outline_size(Ref &p_theme, int p_outline_size) { + int outline_size = p_outline_size * MAX(p_theme->get_default_base_scale(), 0.5); + + p_theme->set_constant("separator_outline_size", "PopupMenu", outline_size); + p_theme->set_constant("outline_size", "RichTextLabel", outline_size); + p_theme->set_constant("outline_size", "FoldableContainer", outline_size); + p_theme->set_constant("outline_size", "TooltipLabel", outline_size); + p_theme->set_constant("outline_size", "TabBar", outline_size); + p_theme->set_constant("outline_size", "TabContainer", outline_size); + p_theme->set_constant("outline_size", "ItemList", outline_size); + p_theme->set_constant("outline_size", "Tree", outline_size); + p_theme->set_constant("outline_size", "GraphFrameTitleLabel", outline_size); + p_theme->set_constant("outline_size", "GraphNodeTitleLabel", outline_size); + p_theme->set_constant("outline_size", "PopupMenu", outline_size); + p_theme->set_constant("title_outline_size", "Window", outline_size); + p_theme->set_constant("outline_size", "CodeEdit", outline_size); + p_theme->set_constant("outline_size", "TextEdit", outline_size); + p_theme->set_constant("outline_size", "ProgressBar", outline_size); + p_theme->set_constant("outline_size", "LineEdit", outline_size); + p_theme->set_constant("outline_size", "Label", outline_size); + p_theme->set_constant("outline_size", "CheckButton", outline_size); + p_theme->set_constant("outline_size", "CheckBox", outline_size); + p_theme->set_constant("outline_size", "MenuButton", outline_size); + p_theme->set_constant("outline_size", "OptionButton", outline_size); + p_theme->set_constant("outline_size", "LinkButton", outline_size); + p_theme->set_constant("outline_size", "MenuBar", outline_size); + p_theme->set_constant("outline_size", "Button", outline_size); +} + +void update_font_size(Ref &p_theme, int p_font_size) { + float base_scale = MAX(p_theme->get_default_base_scale(), 0.5); + int font_size = p_font_size * base_scale; + + p_theme->set_default_font_size(font_size); + + p_theme->set_font_size(SceneStringName(font_size), "HeaderSmall", font_size + 4 * base_scale); + p_theme->set_font_size(SceneStringName(font_size), "HeaderMedium", font_size + 8 * base_scale); + p_theme->set_font_size(SceneStringName(font_size), "GraphFrameTitleLabel", font_size + 8 * base_scale); + p_theme->set_font_size(SceneStringName(font_size), "HeaderLarge", font_size + 12 * base_scale); +} + +void update_font_embolden(float p_embolden) { + if (custom_font.is_valid() && !using_custom_font_variation) { + custom_font->set_variation_embolden(p_embolden); + } + fallback_font->set_variation_embolden(p_embolden); + bold_font->set_variation_embolden(p_embolden + 0.2); + bold_italics_font->set_variation_embolden(p_embolden + 0.2); + italics_font->set_variation_embolden(p_embolden); +} + +void update_font_spacing_glyph(int p_spacing) { + if (custom_font.is_valid() && !using_custom_font_variation) { + custom_font->set_spacing(TextServer::SPACING_GLYPH, p_spacing); + } + fallback_font->set_spacing(TextServer::SPACING_GLYPH, p_spacing); + bold_font->set_spacing(TextServer::SPACING_GLYPH, p_spacing); + bold_italics_font->set_spacing(TextServer::SPACING_GLYPH, p_spacing); + italics_font->set_spacing(TextServer::SPACING_GLYPH, p_spacing); +} + +void update_font_spacing_space(int p_spacing) { + if (custom_font.is_valid() && !using_custom_font_variation) { + custom_font->set_spacing(TextServer::SPACING_SPACE, p_spacing); + } + fallback_font->set_spacing(TextServer::SPACING_SPACE, p_spacing); + bold_font->set_spacing(TextServer::SPACING_SPACE, p_spacing); + bold_italics_font->set_spacing(TextServer::SPACING_SPACE, p_spacing); + italics_font->set_spacing(TextServer::SPACING_SPACE, p_spacing); +} + +void update_font_spacing_top(int p_spacing) { + if (custom_font.is_valid() && !using_custom_font_variation) { + custom_font->set_spacing(TextServer::SPACING_TOP, p_spacing); + } + fallback_font->set_spacing(TextServer::SPACING_TOP, p_spacing); + bold_italics_font->set_spacing(TextServer::SPACING_TOP, p_spacing); + bold_font->set_spacing(TextServer::SPACING_TOP, p_spacing); + italics_font->set_spacing(TextServer::SPACING_TOP, p_spacing); +} + +void update_font_spacing_bottom(int p_spacing) { + if (custom_font.is_valid() && !using_custom_font_variation) { + custom_font->set_spacing(TextServer::SPACING_BOTTOM, p_spacing); + } + fallback_font->set_spacing(TextServer::SPACING_BOTTOM, p_spacing); + bold_font->set_spacing(TextServer::SPACING_BOTTOM, p_spacing); + bold_italics_font->set_spacing(TextServer::SPACING_BOTTOM, p_spacing); + italics_font->set_spacing(TextServer::SPACING_BOTTOM, p_spacing); +} + +void update_theme_scale(Ref &p_theme) { + float base_scale = MAX(p_theme->get_default_base_scale(), 0.5); + int int_scale = MAX(Math::floor(base_scale), 1); + int x2_scale = 2 * base_scale; + int x4_scale = 4 * base_scale; + int x6_scale = 6 * base_scale; + + popup_panel_style->set_border_width_all(int_scale); + color_picker_popup_panel_style->set_border_width_all(int_scale); + p_theme->set_constant("children_hl_line_width", "Tree", int_scale); + p_theme->set_constant("shadow_offset_x", "Label", int_scale); + p_theme->set_constant("shadow_offset_y", "Label", int_scale); + p_theme->set_constant("shadow_outline_size", "Label", int_scale); + p_theme->set_constant("shadow_offset_x", "GraphNodeTitleLabel", int_scale); + p_theme->set_constant("shadow_offset_y", "GraphNodeTitleLabel", int_scale); + p_theme->set_constant("shadow_outline_size", "GraphNodeTitleLabel", int_scale); + p_theme->set_constant("shadow_offset_x", "GraphFrameTitleLabel", int_scale); + p_theme->set_constant("shadow_offset_y", "GraphFrameTitleLabel", int_scale); + p_theme->set_constant("shadow_outline_size", "GraphFrameTitleLabel", int_scale); + p_theme->set_constant("shadow_offset_x", "TooltipLabel", int_scale); + p_theme->set_constant("shadow_offset_y", "TooltipLabel", int_scale); + p_theme->set_constant("shadow_offset_x", "RichTextLabel", int_scale); + p_theme->set_constant("shadow_offset_y", "RichTextLabel", int_scale); + p_theme->set_constant("shadow_outline_size", "RichTextLabel", int_scale); + p_theme->set_constant("caret_width", "LineEdit", int_scale); + p_theme->set_constant("caret_width", "TextEdit", int_scale); + p_theme->set_constant("relationship_line_width", "Tree", int_scale); + p_theme->set_constant("parent_hl_line_width", "Tree", 2 * int_scale); + p_theme->set_constant("indent", "PopupMenu", 10 * base_scale); + p_theme->set_constant("buttons_separation", "AcceptDialog", 10 * base_scale); + p_theme->set_constant("scroll_speed", "Tree", 12 * base_scale); + p_theme->set_constant("item_margin", "Tree", 16 * base_scale); + p_theme->set_constant("buttons_width", "SpinBox", 16 * base_scale); + p_theme->set_constant("close_h_offset", "Window", 18 * base_scale); + p_theme->set_constant("port_hotzone_inner_extent", "GraphEdit", 22 * base_scale); + p_theme->set_constant("close_v_offset", "Window", 24 * base_scale); + p_theme->set_constant("port_hotzone_outer_extent", "GraphEdit", 26 * base_scale); + p_theme->set_constant("h_width", "ColorPicker", 30 * base_scale); + p_theme->set_constant("sample_height", "ColorPicker", 30 * base_scale); + p_theme->set_constant("swatch_size", "ColorPicker", 32 * base_scale); + p_theme->set_constant("title_height", "Window", 36 * base_scale); + p_theme->set_constant("completion_max_width", "CodeEdit", 50 * base_scale); + p_theme->set_constant("sv_width", "ColorPicker", 256 * base_scale); + p_theme->set_constant("sv_height", "ColorPicker", 256 * base_scale); + + picker_slider_style->set_content_margin(SIDE_TOP, 16 * base_scale); + tab_selected_style->set_border_width(SIDE_TOP, x2_scale); + color_button_focus_style->set_border_width_all(x2_scale); + tab_focus_style->set_border_width_all(x2_scale); + h_separator_style->set_thickness(x2_scale); + v_separator_style->set_thickness(x2_scale); + slider_style->set_content_margin_all(x2_scale); + p_theme->set_constant("line_spacing", "Label", x2_scale); + p_theme->set_constant("line_spacing", "GraphNodeTitleLabel", x2_scale); + p_theme->set_constant("line_spacing", "GraphFrameTitleLabel", x2_scale); + p_theme->set_constant("underline_spacing", "LinkButton", x2_scale); + p_theme->set_constant("field_and_buttons_separation", "SpinBox", x2_scale); + p_theme->set_constant("icon_separation", "TabContainer", x2_scale); + p_theme->set_constant("text_highlight_h_padding", "RichTextLabel", x2_scale); + p_theme->set_constant("text_highlight_v_padding", "RichTextLabel", x2_scale); + p_theme->set_constant("separation", "GraphNode", x2_scale); + p_theme->set_constant(SceneStringName(line_separation), "ItemList", x2_scale); + p_theme->set_constant("table_h_separation", "RichTextLabel", x2_scale); + p_theme->set_constant("table_v_separation", "RichTextLabel", x2_scale); + graph_panel_style->set_border_width(SIDE_LEFT, x2_scale); + graph_panel_style->set_border_width(SIDE_RIGHT, x2_scale); + graph_panel_style->set_border_width(SIDE_BOTTOM, x2_scale); + graph_panel_selected_style->set_border_width(SIDE_LEFT, x2_scale); + graph_panel_selected_style->set_border_width(SIDE_RIGHT, x2_scale); + graph_panel_selected_style->set_border_width(SIDE_BOTTOM, x2_scale); + graph_title_style->set_border_width(SIDE_LEFT, x2_scale); + graph_title_style->set_border_width(SIDE_RIGHT, x2_scale); + graph_title_style->set_border_width(SIDE_TOP, x2_scale); + graph_frame_title_style->set_border_width(SIDE_LEFT, x2_scale); + graph_frame_title_style->set_border_width(SIDE_RIGHT, x2_scale); + graph_frame_title_style->set_border_width(SIDE_TOP, x2_scale); + graph_title_selected_style->set_border_width(SIDE_LEFT, x2_scale); + graph_title_selected_style->set_border_width(SIDE_RIGHT, x2_scale); + graph_title_selected_style->set_border_width(SIDE_TOP, x2_scale); + graph_frame_title_selected_style->set_border_width(SIDE_LEFT, x2_scale); + graph_frame_title_selected_style->set_border_width(SIDE_RIGHT, x2_scale); + graph_frame_title_selected_style->set_border_width(SIDE_TOP, x2_scale); + color_mode_button_pressed_style->set_border_width(SIDE_TOP, x2_scale); + color_sliders_panel_style->set_content_margin_all(x2_scale); + + h_scroll_style->set_content_margin_individual(0, x4_scale, 0, x4_scale); + v_scroll_style->set_content_margin_individual(x4_scale, 0, x4_scale, 0); + color_button_pressed_style->set_border_width_all(x4_scale); + swatches_foldable_panel_style->set_content_margin_all(x4_scale); + swatches_foldable_title_style->set_content_margin_all(x4_scale); + swatches_foldable_title_hover_style->set_content_margin_all(x4_scale); + swatches_foldable_title_collapsed_style->set_content_margin_all(x4_scale); + swatches_foldable_title_collapsed_hover_style->set_content_margin_all(x4_scale); + color_mode_button_hovered_style->set_content_margin_all(x4_scale); + color_mode_button_normal_style->set_content_margin_all(x4_scale); + color_mode_button_pressed_style->set_content_margin_all(x4_scale); + color_picker_button_hovered_style->set_content_margin_all(x4_scale); + color_picker_button_normal_style->set_content_margin_all(x4_scale); + color_picker_button_pressed_style->set_content_margin_all(x4_scale); + color_picker_button_disabled_style->set_content_margin_all(x4_scale); + p_theme->set_constant("h_separation", "SwatchesFoldableContainer", x4_scale); + p_theme->set_constant("grabber_thickness", "SplitContainer", x4_scale); + p_theme->set_constant("grabber_thickness", "HSplitContainer", x4_scale); + p_theme->set_constant("grabber_thickness", "VSplitContainer", x4_scale); + p_theme->set_constant("line_spacing", "TextEdit", x4_scale); + p_theme->set_constant("line_spacing", "CodeEdit", x4_scale); + p_theme->set_constant("h_separation", "PopupMenu", x4_scale); + p_theme->set_constant("v_separation", "PopupMenu", x4_scale); + p_theme->set_constant("v_separation", "Tree", x4_scale); + p_theme->set_constant("h_separation", "MenuBar", x4_scale); + p_theme->set_constant("scroll_border", "Tree", x4_scale); + p_theme->set_constant("resize_margin", "Window", x4_scale); + p_theme->set_constant("drop_mark_width", "TabContainer", x4_scale); + p_theme->set_constant("drop_mark_width", "TabBar", x4_scale); + p_theme->set_constant("h_separation", "ColorPickerGrid", x4_scale); + p_theme->set_constant("v_separation", "ColorPickerGrid", x4_scale); + + color_button_normal_style->set_content_margin_all(x6_scale); + color_button_hover_style->set_content_margin_all(x6_scale); + color_button_pressed_style->set_content_margin_all(x6_scale); + color_button_disabled_style->set_content_margin_all(x6_scale); + color_picker_popup_panel_style->set_content_margin_all(x6_scale); + p_theme->set_constant("minimum_grab_thickness", "SplitContainer", x6_scale); + p_theme->set_constant("minimum_grab_thickness", "HSplitContainer", x6_scale); + p_theme->set_constant("minimum_grab_thickness", "VSplitContainer", x6_scale); + p_theme->set_constant("separation", "ColorPickerVBox", x6_scale); + p_theme->set_constant("separation", "ColorPickerHBox", x6_scale); + p_theme->set_constant("separation", "SplitContainer", x6_scale); + p_theme->set_constant("separation", "HSplitContainer", x6_scale); + p_theme->set_constant("separation", "VSplitContainer", x6_scale); +} + +void update_theme_colors(Ref &p_theme, Color p_base_color, Color p_accent_color, float p_contrast, float p_base2_contrast, float p_base3_contrast, float p_base4_contrast, float p_accent2_contrast, float p_bg_contrast) { + Color contrasted_color = contrast_color(p_base_color, p_contrast); + Color base_color2 = p_base_color.lerp(contrasted_color, p_base2_contrast); + Color base_color3 = p_base_color.lerp(contrasted_color, p_base3_contrast); + Color base_color4 = p_base_color.lerp(contrasted_color, p_base4_contrast); + Color accent_color2 = p_accent_color.lerp(p_base_color, p_accent2_contrast); + Color bg_color = p_base_color.lerp(contrasted_color, p_bg_contrast); + + button_pressed_style->set_bg_color(p_base_color); + color_button_pressed_style->set_bg_color(p_base_color); + color_picker_button_pressed_style->set_bg_color(p_base_color); + menu_button_pressed_style->set_bg_color(p_base_color); + tab_selected_style->set_border_color(p_accent_color); + color_mode_button_pressed_style->set_border_color(p_accent_color); + tab_focus_style->set_border_color(p_accent_color); + graph_panel_selected_style->set_border_color(p_accent_color); + graph_frame_title_selected_style->set_border_color(p_accent_color); + graph_title_selected_style->set_border_color(p_accent_color); + button_focus_style->set_bg_color(p_accent_color); + color_button_focus_style->set_bg_color(p_accent_color); + button_focus_style->set_border_color(p_accent_color); + color_button_focus_style->set_border_color(p_accent_color); + menu_button_focus_style->set_bg_color(p_accent_color); + menu_button_focus_style->set_border_color(p_accent_color); + progress_fill_style->set_bg_color(p_accent_color); + grabber_highlight_style->set_bg_color(p_accent_color); + p_theme->set_color("drop_mark_color", "TabContainer", p_accent_color); + p_theme->set_color("drop_mark_color", "TabBar", p_accent_color); + p_theme->set_color("icon_pressed_color", "Button", p_accent_color); + p_theme->set_color("icon_hover_pressed_color", "Button", p_accent_color); + p_theme->set_color("font_pressed_color", "Button", p_accent_color); + p_theme->set_color("font_pressed_color", "LinkButton", p_accent_color); + p_theme->set_color("font_hover_pressed_color", "Button", p_accent_color); + p_theme->set_color("font_hover_pressed_color", "LinkButton", p_accent_color); + p_theme->set_color("grabber_pressed", "SplitContainer", p_accent_color); + p_theme->set_color("grabber_pressed", "HSplitContainer", p_accent_color); + p_theme->set_color("grabber_pressed", "VSplitContainer", p_accent_color); + p_theme->set_color("clear_button_color_pressed", "LineEdit", p_accent_color); + p_theme->set_color("font_pressed_color", "MenuBar", p_accent_color); + p_theme->set_color("font_pressed_color", "OptionButton", p_accent_color); + p_theme->set_color("font_pressed_color", "MenuButton", p_accent_color); + p_theme->set_color("font_pressed_color", "CheckBox", p_accent_color); + p_theme->set_color("font_hover_pressed_color", "CheckBox", p_accent_color); + p_theme->set_color("font_pressed_color", "CheckButton", p_accent_color); + p_theme->set_color("font_hover_pressed_color", "CheckButton", p_accent_color); + p_theme->set_color("down_pressed_icon_modulate", "SpinBox", p_accent_color); + p_theme->set_color("up_pressed_icon_modulate", "SpinBox", p_accent_color); + p_theme->set_color("selection_stroke", "GraphEdit", p_accent_color); + p_theme->set_color("button_icon_pressed", "FoldableContainer", p_accent_color); + p_theme->set_color("word_highlighted_color", "TextEdit", base_color4); + p_theme->set_color("word_highlighted_color", "CodeEdit", base_color4); + p_theme->set_color("current_line_color", "TextEdit", bg_color); + p_theme->set_color("current_line_color", "CodeEdit", bg_color); + p_theme->set_color("search_result_color", "TextEdit", accent_color2); + p_theme->set_color("search_result_color", "CodeEdit", accent_color2); + p_theme->set_color("selection_color", "LineEdit", base_color3); + p_theme->set_color("selection_color", "TextEdit", base_color3); + p_theme->set_color("selection_color", "CodeEdit", base_color3); + p_theme->set_color("selection_color", "RichTextLabel", base_color3); + popup_panel_style->set_bg_color(base_color3); + color_picker_popup_panel_style->set_bg_color(base_color3); + button_hover_style->set_bg_color(base_color2); + color_button_hover_style->set_bg_color(base_color2); + tab_hovered_style->set_bg_color(base_color2); + color_mode_button_hovered_style->set_bg_color(base_color2); + color_picker_button_hovered_style->set_bg_color(base_color2); + menu_button_hover_style->set_bg_color(base_color2); + slider_style->set_bg_color(base_color2); + picker_slider_style->set_bg_color(base_color2); + foldable_title_hover_style->set_bg_color(base_color2); + swatches_foldable_title_hover_style->set_bg_color(base_color2); + foldable_title_collapsed_hover_style->set_bg_color(base_color2); + swatches_foldable_title_collapsed_hover_style->set_bg_color(base_color2); + panel_style->set_bg_color(bg_color); + graph_panel_style->set_bg_color(bg_color); + graph_panel_selected_style->set_bg_color(bg_color); + embedded_style->set_bg_color(base_color3); + embedded_unfocused_style->set_bg_color(base_color4); + tab_panel_style->set_bg_color(base_color3); + color_sliders_panel_style->set_bg_color(base_color3); + tab_selected_style->set_bg_color(base_color3); + color_mode_button_pressed_style->set_bg_color(base_color3); + popup_hover_style->set_bg_color(base_color2); + progress_background_style->set_bg_color(base_color3); + foldable_panel_style->set_bg_color(base_color3); + swatches_foldable_panel_style->set_bg_color(base_color3); + tab_unselected_style->set_bg_color(base_color4); + button_normal_style->set_bg_color(base_color4); + color_button_normal_style->set_bg_color(base_color4); + color_mode_button_normal_style->set_bg_color(base_color4); + color_picker_button_normal_style->set_bg_color(base_color4); + menu_button_normal_style->set_bg_color(base_color4); + h_scroll_style->set_bg_color(base_color4); + v_scroll_style->set_bg_color(base_color4); + foldable_title_style->set_bg_color(base_color4); + swatches_foldable_title_style->set_bg_color(base_color4); + foldable_title_collapsed_style->set_bg_color(base_color4); + swatches_foldable_title_collapsed_style->set_bg_color(base_color4); + graph_title_style->set_bg_color(base_color4); + graph_frame_title_style->set_bg_color(base_color4); + graph_title_selected_style->set_bg_color(p_base_color); + graph_frame_title_selected_style->set_bg_color(p_base_color); + Color transparent_base_color4 = base_color4; + transparent_base_color4.a = 0.4; + tab_disabled_style->set_bg_color(transparent_base_color4); + button_disabled_style->set_bg_color(transparent_base_color4); + color_button_disabled_style->set_bg_color(transparent_base_color4); + color_picker_button_disabled_style->set_bg_color(transparent_base_color4); + menu_button_disabled_style->set_bg_color(transparent_base_color4); + + float v = p_base_color.get_luminance() <= 0.5 ? 1.f : 0.f; + p_theme->set_color("grid_minor", "GraphEdit", Color(v, v, v, 0.05)); + p_theme->set_color("grid_major", "GraphEdit", Color(v, v, v, 0.2)); + p_theme->set_color("activity", "GraphEdit", Color(v, v, v)); + p_theme->set_color("connection_hover_tint_color", "GraphEdit", Color(1.f - v, 1.f - v, 1.f - v, 0.3)); + p_theme->set_color("connection_valid_target_tint_color", "GraphEdit", Color(v, v, v, 0.4)); +} + +void update_theme_font(Ref &p_theme, Ref p_font) { + if (p_font.is_valid()) { + if (p_font->is_class("FontVariation")) { + custom_font = p_font; + using_custom_font_variation = true; + + Ref base_font = custom_font->get_base_font(); + bold_font->set_base_font(base_font); + bold_italics_font->set_base_font(base_font); + italics_font->set_base_font(base_font); + } else { + custom_font = ThemeDB::get_singleton()->get_fallback_font()->duplicate(); + custom_font->set_base_font(p_font); + using_custom_font_variation = false; + + bold_font->set_base_font(p_font); + bold_italics_font->set_base_font(p_font); + italics_font->set_base_font(p_font); + } + p_theme->set_default_font(custom_font); + + } else { + if (custom_font.is_valid()) { + custom_font = Ref(); + using_custom_font_variation = false; + + Ref base_font = fallback_font->get_base_font(); + bold_font->set_base_font(base_font); + bold_italics_font->set_base_font(base_font); + italics_font->set_base_font(base_font); + } + p_theme->set_default_font(Ref()); + } +} + +void update_font_subpixel_positioning(TextServer::SubpixelPositioning p_font_subpixel_positioning) { + Ref base_font = fallback_font->get_base_font(); + base_font->set_subpixel_positioning(p_font_subpixel_positioning); +} + +void update_font_antialiasing(TextServer::FontAntialiasing p_font_antialiasing) { + Ref base_font = fallback_font->get_base_font(); + base_font->set_antialiasing(p_font_antialiasing); +} + +void update_font_lcd_subpixel_layout(TextServer::FontLCDSubpixelLayout p_font_lcd_subpixel_layout) { + Ref base_font = fallback_font->get_base_font(); + base_font->set_lcd_subpixel_layout(p_font_lcd_subpixel_layout); +} + +void update_font_hinting(TextServer::Hinting p_font_hinting) { + Ref base_font = fallback_font->get_base_font(); + base_font->set_hinting(p_font_hinting); +} + +void update_font_msdf(bool p_font_msdf) { + Ref base_font = fallback_font->get_base_font(); + base_font->set_multichannel_signed_distance_field(p_font_msdf); +} + +void update_font_generate_mipmaps(bool p_font_generate_mipmaps) { + Ref base_font = fallback_font->get_base_font(); + base_font->set_generate_mipmaps(p_font_generate_mipmaps); +} + +void make_default_theme(Ref p_font, float p_scale, TextServer::SubpixelPositioning p_font_subpixel, TextServer::Hinting p_font_hinting, TextServer::FontAntialiasing p_font_antialiasing, TextServer::FontLCDSubpixelLayout p_font_lcd_subpixel_layout, bool p_font_msdf, bool p_font_generate_mipmaps, Color p_base_color, Color p_accent_color, Color p_font_color, Color p_font_outline_color, float p_contrast, float p_base2_contrast, float p_base3_contrast, float p_base4_contrast, float p_accent2_contrast, float p_bg_contrast, int p_margin, int p_padding, int p_border_width, int p_corner_radius, int p_font_size, int p_font_outline, float p_font_embolden, int p_font_spacing_glyph, int p_font_spacing_space, int p_font_spacing_top, int p_font_spacing_bottom) { + float scale = CLAMP(p_scale, 0.5, 8.0); + + Ref t; + t.instantiate(); + + Ref base_font; + base_font.instantiate(); + base_font->set_data_ptr(_font_OpenSans_SemiBold, _font_OpenSans_SemiBold_size); + + fallback_font.instantiate(); + fallback_font->set_base_font(base_font); + + ThemeDB::get_singleton()->set_fallback_font(fallback_font); + + bold_font.instantiate(); + bold_italics_font.instantiate(); + italics_font.instantiate(); + + bold_italics_font->set_variation_transform(Transform2D(1.0, 0.2, 0.0, 1.0, 0.0, 0.0)); + italics_font->set_variation_transform(Transform2D(1.0, 0.2, 0.0, 1.0, 0.0, 0.0)); + + t->set_default_base_scale(scale); + + t->set_type_variation("FlatButton", "Button"); + t->set_type_variation("FlatMenuButton", "MenuButton"); + t->set_type_variation("GraphNodeTitleLabel", "Label"); + t->set_type_variation("GraphFrameTitleLabel", "Label"); + t->set_type_variation("TooltipPanel", "PopupPanel"); + t->set_type_variation("TooltipLabel", "Label"); + t->set_type_variation("FlatPanel", "PanelContainer"); + t->set_type_variation("HeaderSmall", "Label"); + t->set_type_variation("HeaderMedium", "Label"); + t->set_type_variation("HeaderLarge", "Label"); + t->set_type_variation("PickerHSlider", "HSlider"); + t->set_type_variation("PickerModeButton", "Button"); + t->set_type_variation("PickerSlidersPanel", "PanelContainer"); + t->set_type_variation("PickerButton", "Button"); + t->set_type_variation("PickerMenuButton", "MenuButton"); + t->set_type_variation("PickerLineEdit", "LineEdit"); + t->set_type_variation("ColorPickerHBox", "HBoxContainer"); + t->set_type_variation("ColorPickerVBox", "VBoxContainer"); + t->set_type_variation("ColorPickerGrid", "GridContainer"); + t->set_type_variation("SwatchesFoldableContainer", "FoldableContainer"); + + Ref empty_style(memnew(StyleBoxEmpty)); + + panel_style.instantiate(); + popup_panel_style.instantiate(); + color_picker_popup_panel_style.instantiate(); + tab_panel_style.instantiate(); + color_sliders_panel_style.instantiate(); + tab_selected_style.instantiate(); + tab_unselected_style.instantiate(); + tab_hovered_style.instantiate(); + tab_disabled_style.instantiate(); + tab_focus_style.instantiate(); + button_normal_style.instantiate(); + button_hover_style.instantiate(); + button_pressed_style.instantiate(); + button_disabled_style.instantiate(); + button_focus_style.instantiate(); + color_button_normal_style.instantiate(); + color_button_hover_style.instantiate(); + color_button_pressed_style.instantiate(); + color_button_disabled_style.instantiate(); + color_button_focus_style.instantiate(); + menu_button_normal_style.instantiate(); + menu_button_hover_style.instantiate(); + menu_button_pressed_style.instantiate(); + menu_button_disabled_style.instantiate(); + menu_button_focus_style.instantiate(); + popup_hover_style.instantiate(); + progress_background_style.instantiate(); + progress_fill_style.instantiate(); + grabber_style.instantiate(); + grabber_highlight_style.instantiate(); + slider_style.instantiate(); + picker_slider_style.instantiate(); + h_scroll_style.instantiate(); + v_scroll_style.instantiate(); + foldable_panel_style.instantiate(); + foldable_title_style.instantiate(); + foldable_title_collapsed_style.instantiate(); + foldable_title_hover_style.instantiate(); + foldable_title_collapsed_hover_style.instantiate(); + swatches_foldable_panel_style.instantiate(); + swatches_foldable_title_style.instantiate(); + swatches_foldable_title_collapsed_style.instantiate(); + swatches_foldable_title_hover_style.instantiate(); + swatches_foldable_title_collapsed_hover_style.instantiate(); + h_separator_style.instantiate(); + v_separator_style.instantiate(); + flat_button_normal.instantiate(); + embedded_style.instantiate(); + embedded_unfocused_style.instantiate(); + graph_title_style.instantiate(); + graph_frame_title_style.instantiate(); + graph_frame_title_selected_style.instantiate(); + graph_title_selected_style.instantiate(); + graph_panel_style.instantiate(); + graph_panel_selected_style.instantiate(); + color_mode_button_normal_style.instantiate(); + color_mode_button_hovered_style.instantiate(); + color_mode_button_pressed_style.instantiate(); + color_picker_button_normal_style.instantiate(); + color_picker_button_hovered_style.instantiate(); + color_picker_button_pressed_style.instantiate(); + color_picker_button_disabled_style.instantiate(); + + update_theme_font(t, p_font); + update_font_color(t, p_font_color); + update_font_size(t, p_font_size); + update_font_outline_color(t, p_font_outline_color); + update_theme_margins(t, p_margin); + update_theme_padding(t, p_padding); + update_theme_corner_radius(t, p_corner_radius); + update_theme_border_width(t, p_border_width); + update_font_outline_size(t, p_font_outline); + update_theme_border_padding(t, p_border_width + p_padding); + update_theme_scale(t); + update_theme_colors(t, p_base_color, p_accent_color, p_contrast, p_base2_contrast, p_base3_contrast, p_base4_contrast, p_accent2_contrast, p_bg_contrast); + update_theme_icons(t, p_font_color, p_accent_color); + update_font_embolden(p_font_embolden); + update_font_spacing_glyph(p_font_spacing_glyph); + update_font_spacing_space(p_font_spacing_space); + update_font_spacing_top(p_font_spacing_top); + update_font_spacing_bottom(p_font_spacing_bottom); + update_font_subpixel_positioning(p_font_subpixel); + update_font_lcd_subpixel_layout(p_font_lcd_subpixel_layout); + update_font_antialiasing(p_font_antialiasing); + update_font_hinting(p_font_hinting); + update_font_msdf(p_font_msdf); + update_font_generate_mipmaps(p_font_generate_mipmaps); + + t->set_stylebox(SceneStringName(panel), "Panel", panel_style); + t->set_stylebox(SceneStringName(panel), "PanelContainer", panel_style); + t->set_stylebox(SceneStringName(panel), "PopupMenu", popup_panel_style); + t->set_stylebox(SceneStringName(panel), "PopupPanel", popup_panel_style); + t->set_stylebox(SceneStringName(panel), "AcceptDialog", popup_panel_style); + t->set_stylebox(SceneStringName(panel), "TabContainer", tab_panel_style); + t->set_stylebox(SceneStringName(panel), "PickerSlidersPanel", color_sliders_panel_style); + t->set_stylebox(CoreStringName(normal), "PickerModeButton", color_mode_button_normal_style); + t->set_stylebox(SceneStringName(pressed), "PickerModeButton", color_mode_button_pressed_style); + t->set_stylebox("hover_pressed", "PickerModeButton", color_mode_button_pressed_style); + t->set_stylebox("hover", "PickerModeButton", color_mode_button_hovered_style); + t->set_stylebox("disabled", "PickerModeButton", empty_style); + t->set_stylebox("focus", "PickerModeButton", tab_focus_style); + t->set_stylebox("tab_selected", "TabContainer", tab_selected_style); + t->set_stylebox("tab_unselected", "TabContainer", tab_unselected_style); + t->set_stylebox("tab_hovered", "TabContainer", tab_unselected_style); + t->set_stylebox("tab_disabled", "TabContainer", tab_disabled_style); + t->set_stylebox("tab_focus", "TabContainer", tab_focus_style); + t->set_stylebox("tab_selected", "TabBar", tab_selected_style); + t->set_stylebox("tab_unselected", "TabBar", tab_unselected_style); + t->set_stylebox("tab_hovered", "TabBar", tab_unselected_style); + t->set_stylebox("tab_disabled", "TabBar", tab_disabled_style); + t->set_stylebox("tab_focus", "TabBar", tab_focus_style); + t->set_stylebox(CoreStringName(normal), "Button", button_normal_style); + t->set_stylebox("hover", "Button", button_hover_style); + t->set_stylebox(SceneStringName(pressed), "Button", button_pressed_style); + t->set_stylebox("hover_pressed", "Button", button_pressed_style); + t->set_stylebox("disabled", "Button", button_disabled_style); + t->set_stylebox("focus", "Button", button_focus_style); + t->set_stylebox(CoreStringName(normal), "LineEdit", button_normal_style); + t->set_stylebox("read_only", "LineEdit", button_disabled_style); + t->set_stylebox("focus", "LineEdit", button_focus_style); + t->set_stylebox(CoreStringName(normal), "TextEdit", button_normal_style); + t->set_stylebox("read_only", "TextEdit", button_disabled_style); + t->set_stylebox("focus", "TextEdit", button_focus_style); + t->set_stylebox(CoreStringName(normal), "MenuButton", menu_button_normal_style); + t->set_stylebox("hover", "MenuButton", menu_button_hover_style); + t->set_stylebox(SceneStringName(pressed), "MenuButton", menu_button_pressed_style); + t->set_stylebox("hover_pressed", "MenuButton", menu_button_pressed_style); + t->set_stylebox("disabled", "MenuButton", menu_button_disabled_style); + t->set_stylebox("focus", "MenuButton", menu_button_focus_style); + t->set_stylebox("focus", "OptionButton", button_focus_style); + t->set_stylebox("hover", "PopupMenu", popup_hover_style); + t->set_stylebox("background", "ProgressBar", progress_background_style); + t->set_stylebox("fill", "ProgressBar", progress_fill_style); + t->set_stylebox("grabber_area", "HSlider", grabber_style); + t->set_stylebox("grabber_area", "VSlider", grabber_style); + t->set_stylebox("grabber_area_highlight", "HSlider", grabber_highlight_style); + t->set_stylebox("grabber_area_highlight", "VSlider", grabber_highlight_style); + t->set_stylebox("slider", "HSlider", slider_style); + t->set_stylebox("slider", "VSlider", slider_style); + t->set_stylebox("slider", "PickerHSlider", picker_slider_style); + t->set_stylebox("grabber", "HScrollBar", grabber_style); + t->set_stylebox("grabber", "VScrollBar", grabber_style); + t->set_stylebox("grabber_highlight", "HScrollBar", grabber_highlight_style); + t->set_stylebox("grabber_highlight", "VScrollBar", grabber_highlight_style); + t->set_stylebox("grabber_pressed", "HScrollBar", grabber_highlight_style); + t->set_stylebox("grabber_pressed", "VScrollBar", grabber_highlight_style); + t->set_stylebox("scroll", "HScrollBar", h_scroll_style); + t->set_stylebox("scroll", "VScrollBar", v_scroll_style); + t->set_stylebox("focus", "FoldableContainer", button_focus_style); + t->set_stylebox(SceneStringName(panel), "FoldableContainer", foldable_panel_style); + t->set_stylebox("title_panel", "FoldableContainer", foldable_title_style); + t->set_stylebox("title_collapsed_panel", "FoldableContainer", foldable_title_collapsed_style); + t->set_stylebox("title_hover_panel", "FoldableContainer", foldable_title_hover_style); + t->set_stylebox("title_collapsed_hover_panel", "FoldableContainer", foldable_title_collapsed_hover_style); + t->set_stylebox(SceneStringName(panel), "SwatchesFoldableContainer", swatches_foldable_panel_style); + t->set_stylebox("title_panel", "SwatchesFoldableContainer", swatches_foldable_title_style); + t->set_stylebox("title_collapsed_panel", "SwatchesFoldableContainer", swatches_foldable_title_collapsed_style); + t->set_stylebox("title_hover_panel", "SwatchesFoldableContainer", swatches_foldable_title_hover_style); + t->set_stylebox("title_collapsed_hover_panel", "SwatchesFoldableContainer", swatches_foldable_title_collapsed_hover_style); + t->set_stylebox("button_normal_style", "FoldableContainer", color_picker_button_normal_style); + t->set_stylebox("button_hovered_style", "FoldableContainer", color_picker_button_hovered_style); + t->set_stylebox("button_pressed_style", "FoldableContainer", color_picker_button_pressed_style); + t->set_stylebox("button_disabled_style", "FoldableContainer", color_picker_button_disabled_style); + t->set_stylebox("up_background_hovered", "SpinBox", button_hover_style); + t->set_stylebox("down_background_hovered", "SpinBox", button_hover_style); + t->set_stylebox("up_background_pressed", "SpinBox", button_pressed_style); + t->set_stylebox("down_background_pressed", "SpinBox", button_pressed_style); + t->set_stylebox("custom_button", "Tree", button_normal_style); + t->set_stylebox("custom_button_hover", "Tree", button_hover_style); + t->set_stylebox("custom_button_pressed", "Tree", button_pressed_style); + t->set_stylebox("focus", "Tree", button_focus_style); + t->set_stylebox(SceneStringName(panel), "Tree", button_normal_style); + t->set_stylebox("selected", "Tree", popup_hover_style); + t->set_stylebox("selected_focus", "Tree", popup_hover_style); + t->set_stylebox("title_button_hover", "Tree", button_hover_style); + t->set_stylebox("title_button_normal", "Tree", button_normal_style); + t->set_stylebox("title_button_pressed", "Tree", button_pressed_style); + t->set_stylebox("cursor", "Tree", button_focus_style); + t->set_stylebox("cursor_unfocused", "Tree", button_focus_style); + t->set_stylebox("button_pressed", "Tree", button_pressed_style); + t->set_stylebox("labeled_separator_left", "PopupMenu", h_separator_style); + t->set_stylebox("labeled_separator_right", "PopupMenu", h_separator_style); + t->set_stylebox("separator", "PopupMenu", h_separator_style); + t->set_stylebox("separator", "HSeparator", h_separator_style); + t->set_stylebox("separator", "VSeparator", v_separator_style); + t->set_stylebox(SceneStringName(panel), "FlatPanel", popup_panel_style); + t->set_stylebox(CoreStringName(normal), "MenuBar", button_normal_style); + t->set_stylebox("hover", "MenuBar", button_hover_style); + t->set_stylebox(SceneStringName(pressed), "MenuBar", button_pressed_style); + t->set_stylebox("disabled", "MenuBar", button_disabled_style); + t->set_stylebox(CoreStringName(normal), "OptionButton", button_normal_style); + t->set_stylebox("hover", "OptionButton", button_hover_style); + t->set_stylebox(SceneStringName(pressed), "OptionButton", button_pressed_style); + t->set_stylebox("disabled", "OptionButton", button_disabled_style); + t->set_stylebox("normal_mirrored", "OptionButton", button_normal_style); + t->set_stylebox("hover_mirrored", "OptionButton", button_hover_style); + t->set_stylebox("pressed_mirrored", "OptionButton", button_pressed_style); + t->set_stylebox("disabled_mirrored", "OptionButton", button_disabled_style); + t->set_stylebox(CoreStringName(normal), "CheckBox", flat_button_normal); + t->set_stylebox(SceneStringName(pressed), "CheckBox", flat_button_normal); + t->set_stylebox("disabled", "CheckBox", flat_button_normal); + t->set_stylebox("hover", "CheckBox", flat_button_normal); + t->set_stylebox("hover_pressed", "CheckBox", flat_button_normal); + t->set_stylebox("focus", "CheckBox", button_focus_style); + t->set_stylebox("focus", "LinkButton", flat_button_normal); + t->set_stylebox(CoreStringName(normal), "CheckButton", flat_button_normal); + t->set_stylebox(SceneStringName(pressed), "CheckButton", flat_button_normal); + t->set_stylebox("disabled", "CheckButton", flat_button_normal); + t->set_stylebox("hover", "CheckButton", flat_button_normal); + t->set_stylebox("hover_pressed", "CheckButton", flat_button_normal); + t->set_stylebox("focus", "CheckButton", button_focus_style); + t->set_stylebox(CoreStringName(normal), "Label", empty_style); + t->set_stylebox(CoreStringName(normal), "GraphNodeTitleLabel", empty_style); + t->set_stylebox(CoreStringName(normal), "GraphFrameTitleLabel", empty_style); + t->set_stylebox("field_and_buttons_separator", "SpinBox", empty_style); + t->set_stylebox("up_down_buttons_separator", "SpinBox", empty_style); + t->set_stylebox(CoreStringName(normal), "ColorButton", color_button_normal_style); + t->set_stylebox(SceneStringName(pressed), "ColorButton", color_button_pressed_style); + t->set_stylebox("hover_pressed", "ColorButton", color_button_pressed_style); + t->set_stylebox("hover", "ColorButton", color_button_hover_style); + t->set_stylebox("disabled", "ColorButton", color_button_disabled_style); + t->set_stylebox("focus", "ColorButton", color_button_focus_style); + t->set_stylebox("focus", "RichTextLabel", button_focus_style); + t->set_stylebox(CoreStringName(normal), "RichTextLabel", flat_button_normal); + t->set_stylebox(CoreStringName(normal), "CodeEdit", button_normal_style); + t->set_stylebox("focus", "CodeEdit", button_focus_style); + t->set_stylebox("read_only", "CodeEdit", button_disabled_style); + t->set_stylebox("completion", "CodeEdit", empty_style); + t->set_stylebox(CoreStringName(normal), "FlatButton", flat_button_normal); + t->set_stylebox("hover", "FlatButton", button_hover_style); + t->set_stylebox(SceneStringName(pressed), "FlatButton", button_pressed_style); + t->set_stylebox("disabled", "FlatButton", flat_button_normal); + t->set_stylebox(CoreStringName(normal), "FlatMenuButton", flat_button_normal); + t->set_stylebox("hover", "FlatMenuButton", flat_button_normal); + t->set_stylebox(SceneStringName(pressed), "FlatMenuButton", button_pressed_style); + t->set_stylebox("disabled", "FlatMenuButton", flat_button_normal); + t->set_stylebox("scroll_focus", "HScrollBar", empty_style); + t->set_stylebox("scroll_focus", "VScrollBar", empty_style); + t->set_stylebox("up_background", "SpinBox", button_normal_style); + t->set_stylebox("down_background", "SpinBox", button_normal_style); + t->set_stylebox("up_background_disabled", "SpinBox", button_disabled_style); + t->set_stylebox("down_background_disabled", "SpinBox", button_disabled_style); + t->set_stylebox("tabbar_background", "TabContainer", empty_style); + t->set_stylebox("button_pressed", "TabBar", button_pressed_style); + t->set_stylebox("button_highlight", "TabBar", button_normal_style); + t->set_stylebox(SceneStringName(panel), "ScrollContainer", empty_style); + t->set_stylebox(SceneStringName(panel), "TooltipPanel", popup_panel_style); + t->set_stylebox(SceneStringName(panel), "ItemList", panel_style); + t->set_stylebox("focus", "ItemList", button_focus_style); + t->set_stylebox("cursor", "ItemList", button_focus_style); + t->set_stylebox("cursor_unfocused", "ItemList", button_focus_style); + t->set_stylebox(SceneStringName(panel), "PopupDialog", popup_panel_style); + t->set_stylebox("popup_panel", "ColorPickerButton", color_picker_popup_panel_style); + t->set_stylebox("preset_fg", "ColorPresetButton", button_pressed_style); + t->set_stylebox("hovered", "ItemList", button_hover_style); + t->set_stylebox("selected", "ItemList", button_pressed_style); + t->set_stylebox("selected_focus", "ItemList", button_pressed_style); + t->set_stylebox("embedded_border", "Window", embedded_style); + t->set_stylebox("embedded_unfocused_border", "Window", embedded_unfocused_style); + t->set_stylebox("menu_panel", "GraphEdit", button_disabled_style); + t->set_stylebox(SceneStringName(panel), "GraphEdit", tab_panel_style); + t->set_stylebox("camera", "GraphEditMinimap", button_focus_style); + t->set_stylebox(SceneStringName(panel), "GraphEditMinimap", tab_disabled_style); + t->set_stylebox("node", "GraphEditMinimap", tab_unselected_style); + t->set_stylebox("titlebar", "GraphFrame", graph_frame_title_style); + t->set_stylebox("titlebar_selected", "GraphFrame", graph_frame_title_selected_style); + t->set_stylebox(SceneStringName(panel), "GraphFrame", graph_panel_style); + t->set_stylebox("panel_selected", "GraphFrame", graph_panel_selected_style); + t->set_stylebox(SceneStringName(panel), "GraphNode", graph_panel_style); + t->set_stylebox("panel_selected", "GraphNode", graph_panel_selected_style); + t->set_stylebox("titlebar", "GraphNode", graph_title_style); + t->set_stylebox("titlebar_selected", "GraphNode", graph_title_selected_style); + t->set_stylebox("slot", "GraphNode", empty_style); + t->set_stylebox(CoreStringName(normal), "PickerButton", color_picker_button_normal_style); + t->set_stylebox("disabled", "PickerButton", color_picker_button_disabled_style); + t->set_stylebox(SceneStringName(pressed), "PickerButton", color_picker_button_pressed_style); + t->set_stylebox("hover_pressed", "PickerButton", color_picker_button_pressed_style); + t->set_stylebox("hover", "PickerButton", color_picker_button_hovered_style); + t->set_stylebox(CoreStringName(normal), "PickerMenuButton", color_picker_button_normal_style); + t->set_stylebox("disabled", "PickerMenuButton", color_picker_button_normal_style); + t->set_stylebox(SceneStringName(pressed), "PickerMenuButton", color_picker_button_pressed_style); + t->set_stylebox("hover_pressed", "PickerMenuButton", color_picker_button_pressed_style); + t->set_stylebox("hover", "PickerMenuButton", color_picker_button_hovered_style); + t->set_stylebox("focus", "PickerMenuButton", button_focus_style); + t->set_stylebox(CoreStringName(normal), "PickerLineEdit", color_picker_button_normal_style); + t->set_stylebox("read_only", "PickerLineEdit", color_picker_button_normal_style); + + v_separator_style->set_vertical(true); + tab_focus_style->set_draw_center(false); + button_focus_style->set_draw_center(false); + color_button_focus_style->set_draw_center(false); + menu_button_focus_style->set_draw_center(false); + + t->set_font_size(SceneStringName(font_size), "Button", -1); + t->set_font_size(SceneStringName(font_size), "MenuBar", -1); + t->set_font_size(SceneStringName(font_size), "LinkButton", -1); + t->set_font_size(SceneStringName(font_size), "OptionButton", -1); + t->set_font_size(SceneStringName(font_size), "MenuButton", -1); + t->set_font_size(SceneStringName(font_size), "CheckBox", -1); + t->set_font_size(SceneStringName(font_size), "CheckButton", -1); + t->set_font_size(SceneStringName(font_size), "Label", -1); + t->set_font_size(SceneStringName(font_size), "LineEdit", -1); + t->set_font_size(SceneStringName(font_size), "ProgressBar", -1); + t->set_font_size(SceneStringName(font_size), "TextEdit", -1); + t->set_font_size(SceneStringName(font_size), "CodeEdit", -1); + t->set_font_size(SceneStringName(font_size), "PopupMenu", -1); + t->set_font_size(SceneStringName(font_size), "GraphNodeTitleLabel", -1); + t->set_font_size(SceneStringName(font_size), "Tree", -1); + t->set_font_size(SceneStringName(font_size), "ItemList", -1); + t->set_font_size(SceneStringName(font_size), "TabContainer", -1); + t->set_font_size(SceneStringName(font_size), "TabBar", -1); + t->set_font_size(SceneStringName(font_size), "TooltipLabel", -1); + t->set_font_size(SceneStringName(font_size), "FoldableContainer", -1); + t->set_font_size("title_font_size", "Window", -1); + t->set_font_size("font_separator_size", "PopupMenu", -1); + t->set_font_size("title_button_font_size", "Tree", -1); + t->set_font_size("normal_font_size", "RichTextLabel", -1); + t->set_font_size("bold_font_size", "RichTextLabel", -1); + t->set_font_size("italics_font_size", "RichTextLabel", -1); + t->set_font_size("bold_italics_font_size", "RichTextLabel", -1); + t->set_font_size("mono_font_size", "RichTextLabel", -1); + t->set_constant("scrollbar_margin_left", "Tree", -1); + t->set_constant("scrollbar_margin_top", "Tree", -1); + t->set_constant("scrollbar_margin_right", "Tree", -1); + t->set_constant("scrollbar_margin_bottom", "Tree", -1); + + t->set_constant("icon_max_width", "Button", 0); + t->set_constant("icon_max_width", "Tree", 0); + t->set_constant("align_to_largest_stylebox", "Button", 0); + t->set_constant("check_v_offset", "CheckBox", 0); + t->set_constant("check_v_offset", "CheckButton", 0); + t->set_constant("center_grabber", "HSlider", 0); + t->set_constant("grabber_offset", "HSlider", 0); + t->set_constant("center_grabber", "VSlider", 0); + t->set_constant("grabber_offset", "VSlider", 0); + t->set_constant("inner_item_margin_bottom", "Tree", 0); + t->set_constant("inner_item_margin_top", "Tree", 0); + t->set_constant("inner_item_margin_left", "Tree", 0); + t->set_constant("inner_item_margin_right", "Tree", 0); + t->set_constant("buttons_vertical_separation", "SpinBox", 0); + t->set_constant("icon_max_width", "PopupMenu", 0); + t->set_constant("parent_hl_line_margin", "Tree", 0); + t->set_constant("icon_max_width", "TabContainer", 0); + t->set_constant("icon_max_width", "TabBar", 0); + t->set_constant("draw_guides", "Tree", 0); + t->set_constant("side_margin", "TabContainer", 0); + t->set_constant("modulate_arrow", "OptionButton", 0); + t->set_constant("port_h_offset", "GraphNode", 0); + t->set_constant(SceneStringName(line_separation), "RichTextLabel", 0); + + t->set_constant("autohide", "SplitContainer", 1); + t->set_constant("autohide", "HSplitContainer", 1); + t->set_constant("autohide", "VSplitContainer", 1); + t->set_constant("draw_relationship_lines", "Tree", 1); + t->set_constant("center_grabber", "PickerHSlider", 1); + + t->set_constant("minimum_character_width", "LineEdit", 4); + t->set_constant("completion_scroll_width", "CodeEdit", 6); + t->set_constant("completion_lines", "CodeEdit", 7); + + t->set_color("font_shadow_color", "Label", Color(0, 0, 0, 0)); + t->set_color("font_shadow_color", "GraphNodeTitleLabel", Color(0, 0, 0, 0)); + t->set_color("font_shadow_color", "GraphFrameTitleLabel", Color(0, 0, 0, 0)); + t->set_color("font_shadow_color", "TooltipLabel", Color(0, 0, 0, 0)); + t->set_color("font_shadow_color", "RichTextLabel", Color(0, 0, 0, 0)); + t->set_color("background_color", "TextEdit", Color(0, 0, 0, 0)); + t->set_color("background_color", "CodeEdit", Color(0, 0, 0, 0)); + t->set_color("table_odd_row_bg", "RichTextLabel", Color(0, 0, 0, 0)); + t->set_color("table_even_row_bg", "RichTextLabel", Color(0, 0, 0, 0)); + t->set_color("table_border", "RichTextLabel", Color(0, 0, 0, 0)); + + t->set_color("completion_background_color", "CodeEdit", Color(0.17, 0.16, 0.2)); + t->set_color("completion_selected_color", "CodeEdit", Color(0.26, 0.26, 0.27)); + t->set_color("completion_existing_color", "CodeEdit", Color(0.87, 0.87, 0.87, 0.13)); + t->set_color("bookmark_color", "CodeEdit", Color(0.5, 0.64, 1, 0.8)); + t->set_color("breakpoint_color", "CodeEdit", Color(0.9, 0.29, 0.3)); + t->set_color("executing_line_color", "CodeEdit", Color(0.98, 0.89, 0.27)); + t->set_color("code_folding_color", "CodeEdit", Color(0.8, 0.8, 0.8, 0.8)); + t->set_color("folded_code_region_color", "CodeEdit", Color(0.68, 0.46, 0.77, 0.2)); + t->set_color("brace_mismatch_color", "CodeEdit", Color(1, 0.2, 0.2)); + t->set_color("line_number_color", "CodeEdit", Color(0.67, 0.67, 0.67, 0.4)); + t->set_color("line_length_guideline_color", "CodeEdit", Color(0.3, 0.5, 0.8, 0.1)); + + embedded_style->set_content_margin_individual(10, 28, 10, 8); + embedded_unfocused_style->set_content_margin_individual(10, 28, 10, 8); + embedded_style->set_expand_margin_individual(8, 32, 8, 6); + embedded_unfocused_style->set_expand_margin_individual(8, 32, 8, 6); + + t->set_font("bold_font", "RichTextLabel", bold_font); + t->set_font("italics_font", "RichTextLabel", italics_font); + t->set_font("bold_italics_font", "RichTextLabel", bold_italics_font); + t->set_font(SceneStringName(font), "TabBar", Ref()); + t->set_font(SceneStringName(font), "TabContainer", Ref()); + t->set_font(SceneStringName(font), "ItemList", Ref()); + t->set_font(SceneStringName(font), "Tree", Ref()); + t->set_font(SceneStringName(font), "GraphNodeTitleLabel", Ref()); + t->set_font(SceneStringName(font), "PopupMenu", Ref()); + t->set_font(SceneStringName(font), "CodeEdit", Ref()); + t->set_font(SceneStringName(font), "TextEdit", Ref()); + t->set_font(SceneStringName(font), "ProgressBar", Ref()); + t->set_font(SceneStringName(font), "LineEdit", Ref()); + t->set_font(SceneStringName(font), "Label", Ref()); + t->set_font(SceneStringName(font), "CheckButton", Ref()); + t->set_font(SceneStringName(font), "CheckBox", Ref()); + t->set_font(SceneStringName(font), "MenuButton", Ref()); + t->set_font(SceneStringName(font), "OptionButton", Ref()); + t->set_font(SceneStringName(font), "LinkButton", Ref()); + t->set_font(SceneStringName(font), "MenuBar", Ref()); + t->set_font(SceneStringName(font), "Button", Ref()); + t->set_font(SceneStringName(font), "FoldableContainer", Ref()); + t->set_font(SceneStringName(font), "TooltipLabel", Ref()); + t->set_font("title_button_font", "Tree", Ref()); + t->set_font("font_separator", "PopupMenu", Ref()); + t->set_font("title_font", "Window", Ref()); + t->set_font("normal_font", "RichTextLabel", Ref()); + t->set_font("mono_font", "RichTextLabel", Ref()); + + ThemeDB::get_singleton()->set_default_theme(t); + ThemeDB::get_singleton()->set_fallback_base_scale(scale); + ThemeDB::get_singleton()->set_fallback_stylebox(empty_style); + ThemeDB::get_singleton()->set_fallback_font_size(p_font_size * scale); +} + +void finalize_default_theme() { + icons.clear(); + + panel_style.unref(); + popup_panel_style.unref(); + color_picker_popup_panel_style.unref(); + tab_panel_style.unref(); + color_sliders_panel_style.unref(); + tab_selected_style.unref(); + tab_unselected_style.unref(); + tab_hovered_style.unref(); + tab_disabled_style.unref(); + tab_focus_style.unref(); + button_normal_style.unref(); + button_hover_style.unref(); + button_pressed_style.unref(); + button_disabled_style.unref(); + button_focus_style.unref(); + color_button_normal_style.unref(); + color_button_hover_style.unref(); + color_button_pressed_style.unref(); + color_button_disabled_style.unref(); + color_button_focus_style.unref(); + menu_button_normal_style.unref(); + menu_button_hover_style.unref(); + menu_button_pressed_style.unref(); + menu_button_disabled_style.unref(); + menu_button_focus_style.unref(); + popup_hover_style.unref(); + progress_background_style.unref(); + progress_fill_style.unref(); + grabber_style.unref(); + grabber_highlight_style.unref(); + slider_style.unref(); + picker_slider_style.unref(); + h_scroll_style.unref(); + v_scroll_style.unref(); + foldable_panel_style.unref(); + foldable_title_style.unref(); + foldable_title_collapsed_style.unref(); + foldable_title_hover_style.unref(); + foldable_title_collapsed_hover_style.unref(); + swatches_foldable_panel_style.unref(); + swatches_foldable_title_style.unref(); + swatches_foldable_title_collapsed_style.unref(); + swatches_foldable_title_hover_style.unref(); + swatches_foldable_title_collapsed_hover_style.unref(); + h_separator_style.unref(); + v_separator_style.unref(); + flat_button_normal.unref(); + embedded_style.unref(); + embedded_unfocused_style.unref(); + graph_title_style.unref(); + graph_frame_title_style.unref(); + graph_frame_title_selected_style.unref(); + graph_title_selected_style.unref(); + graph_panel_style.unref(); + graph_panel_selected_style.unref(); + color_mode_button_normal_style.unref(); + color_mode_button_hovered_style.unref(); + color_mode_button_pressed_style.unref(); + color_picker_button_normal_style.unref(); + color_picker_button_hovered_style.unref(); + color_picker_button_pressed_style.unref(); + color_picker_button_disabled_style.unref(); + + if (custom_font.is_valid()) { + custom_font.unref(); + } + fallback_font.unref(); + bold_font.unref(); + bold_italics_font.unref(); + italics_font.unref(); +} diff --git a/scene/theme/pixel_default_theme.h b/scene/theme/pixel_default_theme.h new file mode 100644 index 000000000000..135a783c3c49 --- /dev/null +++ b/scene/theme/pixel_default_theme.h @@ -0,0 +1,74 @@ +/**************************************************************************/ +/* pixel_default_theme.h */ +/**************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/**************************************************************************/ +/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ +/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/**************************************************************************/ + +/**************************************************************************/ +/* PIXEL ENGINE */ +/* Copyright (c) 2024-present Pixel Engine contributors (see AUTHORS.md). */ +/**************************************************************************/ +/* NOTICE: */ +/* This file contains modifications and additions specific to the Pixel */ +/* Engine project. While these changes are licensed under the MIT license */ +/* for compatibility, we request proper attribution if reused in any */ +/* derivative works, including meta-forks. */ +/**************************************************************************/ + +#ifndef DEFAULT_THEME_H +#define DEFAULT_THEME_H + +#include "scene/resources/theme.h" + +void finalize_default_theme(); +void update_theme_icons(Ref &p_theme, Color p_font_color, Color p_accent_color); +void update_font_color(Ref &p_theme, Color p_color); +void update_font_outline_color(Ref &p_theme, Color p_color); +void update_theme_margins(Ref &p_theme, int p_margin); +void update_theme_padding(Ref &p_theme, int p_padding); +void update_theme_corner_radius(Ref &p_theme, int p_corner_radius); +void update_theme_border_width(Ref &p_theme, int p_border_width); +void update_font_outline_size(Ref &p_theme, int p_outline_size); +void update_font_size(Ref &p_theme, int p_font_size); +void update_theme_border_padding(Ref &p_theme, int p_border_padding); +void update_theme_scale(Ref &p_theme); +void update_theme_colors(Ref &p_theme, Color p_base_color, Color p_accent_color, float p_contrast, float p_base2_contrast, float p_base3_contrast, float p_base4_contrast, float p_accent2_contrast, float p_bg_contrast); +void update_font_embolden(float p_embolden); +void update_font_spacing_glyph(int p_spacing); +void update_font_spacing_space(int p_spacing); +void update_font_spacing_top(int p_spacing); +void update_font_spacing_bottom(int p_spacing); +void update_theme_font(Ref &p_theme, Ref p_font); +void update_font_subpixel_positioning(TextServer::SubpixelPositioning p_font_subpixel_positioning); +void update_font_antialiasing(TextServer::FontAntialiasing p_font_antialiasing); +void update_font_lcd_subpixel_layout(TextServer::FontLCDSubpixelLayout p_font_lcd_subpixel_layout); +void update_font_hinting(TextServer::Hinting p_font_hinting); +void update_font_msdf(bool p_font_msdf); +void update_font_generate_mipmaps(bool p_font_generate_mipmaps); +void make_default_theme(Ref p_font, float p_scale = 1.f, TextServer::SubpixelPositioning p_font_subpixel = TextServer::SUBPIXEL_POSITIONING_AUTO, TextServer::Hinting p_font_hinting = TextServer::HINTING_LIGHT, TextServer::FontAntialiasing p_font_antialiased = TextServer::FONT_ANTIALIASING_GRAY, TextServer::FontLCDSubpixelLayout p_font_lcd_subpixel_layout = TextServer::FontLCDSubpixelLayout::FONT_LCD_SUBPIXEL_LAYOUT_HRGB, bool p_font_msdf = false, bool p_font_generate_mipmaps = false, Color p_base_color = Color(0.131, 0.152, 0.234), Color p_secondary_color = Color(0.226, 0.478, 0.921), Color p_font_color = Color(0.8, 0.8, 0.8), Color p_font_outline_color = Color(0, 0, 0, 0), float p_contrast = 0.2f, float p_base2_contrast = 0.6f, float p_base3_contrast = 0.4f, float p_base4_contrast = 0.2, float p_accent2_contrast = 0.6, float p_bg_contrast = 0.8, int p_margin = 4, int p_padding = 4, int p_border_width = 2, int p_corner_radius = 6, int p_font_size = 16, int p_font_outline_size = 0, float p_font_embolden = 0.f, int p_font_spacing_glyph = 0, int p_font_spacing_space = 0, int p_font_spacing_top = 0, int p_font_spacing_bottom = 0); + +#endif // DEFAULT_THEME_H diff --git a/scene/theme/theme_db.cpp b/scene/theme/theme_db.cpp index 2817da39ac0b..96fa796455ba 100644 --- a/scene/theme/theme_db.cpp +++ b/scene/theme/theme_db.cpp @@ -49,14 +49,31 @@ #include "scene/resources/font.h" #include "scene/resources/style_box.h" #include "scene/resources/texture.h" +#ifndef PIXEL_ENGINE #include "scene/theme/default_theme.h" +#else +#include "scene/theme/pixel_default_theme.h" +#endif // !PIXEL_ENGINE #include "servers/text_server.h" // Default engine theme creation and configuration. +#ifdef PIXEL_ENGINE +Color ThemeDB::_get_font_color() const { + Color fcolor = Color(0.8, 0.8, 0.8); + FontColorOverride fcolor_override = (FontColorOverride)(int)GLOBAL_GET("gui/theme/font_color_override"); + bool is_dark_theme = ((Color)GLOBAL_GET("gui/theme/base_color")).get_luminance() <= 0.5; + if (fcolor_override == FONT_COLOR_OVERRIDE_DARK || (fcolor_override == FONT_COLOR_OVERRIDE_AUTO && !is_dark_theme)) { + fcolor = Color(0.05, 0.05, 0.05); + } else if (fcolor_override == FONT_COLOR_OVERRIDE_CUSTOM) { + fcolor = GLOBAL_GET("gui/theme/custom_font_color"); + } + return fcolor; +} +#endif // PIXEL_ENGINE void ThemeDB::initialize_theme() { // Default theme-related project settings. - +#ifndef PIXEL_ENGINE // Allow creating the default theme at a different scale to suit higher/lower base resolutions. float default_theme_scale = GLOBAL_DEF(PropertyInfo(Variant::FLOAT, "gui/theme/default_theme_scale", PROPERTY_HINT_RANGE, "0.5,8,0.01", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED), 1.0); @@ -97,13 +114,31 @@ void ThemeDB::initialize_theme() { if (RenderingServer::get_singleton()) { make_default_theme(default_theme_scale, project_font, font_subpixel_positioning, font_hinting, font_antialiasing, lcd_subpixel_layout, font_msdf, font_generate_mipmaps); } +#else + // Always generate the default theme to serve as a fallback for all required theme definitions. + if (RenderingServer::get_singleton()) { + Ref project_font; + if (!custom_font.is_empty() && FileAccess::exists(custom_font)) { + project_font = ResourceLoader::load(custom_font); + if (project_font.is_null()) { + ERR_PRINT("Error loading custom project font '" + custom_font + "'"); + } + } + + make_default_theme(project_font, scale, font_subpixel_positioning, font_hinting, font_antialiasing, font_lcd_subpixel_layout, font_msdf, font_generate_mipmaps, base_color, accent_color, _get_font_color(), font_outline_color, contrast, b2_contrast, b3_contrast, b4_contrast, a2_contrast, bg_contrast, margin, padding, border_width, corner_radius, font_size, font_outline_size, font_embolden, font_spacing_glyph, font_spacing_space, font_spacing_top, font_spacing_bottom); + } +#endif // !PIXEL_ENGINE _init_default_theme_context(); } void ThemeDB::initialize_theme_noproject() { if (RenderingServer::get_singleton()) { +#ifndef PIXEL_ENGINE make_default_theme(1.0, Ref()); +#else + make_default_theme(Ref()); +#endif // !PIXEL_ENGINE } _init_default_theme_context(); @@ -115,6 +150,9 @@ void ThemeDB::finalize_theme() { } _finalize_theme_contexts(); +#ifdef PIXEL_ENGINE + finalize_default_theme(); +#endif // PIXEL_ENGINE default_theme.unref(); fallback_font.unref(); @@ -132,6 +170,7 @@ Ref ThemeDB::get_default_theme() { return default_theme; } +#ifndef PIXEL_ENGINE void ThemeDB::set_project_theme(const Ref &p_project_default) { project_theme = p_project_default; } @@ -139,6 +178,7 @@ void ThemeDB::set_project_theme(const Ref &p_project_default) { Ref ThemeDB::get_project_theme() { return project_theme; } +#endif // !PIXEL_ENGINE // Universal fallback values for theme item types. @@ -278,18 +318,18 @@ void ThemeDB::_propagate_theme_context(Node *p_from_node, ThemeContext *p_contex void ThemeDB::_init_default_theme_context() { default_theme_context = memnew(ThemeContext); - Vector> themes; +#ifndef PIXEL_ENGINE // Only add the project theme to the default context when running projects. - #ifdef TOOLS_ENABLED if (!Engine::get_singleton()->is_editor_hint()) { themes.push_back(project_theme); } #else themes.push_back(project_theme); -#endif +#endif // TOOLS_ENABLED +#endif // !PIXEL_ENGINE themes.push_back(default_theme); default_theme_context->set_themes(themes); @@ -421,9 +461,245 @@ void ThemeDB::_sort_theme_items() { } } +#ifdef PIXEL_ENGINE +void ThemeDB::_update_default_theme() { + bool update_icons = false; + bool scale_changed = false; + bool border_padding_changed = false; + bool update_colors = false; + + float _scale = GLOBAL_GET("gui/theme/default_theme_scale"); + if (default_theme->get_default_base_scale() != _scale) { + default_theme->set_default_base_scale(_scale); + scale_changed = true; + } + + Color _font_color = _get_font_color(); + if (font_color != _font_color) { + font_color = _font_color; + default_theme->freeze_change_propagation(); + update_font_color(default_theme, font_color); + update_icons = true; + } + + Color _accent_color = GLOBAL_GET("gui/theme/accent_color"); + if (accent_color != _accent_color) { + accent_color = _accent_color; + update_icons = true; + update_colors = true; + } + + if (update_icons || scale_changed) { + default_theme->freeze_change_propagation(); + update_theme_icons(default_theme, font_color, accent_color); + emit_signal(SNAME("icons_changed")); + } + + Color _font_outline_color = GLOBAL_GET("gui/theme/font_outline_color"); + if (font_outline_color != _font_outline_color) { + font_outline_color = _font_outline_color; + default_theme->freeze_change_propagation(); + update_font_outline_color(default_theme, font_outline_color); + } + + int _margin = GLOBAL_GET("gui/theme/margin"); + if (margin != _margin || scale_changed) { + margin = _margin; + default_theme->freeze_change_propagation(); + update_theme_margins(default_theme, margin); + } + + int _padding = GLOBAL_GET("gui/theme/padding"); + if (padding != _padding || scale_changed) { + padding = _padding; + default_theme->freeze_change_propagation(); + update_theme_padding(default_theme, padding); + border_padding_changed = true; + } + + int _corner_radius = GLOBAL_GET("gui/theme/corner_radius"); + if (corner_radius != _corner_radius || scale_changed) { + corner_radius = _corner_radius; + default_theme->freeze_change_propagation(); + update_theme_corner_radius(default_theme, corner_radius); + } + + int _border_width = GLOBAL_GET("gui/theme/border_width"); + if (border_width != _border_width || scale_changed) { + border_width = _border_width; + default_theme->freeze_change_propagation(); + update_theme_border_width(default_theme, border_width); + border_padding_changed = true; + } + + int _font_outline_size = GLOBAL_GET("gui/theme/font_outline_size"); + if (font_outline_size != _font_outline_size || scale_changed) { + font_outline_size = _font_outline_size; + default_theme->freeze_change_propagation(); + update_font_outline_size(default_theme, font_outline_size); + } + + int _font_size = GLOBAL_GET("gui/theme/font_size"); + if (font_size != _font_size || scale_changed) { + font_size = _font_size; + default_theme->freeze_change_propagation(); + update_font_size(default_theme, font_size); + } + + if (border_padding_changed || scale_changed) { + default_theme->freeze_change_propagation(); + update_theme_border_padding(default_theme, border_width + padding); + } + + Color _base_color = GLOBAL_GET("gui/theme/base_color"); + if (base_color != _base_color) { + base_color = _base_color; + update_colors = true; + } + + float _contrast = GLOBAL_GET("gui/theme/contrast"); + if (contrast != _contrast) { + contrast = _contrast; + update_colors = true; + } + + float _b2_contrast = GLOBAL_GET("gui/theme/base2_contrast"); + if (b2_contrast != _b2_contrast) { + b2_contrast = _b2_contrast; + update_colors = true; + } + + float _b3_contrast = GLOBAL_GET("gui/theme/base3_contrast"); + if (b3_contrast != _b3_contrast) { + b3_contrast = _b3_contrast; + update_colors = true; + } + + float _b4_contrast = GLOBAL_GET("gui/theme/base4_contrast"); + if (b4_contrast != _b4_contrast) { + b4_contrast = _b4_contrast; + update_colors = true; + } + + float _a2_contrast = GLOBAL_GET("gui/theme/accent2_contrast"); + if (a2_contrast != _a2_contrast) { + a2_contrast = _a2_contrast; + update_colors = true; + } + + float _bg_contrast = GLOBAL_GET("gui/theme/bg_contrast"); + if (bg_contrast != _bg_contrast) { + bg_contrast = _bg_contrast; + update_colors = true; + } + + if (update_colors) { + default_theme->freeze_change_propagation(); + update_theme_colors(default_theme, base_color, accent_color, contrast, b2_contrast, b3_contrast, b4_contrast, a2_contrast, bg_contrast); + } + + float _font_embolden = GLOBAL_GET("gui/theme/font_embolden"); + if (font_embolden != _font_embolden) { + font_embolden = _font_embolden; + default_theme->freeze_change_propagation(); + update_font_embolden(font_embolden); + } + + int _font_spacing_glyph = GLOBAL_GET("gui/theme/font_spacing_glyph"); + if (font_spacing_glyph != _font_spacing_glyph || scale_changed) { + font_spacing_glyph = _font_spacing_glyph; + default_theme->freeze_change_propagation(); + update_font_spacing_glyph(Math::round(font_spacing_glyph * _scale)); + } + + int _font_spacing_space = GLOBAL_GET("gui/theme/font_spacing_space"); + if (font_spacing_space != _font_spacing_space || scale_changed) { + font_spacing_space = _font_spacing_space; + default_theme->freeze_change_propagation(); + update_font_spacing_space(Math::round(font_spacing_space * _scale)); + } + + int _font_spacing_top = GLOBAL_GET("gui/theme/font_spacing_top"); + if (font_spacing_top != _font_spacing_top || scale_changed) { + font_spacing_top = _font_spacing_top; + default_theme->freeze_change_propagation(); + update_font_spacing_top(Math::round(font_spacing_top * _scale)); + } + + int _font_spacing_bottom = GLOBAL_GET("gui/theme/font_spacing_bottom"); + if (font_spacing_bottom != _font_spacing_bottom || scale_changed) { + font_spacing_bottom = _font_spacing_bottom; + default_theme->freeze_change_propagation(); + update_font_spacing_bottom(Math::round(font_spacing_bottom * _scale)); + } + + String _custom_font = GLOBAL_GET("gui/theme/custom_font"); + if (custom_font != _custom_font) { + custom_font = _custom_font; + Ref project_font; + if (!custom_font.is_empty() && FileAccess::exists(custom_font)) { + project_font = ResourceLoader::load(custom_font); + } else { + project_font = Ref(); + } + default_theme->freeze_change_propagation(); + update_theme_font(default_theme, project_font); + } + + TextServer::SubpixelPositioning _font_subpixel_positioning = (TextServer::SubpixelPositioning)(int)GLOBAL_GET("gui/theme/default_font_subpixel_positioning"); + if (font_subpixel_positioning != _font_subpixel_positioning) { + font_subpixel_positioning = _font_subpixel_positioning; + default_theme->freeze_change_propagation(); + update_font_subpixel_positioning(font_subpixel_positioning); + } + + TextServer::FontAntialiasing _font_antialiasing = (TextServer::FontAntialiasing)(int)GLOBAL_GET("gui/theme/default_font_antialiasing"); + if (font_antialiasing != _font_antialiasing) { + font_antialiasing = _font_antialiasing; + default_theme->freeze_change_propagation(); + update_font_antialiasing(font_antialiasing); + } + + TextServer::FontLCDSubpixelLayout _font_lcd_subpixel_layout = (TextServer::FontLCDSubpixelLayout)(int)GLOBAL_GET("gui/theme/lcd_subpixel_layout"); + if (font_lcd_subpixel_layout != _font_lcd_subpixel_layout) { + font_lcd_subpixel_layout = _font_lcd_subpixel_layout; + default_theme->freeze_change_propagation(); + update_font_lcd_subpixel_layout(font_lcd_subpixel_layout); + } + + TextServer::Hinting _font_hinting = (TextServer::Hinting)(int)GLOBAL_GET("gui/theme/default_font_hinting"); + if (font_hinting != _font_hinting) { + font_hinting = _font_hinting; + default_theme->freeze_change_propagation(); + update_font_hinting(font_hinting); + } + + bool _font_msdf = GLOBAL_GET("gui/theme/default_font_multichannel_signed_distance_field"); + if (font_msdf != _font_msdf) { + font_msdf = _font_msdf; + default_theme->freeze_change_propagation(); + update_font_msdf(font_msdf); + } + + bool _font_generate_mipmaps = GLOBAL_GET("gui/theme/default_font_generate_mipmaps"); + if (font_generate_mipmaps != _font_generate_mipmaps) { + font_generate_mipmaps = _font_generate_mipmaps; + default_theme->freeze_change_propagation(); + update_font_generate_mipmaps(font_generate_mipmaps); + } + + if (scale_changed) { + default_theme->freeze_change_propagation(); + update_theme_scale(default_theme); + } + + default_theme->unfreeze_and_propagate_changes(); +} +#endif // PIXEL_ENGINE // Object methods. void ThemeDB::_bind_methods() { +#ifndef PIXEL_ENGINE ClassDB::bind_method(D_METHOD("get_default_theme"), &ThemeDB::get_default_theme); ClassDB::bind_method(D_METHOD("get_project_theme"), &ThemeDB::get_project_theme); @@ -444,8 +720,12 @@ void ThemeDB::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::INT, "fallback_font_size", PROPERTY_HINT_RANGE, "0,256,1,or_greater,suffix:px"), "set_fallback_font_size", "get_fallback_font_size"); ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "fallback_icon", PROPERTY_HINT_RESOURCE_TYPE, "Texture2D", PROPERTY_USAGE_NONE), "set_fallback_icon", "get_fallback_icon"); ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "fallback_stylebox", PROPERTY_HINT_RESOURCE_TYPE, "StyleBox", PROPERTY_USAGE_NONE), "set_fallback_stylebox", "get_fallback_stylebox"); +#endif // !PIXEL_ENGINE ADD_SIGNAL(MethodInfo("fallback_changed")); +#ifdef PIXEL_ENGINE + ADD_SIGNAL(MethodInfo("icons_changed")); +#endif // PIXEL_ENGINE } // Memory management, reference, and initialization. @@ -458,8 +738,44 @@ ThemeDB *ThemeDB::get_singleton() { ThemeDB::ThemeDB() { singleton = this; +#ifdef PIXEL_ENGINE + base_color = GLOBAL_DEF_BASIC(PropertyInfo(Variant::COLOR, "gui/theme/base_color", PROPERTY_HINT_COLOR_NO_ALPHA), Color(0.131, 0.152, 0.234)); + accent_color = GLOBAL_DEF_BASIC(PropertyInfo(Variant::COLOR, "gui/theme/accent_color", PROPERTY_HINT_COLOR_NO_ALPHA), Color(0.226, 0.478, 0.921)); + GLOBAL_DEF_BASIC(PropertyInfo(Variant::INT, "gui/theme/font_color_override", PROPERTY_HINT_ENUM, "Auto,Light,Dark,Custom"), 0); + GLOBAL_DEF_BASIC(PropertyInfo(Variant::COLOR, "gui/theme/custom_font_color", PROPERTY_HINT_COLOR_NO_ALPHA), Color(0.8, 0.8, 0.8)); + font_color = _get_font_color(); + font_outline_color = GLOBAL_DEF_BASIC(PropertyInfo(Variant::COLOR, "gui/theme/font_outline_color"), Color(0, 0, 0, 0)); + contrast = GLOBAL_DEF_BASIC(PropertyInfo(Variant::FLOAT, "gui/theme/contrast", PROPERTY_HINT_RANGE, "-1.0, 1.0, 0.01"), 0.2); + b2_contrast = GLOBAL_DEF_BASIC(PropertyInfo(Variant::FLOAT, "gui/theme/base2_contrast", PROPERTY_HINT_RANGE, "0.0, 1.0, 0.01"), 0.6); + b3_contrast = GLOBAL_DEF_BASIC(PropertyInfo(Variant::FLOAT, "gui/theme/base3_contrast", PROPERTY_HINT_RANGE, "0.0, 1.0, 0.01"), 0.4); + b4_contrast = GLOBAL_DEF_BASIC(PropertyInfo(Variant::FLOAT, "gui/theme/base4_contrast", PROPERTY_HINT_RANGE, "0.0, 1.0, 0.01"), 0.2); + a2_contrast = GLOBAL_DEF_BASIC(PropertyInfo(Variant::FLOAT, "gui/theme/accent2_contrast", PROPERTY_HINT_RANGE, "0.0, 1.0, 0.01"), 0.6); + bg_contrast = GLOBAL_DEF_BASIC(PropertyInfo(Variant::FLOAT, "gui/theme/bg_contrast", PROPERTY_HINT_RANGE, "0.0, 1.0, 0.01"), 0.8); + margin = GLOBAL_DEF_BASIC(PropertyInfo(Variant::INT, "gui/theme/margin", PROPERTY_HINT_RANGE, "0, 32, 1"), 4); + padding = GLOBAL_DEF_BASIC(PropertyInfo(Variant::INT, "gui/theme/padding", PROPERTY_HINT_RANGE, "0, 32, 1"), 4); + border_width = GLOBAL_DEF_BASIC(PropertyInfo(Variant::INT, "gui/theme/border_width", PROPERTY_HINT_RANGE, "0, 32, 1"), 2); + corner_radius = GLOBAL_DEF_BASIC(PropertyInfo(Variant::INT, "gui/theme/corner_radius", PROPERTY_HINT_RANGE, "0, 32, 1"), 6); + font_size = GLOBAL_DEF_BASIC(PropertyInfo(Variant::INT, "gui/theme/font_size", PROPERTY_HINT_RANGE, "0, 64, 1"), 16); + font_outline_size = GLOBAL_DEF_BASIC(PropertyInfo(Variant::INT, "gui/theme/font_outline_size", PROPERTY_HINT_RANGE, "0, 64, 1"), 0); + font_embolden = GLOBAL_DEF_BASIC(PropertyInfo(Variant::FLOAT, "gui/theme/font_embolden", PROPERTY_HINT_RANGE, "-2.0, 2.0, 0.01"), 0.0); + font_spacing_glyph = GLOBAL_DEF_BASIC(PropertyInfo(Variant::INT, "gui/theme/font_spacing_glyph", PROPERTY_HINT_RANGE, "-64, 64, 1"), 0); + font_spacing_space = GLOBAL_DEF_BASIC(PropertyInfo(Variant::INT, "gui/theme/font_spacing_space", PROPERTY_HINT_RANGE, "-64, 64, 1"), 0); + font_spacing_top = GLOBAL_DEF_BASIC(PropertyInfo(Variant::INT, "gui/theme/font_spacing_top", PROPERTY_HINT_RANGE, "-64, 64, 1"), 0); + font_spacing_bottom = GLOBAL_DEF_BASIC(PropertyInfo(Variant::INT, "gui/theme/font_spacing_bottom", PROPERTY_HINT_RANGE, "-64, 64, 1"), 0); + scale = GLOBAL_DEF_BASIC(PropertyInfo(Variant::FLOAT, "gui/theme/default_theme_scale", PROPERTY_HINT_RANGE, "0.5,8,0.01"), 1.0); + custom_font = GLOBAL_DEF_BASIC(PropertyInfo(Variant::STRING, "gui/theme/custom_font", PROPERTY_HINT_FILE, "*.tres,*.res,*.otf,*.ttf,*.woff,*.woff2,*.fnt,*.font,*.pfb,*.pfm"), ""); + font_subpixel_positioning = (TextServer::SubpixelPositioning)(int)GLOBAL_DEF_BASIC(PropertyInfo(Variant::INT, "gui/theme/default_font_subpixel_positioning", PROPERTY_HINT_ENUM, "Disabled,Auto,One Half of a Pixel,One Quarter of a Pixel"), TextServer::SUBPIXEL_POSITIONING_AUTO); + font_antialiasing = (TextServer::FontAntialiasing)(int)GLOBAL_DEF_BASIC(PropertyInfo(Variant::INT, "gui/theme/default_font_antialiasing", PROPERTY_HINT_ENUM, "None,Grayscale,LCD Subpixel"), 1); + font_lcd_subpixel_layout = (TextServer::FontLCDSubpixelLayout)(int)GLOBAL_DEF_BASIC(PropertyInfo(Variant::INT, "gui/theme/lcd_subpixel_layout", PROPERTY_HINT_ENUM, "Disabled,Horizontal RGB,Horizontal BGR,Vertical RGB,Vertical BGR"), 1); + font_hinting = (TextServer::Hinting)(int)GLOBAL_DEF_BASIC(PropertyInfo(Variant::INT, "gui/theme/default_font_hinting", PROPERTY_HINT_ENUM, "None,Light,Normal"), TextServer::HINTING_LIGHT); + font_msdf = GLOBAL_DEF_BASIC("gui/theme/default_font_multichannel_signed_distance_field", false); + font_generate_mipmaps = GLOBAL_DEF_BASIC("gui/theme/default_font_generate_mipmaps", false); +#endif // PIXEL_ENGINE if (MessageQueue::get_singleton()) { // May not exist in tests etc. callable_mp(this, &ThemeDB::_sort_theme_items).call_deferred(); +#ifdef PIXEL_ENGINE + ProjectSettings::get_singleton()->connect("settings_changed", callable_mp(this, &ThemeDB::_update_default_theme)); +#endif // PIXEL_ENGINE } } @@ -469,9 +785,14 @@ ThemeDB::~ThemeDB() { // frees any objects that can be recreated by initialize_theme*(). _finalize_theme_contexts(); +#ifdef PIXEL_ENGINE + finalize_default_theme(); +#endif // PIXEL_ENGINE default_theme.unref(); +#ifndef PIXEL_ENGINE project_theme.unref(); +#endif // !PIXEL_ENGINE fallback_font.unref(); fallback_icon.unref(); diff --git a/scene/theme/theme_db.h b/scene/theme/theme_db.h index 353894f41e47..15e9435fb0dd 100644 --- a/scene/theme/theme_db.h +++ b/scene/theme/theme_db.h @@ -28,6 +28,17 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /**************************************************************************/ +/**************************************************************************/ +/* PIXEL ENGINE */ +/* Copyright (c) 2024-present Pixel Engine contributors (see AUTHORS.md). */ +/**************************************************************************/ +/* NOTICE: */ +/* This file contains modifications and additions specific to the Pixel */ +/* Engine project. While these changes are licensed under the MIT license */ +/* for compatibility, we request proper attribution if reused in any */ +/* derivative works, including meta-forks. */ +/**************************************************************************/ + #ifndef THEME_DB_H #define THEME_DB_H @@ -78,8 +89,50 @@ class ThemeDB : public Object { // Global Theme resources used by the default theme context. Ref default_theme; +#ifndef PIXEL_ENGINE Ref project_theme; +#endif // !PIXEL_ENGINE + +#ifdef PIXEL_ENGINE + enum FontColorOverride { + FONT_COLOR_OVERRIDE_AUTO, + FONT_COLOR_OVERRIDE_LIGHT, + FONT_COLOR_OVERRIDE_DARK, + FONT_COLOR_OVERRIDE_CUSTOM + }; + Color _get_font_color() const; + + Color base_color; + Color accent_color; + Color font_color; + Color font_outline_color; + float contrast; + float b2_contrast; + float b3_contrast; + float b4_contrast; + float a2_contrast; + float bg_contrast; + int margin; + int padding; + int border_width; + int corner_radius; + int font_size; + int font_outline_size; + float font_embolden; + int font_spacing_glyph; + int font_spacing_space; + int font_spacing_top; + int font_spacing_bottom; + float scale; + String custom_font; + TextServer::SubpixelPositioning font_subpixel_positioning; + TextServer::FontLCDSubpixelLayout font_lcd_subpixel_layout; + TextServer::FontAntialiasing font_antialiasing; + TextServer::Hinting font_hinting; + bool font_msdf; + bool font_generate_mipmaps; +#endif // PIXEL_ENGINE // Universal default values, final fallback for every theme. float fallback_base_scale = 1.0; @@ -123,6 +176,9 @@ class ThemeDB : public Object { HashMap> theme_item_binds_list; // Used for listing purposes. void _sort_theme_items(); +#ifdef PIXEL_ENGINE + void _update_default_theme(); +#endif // PIXEL_ENGINE protected: static void _bind_methods(); @@ -137,8 +193,10 @@ class ThemeDB : public Object { void set_default_theme(const Ref &p_default); Ref get_default_theme(); +#ifndef PIXEL_ENGINE void set_project_theme(const Ref &p_project_default); Ref get_project_theme(); +#endif // !PIXEL_ENGINE // Universal fallback values.