You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-19 14:31:59 +00:00
Merge pull request #43416 from pycbouh/graph-minimap
Add a minimap to the GraphEdit
This commit is contained in:
@@ -77,6 +77,17 @@ static Ref<StyleBoxTexture> make_stylebox(T p_src, float p_left, float p_top, fl
|
||||
return style;
|
||||
}
|
||||
|
||||
static Ref<StyleBoxFlat> make_flat_stylebox(Color p_color, float p_margin_left = -1, float p_margin_top = -1, float p_margin_right = -1, float p_margin_bottom = -1) {
|
||||
Ref<StyleBoxFlat> style(memnew(StyleBoxFlat));
|
||||
style->set_bg_color(p_color);
|
||||
style->set_default_margin(MARGIN_LEFT, p_margin_left * scale);
|
||||
style->set_default_margin(MARGIN_RIGHT, p_margin_right * scale);
|
||||
style->set_default_margin(MARGIN_BOTTOM, p_margin_bottom * scale);
|
||||
style->set_default_margin(MARGIN_TOP, p_margin_top * scale);
|
||||
|
||||
return style;
|
||||
}
|
||||
|
||||
static Ref<StyleBoxTexture> sb_expand(Ref<StyleBoxTexture> p_sbox, float p_left, float p_top, float p_right, float p_botton) {
|
||||
p_sbox->set_expand_margin_size(MARGIN_LEFT, p_left * scale);
|
||||
p_sbox->set_expand_margin_size(MARGIN_TOP, p_top * scale);
|
||||
@@ -97,6 +108,25 @@ static Ref<Texture2D> make_icon(T p_src) {
|
||||
return texture;
|
||||
}
|
||||
|
||||
static Ref<Texture2D> flip_icon(Ref<Texture2D> p_texture, bool p_flip_y = false, bool p_flip_x = false) {
|
||||
if (!p_flip_y && !p_flip_x) {
|
||||
return p_texture;
|
||||
}
|
||||
|
||||
Ref<ImageTexture> texture(memnew(ImageTexture));
|
||||
Ref<Image> img = p_texture->get_data();
|
||||
|
||||
if (p_flip_y) {
|
||||
img->flip_y();
|
||||
}
|
||||
if (p_flip_x) {
|
||||
img->flip_x();
|
||||
}
|
||||
|
||||
texture->create_from_image(img);
|
||||
return texture;
|
||||
}
|
||||
|
||||
static Ref<StyleBox> make_empty_stylebox(float p_margin_left = -1, float p_margin_top = -1, float p_margin_right = -1, float p_margin_botton = -1) {
|
||||
Ref<StyleBox> style(memnew(StyleBoxEmpty));
|
||||
|
||||
@@ -854,6 +884,7 @@ void fill_default_theme(Ref<Theme> &theme, const Ref<Font> &default_font, const
|
||||
theme->set_icon("reset", "GraphEdit", make_icon(icon_zoom_reset_png));
|
||||
theme->set_icon("more", "GraphEdit", make_icon(icon_zoom_more_png));
|
||||
theme->set_icon("snap", "GraphEdit", make_icon(icon_snap_grid_png));
|
||||
theme->set_icon("minimap", "GraphEdit", make_icon(icon_grid_minimap_png));
|
||||
theme->set_stylebox("bg", "GraphEdit", make_stylebox(tree_bg_png, 4, 4, 4, 5));
|
||||
theme->set_color("grid_minor", "GraphEdit", Color(1, 1, 1, 0.05));
|
||||
theme->set_color("grid_major", "GraphEdit", Color(1, 1, 1, 0.2));
|
||||
@@ -867,6 +898,19 @@ void fill_default_theme(Ref<Theme> &theme, const Ref<Font> &default_font, const
|
||||
theme->set_constant("port_grab_distance_horizontal", "GraphEdit", 48 * scale);
|
||||
theme->set_constant("port_grab_distance_vertical", "GraphEdit", 6 * scale);
|
||||
|
||||
theme->set_stylebox("bg", "GraphEditMinimap", make_flat_stylebox(Color(0.24, 0.24, 0.24), 0, 0, 0, 0));
|
||||
Ref<StyleBoxFlat> style_minimap_camera = make_flat_stylebox(Color(0.65, 0.65, 0.65, 0.2), 0, 0, 0, 0);
|
||||
style_minimap_camera->set_border_color(Color(0.65, 0.65, 0.65, 0.45));
|
||||
style_minimap_camera->set_border_width_all(1);
|
||||
theme->set_stylebox("camera", "GraphEditMinimap", style_minimap_camera);
|
||||
Ref<StyleBoxFlat> style_minimap_node = make_flat_stylebox(Color(1, 1, 1), 0, 0, 0, 0);
|
||||
style_minimap_node->set_corner_radius_all(2);
|
||||
theme->set_stylebox("node", "GraphEditMinimap", style_minimap_node);
|
||||
|
||||
Ref<Texture2D> resizer_icon = make_icon(window_resizer_png);
|
||||
theme->set_icon("resizer", "GraphEditMinimap", flip_icon(resizer_icon, true, true));
|
||||
theme->set_color("resizer_color", "GraphEditMinimap", Color(1, 1, 1, 0.85));
|
||||
|
||||
// Theme
|
||||
|
||||
default_icon = make_icon(error_icon_png);
|
||||
|
||||
Reference in New Issue
Block a user