/*
* 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 .
*/
#pragma once
#include "../DrawData.hpp"
#include "DrawingProgramCache.hpp"
#include "ToolConfiguration.hpp"
#include "Tools/GridModifyTool.hpp"
#include
#include "Tools/PanCanvasTool.hpp"
#include "Tools/ZoomCanvasTool.hpp"
#include "cereal/archives/portable_binary.hpp"
#include
#include
#include
#include
#include
#include
#include "Tools/DrawingProgramToolBase.hpp"
#include
#include
#include "Layers/DrawingProgramLayerManager.hpp"
#include "DrawingProgramSelection.hpp"
class World;
class PhoneDrawingProgramScreen;
class DrawingProgram {
public:
DrawingProgram(World& initWorld);
void server_init_no_file();
void toolbar_gui(Toolbar& t);
void tool_options_gui(Toolbar& t);
void right_click_popup_gui(Toolbar& t);
void update();
void scale_up(const WorldScalar& scaleUpAmount);
void draw(SkCanvas* canvas, const DrawData& drawData);
void write_components_server(cereal::PortableBinaryOutputArchive& a);
void read_components_client(cereal::PortableBinaryInputArchive& a);
void init_server_callbacks();
void init_client_callbacks();
void add_file_to_canvas_by_path(const std::filesystem::path& filePath, Vector2f dropPos);
CanvasComponentContainer::ObjInfo* add_file_to_canvas_by_data(const std::string& fileName, std::string_view fileBuffer, Vector2f dropPos);
void get_used_resources(std::unordered_set& resourceSet);
Vector4f* color_picker_color(Vector4f* oldColor);
bool phone_gui_tool_specific_bottom_toolbar_exists();
void phone_gui_tool_specific_bottom_toolbar(PhoneDrawingProgramScreen& t);
void load_file(cereal::PortableBinaryInputArchive& a, VersionNumber version);
void save_file(cereal::PortableBinaryOutputArchive& a) const;
World& world;
bool prevent_undo_or_redo();
DrawingProgramCache drawCache;
DrawingProgramLayerManager layerMan;
Vector4f* get_foreground_color_ptr();
void switch_to_tool(DrawingProgramToolType newToolType, bool force = false);
void switch_to_tool_ptr(std::unique_ptr newTool);
void modify_grid(const NetworkingObjects::NetObjWeakPtr& gridToModify);
void invalidate_cache_at_component(CanvasComponentContainer::ObjInfo* objToCheck);
void preupdate_component(CanvasComponentContainer::ObjInfo* objToCheck);
void send_transforms_for(const std::vector& objsToSendTransformsFor);
void on_tab_out();
void input_add_file_to_canvas_callback(const CustomEvents::AddFileToCanvasEvent& addFile);
void input_paste_callback(const CustomEvents::PasteEvent& paste);
void input_android_text_box_input_callback(const CustomEvents::AndroidTextBoxInputEvent& textboxInput);
void input_drop_text_callback(const InputManager::DropCallbackArgs& drop);
void input_drop_file_callback(const InputManager::DropCallbackArgs& drop);
void input_text_key_callback(const InputManager::KeyCallbackArgs& key);
void input_text_callback(const InputManager::TextCallbackArgs& text);
void input_key_callback(const InputManager::KeyCallbackArgs& key);
void input_mouse_button_callback(const InputManager::MouseButtonCallbackArgs& button);
void input_mouse_motion_callback(const InputManager::MouseMotionCallbackArgs& motion);
void input_pure_mouse_button_callback(const InputManager::MouseButtonCallbackArgs& button);
void input_pure_mouse_motion_callback(const InputManager::MouseMotionCallbackArgs& motion);
void input_pen_button_callback(const InputManager::PenButtonCallbackArgs& button);
void input_pen_touch_callback(const InputManager::PenTouchCallbackArgs& touch);
void input_pen_motion_callback(const InputManager::PenMotionCallbackArgs& motion);
void input_pen_axis_callback(const InputManager::PenAxisCallbackArgs& axis);
std::optional get_text_box_start_info();
void set_right_click_popup_location(const Vector2f& newLoc);
void clear_right_click_popup();
void paste_object_clipboard(const Vector2f& pos);
std::unique_ptr drawTool;
private:
void process_transform_message(const std::vector>& transforms);
void drag_drop_update();
void check_updateable_components();
void update_downloading_dropped_files();
void selection_action_menu(Vector2f popupPos);
void right_click_action_menu(Vector2f popupPos, const std::function& innerContent);
void popup_menu_action_button(const char* id, const char* text, const std::function& onClick);
void rebuild_cache();
float drag_point_radius();
void draw_drag_circle(SkCanvas* canvas, const Vector2f& pos, const SkColor4f& c, const DrawData& drawData, float radiusMultiplier = 1.0f);
std::pair select_tool_line_paint(const DrawData& drawData);
bool is_actual_selection_tool(DrawingProgramToolType typeToCheck);
bool is_selection_allowing_tool(DrawingProgramToolType typeToCheck);
DrawingProgramSelection selection;
std::unique_ptr toolToSwitchToAfterUpdate;
std::unordered_set updateableComponents;
void pen_tool_switch_check();
enum class TemporaryMoveToolSwitch {
NONE,
PAN,
ZOOM
};
bool temporaryEraser = false;
TemporaryMoveToolSwitch tempMoveToolSwitch = TemporaryMoveToolSwitch::NONE;
DrawingProgramToolType toolTypeAfterTempMove;
struct GlobalControls {
std::optional lockedCameraScale;
bool leftClickHeld = false;
bool middleClickHeld = false;
DrawingProgramLayerManager::LayerSelector layerSelector = DrawingProgramLayerManager::LayerSelector::LAYER_BEING_EDITED;
int colorEditing = 0;
} controls;
struct DroppedDownloadingFile {
CanvasComponentContainer::ObjInfo* comp;
Vector2f windowSizeWhenDropped;
std::shared_ptr downData;
};
std::vector droppedDownloadingFiles;
std::optional rightClickPopupLocation;
uint32_t nextID = 0;
friend class EyeDropperTool;
friend class RectDrawTool;
friend class EllipseDrawTool;
friend class LineDrawTool;
friend class BrushTool;
friend class EraserTool;
friend class RectSelectTool;
friend class TextBoxTool;
friend class ScreenshotTool;
friend class EditTool;
friend class ImageEditTool;
friend class RectDrawEditTool;
friend class EllipseDrawEditTool;
friend class TextBoxEditTool;
friend class DrawingProgramCache;
friend class DrawingProgramSelection;
friend class LassoSelectTool;
friend class FillTool;
friend class GridEditTool;
friend class GridModifyTool;
friend class ZoomCanvasTool;
friend class PanCanvasTool;
friend class DrawCamera;
friend class DrawingProgramLayerManager;
friend class DrawingProgramLayer;
friend class DrawingProgramLayerFolder;
friend class ToolConfiguration;
};