Rewrite how font oversampling is updated more carefully, fixes #24338
This commit is contained in:
parent
a8510331c0
commit
b203f80dfc
@ -484,6 +484,14 @@ bool SceneTree::iteration(float p_time) {
|
||||
return _quit;
|
||||
}
|
||||
|
||||
void SceneTree::_update_font_oversampling(float p_ratio) {
|
||||
|
||||
if (use_font_oversampling) {
|
||||
DynamicFontAtSize::font_oversampling = p_ratio;
|
||||
DynamicFont::update_oversampling();
|
||||
}
|
||||
}
|
||||
|
||||
bool SceneTree::idle(float p_time) {
|
||||
|
||||
//print_line("ram: "+itos(OS::get_singleton()->get_static_memory_usage())+" sram: "+itos(OS::get_singleton()->get_dynamic_memory_usage()));
|
||||
@ -515,12 +523,6 @@ bool SceneTree::idle(float p_time) {
|
||||
|
||||
last_screen_size = win_size;
|
||||
_update_root_rect();
|
||||
|
||||
if (use_font_oversampling) {
|
||||
DynamicFontAtSize::font_oversampling = OS::get_singleton()->get_window_size().width / root->get_visible_rect().size.width;
|
||||
DynamicFont::update_oversampling();
|
||||
}
|
||||
|
||||
emit_signal("screen_resized");
|
||||
}
|
||||
|
||||
@ -1133,10 +1135,12 @@ void SceneTree::_update_root_rect() {
|
||||
|
||||
if (stretch_mode == STRETCH_MODE_DISABLED) {
|
||||
|
||||
_update_font_oversampling(1.0);
|
||||
root->set_size((last_screen_size / stretch_shrink).floor());
|
||||
root->set_attach_to_screen_rect(Rect2(Point2(), last_screen_size));
|
||||
root->set_size_override_stretch(false);
|
||||
root->set_size_override(false, Size2());
|
||||
root->update_canvas_items();
|
||||
return; //user will take care
|
||||
}
|
||||
|
||||
@ -1154,6 +1158,9 @@ void SceneTree::_update_root_rect() {
|
||||
//same aspect or ignore aspect
|
||||
viewport_size = desired_res;
|
||||
screen_size = video_mode;
|
||||
if (use_font_oversampling) {
|
||||
WARN_PRINT("Font oversampling only works with the following resize modes 'Keep Width', 'Keep Height', and 'Expand'.")
|
||||
}
|
||||
} else if (viewport_aspect < video_mode_aspect) {
|
||||
// screen ratio is smaller vertically
|
||||
|
||||
@ -1208,21 +1215,30 @@ void SceneTree::_update_root_rect() {
|
||||
switch (stretch_mode) {
|
||||
case STRETCH_MODE_DISABLED: {
|
||||
// Already handled above
|
||||
_update_font_oversampling(1.0);
|
||||
} break;
|
||||
case STRETCH_MODE_2D: {
|
||||
|
||||
_update_font_oversampling(screen_size.x / viewport_size.x); //screen / viewport radio drives oversampling
|
||||
root->set_size((screen_size / stretch_shrink).floor());
|
||||
root->set_attach_to_screen_rect(Rect2(margin, screen_size));
|
||||
root->set_size_override_stretch(true);
|
||||
root->set_size_override(true, (viewport_size / stretch_shrink).floor());
|
||||
root->update_canvas_items(); //force them to update just in case
|
||||
|
||||
} break;
|
||||
case STRETCH_MODE_VIEWPORT: {
|
||||
|
||||
_update_font_oversampling(1.0);
|
||||
root->set_size((viewport_size / stretch_shrink).floor());
|
||||
root->set_attach_to_screen_rect(Rect2(margin, screen_size));
|
||||
root->set_size_override_stretch(false);
|
||||
root->set_size_override(false, Size2());
|
||||
root->update_canvas_items(); //force them to update just in case
|
||||
|
||||
if (use_font_oversampling) {
|
||||
WARN_PRINT("Font oversampling does not work in 'Viewport' stretch mode, only '2D'.")
|
||||
}
|
||||
|
||||
} break;
|
||||
}
|
||||
|
@ -153,6 +153,7 @@ private:
|
||||
Size2i stretch_min;
|
||||
real_t stretch_shrink;
|
||||
|
||||
void _update_font_oversampling(float p_ratio);
|
||||
void _update_root_rect();
|
||||
|
||||
List<ObjectID> delete_queue;
|
||||
|
@ -693,6 +693,13 @@ bool Viewport::use_arvr() {
|
||||
return arvr;
|
||||
}
|
||||
|
||||
void Viewport::update_canvas_items() {
|
||||
if (!is_inside_tree())
|
||||
return;
|
||||
|
||||
_update_canvas_items(this);
|
||||
}
|
||||
|
||||
void Viewport::set_size(const Size2 &p_size) {
|
||||
|
||||
if (size == p_size.floor())
|
||||
@ -1128,6 +1135,26 @@ Transform2D Viewport::get_final_transform() const {
|
||||
return stretch_transform * global_canvas_transform;
|
||||
}
|
||||
|
||||
void Viewport::_update_canvas_items(Node *p_node) {
|
||||
if (p_node != this) {
|
||||
|
||||
Viewport *vp = Object::cast_to<Viewport>(p_node);
|
||||
if (vp)
|
||||
return;
|
||||
|
||||
CanvasItem *ci = Object::cast_to<CanvasItem>(p_node);
|
||||
if (ci) {
|
||||
ci->update();
|
||||
}
|
||||
}
|
||||
|
||||
int cc = p_node->get_child_count();
|
||||
|
||||
for (int i = 0; i < cc; i++) {
|
||||
_update_canvas_items(p_node->get_child(i));
|
||||
}
|
||||
}
|
||||
|
||||
void Viewport::set_size_override(bool p_enable, const Size2 &p_size, const Vector2 &p_margin) {
|
||||
|
||||
if (size_override == p_enable && p_size == size_override_size)
|
||||
|
@ -385,6 +385,8 @@ private:
|
||||
|
||||
void _drop_mouse_focus();
|
||||
|
||||
void _update_canvas_items(Node *p_node);
|
||||
|
||||
protected:
|
||||
void _notification(int p_what);
|
||||
static void _bind_methods();
|
||||
@ -403,6 +405,7 @@ public:
|
||||
bool is_audio_listener_2d() const;
|
||||
|
||||
void set_size(const Size2 &p_size);
|
||||
void update_canvas_items();
|
||||
|
||||
Size2 get_size() const;
|
||||
Rect2 get_visible_rect() const;
|
||||
|
Loading…
Reference in New Issue
Block a user