/*
* 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 .
*/
#pragma once
#include
#include
#include
#include
#include "DrawingProgramLayerFolder.hpp"
#include "DrawingProgramLayer.hpp"
#include "SerializedBlendMode.hpp"
#include "../../CanvasComponents/CanvasComponentContainer.hpp"
class DrawingProgramLayerFolder;
class DrawingProgramLayer;
class World;
class DrawingProgramLayerManager;
struct DrawingProgramLayerListItemMetaInfo {
std::string name;
float alpha = 1.0f;
SerializedBlendMode blendMode = SerializedBlendMode::BLEND_SRC_OVER;
bool operator==(const DrawingProgramLayerListItemMetaInfo&) const = default;
};
struct DrawingProgramLayerListItemUndoData {
WorldUndoManager::UndoObjectID undoID;
WorldUndoManager::UndoObjectID containerUndoID; // Contains either the undoID of folderData->folderList, or layerData->components. Allows for undo to directly point to those two containers
DrawingProgramLayerListItemMetaInfo metaInfo;
std::optional> folderData;
std::optional> layerData;
void scale_up(const WorldScalar& scaleUpAmount);
};
class DrawingProgramLayerListItem {
public:
DrawingProgramLayerListItem();
DrawingProgramLayerListItem(NetworkingObjects::NetObjManager& netObjMan, const std::string& initName, bool isFolder);
DrawingProgramLayerListItem(World& w, const DrawingProgramLayerListItemUndoData& undoData);
DrawingProgramLayerListItemUndoData get_undo_data(WorldUndoManager& u) const;
bool is_folder() const;
DrawingProgramLayerFolder& get_folder() const;
DrawingProgramLayer& get_layer() const;
static void register_class(World& w);
void reassign_netobj_ids_call();
void set_to_erase();
void set_component_list_callbacks(DrawingProgramLayerManager &layerMan);
void draw(SkCanvas* canvas, const DrawData& drawData) const;
void set_name(NetworkingObjects::DelayUpdateSerializedClassManager& delayedNetObjMan, const std::string& newName) const;
const std::string& get_name() const;
void get_flattened_component_list(std::vector& objList) const;
void get_flattened_layer_list(std::vector& objList);
void scale_up(const WorldScalar& scaleUpAmount);
void get_used_resources(std::unordered_set& resourceSet) const;
void set_alpha(DrawingProgramLayerManager& layerMan, float newAlpha) const;
float get_alpha() const;
void load_file(cereal::PortableBinaryInputArchive& a, VersionNumber version, DrawingProgramLayerManager& layerMan);
void save_file(cereal::PortableBinaryOutputArchive& a) const;
void set_visible(DrawingProgramLayerManager& layerMan, bool newVisible) const;
bool get_visible() const;
void set_blend_mode(DrawingProgramLayerManager& layerMan, SerializedBlendMode newBlendMode) const;
SerializedBlendMode get_blend_mode() const;
void set_metainfo(DrawingProgramLayerManager& layerMan, const DrawingProgramLayerListItemMetaInfo& metaInfo);
DrawingProgramLayerListItemMetaInfo get_metainfo() const;
uint32_t get_component_count() const;
void erase_invalid_components();
private:
static void write_constructor_func(const NetworkingObjects::NetObjTemporaryPtr& o, cereal::PortableBinaryOutputArchive& a);
static void read_constructor_func(const NetworkingObjects::NetObjTemporaryPtr& o, cereal::PortableBinaryInputArchive& a, const std::shared_ptr& c);
std::unique_ptr folderData;
std::unique_ptr layerData;
struct NameData {
std::string name;
template void serialize(Archive& a) {
a(name);
}
};
struct DisplayData {
float alpha = 1.0f;
bool visible = true;
SerializedBlendMode blendMode = SerializedBlendMode::BLEND_SRC_OVER;
template void serialize(Archive& a) {
a(alpha, visible, blendMode);
}
};
NetworkingObjects::NetObjOwnerPtr nameData;
NetworkingObjects::NetObjOwnerPtr displayData;
};