summaryrefslogtreecommitdiff
path: root/src/drivers/GDI
diff options
context:
space:
mode:
authorMatthias Melcher <fltk@matthiasm.com>2016-02-09 21:54:38 +0000
committerMatthias Melcher <fltk@matthiasm.com>2016-02-09 21:54:38 +0000
commit94f0278d4771c816f3303efd2e8fa10fc6c41b7a (patch)
treed60ad09f2f45e2d972541fe19a5a7d26bb3a1ddf /src/drivers/GDI
parent7a0fe79f99ea90106b035047cb37148b4f3809fc (diff)
Porting efforts, minimal Android stuff, cleanup.
- Moving code around for Fl_Double_Window, but not yet happy - Tested CMake for Android cross compilation. Very happy! git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3-porting@11142 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
Diffstat (limited to 'src/drivers/GDI')
-rw-r--r--src/drivers/GDI/Fl_GDI_Graphics_Driver.cxx86
-rw-r--r--src/drivers/GDI/Fl_GDI_Graphics_Driver.h1
2 files changed, 87 insertions, 0 deletions
diff --git a/src/drivers/GDI/Fl_GDI_Graphics_Driver.cxx b/src/drivers/GDI/Fl_GDI_Graphics_Driver.cxx
index 6e782b2b5..0eaf23752 100644
--- a/src/drivers/GDI/Fl_GDI_Graphics_Driver.cxx
+++ b/src/drivers/GDI/Fl_GDI_Graphics_Driver.cxx
@@ -36,6 +36,92 @@ Fl_Graphics_Driver *Fl_Graphics_Driver::newMainGraphicsDriver()
return new Fl_GDI_Graphics_Driver();
}
+// 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;
+static FL_BLENDFUNCTION blendfunc = { 0, 0, 255, 1};
+
+/*
+ * 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_GDI_Graphics_Driver::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;
+ // we have the call, but does our display support alpha blending?
+ // get the desktop's device context
+ HDC 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);
+ ReleaseDC(0L, dc);
+
+ if (alpha_ok) can_do = 1;
+ return can_do;
+}
+
+HDC fl_makeDC(HBITMAP bitmap) {
+ HDC new_gc = CreateCompatibleDC(fl_gc);
+ SetTextAlign(new_gc, TA_BASELINE|TA_LEFT);
+ SetBkMode(new_gc, TRANSPARENT);
+#if USE_COLORMAP
+ if (fl_palette) SelectPalette(new_gc, fl_palette, FALSE);
+#endif
+ SelectObject(new_gc, bitmap);
+ return new_gc;
+}
+
+void Fl_GDI_Graphics_Driver::copy_offscreen(int x,int y,int w,int h,HBITMAP bitmap,int srcx,int srcy) {
+ 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);
+ RestoreDC(new_gc, save);
+ DeleteDC(new_gc);
+}
+
+void Fl_GDI_Graphics_Driver::copy_offscreen_with_alpha(int x,int y,int w,int h,HBITMAP bitmap,int srcx,int srcy) {
+ HDC new_gc = CreateCompatibleDC(fl_gc);
+ int save = SaveDC(new_gc);
+ SelectObject(new_gc, bitmap);
+ 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);
+}
//
// End of "$Id$".
diff --git a/src/drivers/GDI/Fl_GDI_Graphics_Driver.h b/src/drivers/GDI/Fl_GDI_Graphics_Driver.h
index 1dd62a4e6..2dbdbe430 100644
--- a/src/drivers/GDI/Fl_GDI_Graphics_Driver.h
+++ b/src/drivers/GDI/Fl_GDI_Graphics_Driver.h
@@ -41,6 +41,7 @@ public:
static const char *class_id;
const char *class_name() {return class_id;};
virtual int has_feature(driver_feature mask) { return mask & NATIVE; }
+ char can_do_alpha_blending();
// --- bitmap stuff
Fl_Bitmask create_bitmask(int w, int h, const uchar *array);