1
0
Fork 0
mirror of https://github.com/Orama-Interactive/Pixelorama.git synced 2025-01-31 07:29:49 +00:00

Add support for the draw tile mode for the rest of the draw tools, except bucket

Also fixes issues with the draw tile mode with the pencil and eraser tools, such as leaving gaps if the mouse is moving fast, and support for spacing and fill inside tool options.
This commit is contained in:
Emmanouil Papadeas 2024-12-02 23:42:08 +02:00
parent 228bc65a38
commit 889e93e548
6 changed files with 27 additions and 35 deletions

View file

@ -18,6 +18,7 @@ var _brush_image := Image.new()
var _orignal_brush_image := Image.new() ## Contains the original _brush_image, without resizing
var _brush_texture := ImageTexture.new()
var _strength := 1.0
var _is_eraser := false
@warning_ignore("unused_private_class_variable")
var _picking_color := false
@ -320,12 +321,12 @@ func draw_end(pos: Vector2i) -> void:
_polylines = _create_polylines(_indicator)
func draw_tile(pos: Vector2i, tile_index: int) -> void:
func draw_tile(pos: Vector2i) -> void:
var tile_position := get_cell_position(pos)
var tile_index := 0 if _is_eraser else TileSetPanel.selected_tile_index
for cel in _get_selected_draw_cels():
if cel is not CelTileMap:
return
pos = Global.current_project.tiles.get_canon_position(pos)
var tile_position := get_cell_position(pos)
(cel as CelTileMap).set_index(tile_position, tile_index)
@ -570,6 +571,9 @@ func _set_pixel_no_cache(pos: Vector2i, ignore_mirroring := false) -> void:
pos = _stroke_project.tiles.get_canon_position(pos)
if Global.current_project.has_selection:
pos = Global.current_project.selection_map.get_canon_position(pos)
if is_placing_tiles():
draw_tile(pos)
return
if !_stroke_project.can_pixel_get_drawn(pos):
return

View file

@ -189,9 +189,12 @@ func _draw_shape(origin: Vector2i, dest: Vector2i) -> void:
_drawer.reset()
# Draw each point offsetted based on the shape's thickness
var draw_pos := point + thickness_vector
if Global.current_project.can_pixel_get_drawn(draw_pos):
for image in images:
_drawer.set_pixel(image, draw_pos, tool_slot.color)
if is_placing_tiles():
draw_tile(draw_pos)
else:
if Global.current_project.can_pixel_get_drawn(draw_pos):
for image in images:
_drawer.set_pixel(image, draw_pos, tool_slot.color)
commit_undo()

View file

@ -195,9 +195,12 @@ func _draw_shape() -> void:
func _draw_pixel(point: Vector2i, images: Array[ImageExtended]) -> void:
if Global.current_project.can_pixel_get_drawn(point):
for image in images:
_drawer.set_pixel(image, point, tool_slot.color)
if is_placing_tiles():
draw_tile(point)
else:
if Global.current_project.can_pixel_get_drawn(point):
for image in images:
_drawer.set_pixel(image, point, tool_slot.color)
func _clear() -> void:

View file

@ -19,6 +19,7 @@ class EraseOp:
func _init() -> void:
_drawer.color_op = EraseOp.new()
_is_eraser = true
_clear_image = Image.create(1, 1, false, Image.FORMAT_RGBA8)
_clear_image.fill(Color(0, 0, 0, 0))
@ -44,9 +45,6 @@ func draw_start(pos: Vector2i) -> void:
_picking_color = false
Global.canvas.selection.transform_content_confirm()
prepare_undo("Draw")
if is_placing_tiles():
draw_tile(pos, 0)
return
update_mask(_strength == 1)
_changed = false
_drawer.color_op.changed = false
@ -75,9 +73,6 @@ func draw_move(pos_i: Vector2i) -> void:
if Input.is_action_pressed(&"draw_color_picker", true):
_pick_color(pos)
return
if is_placing_tiles():
draw_tile(pos, 0)
return
if _draw_line:
if Global.mirror_view:
@ -99,11 +94,6 @@ func draw_end(pos: Vector2i) -> void:
if _picking_color:
super.draw_end(pos)
return
if is_placing_tiles():
super.draw_end(pos)
draw_tile(pos, 0)
commit_undo()
return
if _draw_line:
if Global.mirror_view:

View file

@ -174,10 +174,13 @@ func _draw_shape() -> void:
for point in points:
# Reset drawer every time because pixel perfect sometimes breaks the tool
_drawer.reset()
# Draw each point offsetted based on the shape's thickness
if Global.current_project.can_pixel_get_drawn(point):
for image in images:
_drawer.set_pixel(image, point, tool_slot.color)
if is_placing_tiles():
draw_tile(point)
else:
# Draw each point offsetted based on the shape's thickness
if Global.current_project.can_pixel_get_drawn(point):
for image in images:
_drawer.set_pixel(image, point, tool_slot.color)
commit_undo()

View file

@ -104,9 +104,6 @@ func draw_start(pos: Vector2i) -> void:
Global.canvas.selection.transform_content_confirm()
prepare_undo("Draw")
if is_placing_tiles():
draw_tile(pos, TileSetPanel.selected_tile_index)
return
var can_skip_mask := true
if tool_slot.color.a < 1 and !_overwrite:
can_skip_mask = false
@ -145,9 +142,6 @@ func draw_move(pos_i: Vector2i) -> void:
if Input.is_action_pressed(&"draw_color_picker", true):
_pick_color(pos)
return
if is_placing_tiles():
draw_tile(pos, TileSetPanel.selected_tile_index)
return
if _draw_line:
_spacing_mode = false # spacing mode is disabled during line mode
@ -173,11 +167,6 @@ func draw_end(pos: Vector2i) -> void:
if _picking_color:
super.draw_end(pos)
return
if is_placing_tiles():
super.draw_end(pos)
draw_tile(pos, TileSetPanel.selected_tile_index)
commit_undo()
return
if _draw_line:
_spacing_mode = false # spacing mode is disabled during line mode