mirror of
https://github.com/Orama-Interactive/Pixelorama.git
synced 2025-03-13 06:45:17 +00:00
Move selection offset code inside SelectionMap.is_pixel_selected()
This commit is contained in:
parent
9184b25c01
commit
9a1464f73b
4 changed files with 13 additions and 29 deletions
|
@ -526,11 +526,7 @@ func is_empty() -> bool:
|
|||
)
|
||||
|
||||
|
||||
func can_pixel_get_drawn(
|
||||
pixel: Vector2i,
|
||||
image: SelectionMap = selection_map,
|
||||
selection_position: Vector2i = Global.canvas.selection.big_bounding_rectangle.position
|
||||
) -> bool:
|
||||
func can_pixel_get_drawn(pixel: Vector2i, image := selection_map) -> bool:
|
||||
if pixel.x < 0 or pixel.y < 0 or pixel.x >= size.x or pixel.y >= size.y:
|
||||
return false
|
||||
|
||||
|
@ -538,10 +534,6 @@ func can_pixel_get_drawn(
|
|||
return false
|
||||
|
||||
if has_selection:
|
||||
if selection_position.x < 0:
|
||||
pixel.x -= selection_position.x
|
||||
if selection_position.y < 0:
|
||||
pixel.y -= selection_position.y
|
||||
return image.is_pixel_selected(pixel)
|
||||
else:
|
||||
return true
|
||||
|
|
|
@ -4,7 +4,13 @@ extends Image
|
|||
var invert_shader := preload("res://src/Shaders/Effects/Invert.gdshader")
|
||||
|
||||
|
||||
func is_pixel_selected(pixel: Vector2i) -> bool:
|
||||
func is_pixel_selected(pixel: Vector2i, calculate_offset := true) -> bool:
|
||||
var selection_position: Vector2i = Global.canvas.selection.big_bounding_rectangle.position
|
||||
if calculate_offset:
|
||||
if selection_position.x < 0:
|
||||
pixel.x -= selection_position.x
|
||||
if selection_position.y < 0:
|
||||
pixel.y -= selection_position.y
|
||||
if pixel.x < 0 or pixel.y < 0 or pixel.x >= get_width() or pixel.y >= get_height():
|
||||
return false
|
||||
var selected: bool = get_pixelv(pixel).a > 0
|
||||
|
|
|
@ -84,27 +84,13 @@ func draw_start(pos: Vector2i) -> void:
|
|||
_start_pos = pos
|
||||
_offset = pos
|
||||
|
||||
var selection_position: Vector2i = selection_node.big_bounding_rectangle.position
|
||||
var offsetted_pos := pos
|
||||
if selection_position.x < 0:
|
||||
offsetted_pos.x -= selection_position.x
|
||||
if selection_position.y < 0:
|
||||
offsetted_pos.y -= selection_position.y
|
||||
|
||||
var quick_copy := Input.is_action_pressed("transform_copy_selection_content", true)
|
||||
if (
|
||||
offsetted_pos.x >= 0
|
||||
and offsetted_pos.y >= 0
|
||||
and project.selection_map.is_pixel_selected(offsetted_pos)
|
||||
project.selection_map.is_pixel_selected(pos)
|
||||
and (!_add and !_subtract and !_intersect or quick_copy)
|
||||
and !_ongoing_selection
|
||||
):
|
||||
if !(
|
||||
Global
|
||||
. current_project
|
||||
. layers[Global.current_project.current_layer]
|
||||
. can_layer_get_drawn()
|
||||
):
|
||||
if not project.layers[project.current_layer].can_layer_get_drawn():
|
||||
return
|
||||
# Move current selection
|
||||
_move = true
|
||||
|
|
|
@ -430,11 +430,11 @@ func select_rect(rect: Rect2i, operation := SelectionOperation.ADD) -> void:
|
|||
if !Rect2i(Vector2i.ZERO, previous_selection_map.get_size()).has_point(pos):
|
||||
continue
|
||||
project.selection_map.select_pixel(
|
||||
pos, previous_selection_map.is_pixel_selected(pos)
|
||||
pos, previous_selection_map.is_pixel_selected(pos, false)
|
||||
)
|
||||
big_bounding_rectangle = project.selection_map.get_used_rect()
|
||||
|
||||
if offset_position != Vector2i.ZERO:
|
||||
if offset_position != Vector2i.ZERO and big_bounding_rectangle.get_area() != 0:
|
||||
big_bounding_rectangle.position += offset_position
|
||||
project.selection_map.move_bitmap_values(project)
|
||||
|
||||
|
@ -685,7 +685,7 @@ func copy() -> void:
|
|||
offset_pos.x = 0
|
||||
if offset_pos.y < 0:
|
||||
offset_pos.y = 0
|
||||
if not project.selection_map.is_pixel_selected(pos + offset_pos):
|
||||
if not project.selection_map.is_pixel_selected(pos + offset_pos, false):
|
||||
to_copy.set_pixelv(pos, Color(0))
|
||||
cl_selection_map.copy_from(project.selection_map)
|
||||
cl_big_bounding_rectangle = big_bounding_rectangle
|
||||
|
|
Loading…
Add table
Reference in a new issue