Textbox updates work again, and added notices for web version users

This commit is contained in:
Yousef Khadadeh 2025-11-17 16:08:42 +03:00
parent f0f289d785
commit 174b267589
8 changed files with 63 additions and 29 deletions

View file

@ -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<ColorTextStyleModifier>(textColor));
textBox->set_text_style_modifier_between({0, 0}, textBox->move(RichText::TextBox::Movement::END, {0, 0}), std::make_shared<SizeTextStyleModifier>(textSize));
@ -64,6 +64,7 @@ void DrawTextBox::load_file(cereal::PortableBinaryInputArchive& a, VersionNumber
std::shared_ptr<DrawComponent> DrawTextBox::copy(DrawingProgram& drawP) const {
auto a = std::make_shared<DrawTextBox>();
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<DrawComponent> DrawTextBox::copy(DrawingProgram& drawP) const {
std::shared_ptr<DrawComponent> DrawTextBox::deep_copy(DrawingProgram& drawP) const {
auto a = std::make_shared<DrawTextBox>();
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<DrawComponent> DrawTextBox::deep_copy(DrawingProgram& drawP) con
void DrawTextBox::update_from_delayed_ptr(const std::shared_ptr<DrawComponent>& delayedUpdatePtr) {
std::shared_ptr<DrawTextBox> newPtr = std::static_pointer_cast<DrawTextBox>(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) {

View file

@ -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<Clay_Color>(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<size_t>::max())
scrollAmount = -static_cast<float>(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
}
}
}

View file

@ -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<Clay_Color>(io->theme->frontColor1), .fontSize = io->fontSize }));
CLAY_TEXT(strArena.std_str_to_clay_str(val), CLAY_TEXT_CONFIG({.textColor = convert_vec4<Clay_Color>(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<Clay_Color>(io->theme->frontColor2), .fontSize = io->fontSize }));
CLAY_TEXT(strArena.std_str_to_clay_str(val), CLAY_TEXT_CONFIG({.textColor = convert_vec4<Clay_Color>(io->theme->frontColor2), .fontSize = io->fontSize, .textAlignment = CLAY_TEXT_ALIGN_CENTER}));
}
}

View file

@ -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 <chrono>
@ -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__

View file

@ -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<std::thread>(&ImageResourceDisplay::load_thread, this);
}
catch(...) {
Logger::get().log("INFO", "[ImageResourceDisplay::load] Failed to create load thread, loading on main thread");
load_thread();
}
return true;

View file

@ -221,7 +221,6 @@ nlohmann::json Toolbar::get_config_json() {
jKeybinds[json(static_cast<InputManager::KeyCodeEnum>(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"))

View file

@ -8,6 +8,7 @@
#include <nlohmann/json.hpp>
#include <Helpers/Serializers.hpp>
#include <SDL3/SDL_dialog.h>
#include <Helpers/VersionNumber.hpp>
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();

View file

@ -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);