summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Melcher <fltk@matthiasm.com>2006-09-16 16:02:00 +0000
committerMatthias Melcher <fltk@matthiasm.com>2006-09-16 16:02:00 +0000
commitb39938e5cc0ce645dde8b1a686811fe7e3164a50 (patch)
tree5982044416dc7b7245364b6d5357664565745785
parent8238e057272f705784571f51d19bf4019c6d4acd (diff)
OK, I believe I fixed the transparency issues on WIN32. Please everyone, test the code on all machines.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.1@5436 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
-rw-r--r--FL/Enumerations.H4
-rw-r--r--FL/win32.H1
-rw-r--r--src/Fl_Double_Window.cxx11
-rw-r--r--src/Fl_Image.cxx20
-rw-r--r--src/fl_draw_image_win32.cxx31
5 files changed, 59 insertions, 8 deletions
diff --git a/FL/Enumerations.H b/FL/Enumerations.H
index 257af0eb7..0ed610131 100644
--- a/FL/Enumerations.H
+++ b/FL/Enumerations.H
@@ -401,6 +401,10 @@ enum Fl_Mode { // visual types and Fl_Gl_Window::mode() (values match Glut)
FL_FAKE_SINGLE = 512 // Fake single buffered windows using double-buffer
};
+// image alpha blending
+
+#define FL_IMAGE_WITH_ALPHA 0x40000000
+
// damage masks
enum Fl_Damage {
diff --git a/FL/win32.H b/FL/win32.H
index fdab206af..ad1b69369 100644
--- a/FL/win32.H
+++ b/FL/win32.H
@@ -132,6 +132,7 @@ extern FL_EXPORT HDC fl_makeDC(HBITMAP);
fl_pop_clip(); RestoreDC(fl_gc, _savedc); DeleteDC(fl_gc); fl_window=_sw; fl_gc = _sgc
FL_EXPORT void fl_copy_offscreen(int x,int y,int w,int h,HBITMAP pixmap,int srcx,int srcy);
+FL_EXPORT void fl_copy_offscreen_with_alpha(int x,int y,int w,int h,HBITMAP pixmap,int srcx,int srcy);
#define fl_delete_offscreen(bitmap) DeleteObject(bitmap);
// Bitmap masks
diff --git a/src/Fl_Double_Window.cxx b/src/Fl_Double_Window.cxx
index 4f87f0bc3..e648fa4ab 100644
--- a/src/Fl_Double_Window.cxx
+++ b/src/Fl_Double_Window.cxx
@@ -87,7 +87,6 @@ static fl_alpha_blend_func fl_alpha_blend = NULL;
* and finds the required function if so.
*/
char fl_can_do_alpha_blending() {
- return 0;
static char been_here = 0;
static char can_do = 0;
if (been_here) return can_do;
@@ -111,8 +110,16 @@ 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);
+ RestoreDC(new_gc, save);
+ DeleteDC(new_gc);
+}
+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);
diff --git a/src/Fl_Image.cxx b/src/Fl_Image.cxx
index f1247512a..649b1373e 100644
--- a/src/Fl_Image.cxx
+++ b/src/Fl_Image.cxx
@@ -331,7 +331,7 @@ void Fl_RGB_Image::draw(int XP, int YP, int WP, int HP, int cx, int cy) {
// account for current clip region (faster on Irix):
int X,Y,W,H; fl_clip_box(XP,YP,WP,HP,X,Y,W,H);
cx += X-XP; cy += Y-YP;
- // clip the box down to the size of image, quit if empty:
+ // clip the box down to the size of image, quit if empty:
if (cx < 0) {W += cx; X -= cx; cx = 0;}
if (cx+W > w()) W = w()-cx;
if (W <= 0) return;
@@ -347,12 +347,26 @@ void Fl_RGB_Image::draw(int XP, int YP, int WP, int HP, int cx, int cy) {
src, 0L, false, kCGRenderingIntentDefault);
CGColorSpaceRelease(lut);
CGDataProviderRelease(src);
+#elif defined(WIN32)
+ id = fl_create_offscreen(w(), h());
+ if (d() == 2 || d() == 4 && fl_can_do_alpha_blending()) {
+ fl_begin_offscreen((Fl_Offscreen)id);
+ fl_draw_image(array, 0, 0, w(), h(), d()|FL_IMAGE_WITH_ALPHA, ld());
+ fl_end_offscreen();
+ } else {
+ fl_begin_offscreen((Fl_Offscreen)id);
+ fl_draw_image(array, 0, 0, w(), h(), d(), ld());
+ fl_end_offscreen();
+ if (d() == 2 || d() == 4) {
+ mask = fl_create_alphamask(w(), h(), d(), ld(), array);
+ }
+ }
#else
id = fl_create_offscreen(w(), h());
fl_begin_offscreen((Fl_Offscreen)id);
fl_draw_image(array, 0, 0, w(), h(), d(), ld());
fl_end_offscreen();
- if (d() == 2 || d() == 4 && !fl_can_do_alpha_blending()) {
+ if (d() == 2 || d() == 4) {
mask = fl_create_alphamask(w(), h(), d(), ld(), array);
}
#endif
@@ -367,6 +381,8 @@ void Fl_RGB_Image::draw(int XP, int YP, int WP, int HP, int cx, int cy) {
BitBlt(fl_gc, X, Y, W, H, new_gc, cx, cy, SRCPAINT);
RestoreDC(new_gc,save);
DeleteDC(new_gc);
+ } else if (d()==2 || d()==4) {
+ fl_copy_offscreen_with_alpha(X, Y, W, H, (Fl_Offscreen)id, cx, cy);
} else {
fl_copy_offscreen(X, Y, W, H, (Fl_Offscreen)id, cx, cy);
}
diff --git a/src/fl_draw_image_win32.cxx b/src/fl_draw_image_win32.cxx
index f55ca9720..05fc7ee8c 100644
--- a/src/fl_draw_image_win32.cxx
+++ b/src/fl_draw_image_win32.cxx
@@ -259,18 +259,41 @@ static void innards(const uchar *buf, int X, int Y, int W, int H,
static int fl_abs(int v) { return v<0 ? -v : v; }
void fl_draw_image(const uchar* buf, int x, int y, int w, int h, int d, int l){
- innards(buf,x,y,w,h,d,l,fl_abs(d),0,0);
+ if (fl_abs(d)&FL_IMAGE_WITH_ALPHA) {
+ d ^= FL_IMAGE_WITH_ALPHA;
+ innards(buf,x,y,w,h,d,l,fl_abs(d),0,0);
+ } else {
+ innards(buf,x,y,w,h,d,l,(d<3&&d>-3),0,0);
+ }
}
+
void fl_draw_image(Fl_Draw_Image_Cb cb, void* data,
int x, int y, int w, int h,int d) {
- innards(0,x,y,w,h,d,0,fl_abs(d),cb,data);
+ if (fl_abs(d)&FL_IMAGE_WITH_ALPHA) {
+ d ^= FL_IMAGE_WITH_ALPHA;
+ innards(0,x,y,w,h,d,0,(d<3&&d>-3),cb,data);
+ } else {
+ innards(0,x,y,w,h,d,0,(d<3&&d>-3),cb,data);
+ }
}
+
void fl_draw_image_mono(const uchar* buf, int x, int y, int w, int h, int d, int l){
- innards(buf,x,y,w,h,d,l,fl_abs(d),0,0);
+ if (fl_abs(d)&FL_IMAGE_WITH_ALPHA) {
+ d ^= FL_IMAGE_WITH_ALPHA;
+ innards(buf,x,y,w,h,d,l,1,0,0);
+ } else {
+ innards(buf,x,y,w,h,d,l,1,0,0);
+ }
}
+
void fl_draw_image_mono(Fl_Draw_Image_Cb cb, void* data,
int x, int y, int w, int h,int d) {
- innards(0,x,y,w,h,d,0,fl_abs(d),cb,data);
+ if (fl_abs(d)&FL_IMAGE_WITH_ALPHA) {
+ d ^= FL_IMAGE_WITH_ALPHA;
+ innards(0,x,y,w,h,d,0,1,cb,data);
+ } else {
+ innards(0,x,y,w,h,d,0,1,cb,data);
+ }
}
void fl_rectf(int x, int y, int w, int h, uchar r, uchar g, uchar b) {