mirror of
https://github.com/Orama-Interactive/Pixelorama.git
synced 2025-01-30 23:19:49 +00:00
Allow the image to be expanded in DrawingAlgos.transform
This commit is contained in:
parent
9b94b71dbc
commit
47a91bbb9a
|
@ -274,12 +274,21 @@ func scale_3x(sprite: Image, tol := 0.196078) -> Image:
|
|||
|
||||
|
||||
func transform(
|
||||
image: Image,
|
||||
params: Dictionary,
|
||||
algorithm: RotationAlgorithm,
|
||||
project := Global.current_project
|
||||
image: Image, params: Dictionary, algorithm: RotationAlgorithm, expand := false
|
||||
) -> void:
|
||||
var transformation_matrix: Transform2D = params.get("transformation_matrix", Transform2D())
|
||||
var pivot: Vector2 = params.get("pivot", image.get_size() / 2)
|
||||
if expand:
|
||||
var image_rect := Rect2(Vector2.ZERO, image.get_size())
|
||||
var new_image_rect := image_rect * transformation_matrix as Rect2i
|
||||
var new_image_size := new_image_rect.size
|
||||
if image.get_size() != new_image_size:
|
||||
pivot = new_image_size / 2 - (Vector2i(pivot) - image.get_size() / 2)
|
||||
var tmp_image := Image.create_empty(
|
||||
new_image_size.x, new_image_size.y, image.has_mipmaps(), image.get_format()
|
||||
)
|
||||
tmp_image.blit_rect(image, image_rect, (new_image_size - image.get_size()) / 2)
|
||||
image.copy_from(tmp_image)
|
||||
if type_is_shader(algorithm):
|
||||
params["pivot"] = pivot / Vector2(image.get_size())
|
||||
var shader := rotxel_shader
|
||||
|
@ -291,9 +300,8 @@ func transform(
|
|||
RotationAlgorithm.NNS:
|
||||
shader = nn_shader
|
||||
var gen := ShaderImageEffect.new()
|
||||
gen.generate_image(image, shader, params, project.size)
|
||||
gen.generate_image(image, shader, params, image.get_size())
|
||||
else:
|
||||
var transformation_matrix: Transform2D = params.get("transformation_matrix", Transform2D())
|
||||
var angle := transformation_matrix.get_rotation()
|
||||
match algorithm:
|
||||
RotationAlgorithm.ROTXEL:
|
||||
|
|
|
@ -114,9 +114,9 @@ func commit_action(cel: Image, project := Global.current_project) -> void:
|
|||
preview.material.set_shader_parameter(param, params[param])
|
||||
else:
|
||||
params["preview"] = false
|
||||
DrawingAlgos.transform(cel, params, rotation_algorithm, project)
|
||||
DrawingAlgos.transform(cel, params, rotation_algorithm)
|
||||
else:
|
||||
DrawingAlgos.transform(image, params, rotation_algorithm, project)
|
||||
DrawingAlgos.transform(image, params, rotation_algorithm)
|
||||
if project.has_selection and selection_checkbox.button_pressed:
|
||||
cel.blend_rect(image, Rect2i(Vector2i.ZERO, image.get_size()), Vector2i.ZERO)
|
||||
else:
|
||||
|
|
Loading…
Reference in a new issue