1
0
Fork 0
mirror of https://github.com/Orama-Interactive/Pixelorama.git synced 2025-03-13 14:55:18 +00:00

Move selection offset code inside SelectionMap.is_pixel_selected()

This commit is contained in:
Emmanouil Papadeas 2024-04-13 17:57:51 +03:00
parent 9184b25c01
commit 9a1464f73b
4 changed files with 13 additions and 29 deletions

View file

@ -526,11 +526,7 @@ func is_empty() -> bool:
) )
func can_pixel_get_drawn( func can_pixel_get_drawn(pixel: Vector2i, image := selection_map) -> bool:
pixel: Vector2i,
image: SelectionMap = selection_map,
selection_position: Vector2i = Global.canvas.selection.big_bounding_rectangle.position
) -> bool:
if pixel.x < 0 or pixel.y < 0 or pixel.x >= size.x or pixel.y >= size.y: if pixel.x < 0 or pixel.y < 0 or pixel.x >= size.x or pixel.y >= size.y:
return false return false
@ -538,10 +534,6 @@ func can_pixel_get_drawn(
return false return false
if has_selection: 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) return image.is_pixel_selected(pixel)
else: else:
return true return true

View file

@ -4,7 +4,13 @@ extends Image
var invert_shader := preload("res://src/Shaders/Effects/Invert.gdshader") 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(): if pixel.x < 0 or pixel.y < 0 or pixel.x >= get_width() or pixel.y >= get_height():
return false return false
var selected: bool = get_pixelv(pixel).a > 0 var selected: bool = get_pixelv(pixel).a > 0

View file

@ -84,27 +84,13 @@ func draw_start(pos: Vector2i) -> void:
_start_pos = pos _start_pos = pos
_offset = 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) var quick_copy := Input.is_action_pressed("transform_copy_selection_content", true)
if ( if (
offsetted_pos.x >= 0 project.selection_map.is_pixel_selected(pos)
and offsetted_pos.y >= 0
and project.selection_map.is_pixel_selected(offsetted_pos)
and (!_add and !_subtract and !_intersect or quick_copy) and (!_add and !_subtract and !_intersect or quick_copy)
and !_ongoing_selection and !_ongoing_selection
): ):
if !( if not project.layers[project.current_layer].can_layer_get_drawn():
Global
. current_project
. layers[Global.current_project.current_layer]
. can_layer_get_drawn()
):
return return
# Move current selection # Move current selection
_move = true _move = true

View file

@ -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): if !Rect2i(Vector2i.ZERO, previous_selection_map.get_size()).has_point(pos):
continue continue
project.selection_map.select_pixel( 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() 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 big_bounding_rectangle.position += offset_position
project.selection_map.move_bitmap_values(project) project.selection_map.move_bitmap_values(project)
@ -685,7 +685,7 @@ func copy() -> void:
offset_pos.x = 0 offset_pos.x = 0
if offset_pos.y < 0: if offset_pos.y < 0:
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)) to_copy.set_pixelv(pos, Color(0))
cl_selection_map.copy_from(project.selection_map) cl_selection_map.copy_from(project.selection_map)
cl_big_bounding_rectangle = big_bounding_rectangle cl_big_bounding_rectangle = big_bounding_rectangle