From d894e9db860ddad9f82011baa9babcb2d8e3e267 Mon Sep 17 00:00:00 2001 From: Variable <77773850+Variable-ind@users.noreply.github.com> Date: Wed, 16 Oct 2024 18:30:30 +0500 Subject: [PATCH] Added Centre Canvas Option (#1123) * add a centre frame option * moved code to view menu * restore left over stuff * fix typo --- project.godot | 5 +++++ src/Autoload/Global.gd | 2 ++ src/UI/TopMenuContainer/TopMenuContainer.gd | 5 +++++ 3 files changed, 12 insertions(+) diff --git a/project.godot b/project.godot index 12285e151..dfbc256ed 100644 --- a/project.godot +++ b/project.godot @@ -903,6 +903,11 @@ previous_project={ "events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":true,"ctrl_pressed":true,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194306,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null) ] } +centre_canvas={ +"deadzone": 0.5, +"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":true,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":67,"physical_keycode":0,"key_label":0,"unicode":67,"location":0,"echo":false,"script":null) +] +} [input_devices] diff --git a/src/Autoload/Global.gd b/src/Autoload/Global.gd index 5d89cdb28..b4b14b1bc 100644 --- a/src/Autoload/Global.gd +++ b/src/Autoload/Global.gd @@ -27,6 +27,7 @@ enum FileMenu { NEW, OPEN, OPEN_LAST_PROJECT, RECENT, SAVE, SAVE_AS, EXPORT, EXP enum EditMenu { UNDO, REDO, COPY, CUT, PASTE, PASTE_IN_PLACE, DELETE, NEW_BRUSH, PREFERENCES } ## Enumeration of items present in the View Menu. enum ViewMenu { + CENTRE_CANVAS, TILE_MODE, TILE_MODE_OFFSETS, GREYSCALE_VIEW, @@ -750,6 +751,7 @@ func _initialize_keychain() -> void: &"palettize": Keychain.InputAction.new("", "Effects menu", true), &"pixelize": Keychain.InputAction.new("", "Effects menu", true), &"posterize": Keychain.InputAction.new("", "Effects menu", true), + &"centre_canvas": Keychain.InputAction.new("", "View menu", true), &"mirror_view": Keychain.InputAction.new("", "View menu", true), &"show_grid": Keychain.InputAction.new("", "View menu", true), &"show_pixel_grid": Keychain.InputAction.new("", "View menu", true), diff --git a/src/UI/TopMenuContainer/TopMenuContainer.gd b/src/UI/TopMenuContainer/TopMenuContainer.gd index f27505ef1..00cf248d7 100644 --- a/src/UI/TopMenuContainer/TopMenuContainer.gd +++ b/src/UI/TopMenuContainer/TopMenuContainer.gd @@ -206,6 +206,7 @@ func _setup_edit_menu() -> void: func _setup_view_menu() -> void: # Order as in Global.ViewMenu enum var view_menu_items := { + "Centre Canvas": "centre_canvas", "Tile Mode": "", "Tile Mode Offsets": "", "Grayscale View": "", @@ -226,6 +227,8 @@ func _setup_view_menu() -> void: _setup_snap_to_submenu(item) elif item == "Tile Mode Offsets": view_menu.add_item(item, i) + elif item == "Centre Canvas": + _set_menu_shortcut(view_menu_items[item], view_menu, i, item) else: _set_menu_shortcut(view_menu_items[item], view_menu, i, item, true) view_menu.set_item_checked(Global.ViewMenu.SHOW_RULERS, true) @@ -599,6 +602,8 @@ func edit_menu_id_pressed(id: int) -> void: func view_menu_id_pressed(id: int) -> void: match id: + Global.ViewMenu.CENTRE_CANVAS: + Global.camera.offset = Global.current_project.size / 2 Global.ViewMenu.TILE_MODE_OFFSETS: _popup_dialog(get_tree().current_scene.tile_mode_offsets_dialog) Global.ViewMenu.GREYSCALE_VIEW: