mirror of
https://github.com/Relintai/pandemonium_engine.git
synced 2025-01-11 13:21:10 +01:00
Cleaned up FloatEdit.
This commit is contained in:
parent
d25efcc17c
commit
8ff93d88e8
@ -1,469 +1,346 @@
|
||||
|
||||
#include "float_edit.h"
|
||||
|
||||
#include "scene/gui/color_rect.h"
|
||||
|
||||
float FloatEdit::get_value() const {
|
||||
return value;
|
||||
return value;
|
||||
}
|
||||
|
||||
void FloatEdit::set_value(const float val) {
|
||||
value = val;
|
||||
void FloatEdit::set_value_float(const float val) {
|
||||
value = val;
|
||||
do_update();
|
||||
slider->set_visible(true);
|
||||
}
|
||||
|
||||
void FloatEdit::set_value(const Variant &v) {
|
||||
if (v.get_type() == Variant::REAL) {
|
||||
value = v;
|
||||
do_update();
|
||||
slider->set_visible(true);
|
||||
} else if (v.get_type() == Variant::STRING && !float_only) {
|
||||
set_text(v);
|
||||
slider->set_visible(false);
|
||||
}
|
||||
}
|
||||
|
||||
float FloatEdit::get_min_value() const {
|
||||
return min_value;
|
||||
return min_value;
|
||||
}
|
||||
|
||||
void FloatEdit::set_min_value(const float val) {
|
||||
min_value = val;
|
||||
void FloatEdit::set_min_value(const float v) {
|
||||
min_value = v;
|
||||
do_update();
|
||||
}
|
||||
|
||||
|
||||
float FloatEdit::get_max_value() const {
|
||||
return max_value;
|
||||
return max_value;
|
||||
}
|
||||
|
||||
void FloatEdit::set_max_value(const float val) {
|
||||
max_value = val;
|
||||
void FloatEdit::set_max_value(const float v) {
|
||||
max_value = v;
|
||||
do_update();
|
||||
}
|
||||
|
||||
|
||||
float FloatEdit::get_step() const {
|
||||
return step;
|
||||
return step;
|
||||
}
|
||||
|
||||
void FloatEdit::set_step(const float val) {
|
||||
step = val;
|
||||
void FloatEdit::set_step(const float v) {
|
||||
step = v;
|
||||
do_update();
|
||||
}
|
||||
|
||||
|
||||
bool FloatEdit::get_float_only() const {
|
||||
return float_only;
|
||||
return float_only;
|
||||
}
|
||||
|
||||
void FloatEdit::set_float_only(const bool val) {
|
||||
float_only = val;
|
||||
float_only = val;
|
||||
}
|
||||
|
||||
|
||||
bool FloatEdit::get_sliding() const {
|
||||
return sliding;
|
||||
return sliding;
|
||||
}
|
||||
|
||||
void FloatEdit::set_sliding(const bool val) {
|
||||
sliding = val;
|
||||
sliding = val;
|
||||
}
|
||||
|
||||
|
||||
float FloatEdit::get_start_position() const {
|
||||
return start_position;
|
||||
return start_position;
|
||||
}
|
||||
|
||||
void FloatEdit::set_start_position(const float val) {
|
||||
start_position = val;
|
||||
start_position = val;
|
||||
}
|
||||
|
||||
|
||||
float FloatEdit::get_last_position() const {
|
||||
return last_position;
|
||||
return last_position;
|
||||
}
|
||||
|
||||
void FloatEdit::set_last_position(const float val) {
|
||||
last_position = val;
|
||||
last_position = val;
|
||||
}
|
||||
|
||||
|
||||
float FloatEdit::get_start_value() const {
|
||||
return start_value;
|
||||
return start_value;
|
||||
}
|
||||
|
||||
void FloatEdit::set_start_value(const float val) {
|
||||
start_value = val;
|
||||
start_value = val;
|
||||
}
|
||||
|
||||
|
||||
int FloatEdit::get_modifiers() const {
|
||||
return modifiers;
|
||||
}
|
||||
|
||||
void FloatEdit::set_modifiers(const int val) {
|
||||
modifiers = val;
|
||||
}
|
||||
|
||||
|
||||
bool FloatEdit::get_from_lower_bound() const {
|
||||
return from_lower_bound;
|
||||
return from_lower_bound;
|
||||
}
|
||||
|
||||
void FloatEdit::set_from_lower_bound(const bool val) {
|
||||
from_lower_bound = val;
|
||||
from_lower_bound = val;
|
||||
}
|
||||
|
||||
|
||||
bool FloatEdit::get_from_upper_bound() const {
|
||||
return from_upper_bound;
|
||||
return from_upper_bound;
|
||||
}
|
||||
|
||||
void FloatEdit::set_from_upper_bound(const bool val) {
|
||||
from_upper_bound = val;
|
||||
from_upper_bound = val;
|
||||
}
|
||||
|
||||
void FloatEdit::do_update(const bool update_text) {
|
||||
if (update_text && slider->is_visible()) {
|
||||
set_text(String::num(value));
|
||||
|
||||
Point2 pos = cursor->get_position();
|
||||
|
||||
//tool;
|
||||
//export ;
|
||||
// setget set_value;
|
||||
float value = 0.5;
|
||||
//export ;
|
||||
// setget set_min_value;
|
||||
float min_value = 0.0;
|
||||
//export ;
|
||||
// setget set_max_value;
|
||||
float max_value = 1.0;
|
||||
//export ;
|
||||
// setget set_step;
|
||||
float step = 0.0;
|
||||
//export ;
|
||||
bool float_only = false;
|
||||
bool sliding = false;
|
||||
float start_position = ;
|
||||
float last_position = ;
|
||||
float start_value = ;
|
||||
int modifiers = ;
|
||||
bool from_lower_bound = false;
|
||||
bool from_upper_bound = false;
|
||||
onready var slider = $Slider;
|
||||
onready var cursor = $Slider/Cursor;
|
||||
signal value_changed(value);
|
||||
if (max_value != min_value) {
|
||||
pos.x = (CLAMP(value, min_value, max_value) - min_value) * (slider->get_size().x - cursor->get_size().x) / (max_value - min_value);
|
||||
} else {
|
||||
pos.x = 0;
|
||||
}
|
||||
|
||||
void FloatEdit::_ready() {
|
||||
do_update();
|
||||
cursor->set_position(pos);
|
||||
}
|
||||
}
|
||||
|
||||
int FloatEdit::get_modifiers(const Ref<InputEventMouseButton> &event) {
|
||||
int new_modifiers = 0;
|
||||
|
||||
void FloatEdit::set_value(const Variant &v) {
|
||||
if (event->get_shift()) {
|
||||
new_modifiers |= 1;
|
||||
}
|
||||
|
||||
if (v is float) {
|
||||
value = v;
|
||||
do_update();
|
||||
$Slider.visible = true;
|
||||
if (event->get_control()) {
|
||||
new_modifiers |= 2;
|
||||
}
|
||||
|
||||
if (event->get_alt()) {
|
||||
new_modifiers |= 4;
|
||||
}
|
||||
|
||||
return new_modifiers;
|
||||
}
|
||||
|
||||
void FloatEdit::_on_LineEdit_gui_input(const Ref<InputEvent> &event) {
|
||||
if (!slider->is_visible() || !is_editable()) {
|
||||
return;
|
||||
}
|
||||
|
||||
else if (v is String && !float_only) {
|
||||
text = v;
|
||||
$Slider.visible = false;
|
||||
Ref<InputEventMouseButton> iemb = event;
|
||||
Ref<InputEventMouseMotion> iemm = event;
|
||||
Ref<InputEventKey> iek = event;
|
||||
|
||||
if (iemb.is_valid() && iemb->get_button_index() == BUTTON_LEFT) {
|
||||
if (iemb->is_pressed()) {
|
||||
last_position = iemb->get_position().x;
|
||||
start_position = last_position;
|
||||
start_value = value;
|
||||
sliding = true;
|
||||
from_lower_bound = value <= min_value;
|
||||
from_upper_bound = value >= max_value;
|
||||
modifiers = get_modifiers(event);
|
||||
} else {
|
||||
sliding = false;
|
||||
}
|
||||
} else if (sliding && iemm.is_valid() && iemm->get_button_mask() == BUTTON_MASK_LEFT) {
|
||||
int new_modifiers = get_modifiers(event);
|
||||
|
||||
if (new_modifiers != modifiers) {
|
||||
start_position = last_position;
|
||||
start_value = value;
|
||||
modifiers = new_modifiers;
|
||||
} else {
|
||||
last_position = iemm->get_position().x;
|
||||
float delta = last_position - start_position;
|
||||
int current_step = step;
|
||||
|
||||
if (iemm->get_control()) {
|
||||
delta *= 0.2;
|
||||
} else if (iemm->get_shift()) {
|
||||
delta *= 5.0;
|
||||
}
|
||||
|
||||
if (iemm->get_alt()) {
|
||||
current_step *= 0.01;
|
||||
}
|
||||
|
||||
float v = start_value + SGN(delta) * pow(abs(delta) * 0.005, 2) * abs(max_value - min_value);
|
||||
|
||||
if (current_step != 0) {
|
||||
v = min_value + floor((v - min_value) / current_step) * current_step;
|
||||
}
|
||||
|
||||
if (!from_lower_bound && v < min_value) {
|
||||
v = min_value;
|
||||
}
|
||||
|
||||
if (!from_upper_bound && v > max_value) {
|
||||
v = max_value;
|
||||
}
|
||||
|
||||
set_value(v);
|
||||
select(0, 0);
|
||||
emit_signal("value_changed", value);
|
||||
release_focus();
|
||||
}
|
||||
} else if (iek.is_valid() && !event->is_echo()) {
|
||||
start_position = last_position;
|
||||
start_value = value;
|
||||
modifiers = get_modifiers(event);
|
||||
}
|
||||
}
|
||||
|
||||
void FloatEdit::_on_LineEdit_text_changed(const String &new_text) {
|
||||
if (new_text.is_valid_float()) {
|
||||
value = new_text.to_float();
|
||||
do_update(false);
|
||||
}
|
||||
}
|
||||
|
||||
void FloatEdit::_on_LineEdit_text_entered(const String &new_text, const Variant &release) {
|
||||
if (new_text.is_valid_float()) {
|
||||
value = new_text.to_float();
|
||||
do_update();
|
||||
emit_signal("value_changed", value);
|
||||
slider->set_visible(true);
|
||||
} else if (float_only) {
|
||||
do_update();
|
||||
emit_signal("value_changed", value);
|
||||
slider->set_visible(true);
|
||||
} else {
|
||||
emit_signal("value_changed", new_text);
|
||||
slider->set_visible(false);
|
||||
}
|
||||
|
||||
void FloatEdit::set_min_value(const float v) {
|
||||
min_value = v;
|
||||
do_update();
|
||||
if (release) {
|
||||
release_focus();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void FloatEdit::set_max_value(const float v) {
|
||||
max_value = v;
|
||||
do_update();
|
||||
void FloatEdit::_on_FloatEdit_focus_entered() {
|
||||
select_all();
|
||||
}
|
||||
|
||||
|
||||
void FloatEdit::set_step(const float v) {
|
||||
step = v;
|
||||
do_update();
|
||||
void FloatEdit::_on_LineEdit_focus_exited() {
|
||||
_on_LineEdit_text_entered(get_text(), false);
|
||||
}
|
||||
|
||||
FloatEdit::FloatEdit() {
|
||||
value = 0.5;
|
||||
min_value = 0.0;
|
||||
max_value = 1.0;
|
||||
step = 0.0;
|
||||
float_only = false;
|
||||
sliding = false;
|
||||
start_position = 0;
|
||||
last_position = 0;
|
||||
start_value = 0;
|
||||
modifiers = 0;
|
||||
from_lower_bound = false;
|
||||
from_upper_bound = false;
|
||||
|
||||
void FloatEdit::do_update(const bool update_text) {
|
||||
set_focus_mode(FOCUS_CLICK);
|
||||
set_text("0.5");
|
||||
set_max_length(100);
|
||||
set_context_menu_enabled(false);
|
||||
cursor_set_blink_enabled(true);
|
||||
|
||||
if (update_text && $Slider.visible) {
|
||||
text = str(value);
|
||||
slider = memnew(ColorRect);
|
||||
slider->set_name("Slider");
|
||||
add_child(slider);
|
||||
slider->set_custom_minimum_size(Vector2(0, 2));
|
||||
slider->set_mouse_filter(MOUSE_FILTER_IGNORE);
|
||||
slider->set_frame_color(Color(0.501961, 0.501961, 0.501961, 1));
|
||||
|
||||
if (cursor != null) {
|
||||
|
||||
if (max_value != min_value) {
|
||||
cursor.rect_position.x = (clamp(value, min_value, max_value)-min_value)*(slider.rect_size.x-cursor.rect_size.x)/(max_value-min_value);
|
||||
cursor = memnew(ColorRect);
|
||||
cursor->set_name("Cursor");
|
||||
slider->add_child(cursor);
|
||||
cursor->set_custom_minimum_size(Vector2(3, 2));
|
||||
cursor->set_mouse_filter(MOUSE_FILTER_IGNORE);
|
||||
}
|
||||
|
||||
|
||||
else {
|
||||
cursor.rect_position.x = 0;
|
||||
FloatEdit::~FloatEdit() {
|
||||
}
|
||||
|
||||
void FloatEdit::_notification(int p_what) {
|
||||
if (p_what == NOTIFICATION_POSTINITIALIZE) {
|
||||
do_update();
|
||||
}
|
||||
}
|
||||
|
||||
void FloatEdit::_bind_methods() {
|
||||
ADD_SIGNAL(MethodInfo("value_changed", PropertyInfo(Variant::INT, "value")));
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_value"), &FloatEdit::get_value);
|
||||
ClassDB::bind_method(D_METHOD("set_value_float", "value"), &FloatEdit::set_value_float);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::REAL, "value"), "set_value", "get_value");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_min_value"), &FloatEdit::get_min_value);
|
||||
ClassDB::bind_method(D_METHOD("set_min_value", "value"), &FloatEdit::set_min_value);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::REAL, "min_value"), "set_min_value", "get_min_value");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_max_value"), &FloatEdit::get_max_value);
|
||||
ClassDB::bind_method(D_METHOD("set_max_value", "value"), &FloatEdit::set_max_value);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::REAL, "max_value"), "set_max_value", "get_max_value");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_step"), &FloatEdit::get_step);
|
||||
ClassDB::bind_method(D_METHOD("set_step", "value"), &FloatEdit::set_step);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::REAL, "step"), "set_step", "get_step");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_float_only"), &FloatEdit::get_float_only);
|
||||
ClassDB::bind_method(D_METHOD("set_float_only", "value"), &FloatEdit::set_float_only);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "float_only"), "set_float_only", "get_float_only");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_sliding"), &FloatEdit::get_sliding);
|
||||
ClassDB::bind_method(D_METHOD("set_sliding", "value"), &FloatEdit::set_sliding);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "sliding"), "set_sliding", "get_sliding");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_start_position"), &FloatEdit::get_start_position);
|
||||
ClassDB::bind_method(D_METHOD("set_start_position", "value"), &FloatEdit::set_start_position);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::REAL, "start_position"), "set_start_position", "get_start_position");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_last_position"), &FloatEdit::get_last_position);
|
||||
ClassDB::bind_method(D_METHOD("set_last_position", "value"), &FloatEdit::set_last_position);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::REAL, "last_position"), "set_last_position", "get_last_position");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_start_value"), &FloatEdit::get_start_value);
|
||||
ClassDB::bind_method(D_METHOD("set_start_value", "value"), &FloatEdit::set_start_value);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::REAL, "start_value"), "set_start_value", "get_start_value");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_from_lower_bound"), &FloatEdit::get_from_lower_bound);
|
||||
ClassDB::bind_method(D_METHOD("set_from_lower_bound", "value"), &FloatEdit::set_from_lower_bound);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "from_lower_bound"), "set_from_lower_bound", "get_from_lower_bound");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_from_upper_bound"), &FloatEdit::get_from_upper_bound);
|
||||
ClassDB::bind_method(D_METHOD("set_from_upper_bound", "value"), &FloatEdit::set_from_upper_bound);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "from_upper_bound"), "set_from_upper_bound", "get_from_upper_bound");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("do_update", "update_text"), &FloatEdit::do_update, true);
|
||||
ClassDB::bind_method(D_METHOD("get_modifiers", "event"), &FloatEdit::get_modifiers);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("_on_LineEdit_gui_input", "event"), &FloatEdit::_on_LineEdit_gui_input);
|
||||
ClassDB::bind_method(D_METHOD("_on_LineEdit_text_changed", "new_text"), &FloatEdit::_on_LineEdit_text_changed);
|
||||
ClassDB::bind_method(D_METHOD("_on_LineEdit_text_entered", "new_text", "release"), &FloatEdit::_on_LineEdit_text_entered, true);
|
||||
ClassDB::bind_method(D_METHOD("_on_FloatEdit_focus_entered"), &FloatEdit::_on_FloatEdit_focus_entered);
|
||||
ClassDB::bind_method(D_METHOD("_on_LineEdit_focus_exited"), &FloatEdit::_on_LineEdit_focus_exited);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
void FloatEdit::get_modifiers(const Variant &event) {
|
||||
Variant = 0;
|
||||
|
||||
if (event.shift) {
|
||||
new_modifiers |= 1;
|
||||
}
|
||||
|
||||
|
||||
if (event.control) {
|
||||
new_modifiers |= 2;
|
||||
}
|
||||
|
||||
|
||||
if (event.alt) {
|
||||
new_modifiers |= 4;
|
||||
}
|
||||
|
||||
return new_modifiers;
|
||||
}
|
||||
|
||||
|
||||
void FloatEdit::_on_LineEdit_gui_input(const InputEvent &event) {
|
||||
|
||||
if (!$Slider.visible || !editable) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (event is InputEventMouseButton && event.button_index == BUTTON_LEFT) {
|
||||
|
||||
if (event.is_pressed()) {
|
||||
last_position = event.position.x;
|
||||
start_position = last_position;
|
||||
start_value = value;
|
||||
sliding = true;
|
||||
from_lower_bound = value <= min_value;
|
||||
from_upper_bound = value >= max_value;
|
||||
modifiers = get_modifiers(event);
|
||||
}
|
||||
|
||||
|
||||
else {
|
||||
sliding = false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
else if (sliding && event is InputEventMouseMotion && event.button_mask == BUTTON_MASK_LEFT) {
|
||||
Variant = get_modifiers(event);
|
||||
|
||||
if (new_modifiers != modifiers) {
|
||||
start_position = last_position;
|
||||
start_value = value;
|
||||
modifiers = new_modifiers;
|
||||
}
|
||||
|
||||
|
||||
else {
|
||||
last_position = event.position.x;
|
||||
float delta = last_position-start_position;
|
||||
Variant = step;
|
||||
|
||||
if (event.control) {
|
||||
delta *= 0.2;
|
||||
}
|
||||
|
||||
|
||||
else if (event.shift) {
|
||||
delta *= 5.0;
|
||||
}
|
||||
|
||||
|
||||
if (event.alt) {
|
||||
current_step *= 0.01;
|
||||
}
|
||||
|
||||
float v = start_value+sign(delta)*pow(abs(delta)*0.005, 2)*abs(max_value - min_value);
|
||||
|
||||
if (current_step != 0) {
|
||||
v = min_value+floor((v - min_value)/current_step)*current_step;
|
||||
}
|
||||
|
||||
|
||||
if (!from_lower_bound && v < min_value) {
|
||||
v = min_value;
|
||||
}
|
||||
|
||||
|
||||
if (!from_upper_bound && v > max_value) {
|
||||
v = max_value;
|
||||
}
|
||||
|
||||
set_value(v);
|
||||
select(0, 0);
|
||||
emit_signal("value_changed", value);
|
||||
release_focus();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
else if (event is InputEventKey && !event.echo) {
|
||||
|
||||
{
|
||||
|
||||
{
|
||||
start_position = last_position;
|
||||
start_value = value;
|
||||
modifiers = get_modifiers(event);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
void FloatEdit::_on_LineEdit_text_changed(const String &new_text) {
|
||||
|
||||
if (new_text.is_valid_float()) {
|
||||
value = new_text.to_float();
|
||||
do_update(false);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
void FloatEdit::_on_LineEdit_text_entered(const String &new_text, const Variant &release) {
|
||||
|
||||
if (new_text.is_valid_float()) {
|
||||
value = new_text.to_float();
|
||||
do_update();
|
||||
emit_signal("value_changed", value);
|
||||
$Slider.visible = true;
|
||||
}
|
||||
|
||||
|
||||
else if (float_only) {
|
||||
do_update();
|
||||
emit_signal("value_changed", value);
|
||||
$Slider.visible = true;
|
||||
}
|
||||
|
||||
|
||||
else {
|
||||
emit_signal("value_changed", new_text);
|
||||
$Slider.visible = false;
|
||||
}
|
||||
|
||||
|
||||
if (release) {
|
||||
release_focus();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
void FloatEdit::_on_FloatEdit_focus_entered() {
|
||||
select_all();
|
||||
}
|
||||
|
||||
|
||||
void FloatEdit::_on_LineEdit_focus_exited() {
|
||||
_on_LineEdit_text_entered(text, false);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
FloatEdit::FloatEdit() {
|
||||
value = 0.5;
|
||||
min_value = 0.0;
|
||||
max_value = 1.0;
|
||||
step = 0.0;
|
||||
float_only = false;
|
||||
sliding = false;
|
||||
start_position = ;
|
||||
last_position = ;
|
||||
start_value = ;
|
||||
modifiers = ;
|
||||
from_lower_bound = false;
|
||||
from_upper_bound = false;
|
||||
}
|
||||
|
||||
FloatEdit::~FloatEdit() {
|
||||
}
|
||||
|
||||
|
||||
static void FloatEdit::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("get_value"), &FloatEdit::get_value);
|
||||
ClassDB::bind_method(D_METHOD("set_value", "value"), &FloatEdit::set_value);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::REAL, "value"), "set_value", "get_value");
|
||||
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_min_value"), &FloatEdit::get_min_value);
|
||||
ClassDB::bind_method(D_METHOD("set_min_value", "value"), &FloatEdit::set_min_value);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::REAL, "min_value"), "set_min_value", "get_min_value");
|
||||
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_max_value"), &FloatEdit::get_max_value);
|
||||
ClassDB::bind_method(D_METHOD("set_max_value", "value"), &FloatEdit::set_max_value);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::REAL, "max_value"), "set_max_value", "get_max_value");
|
||||
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_step"), &FloatEdit::get_step);
|
||||
ClassDB::bind_method(D_METHOD("set_step", "value"), &FloatEdit::set_step);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::REAL, "step"), "set_step", "get_step");
|
||||
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_float_only"), &FloatEdit::get_float_only);
|
||||
ClassDB::bind_method(D_METHOD("set_float_only", "value"), &FloatEdit::set_float_only);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "float_only"), "set_float_only", "get_float_only");
|
||||
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_sliding"), &FloatEdit::get_sliding);
|
||||
ClassDB::bind_method(D_METHOD("set_sliding", "value"), &FloatEdit::set_sliding);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "sliding"), "set_sliding", "get_sliding");
|
||||
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_start_position"), &FloatEdit::get_start_position);
|
||||
ClassDB::bind_method(D_METHOD("set_start_position", "value"), &FloatEdit::set_start_position);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::REAL, "start_position"), "set_start_position", "get_start_position");
|
||||
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_last_position"), &FloatEdit::get_last_position);
|
||||
ClassDB::bind_method(D_METHOD("set_last_position", "value"), &FloatEdit::set_last_position);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::REAL, "last_position"), "set_last_position", "get_last_position");
|
||||
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_start_value"), &FloatEdit::get_start_value);
|
||||
ClassDB::bind_method(D_METHOD("set_start_value", "value"), &FloatEdit::set_start_value);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::REAL, "start_value"), "set_start_value", "get_start_value");
|
||||
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_modifiers"), &FloatEdit::get_modifiers);
|
||||
ClassDB::bind_method(D_METHOD("set_modifiers", "value"), &FloatEdit::set_modifiers);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "modifiers"), "set_modifiers", "get_modifiers");
|
||||
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_from_lower_bound"), &FloatEdit::get_from_lower_bound);
|
||||
ClassDB::bind_method(D_METHOD("set_from_lower_bound", "value"), &FloatEdit::set_from_lower_bound);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "from_lower_bound"), "set_from_lower_bound", "get_from_lower_bound");
|
||||
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_from_upper_bound"), &FloatEdit::get_from_upper_bound);
|
||||
ClassDB::bind_method(D_METHOD("set_from_upper_bound", "value"), &FloatEdit::set_from_upper_bound);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "from_upper_bound"), "set_from_upper_bound", "get_from_upper_bound");
|
||||
|
||||
|
||||
ClassDB::bind_method(D_METHOD("_ready"), &FloatEdit::_ready);
|
||||
ClassDB::bind_method(D_METHOD("set_value", "v"), &FloatEdit::set_value);
|
||||
ClassDB::bind_method(D_METHOD("set_min_value", "v"), &FloatEdit::set_min_value);
|
||||
ClassDB::bind_method(D_METHOD("set_max_value", "v"), &FloatEdit::set_max_value);
|
||||
ClassDB::bind_method(D_METHOD("set_step", "v"), &FloatEdit::set_step);
|
||||
ClassDB::bind_method(D_METHOD("do_update", "update_text"), &FloatEdit::do_update, true);
|
||||
ClassDB::bind_method(D_METHOD("get_modifiers", "event"), &FloatEdit::get_modifiers);
|
||||
ClassDB::bind_method(D_METHOD("_on_LineEdit_gui_input", "event"), &FloatEdit::_on_LineEdit_gui_input);
|
||||
ClassDB::bind_method(D_METHOD("_on_LineEdit_text_changed", "new_text"), &FloatEdit::_on_LineEdit_text_changed);
|
||||
ClassDB::bind_method(D_METHOD("_on_LineEdit_text_entered", "new_text", "release"), &FloatEdit::_on_LineEdit_text_entered, true);
|
||||
ClassDB::bind_method(D_METHOD("_on_FloatEdit_focus_entered"), &FloatEdit::_on_FloatEdit_focus_entered);
|
||||
ClassDB::bind_method(D_METHOD("_on_LineEdit_focus_exited"), &FloatEdit::_on_LineEdit_focus_exited);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -1,172 +0,0 @@
|
||||
|
||||
void construct() {
|
||||
|
||||
//Script: res://addons/mat_maker_gd/widgets/float_edit/float_edit.gd
|
||||
LineEdit *floatedit = memnew(LineEdit);
|
||||
floatedit->set_name("FloatEdit");
|
||||
|
||||
floatedit->set_name("FloatEdit");
|
||||
//floatedit->set("name", FloatEdit));
|
||||
|
||||
floatedit->set_filename("res://addons/mat_maker_gd/widgets/float_edit/float_edit.tscn");
|
||||
//floatedit->set("filename", "res://addons/mat_maker_gd/widgets/float_edit/float_edit.tscn");
|
||||
|
||||
floatedit->set_anchor_left(1);
|
||||
//floatedit->set("anchor_left", 1);
|
||||
|
||||
floatedit->set_anchor_right(1);
|
||||
//floatedit->set("anchor_right", 1);
|
||||
|
||||
floatedit->set_anchor_bottom(1);
|
||||
//floatedit->set("anchor_bottom", 1);
|
||||
|
||||
floatedit->set_margin_left(-1280);
|
||||
//floatedit->set("margin_left", -1280);
|
||||
|
||||
floatedit->set_margin_right(-1222);
|
||||
//floatedit->set("margin_right", -1222);
|
||||
|
||||
floatedit->set_margin_bottom(-696);
|
||||
//floatedit->set("margin_bottom", -696);
|
||||
|
||||
floatedit->set_rect_position(Vector2(-1280, 0));
|
||||
//floatedit->set("rect_position", Vector2(-1280, 0));
|
||||
|
||||
floatedit->set_rect_global_position(Vector2(-1280, 0));
|
||||
//floatedit->set("rect_global_position", Vector2(-1280, 0));
|
||||
|
||||
floatedit->set_rect_size(Vector2(58, 24));
|
||||
//floatedit->set("rect_size", Vector2(58, 24));
|
||||
|
||||
floatedit->set_focus_mode(1);
|
||||
//floatedit->set("focus_mode", 1);
|
||||
|
||||
floatedit->set_text("0.5");
|
||||
//floatedit->set("text", "0.5");
|
||||
|
||||
floatedit->set_max_length(100);
|
||||
//floatedit->set("max_length", 100);
|
||||
|
||||
floatedit->set_context_menu_enabled(False);
|
||||
//floatedit->set("context_menu_enabled", False);
|
||||
|
||||
floatedit->set_caret_blink(True);
|
||||
//floatedit->set("caret_blink", True);
|
||||
|
||||
//floatedit property __meta__ TYPE_DICTIONARY value: {_edit_use_anchors_:False}
|
||||
|
||||
|
||||
|
||||
Timer *timer_floatedit = memnew(Timer);
|
||||
timer_floatedit->set_name("Timer");
|
||||
floatedit->add_child(timer_floatedit);
|
||||
|
||||
timer_floatedit->set_name("Timer");
|
||||
//timer_floatedit->set("name", Timer));
|
||||
|
||||
timer_floatedit->set_wait_time(0.65);
|
||||
//timer_floatedit->set("wait_time", 0.65);
|
||||
|
||||
|
||||
|
||||
PopupMenu *popupmenu_floatedit = memnew(PopupMenu);
|
||||
popupmenu_floatedit->set_name("PopupMenu");
|
||||
floatedit->add_child(popupmenu_floatedit);
|
||||
|
||||
popupmenu_floatedit->set_name("PopupMenu");
|
||||
//popupmenu_floatedit->set("name", PopupMenu));
|
||||
|
||||
//popupmenu_floatedit property items TYPE_ARRAY value: [Cut, [Object:null], 0, False, False, 0, 268435544, Null, , False, Copy, [Object:null], 0, False, False, 1, 268435523, Null, , False, Paste, [Object:null], 0, False, False, 2, 268435542, Null, , False, , [Object:null], 0, False, False, -1, 0, Null, , True, Select All, [Object:null], 0, False, False, 4, 268435521, Null, , False, Clear, [Object:null], 0, False, False, 3, 0, Null, , False, , [Object:null], 0, False, False, -1, 0, Null, , True, Undo, [Object:null], 0, False, False, 5, 268435546, Null, , False, Redo, [Object:null], 0, False, False, 6, 301989978, Null, , False]
|
||||
|
||||
|
||||
|
||||
Timer *timer_popupmenu_floatedit = memnew(Timer);
|
||||
timer_popupmenu_floatedit->set_name("Timer");
|
||||
popupmenu_floatedit->add_child(timer_popupmenu_floatedit);
|
||||
|
||||
timer_popupmenu_floatedit->set_name("Timer");
|
||||
//timer_popupmenu_floatedit->set("name", Timer));
|
||||
|
||||
timer_popupmenu_floatedit->set_wait_time(0.3);
|
||||
//timer_popupmenu_floatedit->set("wait_time", 0.3);
|
||||
|
||||
timer_popupmenu_floatedit->set_one_shot(True);
|
||||
//timer_popupmenu_floatedit->set("one_shot", True);
|
||||
|
||||
|
||||
|
||||
ColorRect *slider_floatedit = memnew(ColorRect);
|
||||
slider_floatedit->set_name("Slider");
|
||||
floatedit->add_child(slider_floatedit);
|
||||
|
||||
slider_floatedit->set_name("Slider");
|
||||
//slider_floatedit->set("name", Slider));
|
||||
|
||||
//slider_floatedit property owner TYPE_OBJECT value: FloatEdit:[LineEdit:55206]
|
||||
|
||||
slider_floatedit->set_anchor_top(1);
|
||||
//slider_floatedit->set("anchor_top", 1);
|
||||
|
||||
slider_floatedit->set_anchor_right(1);
|
||||
//slider_floatedit->set("anchor_right", 1);
|
||||
|
||||
slider_floatedit->set_anchor_bottom(1);
|
||||
//slider_floatedit->set("anchor_bottom", 1);
|
||||
|
||||
slider_floatedit->set_margin_left(2);
|
||||
//slider_floatedit->set("margin_left", 2);
|
||||
|
||||
slider_floatedit->set_margin_top(-3);
|
||||
//slider_floatedit->set("margin_top", -3);
|
||||
|
||||
slider_floatedit->set_margin_right(-2);
|
||||
//slider_floatedit->set("margin_right", -2);
|
||||
|
||||
slider_floatedit->set_margin_bottom(-3);
|
||||
//slider_floatedit->set("margin_bottom", -3);
|
||||
|
||||
slider_floatedit->set_rect_position(Vector2(2, -3));
|
||||
//slider_floatedit->set("rect_position", Vector2(2, -3));
|
||||
|
||||
slider_floatedit->set_rect_global_position(Vector2(2, -3));
|
||||
//slider_floatedit->set("rect_global_position", Vector2(2, -3));
|
||||
|
||||
slider_floatedit->set_rect_min_size(Vector2(0, 2));
|
||||
//slider_floatedit->set("rect_min_size", Vector2(0, 2));
|
||||
|
||||
slider_floatedit->set_mouse_filter(2);
|
||||
//slider_floatedit->set("mouse_filter", 2);
|
||||
|
||||
slider_floatedit->set_color(Color(0.501961, 0.501961, 0.501961, 1));
|
||||
//slider_floatedit->set("color", Color(0.501961, 0.501961, 0.501961, 1));
|
||||
|
||||
|
||||
|
||||
ColorRect *cursor_slider_floatedit = memnew(ColorRect);
|
||||
cursor_slider_floatedit->set_name("Cursor");
|
||||
slider_floatedit->add_child(cursor_slider_floatedit);
|
||||
|
||||
cursor_slider_floatedit->set_name("Cursor");
|
||||
//cursor_slider_floatedit->set("name", Cursor));
|
||||
|
||||
//cursor_slider_floatedit property owner TYPE_OBJECT value: FloatEdit:[LineEdit:55206]
|
||||
|
||||
cursor_slider_floatedit->set_margin_right(3);
|
||||
//cursor_slider_floatedit->set("margin_right", 3);
|
||||
|
||||
cursor_slider_floatedit->set_margin_bottom(1);
|
||||
//cursor_slider_floatedit->set("margin_bottom", 1);
|
||||
|
||||
cursor_slider_floatedit->set_rect_size(Vector2(3, 1));
|
||||
//cursor_slider_floatedit->set("rect_size", Vector2(3, 1));
|
||||
|
||||
cursor_slider_floatedit->set_rect_min_size(Vector2(3, 2));
|
||||
//cursor_slider_floatedit->set("rect_min_size", Vector2(3, 2));
|
||||
|
||||
cursor_slider_floatedit->set_mouse_filter(2);
|
||||
//cursor_slider_floatedit->set("mouse_filter", 2);
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
@ -1,93 +1,81 @@
|
||||
#ifndef FLOAT_EDIT_H
|
||||
#define FLOAT_EDIT_H
|
||||
|
||||
#include "core/os/input_event.h"
|
||||
#include "scene/gui/line_edit.h"
|
||||
|
||||
class ColorRect;
|
||||
|
||||
class FloatEdit : public LineEdit {
|
||||
GDCLASS(FloatEdit, LineEdit);
|
||||
GDCLASS(FloatEdit, LineEdit);
|
||||
|
||||
public:
|
||||
public:
|
||||
float get_value() const;
|
||||
void set_value_float(const float val);
|
||||
void set_value(const Variant &val);
|
||||
|
||||
float get_value() const;
|
||||
void set_value(const float val);
|
||||
float get_min_value() const;
|
||||
void set_min_value(const float val);
|
||||
|
||||
float get_min_value() const;
|
||||
void set_min_value(const float val);
|
||||
float get_max_value() const;
|
||||
void set_max_value(const float val);
|
||||
|
||||
float get_max_value() const;
|
||||
void set_max_value(const float val);
|
||||
float get_step() const;
|
||||
void set_step(const float val);
|
||||
|
||||
float get_step() const;
|
||||
void set_step(const float val);
|
||||
bool get_float_only() const;
|
||||
void set_float_only(const bool val);
|
||||
|
||||
bool get_float_only() const;
|
||||
void set_float_only(const bool val);
|
||||
bool get_sliding() const;
|
||||
void set_sliding(const bool val);
|
||||
|
||||
bool get_sliding() const;
|
||||
void set_sliding(const bool val);
|
||||
float get_start_position() const;
|
||||
void set_start_position(const float val);
|
||||
|
||||
float get_start_position() const;
|
||||
void set_start_position(const float val);
|
||||
float get_last_position() const;
|
||||
void set_last_position(const float val);
|
||||
|
||||
float get_last_position() const;
|
||||
void set_last_position(const float val);
|
||||
float get_start_value() const;
|
||||
void set_start_value(const float val);
|
||||
|
||||
float get_start_value() const;
|
||||
void set_start_value(const float val);
|
||||
bool get_from_lower_bound() const;
|
||||
void set_from_lower_bound(const bool val);
|
||||
|
||||
int get_modifiers() const;
|
||||
void set_modifiers(const int val);
|
||||
bool get_from_upper_bound() const;
|
||||
void set_from_upper_bound(const bool val);
|
||||
|
||||
bool get_from_lower_bound() const;
|
||||
void set_from_lower_bound(const bool val);
|
||||
void do_update(const bool update_text = true);
|
||||
|
||||
bool get_from_upper_bound() const;
|
||||
void set_from_upper_bound(const bool val);
|
||||
int get_modifiers(const Ref<InputEventMouseButton> &event);
|
||||
|
||||
void _ready();
|
||||
void set_value(const Variant &v);
|
||||
void set_min_value(const float v);
|
||||
void set_max_value(const float v);
|
||||
void set_step(const float v);
|
||||
void do_update(const bool update_text = true);
|
||||
void get_modifiers(const Variant &event);
|
||||
void _on_LineEdit_gui_input(const InputEvent &event);
|
||||
void _on_LineEdit_text_changed(const String &new_text);
|
||||
void _on_LineEdit_text_entered(const String &new_text, const Variant &release = true);
|
||||
void _on_FloatEdit_focus_entered();
|
||||
void _on_LineEdit_focus_exited();
|
||||
void _on_LineEdit_gui_input(const Ref<InputEvent> &event);
|
||||
void _on_LineEdit_text_changed(const String &new_text);
|
||||
void _on_LineEdit_text_entered(const String &new_text, const Variant &release = true);
|
||||
void _on_FloatEdit_focus_entered();
|
||||
void _on_LineEdit_focus_exited();
|
||||
|
||||
FloatEdit();
|
||||
~FloatEdit();
|
||||
FloatEdit();
|
||||
~FloatEdit();
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
protected:
|
||||
void _notification(int p_what);
|
||||
|
||||
//tool
|
||||
//export
|
||||
// setget set_value
|
||||
float value = 0.5;
|
||||
//export
|
||||
// setget set_min_value
|
||||
float min_value = 0.0;
|
||||
//export
|
||||
// setget set_max_value
|
||||
float max_value = 1.0;
|
||||
//export
|
||||
// setget set_step
|
||||
float step = 0.0;
|
||||
//export
|
||||
bool float_only = false;
|
||||
bool sliding = false;
|
||||
float start_position = ;
|
||||
float last_position = ;
|
||||
float start_value = ;
|
||||
int modifiers = ;
|
||||
bool from_lower_bound = false;
|
||||
bool from_upper_bound = false;
|
||||
onready var slider = $Slider;
|
||||
onready var cursor = $Slider/Cursor;
|
||||
signal value_changed(value);
|
||||
static void _bind_methods();
|
||||
|
||||
float value;
|
||||
float min_value;
|
||||
float max_value;
|
||||
float step;
|
||||
bool float_only;
|
||||
bool sliding;
|
||||
float start_position;
|
||||
float last_position;
|
||||
float start_value;
|
||||
int modifiers;
|
||||
bool from_lower_bound;
|
||||
bool from_upper_bound;
|
||||
ColorRect *slider;
|
||||
ColorRect *cursor;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user