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:
parent
d579baf830
commit
4365ed8a3a
4 changed files with 84 additions and 24 deletions
|
@ -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))
|
||||||
|
|
||||||
|
|
|
@ -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()
|
||||||
|
|
|
@ -32,23 +32,46 @@ 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
|
||||||
|
|
||||||
var params := {"color": color, "tolerance": _tolerance, "operation": operation}
|
if Tools.is_placing_tiles():
|
||||||
if _add or _subtract or _intersect:
|
var prev_selection_map := SelectionMap.new() # Used for intersect
|
||||||
var selection_tex := ImageTexture.create_from_image(project.selection_map)
|
prev_selection_map.copy_from(project.selection_map)
|
||||||
params["selection"] = selection_tex
|
if !_add and !_subtract and !_intersect:
|
||||||
var gen := ShaderImageEffect.new()
|
Global.canvas.selection.clear_selection()
|
||||||
gen.generate_image(cel_image, shader, params, project.size)
|
if _intersect:
|
||||||
cel_image.convert(Image.FORMAT_LA8)
|
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}
|
||||||
|
if _add or _subtract or _intersect:
|
||||||
|
var selection_tex := ImageTexture.create_from_image(project.selection_map)
|
||||||
|
params["selection"] = selection_tex
|
||||||
|
var gen := ShaderImageEffect.new()
|
||||||
|
gen.generate_image(cel_image, shader, params, project.size)
|
||||||
|
cel_image.convert(Image.FORMAT_LA8)
|
||||||
|
|
||||||
project.selection_map.copy_from(cel_image)
|
project.selection_map.copy_from(cel_image)
|
||||||
Global.canvas.selection.big_bounding_rectangle = project.selection_map.get_used_rect()
|
Global.canvas.selection.big_bounding_rectangle = project.selection_map.get_used_rect()
|
||||||
Global.canvas.selection.commit_undo("Select", undo_data)
|
Global.canvas.selection.commit_undo("Select", undo_data)
|
||||||
|
|
|
@ -81,18 +81,36 @@ 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
|
||||||
set_ellipse(project.selection_map, _rect.position)
|
if Tools.is_placing_tiles():
|
||||||
# Handle mirroring
|
var operation := 0
|
||||||
var mirror_positions := Tools.get_mirrored_positions(_rect.position, project, 1)
|
if _subtract:
|
||||||
var mirror_ends := Tools.get_mirrored_positions(_rect.end, project, 1)
|
operation = 1
|
||||||
for i in mirror_positions.size():
|
elif _intersect:
|
||||||
var mirror_rect := Rect2i()
|
operation = 2
|
||||||
mirror_rect.position = mirror_positions[i]
|
Global.canvas.selection.select_rect(_rect, operation)
|
||||||
mirror_rect.end = mirror_ends[i]
|
# Handle mirroring
|
||||||
set_ellipse(project.selection_map, mirror_rect.abs().position)
|
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.big_bounding_rectangle = project.selection_map.get_used_rect()
|
Global.canvas.selection.commit_undo("Select", undo_data)
|
||||||
Global.canvas.selection.commit_undo("Select", undo_data)
|
else:
|
||||||
|
set_ellipse(project.selection_map, _rect.position)
|
||||||
|
# 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]
|
||||||
|
set_ellipse(project.selection_map, mirror_rect.abs().position)
|
||||||
|
|
||||||
|
Global.canvas.selection.big_bounding_rectangle = project.selection_map.get_used_rect()
|
||||||
|
Global.canvas.selection.commit_undo("Select", undo_data)
|
||||||
|
|
||||||
|
|
||||||
func set_ellipse(selection_map: SelectionMap, pos: Vector2i) -> void:
|
func set_ellipse(selection_map: SelectionMap, pos: Vector2i) -> void:
|
||||||
|
@ -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()
|
||||||
|
|
||||||
rect.size += Vector2i.ONE
|
if not Tools.is_placing_tiles():
|
||||||
|
rect.size += Vector2i.ONE
|
||||||
|
|
||||||
return rect
|
return rect
|
||||||
|
|
Loading…
Add table
Reference in a new issue