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-24 12:42:27 +03:00
# 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>
2025-12-24 12:42:27 +03:00
# include "DrawingProgramLayerFolder.hpp"
# include "DrawingProgramLayer.hpp"
2025-12-25 19:37:41 +03:00
# include "SerializedBlendMode.hpp"
2025-12-26 19:52:36 +03:00
# include "../../CanvasComponents/CanvasComponentContainer.hpp"
2025-12-24 12:42:27 +03:00
class DrawingProgramLayerFolder ;
class DrawingProgramLayer ;
class World ;
2025-12-26 10:10:19 +03:00
class DrawingProgramLayerManager ;
2025-12-24 12:42:27 +03:00
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-10-25 18:07:47 +01:00
bool playerLocked = false ;
bool fogLayer = false ;
2026-01-04 11:37:38 +03:00
bool operator = = ( const DrawingProgramLayerListItemMetaInfo & ) const = default ;
2026-01-03 13:35:24 +03:00
} ;
2026-01-03 19:05:00 +03:00
struct DrawingProgramLayerListItemUndoData {
WorldUndoManager : : UndoObjectID undoID ;
2026-01-04 16:50:47 +03:00
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 ;
2026-01-03 19:05:00 +03:00
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
} ;
2025-12-24 12:42:27 +03:00
class DrawingProgramLayerListItem {
public :
DrawingProgramLayerListItem ( ) ;
DrawingProgramLayerListItem ( NetworkingObjects : : NetObjManager & netObjMan , const std : : string & initName , bool isFolder ) ;
2026-01-03 19:05:00 +03:00
DrawingProgramLayerListItem ( World & w , const DrawingProgramLayerListItemUndoData & undoData ) ;
DrawingProgramLayerListItemUndoData get_undo_data ( WorldUndoManager & u ) const ;
2025-12-24 12:42:27 +03:00
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 ;
2025-12-24 12:42:27 +03:00
void set_name ( NetworkingObjects : : DelayUpdateSerializedClassManager & delayedNetObjMan , const std : : string & newName ) const ;
const std : : string & get_name ( ) const ;
2025-12-30 19:46:08 +03:00
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 ;
2025-12-24 12:42:27 +03:00
2025-12-28 17:34:33 +03:00
void set_alpha ( DrawingProgramLayerManager & layerMan , float newAlpha ) const ;
2025-12-24 12:42:27 +03:00
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 ;
2025-12-28 17:34:33 +03:00
void set_visible ( DrawingProgramLayerManager & layerMan , bool newVisible ) const ;
2025-12-24 12:42:27 +03:00
bool get_visible ( ) const ;
2025-12-25 19:37:41 +03:00
2025-12-28 17:34:33 +03:00
void set_blend_mode ( DrawingProgramLayerManager & layerMan , SerializedBlendMode newBlendMode ) const ;
2025-12-25 19:37:41 +03:00
SerializedBlendMode get_blend_mode ( ) const ;
2025-12-29 20:11:24 +03:00
2026-10-25 18:07:47 +01:00
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 ;
2026-01-04 11:37:38 +03:00
void set_metainfo ( DrawingProgramLayerManager & layerMan , const DrawingProgramLayerListItemMetaInfo & metaInfo ) ;
DrawingProgramLayerListItemMetaInfo get_metainfo ( ) const ;
2025-12-29 20:11:24 +03:00
uint32_t get_component_count ( ) const ;
2026-04-03 14:18:04 +03:00
void erase_invalid_components ( ) ;
2026-10-25 18:07:47 +01:00
// 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 ;
2025-12-24 12:42:27 +03:00
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 ;
2026-10-25 18:07:47 +01:00
bool playerLocked = false ;
bool fogLayer = false ;
2025-12-24 12:42:27 +03:00
template < typename Archive > void serialize ( Archive & a ) {
2026-10-25 18:07:47 +01:00
a ( alpha , visible , blendMode , playerLocked , fogLayer ) ;
2025-12-24 12:42:27 +03:00
}
} ;
NetworkingObjects : : NetObjOwnerPtr < NameData > nameData ;
NetworkingObjects : : NetObjOwnerPtr < DisplayData > displayData ;
} ;