1
0
Fork 0
mirror of https://github.com/Orama-Interactive/Pixelorama.git synced 2025-01-31 07:29:49 +00:00

Change image offset in Resize Canvas

This commit is contained in:
OverloadedOrama 2020-06-24 03:21:44 +03:00
parent 8e2fe8dac3
commit fa2dfb6bca
5 changed files with 86 additions and 11 deletions

View file

@ -350,7 +350,7 @@ msgstr ""
msgid "Light"
msgstr ""
msgid "Invert colors"
msgid "Invert Colors"
msgstr ""
msgid "Desaturation"

View file

@ -636,15 +636,15 @@ func crop_image(image : Image) -> void:
Global.current_project.undo_redo.commit_action()
func resize_canvas(width : int, height : int) -> void:
func resize_canvas(width : int, height : int, offset_x : int, offset_y : 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)
sprite.create(width, height, false, Image.FORMAT_RGBA8)
sprite.blend_rect(c.image, Rect2(Vector2.ZERO, Global.current_project.size), Vector2(offset_x, offset_y))
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)

View file

@ -1,7 +1,36 @@
extends ConfirmationDialog
var width := 64
var height := 64
var offset_x := 0
var offset_y := 0
onready var x_spinbox : SpinBox = $VBoxContainer/OptionsContainer/XSpinBox
onready var y_spinbox : SpinBox = $VBoxContainer/OptionsContainer/YSpinBox
func _on_ResizeCanvas_confirmed() -> void:
var width : int = $VBoxContainer/OptionsContainer/WidthValue.value
var height : int = $VBoxContainer/OptionsContainer/HeightValue.value
DrawingAlgos.resize_canvas(width, height)
DrawingAlgos.resize_canvas(width, height, offset_x, offset_y)
func _on_WidthValue_value_changed(value : int) -> void:
width = value
x_spinbox.min_value = min(width - Global.current_project.size.x, 0)
x_spinbox.max_value = max(width - Global.current_project.size.x, 0)
x_spinbox.value = clamp(x_spinbox.value, x_spinbox.min_value, x_spinbox.max_value)
func _on_HeightValue_value_changed(value : int) -> void:
height = value
y_spinbox.min_value = min(height - Global.current_project.size.y, 0)
y_spinbox.max_value = max(height - Global.current_project.size.y, 0)
y_spinbox.value = clamp(y_spinbox.value, y_spinbox.min_value, y_spinbox.max_value)
func _on_XSpinBox_value_changed(value : int) -> void:
offset_x = value
func _on_YSpinBox_value_changed(value : int) -> void:
offset_y = value

View file

@ -11,7 +11,7 @@ script = ExtResource( 1 )
margin_left = 8.0
margin_top = 8.0
margin_right = 192.0
margin_bottom = 78.0
margin_bottom = 152.0
[node name="ImageSize" type="Label" parent="VBoxContainer"]
margin_right = 184.0
@ -21,7 +21,7 @@ text = "Canvas Size"
[node name="OptionsContainer" type="GridContainer" parent="VBoxContainer"]
margin_top = 18.0
margin_right = 184.0
margin_bottom = 70.0
margin_bottom = 144.0
custom_constants/vseparation = 4
custom_constants/hseparation = 2
columns = 2
@ -58,4 +58,50 @@ min_value = 1.0
max_value = 16384.0
value = 64.0
suffix = "px"
[node name="OffsetLabel" type="Label" parent="VBoxContainer/OptionsContainer"]
margin_top = 56.0
margin_right = 46.0
margin_bottom = 70.0
text = "Offset"
[node name="EmptySpacer" type="Control" parent="VBoxContainer/OptionsContainer"]
margin_left = 48.0
margin_top = 56.0
margin_right = 122.0
margin_bottom = 70.0
[node name="XLabel" type="Label" parent="VBoxContainer/OptionsContainer"]
margin_top = 79.0
margin_right = 46.0
margin_bottom = 93.0
text = "X:"
[node name="XSpinBox" type="SpinBox" parent="VBoxContainer/OptionsContainer"]
margin_left = 48.0
margin_top = 74.0
margin_right = 122.0
margin_bottom = 98.0
mouse_default_cursor_shape = 2
max_value = 0.0
suffix = "px"
[node name="YLabel" type="Label" parent="VBoxContainer/OptionsContainer"]
margin_top = 107.0
margin_right = 46.0
margin_bottom = 121.0
text = "Y:"
[node name="YSpinBox" type="SpinBox" parent="VBoxContainer/OptionsContainer"]
margin_left = 48.0
margin_top = 102.0
margin_right = 122.0
margin_bottom = 126.0
mouse_default_cursor_shape = 2
max_value = 0.0
suffix = "px"
[connection signal="confirmed" from="." to="." method="_on_ResizeCanvas_confirmed"]
[connection signal="value_changed" from="VBoxContainer/OptionsContainer/WidthValue" to="." method="_on_WidthValue_value_changed"]
[connection signal="value_changed" from="VBoxContainer/OptionsContainer/HeightValue" to="." method="_on_HeightValue_value_changed"]
[connection signal="value_changed" from="VBoxContainer/OptionsContainer/XSpinBox" to="." method="_on_XSpinBox_value_changed"]
[connection signal="value_changed" from="VBoxContainer/OptionsContainer/YSpinBox" to="." method="_on_YSpinBox_value_changed"]

View file

@ -83,7 +83,7 @@ func setup_image_menu() -> void:
"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,
"Invert colors" : 0,
"Invert Colors" : 0,
"Desaturation" : 0,
"Outline" : 0,
"Adjust Hue/Saturation/Value" : 0
@ -93,7 +93,7 @@ func setup_image_menu() -> void:
var i := 0
for item in image_menu_items.keys():
image_menu.add_item(item, i, image_menu_items[item])
if i == 4:
if i == 2:
image_menu.add_separator()
i += 1