2025-07-06 20:43:53 +03:00
# pragma once
# include "../DrawData.hpp"
2025-07-19 15:57:09 +03:00
# include "DrawingProgramCache.hpp"
2025-09-18 18:02:11 +03:00
# include "GridModifyTool.hpp"
2025-09-28 15:00:19 +03:00
# include "PanCanvasTool.hpp"
2025-09-28 11:59:08 +03:00
# include "ZoomCanvasTool.hpp"
2025-07-06 20:43:53 +03:00
# include "cereal/archives/portable_binary.hpp"
# include <include/core/SkCanvas.h>
# include <include/core/SkPath.h>
# include <include/core/SkVertices.h>
# include <Helpers/SCollision.hpp>
# include <Helpers/Hashes.hpp>
# include <list>
# include <Helpers/Random.hpp>
2025-07-24 16:35:48 +03:00
# include "DrawingProgramSelection.hpp"
2025-07-06 20:43:53 +03:00
# include "../CollabList.hpp"
2025-08-02 20:10:33 +03:00
# include "DrawingProgramToolBase.hpp"
2025-07-06 20:43:53 +03:00
class World ;
# define DRAG_POINT_RADIUS 10.0f
class DrawingProgram {
public :
DrawingProgram ( World & initWorld ) ;
void init_client_callbacks ( ) ;
void toolbar_gui ( ) ;
void tool_options_gui ( ) ;
void update ( ) ;
void draw ( SkCanvas * canvas , const DrawData & drawData ) ;
void initialize_draw_data ( cereal : : PortableBinaryInputArchive & a ) ;
std : : unordered_set < ServerClientID > get_used_resources ( ) ;
ClientPortionID get_max_id ( ServerPortionID serverID ) ;
void write_to_file ( cereal : : PortableBinaryOutputArchive & a ) ;
World & world ;
2025-07-27 16:53:22 +03:00
bool prevent_undo_or_redo ( ) ;
2025-07-10 22:09:56 +03:00
void add_file_to_canvas_by_path ( const std : : string & filePath , Vector2f dropPos , bool addInSameThread ) ;
void add_file_to_canvas_by_data ( const std : : string & fileName , std : : string_view fileBuffer , Vector2f dropPos ) ;
2025-07-19 15:57:09 +03:00
void parallel_loop_all_components ( std : : function < void ( const std : : shared_ptr < CollabList < std : : shared_ptr < DrawComponent > , ServerClientID > : : ObjectInfo > & ) > func ) ;
2025-07-31 19:28:18 +03:00
// This function, unlike preupdate_component, does not take the object out of the BVH. Use for a draw update that doesn't change the object's bounding box
void invalidate_cache_at_component ( const CollabListType : : ObjectInfoPtr & objToCheck ) ;
void preupdate_component ( const CollabListType : : ObjectInfoPtr & objToCheck ) ;
2025-07-19 15:57:09 +03:00
DrawingProgramCache compCache ;
CollabListType components ;
2025-07-06 20:43:53 +03:00
2025-07-21 13:57:48 +03:00
std : : unordered_set < std : : shared_ptr < DrawComponent > > updateableComponents ;
2025-07-31 09:34:17 +03:00
std : : unordered_map < std : : shared_ptr < DrawComponent > , std : : shared_ptr < DrawComponent > > delayedUpdateComponents ;
2025-07-20 15:24:44 +03:00
2025-07-06 20:43:53 +03:00
Vector4f * get_foreground_color_ptr ( ) ;
2025-08-02 20:39:21 +03:00
void switch_to_tool ( DrawingProgramToolType newToolType ) ;
2025-08-02 21:14:57 +03:00
void switch_to_tool_ptr ( std : : unique_ptr < DrawingProgramToolBase > newTool ) ;
2025-08-18 08:16:29 +03:00
void clear_draw_cache ( ) ;
2025-09-10 15:03:06 +03:00
2025-09-24 13:32:50 +03:00
void modify_grid ( ServerClientID gridToModifyID ) ;
2025-09-28 11:59:08 +03:00
2025-07-06 20:43:53 +03:00
private :
2025-08-26 12:03:09 +03:00
std : : optional < std : : chrono : : steady_clock : : time_point > badFrametimeTimePoint ;
std : : optional < std : : chrono : : steady_clock : : time_point > unorderedObjectsExistTimePoint ;
2025-07-27 20:04:26 +03:00
void client_erase_set ( std : : unordered_set < CollabListType : : ObjectInfoPtr > erasedComponents ) ; // The set might be modified while this is being called, so dont pass by reference
2025-07-21 13:57:48 +03:00
2025-07-26 21:20:14 +03:00
void check_delayed_update_timers ( ) ;
2025-07-21 13:57:48 +03:00
void check_updateable_components ( ) ;
2025-07-26 21:20:14 +03:00
void force_rebuild_cache ( ) ;
2025-07-28 11:09:59 +03:00
bool addToCompCacheOnInsert = true ;
2025-07-10 22:09:56 +03:00
std : : atomic < bool > addFileInNextFrame = false ;
std : : pair < std : : string , Vector2f > addFileInfo ;
void add_file_to_canvas_by_path_execute ( const std : : string & filePath , Vector2f dropPos ) ;
2025-07-06 20:43:53 +03:00
void drag_drop_update ( ) ;
void draw_drag_circle ( SkCanvas * canvas , const Vector2f & pos , const SkColor4f & c , const DrawData & drawData , float radiusMultiplier = 1.0f ) ;
2025-07-27 16:30:45 +03:00
void add_undo_place_component ( const CollabListType : : ObjectInfoPtr & objToUndo ) ;
2025-07-28 11:09:59 +03:00
void add_undo_place_components ( const std : : unordered_set < CollabListType : : ObjectInfoPtr > & objSetToUndo ) ;
2025-07-27 20:04:26 +03:00
void add_undo_erase_components ( const std : : unordered_set < CollabListType : : ObjectInfoPtr > & objSetToUndo ) ;
2025-07-06 20:43:53 +03:00
2025-08-02 12:31:16 +03:00
SkPaint select_tool_line_paint ( ) ;
2025-07-24 16:35:48 +03:00
DrawingProgramSelection selection ;
2025-07-06 20:43:53 +03:00
bool temporaryEraser = false ;
2025-09-28 18:25:46 +03:00
bool temporaryPan = false ;
DrawingProgramToolType toolTypeAfterTempPan ;
2025-07-06 20:43:53 +03:00
struct GlobalControls {
float relativeWidth = 15.0f ;
2025-08-07 17:45:10 +03:00
Vector4f foregroundColor { 1.0f , 1.0f , 1.0f , 1.0f } ;
2025-07-06 20:43:53 +03:00
Vector4f backgroundColor { 0.0f , 0.0f , 0.0f , 1.0f } ;
WorldVec previousMouseWorldPos = { 0 , 0 } ;
WorldVec currentMouseWorldPos = { 0 , 0 } ;
bool leftClick = false ;
bool leftClickHeld = false ;
bool leftClickReleased = false ;
2025-09-28 11:59:08 +03:00
bool middleClick = false ;
bool middleClickHeld = false ;
bool middleClickReleased = false ;
2025-07-06 20:43:53 +03:00
bool cursorHoveringOverCanvas = false ;
int colorEditing = 0 ;
} controls ;
2025-09-28 11:59:08 +03:00
std : : unique_ptr < DrawingProgramToolBase > drawTool ;
2025-07-06 20:43:53 +03:00
uint32_t nextID = 0 ;
2025-08-05 12:11:50 +03:00
friend class EyeDropperTool ;
2025-07-06 20:43:53 +03:00
friend class RectDrawTool ;
friend class EllipseDrawTool ;
friend class BrushTool ;
friend class EraserTool ;
friend class RectSelectTool ;
friend class TextBoxTool ;
friend class ScreenshotTool ;
friend class EditTool ;
2025-08-02 20:10:33 +03:00
friend class ImageEditTool ;
friend class RectDrawEditTool ;
friend class EllipseDrawEditTool ;
friend class TextBoxEditTool ;
2025-07-20 15:24:44 +03:00
friend class DrawingProgramCache ;
2025-07-24 19:35:51 +03:00
friend class DrawingProgramSelection ;
2025-08-02 12:31:16 +03:00
friend class LassoSelectTool ;
2025-09-10 15:03:06 +03:00
friend class GridEditTool ;
2025-09-18 18:02:11 +03:00
friend class GridModifyTool ;
2025-09-28 11:59:08 +03:00
friend class ZoomCanvasTool ;
2025-09-28 15:00:19 +03:00
friend class PanCanvasTool ;
2025-09-28 11:59:08 +03:00
friend class DrawCamera ;
2025-07-06 20:43:53 +03:00
} ;