Initial cleanup for ControlPoint.

This commit is contained in:
Relintai 2022-06-12 16:59:12 +02:00
parent 1943e7f150
commit 28720be0be
4 changed files with 171 additions and 324 deletions

View File

@ -1,233 +1,193 @@
#include "control_point.h" #include "control_point.h"
#include "slope_point.h"
Variant ControlPoint::get_Variant() { #include "core/math/math_defs.h"
return Variant;
}
void ControlPoint::set_Variant(const Variant &val) {
Variant = val;
}
bool ControlPoint::get_moving() const { bool ControlPoint::get_moving() const {
return moving; return moving;
} }
void ControlPoint::set_moving(const bool val) { void ControlPoint::set_moving(const bool val) {
moving = val; moving = val;
} }
float ControlPoint::get_min_x() const { float ControlPoint::get_min_x() const {
return min_x; return min_x;
} }
void ControlPoint::set_min_x(const float val) { void ControlPoint::set_min_x(const float val) {
min_x = val; min_x = val;
} }
float ControlPoint::get_max_x() const { float ControlPoint::get_max_x() const {
return max_x; return max_x;
} }
void ControlPoint::set_max_x(const float val) { void ControlPoint::set_max_x(const float val) {
max_x = val; max_x = val;
} }
float ControlPoint::get_min_y() const { float ControlPoint::get_min_y() const {
return min_y; return min_y;
} }
void ControlPoint::set_min_y(const float val) { void ControlPoint::set_min_y(const float val) {
min_y = val; min_y = val;
} }
float ControlPoint::get_max_y() const { float ControlPoint::get_max_y() const {
return max_y; return max_y;
} }
void ControlPoint::set_max_y(const float val) { void ControlPoint::set_max_y(const float val) {
max_y = val; max_y = val;
} }
void ControlPoint::_draw() {
// var current_theme : Theme = get_node("/root/MainWindow").theme;
// var color : Color = current_theme.get_color("font_color", "Label");
Color color = Color(1, 1, 1, 1);
for (int i = 0; i < get_child_count(); ++i) {
Control *c = Object::cast_to<Control>(get_child(i));
//tool; if (!c) {
//var MMCurve = preload("res://addons/mat_maker_gd/nodes/bases/curve_base.gd"); continue;
bool moving = false; }
float min_x = ;
float max_x = ;
float min_y = ;
float max_y = ;
const OFFSET : Vector2 = Vector2(3, 3);
signal moved(index);
signal removed(index);
void ControlPoint::_ready() { if (c->is_visible()) {
// Replace with function body.; draw_line(OFFSET, c->get_position() + OFFSET, color);
pass; }
}
draw_rect(Rect2(0, 0, 7, 7), color);
} }
void ControlPoint::initialize(const CurveBase::Point &p) {
set_rect_position(get_parent_control()->transform_point(p.p) - OFFSET);
void ControlPoint::_draw() { if (p.ls != Math_INF) {
// var current_theme : Theme = get_node("/root/MainWindow").theme; left_slope_point->set_position(left_slope_point->get_distance() * (get_parent_control()->get_size() * Vector2(1.0, -p.ls)).normalized());
// var color : Color = current_theme.get_color("font_color", "Label"); }
Color color = Color(1, 1, 1, 1);
for (c in get_children()) { if (p.rs != Math_INF) {
right_slope_point->set_position(right_slope_point->get_distance() * (get_parent_control()->get_size() * Vector2(1.0, -p.rs)).normalized());
if (c.visible) { }
draw_line(OFFSET, c.rect_position+OFFSET, color);
} }
void ControlPoint::set_constraint(const float x, const float X, const float y, const float Y) {
min_x = x;
max_x = X;
min_y = y;
max_y = Y;
} }
draw_rect(Rect2(0, 0, 7, 7), color); void ControlPoint::_on_ControlPoint_gui_input(const Ref<InputEvent> &event) {
Ref<InputEventMouseButton> iemb = event;
Ref<InputEventMouseMotion> iemm = event;
if (iemb.is_valid()) {
if (iemb->get_button_index() == BUTTON_LEFT) {
if (iemb->is_pressed()) {
moving = true;
} else {
moving = false;
get_parent()->update_controls();
}
} else if (iemb->get_button_index() == BUTTON_RIGHT && iemb->is_pressed()) {
emit_signal("removed", get_index());
}
} else if (moving && iemm.is_valid()) {
Vector2 rect_position = get_position();
rect_position += iemm->get_relative();
if (rect_position.x < min_x) {
rect_position.x = min_x;
} else if (rect_position.x > max_x) {
rect_position.x = max_x;
}
if (rect_position.y < min_y) {
rect_position.y = min_y;
} else if (rect_position.y > max_y) {
rect_position.y = max_y;
}
set_position(rect_position);
emit_signal("moved", get_index());
}
} }
//p : MMCurve.Point; void ControlPoint::update_tangents() {
update();
void ControlPoint::initialize(const Variant &p) { emit_signal("moved", get_index());
rect_position = get_parent().transform_point(p.p)-OFFSET;
if (p.ls != INF) {
$LeftSlope.rect_position = $LeftSlope.distance*(get_parent().rect_size*Vector2(1.0, -p.ls)).normalized();
} }
ControlPoint::ControlPoint() {
moving = false;
min_x = 0;
max_x = 0;
min_y = 0;
max_y = 0;
if (p.rs != INF) { set_custom_minimum_size(Vector2(7, 7));
$RightSlope.rect_position = $RightSlope.distance*(get_parent().rect_size*Vector2(1.0, -p.rs)).normalized();
left_slope_point = memnew(SlopePoint);
left_slope_point->set_name("LeftSlope");
add_child(left_slope_point);
left_slope_point->set_custom_minimum_size(Vector2(7, 7));
left_slope_point->set_distance(-30);
right_slope_point = memnew(SlopePoint);
right_slope_point->set_name("RightSlope");
add_child(right_slope_point);
right_slope_point->set_custom_minimum_size(Vector2(7, 7));
right_slope_point->set_distance(30);
} }
ControlPoint::~ControlPoint() {
} }
void ControlPoint::_notification(int p_what) {
void ControlPoint::set_constraint(const float x, const float X, const float y, const float Y) { if (p_what == NOTIFICATION_POSTINITIALIZE) {
min_x = x; connect("gui_input", this, "_on_ControlPoint_gui_input");
max_x = X; } else if (p_what == NOTIFICATION_DRAW) {
min_y = y; _draw();
max_y = Y; }
} }
void ControlPoint::_bind_methods() {
ADD_SIGNAL(MethodInfo("moved", PropertyInfo(Variant::INT, "index")));
ADD_SIGNAL(MethodInfo("removed", PropertyInfo(Variant::INT, "index")));
void ControlPoint::_on_ControlPoint_gui_input(const Variant &event) { ClassDB::bind_method(D_METHOD("get_moving"), &ControlPoint::get_moving);
ClassDB::bind_method(D_METHOD("set_moving", "value"), &ControlPoint::set_moving);
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "moving"), "set_moving", "get_moving");
if (event is InputEventMouseButton) { ClassDB::bind_method(D_METHOD("get_min_x"), &ControlPoint::get_min_x);
ClassDB::bind_method(D_METHOD("set_min_x", "value"), &ControlPoint::set_min_x);
ADD_PROPERTY(PropertyInfo(Variant::REAL, "min_x"), "set_min_x", "get_min_x");
if (event.button_index == BUTTON_LEFT) { ClassDB::bind_method(D_METHOD("get_max_x"), &ControlPoint::get_max_x);
ClassDB::bind_method(D_METHOD("set_max_x", "value"), &ControlPoint::set_max_x);
ADD_PROPERTY(PropertyInfo(Variant::REAL, "max_x"), "set_max_x", "get_max_x");
if (event.pressed) { ClassDB::bind_method(D_METHOD("get_min_y"), &ControlPoint::get_min_y);
moving = true; ClassDB::bind_method(D_METHOD("set_min_y", "value"), &ControlPoint::set_min_y);
ADD_PROPERTY(PropertyInfo(Variant::REAL, "min_y"), "set_min_y", "get_min_y");
ClassDB::bind_method(D_METHOD("get_max_y"), &ControlPoint::get_max_y);
ClassDB::bind_method(D_METHOD("set_max_y", "value"), &ControlPoint::set_max_y);
ADD_PROPERTY(PropertyInfo(Variant::REAL, "max_y"), "set_max_y", "get_max_y");
//ClassDB::bind_method(D_METHOD("_draw"), &ControlPoint::_draw);
//ClassDB::bind_method(D_METHOD("initialize", "p"), &ControlPoint::initialize);
ClassDB::bind_method(D_METHOD("set_constraint", "x", "X", "y", "Y"), &ControlPoint::set_constraint);
ClassDB::bind_method(D_METHOD("update_tangents"), &ControlPoint::update_tangents);
ClassDB::bind_method(D_METHOD("_on_ControlPoint_gui_input", "event"), &ControlPoint::_on_ControlPoint_gui_input);
} }
else {
moving = false;
get_parent().update_controls();
}
}
else if (event.button_index == BUTTON_RIGHT && event.pressed) {
emit_signal("removed", get_index());
}
}
else if (moving && event is InputEventMouseMotion) {
rect_position += event.relative;
if (rect_position.x < min_x) {
rect_position.x = min_x;
}
else if (rect_position.x > max_x) {
rect_position.x = max_x;
}
if (rect_position.y < min_y) {
rect_position.y = min_y;
}
else if (rect_position.y > max_y) {
rect_position.y = max_y;
}
emit_signal("moved", get_index());
}
}
void ControlPoint::update_tangents() {
update();
emit_signal("moved", get_index());
}
}
ControlPoint::ControlPoint() {
//var MMCurve = preload("res://addons/mat_maker_gd/nodes/bases/curve_base.gd");
moving = false;
min_x = ;
max_x = ;
min_y = ;
max_y = ;
}
ControlPoint::~ControlPoint() {
}
static void ControlPoint::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_Variant"), &ControlPoint::get_Variant);
ClassDB::bind_method(D_METHOD("set_Variant", "value"), &ControlPoint::set_Variant);
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "Variant", PROPERTY_HINT_RESOURCE_TYPE, "Variant"), "set_Variant", "get_Variant");
ClassDB::bind_method(D_METHOD("get_moving"), &ControlPoint::get_moving);
ClassDB::bind_method(D_METHOD("set_moving", "value"), &ControlPoint::set_moving);
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "moving"), "set_moving", "get_moving");
ClassDB::bind_method(D_METHOD("get_min_x"), &ControlPoint::get_min_x);
ClassDB::bind_method(D_METHOD("set_min_x", "value"), &ControlPoint::set_min_x);
ADD_PROPERTY(PropertyInfo(Variant::REAL, "min_x"), "set_min_x", "get_min_x");
ClassDB::bind_method(D_METHOD("get_max_x"), &ControlPoint::get_max_x);
ClassDB::bind_method(D_METHOD("set_max_x", "value"), &ControlPoint::set_max_x);
ADD_PROPERTY(PropertyInfo(Variant::REAL, "max_x"), "set_max_x", "get_max_x");
ClassDB::bind_method(D_METHOD("get_min_y"), &ControlPoint::get_min_y);
ClassDB::bind_method(D_METHOD("set_min_y", "value"), &ControlPoint::set_min_y);
ADD_PROPERTY(PropertyInfo(Variant::REAL, "min_y"), "set_min_y", "get_min_y");
ClassDB::bind_method(D_METHOD("get_max_y"), &ControlPoint::get_max_y);
ClassDB::bind_method(D_METHOD("set_max_y", "value"), &ControlPoint::set_max_y);
ADD_PROPERTY(PropertyInfo(Variant::REAL, "max_y"), "set_max_y", "get_max_y");
ClassDB::bind_method(D_METHOD("_ready"), &ControlPoint::_ready);
ClassDB::bind_method(D_METHOD("_draw"), &ControlPoint::_draw);
ClassDB::bind_method(D_METHOD("initialize", "p"), &ControlPoint::initialize);
ClassDB::bind_method(D_METHOD("set_constraint", "x", "X", "y", "Y"), &ControlPoint::set_constraint);
ClassDB::bind_method(D_METHOD("_on_ControlPoint_gui_input", "event"), &ControlPoint::_on_ControlPoint_gui_input);
ClassDB::bind_method(D_METHOD("update_tangents"), &ControlPoint::update_tangents);
}

View File

@ -1,116 +0,0 @@
void construct() {
//Script: res://addons/mat_maker_gd/widgets/curve_edit/control_point.gd
Control *controlpoint = memnew(Control);
controlpoint->set_name("ControlPoint");
controlpoint->set_name("ControlPoint");
//controlpoint->set("name", ControlPoint));
controlpoint->set_filename("res://addons/mat_maker_gd/widgets/curve_edit/control_point.tscn");
//controlpoint->set("filename", "res://addons/mat_maker_gd/widgets/curve_edit/control_point.tscn");
controlpoint->set_margin_left(56.986401);
//controlpoint->set("margin_left", 56.986401);
controlpoint->set_margin_top(33.8615);
//controlpoint->set("margin_top", 33.8615);
controlpoint->set_margin_right(63.986401);
//controlpoint->set("margin_right", 63.986401);
controlpoint->set_margin_bottom(40.8615);
//controlpoint->set("margin_bottom", 40.8615);
controlpoint->set_rect_position(Vector2(56.986401, 33.8615));
//controlpoint->set("rect_position", Vector2(56.986401, 33.8615));
controlpoint->set_rect_global_position(Vector2(56.986401, 33.8615));
//controlpoint->set("rect_global_position", Vector2(56.986401, 33.8615));
controlpoint->set_rect_size(Vector2(7, 7));
//controlpoint->set("rect_size", Vector2(7, 7));
controlpoint->set_rect_min_size(Vector2(7, 7));
//controlpoint->set("rect_min_size", Vector2(7, 7));
//controlpoint property __meta__ TYPE_DICTIONARY value: {_edit_use_anchors_:False}
//Script: res://addons/mat_maker_gd/widgets/curve_edit/slope_point.gd
Control *leftslope_controlpoint = memnew(Control);
leftslope_controlpoint->set_name("LeftSlope");
controlpoint->add_child(leftslope_controlpoint);
leftslope_controlpoint->set_name("LeftSlope");
//leftslope_controlpoint->set("name", LeftSlope));
//leftslope_controlpoint property owner TYPE_OBJECT value: ControlPoint:[Control:59789]
leftslope_controlpoint->set_margin_left(-18.5235);
//leftslope_controlpoint->set("margin_left", -18.5235);
leftslope_controlpoint->set_margin_right(-11.5235);
//leftslope_controlpoint->set("margin_right", -11.5235);
leftslope_controlpoint->set_margin_bottom(7);
//leftslope_controlpoint->set("margin_bottom", 7);
leftslope_controlpoint->set_rect_position(Vector2(-18.5235, 0));
//leftslope_controlpoint->set("rect_position", Vector2(-18.5235, 0));
leftslope_controlpoint->set_rect_global_position(Vector2(-18.5235, 0));
//leftslope_controlpoint->set("rect_global_position", Vector2(-18.5235, 0));
leftslope_controlpoint->set_rect_size(Vector2(7, 7));
//leftslope_controlpoint->set("rect_size", Vector2(7, 7));
leftslope_controlpoint->set_rect_min_size(Vector2(7, 7));
//leftslope_controlpoint->set("rect_min_size", Vector2(7, 7));
//leftslope_controlpoint property __meta__ TYPE_DICTIONARY value: {_edit_use_anchors_:False}
leftslope_controlpoint->set_distance(-30);
//leftslope_controlpoint->set("distance", -30);
//Script: res://addons/mat_maker_gd/widgets/curve_edit/slope_point.gd
Control *rightslope_controlpoint = memnew(Control);
rightslope_controlpoint->set_name("RightSlope");
controlpoint->add_child(rightslope_controlpoint);
rightslope_controlpoint->set_name("RightSlope");
//rightslope_controlpoint->set("name", RightSlope));
//rightslope_controlpoint property owner TYPE_OBJECT value: ControlPoint:[Control:59789]
rightslope_controlpoint->set_margin_left(15.6919);
//rightslope_controlpoint->set("margin_left", 15.6919);
rightslope_controlpoint->set_margin_right(22.6919);
//rightslope_controlpoint->set("margin_right", 22.6919);
rightslope_controlpoint->set_margin_bottom(7);
//rightslope_controlpoint->set("margin_bottom", 7);
rightslope_controlpoint->set_rect_position(Vector2(15.6919, 0));
//rightslope_controlpoint->set("rect_position", Vector2(15.6919, 0));
rightslope_controlpoint->set_rect_global_position(Vector2(15.6919, 0));
//rightslope_controlpoint->set("rect_global_position", Vector2(15.6919, 0));
rightslope_controlpoint->set_rect_size(Vector2(7, 7));
//rightslope_controlpoint->set("rect_size", Vector2(7, 7));
//rightslope_controlpoint property __meta__ TYPE_DICTIONARY value: {_edit_use_anchors_:False}
rightslope_controlpoint->set_distance(30);
//rightslope_controlpoint->set("distance", 30);
}

View File

@ -1,55 +1,56 @@
#ifndef CONTROL_POINT_H #ifndef CONTROL_POINT_H
#define CONTROL_POINT_H #define CONTROL_POINT_H
#include "scene/gui/control.h"
#include "../../../nodes/bases/curve_base.h"
class SlopePoint;
class ControlPoint : public Control { class ControlPoint : public Control {
GDCLASS(ControlPoint, Control); GDCLASS(ControlPoint, Control);
public: public:
bool get_moving() const;
void set_moving(const bool val);
Variant get_Variant(); float get_min_x() const;
void set_Variant(const Variant &val); void set_min_x(const float val);
bool get_moving() const; float get_max_x() const;
void set_moving(const bool val); void set_max_x(const float val);
float get_min_x() const; float get_min_y() const;
void set_min_x(const float val); void set_min_y(const float val);
float get_max_x() const; float get_max_y() const;
void set_max_x(const float val); void set_max_y(const float val);
float get_min_y() const; void _draw();
void set_min_y(const float val);
float get_max_y() const; void initialize(const CurveBase::Point &p);
void set_max_y(const float val); void set_constraint(const float x, const float X, const float y, const float Y);
void update_tangents();
void _ready(); void _on_ControlPoint_gui_input(const Ref<InputEvent> &event);
void _draw();
void initialize(const Variant &p);
void set_constraint(const float x, const float X, const float y, const float Y);
void _on_ControlPoint_gui_input(const Variant &event);
void update_tangents();
ControlPoint(); ControlPoint();
~ControlPoint(); ~ControlPoint();
protected: protected:
static void _bind_methods(); void _notification(int p_what);
//tool static void _bind_methods();
Variant = preload("res://addons/mat_maker_gd/nodes/bases/curve_base.gd");
bool moving = false; bool moving;
float min_x = ; float min_x;
float max_x = ; float max_x;
float min_y = ; float min_y;
float max_y = ; float max_y;
const OFFSET : Vector2 = Vector2(3, 3); const Vector2 OFFSET = Vector2(3, 3);
signal moved(index);
signal removed(index); SlopePoint *left_slope_point;
//p : MMCurve.Point SlopePoint *right_slope_point;
}; };
#endif #endif

View File

@ -72,7 +72,9 @@ SlopePoint::~SlopePoint() {
} }
void SlopePoint::_notification(int p_what) { void SlopePoint::_notification(int p_what) {
if (p_what == NOTIFICATION_DRAW) { if (p_what == NOTIFICATION_POSTINITIALIZE) {
connect("gui_input", this, "_on_ControlPoint_gui_input");
} else if (p_what == NOTIFICATION_DRAW) {
// var current_theme : Theme = get_node("/root/MainWindow").theme; // var current_theme : Theme = get_node("/root/MainWindow").theme;
// var color : Color = current_theme.get_color("font_color", "Label"); // var color : Color = current_theme.get_color("font_color", "Label");
Color color = Color(1, 1, 1, 1); Color color = Color(1, 1, 1, 1);