graph_node.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. /**************************************************************************/
  2. /* graph_node.h */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  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. #include "scene/resources/text_line.h"
  34. class GraphNode : public Container {
  35. GDCLASS(GraphNode, Container);
  36. public:
  37. enum Overlay {
  38. OVERLAY_DISABLED,
  39. OVERLAY_BREAKPOINT,
  40. OVERLAY_POSITION
  41. };
  42. private:
  43. struct Slot {
  44. bool enable_left = false;
  45. int type_left = 0;
  46. Color color_left = Color(1, 1, 1, 1);
  47. bool enable_right = false;
  48. int type_right = 0;
  49. Color color_right = Color(1, 1, 1, 1);
  50. Ref<Texture2D> custom_slot_left;
  51. Ref<Texture2D> custom_slot_right;
  52. bool draw_stylebox = true;
  53. };
  54. String title;
  55. Ref<TextLine> title_buf;
  56. String language;
  57. TextDirection text_direction = TEXT_DIRECTION_AUTO;
  58. bool show_close = false;
  59. Vector2 position_offset;
  60. bool comment = false;
  61. bool resizable = false;
  62. bool draggable = true;
  63. bool selectable = true;
  64. bool resizing = false;
  65. Vector2 resizing_from;
  66. Vector2 resizing_from_size;
  67. Rect2 close_rect;
  68. Vector<int> cache_y;
  69. struct PortCache {
  70. Vector2 position;
  71. int height;
  72. int slot_idx;
  73. int type = 0;
  74. Color color;
  75. };
  76. Vector<PortCache> left_port_cache;
  77. Vector<PortCache> right_port_cache;
  78. HashMap<int, Slot> slot_info;
  79. bool connpos_dirty = true;
  80. void _connpos_update();
  81. void _resort();
  82. void _shape();
  83. Vector2 drag_from;
  84. bool selected = false;
  85. Overlay overlay = OVERLAY_DISABLED;
  86. #ifdef TOOLS_ENABLED
  87. void _edit_set_position(const Point2 &p_position) override;
  88. #endif
  89. protected:
  90. virtual void gui_input(const Ref<InputEvent> &p_ev) override;
  91. void _notification(int p_what);
  92. static void _bind_methods();
  93. bool _set(const StringName &p_name, const Variant &p_value);
  94. bool _get(const StringName &p_name, Variant &r_ret) const;
  95. void _get_property_list(List<PropertyInfo> *p_list) const;
  96. void _validate_property(PropertyInfo &p_property) const;
  97. public:
  98. bool has_point(const Point2 &p_point) const override;
  99. 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, const Ref<Texture2D> &p_custom_left = Ref<Texture2D>(), const Ref<Texture2D> &p_custom_right = Ref<Texture2D>(), bool p_draw_stylebox = true);
  100. void clear_slot(int p_idx);
  101. void clear_all_slots();
  102. bool is_slot_enabled_left(int p_idx) const;
  103. void set_slot_enabled_left(int p_idx, bool p_enable_left);
  104. void set_slot_type_left(int p_idx, int p_type_left);
  105. int get_slot_type_left(int p_idx) const;
  106. void set_slot_color_left(int p_idx, const Color &p_color_left);
  107. Color get_slot_color_left(int p_idx) const;
  108. bool is_slot_enabled_right(int p_idx) const;
  109. void set_slot_enabled_right(int p_idx, bool p_enable_right);
  110. void set_slot_type_right(int p_idx, int p_type_right);
  111. int get_slot_type_right(int p_idx) const;
  112. void set_slot_color_right(int p_idx, const Color &p_color_right);
  113. Color get_slot_color_right(int p_idx) const;
  114. bool is_slot_draw_stylebox(int p_idx) const;
  115. void set_slot_draw_stylebox(int p_idx, bool p_enable);
  116. void set_title(const String &p_title);
  117. String get_title() const;
  118. void set_text_direction(TextDirection p_text_direction);
  119. TextDirection get_text_direction() const;
  120. void set_language(const String &p_language);
  121. String get_language() const;
  122. void set_position_offset(const Vector2 &p_offset);
  123. Vector2 get_position_offset() const;
  124. void set_selected(bool p_selected);
  125. bool is_selected();
  126. void set_drag(bool p_drag);
  127. Vector2 get_drag_from();
  128. void set_show_close_button(bool p_enable);
  129. bool is_close_button_visible() const;
  130. int get_connection_input_count();
  131. int get_connection_input_height(int p_port);
  132. Vector2 get_connection_input_position(int p_port);
  133. int get_connection_input_type(int p_port);
  134. Color get_connection_input_color(int p_port);
  135. int get_connection_input_slot(int p_port);
  136. int get_connection_output_count();
  137. int get_connection_output_height(int p_port);
  138. Vector2 get_connection_output_position(int p_port);
  139. int get_connection_output_type(int p_port);
  140. Color get_connection_output_color(int p_port);
  141. int get_connection_output_slot(int p_port);
  142. void set_overlay(Overlay p_overlay);
  143. Overlay get_overlay() const;
  144. void set_comment(bool p_enable);
  145. bool is_comment() const;
  146. void set_resizable(bool p_enable);
  147. bool is_resizable() const;
  148. void set_draggable(bool p_draggable);
  149. bool is_draggable();
  150. void set_selectable(bool p_selectable);
  151. bool is_selectable();
  152. virtual Size2 get_minimum_size() const override;
  153. virtual Vector<int> get_allowed_size_flags_horizontal() const override;
  154. virtual Vector<int> get_allowed_size_flags_vertical() const override;
  155. bool is_resizing() const {
  156. return resizing;
  157. }
  158. GraphNode();
  159. };
  160. VARIANT_ENUM_CAST(GraphNode::Overlay)
  161. #endif // GRAPH_NODE_H