mirror of
https://github.com/Relintai/GraphicsEditor.git
synced 2025-05-04 03:07:56 +02:00
- fixed some null error relating to non existing pixels
- 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
This commit is contained in:
parent
a46eb96ca7
commit
93610d2f9c
@ -1,3 +1,3 @@
|
|||||||
source_md5="4e6da06002747457d0e002efd2f49ef8"
|
source_md5="40a7d1ca6c6f47e4bcd73f53dc225789"
|
||||||
dest_md5="46ed73e9c81c4cac671c27036b30b777"
|
dest_md5="b2a15f5bfa6f8fcf45985ec8c0490366"
|
||||||
|
|
||||||
|
Binary file not shown.
@ -124,6 +124,45 @@ func set_canvas_height(val: int):
|
|||||||
# Layer
|
# Layer
|
||||||
#-------------------------------
|
#-------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
func get_content_margin() -> Rect2:
|
||||||
|
var rect = Rect2(999999, 999999, -999999, -999999)
|
||||||
|
|
||||||
|
preview_layer.image.get_used_rect()
|
||||||
|
for layer in layers:
|
||||||
|
|
||||||
|
var r = layer.image.get_used_rect()
|
||||||
|
|
||||||
|
if r.position.x < rect.position.x:
|
||||||
|
rect.position.x = r.position.x
|
||||||
|
if r.position.y < rect.position.y:
|
||||||
|
rect.position.y = r.position.y
|
||||||
|
if r.size.x > rect.size.x:
|
||||||
|
rect.size.x = r.size.x
|
||||||
|
if r.size.y > rect.size.y:
|
||||||
|
rect.size.y = r.size.y
|
||||||
|
|
||||||
|
return rect
|
||||||
|
|
||||||
|
|
||||||
|
func crop_to_content():
|
||||||
|
var rect = get_content_margin()
|
||||||
|
|
||||||
|
#print(rect)
|
||||||
|
|
||||||
|
for layer in layers:
|
||||||
|
layer.image
|
||||||
|
|
||||||
|
# set_canvas_width(rect.size.x)
|
||||||
|
# set_canvas_height(rect.size.x)
|
||||||
|
|
||||||
|
# preview_layer.resize(width, height)
|
||||||
|
# tool_layer.resize(width, height)
|
||||||
|
# for layer in layers:
|
||||||
|
# layer.resize(width, height)
|
||||||
|
|
||||||
|
|
||||||
func get_active_layer():
|
func get_active_layer():
|
||||||
return active_layer
|
return active_layer
|
||||||
|
|
||||||
@ -195,9 +234,7 @@ func duplicate_layer(layer_name: String, new_layer_name: String):
|
|||||||
|
|
||||||
var dup_layer :GELayer = find_layer_by_name(layer_name)
|
var dup_layer :GELayer = find_layer_by_name(layer_name)
|
||||||
var layer :GELayer = add_new_layer(new_layer_name)
|
var layer :GELayer = add_new_layer(new_layer_name)
|
||||||
for idx in range(dup_layer.pixels.size()):
|
layer.image.copy_from(dup_layer.image)
|
||||||
var pos = GEUtils.to_2D(idx, layer.layer_width)
|
|
||||||
layer.set_pixel(pos.x, pos.y, dup_layer.pixels[idx])
|
|
||||||
return layer
|
return layer
|
||||||
|
|
||||||
|
|
||||||
@ -294,11 +331,8 @@ func get_pixel_v(pos: Vector2):
|
|||||||
|
|
||||||
|
|
||||||
func get_pixel(x: int, y: int):
|
func get_pixel(x: int, y: int):
|
||||||
var idx = GEUtils.to_1D(x, y, canvas_width)
|
|
||||||
if active_layer:
|
if active_layer:
|
||||||
if idx >= 0 and active_layer.pixels.size() <= idx:
|
return active_layer.get_pixel(x, y)
|
||||||
return null
|
|
||||||
return active_layer.pixels[idx]
|
|
||||||
return null
|
return null
|
||||||
|
|
||||||
|
|
||||||
@ -317,11 +351,9 @@ func get_preview_pixel_v(pos: Vector2):
|
|||||||
|
|
||||||
|
|
||||||
func get_preview_pixel(x: int, y: int):
|
func get_preview_pixel(x: int, y: int):
|
||||||
var idx = GEUtils.to_1D(x, y, canvas_width)
|
if not preview_layer:
|
||||||
if preview_layer:
|
return null
|
||||||
if preview_layer.pixels.size() <= idx:
|
return preview_layer.get_pixel(x, y)
|
||||||
return null
|
|
||||||
return preview_layer.pixels[idx]
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -54,7 +54,7 @@ var _actions_history = [] # for undo
|
|||||||
var _redo_history = []
|
var _redo_history = []
|
||||||
var _current_action
|
var _current_action
|
||||||
|
|
||||||
|
var _picked_color = false
|
||||||
|
|
||||||
var mouse_position = Vector2()
|
var mouse_position = Vector2()
|
||||||
var canvas_position = Vector2()
|
var canvas_position = Vector2()
|
||||||
@ -68,6 +68,9 @@ var last_canvas_mouse_position = Vector2()
|
|||||||
var last_cell_mouse_position = Vector2()
|
var last_cell_mouse_position = Vector2()
|
||||||
var last_cell_color = Color()
|
var last_cell_color = Color()
|
||||||
|
|
||||||
|
const current_layer_highlight = Color(0.354706, 0.497302, 0.769531)
|
||||||
|
const other_layer_highlight = Color(0.180392, 0.176471, 0.176471)
|
||||||
|
const locked_layer_highlight = Color(0.098039, 0.094118, 0.094118)
|
||||||
|
|
||||||
|
|
||||||
func _enter_tree():
|
func _enter_tree():
|
||||||
@ -98,6 +101,7 @@ func _ready():
|
|||||||
set_brush(Tools.PAINT)
|
set_brush(Tools.PAINT)
|
||||||
_layer_button_ref[layer_buttons.get_child(0).name] = layer_buttons.get_child(0) #ugly
|
_layer_button_ref[layer_buttons.get_child(0).name] = layer_buttons.get_child(0) #ugly
|
||||||
_connect_layer_buttons()
|
_connect_layer_buttons()
|
||||||
|
highlight_layer(paint_canvas.get_active_layer().name)
|
||||||
|
|
||||||
|
|
||||||
func _input(event):
|
func _input(event):
|
||||||
@ -125,18 +129,27 @@ func _input(event):
|
|||||||
commit_action()
|
commit_action()
|
||||||
|
|
||||||
if (paint_canvas.mouse_in_region and paint_canvas.mouse_on_top):
|
if (paint_canvas.mouse_in_region and paint_canvas.mouse_on_top):
|
||||||
|
|
||||||
if event is InputEventMouseButton:
|
if event is InputEventMouseButton:
|
||||||
match brush_mode:
|
match brush_mode:
|
||||||
Tools.BUCKET:
|
Tools.BUCKET:
|
||||||
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:
|
Tools.COLORPICKER:
|
||||||
if event.button_index == BUTTON_LEFT:
|
if event.button_index == BUTTON_LEFT:
|
||||||
if event.pressed:
|
if event.pressed:
|
||||||
|
if paint_canvas.get_pixel(cell_mouse_position.x, cell_mouse_position.y).a == 0:
|
||||||
|
return
|
||||||
|
selected_color = paint_canvas.get_pixel(cell_mouse_position.x, cell_mouse_position.y)
|
||||||
|
_picked_color = true
|
||||||
find_node("Colors").add_color_prefab(selected_color)
|
find_node("Colors").add_color_prefab(selected_color)
|
||||||
|
elif _picked_color:
|
||||||
set_brush(_previous_tool)
|
set_brush(_previous_tool)
|
||||||
|
elif event.button_index == BUTTON_RIGHT:
|
||||||
|
if event.pressed:
|
||||||
|
set_brush(_previous_tool)
|
||||||
|
|
||||||
Tools.PASTECUT:
|
Tools.PASTECUT:
|
||||||
if event.button_index == BUTTON_RIGHT:
|
if event.button_index == BUTTON_RIGHT:
|
||||||
if event.pressed:
|
if event.pressed:
|
||||||
@ -158,16 +171,21 @@ func _process(delta):
|
|||||||
mouse_position = paint_canvas.get_local_mouse_position()
|
mouse_position = paint_canvas.get_local_mouse_position()
|
||||||
canvas_position = paint_canvas_container_node.rect_position
|
canvas_position = paint_canvas_container_node.rect_position
|
||||||
canvas_mouse_position = Vector2(mouse_position.x - canvas_position.x, mouse_position.y - canvas_position.y)
|
canvas_mouse_position = Vector2(mouse_position.x - canvas_position.x, mouse_position.y - canvas_position.y)
|
||||||
cell_mouse_position = Vector2(floor(canvas_mouse_position.x / grid_size), floor(canvas_mouse_position.y / grid_size))
|
if is_mouse_in_canvas():
|
||||||
if cell_mouse_position.x >= 0 and cell_mouse_position.y >= 0:
|
cell_mouse_position = Vector2(floor(canvas_mouse_position.x / grid_size), floor(canvas_mouse_position.y / grid_size))
|
||||||
cell_color = paint_canvas.get_pixel(cell_mouse_position.x, cell_mouse_position.y)
|
cell_color = paint_canvas.get_pixel(cell_mouse_position.x, cell_mouse_position.y)
|
||||||
update_text_info()
|
update_text_info()
|
||||||
|
|
||||||
if not paint_canvas.is_active_layer_locked():
|
if not is_mouse_in_canvas():
|
||||||
if is_position_in_canvas(last_cell_mouse_position) or is_position_in_canvas(cell_mouse_position):
|
paint_canvas.tool_layer.clear()
|
||||||
brush_process()
|
paint_canvas.update()
|
||||||
|
paint_canvas.tool_layer.update_texture()
|
||||||
_draw_tool_brush()
|
else:
|
||||||
|
if not paint_canvas.is_active_layer_locked():
|
||||||
|
if is_position_in_canvas(last_cell_mouse_position) or is_position_in_canvas(cell_mouse_position):
|
||||||
|
brush_process()
|
||||||
|
|
||||||
|
_draw_tool_brush()
|
||||||
|
|
||||||
#Update last variables with the current variables
|
#Update last variables with the current variables
|
||||||
last_mouse_position = mouse_position
|
last_mouse_position = mouse_position
|
||||||
@ -184,17 +202,25 @@ func _draw_tool_brush():
|
|||||||
Tools.PASTECUT:
|
Tools.PASTECUT:
|
||||||
for idx in range(_selection_cells.size()):
|
for idx in range(_selection_cells.size()):
|
||||||
var pixel = _selection_cells[idx]
|
var pixel = _selection_cells[idx]
|
||||||
if pixel.x < 0 or pixel.y < 0:
|
# if pixel.x < 0 or pixel.y < 0:
|
||||||
print(pixel)
|
# print(pixel)
|
||||||
var color = _selection_colors[idx]
|
var color = _selection_colors[idx]
|
||||||
pixel -= _cut_pos + _cut_size / 2
|
pixel -= _cut_pos + _cut_size / 2
|
||||||
pixel += cell_mouse_position
|
pixel += cell_mouse_position
|
||||||
paint_canvas._set_pixel_v(paint_canvas.tool_layer, pixel, color)
|
paint_canvas._set_pixel_v(paint_canvas.tool_layer, pixel, color)
|
||||||
paint_canvas.update()
|
|
||||||
|
Tools.RAINBOW:
|
||||||
|
paint_canvas._set_pixel(paint_canvas.tool_layer,
|
||||||
|
cell_mouse_position.x, cell_mouse_position.y, Color(0.46875, 0.446777, 0.446777, 0.196078))
|
||||||
|
|
||||||
|
Tools.COLORPICKER:
|
||||||
|
paint_canvas._set_pixel(paint_canvas.tool_layer,
|
||||||
|
cell_mouse_position.x, cell_mouse_position.y, Color(0.866667, 0.847059, 0.847059, 0.196078))
|
||||||
_:
|
_:
|
||||||
paint_canvas._set_pixel(paint_canvas.tool_layer,
|
paint_canvas._set_pixel(paint_canvas.tool_layer,
|
||||||
cell_mouse_position.x, cell_mouse_position.y, selected_color)
|
cell_mouse_position.x, cell_mouse_position.y, selected_color)
|
||||||
|
|
||||||
|
paint_canvas.update()
|
||||||
#TODO add here brush prefab drawing
|
#TODO add here brush prefab drawing
|
||||||
paint_canvas.tool_layer.update_texture()
|
paint_canvas.tool_layer.update_texture()
|
||||||
|
|
||||||
@ -266,8 +292,10 @@ func _handle_cut():
|
|||||||
|
|
||||||
func brush_process():
|
func brush_process():
|
||||||
if Input.is_mouse_button_pressed(BUTTON_LEFT):
|
if Input.is_mouse_button_pressed(BUTTON_LEFT):
|
||||||
if _current_action == null and brush_mode != Tools.COLORPICKER:
|
if _current_action == null:
|
||||||
_current_action = get_action()
|
_current_action = get_action()
|
||||||
|
if brush_mode == Tools.COLORPICKER:
|
||||||
|
_current_action = null
|
||||||
match brush_mode:
|
match brush_mode:
|
||||||
Tools.PAINT:
|
Tools.PAINT:
|
||||||
do_action([cell_mouse_position, last_cell_mouse_position, selected_color])
|
do_action([cell_mouse_position, last_cell_mouse_position, selected_color])
|
||||||
@ -282,8 +310,7 @@ 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:
|
||||||
selected_color = paint_canvas.get_pixel(cell_mouse_position.x, cell_mouse_position.y)
|
pass
|
||||||
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.PASTECUT:
|
Tools.PASTECUT:
|
||||||
@ -346,7 +373,7 @@ func _on_Save_pressed():
|
|||||||
|
|
||||||
func do_action(data: Array):
|
func do_action(data: Array):
|
||||||
if _current_action == null:
|
if _current_action == null:
|
||||||
print("clear redo")
|
#print("clear redo")
|
||||||
_redo_history.clear()
|
_redo_history.clear()
|
||||||
_current_action.do_action(paint_canvas, data)
|
_current_action.do_action(paint_canvas, data)
|
||||||
|
|
||||||
@ -355,7 +382,7 @@ func commit_action():
|
|||||||
if not _current_action:
|
if not _current_action:
|
||||||
return
|
return
|
||||||
|
|
||||||
print("commit action")
|
#print("commit action")
|
||||||
var commit_data = _current_action.commit_action(paint_canvas)
|
var commit_data = _current_action.commit_action(paint_canvas)
|
||||||
var action = get_action()
|
var action = get_action()
|
||||||
action.action_data = _current_action.action_data.duplicate(true)
|
action.action_data = _current_action.action_data.duplicate(true)
|
||||||
@ -383,7 +410,7 @@ func redo_action():
|
|||||||
_actions_history.append(action)
|
_actions_history.append(action)
|
||||||
action.redo_action(paint_canvas)
|
action.redo_action(paint_canvas)
|
||||||
paint_canvas.update()
|
paint_canvas.update()
|
||||||
print("redo action")
|
#print("redo action")
|
||||||
|
|
||||||
|
|
||||||
func undo_action():
|
func undo_action():
|
||||||
@ -394,7 +421,7 @@ func undo_action():
|
|||||||
action.undo_action(paint_canvas)
|
action.undo_action(paint_canvas)
|
||||||
update()
|
update()
|
||||||
paint_canvas.update()
|
paint_canvas.update()
|
||||||
print("undo action")
|
#print("undo action")
|
||||||
|
|
||||||
|
|
||||||
func get_action():
|
func get_action():
|
||||||
@ -420,13 +447,13 @@ func get_action():
|
|||||||
Tools.PASTECUT:
|
Tools.PASTECUT:
|
||||||
return GEPasteCut.new()
|
return GEPasteCut.new()
|
||||||
_:
|
_:
|
||||||
print("no tool!")
|
#print("no tool!")
|
||||||
return null
|
return null
|
||||||
|
|
||||||
|
|
||||||
#---------------------------------------
|
############################################
|
||||||
# Brushes
|
# Brushes
|
||||||
#---------------------------------------
|
############################################
|
||||||
|
|
||||||
|
|
||||||
func set_selected_color(color):
|
func set_selected_color(color):
|
||||||
@ -449,7 +476,7 @@ func set_brush(new_mode):
|
|||||||
_selection_colors.clear()
|
_selection_colors.clear()
|
||||||
Tools.BUCKET:
|
Tools.BUCKET:
|
||||||
_current_action = null
|
_current_action = null
|
||||||
print("Selected: ", Tools.keys()[brush_mode])
|
#print("Selected: ", Tools.keys()[brush_mode])
|
||||||
|
|
||||||
|
|
||||||
func change_color(new_color):
|
func change_color(new_color):
|
||||||
@ -515,26 +542,40 @@ func _on_Editor_visibility_changed():
|
|||||||
pause_mode = not visible
|
pause_mode = not visible
|
||||||
|
|
||||||
|
|
||||||
#---------------------------------------
|
|
||||||
|
############################################
|
||||||
# Layer
|
# Layer
|
||||||
#---------------------------------------
|
############################################
|
||||||
|
|
||||||
|
func highlight_layer(layer_name: String):
|
||||||
|
for button in layer_buttons.get_children():
|
||||||
|
if paint_canvas.find_layer_by_name(button.name).locked:
|
||||||
|
button.get("custom_styles/panel").set("bg_color", locked_layer_highlight)
|
||||||
|
elif button.name == layer_name:
|
||||||
|
button.get("custom_styles/panel").set("bg_color", current_layer_highlight)
|
||||||
|
else:
|
||||||
|
button.get("custom_styles/panel").set("bg_color", other_layer_highlight)
|
||||||
|
|
||||||
|
|
||||||
func toggle_layer_visibility(button, layer_name: String):
|
func toggle_layer_visibility(button, layer_name: String):
|
||||||
print("toggling: ", layer_name)
|
#print("toggling: ", layer_name)
|
||||||
paint_canvas.toggle_layer_visibility(layer_name)
|
paint_canvas.toggle_layer_visibility(layer_name)
|
||||||
|
|
||||||
|
|
||||||
func select_layer(layer_name: String):
|
func select_layer(layer_name: String):
|
||||||
print("select layer: ", layer_name)
|
#print("select layer: ", layer_name)
|
||||||
paint_canvas.select_layer(layer_name)
|
paint_canvas.select_layer(layer_name)
|
||||||
|
highlight_layer(layer_name)
|
||||||
|
|
||||||
|
|
||||||
func lock_layer(button, layer_name: String):
|
func lock_layer(button, layer_name: String):
|
||||||
paint_canvas.toggle_lock_layer(layer_name)
|
paint_canvas.toggle_lock_layer(layer_name)
|
||||||
|
highlight_layer(paint_canvas.get_active_layer().name)
|
||||||
|
|
||||||
|
|
||||||
func add_new_layer():
|
func add_new_layer():
|
||||||
var new_layer_button = layer_buttons.get_child(0).duplicate()
|
var new_layer_button = layer_buttons.get_child(0).duplicate()
|
||||||
|
new_layer_button.set("custom_styles/panel", layer_buttons.get_child(0).get("custom_styles/panel").duplicate())
|
||||||
layer_buttons.add_child_below_node(
|
layer_buttons.add_child_below_node(
|
||||||
layer_buttons.get_child(layer_buttons.get_child_count() - 1), new_layer_button, true)
|
layer_buttons.get_child(layer_buttons.get_child_count() - 1), new_layer_button, true)
|
||||||
_total_added_layers += 1
|
_total_added_layers += 1
|
||||||
@ -543,7 +584,9 @@ func add_new_layer():
|
|||||||
_connect_layer_buttons()
|
_connect_layer_buttons()
|
||||||
|
|
||||||
var layer: GELayer = paint_canvas.add_new_layer(new_layer_button.name)
|
var layer: GELayer = paint_canvas.add_new_layer(new_layer_button.name)
|
||||||
print("added layer: ", layer.name)
|
|
||||||
|
highlight_layer(paint_canvas.get_active_layer().name)
|
||||||
|
#print("added layer: ", layer.name)
|
||||||
return layer
|
return layer
|
||||||
|
|
||||||
|
|
||||||
@ -555,10 +598,13 @@ func remove_active_layer():
|
|||||||
layer_buttons.remove_child(_layer_button_ref[layer_name])
|
layer_buttons.remove_child(_layer_button_ref[layer_name])
|
||||||
_layer_button_ref[layer_name].queue_free()
|
_layer_button_ref[layer_name].queue_free()
|
||||||
_layer_button_ref.erase(layer_name)
|
_layer_button_ref.erase(layer_name)
|
||||||
|
|
||||||
|
highlight_layer(paint_canvas.get_active_layer().name)
|
||||||
|
|
||||||
|
|
||||||
func duplicate_active_layer():
|
func duplicate_active_layer():
|
||||||
var new_layer_button = layer_buttons.get_child(0).duplicate()
|
var new_layer_button = layer_buttons.get_child(0).duplicate()
|
||||||
|
new_layer_button.set("custom_styles/panel", layer_buttons.get_child(0).get("custom_styles/panel").duplicate())
|
||||||
layer_buttons.add_child_below_node(
|
layer_buttons.add_child_below_node(
|
||||||
layer_buttons.get_child(layer_buttons.get_child_count() - 1), new_layer_button, true)
|
layer_buttons.get_child(layer_buttons.get_child_count() - 1), new_layer_button, true)
|
||||||
|
|
||||||
@ -576,19 +622,21 @@ func duplicate_active_layer():
|
|||||||
new_layer_button.find_node("Down").connect("pressed", self, "move_up", [new_layer_button])
|
new_layer_button.find_node("Down").connect("pressed", self, "move_up", [new_layer_button])
|
||||||
new_layer_button.find_node("Lock").connect("pressed", self, "lock_layer", [new_layer_button, new_layer_button.name])
|
new_layer_button.find_node("Lock").connect("pressed", self, "lock_layer", [new_layer_button, new_layer_button.name])
|
||||||
|
|
||||||
print("added layer: ", new_layer.name, " (total:", layer_buttons.get_child_count(), ")")
|
# update highlight
|
||||||
|
highlight_layer(paint_canvas.get_active_layer().name)
|
||||||
|
#print("added layer: ", new_layer.name, " (total:", layer_buttons.get_child_count(), ")")
|
||||||
|
|
||||||
|
|
||||||
func move_up(layer_btn):
|
func move_up(layer_btn):
|
||||||
var new_idx = min(layer_btn.get_index() + 1, layer_buttons.get_child_count())
|
var new_idx = min(layer_btn.get_index() + 1, layer_buttons.get_child_count())
|
||||||
print("move_up: ", layer_btn.name, " from ", layer_btn.get_index(), " to ", new_idx)
|
#print("move_up: ", layer_btn.name, " from ", layer_btn.get_index(), " to ", new_idx)
|
||||||
layer_buttons.move_child(layer_btn, new_idx)
|
layer_buttons.move_child(layer_btn, new_idx)
|
||||||
paint_canvas.move_layer_back(layer_btn.name)
|
paint_canvas.move_layer_back(layer_btn.name)
|
||||||
|
|
||||||
|
|
||||||
func move_down(layer_btn):
|
func move_down(layer_btn):
|
||||||
var new_idx = max(layer_btn.get_index() - 1, 0)
|
var new_idx = max(layer_btn.get_index() - 1, 0)
|
||||||
print("move_down: ", layer_btn.name, " from ", layer_btn.get_index(), " to ", new_idx)
|
#print("move_down: ", layer_btn.name, " from ", layer_btn.get_index(), " to ", new_idx)
|
||||||
layer_buttons.move_child(layer_btn, new_idx)
|
layer_buttons.move_child(layer_btn, new_idx)
|
||||||
paint_canvas.move_layer_forward(layer_btn.name)
|
paint_canvas.move_layer_forward(layer_btn.name)
|
||||||
|
|
||||||
@ -622,14 +670,12 @@ func _on_ColorPicker_popup_closed():
|
|||||||
find_node("Colors").add_color_prefab(find_node("ColorPicker").color)
|
find_node("Colors").add_color_prefab(find_node("ColorPicker").color)
|
||||||
|
|
||||||
|
|
||||||
#---------------------------------------
|
############################################
|
||||||
# MISC
|
# MISC
|
||||||
#---------------------------------------
|
############################################
|
||||||
|
|
||||||
func is_position_in_canvas(pos):
|
func is_position_in_canvas(pos):
|
||||||
last_cell_mouse_position
|
if Rect2(Vector2(), paint_canvas_container_node.rect_size).has_point(pos):
|
||||||
if Rect2(Vector2(), paint_canvas_container_node.rect_size).has_point(
|
|
||||||
pos):
|
|
||||||
return true
|
return true
|
||||||
return false
|
return false
|
||||||
|
|
||||||
|
File diff suppressed because one or more lines are too long
@ -65,7 +65,12 @@ func set_pixel(x, y, color):
|
|||||||
|
|
||||||
|
|
||||||
func get_pixel(x: int, y: int):
|
func get_pixel(x: int, y: int):
|
||||||
return pixels[x + y * layer_width]
|
if x < 0 or y < 0 or x >= image.get_width() or y >= image.get_height():
|
||||||
|
return null
|
||||||
|
image.lock()
|
||||||
|
var pixel = image.get_pixel(x, y)
|
||||||
|
image.unlock()
|
||||||
|
return pixel
|
||||||
|
|
||||||
|
|
||||||
func clear():
|
func clear():
|
||||||
@ -74,6 +79,7 @@ func clear():
|
|||||||
pixels[idx] = Color.transparent
|
pixels[idx] = Color.transparent
|
||||||
var pos = GEUtils.to_2D(idx, layer_width)
|
var pos = GEUtils.to_2D(idx, layer_width)
|
||||||
set_pixel(pos.x, pos.y, Color.transparent)
|
set_pixel(pos.x, pos.y, Color.transparent)
|
||||||
|
update_texture()
|
||||||
|
|
||||||
|
|
||||||
func update_texture():
|
func update_texture():
|
||||||
|
@ -12,8 +12,8 @@ func _ready():
|
|||||||
i.connect("item_pressed", self, "button_pressed")
|
i.connect("item_pressed", self, "button_pressed")
|
||||||
|
|
||||||
func button_pressed(button_name, button_item):
|
func button_pressed(button_name, button_item):
|
||||||
print("pressed: ", button_name)
|
# print("pressed: ", button_name)
|
||||||
print("pressed item is: '%s'" % button_item)
|
# print("pressed item is: '%s'" % button_item)
|
||||||
|
|
||||||
match button_name:
|
match button_name:
|
||||||
"File":
|
"File":
|
||||||
@ -52,6 +52,8 @@ func handle_canvas_menu(pressed_item: String):
|
|||||||
match pressed_item:
|
match pressed_item:
|
||||||
"Change Size":
|
"Change Size":
|
||||||
owner.get_node("ChangeCanvasSize").show()
|
owner.get_node("ChangeCanvasSize").show()
|
||||||
|
"Crop To Content":
|
||||||
|
owner.paint_canvas.crop_to_content()
|
||||||
|
|
||||||
|
|
||||||
func handle_layer_menu(pressed_item: String):
|
func handle_layer_menu(pressed_item: String):
|
||||||
@ -62,6 +64,8 @@ func handle_layer_menu(pressed_item: String):
|
|||||||
editor.remove_active_layer()
|
editor.remove_active_layer()
|
||||||
"Duplicate Layer":
|
"Duplicate Layer":
|
||||||
editor.duplicate_active_layer()
|
editor.duplicate_active_layer()
|
||||||
|
"Clear Layer":
|
||||||
|
owner.paint_canvas.clear_active_layer()
|
||||||
|
|
||||||
|
|
||||||
func handle_grid_menu(pressed_item: String):
|
func handle_grid_menu(pressed_item: String):
|
||||||
|
@ -37,12 +37,12 @@ func _enter_tree():
|
|||||||
}
|
}
|
||||||
|
|
||||||
canvas_size = Vector2(int(rect_size.x / grid_size), int(rect_size.y / grid_size))
|
canvas_size = Vector2(int(rect_size.x / grid_size), int(rect_size.y / grid_size))
|
||||||
print("canvas_size: ", canvas_size)
|
#print("canvas_size: ", canvas_size)
|
||||||
|
|
||||||
|
|
||||||
func _ready():
|
func _ready():
|
||||||
active_layer = add_existing_layer(get_tree().get_nodes_in_group("layer")[0])
|
active_layer = add_existing_layer(get_tree().get_nodes_in_group("layer")[0])
|
||||||
print("active Layer: ", active_layer)
|
#print("active Layer: ", active_layer)
|
||||||
|
|
||||||
|
|
||||||
func get_layer_data(layer_name):
|
func get_layer_data(layer_name):
|
||||||
@ -138,7 +138,7 @@ func duplicate_layer(layer: String, neu_layer_name: String):
|
|||||||
|
|
||||||
func toggle_layer_visibility(layer_name):
|
func toggle_layer_visibility(layer_name):
|
||||||
layers[layer_name].chunks.visible = not layers[layer_name].chunks.visible
|
layers[layer_name].chunks.visible = not layers[layer_name].chunks.visible
|
||||||
print("Layer: ", layer_name, " is now: ", layers[layer_name].chunks.visible)
|
#print("Layer: ", layer_name, " is now: ", layers[layer_name].chunks.visible)
|
||||||
|
|
||||||
|
|
||||||
var util = preload("res://addons/graphics_editor/Util.gd")
|
var util = preload("res://addons/graphics_editor/Util.gd")
|
||||||
@ -229,7 +229,7 @@ func set_local_cell_in_chunk(chunk_x, chunk_y, local_cell_x, local_cell_y, color
|
|||||||
chunk_node = layers[active_layer].chunks.get_node_or_null("C-%s-%s" % [chunk_x, chunk_y])
|
chunk_node = layers[active_layer].chunks.get_node_or_null("C-%s-%s" % [chunk_x, chunk_y])
|
||||||
|
|
||||||
if chunk_node == null:
|
if chunk_node == null:
|
||||||
print("Can't find chunk node!")
|
#print("Can't find chunk node!")
|
||||||
return
|
return
|
||||||
chunk_node.set_cell(local_cell_x, local_cell_y, color)
|
chunk_node.set_cell(local_cell_x, local_cell_y, color)
|
||||||
|
|
||||||
@ -409,7 +409,7 @@ func flood_fill(x, y, target_color, replacement_color):
|
|||||||
else:
|
else:
|
||||||
set_pixel_cell(x, y, replacement_color)
|
set_pixel_cell(x, y, replacement_color)
|
||||||
if flood_fill_queue >= 500:
|
if flood_fill_queue >= 500:
|
||||||
print(flood_fill_queue)
|
#print(flood_fill_queue)
|
||||||
yield(get_tree().create_timer(0.01), "timeout")
|
yield(get_tree().create_timer(0.01), "timeout")
|
||||||
#up
|
#up
|
||||||
if get_pixel_cell_color(x, y - 1) == target_color:
|
if get_pixel_cell_color(x, y - 1) == target_color:
|
||||||
|
@ -19,16 +19,20 @@ func _ready():
|
|||||||
|
|
||||||
|
|
||||||
func _on_SaveFileDialog_file_selected(path):
|
func _on_SaveFileDialog_file_selected(path):
|
||||||
|
#print("selected file: ", path)
|
||||||
file_path = path
|
file_path = path
|
||||||
|
save_file()
|
||||||
|
|
||||||
|
|
||||||
# warning-ignore:unused_argument
|
# warning-ignore:unused_argument
|
||||||
func _on_LineEdit_text_entered(text):
|
func _on_LineEdit_text_entered(text):
|
||||||
save_file()
|
return
|
||||||
|
# print("text entered: ", text)
|
||||||
|
|
||||||
|
|
||||||
func _on_SaveFileDialog_confirmed():
|
func _on_SaveFileDialog_confirmed():
|
||||||
save_file()
|
return
|
||||||
|
# print("confirmed: ", current_path)
|
||||||
|
|
||||||
|
|
||||||
func save_file():
|
func save_file():
|
||||||
@ -38,6 +42,8 @@ func save_file():
|
|||||||
|
|
||||||
for layer in canvas.layers:
|
for layer in canvas.layers:
|
||||||
var idx = 0
|
var idx = 0
|
||||||
|
if not layer.visible:
|
||||||
|
continue
|
||||||
for color in layer.pixels:
|
for color in layer.pixels:
|
||||||
var pos = GEUtils.to_2D(idx, canvas.canvas_width)
|
var pos = GEUtils.to_2D(idx, canvas.canvas_width)
|
||||||
idx += 1
|
idx += 1
|
||||||
@ -49,6 +55,11 @@ func save_file():
|
|||||||
else:
|
else:
|
||||||
image.set_pixel(pos.x, pos.y, color)
|
image.set_pixel(pos.x, pos.y, color)
|
||||||
image.unlock()
|
image.unlock()
|
||||||
|
|
||||||
|
var dir = Directory.new()
|
||||||
|
if dir.file_exists(file_path):
|
||||||
|
dir.remove(file_path)
|
||||||
|
|
||||||
image.save_png(file_path)
|
image.save_png(file_path)
|
||||||
|
|
||||||
|
|
||||||
|
@ -10,6 +10,9 @@ func do_action(canvas, data: Array):
|
|||||||
|
|
||||||
var pixels = GEUtils.get_pixels_in_line(data[0], data[1])
|
var pixels = GEUtils.get_pixels_in_line(data[0], data[1])
|
||||||
for pixel in pixels:
|
for pixel in pixels:
|
||||||
|
if canvas.get_pixel_v(pixel) == null:
|
||||||
|
continue
|
||||||
|
|
||||||
if pixel in action_data.undo.cells:
|
if pixel in action_data.undo.cells:
|
||||||
var brightened_color = canvas.get_pixel_v(pixel).lightened(0.1)
|
var brightened_color = canvas.get_pixel_v(pixel).lightened(0.1)
|
||||||
canvas.set_pixel_v(pixel, brightened_color)
|
canvas.set_pixel_v(pixel, brightened_color)
|
||||||
|
@ -52,7 +52,7 @@ func commit_action(canvas):
|
|||||||
var pos = p + Vector2(px, py)
|
var pos = p + Vector2(px, py)
|
||||||
var color = canvas.get_pixel(pos.x, pos.y)
|
var color = canvas.get_pixel(pos.x, pos.y)
|
||||||
|
|
||||||
if color.a == 0.0:
|
if color == null or color.a == 0.0:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
action_data.redo.cells.append(pos)
|
action_data.redo.cells.append(pos)
|
||||||
|
@ -9,6 +9,8 @@ func do_action(canvas, data: Array):
|
|||||||
|
|
||||||
var pixels = GEUtils.get_pixels_in_line(data[0], data[1])
|
var pixels = GEUtils.get_pixels_in_line(data[0], data[1])
|
||||||
for pixel in pixels:
|
for pixel in pixels:
|
||||||
|
if canvas.get_pixel_v(pixel) == null:
|
||||||
|
continue
|
||||||
if pixel in action_data.undo.cells:
|
if pixel in action_data.undo.cells:
|
||||||
var darkened_color = canvas.get_pixel_v(pixel).darkened(dark_factor)
|
var darkened_color = canvas.get_pixel_v(pixel).darkened(dark_factor)
|
||||||
canvas.set_pixel_v(pixel, darkened_color)
|
canvas.set_pixel_v(pixel, darkened_color)
|
||||||
|
@ -9,7 +9,7 @@ func do_action(canvas, data: Array):
|
|||||||
|
|
||||||
if mouse_start_pos == null:
|
if mouse_start_pos == null:
|
||||||
mouse_start_pos = data[0]
|
mouse_start_pos = data[0]
|
||||||
print("init:", mouse_start_pos)
|
#print("init:", mouse_start_pos)
|
||||||
|
|
||||||
|
|
||||||
action_data.undo.cells.clear()
|
action_data.undo.cells.clear()
|
||||||
|
@ -15,19 +15,21 @@ func _ready():
|
|||||||
|
|
||||||
|
|
||||||
func _on_LineEdit_text_entered(_text):
|
func _on_LineEdit_text_entered(_text):
|
||||||
print(_text)
|
return
|
||||||
|
# print(_text)
|
||||||
#load_img()
|
#load_img()
|
||||||
print("hsadfasd")
|
# print("hsadfasd")
|
||||||
|
|
||||||
|
|
||||||
func _on_LoadFileDialog_file_selected(path):
|
func _on_LoadFileDialog_file_selected(path):
|
||||||
file_path = path
|
file_path = path
|
||||||
print("1ere")
|
#print("1ere")
|
||||||
load_img()
|
load_img()
|
||||||
|
|
||||||
|
|
||||||
func _on_LoadFileDialog_confirmed():
|
func _on_LoadFileDialog_confirmed():
|
||||||
print("ere")
|
return
|
||||||
|
#print("ere")
|
||||||
#load_img()
|
#load_img()
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user