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

Use enums to check the rotation algorithm instead of strings in RotateImage.gd

This commit is contained in:
Emmanouil Papadeas 2023-01-16 22:05:24 +02:00
parent 7001f3a28b
commit 09ff22707b

View file

@ -44,22 +44,22 @@ func set_nodes() -> void:
func _about_to_show() -> void: func _about_to_show() -> void:
drag_pivot = false drag_pivot = false
if pivot == Vector2.INF: if pivot == Vector2.INF:
decide_pivot() _calculate_pivot()
confirmed = false confirmed = false
._about_to_show() ._about_to_show()
wait_apply_timer.wait_time = wait_time_slider.value / 1000.0 wait_apply_timer.wait_time = wait_time_slider.value / 1000.0
angle_slider.value = 0 angle_slider.value = 0
func decide_pivot() -> void: func _calculate_pivot() -> void:
var size := Global.current_project.size var size := Global.current_project.size
pivot = size / 2 pivot = size / 2
# Pivot correction in case of even size # Pivot correction in case of even size
if ( if (
type_option_button.text != "Nearest neighbour (Shader)" type_option_button.get_selected_id() != NNS
and type_option_button.text != "cleanEdge" and type_option_button.get_selected_id() != CLEANEDGE
and type_option_button.text != "OmniScale" and type_option_button.get_selected_id() != OMNISCALE
): ):
if int(size.x) % 2 == 0: if int(size.x) % 2 == 0:
pivot.x -= 0.5 pivot.x -= 0.5
@ -73,9 +73,9 @@ func decide_pivot() -> void:
+ ((selection_rectangle.end - selection_rectangle.position) / 2) + ((selection_rectangle.end - selection_rectangle.position) / 2)
) )
if ( if (
type_option_button.text != "Nearest neighbour (Shader)" type_option_button.get_selected_id() != NNS
and type_option_button.text != "cleanEdge" and type_option_button.get_selected_id() != CLEANEDGE
and type_option_button.text != "OmniScale" and type_option_button.get_selected_id() != OMNISCALE
): ):
# Pivot correction in case of even size # Pivot correction in case of even size
if int(selection_rectangle.end.x - selection_rectangle.position.x) % 2 == 0: if int(selection_rectangle.end.x - selection_rectangle.position.x) % 2 == 0:
@ -114,8 +114,8 @@ func commit_action(cel: Image, _project: Project = Global.current_project) -> vo
cel.set_pixelv(pos, Color(0, 0, 0, 0)) cel.set_pixelv(pos, Color(0, 0, 0, 0))
image.unlock() image.unlock()
cel.unlock() cel.unlock()
match type_option_button.text: match type_option_button.get_selected_id():
"Rotxel with Smear": ROTXEL_SMEAR:
var params := { var params := {
"initial_angle": init_angle_slider.value, "initial_angle": init_angle_slider.value,
"ending_angle": angle_slider.value, "ending_angle": angle_slider.value,
@ -132,7 +132,7 @@ func commit_action(cel: Image, _project: Project = Global.current_project) -> vo
gen.generate_image(cel, rotxel_shader, params, _project.size) gen.generate_image(cel, rotxel_shader, params, _project.size)
yield(gen, "done") yield(gen, "done")
"cleanEdge": CLEANEDGE:
var params := { var params := {
"angle": angle, "angle": angle,
"selection_tex": selection_tex, "selection_tex": selection_tex,
@ -150,7 +150,7 @@ func commit_action(cel: Image, _project: Project = Global.current_project) -> vo
var gen := ShaderImageEffect.new() var gen := ShaderImageEffect.new()
gen.generate_image(cel, clean_edge_shader, params, _project.size) gen.generate_image(cel, clean_edge_shader, params, _project.size)
yield(gen, "done") yield(gen, "done")
"OmniScale": OMNISCALE:
var params := { var params := {
"angle": angle, "angle": angle,
"selection_tex": selection_tex, "selection_tex": selection_tex,
@ -166,7 +166,7 @@ func commit_action(cel: Image, _project: Project = Global.current_project) -> vo
var gen := ShaderImageEffect.new() var gen := ShaderImageEffect.new()
gen.generate_image(cel, DrawingAlgos.omniscale_shader, params, _project.size) gen.generate_image(cel, DrawingAlgos.omniscale_shader, params, _project.size)
yield(gen, "done") yield(gen, "done")
"Nearest neighbour (Shader)": NNS:
var params := { var params := {
"angle": angle, "angle": angle,
"selection_tex": selection_tex, "selection_tex": selection_tex,
@ -180,11 +180,11 @@ func commit_action(cel: Image, _project: Project = Global.current_project) -> vo
var gen := ShaderImageEffect.new() var gen := ShaderImageEffect.new()
gen.generate_image(cel, nn_shader, params, _project.size) gen.generate_image(cel, nn_shader, params, _project.size)
yield(gen, "done") yield(gen, "done")
"Rotxel": ROTXEL:
DrawingAlgos.rotxel(image, angle, pivot) DrawingAlgos.rotxel(image, angle, pivot)
"Nearest neighbour": NN:
DrawingAlgos.nn_rotate(image, angle, pivot) DrawingAlgos.nn_rotate(image, angle, pivot)
"Upscale, Rotate and Downscale": URD:
DrawingAlgos.fake_rotsprite(image, angle, pivot) DrawingAlgos.fake_rotsprite(image, angle, pivot)
if _project.has_selection and selection_checkbox.pressed and !_type_is_shader(): if _project.has_selection and selection_checkbox.pressed and !_type_is_shader():
@ -194,36 +194,32 @@ func commit_action(cel: Image, _project: Project = Global.current_project) -> vo
func _type_is_shader() -> bool: func _type_is_shader() -> bool:
return ( return type_option_button.get_selected_id() <= NNS
type_option_button.text == "Nearest neighbour (Shader)"
or type_option_button.text == "Rotxel with Smear"
or type_option_button.text == "cleanEdge"
or type_option_button.text == "OmniScale"
)
func _on_TypeOptionButton_item_selected(_id: int) -> void: func _on_TypeOptionButton_item_selected(_id: int) -> void:
if type_option_button.text == "Rotxel with Smear": match type_option_button.get_selected_id():
ROTXEL_SMEAR:
var sm := ShaderMaterial.new() var sm := ShaderMaterial.new()
sm.shader = rotxel_shader sm.shader = rotxel_shader
preview.set_material(sm) preview.set_material(sm)
smear_options.visible = true smear_options.visible = true
elif type_option_button.text == "cleanEdge": CLEANEDGE:
var sm := ShaderMaterial.new() var sm := ShaderMaterial.new()
sm.shader = clean_edge_shader sm.shader = clean_edge_shader
preview.set_material(sm) preview.set_material(sm)
smear_options.visible = false smear_options.visible = false
elif type_option_button.text == "OmniScale": OMNISCALE:
var sm := ShaderMaterial.new() var sm := ShaderMaterial.new()
sm.shader = DrawingAlgos.omniscale_shader sm.shader = DrawingAlgos.omniscale_shader
preview.set_material(sm) preview.set_material(sm)
smear_options.visible = false smear_options.visible = false
elif type_option_button.text == "Nearest neighbour (Shader)": NNS:
var sm := ShaderMaterial.new() var sm := ShaderMaterial.new()
sm.shader = nn_shader sm.shader = nn_shader
preview.set_material(sm) preview.set_material(sm)
smear_options.visible = false smear_options.visible = false
else: _:
preview.set_material(null) preview.set_material(null)
smear_options.visible = false smear_options.visible = false
update_preview() update_preview()
@ -280,7 +276,7 @@ func _on_quick_change_angle_pressed(angle_value: int) -> void:
func _on_Centre_pressed() -> void: func _on_Centre_pressed() -> void:
decide_pivot() _calculate_pivot()
func _on_Pivot_value_changed(value: float, is_x: bool) -> void: func _on_Pivot_value_changed(value: float, is_x: bool) -> void: