Cleaned up GradientBase.

This commit is contained in:
Relintai 2022-06-12 13:47:09 +02:00
parent 240871c517
commit a4276b11d0
2 changed files with 82 additions and 131 deletions

View File

@ -1,137 +1,91 @@
#include "gradient_base.h"
int GradientBase::get_interpolation_type() const {
return interpolation_type;
return interpolation_type;
}
void GradientBase::set_interpolation_type(const int val) {
interpolation_type = val;
interpolation_type = val;
set_dirty(true);
}
PoolRealArray GradientBase::get_points() {
return points;
return points;
}
void GradientBase::set_points(const PoolRealArray &val) {
points = val;
points = val;
set_dirty(true);
}
//tool;
//var Gradients = preload("res://addons/mat_maker_gd/nodes/common/gradients.gd");
//export(int) ;
// setget set_interpolation_type, get_interpolation_type;
int interpolation_type = 1;
//export(PoolRealArray) ;
PoolRealArray points = PoolRealArray();
Color GradientBase::get_gradient_color(const float x) {
// if interpolation_type == 0:;
// return Gradients.gradient_type_1(x, points);
// elif interpolation_type == 1:;
// return Gradients.gradient_type_2(x, points);
// elif interpolation_type == 2:;
// return Gradients.gradient_type_3(x, points);
// elif interpolation_type == 3:;
// return Gradients.gradient_type_4(x, points);
return Color(1, 1, 1, 1);
Color GradientBase::get_gradient_color(const float x) {
// if interpolation_type == 0:;
// return Gradients.gradient_type_1(x, points);
// elif interpolation_type == 1:;
// return Gradients.gradient_type_2(x, points);
// elif interpolation_type == 2:;
// return Gradients.gradient_type_3(x, points);
// elif interpolation_type == 3:;
// return Gradients.gradient_type_4(x, points);
return Color(1, 1, 1, 1);
}
int GradientBase::get_interpolation_type() {
return interpolation_type;
float GradientBase::get_point_value(const int index) {
return points[index * 5];
}
void GradientBase::set_interpolation_type(const int val) {
interpolation_type = val;
set_dirty(true);
Color GradientBase::get_point_color(const int index) {
int indx = index * 5;
return Color(points[indx + 1], points[indx + 2], points[indx + 3], points[indx + 4]);
}
void GradientBase::add_point(const float val, const Color &color) {
int s = points.size();
PoolRealArray GradientBase::get_points() {
return points;
points.resize(s + 5);
points.set(s, val);
points.set(s + 1, color.r);
points.set(s + 2, color.g);
points.set(s + 3, color.b);
points.set(s + 4, color.a);
set_dirty(true);
}
void GradientBase::set_points(const PoolRealArray &val) {
points = val;
set_dirty(true);
int GradientBase::get_point_count() {
return points.size() / 5;
}
float GradientBase::get_point_value(const int index) {
return points[index * 5];
void GradientBase::clear() {
points.resize(0);
set_dirty(true);
}
Color GradientBase::get_point_color(const int index) {
int indx = index * 5;
return Color(points[indx + 1], points[indx + 2], points[indx + 3], points[indx + 4]);
GradientBase::GradientBase() {
interpolation_type = 1;
}
void GradientBase::add_point(const float val, const Color &color) {
int s = points.size();
points.resize(s + 5);
points[s] = val;
points[s + 1] = color.r;
points[s + 2] = color.g;
points[s + 3] = color.b;
points[s + 4] = color.a;
set_dirty(true);
GradientBase::~GradientBase() {
}
void GradientBase::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_interpolation_type"), &GradientBase::get_interpolation_type);
ClassDB::bind_method(D_METHOD("set_interpolation_type", "value"), &GradientBase::set_interpolation_type);
ADD_PROPERTY(PropertyInfo(Variant::INT, "interpolation_type"), "set_interpolation_type", "get_interpolation_type");
int GradientBase::get_point_count() {
return points.size() / 5;
ClassDB::bind_method(D_METHOD("get_points"), &GradientBase::get_points);
ClassDB::bind_method(D_METHOD("set_points", "value"), &GradientBase::set_points);
ADD_PROPERTY(PropertyInfo(Variant::POOL_REAL_ARRAY, "points"), "set_points", "get_points");
ClassDB::bind_method(D_METHOD("get_gradient_color", "x"), &GradientBase::get_gradient_color);
ClassDB::bind_method(D_METHOD("get_point_value", "index"), &GradientBase::get_point_value);
ClassDB::bind_method(D_METHOD("get_point_color", "index"), &GradientBase::get_point_color);
ClassDB::bind_method(D_METHOD("add_point", "val", "color"), &GradientBase::add_point);
ClassDB::bind_method(D_METHOD("get_point_count"), &GradientBase::get_point_count);
ClassDB::bind_method(D_METHOD("clear"), &GradientBase::clear);
}
void GradientBase::clear() {
points.resize(0);
set_dirty(true);
}
}
GradientBase::GradientBase() {
//#var Gradients = preload("res://addons/mat_maker_gd/nodes/common/gradients.gd");
interpolation_type = 1;
points = PoolRealArray();
}
GradientBase::~GradientBase() {
}
static void GradientBase::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_interpolation_type"), &GradientBase::get_interpolation_type);
ClassDB::bind_method(D_METHOD("set_interpolation_type", "value"), &GradientBase::set_interpolation_type);
ADD_PROPERTY(PropertyInfo(Variant::INT, "interpolation_type"), "set_interpolation_type", "get_interpolation_type");
ClassDB::bind_method(D_METHOD("get_points"), &GradientBase::get_points);
ClassDB::bind_method(D_METHOD("set_points", "value"), &GradientBase::set_points);
ADD_PROPERTY(PropertyInfo(Variant::POOL_REAL_ARRAY, "points"), "set_points", "get_points");
ClassDB::bind_method(D_METHOD("get_gradient_color", "x"), &GradientBase::get_gradient_color);
ClassDB::bind_method(D_METHOD("get_interpolation_type"), &GradientBase::get_interpolation_type);
ClassDB::bind_method(D_METHOD("set_interpolation_type", "val"), &GradientBase::set_interpolation_type);
ClassDB::bind_method(D_METHOD("get_points"), &GradientBase::get_points);
ClassDB::bind_method(D_METHOD("set_points", "val"), &GradientBase::set_points);
ClassDB::bind_method(D_METHOD("get_point_value", "index"), &GradientBase::get_point_value);
ClassDB::bind_method(D_METHOD("get_point_color", "index"), &GradientBase::get_point_color);
ClassDB::bind_method(D_METHOD("add_point", "val", "color"), &GradientBase::add_point);
ClassDB::bind_method(D_METHOD("get_point_count"), &GradientBase::get_point_count);
ClassDB::bind_method(D_METHOD("clear"), &GradientBase::clear);
}

View File

@ -1,43 +1,40 @@
#ifndef GRADIENT_BASE_H
#define GRADIENT_BASE_H
#include "core/color.h"
#include "core/variant.h"
#include "../mm_node.h"
class GradientBase : public MMNode {
GDCLASS(GradientBase, MMNode);
GDCLASS(GradientBase, MMNode);
public:
public:
int get_interpolation_type() const;
void set_interpolation_type(const int val);
int get_interpolation_type() const;
void set_interpolation_type(const int val);
PoolRealArray get_points();
void set_points(const PoolRealArray &val);
PoolRealArray get_points();
void set_points(const PoolRealArray &val);
Color get_gradient_color(const float x);
Color get_gradient_color(const float x);
int get_interpolation_type();
void set_interpolation_type(const int val);
PoolRealArray get_points();
void set_points(const PoolRealArray &val);
float get_point_value(const int index);
Color get_point_color(const int index);
void add_point(const float val, const Color &color);
int get_point_count();
void clear();
float get_point_value(const int index);
Color get_point_color(const int index);
GradientBase();
~GradientBase();
void add_point(const float val, const Color &color);
protected:
static void _bind_methods();
int get_point_count();
//tool
//var Gradients = preload("res://addons/mat_maker_gd/nodes/common/gradients.gd")
//export(int)
// setget set_interpolation_type, get_interpolation_type
int interpolation_type = 1;
//export(PoolRealArray)
PoolRealArray points = PoolRealArray();
void clear();
GradientBase();
~GradientBase();
protected:
static void _bind_methods();
int interpolation_type;
PoolRealArray points;
};
#endif