mirror of
https://github.com/godotengine/godot.git
synced 2025-10-19 16:03:29 +00:00
Add a minimap to the GraphEdit
This commit is contained in:
parent
65c1db3131
commit
816fef21f9
8 changed files with 511 additions and 10 deletions
|
@ -88,6 +88,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);
|
||||
|
@ -120,6 +131,25 @@ static Ref<Texture> make_icon(T p_src) {
|
|||
return texture;
|
||||
}
|
||||
|
||||
static Ref<Texture> flip_icon(Ref<Texture> 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<BitmapFont> make_font(int p_height, int p_ascent, int p_charcount, const int *p_char_rects, int p_kerning_count, const int *p_kernings, int p_w, int p_h, const unsigned char *p_img) {
|
||||
|
||||
Ref<BitmapFont> font(memnew(BitmapFont));
|
||||
|
@ -851,6 +881,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));
|
||||
|
@ -864,6 +895,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<Texture> 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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue