mirror of
https://github.com/tonytins/CozyPixelStudio.git
synced 2025-05-05 16:24:49 -04:00
Refactoring image_menu_id_pressed method in Main.gd (#243)
* Refactoring image_menu_id_pressed method in Main.gd I've moved the code from each "match" case into a seperate method to make it more readable. Co-authored-by: OverloadedOrama <35376950+OverloadedOrama@users.noreply.github.com>
This commit is contained in:
parent
94b32baa63
commit
852e249143
1 changed files with 115 additions and 79 deletions
62
src/Main.gd
62
src/Main.gd
|
@ -322,15 +322,12 @@ func view_menu_id_pressed(id : int) -> void:
|
|||
Global.canvas.update()
|
||||
|
||||
|
||||
func image_menu_id_pressed(id : int) -> void:
|
||||
if Global.layers[Global.current_layer][2]: # No changes if the layer is locked
|
||||
return
|
||||
match id:
|
||||
0: # Scale Image
|
||||
func show_scale_image_popup() -> void:
|
||||
$ScaleImage.popup_centered()
|
||||
Global.dialog_open(true)
|
||||
|
||||
1: # Crop Image
|
||||
|
||||
func crop_image() -> void:
|
||||
# Use first cel as a starting rectangle
|
||||
var used_rect : Rect2 = Global.canvases[0].layers[0][0].get_used_rect()
|
||||
|
||||
|
@ -369,7 +366,8 @@ func image_menu_id_pressed(id : int) -> void:
|
|||
Global.undo_redo.add_do_method(Global, "redo", Global.canvases)
|
||||
Global.undo_redo.commit_action()
|
||||
|
||||
2: # Flip Horizontal
|
||||
|
||||
func flip_image_horizontal() -> void:
|
||||
var canvas : Canvas = Global.canvas
|
||||
canvas.handle_undo("Draw")
|
||||
canvas.layers[Global.current_layer][0].unlock()
|
||||
|
@ -377,7 +375,8 @@ func image_menu_id_pressed(id : int) -> void:
|
|||
canvas.layers[Global.current_layer][0].lock()
|
||||
canvas.handle_redo("Draw")
|
||||
|
||||
3: # Flip Vertical
|
||||
|
||||
func flip_image_vertical() -> void:
|
||||
var canvas : Canvas = Global.canvas
|
||||
canvas.handle_undo("Draw")
|
||||
canvas.layers[Global.current_layer][0].unlock()
|
||||
|
@ -385,13 +384,15 @@ func image_menu_id_pressed(id : int) -> void:
|
|||
canvas.layers[Global.current_layer][0].lock()
|
||||
canvas.handle_redo("Draw")
|
||||
|
||||
4: # Rotate
|
||||
|
||||
func show_rotate_image_popup() -> void:
|
||||
var image : Image = Global.canvas.layers[Global.current_layer][0]
|
||||
$RotateImage.set_sprite(image)
|
||||
$RotateImage.popup_centered()
|
||||
Global.dialog_open(true)
|
||||
|
||||
5: # Invert Colors
|
||||
|
||||
func invert_image_colors() -> void:
|
||||
var image : Image = Global.canvas.layers[Global.current_layer][0]
|
||||
Global.canvas.handle_undo("Draw")
|
||||
for xx in image.get_size().x:
|
||||
|
@ -402,7 +403,8 @@ func image_menu_id_pressed(id : int) -> void:
|
|||
image.set_pixel(xx, yy, px_color)
|
||||
Global.canvas.handle_redo("Draw")
|
||||
|
||||
6: # Desaturation
|
||||
|
||||
func desaturate_image() -> void:
|
||||
var image : Image = Global.canvas.layers[Global.current_layer][0]
|
||||
Global.canvas.handle_undo("Draw")
|
||||
for xx in image.get_size().x:
|
||||
|
@ -415,15 +417,49 @@ func image_menu_id_pressed(id : int) -> void:
|
|||
image.set_pixel(xx, yy, px_color)
|
||||
Global.canvas.handle_redo("Draw")
|
||||
|
||||
7: # Outline
|
||||
|
||||
func show_add_outline_popup() -> void:
|
||||
$OutlineDialog.popup_centered()
|
||||
Global.dialog_open(true)
|
||||
|
||||
8: # HSV
|
||||
|
||||
func show_hsv_configuration_popup() -> void:
|
||||
$HSVDialog.popup_centered()
|
||||
Global.dialog_open(true)
|
||||
|
||||
|
||||
func image_menu_id_pressed(id : int) -> void:
|
||||
if Global.layers[Global.current_layer][2]: # No changes if the layer is locked
|
||||
return
|
||||
match id:
|
||||
0: # Scale Image
|
||||
show_scale_image_popup()
|
||||
|
||||
1: # Crop Image
|
||||
crop_image()
|
||||
|
||||
2: # Flip Horizontal
|
||||
flip_image_horizontal()
|
||||
|
||||
3: # Flip Vertical
|
||||
flip_image_vertical()
|
||||
|
||||
4: # Rotate
|
||||
show_rotate_image_popup()
|
||||
|
||||
5: # Invert Colors
|
||||
invert_image_colors()
|
||||
|
||||
6: # Desaturation
|
||||
desaturate_image()
|
||||
|
||||
7: # Outline
|
||||
show_add_outline_popup()
|
||||
|
||||
8: # HSV
|
||||
show_hsv_configuration_popup()
|
||||
|
||||
|
||||
func help_menu_id_pressed(id : int) -> void:
|
||||
match id:
|
||||
0: # Splash Screen
|
||||
|
|
Loading…
Add table
Reference in a new issue