Fixed resizing the canvas. Also now the new menu will clear all layers.

This commit is contained in:
Relintai 2022-06-21 22:58:54 +02:00
parent fed839a235
commit 45d8f98459
6 changed files with 35 additions and 8 deletions

View File

@ -57,6 +57,7 @@ void PaintCanvasDialog::_on_about_to_show() {
PaintCanvasDialog::PaintCanvasDialog() {
_x_prev_val = 0;
_y_prev_val = 0;
is_new = false;
set_resizable(true);
set_title("Please Confirm...");

View File

@ -45,6 +45,8 @@ public:
PaintCanvasDialog();
~PaintCanvasDialog();
bool is_new;
protected:
void _on_confirmed();
void _on_about_to_show();

View File

@ -233,17 +233,21 @@ Ref<PaintCanvasLayer> PaintCanvas::remove_layer(const String &layer_name) {
del_layer->clear();
if (del_layer == active_layer) {
for (int i = 0; i < layers.size(); ++i) {
Ref<PaintCanvasLayer> layer = layers[i];
if (layers.size() > 1) {
for (int i = 0; i < layers.size(); ++i) {
Ref<PaintCanvasLayer> layer = layers[i];
ERR_CONTINUE(!layer.is_valid());
ERR_CONTINUE(!layer.is_valid());
if (layer == active_layer) {
continue;
if (layer == active_layer) {
continue;
}
active_layer = layer;
break;
}
active_layer = layer;
break;
} else {
active_layer.unref();
}
}

View File

@ -41,6 +41,7 @@ SOFTWARE.
void PaintNavbar::handle_menu_item_pressed(const int id) {
switch (id) {
case MENU_FILE_NEW:
paint_window->paint_canvas_dialog->is_new = true;
paint_window->paint_canvas_dialog->popup_centered();
break;
case MENU_FILE_SAVE:
@ -60,6 +61,7 @@ void PaintNavbar::handle_menu_item_pressed(const int id) {
case MENU_EDIT_PASTE:
break;
case MENU_CANVAS_CHANGE_SIZE:
paint_window->paint_canvas_dialog->is_new = false;
paint_window->paint_canvas_dialog->popup_centered();
break;
case MENU_CANVAS_CROP_TO_CONTENT:

View File

@ -784,6 +784,11 @@ void PaintWindow::_on_ChangeGridSizeDialog_confirmed() {
}
void PaintWindow::_on_ChangeCanvasSizeDialog_confirmed() {
if (paint_canvas_dialog->is_new) {
delete_all_layers();
add_new_layer();
}
paint_canvas->resize(paint_canvas_dialog->get_size_x(), paint_canvas_dialog->get_size_y());
}
@ -925,6 +930,18 @@ void PaintWindow::duplicate_active_layer() {
//print("added layer: ", new_layer.name, " (total:", layers_box_container.get_child_count(), ")")
}
void PaintWindow::delete_all_layers() {
while (paint_canvas->layers.size() > 0) {
String layer_name = paint_canvas->layers[0]->name;
paint_canvas->remove_layer(layer_name);
layers_box_container->remove_child(_layer_button_ref[layer_name]);
_layer_button_ref[layer_name]->queue_delete();
_layer_button_ref.erase(layer_name);
}
_total_added_layers = 0;
}
void PaintWindow::move_up(Node *layer_btn) {
int new_idx = MIN(layer_btn->get_index() + 1, layers_box_container->get_child_count());
//print("move_up: ", layer_btn.name, " from ", layer_btn.get_index(), " to ", new_idx)

View File

@ -143,6 +143,7 @@ public:
Ref<PaintCanvasLayer> add_new_layer();
void remove_active_layer();
void duplicate_active_layer();
void delete_all_layers();
void move_up(Node *layer_btn);
void move_down(Node *layer_btn);