2021-05-14 03:48:33 +03:00
|
|
|
extends SelectionTool
|
|
|
|
|
|
|
|
var _rect := Rect2(0, 0, 0, 0)
|
|
|
|
|
2021-11-25 14:48:30 +02:00
|
|
|
var _square := false # Mouse Click + Shift
|
|
|
|
var _expand_from_center := false # Mouse Click + Ctrl
|
|
|
|
var _displace_origin = false # Mouse Click + Alt
|
2021-05-14 03:48:33 +03:00
|
|
|
|
|
|
|
|
2021-11-25 14:48:30 +02:00
|
|
|
func _input(event: InputEvent) -> void:
|
2021-05-14 03:48:33 +03:00
|
|
|
if !_move and !_rect.has_no_area():
|
Implement the Keychain Plugin (#700)
* Start implementing the godot_better_input plugin
* Update ShortcutEdit.gd
* Load & save preset option
* Add some groups and fix action events not being deleted on load
* Add MenuInputAction class for multiple menu accelerators
* Create a proper plugin and a BetterInput autoload
* Update menu accelerators
* Move settings to BetterInput
* Move menu enums to Global, make more MenuInputActions
* Add more menu events
* Add new groups
* Optimize BetterInput _input() method
* Remove a lot of lines of code
* Change some previous events, add ignore actions and a View menu group
* Change update_item_accelerator to update_ui
* Move MenuInputAction initialization to BetterInput.gd
* Update hint tooltips when a shortcut changes
Temporarily comment out some code regarding the configurable modifiers
* Some MenuInputAction variable name changes
* Add handle_input() to InputAction
* Update the shortcuts of buttons
* Fix shortcut selector menu position
* Change plugin name into Keychain
* Fix keyboard input dialog exiting when Enter or Space is being pressed
* Add two more groups
* Make groups folded by default
* Temporarily make tool modifier shortcuts not configurable
A temporary change, they will be made configurable again, with different actions that are currently mapped to the same events, local/independent from each other.
* Add license for Keychain
* Fix issue where a key event would be added in other input types
* Fix bug where the assigned state was not updated when the dialog appeared again
* Update Main.tscn
* Add a disabled line edit in keyboard shortcut selector to grab focus
* Load presets in the Keychain autoload
This way, the input actions get updated from the start, instead of only at the ShortcutEdit scene.
WARNING, this currently causes crashes if the menu items have no shortcut binded to them.
* Move custom settings away from Keychain.gd
To keep it the same as the upstream plugin
* Change menu enum names
* Made action_get_first_key() more general
* Use arrays for menu items instead of dictionaries, fixes crash
* Move moveable panels to Window menu
* Format
* Optimize hint tooltip updating
* Add support for translations in Keychain
* Translation changes
* Made tool modifiers configurable
Needs more testing.
* Made camera arrow key movement configurable & joypad axis support
This commit removes the ability to press Shift and Control+Shift to adjust the camera arrow key movement speed. Instead, the speed depends on the zoom level.
The right joypad analog stick is configured to move the camera by default.
* Rename presets into shortcut profiles, use Resources and let users create their own
* [skip ci] Update addons README
* Update Global.gd
2022-05-16 15:07:51 +03:00
|
|
|
if event.is_action_pressed("shape_perfect"):
|
2021-05-14 03:48:33 +03:00
|
|
|
_square = true
|
Implement the Keychain Plugin (#700)
* Start implementing the godot_better_input plugin
* Update ShortcutEdit.gd
* Load & save preset option
* Add some groups and fix action events not being deleted on load
* Add MenuInputAction class for multiple menu accelerators
* Create a proper plugin and a BetterInput autoload
* Update menu accelerators
* Move settings to BetterInput
* Move menu enums to Global, make more MenuInputActions
* Add more menu events
* Add new groups
* Optimize BetterInput _input() method
* Remove a lot of lines of code
* Change some previous events, add ignore actions and a View menu group
* Change update_item_accelerator to update_ui
* Move MenuInputAction initialization to BetterInput.gd
* Update hint tooltips when a shortcut changes
Temporarily comment out some code regarding the configurable modifiers
* Some MenuInputAction variable name changes
* Add handle_input() to InputAction
* Update the shortcuts of buttons
* Fix shortcut selector menu position
* Change plugin name into Keychain
* Fix keyboard input dialog exiting when Enter or Space is being pressed
* Add two more groups
* Make groups folded by default
* Temporarily make tool modifier shortcuts not configurable
A temporary change, they will be made configurable again, with different actions that are currently mapped to the same events, local/independent from each other.
* Add license for Keychain
* Fix issue where a key event would be added in other input types
* Fix bug where the assigned state was not updated when the dialog appeared again
* Update Main.tscn
* Add a disabled line edit in keyboard shortcut selector to grab focus
* Load presets in the Keychain autoload
This way, the input actions get updated from the start, instead of only at the ShortcutEdit scene.
WARNING, this currently causes crashes if the menu items have no shortcut binded to them.
* Move custom settings away from Keychain.gd
To keep it the same as the upstream plugin
* Change menu enum names
* Made action_get_first_key() more general
* Use arrays for menu items instead of dictionaries, fixes crash
* Move moveable panels to Window menu
* Format
* Optimize hint tooltip updating
* Add support for translations in Keychain
* Translation changes
* Made tool modifiers configurable
Needs more testing.
* Made camera arrow key movement configurable & joypad axis support
This commit removes the ability to press Shift and Control+Shift to adjust the camera arrow key movement speed. Instead, the speed depends on the zoom level.
The right joypad analog stick is configured to move the camera by default.
* Rename presets into shortcut profiles, use Resources and let users create their own
* [skip ci] Update addons README
* Update Global.gd
2022-05-16 15:07:51 +03:00
|
|
|
elif event.is_action_released("shape_perfect"):
|
2021-05-14 03:48:33 +03:00
|
|
|
_square = false
|
Implement the Keychain Plugin (#700)
* Start implementing the godot_better_input plugin
* Update ShortcutEdit.gd
* Load & save preset option
* Add some groups and fix action events not being deleted on load
* Add MenuInputAction class for multiple menu accelerators
* Create a proper plugin and a BetterInput autoload
* Update menu accelerators
* Move settings to BetterInput
* Move menu enums to Global, make more MenuInputActions
* Add more menu events
* Add new groups
* Optimize BetterInput _input() method
* Remove a lot of lines of code
* Change some previous events, add ignore actions and a View menu group
* Change update_item_accelerator to update_ui
* Move MenuInputAction initialization to BetterInput.gd
* Update hint tooltips when a shortcut changes
Temporarily comment out some code regarding the configurable modifiers
* Some MenuInputAction variable name changes
* Add handle_input() to InputAction
* Update the shortcuts of buttons
* Fix shortcut selector menu position
* Change plugin name into Keychain
* Fix keyboard input dialog exiting when Enter or Space is being pressed
* Add two more groups
* Make groups folded by default
* Temporarily make tool modifier shortcuts not configurable
A temporary change, they will be made configurable again, with different actions that are currently mapped to the same events, local/independent from each other.
* Add license for Keychain
* Fix issue where a key event would be added in other input types
* Fix bug where the assigned state was not updated when the dialog appeared again
* Update Main.tscn
* Add a disabled line edit in keyboard shortcut selector to grab focus
* Load presets in the Keychain autoload
This way, the input actions get updated from the start, instead of only at the ShortcutEdit scene.
WARNING, this currently causes crashes if the menu items have no shortcut binded to them.
* Move custom settings away from Keychain.gd
To keep it the same as the upstream plugin
* Change menu enum names
* Made action_get_first_key() more general
* Use arrays for menu items instead of dictionaries, fixes crash
* Move moveable panels to Window menu
* Format
* Optimize hint tooltip updating
* Add support for translations in Keychain
* Translation changes
* Made tool modifiers configurable
Needs more testing.
* Made camera arrow key movement configurable & joypad axis support
This commit removes the ability to press Shift and Control+Shift to adjust the camera arrow key movement speed. Instead, the speed depends on the zoom level.
The right joypad analog stick is configured to move the camera by default.
* Rename presets into shortcut profiles, use Resources and let users create their own
* [skip ci] Update addons README
* Update Global.gd
2022-05-16 15:07:51 +03:00
|
|
|
if event.is_action_pressed("shape_center"):
|
2021-05-14 03:48:33 +03:00
|
|
|
_expand_from_center = true
|
Implement the Keychain Plugin (#700)
* Start implementing the godot_better_input plugin
* Update ShortcutEdit.gd
* Load & save preset option
* Add some groups and fix action events not being deleted on load
* Add MenuInputAction class for multiple menu accelerators
* Create a proper plugin and a BetterInput autoload
* Update menu accelerators
* Move settings to BetterInput
* Move menu enums to Global, make more MenuInputActions
* Add more menu events
* Add new groups
* Optimize BetterInput _input() method
* Remove a lot of lines of code
* Change some previous events, add ignore actions and a View menu group
* Change update_item_accelerator to update_ui
* Move MenuInputAction initialization to BetterInput.gd
* Update hint tooltips when a shortcut changes
Temporarily comment out some code regarding the configurable modifiers
* Some MenuInputAction variable name changes
* Add handle_input() to InputAction
* Update the shortcuts of buttons
* Fix shortcut selector menu position
* Change plugin name into Keychain
* Fix keyboard input dialog exiting when Enter or Space is being pressed
* Add two more groups
* Make groups folded by default
* Temporarily make tool modifier shortcuts not configurable
A temporary change, they will be made configurable again, with different actions that are currently mapped to the same events, local/independent from each other.
* Add license for Keychain
* Fix issue where a key event would be added in other input types
* Fix bug where the assigned state was not updated when the dialog appeared again
* Update Main.tscn
* Add a disabled line edit in keyboard shortcut selector to grab focus
* Load presets in the Keychain autoload
This way, the input actions get updated from the start, instead of only at the ShortcutEdit scene.
WARNING, this currently causes crashes if the menu items have no shortcut binded to them.
* Move custom settings away from Keychain.gd
To keep it the same as the upstream plugin
* Change menu enum names
* Made action_get_first_key() more general
* Use arrays for menu items instead of dictionaries, fixes crash
* Move moveable panels to Window menu
* Format
* Optimize hint tooltip updating
* Add support for translations in Keychain
* Translation changes
* Made tool modifiers configurable
Needs more testing.
* Made camera arrow key movement configurable & joypad axis support
This commit removes the ability to press Shift and Control+Shift to adjust the camera arrow key movement speed. Instead, the speed depends on the zoom level.
The right joypad analog stick is configured to move the camera by default.
* Rename presets into shortcut profiles, use Resources and let users create their own
* [skip ci] Update addons README
* Update Global.gd
2022-05-16 15:07:51 +03:00
|
|
|
elif event.is_action_released("shape_center"):
|
2021-05-14 03:48:33 +03:00
|
|
|
_expand_from_center = false
|
Implement the Keychain Plugin (#700)
* Start implementing the godot_better_input plugin
* Update ShortcutEdit.gd
* Load & save preset option
* Add some groups and fix action events not being deleted on load
* Add MenuInputAction class for multiple menu accelerators
* Create a proper plugin and a BetterInput autoload
* Update menu accelerators
* Move settings to BetterInput
* Move menu enums to Global, make more MenuInputActions
* Add more menu events
* Add new groups
* Optimize BetterInput _input() method
* Remove a lot of lines of code
* Change some previous events, add ignore actions and a View menu group
* Change update_item_accelerator to update_ui
* Move MenuInputAction initialization to BetterInput.gd
* Update hint tooltips when a shortcut changes
Temporarily comment out some code regarding the configurable modifiers
* Some MenuInputAction variable name changes
* Add handle_input() to InputAction
* Update the shortcuts of buttons
* Fix shortcut selector menu position
* Change plugin name into Keychain
* Fix keyboard input dialog exiting when Enter or Space is being pressed
* Add two more groups
* Make groups folded by default
* Temporarily make tool modifier shortcuts not configurable
A temporary change, they will be made configurable again, with different actions that are currently mapped to the same events, local/independent from each other.
* Add license for Keychain
* Fix issue where a key event would be added in other input types
* Fix bug where the assigned state was not updated when the dialog appeared again
* Update Main.tscn
* Add a disabled line edit in keyboard shortcut selector to grab focus
* Load presets in the Keychain autoload
This way, the input actions get updated from the start, instead of only at the ShortcutEdit scene.
WARNING, this currently causes crashes if the menu items have no shortcut binded to them.
* Move custom settings away from Keychain.gd
To keep it the same as the upstream plugin
* Change menu enum names
* Made action_get_first_key() more general
* Use arrays for menu items instead of dictionaries, fixes crash
* Move moveable panels to Window menu
* Format
* Optimize hint tooltip updating
* Add support for translations in Keychain
* Translation changes
* Made tool modifiers configurable
Needs more testing.
* Made camera arrow key movement configurable & joypad axis support
This commit removes the ability to press Shift and Control+Shift to adjust the camera arrow key movement speed. Instead, the speed depends on the zoom level.
The right joypad analog stick is configured to move the camera by default.
* Rename presets into shortcut profiles, use Resources and let users create their own
* [skip ci] Update addons README
* Update Global.gd
2022-05-16 15:07:51 +03:00
|
|
|
if event.is_action_pressed("shape_displace"):
|
2021-05-14 03:48:33 +03:00
|
|
|
_displace_origin = true
|
Implement the Keychain Plugin (#700)
* Start implementing the godot_better_input plugin
* Update ShortcutEdit.gd
* Load & save preset option
* Add some groups and fix action events not being deleted on load
* Add MenuInputAction class for multiple menu accelerators
* Create a proper plugin and a BetterInput autoload
* Update menu accelerators
* Move settings to BetterInput
* Move menu enums to Global, make more MenuInputActions
* Add more menu events
* Add new groups
* Optimize BetterInput _input() method
* Remove a lot of lines of code
* Change some previous events, add ignore actions and a View menu group
* Change update_item_accelerator to update_ui
* Move MenuInputAction initialization to BetterInput.gd
* Update hint tooltips when a shortcut changes
Temporarily comment out some code regarding the configurable modifiers
* Some MenuInputAction variable name changes
* Add handle_input() to InputAction
* Update the shortcuts of buttons
* Fix shortcut selector menu position
* Change plugin name into Keychain
* Fix keyboard input dialog exiting when Enter or Space is being pressed
* Add two more groups
* Make groups folded by default
* Temporarily make tool modifier shortcuts not configurable
A temporary change, they will be made configurable again, with different actions that are currently mapped to the same events, local/independent from each other.
* Add license for Keychain
* Fix issue where a key event would be added in other input types
* Fix bug where the assigned state was not updated when the dialog appeared again
* Update Main.tscn
* Add a disabled line edit in keyboard shortcut selector to grab focus
* Load presets in the Keychain autoload
This way, the input actions get updated from the start, instead of only at the ShortcutEdit scene.
WARNING, this currently causes crashes if the menu items have no shortcut binded to them.
* Move custom settings away from Keychain.gd
To keep it the same as the upstream plugin
* Change menu enum names
* Made action_get_first_key() more general
* Use arrays for menu items instead of dictionaries, fixes crash
* Move moveable panels to Window menu
* Format
* Optimize hint tooltip updating
* Add support for translations in Keychain
* Translation changes
* Made tool modifiers configurable
Needs more testing.
* Made camera arrow key movement configurable & joypad axis support
This commit removes the ability to press Shift and Control+Shift to adjust the camera arrow key movement speed. Instead, the speed depends on the zoom level.
The right joypad analog stick is configured to move the camera by default.
* Rename presets into shortcut profiles, use Resources and let users create their own
* [skip ci] Update addons README
* Update Global.gd
2022-05-16 15:07:51 +03:00
|
|
|
elif event.is_action_released("shape_displace"):
|
2021-05-14 03:48:33 +03:00
|
|
|
_displace_origin = false
|
|
|
|
|
|
|
|
|
2021-11-25 14:48:30 +02:00
|
|
|
func draw_move(position: Vector2) -> void:
|
2021-05-14 03:48:33 +03:00
|
|
|
if selection_node.arrow_key_move:
|
|
|
|
return
|
|
|
|
.draw_move(position)
|
|
|
|
if !_move:
|
|
|
|
if _displace_origin:
|
|
|
|
_start_pos += position - _offset
|
|
|
|
_rect = _get_result_rect(_start_pos, position)
|
|
|
|
_set_cursor_text(_rect)
|
|
|
|
_offset = position
|
|
|
|
|
|
|
|
|
2021-11-25 14:48:30 +02:00
|
|
|
func draw_end(position: Vector2) -> void:
|
2021-05-14 03:48:33 +03:00
|
|
|
if selection_node.arrow_key_move:
|
|
|
|
return
|
|
|
|
.draw_end(position)
|
|
|
|
_rect = Rect2(0, 0, 0, 0)
|
|
|
|
_square = false
|
|
|
|
_expand_from_center = false
|
|
|
|
_displace_origin = false
|
|
|
|
|
|
|
|
|
|
|
|
func draw_preview() -> void:
|
|
|
|
if !_move && !_rect.has_no_area():
|
2021-11-25 14:48:30 +02:00
|
|
|
var canvas: Node2D = Global.canvas.previews
|
|
|
|
var position := canvas.position
|
|
|
|
var scale := canvas.scale
|
2021-05-14 03:48:33 +03:00
|
|
|
if Global.mirror_view:
|
2021-11-25 14:48:30 +02:00
|
|
|
position.x = position.x + Global.current_project.size.x
|
|
|
|
scale.x = -1
|
2021-05-14 03:48:33 +03:00
|
|
|
|
|
|
|
var border := _get_shape_points_filled(_rect.size)
|
|
|
|
var indicator := _fill_bitmap_with_points(border, _rect.size)
|
|
|
|
|
2021-11-25 14:48:30 +02:00
|
|
|
canvas.draw_set_transform(_rect.position, canvas.rotation, scale)
|
2021-05-14 03:48:33 +03:00
|
|
|
for line in _create_polylines(indicator):
|
|
|
|
canvas.draw_polyline(PoolVector2Array(line), Color.black)
|
|
|
|
|
|
|
|
canvas.draw_set_transform(canvas.position, canvas.rotation, canvas.scale)
|
|
|
|
|
|
|
|
|
2021-11-25 14:48:30 +02:00
|
|
|
func apply_selection(_position: Vector2) -> void:
|
|
|
|
var project: Project = Global.current_project
|
2021-05-14 03:48:33 +03:00
|
|
|
if !_add and !_subtract and !_intersect:
|
|
|
|
Global.canvas.selection.clear_selection()
|
|
|
|
if _rect.size == Vector2.ZERO and Global.current_project.has_selection:
|
2021-12-02 13:25:20 +02:00
|
|
|
Global.canvas.selection.commit_undo("Select", undo_data)
|
2021-05-14 03:48:33 +03:00
|
|
|
|
|
|
|
if _rect.size != Vector2.ZERO:
|
2021-11-25 14:48:30 +02:00
|
|
|
var selection_bitmap_copy: BitMap = project.selection_bitmap.duplicate()
|
2021-05-14 03:48:33 +03:00
|
|
|
set_ellipse(selection_bitmap_copy, _rect.position)
|
2021-05-16 03:19:49 +03:00
|
|
|
|
2021-05-14 03:48:33 +03:00
|
|
|
# Handle mirroring
|
2022-02-17 16:07:03 +02:00
|
|
|
if Tools.horizontal_mirror:
|
2021-05-14 03:48:33 +03:00
|
|
|
var mirror_x_rect := _rect
|
2021-11-25 14:48:30 +02:00
|
|
|
mirror_x_rect.position.x = (
|
|
|
|
Global.current_project.x_symmetry_point
|
|
|
|
- _rect.position.x
|
|
|
|
+ 1
|
|
|
|
)
|
2021-05-16 03:19:49 +03:00
|
|
|
mirror_x_rect.end.x = Global.current_project.x_symmetry_point - _rect.end.x + 1
|
2021-05-14 03:48:33 +03:00
|
|
|
set_ellipse(selection_bitmap_copy, mirror_x_rect.abs().position)
|
2022-02-17 16:07:03 +02:00
|
|
|
if Tools.vertical_mirror:
|
2021-05-14 03:48:33 +03:00
|
|
|
var mirror_xy_rect := mirror_x_rect
|
2021-11-25 14:48:30 +02:00
|
|
|
mirror_xy_rect.position.y = (
|
|
|
|
Global.current_project.y_symmetry_point
|
|
|
|
- _rect.position.y
|
|
|
|
+ 1
|
|
|
|
)
|
2021-05-16 03:19:49 +03:00
|
|
|
mirror_xy_rect.end.y = Global.current_project.y_symmetry_point - _rect.end.y + 1
|
2021-05-14 03:48:33 +03:00
|
|
|
set_ellipse(selection_bitmap_copy, mirror_xy_rect.abs().position)
|
2022-02-17 16:07:03 +02:00
|
|
|
if Tools.vertical_mirror:
|
2021-05-14 03:48:33 +03:00
|
|
|
var mirror_y_rect := _rect
|
2021-11-25 14:48:30 +02:00
|
|
|
mirror_y_rect.position.y = (
|
|
|
|
Global.current_project.y_symmetry_point
|
|
|
|
- _rect.position.y
|
|
|
|
+ 1
|
|
|
|
)
|
2021-05-16 03:19:49 +03:00
|
|
|
mirror_y_rect.end.y = Global.current_project.y_symmetry_point - _rect.end.y + 1
|
2021-05-14 03:48:33 +03:00
|
|
|
set_ellipse(selection_bitmap_copy, mirror_y_rect.abs().position)
|
|
|
|
|
|
|
|
project.selection_bitmap = selection_bitmap_copy
|
2021-11-25 14:48:30 +02:00
|
|
|
Global.canvas.selection.big_bounding_rectangle = project.get_selection_rectangle(
|
|
|
|
project.selection_bitmap
|
|
|
|
)
|
2021-12-02 13:25:20 +02:00
|
|
|
Global.canvas.selection.commit_undo("Select", undo_data)
|
2021-05-14 03:48:33 +03:00
|
|
|
|
|
|
|
|
2021-11-25 14:48:30 +02:00
|
|
|
func set_ellipse(bitmap: BitMap, position: Vector2) -> void:
|
|
|
|
var project: Project = Global.current_project
|
|
|
|
var bitmap_size: Vector2 = bitmap.get_size()
|
2021-05-14 03:48:33 +03:00
|
|
|
if _intersect:
|
|
|
|
bitmap.set_bit_rect(Rect2(Vector2.ZERO, bitmap_size), false)
|
|
|
|
var points := _get_shape_points_filled(_rect.size)
|
|
|
|
for p in points:
|
2021-11-25 14:48:30 +02:00
|
|
|
var pos: Vector2 = position + p
|
2021-05-14 03:48:33 +03:00
|
|
|
if pos.x < 0 or pos.y < 0 or pos.x >= bitmap_size.x or pos.y >= bitmap_size.y:
|
|
|
|
continue
|
|
|
|
if _intersect:
|
|
|
|
if project.selection_bitmap.get_bit(pos):
|
|
|
|
bitmap.set_bit(pos, true)
|
|
|
|
else:
|
|
|
|
bitmap.set_bit(pos, !_subtract)
|
|
|
|
|
|
|
|
|
2021-11-25 14:48:30 +02:00
|
|
|
# Given an origin point and destination point, returns a rect representing
|
|
|
|
# where the shape will be drawn and what is its size
|
2021-05-14 03:48:33 +03:00
|
|
|
func _get_result_rect(origin: Vector2, dest: Vector2) -> Rect2:
|
|
|
|
var rect := Rect2(Vector2.ZERO, Vector2.ZERO)
|
|
|
|
|
|
|
|
# Center the rect on the mouse
|
|
|
|
if _expand_from_center:
|
|
|
|
var new_size := (dest - origin).floor()
|
|
|
|
# Make rect 1:1 while centering it on the mouse
|
|
|
|
if _square:
|
2021-11-25 14:48:30 +02:00
|
|
|
var square_size := max(abs(new_size.x), abs(new_size.y))
|
|
|
|
new_size = Vector2(square_size, square_size)
|
2021-05-14 03:48:33 +03:00
|
|
|
|
|
|
|
origin -= new_size
|
|
|
|
dest = origin + 2 * new_size
|
|
|
|
|
|
|
|
# Make rect 1:1 while not trying to center it
|
|
|
|
if _square:
|
|
|
|
var square_size := min(abs(origin.x - dest.x), abs(origin.y - dest.y))
|
|
|
|
rect.position.x = origin.x if origin.x < dest.x else origin.x - square_size
|
|
|
|
rect.position.y = origin.y if origin.y < dest.y else origin.y - square_size
|
|
|
|
rect.size = Vector2(square_size, square_size)
|
|
|
|
# Get the rect without any modifications
|
|
|
|
else:
|
|
|
|
rect.position = Vector2(min(origin.x, dest.x), min(origin.y, dest.y))
|
|
|
|
rect.size = (origin - dest).abs()
|
|
|
|
|
|
|
|
rect.size += Vector2.ONE
|
|
|
|
|
|
|
|
return rect
|
|
|
|
|
|
|
|
|
|
|
|
func _get_shape_points_filled(size: Vector2) -> PoolVector2Array:
|
|
|
|
var border := _get_ellipse_points(Vector2.ZERO, size)
|
|
|
|
var filling := []
|
|
|
|
var bitmap := _fill_bitmap_with_points(border, size)
|
|
|
|
|
|
|
|
for x in range(1, ceil(size.x / 2)):
|
|
|
|
var fill := false
|
|
|
|
var prev_is_true := false
|
|
|
|
for y in range(0, ceil(size.y / 2)):
|
|
|
|
var top_l_p := Vector2(x, y)
|
|
|
|
var bit := bitmap.get_bit(top_l_p)
|
|
|
|
|
|
|
|
if bit and not fill:
|
|
|
|
prev_is_true = true
|
|
|
|
continue
|
|
|
|
|
|
|
|
if not bit and (fill or prev_is_true):
|
|
|
|
filling.append(top_l_p)
|
|
|
|
filling.append(Vector2(x, size.y - y - 1))
|
|
|
|
filling.append(Vector2(size.x - x - 1, y))
|
|
|
|
filling.append(Vector2(size.x - x - 1, size.y - y - 1))
|
|
|
|
|
|
|
|
if prev_is_true:
|
|
|
|
fill = true
|
|
|
|
prev_is_true = false
|
|
|
|
elif bit and fill:
|
|
|
|
break
|
|
|
|
|
|
|
|
return PoolVector2Array(border + filling)
|
|
|
|
|
|
|
|
|
|
|
|
# Algorithm based on http://members.chello.at/easyfilter/bresenham.html
|
2021-11-25 14:48:30 +02:00
|
|
|
func _get_ellipse_points(pos: Vector2, size: Vector2) -> Array:
|
2021-05-14 03:48:33 +03:00
|
|
|
var array := []
|
|
|
|
var x0 := int(pos.x)
|
|
|
|
var x1 := pos.x + int(size.x - 1)
|
|
|
|
var y0 := int(pos.y)
|
|
|
|
var y1 := int(pos.y) + int(size.y - 1)
|
|
|
|
var a := int(abs(x1 - x0))
|
|
|
|
var b := int(abs(y1 - x0))
|
|
|
|
var b1 := b & 1
|
2021-11-25 14:48:30 +02:00
|
|
|
var dx := 4 * (1 - a) * b * b
|
|
|
|
var dy := 4 * (b1 + 1) * a * a
|
|
|
|
var err := dx + dy + b1 * a * a
|
2021-05-14 03:48:33 +03:00
|
|
|
var e2 := 0
|
|
|
|
|
|
|
|
if x0 > x1:
|
|
|
|
x0 = x1
|
|
|
|
x1 += a
|
|
|
|
|
|
|
|
if y0 > y1:
|
|
|
|
y0 = y1
|
|
|
|
|
|
|
|
# warning-ignore:integer_division
|
2021-11-25 14:48:30 +02:00
|
|
|
y0 += (b + 1) / 2
|
|
|
|
y1 = y0 - b1
|
|
|
|
a *= 8 * a
|
|
|
|
b1 = 8 * b * b
|
2021-05-14 03:48:33 +03:00
|
|
|
|
|
|
|
while x0 <= x1:
|
|
|
|
var v1 := Vector2(x1, y0)
|
|
|
|
var v2 := Vector2(x0, y0)
|
|
|
|
var v3 := Vector2(x0, y1)
|
|
|
|
var v4 := Vector2(x1, y1)
|
|
|
|
array.append(v1)
|
|
|
|
array.append(v2)
|
|
|
|
array.append(v3)
|
|
|
|
array.append(v4)
|
|
|
|
|
2021-11-25 14:48:30 +02:00
|
|
|
e2 = 2 * err
|
2021-05-14 03:48:33 +03:00
|
|
|
|
|
|
|
if e2 <= dy:
|
|
|
|
y0 += 1
|
|
|
|
y1 -= 1
|
|
|
|
dy += a
|
|
|
|
err += dy
|
|
|
|
|
2021-11-25 14:48:30 +02:00
|
|
|
if e2 >= dx || 2 * err > dy:
|
|
|
|
x0 += 1
|
|
|
|
x1 -= 1
|
2021-05-14 03:48:33 +03:00
|
|
|
dx += b1
|
|
|
|
err += dx
|
|
|
|
|
2021-11-25 14:48:30 +02:00
|
|
|
while y0 - y1 < b:
|
|
|
|
var v1 := Vector2(x0 - 1, y0)
|
|
|
|
var v2 := Vector2(x1 + 1, y0)
|
|
|
|
var v3 := Vector2(x0 - 1, y1)
|
|
|
|
var v4 := Vector2(x1 + 1, y1)
|
2021-05-14 03:48:33 +03:00
|
|
|
array.append(v1)
|
|
|
|
array.append(v2)
|
|
|
|
array.append(v3)
|
|
|
|
array.append(v4)
|
2021-11-25 14:48:30 +02:00
|
|
|
y0 += 1
|
|
|
|
y1 -= 1
|
2021-05-14 03:48:33 +03:00
|
|
|
|
|
|
|
return array
|
|
|
|
|
|
|
|
|
|
|
|
func _fill_bitmap_with_points(points: Array, size: Vector2) -> BitMap:
|
|
|
|
var bitmap := BitMap.new()
|
|
|
|
bitmap.create(size)
|
|
|
|
|
|
|
|
for point in points:
|
|
|
|
bitmap.set_bit(point, 1)
|
|
|
|
|
|
|
|
return bitmap
|