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

Changes in the Rotate image dialog and script

This commit is contained in:
Emmanouil Papadeas 2022-07-25 14:39:23 +03:00
parent 7381311e71
commit dfc8499d06
2 changed files with 81 additions and 143 deletions

View file

@ -5,6 +5,9 @@ var shader: Shader = preload("res://src/Shaders/Rotation.shader")
var pivot := Vector2.INF
onready var type_option_button: OptionButton = $VBoxContainer/HBoxContainer2/TypeOptionButton
onready var pivot_indicator: Control = $VBoxContainer/AspectRatioContainer/Indicator
onready var x_pivot: SpinBox = $VBoxContainer/Pivot/TitleButtons/XPivot
onready var y_pivot: SpinBox = $VBoxContainer/Pivot/TitleButtons/YPivot
onready var angle_hslider: HSlider = $VBoxContainer/AngleOptions/AngleHSlider
onready var angle_spinbox: SpinBox = $VBoxContainer/AngleOptions/AngleSpinBox
onready var wait_apply_timer = $WaitApply
@ -35,9 +38,9 @@ func _about_to_show() -> void:
angle_hslider.value = 0
func decide_pivot():
func decide_pivot() -> void:
var size := Global.current_project.size
pivot = Vector2(size.x / 2, size.y / 2)
pivot = size / 2
# Pivot correction in case of even size
if type_option_button.text != "Nearest neighbour (Shader)":
@ -59,20 +62,18 @@ func decide_pivot():
if int(selection_rectangle.end.y - selection_rectangle.position.y) % 2 == 0:
pivot.y -= 0.5
$VBoxContainer/Pivot/Options/X/XPivot.value = pivot.x
$VBoxContainer/Pivot/Options/Y/YPivot.value = pivot.y
x_pivot.value = pivot.x
y_pivot.value = pivot.y
func commit_action(_cel: Image, _project: Project = Global.current_project) -> void:
func commit_action(cel: Image, _project: Project = Global.current_project) -> void:
var angle: float = deg2rad(angle_hslider.value)
# warning-ignore:integer_division
# warning-ignore:integer_division
var selection_size := _cel.get_size()
var selection_size := cel.get_size()
var selection_tex := ImageTexture.new()
var image := Image.new()
image.copy_from(_cel)
image.copy_from(cel)
if _project.has_selection and selection_checkbox.pressed:
var selection_rectangle: Rect2 = _project.get_selection_rectangle()
selection_size = selection_rectangle.size
@ -82,16 +83,16 @@ func commit_action(_cel: Image, _project: Project = Global.current_project) -> v
if type_option_button.text != "Nearest neighbour (Shader)":
image.lock()
_cel.lock()
cel.lock()
for x in _project.size.x:
for y in _project.size.y:
var pos := Vector2(x, y)
if !_project.can_pixel_get_drawn(pos):
image.set_pixelv(pos, Color(0, 0, 0, 0))
else:
_cel.set_pixelv(pos, Color(0, 0, 0, 0))
cel.set_pixelv(pos, Color(0, 0, 0, 0))
image.unlock()
_cel.unlock()
cel.unlock()
match type_option_button.text:
"Rotxel":
DrawingAlgos.rotxel(image, angle, pivot)
@ -100,20 +101,18 @@ func commit_action(_cel: Image, _project: Project = Global.current_project) -> v
"Upscale, Rotate and Downscale":
DrawingAlgos.fake_rotsprite(image, angle, pivot)
"Nearest neighbour (Shader)":
var params := {
"angle": angle,
"selection_tex": selection_tex,
"selection_pivot": pivot,
"selection_size": selection_size
}
if !confirmed:
preview.material.set_shader_param("angle", angle)
preview.material.set_shader_param("selection_tex", selection_tex)
preview.material.set_shader_param("selection_pivot", pivot)
preview.material.set_shader_param("selection_size", selection_size)
for param in params:
preview.material.set_shader_param(param, params[param])
else:
var params = {
"angle": angle,
"selection_tex": selection_tex,
"selection_pivot": pivot,
"selection_size": selection_size
}
var gen := ShaderImageEffect.new()
gen.generate_image(_cel, shader, params, _project.size)
gen.generate_image(cel, shader, params, _project.size)
yield(gen, "done")
if (
@ -121,9 +120,9 @@ func commit_action(_cel: Image, _project: Project = Global.current_project) -> v
and selection_checkbox.pressed
and type_option_button.text != "Nearest neighbour (Shader)"
):
_cel.blend_rect(image, Rect2(Vector2.ZERO, image.get_size()), Vector2.ZERO)
cel.blend_rect(image, Rect2(Vector2.ZERO, image.get_size()), Vector2.ZERO)
else:
_cel.blit_rect(image, Rect2(Vector2.ZERO, image.get_size()), Vector2.ZERO)
cel.blit_rect(image, Rect2(Vector2.ZERO, image.get_size()), Vector2.ZERO)
func _on_HSlider_value_changed(_value: float) -> void:
@ -165,8 +164,8 @@ func _on_LiveCheckbox_toggled(button_pressed: bool) -> void:
func _on_quick_change_angle_pressed(change_type: String) -> void:
var current_angle = angle_hslider.value
var new_angle = current_angle
var current_angle := angle_hslider.value
var new_angle := current_angle
match change_type:
"-90":
new_angle = current_angle - 90
@ -186,17 +185,6 @@ func _on_quick_change_angle_pressed(change_type: String) -> void:
angle_hslider.value = new_angle
func _on_TogglePivot_toggled(button_pressed: bool) -> void:
$VBoxContainer/Pivot/Options.visible = button_pressed
if button_pressed:
$VBoxContainer/Pivot/TitleButtons/TogglePivot.text = "Pivot Options: (v)"
$VBoxContainer/Pivot/TitleButtons/TogglePivot.focus_mode = 0
else:
$VBoxContainer/Pivot/TitleButtons/TogglePivot.text = "Pivot Options: (>)"
$VBoxContainer/Pivot/TitleButtons/TogglePivot.focus_mode = 0
rect_size.y += 1 # Reset rect_size of dialog
func _on_Centre_pressed() -> void:
decide_pivot()
@ -207,13 +195,12 @@ func _on_Pivot_value_changed(value: float, is_x: bool) -> void:
else:
pivot.y = value
# Refresh the indicator
$VBoxContainer/AspectRatioContainer/Indicator.update()
pivot_indicator.update()
if angle_hslider.value != 0:
update_preview()
func _on_Indicator_draw() -> void:
var pivot_indicator = $VBoxContainer/AspectRatioContainer/Indicator
var img_size := preview_image.get_size()
# find the scale using the larger measurement
var ratio = pivot_indicator.rect_size / img_size
@ -237,19 +224,16 @@ func _on_Indicator_draw() -> void:
func _on_Indicator_gui_input(event: InputEvent) -> void:
if event is InputEventMouseMotion:
if event.pressure == 1.0:
var pivot_indicator = $VBoxContainer/AspectRatioContainer/Indicator
var x_pivot = $VBoxContainer/Pivot/Options/X/XPivot
var y_pivot = $VBoxContainer/Pivot/Options/Y/YPivot
var img_size := preview_image.get_size()
var mouse_pos = get_local_mouse_position() - pivot_indicator.rect_position
var ratio = img_size / pivot_indicator.rect_size
var mouse_pos := get_local_mouse_position() - pivot_indicator.rect_position
var ratio := img_size / pivot_indicator.rect_size
# we need to set the scale according to the larger side
var conversion_scale: float
if img_size.x > img_size.y:
conversion_scale = ratio.x
else:
conversion_scale = ratio.y
var new_pos = mouse_pos * conversion_scale
var new_pos := mouse_pos * conversion_scale
x_pivot.value = new_pos.x
y_pivot.value = new_pos.y
pivot_indicator.update()

View file

@ -21,13 +21,13 @@ margin_bottom = -36.0
[node name="AspectRatioContainer" type="AspectRatioContainer" parent="VBoxContainer"]
margin_right = 326.0
margin_bottom = 226.0
margin_bottom = 222.0
size_flags_vertical = 3
[node name="Preview" type="TextureRect" parent="VBoxContainer/AspectRatioContainer"]
margin_left = 50.0
margin_right = 276.0
margin_bottom = 226.0
margin_left = 52.0
margin_right = 274.0
margin_bottom = 222.0
rect_min_size = Vector2( 200, 200 )
expand = true
stretch_mode = 5
@ -40,21 +40,22 @@ margin_right = 0.0
margin_bottom = 0.0
[node name="Indicator" type="Control" parent="VBoxContainer/AspectRatioContainer"]
margin_left = 50.0
margin_right = 276.0
margin_bottom = 226.0
margin_left = 52.0
margin_right = 274.0
margin_bottom = 222.0
mouse_default_cursor_shape = 2
[node name="LiveSettings" type="HBoxContainer" parent="VBoxContainer"]
margin_top = 230.0
margin_top = 226.0
margin_right = 326.0
margin_bottom = 254.0
margin_bottom = 250.0
alignment = 1
[node name="LiveCheckbox" type="CheckBox" parent="VBoxContainer/LiveSettings"]
margin_left = 109.0
margin_right = 217.0
margin_bottom = 24.0
mouse_default_cursor_shape = 2
pressed = true
text = "Live Preview"
@ -85,9 +86,9 @@ editable = false
suffix = "msec"
[node name="HBoxContainer2" type="HBoxContainer" parent="VBoxContainer"]
margin_top = 258.0
margin_top = 254.0
margin_right = 326.0
margin_bottom = 278.0
margin_bottom = 274.0
[node name="Label" type="Label" parent="VBoxContainer/HBoxContainer2"]
margin_top = 3.0
@ -104,105 +105,59 @@ size_flags_horizontal = 3
size_flags_vertical = 3
[node name="HSeparator" type="HSeparator" parent="VBoxContainer"]
margin_top = 282.0
margin_top = 278.0
margin_right = 326.0
margin_bottom = 286.0
margin_bottom = 282.0
[node name="Pivot" type="VBoxContainer" parent="VBoxContainer"]
margin_top = 290.0
margin_top = 286.0
margin_right = 326.0
margin_bottom = 310.0
[node name="TitleButtons" type="HBoxContainer" parent="VBoxContainer/Pivot"]
margin_right = 326.0
margin_bottom = 20.0
margin_bottom = 24.0
[node name="TogglePivot" type="Button" parent="VBoxContainer/Pivot/TitleButtons"]
margin_right = 268.0
margin_bottom = 20.0
[node name="Label" type="Label" parent="VBoxContainer/Pivot/TitleButtons"]
margin_top = 5.0
margin_right = 70.0
margin_bottom = 19.0
text = "Pivot (x, y):"
align = 2
valign = 1
[node name="XPivot" type="SpinBox" parent="VBoxContainer/Pivot/TitleButtons"]
margin_left = 74.0
margin_right = 169.0
margin_bottom = 24.0
mouse_default_cursor_shape = 2
size_flags_horizontal = 3
size_flags_vertical = 2
toggle_mode = true
text = "Pivot Options (>)"
flat = true
align = 0
min_value = -10000.0
max_value = 10000.0
step = 0.5
allow_greater = true
allow_lesser = true
[node name="YPivot" type="SpinBox" parent="VBoxContainer/Pivot/TitleButtons"]
margin_left = 173.0
margin_right = 268.0
margin_bottom = 24.0
mouse_default_cursor_shape = 2
size_flags_horizontal = 3
min_value = -10000.0
max_value = 10000.0
step = 0.5
allow_greater = true
allow_lesser = true
[node name="Centre" type="Button" parent="VBoxContainer/Pivot/TitleButtons"]
margin_left = 272.0
margin_right = 326.0
margin_bottom = 20.0
hint_tooltip = "Centers the pivot (if selection is present then it's centre is selected instead)"
margin_bottom = 24.0
hint_tooltip = "Places the pivot at the center of the image, or at the center of the selection, if it is present."
mouse_default_cursor_shape = 2
text = "Center"
[node name="Options" type="VBoxContainer" parent="VBoxContainer/Pivot"]
visible = false
margin_top = 24.0
margin_right = 326.0
margin_bottom = 76.0
size_flags_horizontal = 3
alignment = 1
[node name="X" type="HBoxContainer" parent="VBoxContainer/Pivot/Options"]
margin_right = 326.0
margin_bottom = 24.0
[node name="Label" type="Label" parent="VBoxContainer/Pivot/Options/X"]
margin_top = 5.0
margin_right = 106.0
margin_bottom = 19.0
size_flags_horizontal = 3
text = "X-axis"
align = 2
valign = 1
[node name="XPivot" type="SpinBox" parent="VBoxContainer/Pivot/Options/X"]
margin_left = 110.0
margin_right = 216.0
margin_bottom = 24.0
size_flags_horizontal = 3
min_value = -10000.0
max_value = 10000.0
step = 0.5
allow_greater = true
allow_lesser = true
[node name="Spacer" type="Control" parent="VBoxContainer/Pivot/Options/X"]
margin_left = 220.0
margin_right = 326.0
margin_bottom = 24.0
size_flags_horizontal = 3
[node name="Y" type="HBoxContainer" parent="VBoxContainer/Pivot/Options"]
margin_top = 28.0
margin_right = 326.0
margin_bottom = 52.0
[node name="Label" type="Label" parent="VBoxContainer/Pivot/Options/Y"]
margin_top = 5.0
margin_right = 106.0
margin_bottom = 19.0
size_flags_horizontal = 3
text = "Y-axis"
align = 2
valign = 1
[node name="YPivot" type="SpinBox" parent="VBoxContainer/Pivot/Options/Y"]
margin_left = 110.0
margin_right = 216.0
margin_bottom = 24.0
size_flags_horizontal = 3
min_value = -10000.0
max_value = 10000.0
step = 0.5
allow_greater = true
allow_lesser = true
[node name="Spacer" type="Control" parent="VBoxContainer/Pivot/Options/Y"]
margin_left = 220.0
margin_right = 326.0
margin_bottom = 24.0
size_flags_horizontal = 3
[node name="HSeparator2" type="HSeparator" parent="VBoxContainer"]
margin_top = 314.0
margin_right = 326.0
@ -308,10 +263,9 @@ selected = 0
[connection signal="toggled" from="VBoxContainer/LiveSettings/LiveCheckbox" to="." method="_on_LiveCheckbox_toggled"]
[connection signal="value_changed" from="VBoxContainer/WaitSettings/WaitTime" to="." method="_on_WaitTime_value_changed"]
[connection signal="item_selected" from="VBoxContainer/HBoxContainer2/TypeOptionButton" to="." method="_on_TypeOptionButton_item_selected"]
[connection signal="toggled" from="VBoxContainer/Pivot/TitleButtons/TogglePivot" to="." method="_on_TogglePivot_toggled"]
[connection signal="value_changed" from="VBoxContainer/Pivot/TitleButtons/XPivot" to="." method="_on_Pivot_value_changed" binds= [ true ]]
[connection signal="value_changed" from="VBoxContainer/Pivot/TitleButtons/YPivot" to="." method="_on_Pivot_value_changed" binds= [ false ]]
[connection signal="pressed" from="VBoxContainer/Pivot/TitleButtons/Centre" to="." method="_on_Centre_pressed"]
[connection signal="value_changed" from="VBoxContainer/Pivot/Options/X/XPivot" to="." method="_on_Pivot_value_changed" binds= [ true ]]
[connection signal="value_changed" from="VBoxContainer/Pivot/Options/Y/YPivot" to="." method="_on_Pivot_value_changed" binds= [ false ]]
[connection signal="value_changed" from="VBoxContainer/AngleOptions/AngleHSlider" to="." method="_on_HSlider_value_changed"]
[connection signal="value_changed" from="VBoxContainer/AngleOptions/AngleSpinBox" to="." method="_on_SpinBox_value_changed"]
[connection signal="pressed" from="VBoxContainer/QuickRotations/Deduct90" to="." method="_on_quick_change_angle_pressed" binds= [ "-90" ]]