From 174b267589bf2ba74fed4297a6c6bff98cd06894 Mon Sep 17 00:00:00 2001 From: Yousef Khadadeh Date: Mon, 17 Nov 2025 16:08:42 +0300 Subject: [PATCH] Textbox updates work again, and added notices for web version users --- src/DrawComponents/DrawTextBox.cpp | 10 +++-- src/GUIStuff/Elements/FontPicker.cpp | 9 +++++ src/GUIStuff/GUIManager.cpp | 4 +- src/MainProgram.cpp | 17 +++++++- src/ResourceDisplay/ImageResourceDisplay.cpp | 4 +- src/Toolbar.cpp | 42 ++++++++++---------- src/Toolbar.hpp | 3 +- src/World.cpp | 3 ++ 8 files changed, 63 insertions(+), 29 deletions(-) diff --git a/src/DrawComponents/DrawTextBox.cpp b/src/DrawComponents/DrawTextBox.cpp index 8f99d8b..ab567d6 100644 --- a/src/DrawComponents/DrawTextBox.cpp +++ b/src/DrawComponents/DrawTextBox.cpp @@ -43,12 +43,12 @@ void DrawTextBox::save_file(cereal::PortableBinaryOutputArchive& a) const { void DrawTextBox::load_file(cereal::PortableBinaryInputArchive& a, VersionNumber version) { if(version < VersionNumber(0, 3, 0)) { - bool editing; // Unused + bool loadedEditing; // Unused Vector4f textColor; float textSize; - RichText::TextBox::Cursor cursor; // Unused, Equivalent to old cursor structure, just paragraph index and text index flipped + RichText::TextBox::Cursor loadedCursor; // Unused, Equivalent to old cursor structure, just paragraph index and text index flipped std::string currentText; - a(editing, d.p1, d.p2, textColor, textSize, cursor, currentText); + a(loadedEditing, d.p1, d.p2, textColor, textSize, loadedCursor, currentText); textBox->insert({0, 0}, currentText); textBox->set_text_style_modifier_between({0, 0}, textBox->move(RichText::TextBox::Movement::END, {0, 0}), std::make_shared(textColor)); textBox->set_text_style_modifier_between({0, 0}, textBox->move(RichText::TextBox::Movement::END, {0, 0}), std::make_shared(textSize)); @@ -64,6 +64,7 @@ void DrawTextBox::load_file(cereal::PortableBinaryInputArchive& a, VersionNumber std::shared_ptr DrawTextBox::copy(DrawingProgram& drawP) const { auto a = std::make_shared(); a->d = d; + *a->cursor = *cursor; a->coords = coords; a->textBox->set_rich_text_data(textBox->get_rich_text_data()); a->init_text_box(drawP); @@ -73,6 +74,7 @@ std::shared_ptr DrawTextBox::copy(DrawingProgram& drawP) const { std::shared_ptr DrawTextBox::deep_copy(DrawingProgram& drawP) const { auto a = std::make_shared(); a->d = d; + *a->cursor = *cursor; a->coords = coords; a->textBox->set_rich_text_data(textBox->get_rich_text_data()); a->collisionTree = collisionTree; @@ -83,6 +85,8 @@ std::shared_ptr DrawTextBox::deep_copy(DrawingProgram& drawP) con void DrawTextBox::update_from_delayed_ptr(const std::shared_ptr& delayedUpdatePtr) { std::shared_ptr newPtr = std::static_pointer_cast(delayedUpdatePtr); d = newPtr->d; + *cursor = *newPtr->cursor; + textBox->set_rich_text_data(newPtr->textBox->get_rich_text_data()); } void DrawTextBox::init_text_box(DrawingProgram& drawP) { diff --git a/src/GUIStuff/Elements/FontPicker.cpp b/src/GUIStuff/Elements/FontPicker.cpp index 8c335d6..34d38d2 100644 --- a/src/GUIStuff/Elements/FontPicker.cpp +++ b/src/GUIStuff/Elements/FontPicker.cpp @@ -76,6 +76,7 @@ bool GUIStuff::FontPicker::update(UpdateInputData& io, std::string* fontName, GU CLAY({ .layout = { .sizing = {.width = CLAY_SIZING_FIXED(250), .height = CLAY_SIZING_FIT(0, 300)}, + .layoutDirection = CLAY_TOP_TO_BOTTOM }, .backgroundColor = convert_vec4(io.theme->backColor1), .cornerRadius = CLAY_CORNER_RADIUS(4), @@ -158,6 +159,14 @@ bool GUIStuff::FontPicker::update(UpdateInputData& io, std::string* fontName, GU if(fontChangedFromTextbox && !io->mouse.leftClick && val != std::numeric_limits::max()) scrollAmount = -static_cast(val) * ENTRY_HEIGHT; }); + #ifdef __EMSCRIPTEN__ + CLAY({ + .layout = { + .padding = CLAY_PADDING_ALL(io.theme->padding1) + }}) { + gui->text_label_light_centered("Local fonts not usable in web version"); + } + #endif } } } diff --git a/src/GUIStuff/GUIManager.cpp b/src/GUIStuff/GUIManager.cpp index 844bda7..3ebbd9e 100644 --- a/src/GUIStuff/GUIManager.cpp +++ b/src/GUIStuff/GUIManager.cpp @@ -313,7 +313,7 @@ void GUIManager::text_label_centered(const std::string& val) { .childAlignment = {.x = CLAY_ALIGN_X_CENTER, .y = CLAY_ALIGN_Y_CENTER}, } }) { - CLAY_TEXT(strArena.std_str_to_clay_str(val), CLAY_TEXT_CONFIG({.textColor = convert_vec4(io->theme->frontColor1), .fontSize = io->fontSize })); + CLAY_TEXT(strArena.std_str_to_clay_str(val), CLAY_TEXT_CONFIG({.textColor = convert_vec4(io->theme->frontColor1), .fontSize = io->fontSize, .textAlignment = CLAY_TEXT_ALIGN_CENTER})); } } @@ -324,7 +324,7 @@ void GUIManager::text_label_light_centered(const std::string& val) { .childAlignment = {.x = CLAY_ALIGN_X_CENTER, .y = CLAY_ALIGN_Y_CENTER}, } }) { - CLAY_TEXT(strArena.std_str_to_clay_str(val), CLAY_TEXT_CONFIG({.textColor = convert_vec4(io->theme->frontColor2), .fontSize = io->fontSize })); + CLAY_TEXT(strArena.std_str_to_clay_str(val), CLAY_TEXT_CONFIG({.textColor = convert_vec4(io->theme->frontColor2), .fontSize = io->fontSize, .textAlignment = CLAY_TEXT_ALIGN_CENTER})); } } diff --git a/src/MainProgram.cpp b/src/MainProgram.cpp index 606c07c..7a0d939 100755 --- a/src/MainProgram.cpp +++ b/src/MainProgram.cpp @@ -1,5 +1,7 @@ #include "MainProgram.hpp" #include "DrawingProgram/DrawingProgramToolBase.hpp" +#include "Helpers/VersionNumber.hpp" +#include "VersionConstants.hpp" #include "cereal/archives/portable_binary.hpp" #include "cereal/details/helpers.hpp" #include @@ -169,6 +171,7 @@ void MainProgram::save_config() { using json = nlohmann::json; json j; + j["version"] = VersionConstants::CURRENT_VERSION_STRING; j["settings"] = toolbar.get_config_json(); j["window"]["pos"] = window.writtenPos; j["window"]["size"] = window.writtenSize; @@ -198,11 +201,23 @@ void MainProgram::load_config() { toolbar.file_selector_path() = homePath; if(f.is_open()) { using json = nlohmann::json; + try { json j; f >> j; + + VersionNumber version(0, 0, 1); try { - toolbar.set_config_json(j["settings"]); + std::string versionStr; + j.at("version").get_to(versionStr); + auto optVersion = version_str_to_version_numbers(versionStr); + if(optVersion.has_value()) + version = optVersion.value(); + } + catch(...) {} + + try { + toolbar.set_config_json(j["settings"], version); } catch(...) {} #ifndef __EMSCRIPTEN__ diff --git a/src/ResourceDisplay/ImageResourceDisplay.cpp b/src/ResourceDisplay/ImageResourceDisplay.cpp index 24a3575..7e74d27 100644 --- a/src/ResourceDisplay/ImageResourceDisplay.cpp +++ b/src/ResourceDisplay/ImageResourceDisplay.cpp @@ -86,16 +86,16 @@ bool ImageResourceDisplay::load(ResourceManager& rMan, const std::string& fileNa totalFramesToLoad = codec->getFrameCount(); imageInfo = codec->getInfo(); frames.resize(totalFramesToLoad); + loadedFrames = 0; if(rotate) { Logger::get().log("INFO", "Image loaded is rotated, so must rotate dimensions"); imageInfo = imageInfo.makeDimensions(SkISize(imageInfo.height(), imageInfo.width())); } try{ - Logger::get().log("INFO", "[ImageResourceDisplay::load] Failed to create load thread, loading on main thread"); - loadedFrames = 0; loadThread = std::make_unique(&ImageResourceDisplay::load_thread, this); } catch(...) { + Logger::get().log("INFO", "[ImageResourceDisplay::load] Failed to create load thread, loading on main thread"); load_thread(); } return true; diff --git a/src/Toolbar.cpp b/src/Toolbar.cpp index 3b155fd..1d6ba8b 100644 --- a/src/Toolbar.cpp +++ b/src/Toolbar.cpp @@ -221,7 +221,6 @@ nlohmann::json Toolbar::get_config_json() { jKeybinds[json(static_cast(i))] = main.input.key_assignment_to_str(f->first); } toRet["keybinds"] = jKeybinds; - toRet["guiScale"] = guiScale; toRet["jumpTransitionTime"] = jumpTransitionTime; toRet["dragZoomSpeed"] = dragZoomSpeed; @@ -250,7 +249,7 @@ nlohmann::json Toolbar::get_config_json() { return toRet; } -void Toolbar::set_config_json(const nlohmann::json& j) { +void Toolbar::set_config_json(const nlohmann::json& j, VersionNumber version) { using json = nlohmann::json; main.input.keyAssignments.clear(); try { @@ -274,27 +273,28 @@ void Toolbar::set_config_json(const nlohmann::json& j) { catch(...) { main.input.keyAssignments = main.input.defaultKeyAssignments; } - j.at("displayName").get_to(main.displayName); - j.at("jumpTransitionTime").get_to(jumpTransitionTime); - j.at("dragZoomSpeed").get_to(dragZoomSpeed); - j.at("scrollZoomSpeed").get_to(scrollZoomSpeed); - j.at("guiScale").get_to(guiScale); - j.at("showPerformance").get_to(showPerformance); - j.at("useNativeFilePicker").get_to(useNativeFilePicker); - j.at("themeInUse").get_to(themeData.themeCurrentlyLoaded); - j.at("velocityAffectsBrushWidth").get_to(velocityAffectsBrushWidth); - j.at("jumpTransitionEasing").get_to(jumpTransitionEasing); - j.at("defaultCanvasBackgroundColor").get_to(main.defaultCanvasBackgroundColor); - j.at("flipZoomToolDirection").get_to(flipZoomToolDirection); + try{j.at("displayName").get_to(main.displayName);} catch(...) {} + try{j.at("jumpTransitionTime").get_to(jumpTransitionTime);} catch(...) {} + try{j.at("dragZoomSpeed").get_to(dragZoomSpeed);} catch(...) {} + try{j.at("scrollZoomSpeed").get_to(scrollZoomSpeed);} catch(...) {} + try{j.at("guiScale").get_to(guiScale);} catch(...) {} + try{j.at("showPerformance").get_to(showPerformance);} catch(...) {} + try{j.at("useNativeFilePicker").get_to(useNativeFilePicker);} catch(...) {} + try{j.at("themeInUse").get_to(themeData.themeCurrentlyLoaded);} catch(...) {} + try{j.at("velocityAffectsBrushWidth").get_to(velocityAffectsBrushWidth);} catch(...) {} + try{j.at("jumpTransitionEasing").get_to(jumpTransitionEasing);} catch(...) {} + if(version >= VersionNumber(0, 3, 0)) + try{j.at("defaultCanvasBackgroundColor").get_to(main.defaultCanvasBackgroundColor);} catch(...) {} + try{j.at("flipZoomToolDirection").get_to(flipZoomToolDirection);} catch(...) {} #ifndef __EMSCRIPTEN__ - j.at("checkForUpdates").get_to(updateCheckerData.checkForUpdates); + try{j.at("checkForUpdates").get_to(updateCheckerData.checkForUpdates);} catch(...) {} #endif - j.at("tablet").at("pressureAffectsBrushWidth").get_to(tabletOptions.pressureAffectsBrushWidth); - j.at("tablet").at("smoothingSamplingTime").get_to(tabletOptions.smoothingSamplingTime); - j.at("tablet").at("middleClickButton").get_to(tabletOptions.middleClickButton); - j.at("tablet").at("rightClickButton").get_to(tabletOptions.rightClickButton); - j.at("tablet").at("ignoreMouseMovementWhenPenInProximity").get_to(tabletOptions.ignoreMouseMovementWhenPenInProximity); + try{j.at("tablet").at("pressureAffectsBrushWidth").get_to(tabletOptions.pressureAffectsBrushWidth);} catch(...) {} + try{j.at("tablet").at("smoothingSamplingTime").get_to(tabletOptions.smoothingSamplingTime);} catch(...) {} + try{j.at("tablet").at("middleClickButton").get_to(tabletOptions.middleClickButton);} catch(...) {} + try{j.at("tablet").at("rightClickButton").get_to(tabletOptions.rightClickButton);} catch(...) {} + try{j.at("tablet").at("ignoreMouseMovementWhenPenInProximity").get_to(tabletOptions.ignoreMouseMovementWhenPenInProximity);} catch(...) {} main.update_display_names(); } @@ -563,6 +563,8 @@ R"(This version contains more known issues than the native version of the app. T - Rare crashes - If this browser tab is unfocused, or the window is minimized, any InfiniPaint tabs connected online (whether host or client) will be disconnected - 4GB memory limit. Might be a problem if you're uploading many files/images +- Not multithreaded +- Can't access local fonts If you like this app, consider downloading the native version for your system)"); if(gui.text_button_wide("got it", "Got It")) diff --git a/src/Toolbar.hpp b/src/Toolbar.hpp index cab9af3..058b9e3 100644 --- a/src/Toolbar.hpp +++ b/src/Toolbar.hpp @@ -8,6 +8,7 @@ #include #include #include +#include class MainProgram; @@ -55,7 +56,7 @@ class Toolbar { GUIStuff::GUIManager gui; nlohmann::json get_config_json(); - void set_config_json(const nlohmann::json& j); + void set_config_json(const nlohmann::json& j, VersionNumber version); void save_palettes(); void load_palettes(); diff --git a/src/World.cpp b/src/World.cpp index 449c474..2274108 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -3,6 +3,7 @@ #include "Helpers/HsvRgb.hpp" #include "Helpers/MathExtras.hpp" #include "Helpers/Networking/ByteStream.hpp" +#include "Helpers/VersionNumber.hpp" #include "Server/CommandList.hpp" #include "MainProgram.hpp" #include "SharedTypes.hpp" @@ -339,6 +340,8 @@ void World::load_from_file(const std::filesystem::path& fileName, std::string_vi ByteMemStream f((char*)uncompressedDataView.data(), uncompressedDataView.size()); + Logger::get().log("INFO", "Loading file from version " + version_numbers_to_version_str(fileVersion)); + cereal::PortableBinaryInputArchive a(f); load_file(a, fileVersion); nextClientID = get_max_id(ownID);