godot/scene/gui/graph_edit.h

228 lines
7.1 KiB
C++
Raw Normal View History

/*************************************************************************/
/* graph_edit.h */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2020 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 */
/* "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. */
/*************************************************************************/
#ifndef GRAPH_EDIT_H
#define GRAPH_EDIT_H
#include "scene/gui/box_container.h"
#include "scene/gui/button.h"
#include "scene/gui/graph_node.h"
#include "scene/gui/scroll_bar.h"
2016-01-19 09:10:44 +08:00
#include "scene/gui/slider.h"
#include "scene/gui/spin_box.h"
#include "scene/gui/texture_rect.h"
class GraphEdit;
class GraphEditFilter : public Control {
GDCLASS(GraphEditFilter, Control);
2015-07-21 09:15:06 +08:00
friend class GraphEdit;
GraphEdit *ge;
2020-07-10 18:34:39 +08:00
virtual bool has_point(const Point2 &p_point) const override;
public:
2015-07-21 09:15:06 +08:00
GraphEditFilter(GraphEdit *p_edit);
};
class GraphEdit : public Control {
GDCLASS(GraphEdit, Control);
public:
2015-07-21 09:15:06 +08:00
struct Connection {
StringName from;
StringName to;
int from_port;
int to_port;
float activity;
2015-07-21 09:15:06 +08:00
};
private:
Button *zoom_minus;
Button *zoom_reset;
Button *zoom_plus;
Button *snap_button;
SpinBox *snap_amount;
void _zoom_minus();
void _zoom_reset();
void _zoom_plus();
HScrollBar *h_scroll;
VScrollBar *v_scroll;
Improve VisualScript UX * Prototype faster function call ux. * Work on general search ux. * Able to create nodes from search. * Show class for variables but not methods. * Get actions search working. * Descriptions now show for both methods and properties. * Enable zooming on mouse wheel up and down. * Make the drag trigger on right mouse button. * Search now shows for action visual script nodes. * Able to search visual node names. * Search works better. * Change zooming scale to hide artifacts better. * Remove zoom changes * Select from base should check properties too like the other functions. * Seq_connect flag is needed to set sequence lines correctly. * Remove comment * Code cleanup with function names and arguments. * Use brief description for search descriptions. * Clean and fix bug with input nodes connecting with sequence lines. * Add a warning and fix some edge conditions with sequence into data lines and vice versa. * Don't search functions when pulling from a sequence node. * Don't show actions when pulling from a data line. * Set set and get properties. * Convert visual script operators to the correct type * Create a function preset finds only functions. * Singletons can now find functions. * Add shift-a for generic search. * Add brief descriptions for Visual Script nodes. * Search boxes can now filter names. * Add bigger hit zones to node connect. * For the drop zones, make all the rect2 areas the same size. * Function names in visual script node should be lower case so that search works better. * Use the convention of capitalize() for set, set, visual script nodes and methods. * Make search more general. Ignore "_" and make case-insensitive. Also made the search window smaller and remove extra info from search * Make type_cast use the connecting node's type and remove use of found variable. * Fix case where you call an instance's call function where it becomes an invalid call. * Make get_visual_node_names use a set of filters, move action creations and fix bug with sequence node connections. * Make the window bigger. * Make connect_data and connect_seq more robust. * Add icons to search items. * Add vs constructors in shift-a menu. * Operators, builtins and constructors show type name. Fix several problems with port connections. * In shift-a mode search everything. * Code cleanup * Work on autocompleting the type. * Use type guess in action creation. * Check if type hint string exists in object variables when generating the visual script search. * Add the hint to SceneTree. * Add original type detection. * Make type casting great again. This puts the type casted base type as the data output type string hint. * Pass the type in a VisualScriptFunctionCall too. * Set the base type correctly in VisualScriptFunctionGet and VisualScriptFunctionSet using hint string. * Make sure the instance is passed in VisualScriptPropertySet. * Restore search on the node's type. * Remove dependencies from graph_edit. * Remove dependencies from property_selector and name the class visual_script_property_selector. * Extract hot zones into a function. * Move hot_zones constants into default theme. * Bigger capture zones. * Clean messy port_grab_distance variables. * Remove RMB functionality. * Remove memory leak on showing visual script descriptions. * Read the port_grab_distance constants on enter tree and theme changed.
2018-05-13 11:34:35 +08:00
float port_grab_distance_horizontal;
float port_grab_distance_vertical;
2015-07-21 09:15:06 +08: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;
bool just_disconnected;
bool connecting_valid;
Vector2 click_pos;
2015-07-21 09:15:06 +08:00
bool dragging;
bool just_selected;
bool moving_selection;
2015-07-21 09:15:06 +08:00
Vector2 drag_accum;
float zoom;
2015-07-25 08:59:48 +08:00
bool box_selecting;
bool box_selection_mode_additive;
2015-07-25 08:59:48 +08:00
Point2 box_selecting_from;
Point2 box_selecting_to;
Rect2 box_selecting_rect;
List<GraphNode *> previus_selected;
2015-07-25 08:59:48 +08:00
bool setting_scroll_ofs;
2015-07-21 09:15:06 +08:00
bool right_disconnects;
bool updating;
bool awaiting_scroll_offset_update;
2015-07-21 09:15:06 +08:00
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;
2016-08-23 21:15:47 +08: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);
void _graph_node_raised(Node *p_gn);
2015-07-21 09:15:06 +08:00
void _graph_node_moved(Node *p_gn);
2015-07-21 09:15:06 +08:00
void _update_scroll();
void _scroll_moved(double);
void _gui_input(const Ref<InputEvent> &p_ev);
Control *connections_layer;
2015-07-21 09:15:06 +08:00
GraphEditFilter *top_layer;
void _top_layer_input(const Ref<InputEvent> &p_ev);
Improve VisualScript UX * Prototype faster function call ux. * Work on general search ux. * Able to create nodes from search. * Show class for variables but not methods. * Get actions search working. * Descriptions now show for both methods and properties. * Enable zooming on mouse wheel up and down. * Make the drag trigger on right mouse button. * Search now shows for action visual script nodes. * Able to search visual node names. * Search works better. * Change zooming scale to hide artifacts better. * Remove zoom changes * Select from base should check properties too like the other functions. * Seq_connect flag is needed to set sequence lines correctly. * Remove comment * Code cleanup with function names and arguments. * Use brief description for search descriptions. * Clean and fix bug with input nodes connecting with sequence lines. * Add a warning and fix some edge conditions with sequence into data lines and vice versa. * Don't search functions when pulling from a sequence node. * Don't show actions when pulling from a data line. * Set set and get properties. * Convert visual script operators to the correct type * Create a function preset finds only functions. * Singletons can now find functions. * Add shift-a for generic search. * Add brief descriptions for Visual Script nodes. * Search boxes can now filter names. * Add bigger hit zones to node connect. * For the drop zones, make all the rect2 areas the same size. * Function names in visual script node should be lower case so that search works better. * Use the convention of capitalize() for set, set, visual script nodes and methods. * Make search more general. Ignore "_" and make case-insensitive. Also made the search window smaller and remove extra info from search * Make type_cast use the connecting node's type and remove use of found variable. * Fix case where you call an instance's call function where it becomes an invalid call. * Make get_visual_node_names use a set of filters, move action creations and fix bug with sequence node connections. * Make the window bigger. * Make connect_data and connect_seq more robust. * Add icons to search items. * Add vs constructors in shift-a menu. * Operators, builtins and constructors show type name. Fix several problems with port connections. * In shift-a mode search everything. * Code cleanup * Work on autocompleting the type. * Use type guess in action creation. * Check if type hint string exists in object variables when generating the visual script search. * Add the hint to SceneTree. * Add original type detection. * Make type casting great again. This puts the type casted base type as the data output type string hint. * Pass the type in a VisualScriptFunctionCall too. * Set the base type correctly in VisualScriptFunctionGet and VisualScriptFunctionSet using hint string. * Make sure the instance is passed in VisualScriptPropertySet. * Restore search on the node's type. * Remove dependencies from graph_edit. * Remove dependencies from property_selector and name the class visual_script_property_selector. * Extract hot zones into a function. * Move hot_zones constants into default theme. * Bigger capture zones. * Clean messy port_grab_distance variables. * Remove RMB functionality. * Remove memory leak on showing visual script descriptions. * Read the port_grab_distance constants on enter tree and theme changed.
2018-05-13 11:34:35 +08:00
bool is_in_hot_zone(const Vector2 &pos, const Vector2 &p_mouse_pos);
Improve VisualScript UX * Prototype faster function call ux. * Work on general search ux. * Able to create nodes from search. * Show class for variables but not methods. * Get actions search working. * Descriptions now show for both methods and properties. * Enable zooming on mouse wheel up and down. * Make the drag trigger on right mouse button. * Search now shows for action visual script nodes. * Able to search visual node names. * Search works better. * Change zooming scale to hide artifacts better. * Remove zoom changes * Select from base should check properties too like the other functions. * Seq_connect flag is needed to set sequence lines correctly. * Remove comment * Code cleanup with function names and arguments. * Use brief description for search descriptions. * Clean and fix bug with input nodes connecting with sequence lines. * Add a warning and fix some edge conditions with sequence into data lines and vice versa. * Don't search functions when pulling from a sequence node. * Don't show actions when pulling from a data line. * Set set and get properties. * Convert visual script operators to the correct type * Create a function preset finds only functions. * Singletons can now find functions. * Add shift-a for generic search. * Add brief descriptions for Visual Script nodes. * Search boxes can now filter names. * Add bigger hit zones to node connect. * For the drop zones, make all the rect2 areas the same size. * Function names in visual script node should be lower case so that search works better. * Use the convention of capitalize() for set, set, visual script nodes and methods. * Make search more general. Ignore "_" and make case-insensitive. Also made the search window smaller and remove extra info from search * Make type_cast use the connecting node's type and remove use of found variable. * Fix case where you call an instance's call function where it becomes an invalid call. * Make get_visual_node_names use a set of filters, move action creations and fix bug with sequence node connections. * Make the window bigger. * Make connect_data and connect_seq more robust. * Add icons to search items. * Add vs constructors in shift-a menu. * Operators, builtins and constructors show type name. Fix several problems with port connections. * In shift-a mode search everything. * Code cleanup * Work on autocompleting the type. * Use type guess in action creation. * Check if type hint string exists in object variables when generating the visual script search. * Add the hint to SceneTree. * Add original type detection. * Make type casting great again. This puts the type casted base type as the data output type string hint. * Pass the type in a VisualScriptFunctionCall too. * Set the base type correctly in VisualScriptFunctionGet and VisualScriptFunctionSet using hint string. * Make sure the instance is passed in VisualScriptPropertySet. * Restore search on the node's type. * Remove dependencies from graph_edit. * Remove dependencies from property_selector and name the class visual_script_property_selector. * Extract hot zones into a function. * Move hot_zones constants into default theme. * Bigger capture zones. * Clean messy port_grab_distance variables. * Remove RMB functionality. * Remove memory leak on showing visual script descriptions. * Read the port_grab_distance constants on enter tree and theme changed.
2018-05-13 11:34:35 +08:00
2015-07-21 09:15:06 +08:00
void _top_layer_draw();
void _connections_layer_draw();
2015-07-21 09:15:06 +08:00
void _update_scroll_offset();
2015-07-21 09:15:06 +08:00
Array _get_connection_list() const;
2016-08-23 21:15:47 +08:00
bool lines_on_bg;
struct ConnType {
union {
struct {
uint32_t type_a;
uint32_t type_b;
};
uint64_t key;
};
bool operator<(const ConnType &p_type) const {
return key < p_type.key;
}
ConnType(uint32_t a = 0, uint32_t b = 0) {
type_a = a;
type_b = b;
}
};
Set<ConnType> valid_connection_types;
Set<int> valid_left_disconnect_types;
Set<int> valid_right_disconnect_types;
HBoxContainer *zoom_hb;
2015-07-21 09:15:06 +08:00
friend class GraphEditFilter;
bool _filter_input(const Point2 &p_point);
void _snap_toggled();
void _snap_value_changed(double);
bool _check_clickable_control(Control *p_control, const Vector2 &pos);
protected:
2015-07-21 09:15:06 +08:00
static void _bind_methods();
2020-07-10 18:34:39 +08:00
virtual void add_child_notify(Node *p_child) override;
virtual void remove_child_notify(Node *p_child) override;
2015-07-21 09:15:06 +08:00
void _notification(int p_what);
2020-07-10 18:34:39 +08:00
virtual bool clips_input() const override;
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 09:15:06 +08:00
void clear_connections();
void set_connection_activity(const StringName &p_from, int p_from_port, const StringName &p_to, int p_to_port, float p_activity);
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;
void set_zoom(float p_zoom);
2017-11-02 04:49:39 +08:00
void set_zoom_custom(float p_zoom, const Vector2 &p_center);
float get_zoom() const;
2015-07-21 09:15:06 +08:00
GraphEditFilter *get_top_layer() const { return top_layer; }
void get_connection_list(List<Connection> *r_connections) const;
2015-07-21 09:15:06 +08:00
void set_right_disconnects(bool p_enable);
bool is_right_disconnects_enabled() const;
2016-03-09 07:00:52 +08: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);
void set_scroll_ofs(const Vector2 &p_ofs);
Vector2 get_scroll_ofs() const;
void set_selected(Node *p_child);
void set_use_snap(bool p_enable);
bool is_using_snap() const;
int get_snap() const;
void set_snap(int p_snap);
HBoxContainer *get_zoom_hbox();
2015-07-21 09:15:06 +08:00
GraphEdit();
};
#endif // GRAPHEdit_H