graph_node.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. /*************************************************************************/
  2. /* graph_node.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2019 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. GDCLASS(GraphNode, Container);
  35. public:
  36. enum Overlay {
  37. OVERLAY_DISABLED,
  38. OVERLAY_BREAKPOINT,
  39. OVERLAY_POSITION
  40. };
  41. private:
  42. struct Slot {
  43. bool enable_left;
  44. int type_left;
  45. Color color_left;
  46. bool enable_right;
  47. int type_right;
  48. Color color_right;
  49. Ref<Texture> custom_slot_left;
  50. Ref<Texture> custom_slot_right;
  51. Slot() {
  52. enable_left = false;
  53. type_left = 0;
  54. color_left = Color(1, 1, 1, 1);
  55. enable_right = false;
  56. type_right = 0;
  57. color_right = Color(1, 1, 1, 1);
  58. }
  59. };
  60. String title;
  61. bool show_close;
  62. Vector2 offset;
  63. bool comment;
  64. bool resizable;
  65. bool resizing;
  66. Vector2 resizing_from;
  67. Vector2 resizing_from_size;
  68. Rect2 close_rect;
  69. Vector<int> cache_y;
  70. struct ConnCache {
  71. Vector2 pos;
  72. int type;
  73. Color color;
  74. };
  75. Vector<ConnCache> conn_input_cache;
  76. Vector<ConnCache> conn_output_cache;
  77. Map<int, Slot> slot_info;
  78. bool connpos_dirty;
  79. void _connpos_update();
  80. void _resort();
  81. Vector2 drag_from;
  82. bool selected;
  83. Overlay overlay;
  84. protected:
  85. void _gui_input(const Ref<InputEvent> &p_ev);
  86. void _notification(int p_what);
  87. static void _bind_methods();
  88. bool _set(const StringName &p_name, const Variant &p_value);
  89. bool _get(const StringName &p_name, Variant &r_ret) const;
  90. void _get_property_list(List<PropertyInfo> *p_list) const;
  91. public:
  92. bool has_point(const Point2 &p_point) const;
  93. 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<Texture> &p_custom_left = Ref<Texture>(), const Ref<Texture> &p_custom_right = Ref<Texture>());
  94. void clear_slot(int p_idx);
  95. void clear_all_slots();
  96. bool is_slot_enabled_left(int p_idx) const;
  97. int get_slot_type_left(int p_idx) const;
  98. Color get_slot_color_left(int p_idx) const;
  99. bool is_slot_enabled_right(int p_idx) const;
  100. int get_slot_type_right(int p_idx) const;
  101. Color get_slot_color_right(int p_idx) const;
  102. void set_title(const String &p_title);
  103. String get_title() const;
  104. void set_offset(const Vector2 &p_offset);
  105. Vector2 get_offset() const;
  106. void set_selected(bool p_selected);
  107. bool is_selected();
  108. void set_drag(bool p_drag);
  109. Vector2 get_drag_from();
  110. void set_show_close_button(bool p_enable);
  111. bool is_close_button_visible() const;
  112. int get_connection_input_count();
  113. int get_connection_output_count();
  114. Vector2 get_connection_input_position(int p_idx);
  115. int get_connection_input_type(int p_idx);
  116. Color get_connection_input_color(int p_idx);
  117. Vector2 get_connection_output_position(int p_idx);
  118. int get_connection_output_type(int p_idx);
  119. Color get_connection_output_color(int p_idx);
  120. void set_overlay(Overlay p_overlay);
  121. Overlay get_overlay() const;
  122. void set_comment(bool p_enable);
  123. bool is_comment() const;
  124. void set_resizable(bool p_enable);
  125. bool is_resizable() const;
  126. virtual Size2 get_minimum_size() const;
  127. bool is_resizing() const { return resizing; }
  128. GraphNode();
  129. };
  130. VARIANT_ENUM_CAST(GraphNode::Overlay)
  131. #endif // GRAPH_NODE_H