1
0
Fork 0
mirror of https://github.com/Orama-Interactive/Pixelorama.git synced 2025-01-30 23:19:49 +00:00

Added a dialog for image flipping with options

This commit is contained in:
OverloadedOrama 2020-07-30 00:01:04 +03:00
parent d4fe1f7b12
commit 0d1e45cfe4
6 changed files with 208 additions and 41 deletions

View file

@ -124,6 +124,9 @@ msgstr ""
msgid "Clear Selection" msgid "Clear Selection"
msgstr "" msgstr ""
msgid "Flip"
msgstr ""
msgid "Flip Horizontal" msgid "Flip Horizontal"
msgstr "" msgstr ""

View file

@ -352,16 +352,6 @@ show_guides={
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":true,"meta":false,"command":true,"pressed":false,"scancode":70,"unicode":0,"echo":false,"script":null) "events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":true,"meta":false,"command":true,"pressed":false,"scancode":70,"unicode":0,"echo":false,"script":null)
] ]
} }
image_flip_horizontal={
"deadzone": 0.5,
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":true,"control":false,"meta":false,"command":false,"pressed":false,"scancode":72,"unicode":0,"echo":false,"script":null)
]
}
image_flip_vertical={
"deadzone": 0.5,
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":true,"control":false,"meta":false,"command":false,"pressed":false,"scancode":86,"unicode":0,"echo":false,"script":null)
]
}
left_zoom_tool={ left_zoom_tool={
"deadzone": 0.5, "deadzone": 0.5,
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":90,"unicode":0,"echo":false,"script":null) "events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":90,"unicode":0,"echo":false,"script":null)

View file

@ -0,0 +1,123 @@
extends ConfirmationDialog
enum {CEL, FRAME, ALL_FRAMES, ALL_PROJECTS}
var affect : int = CEL
var pixels := []
var current_cel : Image
var preview_image : Image
var preview_texture : ImageTexture
onready var preview : TextureRect = $VBoxContainer/Preview
onready var flip_h : CheckBox = $VBoxContainer/OptionsContainer/FlipHorizontal
onready var flip_v : CheckBox = $VBoxContainer/OptionsContainer/FlipVertical
onready var selection_checkbox = $VBoxContainer/OptionsContainer/SelectionCheckBox
func _ready() -> void:
current_cel = Image.new()
preview_image = Image.new()
preview_texture = ImageTexture.new()
func _on_FlipImageDialog_about_to_show() -> void:
current_cel = Global.current_project.frames[Global.current_project.current_frame].cels[Global.current_project.current_layer].image
_on_SelectionCheckBox_toggled(selection_checkbox.pressed)
func _on_FlipImageDialog_confirmed() -> void:
if affect == CEL:
Global.canvas.handle_undo("Draw")
flip_image(current_cel, pixels)
Global.canvas.handle_redo("Draw")
elif affect == FRAME:
Global.canvas.handle_undo("Draw", Global.current_project, -1)
for cel in Global.current_project.frames[Global.current_project.current_frame].cels:
flip_image(cel.image, pixels)
Global.canvas.handle_redo("Draw", Global.current_project, -1)
elif affect == ALL_FRAMES:
Global.canvas.handle_undo("Draw", Global.current_project, -1, -1)
for frame in Global.current_project.frames:
for cel in frame.cels:
flip_image(cel.image, pixels)
Global.canvas.handle_redo("Draw", Global.current_project, -1, -1)
elif affect == ALL_PROJECTS:
for project in Global.projects:
var _pixels := []
if selection_checkbox.pressed:
_pixels = project.selected_pixels.duplicate()
else:
for x in project.size.x:
for y in project.size.y:
_pixels.append(Vector2(x, y))
Global.canvas.handle_undo("Draw", project, -1, -1)
for frame in project.frames:
for cel in frame.cels:
flip_image(cel.image, _pixels, project)
Global.canvas.handle_redo("Draw", project, -1, -1)
func _on_FlipHorizontal_toggled(_button_pressed : bool) -> void:
update_preview()
func _on_FlipVertical_toggled(_button_pressed : bool) -> void:
update_preview()
func _on_SelectionCheckBox_toggled(button_pressed : bool) -> void:
pixels.clear()
if button_pressed:
pixels = Global.current_project.selected_pixels.duplicate()
else:
for x in Global.current_project.size.x:
for y in Global.current_project.size.y:
pixels.append(Vector2(x, y))
update_preview()
func _on_AffectOptionButton_item_selected(index : int) -> void:
affect = index
func update_preview() -> void:
preview_image.copy_from(current_cel)
flip_image(preview_image, pixels)
preview_texture.create_from_image(preview_image, 0)
preview.texture = preview_texture
func flip_image(image : Image, _pixels : Array, project : Project = Global.current_project) -> void:
var entire_image_selected : bool = _pixels.size() == project.size.x * project.size.y
if entire_image_selected:
if flip_h.pressed:
image.flip_x()
if flip_v.pressed:
image.flip_y()
else:
# Create a temporary image that only has the selected pixels in it
var selected_image := Image.new()
selected_image.create(image.get_width(), image.get_height(), false, Image.FORMAT_RGBA8)
selected_image.lock()
image.lock()
for i in _pixels:
var color : Color = image.get_pixelv(i)
selected_image.set_pixelv(i, color)
image.set_pixelv(i, Color(0, 0, 0, 0))
if flip_h.pressed:
selected_image.flip_x()
if flip_v.pressed:
selected_image.flip_y()
image.blit_rect_mask(selected_image, selected_image, Rect2(Vector2.ZERO, selected_image.get_size()), Vector2.ZERO)
func _on_FlipImageDialog_popup_hide() -> void:
Global.dialog_open(false)

View file

@ -0,0 +1,65 @@
[gd_scene load_steps=2 format=2]
[ext_resource path="res://src/UI/Dialogs/ImageEffects/FlipImageDialog.gd" type="Script" id=1]
[node name="FlipImageDialog" type="ConfirmationDialog"]
margin_right = 200.0
margin_bottom = 70.0
script = ExtResource( 1 )
[node name="VBoxContainer" type="VBoxContainer" parent="."]
margin_left = 8.0
margin_top = 8.0
margin_right = 275.0
margin_bottom = 264.0
[node name="Preview" type="TextureRect" parent="VBoxContainer"]
margin_right = 267.0
margin_bottom = 200.0
rect_min_size = Vector2( 200, 200 )
expand = true
stretch_mode = 6
[node name="OptionsContainer" type="GridContainer" parent="VBoxContainer"]
margin_top = 204.0
margin_right = 267.0
margin_bottom = 256.0
columns = 2
[node name="FlipHorizontal" type="CheckBox" parent="VBoxContainer/OptionsContainer"]
margin_right = 160.0
margin_bottom = 24.0
mouse_default_cursor_shape = 2
text = "Flip Horizontal"
[node name="FlipVertical" type="CheckBox" parent="VBoxContainer/OptionsContainer"]
margin_left = 164.0
margin_right = 267.0
margin_bottom = 24.0
mouse_default_cursor_shape = 2
text = "Flip Vertical"
[node name="SelectionCheckBox" type="CheckBox" parent="VBoxContainer/OptionsContainer"]
margin_top = 28.0
margin_right = 160.0
margin_bottom = 52.0
mouse_default_cursor_shape = 2
pressed = true
text = "Only affect selection"
[node name="AffectOptionButton" type="OptionButton" parent="VBoxContainer/OptionsContainer"]
margin_left = 164.0
margin_top = 28.0
margin_right = 267.0
margin_bottom = 52.0
mouse_default_cursor_shape = 2
text = "Current cel"
items = [ "Current cel", null, false, 0, null, "Current frame", null, false, 1, null, "All frames", null, false, 2, null, "All projects", null, false, 3, null ]
selected = 0
[connection signal="about_to_show" from="." to="." method="_on_FlipImageDialog_about_to_show"]
[connection signal="confirmed" from="." to="." method="_on_FlipImageDialog_confirmed"]
[connection signal="popup_hide" from="." to="." method="_on_FlipImageDialog_popup_hide"]
[connection signal="toggled" from="VBoxContainer/OptionsContainer/FlipHorizontal" to="." method="_on_FlipHorizontal_toggled"]
[connection signal="toggled" from="VBoxContainer/OptionsContainer/FlipVertical" to="." method="_on_FlipVertical_toggled"]
[connection signal="toggled" from="VBoxContainer/OptionsContainer/SelectionCheckBox" to="." method="_on_SelectionCheckBox_toggled"]
[connection signal="item_selected" from="VBoxContainer/OptionsContainer/AffectOptionButton" to="." method="_on_AffectOptionButton_item_selected"]

View file

@ -1,5 +1,6 @@
[gd_scene load_steps=8 format=2] [gd_scene load_steps=9 format=2]
[ext_resource path="res://src/UI/Dialogs/ImageEffects/FlipImageDialog.tscn" type="PackedScene" id=1]
[ext_resource path="res://src/UI/Dialogs/ImageEffects/ResizeCanvas.tscn" type="PackedScene" id=8] [ext_resource path="res://src/UI/Dialogs/ImageEffects/ResizeCanvas.tscn" type="PackedScene" id=8]
[ext_resource path="res://src/UI/Dialogs/ImageEffects/RotateImage.tscn" type="PackedScene" id=9] [ext_resource path="res://src/UI/Dialogs/ImageEffects/RotateImage.tscn" type="PackedScene" id=9]
[ext_resource path="res://src/UI/Dialogs/ImageEffects/ShaderEffect.tscn" type="PackedScene" id=10] [ext_resource path="res://src/UI/Dialogs/ImageEffects/ShaderEffect.tscn" type="PackedScene" id=10]
@ -8,16 +9,14 @@
[ext_resource path="res://src/UI/Dialogs/ImageEffects/OutlineDialog.tscn" type="PackedScene" id=13] [ext_resource path="res://src/UI/Dialogs/ImageEffects/OutlineDialog.tscn" type="PackedScene" id=13]
[ext_resource path="res://src/UI/Dialogs/ImageEffects/ScaleImage.tscn" type="PackedScene" id=14] [ext_resource path="res://src/UI/Dialogs/ImageEffects/ScaleImage.tscn" type="PackedScene" id=14]
[node name="ImageEffects" type="Control"] [node name="ImageEffects" type="Control"]
mouse_filter = 2 mouse_filter = 2
__meta__ = { __meta__ = {
"_edit_use_anchors_": false "_edit_use_anchors_": false
} }
[node name="FlipImageDialog" parent="." instance=ExtResource( 1 )]
[node name="ScaleImage" parent="." instance=ExtResource( 14 )] [node name="ScaleImage" parent="." instance=ExtResource( 14 )]
margin_bottom = 127.0 margin_bottom = 127.0

View file

@ -87,8 +87,7 @@ func setup_image_menu() -> void:
"Scale Image" : 0, "Scale Image" : 0,
"Crop Image" : 0, "Crop Image" : 0,
"Resize Canvas" : 0, "Resize Canvas" : 0,
"Flip Horizontal" : InputMap.get_action_list("image_flip_horizontal")[0].get_scancode_with_modifiers(), "Flip" : 0,
"Flip Vertical" : InputMap.get_action_list("image_flip_vertical")[0].get_scancode_with_modifiers(),
"Rotate Image" : 0, "Rotate Image" : 0,
"Invert Colors" : 0, "Invert Colors" : 0,
"Desaturation" : 0, "Desaturation" : 0,
@ -311,30 +310,30 @@ func image_menu_id_pressed(id : int) -> void:
2: # Resize Canvas 2: # Resize Canvas
show_resize_canvas_popup() show_resize_canvas_popup()
3: # Flip Horizontal 3: # Flip
flip_image(true) Global.control.get_node("Dialogs/ImageEffects/FlipImageDialog").popup_centered()
Global.dialog_open(true)
4: # Flip Vertical 4: # Rotate
flip_image(false)
5: # Rotate
show_rotate_image_popup() show_rotate_image_popup()
6: # Invert Colors 5: # Invert Colors
DrawingAlgos.invert_image_colors(image) DrawingAlgos.invert_image_colors(image)
7: # Desaturation 6: # Desaturation
DrawingAlgos.desaturate_image(image) DrawingAlgos.desaturate_image(image)
8: # Outline 7: # Outline
show_add_outline_popup() show_add_outline_popup()
9: # HSV 8: # HSV
show_hsv_configuration_popup() show_hsv_configuration_popup()
10: # Gradient
9: # Gradient
Global.control.get_node("Dialogs/ImageEffects/GradientDialog").popup_centered() Global.control.get_node("Dialogs/ImageEffects/GradientDialog").popup_centered()
Global.dialog_open(true) Global.dialog_open(true)
11: # Shader
10: # Shader
Global.control.get_node("Dialogs/ImageEffects/ShaderEffect").popup_centered() Global.control.get_node("Dialogs/ImageEffects/ShaderEffect").popup_centered()
Global.dialog_open(true) Global.dialog_open(true)
@ -349,18 +348,6 @@ func show_resize_canvas_popup() -> void:
Global.dialog_open(true) 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")
image.unlock()
if horizontal:
image.flip_x()
else:
image.flip_y()
image.lock()
Global.canvas.handle_redo("Draw")
func show_rotate_image_popup() -> void: func show_rotate_image_popup() -> void:
var image : Image = Global.current_project.frames[Global.current_project.current_frame].cels[Global.current_project.current_layer].image var image : Image = Global.current_project.frames[Global.current_project.current_frame].cels[Global.current_project.current_layer].image
Global.control.get_node("Dialogs/ImageEffects/RotateImage").set_sprite(image) Global.control.get_node("Dialogs/ImageEffects/RotateImage").set_sprite(image)