2025-12-25 17:18:28 +03:00
|
|
|
#include "DrawingProgramLayer.hpp"
|
2025-12-26 10:10:19 +03:00
|
|
|
#include "DrawingProgramLayerManager.hpp"
|
|
|
|
|
#include "../DrawingProgram.hpp"
|
|
|
|
|
#include <Helpers/Parallel.hpp>
|
2025-12-25 17:18:28 +03:00
|
|
|
|
2025-12-26 19:52:36 +03:00
|
|
|
void DrawingProgramLayer::draw(SkCanvas* canvas, const DrawData& drawData) const {
|
2025-12-25 17:18:28 +03:00
|
|
|
for(auto& p : components->get_data())
|
|
|
|
|
p->obj->draw(canvas, drawData);
|
|
|
|
|
}
|
2025-12-26 10:10:19 +03:00
|
|
|
|
2025-12-28 17:34:33 +03:00
|
|
|
void DrawingProgramLayer::set_component_list_callbacks(DrawingProgramLayerListItem& layerListItem, DrawingProgramLayerManager& layerMan) const {
|
2025-12-26 10:10:19 +03:00
|
|
|
components->set_insert_callback([&](const CanvasComponentContainer::ObjInfoSharedPtr& c) {
|
|
|
|
|
c->obj->set_owner_obj_info(c);
|
2025-12-28 17:34:33 +03:00
|
|
|
c->obj->parentLayer = &layerListItem;
|
2025-12-26 10:10:19 +03:00
|
|
|
c->obj->commit_update(layerMan.drawP); // Run commit update on insert so that world bounds are calculated
|
2025-12-28 17:34:33 +03:00
|
|
|
layerMan.drawP.drawCache.add_component(c);
|
|
|
|
|
if(c->obj->get_comp().get_type() == CanvasComponentType::IMAGE)
|
|
|
|
|
layerMan.drawP.updateableComponents.emplace(c);
|
|
|
|
|
});
|
|
|
|
|
components->set_erase_callback([&](const CanvasComponentContainer::ObjInfoSharedPtr& c) {
|
|
|
|
|
layerMan.drawP.drawCache.erase_component(c);
|
|
|
|
|
layerMan.drawP.drawTool->erase_component(c);
|
|
|
|
|
std::erase_if(layerMan.drawP.droppedDownloadingFiles, [&c](auto& downloadingFile) {
|
|
|
|
|
return downloadingFile.comp == c;
|
|
|
|
|
});
|
|
|
|
|
layerMan.drawP.updateableComponents.erase(c);
|
|
|
|
|
});
|
|
|
|
|
components->set_move_callback([&](const CanvasComponentContainer::ObjInfoSharedPtr& c, uint32_t oldPos) {
|
|
|
|
|
layerMan.drawP.drawCache.invalidate_cache_at_aabb(c->obj->get_world_bounds());
|
2025-12-26 10:10:19 +03:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-26 19:52:36 +03:00
|
|
|
void DrawingProgramLayer::commit_update_dont_invalidate_cache(DrawingProgramLayerManager& layerMan) const {
|
2025-12-26 10:10:19 +03:00
|
|
|
parallel_loop_container(components->get_data(), [&layerMan](auto& comp) {
|
|
|
|
|
comp->obj->commit_update_dont_invalidate_cache(layerMan.drawP);
|
|
|
|
|
});
|
|
|
|
|
}
|
2025-12-26 19:52:36 +03:00
|
|
|
|
|
|
|
|
void DrawingProgramLayer::get_flattened_component_list(std::vector<CanvasComponentContainer::ObjInfoSharedPtr>& objList) const {
|
|
|
|
|
objList.insert(objList.begin(), components->get_data().begin(), components->get_data().end());
|
|
|
|
|
}
|