summaryrefslogtreecommitdiffhomepage
path: root/opentrack-logic/mappings.hpp
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2016-06-16 12:34:31 +0200
committerStanislaw Halik <sthalik@misaki.pl>2016-06-16 12:35:51 +0200
commit0760fe011114fa440275b487eaf766b015f40e5b (patch)
treea0141fb291b7dc1e38d16dd0eb2c767ec93b310a /opentrack-logic/mappings.hpp
parent60460f56cabe0155996adf8ba5e9f6730ef0b203 (diff)
all: split "api" into "api" and "logic"
Here, the "logic" module has all the stuff for building one's own graphical user interface. The "api" module has stuff used by other trackers. While at it, each of "api", "logic", and "compat" need their own export headers. This is because of preprocessor symbol clashes. This is all because a change in the "gui"-only dependency required a relink of all the trackers, protocols, and flters. It takes too long when building in the release configuration. With the split, only the "gui" module gets rebuilt. Since it has close to no static dependencies, it's fast enough.
Diffstat (limited to 'opentrack-logic/mappings.hpp')
-rw-r--r--opentrack-logic/mappings.hpp89
1 files changed, 89 insertions, 0 deletions
diff --git a/opentrack-logic/mappings.hpp b/opentrack-logic/mappings.hpp
new file mode 100644
index 00000000..087ea7f3
--- /dev/null
+++ b/opentrack-logic/mappings.hpp
@@ -0,0 +1,89 @@
+/* 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 "opentrack-compat/options.hpp"
+using namespace options;
+#include "spline-widget/functionconfig.h"
+#include "main-settings.hpp"
+
+class Mapping {
+public:
+ Mapping(QString primary,
+ QString secondary,
+ int max_x,
+ int max_y,
+ axis_opts& opts) :
+ curve(max_x, max_y),
+ curveAlt(max_x, max_y),
+ opts(opts),
+ name1(primary),
+ name2(secondary)
+ {
+ mem<QSettings> iniFile = group::ini_file();
+ curve.loadSettings(*iniFile, primary);
+ curveAlt.loadSettings(*iniFile, secondary);
+ }
+ Map curve;
+ Map curveAlt;
+ axis_opts& opts;
+ QString name1, name2;
+};
+
+class Mappings {
+private:
+ Mapping axes[6];
+public:
+ Mappings(std::vector<axis_opts*> opts) :
+ axes {
+ Mapping("tx","tx_alt", 100, 100, *opts[TX]),
+ Mapping("ty","ty_alt", 100, 100, *opts[TY]),
+ Mapping("tz","tz_alt", 100, 100, *opts[TZ]),
+ Mapping("rx", "rx_alt", 180, 180, *opts[Yaw]),
+ Mapping("ry", "ry_alt", 180, 180, *opts[Pitch]),
+ Mapping("rz", "rz_alt", 180, 180, *opts[Roll])
+ }
+ {}
+
+ inline Mapping& operator()(int i) { return axes[i]; }
+ inline const Mapping& operator()(int i) const { return axes[i]; }
+
+ void load_mappings()
+ {
+ mem<QSettings> iniFile = group::ini_file();
+
+ for (int i = 0; i < 6; i++)
+ {
+ axes[i].curve.loadSettings(*iniFile, axes[i].name1);
+ axes[i].curveAlt.loadSettings(*iniFile, axes[i].name2);
+ axes[i].opts.b->reload();
+ }
+ }
+ void save_mappings()
+ {
+ mem<QSettings> iniFile = group::ini_file();
+
+ for (int i = 0; i < 6; i++)
+ {
+ axes[i].curve.saveSettings(*iniFile, axes[i].name1);
+ axes[i].curveAlt.saveSettings(*iniFile, axes[i].name2);
+ axes[i].opts.b->save();
+ }
+ }
+
+ void invalidate_unsaved()
+ {
+ for (int i = 0; i < 6; i++)
+ {
+ axes[i].curve.invalidate_unsaved_settings();
+ axes[i].curveAlt.invalidate_unsaved_settings();
+ axes[i].opts.b->reload();
+ }
+ }
+};