Add minimum brush size, remove speed based brush size, and fixed textboxes not showing 0 value
This commit is contained in:
parent
470faf1cc5
commit
270cd98195
5 changed files with 13 additions and 28 deletions
|
|
@ -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<int>(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<float>((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;
|
||||
|
|
|
|||
|
|
@ -34,7 +34,6 @@ class BrushTool : public DrawingProgramToolBase {
|
|||
float val;
|
||||
std::chrono::steady_clock::time_point t;
|
||||
};
|
||||
std::deque<SmoothingPoint> velocitySmoothingData;
|
||||
std::deque<SmoothingPoint> penSmoothingData;
|
||||
|
||||
std::shared_ptr<DrawBrushStroke> intermediateItem;
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ template <typename T> 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 <typename T> class TextBox : public Element {
|
|||
}
|
||||
if(data && selection.justUnselected) {
|
||||
std::optional<T> 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 <typename T> 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<RichText::TextBox>();
|
||||
|
|
@ -116,14 +116,14 @@ template <typename T> class TextBox : public Element {
|
|||
|
||||
void update_on_edit() {
|
||||
std::optional<T> dataToAssign = fromStr(textbox->get_string());
|
||||
if(dataToAssign) {
|
||||
if(dataToAssign.has_value()) {
|
||||
*data = dataToAssign.value();
|
||||
oldData = *data;
|
||||
}
|
||||
}
|
||||
|
||||
T* data = nullptr;
|
||||
T oldData;
|
||||
std::optional<T> oldData;
|
||||
|
||||
std::function<std::optional<T>(const std::string&)> fromStr;
|
||||
std::function<std::string(const T&)> toStr;
|
||||
|
|
|
|||
|
|
@ -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<uint8_t>("middle click", "Middle click pen button", &tabletOptions.middleClickButton, 1, 255);
|
||||
gui.input_scalar_field<uint8_t>("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
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue