OpenShot Library | libopenshot 0.3.3
Loading...
Searching...
No Matches
Coordinate.cpp
Go to the documentation of this file.
1
9// Copyright (c) 2008-2019 OpenShot Studios, LLC
10//
11// SPDX-License-Identifier: LGPL-3.0-or-later
12
13#include "Coordinate.h"
14#include "Exceptions.h"
15
16using namespace openshot;
17
18// Default constructor for a coordinate, delegating to the full signature
20
21// Constructor which also allows the user to set the X and Y
22Coordinate::Coordinate(double x, double y) : X(x), Y(y) {}
23
24// Constructor which accepts a std::pair for (X, Y)
25Coordinate::Coordinate(const std::pair<double, double>& co)
26 : X(co.first), Y(co.second) {}
27
28// Generate JSON string of this object
29std::string Coordinate::Json() const {
30
31 // Return formatted string
32 return JsonValue().toStyledString();
33}
34
35// Generate Json::Value for this object
36Json::Value Coordinate::JsonValue() const {
37
38 // Create root json object
39 Json::Value root;
40 root["X"] = X;
41 root["Y"] = Y;
42 //root["increasing"] = increasing;
43 //root["repeated"] = Json::Value(Json::objectValue);
44 //root["repeated"]["num"] = repeated.num;
45 //root["repeated"]["den"] = repeated.den;
46 //root["delta"] = delta;
47
48 // return JsonValue
49 return root;
50}
51
52// Load JSON string into this object
53void Coordinate::SetJson(const std::string value) {
54
55 // Parse JSON string into JSON objects
56 try
57 {
58 const Json::Value root = openshot::stringToJson(value);
59 // Set all values that match
60 SetJsonValue(root);
61 }
62 catch (const std::exception& e)
63 {
64 // Error parsing JSON (or missing keys)
65 throw InvalidJSON("JSON is invalid (missing keys or invalid data types)");
66 }
67}
68
69// Load Json::Value into this object
70void Coordinate::SetJsonValue(const Json::Value root) {
71
72 // Set data from Json (if key is found)
73 if (!root["X"].isNull())
74 X = root["X"].asDouble();
75 if (!root["Y"].isNull())
76 Y = root["Y"].asDouble();
77}
Header file for Coordinate class.
Header file for all Exception classes.
A Cartesian coordinate (X, Y) used in the Keyframe animation system.
Definition Coordinate.h:38
void SetJsonValue(const Json::Value root)
Load Json::Value into this object.
Json::Value JsonValue() const
Generate Json::Value for this object.
std::string Json() const
Generate JSON string of this object.
void SetJson(const std::string value)
Load JSON string into this object.
double X
The X value of the coordinate (usually representing the frame #)
Definition Coordinate.h:40
double Y
The Y value of the coordinate (usually representing the value of the property being animated)
Definition Coordinate.h:41
Coordinate()
The default constructor, which defaults to (0,0)
Exception for invalid JSON.
Definition Exceptions.h:218
This namespace is the default namespace for all code in the openshot library.
Definition Compressor.h:29
const Json::Value stringToJson(const std::string value)
Definition Json.cpp:16