no echo when undo, added custom colors to grid on color change, when loading imgs bigger than canvas then canvas size increases

This commit is contained in:
cobrapitz 2020-10-31 18:35:52 +01:00
parent d1e58f7c55
commit 8484a93eda
4 changed files with 204 additions and 161 deletions

View File

@ -17,6 +17,17 @@ func change_color_to(color):
emit_signal("color_change_request", color) emit_signal("color_change_request", color)
func add_color_prefab(color: Color):
var dup = get_child(0).duplicate()
add_child(dup)
move_child(dup, 0)
dup.set("custom_styles/normal", StyleBoxFlat.new())
dup.get("custom_styles/normal").set("bg_color", color)
for child in get_children():
if child.is_connected("pressed", self, "change_color_to"):
return
child.connect("pressed", self, "change_color_to", [child.get("custom_styles/normal").bg_color])

View File

@ -20,7 +20,7 @@ var paint_canvas: GECanvas
var canvas_background: TextureRect var canvas_background: TextureRect
var grids_node var grids_node
var colors_grid var colors_grid
var selected_color = Color(1, 1, 1, 1) var selected_color = Color(1, 1, 1, 1) setget set_selected_color
var util = preload("res://addons/graphics_editor/Util.gd") var util = preload("res://addons/graphics_editor/Util.gd")
var textinfo var textinfo
var allow_drawing = true var allow_drawing = true
@ -96,9 +96,10 @@ func _input(event):
if not mouse_on_top or not mouse_in_region: if not mouse_on_top or not mouse_in_region:
return return
if Input.is_key_pressed(KEY_Z): if event is InputEventKey:
if event.scancode == KEY_Z and event.is_pressed() and not event.is_echo():
undo_action() undo_action()
elif Input.is_key_pressed(KEY_Y): elif event.scancode == KEY_Y and event.is_pressed() and not event.is_echo():
pass pass
_handle_zoom(event) _handle_zoom(event)
@ -114,6 +115,12 @@ func _input(event):
if event.button_index == BUTTON_LEFT: if event.button_index == BUTTON_LEFT:
if event.pressed: if event.pressed:
do_action([cell_mouse_position, last_cell_mouse_position, selected_color]) do_action([cell_mouse_position, last_cell_mouse_position, selected_color])
Tools.COLORPICKER:
if event is InputEventMouseButton:
if event.button_index == BUTTON_LEFT:
if event.pressed:
find_node("Colors").add_color_prefab(selected_color)
set_brush(_previous_tool)
var brush_mode var brush_mode
@ -271,7 +278,7 @@ func brush_process():
return return
if Input.is_mouse_button_pressed(BUTTON_LEFT): if Input.is_mouse_button_pressed(BUTTON_LEFT):
if _current_action == null: if _current_action == null and brush_mode != Tools.COLORPICKER:
_current_action = get_action() _current_action = get_action()
match brush_mode: match brush_mode:
@ -288,7 +295,8 @@ func brush_process():
Tools.BRIGHTEN: Tools.BRIGHTEN:
do_action([cell_mouse_position, last_cell_mouse_position, selected_color]) do_action([cell_mouse_position, last_cell_mouse_position, selected_color])
Tools.COLORPICKER: Tools.COLORPICKER:
change_color(paint_canvas.get_pixel(cell_mouse_position.x, cell_mouse_position.y)) selected_color = paint_canvas.get_pixel(cell_mouse_position.x, cell_mouse_position.y)
find_node("ColorPicker").color = selected_color
Tools.CUT: Tools.CUT:
do_action([cell_mouse_position, last_cell_mouse_position, selected_color]) do_action([cell_mouse_position, last_cell_mouse_position, selected_color])
Tools.RAINBOW: Tools.RAINBOW:
@ -427,6 +435,11 @@ func get_action():
# Brushes # Brushes
#--------------------------------------- #---------------------------------------
func set_selected_color(color):
selected_color = color
func set_brush(new_mode): func set_brush(new_mode):
if brush_mode == new_mode: if brush_mode == new_mode:
return return
@ -609,10 +622,13 @@ func _on_Button_pressed():
add_new_layer() add_new_layer()
func _on_PaintCanvasContainer_mouse_entered(): func _on_PaintCanvasContainer_mouse_entered():
mouse_on_top = true mouse_on_top = true
func _on_PaintCanvasContainer_mouse_exited(): func _on_PaintCanvasContainer_mouse_exited():
mouse_on_top = false mouse_on_top = false
func _on_ColorPicker_popup_closed():
find_node("Colors").add_color_prefab(find_node("ColorPicker").color)

File diff suppressed because one or more lines are too long

View File

@ -40,6 +40,15 @@ func load_img():
var image_data = image.get_data() var image_data = image.get_data()
var layer: GELayer = owner.add_new_layer() var layer: GELayer = owner.add_new_layer()
var width = image.get_width()
var height = image.get_height()
if owner.paint_canvas.canvas_width < width:
owner.paint_canvas.resize(width, owner.paint_canvas.canvas_height)
if owner.paint_canvas.canvas_height < height:
owner.paint_canvas.resize(owner.paint_canvas.canvas_width, height)
for i in range(image_data.size() / 4): for i in range(image_data.size() / 4):
var color = Color(image_data[i*4] / 255.0, image_data[i*4+1] / 255.0, image_data[i*4+2] / 255.0, image_data[i*4+3] / 255.0) var color = Color(image_data[i*4] / 255.0, image_data[i*4+1] / 255.0, image_data[i*4+2] / 255.0, image_data[i*4+3] / 255.0)
var pos = GEUtils.to_2D(i, image.get_width()) var pos = GEUtils.to_2D(i, image.get_width())