|
@@ -1001,6 +1001,17 @@ void Window::_update_viewport_size() {
|
|
float font_oversampling = 1.0;
|
|
float font_oversampling = 1.0;
|
|
window_transform = Transform2D();
|
|
window_transform = Transform2D();
|
|
|
|
|
|
|
|
+ if (content_scale_stretch == Window::CONTENT_SCALE_STRETCH_INTEGER) {
|
|
|
|
+ // We always want to make sure that the content scale factor is a whole
|
|
|
|
+ // number, else there will be pixel wobble no matter what.
|
|
|
|
+ content_scale_factor = Math::floor(content_scale_factor);
|
|
|
|
+
|
|
|
|
+ // A content scale factor of zero is pretty useless.
|
|
|
|
+ if (content_scale_factor < 1) {
|
|
|
|
+ content_scale_factor = 1;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
if (content_scale_mode == CONTENT_SCALE_MODE_DISABLED || content_scale_size.x == 0 || content_scale_size.y == 0) {
|
|
if (content_scale_mode == CONTENT_SCALE_MODE_DISABLED || content_scale_size.x == 0 || content_scale_size.y == 0) {
|
|
font_oversampling = content_scale_factor;
|
|
font_oversampling = content_scale_factor;
|
|
final_size = size;
|
|
final_size = size;
|
|
@@ -1054,13 +1065,26 @@ void Window::_update_viewport_size() {
|
|
screen_size = screen_size.floor();
|
|
screen_size = screen_size.floor();
|
|
viewport_size = viewport_size.floor();
|
|
viewport_size = viewport_size.floor();
|
|
|
|
|
|
|
|
+ if (content_scale_stretch == Window::CONTENT_SCALE_STRETCH_INTEGER) {
|
|
|
|
+ Size2i screen_scale = (screen_size / viewport_size).floor();
|
|
|
|
+ int scale_factor = MIN(screen_scale.x, screen_scale.y);
|
|
|
|
+
|
|
|
|
+ if (scale_factor < 1) {
|
|
|
|
+ scale_factor = 1;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ screen_size = viewport_size * scale_factor;
|
|
|
|
+ }
|
|
|
|
+
|
|
Size2 margin;
|
|
Size2 margin;
|
|
Size2 offset;
|
|
Size2 offset;
|
|
|
|
|
|
- if (content_scale_aspect != CONTENT_SCALE_ASPECT_EXPAND && screen_size.x < video_mode.x) {
|
|
|
|
|
|
+ if (screen_size.x < video_mode.x) {
|
|
margin.x = Math::round((video_mode.x - screen_size.x) / 2.0);
|
|
margin.x = Math::round((video_mode.x - screen_size.x) / 2.0);
|
|
offset.x = Math::round(margin.x * viewport_size.y / screen_size.y);
|
|
offset.x = Math::round(margin.x * viewport_size.y / screen_size.y);
|
|
- } else if (content_scale_aspect != CONTENT_SCALE_ASPECT_EXPAND && screen_size.y < video_mode.y) {
|
|
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (screen_size.y < video_mode.y) {
|
|
margin.y = Math::round((video_mode.y - screen_size.y) / 2.0);
|
|
margin.y = Math::round((video_mode.y - screen_size.y) / 2.0);
|
|
offset.y = Math::round(margin.y * viewport_size.x / screen_size.x);
|
|
offset.y = Math::round(margin.y * viewport_size.x / screen_size.x);
|
|
}
|
|
}
|
|
@@ -1337,6 +1361,15 @@ Window::ContentScaleAspect Window::get_content_scale_aspect() const {
|
|
return content_scale_aspect;
|
|
return content_scale_aspect;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+void Window::set_content_scale_stretch(ContentScaleStretch p_stretch) {
|
|
|
|
+ content_scale_stretch = p_stretch;
|
|
|
|
+ _update_viewport_size();
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+Window::ContentScaleStretch Window::get_content_scale_stretch() const {
|
|
|
|
+ return content_scale_stretch;
|
|
|
|
+}
|
|
|
|
+
|
|
void Window::set_content_scale_factor(real_t p_factor) {
|
|
void Window::set_content_scale_factor(real_t p_factor) {
|
|
ERR_MAIN_THREAD_GUARD;
|
|
ERR_MAIN_THREAD_GUARD;
|
|
ERR_FAIL_COND(p_factor <= 0);
|
|
ERR_FAIL_COND(p_factor <= 0);
|
|
@@ -2593,6 +2626,9 @@ void Window::_bind_methods() {
|
|
ClassDB::bind_method(D_METHOD("set_content_scale_aspect", "aspect"), &Window::set_content_scale_aspect);
|
|
ClassDB::bind_method(D_METHOD("set_content_scale_aspect", "aspect"), &Window::set_content_scale_aspect);
|
|
ClassDB::bind_method(D_METHOD("get_content_scale_aspect"), &Window::get_content_scale_aspect);
|
|
ClassDB::bind_method(D_METHOD("get_content_scale_aspect"), &Window::get_content_scale_aspect);
|
|
|
|
|
|
|
|
+ ClassDB::bind_method(D_METHOD("set_content_scale_stretch", "stretch"), &Window::set_content_scale_stretch);
|
|
|
|
+ ClassDB::bind_method(D_METHOD("get_content_scale_stretch"), &Window::get_content_scale_stretch);
|
|
|
|
+
|
|
ClassDB::bind_method(D_METHOD("set_content_scale_factor", "factor"), &Window::set_content_scale_factor);
|
|
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("get_content_scale_factor"), &Window::get_content_scale_factor);
|
|
|
|
|
|
@@ -2711,7 +2747,8 @@ void Window::_bind_methods() {
|
|
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2I, "content_scale_size"), "set_content_scale_size", "get_content_scale_size");
|
|
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2I, "content_scale_size"), "set_content_scale_size", "get_content_scale_size");
|
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "content_scale_mode", PROPERTY_HINT_ENUM, "Disabled,Canvas Items,Viewport"), "set_content_scale_mode", "get_content_scale_mode");
|
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "content_scale_mode", PROPERTY_HINT_ENUM, "Disabled,Canvas Items,Viewport"), "set_content_scale_mode", "get_content_scale_mode");
|
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "content_scale_aspect", PROPERTY_HINT_ENUM, "Ignore,Keep,Keep Width,Keep Height,Expand"), "set_content_scale_aspect", "get_content_scale_aspect");
|
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "content_scale_aspect", PROPERTY_HINT_ENUM, "Ignore,Keep,Keep Width,Keep Height,Expand"), "set_content_scale_aspect", "get_content_scale_aspect");
|
|
- ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "content_scale_factor"), "set_content_scale_factor", "get_content_scale_factor");
|
|
|
|
|
|
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "content_scale_stretch", PROPERTY_HINT_ENUM, "Fractional,Integer"), "set_content_scale_stretch", "get_content_scale_stretch");
|
|
|
|
+ ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "content_scale_factor", PROPERTY_HINT_RANGE, "0.5,8.0,0.01"), "set_content_scale_factor", "get_content_scale_factor");
|
|
|
|
|
|
ADD_GROUP("Localization", "");
|
|
ADD_GROUP("Localization", "");
|
|
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "auto_translate"), "set_auto_translate", "is_auto_translating");
|
|
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "auto_translate"), "set_auto_translate", "is_auto_translating");
|
|
@@ -2763,6 +2800,9 @@ void Window::_bind_methods() {
|
|
BIND_ENUM_CONSTANT(CONTENT_SCALE_ASPECT_KEEP_HEIGHT);
|
|
BIND_ENUM_CONSTANT(CONTENT_SCALE_ASPECT_KEEP_HEIGHT);
|
|
BIND_ENUM_CONSTANT(CONTENT_SCALE_ASPECT_EXPAND);
|
|
BIND_ENUM_CONSTANT(CONTENT_SCALE_ASPECT_EXPAND);
|
|
|
|
|
|
|
|
+ BIND_ENUM_CONSTANT(CONTENT_SCALE_STRETCH_FRACTIONAL);
|
|
|
|
+ BIND_ENUM_CONSTANT(CONTENT_SCALE_STRETCH_INTEGER);
|
|
|
|
+
|
|
BIND_ENUM_CONSTANT(LAYOUT_DIRECTION_INHERITED);
|
|
BIND_ENUM_CONSTANT(LAYOUT_DIRECTION_INHERITED);
|
|
BIND_ENUM_CONSTANT(LAYOUT_DIRECTION_LOCALE);
|
|
BIND_ENUM_CONSTANT(LAYOUT_DIRECTION_LOCALE);
|
|
BIND_ENUM_CONSTANT(LAYOUT_DIRECTION_LTR);
|
|
BIND_ENUM_CONSTANT(LAYOUT_DIRECTION_LTR);
|