| 767 | } |
| 768 | |
| 769 | void DrawingProgramSelection::paste_clipboard(Vector2f pasteScreenPos) { |
| 770 | check_add_stroke_color_change_undo(); |
| 771 | |
| 772 | if(drawP.layerMan.is_a_layer_being_edited()) { |
| 773 | auto& clipboard = drawP.world.main.clipboard; |
| 774 | |
| 775 | if(!drawP.is_selection_allowing_tool(drawP.drawTool->get_type())) |
| 776 | drawP.switch_to_tool(DrawingProgramToolType::EDIT); |
| 777 | |
| 778 | std::vector<std::pair<CanvasComponentContainer::ObjInfoIterator, CanvasComponentContainer*>> placedComponents; |
| 779 | WorldVec mousePos = drawP.world.drawData.cam.c.from_space(pasteScreenPos); |
| 780 | WorldVec moveVec = drawP.world.main.clipboard.pos - mousePos; |
| 781 | WorldMultiplier scaleMultiplier = WorldMultiplier(drawP.world.main.clipboard.inverseScale) / WorldMultiplier(drawP.world.drawData.cam.c.inverseScale); |
| 782 | WorldScalar scaleLimit(0.001); |
| 783 | for(auto& c : drawP.world.main.clipboard.components) { |
| 784 | if((c->coords.inverseScale / scaleMultiplier) < scaleLimit) { |
| 785 | Logger::get().log(Logger::LogType::WORLDFATAL, "Some pasted objects will be too small! Scale up the canvas first (zoom in alot)"); |
| 786 | return; |
| 787 | } |
| 788 | } |
| 789 | |
| 790 | std::unordered_map<NetworkingObjects::NetObjID, NetworkingObjects::NetObjID> resourceRemapIDs; |
| 791 | for(auto& r : clipboard.resources) |
| 792 | resourceRemapIDs[r.first] = drawP.world.rMan.add_resource(r.second).get_net_id(); |
| 793 | for(auto& c : clipboard.components) { |
| 794 | CanvasComponentContainer* newComponentContainer = new CanvasComponentContainer(drawP.world.netObjMan, *c); |
| 795 | newComponentContainer->get_comp().remap_resource_ids(resourceRemapIDs); |
| 796 | newComponentContainer->coords.translate(-moveVec); |
| 797 | newComponentContainer->coords.scale_about(mousePos, scaleMultiplier); |
| 798 | placedComponents.emplace_back(drawP.layerMan.get_edited_layer_end_iterator(), newComponentContainer); |
| 799 | } |
| 800 | std::vector<CanvasComponentContainer::ObjInfoIterator> newlyInsertedObjectIts; |
| 801 | drawP.layerMan.disable_add_to_cache_and_commit_update_block([&]() { |
| 802 | newlyInsertedObjectIts = drawP.layerMan.add_many_components_to_layer_being_edited(placedComponents); |
| 803 | }); |
| 804 | std::vector<CanvasComponentContainer::ObjInfo*> compSetInserted; |
| 805 | for(auto& it : newlyInsertedObjectIts) |
| 806 | compSetInserted.emplace_back(&(*it)); |
| 807 | parallel_loop_container(compSetInserted, [&drawP = drawP](CanvasComponentContainer::ObjInfo* comp) { |
| 808 | comp->obj->commit_update_dont_invalidate_cache(drawP); |
| 809 | }); |
| 810 | set_to_selection(compSetInserted); |
| 811 | } |
| 812 | } |
| 813 | |
| 814 | void DrawingProgramSelection::paste_image_process_event(const CustomEvents::PasteEvent& paste) { |
| 815 | check_add_stroke_color_change_undo(); |
no test coverage detected