1998-10-20 00:46:58 +04:00
|
|
|
//
|
2005-02-05 23:28:31 +03:00
|
|
|
// "$Id$"
|
1998-10-20 00:46:58 +04:00
|
|
|
//
|
|
|
|
// Double-buffered window code for the Fast Light Tool Kit (FLTK).
|
|
|
|
//
|
2012-03-12 13:39:17 +04:00
|
|
|
// Copyright 1998-2012 by Bill Spitzak and others.
|
1998-10-20 00:46:58 +04:00
|
|
|
//
|
2011-07-19 08:49:30 +04:00
|
|
|
// This library is free software. Distribution and use rights are outlined in
|
|
|
|
// the file "COPYING" which should have been included with this file. If this
|
|
|
|
// file is missing or damaged, see the license at:
|
|
|
|
//
|
|
|
|
// http://www.fltk.org/COPYING.php
|
1998-10-20 00:46:58 +04:00
|
|
|
//
|
2005-04-16 04:13:17 +04:00
|
|
|
// Please report all bugs and problems on the following page:
|
|
|
|
//
|
|
|
|
// http://www.fltk.org/str.php
|
1998-10-20 00:46:58 +04:00
|
|
|
//
|
2012-11-13 18:45:42 +04:00
|
|
|
/** \file
|
|
|
|
Fl_Double_Window implementation.
|
|
|
|
*/
|
1998-10-06 23:14:55 +04:00
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
#include <FL/Fl.H>
|
|
|
|
#include <FL/Fl_Double_Window.H>
|
2012-07-24 08:37:22 +04:00
|
|
|
#include <FL/Fl_Overlay_Window.H>
|
2010-05-27 21:20:18 +04:00
|
|
|
#include <FL/Fl_Printer.H>
|
1998-10-06 23:14:55 +04:00
|
|
|
#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;
|
2011-02-06 15:20:16 +03:00
|
|
|
for (int j = 0; j < a->count; j++) {
|
1998-10-06 23:14:55 +04:00
|
|
|
if (a->visinfo[j].visual == fl_visual->visualid
|
2011-02-06 15:20:16 +03:00
|
|
|
/*&& a->visinfo[j].perflevel > 0*/) {
|
|
|
|
use_xdbe = 1; break;
|
|
|
|
}
|
|
|
|
}
|
1998-10-06 23:14:55 +04:00
|
|
|
XdbeFreeVisualInfo(a);
|
|
|
|
}
|
|
|
|
return use_xdbe;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-07-24 08:37:22 +04:00
|
|
|
|
|
|
|
Fl_Double_Window::Fl_Double_Window(int W, int H, const char *l)
|
|
|
|
: Fl_Window(W,H,l),
|
|
|
|
force_doublebuffering_(0)
|
|
|
|
{
|
|
|
|
type(FL_DOUBLE_WINDOW);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Fl_Double_Window::Fl_Double_Window(int X, int Y, int W, int H, const char *l)
|
|
|
|
: Fl_Window(X,Y,W,H,l),
|
|
|
|
force_doublebuffering_(0)
|
|
|
|
{
|
|
|
|
type(FL_DOUBLE_WINDOW);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-10-06 23:14:55 +04:00
|
|
|
void Fl_Double_Window::show() {
|
|
|
|
Fl_Window::show();
|
|
|
|
}
|
|
|
|
|
2010-07-09 21:31:33 +04:00
|
|
|
|
2010-10-12 16:34:19 +04:00
|
|
|
/** \addtogroup fl_drawings
|
|
|
|
@{
|
|
|
|
*/
|
|
|
|
/** Copy a rectangular area of the given offscreen buffer into the current drawing destination.
|
|
|
|
\param x,y position where to draw the copied rectangle
|
|
|
|
\param w,h size of the copied rectangle
|
|
|
|
\param pixmap offscreen buffer containing the rectangle to copy
|
|
|
|
\param srcx,srcy origin in offscreen buffer of rectangle to copy
|
|
|
|
*/
|
2012-11-07 00:46:14 +04:00
|
|
|
#if FLTK_ABI_VERSION >= 10301
|
2012-04-28 04:42:31 +04:00
|
|
|
void fl_copy_offscreen(int x, int y, int w, int h, Fl_Offscreen pixmap, int srcx, int srcy) {
|
2012-03-18 22:48:29 +04:00
|
|
|
fl_graphics_driver->copy_offscreen(x, y, w, h, pixmap, srcx, srcy);
|
|
|
|
}
|
|
|
|
#else
|
2010-07-09 21:31:33 +04:00
|
|
|
void fl_copy_offscreen(int x, int y, int w, int h, Fl_Offscreen pixmap, int srcx, int srcy) {
|
2012-03-18 22:48:29 +04:00
|
|
|
#ifdef WIN32
|
|
|
|
if (fl_graphics_driver->class_name() == Fl_GDI_Graphics_Driver::class_id ||
|
|
|
|
fl_graphics_driver->class_name() == Fl_GDI_Printer_Graphics_Driver::class_id) {
|
|
|
|
#else
|
2012-03-12 13:39:17 +04:00
|
|
|
if (fl_graphics_driver->class_name() == Fl_Display_Device::display_device()->driver()->class_name()) {
|
2012-03-18 22:48:29 +04:00
|
|
|
#endif
|
|
|
|
#ifdef USE_X11
|
|
|
|
((Fl_Xlib_Graphics_Driver*)fl_graphics_driver)->copy_offscreen(x, y, w, h, pixmap, srcx, srcy);
|
|
|
|
#elif defined(WIN32)
|
|
|
|
((Fl_GDI_Graphics_Driver*)fl_graphics_driver)->copy_offscreen(x, y, w, h, pixmap, srcx, srcy);
|
|
|
|
#elif defined(__APPLE__)
|
|
|
|
((Fl_Quartz_Graphics_Driver*)fl_graphics_driver)->copy_offscreen(x, y, w, h, pixmap, srcx, srcy);
|
|
|
|
#endif
|
2010-07-09 21:31:33 +04:00
|
|
|
}
|
|
|
|
else { // when copy is not to the display
|
2012-03-18 22:48:29 +04:00
|
|
|
fl_graphics_driver->copy_offscreen(x, y, w, h, pixmap, srcx, srcy);
|
2010-07-09 21:31:33 +04:00
|
|
|
}
|
|
|
|
}
|
2012-03-18 22:48:29 +04:00
|
|
|
#endif // FLTK_ABI_VERSION
|
2010-10-12 16:34:19 +04:00
|
|
|
/** @} */
|
2010-07-09 21:31:33 +04:00
|
|
|
|
2012-03-18 22:48:29 +04:00
|
|
|
/** see fl_copy_offscreen() */
|
|
|
|
void Fl_Graphics_Driver::copy_offscreen(int x, int y, int w, int h, Fl_Offscreen pixmap, int srcx, int srcy)
|
|
|
|
{
|
|
|
|
fl_begin_offscreen(pixmap);
|
|
|
|
uchar *img = fl_read_image(NULL, srcx, srcy, w, h, 0);
|
|
|
|
fl_end_offscreen();
|
|
|
|
fl_draw_image(img, x, y, w, h, 3, 0);
|
|
|
|
delete[] img;
|
|
|
|
}
|
|
|
|
|
2008-10-14 03:44:22 +04:00
|
|
|
#if defined(USE_X11)
|
2008-10-14 03:10:43 +04:00
|
|
|
|
2012-03-18 22:48:29 +04:00
|
|
|
void Fl_Xlib_Graphics_Driver::copy_offscreen(int x, int y, int w, int h, Fl_Offscreen pixmap, int srcx, int srcy) {
|
2011-02-06 15:20:16 +03:00
|
|
|
XCopyArea(fl_display, pixmap, fl_window, fl_gc, srcx, srcy, w, h, x, y);
|
2010-07-09 21:31:33 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-10-14 03:10:43 +04:00
|
|
|
// maybe someone feels inclined to implement alpha blending on X11?
|
|
|
|
char fl_can_do_alpha_blending() {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#elif defined(WIN32)
|
1998-10-06 23:14:55 +04:00
|
|
|
|
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
|
|
|
|
2006-09-15 19:35:16 +04:00
|
|
|
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;
|
2006-09-17 16:49:19 +04:00
|
|
|
static FL_BLENDFUNCTION blendfunc = { 0, 0, 255, 1};
|
2006-09-15 19:35:16 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 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;
|
2006-09-17 16:49:19 +04:00
|
|
|
// do this test only once
|
2006-09-15 19:35:16 +04:00
|
|
|
if (been_here) return can_do;
|
2006-09-17 16:49:19 +04:00
|
|
|
been_here = 1;
|
|
|
|
// load the library that implements alpha blending
|
2006-09-15 19:35:16 +04:00
|
|
|
HMODULE hMod = LoadLibrary("MSIMG32.DLL");
|
2006-09-17 16:49:19 +04:00
|
|
|
// give up if that doesn't exist (Win95?)
|
2006-09-15 19:35:16 +04:00
|
|
|
if (!hMod) return 0;
|
2006-09-17 16:49:19 +04:00
|
|
|
// now find the blending function inside that dll
|
2006-09-15 19:35:16 +04:00
|
|
|
fl_alpha_blend = (fl_alpha_blend_func)GetProcAddress(hMod, "AlphaBlend");
|
2006-09-17 16:49:19 +04:00
|
|
|
// give up if we can't find it (Win95)
|
2006-09-15 19:35:16 +04:00
|
|
|
if (!fl_alpha_blend) return 0;
|
2010-01-15 17:29:48 +03:00
|
|
|
// we have the call, but does our display support alpha blending?
|
|
|
|
// get the desktop's device context
|
|
|
|
HDC dc = GetDC(0L);
|
2006-09-17 16:49:19 +04:00
|
|
|
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);
|
2007-05-14 19:51:00 +04:00
|
|
|
/*COLORREF set = */ SetPixel(new_gc, 0, 0, 0x01010101);
|
2006-09-17 16:49:19 +04:00
|
|
|
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);
|
2010-01-15 17:29:48 +03:00
|
|
|
ReleaseDC(0L, dc);
|
2006-09-17 16:49:19 +04:00
|
|
|
|
|
|
|
if (alpha_ok) can_do = 1;
|
|
|
|
return can_do;
|
2006-09-15 19:35:16 +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
|
|
|
}
|
|
|
|
|
2012-03-18 22:48:29 +04:00
|
|
|
void Fl_GDI_Graphics_Driver::copy_offscreen(int x,int y,int w,int h,HBITMAP bitmap,int srcx,int srcy) {
|
2006-09-16 20:02:00 +04:00
|
|
|
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);
|
|
|
|
}
|
2006-09-15 19:35:16 +04:00
|
|
|
|
2012-03-12 15:55:50 +04:00
|
|
|
void Fl_GDI_Graphics_Driver::copy_offscreen_with_alpha(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);
|
2005-09-13 03:03:34 +04:00
|
|
|
int save = SaveDC(new_gc);
|
1998-10-15 18:06:16 +04:00
|
|
|
SelectObject(new_gc, bitmap);
|
2006-09-17 16:49:19 +04:00
|
|
|
BOOL alpha_ok = 0;
|
|
|
|
// first try to alpha blend
|
2014-09-23 14:36:58 +04:00
|
|
|
if ( fl_can_do_alpha_blending() ) {
|
2014-02-22 19:04:44 +04:00
|
|
|
alpha_ok = fl_alpha_blend(fl_gc, x, y, w, h, new_gc, srcx, srcy, w, h, blendfunc);
|
2011-02-06 15:20:16 +03:00
|
|
|
}
|
2010-03-30 15:18:45 +04:00
|
|
|
// if that failed (it shouldn't), still copy the bitmap over, but now alpha is 1
|
2010-05-27 21:20:18 +04:00
|
|
|
if (!alpha_ok) {
|
2006-09-15 19:35:16 +04:00
|
|
|
BitBlt(fl_gc, x, y, w, h, new_gc, srcx, srcy, SRCCOPY);
|
2011-02-06 15:20:16 +03:00
|
|
|
}
|
2005-09-13 03:03:34 +04:00
|
|
|
RestoreDC(new_gc, save);
|
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
|
|
|
|
2010-10-12 16:34:19 +04:00
|
|
|
#elif defined(__APPLE_QUARTZ__) || defined(FL_DOXYGEN)
|
2004-08-25 04:20:27 +04:00
|
|
|
|
2006-09-15 19:35:16 +04:00
|
|
|
char fl_can_do_alpha_blending() {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2012-03-18 22:48:29 +04:00
|
|
|
#if ! defined(FL_DOXYGEN)
|
2012-03-12 15:55:50 +04:00
|
|
|
Fl_Offscreen Fl_Quartz_Graphics_Driver::create_offscreen_with_alpha(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(
|
2010-10-12 16:34:19 +04:00
|
|
|
data, w, h, 8, w*4, lut, kCGImageAlphaPremultipliedLast);
|
2004-08-31 04:27:40 +04:00
|
|
|
CGColorSpaceRelease(lut);
|
|
|
|
return (Fl_Offscreen)ctx;
|
2004-08-25 04:20:27 +04:00
|
|
|
}
|
2012-03-18 22:48:29 +04:00
|
|
|
#endif
|
2004-08-25 04:20:27 +04:00
|
|
|
|
2010-10-12 16:34:19 +04:00
|
|
|
/** \addtogroup fl_drawings
|
|
|
|
@{
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
Creation of an offscreen graphics buffer.
|
|
|
|
\param w,h width and height in pixels of the buffer.
|
|
|
|
\return the created graphics buffer.
|
|
|
|
*/
|
|
|
|
Fl_Offscreen fl_create_offscreen(int w, int h) {
|
2004-09-01 02:00:49 +04:00
|
|
|
void *data = calloc(w*h,4);
|
|
|
|
CGColorSpaceRef lut = CGColorSpaceCreateDeviceRGB();
|
|
|
|
CGContextRef ctx = CGBitmapContextCreate(
|
2010-10-12 16:34:19 +04:00
|
|
|
data, w, h, 8, w*4, lut, kCGImageAlphaNoneSkipLast);
|
2004-09-01 02:00:49 +04:00
|
|
|
CGColorSpaceRelease(lut);
|
|
|
|
return (Fl_Offscreen)ctx;
|
|
|
|
}
|
|
|
|
|
2011-02-06 15:20:16 +03:00
|
|
|
static void bmProviderRelease (void *src, const void *data, size_t size) {
|
2010-07-03 14:13:22 +04:00
|
|
|
CFIndex count = CFGetRetainCount(src);
|
|
|
|
CFRelease(src);
|
|
|
|
if(count == 1) free((void*)data);
|
|
|
|
}
|
|
|
|
|
2012-03-18 22:48:29 +04:00
|
|
|
void Fl_Quartz_Graphics_Driver::copy_offscreen(int x,int y,int w,int h,Fl_Offscreen osrc,int srcx,int srcy) {
|
2004-08-31 04:27:40 +04:00
|
|
|
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();
|
2010-07-03 14:13:22 +04:00
|
|
|
// when output goes to a Quartz printercontext, release of the bitmap must be
|
|
|
|
// delayed after the end of the print page
|
|
|
|
CFRetain(src);
|
|
|
|
CGDataProviderRef src_bytes = CGDataProviderCreateWithData( src, data, sw*sh*4, bmProviderRelease);
|
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();
|
2006-06-04 14:21:45 +04:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2010-10-12 16:34:19 +04:00
|
|
|
/** Deletion of an offscreen graphics buffer.
|
|
|
|
\param ctx the buffer to be deleted.
|
|
|
|
*/
|
2004-08-31 04:27:40 +04:00
|
|
|
void fl_delete_offscreen(Fl_Offscreen ctx) {
|
|
|
|
if (!ctx) return;
|
|
|
|
void *data = CGBitmapContextGetData((CGContextRef)ctx);
|
2010-07-03 14:13:22 +04:00
|
|
|
CFIndex count = CFGetRetainCount(ctx);
|
2004-08-31 04:27:40 +04:00
|
|
|
CGContextRelease((CGContextRef)ctx);
|
2010-07-03 14:13:22 +04:00
|
|
|
if(count == 1) free(data);
|
2004-08-31 04:27:40 +04:00
|
|
|
}
|
2004-08-25 04:20:27 +04:00
|
|
|
|
2006-06-06 12:00:56 +04:00
|
|
|
const int stack_max = 16;
|
|
|
|
static int stack_ix = 0;
|
|
|
|
static CGContextRef stack_gc[stack_max];
|
|
|
|
static Window stack_window[stack_max];
|
2010-07-09 21:31:33 +04:00
|
|
|
static Fl_Surface_Device *_ss;
|
2004-08-31 04:27:40 +04:00
|
|
|
|
2010-10-12 16:34:19 +04:00
|
|
|
/** Send all subsequent drawing commands to this offscreen buffer.
|
|
|
|
\param ctx the offscreen buffer.
|
|
|
|
*/
|
2004-08-31 04:27:40 +04:00
|
|
|
void fl_begin_offscreen(Fl_Offscreen ctx) {
|
2011-02-02 15:42:47 +03:00
|
|
|
_ss = Fl_Surface_Device::surface();
|
2011-02-02 14:29:18 +03:00
|
|
|
Fl_Display_Device::display_device()->set_current();
|
2006-06-06 12:00:56 +04:00
|
|
|
if (stack_ix<stack_max) {
|
|
|
|
stack_gc[stack_ix] = fl_gc;
|
|
|
|
stack_window[stack_ix] = fl_window;
|
|
|
|
} else
|
|
|
|
fprintf(stderr, "FLTK CGContext Stack overflow error\n");
|
|
|
|
stack_ix++;
|
|
|
|
|
2004-08-31 04:27:40 +04:00
|
|
|
fl_gc = (CGContextRef)ctx;
|
|
|
|
fl_window = 0;
|
|
|
|
CGContextSaveGState(fl_gc);
|
2010-06-19 19:19:13 +04:00
|
|
|
fl_push_no_clip();
|
2004-08-25 04:20:27 +04:00
|
|
|
}
|
|
|
|
|
2010-10-12 16:34:19 +04:00
|
|
|
/** Quit sending drawing commands to the current offscreen buffer.
|
|
|
|
*/
|
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();
|
2010-06-19 19:19:13 +04:00
|
|
|
fl_pop_clip();
|
2006-06-06 12:00:56 +04:00
|
|
|
if (stack_ix>0)
|
|
|
|
stack_ix--;
|
|
|
|
else
|
|
|
|
fprintf(stderr, "FLTK CGContext Stack underflow error\n");
|
|
|
|
if (stack_ix<stack_max) {
|
|
|
|
fl_gc = stack_gc[stack_ix];
|
|
|
|
fl_window = stack_window[stack_ix];
|
|
|
|
}
|
2010-07-09 21:31:33 +04:00
|
|
|
_ss->set_current();
|
2001-11-27 20:44:08 +03:00
|
|
|
}
|
|
|
|
|
2010-10-12 16:34:19 +04:00
|
|
|
/** @} */
|
|
|
|
|
2001-11-27 20:44:08 +03:00
|
|
|
|
2008-10-14 03:10:43 +04:00
|
|
|
#else
|
|
|
|
# error unsupported platform
|
1998-10-06 23:14:55 +04:00
|
|
|
#endif
|
|
|
|
|
2008-09-21 22:55:58 +04:00
|
|
|
/**
|
|
|
|
Forces the window to be redrawn.
|
|
|
|
*/
|
1998-11-05 19:04:53 +03:00
|
|
|
void Fl_Double_Window::flush() {flush(0);}
|
|
|
|
|
2008-09-21 22:55:58 +04:00
|
|
|
/**
|
|
|
|
Forces the window to be redrawn.
|
|
|
|
\param[in] eraseoverlay non-zero to erase overlay, zero to ignore
|
|
|
|
|
|
|
|
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-11-05 19:04:53 +03:00
|
|
|
void Fl_Double_Window::flush(int eraseoverlay) {
|
2014-02-07 04:09:52 +04:00
|
|
|
if (!shown()) return;
|
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);
|
2011-11-28 16:32:56 +04:00
|
|
|
if (!myi) return; // window not yet created
|
2000-11-20 22:02:20 +03:00
|
|
|
if (!myi->other_xid) {
|
1998-10-06 23:14:55 +04:00
|
|
|
#if USE_XDBE
|
2007-02-08 23:50:01 +03:00
|
|
|
if (can_xdbe()) {
|
2011-02-06 15:20:16 +03:00
|
|
|
myi->other_xid = XdbeAllocateBackBufferName(fl_display, fl_xid(this), XdbeCopied);
|
2007-02-08 23:50:01 +03:00
|
|
|
myi->backbuffer_bad = 1;
|
|
|
|
} else
|
1998-10-06 23:14:55 +04:00
|
|
|
#endif
|
2008-10-14 03:10:43 +04:00
|
|
|
#if defined(USE_X11) || defined(WIN32)
|
|
|
|
myi->other_xid = fl_create_offscreen(w(), h());
|
|
|
|
clear_damage(FL_DAMAGE_ALL);
|
2004-08-25 04:20:27 +04:00
|
|
|
#elif defined(__APPLE_QUARTZ__)
|
2004-12-27 22:16:42 +03:00
|
|
|
if (force_doublebuffering_) {
|
2000-11-20 22:02:20 +03:00
|
|
|
myi->other_xid = fl_create_offscreen(w(), h());
|
2004-12-27 22:16:42 +03:00
|
|
|
clear_damage(FL_DAMAGE_ALL);
|
|
|
|
}
|
2001-12-06 03:17:47 +03:00
|
|
|
#else
|
2008-10-14 03:10:43 +04:00
|
|
|
# error unsupported platform
|
2004-12-27 22:16:42 +03:00
|
|
|
#endif
|
1998-10-06 23:14:55 +04:00
|
|
|
}
|
1998-11-05 19:04:53 +03:00
|
|
|
#if USE_XDBE
|
|
|
|
if (use_xdbe) {
|
2010-06-09 12:36:25 +04:00
|
|
|
if (myi->backbuffer_bad || eraseoverlay) {
|
2007-02-08 23:50:01 +03:00
|
|
|
// Make sure we do a complete redraw...
|
2000-11-20 22:02:20 +03:00
|
|
|
if (myi->region) {XDestroyRegion(myi->region); myi->region = 0;}
|
1998-11-05 19:04:53 +03:00
|
|
|
clear_damage(FL_DAMAGE_ALL);
|
2007-02-08 23:50:01 +03:00
|
|
|
myi->backbuffer_bad = 0;
|
1998-11-05 19:04:53 +03:00
|
|
|
}
|
2007-02-08 23:50:01 +03:00
|
|
|
|
|
|
|
// Redraw as needed...
|
1998-11-05 19:04:53 +03:00
|
|
|
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
|
|
|
}
|
2007-02-08 23:50:01 +03:00
|
|
|
|
|
|
|
// Copy contents of back buffer to window...
|
|
|
|
XdbeSwapInfo s;
|
|
|
|
s.swap_window = fl_xid(this);
|
|
|
|
s.swap_action = XdbeCopied;
|
|
|
|
XdbeSwapBuffers(fl_display, &s, 1);
|
|
|
|
return;
|
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);
|
2005-09-13 03:03:34 +04:00
|
|
|
int save = SaveDC(fl_gc);
|
1998-10-15 18:06:16 +04:00
|
|
|
fl_restore_clip(); // duplicate region into new gc
|
|
|
|
draw();
|
2005-09-13 03:03:34 +04:00
|
|
|
RestoreDC(fl_gc, save);
|
1998-10-15 18:38:16 +04:00
|
|
|
DeleteDC(fl_gc);
|
1998-10-15 18:06:16 +04:00
|
|
|
fl_gc = _sgc;
|
2011-01-06 13:24:58 +03:00
|
|
|
//# if defined(FLTK_USE_CAIRO)
|
2008-09-25 22:26:33 +04:00
|
|
|
//if Fl::cairo_autolink_context() Fl::cairo_make_current(this); // capture gc changes automatically to update the cairo context adequately
|
|
|
|
//# endif
|
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
|
2010-06-09 12:36:25 +04:00
|
|
|
if (use_xdbe) {
|
|
|
|
Fl_X* myi = Fl_X::i(this);
|
|
|
|
if (myi && myi->other_xid && (ow < w() || oh < h())) {
|
|
|
|
// STR #2152: Deallocate the back buffer to force creation of a new one.
|
|
|
|
XdbeDeallocateBackBufferName(fl_display,myi->other_xid);
|
|
|
|
myi->other_xid = 0;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
1998-10-06 23:14:55 +04:00
|
|
|
#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();
|
|
|
|
}
|
|
|
|
|
2008-09-14 02:33:03 +04:00
|
|
|
/**
|
|
|
|
The destructor <I>also deletes all the children</I>. This allows a
|
|
|
|
whole tree to be deleted at once, without having to keep a pointer to
|
|
|
|
all the children in the user code.
|
|
|
|
*/
|
1998-10-06 23:14:55 +04:00
|
|
|
Fl_Double_Window::~Fl_Double_Window() {
|
|
|
|
hide();
|
|
|
|
}
|
1998-10-20 00:46:58 +04:00
|
|
|
|
2012-07-24 08:37:22 +04:00
|
|
|
|
|
|
|
Fl_Overlay_Window::Fl_Overlay_Window(int W, int H, const char *l)
|
|
|
|
: Fl_Double_Window(W,H,l)
|
|
|
|
{
|
|
|
|
overlay_ = 0;
|
|
|
|
force_doublebuffering_=1;
|
|
|
|
image(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Fl_Overlay_Window::Fl_Overlay_Window(int X, int Y, int W, int H, const char *l)
|
|
|
|
: Fl_Double_Window(X,Y,W,H,l)
|
|
|
|
{
|
|
|
|
overlay_ = 0;
|
|
|
|
force_doublebuffering_=1;
|
|
|
|
image(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-10-20 00:46:58 +04:00
|
|
|
//
|
2005-02-05 23:28:31 +03:00
|
|
|
// End of "$Id$".
|
1998-10-20 00:46:58 +04:00
|
|
|
//
|