mirror of
https://github.com/Relintai/GraphicsEditor.git
synced 2025-04-19 10:43:13 +02:00
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:
parent
d1e58f7c55
commit
8484a93eda
@ -17,6 +17,17 @@ func change_color_to(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])
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -20,7 +20,7 @@ var paint_canvas: GECanvas
|
||||
var canvas_background: TextureRect
|
||||
var grids_node
|
||||
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 textinfo
|
||||
var allow_drawing = true
|
||||
@ -96,10 +96,11 @@ func _input(event):
|
||||
if not mouse_on_top or not mouse_in_region:
|
||||
return
|
||||
|
||||
if Input.is_key_pressed(KEY_Z):
|
||||
undo_action()
|
||||
elif Input.is_key_pressed(KEY_Y):
|
||||
pass
|
||||
if event is InputEventKey:
|
||||
if event.scancode == KEY_Z and event.is_pressed() and not event.is_echo():
|
||||
undo_action()
|
||||
elif event.scancode == KEY_Y and event.is_pressed() and not event.is_echo():
|
||||
pass
|
||||
|
||||
_handle_zoom(event)
|
||||
|
||||
@ -114,6 +115,12 @@ func _input(event):
|
||||
if event.button_index == BUTTON_LEFT:
|
||||
if event.pressed:
|
||||
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
|
||||
@ -271,7 +278,7 @@ func brush_process():
|
||||
return
|
||||
|
||||
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()
|
||||
|
||||
match brush_mode:
|
||||
@ -288,7 +295,8 @@ func brush_process():
|
||||
Tools.BRIGHTEN:
|
||||
do_action([cell_mouse_position, last_cell_mouse_position, selected_color])
|
||||
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:
|
||||
do_action([cell_mouse_position, last_cell_mouse_position, selected_color])
|
||||
Tools.RAINBOW:
|
||||
@ -427,6 +435,11 @@ func get_action():
|
||||
# Brushes
|
||||
#---------------------------------------
|
||||
|
||||
|
||||
func set_selected_color(color):
|
||||
selected_color = color
|
||||
|
||||
|
||||
func set_brush(new_mode):
|
||||
if brush_mode == new_mode:
|
||||
return
|
||||
@ -609,10 +622,13 @@ func _on_Button_pressed():
|
||||
add_new_layer()
|
||||
|
||||
|
||||
|
||||
func _on_PaintCanvasContainer_mouse_entered():
|
||||
mouse_on_top = true
|
||||
|
||||
|
||||
func _on_PaintCanvasContainer_mouse_exited():
|
||||
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
@ -40,6 +40,15 @@ func load_img():
|
||||
var image_data = image.get_data()
|
||||
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):
|
||||
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())
|
||||
|
Loading…
Reference in New Issue
Block a user