2016-06-18 14:46:12 +02:00
|
|
|
/*************************************************************************/
|
2018-01-05 00:50:27 +01:00
|
|
|
/* graph_edit.h */
|
2016-06-18 14:46:12 +02:00
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
2017-08-27 14:16:55 +02:00
|
|
|
/* https://godotengine.org */
|
2016-06-18 14:46:12 +02:00
|
|
|
/*************************************************************************/
|
2020-01-01 11:16:22 +01:00
|
|
|
/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
|
2016-06-18 14:46:12 +02:00
|
|
|
/* */
|
|
|
|
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
|
|
/* a copy of this software and associated documentation files (the */
|
|
|
|
/* "Software"), to deal in the Software without restriction, including */
|
|
|
|
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
|
|
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
|
|
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
|
|
/* the following conditions: */
|
|
|
|
/* */
|
|
|
|
/* The above copyright notice and this permission notice shall be */
|
|
|
|
/* included in all copies or substantial portions of the Software. */
|
|
|
|
/* */
|
|
|
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
|
|
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
|
|
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
|
|
|
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
|
|
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
|
|
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
|
/*************************************************************************/
|
2018-01-05 00:50:27 +01:00
|
|
|
|
2015-01-03 20:52:37 +01:00
|
|
|
#ifndef GRAPH_EDIT_H
|
|
|
|
#define GRAPH_EDIT_H
|
|
|
|
|
2018-06-19 03:10:48 +02:00
|
|
|
#include "scene/gui/box_container.h"
|
2020-06-19 20:49:04 +02:00
|
|
|
#include "scene/gui/button.h"
|
2015-01-03 20:52:37 +01:00
|
|
|
#include "scene/gui/graph_node.h"
|
|
|
|
#include "scene/gui/scroll_bar.h"
|
2016-01-19 02:10:44 +01:00
|
|
|
#include "scene/gui/slider.h"
|
2016-08-04 05:05:35 +02:00
|
|
|
#include "scene/gui/spin_box.h"
|
2017-01-14 10:52:54 +01:00
|
|
|
#include "scene/gui/texture_rect.h"
|
2016-02-08 20:28:12 +01:00
|
|
|
|
2015-01-03 20:52:37 +01:00
|
|
|
class GraphEdit;
|
|
|
|
|
|
|
|
class GraphEditFilter : public Control {
|
2017-03-05 16:44:50 +01:00
|
|
|
GDCLASS(GraphEditFilter, Control);
|
2015-01-03 20:52:37 +01:00
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
friend class GraphEdit;
|
|
|
|
GraphEdit *ge;
|
2020-07-10 12:34:39 +02:00
|
|
|
virtual bool has_point(const Point2 &p_point) const override;
|
2015-01-03 20:52:37 +01:00
|
|
|
|
|
|
|
public:
|
2015-07-21 03:15:06 +02:00
|
|
|
GraphEditFilter(GraphEdit *p_edit);
|
2015-01-03 20:52:37 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
class GraphEdit : public Control {
|
2017-03-05 16:44:50 +01:00
|
|
|
GDCLASS(GraphEdit, Control);
|
2015-01-03 20:52:37 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
public:
|
2015-07-21 03:15:06 +02:00
|
|
|
struct Connection {
|
|
|
|
StringName from;
|
|
|
|
StringName to;
|
|
|
|
int from_port;
|
|
|
|
int to_port;
|
2018-06-19 03:10:48 +02:00
|
|
|
float activity;
|
2015-07-21 03:15:06 +02:00
|
|
|
};
|
2016-02-08 20:28:12 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
private:
|
2020-06-19 20:49:04 +02:00
|
|
|
Button *zoom_minus;
|
|
|
|
Button *zoom_reset;
|
|
|
|
Button *zoom_plus;
|
2016-02-08 20:28:12 +01:00
|
|
|
|
2020-06-19 20:49:04 +02:00
|
|
|
Button *snap_button;
|
2016-08-04 05:05:35 +02:00
|
|
|
SpinBox *snap_amount;
|
|
|
|
|
2016-02-08 20:28:12 +01:00
|
|
|
void _zoom_minus();
|
|
|
|
void _zoom_reset();
|
|
|
|
void _zoom_plus();
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
HScrollBar *h_scroll;
|
|
|
|
VScrollBar *v_scroll;
|
2015-01-03 20:52:37 +01:00
|
|
|
|
2018-05-13 05:34:35 +02:00
|
|
|
float port_grab_distance_horizontal;
|
|
|
|
float port_grab_distance_vertical;
|
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
bool connecting;
|
|
|
|
String connecting_from;
|
|
|
|
bool connecting_out;
|
|
|
|
int connecting_index;
|
|
|
|
int connecting_type;
|
|
|
|
Color connecting_color;
|
|
|
|
bool connecting_target;
|
|
|
|
Vector2 connecting_to;
|
|
|
|
String connecting_target_to;
|
|
|
|
int connecting_target_index;
|
2018-10-19 13:31:35 +02:00
|
|
|
bool just_disconnected;
|
2020-07-04 07:00:17 +02:00
|
|
|
bool connecting_valid;
|
|
|
|
Vector2 click_pos;
|
2015-01-03 20:52:37 +01:00
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
bool dragging;
|
|
|
|
bool just_selected;
|
|
|
|
Vector2 drag_accum;
|
2015-01-03 20:52:37 +01:00
|
|
|
|
2016-01-19 00:32:37 +01:00
|
|
|
float zoom;
|
|
|
|
|
2015-07-25 02:59:48 +02:00
|
|
|
bool box_selecting;
|
2020-04-10 22:00:50 +02:00
|
|
|
bool box_selection_mode_additive;
|
2015-07-25 02:59:48 +02:00
|
|
|
Point2 box_selecting_from;
|
|
|
|
Point2 box_selecting_to;
|
|
|
|
Rect2 box_selecting_rect;
|
2017-03-05 16:44:50 +01:00
|
|
|
List<GraphNode *> previus_selected;
|
2015-07-25 02:59:48 +02:00
|
|
|
|
2016-08-07 00:00:54 +02:00
|
|
|
bool setting_scroll_ofs;
|
2015-07-21 03:15:06 +02:00
|
|
|
bool right_disconnects;
|
|
|
|
bool updating;
|
2016-08-31 04:44:14 +02:00
|
|
|
bool awaiting_scroll_offset_update;
|
2015-07-21 03:15:06 +02:00
|
|
|
List<Connection> connections;
|
2015-01-03 20:52:37 +01:00
|
|
|
|
2017-07-01 02:30:17 +02:00
|
|
|
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;
|
2016-08-23 15:15:47 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void _draw_cos_line(CanvasItem *p_where, const Vector2 &p_from, const Vector2 &p_to, const Color &p_color, const Color &p_to_color);
|
2015-01-03 20:52:37 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void _graph_node_raised(Node *p_gn);
|
2015-07-21 03:15:06 +02:00
|
|
|
void _graph_node_moved(Node *p_gn);
|
2015-01-03 20:52:37 +01:00
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
void _update_scroll();
|
|
|
|
void _scroll_moved(double);
|
2017-05-20 17:38:03 +02:00
|
|
|
void _gui_input(const Ref<InputEvent> &p_ev);
|
2015-01-03 20:52:37 +01:00
|
|
|
|
2016-08-31 04:44:14 +02:00
|
|
|
Control *connections_layer;
|
2015-07-21 03:15:06 +02:00
|
|
|
GraphEditFilter *top_layer;
|
2017-05-20 17:38:03 +02:00
|
|
|
void _top_layer_input(const Ref<InputEvent> &p_ev);
|
2018-05-13 05:34:35 +02:00
|
|
|
|
2018-08-20 18:38:18 +02:00
|
|
|
bool is_in_hot_zone(const Vector2 &pos, const Vector2 &p_mouse_pos);
|
2018-05-13 05:34:35 +02:00
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
void _top_layer_draw();
|
2016-08-31 04:44:14 +02:00
|
|
|
void _connections_layer_draw();
|
2015-07-21 03:15:06 +02:00
|
|
|
void _update_scroll_offset();
|
2015-01-03 20:52:37 +01:00
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
Array _get_connection_list() const;
|
2015-01-08 04:41:34 +01:00
|
|
|
|
2016-08-23 15:15:47 +02:00
|
|
|
bool lines_on_bg;
|
|
|
|
|
2016-08-03 00:11:05 +02:00
|
|
|
struct ConnType {
|
|
|
|
union {
|
|
|
|
struct {
|
|
|
|
uint32_t type_a;
|
|
|
|
uint32_t type_b;
|
|
|
|
};
|
|
|
|
uint64_t key;
|
|
|
|
};
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
bool operator<(const ConnType &p_type) const {
|
|
|
|
return key < p_type.key;
|
2016-08-03 00:11:05 +02:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ConnType(uint32_t a = 0, uint32_t b = 0) {
|
|
|
|
type_a = a;
|
|
|
|
type_b = b;
|
2016-08-03 00:11:05 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
Set<ConnType> valid_connection_types;
|
|
|
|
Set<int> valid_left_disconnect_types;
|
|
|
|
Set<int> valid_right_disconnect_types;
|
|
|
|
|
2018-06-19 03:10:48 +02:00
|
|
|
HBoxContainer *zoom_hb;
|
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
friend class GraphEditFilter;
|
2017-03-05 16:44:50 +01:00
|
|
|
bool _filter_input(const Point2 &p_point);
|
2016-08-04 05:05:35 +02:00
|
|
|
void _snap_toggled();
|
|
|
|
void _snap_value_changed(double);
|
2015-01-03 20:52:37 +01:00
|
|
|
|
2018-08-20 18:38:18 +02:00
|
|
|
bool _check_clickable_control(Control *p_control, const Vector2 &pos);
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
protected:
|
2015-07-21 03:15:06 +02:00
|
|
|
static void _bind_methods();
|
2020-07-10 12:34:39 +02:00
|
|
|
virtual void add_child_notify(Node *p_child) override;
|
|
|
|
virtual void remove_child_notify(Node *p_child) override;
|
2015-07-21 03:15:06 +02:00
|
|
|
void _notification(int p_what);
|
2020-07-10 12:34:39 +02:00
|
|
|
virtual bool clips_input() const override;
|
2015-01-03 20:52:37 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
public:
|
|
|
|
Error connect_node(const StringName &p_from, int p_from_port, const StringName &p_to, int p_to_port);
|
|
|
|
bool is_node_connected(const StringName &p_from, int p_from_port, const StringName &p_to, int p_to_port);
|
|
|
|
void disconnect_node(const StringName &p_from, int p_from_port, const StringName &p_to, int p_to_port);
|
2015-07-21 03:15:06 +02:00
|
|
|
void clear_connections();
|
2015-01-03 20:52:37 +01:00
|
|
|
|
2018-06-19 03:10:48 +02:00
|
|
|
void set_connection_activity(const StringName &p_from, int p_from_port, const StringName &p_to, int p_to_port, float p_activity);
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void add_valid_connection_type(int p_type, int p_with_type);
|
|
|
|
void remove_valid_connection_type(int p_type, int p_with_type);
|
|
|
|
bool is_valid_connection_type(int p_type, int p_with_type) const;
|
2016-08-03 00:11:05 +02:00
|
|
|
|
2016-01-19 00:32:37 +01:00
|
|
|
void set_zoom(float p_zoom);
|
2017-11-01 21:49:39 +01:00
|
|
|
void set_zoom_custom(float p_zoom, const Vector2 &p_center);
|
2016-01-19 00:32:37 +01:00
|
|
|
float get_zoom() const;
|
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
GraphEditFilter *get_top_layer() const { return top_layer; }
|
|
|
|
void get_connection_list(List<Connection> *r_connections) const;
|
2015-01-03 20:52:37 +01:00
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
void set_right_disconnects(bool p_enable);
|
|
|
|
bool is_right_disconnects_enabled() const;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2016-08-03 00:11:05 +02:00
|
|
|
void add_valid_right_disconnect_type(int p_type);
|
|
|
|
void remove_valid_right_disconnect_type(int p_type);
|
|
|
|
|
|
|
|
void add_valid_left_disconnect_type(int p_type);
|
|
|
|
void remove_valid_left_disconnect_type(int p_type);
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void set_scroll_ofs(const Vector2 &p_ofs);
|
2016-01-17 22:26:32 +01:00
|
|
|
Vector2 get_scroll_ofs() const;
|
2015-01-07 05:45:46 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void set_selected(Node *p_child);
|
2016-08-03 00:11:05 +02:00
|
|
|
|
2016-08-04 05:05:35 +02:00
|
|
|
void set_use_snap(bool p_enable);
|
|
|
|
bool is_using_snap() const;
|
|
|
|
|
|
|
|
int get_snap() const;
|
|
|
|
void set_snap(int p_snap);
|
2015-01-03 20:52:37 +01:00
|
|
|
|
2018-06-19 03:10:48 +02:00
|
|
|
HBoxContainer *get_zoom_hbox();
|
|
|
|
|
2015-07-21 03:15:06 +02:00
|
|
|
GraphEdit();
|
2015-01-03 20:52:37 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // GRAPHEdit_H
|