summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2015-07-08 05:55:32 +0200
committerStanislaw Halik <sthalik@misaki.pl>2015-07-08 05:55:59 +0200
commit527eef2a2f0e68b286e1b782ba148ecdfafbb89c (patch)
tree2be0f0b96df712f7b12534291db3c36564be62ca
parent3a54a111567370ecf903704d702d12736b693a8e (diff)
parentab47eac174db02710a7fa6c194e00c31cef755a4 (diff)
Merge branch 'unstable' into trackhat-ui
-rw-r--r--README.md2
-rw-r--r--facetracknoir/main.cpp26
-rw-r--r--facetracknoir/ui.cpp72
-rw-r--r--ftnoir_protocol_ft/ftnoir_protocol_ft.h2
-rw-r--r--ftnoir_protocol_sc/ftnoir_protocol_sc.cpp3
-rw-r--r--opentrack/mappings.hpp9
-rw-r--r--opentrack/opencv-camera-dialog.hpp23
-rw-r--r--opentrack/options.hpp2
-rw-r--r--opentrack/plugin-support.hpp13
-rw-r--r--opentrack/selected-libraries.cpp11
-rw-r--r--opentrack/selected-libraries.hpp8
-rw-r--r--opentrack/shortcuts.h8
-rw-r--r--opentrack/simple-mat.hpp8
-rw-r--r--opentrack/state.hpp8
-rw-r--r--opentrack/thread.hpp8
-rw-r--r--opentrack/timer.hpp8
-rw-r--r--opentrack/tracker.cpp1
-rw-r--r--opentrack/tracker.h10
-rw-r--r--opentrack/work.hpp8
-rw-r--r--qfunctionconfigurator/functionconfig.cpp65
-rw-r--r--qfunctionconfigurator/functionconfig.h10
-rw-r--r--qfunctionconfigurator/qfunctionconfigurator.cpp61
22 files changed, 237 insertions, 129 deletions
diff --git a/README.md b/README.md
index 85139930..4abcdf07 100644
--- a/README.md
+++ b/README.md
@@ -27,6 +27,7 @@ Not to be confused with railway planning software <<http://opentrack.ch>>
- Relaying UDP via FreePIE-specific Android app
- Joystick analog axes (Windows, Linux)
- Windows Phone [tracker](http://www.windowsphone.com/en-us/store/app/opentrack-head-tracking/1c604f32-6d68-40ef-aa44-3163e30f547f) over opentrack UDP protocol
+- Arduino with custom firmware
# Output
@@ -59,6 +60,7 @@ Don't be afraid to submit an issue/feature request if need arises.
- Ryan Spicer (OSX tester, contributor)
- Patrick Ruoff (PT tracker)
- Ulf Schreiber (PT tracker)
+- furax49 (hatire tracker)
- Andrzej Czarnowski (quality assurance)
- uglyDwarf (high CON)
- Wim Vriend (historically)
diff --git a/facetracknoir/main.cpp b/facetracknoir/main.cpp
index 6d29e3b5..326b40ec 100644
--- a/facetracknoir/main.cpp
+++ b/facetracknoir/main.cpp
@@ -60,34 +60,14 @@ int main(int argc, char** argv)
QApplication::setAttribute(Qt::AA_X11InitThreads, true);
QApplication app(argc, argv);
- QCommandLineParser p;
- p.setApplicationDescription("opentrack - Head tracking software for MS Windows, Linux, and Apple OSX");
- p.addHelpOption();
- QCommandLineOption autostartOption(QStringList() << "a" << "autostart", "Load <profile> and start tracking", "profile");
- p.addOption(autostartOption);
- p.process(app);
-
- QString profile = p.value(autostartOption);
-
- bool use_profile = profile.endsWith(".ini") && QFileInfo(profile).exists() && QFileInfo(profile).isFile();
- if (!profile.isEmpty() && !use_profile)
- QMessageBox::warning(nullptr, "Can't load profile", "Profile " + profile + " specified but can't be opened!",
- QMessageBox::Ok, QMessageBox::NoButton);
-
- if (use_profile)
- MainWindow::set_profile(profile);
-
auto w = std::make_shared<MainWindow>();
-
- if (use_profile)
- w->startTracker();
-
+
w->show();
app.exec();
- // on MSVC crashes in atexit
+ // on MSVC crashes in atexit
#ifdef _MSC_VER
- TerminateProcess(GetCurrentProcess(), 0);
+ TerminateProcess(GetCurrentProcess(), 0);
#endif
return 0;
}
diff --git a/facetracknoir/ui.cpp b/facetracknoir/ui.cpp
index 8cf14050..405c516a 100644
--- a/facetracknoir/ui.cpp
+++ b/facetracknoir/ui.cpp
@@ -310,64 +310,60 @@ void MainWindow::showHeadPose()
}
template<typename t>
-mem<t> mk_dialog(mem<dylib> lib)
+bool mk_dialog(mem<dylib> lib, mem<t>* orig)
{
+ if (*orig && (*orig)->isVisible())
+ {
+ (*orig)->show();
+ (*orig)->raise();
+ return false;
+ }
+
if (lib && lib->Dialog)
{
auto dialog = mem<t>(reinterpret_cast<t*>(lib->Dialog()));
dialog->setWindowFlags(Qt::Dialog);
dialog->setFixedSize(dialog->size());
- return dialog;
+
+ *orig = dialog;
+ dialog->show();
+ dialog->raise();
+
+ return true;
}
- return nullptr;
+ return false;
}
-
void MainWindow::showProtocolSettings() {
- if (pProtocolDialog && pProtocolDialog->isVisible())
+ if (mk_dialog(current_protocol(), &pProtocolDialog) && libs.pProtocol)
+ pProtocolDialog->register_protocol(libs.pProtocol.get());
+}
+template<typename t, typename... Args>
+bool mk_window(mem<t>* place, Args... params)
+{
+ if (*place && (*place)->isVisible())
{
- pProtocolDialog->show();
- pProtocolDialog->raise();
- } else
+ (*place)->show();
+ (*place)->raise();
+ return false;
+ }
+ else
{
- auto dialog = mk_dialog<IProtocolDialog>(current_protocol());
- if (!dialog) return;
- pProtocolDialog = dialog;
- if (libs.pProtocol != nullptr)
- dialog->register_protocol(libs.pProtocol.get());
- dialog->show();
- dialog->raise();
+ *place = std::make_shared<t>(params...);
+ (*place)->setWindowFlags(Qt::Dialog);
+ (*place)->show();
+ (*place)->raise();
+ return true;
}
}
void MainWindow::showKeyboardShortcuts() {
- if (shortcuts_widget && shortcuts_widget->isVisible())
- {
- shortcuts_widget->show();
- shortcuts_widget->raise();
- }
- else
- {
- shortcuts_widget = std::make_shared<OptionsDialog>(static_cast<State&>(*this));
- shortcuts_widget->setWindowFlags(Qt::Dialog);
+ if (mk_window<OptionsDialog, State&>(&shortcuts_widget, *this))
connect(shortcuts_widget.get(), SIGNAL(reload()), this, SLOT(bindKeyboardShortcuts()));
- shortcuts_widget->show();
- shortcuts_widget->raise();
- }
}
void MainWindow::showCurveConfiguration() {
- if (mapping_widget && mapping_widget->isVisible())
- {
- mapping_widget->show();
- mapping_widget->raise();
- }
- else
- {
- mapping_widget = std::make_shared<MapWidget>(pose, s);
- mapping_widget->setWindowFlags(Qt::Dialog);
- mapping_widget->show();
- }
+ mk_window<MapWidget, Mappings&, main_settings&>(&mapping_widget, pose, s);
}
void MainWindow::exit() {
diff --git a/ftnoir_protocol_ft/ftnoir_protocol_ft.h b/ftnoir_protocol_ft/ftnoir_protocol_ft.h
index ade6ac75..3fe9952d 100644
--- a/ftnoir_protocol_ft/ftnoir_protocol_ft.h
+++ b/ftnoir_protocol_ft/ftnoir_protocol_ft.h
@@ -38,7 +38,7 @@
#include <QMutexLocker>
#include "compat/compat.h"
#include "opentrack/options.hpp"
-#include "../freetrackclient/fttypes.h"
+#include "freetrackclient/fttypes.h"
using namespace options;
struct settings : opts {
diff --git a/ftnoir_protocol_sc/ftnoir_protocol_sc.cpp b/ftnoir_protocol_sc/ftnoir_protocol_sc.cpp
index 7d4e09f9..52db14f8 100644
--- a/ftnoir_protocol_sc/ftnoir_protocol_sc.cpp
+++ b/ftnoir_protocol_sc/ftnoir_protocol_sc.cpp
@@ -41,6 +41,9 @@ FTNoIR_Protocol::~FTNoIR_Protocol()
void FTNoIR_Protocol::run()
{
+ (void) SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_ABOVE_NORMAL);
+ (void) SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_HIGHEST);
+
HANDLE event = CreateEvent(NULL, FALSE, FALSE, nullptr);
if (event == nullptr)
diff --git a/opentrack/mappings.hpp b/opentrack/mappings.hpp
index 3336dcd8..85d9900c 100644
--- a/opentrack/mappings.hpp
+++ b/opentrack/mappings.hpp
@@ -1,9 +1,16 @@
+/* Copyright (c) 2014-2015 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 <QSettings>
#include "options.hpp"
using namespace options;
-#include "../qfunctionconfigurator/functionconfig.h"
+#include "qfunctionconfigurator/functionconfig.h"
#include "main-settings.hpp"
class Mapping {
diff --git a/opentrack/opencv-camera-dialog.hpp b/opentrack/opencv-camera-dialog.hpp
index 3b700a70..6218f125 100644
--- a/opentrack/opencv-camera-dialog.hpp
+++ b/opentrack/opencv-camera-dialog.hpp
@@ -1,5 +1,6 @@
#pragma once
+#include <QTimer>
#include <QMutex>
#include <QMutexLocker>
#include <opencv2/videoio.hpp>
@@ -9,6 +10,14 @@ template<typename tracker>
class camera_dialog
{
cv::VideoCapture fake_capture;
+ QTimer t;
+
+private:
+ void delete_capture()
+ {
+ fake_capture.open("");
+ }
+
public:
void open_camera_settings(cv::VideoCapture* cap, const QString& camera_name, QMutex* camera_mtx)
{
@@ -23,10 +32,20 @@ public:
}
}
+ if (t.isActive())
+ return;
+
+ // don't hog the camera capture
+ if (!t.isSingleShot())
+ QObject::connect(&t, &QTimer::timeout, [&]() -> void { delete_capture(); });
+
+ t.setSingleShot(true);
+ t.setInterval(3000);
+
fake_capture = cv::VideoCapture(camera_name_to_index(camera_name));
fake_capture.set(cv::CAP_PROP_SETTINGS, 1);
- // don't hog the camera capture
- fake_capture.open("");
+ // HACK: we're not notified when it's safe to close the capture
+ t.start();
}
};
diff --git a/opentrack/options.hpp b/opentrack/options.hpp
index c2fe8705..9768bc43 100644
--- a/opentrack/options.hpp
+++ b/opentrack/options.hpp
@@ -1,4 +1,4 @@
-/* Copyright (c) 2013-2014 Stanislaw Halik
+/* Copyright (c) 2013-2015 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
diff --git a/opentrack/plugin-support.hpp b/opentrack/plugin-support.hpp
index 7f2734af..78443cae 100644
--- a/opentrack/plugin-support.hpp
+++ b/opentrack/plugin-support.hpp
@@ -1,5 +1,3 @@
-#pragma once
-
/* Copyright (c) 2015 Stanislaw Halik
*
* Permission to use, copy, modify, and/or distribute this software for any
@@ -7,6 +5,8 @@
* copyright notice and this permission notice appear in all copies.
*/
+#pragma once
+
#include "plugin-api.hpp"
#include "options.hpp"
@@ -242,3 +242,12 @@ private:
return ret;
}
};
+
+template<typename t>
+mem<t> make_dylib_instance(mem<dylib> lib)
+{
+ mem<t> ret;
+ if (lib != nullptr && lib->Constructor)
+ ret = mem<t>(reinterpret_cast<t*>(reinterpret_cast<OPENTRACK_CTOR_FUNPTR>(lib->Constructor)()));
+ return ret;
+}
diff --git a/opentrack/selected-libraries.cpp b/opentrack/selected-libraries.cpp
index d76c0111..630b7db2 100644
--- a/opentrack/selected-libraries.cpp
+++ b/opentrack/selected-libraries.cpp
@@ -5,15 +5,6 @@ SelectedLibraries::~SelectedLibraries()
{
}
-template<typename t>
-static mem<t> make_instance(mem<dylib> lib)
-{
- mem<t> ret;
- if (lib != nullptr && lib->Constructor)
- ret = mem<t>(reinterpret_cast<t*>(reinterpret_cast<OPENTRACK_CTOR_FUNPTR>(lib->Constructor)()));
- return ret;
-}
-
SelectedLibraries::SelectedLibraries(QFrame* frame, mem<ITracker> t, dylibptr p, mem<IFilter> f) :
pTracker(nullptr),
pFilter(nullptr),
@@ -21,7 +12,7 @@ SelectedLibraries::SelectedLibraries(QFrame* frame, mem<ITracker> t, dylibptr p,
correct(false)
{
pTracker = t;
- pProtocol = make_instance<IProtocol>(p);
+ pProtocol = make_dylib_instance<IProtocol>(p);
pFilter = f;
if (!pTracker || !pProtocol)
diff --git a/opentrack/selected-libraries.hpp b/opentrack/selected-libraries.hpp
index 07ea419b..547f5f54 100644
--- a/opentrack/selected-libraries.hpp
+++ b/opentrack/selected-libraries.hpp
@@ -1,3 +1,11 @@
+/* Copyright (c) 2014-2015, Stanislaw Halik <sthalik@misaki.pl>
+
+ * 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 "opentrack/plugin-support.hpp"
diff --git a/opentrack/shortcuts.h b/opentrack/shortcuts.h
index ee0d9777..520042f0 100644
--- a/opentrack/shortcuts.h
+++ b/opentrack/shortcuts.h
@@ -1,3 +1,11 @@
+/* Copyright (c) 2014-2015, Stanislaw Halik <sthalik@misaki.pl>
+
+ * 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 <QObject>
#include <QWidget>
diff --git a/opentrack/simple-mat.hpp b/opentrack/simple-mat.hpp
index 1cea967e..e111305a 100644
--- a/opentrack/simple-mat.hpp
+++ b/opentrack/simple-mat.hpp
@@ -1,3 +1,11 @@
+/* Copyright (c) 2014-2015, Stanislaw Halik <sthalik@misaki.pl>
+
+ * 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 <algorithm>
#include <initializer_list>
diff --git a/opentrack/state.hpp b/opentrack/state.hpp
index bfbf113e..e4cb0f04 100644
--- a/opentrack/state.hpp
+++ b/opentrack/state.hpp
@@ -1,3 +1,11 @@
+/* Copyright (c) 2014-2015, Stanislaw Halik <sthalik@misaki.pl>
+
+ * 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 <vector>
diff --git a/opentrack/thread.hpp b/opentrack/thread.hpp
index b1db9158..946f2972 100644
--- a/opentrack/thread.hpp
+++ b/opentrack/thread.hpp
@@ -1,3 +1,11 @@
+/* Copyright (c) 2014-2015, Stanislaw Halik <sthalik@misaki.pl>
+
+ * 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 <QDebug>
diff --git a/opentrack/timer.hpp b/opentrack/timer.hpp
index eb956213..fd710499 100644
--- a/opentrack/timer.hpp
+++ b/opentrack/timer.hpp
@@ -1,3 +1,11 @@
+/* Copyright (c) 2014-2015, Stanislaw Halik <sthalik@misaki.pl>
+
+ * 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 <ctime>
#if defined (_WIN32)
diff --git a/opentrack/tracker.cpp b/opentrack/tracker.cpp
index e39e54dd..38d95f84 100644
--- a/opentrack/tracker.cpp
+++ b/opentrack/tracker.cpp
@@ -106,7 +106,6 @@ void Tracker::logic()
dmat<3, 1> t { value(0), value(1), value(2) };
r = cam * r;
- t = cam * t;
bool can_center = false;
diff --git a/opentrack/tracker.h b/opentrack/tracker.h
index d4dc149f..453357c4 100644
--- a/opentrack/tracker.h
+++ b/opentrack/tracker.h
@@ -1,3 +1,11 @@
+/* Copyright (c) 2014-2015, Stanislaw Halik <sthalik@misaki.pl>
+
+ * 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 <vector>
@@ -9,7 +17,7 @@
#include "simple-mat.hpp"
#include "selected-libraries.hpp"
-#include "../qfunctionconfigurator/functionconfig.h"
+#include "qfunctionconfigurator/functionconfig.h"
#include "main-settings.hpp"
#include "options.hpp"
diff --git a/opentrack/work.hpp b/opentrack/work.hpp
index eb5bd4ff..39eb12fb 100644
--- a/opentrack/work.hpp
+++ b/opentrack/work.hpp
@@ -1,3 +1,11 @@
+/* Copyright (c) 2014-2015, Stanislaw Halik <sthalik@misaki.pl>
+
+ * 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 "opentrack/main-settings.hpp"
diff --git a/qfunctionconfigurator/functionconfig.cpp b/qfunctionconfigurator/functionconfig.cpp
index 70393246..7edbe0ef 100644
--- a/qfunctionconfigurator/functionconfig.cpp
+++ b/qfunctionconfigurator/functionconfig.cpp
@@ -24,7 +24,7 @@ Map::Map() :
float Map::getValue(float x) {
QMutexLocker foo(&_mutex);
- float q = x * MEMOIZE_PRECISION;
+ float q = x * precision();
int xi = (int)q;
float yi = getValueInternal(xi);
float yiplus1 = getValueInternal(xi+1);
@@ -69,46 +69,56 @@ static bool sortFn(const QPointF& one, const QPointF& two) {
void Map::reload() {
if (cur.input.size())
{
- auto& input = cur.input;
+ qStableSort(cur.input.begin(), cur.input.end(), sortFn);
+
+ QList<QPointF> input = cur.input;
auto& data = cur.data;
-
- qStableSort(input.begin(), input.end(), sortFn);
- data = std::vector<float>(MEMOIZE_PRECISION * input[input.size() - 1].x());
+
+ data = std::vector<float>(value_count);
+ const int mult = precision();
const int sz = data.size();
for (int i = 0; i < sz; i++)
data[i] = -1;
- for (int k = 0; k < input[0].x() * MEMOIZE_PRECISION; k++) {
- if (k < sz)
- data[k] = input[0].y() * k / (input[0].x() * MEMOIZE_PRECISION);
+ if (input.size() == 1)
+ {
+ for (int k = 0; k < input[0].x() * mult; k++) {
+ if (k < sz)
+ data[k] = input[0].y() * k / (input[0].x() * mult);
+ }
}
+ else if (input[0].x() > 1e-2)
+ input.prepend(QPointF(0, 0));
for (int i = 0; i < sz; i++) {
QPointF p0 = ensureInBounds(input, i - 1);
QPointF p1 = ensureInBounds(input, i);
QPointF p2 = ensureInBounds(input, i + 1);
QPointF p3 = ensureInBounds(input, i + 2);
+
+ const float p0_x = p0.x(), p1_x = p1.x(), p2_x = p2.x(), p3_x = p3.x();
+ const float p0_y = p0.y(), p1_y = p1.y(), p2_y = p2.y(), p3_y = p3.y();
- int end = std::min<int>(sz, p2.x() * MEMOIZE_PRECISION);
- int start = p1.x() * MEMOIZE_PRECISION;
+ int end = std::min<int>(sz, p2.x() * mult);
+ int start = p1.x() * mult;
for (int j = start; j < end; j++) {
- double t = (j - start) / (double) (end - start);
- double t2 = t*t;
- double t3 = t*t*t;
+ float t = (j - start) / (float) (end - start);
+ float t2 = t*t;
+ float t3 = t*t*t;
+
+ int x = .5 * ((2. * p1_x) +
+ (-p0_x + p2_x) * t +
+ (2. * p0_x - 5. * p1_x + 4. * p2_x - p3_x) * t2 +
+ (-p0_x + 3. * p1_x - 3. * p2_x + p3_x) * t3)
+ * mult;
- int x = .5 * ((2. * p1.x()) +
- (-p0.x() + p2.x()) * t +
- (2. * p0.x() - 5. * p1.x() + 4. * p2.x() - p3.x()) * t2 +
- (-p0.x() + 3. * p1.x() - 3. * p2.x() + p3.x()) * t3)
- * MEMOIZE_PRECISION;
-
- float y = .5 * ((2. * p1.y()) +
- (-p0.y() + p2.y()) * t +
- (2. * p0.y() - 5. * p1.y() + 4. * p2.y() - p3.y()) * t2 +
- (-p0.y() + 3. * p1.y() - 3. * p2.y() + p3.y()) * t3);
+ float y = .5 * ((2. * p1_y) +
+ (-p0_y + p2_y) * t +
+ (2. * p0_y - 5. * p1_y + 4. * p2_y - p3_y) * t2 +
+ (-p0_y + 3. * p1_y - 3. * p2_y + p3_y) * t3);
if (x >= 0 && x < sz)
data[x] = y;
@@ -118,7 +128,7 @@ void Map::reload() {
float last = 0;
for (int i = 0; i < sz; i++)
{
- if (data[i] <= 0)
+ if (data[i] < 0)
data[i] = last;
last = data[i];
}
@@ -216,3 +226,10 @@ void Map::saveSettings(QSettings& settings, const QString& title) {
settings.endGroup();
}
+
+
+int Map::precision() const {
+ if (cur.input.size())
+ return value_count / std::max<float>(1.f, (cur.input[cur.input.size() - 1].x()));
+ return 1;
+}
diff --git a/qfunctionconfigurator/functionconfig.h b/qfunctionconfigurator/functionconfig.h
index 4ce5efee..f7930cb2 100644
--- a/qfunctionconfigurator/functionconfig.h
+++ b/qfunctionconfigurator/functionconfig.h
@@ -14,7 +14,7 @@
#include <QSettings>
#include <QMutex>
#include <vector>
-#include "../opentrack/qcopyable-mutex.hpp"
+#include "opentrack/qcopyable-mutex.hpp"
class Map {
private:
@@ -22,8 +22,10 @@ private:
QList<QPointF> input;
std::vector<float> data;
};
-
- static constexpr long MEMOIZE_PRECISION = 25;
+
+ static constexpr int value_count = 9001;
+
+ int precision() const;
void reload();
float getValueInternal(int x);
@@ -32,7 +34,7 @@ private:
volatile bool activep;
int max_x;
int max_y;
-
+
State cur, saved;
public:
int maxInput() const { return max_x; }
diff --git a/qfunctionconfigurator/qfunctionconfigurator.cpp b/qfunctionconfigurator/qfunctionconfigurator.cpp
index e1c40396..3d86216e 100644
--- a/qfunctionconfigurator/qfunctionconfigurator.cpp
+++ b/qfunctionconfigurator/qfunctionconfigurator.cpp
@@ -1,4 +1,4 @@
-#include "../opentrack/options.hpp"
+#include "opentrack/options.hpp"
using namespace options;
#include "qfunctionconfigurator/qfunctionconfigurator.h"
#include <QPainter>
@@ -132,7 +132,7 @@ void QFunctionConfigurator::drawFunction()
QPen pen(spline_color, 1.2, Qt::SolidLine);
const double max = _config->maxInput();
- const double step = std::max(.1, max / 300.);
+ const double step = std::max(1e-2, max / 500.);
QPointF prev = point_to_pixel(QPointF(0, 0));
for (double i = 0; i < max; i += step) {
@@ -141,11 +141,6 @@ void QFunctionConfigurator::drawFunction()
drawLine(&painter, prev, cur, pen);
prev = cur;
}
- if (points.size())
- {
- auto last = point_to_pixel(points[points.size()-1]);
- drawLine(&painter, prev, last, pen);
- }
}
void QFunctionConfigurator::paintEvent(QPaintEvent *e)
@@ -259,16 +254,45 @@ void QFunctionConfigurator::mouseMoveEvent(QMouseEvent *e)
bool overlap = false;
- QPointF new_pt = pixel_coord_to_point(e->pos());
+ QPoint pix = e->pos();
+ QPointF new_pt = pixel_coord_to_point(pix);
- if (moving_control_point_idx + 1 < points.size())
- overlap |= new_pt.x() > points[moving_control_point_idx+1].x();
- if (moving_control_point_idx != 0)
- overlap |= new_pt.x() < points[moving_control_point_idx-1].x();
+ static constexpr int limit = 16;
- if (overlap)
- moving_control_point_idx = -1;
- else
+ for (int i = 0; i < 2; i++)
+ {
+ bool bad = false;
+ if (moving_control_point_idx + 1 < points.size())
+ {
+ auto other = points[moving_control_point_idx+1];
+ auto other_pix = point_to_pixel(other);
+ bad = pix.x() + limit > other_pix.x();
+ if (i == 0 && bad)
+ {
+ pix.setX(other_pix.x() - limit - 1);
+ new_pt = pixel_coord_to_point(pix);
+ }
+ else
+ overlap |= bad;
+ }
+ if (moving_control_point_idx != 0)
+ {
+ auto other = points[moving_control_point_idx-1];
+ auto other_pix = point_to_pixel(other);
+ bad = pix.x() - limit < other_pix.x();
+ if (i == 0 && bad)
+ {
+ pix.setX(other_pix.x() + limit + 1);
+ new_pt = pixel_coord_to_point(pix);
+ }
+ else
+ overlap |= bad;
+ }
+ if (!bad)
+ break;
+ }
+
+ if (!overlap)
{
points[moving_control_point_idx] = new_pt;
_config->movePoint(moving_control_point_idx, new_pt);
@@ -299,12 +323,7 @@ void QFunctionConfigurator::mouseReleaseEvent(QMouseEvent *e)
return;
if (e->button() == Qt::LeftButton) {
- QList<QPointF> points = _config->getPoints();
- if (moving_control_point_idx >= 0 && moving_control_point_idx < points.size()) {
- if (_config) {
- _config->movePoint(moving_control_point_idx, pixel_coord_to_point(e->pos()));
- }
- }
+ mouseMoveEvent(e);
setCursor(Qt::ArrowCursor);
moving_control_point_idx = -1;