2019-08-18 09:28:38 +00:00
|
|
|
extends Control
|
|
|
|
|
|
|
|
var opensprite_file_selected := false
|
2019-11-13 13:45:55 +00:00
|
|
|
var redone := false
|
2020-02-22 22:52:51 +00:00
|
|
|
var is_quitting_on_save := false
|
2022-03-21 00:24:13 +00:00
|
|
|
var cursor_image: Texture = preload("res://assets/graphics/cursor.png")
|
2021-11-22 19:32:39 +00:00
|
|
|
|
2022-01-29 22:47:25 +00:00
|
|
|
onready var ui := $MenuAndUI/UI/DockableContainer
|
|
|
|
onready var scroll_container := ui.find_node("ColorAndToolOptions/ScrollContainer")
|
2021-11-25 12:48:30 +00:00
|
|
|
onready var quit_dialog: ConfirmationDialog = find_node("QuitDialog")
|
2022-03-28 23:35:32 +00:00
|
|
|
onready var quit_and_save_dialog: ConfirmationDialog = find_node("QuitAndSaveDialog")
|
2020-05-01 17:47:10 +00:00
|
|
|
|
2021-10-02 12:08:58 +00:00
|
|
|
|
2022-03-21 23:48:14 +00:00
|
|
|
func _init() -> void:
|
|
|
|
if OS.get_name() == "OSX":
|
|
|
|
_use_osx_shortcuts()
|
|
|
|
|
|
|
|
|
2019-08-18 09:28:38 +00:00
|
|
|
func _ready() -> void:
|
2021-11-22 15:37:06 +00:00
|
|
|
randomize()
|
2019-12-04 17:16:18 +00:00
|
|
|
get_tree().set_auto_accept_quit(false)
|
2021-11-29 15:12:30 +00:00
|
|
|
_setup_application_window_size()
|
2021-03-06 13:59:26 +00:00
|
|
|
|
2020-06-05 17:15:40 +00:00
|
|
|
Global.window_title = tr("untitled") + " - Pixelorama " + Global.current_version
|
2020-05-23 21:22:06 +00:00
|
|
|
|
2020-06-04 18:05:36 +00:00
|
|
|
Global.current_project.layers[0].name = tr("Layer") + " 0"
|
2020-05-23 21:22:06 +00:00
|
|
|
|
|
|
|
Import.import_brushes(Global.directory_module.get_brushes_search_path_in_order())
|
|
|
|
Import.import_patterns(Global.directory_module.get_patterns_search_path_in_order())
|
|
|
|
|
2022-03-28 23:35:32 +00:00
|
|
|
quit_and_save_dialog.add_button("Save & Exit", false, "Save")
|
|
|
|
quit_and_save_dialog.get_ok().text = "Exit without saving"
|
2020-05-23 21:22:06 +00:00
|
|
|
|
2021-11-25 12:48:30 +00:00
|
|
|
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)
|
|
|
|
)
|
2020-10-25 01:26:31 +00:00
|
|
|
|
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()
|
|
|
|
|
2021-11-22 19:32:39 +00:00
|
|
|
var i := 0
|
|
|
|
for camera in Global.cameras:
|
|
|
|
camera.index = i
|
|
|
|
i += 1
|
|
|
|
|
2020-07-10 23:09:17 +00:00
|
|
|
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
|
2020-07-17 23:27:47 +00:00
|
|
|
Global.save_sprites_dialog.get_vbox().add_child(zstd_checkbox)
|
2020-07-10 23:09:17 +00:00
|
|
|
|
2021-11-29 15:12:30 +00:00
|
|
|
_handle_backup()
|
2020-05-23 21:22:06 +00:00
|
|
|
|
2020-05-29 21:28:17 +00:00
|
|
|
# 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():
|
2020-06-11 22:11:58 +00:00
|
|
|
OpenSave.handle_loading_files(OS.get_cmdline_args())
|
2020-05-29 17:19:22 +00:00
|
|
|
get_tree().connect("files_dropped", self, "_on_files_dropped")
|
2020-05-23 21:22:06 +00:00
|
|
|
|
2021-10-02 12:08:58 +00:00
|
|
|
if OS.get_name() == "Android":
|
|
|
|
OS.request_permissions()
|
|
|
|
|
2021-11-29 15:12:30 +00:00
|
|
|
_show_splash_screen()
|
2021-11-17 17:59:14 +00:00
|
|
|
|
2021-03-06 13:59:26 +00:00
|
|
|
|
2021-11-25 12:48:30 +00:00
|
|
|
func _input(event: InputEvent) -> void:
|
2020-05-23 21:22:06 +00:00
|
|
|
Global.left_cursor.position = get_global_mouse_position() + Vector2(-32, 32)
|
|
|
|
Global.right_cursor.position = get_global_mouse_position() + Vector2(32, 32)
|
|
|
|
|
|
|
|
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()
|
|
|
|
|
2021-11-25 12:48:30 +00:00
|
|
|
# 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,
|
2021-11-25 12:48:30 +00:00
|
|
|
# because they get called as an accelerator once pressed (TopMenuContainer.gd, Line 152)
|
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()
|
2020-12-22 15:45:17 +00:00
|
|
|
return
|
|
|
|
|
2021-11-25 12:48:30 +00:00
|
|
|
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()
|
2020-05-23 21:22:06 +00:00
|
|
|
|
2021-11-25 12:48:30 +00:00
|
|
|
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()
|
2020-12-22 15:45:17 +00:00
|
|
|
|
2021-11-25 12:48:30 +00:00
|
|
|
if event.is_action("undo") and !event.shift: # Ctrl + Z and check if shift isn't pressed
|
|
|
|
# so "undo" isn't accidentaly triggered while using "redo_secondary"
|
|
|
|
Global.current_project.commit_undo()
|
2020-12-22 15:45:17 +00:00
|
|
|
|
2020-05-23 21:22:06 +00:00
|
|
|
|
2021-11-29 15:12:30 +00:00
|
|
|
func _setup_application_window_size() -> void:
|
2021-11-25 12:48:30 +00:00
|
|
|
get_tree().set_screen_stretch(
|
|
|
|
SceneTree.STRETCH_MODE_DISABLED,
|
|
|
|
SceneTree.STRETCH_ASPECT_IGNORE,
|
|
|
|
Vector2(1024, 576),
|
|
|
|
Global.shrink
|
|
|
|
)
|
2022-03-21 00:24:13 +00:00
|
|
|
set_custom_cursor()
|
|
|
|
|
|
|
|
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)
|
2019-12-07 15:45:48 +00:00
|
|
|
|
|
|
|
# Restore the window position/size if values are present in the configuration cache
|
2019-12-18 16:12:44 +00:00
|
|
|
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")
|
2019-11-19 21:36:37 +00:00
|
|
|
|
|
|
|
if !OS.window_maximized:
|
2019-12-18 16:12:44 +00:00
|
|
|
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")
|
2019-11-19 21:36:37 +00:00
|
|
|
|
2020-05-23 21:22:06 +00:00
|
|
|
|
2022-03-21 00:24:13 +00:00
|
|
|
func set_custom_cursor() -> void:
|
|
|
|
if Global.native_cursors:
|
|
|
|
return
|
|
|
|
|
|
|
|
if Global.shrink == 1.0:
|
|
|
|
Input.set_custom_mouse_cursor(cursor_image, Input.CURSOR_CROSS, Vector2(15, 15))
|
|
|
|
else:
|
|
|
|
var cursor_data := cursor_image.get_data()
|
|
|
|
cursor_data.resize(
|
|
|
|
cursor_data.get_width() * Global.shrink, cursor_data.get_height() * Global.shrink, 0
|
|
|
|
)
|
|
|
|
var new_cursor_tex := ImageTexture.new()
|
|
|
|
new_cursor_tex.create_from_image(cursor_data, 0)
|
|
|
|
Input.set_custom_mouse_cursor(
|
|
|
|
new_cursor_tex, Input.CURSOR_CROSS, Vector2(15, 15) * Global.shrink
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2021-11-29 15:12:30 +00:00
|
|
|
func _show_splash_screen() -> void:
|
2021-11-17 17:59:14 +00:00
|
|
|
if not Global.config_cache.has_section_key("preferences", "startup"):
|
|
|
|
Global.config_cache.set_value("preferences", "startup", true)
|
|
|
|
|
2020-02-18 23:13:29 +00:00
|
|
|
if Global.config_cache.get_value("preferences", "startup"):
|
2022-02-17 13:22:34 +00:00
|
|
|
# Wait for the window to adjust itself, so the popup is correctly centered
|
|
|
|
yield(get_tree(), "idle_frame")
|
2021-11-17 17:59:14 +00:00
|
|
|
|
2021-11-25 12:48:30 +00:00
|
|
|
$Dialogs/SplashDialog.popup_centered() # Splash screen
|
2020-05-08 00:10:23 +00:00
|
|
|
modulate = Color(0.5, 0.5, 0.5)
|
2020-02-18 23:13:29 +00:00
|
|
|
else:
|
|
|
|
Global.can_draw = true
|
2020-01-14 03:44:16 +00:00
|
|
|
|
2020-05-23 21:22:06 +00:00
|
|
|
|
2021-11-29 15:12:30 +00:00
|
|
|
func _handle_backup() -> void:
|
2021-11-25 17:10:04 +00:00
|
|
|
# If backup file exists, Pixelorama was not closed properly (probably crashed) - reopen backup
|
2021-11-25 12:48:30 +00:00
|
|
|
var backup_confirmation: ConfirmationDialog = $Dialogs/BackupConfirmation
|
2020-07-17 23:27:47 +00:00
|
|
|
backup_confirmation.get_cancel().text = tr("Delete")
|
2020-04-30 17:33:24 +00:00
|
|
|
if Global.config_cache.has_section("backups"):
|
|
|
|
var project_paths = Global.config_cache.get_section_keys("backups")
|
|
|
|
if project_paths.size() > 0:
|
2020-06-05 23:16:53 +00:00
|
|
|
# Get backup paths
|
|
|
|
var backup_paths := []
|
|
|
|
for p_path in project_paths:
|
|
|
|
backup_paths.append(Global.config_cache.get_value("backups", p_path))
|
2020-04-30 17:33:24 +00:00
|
|
|
# Temporatily stop autosave until user confirms backup
|
|
|
|
OpenSave.autosave_timer.stop()
|
2021-11-25 12:48:30 +00:00
|
|
|
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]
|
|
|
|
)
|
2020-07-17 23:27:47 +00:00
|
|
|
backup_confirmation.popup_centered()
|
2020-05-08 00:10:23 +00:00
|
|
|
Global.can_draw = false
|
|
|
|
modulate = Color(0.5, 0.5, 0.5)
|
2020-04-30 17:33:24 +00:00
|
|
|
else:
|
2020-04-30 21:02:52 +00:00
|
|
|
if Global.open_last_project:
|
|
|
|
load_last_project()
|
2020-04-30 17:33:24 +00:00
|
|
|
else:
|
2020-04-30 21:02:52 +00:00
|
|
|
if Global.open_last_project:
|
|
|
|
load_last_project()
|
2020-04-21 17:45:02 +00:00
|
|
|
|
2020-05-23 21:22:06 +00:00
|
|
|
|
2021-11-25 12:48:30 +00:00
|
|
|
func _notification(what: int) -> void:
|
2020-12-15 15:30:47 +00:00
|
|
|
match what:
|
2021-12-11 18:02:51 +00:00
|
|
|
MainLoop.NOTIFICATION_WM_QUIT_REQUEST:
|
2020-12-15 15:30:47 +00:00
|
|
|
show_quit_dialog()
|
2021-11-25 12:48:30 +00:00
|
|
|
# If the mouse exits the window and another application has the focus,
|
2021-12-11 18:02:51 +00:00
|
|
|
# pause the application
|
|
|
|
MainLoop.NOTIFICATION_WM_FOCUS_OUT:
|
|
|
|
Global.has_focus = false
|
|
|
|
if Global.pause_when_unfocused:
|
|
|
|
get_tree().paused = true
|
2021-11-25 12:48:30 +00:00
|
|
|
MainLoop.NOTIFICATION_WM_MOUSE_EXIT:
|
2021-12-11 18:02:51 +00:00
|
|
|
if !OS.is_window_focused() and Global.pause_when_unfocused:
|
|
|
|
get_tree().paused = true
|
|
|
|
# Unpause it when the mouse enters the window or when it gains focus
|
|
|
|
MainLoop.NOTIFICATION_WM_MOUSE_ENTER:
|
|
|
|
get_tree().paused = false
|
2021-11-04 00:46:12 +00:00
|
|
|
MainLoop.NOTIFICATION_WM_FOCUS_IN:
|
2021-12-11 18:02:51 +00:00
|
|
|
get_tree().paused = false
|
2021-11-04 00:46:12 +00:00
|
|
|
var mouse_pos := get_global_mouse_position()
|
2021-11-25 12:48:30 +00:00
|
|
|
var viewport_rect := Rect2(
|
|
|
|
Global.main_viewport.rect_global_position, Global.main_viewport.rect_size
|
|
|
|
)
|
2021-11-04 00:46:12 +00:00
|
|
|
if viewport_rect.has_point(mouse_pos):
|
|
|
|
Global.has_focus = true
|
2020-05-29 21:28:17 +00:00
|
|
|
|
|
|
|
|
2021-11-25 12:48:30 +00:00
|
|
|
func _on_files_dropped(_files: PoolStringArray, _screen: int) -> void:
|
2020-06-11 22:11:58 +00:00
|
|
|
OpenSave.handle_loading_files(_files)
|
2021-09-06 12:36:28 +00:00
|
|
|
var splash_dialog = Global.control.get_node("Dialogs/SplashDialog")
|
|
|
|
if splash_dialog.visible:
|
|
|
|
splash_dialog.hide()
|
2020-05-29 21:28:17 +00:00
|
|
|
|
|
|
|
|
2020-04-30 21:02:52 +00:00
|
|
|
func load_last_project() -> void:
|
2020-07-28 22:54:15 +00:00
|
|
|
if OS.get_name() == "HTML5":
|
|
|
|
return
|
2020-04-30 21:02:52 +00:00
|
|
|
# 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()
|
2021-11-25 12:48:30 +00:00
|
|
|
if file_check.file_exists(file_path): # If yes then load the file
|
2020-06-11 22:11:58 +00:00
|
|
|
OpenSave.open_pxo_file(file_path)
|
2021-11-16 22:17:02 +00:00
|
|
|
# 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())
|
2020-04-30 21:02:52 +00:00
|
|
|
else:
|
|
|
|
# If file doesn't exist on disk then warn user about this
|
2020-05-19 22:37:36 +00:00
|
|
|
Global.error_dialog.set_text("Cannot find last project file.")
|
|
|
|
Global.error_dialog.popup_centered()
|
2020-05-08 15:37:45 +00:00
|
|
|
Global.dialog_open(true)
|
2020-04-21 17:45:02 +00:00
|
|
|
|
2020-04-02 12:28:47 +00:00
|
|
|
|
2021-11-25 12:48:30 +00:00
|
|
|
func load_recent_project_file(path: String) -> void:
|
2020-10-26 20:51:55 +00:00
|
|
|
if OS.get_name() == "HTML5":
|
|
|
|
return
|
2020-10-27 21:03:43 +00:00
|
|
|
|
2020-10-26 20:51:55 +00:00
|
|
|
# Check if file still exists on disk
|
|
|
|
var file_check := File.new()
|
2021-11-25 12:48:30 +00:00
|
|
|
if file_check.file_exists(path): # If yes then load the file
|
2020-10-26 20:51:55 +00:00
|
|
|
OpenSave.handle_loading_files([path])
|
2021-11-16 22:17:02 +00:00
|
|
|
# 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())
|
2020-10-26 20:51:55 +00:00
|
|
|
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)
|
|
|
|
|
|
|
|
|
2021-11-25 12:48:30 +00:00
|
|
|
func _on_OpenSprite_file_selected(path: String) -> void:
|
2020-06-11 22:11:58 +00:00
|
|
|
OpenSave.handle_loading_files([path])
|
2021-11-16 22:17:02 +00:00
|
|
|
Global.save_sprites_dialog.current_dir = path.get_base_dir()
|
|
|
|
Global.config_cache.set_value("data", "current_dir", path.get_base_dir())
|
2020-02-22 15:14:32 +00:00
|
|
|
|
2019-11-21 19:13:15 +00:00
|
|
|
|
2021-11-25 12:48:30 +00:00
|
|
|
func _on_SaveSprite_file_selected(path: String) -> void:
|
|
|
|
save_project(path)
|
|
|
|
|
|
|
|
|
|
|
|
func save_project(path: String) -> void:
|
|
|
|
var zstd: bool = Global.save_sprites_dialog.get_vbox().get_node("ZSTDCompression").pressed
|
2020-07-10 23:09:17 +00:00
|
|
|
OpenSave.save_pxo_file(path, false, zstd)
|
2021-11-16 22:17:02 +00:00
|
|
|
Global.open_sprites_dialog.current_dir = path.get_base_dir()
|
|
|
|
Global.config_cache.set_value("data", "current_dir", path.get_base_dir())
|
2020-04-09 20:54:05 +00:00
|
|
|
|
2020-02-22 22:52:51 +00:00
|
|
|
if is_quitting_on_save:
|
|
|
|
_on_QuitDialog_confirmed()
|
2019-09-14 19:55:33 +00:00
|
|
|
|
|
|
|
|
2020-06-30 17:25:43 +00:00
|
|
|
func _on_SaveSpriteHTML5_confirmed() -> void:
|
2021-11-25 12:48:30 +00:00
|
|
|
var file_name = Global.save_sprites_html5_dialog.get_node(
|
|
|
|
"FileNameContainer/FileNameLineEdit"
|
|
|
|
).text
|
2020-06-30 17:25:43 +00:00
|
|
|
file_name += ".pxo"
|
|
|
|
var path = "user://".plus_file(file_name)
|
2020-07-10 23:09:17 +00:00
|
|
|
OpenSave.save_pxo_file(path, false, false)
|
2020-06-30 17:25:43 +00:00
|
|
|
|
|
|
|
|
2020-06-11 22:11:58 +00:00
|
|
|
func _on_OpenSprite_popup_hide() -> void:
|
2019-08-18 09:28:38 +00:00
|
|
|
if !opensprite_file_selected:
|
2020-05-08 15:37:45 +00:00
|
|
|
_can_draw_true()
|
2019-08-18 09:28:38 +00:00
|
|
|
|
2020-05-01 17:47:10 +00:00
|
|
|
|
2019-08-18 09:28:38 +00:00
|
|
|
func _can_draw_true() -> void:
|
2020-05-08 15:37:45 +00:00
|
|
|
Global.dialog_open(false)
|
2020-05-01 17:47:10 +00:00
|
|
|
|
|
|
|
|
2020-02-23 00:11:52 +00:00
|
|
|
func show_quit_dialog() -> void:
|
2022-01-07 01:36:16 +00:00
|
|
|
var changed_project := false
|
|
|
|
for project in Global.projects:
|
|
|
|
if project.has_changed:
|
|
|
|
changed_project = true
|
|
|
|
break
|
|
|
|
|
2021-11-23 00:36:22 +00:00
|
|
|
if !quit_dialog.visible:
|
2022-01-07 01:36:16 +00:00
|
|
|
if !changed_project:
|
2022-01-05 00:34:45 +00:00
|
|
|
if Global.quit_confirmation:
|
|
|
|
quit_dialog.call_deferred("popup_centered")
|
|
|
|
else:
|
|
|
|
_on_QuitDialog_confirmed()
|
2020-02-23 00:11:52 +00:00
|
|
|
else:
|
2022-03-28 23:35:32 +00:00
|
|
|
quit_and_save_dialog.call_deferred("popup_centered")
|
2020-04-13 02:07:52 +00:00
|
|
|
|
2020-05-08 15:37:45 +00:00
|
|
|
Global.dialog_open(true)
|
2020-02-23 00:11:52 +00:00
|
|
|
|
2020-04-13 02:07:52 +00:00
|
|
|
|
2021-11-25 12:48:30 +00:00
|
|
|
func _on_QuitAndSaveDialog_custom_action(action: String) -> void:
|
2020-02-22 15:02:56 +00:00
|
|
|
if action == "Save":
|
2020-02-22 22:52:51 +00:00
|
|
|
is_quitting_on_save = true
|
2020-07-17 23:27:47 +00:00
|
|
|
Global.save_sprites_dialog.popup_centered()
|
2021-11-23 00:36:22 +00:00
|
|
|
quit_dialog.hide()
|
2020-05-08 15:37:45 +00:00
|
|
|
Global.dialog_open(true)
|
2020-02-22 15:02:56 +00:00
|
|
|
|
2020-04-13 02:07:52 +00:00
|
|
|
|
2020-02-22 22:52:51 +00:00
|
|
|
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()
|
2020-04-27 15:09:54 +00:00
|
|
|
|
|
|
|
|
2021-11-25 12:48:30 +00:00
|
|
|
func _on_BackupConfirmation_confirmed(project_paths: Array, backup_paths: Array) -> void:
|
2020-06-05 23:16:53 +00:00
|
|
|
OpenSave.reload_backup_file(project_paths, backup_paths)
|
2020-07-31 20:26:52 +00:00
|
|
|
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
|
2021-11-25 12:48:30 +00:00
|
|
|
Global.top_menu_container.file_menu.set_item_text(
|
|
|
|
4, tr("Save") + " %s" % OpenSave.current_save_paths[0].get_file()
|
|
|
|
)
|
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(6, tr("Export"))
|
2020-04-30 17:33:24 +00:00
|
|
|
|
|
|
|
|
2021-11-25 12:48:30 +00:00
|
|
|
func _on_BackupConfirmation_delete(project_paths: Array, backup_paths: Array) -> void:
|
2020-06-05 23:16:53 +00:00
|
|
|
for i in range(project_paths.size()):
|
|
|
|
OpenSave.remove_backup_by_path(project_paths[i], backup_paths[i])
|
2020-04-30 17:33:24 +00:00
|
|
|
# Reopen last project
|
2020-04-30 21:02:52 +00:00
|
|
|
if Global.open_last_project:
|
|
|
|
load_last_project()
|
2021-10-11 17:40:26 +00:00
|
|
|
|
|
|
|
|
|
|
|
func _on_BackupConfirmation_popup_hide() -> void:
|
2021-12-14 19:51:52 +00:00
|
|
|
if Global.enable_autosave:
|
|
|
|
OpenSave.autosave_timer.start()
|
2021-11-22 15:37:06 +00:00
|
|
|
|
|
|
|
|
2021-11-29 15:12:30 +00:00
|
|
|
func _use_osx_shortcuts() -> void:
|
2021-11-22 15:37:06 +00:00
|
|
|
var inputmap := InputMap
|
|
|
|
|
|
|
|
for action in inputmap.get_actions():
|
2021-11-25 12:48:30 +00:00
|
|
|
var event: InputEvent = inputmap.get_action_list(action)[0]
|
2021-11-22 15:37:06 +00:00
|
|
|
|
|
|
|
if event.is_action("show_pixel_grid"):
|
|
|
|
event.shift = true
|
|
|
|
|
|
|
|
if event.control:
|
|
|
|
event.control = false
|
|
|
|
event.command = true
|
|
|
|
|
|
|
|
|
|
|
|
func _exit_tree() -> void:
|
2022-03-01 22:41:22 +00:00
|
|
|
Global.config_cache.set_value("window", "layout", Global.top_menu_container.selected_layout)
|
2021-11-22 15:37:06 +00:00
|
|
|
Global.config_cache.set_value("window", "screen", OS.current_screen)
|
2021-11-25 12:48:30 +00:00
|
|
|
Global.config_cache.set_value(
|
|
|
|
"window", "maximized", OS.window_maximized || OS.window_fullscreen
|
|
|
|
)
|
2021-11-22 15:37:06 +00:00
|
|
|
Global.config_cache.set_value("window", "position", OS.window_position)
|
|
|
|
Global.config_cache.set_value("window", "size", OS.window_size)
|
|
|
|
Global.config_cache.save("user://cache.ini")
|
|
|
|
|
|
|
|
var i := 0
|
|
|
|
for project in Global.projects:
|
2021-12-11 19:29:32 +00:00
|
|
|
project.remove()
|
2021-11-22 15:37:06 +00:00
|
|
|
OpenSave.remove_backup(i)
|
|
|
|
i += 1
|