diff options
author | dankan1890 <mewuidev2@gmail.com> | 2019-04-18 22:35:00 +0200 |
---|---|---|
committer | dankan1890 <mewuidev2@gmail.com> | 2019-04-21 02:51:49 +0200 |
commit | 12a01a33aade58c6d1bab6fef1a41261d4223643 (patch) | |
tree | 1fbeb199c770400361115a253d3b1583acc97957 /editor | |
parent | 4ad255a078da0e9cc2620fe714bd722aae38206f (diff) |
Tileset-Editor: Added alternative tool for drawing a rectangular shape.
Diffstat (limited to 'editor')
-rw-r--r-- | editor/plugins/tile_set_editor_plugin.cpp | 39 |
1 files changed, 34 insertions, 5 deletions
diff --git a/editor/plugins/tile_set_editor_plugin.cpp b/editor/plugins/tile_set_editor_plugin.cpp index 8cf00cf67d..21470d81ed 100644 --- a/editor/plugins/tile_set_editor_plugin.cpp +++ b/editor/plugins/tile_set_editor_plugin.cpp @@ -1561,13 +1561,42 @@ void TileSetEditor::_on_workspace_input(const Ref<InputEvent> &p_ie) { if (mb->is_pressed() && mb->get_button_index() == BUTTON_LEFT) { _set_edited_collision_shape(Ref<ConvexPolygonShape2D>()); current_shape.resize(0); - current_shape.push_back(snap_point(shape_anchor)); - current_shape.push_back(snap_point(shape_anchor + Vector2(current_tile_region.size.x, 0))); - current_shape.push_back(snap_point(shape_anchor + current_tile_region.size)); - current_shape.push_back(snap_point(shape_anchor + Vector2(0, current_tile_region.size.y))); - close_shape(shape_anchor); + Vector2 pos = mb->get_position(); + pos = snap_point(pos); + current_shape.push_back(pos); + current_shape.push_back(pos); + current_shape.push_back(pos); + current_shape.push_back(pos); + creating_shape = true; workspace->update(); + return; } else if (mb->is_pressed() && mb->get_button_index() == BUTTON_RIGHT) { + if (creating_shape) { + creating_shape = false; + _select_edited_shape_coord(); + workspace->update(); + } + } else if (!mb->is_pressed() && mb->get_button_index() == BUTTON_LEFT) { + if (creating_shape) { + if ((current_shape[0] - current_shape[1]).length_squared() <= grab_threshold) { + current_shape.set(0, snap_point(shape_anchor)); + current_shape.set(1, snap_point(shape_anchor + Vector2(current_tile_region.size.x, 0))); + current_shape.set(2, snap_point(shape_anchor + current_tile_region.size)); + current_shape.set(3, snap_point(shape_anchor + Vector2(0, current_tile_region.size.y))); + } + close_shape(shape_anchor); + workspace->update(); + return; + } + } + } else if (mm.is_valid()) { + if (creating_shape) { + Vector2 pos = mm->get_position(); + pos = snap_point(pos); + Vector2 p = current_shape[2]; + current_shape.set(3, snap_point(Vector2(pos.x, p.y))); + current_shape.set(0, snap_point(pos)); + current_shape.set(1, snap_point(Vector2(p.x, pos.y))); workspace->update(); } } |