forked from mbrlabs/Lorien
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This commit introduces super eraser tool which removes the entire stroke upon contact with cursor. Undo/Redo works fine. However, I still need to handle stroke size somehow.
- Loading branch information
Showing
11 changed files
with
159 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
[remap] | ||
|
||
importer="texture" | ||
type="StreamTexture" | ||
path="res://.import/super_eraser_tool.png-07ce97550fe2bbcde89ee994efb82315.stex" | ||
metadata={ | ||
"vram_texture": false | ||
} | ||
|
||
[deps] | ||
|
||
source_file="res://Assets/Icons/super_eraser_tool.png" | ||
dest_files=[ "res://.import/super_eraser_tool.png-07ce97550fe2bbcde89ee994efb82315.stex" ] | ||
|
||
[params] | ||
|
||
compress/mode=0 | ||
compress/lossy_quality=0.7 | ||
compress/hdr_mode=0 | ||
compress/bptc_ldr=0 | ||
compress/normal_map=0 | ||
flags/repeat=0 | ||
flags/filter=true | ||
flags/mipmaps=false | ||
flags/anisotropic=false | ||
flags/srgb=2 | ||
process/fix_alpha_border=true | ||
process/premult_alpha=false | ||
process/HDR_as_SRGB=false | ||
process/invert_color=false | ||
process/normal_map_invert_y=false | ||
stream=false | ||
size_limit=0 | ||
detect_3d=true | ||
svg/scale=1.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
class_name SuperEraserTool | ||
extends CanvasTool | ||
|
||
# ------------------------------------------------------------------------------------------------- | ||
export var pressure_curve: Curve | ||
var _last_mouse_motion: InputEventMouseMotion | ||
var _removed_strokes := [] # BrushStroke -> Vector2 | ||
|
||
# ------------------------------------------------------------------------------------------------- | ||
func _input(event: InputEvent) -> void: | ||
if event is InputEventMouseMotion: | ||
_last_mouse_motion = event | ||
_cursor.global_position = xform_vector2(event.global_position) | ||
|
||
if event is InputEventMouseButton: | ||
if event.button_index == BUTTON_LEFT: | ||
if event.pressed && _last_mouse_motion != null: | ||
_last_mouse_motion.global_position = event.global_position | ||
_last_mouse_motion.position = event.position | ||
performing_stroke = true | ||
elif !event.pressed: | ||
performing_stroke = false | ||
|
||
# ------------------------------------------------------------------------------------------------- | ||
func _process(delta: float) -> void: | ||
if performing_stroke && _last_mouse_motion != null: | ||
_remove_stroke(_last_mouse_motion.global_position) | ||
_add_undoredo_action_for_erased_strokes() | ||
_last_mouse_motion = null | ||
|
||
# ------------------------------------------------------------------------------------------------ | ||
func _stroke_intersects_circle(stroke, circle_position: Vector2, circle_radius: float) -> bool: | ||
for i in stroke.points.size() - 1: | ||
var start = _calc_abs_stroke_point(stroke.points[i], stroke) | ||
var end = _calc_abs_stroke_point(stroke.points[i + 1], stroke) | ||
if Geometry.segment_intersects_circle(start, end, circle_position, circle_radius) >= 0: | ||
return true | ||
return false | ||
|
||
# ------------------------------------------------------------------------------------------------- | ||
func _remove_stroke(brush_position: Vector2) -> void: | ||
for stroke in _canvas.get_strokes_in_camera_frustrum(): | ||
# check if brush intersects stroke (and not already being removed) | ||
if !_removed_strokes.has(stroke) && _stroke_intersects_circle(stroke, brush_position, | ||
float(_cursor._brush_size)/2): | ||
# Add stroke to remove to _removed_strokes | ||
_removed_strokes.append(stroke) | ||
|
||
# ------------------------------------------------------------------------------------------------ | ||
func _calc_abs_stroke_point(p: Vector2, stroke: BrushStroke) -> Vector2: | ||
return (p + stroke.position - _canvas.get_camera_offset()) / _canvas.get_camera_zoom() | ||
|
||
# ------------------------------------------------------------------------------------------------ | ||
func _add_undoredo_action_for_erased_strokes() -> void: | ||
var project: Project = ProjectManager.get_active_project() | ||
if _removed_strokes.size(): | ||
project.undo_redo.create_action("Erase Stroke") | ||
for stroke in _removed_strokes: | ||
_removed_strokes.erase(stroke) | ||
project.undo_redo.add_do_method(_canvas, "_do_delete_stroke", stroke) | ||
project.undo_redo.add_undo_method(_canvas, "_undo_delete_stroke", stroke) | ||
project.undo_redo.commit_action() | ||
project.dirty = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ enum Tool { | |
RECTANGLE, | ||
LINE, | ||
ERASER, | ||
SUPERERASER | ||
SELECT, | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters