1
0
Fork 0
mirror of https://github.com/Orama-Interactive/Pixelorama.git synced 2025-01-19 17:49:47 +00:00
Pixelorama/Prefabs/Dialogs/RotateImage.gd

57 lines
1.6 KiB
GDScript3
Raw Normal View History

2020-01-27 15:23:52 +00:00
extends ConfirmationDialog
var texture : ImageTexture
var aux_img : Image
var layer : Image
func _ready():
texture = ImageTexture.new()
texture.flags = 0
aux_img = Image.new()
$VBoxContainer/HBoxContainer2/OptionButton.add_item("Rotxel")
2020-02-03 16:55:55 +00:00
$VBoxContainer/HBoxContainer2/OptionButton.add_item("Nearest neighbour")
2020-01-27 15:23:52 +00:00
func set_sprite(sprite : Image):
aux_img.copy_from(sprite)
layer = sprite
texture.create_from_image(aux_img, 0)
$VBoxContainer/TextureRect.texture = texture
func _on_HSlider_value_changed(_value):
2020-02-03 16:55:55 +00:00
rotate()
2020-01-27 15:23:52 +00:00
$VBoxContainer/HBoxContainer/SpinBox.value = $VBoxContainer/HBoxContainer/HSlider.value
func _on_SpinBox_value_changed(_value):
2020-01-27 15:23:52 +00:00
$VBoxContainer/HBoxContainer/HSlider.value = $VBoxContainer/HBoxContainer/SpinBox.value
func _on_RotateImage_confirmed():
Global.canvas.handle_undo("Draw")
match $VBoxContainer/HBoxContainer2/OptionButton.text:
"Rotxel":
Global.rotxel(layer,$VBoxContainer/HBoxContainer/HSlider.value*PI/180)
"Nearest neighbour":
Global.nn_rotate(layer,$VBoxContainer/HBoxContainer/HSlider.value*PI/180)
2020-01-27 15:23:52 +00:00
Global.canvas.handle_redo("Draw")
$VBoxContainer/HBoxContainer/HSlider.value = 0
2020-02-03 16:55:55 +00:00
func rotate():
var sprite : Image = Image.new()
sprite.copy_from(aux_img)
match $VBoxContainer/HBoxContainer2/OptionButton.text:
"Rotxel":
Global.rotxel(sprite,$VBoxContainer/HBoxContainer/HSlider.value*PI/180)
"Nearest neighbour":
Global.nn_rotate(sprite,$VBoxContainer/HBoxContainer/HSlider.value*PI/180)
texture.create_from_image(sprite, 0)
func _on_OptionButton_item_selected(_id):
2020-02-03 16:55:55 +00:00
rotate()
func _on_RotateImage_about_to_show():
$VBoxContainer/HBoxContainer/HSlider.value = 0