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