summaryrefslogtreecommitdiff
path: root/scene/gui/graph_edit.h
diff options
context:
space:
mode:
Diffstat (limited to 'scene/gui/graph_edit.h')
-rw-r--r--scene/gui/graph_edit.h170
1 files changed, 137 insertions, 33 deletions
diff --git a/scene/gui/graph_edit.h b/scene/gui/graph_edit.h
index d87bd41f27..44e50aa3c2 100644
--- a/scene/gui/graph_edit.h
+++ b/scene/gui/graph_edit.h
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
+/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -34,6 +34,7 @@
#include "scene/gui/box_container.h"
#include "scene/gui/button.h"
#include "scene/gui/graph_node.h"
+#include "scene/gui/label.h"
#include "scene/gui/scroll_bar.h"
#include "scene/gui/slider.h"
#include "scene/gui/spin_box.h"
@@ -45,6 +46,7 @@ class GraphEditFilter : public Control {
GDCLASS(GraphEditFilter, Control);
friend class GraphEdit;
+ friend class GraphEditMinimap;
GraphEdit *ge;
virtual bool has_point(const Point2 &p_point) const override;
@@ -52,6 +54,43 @@ public:
GraphEditFilter(GraphEdit *p_edit);
};
+class GraphEditMinimap : public Control {
+ GDCLASS(GraphEditMinimap, Control);
+
+ friend class GraphEdit;
+ friend class GraphEditFilter;
+ GraphEdit *ge;
+
+protected:
+public:
+ GraphEditMinimap(GraphEdit *p_edit);
+
+ void update_minimap();
+ Rect2 get_camera_rect();
+
+private:
+ Vector2 minimap_padding;
+ Vector2 minimap_offset;
+ Vector2 graph_proportions;
+ Vector2 graph_padding;
+ Vector2 camera_position;
+ Vector2 camera_size;
+
+ bool is_pressing;
+ bool is_resizing;
+
+ Vector2 _get_render_size();
+ Vector2 _get_graph_offset();
+ Vector2 _get_graph_size();
+
+ Vector2 _convert_from_graph_position(const Vector2 &p_position);
+ Vector2 _convert_to_graph_position(const Vector2 &p_position);
+
+ virtual void gui_input(const Ref<InputEvent> &p_ev) override;
+
+ void _adjust_graph_scroll(const Vector2 &p_offset);
+};
+
class GraphEdit : public Control {
GDCLASS(GraphEdit, Control);
@@ -59,12 +98,13 @@ public:
struct Connection {
StringName from;
StringName to;
- int from_port;
- int to_port;
- float activity;
+ int from_port = 0;
+ int to_port = 0;
+ float activity = 0.0;
};
private:
+ Label *zoom_label;
Button *zoom_minus;
Button *zoom_reset;
Button *zoom_plus;
@@ -72,69 +112,82 @@ private:
Button *snap_button;
SpinBox *snap_amount;
- void _zoom_minus();
- void _zoom_reset();
- void _zoom_plus();
+ Button *minimap_button;
+
+ Button *layout_button;
HScrollBar *h_scroll;
VScrollBar *v_scroll;
- float port_grab_distance_horizontal;
+ float port_grab_distance_horizontal = 0.0;
float port_grab_distance_vertical;
- bool connecting;
+ bool connecting = false;
String connecting_from;
- bool connecting_out;
- int connecting_index;
- int connecting_type;
+ bool connecting_out = false;
+ int connecting_index = 0;
+ int connecting_type = 0;
Color connecting_color;
- bool connecting_target;
+ bool connecting_target = false;
Vector2 connecting_to;
String connecting_target_to;
int connecting_target_index;
- bool just_disconnected;
- bool connecting_valid;
+ bool just_disconnected = false;
+ bool connecting_valid = false;
Vector2 click_pos;
- bool dragging;
- bool just_selected;
- bool moving_selection;
+ bool dragging = false;
+ bool just_selected = false;
+ bool moving_selection = false;
Vector2 drag_accum;
- float zoom;
+ float zoom = 1.0;
+ float zoom_step = 1.2;
+ float zoom_min;
+ float zoom_max;
+
+ void _zoom_minus();
+ void _zoom_reset();
+ void _zoom_plus();
+ void _update_zoom_label();
- bool box_selecting;
- bool box_selection_mode_additive;
+ bool box_selecting = false;
+ bool box_selection_mode_additive = false;
Point2 box_selecting_from;
Point2 box_selecting_to;
Rect2 box_selecting_rect;
- List<GraphNode *> previus_selected;
+ List<GraphNode *> previous_selected;
- bool setting_scroll_ofs;
- bool right_disconnects;
- bool updating;
- bool awaiting_scroll_offset_update;
+ bool setting_scroll_ofs = false;
+ bool right_disconnects = false;
+ bool updating = false;
+ bool awaiting_scroll_offset_update = false;
List<Connection> connections;
- void _bake_segment2d(Vector<Vector2> &points, Vector<Color> &colors, float p_begin, float p_end, const Vector2 &p_a, const Vector2 &p_out, const Vector2 &p_b, const Vector2 &p_in, int p_depth, int p_min_depth, int p_max_depth, float p_tol, const Color &p_color, const Color &p_to_color, int &lines) const;
+ float lines_thickness = 2.0f;
+ bool lines_antialiased = true;
- void _draw_cos_line(CanvasItem *p_where, const Vector2 &p_from, const Vector2 &p_to, const Color &p_color, const Color &p_to_color);
+ PackedVector2Array get_connection_line(const Vector2 &p_from, const Vector2 &p_to);
+ void _draw_connection_line(CanvasItem *p_where, const Vector2 &p_from, const Vector2 &p_to, const Color &p_color, const Color &p_to_color, float p_width, float p_zoom);
void _graph_node_raised(Node *p_gn);
void _graph_node_moved(Node *p_gn);
+ void _graph_node_slot_updated(int p_index, Node *p_gn);
void _update_scroll();
void _scroll_moved(double);
- void _gui_input(const Ref<InputEvent> &p_ev);
+ virtual void gui_input(const Ref<InputEvent> &p_ev) override;
Control *connections_layer;
GraphEditFilter *top_layer;
+ GraphEditMinimap *minimap;
void _top_layer_input(const Ref<InputEvent> &p_ev);
- bool is_in_hot_zone(const Vector2 &pos, const Vector2 &p_mouse_pos);
+ bool is_in_hot_zone(const Vector2 &pos, const Vector2 &p_mouse_pos, const Vector2i &p_port_size, bool p_left);
void _top_layer_draw();
void _connections_layer_draw();
+ void _minimap_draw();
void _update_scroll_offset();
Array _get_connection_list() const;
@@ -147,7 +200,7 @@ private:
uint32_t type_a;
uint32_t type_b;
};
- uint64_t key;
+ uint64_t key = 0;
};
bool operator<(const ConnType &p_type) const {
@@ -171,14 +224,36 @@ private:
void _snap_toggled();
void _snap_value_changed(double);
+ friend class GraphEditMinimap;
+ void _minimap_toggled();
+
bool _check_clickable_control(Control *p_control, const Vector2 &pos);
+ bool arranging_graph = false;
+
+ enum SET_OPERATIONS {
+ IS_EQUAL,
+ IS_SUBSET,
+ DIFFERENCE,
+ UNION,
+ };
+
+ int _set_operations(SET_OPERATIONS p_operation, Set<StringName> &r_u, const Set<StringName> &r_v);
+ HashMap<int, Vector<StringName>> _layering(const Set<StringName> &r_selected_nodes, const HashMap<StringName, Set<StringName>> &r_upper_neighbours);
+ Vector<StringName> _split(const Vector<StringName> &r_layer, const HashMap<StringName, Dictionary> &r_crossings);
+ void _horizontal_alignment(Dictionary &r_root, Dictionary &r_align, const HashMap<int, Vector<StringName>> &r_layers, const HashMap<StringName, Set<StringName>> &r_upper_neighbours, const Set<StringName> &r_selected_nodes);
+ void _crossing_minimisation(HashMap<int, Vector<StringName>> &r_layers, const HashMap<StringName, Set<StringName>> &r_upper_neighbours);
+ void _calculate_inner_shifts(Dictionary &r_inner_shifts, const Dictionary &r_root, const Dictionary &r_node_names, const Dictionary &r_align, const Set<StringName> &r_block_heads, const HashMap<StringName, Pair<int, int>> &r_port_info);
+ float _calculate_threshold(StringName p_v, StringName p_w, const Dictionary &r_node_names, const HashMap<int, Vector<StringName>> &r_layers, const Dictionary &r_root, const Dictionary &r_align, const Dictionary &r_inner_shift, real_t p_current_threshold, const HashMap<StringName, Vector2> &r_node_positions);
+ void _place_block(StringName p_v, float p_delta, const HashMap<int, Vector<StringName>> &r_layers, const Dictionary &r_root, const Dictionary &r_align, const Dictionary &r_node_name, const Dictionary &r_inner_shift, Dictionary &r_sink, Dictionary &r_shift, HashMap<StringName, Vector2> &r_node_positions);
+
protected:
static void _bind_methods();
virtual void add_child_notify(Node *p_child) override;
virtual void remove_child_notify(Node *p_child) override;
void _notification(int p_what);
- virtual bool clips_input() const override;
+
+ GDVIRTUAL2RC(Vector<Vector2>, _get_connection_line, Vector2, Vector2)
public:
Error connect_node(const StringName &p_from, int p_from_port, const StringName &p_to, int p_to_port);
@@ -196,7 +271,28 @@ public:
void set_zoom_custom(float p_zoom, const Vector2 &p_center);
float get_zoom() const;
+ void set_zoom_min(float p_zoom_min);
+ float get_zoom_min() const;
+
+ void set_zoom_max(float p_zoom_max);
+ float get_zoom_max() const;
+
+ void set_zoom_step(float p_zoom_step);
+ float get_zoom_step() const;
+
+ void set_show_zoom_label(bool p_enable);
+ bool is_showing_zoom_label() const;
+
+ void set_minimap_size(Vector2 p_size);
+ Vector2 get_minimap_size() const;
+ void set_minimap_opacity(float p_opacity);
+ float get_minimap_opacity() const;
+
+ void set_minimap_enabled(bool p_enable);
+ bool is_minimap_enabled() const;
+
GraphEditFilter *get_top_layer() const { return top_layer; }
+ GraphEditMinimap *get_minimap() const { return minimap; }
void get_connection_list(List<Connection> *r_connections) const;
void set_right_disconnects(bool p_enable);
@@ -219,8 +315,16 @@ public:
int get_snap() const;
void set_snap(int p_snap);
+ void set_connection_lines_thickness(float p_thickness);
+ float get_connection_lines_thickness() const;
+
+ void set_connection_lines_antialiased(bool p_antialiased);
+ bool is_connection_lines_antialiased() const;
+
HBoxContainer *get_zoom_hbox();
+ void arrange_nodes();
+
GraphEdit();
};