Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

highlighter tool #244

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@
# Mono-specific ignores
.mono/
data_*/

.DS_Store
Binary file added lorien/Assets/Icons/mark-pen-fill.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
35 changes: 35 additions & 0 deletions lorien/Assets/Icons/mark-pen-fill.png.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
[remap]

importer="texture"
type="StreamTexture"
path="res://.import/mark-pen-fill.png-2455cd4a2659c733e0b2303d8ed528cc.stex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://Assets/Icons/mark-pen-fill.png"
dest_files=[ "res://.import/mark-pen-fill.png-2455cd4a2659c733e0b2303d8ed528cc.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
1 change: 1 addition & 0 deletions lorien/BrushStroke/BrushStroke.gd
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ var points: Array # Array<Vector2>
var pressures: Array # Array<float>
var top_left_pos: Vector2
var bottom_right_pos: Vector2
var layer: int

# ------------------------------------------------------------------------------------------------
func _ready():
Expand Down
90 changes: 70 additions & 20 deletions lorien/InfiniteCanvas/InfiniteCanvas.gd
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ const PLAYER = preload("res://Misc/Player/Player.tscn")

# -------------------------------------------------------------------------------------------------
onready var _brush_tool: BrushTool = $BrushTool
onready var _highlighter_tool: BrushTool = $HighlighterTool
onready var _rectangle_tool: RectangleTool = $RectangleTool
onready var _line_tool: LineTool = $LineTool
onready var _circle_tool: CircleTool = $CircleTool
onready var _eraser_tool: EraserTool = $EraserTool
onready var _selection_tool: SelectionTool = $SelectionTool
onready var _active_tool: CanvasTool = _brush_tool
onready var _strokes_parent: Node2D = $Viewport/Strokes
onready var _strokes_brush: Node2D = $Viewport/Strokes_Brush
onready var _strokes_highlighter: Node2D = $Viewport/Strokes_Highlighter
onready var _camera: Camera2D = $Viewport/Camera2D
onready var _viewport: Viewport = $Viewport
onready var _grid: InfiniteCanvasGrid = $Viewport/Grid
Expand All @@ -38,7 +40,9 @@ func _ready():
_brush_size = Settings.get_value(Settings.GENERAL_DEFAULT_BRUSH_SIZE, Config.DEFAULT_BRUSH_SIZE)
_active_tool._on_brush_size_changed(_brush_size)
_active_tool.enabled = false


_highlighter_tool.set_layer(1)

get_tree().get_root().connect("size_changed", self, "_on_window_resized")

for child in $Viewport.get_children():
Expand Down Expand Up @@ -92,6 +96,9 @@ func use_tool(tool_type: int) -> void:
Types.Tool.BRUSH:
_active_tool = _brush_tool
_use_optimizer = true
Types.Tool.HIGHLIGHTER:
_active_tool = _highlighter_tool
_use_optimizer = true
Types.Tool.RECTANGLE:
_active_tool = _rectangle_tool
_use_optimizer = false
Expand Down Expand Up @@ -125,7 +132,7 @@ func set_background_color(color: Color) -> void:
func enable_colliders(enable: bool) -> void:
if _colliders_enabled != enable:
_colliders_enabled = enable
for stroke in _strokes_parent.get_children():
for stroke in _strokes_brush.get_children():
stroke.enable_collider(enable)

# -------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -180,18 +187,29 @@ func take_screenshot() -> Image:

# -------------------------------------------------------------------------------------------------
func start_stroke() -> void:
var _selected_layer := _active_tool.get_layer()
_current_stroke = BRUSH_STROKE.instance()
_current_stroke.size = _brush_size
_current_stroke.color = _brush_color
_current_stroke.layer = _selected_layer

_strokes_parent.add_child(_current_stroke)
if _selected_layer == 1 :
_current_stroke.size = _brush_size * 10
_current_stroke.color = Color(_brush_color.r,_brush_color.g,_brush_color.b,0.8)
_strokes_highlighter.add_child(_current_stroke)
else :
_current_stroke.size = _brush_size
_current_stroke.color = _brush_color
_strokes_brush.add_child(_current_stroke)

_optimizer.reset()

# -------------------------------------------------------------------------------------------------
func add_stroke(stroke: BrushStroke) -> void:
if _current_project != null:
_current_project.strokes.append(stroke)
_strokes_parent.add_child(stroke)
if stroke.layer == 1 :
_strokes_highlighter.add_child(stroke)
else :
_strokes_brush.add_child(stroke)
info.point_count += stroke.points.size()
info.stroke_count += 1

Expand All @@ -215,7 +233,11 @@ func end_stroke() -> void:
if _current_stroke != null:
var points: Array = _current_stroke.points
if points.size() <= 1 || (points.size() == 2 && points.front().is_equal_approx(points.back())):
_strokes_parent.remove_child(_current_stroke)
if _current_stroke.layer == 1 :
_strokes_highlighter.remove_child(_current_stroke)
else :
_strokes_brush.remove_child(_current_stroke)

_current_stroke.queue_free()
else:
if _use_optimizer:
Expand All @@ -234,15 +256,23 @@ func end_stroke() -> void:
_current_stroke.enable_collider(true)

# Remove the line temporally from the node tree, so the adding is registered in the undo-redo histrory below
_strokes_parent.remove_child(_current_stroke)
if _current_stroke.layer == 1 :
_strokes_highlighter.remove_child(_current_stroke)
else :
_strokes_brush.remove_child(_current_stroke)

_current_project.undo_redo.create_action("Stroke")
_current_project.undo_redo.add_undo_method(self, "undo_last_stroke")
_current_project.undo_redo.add_undo_reference(_current_stroke)
_current_project.undo_redo.add_do_method(_strokes_parent, "add_child", _current_stroke)
_current_project.undo_redo.add_do_property(info, "stroke_count", info.stroke_count + 1)
_current_project.undo_redo.add_do_property(info, "point_count", info.point_count + _current_stroke.points.size())
_current_project.undo_redo.add_do_method(_current_project, "add_stroke", _current_stroke)
if _current_stroke.layer == 1 :
_current_project.undo_redo.add_do_method(_strokes_highlighter, "add_child", _current_stroke)
_current_project.undo_redo.add_do_method(_current_project, "add_stroke", _current_stroke)
else :
_current_project.undo_redo.add_do_method(_strokes_brush, "add_child", _current_stroke)
_current_project.undo_redo.add_do_method(_current_project, "add_stroke", _current_stroke)

_current_project.undo_redo.commit_action()

_current_stroke = null
Expand All @@ -255,17 +285,24 @@ func add_strokes(strokes: Array) -> void:
point_count += stroke.points.size()
_current_project.undo_redo.add_undo_method(self, "undo_last_stroke")
_current_project.undo_redo.add_undo_reference(stroke)
_current_project.undo_redo.add_do_method(_strokes_parent, "add_child", stroke)
_current_project.undo_redo.add_do_method(_current_project, "add_stroke", stroke)
if stroke.layer == 1 :
_current_project.undo_redo.add_do_method(_strokes_highlighter, "add_child", stroke)
_current_project.undo_redo.add_do_method(_current_project, "add_stroke", stroke)
else :
_current_project.undo_redo.add_do_method(_strokes_brush, "add_child", stroke)
_current_project.undo_redo.add_do_method(_current_project, "add_stroke", stroke)

_current_project.undo_redo.add_do_property(info, "stroke_count", info.stroke_count + strokes.size())
_current_project.undo_redo.add_do_property(info, "point_count", info.point_count + point_count)
_current_project.undo_redo.commit_action()

# -------------------------------------------------------------------------------------------------
func use_project(project: Project) -> void:
# Cleanup old data
for stroke in _strokes_parent.get_children():
_strokes_parent.remove_child(stroke)
for stroke in _strokes_brush.get_children():
_strokes_brush.remove_child(stroke)
for stroke in _strokes_highlighter.get_children():
_strokes_highlighter.remove_child(stroke)
info.point_count = 0
info.stroke_count = 0

Expand All @@ -276,7 +313,10 @@ func use_project(project: Project) -> void:
# Add new data
_current_project = project
for stroke in _current_project.strokes:
_strokes_parent.add_child(stroke)
if stroke.layer==1:
_strokes_highlighter.add_child(stroke)
else:
_strokes_brush.add_child(stroke)
info.stroke_count += 1
info.point_count += stroke.points.size()

Expand All @@ -285,8 +325,11 @@ func use_project(project: Project) -> void:
# -------------------------------------------------------------------------------------------------
func undo_last_stroke() -> void:
if _current_stroke == null && !_current_project.strokes.empty():
var stroke = _strokes_parent.get_child(_strokes_parent.get_child_count() - 1)
_strokes_parent.remove_child(stroke)
var stroke = _current_project.strokes.back()
if stroke.layer == 1 :
_strokes_highlighter.remove_child(stroke)
else :
_strokes_brush.remove_child(stroke)
_current_project.remove_last_stroke()
info.point_count -= stroke.points.size()
info.stroke_count -= 1
Expand Down Expand Up @@ -339,7 +382,10 @@ func _delete_selected_strokes() -> void:
func _do_delete_stroke(stroke: BrushStroke) -> void:
var index := _current_project.strokes.find(stroke)
_current_project.strokes.remove(index)
_strokes_parent.remove_child(stroke)
if stroke.layer==1 :
_strokes_highlighter.remove_child(stroke)
else :
_strokes_brush.remove_child(stroke)
info.point_count -= stroke.points.size()
info.stroke_count -= 1

Expand All @@ -348,7 +394,11 @@ func _do_delete_stroke(stroke: BrushStroke) -> void:
# -------------------------------------------------------------------------------------------------
func _undo_delete_stroke(stroke: BrushStroke) -> void:
_current_project.strokes.append(stroke)
_strokes_parent.add_child(stroke)
if stroke.layer == 1 :
_strokes_highlighter.add_child(stroke)
else :
_strokes_brush.add_child(stroke)

info.point_count += stroke.points.size()
info.stroke_count += 1

Expand Down
9 changes: 8 additions & 1 deletion lorien/InfiniteCanvas/InfiniteCanvas.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ script = ExtResource( 5 )
cursor_path = NodePath("../Viewport/BrushCursor")
pressure_curve = ExtResource( 3 )

[node name="HighlighterTool" type="Node" parent="."]
script = ExtResource( 5 )
cursor_path = NodePath("../Viewport/BrushCursor")
pressure_curve = ExtResource( 3 )

[node name="RectangleTool" type="Node" parent="."]
script = ExtResource( 11 )
cursor_path = NodePath("../Viewport/BrushCursor")
Expand Down Expand Up @@ -70,7 +75,9 @@ script = ExtResource( 2 )
script = ExtResource( 12 )
camera_path = NodePath("../Camera2D")

[node name="Strokes" type="Node2D" parent="Viewport"]
[node name="Strokes_Highlighter" type="Node2D" parent="Viewport"]

[node name="Strokes_Brush" type="Node2D" parent="Viewport"]

[node name="DebugDraw" type="Node2D" parent="Viewport"]
script = ExtResource( 15 )
Expand Down
9 changes: 9 additions & 0 deletions lorien/InfiniteCanvas/Tools/CanvasTool.gd
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,22 @@ var _cursor: Sprite # This is a BaseCursor. Can't type it.
var _canvas: Node # This is an InfinteCanvas. Can't type it though because of cyclic dependency bugs...
var enabled := false setget set_enabled, get_enabled
var performing_stroke := false
var _layer := 2

# -------------------------------------------------------------------------------------------------
func _ready():
_cursor = get_node(cursor_path)
_canvas = get_parent()
set_enabled(false)

# -------------------------------------------------------------------------------------------------
func set_layer(layer: int) -> void:
self._layer = layer

# -------------------------------------------------------------------------------------------------
func get_layer() -> int:
return self._layer

# -------------------------------------------------------------------------------------------------
func tool_event(event: InputEvent) -> void:
pass
Expand Down
2 changes: 2 additions & 0 deletions lorien/Main.gd
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ func _unhandled_input(event):
_canvas.center_to_mouse()
elif Utils.event_pressed_bug_workaround("shortcut_brush_tool", event):
_toolbar.enable_tool(Types.Tool.BRUSH)
elif Utils.event_pressed_bug_workaround("shortcut_highlighter_tool", event):
_toolbar.enable_tool(Types.Tool.HIGHLIGHTER)
elif Utils.event_pressed_bug_workaround("shortcut_rectangle_tool", event):
_toolbar.enable_tool(Types.Tool.RECTANGLE)
elif Utils.event_pressed_bug_workaround("shortcut_circle_tool", event):
Expand Down
1 change: 1 addition & 0 deletions lorien/Misc/Types.gd
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ class_name Types
# -------------------------------------------------------------------------------------------------
enum Tool {
BRUSH,
HIGHLIGHTER,
RECTANGLE,
CIRCLE,
LINE,
Expand Down
Loading