From 88bf7f35e18f968c14223e4a48f810b003955b88 Mon Sep 17 00:00:00 2001 From: Gen Date: Mon, 27 Jul 2015 08:36:21 +0800 Subject: [PATCH 1/6] Fixed the mouse position for control when it is in a canvas_layer. --- scene/2d/canvas_item.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scene/2d/canvas_item.cpp b/scene/2d/canvas_item.cpp index 789c6bdbe4a..19b1057abee 100644 --- a/scene/2d/canvas_item.cpp +++ b/scene/2d/canvas_item.cpp @@ -1146,6 +1146,8 @@ Matrix32 CanvasItem::get_canvas_transform() const { if (canvas_layer) return canvas_layer->get_transform(); + else if (get_parent()->cast_to()) + return get_parent()->cast_to()->get_canvas_transform(); else return get_viewport()->get_canvas_transform(); From 354bc0385bde49c08c5d07942d4b0475c919bfd1 Mon Sep 17 00:00:00 2001 From: Franklin Sobrinho Date: Sun, 22 Nov 2015 20:08:50 -0300 Subject: [PATCH 2/6] Add StaticBody collision generation for all selected MeshInstance nodes --- tools/editor/plugins/mesh_editor_plugin.cpp | 138 +++++++++++--------- tools/editor/plugins/mesh_editor_plugin.h | 13 +- 2 files changed, 77 insertions(+), 74 deletions(-) diff --git a/tools/editor/plugins/mesh_editor_plugin.cpp b/tools/editor/plugins/mesh_editor_plugin.cpp index cea774f94ba..5314529a230 100644 --- a/tools/editor/plugins/mesh_editor_plugin.cpp +++ b/tools/editor/plugins/mesh_editor_plugin.cpp @@ -1,13 +1,8 @@ #include "mesh_editor_plugin.h" -#include "tools/editor/editor_plugin.h" -#include "tools/editor/editor_node.h" -#include "scene/3d/mesh_instance.h" #include "scene/3d/physics_body.h" #include "scene/3d/body_shape.h" -#include "scene/gui/spin_box.h" #include "scene/gui/box_container.h" -#include "scene/3d/mesh_instance.h" #include "scene/3d/navigation_mesh.h" #include "spatial_editor_plugin.h" @@ -38,92 +33,106 @@ void MeshInstanceEditor::_menu_option(int p_option) { } switch(p_option) { - case MENU_OPTION_CREATE_STATIC_TRIMESH_BODY: { - - Ref shape = mesh->create_trimesh_shape(); - if (shape.is_null()) - return; - StaticBody *body = memnew( StaticBody ); - CollisionShape *cshape = memnew( CollisionShape ); - cshape->set_shape(shape); - body->add_child(cshape); - Node *owner = node==get_tree()->get_edited_scene_root() ? node : node->get_owner(); - - UndoRedo *ur = EditorNode::get_singleton()->get_undo_redo(); - ur->create_action("Create Static Trimesh"); - ur->add_do_method(node,"add_child",body); - ur->add_do_method(body,"set_owner",owner); - ur->add_do_method(cshape,"set_owner",owner); - ur->add_do_reference(body); - ur->add_undo_method(node,"remove_child",body); - ur->commit_action(); - - } break; + case MENU_OPTION_CREATE_STATIC_TRIMESH_BODY: case MENU_OPTION_CREATE_STATIC_CONVEX_BODY: { - Ref shape = mesh->create_convex_shape(); - if (shape.is_null()) - return; - StaticBody *body = memnew( StaticBody ); - CollisionShape *cshape = memnew( CollisionShape ); - cshape->set_shape(shape); - body->add_child(cshape); - Node *owner = node==get_tree()->get_edited_scene_root() ? node : node->get_owner(); + bool trimesh_shape = (p_option==MENU_OPTION_CREATE_STATIC_TRIMESH_BODY); + EditorSelection *editor_selection = EditorNode::get_singleton()->get_editor_selection(); UndoRedo *ur = EditorNode::get_singleton()->get_undo_redo(); - ur->create_action("Create Static Trimesh"); - ur->add_do_method(node,"add_child",body); - ur->add_do_method(body,"set_owner",owner); - ur->add_do_method(cshape,"set_owner",owner); - ur->add_do_reference(body); - ur->add_undo_method(node,"remove_child",body); - ur->commit_action(); - } break; - case MENU_OPTION_CREATE_TRIMESH_COLLISION_SHAPE: { + List selection = editor_selection->get_selected_node_list(); + if (selection.empty()) { + Ref shape = trimesh_shape ? mesh->create_trimesh_shape() : mesh->create_convex_shape(); + if (shape.is_null()) + return; - if (node==get_tree()->get_edited_scene_root()) { - err_dialog->set_text("This doesn't work on scene root!"); - err_dialog->popup_centered_minsize(); + CollisionShape *cshape = memnew( CollisionShape ); + cshape->set_shape(shape); + StaticBody *body = memnew( StaticBody ); + body->add_child(cshape); + + Node *owner = node==get_tree()->get_edited_scene_root() ? node : node->get_owner(); + + if (trimesh_shape) + ur->create_action("Create Static Trimesh Body"); + else + ur->create_action("Create Static Convex Body"); + + ur->add_do_method(node,"add_child",body); + ur->add_do_method(body,"set_owner",owner); + ur->add_do_method(cshape,"set_owner",owner); + ur->add_do_reference(body); + ur->add_undo_method(node,"remove_child",body); + ur->commit_action(); return; } - Ref shape = mesh->create_trimesh_shape(); - if (shape.is_null()) - return; - CollisionShape *cshape = memnew( CollisionShape ); - cshape->set_shape(shape); - Node *owner = node->get_owner(); + if (trimesh_shape) + ur->create_action("Create Static Trimesh Body"); + else + ur->create_action("Create Static Convex Body"); + + for (List::Element *E=selection.front();E;E=E->next()) { + + MeshInstance *instance = E->get()->cast_to(); + if (!instance) + continue; + + Ref m = instance->get_mesh(); + if (m.is_null()) + continue; + + Ref shape = trimesh_shape ? m->create_trimesh_shape() : m->create_convex_shape(); + if (shape.is_null()) + continue; + + CollisionShape *cshape = memnew( CollisionShape ); + cshape->set_shape(shape); + StaticBody *body = memnew( StaticBody ); + body->add_child(cshape); + + Node *owner = instance==get_tree()->get_edited_scene_root() ? instance : instance->get_owner(); + + ur->add_do_method(instance,"add_child",body); + ur->add_do_method(body,"set_owner",owner); + ur->add_do_method(cshape,"set_owner",owner); + ur->add_do_reference(body); + ur->add_undo_method(instance,"remove_child",body); + } - UndoRedo *ur = EditorNode::get_singleton()->get_undo_redo(); - ur->create_action("Create Static Trimesh"); - ur->add_do_method(node->get_parent(),"add_child",cshape); - ur->add_do_method(node->get_parent(),"move_child",cshape,node->get_index()+1); - ur->add_do_method(cshape,"set_owner",owner); - ur->add_do_reference(cshape); - ur->add_undo_method(node->get_parent(),"remove_child",cshape); ur->commit_action(); } break; + + case MENU_OPTION_CREATE_TRIMESH_COLLISION_SHAPE: case MENU_OPTION_CREATE_CONVEX_COLLISION_SHAPE: { - if (node==get_tree()->get_edited_scene_root()) { err_dialog->set_text("This doesn't work on scene root!"); err_dialog->popup_centered_minsize(); return; } - Ref shape = mesh->create_convex_shape(); + + bool trimesh_shape = (p_option==MENU_OPTION_CREATE_TRIMESH_COLLISION_SHAPE); + + Ref shape = trimesh_shape ? mesh->create_trimesh_shape() : mesh->create_convex_shape(); if (shape.is_null()) return; + CollisionShape *cshape = memnew( CollisionShape ); cshape->set_shape(shape); Node *owner = node->get_owner(); UndoRedo *ur = EditorNode::get_singleton()->get_undo_redo(); - ur->create_action("Create Static Trimesh"); + + if (trimesh_shape) + ur->create_action("Create Trimesh Shape"); + else + ur->create_action("Create Convex Shape"); + ur->add_do_method(node->get_parent(),"add_child",cshape); ur->add_do_method(node->get_parent(),"move_child",cshape,node->get_index()+1); ur->add_do_method(cshape,"set_owner",owner); @@ -132,11 +141,9 @@ void MeshInstanceEditor::_menu_option(int p_option) { ur->commit_action(); } break; + case MENU_OPTION_CREATE_NAVMESH: { - - - Ref nmesh = memnew( NavigationMesh ); if (nmesh.is_null()) @@ -158,6 +165,7 @@ void MeshInstanceEditor::_menu_option(int p_option) { ur->add_undo_method(node,"remove_child",nmi); ur->commit_action(); } break; + case MENU_OPTION_CREATE_OUTLINE_MESH: { outline_dialog->popup_centered(Vector2(200, 90)); diff --git a/tools/editor/plugins/mesh_editor_plugin.h b/tools/editor/plugins/mesh_editor_plugin.h index e502b5dc2b9..6b3e23f31fe 100644 --- a/tools/editor/plugins/mesh_editor_plugin.h +++ b/tools/editor/plugins/mesh_editor_plugin.h @@ -23,24 +23,19 @@ class MeshInstanceEditor : public Node { MENU_OPTION_CREATE_OUTLINE_MESH, }; + MeshInstance *node; + + MenuButton *options; + ConfirmationDialog *outline_dialog; SpinBox *outline_size; AcceptDialog *err_dialog; - - Panel *panel; - MeshInstance *node; - - LineEdit *surface_source; - LineEdit *mesh_source; - - void _menu_option(int p_option); void _create_outline_mesh(); friend class MeshInstanceEditorPlugin; - MenuButton * options; protected: void _node_removed(Node *p_node); From 5f739a266057d7059c1787b22b404c5f3661b8e6 Mon Sep 17 00:00:00 2001 From: neikeq Date: Wed, 9 Dec 2015 19:56:41 +0100 Subject: [PATCH 3/6] TextEdit: Scroll while selecting with mouse idle --- scene/gui/text_edit.cpp | 41 ++++++++++++++++++++++++++++++++++++++--- scene/gui/text_edit.h | 2 ++ 2 files changed, 40 insertions(+), 3 deletions(-) diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp index 78792dc785e..29969b65e66 100644 --- a/scene/gui/text_edit.cpp +++ b/scene/gui/text_edit.cpp @@ -29,6 +29,7 @@ #include "text_edit.h" #include "os/keyboard.h" +#include "os/input.h" #include "os/os.h" #include "globals.h" @@ -349,6 +350,29 @@ void TextEdit::_update_scrollbars() { updating_scrolls=false; } +void TextEdit::_click_selection_held() { + + if (Input::get_singleton()->is_mouse_button_pressed(BUTTON_LEFT) && selection.selecting_mode!=Selection::MODE_NONE) { + + Point2 mp = Input::get_singleton()->get_mouse_pos()-get_global_pos(); + + int row,col; + _get_mouse_pos(Point2i(mp.x,mp.y), row,col); + + select(selection.selecting_line,selection.selecting_column,row,col); + + cursor_set_line( row ); + cursor_set_column( col ); + update(); + + click_select_held->start(); + + } else { + + click_select_held->stop(); + } +} + void TextEdit::_notification(int p_what) { @@ -1292,6 +1316,9 @@ void TextEdit::_input_event(const InputEvent& p_input_event) { update(); } } else { + + if (mb.button_index==BUTTON_LEFT) + click_select_held->stop(); // notify to show soft keyboard notification(NOTIFICATION_FOCUS_ENTER); @@ -1304,16 +1331,18 @@ void TextEdit::_input_event(const InputEvent& p_input_event) { if (mm.button_mask&BUTTON_MASK_LEFT) { - int row,col; - _get_mouse_pos(Point2i(mm.x,mm.y), row,col); - if (selection.selecting_mode!=Selection::MODE_NONE) { + + int row,col; + _get_mouse_pos(Point2i(mm.x,mm.y), row,col); select(selection.selecting_line,selection.selecting_column,row,col); cursor_set_line( row ); cursor_set_column( col ); update(); + + click_select_held->start(); } @@ -3697,6 +3726,7 @@ void TextEdit::_bind_methods() { ObjectTypeDB::bind_method(_MD("_cursor_changed_emit"),&TextEdit::_cursor_changed_emit); ObjectTypeDB::bind_method(_MD("_text_changed_emit"),&TextEdit::_text_changed_emit); ObjectTypeDB::bind_method(_MD("_push_current_op"),&TextEdit::_push_current_op); + ObjectTypeDB::bind_method(_MD("_click_selection_held"),&TextEdit::_click_selection_held); BIND_CONSTANT( SEARCH_MATCH_CASE ); BIND_CONSTANT( SEARCH_WHOLE_WORDS ); @@ -3811,6 +3841,11 @@ TextEdit::TextEdit() { idle_detect->set_one_shot(true); idle_detect->set_wait_time(GLOBAL_DEF("display/text_edit_idle_detect_sec",3)); idle_detect->connect("timeout", this,"_push_current_op"); + + click_select_held = memnew( Timer ); + add_child(click_select_held); + click_select_held->set_wait_time(0.05); + click_select_held->connect("timeout", this,"_click_selection_held"); #if 0 syntax_coloring=true; diff --git a/scene/gui/text_edit.h b/scene/gui/text_edit.h index 91369309cf3..f8e8ef3b9a1 100644 --- a/scene/gui/text_edit.h +++ b/scene/gui/text_edit.h @@ -219,6 +219,7 @@ class TextEdit : public Control { uint64_t last_dblclk; Timer *idle_detect; + Timer *click_select_held; HScrollBar *h_scroll; VScrollBar *v_scroll; bool updating_scrolls; @@ -240,6 +241,7 @@ class TextEdit : public Control { void adjust_viewport_to_cursor(); void _scroll_moved(double); void _update_scrollbars(); + void _click_selection_held(); void _pre_shift_selection(); void _post_shift_selection(); From d4051e6eb91ecad424a0c1d4438d99fbe622cbe3 Mon Sep 17 00:00:00 2001 From: neikeq Date: Tue, 8 Dec 2015 19:04:56 +0100 Subject: [PATCH 4/6] Spinbox: increase/decrease with mouse held --- scene/gui/spin_box.cpp | 31 +++++++++++++++++++++ scene/gui/spin_box.h | 4 +++ scene/gui/tree.cpp | 62 +++++++++++++++++++++++++++++++++++++++++- scene/gui/tree.h | 7 ++++- 4 files changed, 102 insertions(+), 2 deletions(-) diff --git a/scene/gui/spin_box.cpp b/scene/gui/spin_box.cpp index a48136f541e..051a8dd0181 100644 --- a/scene/gui/spin_box.cpp +++ b/scene/gui/spin_box.cpp @@ -68,6 +68,25 @@ void SpinBox::_line_edit_input(const InputEvent& p_event) { } +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); + set_val( get_val() + (up?get_step():-get_step())); + + if (range_click_timer->is_one_shot()) { + range_click_timer->set_wait_time(0.075); + range_click_timer->set_one_shot(false); + range_click_timer->start(); + } + + } else { + range_click_timer->stop(); + } +} + void SpinBox::_input_event(const InputEvent& p_event) { @@ -85,6 +104,10 @@ void SpinBox::_input_event(const InputEvent& p_event) { set_val( get_val() + (up?get_step():-get_step())); + range_click_timer->set_wait_time(0.6); + range_click_timer->set_one_shot(true); + range_click_timer->start(); + } break; case BUTTON_RIGHT: { @@ -112,6 +135,8 @@ void SpinBox::_input_event(const InputEvent& p_event) { if (p_event.type==InputEvent::MOUSE_BUTTON && !p_event.mouse_button.pressed && p_event.mouse_button.button_index==1) { //set_default_cursor_shape(CURSOR_ARROW); + range_click_timer->stop(); + if (drag.enabled) { drag.enabled=false; Input::get_singleton()->set_mouse_mode(Input::MOUSE_MODE_VISIBLE); @@ -167,6 +192,7 @@ void SpinBox::_notification(int p_what) { Size2i size = get_size(); updown->draw(ci,Point2i(size.width-updown->get_width(),(size.height-updown->get_height())/2)); + } else if (p_what==NOTIFICATION_FOCUS_EXIT) { @@ -227,6 +253,7 @@ void SpinBox::_bind_methods() { ObjectTypeDB::bind_method(_MD("_line_edit_focus_exit"),&SpinBox::_line_edit_focus_exit); ObjectTypeDB::bind_method(_MD("get_line_edit"),&SpinBox::get_line_edit); ObjectTypeDB::bind_method(_MD("_line_edit_input"),&SpinBox::_line_edit_input); + ObjectTypeDB::bind_method(_MD("_range_click_timeout"),&SpinBox::_range_click_timeout); ADD_PROPERTY(PropertyInfo(Variant::BOOL,"editable"),_SCS("set_editable"),_SCS("is_editable")); @@ -248,4 +275,8 @@ SpinBox::SpinBox() { line_edit->connect("focus_exit",this,"_line_edit_focus_exit",Vector(),CONNECT_DEFERRED); line_edit->connect("input_event",this,"_line_edit_input"); drag.enabled=false; + + range_click_timer = memnew( Timer ); + range_click_timer->connect("timeout",this,"_range_click_timeout"); + add_child(range_click_timer); } diff --git a/scene/gui/spin_box.h b/scene/gui/spin_box.h index 4c8cb8432a2..1b3bc6d8170 100644 --- a/scene/gui/spin_box.h +++ b/scene/gui/spin_box.h @@ -31,6 +31,7 @@ #include "scene/gui/line_edit.h" #include "scene/gui/range.h" +#include "scene/main/timer.h" class SpinBox : public Range { @@ -39,6 +40,9 @@ class SpinBox : public Range { LineEdit *line_edit; int last_w; + Timer *range_click_timer; + void _range_click_timeout(); + void _text_entered(const String& p_string); virtual void _value_changed(double); String prefix; diff --git a/scene/gui/tree.cpp b/scene/gui/tree.cpp index 16a12fe4077..ee7c0724e3b 100644 --- a/scene/gui/tree.cpp +++ b/scene/gui/tree.cpp @@ -1369,7 +1369,40 @@ Rect2 Tree::search_item_rect(TreeItem *p_from, TreeItem *p_item) { } +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(); + if (show_column_titles) { + pos.y-=_get_title_button_height(); + + if (pos.y<0) { + range_click_timer->stop(); + return; + } + } + + click_handled=false; + InputModifierState mod = {}; // should be irrelevant.. + + blocked++; + propagate_mouse_event(pos+cache.offset, 0, 0, false, root, BUTTON_LEFT, mod); + blocked--; + + if (range_click_timer->is_one_shot()) { + range_click_timer->set_wait_time(0.05); + range_click_timer->set_one_shot(false); + range_click_timer->start(); + } + + if (!click_handled) + range_click_timer->stop(); + + } else { + range_click_timer->stop(); + } +} int Tree::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) { @@ -1564,9 +1597,25 @@ int Tree::propagate_mouse_event(const Point2i &p_pos,int x_ofs,int y_ofs,bool p_ bool up=p_pos.y < (item_h /2); if (p_button==BUTTON_LEFT) { + + if (range_click_timer->get_time_left() == 0) { + + range_item_last=p_item; + range_up_last=up; + + range_click_timer->set_wait_time(0.6); + range_click_timer->set_one_shot(true); + range_click_timer->start(); + + } else if (up != range_up_last) { + + return -1; // break. avoid changing direction on mouse held + } + p_item->set_range( col, c.val + (up?1.0:-1.0) * c.step ); item_edited(col,p_item); + } else if (p_button==BUTTON_RIGHT) { p_item->set_range( col, (up?c.max:c.min) ); @@ -2024,6 +2073,8 @@ void Tree::_input_event(InputEvent p_event) { update_cache(); const InputEventMouseMotion& b=p_event.mouse_motion; + range_click_timer->stop(); + Ref bg = cache.bg; Point2 pos = Point2(b.x,b.y) - bg->get_offset(); @@ -2031,7 +2082,6 @@ void Tree::_input_event(InputEvent p_event) { Cache::ClickType old_hover = cache.hover_type; int old_index = cache.hover_index; - cache.hover_type=Cache::CLICK_NONE; cache.hover_index=0; if (show_column_titles) { @@ -2108,6 +2158,8 @@ void Tree::_input_event(InputEvent p_event) { if (b.button_index==BUTTON_LEFT) { + range_click_timer->stop(); + if (pressing_for_editor) { if (range_drag_enabled) { @@ -2228,10 +2280,13 @@ 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; } @@ -3135,6 +3190,7 @@ bool Tree::is_folding_hidden() const { void Tree::_bind_methods() { + ObjectTypeDB::bind_method(_MD("_range_click_timeout"),&Tree::_range_click_timeout); 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); @@ -3229,6 +3285,10 @@ Tree::Tree() { add_child(h_scroll); add_child(v_scroll); + range_click_timer = memnew( Timer ); + range_click_timer->connect("timeout",this,"_range_click_timeout"); + add_child(range_click_timer); + 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"); diff --git a/scene/gui/tree.h b/scene/gui/tree.h index 8fb9b802a1f..55ccc16d017 100644 --- a/scene/gui/tree.h +++ b/scene/gui/tree.h @@ -127,7 +127,7 @@ friend class Tree; - TreeItem(Tree *p_tree); + TreeItem(Tree *p_tree); void _changed_notify(int p_cell); @@ -301,6 +301,11 @@ friend class TreeItem; Vector columns; + Timer *range_click_timer; + TreeItem *range_item_last; + bool range_up_last; + void _range_click_timeout(); + int compute_item_height(TreeItem *p_item) const; int get_item_height(TreeItem *p_item) const; // void draw_item_text(String p_text,const Ref& p_icon,int p_icon_max_w,bool p_tool,Rect2i p_rect,const Color& p_color); From e4dce93520ce69e68fed68a4886b6f68ac3e98a7 Mon Sep 17 00:00:00 2001 From: Franklin Sobrinho Date: Fri, 11 Dec 2015 07:53:40 -0300 Subject: [PATCH 5/6] Fix error message when using is_connected with a script signal --- core/object.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/core/object.cpp b/core/object.cpp index 96f0c868321..f6ba76a0b56 100644 --- a/core/object.cpp +++ b/core/object.cpp @@ -1405,6 +1405,10 @@ bool Object::is_connected(const StringName& p_signal, Object *p_to_object, const bool signal_is_valid = ObjectTypeDB::has_signal(get_type_name(),p_signal); if (signal_is_valid) return false; + + if (!script.is_null() && Ref