From bb453f8a2023fc77001a170fb99089d46adc19d7 Mon Sep 17 00:00:00 2001 From: Marco Eibensteiner Date: Thu, 10 Apr 2025 22:40:54 +0200 Subject: [PATCH 01/16] Init Text Box Prototype --- lorien/Assets/Icons/text-block.png | Bin 0 -> 426 bytes lorien/Assets/Icons/text-block.png.import | 34 +++++++++++++ lorien/InfiniteCanvas/InfiniteCanvas.gd | 35 +++++++++++++ lorien/InfiniteCanvas/InfiniteCanvas.tscn | 19 ++++++- lorien/InfiniteCanvas/Tools/TextBoxTool.gd | 51 +++++++++++++++++++ lorien/Misc/Types.gd | 1 + lorien/TextBox/TextBox.gd | 55 +++++++++++++++++++++ lorien/TextBox/TextBox.tscn | 54 ++++++++++++++++++++ lorien/TextBox/TextBox2.gd | 21 ++++++++ lorien/TextBox/TextBox2.tscn | 42 ++++++++++++++++ lorien/UI/Components/PaletteButton.tscn | 34 ++++++------- lorien/UI/Toolbar.gd | 9 ++++ lorien/UI/Toolbar.tscn | 14 +++++- lorien/project.godot | 4 ++ 14 files changed, 354 insertions(+), 19 deletions(-) create mode 100644 lorien/Assets/Icons/text-block.png create mode 100644 lorien/Assets/Icons/text-block.png.import create mode 100644 lorien/InfiniteCanvas/Tools/TextBoxTool.gd create mode 100644 lorien/TextBox/TextBox.gd create mode 100644 lorien/TextBox/TextBox.tscn create mode 100644 lorien/TextBox/TextBox2.gd create mode 100644 lorien/TextBox/TextBox2.tscn diff --git a/lorien/Assets/Icons/text-block.png b/lorien/Assets/Icons/text-block.png new file mode 100644 index 0000000000000000000000000000000000000000..3fced245a8eb44a2fd89d8955220903abcafacd3 GIT binary patch literal 426 zcmV;b0agBqP)Px$WJyFpR5(v{RMC}#FbtDCNjEt$kDQZJ zouz|e@_kAgR$*^IFMu~}p!WdHaic9M0|oN}G*B36HnFxOKtBL7i%rhSw8O_F`R+*C z)M%-J%;nVX2VU)wlssi5S%4(DEH`}w@B%Q?xEzc+)yzOy8jCb3Jq3R66a~DD{5d+J zmKp1$be0y3ZhP?rEaqkJwN^-O7?onzCbWiJ^-jaclTy+E;>*ZsFH%u*eL$&Nn60Gu zT55MccUafp(-;wj(GDbeIvyI;&) zzVdMbd``E9tjvCQZ-8c)k3lV|!bG!qo3*P;DdP1Vba{=`eUyK=n$gazWpNSz18Rfm U8iCRYZU6uP07*qoM6N<$f}gs!P5=M^ literal 0 HcmV?d00001 diff --git a/lorien/Assets/Icons/text-block.png.import b/lorien/Assets/Icons/text-block.png.import new file mode 100644 index 00000000..1620fac1 --- /dev/null +++ b/lorien/Assets/Icons/text-block.png.import @@ -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 diff --git a/lorien/InfiniteCanvas/InfiniteCanvas.gd b/lorien/InfiniteCanvas/InfiniteCanvas.gd index bab70818..abac95df 100644 --- a/lorien/InfiniteCanvas/InfiniteCanvas.gd +++ b/lorien/InfiniteCanvas/InfiniteCanvas.gd @@ -12,9 +12,11 @@ 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 @@ -66,6 +68,13 @@ func _ready() -> void: info.pen_inverted = false +func _process(delta: float) -> void: + var node : Node = $SubViewport.gui_get_focus_owner() + #if node != null: + # print(node.name) + #else: + # print("Node is null") + # ------------------------------------------------------------------------------------------------- func _unhandled_key_input(event: InputEvent) -> void: _process_event(event) @@ -133,6 +142,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 @@ -388,3 +400,26 @@ func _undo_delete_stroke(stroke: BrushStroke) -> void: _strokes_parent.add_child(stroke) info.point_count += stroke.points.size() info.stroke_count += 1 + +# ------------------------------------------------------------------------------------------------- +func _create_textbox(textBox : Label) -> void: + _textboxes_parent.add_child(textBox) + +func _on_mouse_exited() -> void: + print("Mouse left infinite canvas") + + +func _on_mouse_entered() -> void: + print("Mouse entered infinite canvas") + + +func _on_text_box_tool_text_box_tool_reset() -> void: + print("Text Box Reset on infinite canvas") + #grab_click_focus() + grab_focus() + #mouse_exited.emit() + #mouse_entered.emit() + + +func _on_focus_entered() -> void: + print("focus on infiniteCanvas") diff --git a/lorien/InfiniteCanvas/InfiniteCanvas.tscn b/lorien/InfiniteCanvas/InfiniteCanvas.tscn index c0a94fdb..2c31be64 100644 --- a/lorien/InfiniteCanvas/InfiniteCanvas.tscn +++ b/lorien/InfiniteCanvas/InfiniteCanvas.tscn @@ -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"] @@ -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/TextBox2.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"] @@ -55,6 +57,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) @@ -80,3 +87,13 @@ 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="text_box_tool_reset" from="TextBoxTool" to="." method="_on_text_box_tool_text_box_tool_reset"] diff --git a/lorien/InfiniteCanvas/Tools/TextBoxTool.gd b/lorien/InfiniteCanvas/Tools/TextBoxTool.gd new file mode 100644 index 00000000..3526d1d8 --- /dev/null +++ b/lorien/InfiniteCanvas/Tools/TextBoxTool.gd @@ -0,0 +1,51 @@ +class_name TextBoxTool +extends CanvasTool + +@export var _textBox: PackedScene +var textBoxInstance : TextBox2 + +signal text_box_tool_reset + +enum State { + CREATING, + EDITING +} + +@export +var _state = State.CREATING +@export +var _position : Vector2 + +func _ready() -> void: + super() + _state = State.CREATING + +# ------------------------------------------------------------------------------------------------- +func tool_event(event: InputEvent) -> void: + + if event is InputEventMouseButton: + if event.button_index == MOUSE_BUTTON_LEFT: + if event.pressed && _state == State.CREATING: + _state = State.EDITING + textBoxInstance = _textBox.instantiate() + textBoxInstance.set_position(_cursor.global_position) + textBoxInstance.textBox_ok.connect(save_label) + _position = _cursor.global_position + add_child(textBoxInstance) + +func save_label(value : String) -> void: + var label : Label = Label.new() + label.text = value + label.set_position(_position) + _canvas._create_textbox(label) + _state = State.CREATING + +# ------------------------------------------------------------------------------------------------ +#func reset() -> void: +# _state = State.CREATING + #if textBoxInstance != null: + #textBoxInstance.release_focus() + # textBoxInstance = null +# print("Reset in TextBoxTool") + + diff --git a/lorien/Misc/Types.gd b/lorien/Misc/Types.gd index 46013c36..c56e0cda 100644 --- a/lorien/Misc/Types.gd +++ b/lorien/Misc/Types.gd @@ -9,6 +9,7 @@ enum Tool { LINE, ERASER, SELECT, + TEXTBOX, } # ------------------------------------------------------------------------------------------------- diff --git a/lorien/TextBox/TextBox.gd b/lorien/TextBox/TextBox.gd new file mode 100644 index 00000000..400b9441 --- /dev/null +++ b/lorien/TextBox/TextBox.gd @@ -0,0 +1,55 @@ +class_name TextBox extends Control + +@onready var _textEdit : TextEdit = $VBoxContainer/PanelContainer/TextEdit +@onready var _label : Label = $VBoxContainer/PanelContainer/Label +@onready var _btn_ok : Button = $VBoxContainer/HBoxContainer/btn_ok +@onready var _btn_cancel : Button = $VBoxContainer/HBoxContainer/btn_cancel +@onready var _panel : PanelContainer = $VBoxContainer/PanelContainer + +signal label_created + +#func _on_text_edit_focus_exited() -> void: + #_label.text = _textEdit.text + #_textEdit.hide() + #_label.show() + #_btn_cancel.hide() + #_btn_ok.hide() + #_textEdit.release_focus() + #label_created.emit() + ## Find Infinit canvas and give focus back + +func _on_btn_ok_button_up() -> void: + _label.text = _textEdit.text + _textEdit.hide() + _btn_cancel.hide() + _btn_ok.hide() + _label.show() + #_textEdit.release_focus() + #_label.grab_focus() + label_created.emit() + + +func _on_btn_cancel_button_up() -> void: + #_textEdit.release_focus() + call_deferred("queue_free") + label_created.emit() + + +func _on_text_edit_mouse_exited() -> void: + print("Mouse Exited Text Edit") + + +func _on_panel_container_mouse_exited() -> void: + print("Mouse left container") + + +func _on_v_box_container_mouse_exited() -> void: + print("Mouse left VBox") + + +func _on_label_focus_entered() -> void: + print("label focus entered") + + +func _on_label_focus_exited() -> void: + print("label focus exited") diff --git a/lorien/TextBox/TextBox.tscn b/lorien/TextBox/TextBox.tscn new file mode 100644 index 00000000..3631715a --- /dev/null +++ b/lorien/TextBox/TextBox.tscn @@ -0,0 +1,54 @@ +[gd_scene load_steps=2 format=3 uid="uid://7dswpn8jua61"] + +[ext_resource type="Script" path="res://TextBox/TextBox.gd" id="1_cx17r"] + +[node name="TextBox" type="Control"] +layout_mode = 3 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +script = ExtResource("1_cx17r") + +[node name="VBoxContainer" type="VBoxContainer" parent="."] +layout_mode = 0 +offset_right = 40.0 +offset_bottom = 40.0 + +[node name="HBoxContainer" type="HBoxContainer" parent="VBoxContainer"] +layout_mode = 2 + +[node name="btn_ok" type="Button" parent="VBoxContainer/HBoxContainer"] +layout_mode = 2 +size_flags_horizontal = 0 +size_flags_vertical = 8 +text = "OK" + +[node name="btn_cancel" type="Button" parent="VBoxContainer/HBoxContainer"] +layout_mode = 2 +size_flags_horizontal = 8 +size_flags_vertical = 8 +text = "Cancel" + +[node name="PanelContainer" type="PanelContainer" parent="VBoxContainer"] +custom_minimum_size = Vector2(300, 25) +layout_mode = 2 + +[node name="Label" type="Label" parent="VBoxContainer/PanelContainer"] +visible = false +layout_mode = 2 + +[node name="TextEdit" type="TextEdit" parent="VBoxContainer/PanelContainer"] +layout_mode = 2 +wrap_mode = 1 +scroll_fit_content_height = true + +[connection signal="mouse_exited" from="VBoxContainer" to="." method="_on_v_box_container_mouse_exited"] +[connection signal="button_up" from="VBoxContainer/HBoxContainer/btn_ok" to="." method="_on_btn_ok_button_up"] +[connection signal="button_up" from="VBoxContainer/HBoxContainer/btn_cancel" to="." method="_on_btn_cancel_button_up"] +[connection signal="mouse_exited" from="VBoxContainer/PanelContainer" to="." method="_on_panel_container_mouse_exited"] +[connection signal="focus_entered" from="VBoxContainer/PanelContainer/Label" to="." method="_on_label_focus_entered"] +[connection signal="focus_exited" from="VBoxContainer/PanelContainer/Label" to="." method="_on_label_focus_exited"] +[connection signal="focus_exited" from="VBoxContainer/PanelContainer/TextEdit" to="." method="_on_text_edit_focus_exited"] +[connection signal="mouse_exited" from="VBoxContainer/PanelContainer/TextEdit" to="." method="_on_text_edit_mouse_exited"] diff --git a/lorien/TextBox/TextBox2.gd b/lorien/TextBox/TextBox2.gd new file mode 100644 index 00000000..2bc87a39 --- /dev/null +++ b/lorien/TextBox/TextBox2.gd @@ -0,0 +1,21 @@ +class_name TextBox2 extends PopupPanel + +@onready +var textEdit : TextEdit = $Control/VBoxContainer/TextEdit + +signal textBox_ok +signal textBox_cancel + +# Called when the node enters the scene tree for the first time. +func _ready() -> void: + pass # Replace with function body. + + +# Called every frame. 'delta' is the elapsed time since the previous frame. +func _process(delta: float) -> void: + pass + + +func _on_save_button_pressed() -> void: + textBox_ok.emit(textEdit.text) + queue_free() diff --git a/lorien/TextBox/TextBox2.tscn b/lorien/TextBox/TextBox2.tscn new file mode 100644 index 00000000..ad2dbdf5 --- /dev/null +++ b/lorien/TextBox/TextBox2.tscn @@ -0,0 +1,42 @@ +[gd_scene load_steps=2 format=3 uid="uid://ccl05i282g120"] + +[ext_resource type="Script" path="res://TextBox/TextBox2.gd" id="1_pskl6"] + +[node name="PopupPanel" type="PopupPanel"] +size = Vector2i(200, 200) +visible = true +always_on_top = true +script = ExtResource("1_pskl6") + +[node name="Control" type="Control" parent="."] +layout_mode = 3 +anchors_preset = 0 +offset_left = 4.0 +offset_top = 4.0 +offset_right = 196.0 +offset_bottom = 196.0 + +[node name="VBoxContainer" type="VBoxContainer" parent="Control"] +layout_mode = 1 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 + +[node name="TextEdit" type="TextEdit" parent="Control/VBoxContainer"] +custom_minimum_size = Vector2(100, 150) +layout_mode = 2 + +[node name="HBoxContainer" type="HBoxContainer" parent="Control/VBoxContainer"] +layout_mode = 2 + +[node name="SaveButton" type="Button" parent="Control/VBoxContainer/HBoxContainer"] +layout_mode = 2 +text = "Save" + +[node name="CancelButton" type="Button" parent="Control/VBoxContainer/HBoxContainer"] +layout_mode = 2 +text = "Cancel" + +[connection signal="pressed" from="Control/VBoxContainer/HBoxContainer/SaveButton" to="." method="_on_save_button_pressed"] diff --git a/lorien/UI/Components/PaletteButton.tscn b/lorien/UI/Components/PaletteButton.tscn index d09c1864..00671869 100644 --- a/lorien/UI/Components/PaletteButton.tscn +++ b/lorien/UI/Components/PaletteButton.tscn @@ -1,18 +1,24 @@ -[gd_scene load_steps=4 format=2] +[gd_scene load_steps=4 format=3 uid="uid://bgh8biiyio5bn"] -[ext_resource path="res://Assets/Textures/palette_button_outline.png" type="Texture2D" id=1] -[ext_resource path="res://Assets/Textures/palette_button.png" type="Texture2D" id=2] -[ext_resource path="res://UI/Components/PaletteButton.gd" type="Script" id=3] +[ext_resource type="Texture2D" uid="uid://d2x4s44tq3fd3" path="res://Assets/Textures/palette_button_outline.png" id="1"] +[ext_resource type="Texture2D" uid="uid://bb2kaiahpvl5m" path="res://Assets/Textures/palette_button.png" id="2"] +[ext_resource type="Script" path="res://UI/Components/PaletteButton.gd" id="3"] [node name="PaletteButton" type="Control"] +custom_minimum_size = Vector2(31, 31) +layout_mode = 3 +anchors_preset = 15 anchor_right = 1.0 anchor_bottom = 1.0 offset_right = -1889.0 offset_bottom = -1049.0 -custom_minimum_size = Vector2( 31, 31 ) -script = ExtResource( 3 ) +grow_horizontal = 2 +grow_vertical = 2 +script = ExtResource("3") [node name="Color" type="TextureRect" parent="."] +custom_minimum_size = Vector2(32, 32) +layout_mode = 0 anchor_left = 0.5 anchor_top = 0.5 anchor_right = 0.5 @@ -21,20 +27,14 @@ offset_left = -16.0 offset_top = -16.0 offset_right = 16.0 offset_bottom = 16.0 -custom_minimum_size = Vector2( 32, 32 ) -texture = ExtResource( 2 ) -expand = true +texture = ExtResource("2") +expand_mode = 1 stretch_mode = 6 -__meta__ = { -"_edit_use_anchors_": false -} [node name="Selection" type="TextureRect" parent="."] +layout_mode = 0 anchor_right = 1.0 anchor_bottom = 1.0 -texture = ExtResource( 1 ) -expand = true +texture = ExtResource("1") +expand_mode = 1 stretch_mode = 4 -__meta__ = { -"_edit_use_anchors_": false -} diff --git a/lorien/UI/Toolbar.gd b/lorien/UI/Toolbar.gd index 6f84dbac..0217a87b 100644 --- a/lorien/UI/Toolbar.gd +++ b/lorien/UI/Toolbar.gd @@ -33,6 +33,7 @@ const BUTTON_NORMAL_COLOR = Color.WHITE @onready var _tool_btn_line: FlatTextureButton = $Console/Left/LineToolButton @onready var _tool_btn_eraser: FlatTextureButton = $Console/Left/EraserToolButton @onready var _tool_btn_selection: FlatTextureButton = $Console/Left/SelectionToolButton +@onready var _tool_btn_textbox: FlatTextureButton = $Console/Left/TextBoxToolButton var _last_active_tool_button: FlatTextureButton @@ -65,6 +66,7 @@ func _ready() -> void: _tool_btn_line.pressed.connect(_on_line_tool_pressed) _tool_btn_eraser.pressed.connect(_on_eraser_tool_pressed) _tool_btn_selection.pressed.connect(_on_select_tool_pressed) + _tool_btn_textbox.pressed.connect(_on_textbox_tool_pressed) # ------------------------------------------------------------------------------------------------- func enable_tool(tool_type: Types.Tool) -> void: @@ -76,6 +78,7 @@ func enable_tool(tool_type: Types.Tool) -> void: Types.Tool.SELECT: btn = _tool_btn_selection Types.Tool.RECTANGLE: btn = _tool_btn_rectangle Types.Tool.CIRCLE: btn = _tool_btn_circle + Types.Tool.TEXTBOX: btn = _tool_btn_textbox btn.toggle() _change_active_tool_button(btn) @@ -112,6 +115,7 @@ func _on_keybinding_changed(action: KeybindingsManager.Action) -> void: "shortcut_line_tool": _tool_btn_line.tooltip_text = fmt % [tr("TOOLBAR_TOOLTIP_LINE_TOOL"), label] "shortcut_eraser_tool": _tool_btn_eraser.tooltip_text = fmt % [tr("TOOLBAR_TOOLTIP_ERASER_TOOL"), label] "shortcut_select_tool": _tool_btn_selection.tooltip_text = fmt % [tr("TOOLBAR_TOOLTIP_SELECT_TOOL"), label] + "shortcut_textbox_tool": _tool_btn_textbox.tooltip_text = fmt % [tr("TOOLBAR_TOOLTIP_TEXTBOX_TOOL"), label] # ------------------------------------------------------------------------------------------------- func _on_open_project_pressed() -> void: @@ -167,6 +171,11 @@ func _on_eraser_tool_pressed() -> void: func _on_select_tool_pressed() -> void: _change_active_tool_button(_tool_btn_selection) tool_changed.emit(Types.Tool.SELECT) + +# ------------------------------------------------------------------------------------------------- +func _on_textbox_tool_pressed() -> void: + _change_active_tool_button(_tool_btn_textbox) + tool_changed.emit(Types.Tool.TEXTBOX) # ------------------------------------------------------------------------------------------------- func _change_active_tool_button(btn: TextureButton) -> void: diff --git a/lorien/UI/Toolbar.tscn b/lorien/UI/Toolbar.tscn index c8866485..88b0125e 100644 --- a/lorien/UI/Toolbar.tscn +++ b/lorien/UI/Toolbar.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=19 format=3 uid="uid://c0ral10lvpo7f"] +[gd_scene load_steps=20 format=3 uid="uid://c0ral10lvpo7f"] [ext_resource type="Texture2D" uid="uid://c4kv3i7fmom58" path="res://Assets/Icons/save_file.png" id="1"] [ext_resource type="Texture2D" uid="uid://dxi6gc6npiskq" path="res://Assets/Icons/open_file.png" id="2"] @@ -14,6 +14,7 @@ [ext_resource type="Script" path="res://UI/Components/FlatTextureButton.gd" id="13"] [ext_resource type="Theme" uid="uid://u5qnpgxqykiv" path="res://UI/Themes/theme_dark.tres" id="15"] [ext_resource type="Texture2D" uid="uid://ddxis8f7tvg66" path="res://Assets/Icons/selection_tool.png" id="16"] +[ext_resource type="Texture2D" uid="uid://desowbtf21cic" path="res://Assets/Icons/text-block.png" id="16_hx67p"] [ext_resource type="Texture2D" uid="uid://0qicbkag5jd3" path="res://Assets/Icons/circle_tool.png" id="19"] [sub_resource type="StyleBoxEmpty" id="2"] @@ -181,6 +182,17 @@ script = ExtResource("13") hover_tint = Color(0.662745, 0.945098, 0.87451, 1) pressed_tint = Color(0.572549, 1, 0.894118, 1) +[node name="TextBoxToolButton" type="TextureButton" parent="Console/Left"] +layout_mode = 2 +size_flags_horizontal = 4 +size_flags_vertical = 4 +tooltip_text = "TOOLBAR_TOOLTIP_SELECT_TOOL" +toggle_mode = true +texture_normal = ExtResource("16_hx67p") +script = ExtResource("13") +hover_tint = Color(0.662745, 0.945098, 0.87451, 1) +pressed_tint = Color(0.572549, 1, 0.894118, 1) + [node name="VSeparator4" type="VSeparator" parent="Console/Left"] layout_mode = 2 theme_override_styles/separator = SubResource("3") diff --git a/lorien/project.godot b/lorien/project.godot index 6d92db3a..1f15e3b5 100644 --- a/lorien/project.godot +++ b/lorien/project.godot @@ -62,6 +62,10 @@ window/vsync/vsync_mode=false naming/scene_name_casing=1 naming/script_name_casing=1 +[gui] + +theme/default_font_multichannel_signed_distance_field=true + [input] ui_accept={ From 292f9c9d21ef32fc5c8362341b7fa4ad762c55c7 Mon Sep 17 00:00:00 2001 From: Marco Eibensteiner Date: Sat, 12 Apr 2025 20:58:39 +0200 Subject: [PATCH 02/16] Fixed pop up location --- lorien/InfiniteCanvas/Tools/TextBoxTool.gd | 7 ++++++- lorien/project.godot | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lorien/InfiniteCanvas/Tools/TextBoxTool.gd b/lorien/InfiniteCanvas/Tools/TextBoxTool.gd index 3526d1d8..0cb85d7c 100644 --- a/lorien/InfiniteCanvas/Tools/TextBoxTool.gd +++ b/lorien/InfiniteCanvas/Tools/TextBoxTool.gd @@ -28,10 +28,15 @@ func tool_event(event: InputEvent) -> void: if event.pressed && _state == State.CREATING: _state = State.EDITING textBoxInstance = _textBox.instantiate() - textBoxInstance.set_position(_cursor.global_position) + textBoxInstance.set_position(event.position) textBoxInstance.textBox_ok.connect(save_label) + textBoxInstance.exclusive = true _position = _cursor.global_position add_child(textBoxInstance) + var window_position : Vector2i = DisplayServer.window_get_position(0) + textBoxInstance.get_window_id() + print(DisplayServer.get_window_list()[1]) + DisplayServer.window_set_current_screen(DisplayServer.window_get_current_screen(0), DisplayServer.get_window_list()[1]) func save_label(value : String) -> void: var label : Label = Label.new() diff --git a/lorien/project.godot b/lorien/project.godot index 1f15e3b5..e51564bc 100644 --- a/lorien/project.godot +++ b/lorien/project.godot @@ -51,6 +51,7 @@ gdscript/warnings/unused_argument=false window/size/viewport_width=1920 window/size/viewport_height=1080 +window/size/initial_position_type=3 window/size/window_width_override=1440 window/size/window_height_override=810 window/subwindows/embed_subwindows=false From f09147281a1c7c3f2c76b4a8f8de4c468d43bf6c Mon Sep 17 00:00:00 2001 From: tafode Date: Wed, 16 Apr 2025 20:21:52 +0200 Subject: [PATCH 03/16] Changed pop up to panel, to prevent some issues. Started implementing save/load function --- lorien/InfiniteCanvas/InfiniteCanvas.gd | 24 +++++++++- lorien/InfiniteCanvas/InfiniteCanvas.tscn | 7 +++ lorien/InfiniteCanvas/Tools/TextBoxTool.gd | 29 +---------- lorien/ProjectManager/Project.gd | 7 +++ lorien/ProjectManager/Serializer.gd | 20 +++++++- lorien/TextBox/Panel.gd | 5 ++ lorien/TextBox/TextBox.gd | 56 +--------------------- lorien/TextBox/TextBox.tscn | 42 ---------------- lorien/TextBox/TextBox2.gd | 31 +++++++----- lorien/TextBox/TextBox2.tscn | 49 +++++++++++-------- lorien/UI/Themes/theme_dark.tres | 5 +- 11 files changed, 112 insertions(+), 163 deletions(-) create mode 100644 lorien/TextBox/Panel.gd diff --git a/lorien/InfiniteCanvas/InfiniteCanvas.gd b/lorien/InfiniteCanvas/InfiniteCanvas.gd index abac95df..b4dcee5b 100644 --- a/lorien/InfiniteCanvas/InfiniteCanvas.gd +++ b/lorien/InfiniteCanvas/InfiniteCanvas.gd @@ -20,6 +20,7 @@ const PLAYER = preload("res://Misc/Player/Player.tscn") @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") @@ -308,6 +309,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 @@ -321,6 +324,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() @@ -404,6 +409,7 @@ func _undo_delete_stroke(stroke: BrushStroke) -> void: # ------------------------------------------------------------------------------------------------- func _create_textbox(textBox : Label) -> void: _textboxes_parent.add_child(textBox) + _current_project.textBoxes.append(textBox) func _on_mouse_exited() -> void: print("Mouse left infinite canvas") @@ -416,10 +422,24 @@ func _on_mouse_entered() -> void: func _on_text_box_tool_text_box_tool_reset() -> void: print("Text Box Reset on infinite canvas") #grab_click_focus() - grab_focus() + #grab_focus() #mouse_exited.emit() #mouse_entered.emit() - func _on_focus_entered() -> void: print("focus on infiniteCanvas") + +func _on_text_box_tool_show_text_box_dialog(dialogPosition : Vector2) -> void: + print("Catch Show Dialog Event ", dialogPosition) + _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) + _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 diff --git a/lorien/InfiniteCanvas/InfiniteCanvas.tscn b/lorien/InfiniteCanvas/InfiniteCanvas.tscn index 2c31be64..b1856244 100644 --- a/lorien/InfiniteCanvas/InfiniteCanvas.tscn +++ b/lorien/InfiniteCanvas/InfiniteCanvas.tscn @@ -28,6 +28,10 @@ anchor_right = 1.0 anchor_bottom = 1.0 script = ExtResource("1") +[node name="TextBoxEditor" parent="." instance=ExtResource("10_gdd0v")] +visible = true +layout_mode = 2 + [node name="BrushTool" type="Node" parent="."] script = ExtResource("5") pressure_curve = ExtResource("3") @@ -96,4 +100,7 @@ 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="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"] diff --git a/lorien/InfiniteCanvas/Tools/TextBoxTool.gd b/lorien/InfiniteCanvas/Tools/TextBoxTool.gd index 0cb85d7c..e1899bfb 100644 --- a/lorien/InfiniteCanvas/Tools/TextBoxTool.gd +++ b/lorien/InfiniteCanvas/Tools/TextBoxTool.gd @@ -5,6 +5,7 @@ extends CanvasTool var textBoxInstance : TextBox2 signal text_box_tool_reset +signal show_textBoxDialog enum State { CREATING, @@ -27,30 +28,4 @@ func tool_event(event: InputEvent) -> void: if event.button_index == MOUSE_BUTTON_LEFT: if event.pressed && _state == State.CREATING: _state = State.EDITING - textBoxInstance = _textBox.instantiate() - textBoxInstance.set_position(event.position) - textBoxInstance.textBox_ok.connect(save_label) - textBoxInstance.exclusive = true - _position = _cursor.global_position - add_child(textBoxInstance) - var window_position : Vector2i = DisplayServer.window_get_position(0) - textBoxInstance.get_window_id() - print(DisplayServer.get_window_list()[1]) - DisplayServer.window_set_current_screen(DisplayServer.window_get_current_screen(0), DisplayServer.get_window_list()[1]) - -func save_label(value : String) -> void: - var label : Label = Label.new() - label.text = value - label.set_position(_position) - _canvas._create_textbox(label) - _state = State.CREATING - -# ------------------------------------------------------------------------------------------------ -#func reset() -> void: -# _state = State.CREATING - #if textBoxInstance != null: - #textBoxInstance.release_focus() - # textBoxInstance = null -# print("Reset in TextBoxTool") - - + show_textBoxDialog.emit(_cursor.global_position) diff --git a/lorien/ProjectManager/Project.gd b/lorien/ProjectManager/Project.gd index 8ca7806e..c9b3ea3f 100644 --- a/lorien/ProjectManager/Project.gd +++ b/lorien/ProjectManager/Project.gd @@ -17,6 +17,7 @@ var loaded := false var filepath: String var meta_data: Dictionary var strokes: Array[BrushStroke] +var textBoxes : Array[TextBox] # ------------------------------------------------------------------------------------------------- func _init() -> void: @@ -34,6 +35,7 @@ func clear() -> void: undo_redo = null meta_data.clear() strokes.clear() + textBoxes.clear() # ------------------------------------------------------------------------------------------------- func add_stroke(stroke: BrushStroke) -> void: @@ -45,6 +47,11 @@ func remove_last_stroke() -> void: if !strokes.is_empty(): strokes.pop_back() +#------------------------------------------------------------------------------------------------- +func add_text_box(textBox : TextBox) -> void: + textBoxes.append(textBox) + dirty = true + # ------------------------------------------------------------------------------------------------- func get_scene_file_path() -> String: if filepath.is_empty(): diff --git a/lorien/ProjectManager/Serializer.gd b/lorien/ProjectManager/Serializer.gd index bf348f28..a7790eef 100644 --- a/lorien/ProjectManager/Serializer.gd +++ b/lorien/ProjectManager/Serializer.gd @@ -6,12 +6,14 @@ class_name Serializer # ------------------------------------------------------------------------------------------------- const BRUSH_STROKE = preload("res://BrushStroke/BrushStroke.tscn") +const TEXT_BOX = preload("res://TextBox/TextBox.tscn") const COMPRESSION_METHOD = FileAccess.COMPRESSION_DEFLATE const POINT_ELEM_SIZE := 3 const VERSION_NUMBER := 1 const TYPE_BRUSH_STROKE := 0 const TYPE_ERASER_STROKE_DEPRECATED := 1 # Deprecated since v0; will be ignored when read; structually the same as normal brush stroke +const TYPE_TEXT_BOX := 2 # ------------------------------------------------------------------------------------------------- static func save_project(project: Project) -> void: @@ -53,7 +55,14 @@ static func save_project(project: Project) -> void: file.store_8(pressure) p_idx += 1 - # Done + # Text Box Data + for textBox : TextBox in project.textBoxes: + file.store_8(TYPE_TEXT_BOX) + file.store_float(textBox.global_position.x) + file.store_float(textBox.global_position.y) + file.store_pascal_string(textBox.text) + + # Done file.close() print("Saved %s in %d ms" % [project.filepath, (Time.get_ticks_msec() - start_time)]) @@ -109,6 +118,15 @@ static func load_project(project: Project) -> void: print("Skipped deprecated eraser stroke: %d points" % point_count) else: project.strokes.append(brush_stroke) + TYPE_TEXT_BOX: + var x = file.get_float() + var y = file.get_float() + var text = file.get_pascal_string() + var textBox : TextBox = TextBox.new() + textBox.set_global_position(Vector2(x,y)) + textBox.text = text; + + project.textBoxes.append(textBox) _: printerr("Invalid type") diff --git a/lorien/TextBox/Panel.gd b/lorien/TextBox/Panel.gd new file mode 100644 index 00000000..ac516c42 --- /dev/null +++ b/lorien/TextBox/Panel.gd @@ -0,0 +1,5 @@ +extends Panel + +func _unhandled_key_input(event: InputEvent) -> void: + if event is InputEventMouseButton: + print("CLICK TEST") diff --git a/lorien/TextBox/TextBox.gd b/lorien/TextBox/TextBox.gd index 400b9441..49cecc07 100644 --- a/lorien/TextBox/TextBox.gd +++ b/lorien/TextBox/TextBox.gd @@ -1,55 +1 @@ -class_name TextBox extends Control - -@onready var _textEdit : TextEdit = $VBoxContainer/PanelContainer/TextEdit -@onready var _label : Label = $VBoxContainer/PanelContainer/Label -@onready var _btn_ok : Button = $VBoxContainer/HBoxContainer/btn_ok -@onready var _btn_cancel : Button = $VBoxContainer/HBoxContainer/btn_cancel -@onready var _panel : PanelContainer = $VBoxContainer/PanelContainer - -signal label_created - -#func _on_text_edit_focus_exited() -> void: - #_label.text = _textEdit.text - #_textEdit.hide() - #_label.show() - #_btn_cancel.hide() - #_btn_ok.hide() - #_textEdit.release_focus() - #label_created.emit() - ## Find Infinit canvas and give focus back - -func _on_btn_ok_button_up() -> void: - _label.text = _textEdit.text - _textEdit.hide() - _btn_cancel.hide() - _btn_ok.hide() - _label.show() - #_textEdit.release_focus() - #_label.grab_focus() - label_created.emit() - - -func _on_btn_cancel_button_up() -> void: - #_textEdit.release_focus() - call_deferred("queue_free") - label_created.emit() - - -func _on_text_edit_mouse_exited() -> void: - print("Mouse Exited Text Edit") - - -func _on_panel_container_mouse_exited() -> void: - print("Mouse left container") - - -func _on_v_box_container_mouse_exited() -> void: - print("Mouse left VBox") - - -func _on_label_focus_entered() -> void: - print("label focus entered") - - -func _on_label_focus_exited() -> void: - print("label focus exited") +class_name TextBox extends Label diff --git a/lorien/TextBox/TextBox.tscn b/lorien/TextBox/TextBox.tscn index 3631715a..758a2e11 100644 --- a/lorien/TextBox/TextBox.tscn +++ b/lorien/TextBox/TextBox.tscn @@ -10,45 +10,3 @@ anchor_bottom = 1.0 grow_horizontal = 2 grow_vertical = 2 script = ExtResource("1_cx17r") - -[node name="VBoxContainer" type="VBoxContainer" parent="."] -layout_mode = 0 -offset_right = 40.0 -offset_bottom = 40.0 - -[node name="HBoxContainer" type="HBoxContainer" parent="VBoxContainer"] -layout_mode = 2 - -[node name="btn_ok" type="Button" parent="VBoxContainer/HBoxContainer"] -layout_mode = 2 -size_flags_horizontal = 0 -size_flags_vertical = 8 -text = "OK" - -[node name="btn_cancel" type="Button" parent="VBoxContainer/HBoxContainer"] -layout_mode = 2 -size_flags_horizontal = 8 -size_flags_vertical = 8 -text = "Cancel" - -[node name="PanelContainer" type="PanelContainer" parent="VBoxContainer"] -custom_minimum_size = Vector2(300, 25) -layout_mode = 2 - -[node name="Label" type="Label" parent="VBoxContainer/PanelContainer"] -visible = false -layout_mode = 2 - -[node name="TextEdit" type="TextEdit" parent="VBoxContainer/PanelContainer"] -layout_mode = 2 -wrap_mode = 1 -scroll_fit_content_height = true - -[connection signal="mouse_exited" from="VBoxContainer" to="." method="_on_v_box_container_mouse_exited"] -[connection signal="button_up" from="VBoxContainer/HBoxContainer/btn_ok" to="." method="_on_btn_ok_button_up"] -[connection signal="button_up" from="VBoxContainer/HBoxContainer/btn_cancel" to="." method="_on_btn_cancel_button_up"] -[connection signal="mouse_exited" from="VBoxContainer/PanelContainer" to="." method="_on_panel_container_mouse_exited"] -[connection signal="focus_entered" from="VBoxContainer/PanelContainer/Label" to="." method="_on_label_focus_entered"] -[connection signal="focus_exited" from="VBoxContainer/PanelContainer/Label" to="." method="_on_label_focus_exited"] -[connection signal="focus_exited" from="VBoxContainer/PanelContainer/TextEdit" to="." method="_on_text_edit_focus_exited"] -[connection signal="mouse_exited" from="VBoxContainer/PanelContainer/TextEdit" to="." method="_on_text_edit_mouse_exited"] diff --git a/lorien/TextBox/TextBox2.gd b/lorien/TextBox/TextBox2.gd index 2bc87a39..35965bde 100644 --- a/lorien/TextBox/TextBox2.gd +++ b/lorien/TextBox/TextBox2.gd @@ -1,21 +1,28 @@ -class_name TextBox2 extends PopupPanel +class_name TextBox2 extends PanelContainer @onready -var textEdit : TextEdit = $Control/VBoxContainer/TextEdit +var textEdit : TextEdit = $Panel/VBoxContainer/TextEdit signal textBox_ok signal textBox_cancel +var label_position : Vector2 -# Called when the node enters the scene tree for the first time. -func _ready() -> void: - pass # Replace with function body. - +func _on_save_button_pressed() -> void: + textBox_ok.emit(textEdit.text, label_position) + textEdit.text = "" + visible = false -# Called every frame. 'delta' is the elapsed time since the previous frame. -func _process(delta: float) -> void: - pass +func _unhandled_key_input(event: InputEvent) -> void: + if event is InputEventMouseButton: + textEdit.text = "" + visible = false +func _on_close_requested() -> void: + textBox_cancel.emit() + textEdit.text = "" + visible = false -func _on_save_button_pressed() -> void: - textBox_ok.emit(textEdit.text) - queue_free() +func _on_cancel_button_pressed() -> void: + textBox_cancel.emit() + textEdit.text = "" + visible = false diff --git a/lorien/TextBox/TextBox2.tscn b/lorien/TextBox/TextBox2.tscn index ad2dbdf5..7429f995 100644 --- a/lorien/TextBox/TextBox2.tscn +++ b/lorien/TextBox/TextBox2.tscn @@ -1,42 +1,49 @@ -[gd_scene load_steps=2 format=3 uid="uid://ccl05i282g120"] +[gd_scene load_steps=3 format=3 uid="uid://ccl05i282g120"] [ext_resource type="Script" path="res://TextBox/TextBox2.gd" id="1_pskl6"] +[ext_resource type="Script" path="res://TextBox/Panel.gd" id="2_mvgor"] -[node name="PopupPanel" type="PopupPanel"] -size = Vector2i(200, 200) -visible = true -always_on_top = true +[node name="PopupPanel" type="PanelContainer"] +visible = false +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 script = ExtResource("1_pskl6") -[node name="Control" type="Control" parent="."] -layout_mode = 3 -anchors_preset = 0 -offset_left = 4.0 -offset_top = 4.0 -offset_right = 196.0 -offset_bottom = 196.0 +[node name="Panel" type="Panel" parent="."] +layout_mode = 2 +script = ExtResource("2_mvgor") -[node name="VBoxContainer" type="VBoxContainer" parent="Control"] +[node name="VBoxContainer" type="VBoxContainer" parent="Panel"] layout_mode = 1 -anchors_preset = 15 -anchor_right = 1.0 -anchor_bottom = 1.0 +anchors_preset = 8 +anchor_left = 0.5 +anchor_top = 0.5 +anchor_right = 0.5 +anchor_bottom = 0.5 +offset_left = 26.0 +offset_top = -12.5 +offset_right = 134.0 +offset_bottom = 172.5 grow_horizontal = 2 grow_vertical = 2 -[node name="TextEdit" type="TextEdit" parent="Control/VBoxContainer"] +[node name="TextEdit" type="TextEdit" parent="Panel/VBoxContainer"] custom_minimum_size = Vector2(100, 150) layout_mode = 2 -[node name="HBoxContainer" type="HBoxContainer" parent="Control/VBoxContainer"] +[node name="HBoxContainer" type="HBoxContainer" parent="Panel/VBoxContainer"] layout_mode = 2 -[node name="SaveButton" type="Button" parent="Control/VBoxContainer/HBoxContainer"] +[node name="SaveButton" type="Button" parent="Panel/VBoxContainer/HBoxContainer"] layout_mode = 2 text = "Save" -[node name="CancelButton" type="Button" parent="Control/VBoxContainer/HBoxContainer"] +[node name="CancelButton" type="Button" parent="Panel/VBoxContainer/HBoxContainer"] layout_mode = 2 text = "Cancel" -[connection signal="pressed" from="Control/VBoxContainer/HBoxContainer/SaveButton" to="." method="_on_save_button_pressed"] +[connection signal="pressed" from="Panel/VBoxContainer/HBoxContainer/SaveButton" to="." method="_on_save_button_pressed"] +[connection signal="pressed" from="Panel/VBoxContainer/HBoxContainer/CancelButton" to="." method="_on_cancel_button_pressed"] diff --git a/lorien/UI/Themes/theme_dark.tres b/lorien/UI/Themes/theme_dark.tres index 0dfa382c..d70eac36 100644 --- a/lorien/UI/Themes/theme_dark.tres +++ b/lorien/UI/Themes/theme_dark.tres @@ -1,6 +1,5 @@ -[gd_resource type="Theme" load_steps=27 format=4 uid="uid://u5qnpgxqykiv"] +[gd_resource type="Theme" load_steps=26 format=4 uid="uid://u5qnpgxqykiv"] -[ext_resource type="Texture2D" uid="uid://bp1yka17gbjtu" path="res://Assets/Icons/close.png" id="1_qgxa7"] [ext_resource type="StyleBox" uid="uid://kdduww61cjw" path="res://UI/Themes/tab_inactive_dark.tres" id="2_n6mkw"] [ext_resource type="StyleBox" uid="uid://dtn7ehcyfik4a" path="res://UI/Themes/tab_active_dark.tres" id="3_rqnin"] @@ -2562,7 +2561,7 @@ TabBar/constants/h_separation = 4 TabBar/constants/icon_max_width = 0 TabBar/constants/outline_size = 0 TabBar/fonts/font = SubResource("FontFile_1bm21") -TabBar/icons/close = ExtResource("1_qgxa7") +TabBar/icons/close = null TabBar/styles/button_highlight = SubResource("StyleBoxEmpty_me351") TabBar/styles/button_pressed = SubResource("StyleBoxEmpty_n0chp") TabBar/styles/tab_disabled = ExtResource("2_n6mkw") From d2befa48fd364af6caa1c47e624e37c668cd12c3 Mon Sep 17 00:00:00 2001 From: Marco Eibensteiner Date: Sat, 24 May 2025 23:33:25 +0200 Subject: [PATCH 04/16] Added possibility to select and move text labels --- lorien/InfiniteCanvas/InfiniteCanvas.gd | 2 + lorien/InfiniteCanvas/InfiniteCanvas.tscn | 1 - lorien/InfiniteCanvas/Tools/EraserTool.gd | 3 +- lorien/InfiniteCanvas/Tools/SelectionTool.gd | 103 ++++++++++++++++++- lorien/Main.gd | 4 +- lorien/Misc/Utils.gd | 8 +- lorien/ProjectManager/Serializer.gd | 6 +- lorien/TextBox/Panel.gd | 11 ++ lorien/TextBox/TextBox2.gd | 14 +++ lorien/TextBox/TextBox2.tscn | 24 ++++- 10 files changed, 159 insertions(+), 17 deletions(-) diff --git a/lorien/InfiniteCanvas/InfiniteCanvas.gd b/lorien/InfiniteCanvas/InfiniteCanvas.gd index b4dcee5b..fdcff6a1 100644 --- a/lorien/InfiniteCanvas/InfiniteCanvas.gd +++ b/lorien/InfiniteCanvas/InfiniteCanvas.gd @@ -197,6 +197,8 @@ func get_strokes_in_camera_frustrum() -> Array: 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) diff --git a/lorien/InfiniteCanvas/InfiniteCanvas.tscn b/lorien/InfiniteCanvas/InfiniteCanvas.tscn index b1856244..48efb867 100644 --- a/lorien/InfiniteCanvas/InfiniteCanvas.tscn +++ b/lorien/InfiniteCanvas/InfiniteCanvas.tscn @@ -29,7 +29,6 @@ anchor_bottom = 1.0 script = ExtResource("1") [node name="TextBoxEditor" parent="." instance=ExtResource("10_gdd0v")] -visible = true layout_mode = 2 [node name="BrushTool" type="Node" parent="."] diff --git a/lorien/InfiniteCanvas/Tools/EraserTool.gd b/lorien/InfiniteCanvas/Tools/EraserTool.gd index de1d821e..afbf8e3a 100644 --- a/lorien/InfiniteCanvas/Tools/EraserTool.gd +++ b/lorien/InfiniteCanvas/Tools/EraserTool.gd @@ -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()) # ------------------------------------------------------------------------------------------------ diff --git a/lorien/InfiniteCanvas/Tools/SelectionTool.gd b/lorien/InfiniteCanvas/Tools/SelectionTool.gd index 1ae69d1e..b55796ab 100644 --- a/lorien/InfiniteCanvas/Tools/SelectionTool.gd +++ b/lorien/InfiniteCanvas/Tools/SelectionTool.gd @@ -8,8 +8,11 @@ const MAX_FLOAT := 2147483646.0 const MIN_FLOAT := -2147483646.0 const META_OFFSET := "offset" const GROUP_SELECTED_STROKES := "selected_strokes" # selected strokes +const GROUP_SELECTED_TEXT_BOXES := "selected_text_boxes" const GROUP_STROKES_IN_SELECTION_RECTANGLE := "strokes_in_selection_rectangle" # strokes that are in selection rectangle but not commit (i.e. the user is still selecting) +const GROUP_TEXT_BOXES__IN_SELECTION_RECTANGLE := "text_boxes_in_selection_rectangle" # strokes that are in selection rectangle but not commit (i.e. the user is still selecting) const GROUP_MARKED_FOR_DESELECTION := "strokes_marked_for_deselection" # strokes that need to be deslected once LMB is released +const GROUP_MARKED_TEXT_BOXES_FOR_DESELECTION = "text_boxes_marked_for_deselection" const GROUP_COPIED_STROKES := "strokes_copied" # ------------------------------------------------------------------------------------------------- @@ -28,6 +31,7 @@ var _selecting_end_pos: Vector2 = Vector2.ZERO var _multi_selecting: bool var _mouse_moved_during_pressed := false var _stroke_positions_before_move := {} # BrushStroke -> Vector2 +var _text_box_positions_before_move := {} # TextBox -> Vector2 var _bounding_box_cache := {} # BrushStroke -> Rect2 # ------------------------------------------------------------------------------------------------ @@ -54,28 +58,36 @@ func tool_event(event: InputEvent) -> void: var strokes := get_tree().get_nodes_in_group(GROUP_COPIED_STROKES) if !strokes.is_empty(): deselect_all_strokes() + deselect_all_text_boxes() _cursor.mode = SelectionCursor.Mode.MOVE _paste_strokes(strokes) if event is InputEventMouseButton && !disable_stroke: if event.button_index == MOUSE_BUTTON_LEFT: # LMB down - decide if we should select/multiselect or move the selection + print("selected strokes", get_selected_strokes().size()) + print("selected text boxes", get_selected_strokes().size()) if event.pressed: _selecting_start_pos = _cursor.global_position if event.shift_pressed: _state = State.SELECTING _multi_selecting = true _build_bounding_boxes() - elif get_selected_strokes().size() == 0: + elif get_selected_strokes().size() == 0 && get_selected_text_boxes().size() == 0: + print("Nothing Selected") _state = State.SELECTING _multi_selecting = false _build_bounding_boxes() else: + print("Else Moving") _state = State.MOVING _mouse_moved_during_pressed = false _offset_selected_strokes(_cursor.global_position) + _offset_selected_text_boxes(_cursor.global_position) for s: BrushStroke in get_selected_strokes(): _stroke_positions_before_move[s] = s.global_position + for t: TextBox in get_selected_text_boxes(): + _text_box_positions_before_move[t] = t.global_position # LMB up - stop selection or movement else: if _state == State.SELECTING: @@ -83,21 +95,27 @@ func tool_event(event: InputEvent) -> void: _selection_rectangle.reset() _selection_rectangle.queue_redraw() _commit_strokes_under_selection_rectangle() + _commit_text_boxes_under_selection_rectangle() _deselect_marked_strokes() - if get_selected_strokes().size() > 0: + _deselect_marked_text_boxes() + if get_selected_strokes().size() > 0 || get_selected_text_boxes().size() > 0: _cursor.mode = SelectionCursor.Mode.MOVE elif _state == State.MOVING: _state = State.NONE if _mouse_moved_during_pressed: _add_undoredo_action_for_moved_strokes() + #_add_undoredo_action_for_moved_text_boxes() _stroke_positions_before_move.clear() + _text_box_positions_before_move.clear() else: deselect_all_strokes() + deselect_all_text_boxes() _mouse_moved_during_pressed = false # RMB down - just deselect elif event.button_index == MOUSE_BUTTON_RIGHT && event.pressed && _state == State.NONE: deselect_all_strokes() + deselect_all_text_boxes() # Mouse movement: move the selection elif event is InputEventMouseMotion: @@ -111,13 +129,14 @@ func tool_event(event: InputEvent) -> void: elif _state == State.MOVING: _mouse_moved_during_pressed = true _move_selected_strokes() + _move_selected_text_boxes() # Shift click - switch between move/select cursor mode elif event is InputEventKey: if event.keycode == KEY_SHIFT: if event.pressed: _cursor.mode = SelectionCursor.Mode.SELECT - elif get_selected_strokes().size() > 0: + elif get_selected_strokes().size() > 0 || get_selected_text_boxes().size() > 0: _cursor.mode = SelectionCursor.Mode.MOVE # ------------------------------------------------------------------------------------------------ @@ -131,6 +150,10 @@ func compute_selection(start_pos: Vector2, end_pos: Vector2) -> void: if selection_rect.has_point(abs_point): _set_stroke_selected(stroke) break + for textBox: TextBox in _canvas.get_all_text_boxes(): + var bounding_text_box_box: Rect2 = textBox.get_global_rect() + if selection_rect.intersects(bounding_text_box_box): + _set_text_box_selected(textBox) _canvas.info.selected_lines = get_selected_strokes().size() # ------------------------------------------------------------------------------------------------ @@ -176,7 +199,7 @@ func _modify_strokes_colors(strokes: Array[BrushStroke], color: Color) -> void: # ------------------------------------------------------------------------------------------------ func _build_bounding_boxes() -> void: _bounding_box_cache.clear() - _bounding_box_cache = Utils.calculte_bounding_boxes(_canvas.get_all_strokes()) + _bounding_box_cache = Utils.calculte_bounding_boxes(_canvas.get_all_strokes(), _canvas.get_all_text_boxes()) #$"../Viewport/DebugDraw".set_bounding_boxes(_bounding_box_cache.values()) # ------------------------------------------------------------------------------------------------ @@ -187,7 +210,16 @@ func _set_stroke_selected(stroke: BrushStroke) -> void: else: stroke.modulate = Config.DEFAULT_SELECTION_COLOR stroke.add_to_group(GROUP_STROKES_IN_SELECTION_RECTANGLE) - + +# ------------------------------------------------------------------------------------------------ +func _set_text_box_selected(text_box : TextBox) -> void: + if text_box.is_in_group(GROUP_SELECTED_TEXT_BOXES): + text_box.modulate = Color.WHITE + text_box.add_to_group(GROUP_MARKED_TEXT_BOXES_FOR_DESELECTION) + else: + text_box.modulate = Config.DEFAULT_SELECTION_COLOR + text_box.add_to_group(GROUP_TEXT_BOXES__IN_SELECTION_RECTANGLE) + # ------------------------------------------------------------------------------------------------ func _add_undoredo_action_for_moved_strokes() -> void: var project: Project = ProjectManager.get_active_project() @@ -195,6 +227,19 @@ func _add_undoredo_action_for_moved_strokes() -> void: for stroke: BrushStroke in _stroke_positions_before_move.keys(): project.undo_redo.add_do_property(stroke, "global_position", stroke.global_position) project.undo_redo.add_undo_property(stroke, "global_position", _stroke_positions_before_move[stroke]) + for text_box: TextBox in _text_box_positions_before_move.keys(): + project.undo_redo.add_do_property(text_box, "global_position", text_box.global_position) + project.undo_redo.add_undo_property(text_box, "global_position", _text_box_positions_before_move[text_box]) + project.undo_redo.commit_action() + project.dirty = true + +# ------------------------------------------------------------------------------------------------ +func _add_undoredo_action_for_moved_text_boxes() -> void: + var project: Project = ProjectManager.get_active_project() + project.undo_redo.create_action("Move Text_Boxes") + for text_box: TextBox in _text_box_positions_before_move.keys(): + project.undo_redo.add_do_property(text_box, "global_position", text_box.global_position) + project.undo_redo.add_undo_property(text_box, "global_position", _text_box_positions_before_move[text_box]) project.undo_redo.commit_action() project.dirty = true @@ -202,18 +247,35 @@ func _add_undoredo_action_for_moved_strokes() -> void: func _offset_selected_strokes(offset: Vector2) -> void: for stroke: BrushStroke in get_selected_strokes(): stroke.set_meta(META_OFFSET, stroke.position - offset) + +# ------------------------------------------------------------------------------------------------- +func _offset_selected_text_boxes(offset: Vector2) -> void: + for text_box: TextBox in get_selected_text_boxes(): + text_box.set_meta(META_OFFSET, text_box.position - offset) # ------------------------------------------------------------------------------------------------- func _move_selected_strokes() -> void: for stroke: BrushStroke in get_selected_strokes(): stroke.global_position = stroke.get_meta(META_OFFSET) + _cursor.global_position +# ------------------------------------------------------------------------------------------------- +func _move_selected_text_boxes() -> void: + for text_box: TextBox in get_selected_text_boxes(): + text_box.global_position = text_box.get_meta(META_OFFSET) + _cursor.global_position + # ------------------------------------------------------------------------------------------------ func _commit_strokes_under_selection_rectangle() -> void: for stroke: BrushStroke in get_tree().get_nodes_in_group(GROUP_STROKES_IN_SELECTION_RECTANGLE): stroke.remove_from_group(GROUP_STROKES_IN_SELECTION_RECTANGLE) stroke.add_to_group(GROUP_SELECTED_STROKES) +# ------------------------------------------------------------------------------------------------ +func _commit_text_boxes_under_selection_rectangle() -> void: + for text_box: TextBox in get_tree().get_nodes_in_group(GROUP_TEXT_BOXES__IN_SELECTION_RECTANGLE): + text_box.remove_from_group(GROUP_TEXT_BOXES__IN_SELECTION_RECTANGLE) + text_box.add_to_group(GROUP_SELECTED_TEXT_BOXES) + print(get_selected_text_boxes()) + # ------------------------------------------------------------------------------------------------ func _deselect_marked_strokes() -> void: for stroke: BrushStroke in get_tree().get_nodes_in_group(GROUP_MARKED_FOR_DESELECTION): @@ -221,6 +283,13 @@ func _deselect_marked_strokes() -> void: stroke.remove_from_group(GROUP_SELECTED_STROKES) stroke.modulate = Color.WHITE +# ------------------------------------------------------------------------------------------------ +func _deselect_marked_text_boxes() -> void: + for textBox: TextBox in get_tree().get_nodes_in_group(GROUP_MARKED_TEXT_BOXES_FOR_DESELECTION): + textBox.remove_from_group(GROUP_MARKED_TEXT_BOXES_FOR_DESELECTION) + textBox.remove_from_group(GROUP_SELECTED_TEXT_BOXES) + textBox.modulate = Color.WHITE + # ------------------------------------------------------------------------------------------------ func deselect_all_strokes() -> void: var selected_strokes: Array = get_selected_strokes() @@ -234,6 +303,18 @@ func deselect_all_strokes() -> void: _canvas.info.selected_lines = 0 _cursor.mode = SelectionCursor.Mode.SELECT +# ------------------------------------------------------------------------------------------------ +func deselect_all_text_boxes() -> void: + var selected_text_boxes: Array = get_selected_text_boxes() + if selected_text_boxes.size(): + get_tree().set_group(GROUP_SELECTED_TEXT_BOXES, "modulate", Color.WHITE) + get_tree().set_group(GROUP_TEXT_BOXES__IN_SELECTION_RECTANGLE, "modulate", Color.WHITE) + Utils.remove_group_from_all_nodes(GROUP_SELECTED_TEXT_BOXES) + Utils.remove_group_from_all_nodes(GROUP_MARKED_TEXT_BOXES_FOR_DESELECTION) + Utils.remove_group_from_all_nodes(GROUP_TEXT_BOXES__IN_SELECTION_RECTANGLE) + + _cursor.mode = SelectionCursor.Mode.SELECT + # ------------------------------------------------------------------------------------------------ func is_selecting() -> bool: return _state == State.SELECTING @@ -248,6 +329,16 @@ func get_selected_strokes() -> Array[BrushStroke]: return strokes +# ------------------------------------------------------------------------------------------------ +func get_selected_text_boxes() -> Array[TextBox]: + # Can't cast from Array[Node] to Array[TextBox] directly (godot bug/missing feature?) + # so let's do it per item + var text_boxes: Array[TextBox] + for text_box in get_tree().get_nodes_in_group(GROUP_SELECTED_TEXT_BOXES): + text_boxes.append(text_box as TextBox) + + return text_boxes + # ------------------------------------------------------------------------------------------------ func _on_brush_color_changed(color: Color) -> void: var strokes := get_selected_strokes() @@ -259,4 +350,6 @@ func reset() -> void: _selection_rectangle.reset() _selection_rectangle.queue_redraw() _commit_strokes_under_selection_rectangle() + _commit_text_boxes_under_selection_rectangle() deselect_all_strokes() + deselect_all_text_boxes() diff --git a/lorien/Main.gd b/lorien/Main.gd index 9d6d2c7a..3adc0cf7 100644 --- a/lorien/Main.gd +++ b/lorien/Main.gd @@ -144,7 +144,9 @@ func _process(delta: float) -> void: var active_project: Project = ProjectManager.get_active_project() if active_project != null: _menubar.update_tab_title(active_project) - + + var nodes_in_group = get_tree().get_nodes_in_group("text_boxes_in_selection_rectangle") + # ------------------------------------------------------------------------------------------------- func _unhandled_input(event: InputEvent) -> void: # Idle time over; let's set the fps high again diff --git a/lorien/Misc/Utils.gd b/lorien/Misc/Utils.gd index 3d8617a0..cd3256e8 100644 --- a/lorien/Misc/Utils.gd +++ b/lorien/Misc/Utils.gd @@ -43,7 +43,7 @@ func calculate_rect(start_pos: Vector2, end_pos: Vector2) -> Rect2: return area # ------------------------------------------------------------------------------------------------- -func calculte_bounding_boxes(strokes: Array[BrushStroke], margin: float = 0.0) -> Dictionary: +func calculte_bounding_boxes(strokes: Array[BrushStroke], text_boxes: Array[TextBox], margin: float = 0.0) -> Dictionary: var result := {} for stroke: BrushStroke in strokes: var top_left := stroke.position + stroke.top_left_pos @@ -52,6 +52,12 @@ func calculte_bounding_boxes(strokes: Array[BrushStroke], margin: float = 0.0) - if margin > 0: bounding_box = bounding_box.grow(margin) result[stroke] = bounding_box + + for text_box : TextBox in text_boxes: + var text_box_bounding_box := text_box.get_global_rect() + #if margin > 0: + # text_box_bounding_box := text_box_bounding_box.grow(margin) + result[text_box] = text_box_bounding_box return result # ------------------------------------------------------------------------------------------------- diff --git a/lorien/ProjectManager/Serializer.gd b/lorien/ProjectManager/Serializer.gd index a7790eef..1d5a2909 100644 --- a/lorien/ProjectManager/Serializer.gd +++ b/lorien/ProjectManager/Serializer.gd @@ -11,9 +11,9 @@ const COMPRESSION_METHOD = FileAccess.COMPRESSION_DEFLATE const POINT_ELEM_SIZE := 3 const VERSION_NUMBER := 1 -const TYPE_BRUSH_STROKE := 0 -const TYPE_ERASER_STROKE_DEPRECATED := 1 # Deprecated since v0; will be ignored when read; structually the same as normal brush stroke -const TYPE_TEXT_BOX := 2 +const TYPE_BRUSH_STROKE : int = 0 +const TYPE_ERASER_STROKE_DEPRECATED : int = 1 # Deprecated since v0; will be ignored when read; structually the same as normal brush stroke +const TYPE_TEXT_BOX : int = 2 # ------------------------------------------------------------------------------------------------- static func save_project(project: Project) -> void: diff --git a/lorien/TextBox/Panel.gd b/lorien/TextBox/Panel.gd index ac516c42..e3d857e6 100644 --- a/lorien/TextBox/Panel.gd +++ b/lorien/TextBox/Panel.gd @@ -1,5 +1,16 @@ extends Panel +signal close_click + +func _gui_input(event: InputEvent) -> void: + print("CLICK TEST 1") + if event is InputEventMouseButton: + print("Click Test 2") + if event.button_index == MOUSE_BUTTON_LEFT: + if event.pressed: + close_click.emit() + + func _unhandled_key_input(event: InputEvent) -> void: if event is InputEventMouseButton: print("CLICK TEST") diff --git a/lorien/TextBox/TextBox2.gd b/lorien/TextBox/TextBox2.gd index 35965bde..404cb1b9 100644 --- a/lorien/TextBox/TextBox2.gd +++ b/lorien/TextBox/TextBox2.gd @@ -2,6 +2,8 @@ class_name TextBox2 extends PanelContainer @onready var textEdit : TextEdit = $Panel/VBoxContainer/TextEdit +@onready +var saveButton : Button = $Panel/VBoxContainer/HBoxContainer/SaveButton signal textBox_ok signal textBox_cancel @@ -26,3 +28,15 @@ func _on_cancel_button_pressed() -> void: textBox_cancel.emit() textEdit.text = "" visible = false + + +func _on_panel_close_click() -> void: + textBox_cancel.emit() + textEdit.text = "" + visible = false + + +func _on_visibility_changed() -> void: + if visible: + textEdit.grab_focus() + diff --git a/lorien/TextBox/TextBox2.tscn b/lorien/TextBox/TextBox2.tscn index 7429f995..4ec436f2 100644 --- a/lorien/TextBox/TextBox2.tscn +++ b/lorien/TextBox/TextBox2.tscn @@ -23,27 +23,41 @@ anchor_left = 0.5 anchor_top = 0.5 anchor_right = 0.5 anchor_bottom = 0.5 -offset_left = 26.0 -offset_top = -12.5 -offset_right = 134.0 -offset_bottom = 172.5 +offset_left = -125.0 +offset_top = -100.0 +offset_right = 125.0 +offset_bottom = 100.0 grow_horizontal = 2 grow_vertical = 2 [node name="TextEdit" type="TextEdit" parent="Panel/VBoxContainer"] -custom_minimum_size = Vector2(100, 150) +custom_minimum_size = Vector2(200, 150) layout_mode = 2 +size_flags_horizontal = 4 +focus_next = NodePath("../HBoxContainer/SaveButton") +focus_previous = NodePath("../HBoxContainer/CancelButton") [node name="HBoxContainer" type="HBoxContainer" parent="Panel/VBoxContainer"] layout_mode = 2 +size_flags_horizontal = 4 [node name="SaveButton" type="Button" parent="Panel/VBoxContainer/HBoxContainer"] layout_mode = 2 +focus_neighbor_left = NodePath("../CancelButton") +focus_neighbor_right = NodePath("../CancelButton") +focus_next = NodePath("../CancelButton") +focus_previous = NodePath("../CancelButton") text = "Save" [node name="CancelButton" type="Button" parent="Panel/VBoxContainer/HBoxContainer"] layout_mode = 2 +focus_neighbor_left = NodePath("../SaveButton") +focus_neighbor_right = NodePath("../SaveButton") +focus_next = NodePath("../SaveButton") +focus_previous = NodePath("../SaveButton") text = "Cancel" +[connection signal="visibility_changed" from="." to="." method="_on_visibility_changed"] +[connection signal="close_click" from="Panel" to="." method="_on_panel_close_click"] [connection signal="pressed" from="Panel/VBoxContainer/HBoxContainer/SaveButton" to="." method="_on_save_button_pressed"] [connection signal="pressed" from="Panel/VBoxContainer/HBoxContainer/CancelButton" to="." method="_on_cancel_button_pressed"] From 6d109971f0d4255951845857852e560a8ce05f18 Mon Sep 17 00:00:00 2001 From: Marco Eibensteiner Date: Tue, 27 May 2025 21:54:04 +0200 Subject: [PATCH 05/16] Added delete function and delete undo for textboxes --- lorien/InfiniteCanvas/InfiniteCanvas.gd | 31 +++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/lorien/InfiniteCanvas/InfiniteCanvas.gd b/lorien/InfiniteCanvas/InfiniteCanvas.gd index fdcff6a1..5e984ed3 100644 --- a/lorien/InfiniteCanvas/InfiniteCanvas.gd +++ b/lorien/InfiniteCanvas/InfiniteCanvas.gd @@ -102,10 +102,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) @@ -391,6 +393,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) @@ -399,6 +414,15 @@ func _do_delete_stroke(stroke: BrushStroke) -> void: info.point_count -= stroke.points.size() info.stroke_count -= 1 +# 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. + +# ------------------------------------------------------------------------------------------------- +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. # ------------------------------------------------------------------------------------------------- @@ -408,6 +432,13 @@ func _undo_delete_stroke(stroke: BrushStroke) -> void: 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 : Label) -> void: _textboxes_parent.add_child(textBox) From c94bf455ba4cc74cc74e8dcecae749baaf9ec9e7 Mon Sep 17 00:00:00 2001 From: Marco Eibensteiner Date: Wed, 28 May 2025 23:39:02 +0200 Subject: [PATCH 06/16] Enabled editing the existing text boxes --- lorien/InfiniteCanvas/InfiniteCanvas.gd | 15 ++++++++++++++- lorien/InfiniteCanvas/InfiniteCanvas.tscn | 2 ++ lorien/InfiniteCanvas/Tools/TextBoxTool.gd | 6 ++++++ lorien/TextBox/TextBox.gd | 7 +++++++ lorien/TextBox/TextBox.tscn | 11 +++++------ lorien/TextBox/TextBox2.gd | 11 +++++++++-- lorien/export_presets.cfg | 4 ++-- 7 files changed, 45 insertions(+), 11 deletions(-) diff --git a/lorien/InfiniteCanvas/InfiniteCanvas.gd b/lorien/InfiniteCanvas/InfiniteCanvas.gd index 5e984ed3..367c731c 100644 --- a/lorien/InfiniteCanvas/InfiniteCanvas.gd +++ b/lorien/InfiniteCanvas/InfiniteCanvas.gd @@ -440,7 +440,7 @@ func _undo_delete_text_box(text_box: TextBox) -> void: _textboxes_parent.add_child(text_box) # ------------------------------------------------------------------------------------------------- -func _create_textbox(textBox : Label) -> void: +func _create_textbox(textBox : TextBox) -> void: _textboxes_parent.add_child(textBox) _current_project.textBoxes.append(textBox) @@ -476,3 +476,16 @@ func _on_text_box_editor_text_box_ok(value : String, labelPosition : Vector2) -> 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: + print("Show Dialog for existing text Box") + _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 diff --git a/lorien/InfiniteCanvas/InfiniteCanvas.tscn b/lorien/InfiniteCanvas/InfiniteCanvas.tscn index 48efb867..5810c108 100644 --- a/lorien/InfiniteCanvas/InfiniteCanvas.tscn +++ b/lorien/InfiniteCanvas/InfiniteCanvas.tscn @@ -101,5 +101,7 @@ mouse_filter = 1 [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"] diff --git a/lorien/InfiniteCanvas/Tools/TextBoxTool.gd b/lorien/InfiniteCanvas/Tools/TextBoxTool.gd index e1899bfb..6fd3a0be 100644 --- a/lorien/InfiniteCanvas/Tools/TextBoxTool.gd +++ b/lorien/InfiniteCanvas/Tools/TextBoxTool.gd @@ -6,6 +6,7 @@ var textBoxInstance : TextBox2 signal text_box_tool_reset signal show_textBoxDialog +signal edit_existing_textBox enum State { CREATING, @@ -27,5 +28,10 @@ func tool_event(event: InputEvent) -> void: if event is InputEventMouseButton: if event.button_index == MOUSE_BUTTON_LEFT: if event.pressed && _state == State.CREATING: + print(event.global_position) + for textBox : TextBox in get_parent()._textboxes_parent.get_children(): + if textBox.get_rect().has_point(event.global_position): + print("Click inside TextBox") + edit_existing_textBox.emit(textBox) _state = State.EDITING show_textBoxDialog.emit(_cursor.global_position) diff --git a/lorien/TextBox/TextBox.gd b/lorien/TextBox/TextBox.gd index 49cecc07..9b17dce1 100644 --- a/lorien/TextBox/TextBox.gd +++ b/lorien/TextBox/TextBox.gd @@ -1 +1,8 @@ +@icon("res://Assets/Icons/text-block.png") class_name TextBox extends Label + +@export +var test : String + +func _gui_input(event: InputEvent) -> void: + print("GUI INPUT TEXTBOX") diff --git a/lorien/TextBox/TextBox.tscn b/lorien/TextBox/TextBox.tscn index 758a2e11..bbe3bb06 100644 --- a/lorien/TextBox/TextBox.tscn +++ b/lorien/TextBox/TextBox.tscn @@ -1,12 +1,11 @@ -[gd_scene load_steps=2 format=3 uid="uid://7dswpn8jua61"] +[gd_scene format=3 uid="uid://7dswpn8jua61"] -[ext_resource type="Script" path="res://TextBox/TextBox.gd" id="1_cx17r"] - -[node name="TextBox" type="Control"] -layout_mode = 3 +[node name="TextBox" type="Label"] anchors_preset = 15 anchor_right = 1.0 anchor_bottom = 1.0 grow_horizontal = 2 grow_vertical = 2 -script = ExtResource("1_cx17r") + +[connection signal="mouse_entered" from="." to="." method="_on_mouse_entered"] +[connection signal="mouse_exited" from="." to="." method="_on_mouse_exited"] diff --git a/lorien/TextBox/TextBox2.gd b/lorien/TextBox/TextBox2.gd index 404cb1b9..28ab942d 100644 --- a/lorien/TextBox/TextBox2.gd +++ b/lorien/TextBox/TextBox2.gd @@ -4,15 +4,23 @@ class_name TextBox2 extends PanelContainer var textEdit : TextEdit = $Panel/VBoxContainer/TextEdit @onready var saveButton : Button = $Panel/VBoxContainer/HBoxContainer/SaveButton +var textBox : TextBox signal textBox_ok signal textBox_cancel +signal textBox_ok_update var label_position : Vector2 func _on_save_button_pressed() -> void: - textBox_ok.emit(textEdit.text, label_position) + if textBox == null: + textBox_ok.emit(textEdit.text, label_position) + else: + textBox_ok_update.emit() + textBox.text = textEdit.text + textBox = null textEdit.text = "" visible = false + func _unhandled_key_input(event: InputEvent) -> void: if event is InputEventMouseButton: @@ -39,4 +47,3 @@ func _on_panel_close_click() -> void: func _on_visibility_changed() -> void: if visible: textEdit.grab_focus() - diff --git a/lorien/export_presets.cfg b/lorien/export_presets.cfg index 107264b1..4a610ad7 100644 --- a/lorien/export_presets.cfg +++ b/lorien/export_presets.cfg @@ -9,7 +9,7 @@ custom_features="" export_filter="all_resources" include_filter="Assets/I18N/*" exclude_filter="" -export_path="../../../Lorien.x86_64" +export_path="../../../Lorien_Test/Linux/Lorien.x86_64" encryption_include_filters="" encryption_exclude_filters="" encrypt_pck=false @@ -49,7 +49,7 @@ custom_features="" export_filter="all_resources" include_filter="Assets/I18N/*" exclude_filter="" -export_path="" +export_path="../../../Lorien_Test/Windows/Lorien.exe" encryption_include_filters="" encryption_exclude_filters="" encrypt_pck=false From b853ca4508fd8acf1e137748d7b491260428c693 Mon Sep 17 00:00:00 2001 From: Marco Eibensteiner Date: Fri, 30 May 2025 22:20:43 +0200 Subject: [PATCH 07/16] Added Possibility to change color of labels --- lorien/InfiniteCanvas/InfiniteCanvas.gd | 1 + lorien/InfiniteCanvas/Tools/SelectionTool.gd | 7 +++++++ lorien/ProjectManager/Serializer.gd | 9 +++++++++ lorien/TextBox/Panel.gd | 2 -- 4 files changed, 17 insertions(+), 2 deletions(-) diff --git a/lorien/InfiniteCanvas/InfiniteCanvas.gd b/lorien/InfiniteCanvas/InfiniteCanvas.gd index 367c731c..3fc9dad5 100644 --- a/lorien/InfiniteCanvas/InfiniteCanvas.gd +++ b/lorien/InfiniteCanvas/InfiniteCanvas.gd @@ -471,6 +471,7 @@ func _on_text_box_editor_text_box_ok(value : String, labelPosition : Vector2) -> 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 diff --git a/lorien/InfiniteCanvas/Tools/SelectionTool.gd b/lorien/InfiniteCanvas/Tools/SelectionTool.gd index b55796ab..52a00e0f 100644 --- a/lorien/InfiniteCanvas/Tools/SelectionTool.gd +++ b/lorien/InfiniteCanvas/Tools/SelectionTool.gd @@ -195,6 +195,11 @@ func _duplicate_stroke(stroke: BrushStroke, offset: Vector2) -> BrushStroke: func _modify_strokes_colors(strokes: Array[BrushStroke], color: Color) -> void: for stroke: BrushStroke in strokes: stroke.color = color + +# ------------------------------------------------------------------------------------------------ +func _modify_text_boxes_colors(text_boxes: Array[TextBox], color: Color) -> void: + for text_box: TextBox in text_boxes: + text_box.add_theme_color_override("font_color", color) # ------------------------------------------------------------------------------------------------ func _build_bounding_boxes() -> void: @@ -342,7 +347,9 @@ func get_selected_text_boxes() -> Array[TextBox]: # ------------------------------------------------------------------------------------------------ func _on_brush_color_changed(color: Color) -> void: var strokes := get_selected_strokes() + var text_boxes := get_selected_text_boxes() _modify_strokes_colors(strokes, color) + _modify_text_boxes_colors(text_boxes, color) # ------------------------------------------------------------------------------------------------ func reset() -> void: diff --git a/lorien/ProjectManager/Serializer.gd b/lorien/ProjectManager/Serializer.gd index 1d5a2909..b70b1123 100644 --- a/lorien/ProjectManager/Serializer.gd +++ b/lorien/ProjectManager/Serializer.gd @@ -61,6 +61,10 @@ static func save_project(project: Project) -> void: file.store_float(textBox.global_position.x) file.store_float(textBox.global_position.y) file.store_pascal_string(textBox.text) + var textBoxColor : Color = textBox.get("theme_override_colors/font_color") + file.store_8(textBoxColor.r8) + file.store_8(textBoxColor.g8) + file.store_8(textBoxColor.b8) # Done file.close() @@ -125,6 +129,11 @@ static func load_project(project: Project) -> void: var textBox : TextBox = TextBox.new() textBox.set_global_position(Vector2(x,y)) textBox.text = text; + var r := file.get_8() + var g := file.get_8() + var b := file.get_8() + var textBoxColor : Color = Color(r/255.0, g/255.0, b/255.0, 1.0) + textBox.add_theme_color_override("font_color", textBoxColor) project.textBoxes.append(textBox) _: diff --git a/lorien/TextBox/Panel.gd b/lorien/TextBox/Panel.gd index e3d857e6..87812f54 100644 --- a/lorien/TextBox/Panel.gd +++ b/lorien/TextBox/Panel.gd @@ -3,9 +3,7 @@ extends Panel signal close_click func _gui_input(event: InputEvent) -> void: - print("CLICK TEST 1") if event is InputEventMouseButton: - print("Click Test 2") if event.button_index == MOUSE_BUTTON_LEFT: if event.pressed: close_click.emit() From be892a4f7d96829aeaa195d5bbe463c08d56ddc8 Mon Sep 17 00:00:00 2001 From: Marco Eibensteiner Date: Fri, 30 May 2025 23:19:56 +0200 Subject: [PATCH 08/16] Added Text Boxes to Export --- lorien/Main.gd | 2 +- lorien/Misc/SvgExporter.gd | 30 +++++++++++++++++++++++++++++- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/lorien/Main.gd b/lorien/Main.gd index 3adc0cf7..35b67019 100644 --- a/lorien/Main.gd +++ b/lorien/Main.gd @@ -508,7 +508,7 @@ func _on_export_confirmed(path: String) -> void: if project != null: var background := _canvas.get_background_color() var svg := SvgExporter.new() - svg.export_svg(project.strokes, background, path) + svg.export_svg(project.strokes, project.textBoxes, background, path) _: printerr("Unsupported format") diff --git a/lorien/Misc/SvgExporter.gd b/lorien/Misc/SvgExporter.gd index c4f4f149..849967b7 100644 --- a/lorien/Misc/SvgExporter.gd +++ b/lorien/Misc/SvgExporter.gd @@ -8,7 +8,7 @@ extends RefCounted const EDGE_MARGIN := 0.025 # ------------------------------------------------------------------------------------------------- -func export_svg(strokes: Array[BrushStroke], background: Color, path: String) -> void: +func export_svg(strokes: Array[BrushStroke], text_boxes: Array[TextBox], background: Color, path: String) -> void: var start_time := Time.get_ticks_msec() # Open file @@ -25,6 +25,18 @@ func export_svg(strokes: Array[BrushStroke], background: Color, path: String) -> min_dim.y = min(min_dim.y, stroke.top_left_pos.y + stroke.global_position.y) max_dim.x = max(max_dim.x, stroke.bottom_right_pos.x + stroke.global_position.x) max_dim.y = max(max_dim.y, stroke.bottom_right_pos.y + stroke.global_position.y) + print("Stroke min",min_dim.x," ",min_dim.y) + print("Stroke max",max_dim.x," ",max_dim.y) + + for text_box: TextBox in text_boxes: + min_dim.x = min(min_dim.x, text_box.get_rect().position.x) + min_dim.y = min(min_dim.y, text_box.get_rect().position.y) + max_dim.x = max(max_dim.x, text_box.get_rect().position.x+text_box.get_rect().size.x) + max_dim.y = max(max_dim.y, text_box.get_rect().position.y+text_box.get_rect().size.y) + print("Global Position X: ",text_box.global_position.x, " Rect Position x: ", text_box.get_rect().position.x, " Rect Size x: ", text_box.get_rect().size.x) + print("Text Box min",min_dim.x," ",min_dim.y) + print("Text Box max",max_dim.x," ",max_dim.y) + var size := max_dim - min_dim var margin_size := size * EDGE_MARGIN size += margin_size*2.0 @@ -35,6 +47,8 @@ func export_svg(strokes: Array[BrushStroke], background: Color, path: String) -> _svg_rect(file, origin, size, background) for stroke: BrushStroke in strokes: _svg_polyline(file, stroke) + for text_box: TextBox in text_boxes: + _svg_text(file, text_box) _svg_end(file) # Flush and close the file @@ -71,3 +85,17 @@ func _svg_polyline(file: FileAccess, stroke: BrushStroke) -> void: file.store_string("%.1f %.1f" % [point.x, point.y]) idx += 1 file.store_string("\" style=\"fill:none;stroke:#%s;stroke-width:2\"/>\n" % stroke.color.to_html(false)) + +# ------------------------------------------------------------------------------------------------- +func _svg_text(file: FileAccess, text_box: TextBox) -> void: + file.store_string("") + file.store_string(text_box.text) + file.store_string("\n") + From 3588fb54c3c6e0caa0a4663e8c951c8266dd62e7 Mon Sep 17 00:00:00 2001 From: Marco Eibensteiner Date: Sat, 31 May 2025 22:29:09 +0200 Subject: [PATCH 09/16] Improved Look of the Text Editor Pop Up --- lorien/TextBox/TextBox2.gd | 4 +-- lorien/TextBox/TextBox2.tscn | 48 +++++++++++++++++++++++++++--------- 2 files changed, 39 insertions(+), 13 deletions(-) diff --git a/lorien/TextBox/TextBox2.gd b/lorien/TextBox/TextBox2.gd index 28ab942d..81beaca7 100644 --- a/lorien/TextBox/TextBox2.gd +++ b/lorien/TextBox/TextBox2.gd @@ -1,9 +1,9 @@ class_name TextBox2 extends PanelContainer @onready -var textEdit : TextEdit = $Panel/VBoxContainer/TextEdit +var textEdit : TextEdit = $Panel/Panel/VBoxContainer/TextEdit @onready -var saveButton : Button = $Panel/VBoxContainer/HBoxContainer/SaveButton +var saveButton : Button = $Panel/Panel/VBoxContainer/HBoxContainer/SaveButton var textBox : TextBox signal textBox_ok diff --git a/lorien/TextBox/TextBox2.tscn b/lorien/TextBox/TextBox2.tscn index 4ec436f2..666ec675 100644 --- a/lorien/TextBox/TextBox2.tscn +++ b/lorien/TextBox/TextBox2.tscn @@ -1,8 +1,17 @@ -[gd_scene load_steps=3 format=3 uid="uid://ccl05i282g120"] +[gd_scene load_steps=6 format=3 uid="uid://ccl05i282g120"] [ext_resource type="Script" path="res://TextBox/TextBox2.gd" id="1_pskl6"] [ext_resource type="Script" path="res://TextBox/Panel.gd" id="2_mvgor"] +[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_jirs3"] +bg_color = Color(0.6, 0.6, 0.6, 0) + +[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_u5mq5"] +bg_color = Color(0.6, 0.6, 0.6, 0) + +[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_q5oxc"] +bg_color = Color(0.266575, 0.266575, 0.266575, 1) + [node name="PopupPanel" type="PanelContainer"] visible = false anchors_preset = 15 @@ -10,38 +19,55 @@ anchor_right = 1.0 anchor_bottom = 1.0 grow_horizontal = 2 grow_vertical = 2 +theme_override_styles/panel = SubResource("StyleBoxFlat_jirs3") script = ExtResource("1_pskl6") [node name="Panel" type="Panel" parent="."] layout_mode = 2 +theme_override_styles/panel = SubResource("StyleBoxFlat_u5mq5") script = ExtResource("2_mvgor") -[node name="VBoxContainer" type="VBoxContainer" parent="Panel"] +[node name="Panel" type="Panel" parent="Panel"] +layout_mode = 1 +anchors_preset = 8 +anchor_left = 0.5 +anchor_top = 0.5 +anchor_right = 0.5 +anchor_bottom = 0.5 +offset_left = -200.0 +offset_top = -110.0 +offset_right = 200.0 +offset_bottom = 110.0 +grow_horizontal = 2 +grow_vertical = 2 +theme_override_styles/panel = SubResource("StyleBoxFlat_q5oxc") + +[node name="VBoxContainer" type="VBoxContainer" parent="Panel/Panel"] layout_mode = 1 anchors_preset = 8 anchor_left = 0.5 anchor_top = 0.5 anchor_right = 0.5 anchor_bottom = 0.5 -offset_left = -125.0 +offset_left = -200.0 offset_top = -100.0 -offset_right = 125.0 +offset_right = 200.0 offset_bottom = 100.0 grow_horizontal = 2 grow_vertical = 2 -[node name="TextEdit" type="TextEdit" parent="Panel/VBoxContainer"] -custom_minimum_size = Vector2(200, 150) +[node name="TextEdit" type="TextEdit" parent="Panel/Panel/VBoxContainer"] +custom_minimum_size = Vector2(350, 150) layout_mode = 2 size_flags_horizontal = 4 focus_next = NodePath("../HBoxContainer/SaveButton") focus_previous = NodePath("../HBoxContainer/CancelButton") -[node name="HBoxContainer" type="HBoxContainer" parent="Panel/VBoxContainer"] +[node name="HBoxContainer" type="HBoxContainer" parent="Panel/Panel/VBoxContainer"] layout_mode = 2 size_flags_horizontal = 4 -[node name="SaveButton" type="Button" parent="Panel/VBoxContainer/HBoxContainer"] +[node name="SaveButton" type="Button" parent="Panel/Panel/VBoxContainer/HBoxContainer"] layout_mode = 2 focus_neighbor_left = NodePath("../CancelButton") focus_neighbor_right = NodePath("../CancelButton") @@ -49,7 +75,7 @@ focus_next = NodePath("../CancelButton") focus_previous = NodePath("../CancelButton") text = "Save" -[node name="CancelButton" type="Button" parent="Panel/VBoxContainer/HBoxContainer"] +[node name="CancelButton" type="Button" parent="Panel/Panel/VBoxContainer/HBoxContainer"] layout_mode = 2 focus_neighbor_left = NodePath("../SaveButton") focus_neighbor_right = NodePath("../SaveButton") @@ -59,5 +85,5 @@ text = "Cancel" [connection signal="visibility_changed" from="." to="." method="_on_visibility_changed"] [connection signal="close_click" from="Panel" to="." method="_on_panel_close_click"] -[connection signal="pressed" from="Panel/VBoxContainer/HBoxContainer/SaveButton" to="." method="_on_save_button_pressed"] -[connection signal="pressed" from="Panel/VBoxContainer/HBoxContainer/CancelButton" to="." method="_on_cancel_button_pressed"] +[connection signal="pressed" from="Panel/Panel/VBoxContainer/HBoxContainer/SaveButton" to="." method="_on_save_button_pressed"] +[connection signal="pressed" from="Panel/Panel/VBoxContainer/HBoxContainer/CancelButton" to="." method="_on_cancel_button_pressed"] From e0fe04822831223c079192e2493b7d3caf337619 Mon Sep 17 00:00:00 2001 From: Marco Eibensteiner Date: Sat, 31 May 2025 22:51:38 +0200 Subject: [PATCH 10/16] Clean Up --- lorien/InfiniteCanvas/InfiniteCanvas.gd | 41 ++++---------------- lorien/InfiniteCanvas/Tools/SelectionTool.gd | 18 ++++----- lorien/Misc/Utils.gd | 2 - lorien/TextBox/Panel.gd | 5 --- lorien/TextBox/TextBox.gd | 7 ---- lorien/export_presets.cfg | 4 +- 6 files changed, 16 insertions(+), 61 deletions(-) diff --git a/lorien/InfiniteCanvas/InfiniteCanvas.gd b/lorien/InfiniteCanvas/InfiniteCanvas.gd index 3fc9dad5..69f6e81d 100644 --- a/lorien/InfiniteCanvas/InfiniteCanvas.gd +++ b/lorien/InfiniteCanvas/InfiniteCanvas.gd @@ -69,13 +69,6 @@ func _ready() -> void: info.pen_inverted = false -func _process(delta: float) -> void: - var node : Node = $SubViewport.gui_get_focus_owner() - #if node != null: - # print(node.name) - #else: - # print("Node is null") - # ------------------------------------------------------------------------------------------------- func _unhandled_key_input(event: InputEvent) -> void: _process_event(event) @@ -199,6 +192,7 @@ func get_strokes_in_camera_frustrum() -> Array: func get_all_strokes() -> Array[BrushStroke]: return _current_project.strokes +# ------------------------------------------------------------------------------------------------- func get_all_text_boxes() -> Array[TextBox]: return _current_project.textBoxes # ------------------------------------------------------------------------------------------------- @@ -414,9 +408,6 @@ func _do_delete_stroke(stroke: BrushStroke) -> void: info.point_count -= stroke.points.size() info.stroke_count -= 1 -# 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. - # ------------------------------------------------------------------------------------------------- func _do_delete_text_box(text_box: TextBox) -> void: var index := _current_project.textBoxes.find(text_box) @@ -444,29 +435,12 @@ func _create_textbox(textBox : TextBox) -> void: _textboxes_parent.add_child(textBox) _current_project.textBoxes.append(textBox) -func _on_mouse_exited() -> void: - print("Mouse left infinite canvas") - - -func _on_mouse_entered() -> void: - print("Mouse entered infinite canvas") - - -func _on_text_box_tool_text_box_tool_reset() -> void: - print("Text Box Reset on infinite canvas") - #grab_click_focus() - #grab_focus() - #mouse_exited.emit() - #mouse_entered.emit() - -func _on_focus_entered() -> void: - print("focus on infiniteCanvas") - +# ------------------------------------------------------------------------------------------------- func _on_text_box_tool_show_text_box_dialog(dialogPosition : Vector2) -> void: - print("Catch Show Dialog Event ", dialogPosition) _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 @@ -475,18 +449,17 @@ func _on_text_box_editor_text_box_ok(value : String, labelPosition : Vector2) -> _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: - print("Show Dialog for existing text Box") _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 diff --git a/lorien/InfiniteCanvas/Tools/SelectionTool.gd b/lorien/InfiniteCanvas/Tools/SelectionTool.gd index 52a00e0f..99962c5f 100644 --- a/lorien/InfiniteCanvas/Tools/SelectionTool.gd +++ b/lorien/InfiniteCanvas/Tools/SelectionTool.gd @@ -10,7 +10,7 @@ const META_OFFSET := "offset" const GROUP_SELECTED_STROKES := "selected_strokes" # selected strokes const GROUP_SELECTED_TEXT_BOXES := "selected_text_boxes" const GROUP_STROKES_IN_SELECTION_RECTANGLE := "strokes_in_selection_rectangle" # strokes that are in selection rectangle but not commit (i.e. the user is still selecting) -const GROUP_TEXT_BOXES__IN_SELECTION_RECTANGLE := "text_boxes_in_selection_rectangle" # strokes that are in selection rectangle but not commit (i.e. the user is still selecting) +const GROUP_TEXT_BOXES_IN_SELECTION_RECTANGLE := "text_boxes_in_selection_rectangle" # strokes that are in selection rectangle but not commit (i.e. the user is still selecting) const GROUP_MARKED_FOR_DESELECTION := "strokes_marked_for_deselection" # strokes that need to be deslected once LMB is released const GROUP_MARKED_TEXT_BOXES_FOR_DESELECTION = "text_boxes_marked_for_deselection" const GROUP_COPIED_STROKES := "strokes_copied" @@ -65,8 +65,6 @@ func tool_event(event: InputEvent) -> void: if event is InputEventMouseButton && !disable_stroke: if event.button_index == MOUSE_BUTTON_LEFT: # LMB down - decide if we should select/multiselect or move the selection - print("selected strokes", get_selected_strokes().size()) - print("selected text boxes", get_selected_strokes().size()) if event.pressed: _selecting_start_pos = _cursor.global_position if event.shift_pressed: @@ -74,12 +72,10 @@ func tool_event(event: InputEvent) -> void: _multi_selecting = true _build_bounding_boxes() elif get_selected_strokes().size() == 0 && get_selected_text_boxes().size() == 0: - print("Nothing Selected") _state = State.SELECTING _multi_selecting = false _build_bounding_boxes() else: - print("Else Moving") _state = State.MOVING _mouse_moved_during_pressed = false _offset_selected_strokes(_cursor.global_position) @@ -104,7 +100,7 @@ func tool_event(event: InputEvent) -> void: _state = State.NONE if _mouse_moved_during_pressed: _add_undoredo_action_for_moved_strokes() - #_add_undoredo_action_for_moved_text_boxes() + _add_undoredo_action_for_moved_text_boxes() _stroke_positions_before_move.clear() _text_box_positions_before_move.clear() else: @@ -223,7 +219,7 @@ func _set_text_box_selected(text_box : TextBox) -> void: text_box.add_to_group(GROUP_MARKED_TEXT_BOXES_FOR_DESELECTION) else: text_box.modulate = Config.DEFAULT_SELECTION_COLOR - text_box.add_to_group(GROUP_TEXT_BOXES__IN_SELECTION_RECTANGLE) + text_box.add_to_group(GROUP_TEXT_BOXES_IN_SELECTION_RECTANGLE) # ------------------------------------------------------------------------------------------------ func _add_undoredo_action_for_moved_strokes() -> void: @@ -276,8 +272,8 @@ func _commit_strokes_under_selection_rectangle() -> void: # ------------------------------------------------------------------------------------------------ func _commit_text_boxes_under_selection_rectangle() -> void: - for text_box: TextBox in get_tree().get_nodes_in_group(GROUP_TEXT_BOXES__IN_SELECTION_RECTANGLE): - text_box.remove_from_group(GROUP_TEXT_BOXES__IN_SELECTION_RECTANGLE) + for text_box: TextBox in get_tree().get_nodes_in_group(GROUP_TEXT_BOXES_IN_SELECTION_RECTANGLE): + text_box.remove_from_group(GROUP_TEXT_BOXES_IN_SELECTION_RECTANGLE) text_box.add_to_group(GROUP_SELECTED_TEXT_BOXES) print(get_selected_text_boxes()) @@ -313,10 +309,10 @@ func deselect_all_text_boxes() -> void: var selected_text_boxes: Array = get_selected_text_boxes() if selected_text_boxes.size(): get_tree().set_group(GROUP_SELECTED_TEXT_BOXES, "modulate", Color.WHITE) - get_tree().set_group(GROUP_TEXT_BOXES__IN_SELECTION_RECTANGLE, "modulate", Color.WHITE) + get_tree().set_group(GROUP_TEXT_BOXES_IN_SELECTION_RECTANGLE, "modulate", Color.WHITE) Utils.remove_group_from_all_nodes(GROUP_SELECTED_TEXT_BOXES) Utils.remove_group_from_all_nodes(GROUP_MARKED_TEXT_BOXES_FOR_DESELECTION) - Utils.remove_group_from_all_nodes(GROUP_TEXT_BOXES__IN_SELECTION_RECTANGLE) + Utils.remove_group_from_all_nodes(GROUP_TEXT_BOXES_IN_SELECTION_RECTANGLE) _cursor.mode = SelectionCursor.Mode.SELECT diff --git a/lorien/Misc/Utils.gd b/lorien/Misc/Utils.gd index cd3256e8..df1415dc 100644 --- a/lorien/Misc/Utils.gd +++ b/lorien/Misc/Utils.gd @@ -55,8 +55,6 @@ func calculte_bounding_boxes(strokes: Array[BrushStroke], text_boxes: Array[Text for text_box : TextBox in text_boxes: var text_box_bounding_box := text_box.get_global_rect() - #if margin > 0: - # text_box_bounding_box := text_box_bounding_box.grow(margin) result[text_box] = text_box_bounding_box return result diff --git a/lorien/TextBox/Panel.gd b/lorien/TextBox/Panel.gd index 87812f54..20b5e8bb 100644 --- a/lorien/TextBox/Panel.gd +++ b/lorien/TextBox/Panel.gd @@ -7,8 +7,3 @@ func _gui_input(event: InputEvent) -> void: if event.button_index == MOUSE_BUTTON_LEFT: if event.pressed: close_click.emit() - - -func _unhandled_key_input(event: InputEvent) -> void: - if event is InputEventMouseButton: - print("CLICK TEST") diff --git a/lorien/TextBox/TextBox.gd b/lorien/TextBox/TextBox.gd index 9b17dce1..49cecc07 100644 --- a/lorien/TextBox/TextBox.gd +++ b/lorien/TextBox/TextBox.gd @@ -1,8 +1 @@ -@icon("res://Assets/Icons/text-block.png") class_name TextBox extends Label - -@export -var test : String - -func _gui_input(event: InputEvent) -> void: - print("GUI INPUT TEXTBOX") diff --git a/lorien/export_presets.cfg b/lorien/export_presets.cfg index 4a610ad7..e0f46e42 100644 --- a/lorien/export_presets.cfg +++ b/lorien/export_presets.cfg @@ -9,7 +9,7 @@ custom_features="" export_filter="all_resources" include_filter="Assets/I18N/*" exclude_filter="" -export_path="../../../Lorien_Test/Linux/Lorien.x86_64" +export_path="../../../Linux_PR/Lorien.x86_64" encryption_include_filters="" encryption_exclude_filters="" encrypt_pck=false @@ -49,7 +49,7 @@ custom_features="" export_filter="all_resources" include_filter="Assets/I18N/*" exclude_filter="" -export_path="../../../Lorien_Test/Windows/Lorien.exe" +export_path="" encryption_include_filters="" encryption_exclude_filters="" encrypt_pck=false From b23c05326de8b07bb9a47639c3fc200b730818f1 Mon Sep 17 00:00:00 2001 From: Marco Eibensteiner Date: Sat, 31 May 2025 22:54:00 +0200 Subject: [PATCH 11/16] Clean Up --- lorien/export_presets.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lorien/export_presets.cfg b/lorien/export_presets.cfg index e0f46e42..107264b1 100644 --- a/lorien/export_presets.cfg +++ b/lorien/export_presets.cfg @@ -9,7 +9,7 @@ custom_features="" export_filter="all_resources" include_filter="Assets/I18N/*" exclude_filter="" -export_path="../../../Linux_PR/Lorien.x86_64" +export_path="../../../Lorien.x86_64" encryption_include_filters="" encryption_exclude_filters="" encrypt_pck=false From fd989cfd43942526f44fd5c295c97509c24f2dfe Mon Sep 17 00:00:00 2001 From: Marco Eibensteiner Date: Sat, 31 May 2025 22:56:26 +0200 Subject: [PATCH 12/16] Renamed TextBox2 to TextBoxEditor --- lorien/InfiniteCanvas/InfiniteCanvas.tscn | 2 +- lorien/InfiniteCanvas/Tools/TextBoxTool.gd | 2 +- lorien/TextBox/TextBox2.gd | 2 +- lorien/TextBox/{TextBox2.tscn => TextBoxEditor.tscn} | 8 ++++---- 4 files changed, 7 insertions(+), 7 deletions(-) rename lorien/TextBox/{TextBox2.tscn => TextBoxEditor.tscn} (97%) diff --git a/lorien/InfiniteCanvas/InfiniteCanvas.tscn b/lorien/InfiniteCanvas/InfiniteCanvas.tscn index 5810c108..964fdbac 100644 --- a/lorien/InfiniteCanvas/InfiniteCanvas.tscn +++ b/lorien/InfiniteCanvas/InfiniteCanvas.tscn @@ -11,7 +11,7 @@ [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/TextBox2.tscn" id="10_gdd0v"] +[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"] diff --git a/lorien/InfiniteCanvas/Tools/TextBoxTool.gd b/lorien/InfiniteCanvas/Tools/TextBoxTool.gd index 6fd3a0be..edc06c59 100644 --- a/lorien/InfiniteCanvas/Tools/TextBoxTool.gd +++ b/lorien/InfiniteCanvas/Tools/TextBoxTool.gd @@ -2,7 +2,7 @@ class_name TextBoxTool extends CanvasTool @export var _textBox: PackedScene -var textBoxInstance : TextBox2 +var textBoxInstance : TextBoxEditor signal text_box_tool_reset signal show_textBoxDialog diff --git a/lorien/TextBox/TextBox2.gd b/lorien/TextBox/TextBox2.gd index 81beaca7..c95dd5a8 100644 --- a/lorien/TextBox/TextBox2.gd +++ b/lorien/TextBox/TextBox2.gd @@ -1,4 +1,4 @@ -class_name TextBox2 extends PanelContainer +class_name TextBoxEditor extends PanelContainer @onready var textEdit : TextEdit = $Panel/Panel/VBoxContainer/TextEdit diff --git a/lorien/TextBox/TextBox2.tscn b/lorien/TextBox/TextBoxEditor.tscn similarity index 97% rename from lorien/TextBox/TextBox2.tscn rename to lorien/TextBox/TextBoxEditor.tscn index 666ec675..aff06eca 100644 --- a/lorien/TextBox/TextBox2.tscn +++ b/lorien/TextBox/TextBoxEditor.tscn @@ -1,7 +1,7 @@ [gd_scene load_steps=6 format=3 uid="uid://ccl05i282g120"] -[ext_resource type="Script" path="res://TextBox/TextBox2.gd" id="1_pskl6"] -[ext_resource type="Script" path="res://TextBox/Panel.gd" id="2_mvgor"] +[ext_resource type="Script" path="res://TextBox/TextBox2.gd" id="1_l1c4a"] +[ext_resource type="Script" path="res://TextBox/Panel.gd" id="2_fvesn"] [sub_resource type="StyleBoxFlat" id="StyleBoxFlat_jirs3"] bg_color = Color(0.6, 0.6, 0.6, 0) @@ -20,12 +20,12 @@ anchor_bottom = 1.0 grow_horizontal = 2 grow_vertical = 2 theme_override_styles/panel = SubResource("StyleBoxFlat_jirs3") -script = ExtResource("1_pskl6") +script = ExtResource("1_l1c4a") [node name="Panel" type="Panel" parent="."] layout_mode = 2 theme_override_styles/panel = SubResource("StyleBoxFlat_u5mq5") -script = ExtResource("2_mvgor") +script = ExtResource("2_fvesn") [node name="Panel" type="Panel" parent="Panel"] layout_mode = 1 From 4ea4109469e60d9f0dfe022a3bdd325e9d8cdf27 Mon Sep 17 00:00:00 2001 From: Marco Eibensteiner Date: Wed, 24 Sep 2025 15:42:13 +0200 Subject: [PATCH 13/16] Added changing_theme to the Text Box Editor --- lorien/TextBox/TextBox2.gd | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/lorien/TextBox/TextBox2.gd b/lorien/TextBox/TextBox2.gd index c95dd5a8..f680e32e 100644 --- a/lorien/TextBox/TextBox2.gd +++ b/lorien/TextBox/TextBox2.gd @@ -5,12 +5,17 @@ var textEdit : TextEdit = $Panel/Panel/VBoxContainer/TextEdit @onready var saveButton : Button = $Panel/Panel/VBoxContainer/HBoxContainer/SaveButton var textBox : TextBox - +@onready +var panel : Panel = $Panel/Panel signal textBox_ok signal textBox_cancel signal textBox_ok_update var label_position : Vector2 + +func _ready() -> void: + Settings.changed_theme.connect(_on_theme_changed) + func _on_save_button_pressed() -> void: if textBox == null: textBox_ok.emit(textEdit.text, label_position) @@ -43,7 +48,13 @@ func _on_panel_close_click() -> void: textEdit.text = "" visible = false +func _on_theme_changed(themeName : String) -> void: + var themePath : String = str("res://UI/Themes/", themeName, "/theme.tres") + var currentTheme : Theme = load(themePath) + theme = currentTheme func _on_visibility_changed() -> void: + + if visible: textEdit.grab_focus() From 16cc37a298f73873cf6a1887884ab29a82742582 Mon Sep 17 00:00:00 2001 From: Marco Eibensteiner Date: Tue, 30 Sep 2025 20:59:50 +0200 Subject: [PATCH 14/16] Changed to TextEdits and Labels... but it's not working correctly --- lorien/InfiniteCanvas/InfiniteCanvas.gd | 50 ++++++++++++-------- lorien/InfiniteCanvas/Tools/SelectionTool.gd | 4 +- lorien/InfiniteCanvas/Tools/TextBoxTool.gd | 2 +- lorien/Main.gd | 8 ++++ lorien/Misc/SvgExporter.gd | 8 ++-- lorien/Misc/Utils.gd | 4 +- lorien/ProjectManager/Project.gd | 2 +- lorien/ProjectManager/Serializer.gd | 2 +- lorien/TextBox/TextBox.gd | 2 +- lorien/TextBox/TextBox2.gd | 2 - lorien/UI/Themes/dark/theme.tres | 5 +- 11 files changed, 53 insertions(+), 36 deletions(-) diff --git a/lorien/InfiniteCanvas/InfiniteCanvas.gd b/lorien/InfiniteCanvas/InfiniteCanvas.gd index 69f6e81d..c14e5ae0 100644 --- a/lorien/InfiniteCanvas/InfiniteCanvas.gd +++ b/lorien/InfiniteCanvas/InfiniteCanvas.gd @@ -36,6 +36,7 @@ var _use_optimizer := true var _optimizer: BrushStrokeOptimizer var _player: Player = null var _player_enabled := false +var _textEdit : TextEdit = TextEdit.new() # ------------------------------------------------------------------------------------------------- func _ready() -> void: @@ -193,7 +194,7 @@ func get_all_strokes() -> Array[BrushStroke]: return _current_project.strokes # ------------------------------------------------------------------------------------------------- -func get_all_text_boxes() -> Array[TextBox]: +func get_all_text_boxes() -> Array[Label]: return _current_project.textBoxes # ------------------------------------------------------------------------------------------------- func enable() -> void: @@ -431,35 +432,46 @@ func _undo_delete_text_box(text_box: TextBox) -> void: _textboxes_parent.add_child(text_box) # ------------------------------------------------------------------------------------------------- -func _create_textbox(textBox : TextBox) -> void: +func _create_textEdit(textBox : TextEdit) -> void: + _textboxes_parent.add_child(textBox) + _current_project.textBoxes.append(textBox) + +func _create_label(textBox : Label) -> 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 + print("TEXT BOX TOOL SHOW") + _textEdit = TextEdit.new() + _textEdit.set_position(dialogPosition) + _textEdit.custom_minimum_size = Vector2(350, 150) + _textEdit.SIZE_FILL + _textEdit.focus_exited.connect(_change_edit_to_label) + _create_textEdit(_textEdit) + +# ------------------------------------------------------------------------------------------------- +func _change_edit_to_label() -> void: + print("Focus Lost") + _on_text_box_editor_text_box_ok(_textEdit.text, _textEdit.position) + _textEdit.queue_free() + # ------------------------------------------------------------------------------------------------- func _on_text_box_editor_text_box_ok(value : String, labelPosition : Vector2) -> void: - var label : TextBox = TextBox.new() + var label : Label = Label.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: + _create_label(label) _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 +func _on_text_box_tool_edit_existing_text_box(textBox : Label) -> void: + _textEdit = TextEdit.new() + _textEdit.custom_minimum_size = Vector2(350, 150) + _textEdit.SIZE_FILL + _textEdit.focus_exited.connect(_change_edit_to_label) + _textEdit.position = textBox.position + _textEdit.text = textBox.text + _create_textEdit(_textEdit) diff --git a/lorien/InfiniteCanvas/Tools/SelectionTool.gd b/lorien/InfiniteCanvas/Tools/SelectionTool.gd index 99962c5f..41790782 100644 --- a/lorien/InfiniteCanvas/Tools/SelectionTool.gd +++ b/lorien/InfiniteCanvas/Tools/SelectionTool.gd @@ -146,7 +146,7 @@ func compute_selection(start_pos: Vector2, end_pos: Vector2) -> void: if selection_rect.has_point(abs_point): _set_stroke_selected(stroke) break - for textBox: TextBox in _canvas.get_all_text_boxes(): + for textBox: Label in _canvas.get_all_text_boxes(): var bounding_text_box_box: Rect2 = textBox.get_global_rect() if selection_rect.intersects(bounding_text_box_box): _set_text_box_selected(textBox) @@ -213,7 +213,7 @@ func _set_stroke_selected(stroke: BrushStroke) -> void: stroke.add_to_group(GROUP_STROKES_IN_SELECTION_RECTANGLE) # ------------------------------------------------------------------------------------------------ -func _set_text_box_selected(text_box : TextBox) -> void: +func _set_text_box_selected(text_box : Label) -> void: if text_box.is_in_group(GROUP_SELECTED_TEXT_BOXES): text_box.modulate = Color.WHITE text_box.add_to_group(GROUP_MARKED_TEXT_BOXES_FOR_DESELECTION) diff --git a/lorien/InfiniteCanvas/Tools/TextBoxTool.gd b/lorien/InfiniteCanvas/Tools/TextBoxTool.gd index edc06c59..ba30b034 100644 --- a/lorien/InfiniteCanvas/Tools/TextBoxTool.gd +++ b/lorien/InfiniteCanvas/Tools/TextBoxTool.gd @@ -29,7 +29,7 @@ func tool_event(event: InputEvent) -> void: if event.button_index == MOUSE_BUTTON_LEFT: if event.pressed && _state == State.CREATING: print(event.global_position) - for textBox : TextBox in get_parent()._textboxes_parent.get_children(): + for textBox : Label in get_parent()._textboxes_parent.get_children(): if textBox.get_rect().has_point(event.global_position): print("Click inside TextBox") edit_existing_textBox.emit(textBox) diff --git a/lorien/Main.gd b/lorien/Main.gd index af776b39..b034e765 100644 --- a/lorien/Main.gd +++ b/lorien/Main.gd @@ -136,6 +136,14 @@ func _exit_tree() -> void: # ------------------------------------------------------------------------------------------------- func _process(delta: float) -> void: + + var focused_control = get_viewport().gui_get_focus_owner() + + if focused_control: + print("Focused Control: ", focused_control.name) + else: + print("No control has focus.") + # Lower fps if user is idle var idle := (Time.get_ticks_msec() - _last_input_time) > Config.BACKGROUND_IDLE_TIME_THRESHOLD if !_player_enabled && !_canvas.is_drawing() && idle: diff --git a/lorien/Misc/SvgExporter.gd b/lorien/Misc/SvgExporter.gd index 849967b7..a3867103 100644 --- a/lorien/Misc/SvgExporter.gd +++ b/lorien/Misc/SvgExporter.gd @@ -8,7 +8,7 @@ extends RefCounted const EDGE_MARGIN := 0.025 # ------------------------------------------------------------------------------------------------- -func export_svg(strokes: Array[BrushStroke], text_boxes: Array[TextBox], background: Color, path: String) -> void: +func export_svg(strokes: Array[BrushStroke], text_boxes: Array[Label], background: Color, path: String) -> void: var start_time := Time.get_ticks_msec() # Open file @@ -28,7 +28,7 @@ func export_svg(strokes: Array[BrushStroke], text_boxes: Array[TextBox], backgro print("Stroke min",min_dim.x," ",min_dim.y) print("Stroke max",max_dim.x," ",max_dim.y) - for text_box: TextBox in text_boxes: + for text_box: Label in text_boxes: min_dim.x = min(min_dim.x, text_box.get_rect().position.x) min_dim.y = min(min_dim.y, text_box.get_rect().position.y) max_dim.x = max(max_dim.x, text_box.get_rect().position.x+text_box.get_rect().size.x) @@ -47,7 +47,7 @@ func export_svg(strokes: Array[BrushStroke], text_boxes: Array[TextBox], backgro _svg_rect(file, origin, size, background) for stroke: BrushStroke in strokes: _svg_polyline(file, stroke) - for text_box: TextBox in text_boxes: + for text_box: Label in text_boxes: _svg_text(file, text_box) _svg_end(file) @@ -87,7 +87,7 @@ func _svg_polyline(file: FileAccess, stroke: BrushStroke) -> void: file.store_string("\" style=\"fill:none;stroke:#%s;stroke-width:2\"/>\n" % stroke.color.to_html(false)) # ------------------------------------------------------------------------------------------------- -func _svg_text(file: FileAccess, text_box: TextBox) -> void: +func _svg_text(file: FileAccess, text_box: Label) -> void: file.store_string(" Rect2: return area # ------------------------------------------------------------------------------------------------- -func calculte_bounding_boxes(strokes: Array[BrushStroke], text_boxes: Array[TextBox], margin: float = 0.0) -> Dictionary: +func calculte_bounding_boxes(strokes: Array[BrushStroke], text_boxes: Array[Label], margin: float = 0.0) -> Dictionary: var result := {} for stroke: BrushStroke in strokes: var top_left := stroke.position + stroke.top_left_pos @@ -53,7 +53,7 @@ func calculte_bounding_boxes(strokes: Array[BrushStroke], text_boxes: Array[Text bounding_box = bounding_box.grow(margin) result[stroke] = bounding_box - for text_box : TextBox in text_boxes: + for text_box : Label in text_boxes: var text_box_bounding_box := text_box.get_global_rect() result[text_box] = text_box_bounding_box return result diff --git a/lorien/ProjectManager/Project.gd b/lorien/ProjectManager/Project.gd index 36476c20..93d86424 100644 --- a/lorien/ProjectManager/Project.gd +++ b/lorien/ProjectManager/Project.gd @@ -17,7 +17,7 @@ var loaded := false var filepath: String var meta_data: Dictionary var strokes: Array[BrushStroke] -var textBoxes : Array[TextBox] +var textBoxes : Array[Label] # ------------------------------------------------------------------------------------------------- func _init() -> void: diff --git a/lorien/ProjectManager/Serializer.gd b/lorien/ProjectManager/Serializer.gd index b70b1123..878477ea 100644 --- a/lorien/ProjectManager/Serializer.gd +++ b/lorien/ProjectManager/Serializer.gd @@ -56,7 +56,7 @@ static func save_project(project: Project) -> void: p_idx += 1 # Text Box Data - for textBox : TextBox in project.textBoxes: + for textBox : Label in project.textBoxes: file.store_8(TYPE_TEXT_BOX) file.store_float(textBox.global_position.x) file.store_float(textBox.global_position.y) diff --git a/lorien/TextBox/TextBox.gd b/lorien/TextBox/TextBox.gd index 49cecc07..91e4f423 100644 --- a/lorien/TextBox/TextBox.gd +++ b/lorien/TextBox/TextBox.gd @@ -1 +1 @@ -class_name TextBox extends Label +class_name TextBox extends TextEdit diff --git a/lorien/TextBox/TextBox2.gd b/lorien/TextBox/TextBox2.gd index f680e32e..763b39fa 100644 --- a/lorien/TextBox/TextBox2.gd +++ b/lorien/TextBox/TextBox2.gd @@ -54,7 +54,5 @@ func _on_theme_changed(themeName : String) -> void: theme = currentTheme func _on_visibility_changed() -> void: - - if visible: textEdit.grab_focus() diff --git a/lorien/UI/Themes/dark/theme.tres b/lorien/UI/Themes/dark/theme.tres index 365e8fee..d845838f 100644 --- a/lorien/UI/Themes/dark/theme.tres +++ b/lorien/UI/Themes/dark/theme.tres @@ -1,6 +1,5 @@ -[gd_resource type="Theme" load_steps=28 format=4 uid="uid://u5qnpgxqykiv"] +[gd_resource type="Theme" load_steps=26 format=4 uid="uid://u5qnpgxqykiv"] -[ext_resource type="Texture2D" uid="uid://bp1yka17gbjtu" path="res://Assets/Icons/close.png" id="1_qgxa7"] [ext_resource type="StyleBox" uid="uid://kdduww61cjw" path="res://UI/Themes/dark/tab_inactive.tres" id="2_n6mkw"] [ext_resource type="StyleBox" uid="uid://dtn7ehcyfik4a" path="res://UI/Themes/dark/tab_active.tres" id="3_rqnin"] @@ -2562,7 +2561,7 @@ TabBar/constants/h_separation = 4 TabBar/constants/icon_max_width = 0 TabBar/constants/outline_size = 0 TabBar/fonts/font = SubResource("FontFile_1bm21") -TabBar/icons/close = ExtResource("1_qgxa7") +TabBar/icons/close = null TabBar/styles/button_highlight = SubResource("StyleBoxEmpty_me351") TabBar/styles/button_pressed = SubResource("StyleBoxEmpty_n0chp") TabBar/styles/tab_disabled = ExtResource("2_n6mkw") From 9f532eed79f1d8375055e55c3e10c6f55df2bcf3 Mon Sep 17 00:00:00 2001 From: Marco Eibensteiner Date: Tue, 11 Nov 2025 22:37:51 +0100 Subject: [PATCH 15/16] Issue fixed with calling enable() --- lorien/InfiniteCanvas/InfiniteCanvas.gd | 27 ++++++++----- lorien/InfiniteCanvas/InfiniteCanvas.tscn | 7 +++- lorien/InfiniteCanvas/PanZoomCamera.gd | 2 + lorien/InfiniteCanvas/Tools/SelectionTool.gd | 24 +++++------ lorien/InfiniteCanvas/Tools/TextBoxTool.gd | 42 +++++++++++++------- lorien/Main.gd | 8 ++-- 6 files changed, 69 insertions(+), 41 deletions(-) diff --git a/lorien/InfiniteCanvas/InfiniteCanvas.gd b/lorien/InfiniteCanvas/InfiniteCanvas.gd index c14e5ae0..5cb706f7 100644 --- a/lorien/InfiniteCanvas/InfiniteCanvas.gd +++ b/lorien/InfiniteCanvas/InfiniteCanvas.gd @@ -80,9 +80,14 @@ func _gui_input(event: InputEvent) -> void: # ------------------------------------------------------------------------------------------------- func _process_event(event: InputEvent) -> void: + print("Process Event") if event is InputEventMouseMotion: + print("Input is Mouse Motion") info.current_pressure = event.pressure + print("Current Pressure ", info.current_pressure) + print("Event.pressure ", event.pressure) if info.pen_inverted != event.pen_inverted: + print("Pen Inverted is not the same as event pen inverted", info.pen_inverted, event.pen_inverted) info.pen_inverted = event.pen_inverted if info.pen_inverted: var tool_type := _active_tool_type @@ -94,11 +99,13 @@ func _process_event(event: InputEvent) -> void: use_tool(_active_tool_type) if event.is_action("deselect_all_strokes"): + print("Action is 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"): + print("Action is Delete Selected Strokes") if _active_tool == _selection_tool: _delete_selected_strokes() _delete_selected_text_boxes_strokes() @@ -393,7 +400,7 @@ 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: + for text_box: Label 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)) @@ -432,13 +439,10 @@ func _undo_delete_text_box(text_box: TextBox) -> void: _textboxes_parent.add_child(text_box) # ------------------------------------------------------------------------------------------------- -func _create_textEdit(textBox : TextEdit) -> void: - _textboxes_parent.add_child(textBox) - _current_project.textBoxes.append(textBox) - func _create_label(textBox : Label) -> void: _textboxes_parent.add_child(textBox) _current_project.textBoxes.append(textBox) + enable() # ------------------------------------------------------------------------------------------------- func _on_text_box_tool_show_text_box_dialog(dialogPosition : Vector2) -> void: @@ -448,23 +452,27 @@ func _on_text_box_tool_show_text_box_dialog(dialogPosition : Vector2) -> void: _textEdit.custom_minimum_size = Vector2(350, 150) _textEdit.SIZE_FILL _textEdit.focus_exited.connect(_change_edit_to_label) - _create_textEdit(_textEdit) + _textboxes_parent.add_child(_textEdit) # ------------------------------------------------------------------------------------------------- func _change_edit_to_label() -> void: print("Focus Lost") - _on_text_box_editor_text_box_ok(_textEdit.text, _textEdit.position) + if _textEdit.text != "": + _on_text_box_editor_text_box_ok(_textEdit.text, _textEdit.position) + _textbox_tool._state = _textbox_tool.State.NONE _textEdit.queue_free() + _textbox_tool.reset() + enable() # ------------------------------------------------------------------------------------------------- func _on_text_box_editor_text_box_ok(value : String, labelPosition : Vector2) -> void: + print("Text Box OK") var label : Label = Label.new() label.text = value label.set_position(labelPosition) label.add_theme_color_override("font_color", _brush_color) _create_label(label) - _textbox_tool._state = _textbox_tool.State.CREATING # ------------------------------------------------------------------------------------------------- func _on_text_box_tool_edit_existing_text_box(textBox : Label) -> void: @@ -474,4 +482,5 @@ func _on_text_box_tool_edit_existing_text_box(textBox : Label) -> void: _textEdit.focus_exited.connect(_change_edit_to_label) _textEdit.position = textBox.position _textEdit.text = textBox.text - _create_textEdit(_textEdit) + _textboxes_parent.add_child(_textEdit) + textBox.call_deferred("queue_free") diff --git a/lorien/InfiniteCanvas/InfiniteCanvas.tscn b/lorien/InfiniteCanvas/InfiniteCanvas.tscn index 964fdbac..9802f750 100644 --- a/lorien/InfiniteCanvas/InfiniteCanvas.tscn +++ b/lorien/InfiniteCanvas/InfiniteCanvas.tscn @@ -62,7 +62,6 @@ 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="."] @@ -96,6 +95,11 @@ layout_mode = 3 anchors_preset = 0 mouse_filter = 1 +[node name="Label" type="Label" parent="SubViewport/TextBoxes"] +layout_mode = 0 +offset_right = 40.0 +offset_bottom = 22.3333 + [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"] @@ -104,4 +108,3 @@ mouse_filter = 1 [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"] diff --git a/lorien/InfiniteCanvas/PanZoomCamera.gd b/lorien/InfiniteCanvas/PanZoomCamera.gd index 804b79c2..c3135596 100644 --- a/lorien/InfiniteCanvas/PanZoomCamera.gd +++ b/lorien/InfiniteCanvas/PanZoomCamera.gd @@ -86,6 +86,8 @@ func _input(event): # ------------------------------------------------------------------------------------------------- func tool_event(event: InputEvent) -> void: + print(event) + print("Input is enabled: ", _is_input_enabled) if _is_input_enabled: if event is InputEventKey: if Utils.is_action_pressed("canvas_pan_key", event): diff --git a/lorien/InfiniteCanvas/Tools/SelectionTool.gd b/lorien/InfiniteCanvas/Tools/SelectionTool.gd index 41790782..23c46575 100644 --- a/lorien/InfiniteCanvas/Tools/SelectionTool.gd +++ b/lorien/InfiniteCanvas/Tools/SelectionTool.gd @@ -82,7 +82,7 @@ func tool_event(event: InputEvent) -> void: _offset_selected_text_boxes(_cursor.global_position) for s: BrushStroke in get_selected_strokes(): _stroke_positions_before_move[s] = s.global_position - for t: TextBox in get_selected_text_boxes(): + for t: Label in get_selected_text_boxes(): _text_box_positions_before_move[t] = t.global_position # LMB up - stop selection or movement else: @@ -193,8 +193,8 @@ func _modify_strokes_colors(strokes: Array[BrushStroke], color: Color) -> void: stroke.color = color # ------------------------------------------------------------------------------------------------ -func _modify_text_boxes_colors(text_boxes: Array[TextBox], color: Color) -> void: - for text_box: TextBox in text_boxes: +func _modify_text_boxes_colors(text_boxes: Array[Label], color: Color) -> void: + for text_box: Label in text_boxes: text_box.add_theme_color_override("font_color", color) # ------------------------------------------------------------------------------------------------ @@ -228,7 +228,7 @@ func _add_undoredo_action_for_moved_strokes() -> void: for stroke: BrushStroke in _stroke_positions_before_move.keys(): project.undo_redo.add_do_property(stroke, "global_position", stroke.global_position) project.undo_redo.add_undo_property(stroke, "global_position", _stroke_positions_before_move[stroke]) - for text_box: TextBox in _text_box_positions_before_move.keys(): + for text_box: Label in _text_box_positions_before_move.keys(): project.undo_redo.add_do_property(text_box, "global_position", text_box.global_position) project.undo_redo.add_undo_property(text_box, "global_position", _text_box_positions_before_move[text_box]) project.undo_redo.commit_action() @@ -238,7 +238,7 @@ func _add_undoredo_action_for_moved_strokes() -> void: func _add_undoredo_action_for_moved_text_boxes() -> void: var project: Project = ProjectManager.get_active_project() project.undo_redo.create_action("Move Text_Boxes") - for text_box: TextBox in _text_box_positions_before_move.keys(): + for text_box: Label in _text_box_positions_before_move.keys(): project.undo_redo.add_do_property(text_box, "global_position", text_box.global_position) project.undo_redo.add_undo_property(text_box, "global_position", _text_box_positions_before_move[text_box]) project.undo_redo.commit_action() @@ -251,7 +251,7 @@ func _offset_selected_strokes(offset: Vector2) -> void: # ------------------------------------------------------------------------------------------------- func _offset_selected_text_boxes(offset: Vector2) -> void: - for text_box: TextBox in get_selected_text_boxes(): + for text_box: Label in get_selected_text_boxes(): text_box.set_meta(META_OFFSET, text_box.position - offset) # ------------------------------------------------------------------------------------------------- @@ -261,7 +261,7 @@ func _move_selected_strokes() -> void: # ------------------------------------------------------------------------------------------------- func _move_selected_text_boxes() -> void: - for text_box: TextBox in get_selected_text_boxes(): + for text_box: Label in get_selected_text_boxes(): text_box.global_position = text_box.get_meta(META_OFFSET) + _cursor.global_position # ------------------------------------------------------------------------------------------------ @@ -272,7 +272,7 @@ func _commit_strokes_under_selection_rectangle() -> void: # ------------------------------------------------------------------------------------------------ func _commit_text_boxes_under_selection_rectangle() -> void: - for text_box: TextBox in get_tree().get_nodes_in_group(GROUP_TEXT_BOXES_IN_SELECTION_RECTANGLE): + for text_box: Label in get_tree().get_nodes_in_group(GROUP_TEXT_BOXES_IN_SELECTION_RECTANGLE): text_box.remove_from_group(GROUP_TEXT_BOXES_IN_SELECTION_RECTANGLE) text_box.add_to_group(GROUP_SELECTED_TEXT_BOXES) print(get_selected_text_boxes()) @@ -286,7 +286,7 @@ func _deselect_marked_strokes() -> void: # ------------------------------------------------------------------------------------------------ func _deselect_marked_text_boxes() -> void: - for textBox: TextBox in get_tree().get_nodes_in_group(GROUP_MARKED_TEXT_BOXES_FOR_DESELECTION): + for textBox: Label in get_tree().get_nodes_in_group(GROUP_MARKED_TEXT_BOXES_FOR_DESELECTION): textBox.remove_from_group(GROUP_MARKED_TEXT_BOXES_FOR_DESELECTION) textBox.remove_from_group(GROUP_SELECTED_TEXT_BOXES) textBox.modulate = Color.WHITE @@ -331,12 +331,12 @@ func get_selected_strokes() -> Array[BrushStroke]: return strokes # ------------------------------------------------------------------------------------------------ -func get_selected_text_boxes() -> Array[TextBox]: +func get_selected_text_boxes() -> Array[Label]: # Can't cast from Array[Node] to Array[TextBox] directly (godot bug/missing feature?) # so let's do it per item - var text_boxes: Array[TextBox] + var text_boxes: Array[Label] for text_box in get_tree().get_nodes_in_group(GROUP_SELECTED_TEXT_BOXES): - text_boxes.append(text_box as TextBox) + text_boxes.append(text_box as Label) return text_boxes diff --git a/lorien/InfiniteCanvas/Tools/TextBoxTool.gd b/lorien/InfiniteCanvas/Tools/TextBoxTool.gd index ba30b034..6964d58c 100644 --- a/lorien/InfiniteCanvas/Tools/TextBoxTool.gd +++ b/lorien/InfiniteCanvas/Tools/TextBoxTool.gd @@ -1,37 +1,51 @@ class_name TextBoxTool extends CanvasTool -@export var _textBox: PackedScene -var textBoxInstance : TextBoxEditor - -signal text_box_tool_reset signal show_textBoxDialog signal edit_existing_textBox enum State { + NONE, CREATING, EDITING } @export -var _state = State.CREATING +var _state = State.NONE @export var _position : Vector2 func _ready() -> void: super() - _state = State.CREATING + _state = State.NONE +func _process(delta: float) -> void: + print("State: ", _state) # ------------------------------------------------------------------------------------------------- func tool_event(event: InputEvent) -> void: + if event is InputEventMouseButton: if event.button_index == MOUSE_BUTTON_LEFT: - if event.pressed && _state == State.CREATING: - print(event.global_position) - for textBox : Label in get_parent()._textboxes_parent.get_children(): - if textBox.get_rect().has_point(event.global_position): - print("Click inside TextBox") - edit_existing_textBox.emit(textBox) - _state = State.EDITING - show_textBoxDialog.emit(_cursor.global_position) + print(_state) + if event.pressed && _state == State.NONE: + print("Create TextEdit Here") + + for textBox : Control in get_parent()._textboxes_parent.get_children(): + if textBox is Label: + print("Label ", event.global_position, textBox.get_rect(), textBox.get_global_rect()) + + if textBox.get_rect().has_point(event.global_position): + print("Click inside TextBox") + edit_existing_textBox.emit(textBox) + _state = State.EDITING + else: + print("Clicking outside TextBox") + elif textBox is TextEdit: + print("TextEdit") + + if _state == State.NONE: + show_textBoxDialog.emit(_cursor.global_position) + + elif event.button_index == MOUSE_BUTTON_RIGHT: + print("END Edit") diff --git a/lorien/Main.gd b/lorien/Main.gd index b034e765..82f47349 100644 --- a/lorien/Main.gd +++ b/lorien/Main.gd @@ -139,10 +139,10 @@ func _process(delta: float) -> void: var focused_control = get_viewport().gui_get_focus_owner() - if focused_control: - print("Focused Control: ", focused_control.name) - else: - print("No control has focus.") + #if focused_control: + # print("Focused Control: ", focused_control.name) + #else: + # print("No control has focus.") # Lower fps if user is idle var idle := (Time.get_ticks_msec() - _last_input_time) > Config.BACKGROUND_IDLE_TIME_THRESHOLD From 3268fd9bc01de327e4d0c236c5df3faf97489b17 Mon Sep 17 00:00:00 2001 From: Marco Eibensteiner Date: Wed, 12 Nov 2025 22:20:50 +0100 Subject: [PATCH 16/16] More clean up --- lorien/InfiniteCanvas/InfiniteCanvas.gd | 16 +--- lorien/InfiniteCanvas/InfiniteCanvas.tscn | 9 +- lorien/InfiniteCanvas/PanZoomCamera.gd | 2 - lorien/InfiniteCanvas/Tools/SelectionTool.gd | 1 - lorien/InfiniteCanvas/Tools/TextBoxTool.gd | 17 +--- lorien/Main.gd | 7 -- lorien/Misc/SvgExporter.gd | 5 -- lorien/ProjectManager/Project.gd | 5 -- lorien/ProjectManager/Serializer.gd | 3 +- lorien/TextBox/Panel.gd | 9 -- lorien/TextBox/TextBox.gd | 1 - lorien/TextBox/TextBox.tscn | 11 --- lorien/TextBox/TextBox2.gd | 58 ------------- lorien/TextBox/TextBoxEditor.tscn | 89 -------------------- 14 files changed, 6 insertions(+), 227 deletions(-) delete mode 100644 lorien/TextBox/Panel.gd delete mode 100644 lorien/TextBox/TextBox.gd delete mode 100644 lorien/TextBox/TextBox.tscn delete mode 100644 lorien/TextBox/TextBox2.gd delete mode 100644 lorien/TextBox/TextBoxEditor.tscn diff --git a/lorien/InfiniteCanvas/InfiniteCanvas.gd b/lorien/InfiniteCanvas/InfiniteCanvas.gd index 5cb706f7..249eb05a 100644 --- a/lorien/InfiniteCanvas/InfiniteCanvas.gd +++ b/lorien/InfiniteCanvas/InfiniteCanvas.gd @@ -20,7 +20,6 @@ const PLAYER = preload("res://Misc/Player/Player.tscn") @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") @@ -80,14 +79,10 @@ func _gui_input(event: InputEvent) -> void: # ------------------------------------------------------------------------------------------------- func _process_event(event: InputEvent) -> void: - print("Process Event") + if event is InputEventMouseMotion: - print("Input is Mouse Motion") info.current_pressure = event.pressure - print("Current Pressure ", info.current_pressure) - print("Event.pressure ", event.pressure) if info.pen_inverted != event.pen_inverted: - print("Pen Inverted is not the same as event pen inverted", info.pen_inverted, event.pen_inverted) info.pen_inverted = event.pen_inverted if info.pen_inverted: var tool_type := _active_tool_type @@ -99,13 +94,11 @@ func _process_event(event: InputEvent) -> void: use_tool(_active_tool_type) if event.is_action("deselect_all_strokes"): - print("Action is 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"): - print("Action is Delete Selected Strokes") if _active_tool == _selection_tool: _delete_selected_strokes() _delete_selected_text_boxes_strokes() @@ -417,7 +410,7 @@ func _do_delete_stroke(stroke: BrushStroke) -> void: info.stroke_count -= 1 # ------------------------------------------------------------------------------------------------- -func _do_delete_text_box(text_box: TextBox) -> void: +func _do_delete_text_box(text_box: Label) -> void: var index := _current_project.textBoxes.find(text_box) _current_project.textBoxes.remove_at(index) _textboxes_parent.remove_child(text_box) @@ -434,7 +427,7 @@ func _undo_delete_stroke(stroke: BrushStroke) -> void: # 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: +func _undo_delete_text_box(text_box: Label) -> void: _current_project.textBoxes.append(text_box) _textboxes_parent.add_child(text_box) @@ -446,7 +439,6 @@ func _create_label(textBox : Label) -> void: # ------------------------------------------------------------------------------------------------- func _on_text_box_tool_show_text_box_dialog(dialogPosition : Vector2) -> void: - print("TEXT BOX TOOL SHOW") _textEdit = TextEdit.new() _textEdit.set_position(dialogPosition) _textEdit.custom_minimum_size = Vector2(350, 150) @@ -456,7 +448,6 @@ func _on_text_box_tool_show_text_box_dialog(dialogPosition : Vector2) -> void: # ------------------------------------------------------------------------------------------------- func _change_edit_to_label() -> void: - print("Focus Lost") if _textEdit.text != "": _on_text_box_editor_text_box_ok(_textEdit.text, _textEdit.position) _textbox_tool._state = _textbox_tool.State.NONE @@ -467,7 +458,6 @@ func _change_edit_to_label() -> void: # ------------------------------------------------------------------------------------------------- func _on_text_box_editor_text_box_ok(value : String, labelPosition : Vector2) -> void: - print("Text Box OK") var label : Label = Label.new() label.text = value label.set_position(labelPosition) diff --git a/lorien/InfiniteCanvas/InfiniteCanvas.tscn b/lorien/InfiniteCanvas/InfiniteCanvas.tscn index 9802f750..1a792196 100644 --- a/lorien/InfiniteCanvas/InfiniteCanvas.tscn +++ b/lorien/InfiniteCanvas/InfiniteCanvas.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=19 format=3 uid="uid://c4u5gk5n2aiom"] +[gd_scene load_steps=18 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"] @@ -11,7 +11,6 @@ [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"] @@ -28,9 +27,6 @@ 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") @@ -103,8 +99,5 @@ offset_bottom = 22.3333 [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"] diff --git a/lorien/InfiniteCanvas/PanZoomCamera.gd b/lorien/InfiniteCanvas/PanZoomCamera.gd index c3135596..804b79c2 100644 --- a/lorien/InfiniteCanvas/PanZoomCamera.gd +++ b/lorien/InfiniteCanvas/PanZoomCamera.gd @@ -86,8 +86,6 @@ func _input(event): # ------------------------------------------------------------------------------------------------- func tool_event(event: InputEvent) -> void: - print(event) - print("Input is enabled: ", _is_input_enabled) if _is_input_enabled: if event is InputEventKey: if Utils.is_action_pressed("canvas_pan_key", event): diff --git a/lorien/InfiniteCanvas/Tools/SelectionTool.gd b/lorien/InfiniteCanvas/Tools/SelectionTool.gd index 23c46575..cc7e7a15 100644 --- a/lorien/InfiniteCanvas/Tools/SelectionTool.gd +++ b/lorien/InfiniteCanvas/Tools/SelectionTool.gd @@ -275,7 +275,6 @@ func _commit_text_boxes_under_selection_rectangle() -> void: for text_box: Label in get_tree().get_nodes_in_group(GROUP_TEXT_BOXES_IN_SELECTION_RECTANGLE): text_box.remove_from_group(GROUP_TEXT_BOXES_IN_SELECTION_RECTANGLE) text_box.add_to_group(GROUP_SELECTED_TEXT_BOXES) - print(get_selected_text_boxes()) # ------------------------------------------------------------------------------------------------ func _deselect_marked_strokes() -> void: diff --git a/lorien/InfiniteCanvas/Tools/TextBoxTool.gd b/lorien/InfiniteCanvas/Tools/TextBoxTool.gd index 6964d58c..40fca2ac 100644 --- a/lorien/InfiniteCanvas/Tools/TextBoxTool.gd +++ b/lorien/InfiniteCanvas/Tools/TextBoxTool.gd @@ -19,33 +19,18 @@ func _ready() -> void: super() _state = State.NONE -func _process(delta: float) -> void: - print("State: ", _state) # ------------------------------------------------------------------------------------------------- func tool_event(event: InputEvent) -> void: - - + if event is InputEventMouseButton: if event.button_index == MOUSE_BUTTON_LEFT: - print(_state) if event.pressed && _state == State.NONE: - print("Create TextEdit Here") for textBox : Control in get_parent()._textboxes_parent.get_children(): if textBox is Label: - print("Label ", event.global_position, textBox.get_rect(), textBox.get_global_rect()) - if textBox.get_rect().has_point(event.global_position): - print("Click inside TextBox") edit_existing_textBox.emit(textBox) _state = State.EDITING - else: - print("Clicking outside TextBox") - elif textBox is TextEdit: - print("TextEdit") if _state == State.NONE: show_textBoxDialog.emit(_cursor.global_position) - - elif event.button_index == MOUSE_BUTTON_RIGHT: - print("END Edit") diff --git a/lorien/Main.gd b/lorien/Main.gd index 82f47349..b15c0fbe 100644 --- a/lorien/Main.gd +++ b/lorien/Main.gd @@ -137,13 +137,6 @@ func _exit_tree() -> void: # ------------------------------------------------------------------------------------------------- func _process(delta: float) -> void: - var focused_control = get_viewport().gui_get_focus_owner() - - #if focused_control: - # print("Focused Control: ", focused_control.name) - #else: - # print("No control has focus.") - # Lower fps if user is idle var idle := (Time.get_ticks_msec() - _last_input_time) > Config.BACKGROUND_IDLE_TIME_THRESHOLD if !_player_enabled && !_canvas.is_drawing() && idle: diff --git a/lorien/Misc/SvgExporter.gd b/lorien/Misc/SvgExporter.gd index a3867103..15857b84 100644 --- a/lorien/Misc/SvgExporter.gd +++ b/lorien/Misc/SvgExporter.gd @@ -25,17 +25,12 @@ func export_svg(strokes: Array[BrushStroke], text_boxes: Array[Label], backgroun min_dim.y = min(min_dim.y, stroke.top_left_pos.y + stroke.global_position.y) max_dim.x = max(max_dim.x, stroke.bottom_right_pos.x + stroke.global_position.x) max_dim.y = max(max_dim.y, stroke.bottom_right_pos.y + stroke.global_position.y) - print("Stroke min",min_dim.x," ",min_dim.y) - print("Stroke max",max_dim.x," ",max_dim.y) for text_box: Label in text_boxes: min_dim.x = min(min_dim.x, text_box.get_rect().position.x) min_dim.y = min(min_dim.y, text_box.get_rect().position.y) max_dim.x = max(max_dim.x, text_box.get_rect().position.x+text_box.get_rect().size.x) max_dim.y = max(max_dim.y, text_box.get_rect().position.y+text_box.get_rect().size.y) - print("Global Position X: ",text_box.global_position.x, " Rect Position x: ", text_box.get_rect().position.x, " Rect Size x: ", text_box.get_rect().size.x) - print("Text Box min",min_dim.x," ",min_dim.y) - print("Text Box max",max_dim.x," ",max_dim.y) var size := max_dim - min_dim var margin_size := size * EDGE_MARGIN diff --git a/lorien/ProjectManager/Project.gd b/lorien/ProjectManager/Project.gd index 93d86424..42a87ab3 100644 --- a/lorien/ProjectManager/Project.gd +++ b/lorien/ProjectManager/Project.gd @@ -47,11 +47,6 @@ func remove_last_stroke() -> void: if !strokes.is_empty(): strokes.pop_back() -#------------------------------------------------------------------------------------------------- -func add_text_box(textBox : TextBox) -> void: - textBoxes.append(textBox) - dirty = true - # ------------------------------------------------------------------------------------------------- func get_scene_file_path() -> String: if filepath.is_empty(): diff --git a/lorien/ProjectManager/Serializer.gd b/lorien/ProjectManager/Serializer.gd index 878477ea..d7fad55f 100644 --- a/lorien/ProjectManager/Serializer.gd +++ b/lorien/ProjectManager/Serializer.gd @@ -6,7 +6,6 @@ class_name Serializer # ------------------------------------------------------------------------------------------------- const BRUSH_STROKE = preload("res://BrushStroke/BrushStroke.tscn") -const TEXT_BOX = preload("res://TextBox/TextBox.tscn") const COMPRESSION_METHOD = FileAccess.COMPRESSION_DEFLATE const POINT_ELEM_SIZE := 3 @@ -126,7 +125,7 @@ static func load_project(project: Project) -> void: var x = file.get_float() var y = file.get_float() var text = file.get_pascal_string() - var textBox : TextBox = TextBox.new() + var textBox : Label = Label.new() textBox.set_global_position(Vector2(x,y)) textBox.text = text; var r := file.get_8() diff --git a/lorien/TextBox/Panel.gd b/lorien/TextBox/Panel.gd deleted file mode 100644 index 20b5e8bb..00000000 --- a/lorien/TextBox/Panel.gd +++ /dev/null @@ -1,9 +0,0 @@ -extends Panel - -signal close_click - -func _gui_input(event: InputEvent) -> void: - if event is InputEventMouseButton: - if event.button_index == MOUSE_BUTTON_LEFT: - if event.pressed: - close_click.emit() diff --git a/lorien/TextBox/TextBox.gd b/lorien/TextBox/TextBox.gd deleted file mode 100644 index 91e4f423..00000000 --- a/lorien/TextBox/TextBox.gd +++ /dev/null @@ -1 +0,0 @@ -class_name TextBox extends TextEdit diff --git a/lorien/TextBox/TextBox.tscn b/lorien/TextBox/TextBox.tscn deleted file mode 100644 index bbe3bb06..00000000 --- a/lorien/TextBox/TextBox.tscn +++ /dev/null @@ -1,11 +0,0 @@ -[gd_scene format=3 uid="uid://7dswpn8jua61"] - -[node name="TextBox" type="Label"] -anchors_preset = 15 -anchor_right = 1.0 -anchor_bottom = 1.0 -grow_horizontal = 2 -grow_vertical = 2 - -[connection signal="mouse_entered" from="." to="." method="_on_mouse_entered"] -[connection signal="mouse_exited" from="." to="." method="_on_mouse_exited"] diff --git a/lorien/TextBox/TextBox2.gd b/lorien/TextBox/TextBox2.gd deleted file mode 100644 index 763b39fa..00000000 --- a/lorien/TextBox/TextBox2.gd +++ /dev/null @@ -1,58 +0,0 @@ -class_name TextBoxEditor extends PanelContainer - -@onready -var textEdit : TextEdit = $Panel/Panel/VBoxContainer/TextEdit -@onready -var saveButton : Button = $Panel/Panel/VBoxContainer/HBoxContainer/SaveButton -var textBox : TextBox -@onready -var panel : Panel = $Panel/Panel -signal textBox_ok -signal textBox_cancel -signal textBox_ok_update -var label_position : Vector2 - - -func _ready() -> void: - Settings.changed_theme.connect(_on_theme_changed) - -func _on_save_button_pressed() -> void: - if textBox == null: - textBox_ok.emit(textEdit.text, label_position) - else: - textBox_ok_update.emit() - textBox.text = textEdit.text - textBox = null - textEdit.text = "" - visible = false - - -func _unhandled_key_input(event: InputEvent) -> void: - if event is InputEventMouseButton: - textEdit.text = "" - visible = false - -func _on_close_requested() -> void: - textBox_cancel.emit() - textEdit.text = "" - visible = false - -func _on_cancel_button_pressed() -> void: - textBox_cancel.emit() - textEdit.text = "" - visible = false - - -func _on_panel_close_click() -> void: - textBox_cancel.emit() - textEdit.text = "" - visible = false - -func _on_theme_changed(themeName : String) -> void: - var themePath : String = str("res://UI/Themes/", themeName, "/theme.tres") - var currentTheme : Theme = load(themePath) - theme = currentTheme - -func _on_visibility_changed() -> void: - if visible: - textEdit.grab_focus() diff --git a/lorien/TextBox/TextBoxEditor.tscn b/lorien/TextBox/TextBoxEditor.tscn deleted file mode 100644 index aff06eca..00000000 --- a/lorien/TextBox/TextBoxEditor.tscn +++ /dev/null @@ -1,89 +0,0 @@ -[gd_scene load_steps=6 format=3 uid="uid://ccl05i282g120"] - -[ext_resource type="Script" path="res://TextBox/TextBox2.gd" id="1_l1c4a"] -[ext_resource type="Script" path="res://TextBox/Panel.gd" id="2_fvesn"] - -[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_jirs3"] -bg_color = Color(0.6, 0.6, 0.6, 0) - -[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_u5mq5"] -bg_color = Color(0.6, 0.6, 0.6, 0) - -[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_q5oxc"] -bg_color = Color(0.266575, 0.266575, 0.266575, 1) - -[node name="PopupPanel" type="PanelContainer"] -visible = false -anchors_preset = 15 -anchor_right = 1.0 -anchor_bottom = 1.0 -grow_horizontal = 2 -grow_vertical = 2 -theme_override_styles/panel = SubResource("StyleBoxFlat_jirs3") -script = ExtResource("1_l1c4a") - -[node name="Panel" type="Panel" parent="."] -layout_mode = 2 -theme_override_styles/panel = SubResource("StyleBoxFlat_u5mq5") -script = ExtResource("2_fvesn") - -[node name="Panel" type="Panel" parent="Panel"] -layout_mode = 1 -anchors_preset = 8 -anchor_left = 0.5 -anchor_top = 0.5 -anchor_right = 0.5 -anchor_bottom = 0.5 -offset_left = -200.0 -offset_top = -110.0 -offset_right = 200.0 -offset_bottom = 110.0 -grow_horizontal = 2 -grow_vertical = 2 -theme_override_styles/panel = SubResource("StyleBoxFlat_q5oxc") - -[node name="VBoxContainer" type="VBoxContainer" parent="Panel/Panel"] -layout_mode = 1 -anchors_preset = 8 -anchor_left = 0.5 -anchor_top = 0.5 -anchor_right = 0.5 -anchor_bottom = 0.5 -offset_left = -200.0 -offset_top = -100.0 -offset_right = 200.0 -offset_bottom = 100.0 -grow_horizontal = 2 -grow_vertical = 2 - -[node name="TextEdit" type="TextEdit" parent="Panel/Panel/VBoxContainer"] -custom_minimum_size = Vector2(350, 150) -layout_mode = 2 -size_flags_horizontal = 4 -focus_next = NodePath("../HBoxContainer/SaveButton") -focus_previous = NodePath("../HBoxContainer/CancelButton") - -[node name="HBoxContainer" type="HBoxContainer" parent="Panel/Panel/VBoxContainer"] -layout_mode = 2 -size_flags_horizontal = 4 - -[node name="SaveButton" type="Button" parent="Panel/Panel/VBoxContainer/HBoxContainer"] -layout_mode = 2 -focus_neighbor_left = NodePath("../CancelButton") -focus_neighbor_right = NodePath("../CancelButton") -focus_next = NodePath("../CancelButton") -focus_previous = NodePath("../CancelButton") -text = "Save" - -[node name="CancelButton" type="Button" parent="Panel/Panel/VBoxContainer/HBoxContainer"] -layout_mode = 2 -focus_neighbor_left = NodePath("../SaveButton") -focus_neighbor_right = NodePath("../SaveButton") -focus_next = NodePath("../SaveButton") -focus_previous = NodePath("../SaveButton") -text = "Cancel" - -[connection signal="visibility_changed" from="." to="." method="_on_visibility_changed"] -[connection signal="close_click" from="Panel" to="." method="_on_panel_close_click"] -[connection signal="pressed" from="Panel/Panel/VBoxContainer/HBoxContainer/SaveButton" to="." method="_on_save_button_pressed"] -[connection signal="pressed" from="Panel/Panel/VBoxContainer/HBoxContainer/CancelButton" to="." method="_on_cancel_button_pressed"]