2020-10-25 18:39:10 +01:00
|
|
|
tool
|
|
|
|
extends FileDialog
|
|
|
|
|
|
|
|
var canvas
|
|
|
|
|
|
|
|
var file_path = ""
|
|
|
|
|
|
|
|
|
|
|
|
func _enter_tree():
|
2020-10-26 17:01:31 +01:00
|
|
|
canvas = get_parent().get_node("Panel/VBoxContainer/HBoxContainer/PaintCanvasContainer/Canvas")
|
2020-10-25 18:39:10 +01:00
|
|
|
|
|
|
|
|
|
|
|
func _ready():
|
|
|
|
# warning-ignore:return_value_discarded
|
|
|
|
get_line_edit().connect("text_entered", self, "_on_LineEdit_text_entered")
|
|
|
|
invalidate()
|
|
|
|
clear_filters()
|
|
|
|
add_filter("*.png ; PNG Images")
|
|
|
|
|
|
|
|
|
|
|
|
func _on_SaveFileDialog_file_selected(path):
|
|
|
|
file_path = path
|
|
|
|
|
2020-10-26 17:01:31 +01:00
|
|
|
|
2020-10-25 18:39:10 +01:00
|
|
|
# warning-ignore:unused_argument
|
|
|
|
func _on_LineEdit_text_entered(text):
|
|
|
|
save_file()
|
|
|
|
|
2020-10-26 17:01:31 +01:00
|
|
|
|
2020-10-25 18:39:10 +01:00
|
|
|
func _on_SaveFileDialog_confirmed():
|
|
|
|
save_file()
|
|
|
|
|
|
|
|
|
|
|
|
func save_file():
|
|
|
|
var image = Image.new()
|
2020-10-26 17:01:31 +01:00
|
|
|
image.create(canvas.canvas_width, canvas.canvas_height, true, Image.FORMAT_RGBA8)
|
2020-10-25 18:39:10 +01:00
|
|
|
image.lock()
|
|
|
|
|
2020-10-27 20:18:11 +01:00
|
|
|
for layer in canvas.layers:
|
2020-10-26 17:01:31 +01:00
|
|
|
var idx = 0
|
|
|
|
for color in layer.pixels:
|
|
|
|
var pos = GEUtils.to_2D(idx, canvas.canvas_width)
|
|
|
|
idx += 1
|
|
|
|
|
|
|
|
image.lock()
|
|
|
|
var current_color = image.get_pixel(pos.x, pos.y)
|
|
|
|
if current_color.a != 0:
|
|
|
|
image.set_pixel(pos.x, pos.y, current_color.blend(color))
|
|
|
|
else:
|
|
|
|
image.set_pixel(pos.x, pos.y, color)
|
2020-10-25 18:39:10 +01:00
|
|
|
image.unlock()
|
|
|
|
image.save_png(file_path)
|
|
|
|
|
2020-10-26 17:01:31 +01:00
|
|
|
|
2020-10-25 18:39:10 +01:00
|
|
|
func _on_SaveFileDialog_about_to_show():
|
|
|
|
invalidate()
|
|
|
|
|
2020-10-26 17:01:31 +01:00
|
|
|
|
2020-10-25 18:39:10 +01:00
|
|
|
func _on_SaveFileDialog_visibility_changed():
|
|
|
|
invalidate()
|