Skip to content

Commit 9ee2640

Browse files
committed
Merge pull request #109358 from zenorbi/styleboxflat-antialiasing-adjust-for-oversampling
Adjust StyleBoxFlat antialiasing to account for Viewport oversampling
2 parents cc008b2 + a29be8f commit 9ee2640

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

scene/resources/style_box_flat.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@
3030

3131
#include "style_box_flat.h"
3232

33-
#include "scene/main/scene_tree.h"
34-
#include "scene/main/window.h"
33+
#include "scene/main/canvas_item.h"
34+
#include "scene/main/viewport.h"
3535
#include "servers/rendering/rendering_server.h"
3636

3737
float StyleBoxFlat::get_style_margin(Side p_side) const {
@@ -497,17 +497,18 @@ void StyleBoxFlat::draw(RID p_canvas_item, const Rect2 &p_rect) const {
497497
real_t aa_size_scaled = 1.0f;
498498
if (aa_on) {
499499
real_t scale_factor = 1.0f;
500-
const SceneTree *tree = Object::cast_to<SceneTree>(OS::get_singleton()->get_main_loop());
501-
if (tree) {
502-
const Window *window = tree->get_root();
503-
const Vector2 stretch_scale = window->get_stretch_transform().get_scale();
504-
scale_factor = MIN(stretch_scale.x, stretch_scale.y);
500+
CanvasItem *ci = CanvasItem::get_current_item_drawn();
501+
if (ci) {
502+
Viewport *vp = ci->get_viewport();
503+
if (vp) {
504+
scale_factor = vp->get_oversampling();
505+
}
505506
}
506507

507508
// Adjust AA feather size to account for the 2D scale factor, so that
508509
// antialiasing doesn't become blurry at viewport resolutions higher
509510
// than the default when using the `canvas_items` stretch mode
510-
// (or when using `content_scale_factor` values different than `1.0`).
511+
// (or when using `oversampling` values different than `1.0`).
511512
aa_size_scaled = aa_size / scale_factor;
512513
}
513514

0 commit comments

Comments
 (0)