Replace global oversampling with overrideable per-viewport oversampling.

This commit is contained in:
Pāvels Nadtočajevs
2025-03-30 14:20:25 +03:00
parent 215acd52e8
commit 4afeca3bcf
38 changed files with 1235 additions and 557 deletions

View File

@@ -1196,7 +1196,6 @@ void Window::_update_viewport_size() {
Size2i final_size;
Size2 final_size_override;
Rect2i attach_to_screen_rect(Point2i(), size);
double font_oversampling = 1.0;
window_transform = Transform2D();
if (content_scale_stretch == Window::CONTENT_SCALE_STRETCH_INTEGER) {
@@ -1211,7 +1210,6 @@ void Window::_update_viewport_size() {
}
if (content_scale_mode == CONTENT_SCALE_MODE_DISABLED || content_scale_size.x == 0 || content_scale_size.y == 0) {
font_oversampling = content_scale_factor;
final_size = size;
final_size_override = Size2(size) / content_scale_factor;
} else {
@@ -1289,14 +1287,11 @@ void Window::_update_viewport_size() {
switch (content_scale_mode) {
case CONTENT_SCALE_MODE_DISABLED: {
// Already handled above
//_update_font_oversampling(1.0);
} break;
case CONTENT_SCALE_MODE_CANVAS_ITEMS: {
final_size = screen_size;
final_size_override = viewport_size / content_scale_factor;
attach_to_screen_rect = Rect2(margin, screen_size);
font_oversampling = (screen_size.x / viewport_size.x) * content_scale_factor;
window_transform.translate_local(margin);
} break;
@@ -1315,7 +1310,7 @@ void Window::_update_viewport_size() {
}
bool allocate = is_inside_tree() && visible && (window_id != DisplayServer::INVALID_WINDOW_ID || embedder != nullptr);
bool ci_updated = _set_size(final_size, final_size_override, allocate);
_set_size(final_size, final_size_override, allocate);
if (window_id != DisplayServer::INVALID_WINDOW_ID) {
RenderingServer::get_singleton()->viewport_attach_to_screen(get_viewport_rid(), attach_to_screen_rect, window_id);
@@ -1323,19 +1318,6 @@ void Window::_update_viewport_size() {
RenderingServer::get_singleton()->viewport_attach_to_screen(get_viewport_rid(), Rect2i(), DisplayServer::INVALID_WINDOW_ID);
}
if (window_id == DisplayServer::MAIN_WINDOW_ID) {
if (!use_font_oversampling) {
font_oversampling = 1.0;
}
if (!Math::is_equal_approx(TS->font_get_global_oversampling(), font_oversampling)) {
TS->font_set_global_oversampling(font_oversampling);
if (!ci_updated) {
update_canvas_items();
emit_signal(SNAME("size_changed"));
}
}
}
notification(NOTIFICATION_WM_SIZE_CHANGED);
if (embedder) {
@@ -1721,20 +1703,6 @@ real_t Window::get_content_scale_factor() const {
return content_scale_factor;
}
void Window::set_use_font_oversampling(bool p_oversampling) {
ERR_MAIN_THREAD_GUARD;
if (is_inside_tree() && window_id != DisplayServer::MAIN_WINDOW_ID) {
ERR_FAIL_MSG("Only the root window can set and use font oversampling.");
}
use_font_oversampling = p_oversampling;
_update_viewport_size();
}
bool Window::is_using_font_oversampling() const {
ERR_READ_THREAD_GUARD_V(false);
return use_font_oversampling;
}
DisplayServer::WindowID Window::get_window_id() const {
ERR_READ_THREAD_GUARD_V(DisplayServer::INVALID_WINDOW_ID);
if (get_embedder()) {
@@ -2955,6 +2923,15 @@ bool Window::is_layout_rtl() const {
}
#ifndef DISABLE_DEPRECATED
void Window::set_use_font_oversampling(bool p_oversampling) {
Viewport::set_use_oversampling(p_oversampling);
}
bool Window::is_using_font_oversampling() const {
return Viewport::is_using_oversampling();
}
void Window::set_auto_translate(bool p_enable) {
ERR_MAIN_THREAD_GUARD;
set_auto_translate_mode(p_enable ? AUTO_TRANSLATE_MODE_ALWAYS : AUTO_TRANSLATE_MODE_DISABLED);
@@ -3138,9 +3115,6 @@ void Window::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_content_scale_factor", "factor"), &Window::set_content_scale_factor);
ClassDB::bind_method(D_METHOD("get_content_scale_factor"), &Window::get_content_scale_factor);
ClassDB::bind_method(D_METHOD("set_use_font_oversampling", "enable"), &Window::set_use_font_oversampling);
ClassDB::bind_method(D_METHOD("is_using_font_oversampling"), &Window::is_using_font_oversampling);
ClassDB::bind_method(D_METHOD("set_mouse_passthrough_polygon", "polygon"), &Window::set_mouse_passthrough_polygon);
ClassDB::bind_method(D_METHOD("get_mouse_passthrough_polygon"), &Window::get_mouse_passthrough_polygon);
@@ -3207,6 +3181,9 @@ void Window::_bind_methods() {
#ifndef DISABLE_DEPRECATED
ClassDB::bind_method(D_METHOD("set_auto_translate", "enable"), &Window::set_auto_translate);
ClassDB::bind_method(D_METHOD("is_auto_translating"), &Window::is_auto_translating);
ClassDB::bind_method(D_METHOD("set_use_font_oversampling", "enable"), &Window::set_use_font_oversampling);
ClassDB::bind_method(D_METHOD("is_using_font_oversampling"), &Window::is_using_font_oversampling);
#endif
ClassDB::bind_method(D_METHOD("popup", "rect"), &Window::popup, DEFVAL(Rect2i()));