infinipaint/src/MainProgram.hpp

152 lines
5.2 KiB
C++
Raw Normal View History

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>
#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"
#include "DrawingProgram/ToolConfiguration.hpp"
#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 {
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;
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
sk_sp<SkSurface> intermediateSurface;
SkCanvas* intermediateCanvas;
2025-07-06 20:43:53 +03:00
SDL_Window* sdlWindow;
bool canCreateSurfaces = false;
2025-07-06 20:43:53 +03:00
} window;
2025-12-29 19:57:36 +03:00
struct Clipboard {
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;
ToolConfiguration toolConfig;
2025-07-06 20:43:53 +03:00
std::ofstream* logFile;
std::deque<Toolbar::LogMessage> logMessages;
std::string newAddr;
MainProgram();
void update();
void draw(SkCanvas* canvas, std::shared_ptr<World> worldToDraw, const DrawData& drawData);
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();
void init_net_library();
2025-11-20 12:38:28 +03:00
void set_vsync_value(int vsyncValue);
void update_scale_and_density();
float get_scale_and_density_factor_gui();
2026-01-18 13:39:49 +03:00
bool app_close_requested();
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;
GlobalConfig conf;
2025-07-06 20:43:53 +03:00
void input_drop_file_callback(const InputManager::DropCallbackArgs& drop);
void input_drop_text_callback(const InputManager::DropCallbackArgs& drop);
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();
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);
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);
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);
};