From 7219a5a2743121049d48448590ad9bca99fe0c51 Mon Sep 17 00:00:00 2001 From: OverloadedOrama <35376950+OverloadedOrama@users.noreply.github.com> Date: Sat, 13 Jun 2020 20:22:25 +0300 Subject: [PATCH] Added Resize Canvas option to Image menu --- Translations/Translations.pot | 9 +++++ src/Autoload/DrawingAlgos.gd | 18 ++++++++++ src/Main.tscn | 10 +++++- src/UI/Dialogs/ResizeCanvas.gd | 7 ++++ src/UI/Dialogs/ResizeCanvas.tscn | 61 ++++++++++++++++++++++++++++++++ src/UI/Dialogs/ScaleImage.tscn | 46 ++++++++++++------------ src/UI/TopMenuContainer.gd | 23 ++++++++---- 7 files changed, 142 insertions(+), 32 deletions(-) create mode 100644 src/UI/Dialogs/ResizeCanvas.gd create mode 100644 src/UI/Dialogs/ResizeCanvas.tscn diff --git a/Translations/Translations.pot b/Translations/Translations.pot index 55adc0f..c567351 100644 --- a/Translations/Translations.pot +++ b/Translations/Translations.pot @@ -19,6 +19,9 @@ msgstr "" msgid "Image Size" msgstr "" +msgid "Canvas Size" +msgstr "" + msgid "Width:" msgstr "" @@ -97,6 +100,9 @@ msgstr "" msgid "Crop Image" msgstr "" +msgid "Resize Canvas" +msgstr "" + msgid "Rotate Image" msgstr "" @@ -127,6 +133,9 @@ msgstr "" msgid "Show Animation Timeline" msgstr "" +msgid "Zen Mode" +msgstr "" + msgid "Fill with color:" msgstr "" diff --git a/src/Autoload/DrawingAlgos.gd b/src/Autoload/DrawingAlgos.gd index 2a9961a..94ff919 100644 --- a/src/Autoload/DrawingAlgos.gd +++ b/src/Autoload/DrawingAlgos.gd @@ -636,6 +636,24 @@ func crop_image(image : Image) -> void: Global.current_project.undo_redo.commit_action() +func resize_canvas(width : int, height : int) -> void: + Global.current_project.undos += 1 + Global.current_project.undo_redo.create_action("Scale") + Global.current_project.undo_redo.add_do_property(Global.current_project, "size", Vector2(width, height).floor()) + for f in Global.current_project.frames: + for c in f.cels: + var sprite := Image.new() + sprite.copy_from(c.image) + sprite.crop(width, height) + Global.current_project.undo_redo.add_do_property(c.image, "data", sprite.data) + Global.current_project.undo_redo.add_undo_property(c.image, "data", c.image.data) + + Global.current_project.undo_redo.add_undo_property(Global.current_project, "size", Global.current_project.size) + Global.current_project.undo_redo.add_undo_method(Global, "undo") + Global.current_project.undo_redo.add_do_method(Global, "redo") + Global.current_project.undo_redo.commit_action() + + func invert_image_colors(image : Image) -> void: Global.canvas.handle_undo("Draw") for xx in image.get_size().x: diff --git a/src/Main.tscn b/src/Main.tscn index f0fd625..d294395 100644 --- a/src/Main.tscn +++ b/src/Main.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=18 format=2] +[gd_scene load_steps=19 format=2] [ext_resource path="res://assets/themes/dark/theme.tres" type="Theme" id=1] [ext_resource path="res://src/Main.gd" type="Script" id=2] @@ -6,6 +6,7 @@ [ext_resource path="res://src/UI/UI.tscn" type="PackedScene" id=4] [ext_resource path="res://src/UI/PatternsPopup.tscn" type="PackedScene" id=5] [ext_resource path="res://src/UI/BrushesPopup.tscn" type="PackedScene" id=6] +[ext_resource path="res://src/UI/Dialogs/ResizeCanvas.tscn" type="PackedScene" id=7] [ext_resource path="res://src/UI/Dialogs/SaveSprite.tscn" type="PackedScene" id=11] [ext_resource path="res://src/UI/Dialogs/OpenSprite.tscn" type="PackedScene" id=12] [ext_resource path="res://src/UI/Dialogs/SplashDialog.tscn" type="PackedScene" id=27] @@ -50,13 +51,19 @@ __meta__ = { [node name="CreateNewImage" parent="." instance=ExtResource( 28 )] [node name="OpenSprite" parent="." instance=ExtResource( 12 )] +current_dir = "/Users" +current_path = "/Users/" [node name="SaveSprite" parent="." instance=ExtResource( 11 )] +current_dir = "/Users" +current_path = "/Users/" [node name="ExportDialog" parent="." instance=ExtResource( 39 )] [node name="ScaleImage" parent="." instance=ExtResource( 31 )] +[node name="ResizeCanvas" parent="." instance=ExtResource( 7 )] + [node name="PreferencesDialog" parent="." instance=ExtResource( 32 )] [node name="RotateImage" parent="." instance=ExtResource( 38 )] @@ -119,6 +126,7 @@ visible = false [connection signal="popup_hide" from="SaveSprite" to="." method="_can_draw_true"] [connection signal="popup_hide" from="ExportDialog" to="." method="_can_draw_true"] [connection signal="popup_hide" from="ScaleImage" to="." method="_can_draw_true"] +[connection signal="popup_hide" from="ResizeCanvas" to="." method="_can_draw_true"] [connection signal="popup_hide" from="PreferencesDialog" to="." method="_can_draw_true"] [connection signal="popup_hide" from="RotateImage" to="." method="_can_draw_true"] [connection signal="popup_hide" from="OutlineDialog" to="." method="_can_draw_true"] diff --git a/src/UI/Dialogs/ResizeCanvas.gd b/src/UI/Dialogs/ResizeCanvas.gd new file mode 100644 index 0000000..8c262f4 --- /dev/null +++ b/src/UI/Dialogs/ResizeCanvas.gd @@ -0,0 +1,7 @@ +extends ConfirmationDialog + + +func _on_ResizeCanvas_confirmed() -> void: + var width : int = $VBoxContainer/OptionsContainer/WidthValue.value + var height : int = $VBoxContainer/OptionsContainer/HeightValue.value + DrawingAlgos.resize_canvas(width, height) diff --git a/src/UI/Dialogs/ResizeCanvas.tscn b/src/UI/Dialogs/ResizeCanvas.tscn new file mode 100644 index 0000000..cfc2471 --- /dev/null +++ b/src/UI/Dialogs/ResizeCanvas.tscn @@ -0,0 +1,61 @@ +[gd_scene load_steps=2 format=2] + +[ext_resource path="res://src/UI/Dialogs/ResizeCanvas.gd" type="Script" id=1] + +[node name="ResizeCanvas" type="ConfirmationDialog"] +margin_right = 200.0 +margin_bottom = 114.0 +script = ExtResource( 1 ) + +[node name="VBoxContainer" type="VBoxContainer" parent="."] +margin_left = 8.0 +margin_top = 8.0 +margin_right = 192.0 +margin_bottom = 78.0 + +[node name="ImageSize" type="Label" parent="VBoxContainer"] +margin_right = 184.0 +margin_bottom = 14.0 +text = "Canvas Size" + +[node name="OptionsContainer" type="GridContainer" parent="VBoxContainer"] +margin_top = 18.0 +margin_right = 184.0 +margin_bottom = 70.0 +custom_constants/vseparation = 4 +custom_constants/hseparation = 2 +columns = 2 + +[node name="WidthLabel" type="Label" parent="VBoxContainer/OptionsContainer"] +margin_top = 5.0 +margin_right = 46.0 +margin_bottom = 19.0 +text = "Width:" + +[node name="WidthValue" type="SpinBox" parent="VBoxContainer/OptionsContainer"] +margin_left = 48.0 +margin_right = 122.0 +margin_bottom = 24.0 +mouse_default_cursor_shape = 2 +min_value = 1.0 +max_value = 16384.0 +value = 64.0 +suffix = "px" + +[node name="Height" type="Label" parent="VBoxContainer/OptionsContainer"] +margin_top = 33.0 +margin_right = 46.0 +margin_bottom = 47.0 +text = "Height:" + +[node name="HeightValue" type="SpinBox" parent="VBoxContainer/OptionsContainer"] +margin_left = 48.0 +margin_top = 28.0 +margin_right = 122.0 +margin_bottom = 52.0 +mouse_default_cursor_shape = 2 +min_value = 1.0 +max_value = 16384.0 +value = 64.0 +suffix = "px" +[connection signal="confirmed" from="." to="." method="_on_ResizeCanvas_confirmed"] diff --git a/src/UI/Dialogs/ScaleImage.tscn b/src/UI/Dialogs/ScaleImage.tscn index 2a2bd46..9bdc66a 100644 --- a/src/UI/Dialogs/ScaleImage.tscn +++ b/src/UI/Dialogs/ScaleImage.tscn @@ -2,8 +2,6 @@ [ext_resource path="res://src/UI/Dialogs/ScaleImage.gd" type="Script" id=1] - - [node name="ScaleImage" type="ConfirmationDialog"] margin_right = 200.0 margin_bottom = 114.0 @@ -17,27 +15,27 @@ margin_bottom = 102.0 [node name="ImageSize" type="Label" parent="VBoxContainer"] margin_right = 184.0 -margin_bottom = 15.0 +margin_bottom = 14.0 text = "Image Size" [node name="OptionsContainer" type="GridContainer" parent="VBoxContainer"] -margin_top = 19.0 +margin_top = 18.0 margin_right = 184.0 -margin_bottom = 90.0 +margin_bottom = 94.0 custom_constants/vseparation = 4 custom_constants/hseparation = 2 columns = 2 [node name="WidthLabel" type="Label" parent="VBoxContainer/OptionsContainer"] margin_top = 5.0 -margin_right = 72.0 -margin_bottom = 20.0 +margin_right = 87.0 +margin_bottom = 19.0 text = "Width:" [node name="WidthValue" type="SpinBox" parent="VBoxContainer/OptionsContainer"] -margin_left = 72.0 -margin_right = 155.0 -margin_bottom = 25.0 +margin_left = 89.0 +margin_right = 168.0 +margin_bottom = 24.0 mouse_default_cursor_shape = 2 min_value = 1.0 max_value = 16384.0 @@ -45,16 +43,16 @@ value = 64.0 suffix = "px" [node name="Height" type="Label" parent="VBoxContainer/OptionsContainer"] -margin_top = 30.0 -margin_right = 72.0 -margin_bottom = 45.0 +margin_top = 33.0 +margin_right = 87.0 +margin_bottom = 47.0 text = "Height:" [node name="HeightValue" type="SpinBox" parent="VBoxContainer/OptionsContainer"] -margin_left = 72.0 -margin_top = 25.0 -margin_right = 155.0 -margin_bottom = 50.0 +margin_left = 89.0 +margin_top = 28.0 +margin_right = 168.0 +margin_bottom = 52.0 mouse_default_cursor_shape = 2 min_value = 1.0 max_value = 16384.0 @@ -62,16 +60,16 @@ value = 64.0 suffix = "px" [node name="InterpolationLabel" type="Label" parent="VBoxContainer/OptionsContainer"] -margin_top = 53.0 -margin_right = 72.0 -margin_bottom = 68.0 +margin_top = 59.0 +margin_right = 87.0 +margin_bottom = 73.0 text = "Interpolation:" [node name="InterpolationType" type="OptionButton" parent="VBoxContainer/OptionsContainer"] -margin_left = 72.0 -margin_top = 50.0 -margin_right = 155.0 -margin_bottom = 71.0 +margin_left = 89.0 +margin_top = 56.0 +margin_right = 168.0 +margin_bottom = 76.0 text = "Nearest" items = [ "Nearest", null, false, 0, null, "Bilinear", null, false, 1, null, "Cubic", null, false, 2, null, "Trilinear", null, false, 3, null, "Lanczos", null, false, 4, null ] selected = 0 diff --git a/src/UI/TopMenuContainer.gd b/src/UI/TopMenuContainer.gd index 37612a6..58d8a86 100644 --- a/src/UI/TopMenuContainer.gd +++ b/src/UI/TopMenuContainer.gd @@ -79,6 +79,7 @@ func setup_image_menu() -> void: var image_menu_items := { "Scale Image" : 0, "Crop Image" : 0, + "Resize Canvas" : 0, "Flip Horizontal" : InputMap.get_action_list("image_flip_horizontal")[0].get_scancode_with_modifiers(), "Flip Vertical" : InputMap.get_action_list("image_flip_vertical")[0].get_scancode_with_modifiers(), "Rotate Image" : 0, @@ -275,25 +276,28 @@ func image_menu_id_pressed(id : int) -> void: 1: # Crop Image DrawingAlgos.crop_image(image) - 2: # Flip Horizontal + 2: # Resize Canvas + show_resize_canvas_popup() + + 3: # Flip Horizontal flip_image(true) - 3: # Flip Vertical + 4: # Flip Vertical flip_image(false) - 4: # Rotate + 5: # Rotate show_rotate_image_popup() - 5: # Invert Colors + 6: # Invert Colors DrawingAlgos.invert_image_colors(image) - 6: # Desaturation + 7: # Desaturation DrawingAlgos.desaturate_image(image) - 7: # Outline + 8: # Outline show_add_outline_popup() - 8: # HSV + 9: # HSV show_hsv_configuration_popup() @@ -302,6 +306,11 @@ func show_scale_image_popup() -> void: Global.dialog_open(true) +func show_resize_canvas_popup() -> void: + Global.control.get_node("ResizeCanvas").popup_centered() + Global.dialog_open(true) + + func flip_image(horizontal : bool) -> void: var image : Image = Global.current_project.frames[Global.current_project.current_frame].cels[Global.current_project.current_layer].image Global.canvas.handle_undo("Draw")