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-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>
|
|
|
|
|
#include "BrushTool.hpp"
|
|
|
|
|
#include "EraserTool.hpp"
|
|
|
|
|
#include "RectSelectTool.hpp"
|
|
|
|
|
#include "RectDrawTool.hpp"
|
|
|
|
|
#include "EllipseDrawTool.hpp"
|
|
|
|
|
#include "TextBoxTool.hpp"
|
|
|
|
|
#include "InkDropperTool.hpp"
|
|
|
|
|
#include "ScreenshotTool.hpp"
|
|
|
|
|
#include "EditTool.hpp"
|
|
|
|
|
#include "ImageTool.hpp"
|
|
|
|
|
#include "../CollabList.hpp"
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
void free_collider_memory();
|
|
|
|
|
void allocate_collider_memory();
|
|
|
|
|
|
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-06 20:43:53 +03:00
|
|
|
bool colliderAllocated = false;
|
|
|
|
|
|
2025-07-19 15:57:09 +03:00
|
|
|
DrawingProgramCache compCache;
|
|
|
|
|
|
|
|
|
|
typedef CollabList<std::shared_ptr<DrawComponent>, ServerClientID> CollabListType;
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
std::unordered_set<std::shared_ptr<DrawComponent>> delayedUpdateTransformComponents;
|
2025-07-20 15:24:44 +03:00
|
|
|
|
2025-07-06 20:43:53 +03:00
|
|
|
Vector4f* get_foreground_color_ptr();
|
|
|
|
|
private:
|
2025-07-21 13:57:48 +03:00
|
|
|
|
|
|
|
|
void check_delayed_update_transform_timers();
|
|
|
|
|
void check_updateable_components();
|
|
|
|
|
|
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 draw_cache(SkCanvas* canvas, const DrawData& drawData, const std::shared_ptr<DrawComponent>& lastComp);
|
|
|
|
|
|
|
|
|
|
void check_all_collisions_base(const SCollision::ColliderCollection<WorldScalar>& checkAgainstWorld, const SCollision::ColliderCollection<float>& checkAgainstCam);
|
|
|
|
|
void check_all_collisions(const SCollision::ColliderCollection<WorldScalar>& checkAgainst);
|
|
|
|
|
void check_all_collisions_transform(const SCollision::ColliderCollection<float>& checkAgainst);
|
|
|
|
|
|
|
|
|
|
void add_variable_width_line(SkPath& p, const DrawData& drawData, const WorldVec& p1, const WorldVec& p2, float w1, float w2);
|
|
|
|
|
void reset_selection();
|
|
|
|
|
void reset_tools();
|
|
|
|
|
|
|
|
|
|
void drag_drop_update();
|
|
|
|
|
|
|
|
|
|
void draw_drag_circle(SkCanvas* canvas, const Vector2f& pos, const SkColor4f& c, const DrawData& drawData, float radiusMultiplier = 1.0f);
|
|
|
|
|
|
|
|
|
|
void add_undo_place_component(uint64_t placement, const std::shared_ptr<DrawComponent>& comp);
|
|
|
|
|
void add_undo_place_components(uint64_t placement, const std::vector<std::shared_ptr<DrawComponent>>& comps);
|
|
|
|
|
|
2025-07-22 12:22:08 +03:00
|
|
|
uint64_t draw_components_to_canvas(SkCanvas* canvas, const DrawData& drawData, bool dontUseCache);
|
2025-07-19 15:57:09 +03:00
|
|
|
|
2025-07-06 20:43:53 +03:00
|
|
|
BrushTool brushTool;
|
|
|
|
|
EraserTool eraserTool;
|
|
|
|
|
RectSelectTool rectSelectTool;
|
|
|
|
|
RectDrawTool rectDrawTool;
|
|
|
|
|
EllipseDrawTool ellipseDrawTool;
|
|
|
|
|
TextBoxTool textBoxTool;
|
|
|
|
|
InkDropperTool inkDropperTool;
|
|
|
|
|
ScreenshotTool screenshotTool;
|
|
|
|
|
EditTool editTool;
|
|
|
|
|
ImageTool imageTool;
|
|
|
|
|
|
|
|
|
|
bool temporaryEraser = false;
|
|
|
|
|
|
|
|
|
|
enum Tool : int {
|
|
|
|
|
TOOL_BRUSH = 0,
|
|
|
|
|
TOOL_ERASER,
|
|
|
|
|
TOOL_RECTSELECT,
|
|
|
|
|
TOOL_RECTANGLE,
|
|
|
|
|
TOOL_ELLIPSE,
|
|
|
|
|
TOOL_TEXTBOX,
|
|
|
|
|
TOOL_INKDROPPER,
|
|
|
|
|
TOOL_SCREENSHOT,
|
|
|
|
|
TOOL_EDIT
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct GlobalControls {
|
|
|
|
|
float relativeWidth = 15.0f;
|
|
|
|
|
|
|
|
|
|
Vector4f foregroundColor{0.9f, 0.9f, 0.9f, 1.0f};
|
|
|
|
|
Vector4f backgroundColor{0.0f, 0.0f, 0.0f, 1.0f};
|
|
|
|
|
int previousSelected = 0;
|
|
|
|
|
WorldVec previousMouseWorldPos = {0, 0};
|
|
|
|
|
WorldVec currentMouseWorldPos = {0, 0};
|
|
|
|
|
int selectedTool = 0;
|
|
|
|
|
bool leftClick = false;
|
|
|
|
|
bool leftClickHeld = false;
|
|
|
|
|
bool leftClickReleased = false;
|
|
|
|
|
bool cursorHoveringOverCanvas = false;
|
|
|
|
|
|
|
|
|
|
int colorEditing = 0;
|
|
|
|
|
} controls;
|
|
|
|
|
|
|
|
|
|
uint32_t nextID = 0;
|
|
|
|
|
|
|
|
|
|
friend class InkDropperTool;
|
|
|
|
|
friend class RectDrawTool;
|
|
|
|
|
friend class EllipseDrawTool;
|
|
|
|
|
friend class BrushTool;
|
|
|
|
|
friend class EraserTool;
|
|
|
|
|
friend class RectSelectTool;
|
|
|
|
|
friend class TextBoxTool;
|
|
|
|
|
friend class ScreenshotTool;
|
|
|
|
|
friend class EditTool;
|
|
|
|
|
friend class ImageTool;
|
2025-07-20 15:24:44 +03:00
|
|
|
friend class DrawingProgramCache;
|
2025-07-06 20:43:53 +03:00
|
|
|
};
|