mirror of
https://github.com/godotengine/godot.git
synced 2025-11-01 06:01:14 +00:00
-Work in progress visual shader editor *DOES NOT WORK YET*
This commit is contained in:
parent
eb1f978b1c
commit
fbdd925d9b
51 changed files with 4587 additions and 2172 deletions
|
|
@ -76,7 +76,7 @@ void GraphNode::_get_property_list( List<PropertyInfo> *p_list) const{
|
|||
int idx=0;
|
||||
for(int i=0;i<get_child_count();i++) {
|
||||
Control *c=get_child(i)->cast_to<Control>();
|
||||
if (!c || c->is_set_as_toplevel() || !c->get_owner())
|
||||
if (!c || c->is_set_as_toplevel() )
|
||||
continue;
|
||||
|
||||
String base="slot/"+itos(idx)+"/";
|
||||
|
|
@ -122,6 +122,7 @@ void GraphNode::_resort() {
|
|||
|
||||
}
|
||||
|
||||
|
||||
int vofs=0;
|
||||
int w = get_size().x - sb->get_minimum_size().x;
|
||||
|
||||
|
|
@ -131,7 +132,7 @@ void GraphNode::_resort() {
|
|||
Control *c=get_child(i)->cast_to<Control>();
|
||||
if (!c)
|
||||
continue;
|
||||
if (c->is_set_as_toplevel() || !c->get_owner())
|
||||
if (c->is_set_as_toplevel())
|
||||
continue;
|
||||
|
||||
Size2i size=c->get_combined_minimum_size();
|
||||
|
|
@ -150,6 +151,8 @@ void GraphNode::_resort() {
|
|||
|
||||
_change_notify();
|
||||
update();
|
||||
connpos_dirty=true;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -160,14 +163,34 @@ void GraphNode::_notification(int p_what) {
|
|||
|
||||
Ref<StyleBox> sb=get_stylebox("frame");
|
||||
Ref<Texture> port =get_icon("port");
|
||||
Ref<Texture> close =get_icon("close");
|
||||
int close_offset = get_constant("close_offset");
|
||||
Ref<Font> title_font = get_font("title_font");
|
||||
int title_offset = get_constant("title_offset");
|
||||
Color title_color = get_color("title_color");
|
||||
Point2i icofs = -port->get_size()*0.5;
|
||||
int edgeofs=3;
|
||||
int edgeofs=get_constant("port_offset");
|
||||
icofs.y+=sb->get_margin(MARGIN_TOP);
|
||||
draw_style_box(sb,Rect2(Point2(),get_size()));
|
||||
|
||||
int w = get_size().width-sb->get_minimum_size().x;
|
||||
|
||||
if (show_close)
|
||||
w-=close->get_width();
|
||||
|
||||
draw_string(title_font,Point2(sb->get_margin(MARGIN_LEFT),-title_font->get_height()+title_font->get_ascent()+title_offset),title,title_color,w);
|
||||
if (show_close) {
|
||||
Vector2 cpos = Point2(w+sb->get_margin(MARGIN_LEFT),-close->get_height()+close_offset);
|
||||
draw_texture(close,cpos);
|
||||
close_rect.pos=cpos;
|
||||
close_rect.size=close->get_size();
|
||||
} else {
|
||||
close_rect=Rect2();
|
||||
}
|
||||
|
||||
for (Map<int,Slot>::Element *E=slot_info.front();E;E=E->next()) {
|
||||
|
||||
if (E->key()>cache_y.size())
|
||||
if (E->key() < 0 || E->key()>=cache_y.size())
|
||||
continue;
|
||||
if (!slot_info.has(E->key()))
|
||||
continue;
|
||||
|
|
@ -180,6 +203,7 @@ void GraphNode::_notification(int p_what) {
|
|||
|
||||
}
|
||||
}
|
||||
|
||||
if (p_what==NOTIFICATION_SORT_CHILDREN) {
|
||||
|
||||
_resort();
|
||||
|
|
@ -187,16 +211,6 @@ void GraphNode::_notification(int p_what) {
|
|||
|
||||
}
|
||||
|
||||
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,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) {
|
||||
|
||||
|
|
@ -216,17 +230,23 @@ void GraphNode::set_slot(int p_idx,bool p_enable_left,int p_type_left,const Colo
|
|||
s.color_right=p_color_right;
|
||||
slot_info[p_idx]=s;
|
||||
update();
|
||||
connpos_dirty=true;
|
||||
|
||||
}
|
||||
|
||||
void GraphNode::clear_slot(int p_idx){
|
||||
|
||||
slot_info.erase(p_idx);
|
||||
update();
|
||||
connpos_dirty=true;
|
||||
|
||||
}
|
||||
void GraphNode::clear_all_slots(){
|
||||
|
||||
slot_info.clear();
|
||||
update();
|
||||
connpos_dirty=true;
|
||||
|
||||
}
|
||||
bool GraphNode::is_slot_enabled_left(int p_idx) const{
|
||||
|
||||
|
|
@ -280,18 +300,26 @@ Color GraphNode::get_slot_color_right(int p_idx) const{
|
|||
|
||||
Size2 GraphNode::get_minimum_size() const {
|
||||
|
||||
Ref<Font> title_font = get_font("title_font");
|
||||
|
||||
int sep=get_constant("separation");
|
||||
Ref<StyleBox> sb=get_stylebox("frame");
|
||||
bool first=true;
|
||||
|
||||
Size2 minsize;
|
||||
minsize.x=title_font->get_string_size(title).x;
|
||||
if (show_close) {
|
||||
Ref<Texture> close =get_icon("close");
|
||||
minsize.x+=sep+close->get_width();
|
||||
}
|
||||
|
||||
|
||||
for(int i=0;i<get_child_count();i++) {
|
||||
|
||||
Control *c=get_child(i)->cast_to<Control>();
|
||||
if (!c)
|
||||
continue;
|
||||
if (c->is_set_as_toplevel() || !c->get_owner())
|
||||
if (c->is_set_as_toplevel())
|
||||
continue;
|
||||
|
||||
Size2i size=c->get_combined_minimum_size();
|
||||
|
|
@ -308,13 +336,225 @@ Size2 GraphNode::get_minimum_size() const {
|
|||
return minsize+sb->get_minimum_size();
|
||||
}
|
||||
|
||||
void GraphNode::set_title(const String& p_title) {
|
||||
|
||||
title=p_title;
|
||||
minimum_size_changed();
|
||||
update();
|
||||
|
||||
}
|
||||
|
||||
String GraphNode::get_title() const{
|
||||
|
||||
return title;
|
||||
}
|
||||
|
||||
void GraphNode::set_offset(const Vector2& p_offset) {
|
||||
|
||||
offset=p_offset;
|
||||
emit_signal("offset_changed");
|
||||
update();
|
||||
}
|
||||
|
||||
Vector2 GraphNode::get_offset() const {
|
||||
|
||||
return offset;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void GraphNode::set_show_close_button(bool p_enable){
|
||||
|
||||
show_close=p_enable;
|
||||
update();
|
||||
}
|
||||
bool GraphNode::is_close_button_visible() const{
|
||||
|
||||
return show_close;
|
||||
}
|
||||
|
||||
void GraphNode::_connpos_update() {
|
||||
|
||||
|
||||
int edgeofs=get_constant("port_offset");
|
||||
int sep=get_constant("separation");
|
||||
|
||||
Ref<StyleBox> sb=get_stylebox("frame");
|
||||
Ref<Texture> port =get_icon("port");
|
||||
conn_input_cache.clear();
|
||||
conn_output_cache.clear();
|
||||
int vofs=0;
|
||||
|
||||
int idx=0;
|
||||
|
||||
for(int i=0;i<get_child_count();i++) {
|
||||
Control *c=get_child(i)->cast_to<Control>();
|
||||
if (!c)
|
||||
continue;
|
||||
if (c->is_set_as_toplevel())
|
||||
continue;
|
||||
|
||||
Size2i size=c->get_combined_minimum_size();
|
||||
|
||||
int y = sb->get_margin(MARGIN_TOP)+vofs;
|
||||
int h = size.y;
|
||||
|
||||
|
||||
if (slot_info.has(idx)) {
|
||||
|
||||
if (slot_info[idx].enable_left) {
|
||||
ConnCache cc;
|
||||
cc.pos=Point2i(edgeofs,y+h/2);
|
||||
cc.type=slot_info[idx].type_left;
|
||||
cc.color=slot_info[idx].color_left;
|
||||
conn_input_cache.push_back(cc);
|
||||
}
|
||||
if (slot_info[idx].enable_right) {
|
||||
ConnCache cc;
|
||||
cc.pos=Point2i(get_size().width-edgeofs,y+h/2);
|
||||
cc.type=slot_info[idx].type_right;
|
||||
cc.color=slot_info[idx].color_right;
|
||||
conn_output_cache.push_back(cc);
|
||||
}
|
||||
}
|
||||
|
||||
if (vofs>0)
|
||||
vofs+=sep;
|
||||
vofs+=size.y;
|
||||
idx++;
|
||||
|
||||
}
|
||||
|
||||
|
||||
connpos_dirty=false;
|
||||
}
|
||||
|
||||
int GraphNode::get_connection_input_count() {
|
||||
|
||||
if (connpos_dirty)
|
||||
_connpos_update();
|
||||
|
||||
return conn_input_cache.size();
|
||||
|
||||
}
|
||||
int GraphNode::get_connection_output_count() {
|
||||
|
||||
if (connpos_dirty)
|
||||
_connpos_update();
|
||||
|
||||
return conn_output_cache.size();
|
||||
|
||||
}
|
||||
|
||||
|
||||
Vector2 GraphNode::get_connection_input_pos(int p_idx) {
|
||||
|
||||
if (connpos_dirty)
|
||||
_connpos_update();
|
||||
|
||||
ERR_FAIL_INDEX_V(p_idx,conn_input_cache.size(),Vector2());
|
||||
return conn_input_cache[p_idx].pos;
|
||||
}
|
||||
|
||||
int GraphNode::get_connection_input_type(int p_idx) {
|
||||
|
||||
if (connpos_dirty)
|
||||
_connpos_update();
|
||||
|
||||
ERR_FAIL_INDEX_V(p_idx,conn_input_cache.size(),0);
|
||||
return conn_input_cache[p_idx].type;
|
||||
}
|
||||
|
||||
Color GraphNode::get_connection_input_color(int p_idx) {
|
||||
|
||||
if (connpos_dirty)
|
||||
_connpos_update();
|
||||
|
||||
ERR_FAIL_INDEX_V(p_idx,conn_input_cache.size(),Color());
|
||||
return conn_input_cache[p_idx].color;
|
||||
}
|
||||
|
||||
Vector2 GraphNode::get_connection_output_pos(int p_idx){
|
||||
|
||||
if (connpos_dirty)
|
||||
_connpos_update();
|
||||
|
||||
ERR_FAIL_INDEX_V(p_idx,conn_output_cache.size(),Vector2());
|
||||
return conn_output_cache[p_idx].pos;
|
||||
|
||||
}
|
||||
|
||||
int GraphNode::get_connection_output_type(int p_idx) {
|
||||
|
||||
if (connpos_dirty)
|
||||
_connpos_update();
|
||||
|
||||
ERR_FAIL_INDEX_V(p_idx,conn_output_cache.size(),0);
|
||||
return conn_output_cache[p_idx].type;
|
||||
}
|
||||
|
||||
Color GraphNode::get_connection_output_color(int p_idx) {
|
||||
|
||||
if (connpos_dirty)
|
||||
_connpos_update();
|
||||
|
||||
ERR_FAIL_INDEX_V(p_idx,conn_output_cache.size(),Color());
|
||||
return conn_output_cache[p_idx].color;
|
||||
}
|
||||
|
||||
void GraphNode::_input_event(const InputEvent& p_ev) {
|
||||
|
||||
if (p_ev.type==InputEvent::MOUSE_BUTTON && p_ev.mouse_button.pressed && p_ev.mouse_button.button_index==BUTTON_LEFT) {
|
||||
|
||||
Vector2 mpos = Vector2(p_ev.mouse_button.x,p_ev.mouse_button.y);
|
||||
if (close_rect.size!=Size2() && close_rect.has_point(mpos)) {
|
||||
emit_signal("close_request");
|
||||
return;
|
||||
}
|
||||
|
||||
drag_from=get_offset();
|
||||
drag_accum=Vector2();
|
||||
dragging=true;
|
||||
emit_signal("raise_request");
|
||||
|
||||
}
|
||||
|
||||
if (p_ev.type==InputEvent::MOUSE_BUTTON && !p_ev.mouse_button.pressed && p_ev.mouse_button.button_index==BUTTON_LEFT) {
|
||||
|
||||
dragging=false;
|
||||
emit_signal("dragged",drag_from,get_offset()); //useful for undo/redo
|
||||
}
|
||||
|
||||
if (p_ev.type==InputEvent::MOUSE_MOTION && dragging) {
|
||||
|
||||
drag_accum+=Vector2(p_ev.mouse_motion.relative_x,p_ev.mouse_motion.relative_y);
|
||||
set_offset(drag_from+drag_accum);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
void GraphNode::_bind_methods() {
|
||||
|
||||
ObjectTypeDB::bind_method(_MD("set_title","title"),&GraphNode::set_title);
|
||||
ObjectTypeDB::bind_method(_MD("get_title"),&GraphNode::get_title);
|
||||
ObjectTypeDB::bind_method(_MD("_input_event"),&GraphNode::_input_event);
|
||||
|
||||
ObjectTypeDB::bind_method(_MD("set_show_close_button","show"),&GraphNode::set_show_close_button);
|
||||
ObjectTypeDB::bind_method(_MD("is_close_button_visible"),&GraphNode::is_close_button_visible);
|
||||
|
||||
ADD_PROPERTY( PropertyInfo(Variant::STRING,"title"),_SCS("set_title"),_SCS("get_title"));
|
||||
ADD_PROPERTY( PropertyInfo(Variant::BOOL,"show_close"),_SCS("set_show_close_button"),_SCS("is_close_button_visible"));
|
||||
|
||||
ADD_SIGNAL(MethodInfo("offset_changed"));
|
||||
ADD_SIGNAL(MethodInfo("dragged",PropertyInfo(Variant::VECTOR2,"from"),PropertyInfo(Variant::VECTOR2,"to")));
|
||||
ADD_SIGNAL(MethodInfo("raise_request"));
|
||||
ADD_SIGNAL(MethodInfo("close_request"));
|
||||
}
|
||||
|
||||
GraphNode::GraphNode() {
|
||||
|
||||
|
||||
dragging=false;
|
||||
show_close=false;
|
||||
connpos_dirty=true;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue