Skip to content
Open
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
Binary file added lorien/Assets/Icons/text-block.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 34 additions & 0 deletions lorien/Assets/Icons/text-block.png.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[remap]

importer="texture"
type="CompressedTexture2D"
uid="uid://desowbtf21cic"
path="res://.godot/imported/text-block.png-6805ad0a47d23e70568cf3e8fb3f0677.ctex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://Assets/Icons/text-block.png"
dest_files=["res://.godot/imported/text-block.png-6805ad0a47d23e70568cf3e8fb3f0677.ctex"]

[params]

compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1
75 changes: 75 additions & 0 deletions lorien/InfiniteCanvas/InfiniteCanvas.gd
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,15 @@ const PLAYER = preload("res://Misc/Player/Player.tscn")
@onready var _circle_tool: CircleTool = $CircleTool
@onready var _eraser_tool: EraserTool = $EraserTool
@onready var _selection_tool: SelectionTool = $SelectionTool
@onready var _textbox_tool: TextBoxTool = $TextBoxTool
@onready var _active_tool: CanvasTool = _brush_tool
@onready var _active_tool_type: int = Types.Tool.BRUSH
@onready var _strokes_parent: Node2D = $SubViewport/Strokes
@onready var _textboxes_parent: Control = $SubViewport/TextBoxes
@onready var _camera: Camera2D = $SubViewport/Camera2D
@onready var _viewport: SubViewport = $SubViewport
@onready var _grid: InfiniteCanvasGrid = $SubViewport/Grid
@onready var _text_box_editor : PanelContainer = $TextBoxEditor

@onready var _constant_pressure_curve := load("res://InfiniteCanvas/constant_pressure_curve.tres")
@onready var _default_pressure_curve := load("res://InfiniteCanvas/default_pressure_curve.tres")
Expand Down Expand Up @@ -92,10 +95,12 @@ func _process_event(event: InputEvent) -> void:
if event.is_action("deselect_all_strokes"):
if _active_tool == _selection_tool:
_selection_tool.deselect_all_strokes()
_selection_tool.deselect_all_text_boxes()

if event.is_action("delete_selected_strokes"):
if _active_tool == _selection_tool:
_delete_selected_strokes()
_delete_selected_text_boxes_strokes()

if !get_tree().root.get_viewport().is_input_handled():
_camera.tool_event(event)
Expand Down Expand Up @@ -133,6 +138,9 @@ func use_tool(tool_type: int) -> void:
Types.Tool.SELECT:
_active_tool = _selection_tool
_use_optimizer = false
Types.Tool.TEXTBOX:
_active_tool = _textbox_tool
_use_optimizer = false

if prev_tool != _active_tool:
prev_tool.enabled = false
Expand Down Expand Up @@ -185,6 +193,9 @@ func get_all_strokes() -> Array[BrushStroke]:
return _current_project.strokes

# -------------------------------------------------------------------------------------------------
func get_all_text_boxes() -> Array[TextBox]:
return _current_project.textBoxes
# -------------------------------------------------------------------------------------------------
func enable() -> void:
Input.set_mouse_mode(Input.MOUSE_MODE_HIDDEN)
_camera.enable_input()
Expand Down Expand Up @@ -296,6 +307,8 @@ func use_project(project: Project) -> void:
# Cleanup old data
for stroke in _strokes_parent.get_children():
_strokes_parent.remove_child(stroke)
for textBox in _textboxes_parent.get_children():
_textboxes_parent.remove_child(textBox)
info.point_count = 0
info.stroke_count = 0

Expand All @@ -309,6 +322,8 @@ func use_project(project: Project) -> void:
_strokes_parent.add_child(stroke)
info.stroke_count += 1
info.point_count += stroke.points.size()
for textBox in _current_project.textBoxes:
_textboxes_parent.add_child(textBox)

_grid.queue_redraw()

Expand Down Expand Up @@ -372,6 +387,19 @@ func _delete_selected_strokes() -> void:
_current_project.undo_redo.commit_action()
_current_project.dirty = true

# -------------------------------------------------------------------------------------------------
func _delete_selected_text_boxes_strokes() -> void:
var text_boxes := _selection_tool.get_selected_text_boxes()
if !text_boxes.is_empty():
_current_project.undo_redo.create_action("Delete Selection")
for text_box: TextBox in text_boxes:
_current_project.undo_redo.add_do_method(_do_delete_text_box.bind(text_box))
_current_project.undo_redo.add_undo_reference(text_box)
_current_project.undo_redo.add_undo_method(_undo_delete_text_box.bind(text_box))
_selection_tool.deselect_all_text_boxes()
_current_project.undo_redo.commit_action()
_current_project.dirty = true

# -------------------------------------------------------------------------------------------------
func _do_delete_stroke(stroke: BrushStroke) -> void:
var index := _current_project.strokes.find(stroke)
Expand All @@ -380,6 +408,12 @@ func _do_delete_stroke(stroke: BrushStroke) -> void:
info.point_count -= stroke.points.size()
info.stroke_count -= 1

# -------------------------------------------------------------------------------------------------
func _do_delete_text_box(text_box: TextBox) -> void:
var index := _current_project.textBoxes.find(text_box)
_current_project.textBoxes.remove_at(index)
_textboxes_parent.remove_child(text_box)

# FIXME: this adds strokes at the back and does not preserve stroke order; not sure how to do that except saving before
# and after versions of the stroke arrays which is a nogo.
# -------------------------------------------------------------------------------------------------
Expand All @@ -388,3 +422,44 @@ func _undo_delete_stroke(stroke: BrushStroke) -> void:
_strokes_parent.add_child(stroke)
info.point_count += stroke.points.size()
info.stroke_count += 1

# FIXME: this adds text boxes at the back and does not preserve text boxes order; not sure how to do that except saving before
# and after versions of the text boxes arrays which is a nogo.
# -------------------------------------------------------------------------------------------------
func _undo_delete_text_box(text_box: TextBox) -> void:
_current_project.textBoxes.append(text_box)
_textboxes_parent.add_child(text_box)

# -------------------------------------------------------------------------------------------------
func _create_textbox(textBox : TextBox) -> void:
_textboxes_parent.add_child(textBox)
_current_project.textBoxes.append(textBox)

# -------------------------------------------------------------------------------------------------
func _on_text_box_tool_show_text_box_dialog(dialogPosition : Vector2) -> void:
_text_box_editor.visible = true
_text_box_editor.label_position = dialogPosition

# -------------------------------------------------------------------------------------------------
func _on_text_box_editor_text_box_ok(value : String, labelPosition : Vector2) -> void:
var label : TextBox = TextBox.new()
label.text = value
label.set_position(labelPosition)
label.add_theme_color_override("font_color", _brush_color)
_create_textbox(label)
_textbox_tool._state = _textbox_tool.State.CREATING

# -------------------------------------------------------------------------------------------------
func _on_text_box_editor_text_box_cancel() -> void:
_textbox_tool._state = _textbox_tool.State.CREATING

# -------------------------------------------------------------------------------------------------
func _on_text_box_tool_edit_existing_text_box(textBox : TextBox) -> void:
_text_box_editor.visible = true
_text_box_editor.textEdit.text = textBox.text
_text_box_editor.label_position = textBox.position
_text_box_editor.textBox = textBox

# -------------------------------------------------------------------------------------------------
func _on_text_box_editor_text_box_ok_update() -> void:
_textbox_tool._state = _textbox_tool.State.CREATING
27 changes: 26 additions & 1 deletion lorien/InfiniteCanvas/InfiniteCanvas.tscn
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[gd_scene load_steps=17 format=3 uid="uid://c4u5gk5n2aiom"]
[gd_scene load_steps=19 format=3 uid="uid://c4u5gk5n2aiom"]

[ext_resource type="Script" path="res://InfiniteCanvas/InfiniteCanvas.gd" id="1"]
[ext_resource type="Script" path="res://InfiniteCanvas/PanZoomCamera.gd" id="2"]
Expand All @@ -9,7 +9,9 @@
[ext_resource type="Script" path="res://InfiniteCanvas/Tools/SelectionTool.gd" id="7"]
[ext_resource type="PackedScene" path="res://InfiniteCanvas/Cursor/SelectionCursor/SelectionCursor.tscn" id="8"]
[ext_resource type="Script" path="res://InfiniteCanvas/Tools/SelectionRectangle.gd" id="9"]
[ext_resource type="Script" path="res://InfiniteCanvas/Tools/TextBoxTool.gd" id="9_yqcq5"]
[ext_resource type="Shader" path="res://InfiniteCanvas/Tools/selection_rectangle.gdshader" id="10"]
[ext_resource type="PackedScene" uid="uid://ccl05i282g120" path="res://TextBox/TextBoxEditor.tscn" id="10_gdd0v"]
[ext_resource type="Script" path="res://InfiniteCanvas/Tools/RectangleTool.gd" id="11"]
[ext_resource type="Script" path="res://InfiniteCanvas/InfiniteCanvasGrid.gd" id="12"]
[ext_resource type="Script" path="res://InfiniteCanvas/Tools/CircleTool.gd" id="13"]
Expand All @@ -26,6 +28,9 @@ anchor_right = 1.0
anchor_bottom = 1.0
script = ExtResource("1")

[node name="TextBoxEditor" parent="." instance=ExtResource("10_gdd0v")]
layout_mode = 2

[node name="BrushTool" type="Node" parent="."]
script = ExtResource("5")
pressure_curve = ExtResource("3")
Expand Down Expand Up @@ -55,6 +60,11 @@ script = ExtResource("7")
selection_rectangle_path = NodePath("../SubViewport/SelectionRectangle")
cursor_path = NodePath("../SubViewport/SelectionCursor")

[node name="TextBoxTool" type="Node" parent="."]
script = ExtResource("9_yqcq5")
_textBox = ExtResource("10_gdd0v")
cursor_path = NodePath("../SubViewport/SelectionCursor")

[node name="SubViewport" type="SubViewport" parent="."]
handle_input_locally = false
size = Vector2i(1920, 1080)
Expand All @@ -80,3 +90,18 @@ script = ExtResource("9")
[node name="BrushCursor" parent="SubViewport" instance=ExtResource("4")]

[node name="SelectionCursor" parent="SubViewport" instance=ExtResource("8")]

[node name="TextBoxes" type="Control" parent="SubViewport"]
layout_mode = 3
anchors_preset = 0
mouse_filter = 1

[connection signal="focus_entered" from="." to="." method="_on_focus_entered"]
[connection signal="mouse_entered" from="." to="." method="_on_mouse_entered"]
[connection signal="mouse_exited" from="." to="." method="_on_mouse_exited"]
[connection signal="textBox_cancel" from="TextBoxEditor" to="." method="_on_text_box_editor_text_box_cancel"]
[connection signal="textBox_ok" from="TextBoxEditor" to="." method="_on_text_box_editor_text_box_ok"]
[connection signal="textBox_ok_update" from="TextBoxEditor" to="." method="_on_text_box_editor_text_box_ok_update"]
[connection signal="edit_existing_textBox" from="TextBoxTool" to="." method="_on_text_box_tool_edit_existing_text_box"]
[connection signal="show_textBoxDialog" from="TextBoxTool" to="." method="_on_text_box_tool_show_text_box_dialog"]
[connection signal="text_box_tool_reset" from="TextBoxTool" to="." method="_on_text_box_tool_text_box_tool_reset"]
3 changes: 2 additions & 1 deletion lorien/InfiniteCanvas/Tools/EraserTool.gd
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ func _add_undoredo_action_for_erased_strokes() -> void:
# ------------------------------------------------------------------------------------------------
func _update_bounding_boxes() -> void:
var strokes := _canvas.get_all_strokes()
_bounding_box_cache = Utils.calculte_bounding_boxes(strokes, BOUNDING_BOX_MARGIN)
var text_boxes := _canvas.get_all_text_boxes()
_bounding_box_cache = Utils.calculte_bounding_boxes(strokes, text_boxes, BOUNDING_BOX_MARGIN)
#$"../Viewport/DebugDraw".set_bounding_boxes(_bounding_box_cache.values())

# ------------------------------------------------------------------------------------------------
Expand Down
Loading