summaryrefslogtreecommitdiffhomepage
path: root/spline-widget/functionconfig.h
blob: ced6934a2b30a9ab7808e3e29bd8905659918c36 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/* Copyright (c) 2012-2016, 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 <QtGlobal>
#include <QList>
#include <QPointF>
#include <QString>
#include <QSettings>
#include <QMutex>
#include <vector>
#include <limits>
#include "opentrack-compat/qcopyable-mutex.hpp"

#ifdef BUILD_spline_widget
#   define SPLINE_WIDGET_EXPORT Q_DECL_EXPORT
#else
#   define SPLINE_WIDGET_EXPORT Q_DECL_IMPORT
#endif

class SPLINE_WIDGET_EXPORT Map {
private:
    static constexpr int value_count = 10000;

    struct State {
        QList<QPointF> input;
        std::vector<float> data;
    };

    int precision() const;
    void reload();
    float getValueInternal(int x);

    MyMutex _mutex;
    QPointF last_input_value;
    float max_x;
    float max_y;
    volatile bool activep;
    State cur, saved;
public:
    float maxInput() const;
    float maxOutput() const;
    Map();
    Map(float maxx, float maxy);

    float getValue(float x);
    bool getLastPoint(QPointF& point);
    void removePoint(int i);
    void removeAllPoints();

    void addPoint(QPointF pt);
    void movePoint(int idx, QPointF pt);
    const QList<QPointF> getPoints();
    void setMaxInput(float MaxInput);
    void setMaxOutput(float MaxOutput);

    void saveSettings(QSettings& settings, const QString& title);
    void loadSettings(QSettings& settings, const QString& title);
    void invalidate_unsaved_settings();

    void setTrackingActive(bool blnActive);
};