infinipaint/src/DrawingProgram/Layers/DrawingProgramLayerListItem.hpp

111 lines
5.2 KiB
C++
Raw Normal View History

/*
* 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/>.
*/
#pragma once
#include <Helpers/NetworkingObjects/NetObjManager.hpp>
#include <Helpers/NetworkingObjects/NetObjOrderedList.hpp>
#include <Helpers/NetworkingObjects/DelayUpdateSerializedClassManager.hpp>
2026-01-01 23:28:26 +03:00
#include <unordered_set>
#include "DrawingProgramLayerFolder.hpp"
#include "DrawingProgramLayer.hpp"
2025-12-25 19:37:41 +03:00
#include "SerializedBlendMode.hpp"
#include "../../CanvasComponents/CanvasComponentContainer.hpp"
class DrawingProgramLayerFolder;
class DrawingProgramLayer;
class World;
2025-12-26 10:10:19 +03:00
class DrawingProgramLayerManager;
2026-01-04 11:37:38 +03:00
struct DrawingProgramLayerListItemMetaInfo {
2026-01-03 13:35:24 +03:00
std::string name;
float alpha = 1.0f;
2026-01-08 19:44:42 +03:00
SerializedBlendMode blendMode = SerializedBlendMode::BLEND_SRC_OVER;
2026-01-04 11:37:38 +03:00
bool operator==(const DrawingProgramLayerListItemMetaInfo&) const = default;
2026-01-03 13:35:24 +03:00
};
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
2026-01-04 11:37:38 +03:00
DrawingProgramLayerListItemMetaInfo metaInfo;
std::optional<std::vector<DrawingProgramLayerListItemUndoData>> folderData;
std::optional<std::vector<DrawingProgramComponentUndoData>> layerData;
2026-01-04 11:37:38 +03:00
void scale_up(const WorldScalar& scaleUpAmount);
2026-01-03 13:35:24 +03:00
};
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();
2025-12-30 21:18:59 +03:00
void set_to_erase();
2025-12-26 10:10:19 +03:00
void set_component_list_callbacks(DrawingProgramLayerManager &layerMan);
2025-12-25 17:18:28 +03:00
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<CanvasComponentContainer::ObjInfo*>& objList) const;
2025-12-29 19:57:36 +03:00
void get_flattened_layer_list(std::vector<DrawingProgramLayerListItem*>& objList);
2025-12-31 16:30:56 +03:00
void scale_up(const WorldScalar& scaleUpAmount);
2026-01-01 23:28:26 +03:00
void get_used_resources(std::unordered_set<NetworkingObjects::NetObjID>& resourceSet) const;
void set_alpha(DrawingProgramLayerManager& layerMan, float newAlpha) const;
float get_alpha() const;
2026-01-01 22:46:02 +03:00
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;
2025-12-25 19:37:41 +03:00
void set_blend_mode(DrawingProgramLayerManager& layerMan, SerializedBlendMode newBlendMode) const;
2025-12-25 19:37:41 +03:00
SerializedBlendMode get_blend_mode() const;
2026-01-04 11:37:38 +03:00
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<DrawingProgramLayerListItem>& o, cereal::PortableBinaryOutputArchive& a);
static void read_constructor_func(const NetworkingObjects::NetObjTemporaryPtr<DrawingProgramLayerListItem>& o, cereal::PortableBinaryInputArchive& a, const std::shared_ptr<NetServer::ClientData>& c);
std::unique_ptr<DrawingProgramLayerFolder> folderData;
std::unique_ptr<DrawingProgramLayer> layerData;
struct NameData {
std::string name;
template <typename Archive> void serialize(Archive& a) {
a(name);
}
};
struct DisplayData {
float alpha = 1.0f;
bool visible = true;
2026-01-08 19:44:42 +03:00
SerializedBlendMode blendMode = SerializedBlendMode::BLEND_SRC_OVER;
template <typename Archive> void serialize(Archive& a) {
2025-12-25 19:37:41 +03:00
a(alpha, visible, blendMode);
}
};
NetworkingObjects::NetObjOwnerPtr<NameData> nameData;
NetworkingObjects::NetObjOwnerPtr<DisplayData> displayData;
};