1
0
Fork 0
mirror of https://github.com/Orama-Interactive/Pixelorama.git synced 2025-03-01 08:53:14 +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 _orignal_brush_image := Image.new() ## Contains the original _brush_image, without resizing
var _brush_texture := ImageTexture.new() var _brush_texture := ImageTexture.new()
var _strength := 1.0 var _strength := 1.0
var _is_eraser := false
@warning_ignore("unused_private_class_variable") @warning_ignore("unused_private_class_variable")
var _picking_color := false var _picking_color := false
@ -320,12 +321,12 @@ func draw_end(pos: Vector2i) -> void:
_polylines = _create_polylines(_indicator) _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(): for cel in _get_selected_draw_cels():
if cel is not CelTileMap: if cel is not CelTileMap:
return 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) (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) pos = _stroke_project.tiles.get_canon_position(pos)
if Global.current_project.has_selection: if Global.current_project.has_selection:
pos = Global.current_project.selection_map.get_canon_position(pos) 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): if !_stroke_project.can_pixel_get_drawn(pos):
return return

View file

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

View file

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

View file

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

View file

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

View file

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