summaryrefslogtreecommitdiff
path: root/wx+/image_tools.cpp
diff options
context:
space:
mode:
authorB Stack <bgstack15@gmail.com>2018-08-10 11:29:21 -0400
committerB Stack <bgstack15@gmail.com>2018-08-10 11:29:21 -0400
commita9255194193b04d599b9f0a64cde6b831dd7d916 (patch)
tree8b975393f5b0f7b4403da85f5095ad57581178e5 /wx+/image_tools.cpp
parent10.2 (diff)
downloadFreeFileSync-a9255194193b04d599b9f0a64cde6b831dd7d916.tar.gz
FreeFileSync-a9255194193b04d599b9f0a64cde6b831dd7d916.tar.bz2
FreeFileSync-a9255194193b04d599b9f0a64cde6b831dd7d916.zip
10.310.3
Diffstat (limited to 'wx+/image_tools.cpp')
-rwxr-xr-xwx+/image_tools.cpp36
1 files changed, 36 insertions, 0 deletions
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())
bgstack15