infinipaint/src/MainProgram.hpp

125 lines
3.4 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"
#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();
float fpsLimit = 10000.0f;
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;
2025-11-20 12:38:28 +03:00
int vsyncValue = 1;
2025-07-06 20:43:53 +03:00
float scale = 1.0f;
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> surface;
SDL_Window* sdlWindow;
} window;
struct Clipboard {
std::vector<std::shared_ptr<DrawComponent>> components;
std::unordered_map<ServerClientID, ResourceData> resources;
WorldVec pos;
2025-10-04 09:10:09 +03:00
WorldScalar inverseScale;
2025-07-06 20:43:53 +03:00
} 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;
std::shared_ptr<World> world;
std::ofstream* logFile;
std::deque<Toolbar::LogMessage> logMessages;
std::string newAddr;
MainProgram();
void update();
void draw(SkCanvas* canvas);
bool setToQuit = false;
void early_destroy();
void new_tab(const World::OpenWorldInfo& tabInfo, bool createSameThread = false);
void set_tab_to_close(size_t tabToClose);
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);
2025-07-06 20:43:53 +03:00
std::filesystem::path homePath;
std::filesystem::path configPath;
bool drawGui = true;
bool takingScreenshot = false;
bool transparentBackground = false;
Vector3f defaultCanvasBackgroundColor = DEFAULT_CANVAS_BACKGROUND_COLOR;
2025-07-06 20:43:53 +03:00
size_t worldIndex = 0;
std::vector<std::shared_ptr<World>> worlds;
std::string displayName;
~MainProgram();
private:
void new_tab_open();
std::atomic<bool> tabSetToOpen = false;
World::OpenWorldInfo newTabToOpenInfo;
std::optional<size_t> setTabToClose;
std::string gen_random_display_name();
void gui();
void draw_grid(SkCanvas* canvas);
};