Re-add cropping of transparent padding on status icons.

Fixes #8303
This commit is contained in:
pentarctagon 2024-01-30 14:12:47 -06:00 committed by Pentarctagon
parent 9dbbb09fc3
commit 37a45c32ce
6 changed files with 42 additions and 7 deletions

View file

@ -3066,7 +3066,7 @@ void display::draw_report(const std::string& report_name, bool tooltip_test)
if (used_ellipsis) goto skip_element;
// Draw an image element.
texture img(image::get_texture(t));
texture img(image::get_texture(t+"~CROP_TRANSPARENCY()"));
if (!img) {
ERR_DP << "could not find image for report: '" << t << "'";

View file

@ -195,6 +195,11 @@ surface gs_modification::operator()(const surface& src) const
return greyscale_image(src);
}
surface crop_transparency_modification::operator()(const surface& src) const
{
return get_non_transparent_portion(src);
}
surface bw_modification::operator()(const surface& src) const
{
return monochrome_image(src, threshold_);
@ -750,6 +755,12 @@ REGISTER_MOD_PARSER(GS, )
return std::make_unique<gs_modification>();
}
// crop transparent padding
REGISTER_MOD_PARSER(CROP_TRANSPARENCY, )
{
return std::make_unique<crop_transparency_modification>();
}
// Black and white
REGISTER_MOD_PARSER(BW, args)
{

View file

@ -224,6 +224,15 @@ public:
virtual surface operator()(const surface& src) const;
};
/**
* Crop transparent padding (CROP_TRANSPARENCY) modification.
*/
class crop_transparency_modification : public modification
{
public:
virtual surface operator()(const surface& src) const;
};
/**
* Black and white (BW) modification.
*/

View file

@ -83,7 +83,7 @@ static config image_report(const std::string &image,
using font::span_color;
static void add_status(config &r,
char const *path, char const *desc1, char const *desc2)
const std::string& path, char const *desc1, char const *desc2)
{
std::ostringstream s;
s << translation::gettext(desc1) << translation::gettext(desc2);

View file

@ -31,6 +31,9 @@
#include <boost/circular_buffer.hpp>
#include <boost/math/constants/constants.hpp>
static lg::log_domain log_display("display");
#define ERR_DP LOG_STREAM(err, log_display)
version_info sdl::get_version()
{
SDL_version sdl_version;
@ -1846,15 +1849,18 @@ struct not_alpha
}
SDL_Rect get_non_transparent_portion(const surface &surf)
surface get_non_transparent_portion(const surface &surf)
{
SDL_Rect res {0,0,0,0};
if(surf == nullptr)
return nullptr;
surface nsurf = surf.clone();
if(nsurf == nullptr) {
PLAIN_LOG << "failed to make neutral surface";
return res;
return nullptr;
}
SDL_Rect res {0,0,0,0};
const not_alpha calc;
surface_lock lock(nsurf);
@ -1912,5 +1918,14 @@ SDL_Rect get_non_transparent_portion(const surface &surf)
res.w = nsurf->w - res.x - n;
return res;
surface cropped = get_surface_portion(nsurf, res);
if(cropped && res.w > 0 && res.h > 0) {
surface scaled = scale_surface(cropped, res.w, res.h);
if(scaled) {
return scaled;
}
}
ERR_DP << "Failed to either crop or scale the surface";
return nsurf;
}

View file

@ -257,7 +257,7 @@ surface rotate_90_surface(const surface &surf, bool clockwise);
surface flip_surface(const surface &surf);
surface flop_surface(const surface &surf);
SDL_Rect get_non_transparent_portion(const surface &surf);
surface get_non_transparent_portion(const surface &surf);
/**
* Helper methods for setting/getting a single pixel in an image.