2019-08-18 09:28:38 +00:00
|
|
|
|
extends Node
|
|
|
|
|
|
2021-11-25 12:48:30 +00:00
|
|
|
|
enum GridTypes { CARTESIAN, ISOMETRIC, ALL }
|
|
|
|
|
enum PressureSensitivity { NONE, ALPHA, SIZE, ALPHA_AND_SIZE }
|
|
|
|
|
enum TileMode { NONE, BOTH, X_AXIS, Y_AXIS }
|
|
|
|
|
enum IconColorFrom { THEME, CUSTOM }
|
|
|
|
|
enum ButtonSize { SMALL, BIG }
|
2021-06-13 23:14:31 +00:00
|
|
|
|
|
2020-05-31 13:04:33 +00:00
|
|
|
|
var root_directory := "."
|
2021-11-29 15:12:30 +00:00
|
|
|
|
var window_title := "" setget _title_changed # Why doesn't Godot have get_window_title()?
|
2020-05-31 13:04:33 +00:00
|
|
|
|
var config_cache := ConfigFile.new()
|
|
|
|
|
var XDGDataPaths = preload("res://src/XDGDataPaths.gd")
|
2021-11-25 12:48:30 +00:00
|
|
|
|
var directory_module: Reference
|
2020-04-13 07:55:01 +00:00
|
|
|
|
|
2021-11-25 12:48:30 +00:00
|
|
|
|
var projects := [] # Array of Projects
|
|
|
|
|
var current_project: Project
|
2021-11-29 15:12:30 +00:00
|
|
|
|
var current_project_index := 0 setget _project_changed
|
2020-06-04 18:05:36 +00:00
|
|
|
|
|
2021-11-25 12:48:30 +00:00
|
|
|
|
var ui_tooltips := {}
|
2020-10-26 20:51:55 +00:00
|
|
|
|
|
2019-12-25 19:42:01 +00:00
|
|
|
|
# Canvas related stuff
|
2020-04-06 15:35:54 +00:00
|
|
|
|
var layers_changed_skip := false
|
2019-08-18 09:28:38 +00:00
|
|
|
|
var can_draw := false
|
2022-02-11 01:16:33 +00:00
|
|
|
|
var move_guides_on_canvas := false
|
2019-10-03 16:37:31 +00:00
|
|
|
|
var has_focus := false
|
2020-04-24 21:42:02 +00:00
|
|
|
|
|
2020-04-11 17:10:07 +00:00
|
|
|
|
var play_only_tags := true
|
2020-07-16 02:05:40 +00:00
|
|
|
|
var show_x_symmetry_axis := false
|
|
|
|
|
var show_y_symmetry_axis := false
|
2020-02-11 22:38:35 +00:00
|
|
|
|
|
2020-06-04 20:20:20 +00:00
|
|
|
|
# Preferences
|
2021-01-20 14:59:42 +00:00
|
|
|
|
var pressure_sensitivity_mode = PressureSensitivity.NONE
|
2020-07-28 22:54:15 +00:00
|
|
|
|
var open_last_project := false
|
2022-01-05 00:34:45 +00:00
|
|
|
|
var quit_confirmation := false
|
2021-06-04 18:44:05 +00:00
|
|
|
|
var smooth_zoom := true
|
|
|
|
|
|
2020-11-07 01:57:35 +00:00
|
|
|
|
var shrink := 1.0
|
2021-03-17 17:28:01 +00:00
|
|
|
|
var dim_on_popup := true
|
2021-06-04 18:44:05 +00:00
|
|
|
|
var modulate_icon_color := Color.gray
|
2021-11-25 12:48:30 +00:00
|
|
|
|
var icon_color_from: int = IconColorFrom.THEME
|
2021-06-04 18:44:05 +00:00
|
|
|
|
var custom_icon_color := Color.gray
|
2021-11-25 12:48:30 +00:00
|
|
|
|
var tool_button_size: int = ButtonSize.SMALL
|
2021-06-03 19:42:08 +00:00
|
|
|
|
|
2021-12-01 18:50:50 +00:00
|
|
|
|
var default_width := 64
|
|
|
|
|
var default_height := 64
|
2020-01-10 19:24:07 +00:00
|
|
|
|
var default_fill_color := Color(0, 0, 0, 0)
|
2021-01-20 14:59:42 +00:00
|
|
|
|
var grid_type = GridTypes.CARTESIAN
|
2021-01-16 18:24:46 +00:00
|
|
|
|
var grid_width := 2
|
|
|
|
|
var grid_height := 2
|
2021-01-18 20:59:26 +00:00
|
|
|
|
var grid_isometric_cell_bounds_width := 16
|
|
|
|
|
var grid_isometric_cell_bounds_height := 8
|
2021-01-20 00:17:33 +00:00
|
|
|
|
var grid_offset_x := 0
|
|
|
|
|
var grid_offset_y := 0
|
|
|
|
|
var grid_draw_over_tile_mode := false
|
2019-12-07 17:34:54 +00:00
|
|
|
|
var grid_color := Color.black
|
2021-11-25 12:48:30 +00:00
|
|
|
|
var pixel_grid_show_at_zoom := 1500.0 # percentage
|
2021-01-16 18:24:46 +00:00
|
|
|
|
var pixel_grid_color := Color("91212121")
|
2019-12-27 00:28:36 +00:00
|
|
|
|
var guide_color := Color.purple
|
2020-04-18 07:03:18 +00:00
|
|
|
|
var checker_size := 10
|
2020-05-03 00:42:44 +00:00
|
|
|
|
var checker_color_1 := Color(0.47, 0.47, 0.47, 1)
|
|
|
|
|
var checker_color_2 := Color(0.34, 0.35, 0.34, 1)
|
2020-08-17 19:30:58 +00:00
|
|
|
|
var checker_follow_movement := false
|
|
|
|
|
var checker_follow_scale := false
|
2020-10-25 23:10:14 +00:00
|
|
|
|
var tilemode_opacity := 1.0
|
2021-05-28 00:46:16 +00:00
|
|
|
|
|
|
|
|
|
var selection_animated_borders := true
|
|
|
|
|
var selection_border_color_1 := Color.white
|
|
|
|
|
var selection_border_color_2 := Color.black
|
|
|
|
|
|
2021-12-11 18:02:51 +00:00
|
|
|
|
var pause_when_unfocused := true
|
2021-01-05 18:01:50 +00:00
|
|
|
|
var fps_limit := 0
|
2019-12-05 23:48:29 +00:00
|
|
|
|
|
2020-07-29 00:16:02 +00:00
|
|
|
|
var autosave_interval := 1.0
|
2020-05-31 20:04:59 +00:00
|
|
|
|
var enable_autosave := true
|
|
|
|
|
|
2019-12-25 19:42:01 +00:00
|
|
|
|
# Tools & options
|
2020-01-13 11:26:06 +00:00
|
|
|
|
var show_left_tool_icon := true
|
|
|
|
|
var show_right_tool_icon := true
|
2019-12-05 23:48:29 +00:00
|
|
|
|
var left_square_indicator_visible := true
|
|
|
|
|
var right_square_indicator_visible := false
|
2022-02-10 20:32:55 +00:00
|
|
|
|
var native_cursors := false
|
|
|
|
|
var cross_cursor := true
|
2020-04-24 21:42:02 +00:00
|
|
|
|
|
2019-12-25 19:42:01 +00:00
|
|
|
|
# View menu options
|
2022-02-11 22:47:26 +00:00
|
|
|
|
var greyscale_view := false
|
2020-11-23 16:53:21 +00:00
|
|
|
|
var mirror_view := false
|
2019-09-09 22:57:46 +00:00
|
|
|
|
var draw_grid := false
|
2021-01-16 18:24:46 +00:00
|
|
|
|
var draw_pixel_grid := false
|
2019-12-03 00:30:38 +00:00
|
|
|
|
var show_rulers := true
|
|
|
|
|
var show_guides := true
|
2019-12-05 23:48:29 +00:00
|
|
|
|
|
2019-12-25 19:42:01 +00:00
|
|
|
|
# Onion skinning options
|
2020-03-26 18:56:30 +00:00
|
|
|
|
var onion_skinning := false
|
2020-05-01 17:47:10 +00:00
|
|
|
|
var onion_skinning_past_rate := 1.0
|
|
|
|
|
var onion_skinning_future_rate := 1.0
|
2019-12-05 23:48:29 +00:00
|
|
|
|
var onion_skinning_blue_red := false
|
|
|
|
|
|
2019-12-25 19:42:01 +00:00
|
|
|
|
# Palettes
|
2019-12-15 03:11:32 +00:00
|
|
|
|
var palettes := {}
|
|
|
|
|
|
2019-12-25 19:42:01 +00:00
|
|
|
|
# Nodes
|
2021-07-21 15:29:52 +00:00
|
|
|
|
var notification_label_node = preload("res://src/UI/NotificationLabel.tscn")
|
2019-12-15 03:11:32 +00:00
|
|
|
|
|
2021-11-25 12:48:30 +00:00
|
|
|
|
onready var root: Node = get_tree().get_root()
|
|
|
|
|
onready var control: Node = root.get_node("Control")
|
|
|
|
|
|
|
|
|
|
onready var left_cursor: Sprite = control.find_node("LeftCursor")
|
|
|
|
|
onready var right_cursor: Sprite = control.find_node("RightCursor")
|
|
|
|
|
onready var canvas: Canvas = control.find_node("Canvas")
|
|
|
|
|
onready var tabs: Tabs = control.find_node("Tabs")
|
|
|
|
|
onready var main_viewport: ViewportContainer = control.find_node("ViewportContainer")
|
2022-02-14 23:42:20 +00:00
|
|
|
|
onready var second_viewport: ViewportContainer = control.find_node("Second Canvas")
|
2022-01-31 00:18:04 +00:00
|
|
|
|
onready var main_canvas_container: Container = control.find_node("Main Canvas")
|
2022-01-29 22:47:25 +00:00
|
|
|
|
onready var canvas_preview_container: Container = control.find_node("Canvas Preview")
|
2021-11-25 12:48:30 +00:00
|
|
|
|
onready var small_preview_viewport: ViewportContainer = canvas_preview_container.find_node(
|
|
|
|
|
"PreviewViewportContainer"
|
|
|
|
|
)
|
|
|
|
|
onready var camera: Camera2D = main_viewport.find_node("Camera2D")
|
2022-02-14 23:42:20 +00:00
|
|
|
|
onready var camera2: Camera2D = second_viewport.find_node("Camera2D2")
|
2021-11-25 12:48:30 +00:00
|
|
|
|
onready var camera_preview: Camera2D = control.find_node("CameraPreview")
|
2022-01-29 22:47:25 +00:00
|
|
|
|
onready var cameras := [camera, camera2, camera_preview]
|
2021-11-25 12:48:30 +00:00
|
|
|
|
onready var horizontal_ruler: BaseButton = control.find_node("HorizontalRuler")
|
|
|
|
|
onready var vertical_ruler: BaseButton = control.find_node("VerticalRuler")
|
|
|
|
|
onready var transparent_checker: ColorRect = control.find_node("TransparentChecker")
|
2022-02-11 22:47:26 +00:00
|
|
|
|
onready var greyscale_vision: ColorRect = control.find_node("GreyscaleVision")
|
2021-11-25 12:48:30 +00:00
|
|
|
|
onready var preview_zoom_slider: VSlider = control.find_node("PreviewZoomSlider")
|
|
|
|
|
|
2022-01-31 22:54:33 +00:00
|
|
|
|
onready var tool_panel: ScrollContainer = control.find_node("Tools")
|
2022-01-29 22:47:25 +00:00
|
|
|
|
onready var left_tool_options_scroll: ScrollContainer = control.find_node("Left Tool Options")
|
|
|
|
|
onready var right_tool_options_scroll: ScrollContainer = control.find_node("Right Tool Options")
|
2021-11-25 12:48:30 +00:00
|
|
|
|
onready var brushes_popup: Popup = control.find_node("BrushesPopup")
|
|
|
|
|
onready var patterns_popup: Popup = control.find_node("PatternsPopup")
|
2022-01-29 22:47:25 +00:00
|
|
|
|
onready var palette_panel: PalettePanel = control.find_node("Palette Panel")
|
2021-11-25 12:48:30 +00:00
|
|
|
|
|
|
|
|
|
onready var top_menu_container: Panel = control.find_node("TopMenuContainer")
|
|
|
|
|
onready var rotation_level_button: Button = control.find_node("RotationLevel")
|
|
|
|
|
onready var rotation_level_spinbox: SpinBox = control.find_node("RotationSpinbox")
|
|
|
|
|
onready var zoom_level_button: Button = control.find_node("ZoomLevel")
|
|
|
|
|
onready var zoom_level_spinbox: SpinBox = control.find_node("ZoomSpinbox")
|
|
|
|
|
onready var cursor_position_label: Label = control.find_node("CursorPosition")
|
|
|
|
|
onready var current_frame_mark_label: Label = control.find_node("CurrentFrameMark")
|
|
|
|
|
|
2022-01-29 22:47:25 +00:00
|
|
|
|
onready var animation_timeline: Panel = control.find_node("Animation Timeline")
|
2021-11-25 12:48:30 +00:00
|
|
|
|
onready var animation_timer: Timer = animation_timeline.find_node("AnimationTimer")
|
|
|
|
|
onready var frame_ids: HBoxContainer = animation_timeline.find_node("FrameIDs")
|
|
|
|
|
onready var play_forward: BaseButton = animation_timeline.find_node("PlayForward")
|
|
|
|
|
onready var play_backwards: BaseButton = animation_timeline.find_node("PlayBackwards")
|
|
|
|
|
onready var layers_container: VBoxContainer = animation_timeline.find_node("LayersContainer")
|
|
|
|
|
onready var frames_container: VBoxContainer = animation_timeline.find_node("FramesContainer")
|
|
|
|
|
onready var tag_container: Control = animation_timeline.find_node("TagContainer")
|
|
|
|
|
onready var remove_frame_button: BaseButton = animation_timeline.find_node("DeleteFrame")
|
|
|
|
|
onready var move_left_frame_button: BaseButton = animation_timeline.find_node("MoveLeft")
|
|
|
|
|
onready var move_right_frame_button: BaseButton = animation_timeline.find_node("MoveRight")
|
|
|
|
|
onready var remove_layer_button: BaseButton = animation_timeline.find_node("RemoveLayer")
|
|
|
|
|
onready var move_up_layer_button: BaseButton = animation_timeline.find_node("MoveUpLayer")
|
|
|
|
|
onready var move_down_layer_button: BaseButton = animation_timeline.find_node("MoveDownLayer")
|
|
|
|
|
onready var merge_down_layer_button: BaseButton = animation_timeline.find_node("MergeDownLayer")
|
|
|
|
|
onready var layer_opacity_slider: HSlider = animation_timeline.find_node("OpacitySlider")
|
|
|
|
|
onready var layer_opacity_spinbox: SpinBox = animation_timeline.find_node("OpacitySpinBox")
|
|
|
|
|
|
|
|
|
|
onready var open_sprites_dialog: FileDialog = control.find_node("OpenSprite")
|
|
|
|
|
onready var save_sprites_dialog: FileDialog = control.find_node("SaveSprite")
|
|
|
|
|
onready var save_sprites_html5_dialog: ConfirmationDialog = control.find_node("SaveSpriteHTML5")
|
|
|
|
|
onready var export_dialog: AcceptDialog = control.find_node("ExportDialog")
|
|
|
|
|
onready var preferences_dialog: AcceptDialog = control.find_node("PreferencesDialog")
|
|
|
|
|
onready var error_dialog: AcceptDialog = control.find_node("ErrorDialog")
|
|
|
|
|
onready var quit_and_save_dialog: ConfirmationDialog = control.find_node("QuitAndSaveDialog")
|
|
|
|
|
|
|
|
|
|
onready var current_version: String = ProjectSettings.get_setting("application/config/Version")
|
2020-05-03 21:04:00 +00:00
|
|
|
|
|
2021-11-15 22:04:50 +00:00
|
|
|
|
|
2019-08-18 09:28:38 +00:00
|
|
|
|
func _ready() -> void:
|
2020-02-09 23:23:33 +00:00
|
|
|
|
if OS.has_feature("standalone"):
|
|
|
|
|
root_directory = OS.get_executable_path().get_base_dir()
|
2021-11-22 15:37:06 +00:00
|
|
|
|
# root_directory must be set earlier than this is because XDGDataDirs depends on it
|
|
|
|
|
directory_module = XDGDataPaths.new()
|
|
|
|
|
|
2019-12-20 14:36:23 +00:00
|
|
|
|
# Load settings from the config file
|
|
|
|
|
config_cache.load("user://cache.ini")
|
2020-10-27 21:03:43 +00:00
|
|
|
|
|
2021-12-01 18:50:50 +00:00
|
|
|
|
default_width = config_cache.get_value("preferences", "default_width", default_width)
|
|
|
|
|
default_height = config_cache.get_value("preferences", "default_height", default_height)
|
2021-12-01 18:02:39 +00:00
|
|
|
|
default_fill_color = config_cache.get_value(
|
|
|
|
|
"preferences", "default_fill_color", default_fill_color
|
|
|
|
|
)
|
2021-12-01 18:50:50 +00:00
|
|
|
|
var proj_size := Vector2(default_width, default_height)
|
2021-12-01 18:02:39 +00:00
|
|
|
|
projects.append(Project.new([], tr("untitled"), proj_size))
|
2020-06-04 23:48:38 +00:00
|
|
|
|
current_project = projects[0]
|
2021-12-01 18:50:50 +00:00
|
|
|
|
current_project.layers.append(Layer.new())
|
|
|
|
|
current_project.fill_color = default_fill_color
|
|
|
|
|
var frame: Frame = current_project.new_empty_frame()
|
|
|
|
|
current_project.frames.append(frame)
|
|
|
|
|
|
2021-11-25 12:48:30 +00:00
|
|
|
|
for node in get_tree().get_nodes_in_group("UIButtons"):
|
|
|
|
|
var tooltip: String = node.hint_tooltip
|
|
|
|
|
if !tooltip.empty() and node.shortcut:
|
|
|
|
|
ui_tooltips[node] = tooltip
|
2020-06-04 23:48:38 +00:00
|
|
|
|
|
2020-04-02 00:29:14 +00:00
|
|
|
|
|
2021-11-25 12:48:30 +00:00
|
|
|
|
func notification_label(text: String) -> void:
|
|
|
|
|
var notification: Label = notification_label_node.instance()
|
2019-12-08 01:12:34 +00:00
|
|
|
|
notification.text = tr(text)
|
2021-09-26 23:41:45 +00:00
|
|
|
|
notification.rect_position = Vector2(70, animation_timeline.rect_position.y)
|
2020-03-01 15:56:34 +00:00
|
|
|
|
notification.theme = control.theme
|
2019-11-13 13:45:55 +00:00
|
|
|
|
get_tree().get_root().add_child(notification)
|
|
|
|
|
|
2020-04-19 18:17:33 +00:00
|
|
|
|
|
2021-11-25 12:48:30 +00:00
|
|
|
|
func general_undo(project: Project = current_project) -> void:
|
2020-07-24 00:41:10 +00:00
|
|
|
|
project.undos -= 1
|
2021-11-25 12:48:30 +00:00
|
|
|
|
var action_name: String = project.undo_redo.get_current_action_name()
|
2020-04-19 18:17:33 +00:00
|
|
|
|
notification_label("Undo: %s" % action_name)
|
|
|
|
|
|
|
|
|
|
|
2021-11-25 12:48:30 +00:00
|
|
|
|
func general_redo(project: Project = current_project) -> void:
|
|
|
|
|
if project.undos < project.undo_redo.get_version(): # If we did undo and then redo
|
2020-07-24 00:41:10 +00:00
|
|
|
|
project.undos = project.undo_redo.get_version()
|
2020-04-19 18:17:33 +00:00
|
|
|
|
if control.redone:
|
2021-11-25 12:48:30 +00:00
|
|
|
|
var action_name: String = project.undo_redo.get_current_action_name()
|
2020-04-19 18:17:33 +00:00
|
|
|
|
notification_label("Redo: %s" % action_name)
|
|
|
|
|
|
|
|
|
|
|
2021-12-02 00:22:32 +00:00
|
|
|
|
func undo_or_redo(
|
|
|
|
|
undo: bool, frame_index := -1, layer_index := -1, project: Project = current_project
|
|
|
|
|
) -> void:
|
|
|
|
|
if undo:
|
|
|
|
|
general_undo(project)
|
|
|
|
|
else:
|
|
|
|
|
general_redo(project)
|
2021-11-25 12:48:30 +00:00
|
|
|
|
var action_name: String = project.undo_redo.get_current_action_name()
|
|
|
|
|
if (
|
2021-12-02 00:22:32 +00:00
|
|
|
|
action_name
|
|
|
|
|
in [
|
|
|
|
|
"Draw",
|
|
|
|
|
"Draw Shape",
|
2021-12-02 11:25:20 +00:00
|
|
|
|
"Select",
|
2021-12-02 00:22:32 +00:00
|
|
|
|
"Move Selection",
|
|
|
|
|
"Scale",
|
|
|
|
|
"Centralize",
|
|
|
|
|
"Merge Layer",
|
|
|
|
|
"Link Cel",
|
|
|
|
|
"Unlink Cel"
|
|
|
|
|
]
|
2021-11-25 12:48:30 +00:00
|
|
|
|
):
|
2021-12-02 00:22:32 +00:00
|
|
|
|
if layer_index > -1 and frame_index > -1:
|
|
|
|
|
canvas.update_texture(layer_index, frame_index, project)
|
2020-06-02 23:14:24 +00:00
|
|
|
|
else:
|
2020-07-24 00:41:10 +00:00
|
|
|
|
for i in project.frames.size():
|
|
|
|
|
for j in project.layers.size():
|
|
|
|
|
canvas.update_texture(j, i, project)
|
2020-06-02 23:14:24 +00:00
|
|
|
|
|
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
|
|
|
|
canvas.selection.update()
|
2020-06-02 23:14:24 +00:00
|
|
|
|
if action_name == "Scale":
|
|
|
|
|
canvas.camera_zoom()
|
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
|
|
|
|
canvas.grid.update()
|
|
|
|
|
canvas.pixel_grid.update()
|
|
|
|
|
cursor_position_label.text = "[%s×%s]" % [project.size.x, project.size.y]
|
2020-06-02 23:14:24 +00:00
|
|
|
|
|
|
|
|
|
elif "Frame" in action_name:
|
|
|
|
|
# This actually means that frames.size is one, but it hasn't been updated yet
|
2021-12-02 00:22:32 +00:00
|
|
|
|
if (undo and project.frames.size() == 2) or project.frames.size() == 1: # Stop animating
|
2019-11-23 22:52:17 +00:00
|
|
|
|
play_forward.pressed = false
|
|
|
|
|
play_backwards.pressed = false
|
|
|
|
|
animation_timer.stop()
|
2019-11-10 01:25:25 +00:00
|
|
|
|
|
2021-01-29 20:00:48 +00:00
|
|
|
|
elif "Move Cels" == action_name:
|
2021-11-25 12:48:30 +00:00
|
|
|
|
project.frames = project.frames # to call frames_changed
|
2021-01-29 20:00:48 +00:00
|
|
|
|
|
2019-12-27 22:57:28 +00:00
|
|
|
|
canvas.update()
|
2020-07-24 00:41:10 +00:00
|
|
|
|
if !project.has_changed:
|
|
|
|
|
project.has_changed = true
|
|
|
|
|
if project == current_project:
|
|
|
|
|
self.window_title = window_title + "(*)"
|
2020-04-19 18:17:33 +00:00
|
|
|
|
|
2019-10-29 21:22:38 +00:00
|
|
|
|
|
2021-11-29 15:12:30 +00:00
|
|
|
|
func _title_changed(value: String) -> void:
|
2020-02-22 15:21:52 +00:00
|
|
|
|
window_title = value
|
|
|
|
|
OS.set_window_title(value)
|
|
|
|
|
|
2020-04-19 18:17:33 +00:00
|
|
|
|
|
2021-11-29 15:12:30 +00:00
|
|
|
|
func _project_changed(value: int) -> void:
|
2021-04-23 20:37:07 +00:00
|
|
|
|
canvas.selection.transform_content_confirm()
|
2020-06-04 18:05:36 +00:00
|
|
|
|
current_project_index = value
|
|
|
|
|
current_project = projects[value]
|
2020-06-05 01:30:31 +00:00
|
|
|
|
current_project.change_project()
|
2020-04-19 17:39:08 +00:00
|
|
|
|
|
2020-04-19 18:17:33 +00:00
|
|
|
|
|
2021-11-25 12:48:30 +00:00
|
|
|
|
func dialog_open(open: bool) -> void:
|
2021-11-25 17:10:04 +00:00
|
|
|
|
var dim_color := Color.white
|
2020-05-08 15:37:45 +00:00
|
|
|
|
if open:
|
|
|
|
|
can_draw = false
|
2021-03-17 17:28:01 +00:00
|
|
|
|
if dim_on_popup:
|
2021-11-25 17:10:04 +00:00
|
|
|
|
dim_color = Color(0.5, 0.5, 0.5)
|
2020-05-08 15:37:45 +00:00
|
|
|
|
else:
|
|
|
|
|
can_draw = true
|
2021-11-25 17:10:04 +00:00
|
|
|
|
|
|
|
|
|
control.get_node("ModulateTween").interpolate_property(
|
|
|
|
|
control, "modulate", control.modulate, dim_color, 0.1, Tween.TRANS_LINEAR, Tween.EASE_OUT
|
|
|
|
|
)
|
2020-05-08 15:37:45 +00:00
|
|
|
|
|
|
|
|
|
control.get_node("ModulateTween").start()
|
|
|
|
|
|
|
|
|
|
|
2021-11-25 12:48:30 +00:00
|
|
|
|
func disable_button(button: BaseButton, disable: bool) -> void:
|
2020-05-03 00:13:08 +00:00
|
|
|
|
button.disabled = disable
|
|
|
|
|
if disable:
|
|
|
|
|
button.mouse_default_cursor_shape = Control.CURSOR_FORBIDDEN
|
|
|
|
|
else:
|
|
|
|
|
button.mouse_default_cursor_shape = Control.CURSOR_POINTING_HAND
|
|
|
|
|
|
|
|
|
|
if button is Button:
|
|
|
|
|
for c in button.get_children():
|
|
|
|
|
if c is TextureRect:
|
2021-12-02 11:25:20 +00:00
|
|
|
|
c.modulate.a = 0.5 if disable else 1.0
|
2020-05-03 00:13:08 +00:00
|
|
|
|
break
|
|
|
|
|
|
|
|
|
|
|
2021-11-25 12:48:30 +00:00
|
|
|
|
func change_button_texturerect(texture_button: TextureRect, new_file_name: String) -> void:
|
2022-02-28 18:40:13 +00:00
|
|
|
|
if !texture_button.texture:
|
|
|
|
|
return
|
2020-05-06 12:19:53 +00:00
|
|
|
|
var file_name := texture_button.texture.resource_path.get_basename().get_file()
|
|
|
|
|
var directory_path := texture_button.texture.resource_path.get_basename().replace(file_name, "")
|
|
|
|
|
texture_button.texture = load(directory_path.plus_file(new_file_name))
|
|
|
|
|
|
|
|
|
|
|
2020-04-11 21:08:45 +00:00
|
|
|
|
func update_hint_tooltips() -> void:
|
2022-02-21 16:02:02 +00:00
|
|
|
|
Tools.update_hint_tooltips()
|
2020-04-12 16:50:14 +00:00
|
|
|
|
|
2021-11-25 12:48:30 +00:00
|
|
|
|
for tip in ui_tooltips:
|
|
|
|
|
tip.hint_tooltip = tr(ui_tooltips[tip]) % tip.shortcut.get_as_text()
|