mirror of
https://github.com/Relintai/GraphicsEditor.git
synced 2024-11-12 08:15:17 +01:00
93610d2f9c
- added layer highlighting (locked, selected, unselected) - brush preview enhancements - removed prints - fixed color picker tool not picking and adding color - fixed tool layer not clearing pixels if out of canvas - added clear active canvas button - disabled not implemented menu buttons - workaround for png saving, when files exists
72 lines
1.4 KiB
GDScript
72 lines
1.4 KiB
GDScript
tool
|
|
extends FileDialog
|
|
|
|
var canvas
|
|
|
|
var file_path = ""
|
|
|
|
|
|
func _enter_tree():
|
|
canvas = get_parent().find_node("Canvas")
|
|
|
|
|
|
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):
|
|
#print("selected file: ", path)
|
|
file_path = path
|
|
save_file()
|
|
|
|
|
|
# warning-ignore:unused_argument
|
|
func _on_LineEdit_text_entered(text):
|
|
return
|
|
# print("text entered: ", text)
|
|
|
|
|
|
func _on_SaveFileDialog_confirmed():
|
|
return
|
|
# print("confirmed: ", current_path)
|
|
|
|
|
|
func save_file():
|
|
var image = Image.new()
|
|
image.create(canvas.canvas_width, canvas.canvas_height, true, Image.FORMAT_RGBA8)
|
|
image.lock()
|
|
|
|
for layer in canvas.layers:
|
|
var idx = 0
|
|
if not layer.visible:
|
|
continue
|
|
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)
|
|
image.unlock()
|
|
|
|
var dir = Directory.new()
|
|
if dir.file_exists(file_path):
|
|
dir.remove(file_path)
|
|
|
|
image.save_png(file_path)
|
|
|
|
|
|
func _on_SaveFileDialog_about_to_show():
|
|
invalidate()
|
|
|
|
|
|
func _on_SaveFileDialog_visibility_changed():
|
|
invalidate()
|