Fixed image effects.

This commit is contained in:
Relintai 2020-11-30 14:36:28 +01:00
parent 548c78d023
commit c4f8224f40
19 changed files with 137 additions and 131 deletions

View File

@ -1,12 +1,9 @@
tool
extends Reference
var DrawGD : Node = null
enum GradientDirection {TOP, BOTTOM, LEFT, RIGHT}
func scale3X(sprite : Image, tol : float = 50) -> Image:
static func scale3X(sprite : Image, tol : float = 50) -> Image:
var scaled = Image.new()
scaled.create(sprite.get_width()*3, sprite.get_height()*3, false, Image.FORMAT_RGBA8)
scaled.lock()
@ -178,7 +175,7 @@ func rotxel(sprite : Image, angle : float) -> void:
aux.unlock()
func fake_rotsprite(sprite : Image, angle : float) -> void:
static func fake_rotsprite(sprite : Image, angle : float) -> void:
sprite.copy_from(scale3X(sprite))
nn_rotate(sprite,angle)
# warning-ignore:integer_division
@ -186,7 +183,7 @@ func fake_rotsprite(sprite : Image, angle : float) -> void:
sprite.resize(sprite.get_width() / 3, sprite.get_height() / 3, 0)
func nn_rotate(sprite : Image, angle : float) -> void:
static func nn_rotate(sprite : Image, angle : float) -> void:
var aux : Image = Image.new()
aux.copy_from(sprite)
sprite.lock()
@ -208,36 +205,37 @@ func nn_rotate(sprite : Image, angle : float) -> void:
aux.unlock()
func similarColors(c1 : Color, c2 : Color, tol : float = 100) -> bool:
static func similarColors(c1 : Color, c2 : Color, tol : float = 100) -> bool:
var dist = colorDistance(c1, c2)
return dist <= tol
func colorDistance(c1 : Color, c2 : Color) -> float:
static func colorDistance(c1 : Color, c2 : Color) -> float:
return sqrt(pow((c1.r - c2.r)*255, 2) + pow((c1.g - c2.g)*255, 2)
+ pow((c1.b - c2.b)*255, 2) + pow((c1.a - c2.a)*255, 2))
# Image effects
func scale_image(width : int, height : int, interpolation : int) -> void:
static func scale_image(DrawGD, width : int, height : int, interpolation : int) -> void:
DrawGD.current_project.undos += 1
DrawGD.current_project.undo_redo.create_action("Scale")
DrawGD.current_project.undo_redo.add_do_property(DrawGD.current_project, "size", Vector2(width, height).floor())
for f in DrawGD.current_project.frames:
for i in range(f.cels.size() - 1, -1, -1):
var sprite := Image.new()
sprite.copy_from(f.cels[i].image)
# Different method for scale3x
if interpolation == 5:
var times : Vector2 = Vector2(ceil(width/(3.0*sprite.get_width())),ceil(height/(3.0*sprite.get_height())))
for _j in range(max(times.x,times.y)):
sprite.copy_from(scale3X(sprite))
sprite.resize(width, height, 0)
else:
sprite.resize(width, height, interpolation)
DrawGD.current_project.undo_redo.add_do_property(f.cels[i].image, "data", sprite.data)
DrawGD.current_project.undo_redo.add_undo_property(f.cels[i].image, "data", f.cels[i].image.data)
var f = DrawGD.current_project.frames
for i in range(f.cels.size() - 1, -1, -1):
var sprite := Image.new()
sprite.copy_from(f.cels[i].image)
# Different method for scale3x
if interpolation == 5:
var times : Vector2 = Vector2(ceil(width/(3.0*sprite.get_width())),ceil(height/(3.0*sprite.get_height())))
for _j in range(max(times.x,times.y)):
sprite.copy_from(scale3X(sprite))
sprite.resize(width, height, 0)
else:
sprite.resize(width, height, interpolation)
DrawGD.current_project.undo_redo.add_do_property(f.cels[i].image, "data", sprite.data)
DrawGD.current_project.undo_redo.add_undo_property(f.cels[i].image, "data", f.cels[i].image.data)
DrawGD.current_project.undo_redo.add_undo_property(DrawGD.current_project, "size", DrawGD.current_project.size)
DrawGD.current_project.undo_redo.add_undo_method(DrawGD, "undo")
@ -245,23 +243,23 @@ func scale_image(width : int, height : int, interpolation : int) -> void:
DrawGD.current_project.undo_redo.commit_action()
func crop_image(image : Image) -> void:
static func crop_image(DrawGD, image : Image) -> void:
# Use first cel as a starting rectangle
var used_rect : Rect2 = image.get_used_rect()
for f in DrawGD.current_project.frames:
# However, if first cel is empty, loop through all cels until we find one that isn't
for cel in f.cels:
if used_rect != Rect2(0, 0, 0, 0):
break
else:
if cel.image.get_used_rect() != Rect2(0, 0, 0, 0):
used_rect = cel.image.get_used_rect()
var f = DrawGD.current_project.frames
# However, if first cel is empty, loop through all cels until we find one that isn't
for cel in f.cels:
if used_rect != Rect2(0, 0, 0, 0):
break
else:
if cel.image.get_used_rect() != Rect2(0, 0, 0, 0):
used_rect = cel.image.get_used_rect()
# Merge all layers with content
for cel in f.cels:
if cel.image.get_used_rect() != Rect2(0, 0, 0, 0):
used_rect = used_rect.merge(cel.image.get_used_rect())
for cel in f.cels:
if cel.image.get_used_rect() != Rect2(0, 0, 0, 0):
used_rect = used_rect.merge(cel.image.get_used_rect())
# If no layer has any content, just return
if used_rect == Rect2(0, 0, 0, 0):
@ -272,12 +270,12 @@ func crop_image(image : Image) -> void:
DrawGD.current_project.undos += 1
DrawGD.current_project.undo_redo.create_action("Scale")
DrawGD.current_project.undo_redo.add_do_property(DrawGD.current_project, "size", Vector2(width, height).floor())
for f in DrawGD.current_project.frames:
# Loop through all the layers to crop them
for j in range(DrawGD.current_project.layers.size() - 1, -1, -1):
var sprite : Image = f.cels[j].image.get_rect(used_rect)
DrawGD.current_project.undo_redo.add_do_property(f.cels[j].image, "data", sprite.data)
DrawGD.current_project.undo_redo.add_undo_property(f.cels[j].image, "data", f.cels[j].image.data)
# Loop through all the layers to crop them
for j in range(DrawGD.current_project.layers.size() - 1, -1, -1):
var sprite : Image = f.cels[j].image.get_rect(used_rect)
DrawGD.current_project.undo_redo.add_do_property(f.cels[j].image, "data", sprite.data)
DrawGD.current_project.undo_redo.add_undo_property(f.cels[j].image, "data", f.cels[j].image.data)
DrawGD.current_project.undo_redo.add_undo_property(DrawGD.current_project, "size", DrawGD.current_project.size)
DrawGD.current_project.undo_redo.add_undo_method(DrawGD, "undo")
@ -285,17 +283,17 @@ func crop_image(image : Image) -> void:
DrawGD.current_project.undo_redo.commit_action()
func resize_canvas(width : int, height : int, offset_x : int, offset_y : int) -> void:
static func resize_canvas(DrawGD, width : int, height : int, offset_x : int, offset_y : int) -> void:
DrawGD.current_project.undos += 1
DrawGD.current_project.undo_redo.create_action("Scale")
DrawGD.current_project.undo_redo.add_do_property(DrawGD.current_project, "size", Vector2(width, height).floor())
for f in DrawGD.current_project.frames:
for c in f.cels:
var sprite := Image.new()
sprite.create(width, height, false, Image.FORMAT_RGBA8)
sprite.blend_rect(c.image, Rect2(Vector2.ZERO, DrawGD.current_project.size), Vector2(offset_x, offset_y))
DrawGD.current_project.undo_redo.add_do_property(c.image, "data", sprite.data)
DrawGD.current_project.undo_redo.add_undo_property(c.image, "data", c.image.data)
var f = DrawGD.current_project.frames
for c in f.cels:
var sprite := Image.new()
sprite.create(width, height, false, Image.FORMAT_RGBA8)
sprite.blend_rect(c.image, Rect2(Vector2.ZERO, DrawGD.current_project.size), Vector2(offset_x, offset_y))
DrawGD.current_project.undo_redo.add_do_property(c.image, "data", sprite.data)
DrawGD.current_project.undo_redo.add_undo_property(c.image, "data", c.image.data)
DrawGD.current_project.undo_redo.add_undo_property(DrawGD.current_project, "size", DrawGD.current_project.size)
DrawGD.current_project.undo_redo.add_undo_method(DrawGD, "undo")
@ -303,7 +301,7 @@ func resize_canvas(width : int, height : int, offset_x : int, offset_y : int) ->
DrawGD.current_project.undo_redo.commit_action()
func invert_image_colors(image : Image, pixels : Array, red := true, green := true, blue := true, alpha := false) -> void:
static func invert_image_colors(image : Image, pixels : Array, red := true, green := true, blue := true, alpha := false) -> void:
image.lock()
for i in pixels:
var px_color := image.get_pixelv(i)
@ -319,7 +317,7 @@ func invert_image_colors(image : Image, pixels : Array, red := true, green := tr
image.set_pixelv(i, px_color)
func desaturate_image(image : Image, pixels : Array, red := true, green := true, blue := true, alpha := false) -> void:
static func desaturate_image(image : Image, pixels : Array, red := true, green := true, blue := true, alpha := false) -> void:
image.lock()
for i in pixels:
var px_color := image.get_pixelv(i)
@ -336,7 +334,7 @@ func desaturate_image(image : Image, pixels : Array, red := true, green := true,
image.set_pixelv(i, px_color)
func generate_outline(image : Image, pixels : Array, outline_color : Color, thickness : int, diagonal : bool, inside_image : bool) -> void:
static func generate_outline(DrawGD, image : Image, pixels : Array, outline_color : Color, thickness : int, diagonal : bool, inside_image : bool) -> void:
if image.is_invisible():
return
var new_image := Image.new()
@ -471,7 +469,7 @@ func generate_outline(image : Image, pixels : Array, outline_color : Color, thic
image.copy_from(new_image)
func adjust_hsv(img: Image, delta_h : float, delta_s : float, delta_v : float, pixels : Array) -> void:
static func adjust_hsv(img: Image, delta_h : float, delta_s : float, delta_v : float, pixels : Array) -> void:
img.lock()
for i in pixels:
var c : Color = img.get_pixelv(i)
@ -506,7 +504,12 @@ func adjust_hsv(img: Image, delta_h : float, delta_s : float, delta_v : float, p
img.unlock()
func generate_gradient(image : Image, colors : Array, steps := 2, direction : int = GradientDirection.TOP, pixels = DrawGD.current_project.selected_pixels) -> void:
static func generate_gradient(DrawGD, image : Image, colors : Array, steps := 2, direction : int = GradientDirection.TOP, pixels = null) -> void:
if !pixels:
pixels = DrawGD.current_project.selected_pixels
if colors.size() < 2:
return

View File

@ -5,7 +5,7 @@ class_name ImageEffect extends AcceptDialog
var Export = preload("res://addons/draw_gd/src/Autoload/Export.gd")
enum {CEL, FRAME, ALL_FRAMES, ALL_PROJECTS}
enum {CEL, FRAME, ALL_PROJECTS}
var affect : int = CEL
var pixels := []
@ -43,9 +43,11 @@ func _enter_tree() -> void:
func _about_to_show() -> void:
current_cel = DrawGD.current_project.frames[DrawGD.current_project.current_frame].cels[DrawGD.current_project.current_layer].image
current_cel = DrawGD.current_project.frames.cels[DrawGD.current_project.current_layer].image
current_frame.fill(Color(0, 0, 0, 0))
var frame = DrawGD.current_project.frames[DrawGD.current_project.current_frame]
var frame = DrawGD.current_project.frames
Export.blend_layers(current_frame, frame)
if selection_checkbox:
_on_SelectionCheckBox_toggled(selection_checkbox.pressed)
@ -65,13 +67,6 @@ func _confirmed() -> void:
commit_action(cel.image, pixels)
DrawGD.canvas.handle_redo("Draw", DrawGD.current_project, -1)
elif affect == ALL_FRAMES:
DrawGD.canvas.handle_undo("Draw", DrawGD.current_project, -1, -1)
for frame in DrawGD.current_project.frames:
for cel in frame.cels:
commit_action(cel.image, pixels)
DrawGD.canvas.handle_redo("Draw", DrawGD.current_project, -1, -1)
elif affect == ALL_PROJECTS:
for project in DrawGD.projects:
var _pixels := []
@ -83,9 +78,11 @@ func _confirmed() -> void:
_pixels.append(Vector2(x, y))
DrawGD.canvas.handle_undo("Draw", project, -1, -1)
for frame in project.frames:
for cel in frame.cels:
commit_action(cel.image, _pixels, project)
var frame = project.frames
for cel in frame.cels:
commit_action(cel.image, _pixels, project)
DrawGD.canvas.handle_redo("Draw", project, -1, -1)

View File

@ -182,11 +182,12 @@ func commit_undo(action : String, undo_data : Dictionary) -> void:
project.undo_redo.add_do_property(project, "selected_rect", redo_data["selected_rect"])
project.undo_redo.add_undo_property(project, "selected_rect", undo_data["selected_rect"])
if "image_data" in undo_data:
var image : Image = project.frames[project.current_frame].cels[project.current_layer].image
var image : Image = project.frames.cels[project.current_layer].image
project.undo_redo.add_do_property(image, "data", redo_data["image_data"])
project.undo_redo.add_undo_property(image, "data", undo_data["image_data"])
project.undo_redo.add_do_method(DrawGD, "redo", project.current_frame, project.current_layer)
project.undo_redo.add_undo_method(DrawGD, "undo", project.current_frame, project.current_layer)
project.undo_redo.add_do_method(DrawGD, "redo", 0, project.current_layer)
project.undo_redo.add_undo_method(DrawGD, "undo", 0, project.current_layer)
project.undo_redo.commit_action()
@ -195,7 +196,7 @@ func _get_undo_data(undo_image : bool) -> Dictionary:
var project = DrawGD.current_project
data["selected_rect"] = DrawGD.current_project.selected_rect
if undo_image:
var image : Image = project.frames[project.current_frame].cels[project.current_layer].image
var image : Image = project.frames.cels[project.current_layer].image
image.unlock()
data["image_data"] = image.data
image.lock()

View File

@ -123,26 +123,21 @@ func handle_undo(action : String, project : Project = DrawGD.current_project, la
if layer_index <= -2:
layer_index = project.current_layer
if frame_index <= -2:
frame_index = project.current_frame
var cels := []
var frames := []
var layers := []
if frame_index == -1:
frames = project.frames
else:
frames.append(project.frames[frame_index])
var frames = project.frames
if layer_index == -1:
layers = project.layers
else:
layers.append(project.layers[layer_index])
for f in frames:
for l in layers:
var index = project.layers.find(l)
cels.append(f.cels[index])
var f = frames
for l in layers:
var index = project.layers.find(l)
cels.append(f.cels[index])
project.undos += 1
project.undo_redo.create_action(action)
@ -164,26 +159,21 @@ func handle_redo(_action : String, project : Project = DrawGD.current_project, l
if layer_index <= -2:
layer_index = project.current_layer
if frame_index <= -2:
frame_index = project.current_frame
var cels := []
var frames := []
var layers := []
if frame_index == -1:
frames = project.frames
else:
frames.append(project.frames[frame_index])
var frames = project.frames
if layer_index == -1:
layers = project.layers
else:
layers.append(project.layers[layer_index])
for f in frames:
for l in layers:
var index = project.layers.find(l)
cels.append(f.cels[index])
var f = frames
for l in layers:
var index = project.layers.find(l)
cels.append(f.cels[index])
for cel in cels:
project.undo_redo.add_do_property(cel.image, "data", cel.image.data)

View File

@ -3,7 +3,6 @@
[ext_resource path="res://addons/draw_gd/src/UI/Dialogs/ImageEffects/DesaturateDialog.gd" type="Script" id=1]
[ext_resource path="res://addons/draw_gd/src/UI/TransparentChecker.tscn" type="PackedScene" id=2]
[node name="DesaturateDialog" type="ConfirmationDialog"]
margin_right = 200.0
margin_bottom = 70.0
@ -21,7 +20,8 @@ __meta__ = {
}
[node name="Preview" type="TextureRect" parent="VBoxContainer"]
margin_right = 263.0
margin_left = 31.0
margin_right = 231.0
margin_bottom = 200.0
rect_min_size = Vector2( 200, 200 )
size_flags_horizontal = 4
@ -95,8 +95,9 @@ margin_right = 263.0
margin_bottom = 24.0
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 ]
items = [ "Current cel", null, false, 0, null, "Current frame", null, false, 1, null, "All projects", null, false, 3, null ]
selected = 0
[connection signal="toggled" from="VBoxContainer/RGBAContainer/RButton" to="." method="_on_RButton_toggled"]
[connection signal="toggled" from="VBoxContainer/RGBAContainer/GButton" to="." method="_on_GButton_toggled"]
[connection signal="toggled" from="VBoxContainer/RGBAContainer/BButton" to="." method="_on_BButton_toggled"]

View File

@ -3,7 +3,6 @@
[ext_resource path="res://addons/draw_gd/src/UI/Dialogs/ImageEffects/FlipImageDialog.gd" type="Script" id=1]
[ext_resource path="res://addons/draw_gd/src/UI/TransparentChecker.tscn" type="PackedScene" id=2]
[node name="FlipImageDialog" type="ConfirmationDialog"]
margin_right = 283.0
margin_bottom = 300.0
@ -67,7 +66,8 @@ margin_right = 267.0
margin_bottom = 52.0
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 ]
items = [ "Current cel", null, false, 0, null, "Current frame", null, false, 1, null, "All projects", null, false, 3, null ]
selected = 0
[connection signal="toggled" from="VBoxContainer/OptionsContainer/FlipHorizontal" to="." method="_on_FlipHorizontal_toggled"]
[connection signal="toggled" from="VBoxContainer/OptionsContainer/FlipVertical" to="." method="_on_FlipVertical_toggled"]

View File

@ -21,7 +21,7 @@ func set_nodes() -> void:
func commit_action(_cel : Image, _pixels : Array, _project : Project = DrawGD.current_project) -> void:
DrawingAlgos.generate_gradient(_cel, [color1.color, color2.color], steps.value, direction.selected, _pixels)
DrawingAlgos.generate_gradient(DrawGD, _cel, [color1.color, color2.color], steps.value, direction.selected, _pixels)
func _on_ColorPickerButton_color_changed(_color : Color) -> void:

View File

@ -3,7 +3,6 @@
[ext_resource path="res://addons/draw_gd/src/UI/Dialogs/ImageEffects/GradientDialog.gd" type="Script" id=1]
[ext_resource path="res://addons/draw_gd/src/UI/TransparentChecker.tscn" type="PackedScene" id=2]
[node name="GradientDialog" type="ConfirmationDialog"]
margin_right = 200.0
margin_bottom = 196.0
@ -115,8 +114,9 @@ margin_right = 285.0
margin_bottom = 100.0
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 ]
items = [ "Current cel", null, false, 0, null, "Current frame", null, false, 1, null, "All projects", null, false, 3, null ]
selected = 0
[connection signal="color_changed" from="VBoxContainer/OptionsContainer/ColorsContainer/ColorPickerButton" to="." method="_on_ColorPickerButton_color_changed"]
[connection signal="color_changed" from="VBoxContainer/OptionsContainer/ColorsContainer/ColorPickerButton2" to="." method="_on_ColorPickerButton2_color_changed"]
[connection signal="value_changed" from="VBoxContainer/OptionsContainer/StepSpinBox" to="." method="_on_StepSpinBox_value_changed"]

View File

@ -3,7 +3,6 @@
[ext_resource path="res://addons/draw_gd/src/UI/Dialogs/ImageEffects/HSVDialog.gd" type="Script" id=1]
[ext_resource path="res://addons/draw_gd/src/UI/TransparentChecker.tscn" type="PackedScene" id=2]
[node name="HSVDialog" type="ConfirmationDialog"]
margin_left = 1.0
margin_top = -1.0
@ -23,7 +22,8 @@ __meta__ = {
}
[node name="Preview" type="TextureRect" parent="VBoxContainer"]
margin_right = 447.0
margin_left = 123.0
margin_right = 323.0
margin_bottom = 200.0
rect_min_size = Vector2( 200, 200 )
size_flags_horizontal = 4
@ -146,8 +146,9 @@ margin_right = 263.0
margin_bottom = 24.0
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 ]
items = [ "Current cel", null, false, 0, null, "Current frame", null, false, 1, null, "All projects", null, false, 3, null ]
selected = 0
[connection signal="value_changed" from="VBoxContainer/HBoxContainer/Sliders/Hue" to="." method="_on_Hue_value_changed"]
[connection signal="value_changed" from="VBoxContainer/HBoxContainer/Sliders/Saturation" to="." method="_on_Saturation_value_changed"]
[connection signal="value_changed" from="VBoxContainer/HBoxContainer/Sliders/Value" to="." method="_on_Value_value_changed"]

View File

@ -11,7 +11,6 @@
[ext_resource path="res://addons/draw_gd/src/UI/Dialogs/ImageEffects/OutlineDialog.tscn" type="PackedScene" id=13]
[ext_resource path="res://addons/draw_gd/src/UI/Dialogs/ImageEffects/ScaleImage.tscn" type="PackedScene" id=14]
[node name="ImageEffects" type="Control"]
mouse_filter = 2
__meta__ = {

View File

@ -3,7 +3,6 @@
[ext_resource path="res://addons/draw_gd/src/UI/Dialogs/ImageEffects/InvertColorsDialog.gd" type="Script" id=1]
[ext_resource path="res://addons/draw_gd/src/UI/TransparentChecker.tscn" type="PackedScene" id=2]
[node name="InvertColorsDialog" type="ConfirmationDialog"]
margin_right = 200.0
margin_bottom = 70.0
@ -95,8 +94,9 @@ margin_right = 263.0
margin_bottom = 24.0
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 ]
items = [ "Current cel", null, false, 0, null, "Current frame", null, false, 1, null, "All projects", null, false, 3, null ]
selected = 0
[connection signal="toggled" from="VBoxContainer/RGBAContainer/RButton" to="." method="_on_RButton_toggled"]
[connection signal="toggled" from="VBoxContainer/RGBAContainer/GButton" to="." method="_on_GButton_toggled"]
[connection signal="toggled" from="VBoxContainer/RGBAContainer/BButton" to="." method="_on_BButton_toggled"]

View File

@ -23,7 +23,7 @@ func set_nodes() -> void:
func commit_action(_cel : Image, _pixels : Array, _project : Project = DrawGD.current_project) -> void:
DrawingAlgos.generate_outline(_cel, _pixels, color, thickness, diagonal, inside_image)
DrawingAlgos.generate_outline(DrawGD, _cel, _pixels, color, thickness, diagonal, inside_image)
func _on_ThickValue_value_changed(value : int) -> void:

View File

@ -3,7 +3,6 @@
[ext_resource path="res://addons/draw_gd/src/UI/Dialogs/ImageEffects/OutlineDialog.gd" type="Script" id=1]
[ext_resource path="res://addons/draw_gd/src/UI/TransparentChecker.tscn" type="PackedScene" id=2]
[node name="OutlineDialog" type="ConfirmationDialog"]
margin_right = 200.0
margin_bottom = 70.0
@ -24,7 +23,8 @@ __meta__ = {
}
[node name="Preview" type="TextureRect" parent="VBoxContainer"]
margin_right = 312.0
margin_left = 56.0
margin_right = 256.0
margin_bottom = 200.0
rect_min_size = Vector2( 200, 200 )
size_flags_horizontal = 4
@ -100,12 +100,15 @@ pressed = true
text = "Only affect selection"
[node name="AffectOptionButton" type="OptionButton" parent="VBoxContainer/OptionsContainer"]
margin_right = 29.0
margin_bottom = 20.0
margin_left = 164.0
margin_top = 80.0
margin_right = 312.0
margin_bottom = 104.0
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 ]
items = [ "Current cel", null, false, 0, null, "Current frame", null, false, 1, null, "All projects", null, false, 3, null ]
selected = 0
[connection signal="value_changed" from="VBoxContainer/OptionsContainer/ThickValue" to="." method="_on_ThickValue_value_changed"]
[connection signal="color_changed" from="VBoxContainer/OptionsContainer/OutlineColor" to="." method="_on_OutlineColor_color_changed"]
[connection signal="toggled" from="VBoxContainer/OptionsContainer/DiagonalCheckBox" to="." method="_on_DiagonalCheckBox_toggled"]

View File

@ -18,6 +18,14 @@ onready var preview_rect : TextureRect = $VBoxContainer/Preview
var DrawGD : Node = null
func _enter_tree() -> void:
var n : Node = get_parent()
while n:
if n.name == "DrawGDSingleton":
DrawGD = n
break
n = n.get_parent()
func _on_ResizeCanvas_about_to_show() -> void:
if first_time:
width_spinbox.value = DrawGD.current_project.size.x
@ -27,7 +35,7 @@ func _on_ResizeCanvas_about_to_show() -> void:
image.create(DrawGD.current_project.size.x, DrawGD.current_project.size.y, false, Image.FORMAT_RGBA8)
image.lock()
var layer_i := 0
for cel in DrawGD.current_project.frames[DrawGD.current_project.current_frame].cels:
for cel in DrawGD.current_project.frames.cels:
if DrawGD.current_project.layers[layer_i].visible:
var cel_image := Image.new()
cel_image.copy_from(cel.image)
@ -46,7 +54,7 @@ func _on_ResizeCanvas_about_to_show() -> void:
func _on_ResizeCanvas_confirmed() -> void:
DrawingAlgos.resize_canvas(width, height, offset_x, offset_y)
DrawingAlgos.resize_canvas(DrawGD, width, height, offset_x, offset_y)
first_time = false

View File

@ -3,7 +3,6 @@
[ext_resource path="res://addons/draw_gd/src/UI/TransparentChecker.tscn" type="PackedScene" id=1]
[ext_resource path="res://addons/draw_gd/src/UI/Dialogs/ImageEffects/ResizeCanvas.gd" type="Script" id=2]
[node name="ResizeCanvas" type="ConfirmationDialog"]
margin_right = 200.0
margin_bottom = 114.0
@ -127,6 +126,7 @@ stretch_mode = 5
[node name="TransparentChecker" parent="VBoxContainer/Preview" instance=ExtResource( 1 )]
show_behind_parent = true
[connection signal="about_to_show" from="." to="." method="_on_ResizeCanvas_about_to_show"]
[connection signal="confirmed" from="." to="." method="_on_ResizeCanvas_confirmed"]
[connection signal="popup_hide" from="." to="." method="_on_ResizeCanvas_popup_hide"]

View File

@ -7,45 +7,37 @@ onready var type_option_button : OptionButton = $VBoxContainer/HBoxContainer2/Ty
onready var angle_hslider : HSlider = $VBoxContainer/AngleOptions/AngleHSlider
onready var angle_spinbox : SpinBox = $VBoxContainer/AngleOptions/AngleSpinBox
func _ready() -> void:
type_option_button.add_item("Rotxel")
type_option_button.add_item("Upscale, Rotate and Downscale")
type_option_button.add_item("Nearest neighbour")
func set_nodes() -> void:
preview = $VBoxContainer/Preview
func _about_to_show() -> void:
._about_to_show()
angle_hslider.value = 0
func commit_action(_cel : Image, _pixels : Array, _project : Project = DrawGD.current_project) -> void:
match type_option_button.text:
"Rotxel":
DrawingAlgos.rotxel(_cel,angle_hslider.value*PI/180)
DrawingAlgos.rotxel(_cel, angle_hslider.value * PI/180)
"Nearest neighbour":
DrawingAlgos.nn_rotate(_cel,angle_hslider.value*PI/180)
DrawingAlgos.nn_rotate(_cel, angle_hslider.value*PI/180)
"Upscale, Rotate and Downscale":
DrawingAlgos.fake_rotsprite(_cel,angle_hslider.value*PI/180)
DrawingAlgos.fake_rotsprite(_cel, angle_hslider.value*PI/180)
func _confirmed() -> void:
._confirmed()
angle_hslider.value = 0
func _on_HSlider_value_changed(_value : float) -> void:
update_preview()
angle_spinbox.value = angle_hslider.value
func _on_SpinBox_value_changed(_value : float) -> void:
angle_hslider.value = angle_spinbox.value
func _on_TypeOptionButton_item_selected(_id : int) -> void:
update_preview()

View File

@ -3,7 +3,6 @@
[ext_resource path="res://addons/draw_gd/src/UI/Dialogs/ImageEffects/RotateImage.gd" type="Script" id=1]
[ext_resource path="res://addons/draw_gd/src/UI/TransparentChecker.tscn" type="PackedScene" id=2]
[node name="RotateImage" type="ConfirmationDialog"]
margin_right = 245.0
margin_bottom = 241.0
@ -56,6 +55,9 @@ margin_bottom = 20.0
mouse_default_cursor_shape = 2
size_flags_horizontal = 3
size_flags_vertical = 3
text = "Rotxel"
items = [ "Rotxel", null, false, 0, null, "Upscale, Rotate and Downscale", null, false, 1, null, "Nearest neighbour", null, false, 2, null ]
selected = 0
[node name="AngleOptions" type="HBoxContainer" parent="VBoxContainer"]
margin_top = 228.0
@ -87,6 +89,7 @@ margin_bottom = 24.0
mouse_default_cursor_shape = 2
max_value = 359.0
suffix = "°"
[connection signal="item_selected" from="VBoxContainer/HBoxContainer2/TypeOptionButton" to="." method="_on_TypeOptionButton_item_selected"]
[connection signal="value_changed" from="VBoxContainer/AngleOptions/AngleHSlider" to="." method="_on_HSlider_value_changed"]
[connection signal="value_changed" from="VBoxContainer/AngleOptions/AngleSpinBox" to="." method="_on_SpinBox_value_changed"]

View File

@ -5,11 +5,19 @@ var DrawGD : Node = null
var DrawingAlgos = preload("res://addons/draw_gd/src/Autoload/DrawingAlgos.gd")
func _enter_tree():
var n : Node = get_parent()
while n:
if n.name == "DrawGDSingleton":
DrawGD = n
break
n = n.get_parent()
func _on_ScaleImage_confirmed() -> void:
var width : int = $VBoxContainer/OptionsContainer/WidthValue.value
var height : int = $VBoxContainer/OptionsContainer/HeightValue.value
var interpolation : int = $VBoxContainer/OptionsContainer/InterpolationType.selected
DrawingAlgos.scale_image(width, height, interpolation)
DrawingAlgos.scale_image(DrawGD, width, height, interpolation)
func _on_ScaleImage_popup_hide() -> void:

View File

@ -301,13 +301,13 @@ func toggle_zen_mode() -> void:
func image_menu_id_pressed(id : int) -> void:
if DrawGD.current_project.layers[DrawGD.current_project.current_layer].locked: # No changes if the layer is locked
return
var image : Image = DrawGD.current_project.frames[DrawGD.current_project.current_frame].cels[DrawGD.current_project.current_layer].image
var image : Image = DrawGD.current_project.frames.cels[DrawGD.current_project.current_layer].image
match id:
0: # Scale Image
show_scale_image_popup()
1: # Crop Image
DrawingAlgos.crop_image(image)
DrawingAlgos.crop_image(DrawGD, image)
2: # Resize Canvas
show_resize_canvas_popup()