2022-06-11 23:39:25 +02:00
|
|
|
|
|
|
|
#include "gradient_base.h"
|
|
|
|
|
|
|
|
int GradientBase::get_interpolation_type() const {
|
2022-06-12 13:47:09 +02:00
|
|
|
return interpolation_type;
|
2022-06-11 23:39:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void GradientBase::set_interpolation_type(const int val) {
|
2022-06-12 13:47:09 +02:00
|
|
|
interpolation_type = val;
|
|
|
|
set_dirty(true);
|
2022-06-11 23:39:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
PoolRealArray GradientBase::get_points() {
|
2022-06-12 13:47:09 +02:00
|
|
|
return points;
|
2022-06-11 23:39:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void GradientBase::set_points(const PoolRealArray &val) {
|
2022-06-12 13:47:09 +02:00
|
|
|
points = val;
|
|
|
|
set_dirty(true);
|
2022-06-11 23:39:25 +02:00
|
|
|
}
|
|
|
|
|
2022-06-12 13:47:09 +02:00
|
|
|
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);
|
2022-06-11 23:39:25 +02:00
|
|
|
}
|
|
|
|
|
2022-06-12 13:47:09 +02:00
|
|
|
float GradientBase::get_point_value(const int index) {
|
|
|
|
return points[index * 5];
|
2022-06-11 23:39:25 +02:00
|
|
|
}
|
|
|
|
|
2022-06-12 13:47:09 +02:00
|
|
|
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]);
|
2022-06-11 23:39:25 +02:00
|
|
|
}
|
|
|
|
|
2022-06-12 13:47:09 +02:00
|
|
|
void GradientBase::add_point(const float val, const Color &color) {
|
|
|
|
int s = points.size();
|
2022-06-11 23:39:25 +02:00
|
|
|
|
2022-06-12 13:47:09 +02:00
|
|
|
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);
|
2022-06-11 23:39:25 +02:00
|
|
|
|
2022-06-12 13:47:09 +02:00
|
|
|
set_dirty(true);
|
2022-06-11 23:39:25 +02:00
|
|
|
}
|
|
|
|
|
2022-06-12 13:47:09 +02:00
|
|
|
int GradientBase::get_point_count() {
|
|
|
|
return points.size() / 5;
|
2022-06-11 23:39:25 +02:00
|
|
|
}
|
|
|
|
|
2022-06-12 13:47:09 +02:00
|
|
|
void GradientBase::clear() {
|
|
|
|
points.resize(0);
|
|
|
|
set_dirty(true);
|
2022-06-11 23:39:25 +02:00
|
|
|
}
|
|
|
|
|
2022-06-12 13:47:09 +02:00
|
|
|
GradientBase::GradientBase() {
|
|
|
|
interpolation_type = 1;
|
2022-06-11 23:39:25 +02:00
|
|
|
}
|
|
|
|
|
2022-06-12 13:47:09 +02:00
|
|
|
GradientBase::~GradientBase() {
|
2022-06-11 23:39:25 +02:00
|
|
|
}
|
|
|
|
|
2022-06-12 13:47:09 +02:00
|
|
|
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");
|
2022-06-11 23:39:25 +02:00
|
|
|
|
2022-06-12 13:47:09 +02:00
|
|
|
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");
|
2022-06-11 23:39:25 +02:00
|
|
|
|
2022-06-12 13:47:09 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("get_gradient_color", "x"), &GradientBase::get_gradient_color);
|
2022-06-11 23:39:25 +02:00
|
|
|
|
2022-06-12 13:47:09 +02:00
|
|
|
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);
|
2022-06-11 23:39:25 +02:00
|
|
|
|
2022-06-12 13:47:09 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("add_point", "val", "color"), &GradientBase::add_point);
|
2022-06-11 23:39:25 +02:00
|
|
|
|
2022-06-12 13:47:09 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("get_point_count"), &GradientBase::get_point_count);
|
2022-06-11 23:39:25 +02:00
|
|
|
|
2022-06-12 13:47:09 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("clear"), &GradientBase::clear);
|
|
|
|
}
|