1998-10-20 00:46:58 +04:00
|
|
|
//
|
2004-11-21 18:33:24 +03:00
|
|
|
// "$Id: Fl_Double_Window.cxx,v 1.12.2.4.2.13 2004/11/21 15:33:24 easysw Exp $"
|
1998-10-20 00:46:58 +04:00
|
|
|
//
|
|
|
|
// Double-buffered window code for the Fast Light Tool Kit (FLTK).
|
|
|
|
//
|
2004-04-11 08:39:01 +04:00
|
|
|
// Copyright 1998-2004 by Bill Spitzak and others.
|
1998-10-20 00:46:58 +04:00
|
|
|
//
|
|
|
|
// This library is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU Library General Public
|
|
|
|
// License as published by the Free Software Foundation; either
|
|
|
|
// version 2 of the License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This library is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
// Library General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Library General Public
|
|
|
|
// License along with this library; if not, write to the Free Software
|
|
|
|
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
|
|
|
// USA.
|
|
|
|
//
|
2000-06-06 01:21:24 +04:00
|
|
|
// Please report all bugs and problems to "fltk-bugs@fltk.org".
|
1998-10-20 00:46:58 +04:00
|
|
|
//
|
1998-10-06 23:14:55 +04:00
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
#include <FL/Fl.H>
|
|
|
|
#include <FL/Fl_Double_Window.H>
|
|
|
|
#include <FL/x.H>
|
|
|
|
#include <FL/fl_draw.H>
|
|
|
|
|
1998-10-20 00:46:58 +04:00
|
|
|
// On systems that support double buffering "naturally" the base
|
|
|
|
// Fl_Window class will probably do double-buffer and this subclass
|
|
|
|
// does nothing.
|
|
|
|
|
1998-10-06 23:14:55 +04:00
|
|
|
#if USE_XDBE
|
|
|
|
|
|
|
|
#include <X11/extensions/Xdbe.h>
|
|
|
|
|
|
|
|
static int use_xdbe;
|
|
|
|
|
|
|
|
static int can_xdbe() {
|
|
|
|
static int tried;
|
|
|
|
if (!tried) {
|
|
|
|
tried = 1;
|
|
|
|
int event_base, error_base;
|
|
|
|
if (!XdbeQueryExtension(fl_display, &event_base, &error_base)) return 0;
|
|
|
|
Drawable root = RootWindow(fl_display,fl_screen);
|
|
|
|
int numscreens = 1;
|
|
|
|
XdbeScreenVisualInfo *a = XdbeGetVisualInfo(fl_display,&root,&numscreens);
|
|
|
|
if (!a) return 0;
|
|
|
|
for (int j = 0; j < a->count; j++)
|
|
|
|
if (a->visinfo[j].visual == fl_visual->visualid
|
|
|
|
/*&& a->visinfo[j].perflevel > 0*/) {use_xdbe = 1; break;}
|
|
|
|
XdbeFreeVisualInfo(a);
|
|
|
|
}
|
|
|
|
return use_xdbe;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
void Fl_Double_Window::show() {
|
2001-11-27 20:44:08 +03:00
|
|
|
#if !defined(WIN32) && !defined(__APPLE__)
|
1998-10-06 23:14:55 +04:00
|
|
|
if (!shown()) { // don't set the background pixel
|
|
|
|
fl_open_display();
|
|
|
|
Fl_X::make_xid(this);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
Fl_Window::show();
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef WIN32
|
|
|
|
|
1998-10-15 18:06:16 +04:00
|
|
|
// Code used to switch output to an off-screen window. See macros in
|
|
|
|
// win32.H which save the old state in local variables.
|
1998-10-06 23:14:55 +04:00
|
|
|
|
1998-10-15 18:06:16 +04:00
|
|
|
HDC fl_makeDC(HBITMAP bitmap) {
|
|
|
|
HDC new_gc = CreateCompatibleDC(fl_gc);
|
|
|
|
SetTextAlign(new_gc, TA_BASELINE|TA_LEFT);
|
|
|
|
SetBkMode(new_gc, TRANSPARENT);
|
1998-10-06 23:14:55 +04:00
|
|
|
#if USE_COLORMAP
|
1998-10-15 18:06:16 +04:00
|
|
|
if (fl_palette) SelectPalette(new_gc, fl_palette, FALSE);
|
1998-10-06 23:14:55 +04:00
|
|
|
#endif
|
1998-10-15 18:06:16 +04:00
|
|
|
SelectObject(new_gc, bitmap);
|
|
|
|
return new_gc;
|
1998-10-06 23:14:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void fl_copy_offscreen(int x,int y,int w,int h,HBITMAP bitmap,int srcx,int srcy) {
|
1998-10-15 18:06:16 +04:00
|
|
|
HDC new_gc = CreateCompatibleDC(fl_gc);
|
|
|
|
SelectObject(new_gc, bitmap);
|
|
|
|
BitBlt(fl_gc, x, y, w, h, new_gc, srcx, srcy, SRCCOPY);
|
1998-10-15 18:38:16 +04:00
|
|
|
DeleteDC(new_gc);
|
1998-10-06 23:14:55 +04:00
|
|
|
}
|
|
|
|
|
1998-10-15 18:06:16 +04:00
|
|
|
extern void fl_restore_clip();
|
|
|
|
|
2004-08-25 04:20:27 +04:00
|
|
|
#elif defined(__APPLE_QD__)
|
2001-11-27 20:44:08 +03:00
|
|
|
|
|
|
|
GWorldPtr fl_create_offscreen(int w, int h) {
|
|
|
|
GWorldPtr gw;
|
|
|
|
Rect bounds;
|
|
|
|
bounds.left=0; bounds.right=w; bounds.top=0; bounds.bottom=h;
|
2001-12-06 03:17:47 +03:00
|
|
|
QDErr err = NewGWorld(&gw, 0, &bounds, 0L, 0L, 0); // 'useTempMem' should not be used (says the Carbon port manual)
|
2001-11-27 20:44:08 +03:00
|
|
|
if ( err == -108 )
|
|
|
|
{ }
|
|
|
|
// fl_message( "The application memory is low. Please increase the initial memory assignment.\n" );
|
|
|
|
if (err!=noErr || gw==0L) return 0L;
|
|
|
|
return gw;
|
|
|
|
}
|
|
|
|
|
|
|
|
void fl_copy_offscreen(int x,int y,int w,int h,GWorldPtr gWorld,int srcx,int srcy) {
|
|
|
|
Rect src;
|
2001-12-06 03:17:47 +03:00
|
|
|
if ( !gWorld ) return;
|
2001-11-27 20:44:08 +03:00
|
|
|
src.top = srcy; src.left = srcx; src.bottom = srcy+h; src.right = srcx+w;
|
|
|
|
Rect dst;
|
|
|
|
GrafPtr dstPort; GetPort(&dstPort);
|
|
|
|
dst.top = y; dst.left = x; dst.bottom = y+h; dst.right = x+w;
|
|
|
|
RGBColor rgb;
|
|
|
|
rgb.red = 0xffff; rgb.green = 0xffff; rgb.blue = 0xffff;
|
|
|
|
RGBBackColor( &rgb );
|
|
|
|
rgb.red = 0x0000; rgb.green = 0x0000; rgb.blue = 0x0000;
|
|
|
|
RGBForeColor( &rgb );
|
|
|
|
CopyBits(GetPortBitMapForCopyBits(gWorld), GetPortBitMapForCopyBits(dstPort), &src, &dst, srcCopy, 0L);
|
|
|
|
}
|
|
|
|
|
|
|
|
void fl_delete_offscreen(GWorldPtr gWorld) {
|
|
|
|
DisposeGWorld(gWorld);
|
|
|
|
}
|
|
|
|
|
|
|
|
static GrafPtr prevPort;
|
|
|
|
static GDHandle prevGD;
|
|
|
|
|
|
|
|
void fl_begin_offscreen(GWorldPtr gWorld) {
|
|
|
|
GetGWorld( &prevPort, &prevGD );
|
|
|
|
if ( gWorld )
|
|
|
|
{
|
2001-12-20 08:27:14 +03:00
|
|
|
SetGWorld( gWorld, 0 ); // sets the correct port
|
2001-11-27 20:44:08 +03:00
|
|
|
PixMapHandle pm = GetGWorldPixMap(gWorld);
|
2001-12-20 08:27:14 +03:00
|
|
|
Boolean ret = LockPixels(pm);
|
|
|
|
if ( ret == false )
|
|
|
|
{
|
|
|
|
Rect rect;
|
|
|
|
GetPortBounds( gWorld, &rect );
|
|
|
|
UpdateGWorld( &gWorld, 0, &rect, 0, 0, 0 );
|
|
|
|
pm = GetGWorldPixMap( gWorld );
|
|
|
|
LockPixels( pm );
|
|
|
|
}
|
|
|
|
fl_window = 0;
|
2001-11-27 20:44:08 +03:00
|
|
|
}
|
|
|
|
fl_push_no_clip();
|
|
|
|
}
|
|
|
|
|
2004-08-25 04:20:27 +04:00
|
|
|
void fl_end_offscreen() {
|
|
|
|
GWorldPtr currPort;
|
|
|
|
GDHandle currGD;
|
|
|
|
GetGWorld( &currPort, &currGD );
|
|
|
|
fl_pop_clip();
|
|
|
|
PixMapHandle pm = GetGWorldPixMap(currPort);
|
|
|
|
UnlockPixels(pm);
|
|
|
|
SetGWorld( prevPort, prevGD );
|
|
|
|
fl_window = GetWindowFromPort( prevPort );
|
|
|
|
}
|
|
|
|
|
|
|
|
extern void fl_restore_clip();
|
|
|
|
|
|
|
|
#elif defined(__APPLE_QUARTZ__)
|
|
|
|
|
2004-08-31 04:27:40 +04:00
|
|
|
Fl_Offscreen fl_create_offscreen(int w, int h) {
|
2004-09-01 02:00:49 +04:00
|
|
|
void *data = calloc(w*h,4);
|
2004-08-31 04:27:40 +04:00
|
|
|
CGColorSpaceRef lut = CGColorSpaceCreateDeviceRGB();
|
|
|
|
CGContextRef ctx = CGBitmapContextCreate(
|
|
|
|
data, w, h, 8, w*4, lut, kCGImageAlphaNoneSkipLast);
|
|
|
|
CGColorSpaceRelease(lut);
|
|
|
|
return (Fl_Offscreen)ctx;
|
2004-08-25 04:20:27 +04:00
|
|
|
}
|
|
|
|
|
2004-09-01 02:00:49 +04:00
|
|
|
Fl_Offscreen fl_create_offscreen_with_alpha(int w, int h) {
|
|
|
|
void *data = calloc(w*h,4);
|
|
|
|
CGColorSpaceRef lut = CGColorSpaceCreateDeviceRGB();
|
|
|
|
CGContextRef ctx = CGBitmapContextCreate(
|
|
|
|
data, w, h, 8, w*4, lut, kCGImageAlphaPremultipliedLast);
|
|
|
|
CGColorSpaceRelease(lut);
|
|
|
|
return (Fl_Offscreen)ctx;
|
|
|
|
}
|
|
|
|
|
2004-08-31 04:27:40 +04:00
|
|
|
void fl_copy_offscreen(int x,int y,int w,int h,Fl_Offscreen osrc,int srcx,int srcy) {
|
|
|
|
CGContextRef src = (CGContextRef)osrc;
|
|
|
|
void *data = CGBitmapContextGetData(src);
|
|
|
|
int sw = CGBitmapContextGetWidth(src);
|
|
|
|
int sh = CGBitmapContextGetHeight(src);
|
2004-09-01 02:00:49 +04:00
|
|
|
CGImageAlphaInfo alpha = CGBitmapContextGetAlphaInfo(src);
|
2004-08-31 04:27:40 +04:00
|
|
|
CGColorSpaceRef lut = CGColorSpaceCreateDeviceRGB();
|
|
|
|
CGDataProviderRef src_bytes = CGDataProviderCreateWithData( 0L, data, sw*sh*4, 0L);
|
2004-09-01 02:00:49 +04:00
|
|
|
CGImageRef img = CGImageCreate( sw, sh, 8, 4*8, 4*sw, lut, alpha,
|
2004-08-31 04:27:40 +04:00
|
|
|
src_bytes, 0L, false, kCGRenderingIntentDefault);
|
|
|
|
// fl_push_clip();
|
|
|
|
CGRect rect = { x, y, w, h };
|
2004-09-01 02:00:49 +04:00
|
|
|
Fl_X::q_begin_image(rect, srcx, srcy, sw, sh);
|
2004-08-31 04:27:40 +04:00
|
|
|
CGContextDrawImage(fl_gc, rect, img);
|
|
|
|
Fl_X::q_end_image();
|
|
|
|
CGImageRelease(img);
|
|
|
|
CGColorSpaceRelease(lut);
|
|
|
|
CGDataProviderRelease(src_bytes);
|
2004-08-25 04:20:27 +04:00
|
|
|
}
|
|
|
|
|
2004-08-31 04:27:40 +04:00
|
|
|
void fl_delete_offscreen(Fl_Offscreen ctx) {
|
|
|
|
if (!ctx) return;
|
|
|
|
void *data = CGBitmapContextGetData((CGContextRef)ctx);
|
|
|
|
CGContextRelease((CGContextRef)ctx);
|
|
|
|
if (!data) return;
|
|
|
|
free(data);
|
|
|
|
}
|
2004-08-25 04:20:27 +04:00
|
|
|
|
2004-08-31 04:27:40 +04:00
|
|
|
static CGContextRef prev_gc = 0;
|
|
|
|
static Window prev_window = 0;
|
|
|
|
|
|
|
|
void fl_begin_offscreen(Fl_Offscreen ctx) {
|
|
|
|
prev_gc = fl_gc;
|
|
|
|
prev_window = fl_window;
|
|
|
|
fl_gc = (CGContextRef)ctx;
|
|
|
|
fl_window = 0;
|
|
|
|
//fl_push_no_clip();
|
|
|
|
CGContextSaveGState(fl_gc);
|
|
|
|
Fl_X::q_fill_context();
|
2004-08-25 04:20:27 +04:00
|
|
|
}
|
|
|
|
|
2001-11-27 20:44:08 +03:00
|
|
|
void fl_end_offscreen() {
|
2004-08-31 04:27:40 +04:00
|
|
|
Fl_X::q_release_context();
|
|
|
|
//fl_pop_clip();
|
|
|
|
fl_gc = prev_gc;
|
|
|
|
fl_window = prev_window;
|
2001-11-27 20:44:08 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
extern void fl_restore_clip();
|
|
|
|
|
1998-10-06 23:14:55 +04:00
|
|
|
#endif
|
|
|
|
|
1998-11-05 19:04:53 +03:00
|
|
|
// Fl_Overlay_Window relies on flush(1) copying the back buffer to the
|
|
|
|
// front everywhere, even if damage() == 0, thus erasing the overlay,
|
|
|
|
// and leaving the clip region set to the entire window.
|
1998-10-15 18:06:16 +04:00
|
|
|
|
1998-11-05 19:04:53 +03:00
|
|
|
void Fl_Double_Window::flush() {flush(0);}
|
|
|
|
|
|
|
|
void Fl_Double_Window::flush(int eraseoverlay) {
|
1998-10-06 23:14:55 +04:00
|
|
|
make_current(); // make sure fl_gc is non-zero
|
2000-11-20 22:02:20 +03:00
|
|
|
Fl_X *myi = Fl_X::i(this);
|
|
|
|
if (!myi->other_xid) {
|
1998-10-06 23:14:55 +04:00
|
|
|
#if USE_XDBE
|
2000-11-20 22:02:20 +03:00
|
|
|
if (can_xdbe()) myi->other_xid =
|
1998-11-05 19:04:53 +03:00
|
|
|
XdbeAllocateBackBufferName(fl_display, fl_xid(this), XdbeUndefined);
|
1998-10-06 23:14:55 +04:00
|
|
|
else
|
|
|
|
#endif
|
2004-08-25 04:20:27 +04:00
|
|
|
#ifdef __APPLE_QD__
|
|
|
|
if ( ( !QDIsPortBuffered( GetWindowPort(myi->xid) ) ) || force_doublebuffering_ )
|
|
|
|
myi->other_xid = fl_create_offscreen(w(), h());
|
|
|
|
#elif defined(__APPLE_QUARTZ__)
|
2004-09-01 02:00:49 +04:00
|
|
|
if (force_doublebuffering_)
|
2000-11-20 22:02:20 +03:00
|
|
|
myi->other_xid = fl_create_offscreen(w(), h());
|
2001-12-06 03:17:47 +03:00
|
|
|
#else
|
|
|
|
myi->other_xid = fl_create_offscreen(w(), h());
|
|
|
|
#endif
|
1998-10-19 21:53:09 +04:00
|
|
|
clear_damage(FL_DAMAGE_ALL);
|
1998-10-06 23:14:55 +04:00
|
|
|
}
|
1998-11-05 19:04:53 +03:00
|
|
|
#if USE_XDBE
|
|
|
|
if (use_xdbe) {
|
|
|
|
// if this is true, copy rather than swap so back buffer is preserved:
|
2000-11-20 22:02:20 +03:00
|
|
|
int copy = (myi->region || eraseoverlay);
|
|
|
|
if (myi->backbuffer_bad) { // make sure we do a complete redraw...
|
|
|
|
if (myi->region) {XDestroyRegion(myi->region); myi->region = 0;}
|
1998-11-05 19:04:53 +03:00
|
|
|
clear_damage(FL_DAMAGE_ALL);
|
|
|
|
}
|
|
|
|
if (damage()) {
|
2000-11-20 22:02:20 +03:00
|
|
|
fl_clip_region(myi->region); myi->region = 0;
|
|
|
|
fl_window = myi->other_xid;
|
1998-11-05 19:04:53 +03:00
|
|
|
draw();
|
2000-11-20 22:02:20 +03:00
|
|
|
fl_window = myi->xid;
|
1998-11-05 19:04:53 +03:00
|
|
|
}
|
|
|
|
if (!copy) {
|
|
|
|
XdbeSwapInfo s;
|
|
|
|
s.swap_window = fl_xid(this);
|
|
|
|
s.swap_action = XdbeUndefined;
|
|
|
|
XdbeSwapBuffers(fl_display, &s, 1);
|
2000-11-20 22:02:20 +03:00
|
|
|
myi->backbuffer_bad = 1;
|
1998-11-05 19:04:53 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
// otherwise just use normal copy from back to front:
|
2000-11-20 22:02:20 +03:00
|
|
|
myi->backbuffer_bad = 0; // which won't destroy the back buffer...
|
1998-11-05 19:04:53 +03:00
|
|
|
} else
|
|
|
|
#endif
|
|
|
|
if (damage() & ~FL_DAMAGE_EXPOSE) {
|
2000-11-20 22:02:20 +03:00
|
|
|
fl_clip_region(myi->region); myi->region = 0;
|
1998-10-06 23:14:55 +04:00
|
|
|
#ifdef WIN32
|
1998-10-15 18:06:16 +04:00
|
|
|
HDC _sgc = fl_gc;
|
2000-11-20 22:02:20 +03:00
|
|
|
fl_gc = fl_makeDC(myi->other_xid);
|
1998-10-15 18:06:16 +04:00
|
|
|
fl_restore_clip(); // duplicate region into new gc
|
|
|
|
draw();
|
1998-10-15 18:38:16 +04:00
|
|
|
DeleteDC(fl_gc);
|
1998-10-15 18:06:16 +04:00
|
|
|
fl_gc = _sgc;
|
2004-09-01 02:00:49 +04:00
|
|
|
#elif defined(__APPLE__)
|
2001-12-20 08:27:14 +03:00
|
|
|
if ( myi->other_xid ) {
|
|
|
|
fl_begin_offscreen( myi->other_xid );
|
|
|
|
fl_clip_region( 0 );
|
|
|
|
draw();
|
|
|
|
fl_end_offscreen();
|
|
|
|
} else {
|
|
|
|
draw();
|
|
|
|
}
|
1998-10-15 18:06:16 +04:00
|
|
|
#else // X:
|
2000-11-20 22:02:20 +03:00
|
|
|
fl_window = myi->other_xid;
|
1998-10-15 18:06:16 +04:00
|
|
|
draw();
|
2000-11-20 22:02:20 +03:00
|
|
|
fl_window = myi->xid;
|
1998-10-15 18:06:16 +04:00
|
|
|
#endif
|
1998-11-05 19:04:53 +03:00
|
|
|
}
|
|
|
|
if (eraseoverlay) fl_clip_region(0);
|
1998-10-15 18:06:16 +04:00
|
|
|
// on Irix (at least) it is faster to reduce the area copied to
|
|
|
|
// the current clip region:
|
|
|
|
int X,Y,W,H; fl_clip_box(0,0,w(),h(),X,Y,W,H);
|
2001-12-06 03:17:47 +03:00
|
|
|
if (myi->other_xid) fl_copy_offscreen(X, Y, W, H, myi->other_xid, X, Y);
|
1998-10-06 23:14:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void Fl_Double_Window::resize(int X,int Y,int W,int H) {
|
|
|
|
int ow = w();
|
|
|
|
int oh = h();
|
|
|
|
Fl_Window::resize(X,Y,W,H);
|
|
|
|
#if USE_XDBE
|
|
|
|
if (use_xdbe) return;
|
|
|
|
#endif
|
2000-11-20 22:02:20 +03:00
|
|
|
Fl_X* myi = Fl_X::i(this);
|
|
|
|
if (myi && myi->other_xid && (ow != w() || oh != h())) {
|
|
|
|
fl_delete_offscreen(myi->other_xid);
|
|
|
|
myi->other_xid = 0;
|
1998-10-06 23:14:55 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Fl_Double_Window::hide() {
|
2000-11-20 22:02:20 +03:00
|
|
|
Fl_X* myi = Fl_X::i(this);
|
|
|
|
if (myi && myi->other_xid) {
|
1998-10-06 23:14:55 +04:00
|
|
|
#if USE_XDBE
|
|
|
|
if (!use_xdbe)
|
|
|
|
#endif
|
2000-11-20 22:02:20 +03:00
|
|
|
fl_delete_offscreen(myi->other_xid);
|
1998-10-06 23:14:55 +04:00
|
|
|
}
|
|
|
|
Fl_Window::hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
Fl_Double_Window::~Fl_Double_Window() {
|
|
|
|
hide();
|
|
|
|
}
|
1998-10-20 00:46:58 +04:00
|
|
|
|
|
|
|
//
|
2004-11-21 18:33:24 +03:00
|
|
|
// End of "$Id: Fl_Double_Window.cxx,v 1.12.2.4.2.13 2004/11/21 15:33:24 easysw Exp $".
|
1998-10-20 00:46:58 +04:00
|
|
|
//
|