summaryrefslogtreecommitdiffhomepage
path: root/opentrack-compat
diff options
context:
space:
mode:
Diffstat (limited to 'opentrack-compat')
-rw-r--r--opentrack-compat/options.cpp67
-rw-r--r--opentrack-compat/options.hpp52
-rw-r--r--opentrack-compat/slider.cpp72
-rw-r--r--opentrack-compat/slider.hpp63
4 files changed, 136 insertions, 118 deletions
diff --git a/opentrack-compat/options.cpp b/opentrack-compat/options.cpp
index dc4998ad..7b2eaa2f 100644
--- a/opentrack-compat/options.cpp
+++ b/opentrack-compat/options.cpp
@@ -240,72 +240,5 @@ OPENTRACK_COMPAT_EXPORT opt_singleton& singleton()
} // end options::detail
-slider_value::slider_value(double cur, double min, double max) :
- cur_(cur),
- min_(min),
- max_(max)
-{
- if (min_ > max_)
- min_ = max_;
- if (cur_ > max_)
- cur_ = max;
- if (cur_ < min_)
- cur_ = min_;
-}
-
-slider_value::slider_value(const slider_value& v) : slider_value(v.cur(), v.min(), v.max())
-{
-}
-
-slider_value::slider_value() : slider_value(0, 0, 0)
-{
-}
-
-slider_value& slider_value::operator=(const slider_value& v)
-{
- cur_ = v.cur_;
-
- min_ = v.min_;
- max_ = v.max_;
-
- return *this;
-}
-
-bool slider_value::operator==(const slider_value& v) const
-{
- using std::fabs;
-
- static constexpr double eps = 1e-3;
-
- return (fabs(v.cur_ - cur_) < eps &&
- fabs(v.min_ - min_) < eps &&
- fabs(v.max_ - max_) < eps);
-}
-
-slider_value slider_value::update_from_slider(int pos, int q_min, int q_max) const
-{
- slider_value v(*this);
-
- const int q_diff = q_max - q_min;
- const double sv_pos = q_diff == 0
- ? -1e6
- : (((pos - q_min) * (v.max() - v.min())) / q_diff + v.min());
-
- if (sv_pos < v.min())
- v = slider_value(v.min(), v.min(), v.max());
- else if (sv_pos > v.max())
- v = slider_value(v.max(), v.min(), v.max());
- else
- v = slider_value(sv_pos, v.min(), v.max());
- return v;
-}
-
-int slider_value::to_slider_pos(int q_min, int q_max) const
-{
- const int q_diff = q_max - q_min;
-
- return int(std::round(((cur() - min()) * q_diff / (max() - min())) + q_min));
-}
-
} // end options
diff --git a/opentrack-compat/options.hpp b/opentrack-compat/options.hpp
index 86c699d6..53249746 100644
--- a/opentrack-compat/options.hpp
+++ b/opentrack-compat/options.hpp
@@ -5,8 +5,6 @@
* copyright notice and this permission notice appear in all copies.
*/
-// XXX TODO this header is too long
-
#pragma once
#include <memory>
@@ -43,6 +41,7 @@
#include <QDebug>
#include "export.hpp"
+#include "slider.hpp"
template<typename t> using mem = std::shared_ptr<t>;
@@ -50,55 +49,6 @@ template<typename t> using mem = std::shared_ptr<t>;
#define OPENTRACK_DEFAULT_CONFIG "default.ini"
#define OPENTRACK_ORG "opentrack-2.3"
-namespace options
-{
- class OPENTRACK_COMPAT_EXPORT slider_value final
- {
- double cur_, min_, max_;
- public:
- slider_value(double cur, double min, double max);
- slider_value(const slider_value& v);
- slider_value();
- slider_value& operator=(const slider_value& v);
- bool operator==(const slider_value& v) const;
- operator double() const { return cur_; }
- double cur() const { return cur_; }
- double min() const { return min_; }
- double max() const { return max_; }
- slider_value update_from_slider(int pos, int q_min, int q_max) const;
- int to_slider_pos(int q_min, int q_max) const;
- };
-}
-
-QT_BEGIN_NAMESPACE
-
-inline QDebug operator << (QDebug dbg, const options::slider_value& val)
-{
- return dbg << val.cur();
-}
-
-inline QDataStream& operator << (QDataStream& out, const options::slider_value& v)
-{
- out << v.cur()
- << v.min()
- << v.max();
- return out;
-}
-
-inline QDataStream& operator >> (QDataStream& in, options::slider_value& v)
-{
- double cur, min, max;
- in >> cur;
- in >> min;
- in >> max;
- v = options::slider_value(cur, min, max);
- return in;
-}
-
-QT_END_NAMESPACE
-
-Q_DECLARE_METATYPE(options::slider_value)
-
namespace options {
namespace {
class custom_type_initializer
diff --git a/opentrack-compat/slider.cpp b/opentrack-compat/slider.cpp
new file mode 100644
index 00000000..fca591a1
--- /dev/null
+++ b/opentrack-compat/slider.cpp
@@ -0,0 +1,72 @@
+#include "slider.hpp"
+
+namespace options {
+
+slider_value::slider_value(double cur, double min, double max) :
+ cur_(cur),
+ min_(min),
+ max_(max)
+{
+ if (min_ > max_)
+ min_ = max_;
+ if (cur_ > max_)
+ cur_ = max;
+ if (cur_ < min_)
+ cur_ = min_;
+}
+
+slider_value::slider_value(const slider_value& v) : slider_value(v.cur(), v.min(), v.max())
+{
+}
+
+slider_value::slider_value() : slider_value(0, 0, 0)
+{
+}
+
+slider_value& slider_value::operator=(const slider_value& v)
+{
+ cur_ = v.cur_;
+
+ min_ = v.min_;
+ max_ = v.max_;
+
+ return *this;
+}
+
+bool slider_value::operator==(const slider_value& v) const
+{
+ using std::fabs;
+
+ static constexpr double eps = 1e-3;
+
+ return (fabs(v.cur_ - cur_) < eps &&
+ fabs(v.min_ - min_) < eps &&
+ fabs(v.max_ - max_) < eps);
+}
+
+slider_value slider_value::update_from_slider(int pos, int q_min, int q_max) const
+{
+ slider_value v(*this);
+
+ const int q_diff = q_max - q_min;
+ const double sv_pos = q_diff == 0
+ ? -1e6
+ : (((pos - q_min) * (v.max() - v.min())) / q_diff + v.min());
+
+ if (sv_pos < v.min())
+ v = slider_value(v.min(), v.min(), v.max());
+ else if (sv_pos > v.max())
+ v = slider_value(v.max(), v.min(), v.max());
+ else
+ v = slider_value(sv_pos, v.min(), v.max());
+ return v;
+}
+
+int slider_value::to_slider_pos(int q_min, int q_max) const
+{
+ const int q_diff = q_max - q_min;
+
+ return int(std::round(((cur() - min()) * q_diff / (max() - min())) + q_min));
+}
+
+} // end ns options
diff --git a/opentrack-compat/slider.hpp b/opentrack-compat/slider.hpp
new file mode 100644
index 00000000..d5e4a7d0
--- /dev/null
+++ b/opentrack-compat/slider.hpp
@@ -0,0 +1,63 @@
+/* Copyright (c) 2016 Stanislaw Halik
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ */
+
+#pragma once
+
+#include "export.hpp"
+#include <QMetaType>
+#include <QDataStream>
+#include <QDebug>
+#include <cmath>
+
+namespace options
+{
+ class OPENTRACK_COMPAT_EXPORT slider_value final
+ {
+ double cur_, min_, max_;
+ public:
+ slider_value(double cur, double min, double max);
+ slider_value(const slider_value& v);
+ slider_value();
+ slider_value& operator=(const slider_value& v);
+ bool operator==(const slider_value& v) const;
+ operator double() const { return cur_; }
+ double cur() const { return cur_; }
+ double min() const { return min_; }
+ double max() const { return max_; }
+ slider_value update_from_slider(int pos, int q_min, int q_max) const;
+ int to_slider_pos(int q_min, int q_max) const;
+ };
+}
+
+QT_BEGIN_NAMESPACE
+
+inline QDebug operator << (QDebug dbg, const options::slider_value& val)
+{
+ return dbg << val.cur();
+}
+
+inline QDataStream& operator << (QDataStream& out, const options::slider_value& v)
+{
+ out << v.cur()
+ << v.min()
+ << v.max();
+ return out;
+}
+
+inline QDataStream& operator >> (QDataStream& in, options::slider_value& v)
+{
+ double cur, min, max;
+ in >> cur;
+ in >> min;
+ in >> max;
+ v = options::slider_value(cur, min, max);
+ return in;
+}
+
+QT_END_NAMESPACE
+
+Q_DECLARE_METATYPE(options::slider_value)