Skip to content

Commit 999ce61

Browse files
committed
Add a minimap to the GraphEdit
1 parent 27f1c67 commit 999ce61

File tree

8 files changed

+509
-9
lines changed

8 files changed

+509
-9
lines changed

doc/classes/GraphEdit.xml

+9
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,15 @@
175175
</methods>
176176
<members>
177177
<member name="focus_mode" type="int" setter="set_focus_mode" getter="get_focus_mode" override="true" enum="Control.FocusMode" default="2" />
178+
<member name="minimap_enabled" type="bool" setter="set_minimap_enabled" getter="is_minimap_enabled" default="true">
179+
If [code]true[/code], the minimap is visible.
180+
</member>
181+
<member name="minimap_opacity" type="float" setter="set_minimap_opacity" getter="get_minimap_opacity" default="0.45">
182+
The opacity of the minimap rectangle.
183+
</member>
184+
<member name="minimap_size" type="Vector2" setter="set_minimap_size" getter="get_minimap_size" default="Vector2(240, 160)">
185+
The size of the minimap rectangle. The map itself is based on the size of the grid area and is scaled to fit this rectangle.
186+
</member>
178187
<member name="rect_clip_content" type="bool" setter="set_clip_contents" getter="is_clipping_contents" override="true" default="true" />
179188
<member name="right_disconnects" type="bool" setter="set_right_disconnects" getter="is_right_disconnects_enabled" default="false">
180189
If [code]true[/code], enables disconnection of existing connections in the GraphEdit by dragging the right end.

editor/editor_themes.cpp

+42-1
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,25 @@ static Ref<StyleBoxLine> make_line_stylebox(Color p_color, int p_thickness = 1,
8585
return style;
8686
}
8787

88+
static Ref<Texture2D> flip_icon(Ref<Texture2D> p_texture, bool p_flip_y = false, bool p_flip_x = false) {
89+
if (!p_flip_y && !p_flip_x) {
90+
return p_texture;
91+
}
92+
93+
Ref<ImageTexture> texture(memnew(ImageTexture));
94+
Ref<Image> img = p_texture->get_data();
95+
96+
if (p_flip_y) {
97+
img->flip_y();
98+
}
99+
if (p_flip_x) {
100+
img->flip_x();
101+
}
102+
103+
texture->create_from_image(img);
104+
return texture;
105+
}
106+
88107
#ifdef MODULE_SVG_ENABLED
89108
static Ref<ImageTexture> editor_generate_icon(int p_index, bool p_convert_color, float p_scale = EDSCALE, bool p_force_filter = false) {
90109
Ref<ImageTexture> icon = memnew(ImageTexture);
@@ -1073,11 +1092,33 @@ Ref<Theme> create_editor_theme(const Ref<Theme> p_theme) {
10731092
theme->set_icon("more", "GraphEdit", theme->get_icon("ZoomMore", "EditorIcons"));
10741093
theme->set_icon("reset", "GraphEdit", theme->get_icon("ZoomReset", "EditorIcons"));
10751094
theme->set_icon("snap", "GraphEdit", theme->get_icon("SnapGrid", "EditorIcons"));
1095+
theme->set_icon("minimap", "GraphEdit", theme->get_icon("GridMinimap", "EditorIcons"));
10761096
theme->set_constant("bezier_len_pos", "GraphEdit", 80 * EDSCALE);
10771097
theme->set_constant("bezier_len_neg", "GraphEdit", 160 * EDSCALE);
10781098

1079-
// GraphNode
1099+
// GraphEditMinimap
1100+
theme->set_stylebox("bg", "GraphEditMinimap", make_flat_stylebox(dark_color_1, 0, 0, 0, 0));
1101+
Ref<StyleBoxFlat> style_minimap_camera;
1102+
Ref<StyleBoxFlat> style_minimap_node;
1103+
if (dark_theme) {
1104+
style_minimap_camera = make_flat_stylebox(Color(0.65, 0.65, 0.65, 0.2), 0, 0, 0, 0);
1105+
style_minimap_camera->set_border_color(Color(0.65, 0.65, 0.65, 0.45));
1106+
style_minimap_node = make_flat_stylebox(Color(1, 1, 1), 0, 0, 0, 0);
1107+
} else {
1108+
style_minimap_camera = make_flat_stylebox(Color(0.38, 0.38, 0.38, 0.2), 0, 0, 0, 0);
1109+
style_minimap_camera->set_border_color(Color(0.38, 0.38, 0.38, 0.45));
1110+
style_minimap_node = make_flat_stylebox(Color(0, 0, 0), 0, 0, 0, 0);
1111+
}
1112+
style_minimap_camera->set_border_width_all(1);
1113+
style_minimap_node->set_corner_radius_all(1);
1114+
theme->set_stylebox("camera", "GraphEditMinimap", style_minimap_camera);
1115+
theme->set_stylebox("node", "GraphEditMinimap", style_minimap_node);
1116+
1117+
Ref<Texture2D> resizer_icon = theme->get_icon("GuiResizer", "EditorIcons");
1118+
theme->set_icon("resizer", "GraphEditMinimap", flip_icon(resizer_icon, true, true));
1119+
theme->set_color("resizer_color", "GraphEditMinimap", Color(1, 1, 1, 0.65));
10801120

1121+
// GraphNode
10811122
const float mv = dark_theme ? 0.0 : 1.0;
10821123
const float mv2 = 1.0 - mv;
10831124
const int gn_margin_side = 28;

editor/icons/GridMinimap.svg

+1
Loading

0 commit comments

Comments
 (0)