-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
517e5b9
commit fcede9a
Showing
11 changed files
with
281 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,2 @@ | ||
# Normalize EOL for all files that Git considers text files. | ||
* text=auto eol=lf |
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,2 @@ | ||
# Godot 4+ specific ignores | ||
.godot/ |
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,21 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2023 Tampopo Games | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
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,2 @@ | ||
# SafeAreaRect | ||
|
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,21 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2023 Tampopo Games | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
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 @@ | ||
[plugin] | ||
|
||
name="SafeAreaRect" | ||
description="" | ||
author="Tampopo Games" | ||
version="0.1.0" | ||
script="plugin.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,15 @@ | ||
@tool | ||
extends EditorPlugin | ||
|
||
|
||
func _enter_tree() -> void: | ||
add_custom_type( | ||
"SafeAreaRect", | ||
"Control", | ||
preload("./safe_area_rect.gd"), | ||
preload("./safe_area_rect.svg") | ||
) | ||
|
||
|
||
func _exit_tree() -> void: | ||
remove_custom_type("SafeAreaRect") |
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,123 @@ | ||
extends Control | ||
|
||
|
||
@export | ||
var ignore_left: bool = false | ||
@export | ||
var ignore_top: bool = false | ||
@export | ||
var ignore_right: bool = false | ||
@export | ||
var ignore_bottom: bool = false | ||
|
||
|
||
var _initial_anchor_left: float | ||
var _initial_anchor_top: float | ||
var _initial_anchor_right: float | ||
var _initial_anchor_bottom: float | ||
var _last_window_size: Vector2i = Vector2i(0, 0) | ||
var _last_safe_area: Rect2i = Rect2i(0, 0, 0, 0) | ||
|
||
|
||
func _init() -> void: | ||
_initial_anchor_left = anchor_left | ||
_initial_anchor_top = anchor_top | ||
_initial_anchor_right = anchor_right | ||
_initial_anchor_bottom = anchor_bottom | ||
|
||
|
||
func _ready() -> void: | ||
apply_safe_area_anchors(true) | ||
|
||
|
||
func _process(_delta: float) -> void: | ||
apply_safe_area_anchors() | ||
|
||
|
||
func apply_safe_area_anchors(force: bool = false) -> void: | ||
if Engine.is_editor_hint(): | ||
return | ||
|
||
if not force and not is_fullscreen(): | ||
return | ||
|
||
var window_size := get_window_size() | ||
var safe_area := get_safe_area() | ||
|
||
if not force and (window_size == _last_window_size and safe_area == _last_safe_area): | ||
return | ||
|
||
set_safe_area_anchors( | ||
self, | ||
NAN if ignore_left else _initial_anchor_left, | ||
NAN if ignore_top else _initial_anchor_top, | ||
NAN if ignore_right else _initial_anchor_right, | ||
NAN if ignore_bottom else _initial_anchor_bottom, | ||
Rect2i( | ||
get_window_position(), | ||
window_size, | ||
), | ||
safe_area, | ||
) | ||
|
||
_last_window_size = window_size | ||
_last_safe_area = safe_area | ||
|
||
|
||
static func get_window_position() -> Vector2i: | ||
return DisplayServer.window_get_position() | ||
|
||
|
||
static func get_window_size() -> Vector2i: | ||
return DisplayServer.window_get_size_with_decorations() | ||
|
||
|
||
static func get_safe_area() -> Rect2i: | ||
return DisplayServer.get_display_safe_area() | ||
|
||
|
||
static func is_fullscreen() -> bool: | ||
var window_mode := DisplayServer.window_get_mode() | ||
return ( | ||
window_mode == DisplayServer.WindowMode.WINDOW_MODE_FULLSCREEN | ||
or window_mode == DisplayServer.WindowMode.WINDOW_MODE_EXCLUSIVE_FULLSCREEN | ||
or window_mode == DisplayServer.WindowMode.WINDOW_MODE_MAXIMIZED | ||
) | ||
|
||
|
||
static func set_safe_area_anchors( | ||
control: Control, | ||
initial_anchor_left: float, | ||
initial_anchor_top: float, | ||
initial_anchor_right: float, | ||
initial_anchor_bottom: float, | ||
window_rect: Rect2i = Rect2i( | ||
get_window_position(), | ||
get_window_size(), | ||
), | ||
safe_area: Rect2i = get_safe_area(), | ||
) -> void: | ||
var window_size := window_rect.size | ||
|
||
if ( | ||
window_size.x > safe_area.size.x | ||
or window_size.y > safe_area.size.y | ||
): | ||
var window_position := window_rect.position | ||
var window_end := window_position + window_size | ||
|
||
if not is_nan(initial_anchor_left): | ||
var new_anchor_left := absf(safe_area.position.x - window_position.x) / window_size.x | ||
control.anchor_left = maxf(new_anchor_left, initial_anchor_left) | ||
|
||
if not is_nan(initial_anchor_top): | ||
var new_anchor_top := absf(safe_area.position.y - window_position.y) / window_size.y | ||
control.anchor_top = maxf(new_anchor_top, initial_anchor_top) | ||
|
||
if not is_nan(initial_anchor_right): | ||
var new_anchor_right := 1 - (absf(safe_area.end.x - window_end.x) / window_size.x) | ||
control.anchor_right = minf(new_anchor_right, initial_anchor_right) | ||
|
||
if not is_nan(initial_anchor_bottom): | ||
var new_anchor_bottom := 1 - (absf(safe_area.end.y - window_end.y) / window_size.y) | ||
control.anchor_bottom = minf(new_anchor_bottom, initial_anchor_bottom) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,38 @@ | ||
[remap] | ||
|
||
importer="texture" | ||
type="CompressedTexture2D" | ||
uid="uid://pmfg5b67xq8" | ||
path="res://.godot/imported/safe_area_rect.svg-0e059d7ebc89cc7843dfb4f7d8116077.ctex" | ||
metadata={ | ||
"has_editor_variant": true, | ||
"vram_texture": false | ||
} | ||
|
||
[deps] | ||
|
||
source_file="res://addons/safe_area_rect/safe_area_rect.svg" | ||
dest_files=["res://.godot/imported/safe_area_rect.svg-0e059d7ebc89cc7843dfb4f7d8116077.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=true | ||
editor/convert_colors_with_editor_theme=true |
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,24 @@ | ||
; 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="SafeAreaRect" | ||
config/features=PackedStringArray("4.2", "GL Compatibility") | ||
config/icon="res://addons/safe_area_rect/safe_area_rect.svg" | ||
|
||
[editor_plugins] | ||
|
||
enabled=PackedStringArray("res://addons/safe_area_rect/plugin.cfg") | ||
|
||
[rendering] | ||
|
||
renderer/rendering_method="gl_compatibility" | ||
renderer/rendering_method.mobile="gl_compatibility" |