OpenShot Library | libopenshot  0.1.9
Coordinate.h
Go to the documentation of this file.
1 /**
2  * @file
3  * @brief Header file for Coordinate 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_COORDINATE_H
29 #define OPENSHOT_COORDINATE_H
30 
31 #include <iostream>
32 #include "Exceptions.h"
33 #include "Fraction.h"
34 #include "Json.h"
35 
36 using namespace std;
37 
38 namespace openshot {
39 
40  /**
41  * @brief This class represents a Cartesian coordinate (X, Y) used in the Keyframe animation system.
42  *
43  * Animation involves the changing (i.e. interpolation) of numbers over time. A series of Coordinate
44  * objects allows us to plot a specific curve or line used during interpolation. In other words, it helps us
45  * control how a number changes over time (quickly or slowly).
46  *
47  * Please see the following <b>Example Code</b>:
48  * \code
49  * Coordinate c1(2,4);
50  * assert(c1.X == 2.0f);
51  * assert(c1.Y == 4.0f);
52  * \endcode
53  */
54  class Coordinate {
55  private:
56  bool increasing; ///< Is the Y value increasing or decreasing?
57  Fraction repeated; ///< Fraction of repeated Y values (for example, 1/3 would be the first Y value of 3 repeated values)
58  double delta; ///< This difference in Y value (from the previous unique Y value)
59 
60  public:
61  double X; ///< The X value of the coordinate (usually representing the frame #)
62  double Y; ///< The Y value of the coordinate (usually representing the value of the property being animated)
63 
64  /// The default constructor, which defaults to (0,0)
65  Coordinate();
66 
67  /// @brief Constructor which also sets the X and Y
68  /// @param x The X coordinate (usually representing the frame #)
69  /// @param y The Y coordinate (usually representing the value of the property being animated)
70  Coordinate(double x, double y);
71 
72  /// @brief Set the repeating Fraction (used internally on the timeline, to track changes to coordinates)
73  /// @param is_repeated The fraction representing how many times this coordinate Y value repeats (only used on the timeline)
74  void Repeat(Fraction is_repeated) { repeated=is_repeated; }
75 
76  /// Get the repeating Fraction (used internally on the timeline, to track changes to coordinates)
77  Fraction Repeat() { return repeated; }
78 
79  /// @brief Set the increasing flag (used internally on the timeline, to track changes to coordinates)
80  /// @param is_increasing Indicates if this coorindate Y value is increasing (when compared to the previous coordinate)
81  void IsIncreasing(bool is_increasing) { increasing = is_increasing; }
82 
83  /// Get the increasing flag (used internally on the timeline, to track changes to coordinates)
84  bool IsIncreasing() { return increasing; }
85 
86  /// @brief Set the delta / difference between previous coordinate value (used internally on the timeline, to track changes to coordinates)
87  /// @param new_delta Indicates how much this Y value differs from the previous Y value
88  void Delta(double new_delta) { delta=new_delta; }
89 
90  /// Get the delta / difference between previous coordinate value (used internally on the timeline, to track changes to coordinates)
91  float Delta() { return delta; }
92 
93  /// Get and Set JSON methods
94  string Json(); ///< Generate JSON string of this object
95  Json::Value JsonValue(); ///< Generate Json::JsonValue for this object
96  void SetJson(string value); ///< Load JSON string into this object
97  void SetJsonValue(Json::Value root); ///< Load Json::JsonValue into this object
98  };
99 
100 }
101 
102 #endif
float Delta()
Get the delta / difference between previous coordinate value (used internally on the timeline...
Definition: Coordinate.h:91
This class represents a Cartesian coordinate (X, Y) used in the Keyframe animation system...
Definition: Coordinate.h:54
Header file for Fraction class.
Fraction Repeat()
Get the repeating Fraction (used internally on the timeline, to track changes to coordinates) ...
Definition: Coordinate.h:77
bool IsIncreasing()
Get the increasing flag (used internally on the timeline, to track changes to coordinates) ...
Definition: Coordinate.h:84
Header file for all Exception classes.
void IsIncreasing(bool is_increasing)
Set the increasing flag (used internally on the timeline, to track changes to coordinates) ...
Definition: Coordinate.h:81
double Y
The Y value of the coordinate (usually representing the value of the property being animated) ...
Definition: Coordinate.h:62
void Repeat(Fraction is_repeated)
Set the repeating Fraction (used internally on the timeline, to track changes to coordinates) ...
Definition: Coordinate.h:74
Header file for JSON class.
This class represents a fraction.
Definition: Fraction.h:42
double X
The X value of the coordinate (usually representing the frame #)
Definition: Coordinate.h:61
This namespace is the default namespace for all code in the openshot library.
void Delta(double new_delta)
Set the delta / difference between previous coordinate value (used internally on the timeline...
Definition: Coordinate.h:88