mirror of
https://github.com/Orama-Interactive/Pixelorama.git
synced 2025-01-30 23:19:49 +00:00
Var pix centralize (#441)
* Added Centralize Image * Add files via upload * Added Centralize Image (fixd some lines) * Added Centralize Image (fixes some lines) * Fixed and removed some lines * Fixed and removed some lines * Removed unnecessary parameters * Removed unnecessary parameters * Update DrawingAlgos.gd
This commit is contained in:
parent
93bbfabb99
commit
eff0adbf21
|
@ -255,6 +255,27 @@ func scale_image(width : int, height : int, interpolation : int) -> void:
|
|||
general_undo_scale()
|
||||
|
||||
|
||||
func centralize() -> void:
|
||||
# Find used rect of the current frame (across all of the layers)
|
||||
var used_rect := Rect2()
|
||||
for cel in Global.current_project.frames[Global.current_project.current_frame].cels:
|
||||
var cel_rect : Rect2 = cel.image.get_used_rect()
|
||||
if not cel_rect.has_no_area():
|
||||
used_rect = cel_rect if used_rect.has_no_area() else used_rect.merge(cel_rect)
|
||||
if used_rect.has_no_area():
|
||||
return
|
||||
|
||||
var offset : Vector2 = (0.5 * (Global.current_project.size - used_rect.size)).floor()
|
||||
general_do_centralize()
|
||||
for c in Global.current_project.frames[Global.current_project.current_frame].cels:
|
||||
var sprite := Image.new()
|
||||
sprite.create(Global.current_project.size.x, Global.current_project.size.y, false, Image.FORMAT_RGBA8)
|
||||
sprite.blend_rect(c.image, used_rect, offset)
|
||||
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_centralize()
|
||||
|
||||
|
||||
func crop_image(image : Image) -> void:
|
||||
# Use first cel as a starting rectangle
|
||||
var used_rect : Rect2 = image.get_used_rect()
|
||||
|
@ -335,6 +356,17 @@ func general_undo_scale() -> void:
|
|||
Global.current_project.undo_redo.commit_action()
|
||||
|
||||
|
||||
func general_do_centralize() -> void:
|
||||
Global.current_project.undos += 1
|
||||
Global.current_project.undo_redo.create_action("Centralize")
|
||||
|
||||
|
||||
func general_undo_centralize() -> void:
|
||||
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()
|
||||
|
||||
|
||||
func invert_image_colors(image : Image, pixels : Array, red := true, green := true, blue := true, alpha := false) -> void:
|
||||
image.lock()
|
||||
for i in pixels:
|
||||
|
|
|
@ -337,7 +337,7 @@ func general_redo(project : Project = current_project) -> void:
|
|||
func undo(_frame_index := -1, _layer_index := -1, project : Project = current_project) -> void:
|
||||
general_undo(project)
|
||||
var action_name : String = project.undo_redo.get_current_action_name()
|
||||
if action_name == "Draw" or action_name == "Rectangle Select" or action_name == "Scale" or action_name == "Merge Layer" or action_name == "Link Cel" or action_name == "Unlink Cel":
|
||||
if action_name == "Draw" or action_name == "Rectangle Select" or action_name == "Scale" or action_name == "Centralize" or action_name == "Merge Layer" or action_name == "Link Cel" or action_name == "Unlink Cel":
|
||||
if _layer_index > -1 and _frame_index > -1:
|
||||
canvas.update_texture(_layer_index, _frame_index, project)
|
||||
else:
|
||||
|
@ -368,7 +368,7 @@ func undo(_frame_index := -1, _layer_index := -1, project : Project = current_pr
|
|||
func redo(_frame_index := -1, _layer_index := -1, project : Project = current_project) -> void:
|
||||
general_redo(project)
|
||||
var action_name : String = project.undo_redo.get_current_action_name()
|
||||
if action_name == "Draw" or action_name == "Rectangle Select" or action_name == "Scale" or action_name == "Merge Layer" or action_name == "Link Cel" or action_name == "Unlink Cel":
|
||||
if action_name == "Draw" or action_name == "Rectangle Select" or action_name == "Scale" or action_name == "Centralize" or action_name == "Merge Layer" or action_name == "Link Cel" or action_name == "Unlink Cel":
|
||||
if _layer_index > -1 and _frame_index > -1:
|
||||
canvas.update_texture(_layer_index, _frame_index, project)
|
||||
else:
|
||||
|
|
|
@ -4,7 +4,7 @@ extends Panel
|
|||
enum FileMenuId {NEW, OPEN, OPEN_LAST_PROJECT, SAVE, SAVE_AS, EXPORT, EXPORT_AS, QUIT}
|
||||
enum EditMenuId {UNDO, REDO, COPY, CUT, PASTE, DELETE, CLEAR_SELECTION, PREFERENCES}
|
||||
enum ViewMenuId {TILE_MODE, MIRROR_VIEW, SHOW_GRID, SHOW_PIXEL_GRID, SHOW_RULERS, SHOW_GUIDES, SHOW_ANIMATION_TIMELINE, ZEN_MODE, FULLSCREEN_MODE}
|
||||
enum ImageMenuId {SCALE_IMAGE, CROP_IMAGE, RESIZE_CANVAS, FLIP, ROTATE, INVERT_COLORS, DESATURATION, OUTLINE, HSV, GRADIENT, SHADER}
|
||||
enum ImageMenuId {SCALE_IMAGE,CENTRALIZE_IMAGE, CROP_IMAGE, RESIZE_CANVAS, FLIP, ROTATE, INVERT_COLORS, DESATURATION, OUTLINE, HSV, GRADIENT, SHADER}
|
||||
enum HelpMenuId {VIEW_SPLASH_SCREEN, ONLINE_DOCS, ISSUE_TRACKER, CHANGELOG, ABOUT_PIXELORAMA}
|
||||
|
||||
|
||||
|
@ -116,6 +116,7 @@ func setup_tile_mode_submenu(item : String):
|
|||
func setup_image_menu() -> void:
|
||||
var image_menu_items := { # order as in ImageMenuId enum
|
||||
"Scale Image" : 0,
|
||||
"Centralize Image" : 0,
|
||||
"Crop Image" : 0,
|
||||
"Resize Canvas" : 0,
|
||||
"Flip" : 0,
|
||||
|
@ -359,6 +360,9 @@ func image_menu_id_pressed(id : int) -> void:
|
|||
ImageMenuId.SCALE_IMAGE:
|
||||
show_scale_image_popup()
|
||||
|
||||
ImageMenuId.CENTRALIZE_IMAGE:
|
||||
DrawingAlgos.centralize()
|
||||
|
||||
ImageMenuId.CROP_IMAGE:
|
||||
DrawingAlgos.crop_image(image)
|
||||
|
||||
|
|
Loading…
Reference in a new issue