diff options
Diffstat (limited to 'scene/gui')
| -rw-r--r-- | scene/gui/control.cpp | 24 | ||||
| -rw-r--r-- | scene/gui/control.h | 2 | ||||
| -rw-r--r-- | scene/gui/graph_edit.cpp | 87 | ||||
| -rw-r--r-- | scene/gui/graph_edit.h | 10 | ||||
| -rw-r--r-- | scene/gui/graph_node.cpp | 11 | ||||
| -rw-r--r-- | scene/gui/spin_box.cpp | 3 | ||||
| -rw-r--r-- | scene/gui/tree.cpp | 37 | ||||
| -rw-r--r-- | scene/gui/tree.h | 5 |
8 files changed, 156 insertions, 23 deletions
diff --git a/scene/gui/control.cpp b/scene/gui/control.cpp index 90c72989bd..8f6a0b4d53 100644 --- a/scene/gui/control.cpp +++ b/scene/gui/control.cpp @@ -606,14 +606,14 @@ void Control::force_drag(const Variant& p_data,Control *p_control) { ERR_FAIL_COND(!is_inside_tree()); ERR_FAIL_COND(p_data.get_type()==Variant::NIL); - get_viewport()->_gui_force_drag(p_data,p_control); + get_viewport()->_gui_force_drag(this,p_data,p_control); } void Control::set_drag_preview(Control *p_control) { ERR_FAIL_COND(!is_inside_tree()); - get_viewport()->_gui_set_drag_preview(p_control); + get_viewport()->_gui_set_drag_preview(this,p_control); } @@ -2046,6 +2046,26 @@ Vector2 Control::get_scale() const{ return data.scale; } +Control *Control::get_root_parent_control() const { + + const CanvasItem *ci=this; + const Control *root=this; + + while(ci) { + + const Control *c = ci->cast_to<Control>(); + if (c) { + root=c; + + if (c->data.RI || c->data.MI || c->is_toplevel_control()) + break; + } + + ci=ci->get_parent_item(); + } + + return const_cast<Control*>(root); +} void Control::_bind_methods() { diff --git a/scene/gui/control.h b/scene/gui/control.h index ab777a6a6c..a16d88a6df 100644 --- a/scene/gui/control.h +++ b/scene/gui/control.h @@ -360,6 +360,8 @@ public: virtual bool is_text_field() const; + Control *get_root_parent_control() const; + Control(); ~Control(); diff --git a/scene/gui/graph_edit.cpp b/scene/gui/graph_edit.cpp index 85f00f9d84..d0c82c15b8 100644 --- a/scene/gui/graph_edit.cpp +++ b/scene/gui/graph_edit.cpp @@ -1,6 +1,7 @@ #include "graph_edit.h" #include "os/input.h" #include "os/keyboard.h" +#include "scene/gui/box_container.h" bool GraphEditFilter::has_point(const Point2& p_point) const { return ge->_filter_input(p_point); @@ -151,6 +152,7 @@ void GraphEdit::add_child_notify(Node *p_child) { top_layer->call_deferred("raise"); //top layer always on top! GraphNode *gn = p_child->cast_to<GraphNode>(); if (gn) { + gn->set_scale(Vector2(zoom,zoom)); gn->connect("offset_changed",this,"_graph_node_moved",varray(gn)); gn->connect("raise_request",this,"_graph_node_raised",varray(gn)); _graph_node_moved(gn); @@ -184,6 +186,8 @@ void GraphEdit::_notification(int p_what) { h_scroll->set_anchor_and_margin(MARGIN_TOP,ANCHOR_END,hmin.height); h_scroll->set_anchor_and_margin(MARGIN_BOTTOM,ANCHOR_END,0); + zoom_icon->set_texture( get_icon("Zoom", "EditorIcons")); + } if (p_what==NOTIFICATION_DRAW) { VS::get_singleton()->canvas_item_set_clip(get_canvas_item(),true); @@ -384,8 +388,6 @@ void GraphEdit::_top_layer_input(const InputEvent& p_ev) { } - - } void GraphEdit::_draw_cos_line(const Vector2& p_from, const Vector2& p_to,const Color& p_color) { @@ -525,7 +527,9 @@ void GraphEdit::_input_event(const InputEvent& p_ev) { if (!gn) continue; - bool in_box = gn->get_rect().intersects(box_selecting_rect); + Rect2 r = gn->get_rect(); + r.size*=zoom; + bool in_box = r.intersects(box_selecting_rect); if (in_box) gn->set_selected(box_selection_mode_aditive); @@ -554,7 +558,12 @@ void GraphEdit::_input_event(const InputEvent& p_ev) { } top_layer->update(); } else { - emit_signal("popup_request", Vector2(b.global_x, b.global_y)); + if (connecting) { + connecting = false; + top_layer->update(); + } else { + emit_signal("popup_request", Vector2(b.global_x, b.global_y)); + } } } @@ -564,8 +573,12 @@ void GraphEdit::_input_event(const InputEvent& p_ev) { for(int i=get_child_count()-1;i>=0;i--) { GraphNode *gn=get_child(i)->cast_to<GraphNode>(); - if (gn && gn->get_rect().has_point(get_local_mouse_pos())) - gn->set_selected(false); + if (gn) { + Rect2 r = gn->get_rect(); + r.size*=zoom; + if (r.has_point(get_local_mouse_pos())) + gn->set_selected(false); + } } } @@ -594,8 +607,12 @@ void GraphEdit::_input_event(const InputEvent& p_ev) { gn=get_child(i)->cast_to<GraphNode>(); - if (gn && gn->get_rect().has_point(get_local_mouse_pos())) - break; + if (gn) { + Rect2 r = gn->get_rect(); + r.size*=zoom; + if (r.has_point(get_local_mouse_pos())) + break; + } } if (gn) { @@ -624,6 +641,9 @@ void GraphEdit::_input_event(const InputEvent& p_ev) { } } else { + if (_filter_input(Vector2(b.x,b.y))) + return; + box_selecting = true; box_selecting_from = get_local_mouse_pos(); if (b.mod.control) { @@ -668,6 +688,14 @@ void GraphEdit::_input_event(const InputEvent& p_ev) { previus_selected.clear(); top_layer->update(); } + + if (b.button_index==BUTTON_WHEEL_UP && b.pressed) { + sl_zoom->set_val(zoom/0.9); + } + + if (b.button_index==BUTTON_WHEEL_DOWN && b.pressed) { + sl_zoom->set_val(zoom*0.9); + } } if (p_ev.type==InputEvent::KEY && p_ev.key.scancode==KEY_D && p_ev.key.pressed && p_ev.key.mod.command) { @@ -688,6 +716,29 @@ void GraphEdit::clear_connections() { update(); } +void GraphEdit::set_zoom(float p_zoom) { + + if (p_zoom<0.01) p_zoom=0.01; + if (p_zoom>4) p_zoom=4; + if (zoom == p_zoom) + return; + + float prev_zoom = zoom; + zoom = p_zoom; + for (int i = 0; i < get_child_count(); i++) { + GraphNode *child = get_child(i)->cast_to<GraphNode>(); + if (!child) + continue; + Point2 ofs = child->get_offset() / prev_zoom * zoom; + child->set_scale(Vector2(zoom,zoom)); + child->set_offset(ofs); + } + update(); +} + +float GraphEdit::get_zoom() const { + return zoom; +} void GraphEdit::set_right_disconnects(bool p_enable) { @@ -722,6 +773,9 @@ void GraphEdit::_bind_methods() { ObjectTypeDB::bind_method(_MD("get_connection_list"),&GraphEdit::_get_connection_list); ObjectTypeDB::bind_method(_MD("get_scroll_ofs"),&GraphEdit::get_scroll_ofs); + ObjectTypeDB::bind_method(_MD("set_zoom","p_zoom"),&GraphEdit::set_zoom); + ObjectTypeDB::bind_method(_MD("get_zoom"),&GraphEdit::get_zoom); + ObjectTypeDB::bind_method(_MD("set_right_disconnects","enable"),&GraphEdit::set_right_disconnects); ObjectTypeDB::bind_method(_MD("is_right_disconnects_enabled"),&GraphEdit::is_right_disconnects_enabled); @@ -773,4 +827,21 @@ GraphEdit::GraphEdit() { h_scroll->connect("value_changed", this,"_scroll_moved"); v_scroll->connect("value_changed", this,"_scroll_moved"); + + zoom = 1; + + HBoxContainer* tools = memnew( HBoxContainer ); + add_child(tools); + + zoom_icon = memnew( TextureFrame ); + tools->add_child(zoom_icon); + + sl_zoom = memnew( HSlider ); + sl_zoom->set_min(0.01); + sl_zoom->set_max(4); + sl_zoom->set_val(1); + sl_zoom->set_step(0.01); + sl_zoom->connect("value_changed", this, "set_zoom"); + tools->add_child(sl_zoom); + sl_zoom->set_custom_minimum_size(Size2(200,0)); } diff --git a/scene/gui/graph_edit.h b/scene/gui/graph_edit.h index 5e339e4e7e..ec278827b1 100644 --- a/scene/gui/graph_edit.h +++ b/scene/gui/graph_edit.h @@ -3,7 +3,8 @@ #include "scene/gui/graph_node.h" #include "scene/gui/scroll_bar.h" - +#include "scene/gui/slider.h" +#include "texture_frame.h" class GraphEdit; class GraphEditFilter : public Control { @@ -34,6 +35,8 @@ public: }; private: + TextureFrame* zoom_icon; + HSlider* sl_zoom; HScrollBar* h_scroll; VScrollBar* v_scroll; @@ -53,6 +56,8 @@ private: bool just_selected; Vector2 drag_accum; + float zoom; + bool box_selecting; bool box_selection_mode_aditive; Point2 box_selecting_from; @@ -96,6 +101,9 @@ public: void disconnect_node(const StringName& p_from, int p_from_port,const StringName& p_to,int p_to_port); void clear_connections(); + void set_zoom(float p_zoom); + float get_zoom() const; + GraphEditFilter *get_top_layer() const { return top_layer; } void get_connection_list(List<Connection> *r_connections) const; diff --git a/scene/gui/graph_node.cpp b/scene/gui/graph_node.cpp index 5efc9757b7..762afb158a 100644 --- a/scene/gui/graph_node.cpp +++ b/scene/gui/graph_node.cpp @@ -474,7 +474,10 @@ Vector2 GraphNode::get_connection_input_pos(int p_idx) { _connpos_update(); ERR_FAIL_INDEX_V(p_idx,conn_input_cache.size(),Vector2()); - return conn_input_cache[p_idx].pos; + Vector2 pos = conn_input_cache[p_idx].pos; + pos.x *= get_scale().x; + pos.y *= get_scale().y; + return pos; } int GraphNode::get_connection_input_type(int p_idx) { @@ -501,8 +504,10 @@ Vector2 GraphNode::get_connection_output_pos(int p_idx){ _connpos_update(); ERR_FAIL_INDEX_V(p_idx,conn_output_cache.size(),Vector2()); - return conn_output_cache[p_idx].pos; - + Vector2 pos = conn_output_cache[p_idx].pos; + pos.x *= get_scale().x; + pos.y *= get_scale().y; + return pos; } int GraphNode::get_connection_output_type(int p_idx) { diff --git a/scene/gui/spin_box.cpp b/scene/gui/spin_box.cpp index 38c61ded2c..2b64d36a81 100644 --- a/scene/gui/spin_box.cpp +++ b/scene/gui/spin_box.cpp @@ -72,8 +72,7 @@ void SpinBox::_range_click_timeout() { if (!drag.enabled && Input::get_singleton()->is_mouse_button_pressed(BUTTON_LEFT)) { - int pos_y = Input::get_singleton()->get_mouse_pos().y-get_global_pos().y; - bool up = pos_y < (get_size().height/2); + bool up = get_local_mouse_pos().y < (get_size().height/2); set_val( get_val() + (up?get_step():-get_step())); if (range_click_timer->is_one_shot()) { diff --git a/scene/gui/tree.cpp b/scene/gui/tree.cpp index 8d28180490..66ce117c9d 100644 --- a/scene/gui/tree.cpp +++ b/scene/gui/tree.cpp @@ -1373,7 +1373,7 @@ void Tree::_range_click_timeout() { if (range_item_last && !range_drag_enabled && Input::get_singleton()->is_mouse_button_pressed(BUTTON_LEFT)) { - Point2 pos = (Input::get_singleton()->get_mouse_pos()-get_global_pos())-cache.bg->get_offset(); + Point2 pos = get_local_mouse_pos()-cache.bg->get_offset(); if (show_column_titles) { pos.y-=_get_title_button_height(); @@ -1384,7 +1384,7 @@ void Tree::_range_click_timeout() { } click_handled=false; - InputModifierState mod = {}; // should be irrelevant.. + InputModifierState mod = InputModifierState(); // should be irrelevant.. blocked++; propagate_mouse_event(pos+cache.offset, 0, 0, false, root, BUTTON_LEFT, mod); @@ -1414,6 +1414,10 @@ int Tree::propagate_mouse_event(const Point2i &p_pos,int x_ofs,int y_ofs,bool p_ if (!skip && p_pos.y<item_h) { // check event! + if (range_click_timer->get_time_left() > 0 && p_item != range_item_last) { + return -1; + } + if (!hide_folding && (p_pos.x >=x_ofs && p_pos.x < (x_ofs+cache.item_margin) )) { @@ -1719,6 +1723,7 @@ int Tree::propagate_mouse_event(const Point2i &p_pos,int x_ofs,int y_ofs,bool p_ void Tree::text_editor_enter(String p_text) { + text_changed=false; text_editor->hide(); value_editor->hide(); @@ -1757,6 +1762,22 @@ void Tree::text_editor_enter(String p_text) { } +void Tree::text_editor_changed(String p_text) { + + text_changed=true; +} + +void Tree::text_editor_hide() { + + if (!text_changed) + return; + + if (Input::get_singleton()->is_key_pressed(KEY_ESCAPE)) + return; + + text_editor_enter(text_editor->get_text()); +} + void Tree::value_editor_changed(double p_value) { if (updating_value_editor) { @@ -2074,8 +2095,6 @@ void Tree::_input_event(InputEvent p_event) { update_cache(); const InputEventMouseMotion& b=p_event.mouse_motion; - range_click_timer->stop(); - Ref<StyleBox> bg = cache.bg; Point2 pos = Point2(b.x,b.y) - bg->get_offset(); @@ -2272,12 +2291,10 @@ void Tree::_input_event(InputEvent p_event) { } break; case BUTTON_WHEEL_UP: { - range_click_timer->stop(); v_scroll->set_val( v_scroll->get_val()-v_scroll->get_page()/8 ); } break; case BUTTON_WHEEL_DOWN: { - range_click_timer->stop(); v_scroll->set_val( v_scroll->get_val()+v_scroll->get_page()/8 ); } break; } @@ -2350,6 +2367,8 @@ bool Tree::edit_selected() { } else if (c.mode==TreeItem::CELL_MODE_STRING || c.mode==TreeItem::CELL_MODE_RANGE) { + text_changed=false; + Point2i textedpos=get_global_pos() + rect.pos; text_editor->set_pos( textedpos ); text_editor->set_size( rect.size); @@ -3185,6 +3204,8 @@ void Tree::_bind_methods() { ObjectTypeDB::bind_method(_MD("_input_event"),&Tree::_input_event); ObjectTypeDB::bind_method(_MD("_popup_select"),&Tree::popup_select); ObjectTypeDB::bind_method(_MD("_text_editor_enter"),&Tree::text_editor_enter); + ObjectTypeDB::bind_method(_MD("_text_editor_changed"),&Tree::text_editor_changed); + ObjectTypeDB::bind_method(_MD("_text_editor_hide"),&Tree::text_editor_hide); ObjectTypeDB::bind_method(_MD("_value_editor_changed"),&Tree::value_editor_changed); ObjectTypeDB::bind_method(_MD("_scroll_moved"),&Tree::_scroll_moved); @@ -3283,6 +3304,8 @@ Tree::Tree() { h_scroll->connect("value_changed", this,"_scroll_moved"); v_scroll->connect("value_changed", this,"_scroll_moved"); text_editor->connect("text_entered", this,"_text_editor_enter"); + text_editor->connect("text_changed",this,"_text_editor_changed"); + text_editor->connect("hide",this,"_text_editor_hide"); popup_menu->connect("item_pressed", this,"_popup_select"); value_editor->connect("value_changed", this,"_value_editor_changed"); @@ -3316,6 +3339,8 @@ Tree::Tree() { hide_folding=false; + text_changed=false; + } diff --git a/scene/gui/tree.h b/scene/gui/tree.h index 54e6a9c6b9..2562e6aaef 100644 --- a/scene/gui/tree.h +++ b/scene/gui/tree.h @@ -271,7 +271,6 @@ friend class TreeItem; bool range_drag_enabled; Vector2 range_drag_capture_pos; - //TreeItem *cursor_item; //int cursor_column; @@ -314,6 +313,8 @@ friend class TreeItem; void select_single_item(TreeItem *p_selected,TreeItem *p_current,int p_col,TreeItem *p_prev=NULL,bool *r_in_range=NULL); int propagate_mouse_event(const Point2i &p_pos,int x_ofs,int y_ofs,bool p_doubleclick,TreeItem *p_item,int p_button,const InputModifierState& p_mod); void text_editor_enter(String p_text); + void text_editor_changed(String p_text); + void text_editor_hide(); void value_editor_changed(double p_value); void popup_select(int p_option); @@ -418,6 +419,8 @@ friend class TreeItem; bool hide_folding; + bool text_changed; + protected: static void _bind_methods(); |