-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-Authored-By: A Thousand Ships <[email protected]>
- Loading branch information
1 parent
6d5ded3
commit dde8496
Showing
28 changed files
with
1,074 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Window Management | ||
|
||
A demo showing all [`Window`](https://docs.godotengine.org/en/stable/classes/class_window.html) classes and their use within the main window. | ||
|
||
It includes: | ||
- Embedding/Unembedding subwindows. | ||
- Using a transparent window. | ||
- Adding physical objects to new windows. | ||
- Showcase of all Dialog Windows. | ||
- Showcase of all Popup Windows. | ||
- Adding elements to Popup Menu. | ||
- Adding an icon to system tray. | ||
|
||
Language: GDScript | ||
|
||
Renderer: Compatbility | ||
|
||
## Screenshots | ||
|
||
 |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
[remap] | ||
|
||
importer="texture" | ||
type="CompressedTexture2D" | ||
uid="uid://cehd300ehf1vw" | ||
path="res://.godot/imported/icon.webp-e94f9a68b0f625a567a797079e4d325f.ctex" | ||
metadata={ | ||
"vram_texture": false | ||
} | ||
|
||
[deps] | ||
|
||
source_file="res://icon.webp" | ||
dest_files=["res://.godot/imported/icon.webp-e94f9a68b0f625a567a797079e4d325f.ctex"] | ||
|
||
[params] | ||
|
||
compress/mode=0 | ||
compress/high_quality=false | ||
compress/lossy_quality=0.7 | ||
compress/hdr_compression=1 | ||
compress/normal_map=0 | ||
compress/channel_pack=0 | ||
mipmaps/generate=false | ||
mipmaps/limit=-1 | ||
roughness/mode=0 | ||
roughness/src_normal="" | ||
process/fix_alpha_border=true | ||
process/premult_alpha=false | ||
process/normal_map_invert_y=false | ||
process/hdr_as_srgb=false | ||
process/hdr_clamp_exposure=false | ||
process/size_limit=0 | ||
detect_3d/compress_to=1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
; Engine configuration file. | ||
; It's best edited using the editor UI and not directly, | ||
; since the parameters that go here are not all obvious. | ||
; | ||
; Format: | ||
; [section] ; section goes between [] | ||
; param=value ; assign values to parameters | ||
|
||
config_version=5 | ||
|
||
[application] | ||
|
||
config/name="Multiple Windows Demo" | ||
config/description="A demo showing all Window classes and their use within the main window." | ||
run/main_scene="res://scenes/main_scene.tscn" | ||
config/features=PackedStringArray("4.3", "GL Compatibility") | ||
run/low_processor_mode=true | ||
config/icon="res://icon.webp" | ||
|
||
[display] | ||
|
||
window/size/viewport_width=650 | ||
window/size/viewport_height=650 | ||
window/stretch/mode="canvas_items" | ||
window/stretch/aspect="expand" | ||
window/per_pixel_transparency/allowed=true | ||
|
||
[rendering] | ||
|
||
renderer/rendering_method="gl_compatibility" | ||
renderer/rendering_method.mobile="gl_compatibility" |
7 changes: 7 additions & 0 deletions
7
misc/multiple_windows/scenes/accept_dialogue/accept_dialog.tscn
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
[gd_scene format=3 uid="uid://cudrukovmha7p"] | ||
|
||
[node name="AcceptDialog" type="AcceptDialog"] | ||
initial_position = 2 | ||
size = Vector2i(277, 100) | ||
visible = true | ||
dialog_text = "This is an AcceptDialog window" |
7 changes: 7 additions & 0 deletions
7
misc/multiple_windows/scenes/confimation_dialogue/confirmation_dialog.tscn
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
[gd_scene format=3 uid="uid://1nswovajdv3n"] | ||
|
||
[node name="ConfirmationDialog" type="ConfirmationDialog"] | ||
initial_position = 2 | ||
size = Vector2i(310, 100) | ||
visible = true | ||
dialog_text = "This is a ConfimationDialog window" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
extends BaseButton | ||
|
||
@export var others: Array[BaseButton] = [] | ||
|
||
enum Behavior { | ||
ENABLE_OTHERS_WHEN_ENABLED, | ||
ENABLE_OTHERS_WHEN_DISABLED | ||
} | ||
|
||
@export var behavior: Behavior = Behavior.ENABLE_OTHERS_WHEN_ENABLED | ||
|
||
func _ready() -> void: | ||
var others_disabled: bool | ||
if behavior == Behavior.ENABLE_OTHERS_WHEN_ENABLED: | ||
others_disabled = not button_pressed | ||
else: | ||
others_disabled = button_pressed | ||
for other in others: | ||
other.disabled = others_disabled | ||
|
||
|
||
func _toggled(toggled_on: bool) -> void: | ||
if behavior == Behavior.ENABLE_OTHERS_WHEN_ENABLED: | ||
for other in others: | ||
other.disabled = not toggled_on | ||
else: | ||
for other in others: | ||
other.disabled = toggled_on |
19 changes: 19 additions & 0 deletions
19
misc/multiple_windows/scenes/draggable_window/draggable_region.gd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
extends Area2D | ||
|
||
var window_delta: Vector2i | ||
|
||
var held_down: bool = false | ||
|
||
func _input_event(_viewport, event, _shape_idx): | ||
if event is InputEventMouseButton: | ||
held_down = event.pressed | ||
if event.pressed: | ||
window_delta = get_window().position - DisplayServer.mouse_get_position() | ||
|
||
|
||
func _process(_delta): | ||
if held_down: | ||
get_window().position = DisplayServer.mouse_get_position() + window_delta | ||
var mouse_state = DisplayServer.mouse_get_button_state() | ||
if mouse_state & MOUSE_BUTTON_MASK_LEFT == 0: | ||
held_down = false |
39 changes: 39 additions & 0 deletions
39
misc/multiple_windows/scenes/draggable_window/draggable_window.tscn
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
[gd_scene load_steps=6 format=3 uid="uid://ek1fmwy87san"] | ||
|
||
[ext_resource type="Texture2D" uid="uid://pgdemhy0xqog" path="res://scenes/draggable_window/hand.svg" id="1_y4nm8"] | ||
[ext_resource type="Script" path="res://scenes/draggable_window/draggable_region.gd" id="2_pflw3"] | ||
[ext_resource type="Script" path="res://scenes/draggable_window/sprite_polygon_passthrough.gd" id="3_20753"] | ||
|
||
[sub_resource type="PlaceholderTexture2D" id="PlaceholderTexture2D_ghj85"] | ||
size = Vector2(256, 256) | ||
|
||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_cvhp1"] | ||
size = Vector2(128, 128) | ||
|
||
[node name="DraggableWindow" type="Window"] | ||
transparent_bg = true | ||
physics_object_picking = true | ||
size = Vector2i(128, 128) | ||
unresizable = true | ||
borderless = true | ||
always_on_top = true | ||
transparent = true | ||
|
||
[node name="BG" type="Sprite2D" parent="."] | ||
visible = false | ||
texture = SubResource("PlaceholderTexture2D_ghj85") | ||
centered = false | ||
|
||
[node name="Icon" type="Sprite2D" parent="."] | ||
position = Vector2(64, 64) | ||
texture = ExtResource("1_y4nm8") | ||
|
||
[node name="Area2D" type="Area2D" parent="Icon"] | ||
script = ExtResource("2_pflw3") | ||
|
||
[node name="CollisionShape2D" type="CollisionShape2D" parent="Icon/Area2D"] | ||
shape = SubResource("RectangleShape2D_cvhp1") | ||
|
||
[node name="PassthroughGenerator" type="Node" parent="." node_paths=PackedStringArray("sprite")] | ||
script = ExtResource("3_20753") | ||
sprite = NodePath("../Icon") |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
37 changes: 37 additions & 0 deletions
37
misc/multiple_windows/scenes/draggable_window/hand.svg.import
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
[remap] | ||
|
||
importer="texture" | ||
type="CompressedTexture2D" | ||
uid="uid://pgdemhy0xqog" | ||
path="res://.godot/imported/hand.svg-b2d702bcd7ae140c6ed485fe3d5b4a36.ctex" | ||
metadata={ | ||
"vram_texture": false | ||
} | ||
|
||
[deps] | ||
|
||
source_file="res://scenes/draggable_window/hand.svg" | ||
dest_files=["res://.godot/imported/hand.svg-b2d702bcd7ae140c6ed485fe3d5b4a36.ctex"] | ||
|
||
[params] | ||
|
||
compress/mode=0 | ||
compress/high_quality=false | ||
compress/lossy_quality=0.7 | ||
compress/hdr_compression=1 | ||
compress/normal_map=0 | ||
compress/channel_pack=0 | ||
mipmaps/generate=false | ||
mipmaps/limit=-1 | ||
roughness/mode=0 | ||
roughness/src_normal="" | ||
process/fix_alpha_border=true | ||
process/premult_alpha=false | ||
process/normal_map_invert_y=false | ||
process/hdr_as_srgb=false | ||
process/hdr_clamp_exposure=false | ||
process/size_limit=0 | ||
detect_3d/compress_to=1 | ||
svg/scale=1.0 | ||
editor/scale_with_editor_scale=false | ||
editor/convert_colors_with_editor_theme=false |
41 changes: 41 additions & 0 deletions
41
misc/multiple_windows/scenes/draggable_window/sprite_polygon_passthrough.gd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
extends Node | ||
|
||
@export var sprite: Sprite2D | ||
|
||
# Call function when updating the sprite | ||
#func _ready(): | ||
#sprite.texture_changed.connect(generate_polygon) | ||
#sprite.frame_changed.connect(generate_polygon) | ||
#_on_sprite_texture_changed() | ||
|
||
|
||
func generate_polygon(): | ||
# Make a bitmap out of a sprite. | ||
var bitmap = BitMap.new() | ||
bitmap.create_from_image_alpha(sprite.texture.get_image()) | ||
# Cell size in case sprite cell is used for animation. | ||
var cell_size_x = float(bitmap.get_size().x) / sprite.hframes | ||
var cell_size_y = float(bitmap.get_size().y) / sprite.vframes | ||
var cell_rect: Rect2 = Rect2(cell_size_x * sprite.frame_coords.x, cell_size_y * sprite.frame_coords.y, cell_size_x, cell_size_y) | ||
# Grow bitmap to make sure every pixel will be captured. | ||
bitmap.grow_mask(1, cell_rect) | ||
# Generate array of polygons from bitmap. | ||
var bitmap_polygons: Array[PackedVector2Array] = bitmap.opaque_to_polygons(cell_rect, 1.0) | ||
var polygon = PackedVector2Array() | ||
# Offset to position polygon correctly in relation of sprite to a window. | ||
var offset: Vector2 = sprite.position + sprite.offset | ||
if sprite.centered: | ||
offset -= Vector2(cell_size_x, cell_size_y) / 2 | ||
|
||
# First point is used to connect multiple polygons into one big polygon. | ||
var first_point: Vector2 = bitmap_polygons[0][0] | ||
# Uniting all polygons into polygon for window to use. | ||
for bitmap_polygon: PackedVector2Array in bitmap_polygons: | ||
for point: Vector2 in bitmap_polygon: | ||
polygon.append(point + offset) | ||
|
||
polygon.append(first_point) | ||
polygon.append(first_point) | ||
|
||
# Apply passthrough mask to the window. | ||
get_window().mouse_passthrough_polygon = polygon |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
[gd_scene format=3 uid="uid://dx84v67isxyjv"] | ||
|
||
[node name="FileDialog" type="FileDialog"] | ||
initial_position = 2 | ||
size = Vector2i(700, 400) | ||
visible = true |
Oops, something went wrong.