diff --git a/lorien/Assets/I18n/en.txt b/lorien/Assets/I18n/en.txt index 7a75ef3c..44e502ec 100644 --- a/lorien/Assets/I18n/en.txt +++ b/lorien/Assets/I18n/en.txt @@ -32,6 +32,8 @@ TOOLBAR_TOOLTIP_BRUSH_COLOR Brush Color TOOLBAR_TOOLTIP_BRUSH_SIZE Brush Size TOOLBAR_TOOLTIP_CANVAS_COLOR Canvas Color TOOLBAR_FULLSCREEN_TOGGLE Toggle fullscreen +TOOLBAR_TOOLTIP_ZOOM_TO_DRAWING Zoom to Drawing +TOOLBAR_TOOLTIP_RESET_TO_CENTER Reset Camera to Center # ----------------------------------------------------------------------------- # Color Palette Picker @@ -160,6 +162,8 @@ ACTION_toggle_zen_mode Toggle Zen Mode ACTION_toggle_player Toggle Easteregg ACTION_toggle_fullscreen Toggle Fullscreen ACTION_canvas_pan_key Pan Key +ACTION_canvas_reset_to_center Reset to center +ACTION_canvas_zoom_to_drawing Zoom to drawing # ----------------------------------------------------------------------------- # Kebindings dialog messages diff --git a/lorien/Assets/Icons/reset_to_center.png b/lorien/Assets/Icons/reset_to_center.png new file mode 100644 index 00000000..443708d1 Binary files /dev/null and b/lorien/Assets/Icons/reset_to_center.png differ diff --git a/lorien/Assets/Icons/reset_to_center.png.import b/lorien/Assets/Icons/reset_to_center.png.import new file mode 100644 index 00000000..33638091 --- /dev/null +++ b/lorien/Assets/Icons/reset_to_center.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://dcxctfytoiq28" +path="res://.godot/imported/reset_to_center.png-f0c4ce74002102472b04bab039768552.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://Assets/Icons/reset_to_center.png" +dest_files=["res://.godot/imported/reset_to_center.png-f0c4ce74002102472b04bab039768552.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/Assets/Icons/zoom_to_drawing.png b/lorien/Assets/Icons/zoom_to_drawing.png new file mode 100644 index 00000000..d8fd470b Binary files /dev/null and b/lorien/Assets/Icons/zoom_to_drawing.png differ diff --git a/lorien/Assets/Icons/zoom_to_drawing.png.import b/lorien/Assets/Icons/zoom_to_drawing.png.import new file mode 100644 index 00000000..b8a8893d --- /dev/null +++ b/lorien/Assets/Icons/zoom_to_drawing.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://dug7uaervy2ik" +path="res://.godot/imported/zoom_to_drawing.png-0adbb90ff26abb26c463d52713a19708.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://Assets/Icons/zoom_to_drawing.png" +dest_files=["res://.godot/imported/zoom_to_drawing.png-0adbb90ff26abb26c463d52713a19708.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 b42d3a25..29813587 100644 --- a/lorien/InfiniteCanvas/InfiniteCanvas.gd +++ b/lorien/InfiniteCanvas/InfiniteCanvas.gd @@ -104,6 +104,17 @@ func center_to_mouse() -> void: var screen_space_cursor_pos := _viewport.get_mouse_position() _camera.do_center(screen_space_cursor_pos) +# ------------------------------------------------------------------------------------------------- +func reset_to_center(): + if _active_tool != null: + _camera.reset_to_center() + +# ------------------------------------------------------------------------------------------------- +func zoom_to_drawing(): + if _active_tool != null: + _camera.zoom_to_drawing() + + # ------------------------------------------------------------------------------------------------- func use_tool(tool_type: int) -> void: var prev_tool := _active_tool diff --git a/lorien/InfiniteCanvas/PanZoomCamera.gd b/lorien/InfiniteCanvas/PanZoomCamera.gd index 521d07f7..2cf3ebf5 100644 --- a/lorien/InfiniteCanvas/PanZoomCamera.gd +++ b/lorien/InfiniteCanvas/PanZoomCamera.gd @@ -17,6 +17,8 @@ var _zoom_active := false var _current_zoom_level := 1.0 var _start_mouse_pos := Vector2(0.0, 0.0) +@onready var _topbar : VBoxContainer = get_node("/root/Main/Topbar") +@onready var _statusbar : Panel = get_node("/root/Main/Statusbar") # ------------------------------------------------------------------------------------------------- func set_zoom_level(zoom_level: float) -> void: _current_zoom_level = _to_nearest_zoom_step(zoom_level) @@ -33,6 +35,67 @@ func do_center(screen_space_center_point: Vector2) -> void: get_viewport().warp_mouse(screen_space_center) _do_pan(delta) +# ------------------------------------------------------------------------------------------------- +func reset_to_center(): + offset = Vector2(0.0,0.0) + emit_signal("position_changed", offset) + _zoom_canvas(1.0, Vector2(0.0,0.0)) + +# ------------------------------------------------------------------------------------------------- +func zoom_to_drawing(): + var max_dim : Vector2 = BrushStroke.MIN_VECTOR2 + var min_dim : Vector2 = BrushStroke.MAX_VECTOR2 + var project: Project = ProjectManager.get_active_project() + var zoom_steps_x : int = 0 + var zoom_steps_y : int = 0 + var zoom_x : float = 1 + var zoom_y :float = 1 + var final_zoom : float + var zoomed_viewport_size : Vector2 = get_viewport().size + + print(project.strokes.size()) + if project.strokes.is_empty(): + reset_to_center() + else: + #subtract UI size from viewport if it is visible + if _topbar.visible && _statusbar.visible: + zoomed_viewport_size.y = zoomed_viewport_size.y-(_topbar.get_rect().size.y+_statusbar.get_rect().size.y) + for stroke in project.strokes: + min_dim.x = min(min_dim.x, stroke.top_left_pos.x) + min_dim.y = min(min_dim.y, stroke.top_left_pos.y) + max_dim.x = max(max_dim.x, stroke.bottom_right_pos.x) + max_dim.y = max(max_dim.y, stroke.bottom_right_pos.y) + + var diff_max_dim = Vector2(abs(max_dim.x-min_dim.x), abs(max_dim.y-min_dim.y)) + + while diff_max_dim.x > zoomed_viewport_size.x: + zoomed_viewport_size.x = zoomed_viewport_size.x * 1.1 + zoom_x = zoom_x/1.1 + zoom_steps_x = zoom_steps_x + 1 + + while diff_max_dim.y > zoomed_viewport_size.y: + zoomed_viewport_size.y = zoomed_viewport_size.y * 1.1 + zoom_y = zoom_y/1.1 + zoom_steps_y = zoom_steps_y +1 + + if zoom_steps_x > zoom_steps_y: + final_zoom = zoom_x + else: + final_zoom = zoom_y + + var anchor = Vector2(min_dim.x+get_viewport().size.x/2, min_dim.y+get_viewport().size.y/2) + + final_zoom = final_zoom / 1.1 + var center_offset : Vector2 + center_offset.x = ((1/final_zoom)*get_viewport().size.x)-diff_max_dim.x + center_offset.y = ((1/final_zoom)*(get_viewport().size.y))-diff_max_dim.y + + _zoom_canvas(final_zoom, anchor) + offset = min_dim + offset.y = offset.y-((center_offset.y)/2) + offset.x = offset.x-(center_offset.x/2) + emit_signal("position_changed", offset) + # ------------------------------------------------------------------------------------------------- func tool_event(event: InputEvent) -> void: if _is_input_enabled: diff --git a/lorien/Main.gd b/lorien/Main.gd index 5f2e6dfb..75736d25 100644 --- a/lorien/Main.gd +++ b/lorien/Main.gd @@ -61,6 +61,9 @@ func _ready() -> void: _toolbar.save_project.connect(_on_save_project) _toolbar.brush_size_changed.connect(_on_brush_size_changed) _toolbar.tool_changed.connect(_on_tool_changed) + _toolbar.reset_to_center_action.connect(_on_reset_to_center_action) + _toolbar.zoom_to_drawing_action.connect(_on_zoom_to_drawing_action) + _menubar.create_new_project.connect(_on_create_new_project) _menubar.project_selected.connect(_on_project_selected) @@ -171,6 +174,10 @@ func _unhandled_input(event: InputEvent) -> void: _toggle_zen_mode() elif Utils.event_pressed_bug_workaround("toggle_fullscreen", event): _toggle_fullscreen() + elif Utils.event_pressed_bug_workaround("canvas_reset_to_center", event): + _on_reset_to_center_action() + elif Utils.event_pressed_bug_workaround("canvas_zoom_to_drawing", event): + _on_zoom_to_drawing_action() # ------------------------------------------------------------------------------------------------- func _toggle_player() -> void: @@ -574,3 +581,12 @@ func _get_general_ui_scale() -> float: elif smallest_dimension >= 1700: return Config.DEFAULT_UI_SCALE * 1.5 return Config.DEFAULT_UI_SCALE + +# -------------------------------------------------------------------------------------------------- +func _on_reset_to_center_action() -> void: + _canvas.reset_to_center() + +# -------------------------------------------------------------------------------------------------- +func _on_zoom_to_drawing_action() -> void: + _canvas.zoom_to_drawing() + diff --git a/lorien/UI/Toolbar.gd b/lorien/UI/Toolbar.gd index e9aeb34d..1c2cd381 100644 --- a/lorien/UI/Toolbar.gd +++ b/lorien/UI/Toolbar.gd @@ -10,6 +10,8 @@ signal redo_action signal toggle_brush_color_picker signal brush_size_changed(size: float) signal tool_changed(t: Types.Tool) +signal reset_to_center_action +signal zoom_to_drawing_action # ------------------------------------------------------------------------------------------------- const BUTTON_HOVER_COLOR = Color("50ffd6") @@ -25,6 +27,8 @@ const BUTTON_NORMAL_COLOR = Color.WHITE @onready var _undo_button: FlatTextureButton = $Console/Left/UndoButton @onready var _redo_button: FlatTextureButton = $Console/Left/RedoButton @onready var _color_button: Button = $Console/Left/ColorButton +@onready var _reset_to_center_button: FlatTextureButton = $Console/Left/ResetToCenterButton +@onready var _zoom_to_drawing_button: FlatTextureButton = $Console/Left/ZoomToDrawingButton @onready var _brush_size_label: Label = $Console/Left/BrushSizeLabel @onready var _brush_size_slider: HSlider = $Console/Left/BrushSizeSlider @onready var _tool_btn_brush: FlatTextureButton = $Console/Left/BrushToolButton @@ -58,6 +62,8 @@ func _ready() -> void: _open_button.pressed.connect(_on_open_project_pressed) _save_button.pressed.connect(func() -> void: save_project.emit()) _color_button.pressed.connect(func() -> void: toggle_brush_color_picker.emit()) + _reset_to_center_button.pressed.connect(func() -> void: reset_to_center_action.emit()) + _zoom_to_drawing_button.pressed.connect(func() -> void: zoom_to_drawing_action.emit()) _brush_size_slider.value_changed.connect(_on_brush_size_changed) _tool_btn_brush.pressed.connect(_on_brush_tool_pressed) _tool_btn_rectangle.pressed.connect(_on_rectangle_tool_pressed) diff --git a/lorien/UI/Toolbar.tscn b/lorien/UI/Toolbar.tscn index af371b34..ddbb4aca 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=21 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"] @@ -12,6 +12,8 @@ [ext_resource type="Texture2D" uid="uid://bn1qdw0v30np0" path="res://Assets/Icons/line_tool.png" id="11"] [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://dug7uaervy2ik" path="res://Assets/Icons/zoom_to_drawing.png" id="15_b47ao"] +[ext_resource type="Texture2D" uid="uid://dcxctfytoiq28" path="res://Assets/Icons/reset_to_center.png" id="15_r3wm2"] [ext_resource type="Texture2D" uid="uid://ddxis8f7tvg66" path="res://Assets/Icons/selection_tool.png" id="16"] [ext_resource type="Texture2D" uid="uid://0qicbkag5jd3" path="res://Assets/Icons/circle_tool.png" id="19"] @@ -219,6 +221,32 @@ value = 5.0 layout_mode = 2 text = "12" +[node name="VSeparator5" type="VSeparator" parent="Console/Left"] +layout_mode = 2 +theme_override_styles/separator = SubResource("3") + +[node name="ResetToCenterButton" type="TextureButton" parent="Console/Left"] +layout_mode = 2 +size_flags_horizontal = 4 +size_flags_vertical = 4 +tooltip_text = "TOOLBAR_TOOLTIP_RESET_TO_CENTER" +toggle_mode = true +texture_normal = ExtResource("15_r3wm2") +script = ExtResource("13") +hover_tint = Color(0.662745, 0.945098, 0.87451, 1) +pressed_tint = Color(0.572549, 1, 0.894118, 1) + +[node name="ZoomToDrawingButton" type="TextureButton" parent="Console/Left"] +layout_mode = 2 +size_flags_horizontal = 4 +size_flags_vertical = 4 +tooltip_text = "TOOLBAR_TOOLTIP_ZOOM_TO_DRAWING" +toggle_mode = true +texture_normal = ExtResource("15_b47ao") +script = ExtResource("13") +hover_tint = Color(0.662745, 0.945098, 0.87451, 1) +pressed_tint = Color(0.572549, 1, 0.894118, 1) + [node name="Right" type="HBoxContainer" parent="Console"] layout_mode = 2 size_flags_horizontal = 3 diff --git a/lorien/project.godot b/lorien/project.godot index ed5ebd23..f3fbb99d 100644 --- a/lorien/project.godot +++ b/lorien/project.godot @@ -242,6 +242,16 @@ canvas_pan_key={ "events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":32,"physical_keycode":0,"key_label":0,"unicode":32,"location":0,"echo":false,"script":null) ] } +canvas_reset_to_center={ +"deadzone": 0.5, +"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":0,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null) +] +} +canvas_zoom_to_drawing={ +"deadzone": 0.5, +"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":0,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null) +] +} [locale]