1
0
Fork 0
mirror of https://github.com/Orama-Interactive/Pixelorama.git synced 2025-01-19 17:49:47 +00:00
Pixelorama/src/Main.gd

427 lines
18 KiB
GDScript3
Raw Normal View History

2019-08-18 09:28:38 +00:00
extends Control
var opensprite_file_selected := false
var redone := false
var is_quitting_on_save := false
2019-08-18 09:28:38 +00:00
var tallscreen_is_active = false
onready var ui := $MenuAndUI/UI
onready var tools_and_canvas : HSplitContainer = $MenuAndUI/UI/ToolsAndCanvas
onready var tallscreen_hsplit_container : HSplitContainer = $MenuAndUI/UI/ToolsAndCanvas/CanvasAndTimeline/TallscreenHSplitContainer
onready var bottom_panel : VSplitContainer = tallscreen_hsplit_container.get_node("BottomPanel")
onready var right_panel := $MenuAndUI/UI/RightPanel
onready var tool_and_palette_vsplit := $MenuAndUI/UI/RightPanel/MarginContainer/PreviewAndPalettes/ToolAndPaletteVSplit
onready var color_and_tool_options := $MenuAndUI/UI/RightPanel/MarginContainer/PreviewAndPalettes/ToolAndPaletteVSplit/ColorAndToolOptions
onready var canvas_preview_container := $MenuAndUI/UI/RightPanel/MarginContainer/PreviewAndPalettes/CanvasPreviewContainer
onready var tool_panel := $MenuAndUI/UI/ToolsAndCanvas/ToolPanel
onready var scroll_container := $MenuAndUI/UI/RightPanel/MarginContainer/PreviewAndPalettes/ToolAndPaletteVSplit/ColorAndToolOptions/ScrollContainer
2019-08-18 09:28:38 +00:00
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
var alternate_transparent_background := ColorRect.new()
add_child(alternate_transparent_background)
move_child(alternate_transparent_background,0)
alternate_transparent_background.visible = false
alternate_transparent_background.name = "AlternateTransparentBackground"
alternate_transparent_background.anchor_left = ANCHOR_BEGIN
alternate_transparent_background.anchor_top = ANCHOR_BEGIN
alternate_transparent_background.anchor_right = ANCHOR_END
alternate_transparent_background.anchor_bottom = ANCHOR_END
get_tree().set_auto_accept_quit(false)
setup_application_window_size()
handle_resize()
get_tree().get_root().connect("size_changed", self, "handle_resize")
Global.window_title = tr("untitled") + " - Pixelorama " + Global.current_version
Global.current_project.layers[0].name = tr("Layer") + " 0"
Import.import_brushes(Global.directory_module.get_brushes_search_path_in_order())
Import.import_patterns(Global.directory_module.get_patterns_search_path_in_order())
Global.quit_and_save_dialog.add_button("Save & Exit", false, "Save")
Global.quit_and_save_dialog.get_ok().text = "Exit without saving"
Global.open_sprites_dialog.current_dir = Global.config_cache.get_value("data", "current_dir", OS.get_system_dir(OS.SYSTEM_DIR_DESKTOP))
Global.save_sprites_dialog.current_dir = Global.config_cache.get_value("data", "current_dir", OS.get_system_dir(OS.SYSTEM_DIR_DESKTOP))
(Port) Port Pixelorama to Ubuntu Touch (#517) * Add support for creating Ubuntu Touch click packages. The clickable directory contains the files necessary to create a click package designed for Ubuntu Touch, a community-driven Linux distro for mobile phones as an alternative to iOS and Android. A new CI script has been added to create the packages, which is copied over from one of my other projects. Please change this to suit your needs. A new custom feature "clickable" has been added to the project settings to allow customizations for the Ubuntu Touch platform. Signed-off-by: Marquis Kurt <software@marquiskurt.net> * Make clickable CI follow more closely to desktop builds * Remove sudo from clickable install step * Install software-properties-common * Comment out docker startups in click install * Change export name for Click version * Change name and export mode to pack only * Change means of copying data to clickable dir * Install sudo to docker * Add -g to docker add user * Remove docker user creation * Remove other chpasswd stuff * Split CI into two jobs * Make build-ubports.sh runnable * Use HiPDI GUI theme on Clickable * Move clickable folder to Misc, add release CI targets * Add mobile to clickable settings * Add pixelorama_data to install data * Create pixelorama_data subdir in click itself * Change default save dir for clickable * Update AppArmor policy * Update clickable version to test AppArmor * Revert changes and use user data dir * Add README pertaining to Ubuntu Touch * Remove GODOT_MAC_VERSION from UT port workflow Co-authored-by: Manolis Papadeas <35376950+OverloadedOrama@users.noreply.github.com>
2021-09-25 10:42:31 +00:00
# FIXME: OS.get_system_dir does not grab the correct directory for Ubuntu Touch.
# Additionally, AppArmor policies prevent the app from writing to the /home
# directory. Until the proper AppArmor policies are determined to write to these
# files accordingly, use the user data folder where cache.ini is stored.
# Ubuntu Touch users can access these files in the File Manager at the directory
# ~/.local/pixelorama.orama-interactive/godot/app_userdata/Pixelorama.
if OS.has_feature("clickable"):
Global.open_sprites_dialog.current_dir = OS.get_user_data_dir()
Global.save_sprites_dialog.current_dir = OS.get_user_data_dir()
var zstd_checkbox := CheckBox.new()
zstd_checkbox.name = "ZSTDCompression"
zstd_checkbox.pressed = true
zstd_checkbox.text = "Use ZSTD Compression"
zstd_checkbox.mouse_default_cursor_shape = Control.CURSOR_POINTING_HAND
Global.save_sprites_dialog.get_vbox().add_child(zstd_checkbox)
handle_backup()
# If the user wants to run Pixelorama with arguments in terminal mode
# or open files with Pixelorama directly, then handle that
if OS.get_cmdline_args():
OpenSave.handle_loading_files(OS.get_cmdline_args())
get_tree().connect("files_dropped", self, "_on_files_dropped")
if OS.get_name() == "Android":
OS.request_permissions()
show_splash_screen()
func handle_resize() -> void:
var aspect_ratio = get_viewport_rect().size.x/(0.00001 if get_viewport_rect().size.y == 0 else get_viewport_rect().size.y)
if ( (aspect_ratio <= 3.0/4.0 and Global.panel_layout != Global.PanelLayout.WIDESCREEN)
or Global.panel_layout == Global.PanelLayout.TALLSCREEN):
change_ui_layout("tallscreen")
else:
change_ui_layout("widescreen")
func change_ui_layout(mode : String) -> void:
var colorpicker_is_switched = true if tool_and_palette_vsplit.has_node("ScrollContainer") else false
if mode == "tallscreen" and not tallscreen_is_active:
tallscreen_is_active = true
# changing visibility and re-parenting of nodes for tall screen
if !Global.top_menu_container.zen_mode:
tallscreen_hsplit_container.visible = true
tallscreen_hsplit_container.split_offset = tools_and_canvas.split_offset
reparent_node_to(Global.animation_timeline, tallscreen_hsplit_container.get_node("BottomPanel"), 0)
reparent_node_to(right_panel, bottom_panel, 0)
right_panel.rect_min_size.y = 322
reparent_node_to(canvas_preview_container, tool_and_palette_vsplit, 1)
tool_and_palette_vsplit = replace_node_with(tool_and_palette_vsplit, HBoxContainer.new())
tool_and_palette_vsplit.set("custom_constants/separation", 8)
color_and_tool_options.rect_min_size.x = 280
reparent_node_to(tool_panel, tallscreen_hsplit_container, 0)
var right_panel_margin : MarginContainer = right_panel.find_node("MarginContainer", true, false)
right_panel_margin.set("custom_constants/margin_top", 8)
right_panel_margin.set("custom_constants/margin_left", 0)
right_panel_margin.set("custom_constants/margin_right", 0)
right_panel.find_node("PalettePanel", true, false).size_flags_horizontal = SIZE_FILL
elif mode == "widescreen" and tallscreen_is_active:
tallscreen_is_active = false
# Reparenting and hiding nodes to adjust wide-screen
reparent_node_to(Global.animation_timeline, ui.get_node("ToolsAndCanvas/CanvasAndTimeline"), 1)
tallscreen_hsplit_container.visible = false
tools_and_canvas.split_offset = tallscreen_hsplit_container.split_offset
reparent_node_to(right_panel, ui, -1)
right_panel.rect_min_size.y = 0
reparent_node_to(canvas_preview_container, right_panel.find_node("PreviewAndPalettes"), 0)
tool_and_palette_vsplit = replace_node_with(tool_and_palette_vsplit, VSplitContainer.new())
color_and_tool_options.rect_min_size.x = 0
canvas_preview_container.visible = true
reparent_node_to(tool_panel, ui.find_node("ToolsAndCanvas"), 0)
var right_panel_margin : MarginContainer = right_panel.find_node("MarginContainer", true, false)
right_panel_margin.set("custom_constants/margin_top", 0)
right_panel_margin.set("custom_constants/margin_left", 8)
right_panel_margin.set("custom_constants/margin_right", 8)
right_panel.find_node("PalettePanel", true, false).size_flags_horizontal = SIZE_EXPAND_FILL
if get_viewport_rect().size.x < 908 and mode == "tallscreen":
canvas_preview_container.visible = false
else:
canvas_preview_container.visible = true
if not colorpicker_is_switched and canvas_preview_container.visible and mode == "tallscreen":
reparent_node_to(scroll_container, tool_and_palette_vsplit, 0)
scroll_container.rect_min_size = Vector2(268, 196)
color_and_tool_options.set("custom_constants/separation", 20)
reparent_node_to(canvas_preview_container, color_and_tool_options, -1)
elif colorpicker_is_switched and (not canvas_preview_container.visible or mode != "tallscreen"):
reparent_node_to(scroll_container, color_and_tool_options, -1)
scroll_container.rect_min_size = Vector2(0, 0)
color_and_tool_options.set("custom_constants/separation", 8)
if mode == "widescreen":
reparent_node_to(canvas_preview_container, right_panel.find_node("PreviewAndPalettes", true, false), 0)
else:
reparent_node_to(canvas_preview_container, tool_and_palette_vsplit, 1)
# helper function (change_ui_layout)
# warning: this doesn't really copy any sort of attributes, except a few that were needed in my particular case
func replace_node_with(old : Node, new : Node) -> Node:
var tempname = old.name
old.name = "old"
new.name = tempname
new.size_flags_vertical = old.size_flags_horizontal
new.size_flags_vertical = old.size_flags_vertical
# new.set("custom_constants/autohide", old.get("custom_constants/autohide"))
if new is HBoxContainer:
new.set_alignment(HBoxContainer.ALIGN_CENTER)
new.set("custom_constants/separation", 20)
old.get_parent().add_child(new)
for n in old.get_children():
reparent_node_to(n, new, -1)
old.get_parent().remove_child(old)
old.queue_free()
return new
# helper function (change_ui_layout)
func reparent_node_to(node : Node, dest : Node, pos : int) -> bool:
if dest is Node and node is Node:
node.get_parent().remove_child(node)
dest.add_child(node)
node.set_owner(dest)
if pos >= 0:
dest.move_child(node, pos)
return true
else:
return false
func _input(event : InputEvent) -> void:
Global.left_cursor.position = get_global_mouse_position() + Vector2(-32, 32)
Global.left_cursor.texture = Global.left_cursor_tool_texture
Global.right_cursor.position = get_global_mouse_position() + Vector2(32, 32)
Global.right_cursor.texture = Global.right_cursor_tool_texture
if event is InputEventKey and (event.scancode == KEY_ENTER or event.scancode == KEY_KP_ENTER):
if get_focus_owner() is LineEdit:
get_focus_owner().release_focus()
# The section of code below is reserved for Undo and Redo! Do not place code for Input below, but above.
if !event.is_echo(): # Checks if the action is pressed down
New selection system (#474) * Basic move tool * Added marching ants effect on the selection borders * Rename SelectionRectangle to SelectionShape, make it have non-rectangular shape and multiple SelectionShapes can exist - Create multiple selection rectangles - Merge them together if they intersect - Move the selections (without contents as of right now) - Gizmos are being drawn but they are not functional yet Code is very ugly. * Sort vectors counter-clockwise to be used as polygon borders I did this, no idea if it works properly, probably won't be used but I thought I'd keep it saved somewhere * More experiments I may or may not need Trying to generate a polygon from the individual selected pixels * Change default rectangle select behavior and ability to clip polygons using Control * Fix rectangle selection clipping * Split polygon into two with selection subtracting * Move selection with contents with the move tool Code is still a mess, don't bother looking. * Move some methods from SelectionShape.gd to Selection.gd The purpose of this is to generalize some selection code, so that it applies to all polygons, the entire selection. More will follow. * UndoRedo for border moving Nothing else in the selections system works properly in UndoRedo right now. Needs: - UR support for creating selections - UR support for modifying selections (merging and cutting selections together) - UR support for removing selection - UR support for moving content & for all the rest of the remaining features * Moving all of the selection shape logic to Selection.gd Handle all of the polygons there instead of having them as individual nodes. Should be easier to handle undo/redo this way. This commit probably breaks move tool + selection tool and undo/redo. Code is still a mess. For your sanity, I hope you are not reading this. I promise I will clean up. * Move tool works again Buggy and messy, of course. * Remove unneeded code and restore selection move undoredo logic * Made Selection.gd have one big preview_image for when moving content, instead of each polygon having its own image Could be further optimized for some specific cases. We could also remove selected_pixels from SelectionPolygon. * UndoRedo support for creating, deleting, merging and clipping selections UndoRedo support for moving content not added in this commit. Should work but needs more testing. This PR also removes selected_pixels from the SelectionPolygon class. * Confirm & cancel selection movement, should support undoredo properly too Press Enter or do any editing to confirm movement, Escape to cancel. I will most likely add UI buttons for confirm and cancel too. * Mirror View affects selection * Restore Cut, Copy, Paste and Clear Selection Pasting now no longer requires a pre-existing selection and instead copies the selections themselves too. * Created a new Select menu, which has Select All and Clear Selection as options Clear Selection now also confirms content moving. TopMenuContainer code has changed to no longer rely on Global for the menu buttons. * Draw gizmos as rectangles No functionality yet. They may need to be turned to nodes, so that they can easily resize based on zoom level and check for mouse enter/exit events. * Made gizmos get drawn in the sides and corners of the big bounding rectangle instead of individual selection parts Still no functionality yet. * Restore label text * Minor optimization when clipping selections This will execute the for loop less times * Made a Gizmo class, cursor change on hover, has_focus = false on mouse click Now I should actually make them resize when dragged, aye? * Very basic gizmo resizing, still a WIP, does not work properly yet * Start replacing the array of selected pixels with a BitMap This should optimize the selection making a lot, and it also allows for easy border drawing without having to deal with polygons, thanks to the MarchingAntsOutline.shader Still commit is still a WIP, image effects and brushes may not work properly yet. Because the BitMap has a fixed size, the size of the project, moving the selection outside of canvas boundaries has proven to be a bit tricky. I did implement a hacky way of handling it, but it may be buggy and problematic. I'm still unsure whether this is the best way to handle the situation. * Selection works with mirror view * Draw a black rectangle when the user is making a rectangular selection After they release the mouse, the black rectangle becomes the selection * Make Selection.gd update when undoing/redoing * Fix brushes not working properly with non-rectangular selections * Added invert selection * Cache has_selection as a variable for a speedup * Fix conflict issues with the shape tools * Made the bitmap image squared so the marching ants effect will be the same on both dimensions There may be a better way to fix the issue, perhaps inside the shader itself. * Some optimizations to call selection_bitmap_changed() less times * Restored almost all of the image effects Left to do: - Change gradient's behavior. Unsure of how it will work with non-rectangular selections yet, but it should not generate pixels outside of the selection. - Restore rotation - Resize bitmap on image resize - Remove the `pixels` array from the ImageEffect * Fix Selection.gd not updating when changing project * Resize the selection bitmap along with image resize * Restored rotation's old behavior and finally got rid of the selected_pixels array The rotation does not yet work properly with selections, but at least it now "works". * Resize selection too when using gizmos Left to do for gizmos: - Proper cancel transformation - Begin transformation (currently named move_content_start but it should be renamed to something more general) when resizing gizmos - Keep the original image and selection in memory and resize them. Meaning, gizmos should not resize the already resized data, but only resize the original. This is less destructive as there is no danger of data loss. - Always resize on InputEventMouseMotion. This is going to be worse for performance, but it will look better for the user. * Image and bitmap resizing now uses the original data and begin transformation on gizmo click No matter how many times the user resizes on the current transformation, the original data will not be lost until they either confirm or cancel, so there is no data loss before confirmation/cancel. * Cancel transformation now works properly when the selection has been resized * Made gizmos resize on mouse motion, fix issues with negative bounding rectangle and when combined with the move tool * Resizing can now get out of positive bounds, clearing and inverting now gets limited to the canvas bounds Resizing currently does not work properly with negative (left & up) canvas boundaries * Flip image when resizing and the bounding rectangle gets flipped * Call move_content_confirm() when inverting selection * Attempt to implement selection resizing that goes outside of the canvas boundaries (not working properly yet) * Flip selection when resizing to negative bounding rectangle sizes And fix preview_image vertical flipping * Fix rotation so that it works (almost) properly with selections Rotation algorithms now accept and only work with a given image, and the pivot has been added as a parameter * Experimental gizmo rotation - does not work properly yet Transforming the selection outside of the canvas is still broken. * Fix some issues with moving selection out of canvas bounds * Fix more issues with selection getting resized outside of canvas bounds * Update marching ants effect properly when switching between projects And make sure the frequency of the marching ants effect always looks roughly the same on all project sizes * Made the rotation gizmo part of the gizmos array and resize them based on camera zoom * Remove unneeded parameter from move_bitmap_values() * Remove more unneeded parameters * Move the selection only if the cursor is above it and neither shift nor control are currently pressed * Gradient generation now works on non-rectangular selections Although this behavior might not be the intended one * Copy/paste marching ants effect offset Useful for when the selection is in negative coords * Fix issue with clear selection & UndoRedo * Restore the ability to move selection when it's in negative coords * Made the marching ants offset a Project variable This fixes the issue of project switching and keeping the previous project's offset. Again, this is only relevant for when the selection is in negative coords. * Made the "from current selection" palette preset work with the new selection system * Fix out of bounds error when using the rectangular select tool on negative coords * Some code cleanup * Comment out the rotation gizmo for now, since it does not work properly * Update marching ants shader params and gizmo sizes when the bitmap changes * Move some methods around in Selection.gd
2021-04-17 18:30:12 +00:00
if event.is_action_pressed("redo_secondary"):
# Done, so that "redo_secondary" hasn't a slight delay before it starts.
# The "redo" and "undo" action don't have a slight delay,
# because they get called as an accelerator once pressed (TopMenuContainer.gd / Line 152).
Global.current_project.commit_redo()
return
if event.is_action("redo"): # Ctrl + Y
New selection system (#474) * Basic move tool * Added marching ants effect on the selection borders * Rename SelectionRectangle to SelectionShape, make it have non-rectangular shape and multiple SelectionShapes can exist - Create multiple selection rectangles - Merge them together if they intersect - Move the selections (without contents as of right now) - Gizmos are being drawn but they are not functional yet Code is very ugly. * Sort vectors counter-clockwise to be used as polygon borders I did this, no idea if it works properly, probably won't be used but I thought I'd keep it saved somewhere * More experiments I may or may not need Trying to generate a polygon from the individual selected pixels * Change default rectangle select behavior and ability to clip polygons using Control * Fix rectangle selection clipping * Split polygon into two with selection subtracting * Move selection with contents with the move tool Code is still a mess, don't bother looking. * Move some methods from SelectionShape.gd to Selection.gd The purpose of this is to generalize some selection code, so that it applies to all polygons, the entire selection. More will follow. * UndoRedo for border moving Nothing else in the selections system works properly in UndoRedo right now. Needs: - UR support for creating selections - UR support for modifying selections (merging and cutting selections together) - UR support for removing selection - UR support for moving content & for all the rest of the remaining features * Moving all of the selection shape logic to Selection.gd Handle all of the polygons there instead of having them as individual nodes. Should be easier to handle undo/redo this way. This commit probably breaks move tool + selection tool and undo/redo. Code is still a mess. For your sanity, I hope you are not reading this. I promise I will clean up. * Move tool works again Buggy and messy, of course. * Remove unneeded code and restore selection move undoredo logic * Made Selection.gd have one big preview_image for when moving content, instead of each polygon having its own image Could be further optimized for some specific cases. We could also remove selected_pixels from SelectionPolygon. * UndoRedo support for creating, deleting, merging and clipping selections UndoRedo support for moving content not added in this commit. Should work but needs more testing. This PR also removes selected_pixels from the SelectionPolygon class. * Confirm & cancel selection movement, should support undoredo properly too Press Enter or do any editing to confirm movement, Escape to cancel. I will most likely add UI buttons for confirm and cancel too. * Mirror View affects selection * Restore Cut, Copy, Paste and Clear Selection Pasting now no longer requires a pre-existing selection and instead copies the selections themselves too. * Created a new Select menu, which has Select All and Clear Selection as options Clear Selection now also confirms content moving. TopMenuContainer code has changed to no longer rely on Global for the menu buttons. * Draw gizmos as rectangles No functionality yet. They may need to be turned to nodes, so that they can easily resize based on zoom level and check for mouse enter/exit events. * Made gizmos get drawn in the sides and corners of the big bounding rectangle instead of individual selection parts Still no functionality yet. * Restore label text * Minor optimization when clipping selections This will execute the for loop less times * Made a Gizmo class, cursor change on hover, has_focus = false on mouse click Now I should actually make them resize when dragged, aye? * Very basic gizmo resizing, still a WIP, does not work properly yet * Start replacing the array of selected pixels with a BitMap This should optimize the selection making a lot, and it also allows for easy border drawing without having to deal with polygons, thanks to the MarchingAntsOutline.shader Still commit is still a WIP, image effects and brushes may not work properly yet. Because the BitMap has a fixed size, the size of the project, moving the selection outside of canvas boundaries has proven to be a bit tricky. I did implement a hacky way of handling it, but it may be buggy and problematic. I'm still unsure whether this is the best way to handle the situation. * Selection works with mirror view * Draw a black rectangle when the user is making a rectangular selection After they release the mouse, the black rectangle becomes the selection * Make Selection.gd update when undoing/redoing * Fix brushes not working properly with non-rectangular selections * Added invert selection * Cache has_selection as a variable for a speedup * Fix conflict issues with the shape tools * Made the bitmap image squared so the marching ants effect will be the same on both dimensions There may be a better way to fix the issue, perhaps inside the shader itself. * Some optimizations to call selection_bitmap_changed() less times * Restored almost all of the image effects Left to do: - Change gradient's behavior. Unsure of how it will work with non-rectangular selections yet, but it should not generate pixels outside of the selection. - Restore rotation - Resize bitmap on image resize - Remove the `pixels` array from the ImageEffect * Fix Selection.gd not updating when changing project * Resize the selection bitmap along with image resize * Restored rotation's old behavior and finally got rid of the selected_pixels array The rotation does not yet work properly with selections, but at least it now "works". * Resize selection too when using gizmos Left to do for gizmos: - Proper cancel transformation - Begin transformation (currently named move_content_start but it should be renamed to something more general) when resizing gizmos - Keep the original image and selection in memory and resize them. Meaning, gizmos should not resize the already resized data, but only resize the original. This is less destructive as there is no danger of data loss. - Always resize on InputEventMouseMotion. This is going to be worse for performance, but it will look better for the user. * Image and bitmap resizing now uses the original data and begin transformation on gizmo click No matter how many times the user resizes on the current transformation, the original data will not be lost until they either confirm or cancel, so there is no data loss before confirmation/cancel. * Cancel transformation now works properly when the selection has been resized * Made gizmos resize on mouse motion, fix issues with negative bounding rectangle and when combined with the move tool * Resizing can now get out of positive bounds, clearing and inverting now gets limited to the canvas bounds Resizing currently does not work properly with negative (left & up) canvas boundaries * Flip image when resizing and the bounding rectangle gets flipped * Call move_content_confirm() when inverting selection * Attempt to implement selection resizing that goes outside of the canvas boundaries (not working properly yet) * Flip selection when resizing to negative bounding rectangle sizes And fix preview_image vertical flipping * Fix rotation so that it works (almost) properly with selections Rotation algorithms now accept and only work with a given image, and the pivot has been added as a parameter * Experimental gizmo rotation - does not work properly yet Transforming the selection outside of the canvas is still broken. * Fix some issues with moving selection out of canvas bounds * Fix more issues with selection getting resized outside of canvas bounds * Update marching ants effect properly when switching between projects And make sure the frequency of the marching ants effect always looks roughly the same on all project sizes * Made the rotation gizmo part of the gizmos array and resize them based on camera zoom * Remove unneeded parameter from move_bitmap_values() * Remove more unneeded parameters * Move the selection only if the cursor is above it and neither shift nor control are currently pressed * Gradient generation now works on non-rectangular selections Although this behavior might not be the intended one * Copy/paste marching ants effect offset Useful for when the selection is in negative coords * Fix issue with clear selection & UndoRedo * Restore the ability to move selection when it's in negative coords * Made the marching ants offset a Project variable This fixes the issue of project switching and keeping the previous project's offset. Again, this is only relevant for when the selection is in negative coords. * Made the "from current selection" palette preset work with the new selection system * Fix out of bounds error when using the rectangular select tool on negative coords * Some code cleanup * Comment out the rotation gizmo for now, since it does not work properly * Update marching ants shader params and gizmo sizes when the bitmap changes * Move some methods around in Selection.gd
2021-04-17 18:30:12 +00:00
Global.current_project.commit_redo()
if event.is_action("redo_secondary"): # Shift + Ctrl + Z
New selection system (#474) * Basic move tool * Added marching ants effect on the selection borders * Rename SelectionRectangle to SelectionShape, make it have non-rectangular shape and multiple SelectionShapes can exist - Create multiple selection rectangles - Merge them together if they intersect - Move the selections (without contents as of right now) - Gizmos are being drawn but they are not functional yet Code is very ugly. * Sort vectors counter-clockwise to be used as polygon borders I did this, no idea if it works properly, probably won't be used but I thought I'd keep it saved somewhere * More experiments I may or may not need Trying to generate a polygon from the individual selected pixels * Change default rectangle select behavior and ability to clip polygons using Control * Fix rectangle selection clipping * Split polygon into two with selection subtracting * Move selection with contents with the move tool Code is still a mess, don't bother looking. * Move some methods from SelectionShape.gd to Selection.gd The purpose of this is to generalize some selection code, so that it applies to all polygons, the entire selection. More will follow. * UndoRedo for border moving Nothing else in the selections system works properly in UndoRedo right now. Needs: - UR support for creating selections - UR support for modifying selections (merging and cutting selections together) - UR support for removing selection - UR support for moving content & for all the rest of the remaining features * Moving all of the selection shape logic to Selection.gd Handle all of the polygons there instead of having them as individual nodes. Should be easier to handle undo/redo this way. This commit probably breaks move tool + selection tool and undo/redo. Code is still a mess. For your sanity, I hope you are not reading this. I promise I will clean up. * Move tool works again Buggy and messy, of course. * Remove unneeded code and restore selection move undoredo logic * Made Selection.gd have one big preview_image for when moving content, instead of each polygon having its own image Could be further optimized for some specific cases. We could also remove selected_pixels from SelectionPolygon. * UndoRedo support for creating, deleting, merging and clipping selections UndoRedo support for moving content not added in this commit. Should work but needs more testing. This PR also removes selected_pixels from the SelectionPolygon class. * Confirm & cancel selection movement, should support undoredo properly too Press Enter or do any editing to confirm movement, Escape to cancel. I will most likely add UI buttons for confirm and cancel too. * Mirror View affects selection * Restore Cut, Copy, Paste and Clear Selection Pasting now no longer requires a pre-existing selection and instead copies the selections themselves too. * Created a new Select menu, which has Select All and Clear Selection as options Clear Selection now also confirms content moving. TopMenuContainer code has changed to no longer rely on Global for the menu buttons. * Draw gizmos as rectangles No functionality yet. They may need to be turned to nodes, so that they can easily resize based on zoom level and check for mouse enter/exit events. * Made gizmos get drawn in the sides and corners of the big bounding rectangle instead of individual selection parts Still no functionality yet. * Restore label text * Minor optimization when clipping selections This will execute the for loop less times * Made a Gizmo class, cursor change on hover, has_focus = false on mouse click Now I should actually make them resize when dragged, aye? * Very basic gizmo resizing, still a WIP, does not work properly yet * Start replacing the array of selected pixels with a BitMap This should optimize the selection making a lot, and it also allows for easy border drawing without having to deal with polygons, thanks to the MarchingAntsOutline.shader Still commit is still a WIP, image effects and brushes may not work properly yet. Because the BitMap has a fixed size, the size of the project, moving the selection outside of canvas boundaries has proven to be a bit tricky. I did implement a hacky way of handling it, but it may be buggy and problematic. I'm still unsure whether this is the best way to handle the situation. * Selection works with mirror view * Draw a black rectangle when the user is making a rectangular selection After they release the mouse, the black rectangle becomes the selection * Make Selection.gd update when undoing/redoing * Fix brushes not working properly with non-rectangular selections * Added invert selection * Cache has_selection as a variable for a speedup * Fix conflict issues with the shape tools * Made the bitmap image squared so the marching ants effect will be the same on both dimensions There may be a better way to fix the issue, perhaps inside the shader itself. * Some optimizations to call selection_bitmap_changed() less times * Restored almost all of the image effects Left to do: - Change gradient's behavior. Unsure of how it will work with non-rectangular selections yet, but it should not generate pixels outside of the selection. - Restore rotation - Resize bitmap on image resize - Remove the `pixels` array from the ImageEffect * Fix Selection.gd not updating when changing project * Resize the selection bitmap along with image resize * Restored rotation's old behavior and finally got rid of the selected_pixels array The rotation does not yet work properly with selections, but at least it now "works". * Resize selection too when using gizmos Left to do for gizmos: - Proper cancel transformation - Begin transformation (currently named move_content_start but it should be renamed to something more general) when resizing gizmos - Keep the original image and selection in memory and resize them. Meaning, gizmos should not resize the already resized data, but only resize the original. This is less destructive as there is no danger of data loss. - Always resize on InputEventMouseMotion. This is going to be worse for performance, but it will look better for the user. * Image and bitmap resizing now uses the original data and begin transformation on gizmo click No matter how many times the user resizes on the current transformation, the original data will not be lost until they either confirm or cancel, so there is no data loss before confirmation/cancel. * Cancel transformation now works properly when the selection has been resized * Made gizmos resize on mouse motion, fix issues with negative bounding rectangle and when combined with the move tool * Resizing can now get out of positive bounds, clearing and inverting now gets limited to the canvas bounds Resizing currently does not work properly with negative (left & up) canvas boundaries * Flip image when resizing and the bounding rectangle gets flipped * Call move_content_confirm() when inverting selection * Attempt to implement selection resizing that goes outside of the canvas boundaries (not working properly yet) * Flip selection when resizing to negative bounding rectangle sizes And fix preview_image vertical flipping * Fix rotation so that it works (almost) properly with selections Rotation algorithms now accept and only work with a given image, and the pivot has been added as a parameter * Experimental gizmo rotation - does not work properly yet Transforming the selection outside of the canvas is still broken. * Fix some issues with moving selection out of canvas bounds * Fix more issues with selection getting resized outside of canvas bounds * Update marching ants effect properly when switching between projects And make sure the frequency of the marching ants effect always looks roughly the same on all project sizes * Made the rotation gizmo part of the gizmos array and resize them based on camera zoom * Remove unneeded parameter from move_bitmap_values() * Remove more unneeded parameters * Move the selection only if the cursor is above it and neither shift nor control are currently pressed * Gradient generation now works on non-rectangular selections Although this behavior might not be the intended one * Copy/paste marching ants effect offset Useful for when the selection is in negative coords * Fix issue with clear selection & UndoRedo * Restore the ability to move selection when it's in negative coords * Made the marching ants offset a Project variable This fixes the issue of project switching and keeping the previous project's offset. Again, this is only relevant for when the selection is in negative coords. * Made the "from current selection" palette preset work with the new selection system * Fix out of bounds error when using the rectangular select tool on negative coords * Some code cleanup * Comment out the rotation gizmo for now, since it does not work properly * Update marching ants shader params and gizmo sizes when the bitmap changes * Move some methods around in Selection.gd
2021-04-17 18:30:12 +00:00
Global.current_project.commit_redo()
if event.is_action("undo") and !event.shift: # Ctrl + Z and check if shift isn't pressed
New selection system (#474) * Basic move tool * Added marching ants effect on the selection borders * Rename SelectionRectangle to SelectionShape, make it have non-rectangular shape and multiple SelectionShapes can exist - Create multiple selection rectangles - Merge them together if they intersect - Move the selections (without contents as of right now) - Gizmos are being drawn but they are not functional yet Code is very ugly. * Sort vectors counter-clockwise to be used as polygon borders I did this, no idea if it works properly, probably won't be used but I thought I'd keep it saved somewhere * More experiments I may or may not need Trying to generate a polygon from the individual selected pixels * Change default rectangle select behavior and ability to clip polygons using Control * Fix rectangle selection clipping * Split polygon into two with selection subtracting * Move selection with contents with the move tool Code is still a mess, don't bother looking. * Move some methods from SelectionShape.gd to Selection.gd The purpose of this is to generalize some selection code, so that it applies to all polygons, the entire selection. More will follow. * UndoRedo for border moving Nothing else in the selections system works properly in UndoRedo right now. Needs: - UR support for creating selections - UR support for modifying selections (merging and cutting selections together) - UR support for removing selection - UR support for moving content & for all the rest of the remaining features * Moving all of the selection shape logic to Selection.gd Handle all of the polygons there instead of having them as individual nodes. Should be easier to handle undo/redo this way. This commit probably breaks move tool + selection tool and undo/redo. Code is still a mess. For your sanity, I hope you are not reading this. I promise I will clean up. * Move tool works again Buggy and messy, of course. * Remove unneeded code and restore selection move undoredo logic * Made Selection.gd have one big preview_image for when moving content, instead of each polygon having its own image Could be further optimized for some specific cases. We could also remove selected_pixels from SelectionPolygon. * UndoRedo support for creating, deleting, merging and clipping selections UndoRedo support for moving content not added in this commit. Should work but needs more testing. This PR also removes selected_pixels from the SelectionPolygon class. * Confirm & cancel selection movement, should support undoredo properly too Press Enter or do any editing to confirm movement, Escape to cancel. I will most likely add UI buttons for confirm and cancel too. * Mirror View affects selection * Restore Cut, Copy, Paste and Clear Selection Pasting now no longer requires a pre-existing selection and instead copies the selections themselves too. * Created a new Select menu, which has Select All and Clear Selection as options Clear Selection now also confirms content moving. TopMenuContainer code has changed to no longer rely on Global for the menu buttons. * Draw gizmos as rectangles No functionality yet. They may need to be turned to nodes, so that they can easily resize based on zoom level and check for mouse enter/exit events. * Made gizmos get drawn in the sides and corners of the big bounding rectangle instead of individual selection parts Still no functionality yet. * Restore label text * Minor optimization when clipping selections This will execute the for loop less times * Made a Gizmo class, cursor change on hover, has_focus = false on mouse click Now I should actually make them resize when dragged, aye? * Very basic gizmo resizing, still a WIP, does not work properly yet * Start replacing the array of selected pixels with a BitMap This should optimize the selection making a lot, and it also allows for easy border drawing without having to deal with polygons, thanks to the MarchingAntsOutline.shader Still commit is still a WIP, image effects and brushes may not work properly yet. Because the BitMap has a fixed size, the size of the project, moving the selection outside of canvas boundaries has proven to be a bit tricky. I did implement a hacky way of handling it, but it may be buggy and problematic. I'm still unsure whether this is the best way to handle the situation. * Selection works with mirror view * Draw a black rectangle when the user is making a rectangular selection After they release the mouse, the black rectangle becomes the selection * Make Selection.gd update when undoing/redoing * Fix brushes not working properly with non-rectangular selections * Added invert selection * Cache has_selection as a variable for a speedup * Fix conflict issues with the shape tools * Made the bitmap image squared so the marching ants effect will be the same on both dimensions There may be a better way to fix the issue, perhaps inside the shader itself. * Some optimizations to call selection_bitmap_changed() less times * Restored almost all of the image effects Left to do: - Change gradient's behavior. Unsure of how it will work with non-rectangular selections yet, but it should not generate pixels outside of the selection. - Restore rotation - Resize bitmap on image resize - Remove the `pixels` array from the ImageEffect * Fix Selection.gd not updating when changing project * Resize the selection bitmap along with image resize * Restored rotation's old behavior and finally got rid of the selected_pixels array The rotation does not yet work properly with selections, but at least it now "works". * Resize selection too when using gizmos Left to do for gizmos: - Proper cancel transformation - Begin transformation (currently named move_content_start but it should be renamed to something more general) when resizing gizmos - Keep the original image and selection in memory and resize them. Meaning, gizmos should not resize the already resized data, but only resize the original. This is less destructive as there is no danger of data loss. - Always resize on InputEventMouseMotion. This is going to be worse for performance, but it will look better for the user. * Image and bitmap resizing now uses the original data and begin transformation on gizmo click No matter how many times the user resizes on the current transformation, the original data will not be lost until they either confirm or cancel, so there is no data loss before confirmation/cancel. * Cancel transformation now works properly when the selection has been resized * Made gizmos resize on mouse motion, fix issues with negative bounding rectangle and when combined with the move tool * Resizing can now get out of positive bounds, clearing and inverting now gets limited to the canvas bounds Resizing currently does not work properly with negative (left & up) canvas boundaries * Flip image when resizing and the bounding rectangle gets flipped * Call move_content_confirm() when inverting selection * Attempt to implement selection resizing that goes outside of the canvas boundaries (not working properly yet) * Flip selection when resizing to negative bounding rectangle sizes And fix preview_image vertical flipping * Fix rotation so that it works (almost) properly with selections Rotation algorithms now accept and only work with a given image, and the pivot has been added as a parameter * Experimental gizmo rotation - does not work properly yet Transforming the selection outside of the canvas is still broken. * Fix some issues with moving selection out of canvas bounds * Fix more issues with selection getting resized outside of canvas bounds * Update marching ants effect properly when switching between projects And make sure the frequency of the marching ants effect always looks roughly the same on all project sizes * Made the rotation gizmo part of the gizmos array and resize them based on camera zoom * Remove unneeded parameter from move_bitmap_values() * Remove more unneeded parameters * Move the selection only if the cursor is above it and neither shift nor control are currently pressed * Gradient generation now works on non-rectangular selections Although this behavior might not be the intended one * Copy/paste marching ants effect offset Useful for when the selection is in negative coords * Fix issue with clear selection & UndoRedo * Restore the ability to move selection when it's in negative coords * Made the marching ants offset a Project variable This fixes the issue of project switching and keeping the previous project's offset. Again, this is only relevant for when the selection is in negative coords. * Made the "from current selection" palette preset work with the new selection system * Fix out of bounds error when using the rectangular select tool on negative coords * Some code cleanup * Comment out the rotation gizmo for now, since it does not work properly * Update marching ants shader params and gizmo sizes when the bitmap changes * Move some methods around in Selection.gd
2021-04-17 18:30:12 +00:00
Global.current_project.commit_undo() # so "undo" isn't accidentaly triggered while using "redo_secondary"
func setup_application_window_size() -> void:
if OS.get_name() == "HTML5":
return
# Set a minimum window size to prevent UI elements from collapsing on each other.
OS.min_window_size = Vector2(1024, 576)
2020-11-07 17:12:31 +00:00
get_tree().set_screen_stretch(SceneTree.STRETCH_MODE_DISABLED,
2020-11-07 17:12:31 +00:00
SceneTree.STRETCH_ASPECT_IGNORE, Vector2(1024,576), Global.shrink)
# Restore the window position/size if values are present in the configuration cache
if Global.config_cache.has_section_key("window", "screen"):
OS.current_screen = Global.config_cache.get_value("window", "screen")
if Global.config_cache.has_section_key("window", "maximized"):
OS.window_maximized = Global.config_cache.get_value("window", "maximized")
if !OS.window_maximized:
if Global.config_cache.has_section_key("window", "position"):
OS.window_position = Global.config_cache.get_value("window", "position")
if Global.config_cache.has_section_key("window", "size"):
OS.window_size = Global.config_cache.get_value("window", "size")
func show_splash_screen() -> void:
if not Global.config_cache.has_section_key("preferences", "startup"):
Global.config_cache.set_value("preferences", "startup", true)
if Global.config_cache.get_value("preferences", "startup"):
if OS.window_size != Vector2(1280, 720):
# Wait for the window to adjust itself, so the popup is correctly centered
yield(get_tree(), "screen_resized")
$Dialogs/SplashDialog.popup_centered() # Splash screen
modulate = Color(0.5, 0.5, 0.5)
else:
Global.can_draw = true
func handle_backup() -> void:
# If backup file exists then Pixelorama was not closed properly (probably crashed) - reopen backup
var backup_confirmation : ConfirmationDialog = $Dialogs/BackupConfirmation
backup_confirmation.get_cancel().text = tr("Delete")
if Global.config_cache.has_section("backups"):
var project_paths = Global.config_cache.get_section_keys("backups")
if project_paths.size() > 0:
# Get backup paths
var backup_paths := []
for p_path in project_paths:
backup_paths.append(Global.config_cache.get_value("backups", p_path))
# Temporatily stop autosave until user confirms backup
OpenSave.autosave_timer.stop()
backup_confirmation.connect("confirmed", self, "_on_BackupConfirmation_confirmed", [project_paths, backup_paths])
backup_confirmation.get_cancel().connect("pressed", self, "_on_BackupConfirmation_delete", [project_paths, backup_paths])
backup_confirmation.popup_centered()
Global.can_draw = false
modulate = Color(0.5, 0.5, 0.5)
else:
if Global.open_last_project:
load_last_project()
else:
if Global.open_last_project:
load_last_project()
func _notification(what : int) -> void:
match what:
MainLoop.NOTIFICATION_WM_QUIT_REQUEST: # Handle exit
show_quit_dialog()
MainLoop.NOTIFICATION_WM_FOCUS_OUT: # Called when another program is currently focused
Global.has_focus = false
if Global.fps_limit_focus:
Engine.set_target_fps(Global.idle_fps) # then set the fps to the idle fps (by default 1) to facilitate the cpu
MainLoop.NOTIFICATION_WM_MOUSE_ENTER: # Opposite of the above
if Global.fps_limit_focus:
Engine.set_target_fps(Global.fps_limit) # 0 stands for maximum fps
MainLoop.NOTIFICATION_WM_MOUSE_EXIT: # if the mouse exits the window and another application has the focus set the fps to the idle fps
if !OS.is_window_focused() and Global.fps_limit_focus:
Engine.set_target_fps(Global.idle_fps)
2021-11-04 00:46:12 +00:00
MainLoop.NOTIFICATION_WM_FOCUS_IN:
var mouse_pos := get_global_mouse_position()
var viewport_rect := Rect2(Global.main_viewport.rect_global_position, Global.main_viewport.rect_size)
if viewport_rect.has_point(mouse_pos):
Global.has_focus = true
func _on_files_dropped(_files : PoolStringArray, _screen : int) -> void:
OpenSave.handle_loading_files(_files)
var splash_dialog = Global.control.get_node("Dialogs/SplashDialog")
if splash_dialog.visible:
splash_dialog.hide()
func load_last_project() -> void:
if OS.get_name() == "HTML5":
return
# Check if any project was saved or opened last time
if Global.config_cache.has_section_key("preferences", "last_project_path"):
# Check if file still exists on disk
var file_path = Global.config_cache.get_value("preferences", "last_project_path")
var file_check := File.new()
if file_check.file_exists(file_path): # If yes then load the file
OpenSave.open_pxo_file(file_path)
# Sync file dialogs
Global.save_sprites_dialog.current_dir = file_path.get_base_dir()
Global.open_sprites_dialog.current_dir = file_path.get_base_dir()
Global.config_cache.set_value("data", "current_dir", file_path.get_base_dir())
else:
# If file doesn't exist on disk then warn user about this
Global.error_dialog.set_text("Cannot find last project file.")
Global.error_dialog.popup_centered()
Global.dialog_open(true)
func load_recent_project_file(path : String) -> void:
if OS.get_name() == "HTML5":
return
# Check if file still exists on disk
var file_check := File.new()
if file_check.file_exists(path): # If yes then load the file
OpenSave.handle_loading_files([path])
# Sync file dialogs
Global.save_sprites_dialog.current_dir = path.get_base_dir()
Global.open_sprites_dialog.current_dir = path.get_base_dir()
Global.config_cache.set_value("data", "current_dir", path.get_base_dir())
else:
# If file doesn't exist on disk then warn user about this
Global.error_dialog.set_text("Cannot find project file.")
Global.error_dialog.popup_centered()
Global.dialog_open(true)
func _on_OpenSprite_file_selected(path : String) -> void:
OpenSave.handle_loading_files([path])
Global.save_sprites_dialog.current_dir = path.get_base_dir()
Global.config_cache.set_value("data", "current_dir", path.get_base_dir())
2020-01-10 14:21:46 +00:00
func _on_SaveSprite_file_selected(path : String) -> void:
var zstd = Global.save_sprites_dialog.get_vbox().get_node("ZSTDCompression").pressed
OpenSave.save_pxo_file(path, false, zstd)
Global.open_sprites_dialog.current_dir = path.get_base_dir()
Global.config_cache.set_value("data", "current_dir", path.get_base_dir())
if is_quitting_on_save:
_on_QuitDialog_confirmed()
func _on_SaveSpriteHTML5_confirmed() -> void:
var file_name = Global.save_sprites_html5_dialog.get_node("FileNameContainer/FileNameLineEdit").text
file_name += ".pxo"
var path = "user://".plus_file(file_name)
OpenSave.save_pxo_file(path, false, false)
func _on_OpenSprite_popup_hide() -> void:
2019-08-18 09:28:38 +00:00
if !opensprite_file_selected:
_can_draw_true()
2019-08-18 09:28:38 +00:00
2019-08-18 09:28:38 +00:00
func _can_draw_true() -> void:
Global.dialog_open(false)
func show_quit_dialog() -> void:
if !Global.quit_dialog.visible:
if !Global.current_project.has_changed:
Global.quit_dialog.call_deferred("popup_centered")
else:
Global.quit_and_save_dialog.call_deferred("popup_centered")
Global.dialog_open(true)
func _on_QuitAndSaveDialog_custom_action(action : String) -> void:
if action == "Save":
is_quitting_on_save = true
Global.save_sprites_dialog.popup_centered()
Global.quit_dialog.hide()
Global.dialog_open(true)
func _on_QuitDialog_confirmed() -> void:
# Darken the UI to denote that the application is currently exiting
# (it won't respond to user input in this state).
modulate = Color(0.5, 0.5, 0.5)
get_tree().quit()
func _on_BackupConfirmation_confirmed(project_paths : Array, backup_paths : Array) -> void:
OpenSave.reload_backup_file(project_paths, backup_paths)
OpenSave.autosave_timer.start()
Export.file_name = OpenSave.current_save_paths[0].get_file().trim_suffix(".pxo")
Export.directory_path = OpenSave.current_save_paths[0].get_base_dir()
Export.was_exported = false
New selection system (#474) * Basic move tool * Added marching ants effect on the selection borders * Rename SelectionRectangle to SelectionShape, make it have non-rectangular shape and multiple SelectionShapes can exist - Create multiple selection rectangles - Merge them together if they intersect - Move the selections (without contents as of right now) - Gizmos are being drawn but they are not functional yet Code is very ugly. * Sort vectors counter-clockwise to be used as polygon borders I did this, no idea if it works properly, probably won't be used but I thought I'd keep it saved somewhere * More experiments I may or may not need Trying to generate a polygon from the individual selected pixels * Change default rectangle select behavior and ability to clip polygons using Control * Fix rectangle selection clipping * Split polygon into two with selection subtracting * Move selection with contents with the move tool Code is still a mess, don't bother looking. * Move some methods from SelectionShape.gd to Selection.gd The purpose of this is to generalize some selection code, so that it applies to all polygons, the entire selection. More will follow. * UndoRedo for border moving Nothing else in the selections system works properly in UndoRedo right now. Needs: - UR support for creating selections - UR support for modifying selections (merging and cutting selections together) - UR support for removing selection - UR support for moving content & for all the rest of the remaining features * Moving all of the selection shape logic to Selection.gd Handle all of the polygons there instead of having them as individual nodes. Should be easier to handle undo/redo this way. This commit probably breaks move tool + selection tool and undo/redo. Code is still a mess. For your sanity, I hope you are not reading this. I promise I will clean up. * Move tool works again Buggy and messy, of course. * Remove unneeded code and restore selection move undoredo logic * Made Selection.gd have one big preview_image for when moving content, instead of each polygon having its own image Could be further optimized for some specific cases. We could also remove selected_pixels from SelectionPolygon. * UndoRedo support for creating, deleting, merging and clipping selections UndoRedo support for moving content not added in this commit. Should work but needs more testing. This PR also removes selected_pixels from the SelectionPolygon class. * Confirm & cancel selection movement, should support undoredo properly too Press Enter or do any editing to confirm movement, Escape to cancel. I will most likely add UI buttons for confirm and cancel too. * Mirror View affects selection * Restore Cut, Copy, Paste and Clear Selection Pasting now no longer requires a pre-existing selection and instead copies the selections themselves too. * Created a new Select menu, which has Select All and Clear Selection as options Clear Selection now also confirms content moving. TopMenuContainer code has changed to no longer rely on Global for the menu buttons. * Draw gizmos as rectangles No functionality yet. They may need to be turned to nodes, so that they can easily resize based on zoom level and check for mouse enter/exit events. * Made gizmos get drawn in the sides and corners of the big bounding rectangle instead of individual selection parts Still no functionality yet. * Restore label text * Minor optimization when clipping selections This will execute the for loop less times * Made a Gizmo class, cursor change on hover, has_focus = false on mouse click Now I should actually make them resize when dragged, aye? * Very basic gizmo resizing, still a WIP, does not work properly yet * Start replacing the array of selected pixels with a BitMap This should optimize the selection making a lot, and it also allows for easy border drawing without having to deal with polygons, thanks to the MarchingAntsOutline.shader Still commit is still a WIP, image effects and brushes may not work properly yet. Because the BitMap has a fixed size, the size of the project, moving the selection outside of canvas boundaries has proven to be a bit tricky. I did implement a hacky way of handling it, but it may be buggy and problematic. I'm still unsure whether this is the best way to handle the situation. * Selection works with mirror view * Draw a black rectangle when the user is making a rectangular selection After they release the mouse, the black rectangle becomes the selection * Make Selection.gd update when undoing/redoing * Fix brushes not working properly with non-rectangular selections * Added invert selection * Cache has_selection as a variable for a speedup * Fix conflict issues with the shape tools * Made the bitmap image squared so the marching ants effect will be the same on both dimensions There may be a better way to fix the issue, perhaps inside the shader itself. * Some optimizations to call selection_bitmap_changed() less times * Restored almost all of the image effects Left to do: - Change gradient's behavior. Unsure of how it will work with non-rectangular selections yet, but it should not generate pixels outside of the selection. - Restore rotation - Resize bitmap on image resize - Remove the `pixels` array from the ImageEffect * Fix Selection.gd not updating when changing project * Resize the selection bitmap along with image resize * Restored rotation's old behavior and finally got rid of the selected_pixels array The rotation does not yet work properly with selections, but at least it now "works". * Resize selection too when using gizmos Left to do for gizmos: - Proper cancel transformation - Begin transformation (currently named move_content_start but it should be renamed to something more general) when resizing gizmos - Keep the original image and selection in memory and resize them. Meaning, gizmos should not resize the already resized data, but only resize the original. This is less destructive as there is no danger of data loss. - Always resize on InputEventMouseMotion. This is going to be worse for performance, but it will look better for the user. * Image and bitmap resizing now uses the original data and begin transformation on gizmo click No matter how many times the user resizes on the current transformation, the original data will not be lost until they either confirm or cancel, so there is no data loss before confirmation/cancel. * Cancel transformation now works properly when the selection has been resized * Made gizmos resize on mouse motion, fix issues with negative bounding rectangle and when combined with the move tool * Resizing can now get out of positive bounds, clearing and inverting now gets limited to the canvas bounds Resizing currently does not work properly with negative (left & up) canvas boundaries * Flip image when resizing and the bounding rectangle gets flipped * Call move_content_confirm() when inverting selection * Attempt to implement selection resizing that goes outside of the canvas boundaries (not working properly yet) * Flip selection when resizing to negative bounding rectangle sizes And fix preview_image vertical flipping * Fix rotation so that it works (almost) properly with selections Rotation algorithms now accept and only work with a given image, and the pivot has been added as a parameter * Experimental gizmo rotation - does not work properly yet Transforming the selection outside of the canvas is still broken. * Fix some issues with moving selection out of canvas bounds * Fix more issues with selection getting resized outside of canvas bounds * Update marching ants effect properly when switching between projects And make sure the frequency of the marching ants effect always looks roughly the same on all project sizes * Made the rotation gizmo part of the gizmos array and resize them based on camera zoom * Remove unneeded parameter from move_bitmap_values() * Remove more unneeded parameters * Move the selection only if the cursor is above it and neither shift nor control are currently pressed * Gradient generation now works on non-rectangular selections Although this behavior might not be the intended one * Copy/paste marching ants effect offset Useful for when the selection is in negative coords * Fix issue with clear selection & UndoRedo * Restore the ability to move selection when it's in negative coords * Made the marching ants offset a Project variable This fixes the issue of project switching and keeping the previous project's offset. Again, this is only relevant for when the selection is in negative coords. * Made the "from current selection" palette preset work with the new selection system * Fix out of bounds error when using the rectangular select tool on negative coords * Some code cleanup * Comment out the rotation gizmo for now, since it does not work properly * Update marching ants shader params and gizmo sizes when the bitmap changes * Move some methods around in Selection.gd
2021-04-17 18:30:12 +00:00
Global.top_menu_container.file_menu.set_item_text(4, tr("Save") + " %s" % OpenSave.current_save_paths[0].get_file())
Global.top_menu_container.file_menu.set_item_text(6, tr("Export"))
func _on_BackupConfirmation_delete(project_paths : Array, backup_paths : Array) -> void:
for i in range(project_paths.size()):
OpenSave.remove_backup_by_path(project_paths[i], backup_paths[i])
OpenSave.autosave_timer.start()
# Reopen last project
if Global.open_last_project:
load_last_project()
func _on_BackupConfirmation_popup_hide() -> void:
OpenSave.autosave_timer.start()