graph_node.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. /*************************************************************************/
  2. /* graph_node.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2022 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. #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. Dictionary opentype_features;
  57. String language;
  58. TextDirection text_direction = TEXT_DIRECTION_AUTO;
  59. bool show_close = false;
  60. Vector2 position_offset;
  61. bool comment = false;
  62. bool resizable = false;
  63. bool resizing = false;
  64. Vector2 resizing_from;
  65. Vector2 resizing_from_size;
  66. Rect2 close_rect;
  67. Vector<int> cache_y;
  68. struct ConnCache {
  69. Vector2 pos;
  70. int type = 0;
  71. Color color;
  72. };
  73. Vector<ConnCache> conn_input_cache;
  74. Vector<ConnCache> conn_output_cache;
  75. HashMap<int, Slot> slot_info;
  76. bool connpos_dirty = true;
  77. void _connpos_update();
  78. void _resort();
  79. void _shape();
  80. Vector2 drag_from;
  81. bool selected = false;
  82. Overlay overlay = OVERLAY_DISABLED;
  83. #ifdef TOOLS_ENABLED
  84. void _edit_set_position(const Point2 &p_position) override;
  85. void _validate_property(PropertyInfo &property) const override;
  86. #endif
  87. protected:
  88. virtual void gui_input(const Ref<InputEvent> &p_ev) override;
  89. void _notification(int p_what);
  90. static void _bind_methods();
  91. bool _set(const StringName &p_name, const Variant &p_value);
  92. bool _get(const StringName &p_name, Variant &r_ret) const;
  93. void _get_property_list(List<PropertyInfo> *p_list) const;
  94. public:
  95. bool has_point(const Point2 &p_point) const override;
  96. 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);
  97. void clear_slot(int p_idx);
  98. void clear_all_slots();
  99. bool is_slot_enabled_left(int p_idx) const;
  100. void set_slot_enabled_left(int p_idx, bool p_enable_left);
  101. void set_slot_type_left(int p_idx, int p_type_left);
  102. int get_slot_type_left(int p_idx) const;
  103. void set_slot_color_left(int p_idx, const Color &p_color_left);
  104. Color get_slot_color_left(int p_idx) const;
  105. bool is_slot_enabled_right(int p_idx) const;
  106. void set_slot_enabled_right(int p_idx, bool p_enable_right);
  107. void set_slot_type_right(int p_idx, int p_type_right);
  108. int get_slot_type_right(int p_idx) const;
  109. void set_slot_color_right(int p_idx, const Color &p_color_right);
  110. Color get_slot_color_right(int p_idx) const;
  111. bool is_slot_draw_stylebox(int p_idx) const;
  112. void set_slot_draw_stylebox(int p_idx, bool p_enable);
  113. void set_title(const String &p_title);
  114. String get_title() const;
  115. void set_text_direction(TextDirection p_text_direction);
  116. TextDirection get_text_direction() const;
  117. void set_opentype_feature(const String &p_name, int p_value);
  118. int get_opentype_feature(const String &p_name) const;
  119. void clear_opentype_features();
  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_output_count();
  132. Vector2 get_connection_input_position(int p_idx);
  133. int get_connection_input_type(int p_idx);
  134. Color get_connection_input_color(int p_idx);
  135. Vector2 get_connection_output_position(int p_idx);
  136. int get_connection_output_type(int p_idx);
  137. Color get_connection_output_color(int p_idx);
  138. void set_overlay(Overlay p_overlay);
  139. Overlay get_overlay() const;
  140. void set_comment(bool p_enable);
  141. bool is_comment() const;
  142. void set_resizable(bool p_enable);
  143. bool is_resizable() const;
  144. virtual Size2 get_minimum_size() const override;
  145. virtual Vector<int> get_allowed_size_flags_horizontal() const override;
  146. virtual Vector<int> get_allowed_size_flags_vertical() const override;
  147. bool is_resizing() const {
  148. return resizing;
  149. }
  150. GraphNode();
  151. };
  152. VARIANT_ENUM_CAST(GraphNode::Overlay)
  153. #endif // GRAPH_NODE_H