浏览代码

UI: Fix DoubleSlider behavior for OBS_NUMBER_SLIDER properties

When using e.g. a color correction filter on any source and changing
any value (with slider enabled, e.g. contrast) to -0.10 the value would
get cycle between -0.07/-0.08 at some point when using the up arrow; it
would also get stuck on -0.69.

For the other direction, when starting from e.g. -0.02 the value would
jump from 0.05 to -0.08 when pressing the down arrow.

Problem was reported at https://obsproject.com/forum/threads/32450
Palana 10 年之前
父节点
当前提交
8293103106
共有 1 个文件被更改,包括 4 次插入2 次删除
  1. 4 2
      obs/double-slider.cpp

+ 4 - 2
obs/double-slider.cpp

@@ -1,5 +1,7 @@
 #include "double-slider.hpp"
 #include "double-slider.hpp"
 
 
+#include <cmath>
+
 DoubleSlider::DoubleSlider(QWidget *parent) : QSlider(parent)
 DoubleSlider::DoubleSlider(QWidget *parent) : QSlider(parent)
 {
 {
 	connect(this, SIGNAL(valueChanged(int)),
 	connect(this, SIGNAL(valueChanged(int)),
@@ -24,10 +26,10 @@ void DoubleSlider::setDoubleConstraints(double newMin, double newMax,
 
 
 void DoubleSlider::intValChanged(int val)
 void DoubleSlider::intValChanged(int val)
 {
 {
-	emit doubleValChanged(double(val) * minStep + minVal);
+	emit doubleValChanged((minVal/minStep + val) * minStep);
 }
 }
 
 
 void DoubleSlider::setDoubleVal(double val)
 void DoubleSlider::setDoubleVal(double val)
 {
 {
-	setValue(int((val - minVal) / minStep));
+	setValue(lround((val - minVal) / minStep));
 }
 }