Merge lp:~widelands-dev/widelands/table_image_overlap into lp:widelands

Proposed by GunChleoc
Status: Merged
Merged at revision: 7680
Proposed branch: lp:~widelands-dev/widelands/table_image_overlap
Merge into: lp:widelands
Diff against target: 61 lines (+24/-12)
1 file modified
src/ui_basic/table.cc (+24/-12)
To merge this branch: bzr merge lp:~widelands-dev/widelands/table_image_overlap
Reviewer Review Type Date Requested Status
kaputtnik (community) Approve
TiborB Approve
Review via email: mp+280402@code.launchpad.net

Description of the change

Fixed image overlap on the bottom of tables.

The reason for the bug was that blictrect_scale can't handle cropping as well. So, I am blitting the image into a new Texture, which can then be blitted normally with built-in cropping.

The bug is most notable while scrolling in the Mesages window.

To post a comment you must log in.
Revision history for this message
TiborB (tiborb95) wrote :

Tested. I dont know how it looked before though :)

review: Approve
Revision history for this message
kaputtnik (franku) wrote :

Works fine :-)

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/ui_basic/table.cc'
2--- src/ui_basic/table.cc 2015-11-21 11:34:10 +0000
3+++ src/ui_basic/table.cc 2015-12-29 19:42:11 +0000
4@@ -24,6 +24,7 @@
5 #include "graphic/font.h"
6 #include "graphic/font_handler1.h"
7 #include "graphic/graphic.h"
8+#include "graphic/texture.h"
9 #include "graphic/rendertarget.h"
10 #include "graphic/text/font_set.h"
11 #include "graphic/text_constants.h"
12@@ -297,9 +298,12 @@
13
14 int draw_x = point.x;
15
16- if (pich > 0 && pich > lineheight) {
17+ // We want a bit of margin
18+ int max_pic_height = lineheight - 3;
19+
20+ if (pich > 0 && pich > max_pic_height) {
21 // Scale image to fit lineheight
22- double image_scale = static_cast<double>(lineheight) / pich;
23+ double image_scale = static_cast<double>(max_pic_height) / pich;
24 int blit_width = image_scale * picw;
25
26 if (entry_string.empty()) {
27@@ -310,16 +314,24 @@
28 }
29 }
30
31- dst.blitrect_scale(
32- // Center align if text is empty
33- Rect(draw_x,
34- point.y,
35- blit_width,
36- lineheight),
37- entry_picture,
38- Rect(0, 0, picw, pich),
39- 1.,
40- BlendMode::UseAlpha);
41+ // Temporary texture for the scaled image
42+ Texture* scaled_texture = new Texture(blit_width, max_pic_height);
43+
44+ // Initialize the rectangle
45+ ::fill_rect(Rect(0, 0, blit_width, max_pic_height), RGBAColor(255, 255, 255, 0), scaled_texture);
46+
47+ // Create the scaled image
48+ ::blit(Rect(0, 0, blit_width, max_pic_height),
49+ *entry_picture,
50+ Rect(0, 0, picw, pich),
51+ 1.,
52+ BlendMode::UseAlpha,
53+ scaled_texture);
54+
55+ // This will now blit with any appropriate cropping
56+ dst.blit(Point(draw_x, point.y + 1), scaled_texture);
57+
58+ // For text alignment below
59 picw = blit_width;
60 } else {
61 if (entry_string.empty()) {

Subscribers

People subscribed via source and target branches

to status/vote changes: