2026-05-11 23:06:39 +03:00
|
|
|
/*
|
|
|
|
|
* InfiniPaint
|
|
|
|
|
* Copyright (C) 2025-2026 Yousef Khadadeh
|
|
|
|
|
*
|
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
|
2025-12-25 17:18:28 +03:00
|
|
|
#include "DrawingProgramLayerFolder.hpp"
|
|
|
|
|
#include "DrawingProgramLayerListItem.hpp"
|
2025-12-26 10:10:19 +03:00
|
|
|
#include "DrawingProgramLayer.hpp"
|
|
|
|
|
#include <Helpers/Parallel.hpp>
|
2026-01-01 22:46:02 +03:00
|
|
|
#include "DrawingProgramLayerManager.hpp"
|
|
|
|
|
#include "../DrawingProgram.hpp"
|
|
|
|
|
#include "../../World.hpp"
|
2025-12-25 17:18:28 +03:00
|
|
|
|
2025-12-26 19:52:36 +03:00
|
|
|
void DrawingProgramLayerFolder::draw(SkCanvas* canvas, const DrawData& drawData) const {
|
2025-12-30 19:46:08 +03:00
|
|
|
for(auto& p : (*folderList) | std::views::reverse)
|
|
|
|
|
p.obj->draw(canvas, drawData);
|
2025-12-25 17:18:28 +03:00
|
|
|
}
|
2025-12-26 10:10:19 +03:00
|
|
|
|
2025-12-30 21:18:59 +03:00
|
|
|
void DrawingProgramLayerFolder::set_component_list_callbacks(DrawingProgramLayerManager& layerMan) {
|
2025-12-26 10:10:19 +03:00
|
|
|
folderList->set_insert_callback([&](auto& c) {
|
2026-01-11 09:10:07 +03:00
|
|
|
layerMan.drawP.drawCache.clear_own_cached_surfaces();
|
2025-12-26 10:10:19 +03:00
|
|
|
c->obj->set_component_list_callbacks(layerMan);
|
2026-04-09 12:00:36 +03:00
|
|
|
layerMan.drawP.world.set_to_layout_gui_if_focus();
|
2025-12-26 10:10:19 +03:00
|
|
|
});
|
2025-12-30 21:18:59 +03:00
|
|
|
folderList->set_erase_callback([&](auto& c) {
|
2026-01-11 09:10:07 +03:00
|
|
|
layerMan.drawP.drawCache.clear_own_cached_surfaces();
|
2025-12-30 21:18:59 +03:00
|
|
|
c->obj->set_to_erase();
|
2026-04-09 12:00:36 +03:00
|
|
|
layerMan.drawP.world.set_to_layout_gui_if_focus();
|
2025-12-30 21:18:59 +03:00
|
|
|
});
|
2026-01-11 09:10:07 +03:00
|
|
|
folderList->set_move_callback([&](auto& c, uint32_t oldPos) {
|
|
|
|
|
layerMan.drawP.drawCache.clear_own_cached_surfaces();
|
2026-04-09 12:00:36 +03:00
|
|
|
layerMan.drawP.world.set_to_layout_gui_if_focus();
|
2026-01-11 09:10:07 +03:00
|
|
|
});
|
2025-12-30 19:46:08 +03:00
|
|
|
for(auto& listItem : *folderList)
|
|
|
|
|
listItem.obj->set_component_list_callbacks(layerMan);
|
2025-12-26 10:10:19 +03:00
|
|
|
}
|
|
|
|
|
|
2025-12-30 21:18:59 +03:00
|
|
|
void DrawingProgramLayerFolder::set_to_erase() {
|
|
|
|
|
for(auto& listItem : *folderList)
|
|
|
|
|
listItem.obj->set_to_erase();
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-30 19:46:08 +03:00
|
|
|
void DrawingProgramLayerFolder::get_flattened_component_list(std::vector<CanvasComponentContainer::ObjInfo*>& objList) const {
|
|
|
|
|
for(auto& listItem : (*folderList) | std::views::reverse)
|
|
|
|
|
listItem.obj->get_flattened_component_list(objList);
|
2025-12-26 19:52:36 +03:00
|
|
|
}
|
2025-12-31 11:59:53 +03:00
|
|
|
|
|
|
|
|
NetworkingObjects::NetObjWeakPtr<DrawingProgramLayerListItem> DrawingProgramLayerFolder::get_initial_editing_layer() const {
|
|
|
|
|
// BFS, select a layer that's closest to root as possible
|
|
|
|
|
for(auto& c : *folderList) {
|
|
|
|
|
if(!c.obj->is_folder())
|
|
|
|
|
return c.obj;
|
|
|
|
|
}
|
|
|
|
|
for(auto& c : *folderList) {
|
|
|
|
|
if(c.obj->is_folder()) {
|
|
|
|
|
NetworkingObjects::NetObjWeakPtr<DrawingProgramLayerListItem> toRet = c.obj->get_folder().get_initial_editing_layer();
|
|
|
|
|
if(!toRet.expired())
|
|
|
|
|
return toRet;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return {};
|
|
|
|
|
}
|
2025-12-31 16:30:56 +03:00
|
|
|
|
|
|
|
|
void DrawingProgramLayerFolder::scale_up(const WorldScalar& scaleUpAmount) {
|
|
|
|
|
for(auto& p : *folderList)
|
|
|
|
|
p.obj->scale_up(scaleUpAmount);
|
|
|
|
|
}
|
2026-01-01 22:46:02 +03:00
|
|
|
|
|
|
|
|
void DrawingProgramLayerFolder::load_file(cereal::PortableBinaryInputArchive& a, VersionNumber version, DrawingProgramLayerManager& layerMan) {
|
|
|
|
|
folderList = layerMan.drawP.world.netObjMan.make_obj<NetworkingObjects::NetObjOrderedList<DrawingProgramLayerListItem>>();
|
|
|
|
|
uint32_t folderListSize;
|
|
|
|
|
a(folderListSize);
|
|
|
|
|
for(uint32_t i = 0; i < folderListSize; i++) {
|
|
|
|
|
DrawingProgramLayerListItem* item = new DrawingProgramLayerListItem();
|
|
|
|
|
item->load_file(a, version, layerMan);
|
|
|
|
|
folderList->push_back_and_send_create(folderList, item);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DrawingProgramLayerFolder::save_file(cereal::PortableBinaryOutputArchive& a) const {
|
|
|
|
|
a(folderList->size());
|
|
|
|
|
for(auto& listItem : *folderList)
|
|
|
|
|
listItem.obj->save_file(a);
|
|
|
|
|
}
|
2026-01-01 23:28:26 +03:00
|
|
|
|
2026-04-03 14:18:04 +03:00
|
|
|
void DrawingProgramLayerFolder::erase_invalid_components() {
|
|
|
|
|
for(auto& listItem : *folderList)
|
|
|
|
|
listItem.obj->erase_invalid_components();
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-01 23:28:26 +03:00
|
|
|
void DrawingProgramLayerFolder::get_used_resources(std::unordered_set<NetworkingObjects::NetObjID>& resourceSet) const {
|
|
|
|
|
for(auto& listItem : *folderList)
|
|
|
|
|
listItem.obj->get_used_resources(resourceSet);
|
|
|
|
|
}
|