1
0
Fork 0
mirror of https://github.com/Orama-Interactive/Pixelorama.git synced 2025-01-31 07:29:49 +00:00

Add selection intersection with Ctrl + Shift + Mouse click

This commit is contained in:
Manolis Papadeas 2021-04-22 18:12:45 +03:00
parent ecdf689afd
commit 4412671a08
4 changed files with 56 additions and 12 deletions

View file

@ -1,12 +1,18 @@
extends BaseTool
var _add := false # Shift + Mouse Click
var _subtract := false # Ctrl + Mouse Click
var _intersect := false # Shift + Ctrl + Mouse Click
var undo_data : Dictionary
func draw_start(_position : Vector2) -> void:
Global.canvas.selection.move_content_confirm()
undo_data = Global.canvas.selection._get_undo_data(false)
_intersect = Tools.shift && Tools.control
_add = Tools.shift && !_intersect
_subtract = Tools.control && !_intersect
func draw_move(_position : Vector2) -> void:
@ -20,11 +26,14 @@ func draw_end(position : Vector2) -> void:
if position.x > project.size.x - 1 or position.y > project.size.y - 1:
return
var subtract_from_selection : bool = Tools.control
if !Tools.shift and !subtract_from_selection:
if !_add and !_subtract and !_intersect:
Global.canvas.selection.clear_selection()
var selection_bitmap_copy : BitMap = project.selection_bitmap.duplicate()
if _intersect:
var full_rect = Rect2(Vector2.ZERO, selection_bitmap_copy.get_size())
selection_bitmap_copy.set_bit_rect(full_rect, false)
var cel_image := Image.new()
cel_image.copy_from(project.frames[project.current_frame].cels[project.current_layer].image)
cel_image.lock()
@ -33,7 +42,10 @@ func draw_end(position : Vector2) -> void:
for y in cel_image.get_width():
var pos := Vector2(x, y)
if color.is_equal_approx(cel_image.get_pixelv(pos)):
selection_bitmap_copy.set_bit(pos, !subtract_from_selection)
if _intersect:
selection_bitmap_copy.set_bit(pos, project.selection_bitmap.get_bit(pos))
else:
selection_bitmap_copy.set_bit(pos, !_subtract)
cel_image.unlock()
project.selection_bitmap = selection_bitmap_copy

View file

@ -1,12 +1,18 @@
extends BaseTool
var _add := false # Shift + Mouse Click
var _subtract := false # Ctrl + Mouse Click
var _intersect := false # Shift + Ctrl + Mouse Click
var undo_data : Dictionary
func draw_start(_position : Vector2) -> void:
Global.canvas.selection.move_content_confirm()
undo_data = Global.canvas.selection._get_undo_data(false)
_intersect = Tools.shift && Tools.control
_add = Tools.shift && !_intersect
_subtract = Tools.control && !_intersect
func draw_move(_position : Vector2) -> void:
@ -20,11 +26,14 @@ func draw_end(position : Vector2) -> void:
if position.x > project.size.x - 1 or position.y > project.size.y - 1:
return
var subtract_from_selection : bool = Tools.control
if !Tools.shift and !subtract_from_selection:
if !_add and !_subtract and !_intersect:
Global.canvas.selection.clear_selection()
var selection_bitmap_copy : BitMap = project.selection_bitmap.duplicate()
if _intersect:
var full_rect = Rect2(Vector2.ZERO, selection_bitmap_copy.get_size())
selection_bitmap_copy.set_bit_rect(full_rect, false)
var cel_image := Image.new()
cel_image.copy_from(project.frames[project.current_frame].cels[project.current_layer].image)
cel_image.lock()
@ -45,7 +54,10 @@ func draw_end(position : Vector2) -> void:
east += Vector2.RIGHT
for px in range(west.x + 1, east.x):
var p := Vector2(px, n.y)
selection_bitmap_copy.set_bit(p, !subtract_from_selection)
if _intersect:
selection_bitmap_copy.set_bit(p, project.selection_bitmap.get_bit(p))
else:
selection_bitmap_copy.set_bit(p, !_subtract)
processed.set_bit(p, true)
var north := p + Vector2.UP
var south := p + Vector2.DOWN

View file

@ -8,6 +8,7 @@ var _move := false
var _add := false # Shift + Mouse Click
var _subtract := false # Ctrl + Mouse Click
var _intersect := false # Shift + Ctrl + Mouse Click
var _square := false # Mouse Click + Shift
var _expand_from_center := false # Mouse Click + Ctrl
@ -44,8 +45,9 @@ func draw_start(position : Vector2) -> void:
else:
_start_pos = position
_add = Tools.shift
_subtract = Tools.control
_intersect = Tools.shift && Tools.control
_add = Tools.shift && !_intersect
_subtract = Tools.control && !_intersect
func draw_move(position : Vector2) -> void:
@ -64,12 +66,17 @@ func draw_end(_position : Vector2) -> void:
if _move:
Global.canvas.selection.move_borders_end()
else:
if !_add and !_subtract:
if !_add and !_subtract and !_intersect:
Global.canvas.selection.clear_selection()
if _rect.size == Vector2.ZERO and Global.current_project.has_selection:
Global.canvas.selection.commit_undo("Rectangle Select", undo_data)
if _rect.size != Vector2.ZERO:
Global.canvas.selection.select_rect(_rect, !_subtract)
var operation := 0
if _subtract:
operation = 1
elif _intersect:
operation = 2
Global.canvas.selection.select_rect(_rect, operation)
Global.canvas.selection.commit_undo("Rectangle Select", undo_data)
_move = false

View file

@ -35,6 +35,9 @@ class Gizmo:
return cursor
enum SelectionOperation {ADD, SUBTRACT, INTERSECT}
var clipboard := Clipboard.new()
var is_moving_content := false
var is_pasting := false
@ -244,7 +247,7 @@ func gizmo_rotate() -> void: # Does not work properly yet
update()
func select_rect(rect : Rect2, select := true) -> void:
func select_rect(rect : Rect2, operation : int = SelectionOperation.ADD) -> void:
var project : Project = Global.current_project
var selection_bitmap_copy : BitMap = project.selection_bitmap.duplicate()
var offset_position := Vector2.ZERO # Used only if the selection is outside of the canvas boundaries, on the left and/or above (negative coords)
@ -259,7 +262,17 @@ func select_rect(rect : Rect2, select := true) -> void:
big_bounding_rectangle.position -= offset_position
project.move_bitmap_values(selection_bitmap_copy)
selection_bitmap_copy.set_bit_rect(rect, select)
if operation == SelectionOperation.ADD:
selection_bitmap_copy.set_bit_rect(rect, true)
elif operation == SelectionOperation.SUBTRACT:
selection_bitmap_copy.set_bit_rect(rect, false)
elif operation == SelectionOperation.INTERSECT:
var full_rect = Rect2(Vector2.ZERO, selection_bitmap_copy.get_size())
selection_bitmap_copy.set_bit_rect(full_rect, false)
for x in range(rect.position.x, rect.end.x):
for y in range(rect.position.y, rect.end.y):
var pos := Vector2(x, y)
selection_bitmap_copy.set_bit(pos, project.selection_bitmap.get_bit(pos))
big_bounding_rectangle = project.get_selection_rectangle(selection_bitmap_copy)
if offset_position != Vector2.ZERO: