From 01210b7fba37356ee2c18420762eeeed52489d20 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Sun, 29 Jan 2017 03:10:28 +0100 Subject: gui/mapping-window, spline-widget, logic/main-settings: limited mapping range --- gui/mapping-window.cpp | 24 +++++-- gui/mapping-window.ui | 147 ++++++++++++++++++++++++++++++++-------- logic/main-settings.hpp | 14 +++- spline-widget/spline-widget.hpp | 3 +- spline-widget/spline.cpp | 55 ++++++++------- spline-widget/spline.hpp | 2 +- 6 files changed, 186 insertions(+), 59 deletions(-) diff --git a/gui/mapping-window.cpp b/gui/mapping-window.cpp index d1188e66..d34fcc48 100644 --- a/gui/mapping-window.cpp +++ b/gui/mapping-window.cpp @@ -25,6 +25,10 @@ MapWidget::MapWidget(Mappings& m) : m(m) tie_setting(s.a_yaw.altp, ui.rx_altp); tie_setting(s.a_pitch.altp, ui.ry_altp); tie_setting(s.a_roll.altp, ui.rz_altp); + + tie_setting(s.a_yaw.clamp, ui.max_yaw_rotation); + tie_setting(s.a_pitch.clamp, ui.max_pitch_rotation); + tie_setting(s.a_roll.clamp, ui.max_roll_rotation); } void MapWidget::load() @@ -51,19 +55,23 @@ void MapWidget::load() { nullptr, Yaw, nullptr, false } }; + for (QComboBox* x : { ui.max_yaw_rotation, ui.max_pitch_rotation, ui.max_roll_rotation }) + { + using a = axis_opts::max_rotation; + for (a y : { a::r180, a::r90, a::r60, a::r45, a::r30, a::r20 }) + x->addItem(QString::number(y) + "°", y); + } + for (int i = 0; qfcs[i].qfc; i++) { const bool altp = qfcs[i].altp; Map& axis = m(qfcs[i].axis); spline& conf = altp ? axis.spline_alt : axis.spline_main; - //const QString& name = altp ? axis.name2 : axis.name1; - //conf.set_bundle(make_bundle(name)); - qfcs[i].qfc->setConfig(&conf); + spline_widget& qfc = *qfcs[i].qfc; if (altp) { - spline_widget& qfc = *qfcs[i].qfc; connect(qfcs[i].checkbox, &QCheckBox::toggled, this, [&](bool f) -> void {qfc.setEnabled(f); qfc.force_redraw();}); @@ -71,10 +79,18 @@ void MapWidget::load() qfc.force_redraw(); } + connect(&axis.opts.clamp, static_cast(&base_value::valueChanged), + &qfc, [&conf, &qfc](int value) { conf.set_max_input(value); qfc.reload_spline(); }); + conf.set_max_input(axis.opts.clamp); + if (qfcs[i].axis >= 3) + { qfcs[i].qfc->set_snap(1, 2.5); + } else qfcs[i].qfc->set_snap(.5, 1); + + qfcs[i].qfc->setConfig(&conf); } } diff --git a/gui/mapping-window.ui b/gui/mapping-window.ui index c1a52021..dc43ab8a 100644 --- a/gui/mapping-window.ui +++ b/gui/mapping-window.ui @@ -11,7 +11,7 @@ - + 0 0 @@ -22,12 +22,6 @@ 664 - - - 970 - 664 - - Mapping properties @@ -41,9 +35,6 @@ - - - QTabWidget::North @@ -51,13 +42,48 @@ 0 - - background-color: #ccc; - Yaw + + + + + 0 + 0 + + + + QFrame::NoFrame + + + + + + + 0 + 0 + + + + Max rotation + + + + + + + + 0 + 0 + + + + + + + @@ -104,13 +130,48 @@ - - background-color: #ccc; - Pitch + + + + + 0 + 0 + + + + QFrame::NoFrame + + + + + + + 0 + 0 + + + + Max rotation + + + + + + + + 0 + 0 + + + + + + + @@ -157,13 +218,48 @@ - - background-color: #ccc; - Roll + + + + + 0 + 0 + + + + QFrame::NoFrame + + + + + + + 0 + 0 + + + + Max rotation + + + + + + + + 0 + 0 + + + + + + + @@ -208,11 +304,12 @@ + rzconfig + rz_altp + rzconfig_alt + frame_3 - - background-color: #ccc; - X @@ -263,9 +360,6 @@ - - background-color: #ccc; - Y @@ -316,9 +410,6 @@ - - background-color: #ccc; - Z diff --git a/logic/main-settings.hpp b/logic/main-settings.hpp index 749f6d25..66146913 100644 --- a/logic/main-settings.hpp +++ b/logic/main-settings.hpp @@ -18,18 +18,30 @@ using namespace options; struct axis_opts final { + enum max_rotation : int + { + r180 = 180, + r90 = 90, + r60 = 60, + r45 = 45, + r30 = 30, + r20 = 25, + }; + // note, these two bundles can be the same value with no issues bundle b_settings_window, b_mapping_window; value zero; value src; value invert, altp; + value clamp; axis_opts(bundle b_settings_window, bundle b_mapping_window, QString pfx, int idx) : b_settings_window(b_settings_window), b_mapping_window(b_mapping_window), zero(b_settings_window, n(pfx, "zero-pos"), 0), src(b_settings_window, n(pfx, "source-index"), idx), invert(b_settings_window, n(pfx, "invert-sign"), false), - altp(b_mapping_window, n(pfx, "alt-axis-sign"), false) + altp(b_mapping_window, n(pfx, "alt-axis-sign"), false), + clamp(b_mapping_window, n(pfx, "max-value"), idx == Pitch ? r90 : r180) {} private: static inline QString n(QString pfx, QString name) diff --git a/spline-widget/spline-widget.hpp b/spline-widget/spline-widget.hpp index 921f44a2..4d5a7680 100644 --- a/spline-widget/spline-widget.hpp +++ b/spline-widget/spline-widget.hpp @@ -57,12 +57,13 @@ public: void set_snap(double x, double y) { snap_x = x; snap_y = y; } void get_snap(double& x, double& y) const { x = snap_x; y = snap_y; } +public slots: + void reload_spline(); protected slots: void paintEvent(QPaintEvent *e) override; void mousePressEvent(QMouseEvent *e) override; void mouseMoveEvent(QMouseEvent *e) override; void mouseReleaseEvent(QMouseEvent *e) override; - void reload_spline(); private: int get_closeness_limit(); void show_tooltip(const QPoint& pos, const QPointF& value = QPointF(0, 0)); diff --git a/spline-widget/spline.cpp b/spline-widget/spline.cpp index 59ed9939..8d8fe0e5 100644 --- a/spline-widget/spline.cpp +++ b/spline-widget/spline.cpp @@ -147,31 +147,41 @@ void spline::add_lone_point() s->points = points; } -QPointF spline::ensure_in_bounds(const QList& points, int i) +QPointF spline::ensure_in_bounds(const QList& points, double max_x, int i) { const int sz = points.size(); -start: - if (i < 0 || sz == 0) - return QPointF(0, 0); + if (!(max_x > 0)) + { + if (i < 0 || sz == 0) + return QPointF(0, 0); + + if (i < sz) + return points[i]; - if (i < sz) + return points[sz - 1]; + } + else { - if (max_x > 0 && max_x < points[i]) + do { - i--; - goto start; - } - return points[i]; - } + QPointF ret; - if (max_x > 0 && max_x < points[sz - 1]) - { - i = sz - 2; - goto start; - } + if (i < 0 || sz == 0) + return QPointF(0, 0); + + if (i < sz) + ret = points[i]; + else + ret = points[sz - 1]; - return points[sz - 1]; + if (!(ret.x() > max_x)) + return ret; + else + i--; + } + while (1); + } } bool spline::sort_fn(const QPointF& one, const QPointF& two) @@ -212,10 +222,10 @@ void spline::update_interp_data() for (int i = 0; i < points.size(); i++) { - const QPointF p0 = ensure_in_bounds(points, i - 1); - const QPointF p1 = ensure_in_bounds(points, i + 0); - const QPointF p2 = ensure_in_bounds(points, i + 1); - const QPointF p3 = ensure_in_bounds(points, i + 2); + const QPointF p0 = ensure_in_bounds(points, max_x, i - 1); + const QPointF p1 = ensure_in_bounds(points, max_x, i + 0); + const QPointF p2 = ensure_in_bounds(points, max_x, i + 1); + const QPointF p3 = ensure_in_bounds(points, max_x, i + 2); const double p0_x = p0.x(), p1_x = p1.x(), p2_x = p2.x(), p3_x = p3.x(); const double p0_y = p0.y(), p1_y = p1.y(), p2_y = p2.y(), p3_y = p3.y(); @@ -395,9 +405,6 @@ void spline::recompute() { QPointF& pt(list[i]); - pt.setX(clamp(pt.x(), 0, max_x)); - pt.setY(clamp(pt.y(), 0, max_y)); - const bool overlap = progn( for (int j = 0; j < i; j++) { diff --git a/spline-widget/spline.hpp b/spline-widget/spline.hpp index 660757f2..ade7f69a 100644 --- a/spline-widget/spline.hpp +++ b/spline-widget/spline.hpp @@ -48,7 +48,7 @@ class OPENTRACK_SPLINE_EXPORT spline final void add_lone_point(); static bool sort_fn(const QPointF& one, const QPointF& two); - static QPointF ensure_in_bounds(const QList& points, int i); + static QPointF ensure_in_bounds(const QList& points, double max_x, int i); mem s; QMetaObject::Connection connection; -- cgit v1.2.3