graph_node.h 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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. #pragma once
  31. #include "scene/gui/graph_element.h"
  32. class HBoxContainer;
  33. class GraphNode : public GraphElement {
  34. GDCLASS(GraphNode, GraphElement);
  35. friend class GraphEdit;
  36. struct Slot {
  37. bool enable_left = false;
  38. int type_left = 0;
  39. Color color_left = Color(1, 1, 1, 1);
  40. Ref<Texture2D> custom_port_icon_left;
  41. Variant metadata_left;
  42. bool enable_right = false;
  43. int type_right = 0;
  44. Color color_right = Color(1, 1, 1, 1);
  45. Ref<Texture2D> custom_port_icon_right;
  46. Variant metadata_right;
  47. bool draw_stylebox = true;
  48. };
  49. struct PortCache {
  50. Vector2 pos;
  51. int slot_index;
  52. int type = 0;
  53. Color color;
  54. };
  55. struct _MinSizeCache {
  56. int min_size = 0;
  57. bool will_stretch = false;
  58. int final_size = 0;
  59. };
  60. enum CustomAccessibilityAction {
  61. ACTION_CONNECT_INPUT,
  62. ACTION_CONNECT_OUTPUT,
  63. ACTION_FOLLOW_INPUT,
  64. ACTION_FOLLOW_OUTPUT,
  65. };
  66. void _accessibility_action_slot(const Variant &p_data);
  67. HBoxContainer *titlebar_hbox = nullptr;
  68. Label *title_label = nullptr;
  69. String title;
  70. Vector<PortCache> left_port_cache;
  71. Vector<PortCache> right_port_cache;
  72. HashMap<int, Slot> slot_table;
  73. Vector<int> slot_y_cache;
  74. Control::FocusMode slots_focus_mode = Control::FOCUS_ACCESSIBILITY;
  75. int slot_count = 0;
  76. int selected_slot = -1;
  77. struct ThemeCache {
  78. Ref<StyleBox> panel;
  79. Ref<StyleBox> panel_selected;
  80. Ref<StyleBox> panel_focus;
  81. Ref<StyleBox> titlebar;
  82. Ref<StyleBox> titlebar_selected;
  83. Ref<StyleBox> slot;
  84. Ref<StyleBox> slot_selected;
  85. int separation = 0;
  86. int port_h_offset = 0;
  87. Ref<Texture2D> port;
  88. Ref<Texture2D> resizer;
  89. Color resizer_color;
  90. } theme_cache;
  91. bool port_pos_dirty = true;
  92. bool ignore_invalid_connection_type = false;
  93. void _port_pos_update();
  94. protected:
  95. void _notification(int p_what);
  96. static void _bind_methods();
  97. virtual void _resort() override;
  98. virtual void draw_port(int p_slot_index, Point2i p_pos, bool p_left, const Color &p_color);
  99. GDVIRTUAL4(_draw_port, int, Point2i, bool, const Color &);
  100. bool _set(const StringName &p_name, const Variant &p_value);
  101. bool _get(const StringName &p_name, Variant &r_ret) const;
  102. void _get_property_list(List<PropertyInfo> *p_list) const;
  103. public:
  104. virtual String get_accessibility_container_name(const Node *p_node) const override;
  105. virtual void gui_input(const Ref<InputEvent> &p_event) override;
  106. void set_title(const String &p_title);
  107. String get_title() const;
  108. HBoxContainer *get_titlebar_hbox();
  109. void set_slot(int p_slot_index, 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);
  110. void clear_slot(int p_slot_index);
  111. void clear_all_slots();
  112. bool is_slot_enabled_left(int p_slot_index) const;
  113. void set_slot_enabled_left(int p_slot_index, bool p_enable);
  114. void set_slot_type_left(int p_slot_index, int p_type);
  115. int get_slot_type_left(int p_slot_index) const;
  116. void set_slot_color_left(int p_slot_index, const Color &p_color);
  117. Color get_slot_color_left(int p_slot_index) const;
  118. void set_slot_custom_icon_left(int p_slot_index, const Ref<Texture2D> &p_custom_icon);
  119. Ref<Texture2D> get_slot_custom_icon_left(int p_slot_index) const;
  120. void set_slot_metadata_left(int p_slot_index, const Variant &p_value);
  121. Variant get_slot_metadata_left(int p_slot_index) const;
  122. bool is_slot_enabled_right(int p_slot_index) const;
  123. void set_slot_enabled_right(int p_slot_index, bool p_enable);
  124. void set_slot_type_right(int p_slot_index, int p_type);
  125. int get_slot_type_right(int p_slot_index) const;
  126. void set_slot_color_right(int p_slot_index, const Color &p_color);
  127. Color get_slot_color_right(int p_slot_index) const;
  128. void set_slot_custom_icon_right(int p_slot_index, const Ref<Texture2D> &p_custom_icon);
  129. Ref<Texture2D> get_slot_custom_icon_right(int p_slot_index) const;
  130. void set_slot_metadata_right(int p_slot_index, const Variant &p_value);
  131. Variant get_slot_metadata_right(int p_slot_index) const;
  132. bool is_slot_draw_stylebox(int p_slot_index) const;
  133. void set_slot_draw_stylebox(int p_slot_index, bool p_enable);
  134. void set_ignore_invalid_connection_type(bool p_ignore);
  135. bool is_ignoring_valid_connection_type() const;
  136. int get_input_port_count();
  137. Vector2 get_input_port_position(int p_port_idx);
  138. int get_input_port_type(int p_port_idx);
  139. Color get_input_port_color(int p_port_idx);
  140. int get_input_port_slot(int p_port_idx);
  141. int get_output_port_count();
  142. Vector2 get_output_port_position(int p_port_idx);
  143. int get_output_port_type(int p_port_idx);
  144. Color get_output_port_color(int p_port_idx);
  145. int get_output_port_slot(int p_port_idx);
  146. void set_slots_focus_mode(Control::FocusMode p_focus_mode);
  147. Control::FocusMode get_slots_focus_mode() const;
  148. virtual Size2 get_minimum_size() const override;
  149. virtual CursorShape get_cursor_shape(const Point2 &p_pos = Point2i()) const override;
  150. virtual Vector<int> get_allowed_size_flags_horizontal() const override;
  151. virtual Vector<int> get_allowed_size_flags_vertical() const override;
  152. GraphNode();
  153. };