From cf0a419efae977eba3ed17437f0475a0d7a11bbe Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Sat, 20 Dec 2014 12:32:14 -0300 Subject: [PATCH] WIP work on graph nodes and editing --- scene/gui/graph_node.cpp | 191 +++++++++++++++++++ scene/gui/graph_node.h | 54 ++++++ scene/resources/default_theme/graph_node.png | Bin 0 -> 734 bytes 3 files changed, 245 insertions(+) create mode 100644 scene/gui/graph_node.cpp create mode 100644 scene/gui/graph_node.h create mode 100644 scene/resources/default_theme/graph_node.png diff --git a/scene/gui/graph_node.cpp b/scene/gui/graph_node.cpp new file mode 100644 index 00000000000..96f8828efcc --- /dev/null +++ b/scene/gui/graph_node.cpp @@ -0,0 +1,191 @@ +#include "graph_node.h" + + +void GraphNode::_resort() { + + + + int sep=get_constant("separation"); + Ref sb=get_stylebox("frame"); + bool first=true; + + Size2 minsize; + + for(int i=0;icast_to(); + if (!c || !c->is_visible()) + continue; + if (c->is_set_as_toplevel()) + continue; + + Size2i size=c->get_combined_minimum_size(); + + minsize.y+=size.y; + minsize.x=MAX(minsize.x,size.x); + + if (first) + first=false; + else + minsize.y+=sep; + + } + + int vofs=0; + int w = get_size().x - sb->get_minimum_size().x; + + + for(int i=0;icast_to(); + if (!c || !c->is_visible()) + continue; + if (c->is_set_as_toplevel()) + continue; + + Size2i size=c->get_combined_minimum_size(); + + Rect2 r(sb->get_margin(MARGIN_LEFT),sb->get_margin(MARGIN_TOP)+vofs,w,size.y); + + fit_child_in_rect(c,r); + + + if (vofs>0) + vofs+=sep; + vofs+=size.y; + + } + +} + + +void GraphNode::_notification(int p_what) { + + if (p_what==NOTIFICATION_DRAW) { + + Ref sb=get_stylebox("frame"); + draw_style_box(sb,Rect2(Point2(),get_size())); + } + if (p_what==NOTIFICATION_SORT_CHILDREN) { + + _resort(); + } + +} + +void GraphNode::set_title(const String& p_title) { + + title=p_title; + update(); +} + +String GraphNode::get_title() const { + + return title; +} + +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) { + + ERR_FAIL_COND(p_idx<0); + Slot s; + s.type_left=p_type_left; + s.color_left=p_color_left; + s.index_left=p_index_left; + s.type_right=p_type_right; + s.color_right=p_color_right; + s.index_right=p_index_right; + slot_info[p_idx]=s; + update(); +} + +void GraphNode::clear_slot(int p_idx){ + + slot_info.erase(p_idx); + update(); +} +void GraphNode::clear_all_slots(){ + + slot_info.clear(); + update(); +} +int GraphNode::get_slot_type_left(int p_idx) const{ + + if (!slot_info.has(p_idx)) + return TYPE_DISABLED; + return slot_info[p_idx].type_left; + +} +int GraphNode::get_slot_index_left(int p_idx) const{ + + if (!slot_info.has(p_idx)) + return TYPE_DISABLED; + return slot_info[p_idx].index_left; + +} +Color GraphNode::get_slot_color_left(int p_idx) const{ + + if (!slot_info.has(p_idx)) + return Color(); + return slot_info[p_idx].color_left; + +} + +int GraphNode::get_slot_type_right(int p_idx) const{ + + if (!slot_info.has(p_idx)) + return TYPE_DISABLED; + return slot_info[p_idx].type_right; + +} +int GraphNode::get_slot_index_right(int p_idx) const{ + + if (!slot_info.has(p_idx)) + return TYPE_DISABLED; + return slot_info[p_idx].index_right; + +} +Color GraphNode::get_slot_color_right(int p_idx) const{ + + if (!slot_info.has(p_idx)) + return Color(); + return slot_info[p_idx].color_right; + +} + +Size2 GraphNode::get_minimum_size() const { + + int sep=get_constant("separation"); + Ref sb=get_stylebox("frame"); + bool first=true; + + Size2 minsize; + + for(int i=0;icast_to(); + if (!c || !c->is_visible()) + continue; + if (c->is_set_as_toplevel()) + continue; + + Size2i size=c->get_combined_minimum_size(); + + minsize.y+=size.y; + minsize.x=MAX(minsize.x,size.x); + + if (first) + first=false; + else + minsize.y+=sep; + } + + return minsize+sb->get_minimum_size(); +} + + +void GraphNode::_bind_methods() { + + +} + +GraphNode::GraphNode() +{ +} diff --git a/scene/gui/graph_node.h b/scene/gui/graph_node.h new file mode 100644 index 00000000000..1b2e8cec216 --- /dev/null +++ b/scene/gui/graph_node.h @@ -0,0 +1,54 @@ +#ifndef GRAPH_NODE_H +#define GRAPH_NODE_H + +#include "scene/gui/container.h" + +class GraphNode : public Container { + + OBJ_TYPE(GraphNode,Container); + + + String title; + struct Slot { + int type_left; + int index_left; + Color color_left; + int type_right; + int index_right; + Color color_right; + }; + + Map slot_info; + + void _resort(); +protected: + + void _notification(int p_what); + static void _bind_methods(); +public: + + enum { + TYPE_DISABLED=-1 + }; + + + void set_title(const String& p_title); + String get_title() const; + + void 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); + void clear_slot(int p_idx); + void clear_all_slots(); + int get_slot_type_left(int p_idx) const; + int get_slot_index_left(int p_idx) const; + Color get_slot_color_left(int p_idx) const; + int get_slot_type_right(int p_idx) const; + int get_slot_index_right(int p_idx) const; + Color get_slot_color_right(int p_idx) const; + + virtual Size2 get_minimum_size() const; + + GraphNode(); +}; + + +#endif // GRAPH_NODE_H diff --git a/scene/resources/default_theme/graph_node.png b/scene/resources/default_theme/graph_node.png new file mode 100644 index 0000000000000000000000000000000000000000..b9fe334948609d0d5504c82c9acc5184f52fb882 GIT binary patch literal 734 zcmV<40wMj0P)e zSad^gZEa<4bO1wgWnpw>WFU8GbZ8()Nlj2!fese{00KryL_t(o!|j*9YZO5g$3Jgx zb2&u?D`R5LRzwT&KkzRQE3GVTY_(8Jwa_YHV`*g}h>+etKoAkZ-o%S1XHN5r-0jZ2 zXE8IIy~~mq6$IIVfo1o-&wRh{4Z{xn>mj9?%+1VS5s@1ra;YlV%wC(>(@uB!C7^%_ zkN}OjnfcqZC+6-yxbv7p$6A%EZLbfw`|uVkUpx0Y-Q`EXNPrZWK6SGF@!6B-ZRZr1 zxk^CVOi9y(>o>10eg3j^78s^L189jzdwX*TV&0JjeT7#e8|Gv~5Ro>}0$c<%0Y;`i zAM;rnssmX0y&p}Wk%k&f0hlUg0%8b)VTeg7%_xbQ0+KX#zyl1!zzh*@Lt~P70VNFy zAnA@sP}3s9qqN zz?-&Gl9v5e19Yt7jG?Gle*&PYVavqI3+6XKXe)^9VL{Cbq2^x{5+X=tUj;i`*LJy) zxFyHzodM3x&z^p9kaJ*p< z&$GqwQ%wqt0Jpl