2025-07-06 20:43:53 +03:00
|
|
|
#pragma once
|
2026-04-04 17:52:43 +03:00
|
|
|
#include "CustomEvents.hpp"
|
2025-07-06 20:43:53 +03:00
|
|
|
#include "DrawData.hpp"
|
2025-11-20 12:38:28 +03:00
|
|
|
#include <SDL3/SDL_render.h>
|
2025-08-26 12:03:09 +03:00
|
|
|
#include <chrono>
|
2025-07-06 20:43:53 +03:00
|
|
|
#include <include/core/SkCanvas.h>
|
2026-04-02 19:18:39 +03:00
|
|
|
#include "Helpers/Hashes.hpp"
|
2025-07-06 20:43:53 +03:00
|
|
|
#include "InputManager.hpp"
|
|
|
|
|
#include "FontData.hpp"
|
|
|
|
|
#include "TimePoint.hpp"
|
|
|
|
|
#include "SharedTypes.hpp"
|
|
|
|
|
#include <Eigen/Dense>
|
|
|
|
|
#include <include/core/SkSurfaceProps.h>
|
|
|
|
|
#include "Toolbar.hpp"
|
|
|
|
|
#include "World.hpp"
|
2026-01-26 19:08:36 +03:00
|
|
|
#include "DrawingProgram/ToolConfiguration.hpp"
|
2026-03-31 13:17:58 +03:00
|
|
|
#include "GUIHolder.hpp"
|
|
|
|
|
#include "GlobalConfig.hpp"
|
2026-04-12 12:36:00 +03:00
|
|
|
#include "Screens/Screen.hpp"
|
2025-07-06 20:43:53 +03:00
|
|
|
|
|
|
|
|
#ifdef USE_SKIA_BACKEND_GRAPHITE
|
|
|
|
|
#include "include/gpu/graphite/Recorder.h"
|
|
|
|
|
#elif USE_SKIA_BACKEND_GANESH
|
|
|
|
|
#include "include/gpu/ganesh/GrDirectContext.h"
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
using namespace Eigen;
|
|
|
|
|
|
2026-04-12 12:36:00 +03:00
|
|
|
struct UserLogMessage {
|
|
|
|
|
static constexpr float DISPLAY_TIME = 8.0f;
|
|
|
|
|
static constexpr float FADE_START_TIME = 7.0f;
|
|
|
|
|
std::string text;
|
|
|
|
|
enum {
|
|
|
|
|
COLOR_NORMAL = 0,
|
|
|
|
|
COLOR_ERROR
|
|
|
|
|
} color;
|
|
|
|
|
TimePoint time;
|
|
|
|
|
};
|
|
|
|
|
|
2025-07-06 20:43:53 +03:00
|
|
|
class MainProgram {
|
|
|
|
|
public:
|
|
|
|
|
static constexpr size_t LOG_SIZE = 30;
|
|
|
|
|
|
|
|
|
|
InputManager input;
|
|
|
|
|
|
|
|
|
|
struct Window {
|
2025-08-26 12:03:09 +03:00
|
|
|
std::chrono::steady_clock::duration lastFrameTime = std::chrono::milliseconds(16);
|
2025-07-06 20:43:53 +03:00
|
|
|
Vector2i size = {-1, -1};
|
|
|
|
|
Vector2i pos = {-1, -1};
|
|
|
|
|
Vector2i writtenSize = {-1, -1};
|
|
|
|
|
Vector2i writtenPos = {-1, -1};
|
|
|
|
|
bool maximized = false;
|
|
|
|
|
bool fullscreen = false;
|
|
|
|
|
SkColorType defaultColorType;
|
|
|
|
|
SkAlphaType defaultAlphaType;
|
|
|
|
|
|
2025-11-23 12:53:50 +03:00
|
|
|
float density = 1.0f;
|
2025-07-06 20:43:53 +03:00
|
|
|
float scale = 1.0f;
|
2026-02-08 19:07:55 +03:00
|
|
|
|
2025-07-06 20:43:53 +03:00
|
|
|
int defaultMSAASampleCount = 0;
|
|
|
|
|
SkSurfaceProps defaultMSAASurfaceProps;
|
|
|
|
|
|
|
|
|
|
#ifdef USE_SKIA_BACKEND_GRAPHITE
|
|
|
|
|
std::function<skgpu::graphite::Recorder*()> recorder;
|
|
|
|
|
#elif USE_SKIA_BACKEND_GANESH
|
|
|
|
|
sk_sp<GrDirectContext> ctx;
|
|
|
|
|
#endif
|
2026-03-20 20:53:59 +03:00
|
|
|
|
2026-04-09 01:05:52 +03:00
|
|
|
sk_sp<SkSurface> nativeSurface;
|
|
|
|
|
sk_sp<SkSurface> intermediateSurfaceMSAA;
|
2025-07-06 20:43:53 +03:00
|
|
|
|
|
|
|
|
SDL_Window* sdlWindow;
|
2026-03-20 20:53:59 +03:00
|
|
|
bool canCreateSurfaces = false;
|
2025-07-06 20:43:53 +03:00
|
|
|
} window;
|
|
|
|
|
|
2025-12-29 19:57:36 +03:00
|
|
|
struct Clipboard {
|
2026-01-03 19:05:00 +03:00
|
|
|
std::vector<std::unique_ptr<CanvasComponentContainer::CopyData>> components;
|
2025-12-29 19:57:36 +03:00
|
|
|
std::unordered_map<NetworkingObjects::NetObjID, ResourceData> resources;
|
|
|
|
|
WorldVec pos;
|
|
|
|
|
WorldScalar inverseScale;
|
|
|
|
|
} clipboard;
|
|
|
|
|
|
2025-11-16 10:42:01 +03:00
|
|
|
std::shared_ptr<FontData> fonts;
|
2025-07-06 20:43:53 +03:00
|
|
|
TimePoint deltaTime;
|
2026-03-31 13:33:15 +03:00
|
|
|
GUIHolder g;
|
2026-01-26 19:08:36 +03:00
|
|
|
ToolConfiguration toolConfig;
|
2025-07-06 20:43:53 +03:00
|
|
|
|
|
|
|
|
std::ofstream* logFile;
|
2026-04-12 12:36:00 +03:00
|
|
|
std::deque<UserLogMessage> logMessages;
|
|
|
|
|
|
|
|
|
|
std::unique_ptr<Screen> screen;
|
2025-07-06 20:43:53 +03:00
|
|
|
|
|
|
|
|
MainProgram();
|
|
|
|
|
void update();
|
2026-02-25 13:26:35 +03:00
|
|
|
void draw(SkCanvas* canvas, std::shared_ptr<World> worldToDraw, const DrawData& drawData);
|
2026-02-16 21:27:42 +03:00
|
|
|
sk_sp<SkSurface> create_native_surface(Vector2i resolution, bool isMSAA);
|
2025-07-06 20:43:53 +03:00
|
|
|
|
|
|
|
|
bool setToQuit = false;
|
|
|
|
|
|
|
|
|
|
void early_destroy();
|
|
|
|
|
|
|
|
|
|
bool network_being_used();
|
|
|
|
|
bool net_server_hosted();
|
2025-07-08 12:18:55 +03:00
|
|
|
void update_display_names();
|
2025-07-06 20:43:53 +03:00
|
|
|
|
|
|
|
|
void save_config();
|
|
|
|
|
void load_config();
|
|
|
|
|
|
2025-10-27 20:19:47 +03:00
|
|
|
void init_net_library();
|
2025-11-20 12:38:28 +03:00
|
|
|
void set_vsync_value(int vsyncValue);
|
2025-11-23 12:53:50 +03:00
|
|
|
void update_scale_and_density();
|
|
|
|
|
float get_scale_and_density_factor_gui();
|
2026-01-18 13:39:49 +03:00
|
|
|
bool app_close_requested();
|
2026-04-07 20:33:48 +03:00
|
|
|
void toggle_full_screen();
|
2025-10-27 20:19:47 +03:00
|
|
|
|
2026-03-20 20:53:59 +03:00
|
|
|
void refresh_draw_surfaces();
|
|
|
|
|
|
2025-07-06 20:43:53 +03:00
|
|
|
std::filesystem::path homePath;
|
2026-01-18 13:39:49 +03:00
|
|
|
std::filesystem::path documentsPath;
|
2025-07-06 20:43:53 +03:00
|
|
|
|
|
|
|
|
bool drawGui = true;
|
|
|
|
|
|
|
|
|
|
size_t worldIndex = 0;
|
2026-04-05 20:26:03 +03:00
|
|
|
std::shared_ptr<World> world;
|
2025-07-06 20:43:53 +03:00
|
|
|
std::vector<std::shared_ptr<World>> worlds;
|
|
|
|
|
|
2026-03-31 13:17:58 +03:00
|
|
|
GlobalConfig conf;
|
2025-07-06 20:43:53 +03:00
|
|
|
|
2026-04-02 19:18:39 +03:00
|
|
|
std::optional<unsigned> keybindWaiting;
|
2026-04-11 16:36:24 +03:00
|
|
|
void input_add_file_to_canvas_callback(const CustomEvents::AddFileToCanvasEvent& addFile);
|
|
|
|
|
void input_open_infinipaint_file_callback(const CustomEvents::OpenInfiniPaintFileEvent& openFile);
|
|
|
|
|
void input_paste_callback(const CustomEvents::PasteEvent& paste);
|
|
|
|
|
|
2026-04-02 19:18:39 +03:00
|
|
|
bool input_keybind_callback(const Vector2ui32& newKey);
|
2026-03-04 11:03:05 +03:00
|
|
|
void input_drop_file_callback(const InputManager::DropCallbackArgs& drop);
|
|
|
|
|
void input_drop_text_callback(const InputManager::DropCallbackArgs& drop);
|
2026-03-02 16:36:34 +03:00
|
|
|
void input_key_callback(const InputManager::KeyCallbackArgs& key);
|
2026-04-03 23:02:33 +03:00
|
|
|
void input_text_key_callback(const InputManager::KeyCallbackArgs& key);
|
2026-04-04 17:52:43 +03:00
|
|
|
void input_text_callback(const InputManager::TextCallbackArgs& text);
|
2026-03-02 16:36:34 +03:00
|
|
|
void input_mouse_button_callback(const InputManager::MouseButtonCallbackArgs& button);
|
|
|
|
|
void input_mouse_motion_callback(const InputManager::MouseMotionCallbackArgs& motion);
|
2026-03-02 23:09:48 +03:00
|
|
|
void input_mouse_wheel_callback(const InputManager::MouseWheelCallbackArgs& wheel);
|
2026-03-03 14:59:18 +03:00
|
|
|
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);
|
2026-03-03 16:01:21 +03:00
|
|
|
void input_pen_axis_callback(const InputManager::PenAxisCallbackArgs& axis);
|
2026-03-05 21:09:30 +03:00
|
|
|
void input_multi_finger_touch_callback(const InputManager::MultiFingerTouchCallbackArgs& touch);
|
|
|
|
|
void input_multi_finger_motion_callback(const InputManager::MultiFingerMotionCallbackArgs& motion);
|
|
|
|
|
void input_finger_touch_callback(const InputManager::FingerTouchCallbackArgs& touch);
|
|
|
|
|
void input_finger_motion_callback(const InputManager::FingerMotionCallbackArgs& motion);
|
2026-04-07 20:21:41 +03:00
|
|
|
void input_window_resize_callback(const InputManager::WindowResizeCallbackArgs& w);
|
|
|
|
|
void input_window_scale_callback(const InputManager::WindowScaleCallbackArgs& w);
|
2026-03-02 16:36:34 +03:00
|
|
|
|
2026-04-11 16:36:24 +03:00
|
|
|
void create_new_tab(const CustomEvents::OpenInfiniPaintFileEvent& openFile);
|
2026-04-05 20:26:03 +03:00
|
|
|
void set_tab_to_close(World* world);
|
|
|
|
|
void switch_to_tab(size_t wIndex);
|
|
|
|
|
|
2025-07-06 20:43:53 +03:00
|
|
|
~MainProgram();
|
|
|
|
|
private:
|
2026-04-05 20:26:03 +03:00
|
|
|
std::unordered_set<World*> tabsToClose;
|
|
|
|
|
void close_set_to_close_tabs();
|
|
|
|
|
void post_callback();
|
2025-07-06 20:43:53 +03:00
|
|
|
|
|
|
|
|
std::string gen_random_display_name();
|
|
|
|
|
|
|
|
|
|
void gui();
|
|
|
|
|
void draw_grid(SkCanvas* canvas);
|
|
|
|
|
};
|