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 +0000
+++ src/editor/editorinteractive.cc	2018-04-13 17:51:09 +0000
@@ -307,17 +307,6 @@
 			}
 		}
 
-		const auto blit = [&dst, scale](
-		   const Image* pic, const Vector2f& position, const Vector2i& hotspot) {
-			dst.blitrect_scale(Rectf(position - hotspot.cast<float>() * scale, pic->width() * scale,
-			                         pic->height() * scale),
-			                   pic, Recti(0, 0, pic->width(), pic->height()), 1.f,
-			                   BlendMode::UseAlpha);
-		};
-		const auto blit_overlay = [&field, &blit](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(&dst, 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(&dst, 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(&dst, 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(&dst, 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(&dst, 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(&dst, 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 +0000
+++ src/wui/interactive_base.cc	2018-04-13 17:51:09 +0000
@@ -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<float>(),
+	                   image, Recti(0, 0, image->width(), image->height()), 1.f,
+	                   BlendMode::UseAlpha);
+}
+
+void InteractiveBase::blit_field_overlay(RenderTarget* dst, const FieldsToDraw::Field& field, const Image* image, const Vector2i& hotspot, float scale) {
+	blit_overlay(dst, field.rendertarget_pixel.cast<int>(), image, hotspot, scale);
+}
+
 void InteractiveBase::mainview_move() {
 	if (minimap_registry_.window) {
 		minimap_->set_view(map_view_.view_area().rect());

=== modified file 'src/wui/interactive_base.h'
--- src/wui/interactive_base.h	2018-04-07 16:59:00 +0000
+++ src/wui/interactive_base.h	2018-04-13 17:51:09 +0000
@@ -197,6 +197,8 @@
 	void mainview_move();
 
 	void draw_overlay(RenderTarget&) override;
+	void blit_overlay(RenderTarget* dst, const Vector2i& pos, const Image* image, const Vector2i& hotspot, float scale);
+	void blit_field_overlay(RenderTarget* dst, const FieldsToDraw::Field& field, const Image* image, const Vector2i& hotspot, float scale);
 
 	void unset_sel_picture();
 	void set_sel_picture(const Image* image);

=== modified file 'src/wui/interactive_player.cc'
--- src/wui/interactive_player.cc	2018-04-07 16:59:00 +0000
+++ src/wui/interactive_player.cc	2018-04-13 17:51:09 +0000
@@ -308,12 +308,6 @@
 		}
 
 		const float scale = 1.f / given_map_view->view().zoom;
-		const auto blit_overlay = [dst, f, scale](const Image* pic, const Vector2i& hotspot) {
-			dst->blitrect_scale(Rectf(f->rendertarget_pixel - hotspot.cast<float>() * scale,
-			                          pic->width() * scale, pic->height() * scale),
-			                    pic, Recti(0, 0, pic->width(), pic->height()), 1.f,
-			                    BlendMode::UseAlpha);
-		};
 
 		// Add road building overlays if applicable.
 		if (f->vision > 0) {
@@ -339,7 +333,7 @@
 		{
 			const auto it = work_area_overlays.find(f->fcoords);
 			if (it != work_area_overlays.end()) {
-				blit_overlay(it->second, Vector2i(it->second->width() / 2, it->second->height() / 2));
+				blit_field_overlay(dst, *f, it->second, Vector2i(it->second->width() / 2, it->second->height() / 2), scale);
 			}
 		}
 
@@ -348,22 +342,22 @@
 			if (buildhelp()) {
 				const auto* overlay = get_buildhelp_overlay(plr.get_buildcaps(f->fcoords));
 				if (overlay != nullptr) {
-					blit_overlay(overlay->pic, overlay->hotspot);
+					blit_field_overlay(dst, *f, overlay->pic, overlay->hotspot, scale);
 				}
 			}
 
 			// Blit the selection marker.
 			if (f->fcoords == get_sel_pos().node) {
 				const Image* pic = get_sel_picture();
-				blit_overlay(pic, Vector2i(pic->width() / 2, pic->height() / 2));
+				blit_field_overlay(dst, *f, pic, Vector2i(pic->width() / 2, pic->height() / 2), scale);
 			}
 
 			// Draw road building slopes.
 			{
 				const auto it = road_building.steepness_indicators.find(f->fcoords);
 				if (it != road_building.steepness_indicators.end()) {
-					blit_overlay(
-					   it->second, Vector2i(it->second->width() / 2, it->second->height() / 2));
+					blit_field_overlay(dst, *f,
+					   it->second, Vector2i(it->second->width() / 2, it->second->height() / 2), scale);
 				}
 			}
 		}

=== modified file 'src/wui/interactive_spectator.cc'
--- src/wui/interactive_spectator.cc	2018-04-07 16:59:00 +0000
+++ src/wui/interactive_spectator.cc	2018-04-13 17:51:09 +0000
@@ -140,18 +140,11 @@
 			bob->draw(the_game, text_to_draw, field.rendertarget_pixel, scale, dst);
 		}
 
-		const auto blit_overlay = [dst, &field, scale](const Image* pic, const Vector2i& hotspot) {
-			dst->blitrect_scale(Rectf(field.rendertarget_pixel - hotspot.cast<float>() * scale,
-			                          pic->width() * scale, pic->height() * scale),
-			                    pic, Recti(0, 0, pic->width(), pic->height()), 1.f,
-			                    BlendMode::UseAlpha);
-		};
-
 		// Draw work area previews.
 		const auto it = work_area_overlays.find(field.fcoords);
 		if (it != work_area_overlays.end()) {
 			const Image* pic = it->second;
-			blit_overlay(pic, Vector2i(pic->width() / 2, pic->height() / 2));
+			blit_field_overlay(dst, field, pic, Vector2i(pic->width() / 2, pic->height() / 2), scale);
 		}
 
 		// Draw build help.
@@ -167,14 +160,14 @@
 			}
 			const auto* overlay = get_buildhelp_overlay(caps);
 			if (overlay != nullptr) {
-				blit_overlay(overlay->pic, overlay->hotspot);
+				blit_field_overlay(dst, field, overlay->pic, overlay->hotspot, scale);
 			}
 		}
 
 		// Blit the selection marker.
 		if (field.fcoords == get_sel_pos().node) {
 			const Image* pic = get_sel_picture();
-			blit_overlay(pic, Vector2i(pic->width() / 2, pic->height() / 2));
+			blit_field_overlay(dst, field, pic, Vector2i(pic->width() / 2, pic->height() / 2), scale);
 		}
 	}
 }

_______________________________________________
Mailing list: https://launchpad.net/~widelands-dev
Post to     : widelands-dev@lists.launchpad.net
Unsubscribe : https://launchpad.net/~widelands-dev
More help   : https://help.launchpad.net/ListHelp

Reply via email to