GraphicsEditor/addons/graphics_editor/actions/Pencil.gd

41 lines
985 B
GDScript3
Raw Normal View History

extends GEAction
class_name GEPencil
2020-10-25 18:39:10 +01:00
func do_action(canvas, data: Array):
if not "cells" in action_data.do:
action_data.do["cells"] = []
action_data.do["colors"] = []
if not "cells" in action_data.undo:
action_data.undo["cells"] = []
action_data.undo["colors"] = []
if "layer" in action_data.do:
action_data.do["layer"] = canvas.active_layer
action_data.undo["layer"] = canvas.active_layer
2020-10-25 18:39:10 +01:00
var pixels = GEUtils.get_pixels_in_line(data[0], data[1])
for pixel in pixels:
canvas.set_pixel_v(pixel, data[2])
action_data.do.cells.append(pixel)
action_data.undo.cells.append(pixel)
2020-10-25 18:39:10 +01:00
action_data.do.colors.append(data[2])
action_data.undo.colors.append(Color.transparent)
func commit_action(canvas):
var cells = action_data.do.cells
var colors = action_data.do.colors
2020-10-25 18:39:10 +01:00
func undo_action(canvas):
var cells = action_data.undo.cells
var colors = action_data.undo.colors
for idx in range(cells.size()):
canvas.set_pixel_v(cells[idx], colors[idx])
2020-10-25 18:39:10 +01:00