fixed and improved selection and list selection, closes #2852

This commit is contained in:
Juan Linietsky 2015-12-13 17:16:13 -03:00
parent 7c39ebd05c
commit 72ff61963b
5 changed files with 184 additions and 102 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 470 B

View file

@ -221,7 +221,7 @@ void CanvasItemEditor::_unhandled_key_input(const InputEvent& p_ev) {
void CanvasItemEditor::_tool_select(int p_index) {
ToolButton *tb[TOOL_MAX]={select_button,move_button,rotate_button,pan_button};
ToolButton *tb[TOOL_MAX]={select_button,list_select_button,move_button,rotate_button,pan_button};
for(int i=0;i<TOOL_MAX;i++) {
tb[i]->set_pressed(i==p_index);
@ -938,6 +938,75 @@ bool CanvasItemEditor::get_remove_list(List<Node*> *p_list) {
}
void CanvasItemEditor::_list_select(const InputEventMouseButton& b) {
Point2 click=Point2(b.x,b.y);
Node* scene = editor->get_edited_scene();
if (!scene)
return;
_find_canvas_items_at_pos(click, scene,transform,Matrix32(), selection_results);
for(int i=0;i<selection_results.size();i++) {
CanvasItem *item=selection_results[i].item;
if (item!=scene && item->get_owner()!=scene && !scene->is_editable_instance(item->get_owner())) {
//invalid result
selection_results.remove(i);
i--;
}
}
if (selection_results.size() == 1) {
CanvasItem *item = selection_results[0].item;
selection_results.clear();
additive_selection=b.mod.shift;
if (!_select(item, click, additive_selection, false))
return;
} else if (!selection_results.empty()) {
selection_results.sort();
NodePath root_path = get_tree()->get_edited_scene_root()->get_path();
StringName root_name = root_path.get_name(root_path.get_name_count()-1);
for (int i = 0; i < selection_results.size(); i++) {
CanvasItem *item=selection_results[i].item;
Ref<Texture> icon;
if (item->has_meta("_editor_icon"))
icon=item->get_meta("_editor_icon");
else
icon=get_icon( has_icon(item->get_type(),"EditorIcons")?item->get_type():String("Object"),"EditorIcons");
String node_path="/"+root_name+"/"+root_path.rel_path_to(item->get_path());
selection_menu->add_item(item->get_name());
selection_menu->set_item_icon(i, icon );
selection_menu->set_item_metadata(i, node_path);
selection_menu->set_item_tooltip(i,String(item->get_name())+
"\nType: "+item->get_type()+"\nPath: "+node_path);
}
additive_selection=b.mod.shift;
selection_menu->set_global_pos(Vector2( b.global_x, b.global_y ));
selection_menu->popup();
selection_menu->call_deferred("grab_click_focus");
selection_menu->set_invalidate_click_until_motion();
return;
}
}
void CanvasItemEditor::_viewport_input_event(const InputEvent& p_event) {
{
@ -993,59 +1062,11 @@ void CanvasItemEditor::_viewport_input_event(const InputEvent& p_event) {
if (b.button_index==BUTTON_RIGHT) {
if (b.pressed && tool==TOOL_SELECT && b.mod.alt) {
Point2 click=Point2(b.x,b.y);
if (b.pressed && (tool==TOOL_SELECT && b.mod.alt)) {
Node* scene = editor->get_edited_scene();
if (!scene)
return;
_find_canvas_items_at_pos(click, scene,transform,Matrix32(), selection_results);
if (selection_results.size() == 1) {
CanvasItem *item = selection_results[0].item;
selection_results.clear();
additive_selection=b.mod.shift;
if (!_select(item, click, additive_selection, false))
return;
} else if (!selection_results.empty()) {
selection_results.sort();
NodePath root_path = get_tree()->get_edited_scene_root()->get_path();
StringName root_name = root_path.get_name(root_path.get_name_count()-1);
for (int i = 0; i < selection_results.size(); i++) {
CanvasItem *item=selection_results[i].item;
Ref<Texture> icon;
if (item->has_meta("_editor_icon"))
icon=item->get_meta("_editor_icon");
else
icon=get_icon( has_icon(item->get_type(),"EditorIcons")?item->get_type():String("Object"),"EditorIcons");
String node_path="/"+root_name+"/"+root_path.rel_path_to(item->get_path());
selection_menu->add_item(item->get_name());
selection_menu->set_item_icon(i, icon );
selection_menu->set_item_metadata(i, node_path);
selection_menu->set_item_tooltip(i,String(item->get_name())+
"\nType: "+item->get_type()+"\nPath: "+node_path);
}
additive_selection=b.mod.shift;
selection_menu->set_global_pos(Vector2( b.global_x, b.global_y ));
selection_menu->popup();
selection_menu->call_deferred("grab_click_focus");
return;
}
_list_select(b);
return;
}
if (get_item_count() > 0 && drag!=DRAG_NONE) {
@ -1103,6 +1124,12 @@ void CanvasItemEditor::_viewport_input_event(const InputEvent& p_event) {
//if (!canvas_items.size())
// return;
if (b.button_index==BUTTON_LEFT && tool==TOOL_LIST_SELECT) {
if (b.pressed)
_list_select(b);
return;
}
if (tool==TOOL_PAN || b.button_index!=BUTTON_LEFT || Input::get_singleton()->is_key_pressed(KEY_SPACE))
return;
@ -2118,6 +2145,7 @@ void CanvasItemEditor::_notification(int p_what) {
}
select_button->set_icon( get_icon("ToolSelect","EditorIcons"));
list_select_button->set_icon( get_icon("ListSelect","EditorIcons"));
move_button->set_icon( get_icon("ToolMove","EditorIcons"));
rotate_button->set_icon( get_icon("ToolRotate","EditorIcons"));
pan_button->set_icon( get_icon("ToolPan", "EditorIcons"));
@ -3155,7 +3183,8 @@ CanvasItemEditor::CanvasItemEditor(EditorNode *p_editor) {
hb->add_child(select_button);
select_button->connect("pressed",this,"_tool_select",make_binds(TOOL_SELECT));
select_button->set_pressed(true);
select_button->set_tooltip("Select Mode (Q)\n"+keycode_get_string(KEY_MASK_CMD)+"Drag: Rotate\nAlt+Drag: Move\nPress 'v' to Change Pivot, 'Shift+v' to Drag Pivot (while moving).");
select_button->set_tooltip("Select Mode (Q)\n"+keycode_get_string(KEY_MASK_CMD)+"Drag: Rotate\nAlt+Drag: Move\nPress 'v' to Change Pivot, 'Shift+v' to Drag Pivot (while moving).\nAlt+RMB: Depth list selection");
move_button = memnew( ToolButton );
move_button->set_toggle_mode(true);
@ -3171,6 +3200,12 @@ CanvasItemEditor::CanvasItemEditor(EditorNode *p_editor) {
hb->add_child(memnew(VSeparator));
list_select_button = memnew( ToolButton );
list_select_button->set_toggle_mode(true);
hb->add_child(list_select_button);
list_select_button->connect("pressed",this,"_tool_select",make_binds(TOOL_LIST_SELECT));
list_select_button->set_tooltip("Show a list of all objects at the position clicked\n(same as Alt+RMB in selet mode).");
pan_button = memnew( ToolButton );
pan_button->set_toggle_mode(true);
hb->add_child(pan_button);

View file

@ -67,6 +67,7 @@ class CanvasItemEditor : public VBoxContainer {
enum Tool {
TOOL_SELECT,
TOOL_LIST_SELECT,
TOOL_MOVE,
TOOL_ROTATE,
TOOL_PAN,
@ -240,6 +241,7 @@ class CanvasItemEditor : public VBoxContainer {
List<PoseClipboard> pose_clipboard;
ToolButton *select_button;
ToolButton *list_select_button;
ToolButton *move_button;
ToolButton *rotate_button;
@ -309,6 +311,7 @@ class CanvasItemEditor : public VBoxContainer {
void _clear_canvas_items();
void _visibility_changed(ObjectID p_canvas_item);
void _key_move(const Vector2& p_dir, bool p_snap, KeyMoveMODE p_move_mode);
void _list_select(const InputEventMouseButton& b);
DragType _find_drag_type(const Matrix32& p_xform, const Rect2& p_local_rect, const Point2& p_click, Vector2& r_point);

View file

@ -736,6 +736,68 @@ void SpatialEditorViewport::_smouseenter() {
surface->grab_focus();
}
void SpatialEditorViewport::_list_select(InputEventMouseButton b) {
_find_items_at_pos(Vector2( b.x, b.y ),clicked_includes_current,selection_results,b.mod.shift);
Node *scene=editor->get_edited_scene();
for(int i=0;i<selection_results.size();i++) {
Spatial *item=selection_results[i].item;
if (item!=scene && item->get_owner()!=scene && !scene->is_editable_instance(item->get_owner())) {
//invalid result
selection_results.remove(i);
i--;
}
}
clicked_wants_append=b.mod.shift;
if (selection_results.size() == 1) {
clicked=selection_results[0].item->get_instance_ID();
selection_results.clear();
if (clicked) {
_select_clicked(clicked_wants_append,true);
clicked=0;
}
} else if (!selection_results.empty()) {
NodePath root_path = get_tree()->get_edited_scene_root()->get_path();
StringName root_name = root_path.get_name(root_path.get_name_count()-1);
for (int i = 0; i < selection_results.size(); i++) {
Spatial *spat=selection_results[i].item;
Ref<Texture> icon;
if (spat->has_meta("_editor_icon"))
icon=spat->get_meta("_editor_icon");
else
icon=get_icon( has_icon(spat->get_type(),"EditorIcons")?spat->get_type():String("Object"),"EditorIcons");
String node_path="/"+root_name+"/"+root_path.rel_path_to(spat->get_path());
selection_menu->add_item(spat->get_name());
selection_menu->set_item_icon(i, icon );
selection_menu->set_item_metadata(i, node_path);
selection_menu->set_item_tooltip(i,String(spat->get_name())+
"\nType: "+spat->get_type()+"\nPath: "+node_path);
}
selection_menu->set_global_pos(Vector2( b.global_x, b.global_y ));
selection_menu->popup();
selection_menu->call_deferred("grab_click_focus");
selection_menu->set_invalidate_click_until_motion();
}
}
void SpatialEditorViewport::_sinput(const InputEvent &p_event) {
if (previewing)
@ -868,50 +930,9 @@ void SpatialEditorViewport::_sinput(const InputEvent &p_event) {
if (nav_scheme == NAVIGATION_MAYA)
break;
_find_items_at_pos(Vector2( b.x, b.y ),clicked_includes_current,selection_results,b.mod.shift);
_list_select(b);
return;
clicked_wants_append=b.mod.shift;
if (selection_results.size() == 1) {
clicked=selection_results[0].item->get_instance_ID();
selection_results.clear();
if (clicked) {
_select_clicked(clicked_wants_append,true);
clicked=0;
}
} else if (!selection_results.empty()) {
NodePath root_path = get_tree()->get_edited_scene_root()->get_path();
StringName root_name = root_path.get_name(root_path.get_name_count()-1);
for (int i = 0; i < selection_results.size(); i++) {
Spatial *spat=selection_results[i].item;
Ref<Texture> icon;
if (spat->has_meta("_editor_icon"))
icon=spat->get_meta("_editor_icon");
else
icon=get_icon( has_icon(spat->get_type(),"EditorIcons")?spat->get_type():String("Object"),"EditorIcons");
String node_path="/"+root_name+"/"+root_path.rel_path_to(spat->get_path());
selection_menu->add_item(spat->get_name());
selection_menu->set_item_icon(i, icon );
selection_menu->set_item_metadata(i, node_path);
selection_menu->set_item_tooltip(i,String(spat->get_name())+
"\nType: "+spat->get_type()+"\nPath: "+node_path);
}
selection_menu->set_global_pos(Vector2( b.global_x, b.global_y ));
selection_menu->popup();
selection_menu->call_deferred("grab_click_focus");
break;
}
}
}
@ -984,6 +1005,11 @@ void SpatialEditorViewport::_sinput(const InputEvent &p_event) {
break;
}
if (spatial_editor->get_tool_mode()==SpatialEditor::TOOL_MODE_LIST_SELECT) {
_list_select(b);
break;
}
_edit.mouse_pos=Point2(b.x,b.y);
_edit.snap=false;
_edit.mode=TRANSFORM_NONE;
@ -2841,13 +2867,14 @@ void SpatialEditor::_menu_item_pressed(int p_option) {
case MENU_TOOL_SELECT:
case MENU_TOOL_MOVE:
case MENU_TOOL_ROTATE:
case MENU_TOOL_SCALE: {
case MENU_TOOL_SCALE:
case MENU_TOOL_LIST_SELECT: {
for(int i=0;i<4;i++)
for(int i=0;i<TOOL_MAX;i++)
tool_button[i]->set_pressed(i==p_option);
tool_mode=(ToolMode)p_option;
static const char *_mode[]={"Selection Mode.","Translation Mode.","Rotation Mode.","Scale Mode."};
static const char *_mode[]={"Selection Mode.","Translation Mode.","Rotation Mode.","Scale Mode.","List Selection Mode."};
// set_message(_mode[p_option],3);
update_transform_gizmo();
@ -3530,6 +3557,7 @@ void SpatialEditor::_notification(int p_what) {
tool_button[SpatialEditor::TOOL_MODE_MOVE]->set_icon( get_icon("ToolMove","EditorIcons") );
tool_button[SpatialEditor::TOOL_MODE_ROTATE]->set_icon( get_icon("ToolRotate","EditorIcons") );
tool_button[SpatialEditor::TOOL_MODE_SCALE]->set_icon( get_icon("ToolScale","EditorIcons") );
tool_button[SpatialEditor::TOOL_MODE_LIST_SELECT]->set_icon( get_icon("ListSelect","EditorIcons") );
instance_button->set_icon( get_icon("SpatialAdd","EditorIcons") );
instance_button->hide();
@ -3807,7 +3835,7 @@ SpatialEditor::SpatialEditor(EditorNode *p_editor) {
tool_button[TOOL_MODE_SELECT]->set_pressed(true);
button_binds[0]=MENU_TOOL_SELECT;
tool_button[TOOL_MODE_SELECT]->connect("pressed", this,"_menu_item_pressed",button_binds);
tool_button[TOOL_MODE_SELECT]->set_tooltip("Select Mode (Q)");
tool_button[TOOL_MODE_SELECT]->set_tooltip("Select Mode (Q)\n"+keycode_get_string(KEY_MASK_CMD)+"Drag: Rotate\nAlt+Drag: Move\nAlt+RMB: Depth list selection");
tool_button[TOOL_MODE_MOVE] = memnew( ToolButton );
@ -3839,10 +3867,22 @@ SpatialEditor::SpatialEditor(EditorNode *p_editor) {
hbc_menu->add_child( instance_button );
instance_button->set_flat(true);
instance_button->connect("pressed",this,"_instance_scene");
instance_button->hide();
VSeparator *vs = memnew( VSeparator );
hbc_menu->add_child(vs);
tool_button[TOOL_MODE_LIST_SELECT] = memnew( ToolButton );
hbc_menu->add_child( tool_button[TOOL_MODE_LIST_SELECT] );
tool_button[TOOL_MODE_LIST_SELECT]->set_toggle_mode(true);
tool_button[TOOL_MODE_LIST_SELECT]->set_flat(true);
button_binds[0]=MENU_TOOL_LIST_SELECT;
tool_button[TOOL_MODE_LIST_SELECT]->connect("pressed", this,"_menu_item_pressed",button_binds);
tool_button[TOOL_MODE_LIST_SELECT]->set_tooltip("Show a list of all objects at the position clicked\n(same as Alt+RMB in selet mode).");
vs = memnew( VSeparator );
hbc_menu->add_child(vs);
PopupMenu *p;

View file

@ -239,6 +239,7 @@ private:
void _finish_gizmo_instances();
void _selection_result_pressed(int);
void _selection_menu_hide();
void _list_select(InputEventMouseButton b);
protected:
@ -287,7 +288,9 @@ public:
TOOL_MODE_SELECT,
TOOL_MODE_MOVE,
TOOL_MODE_ROTATE,
TOOL_MODE_SCALE
TOOL_MODE_SCALE,
TOOL_MODE_LIST_SELECT,
TOOL_MAX
};
@ -369,6 +372,7 @@ private:
MENU_TOOL_MOVE,
MENU_TOOL_ROTATE,
MENU_TOOL_SCALE,
MENU_TOOL_LIST_SELECT,
MENU_TRANSFORM_USE_SNAP,
MENU_TRANSFORM_CONFIGURE_SNAP,
MENU_TRANSFORM_LOCAL_COORDS,
@ -392,7 +396,7 @@ private:
};
Button *tool_button[4];
Button *tool_button[TOOL_MAX];
Button *instance_button;