mirror of
https://github.com/Relintai/pandemonium_engine.git
synced 2025-01-11 13:21:10 +01:00
Cleaned up PolygonView.
This commit is contained in:
parent
09e7eb3db2
commit
a12ee8f913
@ -1,171 +1,137 @@
|
||||
|
||||
#include "polygon_view.h"
|
||||
|
||||
#include "../../../nodes/bases/polygon_base.h"
|
||||
|
||||
Variant PolygonView::get_Variant() {
|
||||
return Variant;
|
||||
Ref<PolygonBase> PolygonView::get_polygon() {
|
||||
return polygon;
|
||||
}
|
||||
|
||||
void PolygonView::set_Variant(const Variant &val) {
|
||||
Variant = val;
|
||||
void PolygonView::set_polygon(const Ref<PolygonBase> &val) {
|
||||
polygon = val;
|
||||
update();
|
||||
}
|
||||
|
||||
|
||||
Variant PolygonView::get_Variant() {
|
||||
return Variant;
|
||||
}
|
||||
|
||||
void PolygonView::set_Variant(const Variant &val) {
|
||||
Variant = val;
|
||||
}
|
||||
|
||||
|
||||
Vector2 PolygonView::get_draw_size() {
|
||||
return draw_size;
|
||||
return draw_size;
|
||||
}
|
||||
|
||||
void PolygonView::set_draw_size(const Vector2 &val) {
|
||||
draw_size = val;
|
||||
draw_size = val;
|
||||
}
|
||||
|
||||
|
||||
Vector2 PolygonView::get_draw_offset() {
|
||||
return draw_offset;
|
||||
return draw_offset;
|
||||
}
|
||||
|
||||
void PolygonView::set_draw_offset(const Vector2 &val) {
|
||||
draw_offset = val;
|
||||
draw_offset = val;
|
||||
}
|
||||
|
||||
|
||||
bool PolygonView::get_closed() const {
|
||||
return closed;
|
||||
return closed;
|
||||
}
|
||||
|
||||
void PolygonView::set_closed(const bool val) {
|
||||
closed = val;
|
||||
void PolygonView::set_closed(const bool c) {
|
||||
closed = c;
|
||||
update();
|
||||
}
|
||||
|
||||
|
||||
|
||||
//tool;
|
||||
//var MMPolygon = preload("res://addons/mat_maker_gd/nodes/bases/polygon_base.gd");
|
||||
//: MMPolygon;
|
||||
Variant ;
|
||||
Vector2 draw_size = Vector2(1, 1);
|
||||
Vector2 draw_offset = Vector2(0, 0);
|
||||
bool closed = true;
|
||||
|
||||
void PolygonView::set_closed(const bool c) {
|
||||
closed = c;
|
||||
update();
|
||||
Vector2 PolygonView::transform_point(const Vector2 &p) {
|
||||
return draw_offset + p * draw_size;
|
||||
}
|
||||
|
||||
|
||||
void PolygonView::_ready() {
|
||||
// polygon = MMPolygon.new();
|
||||
connect("resized", self, "_on_resize");
|
||||
_on_resize();
|
||||
Vector2 PolygonView::reverse_transform_point(const Vector2 &p) {
|
||||
return (p - draw_offset) / draw_size;
|
||||
}
|
||||
|
||||
void PolygonView::_draw() {
|
||||
if (!polygon.is_valid()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Vector2 PolygonView::transform_point(const Vector2 &p) {
|
||||
return draw_offset+p*draw_size;
|
||||
// var current_theme : Theme = get_node("/root/MainWindow").theme;
|
||||
// var bg = current_theme.get_stylebox("panel", "Panel").bg_color;
|
||||
// var fg = current_theme.get_color("font_color", "Label");
|
||||
// var axes_color : Color = bg.linear_interpolate(fg, 0.25);
|
||||
// var curve_color : Color = bg.linear_interpolate(fg, 0.75);
|
||||
Color axes_color = Color(0.9, 0.9, 0.9, 1);
|
||||
Color curve_color = Color(1, 1, 1, 1);
|
||||
draw_rect(Rect2(draw_offset, draw_size), axes_color, false);
|
||||
|
||||
PoolVector2Array points = polygon->get_points();
|
||||
|
||||
int index = 0;
|
||||
|
||||
if (closed) {
|
||||
index = points.size() - 1;
|
||||
}
|
||||
|
||||
Vector2 tp = transform_point(points[index]);
|
||||
|
||||
for (int i = 0; i < points.size(); ++i) {
|
||||
Vector2 p = points[i];
|
||||
Vector2 tnp = transform_point(p);
|
||||
draw_line(tp, tnp, curve_color);
|
||||
tp = tnp;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Vector2 PolygonView::reverse_transform_point(const Vector2 &p) {
|
||||
return (p-draw_offset)/draw_size;
|
||||
void PolygonView::_on_resize() {
|
||||
float ds = MIN(get_size().x, get_size().y);
|
||||
draw_size = Vector2(ds, ds);
|
||||
draw_offset = 0.5 * (get_size() - draw_size);
|
||||
update();
|
||||
}
|
||||
|
||||
PolygonView::PolygonView() {
|
||||
draw_size = Vector2(1, 1);
|
||||
draw_offset = Vector2(0, 0);
|
||||
closed = true;
|
||||
|
||||
void PolygonView::set_polygon(const Variant &val) {
|
||||
polygon = val;
|
||||
update();
|
||||
set_size(Vector2(64, 64));
|
||||
set_mouse_filter(MOUSE_FILTER_IGNORE);
|
||||
}
|
||||
|
||||
|
||||
void PolygonView::_draw() {
|
||||
|
||||
if (!polygon) {
|
||||
return;
|
||||
PolygonView::~PolygonView() {
|
||||
}
|
||||
|
||||
// var current_theme : Theme = get_node("/root/MainWindow").theme;
|
||||
// var bg = current_theme.get_stylebox("panel", "Panel").bg_color;
|
||||
// var fg = current_theme.get_color("font_color", "Label");
|
||||
// var axes_color : Color = bg.linear_interpolate(fg, 0.25);
|
||||
// var curve_color : Color = bg.linear_interpolate(fg, 0.75);
|
||||
Color axes_color = Color(0.9, 0.9, 0.9, 1);
|
||||
Color curve_color = Color(1, 1, 1, 1);
|
||||
draw_rect(Rect2(draw_offset, draw_size), axes_color, false);
|
||||
Vector2 tp = transform_point(polygon.points[polygon.points.size()-1 if closed else 0]);
|
||||
|
||||
for (p in polygon.points) {
|
||||
Variant = transform_point(p);
|
||||
draw_line(tp, tnp, curve_color);
|
||||
tp = tnp;
|
||||
void PolygonView::_notification(int p_what) {
|
||||
switch (p_what) {
|
||||
case NOTIFICATION_POSTINITIALIZE: {
|
||||
// polygon = MMPolygon.new();
|
||||
connect("resized", this, "_on_resize");
|
||||
_on_resize();
|
||||
} break;
|
||||
case NOTIFICATION_DRAW: {
|
||||
_draw();
|
||||
} break;
|
||||
default: {
|
||||
} break;
|
||||
}
|
||||
}
|
||||
|
||||
void PolygonView::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("get_polygon"), &PolygonView::get_polygon);
|
||||
ClassDB::bind_method(D_METHOD("set_polygon", "value"), &PolygonView::set_polygon);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "polygon", PROPERTY_HINT_RESOURCE_TYPE, "PolygonBase"), "set_polygon", "get_polygon");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_draw_size"), &PolygonView::get_draw_size);
|
||||
ClassDB::bind_method(D_METHOD("set_draw_size", "value"), &PolygonView::set_draw_size);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "draw_size"), "set_draw_size", "get_draw_size");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_draw_offset"), &PolygonView::get_draw_offset);
|
||||
ClassDB::bind_method(D_METHOD("set_draw_offset", "value"), &PolygonView::set_draw_offset);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "draw_offset"), "set_draw_offset", "get_draw_offset");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_closed"), &PolygonView::get_closed);
|
||||
// ClassDB::bind_method(D_METHOD("set_closed", "value"), &PolygonView::set_closed);
|
||||
ClassDB::bind_method(D_METHOD("set_closed", "c"), &PolygonView::set_closed, true);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "closed"), "set_closed", "get_closed");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("transform_point", "p"), &PolygonView::transform_point);
|
||||
ClassDB::bind_method(D_METHOD("reverse_transform_point", "p"), &PolygonView::reverse_transform_point);
|
||||
|
||||
//ClassDB::bind_method(D_METHOD("_draw"), &PolygonView::_draw);
|
||||
ClassDB::bind_method(D_METHOD("_on_resize"), &PolygonView::_on_resize);
|
||||
}
|
||||
|
||||
|
||||
void PolygonView::_on_resize() {
|
||||
float ds = min(rect_size.x, rect_size.y);
|
||||
draw_size = Vector2(ds, ds);
|
||||
draw_offset = 0.5*(rect_size-draw_size);
|
||||
update();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
PolygonView::PolygonView() {
|
||||
//var MMPolygon = preload("res://addons/mat_maker_gd/nodes/bases/polygon_base.gd");
|
||||
;
|
||||
draw_size = Vector2(1, 1);
|
||||
draw_offset = Vector2(0, 0);
|
||||
closed = true;
|
||||
}
|
||||
|
||||
PolygonView::~PolygonView() {
|
||||
}
|
||||
|
||||
|
||||
static void PolygonView::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("get_Variant"), &PolygonView::get_Variant);
|
||||
ClassDB::bind_method(D_METHOD("set_Variant", "value"), &PolygonView::set_Variant);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "Variant", PROPERTY_HINT_RESOURCE_TYPE, "Variant"), "set_Variant", "get_Variant");
|
||||
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_Variant"), &PolygonView::get_Variant);
|
||||
ClassDB::bind_method(D_METHOD("set_Variant", "value"), &PolygonView::set_Variant);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "Variant", PROPERTY_HINT_RESOURCE_TYPE, "Variant"), "set_Variant", "get_Variant");
|
||||
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_draw_size"), &PolygonView::get_draw_size);
|
||||
ClassDB::bind_method(D_METHOD("set_draw_size", "value"), &PolygonView::set_draw_size);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "draw_size"), "set_draw_size", "get_draw_size");
|
||||
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_draw_offset"), &PolygonView::get_draw_offset);
|
||||
ClassDB::bind_method(D_METHOD("set_draw_offset", "value"), &PolygonView::set_draw_offset);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "draw_offset"), "set_draw_offset", "get_draw_offset");
|
||||
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_closed"), &PolygonView::get_closed);
|
||||
ClassDB::bind_method(D_METHOD("set_closed", "value"), &PolygonView::set_closed);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "closed"), "set_closed", "get_closed");
|
||||
|
||||
|
||||
ClassDB::bind_method(D_METHOD("set_closed", "c"), &PolygonView::set_closed, true);
|
||||
ClassDB::bind_method(D_METHOD("_ready"), &PolygonView::_ready);
|
||||
ClassDB::bind_method(D_METHOD("transform_point", "p"), &PolygonView::transform_point);
|
||||
ClassDB::bind_method(D_METHOD("reverse_transform_point", "p"), &PolygonView::reverse_transform_point);
|
||||
ClassDB::bind_method(D_METHOD("set_polygon", "val"), &PolygonView::set_polygon);
|
||||
ClassDB::bind_method(D_METHOD("_draw"), &PolygonView::_draw);
|
||||
ClassDB::bind_method(D_METHOD("_on_resize"), &PolygonView::_on_resize);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -1,31 +0,0 @@
|
||||
|
||||
void construct() {
|
||||
|
||||
//Script: res://addons/mat_maker_gd/widgets/polygon_edit/polygon_view.gd
|
||||
Control *polygonview = memnew(Control);
|
||||
polygonview->set_name("PolygonView");
|
||||
|
||||
polygonview->set_name("PolygonView");
|
||||
//polygonview->set("name", PolygonView));
|
||||
|
||||
polygonview->set_filename("res://addons/mat_maker_gd/widgets/polygon_edit/polygon_view.tscn");
|
||||
//polygonview->set("filename", "res://addons/mat_maker_gd/widgets/polygon_edit/polygon_view.tscn");
|
||||
|
||||
polygonview->set_margin_right(64);
|
||||
//polygonview->set("margin_right", 64);
|
||||
|
||||
polygonview->set_margin_bottom(64);
|
||||
//polygonview->set("margin_bottom", 64);
|
||||
|
||||
polygonview->set_rect_size(Vector2(64, 64));
|
||||
//polygonview->set("rect_size", Vector2(64, 64));
|
||||
|
||||
polygonview->set_mouse_filter(2);
|
||||
//polygonview->set("mouse_filter", 2);
|
||||
|
||||
//polygonview property __meta__ TYPE_DICTIONARY value: {_edit_use_anchors_:False}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
@ -1,49 +1,45 @@
|
||||
#ifndef POLYGON_VIEW_H
|
||||
#define POLYGON_VIEW_H
|
||||
|
||||
#include "core/reference.h"
|
||||
|
||||
#include "scene/gui/control.h"
|
||||
|
||||
class PolygonBase;
|
||||
|
||||
class PolygonView : public Control {
|
||||
GDCLASS(PolygonView, Control);
|
||||
GDCLASS(PolygonView, Control);
|
||||
|
||||
public:
|
||||
public:
|
||||
Ref<PolygonBase> get_polygon();
|
||||
void set_polygon(const Ref<PolygonBase> &val);
|
||||
|
||||
Variant get_Variant();
|
||||
void set_Variant(const Variant &val);
|
||||
Vector2 get_draw_size();
|
||||
void set_draw_size(const Vector2 &val);
|
||||
|
||||
Variant get_Variant();
|
||||
void set_Variant(const Variant &val);
|
||||
Vector2 get_draw_offset();
|
||||
void set_draw_offset(const Vector2 &val);
|
||||
|
||||
Vector2 get_draw_size();
|
||||
void set_draw_size(const Vector2 &val);
|
||||
bool get_closed() const;
|
||||
void set_closed(const bool c = true);
|
||||
|
||||
Vector2 get_draw_offset();
|
||||
void set_draw_offset(const Vector2 &val);
|
||||
Vector2 transform_point(const Vector2 &p);
|
||||
Vector2 reverse_transform_point(const Vector2 &p);
|
||||
|
||||
bool get_closed() const;
|
||||
void set_closed(const bool val);
|
||||
void _draw();
|
||||
void _on_resize();
|
||||
|
||||
void set_closed(const bool c = true);
|
||||
void _ready();
|
||||
Vector2 transform_point(const Vector2 &p);
|
||||
Vector2 reverse_transform_point(const Vector2 &p);
|
||||
void set_polygon(const Variant &val);
|
||||
void _draw();
|
||||
void _on_resize();
|
||||
PolygonView();
|
||||
~PolygonView();
|
||||
|
||||
PolygonView();
|
||||
~PolygonView();
|
||||
protected:
|
||||
void _notification(int p_what);
|
||||
static void _bind_methods();
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
|
||||
//tool
|
||||
Variant = preload("res://addons/mat_maker_gd/nodes/bases/polygon_base.gd");
|
||||
//: MMPolygon
|
||||
Variant ;
|
||||
Vector2 draw_size = Vector2(1, 1);
|
||||
Vector2 draw_offset = Vector2(0, 0);
|
||||
bool closed = true;
|
||||
Ref<PolygonBase> polygon;
|
||||
Vector2 draw_size = Vector2(1, 1);
|
||||
Vector2 draw_offset = Vector2(0, 0);
|
||||
bool closed = true;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user