X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/f178ab7e82544871ae3e59341c1953d5ce088365..0ddf7c0cad6ab8c394d5e1002660a3dc983735a7:/src/msw/dc.cpp diff --git a/src/msw/dc.cpp b/src/msw/dc.cpp index 79b1b5e14f..63eadae253 100644 --- a/src/msw/dc.cpp +++ b/src/msw/dc.cpp @@ -43,6 +43,7 @@ #include "wx/sysopt.h" #include "wx/dcprint.h" #include "wx/module.h" +#include "wx/dynload.h" #include #include @@ -272,10 +273,12 @@ void wxDC::SelectOldObjects(WXHDC dc) if (m_oldBitmap) { ::SelectObject((HDC) dc, (HBITMAP) m_oldBitmap); +#ifdef __WXDEBUG__ if (m_selectedBitmap.Ok()) { m_selectedBitmap.SetSelectedInto(NULL); } +#endif } m_oldBitmap = 0; if (m_oldPen) @@ -939,6 +942,65 @@ void wxDC::DoDrawBitmap( const wxBitmap &bmp, wxCoord x, wxCoord y, bool useMask HPALETTE oldPal = 0; #endif // wxUSE_PALETTE + // do we have AlphaBlend() and company in the headers? +#ifdef AC_SRC_OVER + if ( bmp.HasAlpha() ) + { + // yes, now try to see if we have it during run-time + + typedef BOOL (WINAPI *AlphaBlend_t)(HDC,int,int,int,int, + HDC,int,int,int,int, + BLENDFUNCTION); + + // bitmaps can be drawn only from GUI thread so there is no need to + // protect this static variable from multiple threads + static bool s_triedToLoad = FALSE; + static AlphaBlend_t pfnAlphaBlend = NULL; + if ( !s_triedToLoad ) + { + s_triedToLoad = TRUE; + + wxDynamicLibrary dll(_T("msimg32.dll")); + if ( dll.IsLoaded() ) + { + pfnAlphaBlend = (AlphaBlend_t)dll.GetSymbol(_T("AlphaBlend")); + if ( pfnAlphaBlend ) + { + // we must keep the DLL loaded if we want to be able to + // call AlphaBlend() so just never unload it at all + dll.Detach(); + } + } + } + + if ( pfnAlphaBlend ) + { + MemoryHDC hdcMem; + SelectInHDC select(hdcMem, GetHbitmapOf(bmp)); + +#ifndef AC_SRC_ALPHA + #define AC_SRC_ALPHA 1 +#endif + + BLENDFUNCTION bf; + bf.BlendOp = AC_SRC_OVER; + bf.BlendFlags = 0; + bf.SourceConstantAlpha = 0xff; + bf.AlphaFormat = AC_SRC_ALPHA; + + if ( !pfnAlphaBlend(GetHdc(), x, y, width, height, + hdcMem, 0, 0, width, height, + bf) ) + { + wxLogLastError(_T("AlphaBlend")); + } + + return; + } + //else: AlphaBlend() not available + } +#endif // defined(AC_SRC_OVER) + if ( useMask ) { wxMask *mask = bmp.GetMask(); @@ -2035,25 +2097,6 @@ void wxDC::SetLogicalScale(double x, double y) m_logicalScaleY = y; } -#if WXWIN_COMPATIBILITY -void wxDC::DoGetTextExtent(const wxString& string, float *x, float *y, - float *descent, float *externalLeading, - wxFont *theFont, bool use16bit) const -{ -#ifdef __WXMICROWIN__ - if (!GetHDC()) return; -#endif - - wxCoord x1, y1, descent1, externalLeading1; - GetTextExtent(string, & x1, & y1, & descent1, & externalLeading1, theFont, use16bit); - *x = x1; *y = y1; - if (descent) - *descent = descent1; - if (externalLeading) - *externalLeading = externalLeading1; -} -#endif - #if wxUSE_DC_CACHEING /*