2025-07-06 20:43:53 +03:00
|
|
|
#pragma once
|
|
|
|
|
#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>
|
|
|
|
|
#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"
|
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;
|
|
|
|
|
|
|
|
|
|
class MainProgram {
|
|
|
|
|
public:
|
|
|
|
|
static constexpr size_t LOG_SIZE = 30;
|
|
|
|
|
|
|
|
|
|
InputManager input;
|
|
|
|
|
|
|
|
|
|
std::chrono::steady_clock::time_point lastFrameTime = std::chrono::steady_clock::now();
|
|
|
|
|
|
|
|
|
|
Vector3f userColor;
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
sk_sp<SkSurface> intermediateSurface;
|
|
|
|
|
SkCanvas* intermediateCanvas;
|
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;
|
|
|
|
|
Toolbar toolbar;
|
2026-03-31 13:33:15 +03:00
|
|
|
GUIHolder g;
|
2025-07-06 20:43:53 +03:00
|
|
|
std::shared_ptr<World> world;
|
2026-01-26 19:08:36 +03:00
|
|
|
ToolConfiguration toolConfig;
|
2025-07-06 20:43:53 +03:00
|
|
|
|
|
|
|
|
std::ofstream* logFile;
|
|
|
|
|
std::deque<Toolbar::LogMessage> logMessages;
|
|
|
|
|
|
|
|
|
|
std::string newAddr;
|
|
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
|
|
|
|
|
void new_tab(const World::OpenWorldInfo& tabInfo, bool createSameThread = false);
|
2026-01-18 13:39:49 +03:00
|
|
|
void set_tab_to_close(const std::weak_ptr<World>& tabToClose);
|
2025-07-06 20:43:53 +03:00
|
|
|
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();
|
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;
|
|
|
|
|
std::filesystem::path configPath;
|
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;
|
|
|
|
|
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-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-02 10:15:22 +03:00
|
|
|
void input_text_key_callback();
|
|
|
|
|
void input_text_input_callback();
|
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-03-02 16:36:34 +03:00
|
|
|
|
2025-07-06 20:43:53 +03:00
|
|
|
~MainProgram();
|
|
|
|
|
private:
|
|
|
|
|
void new_tab_open();
|
|
|
|
|
std::atomic<bool> tabSetToOpen = false;
|
|
|
|
|
World::OpenWorldInfo newTabToOpenInfo;
|
|
|
|
|
|
2026-01-18 13:39:49 +03:00
|
|
|
std::vector<std::weak_ptr<World>> setTabsToClose;
|
2025-07-06 20:43:53 +03:00
|
|
|
|
|
|
|
|
std::string gen_random_display_name();
|
|
|
|
|
|
|
|
|
|
void gui();
|
|
|
|
|
void draw_grid(SkCanvas* canvas);
|
|
|
|
|
};
|