]> git.sesse.net Git - kdenlive/blob - src/beziercurve/cubicbezierspline.h
Add bézier color curves GUI (WIP)
[kdenlive] / src / beziercurve / cubicbezierspline.h
1 /***************************************************************************
2  *   Copyright (C) 2010 by Till Theato (root@ttill.de)                     *
3  *   This file is part of Kdenlive (www.kdenlive.org).                     *
4  *                                                                         *
5  *   Kdenlive is free software: you can redistribute it and/or modify      *
6  *   it under the terms of the GNU General Public License as published by  *
7  *   the Free Software Foundation, either version 2 of the License, or     *
8  *   (at your option) any later version.                                   *
9  *                                                                         *
10  *   Kdenlive is distributed in the hope that it will be useful,           *
11  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
12  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
13  *   GNU General Public License for more details.                          *
14  *                                                                         *
15  *   You should have received a copy of the GNU General Public License     *
16  *   along with Kdenlive.  If not, see <http://www.gnu.org/licenses/>.     *
17  ***************************************************************************/
18
19 #ifndef CUBICBEZIERSPLINE_H
20 #define CUBICBEZIERSPLINE_H
21
22
23 #include <QtCore>
24
25 class BPoint
26 {
27 public:
28     QPointF h1;     // handle 1
29     QPointF p;      // point
30     QPointF h2;     // handle 2
31
32     bool operator==(const BPoint &point) const { return point.h1 == h1 && point.p == p && point.h2 == h2; }
33 };
34
35 class CubicBezierSpline : public QObject
36 {
37     Q_OBJECT
38
39 public:
40     CubicBezierSpline(QObject* parent = 0);
41     CubicBezierSpline(const CubicBezierSpline &spline, QObject* parent = 0);
42     CubicBezierSpline& operator=(const CubicBezierSpline &spline);
43
44     void fromString(const QString &spline);
45     QString toString() const;
46
47     QList <BPoint> points();
48     qreal value(qreal x, bool cont = false);
49
50     int setPoint(int ix, const BPoint &point);
51     int addPoint(const BPoint &point);
52     void removePoint(int ix);
53     void setPrecision(int pre);
54     int getPrecision();
55
56 private:
57     QPointF point(double t, const QList<QPointF> &points);
58     void validatePoints();
59     void keepSorted();
60     void update();
61
62     QList <BPoint> m_points;
63     QMap <double, double> m_spline;
64     QMap <double, double>::const_iterator m_i;
65     bool m_validSpline;
66     int m_precision;
67     
68 };
69
70 #endif