1
0
Fork 0
mirror of https://github.com/Orama-Interactive/Pixelorama.git synced 2025-03-01 08:53:14 +00:00

Support draw tiles mode in elliptical and color select tools

This commit is contained in:
Emmanouil Papadeas 2024-12-04 03:07:35 +02:00
parent d579baf830
commit 4365ed8a3a
4 changed files with 84 additions and 24 deletions

View file

@ -77,6 +77,13 @@ func select_pixel(pixel: Vector2i, select := true) -> void:
set_pixelv(pixel, Color(0)) set_pixelv(pixel, Color(0))
func select_rect(rect: Rect2i, select := true) -> void:
if select:
fill_rect(rect, Color(1, 1, 1, 1))
else:
fill_rect(rect, Color(0))
func select_all() -> void: func select_all() -> void:
fill(Color(1, 1, 1, 1)) fill(Color(1, 1, 1, 1))

View file

@ -215,6 +215,13 @@ func apply_selection(_position: Vector2i) -> void:
_intersect = true _intersect = true
func select_tilemap_cell(
cel: CelTileMap, cell_position: int, selection: SelectionMap, select: bool
) -> void:
var rect := Rect2i(cel.get_cell_coords_in_image(cell_position), cel.tileset.tile_size)
selection.select_rect(rect, select)
func _on_confirm_button_pressed() -> void: func _on_confirm_button_pressed() -> void:
if selection_node.is_moving_content: if selection_node.is_moving_content:
selection_node.transform_content_confirm() selection_node.transform_content_confirm()

View file

@ -32,15 +32,38 @@ func apply_selection(pos: Vector2i) -> void:
if pos.x > project.size.x - 1 or pos.y > project.size.y - 1: if pos.x > project.size.x - 1 or pos.y > project.size.y - 1:
return return
var cel_image := Image.new()
cel_image.copy_from(_get_draw_image())
var color := cel_image.get_pixelv(pos)
var operation := 0 var operation := 0
if _subtract: if _subtract:
operation = 1 operation = 1
elif _intersect: elif _intersect:
operation = 2 operation = 2
if Tools.is_placing_tiles():
var prev_selection_map := SelectionMap.new() # Used for intersect
prev_selection_map.copy_from(project.selection_map)
if !_add and !_subtract and !_intersect:
Global.canvas.selection.clear_selection()
if _intersect:
project.selection_map.clear()
for cel in _get_selected_draw_cels():
if cel is not CelTileMap:
continue
var tilemap_cel := cel as CelTileMap
var tile_index := tilemap_cel.get_cell_index_at_coords(pos)
for i in tilemap_cel.cells.size():
var cell := tilemap_cel.cells[i]
if cell.index == tile_index:
if _intersect:
var p := (cel as CelTileMap).get_cell_coords_in_image(i)
select_tilemap_cell(
cel, i, project.selection_map, prev_selection_map.is_pixel_selected(p)
)
else:
select_tilemap_cell(cel, i, project.selection_map, !_subtract)
else:
var cel_image := Image.new()
cel_image.copy_from(_get_draw_image())
var color := cel_image.get_pixelv(pos)
var params := {"color": color, "tolerance": _tolerance, "operation": operation} var params := {"color": color, "tolerance": _tolerance, "operation": operation}
if _add or _subtract or _intersect: if _add or _subtract or _intersect:
var selection_tex := ImageTexture.create_from_image(project.selection_map) var selection_tex := ImageTexture.create_from_image(project.selection_map)

View file

@ -81,6 +81,24 @@ func apply_selection(_position: Vector2i) -> void:
Global.canvas.selection.commit_undo("Select", undo_data) Global.canvas.selection.commit_undo("Select", undo_data)
if _rect.size == Vector2i.ZERO: if _rect.size == Vector2i.ZERO:
return return
if Tools.is_placing_tiles():
var operation := 0
if _subtract:
operation = 1
elif _intersect:
operation = 2
Global.canvas.selection.select_rect(_rect, operation)
# Handle mirroring
var mirror_positions := Tools.get_mirrored_positions(_rect.position, project, 1)
var mirror_ends := Tools.get_mirrored_positions(_rect.end, project, 1)
for i in mirror_positions.size():
var mirror_rect := Rect2i()
mirror_rect.position = mirror_positions[i]
mirror_rect.end = mirror_ends[i]
Global.canvas.selection.select_rect(mirror_rect.abs(), operation)
Global.canvas.selection.commit_undo("Select", undo_data)
else:
set_ellipse(project.selection_map, _rect.position) set_ellipse(project.selection_map, _rect.position)
# Handle mirroring # Handle mirroring
var mirror_positions := Tools.get_mirrored_positions(_rect.position, project, 1) var mirror_positions := Tools.get_mirrored_positions(_rect.position, project, 1)
@ -116,8 +134,12 @@ func set_ellipse(selection_map: SelectionMap, pos: Vector2i) -> void:
# Given an origin point and destination point, returns a rect representing # Given an origin point and destination point, returns a rect representing
# where the shape will be drawn and what is its size # where the shape will be drawn and what is its size
func _get_result_rect(origin: Vector2i, dest: Vector2i) -> Rect2i: func _get_result_rect(origin: Vector2i, dest: Vector2i) -> Rect2i:
if Tools.is_placing_tiles():
var tileset := (Global.current_project.get_current_cel() as CelTileMap).tileset
var grid_size := tileset.tile_size
origin = Tools.snap_to_rectangular_grid_boundary(origin, grid_size)
dest = Tools.snap_to_rectangular_grid_boundary(dest, grid_size)
var rect := Rect2i() var rect := Rect2i()
# Center the rect on the mouse # Center the rect on the mouse
if _expand_from_center: if _expand_from_center:
var new_size := dest - origin var new_size := dest - origin
@ -140,6 +162,7 @@ func _get_result_rect(origin: Vector2i, dest: Vector2i) -> Rect2i:
rect.position = Vector2i(mini(origin.x, dest.x), mini(origin.y, dest.y)) rect.position = Vector2i(mini(origin.x, dest.x), mini(origin.y, dest.y))
rect.size = (origin - dest).abs() rect.size = (origin - dest).abs()
if not Tools.is_placing_tiles():
rect.size += Vector2i.ONE rect.size += Vector2i.ONE
return rect return rect