Skip to content

Commit

Permalink
Highlight hovered GraphEdit connection by widening the line
Browse files Browse the repository at this point in the history
Currently, GraphEdit connections are highlighted by tinting the color.
With this change the connections are highlighted by widening the line
by a configurable factor.
  • Loading branch information
Sauermann committed Dec 16, 2024
1 parent b9437c3 commit 09a5527
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 12 deletions.
6 changes: 3 additions & 3 deletions doc/classes/GraphEdit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -501,9 +501,6 @@
<theme_item name="activity" data_type="color" type="Color" default="Color(1, 1, 1, 1)">
Color the connection line is interpolated to based on the activity value of a connection (see [method set_connection_activity]).
</theme_item>
<theme_item name="connection_hover_tint_color" data_type="color" type="Color" default="Color(0, 0, 0, 0.3)">
Color which is blended with the connection line when the mouse is hovering over it.
</theme_item>
<theme_item name="connection_rim_color" data_type="color" type="Color" default="Color(0.1, 0.1, 0.1, 0.6)">
Color of the rim around each connection line used for making intersecting lines more distinguishable.
</theme_item>
Expand All @@ -522,6 +519,9 @@
<theme_item name="selection_stroke" data_type="color" type="Color" default="Color(1, 1, 1, 0.8)">
The outline color of the selection rectangle.
</theme_item>
<theme_item name="connection_hover_thickness" data_type="constant" type="int" default="80">
Widen the line of the connection when the mouse is hovering over it by a percentage factor. A value of [code]0[/code] disables the highlight. A value of [code]100[/code] doubles the line width.
</theme_item>
<theme_item name="port_hotzone_inner_extent" data_type="constant" type="int" default="22">
The horizontal range within which a port can be grabbed (inner side).
</theme_item>
Expand Down
2 changes: 1 addition & 1 deletion editor/themes/editor_theme_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1556,7 +1556,7 @@ void EditorThemeManager::_populate_standard_styles(const Ref<EditorTheme> &p_the
p_theme->set_color("selection_stroke", "GraphEdit", p_theme->get_color(SNAME("box_selection_stroke_color"), EditorStringName(Editor)));
p_theme->set_color("activity", "GraphEdit", p_config.dark_theme ? Color(1, 1, 1) : Color(0, 0, 0));

p_theme->set_color("connection_hover_tint_color", "GraphEdit", p_config.dark_theme ? Color(0, 0, 0, 0.3) : Color(1, 1, 1, 0.3));
p_theme->set_constant("connection_hover_thickness", "GraphEdit", 80);
p_theme->set_color("connection_valid_target_tint_color", "GraphEdit", p_config.dark_theme ? Color(1, 1, 1, 0.4) : Color(0, 0, 0, 0.4));
p_theme->set_color("connection_rim_color", "GraphEdit", p_config.tree_panel_style->get_bg_color());

Expand Down
11 changes: 5 additions & 6 deletions scene/gui/graph_edit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1436,15 +1436,14 @@ void GraphEdit::_update_connections() {
to_color = to_color.lerp(theme_cache.activity_color, c->activity);
}

if (c == hovered_connection) {
from_color = from_color.blend(theme_cache.connection_hover_tint_color);
to_color = to_color.blend(theme_cache.connection_hover_tint_color);
}

// Update Line2D node.
Ref<Gradient> line_gradient = memnew(Gradient);

float line_width = _get_shader_line_width();
if (c == hovered_connection) {
line_width *= 1.0f + ((float)theme_cache.connection_hover_thickness / 100.0f);
}

c->_cache.line->set_width(line_width);
line_gradient->set_color(0, from_color);
line_gradient->set_color(1, to_color);
Expand Down Expand Up @@ -2816,7 +2815,7 @@ void GraphEdit::_bind_methods() {
BIND_THEME_ITEM(Theme::DATA_TYPE_COLOR, GraphEdit, grid_minor);

BIND_THEME_ITEM_CUSTOM(Theme::DATA_TYPE_COLOR, GraphEdit, activity_color, "activity");
BIND_THEME_ITEM(Theme::DATA_TYPE_COLOR, GraphEdit, connection_hover_tint_color);
BIND_THEME_ITEM(Theme::DATA_TYPE_CONSTANT, GraphEdit, connection_hover_thickness);
BIND_THEME_ITEM(Theme::DATA_TYPE_COLOR, GraphEdit, connection_valid_target_tint_color);
BIND_THEME_ITEM(Theme::DATA_TYPE_COLOR, GraphEdit, connection_rim_color);
BIND_THEME_ITEM(Theme::DATA_TYPE_COLOR, GraphEdit, selection_fill);
Expand Down
2 changes: 1 addition & 1 deletion scene/gui/graph_edit.h
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ class GraphEdit : public Control {
Color grid_minor;

Color activity_color;
Color connection_hover_tint_color;
int connection_hover_thickness;
Color connection_valid_target_tint_color;
Color connection_rim_color;

Expand Down
2 changes: 1 addition & 1 deletion scene/theme/default_theme.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1252,7 +1252,7 @@ void fill_default_theme(Ref<Theme> &theme, const Ref<Font> &default_font, const
theme->set_color("selection_fill", "GraphEdit", Color(1, 1, 1, 0.3));
theme->set_color("selection_stroke", "GraphEdit", Color(1, 1, 1, 0.8));
theme->set_color("activity", "GraphEdit", Color(1, 1, 1));
theme->set_color("connection_hover_tint_color", "GraphEdit", Color(0, 0, 0, 0.3));
theme->set_constant("connection_hover_thickness", "GraphEdit", 80);
theme->set_color("connection_valid_target_tint_color", "GraphEdit", Color(1, 1, 1, 0.4));
theme->set_color("connection_rim_color", "GraphEdit", style_normal_color);

Expand Down

0 comments on commit 09a5527

Please sign in to comment.