summaryrefslogtreecommitdiff
path: root/wx+/image_tools.cpp
diff options
context:
space:
mode:
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