1
0
Fork 0
mirror of https://github.com/Orama-Interactive/Pixelorama.git synced 2025-01-18 17:19:50 +00:00

somewhat fix transparency for floating window (#1116)

* somewhat fix transparency

* some formatting
This commit is contained in:
Variable 2024-10-17 21:51:45 +05:00 committed by GitHub
parent a64f5f3429
commit 2cb29ab274
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 31 additions and 7 deletions

View file

@ -1,18 +1,22 @@
extends AcceptDialog
var main_canvas := Global.control.find_child("Main Canvas", true, false)
@onready var slider := $VBoxContainer/ValueSlider as ValueSlider
@onready var fullscreen_warning := $VBoxContainer/FullscreenWarning as Label
@onready var main_canvas := Global.control.find_child("Main Canvas") as Control
func _ready() -> void:
if main_canvas is FloatingWindow: ## If it's shifted to a window then get the content
main_canvas = main_canvas.window_content
await get_tree().process_frame
Global.control.main_ui.sort_children.connect(_recalculate_opacity)
func _on_WindowOpacityDialog_about_to_show() -> void:
get_tree().root.transparent = true
get_tree().root.transparent_bg = true
var canvas_window = main_canvas.get_window()
canvas_window.transparent = true
canvas_window.transparent_bg = true
slider.editable = not is_fullscreen()
fullscreen_warning.visible = not slider.editable
@ -31,6 +35,10 @@ func set_window_opacity(value: float) -> void:
if container is TabContainer:
var center := container.get_rect().get_center()
if main_canvas.get_rect().has_point(center):
if main_canvas.get_window() != get_tree().root:
## In case we converted to window while trransparency was active
container.self_modulate.a = 1.0
else:
container.self_modulate.a = value
Global.transparent_checker.update_transparency(value)

View file

@ -1,12 +1,28 @@
extends Panel
var shader_disabled := false
var transparency_material: ShaderMaterial
@onready var main_canvas_container := find_child("Main Canvas") as Container
func _ready() -> void:
transparency_material = material
main_canvas_container.property_list_changed.connect(_re_configure_shader)
update_transparent_shader()
func _re_configure_shader():
await get_tree().process_frame
if get_window() != main_canvas_container.get_window():
material = null
shader_disabled = true
else:
if shader_disabled:
material = transparency_material
shader_disabled = false
func _on_main_canvas_item_rect_changed() -> void:
update_transparent_shader()
@ -20,6 +36,6 @@ func update_transparent_shader() -> void:
return
# Works independently of the transparency feature
var canvas_size: Vector2 = (main_canvas_container.size - Vector2.DOWN * 2) * Global.shrink
material.set_shader_parameter("screen_resolution", get_viewport().size)
material.set_shader_parameter("position", main_canvas_container.global_position * Global.shrink)
material.set_shader_parameter("size", canvas_size)
transparency_material.set_shader_parameter("screen_resolution", get_viewport().size)
transparency_material.set_shader_parameter("position", main_canvas_container.global_position * Global.shrink)
transparency_material.set_shader_parameter("size", canvas_size)