diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/Fl_Double_Window.cxx | 40 |
1 files changed, 34 insertions, 6 deletions
diff --git a/src/Fl_Double_Window.cxx b/src/Fl_Double_Window.cxx index e648fa4ab..427c43807 100644 --- a/src/Fl_Double_Window.cxx +++ b/src/Fl_Double_Window.cxx @@ -80,6 +80,7 @@ typedef struct { BYTE a; BYTE b; BYTE c; BYTE d; } FL_BLENDFUNCTION; typedef BOOL (WINAPI* fl_alpha_blend_func) (HDC,int,int,int,int,HDC,int,int,int,int,FL_BLENDFUNCTION); static fl_alpha_blend_func fl_alpha_blend = NULL; +static FL_BLENDFUNCTION blendfunc = { 0, 0, 255, 1}; /* * This function checks if the version of MSWindows that we @@ -89,13 +90,38 @@ static fl_alpha_blend_func fl_alpha_blend = NULL; char fl_can_do_alpha_blending() { static char been_here = 0; static char can_do = 0; + // do this test only once if (been_here) return can_do; + been_here = 1; + // load the library that implements alpha blending HMODULE hMod = LoadLibrary("MSIMG32.DLL"); + // give up if that doesn't exist (Win95?) if (!hMod) return 0; + // now find the blending function inside that dll fl_alpha_blend = (fl_alpha_blend_func)GetProcAddress(hMod, "AlphaBlend"); + // give up if we can't find it (Win95) if (!fl_alpha_blend) return 0; - can_do = 1; - return 1; + // we have the call, but does our display support alpha blending? + HDC dc = 0L;//fl_gc; + // get the current or the desktop's device context + if (!dc) dc = GetDC(0L); + if (!dc) return 0; + // check the device capabilities flags. However GetDeviceCaps + // does not return anything useful, so we have to do it manually: + + HBITMAP bm = CreateCompatibleBitmap(dc, 1, 1); + HDC new_gc = CreateCompatibleDC(dc); + int save = SaveDC(new_gc); + SelectObject(new_gc, bm); + COLORREF set = SetPixel(new_gc, 0, 0, 0x01010101); + BOOL alpha_ok = fl_alpha_blend(dc, 0, 0, 1, 1, new_gc, 0, 0, 1, 1, blendfunc); + RestoreDC(new_gc, save); + DeleteDC(new_gc); + DeleteObject(bm); + + if (!fl_gc) ReleaseDC(0L, dc); + if (alpha_ok) can_do = 1; + return can_do; } HDC fl_makeDC(HBITMAP bitmap) { @@ -119,13 +145,15 @@ void fl_copy_offscreen(int x,int y,int w,int h,HBITMAP bitmap,int srcx,int srcy) } void fl_copy_offscreen_with_alpha(int x,int y,int w,int h,HBITMAP bitmap,int srcx,int srcy) { - static FL_BLENDFUNCTION blendfunc = { 0, 0, 255, 1}; HDC new_gc = CreateCompatibleDC(fl_gc); int save = SaveDC(new_gc); SelectObject(new_gc, bitmap); - if (fl_can_do_alpha_blending()) - fl_alpha_blend(fl_gc, x, y, w, h, new_gc, srcx, srcy, w, h, blendfunc); - else + BOOL alpha_ok = 0; + // first try to alpha blend + if (fl_can_do_alpha_blending()) + alpha_ok = fl_alpha_blend(fl_gc, x, y, w, h, new_gc, srcx, srcy, w, h, blendfunc); + // if that failed (it shouldn,t), still copy the bitmap over, but now alpha is 1 + if (!alpha_ok) BitBlt(fl_gc, x, y, w, h, new_gc, srcx, srcy, SRCCOPY); RestoreDC(new_gc, save); DeleteDC(new_gc); |
