mirror of
https://github.com/Relintai/pandemonium_engine.git
synced 2024-12-24 12:47:12 +01:00
Cleaned up CurveView.
This commit is contained in:
parent
e4ef99abc4
commit
1943e7f150
124
]
Normal file
124
]
Normal file
@ -0,0 +1,124 @@
|
||||
|
||||
#include "curve_view.h"
|
||||
|
||||
#include "../../../nodes/bases/curve_base.h"
|
||||
#include "core/vector.h"
|
||||
|
||||
bool CurveView::get_show_axes() const {
|
||||
return show_axes;
|
||||
}
|
||||
|
||||
void CurveView::set_show_axes(const bool val) {
|
||||
show_axes = val;
|
||||
}
|
||||
|
||||
Ref<CurveBase> CurveView::get_curve() {
|
||||
return curve;
|
||||
}
|
||||
|
||||
void CurveView::set_curve(const Ref<CurveBase> &val) {
|
||||
curve = val;
|
||||
update();
|
||||
}
|
||||
|
||||
Vector2 CurveView::transform_point(const Vector2 &p) {
|
||||
return (Vector2(0.0, 1.0) + Vector2(1.0, -1.0) * p) * get_size();
|
||||
}
|
||||
|
||||
Vector2 CurveView::reverse_transform_point(const Vector2 &p) {
|
||||
return Vector2(0.0, 1.0) + Vector2(1.0, -1.0) * p / get_size();
|
||||
}
|
||||
|
||||
void CurveView::_draw() {
|
||||
if (!curve.is_valid()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 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);
|
||||
|
||||
if (show_axes) {
|
||||
for (int i = 0; i < 5; ++i) { //i in range(5)
|
||||
Vector2 p = transform_point(0.25 * Vector2(i, i));
|
||||
draw_line(Vector2(p.x, 0), Vector2(p.x, get_size().y - 1), axes_color);
|
||||
draw_line(Vector2(0, p.y), Vector2(get_size().x - 1, p.y), axes_color);
|
||||
}
|
||||
}
|
||||
|
||||
Vector<CurveBase::Point> points = curve->get_points();
|
||||
|
||||
for (int i = 0; i < points.size() - 1; ++i) { //i in range(points.size() - 1)
|
||||
Vector2 p1 = points[i].p;
|
||||
Vector2 p2 = points[i + 1].p;
|
||||
float d = (p2.x - p1.x) / 3.0;
|
||||
float yac = p1.y + d * points[i].rs;
|
||||
float ybc = p2.y - d * points[i + 1].ls;
|
||||
Vector2 p = transform_point(p1);
|
||||
int count = max(1, int((transform_point(p2).x - p.x / 5.0)));
|
||||
|
||||
for (int tt = 0; tt < count; ++tt) { //tt in range(count)
|
||||
Variant = (tt + 1.0) / count;
|
||||
Variant = (1.0 - t);
|
||||
Variant = omt * omt;
|
||||
Variant = omt2 * omt;
|
||||
Variant = t * t;
|
||||
Variant = t2 * t;
|
||||
Variant = p1.x + (p2.x - p1.x) * t;
|
||||
Variant = transform_point(Vector2(x, p1.y * omt3 + yac * omt2 * t * 3.0 + ybc * omt * t2 * 3.0 + p2.y * t3));
|
||||
draw_line(p, np, curve_color);
|
||||
p = np;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CurveView::_on_resize() {
|
||||
update();
|
||||
}
|
||||
|
||||
CurveView::CurveView() {
|
||||
show_axes = false;
|
||||
|
||||
set_anchors_and_margins_preset(PRESET_WIDE, PRESET_MODE_MINSIZE, 4);
|
||||
|
||||
set_mouse_filter(MOUSE_FILTER_IGNORE);
|
||||
}
|
||||
|
||||
CurveView::~CurveView() {
|
||||
}
|
||||
|
||||
void CurveView::_notification(int p_what) {
|
||||
switch (p_what) {
|
||||
case NOTIFICATION_POSTINITIALIZE: {
|
||||
connect("resized", this, "_on_resize");
|
||||
update();
|
||||
} break;
|
||||
case NOTIFICATION_DRAW: {
|
||||
_draw();
|
||||
} break;
|
||||
default: {
|
||||
} break;
|
||||
}
|
||||
}
|
||||
|
||||
void CurveView::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("get_show_axes"), &CurveView::get_show_axes);
|
||||
ClassDB::bind_method(D_METHOD("set_show_axes", "value"), &CurveView::set_show_axes);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "show_axes"), "set_show_axes", "get_show_axes");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_curve"), &CurveView::get_curve);
|
||||
ClassDB::bind_method(D_METHOD("set_curve", "value"), &CurveView::set_curve);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "curve", PROPERTY_HINT_RESOURCE_TYPE, "CurveBase"), "set_curve", "get_curve");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("_on_resize"), &CurveView::_on_resize);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("set_curve", "val"), &CurveView::set_curve);
|
||||
ClassDB::bind_method(D_METHOD("transform_point", "p"), &CurveView::transform_point);
|
||||
ClassDB::bind_method(D_METHOD("reverse_transform_point", "p"), &CurveView::reverse_transform_point);
|
||||
}
|
@ -1,15 +1,8 @@
|
||||
|
||||
#include "curve_view.h"
|
||||
|
||||
|
||||
Variant CurveView::get_Variant() {
|
||||
return Variant;
|
||||
}
|
||||
|
||||
void CurveView::set_Variant(const Variant &val) {
|
||||
Variant = val;
|
||||
}
|
||||
|
||||
#include "../../../nodes/bases/curve_base.h"
|
||||
#include "core/vector.h"
|
||||
|
||||
bool CurveView::get_show_axes() const {
|
||||
return show_axes;
|
||||
@ -19,50 +12,25 @@ void CurveView::set_show_axes(const bool val) {
|
||||
show_axes = val;
|
||||
}
|
||||
|
||||
|
||||
Variant CurveView::get_Variant() {
|
||||
return Variant;
|
||||
Ref<CurveBase> CurveView::get_curve() {
|
||||
return curve;
|
||||
}
|
||||
|
||||
void CurveView::set_Variant(const Variant &val) {
|
||||
Variant = val;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//tool;
|
||||
//var MMCurve = preload("res://addons/mat_maker_gd/nodes/bases/curve_base.gd");
|
||||
//export ;
|
||||
bool show_axes = false;
|
||||
//: MMCurve;
|
||||
Variant ;
|
||||
|
||||
void CurveView::_ready() {
|
||||
// curve = MMCurve.new();
|
||||
connect("resized", self, "_on_resize");
|
||||
update();
|
||||
}
|
||||
|
||||
|
||||
void CurveView::set_curve(const Variant &val) {
|
||||
void CurveView::set_curve(const Ref<CurveBase> &val) {
|
||||
curve = val;
|
||||
update();
|
||||
}
|
||||
|
||||
|
||||
Vector2 CurveView::transform_point(const Vector2 &p) {
|
||||
return (Vector2(0.0, 1.0)+Vector2(1.0, -1.0)*p)*rect_size;
|
||||
return (Vector2(0.0, 1.0) + Vector2(1.0, -1.0) * p) * get_size();
|
||||
}
|
||||
|
||||
|
||||
Vector2 CurveView::reverse_transform_point(const Vector2 &p) {
|
||||
return Vector2(0.0, 1.0)+Vector2(1.0, -1.0)*p/rect_size;
|
||||
return Vector2(0.0, 1.0) + Vector2(1.0, -1.0) * p / get_size();
|
||||
}
|
||||
|
||||
|
||||
void CurveView::_draw() {
|
||||
|
||||
if (!curve) {
|
||||
if (!curve.is_valid()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -77,84 +45,80 @@ Variant = val;
|
||||
Color curve_color = Color(1, 1, 1, 1);
|
||||
|
||||
if (show_axes) {
|
||||
|
||||
for (int i = 0; i < 5; ++i) { //i in range(5)
|
||||
Variant = transform_point(0.25*Vector2(i, i));
|
||||
draw_line(Vector2(p.x, 0), Vector2(p.x, rect_size.y-1), axes_color);
|
||||
draw_line(Vector2(0, p.y), Vector2(rect_size.x-1, p.y), axes_color);
|
||||
Vector2 p = transform_point(0.25 * Vector2(i, i));
|
||||
draw_line(Vector2(p.x, 0), Vector2(p.x, get_size().y - 1), axes_color);
|
||||
draw_line(Vector2(0, p.y), Vector2(get_size().x - 1, p.y), axes_color);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Vector<CurveBase::Point> points = curve->get_points();
|
||||
|
||||
Variant = curve.get_points();
|
||||
for (int i = 0; i < points.size() - 1; ++i) {
|
||||
Vector2 p1 = points[i].p;
|
||||
Vector2 p2 = points[i + 1].p;
|
||||
float d = (p2.x - p1.x) / 3.0;
|
||||
float yac = p1.y + d * points[i].rs;
|
||||
float ybc = p2.y - d * points[i + 1].ls;
|
||||
Vector2 p = transform_point(p1);
|
||||
int count = MAX(1, static_cast<int>((transform_point(p2).x - p.x / 5.0)));
|
||||
|
||||
for (int i = 0; i < points.size() - 1; ++i) { //i in range(points.size() - 1)
|
||||
Variant = points[i].p;
|
||||
Variant = points[i+1].p;
|
||||
Variant = (p2.x-p1.x)/3.0;
|
||||
Variant = p1.y+d*points[i].rs;
|
||||
Variant = p2.y-d*points[i+1].ls;
|
||||
Variant = transform_point(p1);
|
||||
int count = max(1, int((transform_point(p2).x-p.x/5.0)));
|
||||
|
||||
for (int tt = 0; tt < count; ++tt) { //tt in range(count)
|
||||
Variant = (tt+1.0)/count;
|
||||
Variant = (1.0 - t);
|
||||
Variant = omt * omt;
|
||||
Variant = omt2 * omt;
|
||||
Variant = t * t;
|
||||
Variant = t2 * t;
|
||||
Variant = p1.x+(p2.x-p1.x)*t;
|
||||
Variant = transform_point(Vector2(x, p1.y*omt3 + yac*omt2*t*3.0 + ybc*omt*t2*3.0 + p2.y*t3));
|
||||
for (int tt = 0; tt < count; ++tt) {
|
||||
float t = (tt + 1.0) / count;
|
||||
float omt = (1.0 - t);
|
||||
float omt2 = omt * omt;
|
||||
float omt3 = omt2 * omt;
|
||||
float t2 = t * t;
|
||||
float t3 = t2 * t;
|
||||
float x = p1.x + (p2.x - p1.x) * t;
|
||||
Vector2 np = transform_point(Vector2(x, p1.y * omt3 + yac * omt2 * t * 3.0 + ybc * omt * t2 * 3.0 + p2.y * t3));
|
||||
draw_line(p, np, curve_color);
|
||||
p = np;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
void CurveView::_on_resize() {
|
||||
update();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
CurveView::CurveView() {
|
||||
//var MMCurve = preload("res://addons/mat_maker_gd/nodes/bases/curve_base.gd");
|
||||
show_axes = false;
|
||||
;
|
||||
|
||||
set_anchors_and_margins_preset(PRESET_WIDE, PRESET_MODE_MINSIZE, 4);
|
||||
|
||||
set_mouse_filter(MOUSE_FILTER_IGNORE);
|
||||
}
|
||||
|
||||
CurveView::~CurveView() {
|
||||
}
|
||||
|
||||
void CurveView::_notification(int p_what) {
|
||||
switch (p_what) {
|
||||
case NOTIFICATION_POSTINITIALIZE: {
|
||||
connect("resized", this, "_on_resize");
|
||||
update();
|
||||
} break;
|
||||
case NOTIFICATION_DRAW: {
|
||||
_draw();
|
||||
} break;
|
||||
default: {
|
||||
} break;
|
||||
}
|
||||
}
|
||||
|
||||
static void CurveView::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("get_Variant"), &CurveView::get_Variant);
|
||||
ClassDB::bind_method(D_METHOD("set_Variant", "value"), &CurveView::set_Variant);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "Variant", PROPERTY_HINT_RESOURCE_TYPE, "Variant"), "set_Variant", "get_Variant");
|
||||
|
||||
|
||||
void CurveView::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("get_show_axes"), &CurveView::get_show_axes);
|
||||
ClassDB::bind_method(D_METHOD("set_show_axes", "value"), &CurveView::set_show_axes);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "show_axes"), "set_show_axes", "get_show_axes");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_curve"), &CurveView::get_curve);
|
||||
ClassDB::bind_method(D_METHOD("set_curve", "value"), &CurveView::set_curve);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "curve", PROPERTY_HINT_RESOURCE_TYPE, "CurveBase"), "set_curve", "get_curve");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_Variant"), &CurveView::get_Variant);
|
||||
ClassDB::bind_method(D_METHOD("set_Variant", "value"), &CurveView::set_Variant);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "Variant", PROPERTY_HINT_RESOURCE_TYPE, "Variant"), "set_Variant", "get_Variant");
|
||||
ClassDB::bind_method(D_METHOD("_on_resize"), &CurveView::_on_resize);
|
||||
|
||||
|
||||
ClassDB::bind_method(D_METHOD("_ready"), &CurveView::_ready);
|
||||
ClassDB::bind_method(D_METHOD("set_curve", "val"), &CurveView::set_curve);
|
||||
ClassDB::bind_method(D_METHOD("transform_point", "p"), &CurveView::transform_point);
|
||||
ClassDB::bind_method(D_METHOD("reverse_transform_point", "p"), &CurveView::reverse_transform_point);
|
||||
ClassDB::bind_method(D_METHOD("_draw"), &CurveView::_draw);
|
||||
ClassDB::bind_method(D_METHOD("_on_resize"), &CurveView::_on_resize);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -1,46 +0,0 @@
|
||||
|
||||
void construct() {
|
||||
|
||||
//Script: res://addons/mat_maker_gd/widgets/curve_edit/curve_view.gd
|
||||
Control *curveview = memnew(Control);
|
||||
curveview->set_name("CurveView");
|
||||
|
||||
curveview->set_name("CurveView");
|
||||
//curveview->set("name", CurveView));
|
||||
|
||||
curveview->set_filename("res://addons/mat_maker_gd/widgets/curve_edit/curve_view.tscn");
|
||||
//curveview->set("filename", "res://addons/mat_maker_gd/widgets/curve_edit/curve_view.tscn");
|
||||
|
||||
curveview->set_anchor_right(1);
|
||||
//curveview->set("anchor_right", 1);
|
||||
|
||||
curveview->set_anchor_bottom(1);
|
||||
//curveview->set("anchor_bottom", 1);
|
||||
|
||||
curveview->set_margin_left(4);
|
||||
//curveview->set("margin_left", 4);
|
||||
|
||||
curveview->set_margin_top(4);
|
||||
//curveview->set("margin_top", 4);
|
||||
|
||||
curveview->set_margin_right(-4);
|
||||
//curveview->set("margin_right", -4);
|
||||
|
||||
curveview->set_margin_bottom(-4);
|
||||
//curveview->set("margin_bottom", -4);
|
||||
|
||||
curveview->set_rect_position(Vector2(4, 4));
|
||||
//curveview->set("rect_position", Vector2(4, 4));
|
||||
|
||||
curveview->set_rect_global_position(Vector2(4, 4));
|
||||
//curveview->set("rect_global_position", Vector2(4, 4));
|
||||
|
||||
curveview->set_mouse_filter(2);
|
||||
//curveview->set("mouse_filter", 2);
|
||||
|
||||
//curveview property __meta__ TYPE_DICTIONARY value: {_edit_use_anchors_:False}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
@ -1,25 +1,25 @@
|
||||
#ifndef CURVE_VIEW_H
|
||||
#define CURVE_VIEW_H
|
||||
|
||||
#include "core/reference.h"
|
||||
|
||||
#include "scene/gui/control.h"
|
||||
|
||||
class CurveBase;
|
||||
|
||||
class CurveView : public Control {
|
||||
GDCLASS(CurveView, Control);
|
||||
|
||||
public:
|
||||
|
||||
Variant get_Variant();
|
||||
void set_Variant(const Variant &val);
|
||||
|
||||
bool get_show_axes() const;
|
||||
void set_show_axes(const bool val);
|
||||
|
||||
Variant get_Variant();
|
||||
void set_Variant(const Variant &val);
|
||||
Ref<CurveBase> get_curve();
|
||||
void set_curve(const Ref<CurveBase> &val);
|
||||
|
||||
void _ready();
|
||||
void set_curve(const Variant &val);
|
||||
Vector2 transform_point(const Vector2 &p);
|
||||
Vector2 reverse_transform_point(const Vector2 &p);
|
||||
|
||||
void _draw();
|
||||
void _on_resize();
|
||||
|
||||
@ -27,15 +27,12 @@ class CurveView : public Control {
|
||||
~CurveView();
|
||||
|
||||
protected:
|
||||
void _notification(int p_what);
|
||||
|
||||
static void _bind_methods();
|
||||
|
||||
//tool
|
||||
Variant = preload("res://addons/mat_maker_gd/nodes/bases/curve_base.gd");
|
||||
//export
|
||||
bool show_axes = false;
|
||||
//: MMCurve
|
||||
Variant ;
|
||||
Ref<CurveBase> curve;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user