From 6014b987200657b2bf0b982ae56f400d3e70438b Mon Sep 17 00:00:00 2001 From: Relintai Date: Mon, 13 Jun 2022 17:42:10 +0200 Subject: [PATCH] Mostly done ControlPoint. --- .../widgets/polygon_edit/control_point.cpp | 111 +++++++----------- .../widgets/polygon_edit/control_point.ctscn | 43 ------- .../widgets/polygon_edit/control_point.h | 33 +++--- 3 files changed, 60 insertions(+), 127 deletions(-) delete mode 100644 modules/material_maker/editor/widgets/polygon_edit/control_point.ctscn diff --git a/modules/material_maker/editor/widgets/polygon_edit/control_point.cpp b/modules/material_maker/editor/widgets/polygon_edit/control_point.cpp index f720188e9..ef2c0d058 100644 --- a/modules/material_maker/editor/widgets/polygon_edit/control_point.cpp +++ b/modules/material_maker/editor/widgets/polygon_edit/control_point.cpp @@ -1,90 +1,67 @@ #include "control_point.h" - bool ControlPoint::get_moving() const { - return moving; + return moving; } void ControlPoint::set_moving(const bool val) { -moving = val; + moving = val; } - - - //tool; - bool moving = false; - const OFFSET : Vector2 = Vector2(3, 3); - signal moved(index); - signal removed(index); - - 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); - draw_rect(Rect2(0, 0, 7, 7), color); +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); + draw_rect(Rect2(0, 0, 7, 7), color); } - - void ControlPoint::initialize(const Vector2 &p) { - rect_position = get_parent().transform_point(p) - OFFSET; +void ControlPoint::initialize(const Vector2 &p) { + set_rect_position(get_parent().transform_point(p) - OFFSET); } +void ControlPoint::_on_ControlPoint_gui_input(const Ref &event) { + Ref iemb = event; + Ref iemm = event; - void ControlPoint::_on_ControlPoint_gui_input(const Variant &event) { - - if (event is InputEventMouseButton) { - - if (event.button_index == BUTTON_LEFT) { - - if (event.pressed) { - moving = true; + 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 && event->is_pressed()) { + emit_signal("removed", get_index()); + } + } else if (moving && iemm.is_valid()) { + Vector2 rect_position = get_position(); + rect_position += iemm->get_relative(); + set_position(rect_position); + emit_signal("moved", get_index()); + } } +ControlPoint::ControlPoint() { + moving = false; - else { - moving = false; - get_parent().update_controls(); + set_custom_minimum_size(Vector2(7, 7)); } +ControlPoint::~ControlPoint() { } +void ControlPoint::_bind_methods() { + ADD_SIGNAL(MethodInfo("moved", PropertyInfo(Variant::INT, "index"))); + ADD_SIGNAL(MethodInfo("removed", PropertyInfo(Variant::INT, "index"))); - else if (event.button_index == BUTTON_RIGHT && event.pressed) { - emit_signal("removed", get_index()); + 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("_draw"), &ControlPoint::_draw); + ClassDB::bind_method(D_METHOD("initialize", "p"), &ControlPoint::initialize); + + ClassDB::bind_method(D_METHOD("_on_ControlPoint_gui_input", "event"), &ControlPoint::_on_ControlPoint_gui_input); } - -} - - - else if (moving && event is InputEventMouseMotion) { - rect_position += event.relative; - emit_signal("moved", get_index()); -} - -} - -} - - ControlPoint::ControlPoint() { - moving = false; - } - - ControlPoint::~ControlPoint() { - } - - - static void ControlPoint::_bind_methods() { - 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("_draw"), &ControlPoint::_draw); - ClassDB::bind_method(D_METHOD("initialize", "p"), &ControlPoint::initialize); - ClassDB::bind_method(D_METHOD("_on_ControlPoint_gui_input", "event"), &ControlPoint::_on_ControlPoint_gui_input); - - } - - - diff --git a/modules/material_maker/editor/widgets/polygon_edit/control_point.ctscn b/modules/material_maker/editor/widgets/polygon_edit/control_point.ctscn deleted file mode 100644 index 998fd10b6..000000000 --- a/modules/material_maker/editor/widgets/polygon_edit/control_point.ctscn +++ /dev/null @@ -1,43 +0,0 @@ - -void construct() { - -//Script: res://addons/mat_maker_gd/widgets/polygon_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/polygon_edit/control_point.tscn"); -//controlpoint->set("filename", "res://addons/mat_maker_gd/widgets/polygon_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} - - - - -} diff --git a/modules/material_maker/editor/widgets/polygon_edit/control_point.h b/modules/material_maker/editor/widgets/polygon_edit/control_point.h index b8a51b3e4..54f948c11 100644 --- a/modules/material_maker/editor/widgets/polygon_edit/control_point.h +++ b/modules/material_maker/editor/widgets/polygon_edit/control_point.h @@ -1,31 +1,30 @@ #ifndef CONTROL_POINT_H #define CONTROL_POINT_H +#include "scene/gui/control.h" + +#include "core/os/input_event.h" class ControlPoint : public Control { - GDCLASS(ControlPoint, Control); + GDCLASS(ControlPoint, Control); - public: +public: + bool get_moving() const; + void set_moving(const bool val); - bool get_moving() const; - void set_moving(const bool val); + void _draw(); + void initialize(const Vector2 &p); - void _draw(); - void initialize(const Vector2 &p); - void _on_ControlPoint_gui_input(const Variant &event); + void _on_ControlPoint_gui_input(const Ref &event); - ControlPoint(); - ~ControlPoint(); + ControlPoint(); + ~ControlPoint(); - protected: - static void _bind_methods(); +protected: + static void _bind_methods(); - //tool - bool moving = false; - const OFFSET : Vector2 = Vector2(3, 3); - signal moved(index); - signal removed(index); + bool moving = false; + const Vector2 OFFSET = Vector2(3, 3); }; - #endif