mirror of
https://github.com/Relintai/GraphicsEditor.git
synced 2024-11-19 16:27:22 +01:00
added ability to lock alpha, fixed "wrong" alpha when right click
This commit is contained in:
parent
963fdf493e
commit
68ec0db371
@ -126,6 +126,15 @@ func set_canvas_height(val: int):
|
||||
|
||||
|
||||
|
||||
func toggle_alpha_locked(layer_name: String):
|
||||
var layer = find_layer_by_name(layer_name)
|
||||
layer.toggle_alpha_locked()
|
||||
|
||||
|
||||
func is_alpha_locked() -> bool:
|
||||
return active_layer.alpha_locked
|
||||
|
||||
|
||||
func get_content_margin() -> Rect2:
|
||||
var rect = Rect2(999999, 999999, -999999, -999999)
|
||||
|
||||
|
@ -358,9 +358,9 @@ func brush_process():
|
||||
|
||||
match brush_mode:
|
||||
Tools.PAINT:
|
||||
do_action([cell_mouse_position, last_cell_mouse_position, Color(0, 0, 0, 0)])
|
||||
do_action([cell_mouse_position, last_cell_mouse_position, Color.transparent])
|
||||
Tools.BRUSH:
|
||||
do_action([cell_mouse_position, last_cell_mouse_position, Color(0, 0, 0, 0), selected_brush_prefab])
|
||||
do_action([cell_mouse_position, last_cell_mouse_position, Color.transparent, selected_brush_prefab])
|
||||
else:
|
||||
if _current_action and _current_action.can_commit():
|
||||
commit_action()
|
||||
@ -733,5 +733,6 @@ func is_any_menu_open() -> bool:
|
||||
$ChangeGridSizeDialog.visible or \
|
||||
$Settings.visible or \
|
||||
$LoadFileDialog.visible or \
|
||||
$SaveFileDialog.visible
|
||||
$SaveFileDialog.visible or \
|
||||
find_node("Navbar").is_any_menu_open()
|
||||
|
||||
|
File diff suppressed because one or more lines are too long
@ -7,6 +7,7 @@ var layer_width
|
||||
var layer_height
|
||||
var visible = true setget set_visible
|
||||
var locked = false
|
||||
var alpha_locked = false
|
||||
|
||||
var texture: ImageTexture
|
||||
var image: Image
|
||||
@ -90,3 +91,8 @@ func set_visible(vis: bool):
|
||||
|
||||
func toggle_lock():
|
||||
locked = not locked
|
||||
|
||||
|
||||
func toggle_alpha_locked():
|
||||
alpha_locked = not alpha_locked
|
||||
|
||||
|
@ -8,6 +8,6 @@ func _ready():
|
||||
popup.connect("id_pressed", self, "id_pressed")
|
||||
|
||||
func id_pressed(id):
|
||||
emit_signal("item_pressed", name, popup.get_item_text(id))
|
||||
emit_signal("item_pressed", name, popup.get_item_text(id), id)
|
||||
|
||||
|
||||
|
@ -11,28 +11,29 @@ func _ready():
|
||||
for i in get_node("Buttons").get_children():
|
||||
i.connect("item_pressed", self, "button_pressed")
|
||||
|
||||
func button_pressed(button_name, button_item):
|
||||
|
||||
func button_pressed(button_name, button_item, id):
|
||||
# print("pressed: ", button_name)
|
||||
# print("pressed item is: '%s'" % button_item)
|
||||
|
||||
match button_name:
|
||||
"File":
|
||||
handle_file_menu(button_item)
|
||||
handle_file_menu(button_item, id)
|
||||
"Edit":
|
||||
handle_edit_menu(button_item)
|
||||
handle_edit_menu(button_item, id)
|
||||
"Canvas":
|
||||
handle_canvas_menu(button_item)
|
||||
handle_canvas_menu(button_item, id)
|
||||
"Layer":
|
||||
handle_layer_menu(button_item)
|
||||
handle_layer_menu(button_item, id)
|
||||
"Grid":
|
||||
handle_grid_menu(button_item)
|
||||
handle_grid_menu(button_item, id)
|
||||
"Magic":
|
||||
handle_magic_menu(button_item)
|
||||
handle_magic_menu(button_item, id)
|
||||
"Editor":
|
||||
handle_editor_menu(button_item)
|
||||
handle_editor_menu(button_item, id)
|
||||
|
||||
|
||||
func handle_file_menu(pressed_item: String):
|
||||
func handle_file_menu(pressed_item: String, id):
|
||||
match pressed_item:
|
||||
"Save":
|
||||
owner.get_node("SaveFileDialog").show()
|
||||
@ -42,13 +43,13 @@ func handle_file_menu(pressed_item: String):
|
||||
owner.get_node("ConfirmationDialog").show()
|
||||
|
||||
|
||||
func handle_edit_menu(pressed_item: String):
|
||||
func handle_edit_menu(pressed_item: String, id):
|
||||
match pressed_item:
|
||||
"Add Layer":
|
||||
editor.add_new_layer()
|
||||
|
||||
|
||||
func handle_canvas_menu(pressed_item: String):
|
||||
func handle_canvas_menu(pressed_item: String, id):
|
||||
match pressed_item:
|
||||
"Change Size":
|
||||
owner.get_node("ChangeCanvasSize").show()
|
||||
@ -56,7 +57,7 @@ func handle_canvas_menu(pressed_item: String):
|
||||
owner.paint_canvas.crop_to_content()
|
||||
|
||||
|
||||
func handle_layer_menu(pressed_item: String):
|
||||
func handle_layer_menu(pressed_item: String, id):
|
||||
match pressed_item:
|
||||
"Add Layer":
|
||||
editor.add_new_layer()
|
||||
@ -66,9 +67,12 @@ func handle_layer_menu(pressed_item: String):
|
||||
editor.duplicate_active_layer()
|
||||
"Clear Layer":
|
||||
owner.paint_canvas.clear_active_layer()
|
||||
"Toggle Alpha Locked":
|
||||
owner.paint_canvas.active_layer.toggle_alpha_locked()
|
||||
$Buttons/Layer.get_popup().set_item_checked(id, not $Buttons/Layer.get_popup().is_item_checked(id))
|
||||
|
||||
|
||||
func handle_grid_menu(pressed_item: String):
|
||||
func handle_grid_menu(pressed_item: String, id):
|
||||
match pressed_item:
|
||||
"Change Grid Size":
|
||||
owner.get_node("ChangeGridSizeDialog").show()
|
||||
@ -76,13 +80,13 @@ func handle_grid_menu(pressed_item: String):
|
||||
owner.paint_canvas.toggle_grid()
|
||||
|
||||
|
||||
func handle_magic_menu(pressed_item: String):
|
||||
func handle_magic_menu(pressed_item: String, id):
|
||||
match pressed_item:
|
||||
"Add Layer":
|
||||
editor.add_new_layer()
|
||||
|
||||
|
||||
func handle_editor_menu(pressed_item: String):
|
||||
func handle_editor_menu(pressed_item: String, id):
|
||||
match pressed_item:
|
||||
"Settings":
|
||||
owner.get_node("Settings").show()
|
||||
@ -92,3 +96,10 @@ func handle_editor_menu(pressed_item: String):
|
||||
"Reset Canvas Position":
|
||||
owner.paint_canvas_node.rect_position = Vector2(0, 0)
|
||||
|
||||
|
||||
func is_any_menu_open() -> bool:
|
||||
for child in $Buttons.get_children():
|
||||
if child.get_popup().visible:
|
||||
return true
|
||||
return false
|
||||
|
||||
|
@ -13,6 +13,9 @@ func do_action(canvas, data: Array):
|
||||
if canvas.get_pixel_v(pixel) == null:
|
||||
continue
|
||||
|
||||
if canvas.is_alpha_locked() and canvas.get_pixel_v(pixel) == Color.transparent:
|
||||
continue
|
||||
|
||||
if pixel in action_data.undo.cells:
|
||||
var brightened_color = canvas.get_pixel_v(pixel).lightened(0.1)
|
||||
canvas.set_pixel_v(pixel, brightened_color)
|
||||
|
@ -12,6 +12,9 @@ func do_action(canvas: GECanvas, data: Array):
|
||||
if p in action_data.undo.cells or canvas.get_pixel_v(p) == null:
|
||||
continue
|
||||
|
||||
if canvas.is_alpha_locked() and canvas.get_pixel_v(p) == Color.transparent:
|
||||
continue
|
||||
|
||||
action_data.undo.colors.append(canvas.get_pixel_v(p))
|
||||
action_data.undo.cells.append(p)
|
||||
|
||||
|
@ -12,6 +12,9 @@ func do_action(canvas, data: Array):
|
||||
|
||||
for pixel in pixels:
|
||||
if pixel in action_data.undo.cells:
|
||||
continue
|
||||
|
||||
if canvas.is_alpha_locked() and canvas.get_pixel_v(pixel) == Color.transparent:
|
||||
continue
|
||||
|
||||
action_data.undo.colors.append(canvas.get_pixel_v(pixel))
|
||||
|
@ -10,7 +10,11 @@ func do_action(canvas, data: Array):
|
||||
var pixels = GEUtils.get_pixels_in_line(data[0], data[1])
|
||||
for pixel in pixels:
|
||||
if canvas.get_pixel_v(pixel) == null:
|
||||
continue
|
||||
|
||||
if canvas.is_alpha_locked() and canvas.get_pixel_v(pixel) == Color.transparent:
|
||||
continue
|
||||
|
||||
if pixel in action_data.undo.cells:
|
||||
var darkened_color = canvas.get_pixel_v(pixel).darkened(dark_factor)
|
||||
canvas.set_pixel_v(pixel, darkened_color)
|
||||
|
@ -16,6 +16,9 @@ func do_action(canvas, data: Array):
|
||||
|
||||
var pixels = GEUtils.get_pixels_in_line(data[0], mouse_start_pos)
|
||||
for pixel in pixels:
|
||||
if canvas.is_alpha_locked() and canvas.get_pixel_v(pixel) == Color.transparent:
|
||||
continue
|
||||
|
||||
canvas.set_preview_pixel_v(pixel, data[2])
|
||||
action_data.preview.cells.append(pixel)
|
||||
action_data.preview.colors.append(data[2])
|
||||
|
@ -19,6 +19,9 @@ func do_action(canvas, data: Array):
|
||||
if canvas.get_pixel_v(pixel) == null:
|
||||
continue
|
||||
|
||||
if canvas.is_alpha_locked() and canvas.get_pixel_v(pixel) == Color.transparent:
|
||||
continue
|
||||
|
||||
var found = action_data.redo.cells.find(pixel)
|
||||
if found == -1:
|
||||
action_data.redo.cells.append(pixel)
|
||||
|
@ -9,6 +9,10 @@ func do_action(canvas, data: Array):
|
||||
for pixel in pixels:
|
||||
if pixel in action_data.undo.cells or canvas.get_pixel_v(pixel) == null:
|
||||
continue
|
||||
|
||||
if canvas.is_alpha_locked() and canvas.get_pixel_v(pixel) == Color.transparent:
|
||||
continue
|
||||
|
||||
action_data.undo.colors.append(canvas.get_pixel_v(pixel))
|
||||
action_data.undo.cells.append(pixel)
|
||||
canvas.set_pixel_v(pixel, data[2])
|
||||
|
@ -9,6 +9,10 @@ func do_action(canvas, data: Array):
|
||||
for pixel in pixels:
|
||||
if canvas.get_pixel_v(pixel) == null:
|
||||
continue
|
||||
|
||||
if canvas.is_alpha_locked() and canvas.get_pixel_v(pixel) == Color.transparent:
|
||||
continue
|
||||
|
||||
if pixel in action_data.undo.cells:
|
||||
var color = GEUtils.random_color()
|
||||
canvas.set_pixel_v(pixel, color)
|
||||
|
@ -28,6 +28,10 @@ func do_action(canvas, data: Array):
|
||||
for pixel in pixels:
|
||||
if canvas.get_pixel_v(pixel) == null:
|
||||
continue
|
||||
|
||||
if canvas.is_alpha_locked() and canvas.get_pixel_v(pixel) == Color.transparent:
|
||||
continue
|
||||
|
||||
canvas.set_preview_pixel_v(pixel, data[2])
|
||||
action_data.undo.cells.append(pixel)
|
||||
action_data.undo.colors.append(canvas.get_pixel_v(pixel))
|
||||
|
Loading…
Reference in New Issue
Block a user