Skip to content

Commit

Permalink
CraterCrashGH-59 Add configurable corner/border radius
Browse files Browse the repository at this point in the history
  • Loading branch information
Naros committed Jul 14, 2024
1 parent 0ba992d commit a839b76
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/common/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ void OrchestratorSettings::_register_settings()
_settings.emplace_back(COLOR_NO_ALPHA_SETTING("ui/nodes/background_color", Color::html("#191d23")));
_settings.emplace_back(COLOR_NO_ALPHA_SETTING("ui/nodes/border_color", Color(0.059f, 0.067f, 0.082f)));
_settings.emplace_back(COLOR_NO_ALPHA_SETTING("ui/nodes/border_selected_color", Color(0.68f, 0.44f, 0.09f)));
_settings.emplace_back(RANGE_SETTING("ui/nodes/border_radius", "0,16,1", 4));
_settings.emplace_back(RANGE_SETTING("ui/nodes/border_width", "0,8,1", 2));

// Nodes
Expand Down
43 changes: 36 additions & 7 deletions src/editor/theme/theme_cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
#include <godot_cpp/classes/graph_node.hpp>
#include <godot_cpp/classes/project_settings.hpp>
#include <godot_cpp/classes/style_box_flat.hpp>
#include <godot_cpp/classes/window.hpp>
#include <godot_cpp/variant/utility_functions.hpp>

void OrchestratorThemeCache::_settings_changed()
{
Expand All @@ -38,7 +36,8 @@ void OrchestratorThemeCache::_settings_changed()
const Color border = settings->get_setting("ui/nodes/border_color", Color(0, 0, 0));
const Color select = settings->get_setting("ui/nodes/border_selected_color", Color(0.68f, 0.44f, 0.09f));
const Color bkgrnd = settings->get_setting("ui/nodes/background_color", Color::html("#191d23"));
const float bwidth = settings->get_setting("ui/nodes/border_width", 2);
const int radius = settings->get_setting("ui/nodes/border_radius", 4);
const int bwidth = settings->get_setting("ui/nodes/border_width", 2);

Ref<StyleBoxFlat> panel = get_theme_stylebox("panel", "GraphNode");
if (!panel.is_valid())
Expand All @@ -52,6 +51,7 @@ void OrchestratorThemeCache::_settings_changed()
new_panel->set_border_width(SIDE_TOP, 0);
new_panel->set_content_margin_all(2);
new_panel->set_content_margin(SIDE_BOTTOM, 6);
new_panel->set_corner_radius_all(radius);
new_panel->set_corner_radius(CORNER_TOP_LEFT, 0);
new_panel->set_corner_radius(CORNER_TOP_RIGHT, 0);
new_panel->set_bg_color(bkgrnd);
Expand All @@ -74,7 +74,14 @@ void OrchestratorThemeCache::_settings_changed()
if (panel->get_bg_color() != bkgrnd)
panel->set_bg_color(bkgrnd);

if (!UtilityFunctions::is_equal_approx(panel->get_border_width(SIDE_LEFT), bwidth))
if (panel->get_corner_radius(CORNER_BOTTOM_LEFT) != radius)
{
panel->set_corner_radius_all(radius);
panel->set_corner_radius(CORNER_TOP_LEFT, 0);
panel->set_corner_radius(CORNER_TOP_RIGHT, 0);
}

if (panel->get_border_width(SIDE_LEFT) != bwidth)
{
panel->set_border_width_all(bwidth);
panel->set_border_width(SIDE_TOP, 0);
Expand All @@ -89,7 +96,14 @@ void OrchestratorThemeCache::_settings_changed()
if (panel_selected->get_border_color() != select)
panel_selected->set_border_color(select);

if (!UtilityFunctions::is_equal_approx(panel_selected->get_border_width(SIDE_LEFT), bwidth))
if (panel_selected->get_corner_radius(CORNER_BOTTOM_LEFT) != radius)
{
panel_selected->set_corner_radius_all(radius);
panel_selected->set_corner_radius(CORNER_TOP_LEFT, 0);
panel_selected->set_corner_radius(CORNER_TOP_RIGHT, 0);
}

if (panel_selected->get_border_width(SIDE_LEFT) != bwidth)
{
panel_selected->set_border_width_all(bwidth);
panel_selected->set_border_width(SIDE_TOP, 0);
Expand All @@ -115,6 +129,7 @@ void OrchestratorThemeCache::_settings_changed()
new_titlebar->set_bg_color(color);
new_titlebar->set_border_width_all(bwidth);
new_titlebar->set_border_width(SIDE_BOTTOM, 0);
new_titlebar->set_corner_radius_all(radius);
new_titlebar->set_corner_radius(CORNER_BOTTOM_LEFT, 0);
new_titlebar->set_corner_radius(CORNER_BOTTOM_RIGHT, 0);

Expand Down Expand Up @@ -142,7 +157,14 @@ void OrchestratorThemeCache::_settings_changed()
titlebar->set_border_color(border);
}

if (!UtilityFunctions::is_equal_approx(titlebar->get_border_width(SIDE_LEFT), bwidth))
if (titlebar->get_corner_radius(CORNER_TOP_LEFT) != radius)
{
titlebar->set_corner_radius_all(radius);
titlebar->set_corner_radius(CORNER_BOTTOM_LEFT, 0);
titlebar->set_corner_radius(CORNER_BOTTOM_RIGHT, 0);
}

if (titlebar->get_border_width(SIDE_LEFT) != bwidth)
{
titlebar->set_border_width_all(bwidth);
titlebar->set_border_width(SIDE_BOTTOM, 0);
Expand All @@ -156,7 +178,14 @@ void OrchestratorThemeCache::_settings_changed()
if (titlebar_selected->get_border_color() != select)
titlebar_selected->set_border_color(select);

if (!UtilityFunctions::is_equal_approx(titlebar_selected->get_border_width(SIDE_LEFT), bwidth))
if (titlebar_selected->get_corner_radius(CORNER_TOP_LEFT) != radius)
{
titlebar_selected->set_corner_radius_all(radius);
titlebar_selected->set_corner_radius(CORNER_BOTTOM_LEFT, 0);
titlebar_selected->set_corner_radius(CORNER_BOTTOM_RIGHT, 0);
}

if (titlebar_selected->get_border_width(SIDE_LEFT) != bwidth)
{
titlebar_selected->set_border_width_all(bwidth);
titlebar_selected->set_border_width(SIDE_BOTTOM, 0);
Expand Down

0 comments on commit a839b76

Please sign in to comment.