All checks were successful
Windows Release / windows-x86_64 (push) Successful in 1h12m54s
Session/person/layer defaults plus person×layer ACL (Allow/Deny/Inherit) for draw, move, delete, hide, and layer management; bump save format to 0.9.0-fork. Co-authored-by: Cursor <cursoragent@cursor.com>
138 lines
7 KiB
C++
138 lines
7 KiB
C++
/*
|
|
* 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>
|
|
#include <map>
|
|
#include <unordered_set>
|
|
#include "DrawingProgramLayerFolder.hpp"
|
|
#include "DrawingProgramLayer.hpp"
|
|
#include "SerializedBlendMode.hpp"
|
|
#include "../../CollabPermissions.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 playerLocked = false;
|
|
bool fogLayer = false;
|
|
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<std::vector<DrawingProgramLayerListItemUndoData>> folderData;
|
|
std::optional<std::vector<DrawingProgramComponentUndoData>> 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<CanvasComponentContainer::ObjInfo*>& objList) const;
|
|
void get_flattened_layer_list(std::vector<DrawingProgramLayerListItem*>& objList);
|
|
void scale_up(const WorldScalar& scaleUpAmount);
|
|
void get_used_resources(std::unordered_set<NetworkingObjects::NetObjID>& 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_player_locked(DrawingProgramLayerManager& layerMan, bool locked) const;
|
|
bool get_player_locked() const;
|
|
void set_fog_layer(DrawingProgramLayerManager& layerMan, bool fog) const;
|
|
bool is_fog_layer() const;
|
|
// Fog layers are always treated as player-locked for edit checks.
|
|
bool is_player_edit_blocked() const;
|
|
|
|
const CollabPermissionSet& get_layer_defaults() const;
|
|
void set_layer_defaults(DrawingProgramLayerManager& layerMan, const CollabPermissionSet& defaults) const;
|
|
const std::map<std::string, CollabPermissionSet>& get_person_layer_overrides() const;
|
|
void set_person_layer_override(DrawingProgramLayerManager& layerMan, const std::string& displayName, const CollabPermissionSet& overrides) const;
|
|
void clear_person_layer_override(DrawingProgramLayerManager& layerMan, const std::string& displayName) const;
|
|
/** Apply session new-layer defaults (call after create). */
|
|
void apply_new_layer_permission_defaults(DrawingProgramLayerManager& layerMan) const;
|
|
|
|
void set_metainfo(DrawingProgramLayerManager& layerMan, const DrawingProgramLayerListItemMetaInfo& metaInfo);
|
|
DrawingProgramLayerListItemMetaInfo get_metainfo() const;
|
|
|
|
uint32_t get_component_count() const;
|
|
|
|
void erase_invalid_components();
|
|
|
|
// Host→client join projection: same shape as write_constructor_func, omits hidden comps.
|
|
void write_stripped_constructor(cereal::PortableBinaryOutputArchive& a, const std::unordered_set<NetworkingObjects::NetObjID>& hiddenComponentIds) const;
|
|
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;
|
|
SerializedBlendMode blendMode = SerializedBlendMode::BLEND_SRC_OVER;
|
|
bool playerLocked = false;
|
|
bool fogLayer = false;
|
|
CollabPermissionSet layerDefaults = CollabPermissionSet::all_inherit();
|
|
std::map<std::string, CollabPermissionSet> personOverrides;
|
|
template <typename Archive> void serialize(Archive& a) {
|
|
a(alpha, visible, blendMode, playerLocked, fogLayer, layerDefaults, personOverrides);
|
|
}
|
|
void migrate_player_locked_into_defaults();
|
|
void sync_player_locked_from_defaults();
|
|
};
|
|
NetworkingObjects::NetObjOwnerPtr<NameData> nameData;
|
|
NetworkingObjects::NetObjOwnerPtr<DisplayData> displayData;
|
|
};
|