This commit is contained in:
Hearto 2021-11-10 13:59:17 -03:00 committed by GitHub
commit 1067e4f85b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 33 additions and 5 deletions

View file

@ -225,6 +225,33 @@
Configures screen stretching to the given [enum StretchMode], [enum StretchAspect], minimum size and [code]scale[/code].
</description>
</method>
<method name="update_font_oversampling">
<return type="void" />
<argument index="0" name="ratio" type="float" />
<description>
Configures font oversampling to the given [code]ratio[/code].
Example:
[codeblock]
var base_size:Vector2 = Vector2(480.0, 270.0) #Base game size
func ready():
set_screen_stretch(SceneTree.STRETCH_MODE_DISABLED, SceneTree.STRETCH_ASPECT_IGNORE, base_size, 1) #Disable automatic render stretching algorithm
on_screen_resized()
get_tree().connect("screen_resized", self, "on_screen_resized")
#Custom render stretching algorithm
func on_screen_resized():
var scale:float = 3.0 #Custom desired game scale, in this example we wan't 3x the base game size
var viewport_size:Vector2 = base_size * scale #scaled viewport size
var margin:Vector2 = Vector2(0.0,0.0) #No margin
get_tree().update_font_oversampling(scale) #Font oversampling. Match the custom scale
var root:Viewport = get_node("/root") #main viewport
root.set_size(viewport_size)
root.set_attach_to_screen_rect(Rect2(margin, viewport_size)) #offset the viewport inside screen
root.set_size_override_stretch(true)
root.set_size_override(true, base_size)
[/codeblock]
</description>
</method>
</methods>
<members>
<member name="current_scene" type="Node" setter="set_current_scene" getter="get_current_scene">

View file

@ -494,7 +494,7 @@ bool SceneTree::iteration(float p_time) {
return _quit;
}
void SceneTree::_update_font_oversampling(float p_ratio) {
void SceneTree::update_font_oversampling(float p_ratio) {
#ifdef MODULE_FREETYPE_ENABLED
if (use_font_oversampling) {
DynamicFontAtSize::font_oversampling = p_ratio;
@ -1110,7 +1110,7 @@ int SceneTree::get_node_count() const {
void SceneTree::_update_root_rect() {
if (stretch_mode == STRETCH_MODE_DISABLED) {
_update_font_oversampling(stretch_scale);
update_font_oversampling(stretch_scale);
root->set_size(last_screen_size.floor());
root->set_attach_to_screen_rect(Rect2(Point2(), last_screen_size));
root->set_size_override_stretch(true);
@ -1191,7 +1191,7 @@ void SceneTree::_update_root_rect() {
// Already handled above
} break;
case STRETCH_MODE_2D: {
_update_font_oversampling((screen_size.x / viewport_size.x) * stretch_scale); //screen / viewport ratio drives oversampling
update_font_oversampling((screen_size.x / viewport_size.x) * stretch_scale); //screen / viewport ratio drives oversampling
root->set_size(screen_size.floor());
root->set_attach_to_screen_rect(Rect2(margin, screen_size));
root->set_size_override_stretch(true);
@ -1200,7 +1200,7 @@ void SceneTree::_update_root_rect() {
} break;
case STRETCH_MODE_VIEWPORT: {
_update_font_oversampling(1.0);
update_font_oversampling(1.0);
root->set_size((viewport_size / stretch_scale).floor());
root->set_attach_to_screen_rect(Rect2(margin, screen_size));
root->set_size_override_stretch(false);
@ -1885,6 +1885,7 @@ void SceneTree::_bind_methods() {
ClassDB::bind_method(D_METHOD("_connection_failed"), &SceneTree::_connection_failed);
ClassDB::bind_method(D_METHOD("_server_disconnected"), &SceneTree::_server_disconnected);
ClassDB::bind_method(D_METHOD("update_font_oversampling", "ratio"), &SceneTree::update_font_oversampling);
ClassDB::bind_method(D_METHOD("set_use_font_oversampling", "enable"), &SceneTree::set_use_font_oversampling);
ClassDB::bind_method(D_METHOD("is_using_font_oversampling"), &SceneTree::is_using_font_oversampling);

View file

@ -148,7 +148,7 @@ private:
Size2i stretch_min;
real_t stretch_scale;
void _update_font_oversampling(float p_ratio);
void update_font_oversampling(float p_ratio);
void _update_root_rect();
List<ObjectID> delete_queue;