1
0
Fork 0
mirror of https://github.com/Orama-Interactive/Pixelorama.git synced 2025-01-18 17:19:50 +00:00

Created an ImageEffect class

This will be the parent of all (or most) image effect dialog nodes. Currently only parent on FlipImageDialog, will change to be parent of the rest of the effects.
This commit is contained in:
OverloadedOrama 2020-08-25 19:07:12 +03:00
parent b73937fd0c
commit 2af677016e
4 changed files with 89 additions and 52 deletions

View file

@ -44,6 +44,11 @@ _global_script_classes=[ {
"language": "GDScript",
"path": "res://src/UI/Canvas/Rulers/Guide.gd"
}, {
"base": "AcceptDialog",
"class": "ImageEffect",
"language": "GDScript",
"path": "res://src/Classes/ImageEffect.gd"
}, {
"base": "Reference",
"class": "Layer",
"language": "GDScript",
@ -87,6 +92,7 @@ _global_script_class_icons={
"Drawer": "",
"Frame": "",
"Guide": "",
"ImageEffect": "",
"Layer": "",
"LayerButton": "",
"Palette": "",

View file

@ -0,0 +1,77 @@
class_name ImageEffect extends AcceptDialog
# Parent class for all image effects
# Methods that have "pass" are meant to be replaced by the inherited Scripts
enum {CEL, FRAME, ALL_FRAMES, ALL_PROJECTS}
var affect : int = CEL
var pixels := []
var current_cel : Image
var preview_image : Image
var preview_texture : ImageTexture
var preview : TextureRect
var selection_checkbox : CheckBox
func _ready() -> void:
set_nodes()
current_cel = Image.new()
preview_image = Image.new()
preview_texture = ImageTexture.new()
connect("about_to_show", self, "_about_to_show")
connect("popup_hide", self, "_popup_hide")
connect("confirmed", self, "_confirmed")
if selection_checkbox:
selection_checkbox.connect("toggled", self, "_on_SelectionCheckBox_toggled")
func _about_to_show() -> void:
current_cel = Global.current_project.frames[Global.current_project.current_frame].cels[Global.current_project.current_layer].image
if selection_checkbox:
_on_SelectionCheckBox_toggled(selection_checkbox.pressed)
update_transparent_background_size()
func _confirmed() -> void:
pass
func set_nodes() -> void:
pass
func _on_SelectionCheckBox_toggled(button_pressed : bool) -> void:
pixels.clear()
if button_pressed:
pixels = Global.current_project.selected_pixels.duplicate()
else:
for x in Global.current_project.size.x:
for y in Global.current_project.size.y:
pixels.append(Vector2(x, y))
update_preview()
func update_preview() -> void:
pass
func update_transparent_background_size() -> void:
if !preview:
return
var image_size_y = preview.rect_size.y
var image_size_x = preview.rect_size.x
if preview_image.get_size().x > preview_image.get_size().y:
var scale_ratio = preview_image.get_size().x / image_size_x
image_size_y = preview_image.get_size().y / scale_ratio
else:
var scale_ratio = preview_image.get_size().y / image_size_y
image_size_x = preview_image.get_size().x / scale_ratio
preview.get_node("TransparentChecker").rect_size.x = image_size_x
preview.get_node("TransparentChecker").rect_size.y = image_size_y
func _popup_hide() -> void:
Global.dialog_open(false)

View file

@ -1,33 +1,16 @@
extends ConfirmationDialog
extends ImageEffect
enum {CEL, FRAME, ALL_FRAMES, ALL_PROJECTS}
var affect : int = CEL
var pixels := []
var current_cel : Image
var preview_image : Image
var preview_texture : ImageTexture
onready var preview : TextureRect = $VBoxContainer/Preview
onready var flip_h : CheckBox = $VBoxContainer/OptionsContainer/FlipHorizontal
onready var flip_v : CheckBox = $VBoxContainer/OptionsContainer/FlipVertical
onready var selection_checkbox : CheckBox = $VBoxContainer/OptionsContainer/SelectionCheckBox
func _ready() -> void:
current_cel = Image.new()
preview_image = Image.new()
preview_texture = ImageTexture.new()
func set_nodes() -> void:
preview = $VBoxContainer/Preview
selection_checkbox = $VBoxContainer/OptionsContainer/SelectionCheckBox
func _on_FlipImageDialog_about_to_show() -> void:
current_cel = Global.current_project.frames[Global.current_project.current_frame].cels[Global.current_project.current_layer].image
_on_SelectionCheckBox_toggled(selection_checkbox.pressed)
update_transparent_background_size()
func _on_FlipImageDialog_confirmed() -> void:
func _confirmed() -> void:
if affect == CEL:
Global.canvas.handle_undo("Draw")
flip_image(current_cel, pixels)
@ -71,14 +54,7 @@ func _on_FlipVertical_toggled(_button_pressed : bool) -> void:
func _on_SelectionCheckBox_toggled(button_pressed : bool) -> void:
pixels.clear()
if button_pressed:
pixels = Global.current_project.selected_pixels.duplicate()
else:
for x in Global.current_project.size.x:
for y in Global.current_project.size.y:
pixels.append(Vector2(x, y))
._on_SelectionCheckBox_toggled(button_pressed)
update_preview()
@ -117,21 +93,3 @@ func flip_image(image : Image, _pixels : Array, project : Project = Global.curre
selected_image.flip_y()
image.blit_rect_mask(selected_image, selected_image, Rect2(Vector2.ZERO, selected_image.get_size()), Vector2.ZERO)
func update_transparent_background_size() -> void:
var image_size_y = preview.rect_size.y
var image_size_x = preview.rect_size.x
if preview_image.get_size().x > preview_image.get_size().y:
var scale_ratio = preview_image.get_size().x / image_size_x
image_size_y = preview_image.get_size().y / scale_ratio
else:
var scale_ratio = preview_image.get_size().y / image_size_y
image_size_x = preview_image.get_size().x / scale_ratio
preview.get_node("TransparentChecker").rect_size.x = image_size_x
preview.get_node("TransparentChecker").rect_size.y = image_size_y
func _on_FlipImageDialog_popup_hide() -> void:
Global.dialog_open(false)

View file

@ -67,10 +67,6 @@ mouse_default_cursor_shape = 2
text = "Current cel"
items = [ "Current cel", null, false, 0, null, "Current frame", null, false, 1, null, "All frames", null, false, 2, null, "All projects", null, false, 3, null ]
selected = 0
[connection signal="about_to_show" from="." to="." method="_on_FlipImageDialog_about_to_show"]
[connection signal="confirmed" from="." to="." method="_on_FlipImageDialog_confirmed"]
[connection signal="popup_hide" from="." to="." method="_on_FlipImageDialog_popup_hide"]
[connection signal="toggled" from="VBoxContainer/OptionsContainer/FlipHorizontal" to="." method="_on_FlipHorizontal_toggled"]
[connection signal="toggled" from="VBoxContainer/OptionsContainer/FlipVertical" to="." method="_on_FlipVertical_toggled"]
[connection signal="toggled" from="VBoxContainer/OptionsContainer/SelectionCheckBox" to="." method="_on_SelectionCheckBox_toggled"]
[connection signal="item_selected" from="VBoxContainer/OptionsContainer/AffectOptionButton" to="." method="_on_AffectOptionButton_item_selected"]