widelands-dev team mailing list archive
-
widelands-dev team
-
Mailing list archive
-
Message #04863
[Merge] lp:~widelands-dev/widelands/table_image_overlap into lp:widelands
GunChleoc has proposed merging lp:~widelands-dev/widelands/table_image_overlap into lp:widelands.
Requested reviews:
Widelands Developers (widelands-dev)
For more details, see:
https://code.launchpad.net/~widelands-dev/widelands/table_image_overlap/+merge/280402
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.
--
Your team Widelands Developers is requested to review the proposed merge of lp:~widelands-dev/widelands/table_image_overlap into lp:widelands.
=== modified file 'src/ui_basic/table.cc'
--- src/ui_basic/table.cc 2015-11-21 11:34:10 +0000
+++ src/ui_basic/table.cc 2015-12-13 13:59:03 +0000
@@ -24,6 +24,7 @@
#include "graphic/font.h"
#include "graphic/font_handler1.h"
#include "graphic/graphic.h"
+#include "graphic/texture.h"
#include "graphic/rendertarget.h"
#include "graphic/text/font_set.h"
#include "graphic/text_constants.h"
@@ -297,9 +298,12 @@
int draw_x = point.x;
- if (pich > 0 && pich > lineheight) {
+ // We want a bit of margin
+ int max_pic_height = lineheight - 3;
+
+ if (pich > 0 && pich > max_pic_height) {
// Scale image to fit lineheight
- double image_scale = static_cast<double>(lineheight) / pich;
+ double image_scale = static_cast<double>(max_pic_height) / pich;
int blit_width = image_scale * picw;
if (entry_string.empty()) {
@@ -310,16 +314,24 @@
}
}
- dst.blitrect_scale(
- // Center align if text is empty
- Rect(draw_x,
- point.y,
- blit_width,
- lineheight),
- entry_picture,
- Rect(0, 0, picw, pich),
- 1.,
- BlendMode::UseAlpha);
+ // Temporary texture for the scaled image
+ Texture* scaled_texture = new Texture(blit_width, max_pic_height);
+
+ // Initialize the rectangle
+ ::fill_rect(Rect(0, 0, blit_width, max_pic_height), RGBAColor(255, 255, 255, 0), scaled_texture);
+
+ // Create the scaled image
+ ::blit(Rect(0, 0, blit_width, max_pic_height),
+ *entry_picture,
+ Rect(0, 0, picw, pich),
+ 1.,
+ BlendMode::UseAlpha,
+ scaled_texture);
+
+ // This will now blit with any appropriate cropping
+ dst.blit(Point(draw_x, point.y + 1), scaled_texture);
+
+ // For text alignment below
picw = blit_width;
} else {
if (entry_string.empty()) {
Follow ups