Jelajahi Sumber

Highlight hovered `GraphEdit` connection by widening the line

This change causes the connections to be additionally highlighted by
widening the line with a configurable factor.
Markus Sauermann 8 bulan lalu
induk
melakukan
0a875ab3bb

+ 3 - 0
doc/classes/GraphEdit.xml

@@ -551,6 +551,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="0">
+			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>

+ 1 - 0
editor/themes/editor_theme_manager.cpp

@@ -1563,6 +1563,7 @@ void EditorThemeManager::_populate_standard_styles(const Ref<EditorTheme> &p_the
 		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", 0);
 		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());
 

+ 5 - 0
scene/gui/graph_edit.cpp

@@ -1453,6 +1453,10 @@ void GraphEdit::_update_connections() {
 		Ref<Gradient> line_gradient = memnew(Gradient);
 
 		float line_width = _get_shader_line_width();
+		if (conn == hovered_connection) {
+			line_width *= 1.0f + (theme_cache.connection_hover_thickness / 100.0f);
+		}
+
 		conn->_cache.line->set_width(line_width);
 		line_gradient->set_color(0, from_color);
 		line_gradient->set_color(1, to_color);
@@ -2842,6 +2846,7 @@ void GraphEdit::_bind_methods() {
 
 	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);

+ 1 - 0
scene/gui/graph_edit.h

@@ -275,6 +275,7 @@ private:
 
 		Color activity_color;
 		Color connection_hover_tint_color;
+		int connection_hover_thickness;
 		Color connection_valid_target_tint_color;
 		Color connection_rim_color;
 

+ 1 - 0
scene/theme/default_theme.cpp

@@ -1257,6 +1257,7 @@ void fill_default_theme(Ref<Theme> &theme, const Ref<Font> &default_font, const
 	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", 0);
 	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);