GunChleoc has proposed merging
lp:~widelands-dev/widelands/bug-1696702-fuzzy-building-plots into lp:widelands.
Commit message:
Force integer precision for overlays. This fixes fuzzy overlay images when the
player hits Ctrl+0 to reset the zoom.
Requested reviews:
Widelands Developers (widelands-dev)
Related bugs:
Bug #1696702 in widelands: "Zoom reset can end up with fuzzy building plot
icons"
https://bugs.launchpad.net/widelands/+bug/1696702
For more details, see:
https://code.launchpad.net/~widelands-dev/widelands/bug-1696702-fuzzy-building-plots/+merge/343070
Works fine on my Linux. Let's wait for AppVeyor and test on Windows to see if
the bug is indeed gone.
--
Your team Widelands Developers is requested to review the proposed merge of
lp:~widelands-dev/widelands/bug-1696702-fuzzy-building-plots into lp:widelands.
=== modified file 'src/editor/editorinteractive.cc'
--- src/editor/editorinteractive.cc 2018-04-07 16:59:00 +
+++ src/editor/editorinteractive.cc 2018-04-13 17:51:09 +
@@ -307,17 +307,6 @@
}
}
- const auto blit = [, scale](
- const Image* pic, const Vector2f& position, const Vector2i& hotspot) {
- dst.blitrect_scale(Rectf(position - hotspot.cast() * scale, pic->width() * scale,
- pic->height() * scale),
- pic, Recti(0, 0, pic->width(), pic->height()), 1.f,
- BlendMode::UseAlpha);
- };
- const auto blit_overlay = [, ](const Image* pic, const Vector2i& hotspot) {
- blit(pic, field.rendertarget_pixel, hotspot);
- };
-
// Draw resource overlay.
uint8_t const amount = field.fcoords.field->get_resources_amount();
if (draw_resources_ && amount > 0) {
@@ -325,7 +314,7 @@
world.get_resource(field.fcoords.field->get_resources())->editor_image(amount);
if (!immname.empty()) {
const auto* pic = g_gr->images().get(immname);
-blit_overlay(pic, Vector2i(pic->width() / 2, pic->height() / 2));
+blit_field_overlay(, field, pic, Vector2i(pic->width() / 2, pic->height() / 2), scale);
}
}
@@ -334,7 +323,7 @@
const auto* overlay =
get_buildhelp_overlay(tools_->current().nodecaps_for_buildhelp(field.fcoords, ebase));
if (overlay != nullptr) {
-blit_overlay(overlay->pic, overlay->hotspot);
+blit_field_overlay(, field, overlay->pic, overlay->hotspot, scale);
}
}
@@ -345,13 +334,13 @@
playercolor_image(it->second - 1, "images/players/player_position.png");
assert(player_image != nullptr);
constexpr int kStartingPosHotspotY = 55;
- blit_overlay(player_image, Vector2i(player_image->width() / 2, kStartingPosHotspotY));
+ blit_field_overlay(, field, player_image, Vector2i(player_image->width() / 2, kStartingPosHotspotY), scale);
}
// Draw selection markers on the field.
if (selected_nodes.count(field.fcoords) > 0) {
const Image* pic = get_sel_picture();
- blit_overlay(pic, Vector2i(pic->width() / 2, pic->height() / 2));
+ blit_field_overlay(, field, pic, Vector2i(pic->width() / 2, pic->height() / 2), scale);
}
// Draw selection markers on the triangles.
@@ -361,23 +350,23 @@
const FieldsToDraw::Field& bln = fields_to_draw->at(field.bln_index);
if (selected_triangles.count(
Widelands::TCoords<>(field.fcoords, Widelands::TriangleIndex::R))) {
-const Vector2f tripos(
+const Vector2i tripos(
(field.rendertarget_pixel.x + rn.rendertarget_pixel.x + brn.rendertarget_pixel.x) /
- 3.f,
+ 3,
(field.rendertarget_pixel.y + rn.rendertarget_pixel.y + brn.rendertarget_pixel.y) /
- 3.f);
+ 3);
const Image* pic = get_sel_picture();
-blit(pic, tripos, Vector2i(pic->width() / 2, pic->height() / 2));
+blit_overlay(, tripos, pic, Vector2i(pic->width() / 2, pic->height() / 2), scale);
}
if (selected_triangles.count(
Widelands::TCoords<>(field.fcoords, Widelands::TriangleIndex::D))) {
-const Vector2f tripos(
+const Vector2i tripos(
(field.rendertarget_pixel.x + bln.rendertarget_pixel.x + brn.rendertarget_pixel.x) /
- 3.f,
+ 3,
(field.rendertarget_pixel.y + bln.rendertarget_pixel.y + brn.rendertarget_pixel.y) /
- 3.f);
+ 3);
const Image* pic = get_sel_picture();
-blit(pic, tripos, Vector2i(pic->width() / 2, pic->height() / 2));
+blit_overlay(, tripos, pic, Vector2i(pic->width() / 2, pic->height() / 2), scale);
}
}
}
=== modified file 'src/wui/interactive_base.cc'
--- src/wui/interactive_base.cc 2018-04-07 16:59:00 +
+++ src/wui/interactive_base.cc 2018-04-13 17:51:09 +
@@ -458,6 +458,18 @@
}
}
+void InteractiveBase::blit_overlay(RenderTarget* dst, const Vector2i& position, const Image* image, const Vector2i& hotspot, float scale) {
+ const Recti pixel_perfect_rect = Recti(position - hotspot * scale,
+image->width() * scale, image->height() * scale);
+ dst->blitrect_scale(pixel_perfect_rect.cast(),
+