Skip to content

Commit a8fc8ee

Browse files
committed
CraterCrashGH-59 Support border/corner radius & gradient title bars
1 parent c864647 commit a8fc8ee

File tree

3 files changed

+143
-15
lines changed

3 files changed

+143
-15
lines changed

src/editor/graph/graph_node.cpp

Lines changed: 119 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727

2828
#include <godot_cpp/classes/button.hpp>
2929
#include <godot_cpp/classes/editor_inspector.hpp>
30+
#include <godot_cpp/classes/gradient.hpp>
31+
#include <godot_cpp/classes/gradient_texture2d.hpp>
3032
#include <godot_cpp/classes/input.hpp>
3133
#include <godot_cpp/classes/input_event_action.hpp>
3234
#include <godot_cpp/classes/input_event_mouse_button.hpp>
@@ -36,6 +38,7 @@
3638
#include <godot_cpp/classes/script_editor.hpp>
3739
#include <godot_cpp/classes/script_editor_base.hpp>
3840
#include <godot_cpp/classes/style_box_flat.hpp>
41+
#include <godot_cpp/classes/style_box_texture.hpp>
3942

4043
OrchestratorGraphNode::OrchestratorGraphNode(OrchestratorGraphEdit* p_graph, const Ref<OScriptNode>& p_node)
4144
{
@@ -341,37 +344,68 @@ void OrchestratorGraphNode::_update_styles()
341344
apply_style_defaults = false;
342345
Color color = os->get_setting(key);
343346

344-
Ref<StyleBoxFlat> panel = _make_colored_style("panel_selected", color);
347+
Ref<StyleBox> panel = _make_colored_style("panel_selected", color);
345348
if (panel.is_valid())
346349
add_theme_stylebox_override("panel", panel);
347350

348-
Ref<StyleBoxFlat> panel_selected = _make_selected_style("panel");
351+
Ref<StyleBox> panel_selected = _make_selected_style("panel");
349352
if (panel_selected.is_valid())
350353
add_theme_stylebox_override("panel_selected", panel_selected);
351354

352-
Ref<StyleBoxFlat> titlebar = _make_colored_style("titlebar_selected", color, true);
353-
if (titlebar.is_valid())
354-
add_theme_stylebox_override("titlebar", titlebar);
355+
if (_use_gradient_color_style())
356+
{
357+
Ref<StyleBox> sb = _make_colored_style("titlebar_selected", color, true);
358+
if (sb.is_valid())
359+
add_theme_stylebox_override("titlebar", sb);
360+
361+
Ref<StyleBox> sb_selected = _make_selected_style("titlebar", true);
362+
if (sb_selected.is_valid())
363+
add_theme_stylebox_override("titlebar_selected", sb_selected);
364+
365+
Ref<StyleBox> sb2 = _make_gradient_titlebar_style("titlebar_selected", color, false);
366+
if (sb2.is_valid())
367+
add_theme_stylebox_override("titlebar", sb2);
368+
}
369+
else
370+
{
371+
Ref<StyleBox> sb = _make_colored_style("titlebar_selected", color, true);
372+
if (sb.is_valid())
373+
add_theme_stylebox_override("titlebar", sb);
355374

356-
Ref<StyleBoxFlat> titlebar_selected = _make_selected_style("titlebar", true);
357-
if (titlebar_selected.is_valid())
358-
add_theme_stylebox_override("titlebar_selected", titlebar_selected);
375+
Ref<StyleBox> sb_selected = _make_selected_style("titlebar", true);
376+
if (sb_selected.is_valid())
377+
add_theme_stylebox_override("titlebar_selected", sb_selected);
378+
}
359379
}
360380
}
361381

362382
if (apply_style_defaults)
363383
{
364-
Ref<StyleBoxFlat> panel_selected = _make_selected_style("panel_selected");
384+
Ref<StyleBox> panel_selected = _make_selected_style("panel_selected");
365385
if (panel_selected.is_valid())
366386
add_theme_stylebox_override("panel_selected", panel_selected);
367387

368-
Ref<StyleBoxFlat> titlebar_selected = _make_selected_style("titlebar_selected", true);
388+
Ref<StyleBox> titlebar_selected = _make_selected_style("titlebar_selected", true);
369389
if (titlebar_selected.is_valid())
370390
add_theme_stylebox_override("titlebar_selected", titlebar_selected);
371391
}
372392
}
373393

374-
Ref<StyleBoxFlat> OrchestratorGraphNode::_make_colored_style(const String& p_existing_name, const Color& p_color, bool p_titlebar)
394+
Color OrchestratorGraphNode::_get_selection_color() const
395+
{
396+
return { 0.68f, 0.44f, 0.09f };
397+
}
398+
399+
bool OrchestratorGraphNode::_use_gradient_color_style() const
400+
{
401+
OrchestratorSettings* os = OrchestratorSettings::get_singleton();
402+
if (os)
403+
return os->get_setting("ui/nodes/titlebar/use_gradient_colors", false);
404+
405+
return false;
406+
}
407+
408+
Ref<StyleBox> OrchestratorGraphNode::_make_colored_style(const String& p_existing_name, const Color& p_color, bool p_titlebar)
375409
{
376410
Ref<StyleBoxFlat> sb = get_theme_stylebox(p_existing_name);
377411
if (sb.is_valid())
@@ -381,26 +415,98 @@ Ref<StyleBoxFlat> OrchestratorGraphNode::_make_colored_style(const String& p_exi
381415
dup->set_bg_color(p_color);
382416
else
383417
dup->set_border_color(p_color);
418+
419+
_apply_corner_radius(dup, p_titlebar);
420+
384421
return dup;
385422
}
386423
return sb;
387424
}
388425

389-
Ref<StyleBoxFlat> OrchestratorGraphNode::_make_selected_style(const String& p_existing_name, bool p_titlebar)
426+
Ref<StyleBox> OrchestratorGraphNode::_make_selected_style(const String& p_existing_name, bool p_titlebar)
390427
{
391428
Ref<StyleBoxFlat> sb = get_theme_stylebox(p_existing_name);
392429
if (sb.is_valid())
393430
{
394431
Ref<StyleBoxFlat> dup = sb->duplicate(true);
395-
dup->set_border_color(Color(0.68f, 0.44f, 0.09f));
432+
dup->set_border_color(_get_selection_color());
396433
dup->set_border_width(p_titlebar ? SIDE_TOP : SIDE_BOTTOM, 2);
397434
dup->set_border_width(SIDE_LEFT, 2);
398435
dup->set_border_width(SIDE_RIGHT, 2);
436+
437+
_apply_corner_radius(dup, p_titlebar);
438+
399439
return dup;
400440
}
401441
return sb;
402442
}
403443

444+
Ref<StyleBox> OrchestratorGraphNode::_make_gradient_titlebar_style(const String& p_existing_name, const Color& p_color,
445+
bool p_selected)
446+
{
447+
Ref<Gradient> gradient(memnew(Gradient));
448+
449+
PackedFloat32Array offsets;
450+
offsets.push_back(0);
451+
offsets.push_back(1);
452+
gradient->set_offsets(offsets);
453+
454+
PackedColorArray colors = gradient->get_colors();
455+
colors.reverse();
456+
gradient->set_colors(colors);
457+
458+
Ref<GradientTexture2D> texture(memnew(GradientTexture2D));
459+
texture->set_gradient(gradient);
460+
texture->set_width(64);
461+
texture->set_height(64);
462+
texture->set_fill_to(Vector2(1.1, 0));
463+
464+
Ref<StyleBoxTexture> titlebar_tex(memnew(StyleBoxTexture));
465+
titlebar_tex->set_texture(texture);
466+
titlebar_tex->set_modulate(p_color);
467+
468+
Ref<StyleBox> sb = get_theme_stylebox(p_existing_name);
469+
if (sb.is_valid())
470+
{
471+
titlebar_tex->set_content_margin(SIDE_TOP, sb->get_content_margin(SIDE_TOP));
472+
titlebar_tex->set_content_margin(SIDE_RIGHT, sb->get_content_margin(SIDE_RIGHT));
473+
titlebar_tex->set_content_margin(SIDE_BOTTOM, sb->get_content_margin(SIDE_BOTTOM));
474+
titlebar_tex->set_content_margin(SIDE_LEFT, sb->get_content_margin(SIDE_LEFT));
475+
}
476+
477+
if (p_selected)
478+
titlebar_tex->set_modulate(_get_selection_color());
479+
480+
return titlebar_tex;
481+
}
482+
483+
void OrchestratorGraphNode::_apply_corner_radius(Ref<StyleBoxFlat>& p_stylebox, bool p_titlebar)
484+
{
485+
if (p_stylebox.is_valid() && _use_gradient_color_style())
486+
{
487+
// In this case, we explicitly only support a border radius of 6 on the bottom part.
488+
p_stylebox->set_corner_radius(CORNER_BOTTOM_LEFT, 6);
489+
p_stylebox->set_corner_radius(CORNER_BOTTOM_RIGHT, 6);
490+
return;
491+
}
492+
493+
OrchestratorSettings* os = OrchestratorSettings::get_singleton();
494+
if (p_stylebox.is_valid() && os)
495+
{
496+
int border_radius = os->get_setting("ui/nodes/border_radius", 6);
497+
if (p_titlebar)
498+
{
499+
p_stylebox->set_corner_radius(CORNER_TOP_LEFT, border_radius);
500+
p_stylebox->set_corner_radius(CORNER_TOP_RIGHT, border_radius);
501+
}
502+
else
503+
{
504+
p_stylebox->set_corner_radius(CORNER_BOTTOM_LEFT, border_radius);
505+
p_stylebox->set_corner_radius(CORNER_BOTTOM_RIGHT, border_radius);
506+
}
507+
}
508+
}
509+
404510
void OrchestratorGraphNode::_update_node_attributes()
405511
{
406512
// Attempt to shrink the container

src/editor/graph/graph_node.h

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,16 +172,36 @@ class OrchestratorGraphNode : public GraphNode
172172
/// Update the node's styles
173173
void _update_styles();
174174

175+
/// Returns the selection color when a node is selected by the user.
176+
/// @return the selection color
177+
Color _get_selection_color() const;
178+
179+
/// Returns whether to use gradient color scheme
180+
/// @return true to use gradient title bar color scheme, false otherwise
181+
bool _use_gradient_color_style() const;
182+
175183
/// Creates a style based on a specific color.
176184
/// @param p_existing_name the existing style to clone from
177185
/// @param p_color the color to be applied
178186
/// @param p_titlebar whether to treat the style box as a titlebar or panel border
179-
Ref<StyleBoxFlat> _make_colored_style(const String& p_existing_name, const Color& p_color, bool p_titlebar = false);
187+
Ref<StyleBox> _make_colored_style(const String& p_existing_name, const Color& p_color, bool p_titlebar = false);
180188

181189
/// Creates a style based on node selection color.
182190
/// @param p_existing_name the existing style to clone from
183191
/// @param p_titlebar whether to treat the style box as a titlebar or panel border
184-
Ref<StyleBoxFlat> _make_selected_style(const String& p_existing_name, bool p_titlebar = false);
192+
Ref<StyleBox> _make_selected_style(const String& p_existing_name, bool p_titlebar = false);
193+
194+
/// Creates a gradient style box
195+
/// @param p_existing_name the existing style name to use as a basis
196+
/// @param p_color the color to use
197+
/// @param p_selected whether it should render as selected
198+
/// @return the created style box
199+
Ref<StyleBox> _make_gradient_titlebar_style(const String& p_existing_name, const Color& p_color, bool p_selected = false);
200+
201+
/// Apply the configured corner radius to the given style box.
202+
/// @param p_stylebox the style box to be modified
203+
/// @param p_titlebar whether the style box represents the titlebar
204+
void _apply_corner_radius(Ref<StyleBoxFlat>& p_stylebox, bool p_titlebar = false);
185205

186206
/// Called by various callbacks to update node attributes
187207
void _update_node_attributes();

src/plugin/settings.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ void OrchestratorSettings::_register_settings()
9494

9595
_settings.emplace_back(BOOL_SETTING("ui/nodes/show_type_icons", true));
9696
_settings.emplace_back(BOOL_SETTING("ui/nodes/show_conversion_nodes", false));
97+
_settings.emplace_back(RANGE_SETTING("ui/nodes/border_radius", "0,24,1", 6));
98+
_settings.emplace_back(BOOL_SETTING("ui/nodes/titlebar/use_gradient_colors", false));
9799

98100
// Nodes
99101
_settings.emplace_back(COLOR_NO_ALPHA_SETTING("ui/node_colors/constants_and_literals", Color(0.271, 0.392, 0.2)));

0 commit comments

Comments
 (0)