widelands-dev team mailing list archive
-
widelands-dev team
-
Mailing list archive
-
Message #04341
[Merge] lp:~widelands-dev/widelands/bug-1401479 into lp:widelands
GunChleoc has proposed merging lp:~widelands-dev/widelands/bug-1401479 into lp:widelands.
Requested reviews:
Widelands Developers (widelands-dev)
Related bugs:
Bug #1401479 in widelands: "Minimaps button images are scaled down instead of cropped."
https://bugs.launchpad.net/widelands/+bug/1401479
For more details, see:
https://code.launchpad.net/~widelands-dev/widelands/bug-1401479/+merge/270582
Picture buttons now have the option not to scale their picture.
Added blit_monochrome to Rendertarget.
Minimap buttons now don't scale their images.
--
Your team Widelands Developers is requested to review the proposed merge of lp:~widelands-dev/widelands/bug-1401479 into lp:widelands.
=== modified file 'src/graphic/rendertarget.cc'
--- src/graphic/rendertarget.cc 2014-12-07 20:13:27 +0000
+++ src/graphic/rendertarget.cc 2015-09-09 18:54:54 +0000
@@ -184,6 +184,24 @@
}
}
+void RenderTarget::blit_monochrome(const Point& dst,
+ const Image* image,
+ const RGBAColor& blend_mode, UI::Align align) {
+ Point destination_point(dst);
+
+ UI::correct_for_align(align, image->width(), image->height(), &destination_point);
+
+ Rect srcrc(Point(0, 0), image->width(), image->height());
+
+ if (to_surface_geometry(&destination_point, &srcrc)) {
+ ::blit_monochrome(Rect(destination_point.x, destination_point.y, srcrc.w, srcrc.h),
+ *image,
+ srcrc,
+ blend_mode,
+ m_surface);
+ }
+}
+
/**
* Like \ref blit, but use only a sub-rectangle of the source image.
*/
@@ -235,7 +253,7 @@
Point destination_point(destination_rect.x, destination_rect.y);
Rect srcrect(source_rect);
if (to_surface_geometry(&destination_point, &srcrect)) {
- blit_monochrome(
+ ::blit_monochrome(
Rect(destination_point.x, destination_point.y, destination_rect.w, destination_rect.h),
*image,
source_rect,
=== modified file 'src/graphic/rendertarget.h'
--- src/graphic/rendertarget.h 2014-12-06 15:32:50 +0000
+++ src/graphic/rendertarget.h 2015-09-09 18:54:54 +0000
@@ -71,6 +71,12 @@
BlendMode blend_mode = BlendMode::UseAlpha,
UI::Align = UI::Align_TopLeft);
+ // Like blit. See MonochromeBlitProgram for details.
+ void blit_monochrome(const Point& dst,
+ const Image* image,
+ const RGBAColor& blend_mode,
+ UI::Align = UI::Align_TopLeft);
+
void blitrect(const Point& dst,
const Image* image,
const Rect& src,
=== modified file 'src/ui_basic/button.cc'
--- src/ui_basic/button.cc 2014-12-11 10:27:30 +0000
+++ src/ui_basic/button.cc 2015-09-09 18:54:54 +0000
@@ -68,7 +68,7 @@
const Image* bg_pic,
const Image* fg_pic,
const std::string & tooltip_text,
- bool const _enabled, bool const flat)
+ bool const _enabled, bool const flat, const bool keep_image_size)
:
NamedPanel (parent, name, x, y, w, h, tooltip_text),
m_highlighted (false),
@@ -77,6 +77,7 @@
m_enabled (_enabled),
m_repeating (false),
m_flat (flat),
+ m_keep_image_size(keep_image_size),
m_draw_flat_background(false),
m_time_nextact (0),
m_pic_background(bg_pic),
@@ -165,30 +166,51 @@
dst.brighten_rect
(Rect(Point(0, 0), get_w(), get_h()), MOUSE_OVER_BRIGHT_FACTOR);
- // if we got a picture, draw it centered
+ // If we've got a picture, draw it centered
if (m_pic_custom) {
- const int max_image_w = get_w() - 2 * kButtonImageMargin;
- const int max_image_h = get_h() - 2 * kButtonImageMargin;
- double image_scale =
- std::min(1.,
- std::min(static_cast<double>(max_image_w) / m_pic_custom->width(),
- static_cast<double>(max_image_h) / m_pic_custom->height()));
- int blit_width = image_scale * m_pic_custom->width();
- int blit_height = image_scale * m_pic_custom->height();
-
- if (m_enabled) {
- dst.blitrect_scale(
- Rect((get_w() - blit_width) / 2, (get_h() - blit_height) / 2, blit_width, blit_height),
- m_pic_custom,
- Rect(0, 0, m_pic_custom->width(), m_pic_custom->height()),
- 1.,
- BlendMode::UseAlpha);
+ if (m_keep_image_size) {
+ if (m_enabled) {
+ // ">> 1" is almost like "/ 2", but simpler for signed types (difference
+ // is that -1 >> 1 is -1 but -1 / 2 is 0).
+ dst.blit(
+ Point(
+ (get_w() - static_cast<int32_t>(m_pic_custom->width())) >> 1,
+ (get_h() - static_cast<int32_t>(m_pic_custom->height())) >> 1),
+ m_pic_custom);
+ } else {
+ // ">> 1" is almost like "/ 2", but simpler for signed types (difference
+ // is that -1 >> 1 is -1 but -1 / 2 is 0).
+ dst.blit_monochrome(
+ Point(
+ (get_w() - static_cast<int32_t>(m_pic_custom->width())) >> 1,
+ (get_h() - static_cast<int32_t>(m_pic_custom->height())) >> 1),
+ m_pic_custom,
+ RGBAColor(255, 255, 255, 127));
+ }
} else {
- dst.blitrect_scale_monochrome(
- Rect((get_w() - blit_width) / 2, (get_h() - blit_height) / 2, blit_width, blit_height),
- m_pic_custom,
- Rect(0, 0, m_pic_custom->width(), m_pic_custom->height()),
- RGBAColor(255, 255, 255, 127));
+ const int max_image_w = get_w() - 2 * kButtonImageMargin;
+ const int max_image_h = get_h() - 2 * kButtonImageMargin;
+ double image_scale =
+ std::min(1.,
+ std::min(static_cast<double>(max_image_w) / m_pic_custom->width(),
+ static_cast<double>(max_image_h) / m_pic_custom->height()));
+ int blit_width = image_scale * m_pic_custom->width();
+ int blit_height = image_scale * m_pic_custom->height();
+
+ if (m_enabled) {
+ dst.blitrect_scale(
+ Rect((get_w() - blit_width) / 2, (get_h() - blit_height) / 2, blit_width, blit_height),
+ m_pic_custom,
+ Rect(0, 0, m_pic_custom->width(), m_pic_custom->height()),
+ 1.,
+ BlendMode::UseAlpha);
+ } else {
+ dst.blitrect_scale_monochrome(
+ Rect((get_w() - blit_width) / 2, (get_h() - blit_height) / 2, blit_width, blit_height),
+ m_pic_custom,
+ Rect(0, 0, m_pic_custom->width(), m_pic_custom->height()),
+ RGBAColor(255, 255, 255, 127));
+ }
}
} else if (m_title.length()) {
=== modified file 'src/ui_basic/button.h'
--- src/ui_basic/button.h 2014-12-11 10:27:30 +0000
+++ src/ui_basic/button.h 2015-09-09 18:54:54 +0000
@@ -40,7 +40,7 @@
(Panel * const parent,
const std::string & name,
int32_t const x, int32_t const y, uint32_t const w, uint32_t const h,
- const Image* background_pictute_id,
+ const Image* background_picture_id,
const std::string & title_text,
const std::string & tooltip_text = std::string(),
bool const _enabled = true,
@@ -49,11 +49,12 @@
(Panel * const parent,
const std::string & name,
const int32_t x, const int32_t y, const uint32_t w, const uint32_t h,
- const Image* background_pictute_id,
+ const Image* background_picture_id,
const Image* foreground_picture_id,
const std::string & tooltip_text = std::string(),
bool const _enabled = true,
- bool const flat = false);
+ bool const flat = false,
+ bool const keep_image_size = false);
~Button();
void set_pic(const Image* pic);
@@ -99,6 +100,7 @@
bool m_enabled;
bool m_repeating;
bool m_flat;
+ bool m_keep_image_size; // Keep image's original size and center it
bool m_draw_flat_background;
int32_t m_time_nextact;
=== modified file 'src/ui_basic/icongrid.cc'
--- src/ui_basic/icongrid.cc 2014-09-10 14:48:40 +0000
+++ src/ui_basic/icongrid.cc 2015-09-09 18:54:54 +0000
@@ -32,13 +32,13 @@
(IconGrid & parent,
const std::string & name,
int32_t x, int32_t y, uint32_t w, uint32_t h,
- const Image* background_pictute_id,
+ const Image* background_picture_id,
const Image* foreground_picture_id,
uint32_t callback_argument_id,
const std::string & tooltip_text)
:
Button
- (&parent, name, x, y, w, h, background_pictute_id,
+ (&parent, name, x, y, w, h, background_picture_id,
foreground_picture_id,
tooltip_text, true, true),
m_icongrid(parent),
=== modified file 'src/ui_basic/messagebox.cc'
--- src/ui_basic/messagebox.cc 2015-08-06 17:14:34 +0000
+++ src/ui_basic/messagebox.cc 2015-09-09 18:54:54 +0000
@@ -20,7 +20,6 @@
#include "ui_basic/messagebox.h"
#include "base/i18n.h"
-#include "base/log.h" // NOCOM
#include "graphic/font_handler.h"
#include "graphic/graphic.h"
#include "ui_basic/button.h"
=== modified file 'src/wui/minimap.cc'
--- src/wui/minimap.cc 2014-12-07 20:52:55 +0000
+++ src/wui/minimap.cc 2015-09-09 18:54:54 +0000
@@ -143,37 +143,43 @@
but_w() * 0, m_view.get_h() + but_h() * 0, but_w(), but_h(),
g_gr->images().get("pics/but0.png"),
g_gr->images().get("pics/button_terrn.png"),
- _("Terrain")),
+ _("Terrain"),
+ true, false, true),
button_owner
(this, "owner",
but_w() * 1, m_view.get_h() + but_h() * 0, but_w(), but_h(),
g_gr->images().get("pics/but0.png"),
g_gr->images().get("pics/button_owner.png"),
- _("Owner")),
+ _("Owner"),
+ true, false, true),
button_flags
(this, "flags",
but_w() * 2, m_view.get_h() + but_h() * 0, but_w(), but_h(),
g_gr->images().get("pics/but0.png"),
g_gr->images().get("pics/button_flags.png"),
- _("Flags")),
+ _("Flags"),
+ true, false, true),
button_roads
(this, "roads",
but_w() * 0, m_view.get_h() + but_h() * 1, but_w(), but_h(),
g_gr->images().get("pics/but0.png"),
g_gr->images().get("pics/button_roads.png"),
- _("Roads")),
+ _("Roads"),
+ true, false, true),
button_bldns
(this, "buildings",
but_w() * 1, m_view.get_h() + but_h() * 1, but_w(), but_h(),
g_gr->images().get("pics/but0.png"),
g_gr->images().get("pics/button_bldns.png"),
- _("Buildings")),
+ _("Buildings"),
+ true, false, true),
button_zoom
(this, "zoom",
but_w() * 2, m_view.get_h() + but_h() * 1, but_w(), but_h(),
g_gr->images().get("pics/but0.png"),
g_gr->images().get("pics/button_zoom.png"),
- _("Zoom"))
+ _("Zoom"),
+ true, false, true)
{
button_terrn.sigclicked.connect(boost::bind(&MiniMap::toggle, boost::ref(*this), MiniMapLayer::Terrain));
button_owner.sigclicked.connect(boost::bind(&MiniMap::toggle, boost::ref(*this), MiniMapLayer::Owner));
Follow ups