MCPcopy Create free account
hub / github.com/ErrorAtLine0/infinipaint / add_file_to_canvas_by_path

Method add_file_to_canvas_by_path

src/DrawingProgram/DrawingProgram.cpp:721–743  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

719}
720
721void DrawingProgram::add_file_to_canvas_by_path(const std::filesystem::path& filePath, Vector2f dropPos) {
722 if(layerMan.is_a_layer_being_edited()) {
723 NetworkingObjects::NetObjTemporaryPtr<ResourceData> imageTempPtr = world.rMan.add_resource_file(filePath);
724 if(imageTempPtr) {
725 NetworkingObjects::NetObjID imageID = imageTempPtr.get_net_id();
726 ResourceDisplay* display = world.rMan.get_display_data(imageID);
727 Vector2f imTrueDim = display->get_dimensions();
728 CanvasComponentContainer* newContainer = new CanvasComponentContainer(world.netObjMan, CanvasComponentType::IMAGE);
729 ImageCanvasComponent& img = static_cast<ImageCanvasComponent&>(newContainer->get_comp());
730 newContainer->coords = world.drawData.cam.c;
731 if(world.main.g.gui.io.isTouchDevice)
732 newContainer->coords.scale_about_double(world.drawData.cam.c.from_space(dropPos), 1.0 / world.main.get_scale_and_density_factor_gui());
733 float imWidth = imTrueDim.x() / (imTrueDim.x() + imTrueDim.y());
734 float imHeight = imTrueDim.y() / (imTrueDim.x() + imTrueDim.y());
735 Vector2f imDim = Vector2f{world.main.window.size.x() * imWidth, world.main.window.size.x() * imHeight} * display->get_dimension_scale();
736 img.d.p1 = dropPos - imDim;
737 img.d.p2 = dropPos + imDim;
738 img.d.imageID = imageID;
739 auto newObjInfo = layerMan.add_component_to_layer_being_edited(newContainer);
740 layerMan.add_undo_place_component(newObjInfo);
741 }
742 }
743}
744
745CanvasComponentContainer::ObjInfo* DrawingProgram::add_file_to_canvas_by_data(const std::string& fileName, std::string_view fileBuffer, Vector2f dropPos) {
746 if(layerMan.is_a_layer_being_edited()) {

Callers

nothing calls this directly

Calls 13

add_resource_fileMethod · 0.80
get_display_dataMethod · 0.80
scale_about_doubleMethod · 0.80
get_net_idMethod · 0.45
get_dimensionsMethod · 0.45
from_spaceMethod · 0.45
xMethod · 0.45
yMethod · 0.45

Tested by

no test coverage detected