From d7008362b507250ce1474cdbbceb95ab504f053f Mon Sep 17 00:00:00 2001 From: Manolis Papadeas <35376950+OverloadedOrama@users.noreply.github.com> Date: Mon, 23 Nov 2020 18:53:21 +0200 Subject: [PATCH] Added a "Mirror View" option in the View menu Which is used to flip the canvas horizontally and non-destructively. Closes #227 --- CHANGELOG.md | 1 + Translations/Translations.pot | 3 +++ project.godot | 5 +++++ src/Autoload/Global.gd | 1 + src/Tools/Draw.gd | 6 ++++++ src/UI/Canvas/Canvas.gd | 9 ++++++++- src/UI/Canvas/TileMode.gd | 9 +++++++++ src/UI/TopMenuContainer.gd | 38 +++++++++++++++++++++-------------- 8 files changed, 56 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9faf44761..539038a1d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ PinyaColada, RĂ©mi Verschelde (akien-mga), dasimonde, gschwind, AbhinavKDev - Added a "Recent Projects" option in the File menu, to contain the most recently opened projects. ([#370](https://github.com/Orama-Interactive/Pixelorama/pull/370)) - HiDPI support - Pixelorama's UI can now be scaled in the Preferences. ([#140](https://github.com/Orama-Interactive/Pixelorama/issues/140)) - More options have been added to Tile mode, Tile only in X Axis, Y Axis or both Axis. ([#378](https://github.com/Orama-Interactive/Pixelorama/pull/378)) +- Added a "Mirror View" option in the View menu, which is used to flip the canvas horizontally and non-destructively. ([#227](https://github.com/Orama-Interactive/Pixelorama/issues/227)) ### Changed - `~` is now used as a random brush prefix instead of `%`. ([#362](https://github.com/Orama-Interactive/Pixelorama/pull/362)) diff --git a/Translations/Translations.pot b/Translations/Translations.pot index 9c5c7288a..4bf58524f 100644 --- a/Translations/Translations.pot +++ b/Translations/Translations.pot @@ -142,6 +142,9 @@ msgstr "" msgid "Tile Mode" msgstr "" +msgid "Mirror View" +msgstr "" + msgid "Show Grid" msgstr "" diff --git a/project.godot b/project.godot index 80039b17a..ab98d0e0e 100644 --- a/project.godot +++ b/project.godot @@ -414,6 +414,11 @@ cut={ "events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":true,"meta":false,"command":true,"pressed":false,"scancode":88,"unicode":0,"echo":false,"script":null) ] } +mirror_view={ +"deadzone": 0.5, +"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":true,"control":false,"meta":false,"command":false,"pressed":false,"scancode":77,"unicode":0,"echo":false,"script":null) + ] +} [locale] diff --git a/src/Autoload/Global.gd b/src/Autoload/Global.gd index c011a69c4..845a7f7a9 100644 --- a/src/Autoload/Global.gd +++ b/src/Autoload/Global.gd @@ -75,6 +75,7 @@ var right_square_indicator_visible := false # View menu options var tile_mode : int = Tile_Mode.NONE +var mirror_view := false var draw_grid := false var show_rulers := true var show_guides := true diff --git a/src/Tools/Draw.gd b/src/Tools/Draw.gd index 60b785f24..31adf1aa9 100644 --- a/src/Tools/Draw.gd +++ b/src/Tools/Draw.gd @@ -257,6 +257,9 @@ func draw_tool_circle(position : Vector2, fill := false) -> void: func draw_tool_brush(position : Vector2) -> void: + if Global.mirror_view: + position.x = Global.current_project.size.x - position.x + if Global.tile_mode and _get_tile_mode_rect().has_point(position): position = position.posmodv(Global.current_project.size) @@ -331,6 +334,9 @@ func draw_indicator_at(position : Vector2, offset : Vector2, color : Color) -> v func _set_pixel(position : Vector2) -> void: var project : Project = Global.current_project + if Global.mirror_view: + position.x = project.size.x - position.x - 1 + if Global.tile_mode and _get_tile_mode_rect().has_point(position): position = position.posmodv(project.size) diff --git a/src/UI/Canvas/Canvas.gd b/src/UI/Canvas/Canvas.gd index 35a5ad558..c12eb1866 100644 --- a/src/UI/Canvas/Canvas.gd +++ b/src/UI/Canvas/Canvas.gd @@ -4,7 +4,7 @@ extends Node2D var location := Vector2.ZERO var fill_color := Color(0, 0, 0, 0) -var current_pixel := Vector2.ZERO # pretty much same as mouse_pos, but can be accessed externally +var current_pixel := Vector2.ZERO var can_undo := true var cursor_image_has_changed := false var sprite_changed_this_frame := false # for optimization purposes @@ -28,6 +28,12 @@ func _draw() -> void: var current_cels : Array = Global.current_project.frames[Global.current_project.current_frame].cels + var _position := position + var _scale := scale + if Global.mirror_view: + _position.x = _position.x + Global.current_project.size.x + _scale.x = -1 + draw_set_transform(_position, rotation, _scale) # Draw current frame layers for i in range(Global.current_project.layers.size()): var modulate_color := Color(1, 1, 1, current_cels[i].opacity) @@ -37,6 +43,7 @@ func _draw() -> void: if Global.onion_skinning: onion_skinning() tile_mode.update() + draw_set_transform(position, rotation, scale) func _input(event : InputEvent) -> void: diff --git a/src/UI/Canvas/TileMode.gd b/src/UI/Canvas/TileMode.gd index 0fd61e9a9..8a640457d 100644 --- a/src/UI/Canvas/TileMode.gd +++ b/src/UI/Canvas/TileMode.gd @@ -10,6 +10,13 @@ func _draw() -> void: var positions : Array = get_tile_positions(size) var tilemode_opacity = 1.0 - Global.tilemode_opacity + var _position := position + var _scale := scale + if Global.mirror_view: + _position.x = _position.x + Global.current_project.size.x + _scale.x = -1 + draw_set_transform(_position, rotation, _scale) + for i in range(Global.current_project.layers.size()): var modulate_color := Color(1, 1, 1, current_cels[i].opacity - tilemode_opacity) if Global.current_project.layers[i].visible: # if it's visible @@ -17,6 +24,8 @@ func _draw() -> void: for pos in positions: draw_texture(current_cels[i].image_texture, pos, modulate_color) + draw_set_transform(position, rotation, scale) + func get_tile_positions(size): match Global.tile_mode: diff --git a/src/UI/TopMenuContainer.gd b/src/UI/TopMenuContainer.gd index 82a06d595..6ff23401a 100644 --- a/src/UI/TopMenuContainer.gd +++ b/src/UI/TopMenuContainer.gd @@ -75,6 +75,7 @@ func setup_edit_menu() -> void: func setup_view_menu() -> void: var view_menu_items := { "Tile Mode" : 0, + "Mirror View" : InputMap.get_action_list("mirror_view")[0].get_scancode_with_modifiers(), "Show Grid" : InputMap.get_action_list("show_grid")[0].get_scancode_with_modifiers(), "Show Rulers" : InputMap.get_action_list("show_rulers")[0].get_scancode_with_modifiers(), "Show Guides" : InputMap.get_action_list("show_guides")[0].get_scancode_with_modifiers(), @@ -91,9 +92,9 @@ func setup_view_menu() -> void: else: view_menu.add_check_item(item, i, view_menu_items[item]) i += 1 - view_menu.set_item_checked(2, true) # Show Rulers - view_menu.set_item_checked(3, true) # Show Guides - view_menu.set_item_checked(4, true) # Show Animation Timeline + view_menu.set_item_checked(3, true) # Show Rulers + view_menu.set_item_checked(4, true) # Show Guides + view_menu.set_item_checked(5, true) # Show Animation Timeline view_menu.hide_on_checkable_item_selection = false view_menu.connect("id_pressed", self, "view_menu_id_pressed") @@ -253,17 +254,19 @@ func edit_menu_id_pressed(id : int) -> void: func view_menu_id_pressed(id : int) -> void: match id: - 1: # Show grid + 1: # Mirror View + toggle_mirror_view() + 2: # Show grid toggle_show_grid() - 2: # Show rulers + 3: # Show rulers toggle_show_rulers() - 3: # Show guides + 4: # Show guides toggle_show_guides() - 4: # Show animation timeline + 5: # Show animation timeline toggle_show_anim_timeline() - 5: # Zen mode + 6: # Zen mode toggle_zen_mode() - 6: # Fullscreen mode + 7: # Fullscreen mode toggle_fullscreen() Global.canvas.update() @@ -280,22 +283,27 @@ func tile_mode_submenu_id_pressed(id : int): Global.canvas.grid.set_position(Global.transparent_checker.get_position()) +func toggle_mirror_view() -> void: + Global.mirror_view = !Global.mirror_view + view_menu.set_item_checked(1, Global.mirror_view) + + func toggle_show_grid() -> void: Global.draw_grid = !Global.draw_grid - view_menu.set_item_checked(1, Global.draw_grid) + view_menu.set_item_checked(2, Global.draw_grid) Global.canvas.grid.update() func toggle_show_rulers() -> void: Global.show_rulers = !Global.show_rulers - view_menu.set_item_checked(2, Global.show_rulers) + view_menu.set_item_checked(3, Global.show_rulers) Global.horizontal_ruler.visible = Global.show_rulers Global.vertical_ruler.visible = Global.show_rulers func toggle_show_guides() -> void: Global.show_guides = !Global.show_guides - view_menu.set_item_checked(3, Global.show_guides) + view_menu.set_item_checked(4, Global.show_guides) for guide in Global.canvas.get_children(): if guide is Guide and guide in Global.current_project.guides: guide.visible = Global.show_guides @@ -310,7 +318,7 @@ func toggle_show_anim_timeline() -> void: if zen_mode: return Global.show_animation_timeline = !Global.show_animation_timeline - view_menu.set_item_checked(4, Global.show_animation_timeline) + view_menu.set_item_checked(5, Global.show_animation_timeline) Global.animation_timeline.visible = Global.show_animation_timeline @@ -321,12 +329,12 @@ func toggle_zen_mode() -> void: Global.control.get_node("MenuAndUI/UI/RightPanel").visible = zen_mode Global.control.get_node("MenuAndUI/UI/CanvasAndTimeline/ViewportAndRulers/TabsContainer").visible = zen_mode zen_mode = !zen_mode - view_menu.set_item_checked(5, zen_mode) + view_menu.set_item_checked(6, zen_mode) func toggle_fullscreen() -> void: OS.window_fullscreen = !OS.window_fullscreen - view_menu.set_item_checked(6, OS.window_fullscreen) + view_menu.set_item_checked(7, OS.window_fullscreen) func image_menu_id_pressed(id : int) -> void: