Cleaned up SlopePoint.

This commit is contained in:
Relintai 2022-06-12 15:24:10 +02:00
parent 7923375f8e
commit db18d2b5b2
2 changed files with 83 additions and 129 deletions

View File

@ -1,7 +1,6 @@
#include "slope_point.h" #include "slope_point.h"
float SlopePoint::get_distance() const { float SlopePoint::get_distance() const {
return distance; return distance;
} }
@ -10,127 +9,85 @@ void SlopePoint::set_distance(const float val) {
distance = val; distance = val;
} }
Variant SlopePoint::get_moving() {
Variant SlopePoint::get_Variant() { return moving;
return Variant;
} }
void SlopePoint::set_Variant(const Variant &val) { void SlopePoint::set_moving(const bool val) {
Variant = val; moving = val;
} }
//tool;
//export ;
float distance = ;
Variant = false;
const OFFSET = -Vector2(0, 0);
void SlopePoint::_ready() {
// Replace with function body.;
pass;
}
void SlopePoint::_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);
draw_circle(Vector2(3.0, 3.0), 3.0, color);
}
void SlopePoint::_on_ControlPoint_gui_input(const Variant &event) { void SlopePoint::_on_ControlPoint_gui_input(const Variant &event) {
Ref<InputEventMouseButton> iemb = event;
Ref<InputEventMouseMotion> iemm = event;
if (event is InputEventMouseButton) { if (iemb.is_valid()) {
if (iemb->get_button_index() == BUTTON_LEFT) {
if (event.button_index == BUTTON_LEFT) { if (iemb->is_pressed()) {
if (iemb->is_doubleclick()) {
if (event.pressed) { Control *parent = get_parent_control();
Vector2 vector;
if (event.doubleclick) {
Variant = get_parent();
Vector2 vector = ;
if (get_index() == 0) { if (get_index() == 0) {
vector = parent.rect_position-parent.get_parent().get_child(parent.get_index()-1).rect_position; vector = parent->get_position() - Object::cast_to<Control>(parent->get_parent()->get_child(parent->get_index() - 1))->get_position();
} } else {
vector = Object::cast_to<Control>(parent->get_parent()->get_child(parent->get_index() + 1))->get_position() - parent->get_position();
else {
vector = parent.get_parent().get_child(parent.get_index()+1).rect_position-parent.rect_position;
} }
vector = distance * vector.normalized(); vector = distance * vector.normalized();
rect_position = vector-OFFSET; set_position(vector - OFFSET);
if (event.control) { if (iemb->get_control()) {
get_parent().get_child(1-get_index()).rect_position = -vector-OFFSET; Object::cast_to<Control>(get_parent()->get_child(1 - get_index()))->get_position() = -vector - OFFSET;
} }
get_parent().update_tangents(); get_parent()->call("update_tangents");
} } else {
else {
moving = true; moving = true;
} }
} else {
}
else {
moving = false; moving = false;
} }
} }
} else if (moving && iemm.is_valid()) {
} Vector2 vector = get_global_mouse_position() - get_parent_control()->get_global_rect().position + OFFSET;
vector *= SGN(vector.x);
else if (moving && event is InputEventMouseMotion) {
Variant = get_global_mouse_position()-get_parent().get_global_rect().position+OFFSET;
vector *= sign(vector.x);
vector = distance * vector.normalized(); vector = distance * vector.normalized();
rect_position = vector-OFFSET; set_position(vector - OFFSET);
if (event.control) { if (iemm->get_control()) {
get_parent().get_child(1-get_index()).rect_position = -vector-OFFSET; Object::cast_to<Control>(get_parent()->get_child(1 - get_index()))->get_position() = -vector - OFFSET;
} }
get_parent().update_tangents(); get_parent()->call("update_tangents");
} }
}
} }
SlopePoint::SlopePoint() { SlopePoint::SlopePoint() {
distance = ; distance = 0;
= false; moving = false;
} }
SlopePoint::~SlopePoint() { SlopePoint::~SlopePoint() {
} }
void SlopePoint::_notification(int p_what) {
if (p_what == NOTIFICATION_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);
draw_circle(Vector2(3.0, 3.0), 3.0, color);
}
}
static void SlopePoint::_bind_methods() { void SlopePoint::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_distance"), &SlopePoint::get_distance); ClassDB::bind_method(D_METHOD("get_distance"), &SlopePoint::get_distance);
ClassDB::bind_method(D_METHOD("set_distance", "value"), &SlopePoint::set_distance); ClassDB::bind_method(D_METHOD("set_distance", "value"), &SlopePoint::set_distance);
ADD_PROPERTY(PropertyInfo(Variant::REAL, "distance"), "set_distance", "get_distance"); ADD_PROPERTY(PropertyInfo(Variant::REAL, "distance"), "set_distance", "get_distance");
ClassDB::bind_method(D_METHOD("get_moving"), &SlopePoint::get_moving);
ClassDB::bind_method(D_METHOD("set_moving", "value"), &SlopePoint::set_moving);
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "moving"), "set_moving", "get_moving");
ClassDB::bind_method(D_METHOD("get_Variant"), &SlopePoint::get_Variant);
ClassDB::bind_method(D_METHOD("set_Variant", "value"), &SlopePoint::set_Variant);
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "Variant", PROPERTY_HINT_RESOURCE_TYPE, "Variant"), "set_Variant", "get_Variant");
ClassDB::bind_method(D_METHOD("_ready"), &SlopePoint::_ready);
ClassDB::bind_method(D_METHOD("_draw"), &SlopePoint::_draw);
ClassDB::bind_method(D_METHOD("_on_ControlPoint_gui_input", "event"), &SlopePoint::_on_ControlPoint_gui_input); ClassDB::bind_method(D_METHOD("_on_ControlPoint_gui_input", "event"), &SlopePoint::_on_ControlPoint_gui_input);
} }

View File

@ -1,34 +1,31 @@
#ifndef SLOPE_POINT_H #ifndef SLOPE_POINT_H
#define SLOPE_POINT_H #define SLOPE_POINT_H
#include "scene/gui/control.h"
class SlopePoint : public Control { class SlopePoint : public Control {
GDCLASS(SlopePoint, Control); GDCLASS(SlopePoint, Control);
public: public:
float get_distance() const; float get_distance() const;
void set_distance(const float val); void set_distance(const float val);
Variant get_Variant(); Variant get_moving();
void set_Variant(const Variant &val); void set_moving(const bool val);
void _ready();
void _draw();
void _on_ControlPoint_gui_input(const Variant &event); void _on_ControlPoint_gui_input(const Variant &event);
SlopePoint(); SlopePoint();
~SlopePoint(); ~SlopePoint();
protected: protected:
void _notification(int p_what);
static void _bind_methods(); static void _bind_methods();
//tool float distance;
//export bool moving;
float distance = ; const Vector2 OFFSET = -Vector2(0, 0);
Variant = false;
const OFFSET = -Vector2(0, 0);
}; };
#endif #endif