Now the MMTones Editor actually works.

This commit is contained in:
Relintai 2023-03-04 15:11:55 +01:00
parent 51b63cae71
commit fc969f4331
6 changed files with 85 additions and 16 deletions

View File

@ -26,6 +26,8 @@ void MMTonesEditor::set_value(const Ref<MMTones> &v) {
if (_node.is_valid()) { if (_node.is_valid()) {
_node->get_image()->connect("changed", this, "on_input_property_changed"); _node->get_image()->connect("changed", this, "on_input_property_changed");
set_mode(static_cast<Modes>(_node->get_current_mode()));
} }
on_input_property_changed(); on_input_property_changed();
@ -39,6 +41,17 @@ enum ParameterTypes {
PARAMETER_TYPE_OUT_MAX, PARAMETER_TYPE_OUT_MAX,
}; };
void MMTonesEditor::set_mode(Modes mode) {
_current_mode = mode;
_mode_ob->select(static_cast<int>(mode));
_cursor_in_min->set_value(get_parameter_current_mode(PARAMETER_TYPE_IN_MIN));
_cursor_in_mid->set_value(get_parameter_current_mode(PARAMETER_TYPE_IN_MID));
_cursor_in_max->set_value(get_parameter_current_mode(PARAMETER_TYPE_IN_MAX));
_cursor_out_min->set_value(get_parameter_current_mode(PARAMETER_TYPE_OUT_MIN));
_cursor_out_max->set_value(get_parameter_current_mode(PARAMETER_TYPE_OUT_MAX));
}
Color MMTonesEditor::get_parameter(ParameterTypes type) { Color MMTonesEditor::get_parameter(ParameterTypes type) {
if (!_node.is_valid()) { if (!_node.is_valid()) {
return Color(); return Color();
@ -195,9 +208,11 @@ MMTonesEditor::MMTonesEditor() {
auto_button->set_tooltip("Set levels automatically"); auto_button->set_tooltip("Set levels automatically");
auto_button->set_v_size_flags(Control::SIZE_SHRINK_CENTER); auto_button->set_v_size_flags(Control::SIZE_SHRINK_CENTER);
/*
Control *spacer = memnew(Control); Control *spacer = memnew(Control);
spacer->set_custom_minimum_size(Vector2(0, 4)); spacer->set_custom_minimum_size(Vector2(0, 4));
add_child(spacer); add_child(spacer);
*/
_histogram_tr = memnew(TextureRect); _histogram_tr = memnew(TextureRect);
_histogram_tr->set_custom_minimum_size(Vector2(0, 100)); _histogram_tr->set_custom_minimum_size(Vector2(0, 100));
@ -228,11 +243,11 @@ MMTonesEditor::MMTonesEditor() {
_cursor_out_min->connect("cursor_value_changed", this, "on_cursor_value_changed"); _cursor_out_min->connect("cursor_value_changed", this, "on_cursor_value_changed");
_cursor_out_max->connect("cursor_value_changed", this, "on_cursor_value_changed"); _cursor_out_max->connect("cursor_value_changed", this, "on_cursor_value_changed");
/*
spacer = memnew(Control); spacer = memnew(Control);
spacer->set_custom_minimum_size(Vector2(0, 4)); spacer->set_custom_minimum_size(Vector2(0, 4));
add_child(spacer); add_child(spacer);
*/
on_mode_item_selected(MODE_LUMINANCE);
} }
MMTonesEditor::~MMTonesEditor() { MMTonesEditor::~MMTonesEditor() {
@ -293,13 +308,8 @@ void MMTonesEditor::on_auto_levels_pressed() {
} }
void MMTonesEditor::on_mode_item_selected(int id) { void MMTonesEditor::on_mode_item_selected(int id) {
_current_mode = static_cast<Modes>(id); _node->set_current_mode(id);
set_mode(static_cast<Modes>(id));
_cursor_in_min->set_value(get_parameter_current_mode(PARAMETER_TYPE_IN_MIN));
_cursor_in_mid->set_value(get_parameter_current_mode(PARAMETER_TYPE_IN_MID));
_cursor_in_max->set_value(get_parameter_current_mode(PARAMETER_TYPE_IN_MAX));
_cursor_out_min->set_value(get_parameter_current_mode(PARAMETER_TYPE_OUT_MIN));
_cursor_out_max->set_value(get_parameter_current_mode(PARAMETER_TYPE_OUT_MAX));
} }
void MMTonesEditor::on_cursor_value_changed(Control *cursor, float position) { void MMTonesEditor::on_cursor_value_changed(Control *cursor, float position) {

View File

@ -37,6 +37,8 @@ public:
PARAMETER_TYPE_OUT_MAX, PARAMETER_TYPE_OUT_MAX,
}; };
void set_mode(Modes mode);
Color get_parameter(ParameterTypes type); Color get_parameter(ParameterTypes type);
float get_parameter_current_mode(ParameterTypes type); float get_parameter_current_mode(ParameterTypes type);

View File

@ -48,10 +48,49 @@ void MMTonesEditorCursor::resize() {
} }
void MMTonesEditorCursor::_gui_input(const Ref<InputEvent> &p_event) { void MMTonesEditorCursor::_gui_input(const Ref<InputEvent> &p_event) {
Ref<InputEventMouseButton> iemb = p_event;
if (iemb.is_valid()) {
if (iemb->is_pressed()) {
if (_pointer_index != -1) {
return;
}
if (iemb->get_button_index() != BUTTON_LEFT) {
return;
}
_pointer_index = 1;
} else {
if (_pointer_index != 1) {
return;
}
_pointer_index = -1;
Control *parent = get_parent_control();
if (!parent) {
return;
}
Vector2 parent_size = parent->get_size();
Vector2 pos = get_position();
update_value(pos.x / parent_size.x);
}
return;
}
if (_pointer_index != 1) {
return;
}
Ref<InputEventMouseMotion> iemm = p_event; Ref<InputEventMouseMotion> iemm = p_event;
if (iemm.is_valid()) { if (iemm.is_valid()) {
if (((iemm->get_button_mask() & 1) != 0)) {
Control *parent = get_parent_control(); Control *parent = get_parent_control();
if (!parent) { if (!parent) {
@ -65,12 +104,13 @@ void MMTonesEditorCursor::_gui_input(const Ref<InputEvent> &p_event) {
pos.x += iemm->get_relative().x; pos.x += iemm->get_relative().x;
pos.x = MIN(MAX(-0.5 * CURSOR_WIDTH, pos.x), parent_size.x - 0.5 * CURSOR_WIDTH); pos.x = MIN(MAX(-0.5 * CURSOR_WIDTH, pos.x), parent_size.x - 0.5 * CURSOR_WIDTH);
update_value((pos.x + 0.5 * CURSOR_WIDTH) / parent_size.x); set_value((pos.x + 0.5 * CURSOR_WIDTH) / parent_size.x);
}
} }
} }
MMTonesEditorCursor::MMTonesEditorCursor() { MMTonesEditorCursor::MMTonesEditorCursor() {
_pointer_index = -1;
set_mouse_filter(MOUSE_FILTER_STOP);
} }
MMTonesEditorCursor::~MMTonesEditorCursor() { MMTonesEditorCursor::~MMTonesEditorCursor() {

View File

@ -31,6 +31,8 @@ protected:
Color _color; Color _color;
float _position; float _position;
bool _top; bool _top;
int _pointer_index;
}; };
#endif #endif

View File

@ -61,6 +61,13 @@ void MMTones::set_out_min(const Color &val) {
set_dirty(true); set_dirty(true);
} }
int MMTones::get_current_mode() {
return _current_mode;
}
void MMTones::set_current_mode(int val) {
_current_mode = val;
}
void MMTones::_init_properties() { void MMTones::_init_properties() {
if (!input.is_valid()) { if (!input.is_valid()) {
input.instance(); input.instance();
@ -113,6 +120,8 @@ MMTones::MMTones() {
_in_min = Color(0, 0, 0, 0); _in_min = Color(0, 0, 0, 0);
_out_max = Color(1, 1, 1, 1); _out_max = Color(1, 1, 1, 1);
_out_min = Color(0, 0, 0, 0); _out_min = Color(0, 0, 0, 0);
_current_mode = 0;
} }
MMTones::~MMTones() { MMTones::~MMTones() {

View File

@ -29,6 +29,10 @@ public:
Color get_out_min() const; Color get_out_min() const;
void set_out_min(const Color &val); void set_out_min(const Color &val);
// For the editor
int get_current_mode();
void set_current_mode(int val);
void _init_properties(); void _init_properties();
void _register_methods(MMGraphNode *mm_graph_node); void _register_methods(MMGraphNode *mm_graph_node);
void _render(const Ref<MMMaterial> &material); void _render(const Ref<MMMaterial> &material);
@ -48,6 +52,8 @@ protected:
Color _in_min; Color _in_min;
Color _out_max; Color _out_max;
Color _out_min; Color _out_min;
int _current_mode;
}; };
#endif #endif