From 270cd98195765f54dc8ad9620c11a0fada124b34 Mon Sep 17 00:00:00 2001 From: Yousef Khadadeh Date: Sun, 30 Nov 2025 16:19:36 +0300 Subject: [PATCH] Add minimum brush size, remove speed based brush size, and fixed textboxes not showing 0 value --- src/DrawingProgram/BrushTool.cpp | 22 ++++------------------ src/DrawingProgram/BrushTool.hpp | 1 - src/GUIStuff/Elements/TextBox.hpp | 10 +++++----- src/Toolbar.cpp | 6 +++--- src/Toolbar.hpp | 2 +- 5 files changed, 13 insertions(+), 28 deletions(-) diff --git a/src/DrawingProgram/BrushTool.cpp b/src/DrawingProgram/BrushTool.cpp index 5199901..8ecb044 100644 --- a/src/DrawingProgram/BrushTool.cpp +++ b/src/DrawingProgram/BrushTool.cpp @@ -52,17 +52,6 @@ void BrushTool::tool_update() { if(!controls.isDrawing) controls.penSmoothingData.clear(); - float averageScreenSize = (drawP.world.main.window.size.x() + drawP.world.main.window.size.y()) / 2.0f; - float minVel = 0.2f * averageScreenSize; - float maxVel = 3.5f * averageScreenSize; - - while(!controls.velocitySmoothingData.empty() && (std::chrono::steady_clock::now() - controls.velocitySmoothingData.front().t) > std::chrono::milliseconds(200)) - controls.velocitySmoothingData.pop_front(); - controls.velocitySmoothingData.emplace_back( - drawP.world.main.input.mouse.move.norm() / drawP.world.main.deltaTime, - std::chrono::steady_clock::now() - ); - if(drawP.world.main.input.pen.isDown && drawP.controls.leftClickHeld && drawP.world.main.toolbar.tabletOptions.pressureAffectsBrushWidth) { while(!controls.penSmoothingData.empty() && (std::chrono::steady_clock::now() - controls.penSmoothingData.front().t) > std::chrono::milliseconds(static_cast(drawP.world.main.toolbar.tabletOptions.smoothingSamplingTime * 1000.0f))) controls.penSmoothingData.pop_front(); @@ -75,13 +64,10 @@ void BrushTool::tool_update() { averagePressure += width; averagePressure /= controls.penSmoothingData.size(); controls.penWidth = averagePressure; - } - else if(drawP.world.main.toolbar.velocityAffectsBrushWidth) { - float averageVel = 0.0f; - for(auto& [width, t] : controls.velocitySmoothingData) - averageVel += width; - averageVel /= controls.velocitySmoothingData.size(); - controls.penWidth = std::clamp((averageVel - minVel) / (maxVel - minVel), VEL_SMOOTH_MIN, VEL_SMOOTH_MAX); + if(controls.penWidth != 0.0f) { + float brushMinSize = drawP.world.main.toolbar.tabletOptions.brushMinimumSize; + controls.penWidth = brushMinSize + controls.penWidth * (1.0f - brushMinSize); + } } else controls.penWidth = 1.0f; diff --git a/src/DrawingProgram/BrushTool.hpp b/src/DrawingProgram/BrushTool.hpp index 63e93ab..796cdf9 100644 --- a/src/DrawingProgram/BrushTool.hpp +++ b/src/DrawingProgram/BrushTool.hpp @@ -34,7 +34,6 @@ class BrushTool : public DrawingProgramToolBase { float val; std::chrono::steady_clock::time_point t; }; - std::deque velocitySmoothingData; std::deque penSmoothingData; std::shared_ptr intermediateItem; diff --git a/src/GUIStuff/Elements/TextBox.hpp b/src/GUIStuff/Elements/TextBox.hpp index b77ec5d..c880648 100644 --- a/src/GUIStuff/Elements/TextBox.hpp +++ b/src/GUIStuff/Elements/TextBox.hpp @@ -13,7 +13,7 @@ template class TextBox : public Element { bool isUpdating = false; if(!textbox || !cur) - force_update_textbox(io, false); + force_update_textbox(io, true); data = newData; fromStr = newFromStr; @@ -40,7 +40,7 @@ template class TextBox : public Element { } if(data && selection.justUnselected) { std::optional dataToAssign = fromStr(textbox->get_string()); - if(dataToAssign) + if(dataToAssign.has_value()) *data = dataToAssign.value(); force_update_textbox(io, true); isUpdating = true; @@ -99,7 +99,7 @@ template class TextBox : public Element { SelectionHelper selection; private: void force_update_textbox(UpdateInputData& io, bool reallyForce) { - if(data && (*data == oldData) && !reallyForce && textbox && cur) + if(data && oldData.has_value() && (*data == oldData.value()) && !reallyForce && textbox && cur) return; textbox = std::make_shared(); @@ -116,14 +116,14 @@ template class TextBox : public Element { void update_on_edit() { std::optional dataToAssign = fromStr(textbox->get_string()); - if(dataToAssign) { + if(dataToAssign.has_value()) { *data = dataToAssign.value(); oldData = *data; } } T* data = nullptr; - T oldData; + std::optional oldData; std::function(const std::string&)> fromStr; std::function toStr; diff --git a/src/Toolbar.cpp b/src/Toolbar.cpp index 1119bca..8706963 100644 --- a/src/Toolbar.cpp +++ b/src/Toolbar.cpp @@ -261,7 +261,6 @@ nlohmann::json Toolbar::get_config_json() { toRet["displayName"] = main.displayName; toRet["useNativeFilePicker"] = useNativeFilePicker; toRet["themeInUse"] = themeData.themeCurrentlyLoaded; - toRet["velocityAffectsBrushWidth"] = velocityAffectsBrushWidth; toRet["jumpTransitionEasing"] = jumpTransitionEasing; toRet["defaultCanvasBackgroundColor"] = main.defaultCanvasBackgroundColor; toRet["flipZoomToolDirection"] = flipZoomToolDirection; @@ -275,6 +274,7 @@ nlohmann::json Toolbar::get_config_json() { tablet["middleClickButton"] = tabletOptions.middleClickButton; tablet["rightClickButton"] = tabletOptions.rightClickButton; tablet["ignoreMouseMovementWhenPenInProximity"] = tabletOptions.ignoreMouseMovementWhenPenInProximity; + tablet["brushMinimumSize"] = tabletOptions.brushMinimumSize; toRet["tablet"] = tablet; @@ -323,7 +323,6 @@ void Toolbar::set_config_json(const nlohmann::json& j, VersionNumber version) { 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(...) {} @@ -337,6 +336,7 @@ void Toolbar::set_config_json(const nlohmann::json& j, VersionNumber version) { 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(...) {} + try{j.at("tablet").at("brushMinimumSize").get_to(tabletOptions.brushMinimumSize);} catch(...) {} main.update_display_names(); } @@ -1455,7 +1455,6 @@ void Toolbar::options_menu() { gui.slider_scalar_field("scroll zoom slider", "Scroll zoom speed", &scrollZoomSpeed, 0.0, 1.0, 3); gui.checkbox_field("flip zoom tool direction", "Flip zoom tool direction", &flipZoomToolDirection); gui.input_scalar_field("jump transition time", "Jump transition time", &jumpTransitionTime, 0.01f, 1000.0f, 2); - gui.checkbox_field("changebrushwidthwithspeed", "Change brush size with mouse speed", &velocityAffectsBrushWidth); gui.input_scalar_field("Max GUI Scale", "Max GUI Scale", &guiScale, 0.5f, 5.0f, 1); gui.text_label("VSync:"); @@ -1479,6 +1478,7 @@ void Toolbar::options_menu() { gui.slider_scalar_field("smoothing time", "Smoothing sampling time", &tabletOptions.smoothingSamplingTime, 0.001f, 1.0f, 3); gui.input_scalar_field("middle click", "Middle click pen button", &tabletOptions.middleClickButton, 1, 255); gui.input_scalar_field("right click", "Right click pen button", &tabletOptions.rightClickButton, 1, 255); + gui.slider_scalar_field("tablet brush minimum size", "Brush relative minimum size", &tabletOptions.brushMinimumSize, 0.0f, 1.0f, 3); #ifdef _WIN32 gui.checkbox_field("mouse ignore when pen proximity", "Ignore mouse movement when pen in proximity", &tabletOptions.ignoreMouseMovementWhenPenInProximity); #endif diff --git a/src/Toolbar.hpp b/src/Toolbar.hpp index ba9361c..de3184a 100644 --- a/src/Toolbar.hpp +++ b/src/Toolbar.hpp @@ -64,7 +64,6 @@ class Toolbar { bool load_theme(); void load_licenses(); - bool velocityAffectsBrushWidth = false; double dragZoomSpeed = 0.02; double scrollZoomSpeed = 0.4; float jumpTransitionTime = 0.5f; @@ -77,6 +76,7 @@ class Toolbar { uint8_t middleClickButton = 1; uint8_t rightClickButton = 2; bool ignoreMouseMovementWhenPenInProximity = false; + float brushMinimumSize = 0.0f; } tabletOptions; Vector4f* colorLeft = nullptr;