graph_node.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. /*************************************************************************/
  2. /* graph_node.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2021 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. };
  53. String title;
  54. Ref<TextLine> title_buf;
  55. Dictionary opentype_features;
  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 resizing = false;
  63. Vector2 resizing_from;
  64. Vector2 resizing_from_size;
  65. Rect2 close_rect;
  66. Vector<int> cache_y;
  67. struct ConnCache {
  68. Vector2 pos;
  69. int type = 0;
  70. Color color;
  71. };
  72. Vector<ConnCache> conn_input_cache;
  73. Vector<ConnCache> conn_output_cache;
  74. Map<int, Slot> slot_info;
  75. bool connpos_dirty = true;
  76. void _connpos_update();
  77. void _resort();
  78. void _shape();
  79. Vector2 drag_from;
  80. bool selected = false;
  81. Overlay overlay = OVERLAY_DISABLED;
  82. #ifdef TOOLS_ENABLED
  83. void _edit_set_position(const Point2 &p_position) override;
  84. void _validate_property(PropertyInfo &property) const override;
  85. #endif
  86. protected:
  87. virtual void gui_input(const Ref<InputEvent> &p_ev) override;
  88. void _notification(int p_what);
  89. static void _bind_methods();
  90. bool _set(const StringName &p_name, const Variant &p_value);
  91. bool _get(const StringName &p_name, Variant &r_ret) const;
  92. void _get_property_list(List<PropertyInfo> *p_list) const;
  93. public:
  94. bool has_point(const Point2 &p_point) const override;
  95. 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>());
  96. void clear_slot(int p_idx);
  97. void clear_all_slots();
  98. bool is_slot_enabled_left(int p_idx) const;
  99. void set_slot_enabled_left(int p_idx, bool p_enable_left);
  100. void set_slot_type_left(int p_idx, int p_type_left);
  101. int get_slot_type_left(int p_idx) const;
  102. void set_slot_color_left(int p_idx, const Color &p_color_left);
  103. Color get_slot_color_left(int p_idx) const;
  104. bool is_slot_enabled_right(int p_idx) const;
  105. void set_slot_enabled_right(int p_idx, bool p_enable_right);
  106. void set_slot_type_right(int p_idx, int p_type_right);
  107. int get_slot_type_right(int p_idx) const;
  108. void set_slot_color_right(int p_idx, const Color &p_color_right);
  109. Color get_slot_color_right(int p_idx) const;
  110. void set_title(const String &p_title);
  111. String get_title() const;
  112. void set_text_direction(TextDirection p_text_direction);
  113. TextDirection get_text_direction() const;
  114. void set_opentype_feature(const String &p_name, int p_value);
  115. int get_opentype_feature(const String &p_name) const;
  116. void clear_opentype_features();
  117. void set_language(const String &p_language);
  118. String get_language() const;
  119. void set_position_offset(const Vector2 &p_offset);
  120. Vector2 get_position_offset() const;
  121. void set_selected(bool p_selected);
  122. bool is_selected();
  123. void set_drag(bool p_drag);
  124. Vector2 get_drag_from();
  125. void set_show_close_button(bool p_enable);
  126. bool is_close_button_visible() const;
  127. int get_connection_input_count();
  128. int get_connection_output_count();
  129. Vector2 get_connection_input_position(int p_idx);
  130. int get_connection_input_type(int p_idx);
  131. Color get_connection_input_color(int p_idx);
  132. Vector2 get_connection_output_position(int p_idx);
  133. int get_connection_output_type(int p_idx);
  134. Color get_connection_output_color(int p_idx);
  135. void set_overlay(Overlay p_overlay);
  136. Overlay get_overlay() const;
  137. void set_comment(bool p_enable);
  138. bool is_comment() const;
  139. void set_resizable(bool p_enable);
  140. bool is_resizable() const;
  141. virtual Size2 get_minimum_size() const override;
  142. bool is_resizing() const { return resizing; }
  143. GraphNode();
  144. };
  145. VARIANT_ENUM_CAST(GraphNode::Overlay)
  146. #endif // GRAPH_NODE_H