From a9255194193b04d599b9f0a64cde6b831dd7d916 Mon Sep 17 00:00:00 2001 From: B Stack Date: Fri, 10 Aug 2018 11:29:21 -0400 Subject: 10.3 --- wx+/image_tools.cpp | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'wx+/image_tools.cpp') diff --git a/wx+/image_tools.cpp b/wx+/image_tools.cpp index 88a78b21..0cb0e328 100755 --- a/wx+/image_tools.cpp +++ b/wx+/image_tools.cpp @@ -216,6 +216,42 @@ wxImage zen::createImageFromText(const wxString& text, const wxFont& font, const } +wxBitmap zen::layOver(const wxBitmap& background, const wxBitmap& foreground, int alignment) +{ + if (!foreground.IsOk()) return background; + + assert(foreground.HasAlpha() == background.HasAlpha()); //we don't support mixed-mode brittleness! + const int offsetX = [&] + { + if (alignment & wxALIGN_RIGHT) + return background.GetWidth() - foreground.GetWidth(); + if (alignment & wxALIGN_CENTER_HORIZONTAL) + return (background.GetWidth() - foreground.GetWidth()) / 2; + + static_assert(wxALIGN_LEFT == 0); + return 0; + }(); + + const int offsetY = [&] + { + if (alignment & wxALIGN_BOTTOM) + return background.GetHeight() - foreground.GetHeight(); + if (alignment & wxALIGN_CENTER_VERTICAL) + return (background.GetHeight() - foreground.GetHeight()) / 2; + + static_assert(wxALIGN_TOP == 0); + return 0; + }(); + + wxBitmap output(background.ConvertToImage()); //attention: wxBitmap/wxImage use ref-counting without copy on write! + { + wxMemoryDC dc(output); + dc.DrawBitmap(foreground, offsetX, offsetY); + } + return output; +} + + void zen::convertToVanillaImage(wxImage& img) { if (!img.HasAlpha()) -- cgit