OpenShot Library | libopenshot  0.2.5
Point.h
Go to the documentation of this file.
1 /**
2  * @file
3  * @brief Header file for Point class
4  * @author Jonathan Thomas <jonathan@openshot.org>
5  *
6  * @ref License
7  */
8 
9 /* LICENSE
10  *
11  * Copyright (c) 2008-2019 OpenShot Studios, LLC
12  * <http://www.openshotstudios.com/>. This file is part of
13  * OpenShot Library (libopenshot), an open-source project dedicated to
14  * delivering high quality video editing and animation solutions to the
15  * world. For more information visit <http://www.openshot.org/>.
16  *
17  * OpenShot Library (libopenshot) is free software: you can redistribute it
18  * and/or modify it under the terms of the GNU Lesser General Public License
19  * as published by the Free Software Foundation, either version 3 of the
20  * License, or (at your option) any later version.
21  *
22  * OpenShot Library (libopenshot) is distributed in the hope that it will be
23  * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
24  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25  * GNU Lesser General Public License for more details.
26  *
27  * You should have received a copy of the GNU Lesser General Public License
28  * along with OpenShot Library. If not, see <http://www.gnu.org/licenses/>.
29  */
30 
31 #ifndef OPENSHOT_POINT_H
32 #define OPENSHOT_POINT_H
33 
34 #include "Coordinate.h"
35 #include "Exceptions.h"
36 #include "Json.h"
37 
38 namespace openshot
39 {
40  /**
41  * @brief This controls how a Keyframe uses this point to interpolate between two points.
42  *
43  * Bezier is a smooth curve. Linear is a straight line. Constant is a jump from the
44  * previous point to this one.
45  */
47  BEZIER, ///< Bezier curves are quadratic curves, which create a smooth curve.
48  LINEAR, ///< Linear curves are angular, straight lines between two points.
49  CONSTANT ///< Constant curves jump from their previous position to a new one (with no interpolation).
50  };
51 
52  /**
53  * @brief When BEZIER interpolation is used, the point's left and right handles are used
54  * to influence the direction of the curve.
55  *
56  * AUTO will try and adjust the handles automatically, to achieve the smoothest curves.
57  * MANUAL will leave the handles alone, making it the responsibility of the user to set them.
58  */
59  enum HandleType {
60  AUTO, ///< Automatically adjust the handles to achieve the smoothest curve
61  MANUAL ///< Do not automatically adjust handles (set them manually)
62  };
63 
64  /**
65  * @brief A Point is the basic building block of a key-frame curve.
66  *
67  * Points have a primary coordinate and a left and right handle coordinate.
68  * The handles are used to influence the direction of the curve as it
69  * moves between the primary coordinate and the next primary coordinate when the
70  * interpolation mode is BEZIER. When using LINEAR or CONSTANT, the handles are
71  * ignored.
72  *
73  * Please see the following <b>Example Code</b>:
74  * \code
75  * Coordinate c1(3,9);
76  * Point p1(c1, BEZIER);
77  * assert(c1.X == 3);
78  * assert(c1.Y == 9);
79  *
80  * \endcode
81  */
82  class Point {
83  public:
84  Coordinate co; ///< This is the primary coordinate
85  Coordinate handle_left; ///< This is the left handle coordinate (in percentages from 0 to 1)
86  Coordinate handle_right; ///< This is the right handle coordinate (in percentages from 0 to 1)
87  InterpolationType interpolation; ///< This is the interpolation mode
88  HandleType handle_type; ///< This is the handle mode
89 
90  /// Default constructor (defaults to 1,0)
91  Point();
92 
93  /// Constructor which creates a single coordinate at X=1
94  Point(float y);
95 
96  /// Constructor which also creates a Point and sets the X and Y of the Point.
97  Point(float x, float y);
98 
99  /// Constructor which also creates a Point and sets the X,Y, and interpolation of the Point.
100  Point(float x, float y, InterpolationType interpolation);
101 
102  /// Constructor which takes a coordinate
104 
105  /// Constructor which takes a coordinate and interpolation mode
107 
108  /// Constructor which takes a coordinate, interpolation mode, and handle type
110 
111  /// Set the left and right handles to a percent of the primary coordinate (0 to 1)
112  /// Defaults to a smooth curve (Ease in and out)
113  void Initialize_Handles();
114 
115  /// Set the left handle to a percent of the primary coordinate (0 to 1)
116  void Initialize_LeftHandle(float x, float y);
117 
118  /// Set the right handle to a percent of the primary coordinate (0 to 1)
119  void Initialize_RightHandle(float x, float y);
120 
121  /// Get and Set JSON methods
122  std::string Json() const; ///< Generate JSON string of this object
123  Json::Value JsonValue() const; ///< Generate Json::Value for this object
124  void SetJson(const std::string value); ///< Load JSON string into this object
125  void SetJsonValue(const Json::Value root); ///< Load Json::Value into this object
126 
127  };
128 
129 }
130 
131 #endif
Header file for Coordinate class.
Header file for all Exception classes.
Header file for JSON class.
This class represents a Cartesian coordinate (X, Y) used in the Keyframe animation system.
Definition: Coordinate.h:55
A Point is the basic building block of a key-frame curve.
Definition: Point.h:82
Coordinate handle_left
This is the left handle coordinate (in percentages from 0 to 1)
Definition: Point.h:85
void SetJson(const std::string value)
Load JSON string into this object.
Definition: Point.cpp:135
Json::Value JsonValue() const
Generate Json::Value for this object.
Definition: Point.cpp:118
void Initialize_RightHandle(float x, float y)
Set the right handle to a percent of the primary coordinate (0 to 1)
Definition: Point.cpp:105
void Initialize_LeftHandle(float x, float y)
Set the left handle to a percent of the primary coordinate (0 to 1)
Definition: Point.cpp:100
void Initialize_Handles()
Definition: Point.cpp:93
HandleType handle_type
This is the handle mode.
Definition: Point.h:88
Coordinate co
This is the primary coordinate.
Definition: Point.h:84
InterpolationType interpolation
This is the interpolation mode.
Definition: Point.h:87
Coordinate handle_right
This is the right handle coordinate (in percentages from 0 to 1)
Definition: Point.h:86
Point()
Default constructor (defaults to 1,0)
Definition: Point.cpp:37
void SetJsonValue(const Json::Value root)
Load Json::Value into this object.
Definition: Point.cpp:152
std::string Json() const
Get and Set JSON methods.
Definition: Point.cpp:111
This namespace is the default namespace for all code in the openshot library.
HandleType
When BEZIER interpolation is used, the point's left and right handles are used to influence the direc...
Definition: Point.h:59
@ AUTO
Automatically adjust the handles to achieve the smoothest curve.
Definition: Point.h:60
@ MANUAL
Do not automatically adjust handles (set them manually)
Definition: Point.h:61
InterpolationType
This controls how a Keyframe uses this point to interpolate between two points.
Definition: Point.h:46
@ CONSTANT
Constant curves jump from their previous position to a new one (with no interpolation).
Definition: Point.h:49
@ BEZIER
Bezier curves are quadratic curves, which create a smooth curve.
Definition: Point.h:47
@ LINEAR
Linear curves are angular, straight lines between two points.
Definition: Point.h:48