diff options
| author | Matthias Melcher <fltk@matthiasm.com> | 2006-09-15 15:35:16 +0000 |
|---|---|---|
| committer | Matthias Melcher <fltk@matthiasm.com> | 2006-09-15 15:35:16 +0000 |
| commit | c6de2dd3ef9e9a3c17ce210ff1775bd6e183d738 (patch) | |
| tree | d9a781c366b4b41678267c786c4a411b24957bb0 /src/Fl_Double_Window.cxx | |
| parent | dac4c5630458e1183b5d234aed395971a5642d52 (diff) | |
Implemented alpha blending for WIN32. I believe that I did it in a way that is compatible even with Windows 95, but please let me know if you have any concerns. Cygwin not tested, but hopefully OK.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.1@5430 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
Diffstat (limited to 'src/Fl_Double_Window.cxx')
| -rw-r--r-- | src/Fl_Double_Window.cxx | 44 |
1 files changed, 43 insertions, 1 deletions
diff --git a/src/Fl_Double_Window.cxx b/src/Fl_Double_Window.cxx index 54fd2b935..4e5f7bf1b 100644 --- a/src/Fl_Double_Window.cxx +++ b/src/Fl_Double_Window.cxx @@ -76,6 +76,28 @@ void Fl_Double_Window::show() { // Code used to switch output to an off-screen window. See macros in // win32.H which save the old state in local variables. +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; + +/* + * This function checks if the version of MSWindows that we + * curently run on supports alpha blending for bitmap transfers + * and finds the required function if so. + */ +char fl_can_do_alpha_blending() { + static char been_here = 0; + static char can_do = 0; + if (been_here) return can_do; + HMODULE hMod = LoadLibrary("MSIMG32.DLL"); + if (!hMod) return 0; + fl_alpha_blend = (fl_alpha_blend_func)GetProcAddress(hMod, "AlphaBlend"); + if (!fl_alpha_blend) return 0; + can_do = 1; + return 1; +} + HDC fl_makeDC(HBITMAP bitmap) { HDC new_gc = CreateCompatibleDC(fl_gc); SetTextAlign(new_gc, TA_BASELINE|TA_LEFT); @@ -88,10 +110,15 @@ HDC fl_makeDC(HBITMAP bitmap) { } void fl_copy_offscreen(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); - BitBlt(fl_gc, x, y, w, h, new_gc, srcx, srcy, SRCCOPY); + if (fl_can_do_alpha_blending()) + fl_alpha_blend(fl_gc, x, y, w, h, new_gc, srcx, srcy, w, h, blendfunc); + else + BitBlt(fl_gc, x, y, w, h, new_gc, srcx, srcy, SRCCOPY); RestoreDC(new_gc, save); DeleteDC(new_gc); } @@ -100,6 +127,10 @@ extern void fl_restore_clip(); #elif defined(__APPLE_QD__) +char fl_can_do_alpha_blending() { + return 0; +} + GWorldPtr fl_create_offscreen(int w, int h) { GWorldPtr gw; Rect bounds; @@ -173,6 +204,10 @@ extern void fl_restore_clip(); #elif defined(__APPLE_QUARTZ__) +char fl_can_do_alpha_blending() { + return 1; +} + Fl_Offscreen fl_create_offscreen(int w, int h) { void *data = calloc(w*h,4); CGColorSpaceRef lut = CGColorSpaceCreateDeviceRGB(); @@ -254,6 +289,13 @@ void fl_end_offscreen() { extern void fl_restore_clip(); +#else // X11 + +// maybe someone feels inclined to implement alpha blending on X11? +char fl_can_do_alpha_blending() { + return 0; +} + #endif // Fl_Overlay_Window relies on flush(1) copying the back buffer to the |
