graph_node.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /*************************************************************************/
  2. /* graph_node.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /*************************************************************************/
  30. #ifndef GRAPH_NODE_H
  31. #define GRAPH_NODE_H
  32. #include "scene/gui/container.h"
  33. class GraphNode : public Container {
  34. OBJ_TYPE(GraphNode, Container);
  35. struct Slot {
  36. bool enable_left;
  37. int type_left;
  38. Color color_left;
  39. bool enable_right;
  40. int type_right;
  41. Color color_right;
  42. Slot() {
  43. enable_left = false;
  44. type_left = 0;
  45. color_left = Color(1, 1, 1, 1);
  46. enable_right = false;
  47. type_right = 0;
  48. color_right = Color(1, 1, 1, 1);
  49. }
  50. };
  51. String title;
  52. bool show_close;
  53. Vector2 offset;
  54. Rect2 close_rect;
  55. Vector<int> cache_y;
  56. struct ConnCache {
  57. Vector2 pos;
  58. int type;
  59. Color color;
  60. };
  61. Vector<ConnCache> conn_input_cache;
  62. Vector<ConnCache> conn_output_cache;
  63. Map<int, Slot> slot_info;
  64. bool connpos_dirty;
  65. void _connpos_update();
  66. void _resort();
  67. Vector2 drag_from;
  68. bool selected;
  69. protected:
  70. void _input_event(const InputEvent &p_ev);
  71. void _notification(int p_what);
  72. static void _bind_methods();
  73. bool _set(const StringName &p_name, const Variant &p_value);
  74. bool _get(const StringName &p_name, Variant &r_ret) const;
  75. void _get_property_list(List<PropertyInfo> *p_list) const;
  76. public:
  77. void set_slot(int p_idx, bool p_enable_left, int p_type_left, const Color &p_color_left, bool p_enable_right, int p_type_right, const Color &p_color_right);
  78. void clear_slot(int p_idx);
  79. void clear_all_slots();
  80. bool is_slot_enabled_left(int p_idx) const;
  81. int get_slot_type_left(int p_idx) const;
  82. Color get_slot_color_left(int p_idx) const;
  83. bool is_slot_enabled_right(int p_idx) const;
  84. int get_slot_type_right(int p_idx) const;
  85. Color get_slot_color_right(int p_idx) const;
  86. void set_title(const String &p_title);
  87. String get_title() const;
  88. void set_offset(const Vector2 &p_offset);
  89. Vector2 get_offset() const;
  90. void set_selected(bool p_selected);
  91. bool is_selected();
  92. void set_drag(bool p_drag);
  93. Vector2 get_drag_from();
  94. void set_show_close_button(bool p_enable);
  95. bool is_close_button_visible() const;
  96. int get_connection_input_count();
  97. int get_connection_output_count();
  98. Vector2 get_connection_input_pos(int p_idx);
  99. int get_connection_input_type(int p_idx);
  100. Color get_connection_input_color(int p_idx);
  101. Vector2 get_connection_output_pos(int p_idx);
  102. int get_connection_output_type(int p_idx);
  103. Color get_connection_output_color(int p_idx);
  104. virtual Size2 get_minimum_size() const;
  105. GraphNode();
  106. };
  107. #endif // GRAPH_NODE_H