diff --git a/modules/paint/dialogs/paint_canvas_dialog.cpp b/modules/paint/dialogs/paint_canvas_dialog.cpp index 54951be6a..317eb1947 100644 --- a/modules/paint/dialogs/paint_canvas_dialog.cpp +++ b/modules/paint/dialogs/paint_canvas_dialog.cpp @@ -24,34 +24,109 @@ SOFTWARE. #include "paint_canvas_dialog.h" -void PaintCanvasDialog::_ready() { - /* - yield(owner, "ready") - find_node("Width").value = owner.paint_canvas.canvas_width - find_node("Height").value = owner.paint_canvas.canvas_height - */ +#include "scene/gui/box_container.h" +#include "scene/gui/label.h" +#include "scene/gui/spin_box.h" + +int PaintCanvasDialog::get_size_x() const { + return static_cast(size_x_spin_box->get_value()); } -void PaintCanvasDialog::_on_ConfirmationDialog_confirmed() { - /* - var width = find_node("Width").value - var height = find_node("Height").value - print("change canvas size: ", width, " ", height) - owner.paint_canvas.resize(width, height) - */ +void PaintCanvasDialog::set_size_x(const int val) { + size_x_spin_box->set_value(val); + _x_prev_val = val; } -void PaintCanvasDialog::_on_ChangeCanvasSize_visibility_changed() { - /* - if visible: - find_node("Width").value = owner.paint_canvas.canvas_width - find_node("Height").value = owner.paint_canvas.canvas_height - */ + +int PaintCanvasDialog::get_size_y() const { + return static_cast(size_y_spin_box->get_value()); +} +void PaintCanvasDialog::set_size_y(const int val) { + size_y_spin_box->set_value(val); + _y_prev_val = val; +} + +void PaintCanvasDialog::_on_confirmed() { + _x_prev_val = get_size_x(); + _y_prev_val = get_size_y(); +} + +void PaintCanvasDialog::_on_about_to_show() { + set_size_x(_x_prev_val); + set_size_y(_y_prev_val); } PaintCanvasDialog::PaintCanvasDialog() { + _x_prev_val = 0; + _y_prev_val = 0; + + set_resizable(true); + set_title("Please Confirm..."); + + VBoxContainer *main_box_container = memnew(VBoxContainer); + add_child(main_box_container); + + Label *main_label = memnew(Label); + main_label->set_text("Change canvas size?"); + main_label->set_align(Label::ALIGN_CENTER); + main_label->set_v_size_flags(Control::SIZE_EXPAND_FILL); + main_label->set_h_size_flags(Control::SIZE_EXPAND_FILL); + main_box_container->add_child(main_label); + + HBoxContainer *grid_spin_container = memnew(HBoxContainer); + grid_spin_container->set_v_size_flags(Control::SIZE_EXPAND_FILL); + grid_spin_container->set_h_size_flags(Control::SIZE_EXPAND_FILL); + main_box_container->add_child(grid_spin_container); + + Label *grid_label = memnew(Label); + grid_label->set_text("Width (X)"); + grid_label->set_align(Label::ALIGN_CENTER); + grid_label->set_v_size_flags(Control::SIZE_EXPAND_FILL); + grid_label->set_h_size_flags(Control::SIZE_EXPAND_FILL); + grid_spin_container->add_child(grid_label); + + size_x_spin_box = memnew(SpinBox); + size_x_spin_box->set_value(64); + size_x_spin_box->set_min(1); + size_x_spin_box->set_max(2500); + size_x_spin_box->set_v_size_flags(Control::SIZE_EXPAND_FILL); + size_x_spin_box->set_h_size_flags(Control::SIZE_EXPAND_FILL); + grid_spin_container->add_child(size_x_spin_box); + + HBoxContainer *big_grid_spin_container = memnew(HBoxContainer); + big_grid_spin_container->set_v_size_flags(Control::SIZE_EXPAND_FILL); + big_grid_spin_container->set_h_size_flags(Control::SIZE_EXPAND_FILL); + main_box_container->add_child(big_grid_spin_container); + + grid_label = memnew(Label); + grid_label->set_text("Height (Y)"); + grid_label->set_align(Label::ALIGN_CENTER); + grid_label->set_v_size_flags(Control::SIZE_EXPAND_FILL); + grid_label->set_h_size_flags(Control::SIZE_EXPAND_FILL); + big_grid_spin_container->add_child(grid_label); + + size_y_spin_box = memnew(SpinBox); + size_y_spin_box->set_value(64); + size_y_spin_box->set_min(1); + size_y_spin_box->set_max(2500); + size_y_spin_box->set_v_size_flags(Control::SIZE_EXPAND_FILL); + size_y_spin_box->set_h_size_flags(Control::SIZE_EXPAND_FILL); + big_grid_spin_container->add_child(size_y_spin_box); } PaintCanvasDialog::~PaintCanvasDialog() { } -void PaintCanvasDialog::_bind_methods() { +void PaintCanvasDialog::_notification(int p_what) { + switch (p_what) { + case NOTIFICATION_POSTINITIALIZE: { + connect("confirmed", this, "_on_confirmed"); + connect("about_to_show", this, "_on_about_to_show"); + } break; + default: { + } break; + } +} + +void PaintCanvasDialog::_bind_methods() { + ClassDB::bind_method(D_METHOD("_on_confirmed"), &PaintCanvasDialog::_on_confirmed); + ClassDB::bind_method(D_METHOD("_on_about_to_show"), &PaintCanvasDialog::_on_about_to_show); } diff --git a/modules/paint/dialogs/paint_canvas_dialog.h b/modules/paint/dialogs/paint_canvas_dialog.h index 8ffb1009e..d187b828a 100644 --- a/modules/paint/dialogs/paint_canvas_dialog.h +++ b/modules/paint/dialogs/paint_canvas_dialog.h @@ -27,18 +27,32 @@ SOFTWARE. #include "scene/gui/dialogs.h" +class SpinBox; + class PaintCanvasDialog : public ConfirmationDialog { GDCLASS(PaintCanvasDialog, ConfirmationDialog); public: - void _ready(); - void _on_ConfirmationDialog_confirmed(); - void _on_ChangeCanvasSize_visibility_changed(); + int get_size_x() const; + void set_size_x(const int val); + + int get_size_y() const; + void set_size_y(const int val); + + SpinBox *size_x_spin_box; + SpinBox *size_y_spin_box; PaintCanvasDialog(); ~PaintCanvasDialog(); protected: + void _on_confirmed(); + void _on_about_to_show(); + + int _x_prev_val; + int _y_prev_val; + + void _notification(int p_what); static void _bind_methods(); }; diff --git a/modules/paint/dialogs/paint_change_grid_size_dialog.cpp b/modules/paint/dialogs/paint_change_grid_size_dialog.cpp index f01a0d88e..9aabb764c 100644 --- a/modules/paint/dialogs/paint_change_grid_size_dialog.cpp +++ b/modules/paint/dialogs/paint_change_grid_size_dialog.cpp @@ -24,36 +24,75 @@ SOFTWARE. #include "paint_change_grid_size_dialog.h" -void PaintChangeGridSizeDialog::_ready() { - /* - yield(owner, "ready") - find_node("GridValue").value = owner.paint_canvas.grid_size - find_node("BigGridValue").value = owner.paint_canvas.big_grid_size - */ +#include "scene/gui/box_container.h" +#include "scene/gui/label.h" +#include "scene/gui/spin_box.h" + +int PaintChangeGridSizeDialog::get_grid_value() const { + return static_cast(grid_spin_box->get_value()); +} +void PaintChangeGridSizeDialog::set_grid_value(const int val) { + grid_spin_box->set_value(val); } -void PaintChangeGridSizeDialog::_on_ChangeGridSizeDialog_confirmed() { - /* - var grid_size = find_node("GridValue").value - var big_grid_size = find_node("BigGridValue").value - owner.paint_canvas.grid_size = grid_size - owner.paint_canvas.big_grid_size = big_grid_size - */ +int PaintChangeGridSizeDialog::get_big_grid_value() const { + return static_cast(big_grid_spin_box->get_value()); } -void PaintChangeGridSizeDialog::_on_GridValue_value_changed(float value) { - /* - var grid_size = value - owner.paint_canvas.grid_size = grid_size - */ -} -void PaintChangeGridSizeDialog::_on_BigGridValue_value_changed(float value) { - /* - var big_grid_size = value - owner.paint_canvas.big_grid_size = big_grid_size - */ +void PaintChangeGridSizeDialog::set_big_grid_value(const int val) { + big_grid_spin_box->set_value(val); } PaintChangeGridSizeDialog::PaintChangeGridSizeDialog() { + set_resizable(true); + set_title("Change Grid Size"); + + VBoxContainer *main_box_container = memnew(VBoxContainer); + add_child(main_box_container); + + Label *main_label = memnew(Label); + main_label->set_text("Change Grid Size"); + main_label->set_align(Label::ALIGN_CENTER); + main_label->set_v_size_flags(Control::SIZE_EXPAND_FILL); + main_label->set_h_size_flags(Control::SIZE_EXPAND_FILL); + main_box_container->add_child(main_label); + + HBoxContainer *grid_spin_container = memnew(HBoxContainer); + grid_spin_container->set_v_size_flags(Control::SIZE_EXPAND_FILL); + grid_spin_container->set_h_size_flags(Control::SIZE_EXPAND_FILL); + main_box_container->add_child(grid_spin_container); + + Label *grid_label = memnew(Label); + grid_label->set_text("Grid 1"); + grid_label->set_align(Label::ALIGN_CENTER); + grid_label->set_v_size_flags(Control::SIZE_EXPAND_FILL); + grid_label->set_h_size_flags(Control::SIZE_EXPAND_FILL); + grid_spin_container->add_child(grid_label); + + grid_spin_box = memnew(SpinBox); + grid_spin_box->set_value(1); + grid_spin_box->set_max(2500); + grid_spin_box->set_v_size_flags(Control::SIZE_EXPAND_FILL); + grid_spin_box->set_h_size_flags(Control::SIZE_EXPAND_FILL); + grid_spin_container->add_child(grid_spin_box); + + HBoxContainer *big_grid_spin_container = memnew(HBoxContainer); + big_grid_spin_container->set_v_size_flags(Control::SIZE_EXPAND_FILL); + big_grid_spin_container->set_h_size_flags(Control::SIZE_EXPAND_FILL); + main_box_container->add_child(big_grid_spin_container); + + grid_label = memnew(Label); + grid_label->set_text("Grid 2"); + grid_label->set_align(Label::ALIGN_CENTER); + grid_label->set_v_size_flags(Control::SIZE_EXPAND_FILL); + grid_label->set_h_size_flags(Control::SIZE_EXPAND_FILL); + big_grid_spin_container->add_child(grid_label); + + big_grid_spin_box = memnew(SpinBox); + big_grid_spin_box->set_value(8); + big_grid_spin_box->set_max(2500); + big_grid_spin_box->set_v_size_flags(Control::SIZE_EXPAND_FILL); + big_grid_spin_box->set_h_size_flags(Control::SIZE_EXPAND_FILL); + big_grid_spin_container->add_child(big_grid_spin_box); } PaintChangeGridSizeDialog::~PaintChangeGridSizeDialog() { diff --git a/modules/paint/dialogs/paint_change_grid_size_dialog.h b/modules/paint/dialogs/paint_change_grid_size_dialog.h index a0920d64f..7e4f32e6e 100644 --- a/modules/paint/dialogs/paint_change_grid_size_dialog.h +++ b/modules/paint/dialogs/paint_change_grid_size_dialog.h @@ -27,18 +27,24 @@ SOFTWARE. #include "scene/gui/dialogs.h" +class SpinBox; + class PaintChangeGridSizeDialog : public AcceptDialog { GDCLASS(PaintChangeGridSizeDialog, AcceptDialog); public: - void _ready(); - void _on_ChangeGridSizeDialog_confirmed(); - void _on_GridValue_value_changed(float value); - void _on_BigGridValue_value_changed(float value); + int get_grid_value() const; + void set_grid_value(const int val); + + int get_big_grid_value() const; + void set_big_grid_value(const int val); PaintChangeGridSizeDialog(); ~PaintChangeGridSizeDialog(); + SpinBox *grid_spin_box; + SpinBox *big_grid_spin_box; + protected: static void _bind_methods(); }; diff --git a/modules/paint/paint_canvas.cpp b/modules/paint/paint_canvas.cpp index 68fb0ced0..d313e523e 100644 --- a/modules/paint/paint_canvas.cpp +++ b/modules/paint/paint_canvas.cpp @@ -533,6 +533,10 @@ PoolVector2iArray PaintCanvas::get_neighbouring_pixels(const int pos_x, const in } void PaintCanvas::resize(int width, int height) { + if (get_canvas_width() == width && get_canvas_height() == height) { + return; + } + if (width < 0) { width = 1; } diff --git a/modules/paint/paint_window.cpp b/modules/paint/paint_window.cpp index c3d5b993f..77e0602ab 100644 --- a/modules/paint/paint_window.cpp +++ b/modules/paint/paint_window.cpp @@ -782,6 +782,15 @@ void PaintWindow::_on_Editor_visibility_changed() { set_process(is_visible_in_tree()); } +void PaintWindow::_on_ChangeGridSizeDialog_confirmed() { + paint_canvas->set_grid_size(paint_change_grid_size_dialog->get_grid_value()); + paint_canvas->set_big_grid_size(paint_change_grid_size_dialog->get_big_grid_value()); +} + +void PaintWindow::_on_ChangeCanvasSizeDialog_confirmed() { + paint_canvas->resize(paint_canvas_dialog->get_size_x(), paint_canvas_dialog->get_size_y()); +} + void PaintWindow::highlight_layer(const String &layer_name) { for (int i = 0; i < layers_box_container->get_child_count(); ++i) { PaintLayerButton *button = Object::cast_to(layers_box_container->get_child(i)); @@ -1407,10 +1416,16 @@ PaintWindow::PaintWindow() { //PaintCanvasDialog paint_canvas_dialog = memnew(PaintCanvasDialog); + paint_canvas_dialog->set_size_x(64); + paint_canvas_dialog->set_size_y(64); + paint_canvas_dialog->connect("confirmed", this, "_on_ChangeCanvasSizeDialog_confirmed"); add_child(paint_canvas_dialog); //PaintChangeGridSizeDialog paint_change_grid_size_dialog = memnew(PaintChangeGridSizeDialog); + paint_change_grid_size_dialog->set_grid_value(1); + paint_change_grid_size_dialog->set_big_grid_value(8); + paint_change_grid_size_dialog->connect("confirmed", this, "_on_ChangeGridSizeDialog_confirmed"); add_child(paint_change_grid_size_dialog); //PaintLoadFileDialog @@ -1432,6 +1447,9 @@ PaintWindow::PaintWindow() { set_brush(Tools::PAINT); + _on_ChangeCanvasSizeDialog_confirmed(); + _on_ChangeGridSizeDialog_confirmed(); + //find_node("CanvasBackground").material.set_shader_param("pixel_size", 8 * pow(0.5, big_grid_pixels)/paint_canvas.pixel_size) add_new_layer(); @@ -1459,6 +1477,8 @@ void PaintWindow::_bind_methods() { ClassDB::bind_method(D_METHOD("_on_ColorPickerTool_pressed"), &PaintWindow::_on_ColorPickerTool_pressed); ClassDB::bind_method(D_METHOD("_on_CutTool_pressed"), &PaintWindow::_on_CutTool_pressed); ClassDB::bind_method(D_METHOD("_on_Editor_visibility_changed"), &PaintWindow::_on_Editor_visibility_changed); + ClassDB::bind_method(D_METHOD("_on_ChangeGridSizeDialog_confirmed"), &PaintWindow::_on_ChangeGridSizeDialog_confirmed); + ClassDB::bind_method(D_METHOD("_on_ChangeCanvasSizeDialog_confirmed"), &PaintWindow::_on_ChangeCanvasSizeDialog_confirmed); ClassDB::bind_method(D_METHOD("_on_Button_pressed"), &PaintWindow::_on_Button_pressed); ClassDB::bind_method(D_METHOD("_on_PaintCanvasContainer_mouse_entered"), &PaintWindow::_on_PaintCanvasContainer_mouse_entered); diff --git a/modules/paint/paint_window.h b/modules/paint/paint_window.h index fa5aa6b69..a025eee34 100644 --- a/modules/paint/paint_window.h +++ b/modules/paint/paint_window.h @@ -132,6 +132,8 @@ public: void _on_ColorPickerTool_pressed(); void _on_CutTool_pressed(); void _on_Editor_visibility_changed(); + void _on_ChangeGridSizeDialog_confirmed(); + void _on_ChangeCanvasSizeDialog_confirmed(); void highlight_layer(const String &layer_name); void toggle_layer_visibility(Node *button, const String &layer_name);