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
This commit is contained in:
Matthias Melcher 2006-09-16 16:02:00 +00:00
parent 8238e05727
commit b39938e5cc
5 changed files with 59 additions and 8 deletions

View File

@ -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 {

View File

@ -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

View File

@ -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);

View File

@ -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);
}

View File

@ -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) {