Initial cleanup pass on CurveBase.

This commit is contained in:
Relintai 2022-06-12 00:54:08 +02:00
parent c2311362fd
commit 4943aa9569
2 changed files with 206 additions and 255 deletions

View File

@ -1,113 +1,80 @@
#include "curve_base.h"
Variant CurveBase::get_Variant() {
return Variant;
}
void CurveBase::set_Variant(const Variant &val) {
Variant = val;
}
//tool;
Vector2 Point::get_p() {
Vector2 CurveBase::Point::get_p() {
return p;
}
void Point::set_p(const Vector2 &val) {
void CurveBase::Point::set_p(const Vector2 &val) {
p = val;
}
float Point::get_ls() const {
float CurveBase::Point::get_ls() const {
return ls;
}
void Point::set_ls(const float val) {
void CurveBase::Point::set_ls(const float val) {
ls = val;
}
float Point::get_rs() const {
float CurveBase::Point::get_rs() const {
return rs;
}
void Point::set_rs(const float val) {
void CurveBase::Point::set_rs(const float val) {
rs = val;
}
CurveBase::Point::Point() {
ls = 0;
rs = 0;
}
Vector2 p = ;
float ls = ;
float rs = ;
void Point::_init(const float x, const float y, const float nls, const float nrs) {
CurveBase::Point::Point(const float x, const float y, const float nls, const float nrs) {
p = Vector2(x, y);
ls = nls;
rs = nrs;
}
//export(PoolRealArray) ;
CurveBase::Point::~Point() {
}
Point::Point() {
p = ;
ls = ;
rs = ;
}
Point::~Point() {
}
static void Point::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_p"), &Point::get_p);
ClassDB::bind_method(D_METHOD("set_p", "value"), &Point::set_p);
void CurveBase::Point::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_p"), &CurveBase::Point::get_p);
ClassDB::bind_method(D_METHOD("set_p", "value"), &CurveBase::Point::set_p);
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "p"), "set_p", "get_p");
ClassDB::bind_method(D_METHOD("get_ls"), &Point::get_ls);
ClassDB::bind_method(D_METHOD("set_ls", "value"), &Point::set_ls);
ClassDB::bind_method(D_METHOD("get_ls"), &CurveBase::Point::get_ls);
ClassDB::bind_method(D_METHOD("set_ls", "value"), &CurveBase::Point::set_ls);
ADD_PROPERTY(PropertyInfo(Variant::REAL, "ls"), "set_ls", "get_ls");
ClassDB::bind_method(D_METHOD("get_rs"), &Point::get_rs);
ClassDB::bind_method(D_METHOD("set_rs", "value"), &Point::set_rs);
ClassDB::bind_method(D_METHOD("get_rs"), &CurveBase::Point::get_rs);
ClassDB::bind_method(D_METHOD("set_rs", "value"), &CurveBase::Point::set_rs);
ADD_PROPERTY(PropertyInfo(Variant::REAL, "rs"), "set_rs", "get_rs");
ClassDB::bind_method(D_METHOD("_init", "x", "y", "nls", "nrs"), &Point::_init);
}
PoolRealArray CurveBase::get_points() {
return points;
}
Variant ;
void CurveBase::set_points(const PoolRealArray &val) {
points = val;
}
void CurveBase::init_points_01() {
if (points.size() == 0) {
points = [ 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 0.0 ];
}
}
void CurveBase::init_points_11() {
if (points.size() == 0) {
points = [ 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0 ];
}
}
String CurveBase::to_string() {
Variant = PoolStringArray();
PoolStringArray rv;
for (p in points) {
rv.append("(" + str(p.x) + "," + str(p.y) + "," + str(p.ls) + "," + str(p.rs) + ")");
@ -116,13 +83,11 @@ Variant = val;
return rv.join(",");
}
void CurveBase::clear() {
points.clear();
curve_changed();
}
void CurveBase::add_point(const float x, const float y, const float ls, const float rs) {
int indx = points.size() / 4;
@ -130,12 +95,10 @@ Variant = val;
int ii = i * 4;
if (x < points[ii]) {
if (ls == INF) {
ls == 0;
}
if (rs == INF) {
rs == 0;
}
@ -147,7 +110,6 @@ Variant = val;
curve_changed();
return;
}
}
points.append(x);
@ -157,16 +119,12 @@ Variant = val;
curve_changed();
}
bool CurveBase::remove_point(const int i) {
int index = i * 4;
if (index <= 0 || index >= points.size() - 1) {
return false;
}
else {
} else {
points.remove(index);
points.remove(index);
points.remove(index);
@ -177,12 +135,10 @@ Variant = val;
return true;
}
int CurveBase::get_point_count() {
return points.size() / 4;
}
void CurveBase::set_point(const int i, const Point &v) {
int indx = i * 4;
points[indx + 0] = v.p.x;
@ -192,13 +148,11 @@ Variant = val;
curve_changed();
}
Point CurveBase::get_point(const int i) {
int indx = i * 4;
return Point.new(points[indx + 0], points[indx + 1], points[indx + 2], points[indx + 3]);
}
Array CurveBase::get_points() {
Array arr = Array();
int c = get_point_count();
@ -210,7 +164,6 @@ Variant = val;
return arr;
}
void CurveBase::set_points(const Array &arr, const bool notify) {
points.resize(0);
@ -221,54 +174,48 @@ Variant = val;
points.append(p.rs);
}
if (notify) {
curve_changed();
}
}
void CurveBase::curve_changed() {
_curve_changed();
}
void CurveBase::_curve_changed() {
emit_changed();
}
}
CurveBase::CurveBase() {
;
}
CurveBase::~CurveBase() {
}
static void CurveBase::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_Variant"), &CurveBase::get_Variant);
ClassDB::bind_method(D_METHOD("set_Variant", "value"), &CurveBase::set_Variant);
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "Variant", PROPERTY_HINT_RESOURCE_TYPE, "Variant"), "set_Variant", "get_Variant");
ClassDB::bind_method(D_METHOD("init_points_01"), &CurveBase::init_points_01);
ClassDB::bind_method(D_METHOD("init_points_11"), &CurveBase::init_points_11);
ClassDB::bind_method(D_METHOD("to_string"), &CurveBase::to_string);
ClassDB::bind_method(D_METHOD("clear"), &CurveBase::clear);
ClassDB::bind_method(D_METHOD("add_point", "x", "y", "ls", "rs"), &CurveBase::add_point, INF, INF);
ClassDB::bind_method(D_METHOD("remove_point", "i"), &CurveBase::remove_point);
ClassDB::bind_method(D_METHOD("get_point_count"), &CurveBase::get_point_count);
ClassDB::bind_method(D_METHOD("set_point", "i", "v"), &CurveBase::set_point);
ClassDB::bind_method(D_METHOD("get_point", "i"), &CurveBase::get_point);
ClassDB::bind_method(D_METHOD("get_points"), &CurveBase::get_points);
ClassDB::bind_method(D_METHOD("set_points", "arr", "notify"), &CurveBase::set_points, true);
ClassDB::bind_method(D_METHOD("curve_changed"), &CurveBase::curve_changed);
ClassDB::bind_method(D_METHOD("_curve_changed"), &CurveBase::_curve_changed);
}

View File

@ -1,18 +1,16 @@
#ifndef CURVE_BASE_H
#define CURVE_BASE_H
#include "core/variant.h"
#include "../mm_node.h"
class CurveBase : public MMNode {
GDCLASS(CurveBase, MMNode);
public:
Variant get_Variant();
void set_Variant(const Variant &val);
class Point {
public:
Vector2 get_p();
void set_p(const Vector2 &val);
@ -22,31 +20,39 @@ class CurveBase : public MMNode {
float get_rs() const;
void set_rs(const float val);
void _init(const float x, const float y, const float nls, const float nrs);
Point();
Point(const float x, const float y, const float nls, const float nrs);
~Point();
protected:
static void _bind_methods();
Vector2 p = ;
float ls = ;
float rs = ;
//export(PoolRealArray)
Vector2 p;
float ls;
float rs;
};
public:
PoolRealArray get_points();
void set_points(const PoolRealArray &val);
void init_points_01();
void init_points_11();
String to_string();
void clear();
void add_point(const float x, const float y, const float ls = INF, const float rs = INF);
bool remove_point(const int i);
int get_point_count();
void set_point(const int i, const Point &v);
Point get_point(const int i);
Array get_points();
void set_points(const Array &arr, const bool notify = true);
void curve_changed();
void _curve_changed();
@ -56,9 +62,7 @@ class CurveBase : public MMNode {
protected:
static void _bind_methods();
//tool
Variant ;
PoolRealArray points;
};
#endif