infinipaint/src/Toolbar.hpp

243 lines
7.8 KiB
C++
Raw Normal View History

2025-07-06 20:43:53 +03:00
#pragma once
#include "GUIStuff/GUIManager.hpp"
#include "DrawData.hpp"
2025-10-01 20:08:01 +03:00
#include "Helpers/FileDownloader.hpp"
2025-07-06 20:43:53 +03:00
#include "Server/CommandList.hpp"
#include <filesystem>
2025-10-16 09:38:58 +03:00
#include <modules/skparagraph/include/Paragraph.h>
2025-07-06 20:43:53 +03:00
#include <nlohmann/json.hpp>
#include <Helpers/Serializers.hpp>
#include <SDL3/SDL_dialog.h>
#include <Helpers/VersionNumber.hpp>
2025-07-06 20:43:53 +03:00
class MainProgram;
class Toolbar {
public:
struct LogMessage {
std::string text;
enum {
COLOR_NORMAL = 0,
COLOR_ERROR
} color;
TimePoint time;
};
struct ChatMessage {
2025-10-16 09:38:58 +03:00
std::string name;
std::string message;
enum Type {
NORMAL = 0,
JOIN
} type;
2025-07-06 20:43:53 +03:00
TimePoint time;
};
struct ExtensionFilter {
std::string name;
std::string extensions;
};
std::string chatMessageInput;
Toolbar(MainProgram& initMain);
2025-10-14 11:27:55 +03:00
void initialize_io_before_update();
2025-07-06 20:43:53 +03:00
void update();
void draw(SkCanvas* canvas);
void color_selector_left(Vector4f* color);
void color_selector_right(Vector4f* color);
2025-12-01 17:33:14 +03:00
void paint_popup(Vector2f popupPos);
2025-07-06 20:43:53 +03:00
typedef std::function<void(const std::filesystem::path&, const ExtensionFilter& extensionSelected)> OpenFileSelectorCallback;
void open_file_selector(const std::string& filePickerName, const std::vector<ExtensionFilter>& extensionFilters, OpenFileSelectorCallback postSelectionFunc, const std::string& fileName = "", bool isSaving = false);
void save_func();
void save_as_func();
std::filesystem::path& file_selector_path();
std::shared_ptr<GUIStuff::UpdateInputData> io;
GUIStuff::GUIManager gui;
nlohmann::json get_config_json();
void set_config_json(const nlohmann::json& j, VersionNumber version);
2025-07-06 20:43:53 +03:00
void save_palettes();
void load_palettes();
void save_theme();
bool load_theme();
void load_licenses();
double dragZoomSpeed = 0.02;
double scrollZoomSpeed = 0.4;
float jumpTransitionTime = 0.5f;
Vector4f jumpTransitionEasing{0.75, 0.25, 0.25, 0.75};
bool viewWebVersionWelcome = false;
struct TabletOptions {
bool pressureAffectsBrushWidth = true;
float smoothingSamplingTime = 0.04f;
uint8_t middleClickButton = 1;
uint8_t rightClickButton = 2;
2025-07-08 15:12:35 +03:00
bool ignoreMouseMovementWhenPenInProximity = false;
float brushMinimumSize = 0.0f;
2025-07-06 20:43:53 +03:00
} tabletOptions;
Vector4f* colorLeft = nullptr;
Vector4f* colorRight = nullptr;
bool isUpdatingColorLeft = false;
bool isUpdatingColorRight = false;
2025-12-01 17:33:14 +03:00
std::optional<Vector2f> rightClickPopupLocation;
bool flipZoomToolDirection = false;
float final_gui_scale();
2025-07-06 20:43:53 +03:00
private:
2025-09-27 17:59:56 +03:00
void calculate_final_gui_scale();
float final_gui_scale_not_fit();
2025-07-06 20:43:53 +03:00
static void sdl_open_file_dialog_callback(void* userData, const char * const * fileList, int filter);
void reload_theme_list();
void player_list();
void chat_box();
void global_log();
void top_toolbar();
2025-09-06 19:06:30 +03:00
void grid_menu(bool justOpened);
2025-09-12 09:54:49 +03:00
void stop_displaying_grid_menu();
2025-07-06 20:43:53 +03:00
void bookmark_menu(bool justOpened);
void drawing_program_gui();
void options_menu();
void file_picker_gui();
void performance_metrics();
bool color_palette(const std::string& id, Vector4f* color, bool& hoveringOnDropdown);
2025-07-06 20:43:53 +03:00
void open_world_file(int conType, const std::string& netSource, const std::string& serverLocalID);
void load_default_palette();
void load_default_theme();
void about_menu_gui();
void web_version_welcome();
2025-10-01 20:08:01 +03:00
#ifndef __EMSCRIPTEN__
void update_notification_gui();
void update_notification_check();
struct UpdateCheckerData {
bool checkForUpdates = true;
bool showGui = false;
bool updateCheckDone = false;
std::string newVersionStr;
std::shared_ptr<FileDownloader::DownloadData> versionFile;
} updateCheckerData;
#endif
2025-07-06 20:43:53 +03:00
std::string ownLicenseText;
std::vector<std::pair<std::string, std::string>> thirdPartyLicenses;
int selectedLicense = -1;
std::string downloadNameSet;
struct PaletteData {
struct Palette {
std::string name;
std::vector<Vector3f> colors;
NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT(Palette, name, colors)
};
size_t selectedPalette = 0;
int selectedColor = -1;
std::vector<Palette> palettes;
bool addingPalette = false;
std::string newPaletteStr;
} paletteData;
struct ThemeData {
std::vector<std::string> themeDirList;
std::optional<size_t> selectedThemeIndex;
std::string themeCurrentlyLoaded = "Default";
bool openedSaveAsMenu = false;
} themeData;
bool justAssignedColorLeft = false;
bool justAssignedColorRight = false;
bool showPerformance = false;
bool menuPopUpOpen = false;
bool optionsMenuOpen = false;
bool playerMenuOpen = false;
float guiScale = 1.0f;
2025-09-27 17:59:56 +03:00
float finalCalculatedGuiScale = 1.0f;
2025-07-06 20:43:53 +03:00
enum {
CHATBOXSTATE_OPEN,
CHATBOXSTATE_JUSTOPEN,
CHATBOXSTATE_CLOSE
} chatBoxState = CHATBOXSTATE_CLOSE;
enum OptionsMenuType {
HOST_MENU,
CONNECT_MENU,
GENERAL_SETTINGS_MENU,
LOBBY_INFO_MENU,
2025-08-01 10:58:45 +03:00
CANVAS_SETTINGS_MENU,
2025-07-06 20:43:53 +03:00
SET_DOWNLOAD_NAME,
ABOUT_MENU
} optionsMenuType;
enum GeneralSettingsOptions {
GSETTINGS_GENERAL = 0,
GSETTINGS_TABLET,
GSETTINGS_THEME,
GSETTINGS_KEYBINDS,
GSETTINGS_DEBUG
} generalSettingsOptions = GSETTINGS_GENERAL;
struct BookmarkMenu {
bool popupOpen = false;
std::string newName;
uint32_t selectedBookmark = std::numeric_limits<uint32_t>::max();
2025-07-06 20:43:53 +03:00
} bookMenu;
2025-09-06 19:06:30 +03:00
struct GridMenu {
bool popupOpen = false;
std::string newName;
2025-10-06 12:09:17 +03:00
ServerClientID gridSelected = {0, 0};
2025-09-06 19:06:30 +03:00
} gridMenu;
2025-07-06 20:43:53 +03:00
bool useNativeFilePicker = true;
struct FilePicker {
bool isOpen = false;
std::string filePickerWindowName;
std::vector<ExtensionFilter> extensionFiltersComplete;
std::vector<std::string> extensionFilters;
std::vector<std::filesystem::path> entries;
bool refreshEntries = true;
std::filesystem::path currentSearchPath;
std::filesystem::path currentSelectedPath;
std::string fileName;
size_t extensionSelected;
OpenFileSelectorCallback postSelectionFunc;
} filePicker;
struct NativeFilePicker {
std::atomic<bool> isOpen = false;
std::vector<ExtensionFilter> extensionFiltersComplete;
std::vector<SDL_DialogFileFilter> sdlFileFilters;
OpenFileSelectorCallback postSelectionFunc;
};
static NativeFilePicker nativeFilePicker;
std::optional<unsigned> keybindWaiting;
2025-07-06 20:43:53 +03:00
std::filesystem::path testing;
2025-10-16 09:38:58 +03:00
std::unique_ptr<skia::textlayout::Paragraph> build_paragraph_from_chat_message(const ChatMessage& message, float alpha);
2025-07-06 20:43:53 +03:00
void start_gui();
void end_gui();
void load_icons_at(const std::filesystem::path& pathToLoad);
2025-07-06 20:43:53 +03:00
std::string serverToConnectTo;
std::string serverLocalID;
MainProgram& main;
};