From fc695a038e0227347886ffb7c1eec5e093cf487b Mon Sep 17 00:00:00 2001 From: Emmanouil Papadeas <35376950+OverloadedOrama@users.noreply.github.com> Date: Fri, 11 Oct 2024 14:08:43 +0300 Subject: [PATCH] Remove `Global.canvas` from the canvas' children --- src/UI/Canvas/CanvasCamera.gd | 6 +++--- src/UI/Canvas/Gizmos3D.gd | 8 +++++--- src/UI/Canvas/Measurements.gd | 12 +++++++----- src/UI/Canvas/OnionSkinning.gd | 6 +++--- src/UI/Canvas/Selection.gd | 12 ++++++------ src/UI/Canvas/TileMode.gd | 4 +++- src/UI/UI.tscn | 1 + 7 files changed, 28 insertions(+), 21 deletions(-) diff --git a/src/UI/Canvas/CanvasCamera.gd b/src/UI/Canvas/CanvasCamera.gd index fc6870611..c75e4a22b 100644 --- a/src/UI/Canvas/CanvasCamera.gd +++ b/src/UI/Canvas/CanvasCamera.gd @@ -57,8 +57,8 @@ func _ready() -> void: zoom_slider.value_changed.connect(_zoom_slider_value_changed) zoom_changed.connect(_zoom_changed) rotation_changed.connect(_rotation_changed) - viewport_container = get_parent().get_parent() - transparent_checker = get_parent().get_node("TransparentChecker") + viewport_container = get_viewport().get_parent() + transparent_checker = get_viewport().get_node("TransparentChecker") update_transparent_checker_offset() @@ -160,7 +160,7 @@ func fit_to_frame(size: Vector2) -> void: size.x = maxf(absf(a.x - d.x), absf(b.x - c.x)) size.y = maxf(absf(a.y - d.y), absf(b.y - c.y)) - viewport_container = get_parent().get_parent() + viewport_container = get_viewport().get_parent() var h_ratio := viewport_container.size.x / size.x var v_ratio := viewport_container.size.y / size.y var ratio := minf(h_ratio, v_ratio) diff --git a/src/UI/Canvas/Gizmos3D.gd b/src/UI/Canvas/Gizmos3D.gd index e6e2801c1..0106e4709 100644 --- a/src/UI/Canvas/Gizmos3D.gd +++ b/src/UI/Canvas/Gizmos3D.gd @@ -30,6 +30,8 @@ var gizmo_rot_x := PackedVector2Array() var gizmo_rot_y := PackedVector2Array() var gizmo_rot_z := PackedVector2Array() +@onready var canvas := get_parent() as Canvas + func _ready() -> void: set_process_input(false) @@ -188,13 +190,13 @@ func _draw() -> void: # Draw bounding box outline draw_multiline(points, selected_color, 0.5) if object.applying_gizmos == Cel3DObject.Gizmos.X_ROT: - draw_line(gizmos_origin, Global.canvas.current_pixel, Color.RED) + draw_line(gizmos_origin, canvas.current_pixel, Color.RED) continue elif object.applying_gizmos == Cel3DObject.Gizmos.Y_ROT: - draw_line(gizmos_origin, Global.canvas.current_pixel, Color.GREEN) + draw_line(gizmos_origin, canvas.current_pixel, Color.GREEN) continue elif object.applying_gizmos == Cel3DObject.Gizmos.Z_ROT: - draw_line(gizmos_origin, Global.canvas.current_pixel, Color.BLUE) + draw_line(gizmos_origin, canvas.current_pixel, Color.BLUE) continue draw_set_transform(gizmos_origin, 0, draw_scale) # Draw position arrows diff --git a/src/UI/Canvas/Measurements.gd b/src/UI/Canvas/Measurements.gd index ca8318859..86b7e43d9 100644 --- a/src/UI/Canvas/Measurements.gd +++ b/src/UI/Canvas/Measurements.gd @@ -8,6 +8,8 @@ var mode := Global.MeasurementMode.NONE var apparent_width: float = WIDTH var rect_bounds: Rect2i +@onready var canvas := get_parent() as Canvas + func _ready() -> void: font = Themes.get_font() @@ -34,10 +36,10 @@ func _input(_event: InputEvent) -> void: func _prepare_movement_rect() -> void: var project := Global.current_project if project.has_selection: - rect_bounds = Global.canvas.selection.preview_image.get_used_rect() - rect_bounds.position += Vector2i(Global.canvas.selection.big_bounding_rectangle.position) + rect_bounds = canvas.selection.preview_image.get_used_rect() + rect_bounds.position += Vector2i(canvas.selection.big_bounding_rectangle.position) if !rect_bounds.has_area(): - rect_bounds = Global.canvas.selection.big_bounding_rectangle + rect_bounds = canvas.selection.big_bounding_rectangle return if rect_bounds.has_area(): return @@ -65,7 +67,7 @@ func _prepare_movement_rect() -> void: else: rect_bounds = rect_bounds.merge(used_rect) if not rect_bounds.has_area(): - rect_bounds = Rect2(Vector2.ZERO, project.size) + rect_bounds = Rect2i(Vector2i.ZERO, project.size) func _draw_move_measurement() -> void: @@ -74,7 +76,7 @@ func _draw_move_measurement() -> void: dashed_color.a = 0.5 # Draw boundary var boundary := Rect2i(rect_bounds) - boundary.position += Global.canvas.move_preview_location + boundary.position += canvas.move_preview_location draw_rect(boundary, line_color, false, apparent_width) # calculate lines var top := Vector2(boundary.get_center().x, boundary.position.y) diff --git a/src/UI/Canvas/OnionSkinning.gd b/src/UI/Canvas/OnionSkinning.gd index 2f2409fa1..fec72a4ff 100644 --- a/src/UI/Canvas/OnionSkinning.gd +++ b/src/UI/Canvas/OnionSkinning.gd @@ -7,6 +7,8 @@ var opacity := 0.6 var blue_red_color := Color.BLUE var rate := Global.onion_skinning_past_rate +@onready var canvas := get_parent() as Canvas + func _draw() -> void: var project := Global.current_project @@ -36,9 +38,7 @@ func _draw() -> void: if not (layer.name.to_lower().ends_with("_io")): color.a = opacity / i if [change, layer_i] in project.selected_cels: - draw_texture( - cel.image_texture, Global.canvas.move_preview_location, color - ) + draw_texture(cel.image_texture, canvas.move_preview_location, color) else: draw_texture(cel.image_texture, Vector2.ZERO, color) layer_i += 1 diff --git a/src/UI/Canvas/Selection.gd b/src/UI/Canvas/Selection.gd index a6f9a6b58..a540054ad 100644 --- a/src/UI/Canvas/Selection.gd +++ b/src/UI/Canvas/Selection.gd @@ -43,7 +43,7 @@ var content_pivot := Vector2.ZERO var mouse_pos_on_gizmo_drag := Vector2.ZERO var resize_keep_ratio := false -@onready var canvas: Canvas = get_parent() +@onready var canvas := get_parent() as Canvas @onready var marching_ants_outline: Sprite2D = $MarchingAntsOutline @@ -393,7 +393,7 @@ func resize_selection() -> void: ) Global.current_project.selection_map_changed() queue_redraw() - Global.canvas.queue_redraw() + canvas.queue_redraw() func _gizmo_rotate() -> void: @@ -461,7 +461,7 @@ func move_borders_end() -> void: else: Global.current_project.selection_map_changed() queue_redraw() - Global.canvas.queue_redraw() + canvas.queue_redraw() func transform_content_start() -> void: @@ -478,7 +478,7 @@ func transform_content_start() -> void: original_big_bounding_rectangle = big_bounding_rectangle original_offset = Global.current_project.selection_offset queue_redraw() - Global.canvas.queue_redraw() + canvas.queue_redraw() func move_content(move: Vector2) -> void: @@ -522,7 +522,7 @@ func transform_content_confirm() -> void: angle = 0.0 content_pivot = Vector2.ZERO queue_redraw() - Global.canvas.queue_redraw() + canvas.queue_redraw() func transform_content_cancel() -> void: @@ -555,7 +555,7 @@ func transform_content_cancel() -> void: angle = 0.0 content_pivot = Vector2.ZERO queue_redraw() - Global.canvas.queue_redraw() + canvas.queue_redraw() func commit_undo(action: String, undo_data_tmp: Dictionary) -> void: diff --git a/src/UI/Canvas/TileMode.gd b/src/UI/Canvas/TileMode.gd index 316f2eeca..641fde9b6 100644 --- a/src/UI/Canvas/TileMode.gd +++ b/src/UI/Canvas/TileMode.gd @@ -3,6 +3,8 @@ extends Node2D var tiles: Tiles var draw_center := false +@onready var canvas := get_parent() as Canvas + func _draw() -> void: var positions := get_tile_positions() @@ -16,7 +18,7 @@ func _draw() -> void: var modulate_color := Color( tilemode_opacity, tilemode_opacity, tilemode_opacity, tilemode_opacity ) # premultiply alpha blending is applied - var current_frame_texture: Texture2D = Global.canvas.currently_visible_frame.get_texture() + var current_frame_texture := canvas.currently_visible_frame.get_texture() for pos in positions: draw_texture(current_frame_texture, pos, modulate_color) diff --git a/src/UI/UI.tscn b/src/UI/UI.tscn index 33f01a452..1bb78eb62 100644 --- a/src/UI/UI.tscn +++ b/src/UI/UI.tscn @@ -205,6 +205,7 @@ hidden_tabs = { "Reference Images": true, "Second Canvas": true } +windows = {} save_on_change = false [sub_resource type="ShaderMaterial" id="2"]