graph_node.cpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. #include "graph_node.h"
  2. void GraphNode::_resort() {
  3. int sep=get_constant("separation");
  4. Ref<StyleBox> sb=get_stylebox("frame");
  5. bool first=true;
  6. Size2 minsize;
  7. for(int i=0;i<get_child_count();i++) {
  8. Control *c=get_child(i)->cast_to<Control>();
  9. if (!c || !c->is_visible())
  10. continue;
  11. if (c->is_set_as_toplevel())
  12. continue;
  13. Size2i size=c->get_combined_minimum_size();
  14. minsize.y+=size.y;
  15. minsize.x=MAX(minsize.x,size.x);
  16. if (first)
  17. first=false;
  18. else
  19. minsize.y+=sep;
  20. }
  21. int vofs=0;
  22. int w = get_size().x - sb->get_minimum_size().x;
  23. for(int i=0;i<get_child_count();i++) {
  24. Control *c=get_child(i)->cast_to<Control>();
  25. if (!c || !c->is_visible())
  26. continue;
  27. if (c->is_set_as_toplevel())
  28. continue;
  29. Size2i size=c->get_combined_minimum_size();
  30. Rect2 r(sb->get_margin(MARGIN_LEFT),sb->get_margin(MARGIN_TOP)+vofs,w,size.y);
  31. fit_child_in_rect(c,r);
  32. if (vofs>0)
  33. vofs+=sep;
  34. vofs+=size.y;
  35. }
  36. }
  37. void GraphNode::_notification(int p_what) {
  38. if (p_what==NOTIFICATION_DRAW) {
  39. Ref<StyleBox> sb=get_stylebox("frame");
  40. draw_style_box(sb,Rect2(Point2(),get_size()));
  41. }
  42. if (p_what==NOTIFICATION_SORT_CHILDREN) {
  43. _resort();
  44. }
  45. }
  46. void GraphNode::set_title(const String& p_title) {
  47. title=p_title;
  48. update();
  49. }
  50. String GraphNode::get_title() const {
  51. return title;
  52. }
  53. void GraphNode::set_slot(int p_idx,int p_type_left,int p_index_left,const Color& p_color_left, int p_type_right,int p_index_right,const Color& p_color_right) {
  54. ERR_FAIL_COND(p_idx<0);
  55. Slot s;
  56. s.type_left=p_type_left;
  57. s.color_left=p_color_left;
  58. s.index_left=p_index_left;
  59. s.type_right=p_type_right;
  60. s.color_right=p_color_right;
  61. s.index_right=p_index_right;
  62. slot_info[p_idx]=s;
  63. update();
  64. }
  65. void GraphNode::clear_slot(int p_idx){
  66. slot_info.erase(p_idx);
  67. update();
  68. }
  69. void GraphNode::clear_all_slots(){
  70. slot_info.clear();
  71. update();
  72. }
  73. int GraphNode::get_slot_type_left(int p_idx) const{
  74. if (!slot_info.has(p_idx))
  75. return TYPE_DISABLED;
  76. return slot_info[p_idx].type_left;
  77. }
  78. int GraphNode::get_slot_index_left(int p_idx) const{
  79. if (!slot_info.has(p_idx))
  80. return TYPE_DISABLED;
  81. return slot_info[p_idx].index_left;
  82. }
  83. Color GraphNode::get_slot_color_left(int p_idx) const{
  84. if (!slot_info.has(p_idx))
  85. return Color();
  86. return slot_info[p_idx].color_left;
  87. }
  88. int GraphNode::get_slot_type_right(int p_idx) const{
  89. if (!slot_info.has(p_idx))
  90. return TYPE_DISABLED;
  91. return slot_info[p_idx].type_right;
  92. }
  93. int GraphNode::get_slot_index_right(int p_idx) const{
  94. if (!slot_info.has(p_idx))
  95. return TYPE_DISABLED;
  96. return slot_info[p_idx].index_right;
  97. }
  98. Color GraphNode::get_slot_color_right(int p_idx) const{
  99. if (!slot_info.has(p_idx))
  100. return Color();
  101. return slot_info[p_idx].color_right;
  102. }
  103. Size2 GraphNode::get_minimum_size() const {
  104. int sep=get_constant("separation");
  105. Ref<StyleBox> sb=get_stylebox("frame");
  106. bool first=true;
  107. Size2 minsize;
  108. for(int i=0;i<get_child_count();i++) {
  109. Control *c=get_child(i)->cast_to<Control>();
  110. if (!c || !c->is_visible())
  111. continue;
  112. if (c->is_set_as_toplevel())
  113. continue;
  114. Size2i size=c->get_combined_minimum_size();
  115. minsize.y+=size.y;
  116. minsize.x=MAX(minsize.x,size.x);
  117. if (first)
  118. first=false;
  119. else
  120. minsize.y+=sep;
  121. }
  122. return minsize+sb->get_minimum_size();
  123. }
  124. void GraphNode::_bind_methods() {
  125. }
  126. GraphNode::GraphNode()
  127. {
  128. }