diff options
author | Juan Linietsky <reduzio@gmail.com> | 2016-08-30 23:44:14 -0300 |
---|---|---|
committer | Juan Linietsky <reduzio@gmail.com> | 2016-08-30 23:46:41 -0300 |
commit | fb4d6d1db0ed0fb8deb530be4b0ae481fb5ba3cd (patch) | |
tree | 00e8915abce7590ad63e129d7f15425fe75322c5 /scene/gui | |
parent | 2f0e2a78b5caaf659e078c549682e3d1347f7066 (diff) |
More visual script improvements
-Added anti-aliasing on lines
-Improved draw performance enormously
-Removed sequence ports for most nodes, current visual scripts will likely be broken now. Sorry!
Diffstat (limited to 'scene/gui')
-rw-r--r-- | scene/gui/control.cpp | 49 | ||||
-rw-r--r-- | scene/gui/control.h | 5 | ||||
-rw-r--r-- | scene/gui/graph_edit.cpp | 161 | ||||
-rw-r--r-- | scene/gui/graph_edit.h | 3 | ||||
-rw-r--r-- | scene/gui/tree.cpp | 28 | ||||
-rw-r--r-- | scene/gui/tree.h | 4 |
6 files changed, 186 insertions, 64 deletions
diff --git a/scene/gui/control.cpp b/scene/gui/control.cpp index 97133a2a3b..bf35fd25bd 100644 --- a/scene/gui/control.cpp +++ b/scene/gui/control.cpp @@ -449,6 +449,13 @@ void Control::remove_child_notify(Node *p_child) { } +void Control::_update_canvas_item_transform() { + + Matrix32 xform=Matrix32(data.rotation,get_pos()); + xform.scale_basis(data.scale); + VisualServer::get_singleton()->canvas_item_set_transform(get_canvas_item(),xform); + +} void Control::_notification(int p_notification) { @@ -600,10 +607,9 @@ void Control::_notification(int p_notification) { } break; case NOTIFICATION_DRAW: { - Matrix32 xform=Matrix32(data.rotation,get_pos()); - xform.scale_basis(data.scale); - VisualServer::get_singleton()->canvas_item_set_transform(get_canvas_item(),xform); - VisualServer::get_singleton()->canvas_item_set_custom_rect( get_canvas_item(),true, Rect2(Point2(),get_size())); + _update_canvas_item_transform(); + VisualServer::get_singleton()->canvas_item_set_custom_rect( get_canvas_item(),!data.disable_visibility_clip, Rect2(Point2(),get_size())); + //emit_signal(SceneStringNames::get_singleton()->draw); } break; @@ -1272,17 +1278,24 @@ void Control::_size_changed() { new_size_cache.x = MAX( minimum_size.x, new_size_cache.x ); new_size_cache.y = MAX( minimum_size.y, new_size_cache.y ); - - if (new_pos_cache == data.pos_cache && new_size_cache == data.size_cache) - return; // did not change, don't emit signal + bool pos_changed = new_pos_cache != data.pos_cache; + bool size_changed = new_size_cache != data.size_cache; data.pos_cache=new_pos_cache; data.size_cache=new_size_cache; - notification(NOTIFICATION_RESIZED); - item_rect_changed(); - _change_notify_margins(); - _notify_transform(); + if (size_changed) { + notification(NOTIFICATION_RESIZED); + } + if (pos_changed || size_changed) { + item_rect_changed(size_changed); + _change_notify_margins(); + _notify_transform(); + } + + if (pos_changed && !size_changed) { + _update_canvas_item_transform(); //move because it won't be updated + } } float Control::_get_parent_range(int p_idx) const { @@ -2382,6 +2395,19 @@ bool Control::is_minimum_size_adjust_blocked() const { return data.block_minimum_size_adjust; } + + +void Control::set_disable_visibility_clip(bool p_ignore) { + + data.disable_visibility_clip=p_ignore; + update(); +} + +bool Control::is_visibility_clip_disabled() const { + + return data.disable_visibility_clip; +} + void Control::_bind_methods() { @@ -2610,6 +2636,7 @@ Control::Control() { data.drag_owner=0; data.modal_frame=0; data.block_minimum_size_adjust=false; + data.disable_visibility_clip=false; for (int i=0;i<4;i++) { diff --git a/scene/gui/control.h b/scene/gui/control.h index e6b0844869..558439efbf 100644 --- a/scene/gui/control.h +++ b/scene/gui/control.h @@ -129,6 +129,7 @@ private: bool stop_mouse; bool block_minimum_size_adjust; + bool disable_visibility_clip; Control *parent; ObjectID drag_owner; @@ -195,6 +196,7 @@ private: void _unref_font( Ref<Font> p_sc); void _font_changed(); + void _update_canvas_item_transform(); friend class Viewport; @@ -402,6 +404,9 @@ public: void set_block_minimum_size_adjust(bool p_block); bool is_minimum_size_adjust_blocked() const; + void set_disable_visibility_clip(bool p_ignore); + bool is_visibility_clip_disabled() const; + Control(); ~Control(); diff --git a/scene/gui/graph_edit.cpp b/scene/gui/graph_edit.cpp index a7a813d335..2307b33345 100644 --- a/scene/gui/graph_edit.cpp +++ b/scene/gui/graph_edit.cpp @@ -62,6 +62,7 @@ Error GraphEdit::connect_node(const StringName& p_from, int p_from_port,const St connections.push_back(c); top_layer->update(); update(); + connections_layer->update(); return OK; } @@ -87,6 +88,7 @@ void GraphEdit::disconnect_node(const StringName& p_from, int p_from_port,const connections.erase(E); top_layer->update(); update(); + connections_layer->update(); return; } } @@ -118,7 +120,11 @@ Vector2 GraphEdit::get_scroll_ofs() const{ void GraphEdit::_scroll_moved(double) { - _update_scroll_offset(); + + if (!awaiting_scroll_offset_update) { + call_deferred("_update_scroll_offset"); + awaiting_scroll_offset_update=true; + } top_layer->update(); update(); @@ -129,6 +135,8 @@ void GraphEdit::_scroll_moved(double) { void GraphEdit::_update_scroll_offset() { + set_block_minimum_size_adjust(true); + for(int i=0;i<get_child_count();i++) { GraphNode *gn=get_child(i)->cast_to<GraphNode>(); @@ -138,9 +146,15 @@ void GraphEdit::_update_scroll_offset() { Point2 pos=gn->get_offset()*zoom; pos-=Point2(h_scroll->get_val(),v_scroll->get_val()); gn->set_pos(pos); - gn->set_scale(Vector2(zoom,zoom)); + if (gn->get_scale()!=Vector2(zoom,zoom)) { + gn->set_scale(Vector2(zoom,zoom)); + } } + connections_layer->set_pos(-Point2(h_scroll->get_val(),v_scroll->get_val())*zoom); + set_block_minimum_size_adjust(false); + awaiting_scroll_offset_update=false; + } void GraphEdit::_update_scroll() { @@ -149,6 +163,9 @@ void GraphEdit::_update_scroll() { return; updating=true; + + set_block_minimum_size_adjust(true); + Rect2 screen; for(int i=0;i<get_child_count();i++) { @@ -183,7 +200,13 @@ void GraphEdit::_update_scroll() { else v_scroll->show(); - _update_scroll_offset(); + set_block_minimum_size_adjust(false); + + if (!awaiting_scroll_offset_update) { + call_deferred("_update_scroll_offset"); + awaiting_scroll_offset_update=true; + } + updating=false; } @@ -196,6 +219,16 @@ void GraphEdit::_graph_node_raised(Node* p_gn) { if (gn->is_comment()) { move_child(gn,0); } + int first_not_comment=0; + for(int i=0;i<get_child_count();i++) { + GraphNode *gn=get_child(i)->cast_to<GraphNode>(); + if (gn && !gn->is_comment()) { + first_not_comment=i; + break; + } + } + + move_child(connections_layer,first_not_comment); top_layer->raise(); emit_signal("node_selected",p_gn); @@ -208,6 +241,7 @@ void GraphEdit::_graph_node_moved(Node *p_gn) { ERR_FAIL_COND(!gn); top_layer->update(); update(); + connections_layer->update(); } void GraphEdit::add_child_notify(Node *p_child) { @@ -265,6 +299,7 @@ void GraphEdit::_notification(int p_what) { } if (p_what==NOTIFICATION_DRAW) { + draw_style_box( get_stylebox("bg"),Rect2(Point2(),get_size()) ); VS::get_singleton()->canvas_item_set_clip(get_canvas_item(),true); @@ -310,53 +345,7 @@ void GraphEdit::_notification(int p_what) { } - { - //draw connections - List<List<Connection>::Element* > to_erase; - for(List<Connection>::Element *E=connections.front();E;E=E->next()) { - - NodePath fromnp(E->get().from); - - Node * from = get_node(fromnp); - if (!from) { - to_erase.push_back(E); - continue; - } - - GraphNode *gfrom = from->cast_to<GraphNode>(); - - if (!gfrom) { - to_erase.push_back(E); - continue; - } - - NodePath tonp(E->get().to); - Node * to = get_node(tonp); - if (!to) { - to_erase.push_back(E); - continue; - } - - GraphNode *gto = to->cast_to<GraphNode>(); - - if (!gto) { - to_erase.push_back(E); - continue; - } - Vector2 frompos=gfrom->get_connection_output_pos(E->get().from_port)+gfrom->get_pos(); - Color color = gfrom->get_connection_output_color(E->get().from_port); - Vector2 topos=gto->get_connection_input_pos(E->get().to_port)+gto->get_pos(); - Color tocolor = gto->get_connection_input_color(E->get().to_port); - _draw_cos_line(this,frompos,topos,color,tocolor); - - } - - while(to_erase.size()) { - connections.erase(to_erase.front()->get()); - to_erase.pop_front(); - } - } } @@ -588,6 +577,7 @@ void GraphEdit::_top_layer_input(const InputEvent& p_ev) { connecting=false; top_layer->update(); update(); + connections_layer->update(); } @@ -625,7 +615,7 @@ void GraphEdit::_bake_segment2d(CanvasItem* p_where,float p_begin, float p_end,c - p_where->draw_line(beg,end,p_color.linear_interpolate(p_to_color,mp),2); + p_where->draw_line(beg,end,p_color.linear_interpolate(p_to_color,mp),2,true); lines++; } else { _bake_segment2d(p_where,p_begin,mp,p_a,p_out,p_b,p_in,p_depth+1,p_min_depth,p_max_depth,p_tol,p_color,p_to_color,lines); @@ -636,6 +626,7 @@ void GraphEdit::_bake_segment2d(CanvasItem* p_where,float p_begin, float p_end,c void GraphEdit::_draw_cos_line(CanvasItem* p_where,const Vector2& p_from, const Vector2& p_to,const Color& p_color,const Color& p_to_color) { + #if 1 //cubic bezier code @@ -654,8 +645,7 @@ void GraphEdit::_draw_cos_line(CanvasItem* p_where,const Vector2& p_from, const Vector2 c2 = Vector2(-cp_offset,0); int lines=0; - _bake_segment2d(p_where,0,1,p_from,c1,p_to,c2,0,5,12,8,p_color,p_to_color,lines); - //print_line("used lines: "+itos(lines)); + _bake_segment2d(p_where,0,1,p_from,c1,p_to,c2,0,3,9,8,p_color,p_to_color,lines); #else @@ -689,6 +679,59 @@ void GraphEdit::_draw_cos_line(CanvasItem* p_where,const Vector2& p_from, const #endif } + +void GraphEdit::_connections_layer_draw() { + + + { + //draw connections + List<List<Connection>::Element* > to_erase; + for(List<Connection>::Element *E=connections.front();E;E=E->next()) { + + NodePath fromnp(E->get().from); + + Node * from = get_node(fromnp); + if (!from) { + to_erase.push_back(E); + continue; + } + + GraphNode *gfrom = from->cast_to<GraphNode>(); + + if (!gfrom) { + to_erase.push_back(E); + continue; + } + + NodePath tonp(E->get().to); + Node * to = get_node(tonp); + if (!to) { + to_erase.push_back(E); + continue; + } + + GraphNode *gto = to->cast_to<GraphNode>(); + + if (!gto) { + to_erase.push_back(E); + continue; + } + + Vector2 frompos=gfrom->get_connection_output_pos(E->get().from_port)+gfrom->get_offset(); + Color color = gfrom->get_connection_output_color(E->get().from_port); + Vector2 topos=gto->get_connection_input_pos(E->get().to_port)+gto->get_offset(); + Color tocolor = gto->get_connection_input_color(E->get().to_port); + _draw_cos_line(connections_layer,frompos,topos,color,tocolor); + + } + + while(to_erase.size()) { + connections.erase(to_erase.front()->get()); + to_erase.pop_front(); + } + } +} + void GraphEdit::_top_layer_draw() { _update_scroll(); @@ -854,6 +897,7 @@ void GraphEdit::_input_event(const InputEvent& p_ev) { top_layer->update(); update(); + connections_layer->update(); } if (b.button_index==BUTTON_LEFT && b.pressed) { @@ -979,6 +1023,7 @@ void GraphEdit::clear_connections() { connections.clear(); update(); + connections_layer->update(); } void GraphEdit::set_zoom(float p_zoom) { @@ -1112,6 +1157,7 @@ void GraphEdit::set_use_snap(bool p_enable) { snap_button->set_pressed(p_enable); update(); + } bool GraphEdit::is_using_snap() const{ @@ -1175,6 +1221,10 @@ void GraphEdit::_bind_methods() { ObjectTypeDB::bind_method(_MD("_snap_value_changed"),&GraphEdit::_snap_value_changed); ObjectTypeDB::bind_method(_MD("_input_event"),&GraphEdit::_input_event); + ObjectTypeDB::bind_method(_MD("_update_scroll_offset"),&GraphEdit::_update_scroll_offset); + ObjectTypeDB::bind_method(_MD("_connections_layer_draw"),&GraphEdit::_connections_layer_draw); + + ObjectTypeDB::bind_method(_MD("set_selected","node"),&GraphEdit::set_selected); @@ -1195,6 +1245,7 @@ void GraphEdit::_bind_methods() { GraphEdit::GraphEdit() { set_focus_mode(FOCUS_ALL); + awaiting_scroll_offset_update=false; top_layer=NULL; top_layer=memnew(GraphEditFilter(this)); add_child(top_layer); @@ -1204,6 +1255,12 @@ GraphEdit::GraphEdit() { top_layer->set_stop_mouse(false); top_layer->connect("input_event",this,"_top_layer_input"); + connections_layer = memnew( Control ); + add_child(connections_layer); + connections_layer->connect("draw",this,"_connections_layer_draw"); + connections_layer->set_name("CLAYER"); + connections_layer->set_disable_visibility_clip(true); // so it can draw freely and be offseted + h_scroll = memnew(HScrollBar); h_scroll->set_name("_h_scroll"); top_layer->add_child(h_scroll); diff --git a/scene/gui/graph_edit.h b/scene/gui/graph_edit.h index c3276ceacc..ed6e4ef6ac 100644 --- a/scene/gui/graph_edit.h +++ b/scene/gui/graph_edit.h @@ -110,6 +110,7 @@ private: bool setting_scroll_ofs; bool right_disconnects; bool updating; + bool awaiting_scroll_offset_update; List<Connection> connections; void _bake_segment2d(CanvasItem* p_where,float p_begin, float p_end, const Vector2& p_a, const Vector2& p_out, const Vector2& p_b, const Vector2& p_in, int p_depth, int p_min_depth, int p_max_depth, float p_tol, const Color& p_color, const Color& p_to_color, int &lines) const; @@ -123,9 +124,11 @@ private: void _scroll_moved(double); void _input_event(const InputEvent& p_ev); + Control *connections_layer; GraphEditFilter *top_layer; void _top_layer_input(const InputEvent& p_ev); void _top_layer_draw(); + void _connections_layer_draw(); void _update_scroll_offset(); Array _get_connection_list() const; diff --git a/scene/gui/tree.cpp b/scene/gui/tree.cpp index c5beadb750..20794b2faa 100644 --- a/scene/gui/tree.cpp +++ b/scene/gui/tree.cpp @@ -171,6 +171,21 @@ String TreeItem::get_text(int p_column) const { } +void TreeItem::set_suffix(int p_column,String p_suffix) { + + ERR_FAIL_INDEX( p_column, cells.size() ); + cells[p_column].suffix=p_suffix; + + _changed_notify(p_column); + +} + +String TreeItem::get_suffix(int p_column) const { + + ERR_FAIL_INDEX_V( p_column, cells.size(), "" ); + return cells[p_column].suffix; + +} void TreeItem::set_icon(int p_column,const Ref<Texture>& p_icon) { @@ -927,8 +942,12 @@ void Tree::draw_item_rect(const TreeItem::Cell& p_cell,const Rect2i& p_rect,cons Ref<Font> font = cache.font; + String text = p_cell.text; + if (p_cell.suffix!=String()) + text+=" "+p_cell.suffix; + rect.pos.y+=Math::floor((rect.size.y-font->get_height())/2.0) +font->get_ascent(); - font->draw(ci,rect.pos,p_cell.text,p_color,rect.size.x); + font->draw(ci,rect.pos,text,p_color,rect.size.x); } @@ -1175,6 +1194,9 @@ int Tree::draw_item(const Point2i& p_pos,const Point2& p_draw_ofs, const Size2& String s = p_item->cells[i].text; s=s.get_slicec(',',option); + if (p_item->cells[i].suffix!=String()) + s+=" "+p_item->cells[i].suffix; + Ref<Texture> downarrow = cache.select_arrow; font->draw(ci, text_pos, s, col,item_rect.size.x-downarrow->get_width() ); @@ -1191,6 +1213,10 @@ int Tree::draw_item(const Point2i& p_pos,const Point2& p_draw_ofs, const Size2& String valtext = String::num( p_item->cells[i].val, Math::step_decimals( p_item->cells[i].step ) ); //String valtext = rtos( p_item->cells[i].val ); + + if (p_item->cells[i].suffix!=String()) + valtext+=" "+p_item->cells[i].suffix; + font->draw( ci, text_pos, valtext, col, item_rect.size.x-updown->get_width()); if (!p_item->cells[i].editable) diff --git a/scene/gui/tree.h b/scene/gui/tree.h index ff427dbe65..2124dce749 100644 --- a/scene/gui/tree.h +++ b/scene/gui/tree.h @@ -69,6 +69,7 @@ friend class Tree; Ref<Texture> icon; Rect2i icon_region; String text; + String suffix; double min,max,step,val; int icon_max_w; bool expr; @@ -168,6 +169,9 @@ public: void set_text(int p_column,String p_text); String get_text(int p_column) const; + void set_suffix(int p_column,String p_suffix); + String get_suffix(int p_column) const; + void set_icon(int p_column,const Ref<Texture>& p_icon); Ref<Texture> get_icon(int p_column) const; |