Skip to content

Commit

Permalink
Symmetry guides now adjust their position when the image is being res…
Browse files Browse the repository at this point in the history
…ized

Fixes #379
  • Loading branch information
OverloadedOrama committed Nov 25, 2020
1 parent 54c6c86 commit 4d85cf1
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 17 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ PinyaColada, Rémi Verschelde (akien-mga), dasimonde, gschwind, AbhinavKDev
- Fixed issues where fully transparent color could not be picked. One of these cases was [#364](https://github.com/Orama-Interactive/Pixelorama/issues/364).
- Fixed "Export" option in the File menu not working properly and not remembering the directory path and file name when switching between projects (tabs).
- When opening a .pxo project which has guides, they will no longer be added to the project at the first tab too.
- Symmetry guides now adjust their position when the image is being resized. ([#379](https://github.com/Orama-Interactive/Pixelorama/issues/379))
- Fixed Chinese and Korean characters not displaying properly in the Splash dialog and the About dialog.
- Fixed crash when importing an incorrectly formatted GIMP Color Palette file. ([#363](https://github.com/Orama-Interactive/Pixelorama/issues/363))
- Using the lighten/darken on pixels with an alpha value of 0 no longer has an effect on them.
Expand Down
51 changes: 34 additions & 17 deletions src/Autoload/DrawingAlgos.gd
Original file line number Diff line number Diff line change
Expand Up @@ -235,9 +235,7 @@ func colorDistance(c1 : Color, c2 : Color) -> float:
# Image effects

func scale_image(width : int, height : int, interpolation : int) -> void:
Global.current_project.undos += 1
Global.current_project.undo_redo.create_action("Scale")
Global.current_project.undo_redo.add_do_property(Global.current_project, "size", Vector2(width, height).floor())
general_do_scale(width, height)

for f in Global.current_project.frames:
for i in range(f.cels.size() - 1, -1, -1):
Expand All @@ -254,10 +252,7 @@ func scale_image(width : int, height : int, interpolation : int) -> void:
Global.current_project.undo_redo.add_do_property(f.cels[i].image, "data", sprite.data)
Global.current_project.undo_redo.add_undo_property(f.cels[i].image, "data", f.cels[i].image.data)

Global.current_project.undo_redo.add_undo_property(Global.current_project, "size", Global.current_project.size)
Global.current_project.undo_redo.add_undo_method(Global, "undo")
Global.current_project.undo_redo.add_do_method(Global, "redo")
Global.current_project.undo_redo.commit_action()
general_undo_scale()


func crop_image(image : Image) -> void:
Expand All @@ -284,26 +279,19 @@ func crop_image(image : Image) -> void:

var width := used_rect.size.x
var height := used_rect.size.y
Global.current_project.undos += 1
Global.current_project.undo_redo.create_action("Scale")
Global.current_project.undo_redo.add_do_property(Global.current_project, "size", Vector2(width, height).floor())
general_do_scale(width, height)
for f in Global.current_project.frames:
# Loop through all the layers to crop them
for j in range(Global.current_project.layers.size() - 1, -1, -1):
var sprite : Image = f.cels[j].image.get_rect(used_rect)
Global.current_project.undo_redo.add_do_property(f.cels[j].image, "data", sprite.data)
Global.current_project.undo_redo.add_undo_property(f.cels[j].image, "data", f.cels[j].image.data)

Global.current_project.undo_redo.add_undo_property(Global.current_project, "size", Global.current_project.size)
Global.current_project.undo_redo.add_undo_method(Global, "undo")
Global.current_project.undo_redo.add_do_method(Global, "redo")
Global.current_project.undo_redo.commit_action()
general_undo_scale()


func resize_canvas(width : int, height : int, offset_x : int, offset_y : int) -> void:
Global.current_project.undos += 1
Global.current_project.undo_redo.create_action("Scale")
Global.current_project.undo_redo.add_do_property(Global.current_project, "size", Vector2(width, height).floor())
general_do_scale(width, height)
for f in Global.current_project.frames:
for c in f.cels:
var sprite := Image.new()
Expand All @@ -312,7 +300,36 @@ func resize_canvas(width : int, height : int, offset_x : int, offset_y : int) ->
Global.current_project.undo_redo.add_do_property(c.image, "data", sprite.data)
Global.current_project.undo_redo.add_undo_property(c.image, "data", c.image.data)

general_undo_scale()


func general_do_scale(width : int, height : int) -> void:
var x_ratio = Global.current_project.size.x / width
var y_ratio = Global.current_project.size.y / height
var new_x_symmetry_point = Global.current_project.x_symmetry_point / x_ratio
var new_y_symmetry_point = Global.current_project.y_symmetry_point / y_ratio
var new_x_symmetry_axis_points = Global.current_project.x_symmetry_axis.points
var new_y_symmetry_axis_points = Global.current_project.y_symmetry_axis.points
new_x_symmetry_axis_points[0].y /= y_ratio
new_x_symmetry_axis_points[1].y /= y_ratio
new_y_symmetry_axis_points[0].x /= x_ratio
new_y_symmetry_axis_points[1].x /= x_ratio

Global.current_project.undos += 1
Global.current_project.undo_redo.create_action("Scale")
Global.current_project.undo_redo.add_do_property(Global.current_project, "size", Vector2(width, height).floor())
Global.current_project.undo_redo.add_do_property(Global.current_project, "x_symmetry_point", new_x_symmetry_point)
Global.current_project.undo_redo.add_do_property(Global.current_project, "y_symmetry_point", new_y_symmetry_point)
Global.current_project.undo_redo.add_do_property(Global.current_project.x_symmetry_axis, "points", new_x_symmetry_axis_points)
Global.current_project.undo_redo.add_do_property(Global.current_project.y_symmetry_axis, "points", new_y_symmetry_axis_points)


func general_undo_scale() -> void:
Global.current_project.undo_redo.add_undo_property(Global.current_project, "size", Global.current_project.size)
Global.current_project.undo_redo.add_undo_property(Global.current_project, "x_symmetry_point", Global.current_project.x_symmetry_point)
Global.current_project.undo_redo.add_undo_property(Global.current_project, "y_symmetry_point", Global.current_project.y_symmetry_point)
Global.current_project.undo_redo.add_undo_property(Global.current_project.x_symmetry_axis, "points", Global.current_project.x_symmetry_axis.points)
Global.current_project.undo_redo.add_undo_property(Global.current_project.y_symmetry_axis, "points", Global.current_project.y_symmetry_axis.points)
Global.current_project.undo_redo.add_undo_method(Global, "undo")
Global.current_project.undo_redo.add_do_method(Global, "redo")
Global.current_project.undo_redo.commit_action()
Expand Down

0 comments on commit 4d85cf1

Please sign in to comment.