Author: manolo
Date: 2010-07-09 10:31:33 -0700 (Fri, 09 Jul 2010)
New Revision: 7671
Log:
Fixed fl_XXX_offscreen functions when the current output goes to a printer or a 
PostScript device

Modified:
   branches/branch-1.3/FL/win32.H
   branches/branch-1.3/FL/x.H
   branches/branch-1.3/src/Fl_Double_Window.cxx

Modified: branches/branch-1.3/FL/win32.H
===================================================================
--- branches/branch-1.3/FL/win32.H      2010-07-09 17:29:35 UTC (rev 7670)
+++ branches/branch-1.3/FL/win32.H      2010-07-09 17:31:33 UTC (rev 7671)
@@ -121,16 +121,19 @@
 
 // off-screen pixmaps: create, destroy, draw into, copy to window
 typedef HBITMAP Fl_Offscreen;
-#define fl_create_offscreen(w, h) CreateCompatibleBitmap(fl_gc, w, h)
+#define fl_create_offscreen(w, h) \
+  CreateCompatibleBitmap( (fl_gc ? fl_gc : fl_GetDC(0) ) , w, h)
 
 extern FL_EXPORT HDC fl_makeDC(HBITMAP);
 
 # define fl_begin_offscreen(b) \
    HDC _sgc=fl_gc; Window _sw=fl_window; \
+   Fl_Surface_Device *_ss = fl_surface; fl_display_device->set_current(); \
    fl_gc=fl_makeDC(b); int _savedc = SaveDC(fl_gc); fl_window=(HWND)b; 
fl_push_no_clip()
 
 # define fl_end_offscreen() \
-   fl_pop_clip(); RestoreDC(fl_gc, _savedc); DeleteDC(fl_gc); fl_window=_sw; 
fl_gc = _sgc
+   fl_pop_clip(); RestoreDC(fl_gc, _savedc); DeleteDC(fl_gc); 
_ss->set_current(); 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);

Modified: branches/branch-1.3/FL/x.H
===================================================================
--- branches/branch-1.3/FL/x.H  2010-07-09 17:29:35 UTC (rev 7670)
+++ branches/branch-1.3/FL/x.H  2010-07-09 17:31:33 UTC (rev 7671)
@@ -110,16 +110,20 @@
 
 // off-screen pixmaps: create, destroy, draw into, copy to window:
 typedef ulong Fl_Offscreen;
-#define fl_create_offscreen(w,h) \
-  XCreatePixmap(fl_display, fl_window, w, h, fl_visual->depth)
+#   define fl_create_offscreen(w,h) \
+  XCreatePixmap(fl_display, \
+             (fl_surface->type() == Fl_Display_Device::device_type ? \
+             fl_window : fl_xid(Fl::first_window()) ) , \
+             w, h, fl_visual->depth)
 // begin/end are macros that save the old state in local variables:
 #    define fl_begin_offscreen(pixmap) \
-  Window _sw=fl_window; fl_window=pixmap; fl_push_no_clip()
+  Window _sw=fl_window; fl_window=pixmap; \
+  Fl_Surface_Device *_ss = fl_surface; fl_display_device->set_current(); \
+  fl_push_no_clip()
 #    define fl_end_offscreen() \
-  fl_pop_clip(); fl_window = _sw
+  fl_pop_clip(); fl_window = _sw; _ss->set_current()
 
-#    define fl_copy_offscreen(x,y,w,h,pixmap,srcx,srcy) \
-  XCopyArea(fl_display, pixmap, fl_window, fl_gc, srcx, srcy, w, h, x, y)
+extern void fl_copy_offscreen(int x, int y, int w, int h, Fl_Offscreen pixmap, 
int srcx, int srcy);
 #    define fl_delete_offscreen(pixmap) XFreePixmap(fl_display, pixmap)
 
 // Bitmap masks

Modified: branches/branch-1.3/src/Fl_Double_Window.cxx
===================================================================
--- branches/branch-1.3/src/Fl_Double_Window.cxx        2010-07-09 17:29:35 UTC 
(rev 7670)
+++ branches/branch-1.3/src/Fl_Double_Window.cxx        2010-07-09 17:31:33 UTC 
(rev 7671)
@@ -65,8 +65,28 @@
   Fl_Window::show();
 }
 
+static void fl_copy_offscreen_to_display(int x, int y, int w, int h, 
Fl_Offscreen pixmap, int srcx, int srcy);
+
+void fl_copy_offscreen(int x, int y, int w, int h, Fl_Offscreen pixmap, int 
srcx, int srcy) {
+  if( fl_graphics_driver == fl_display_device->driver()) {
+    fl_copy_offscreen_to_display(x, y, w, h, pixmap, srcx, srcy);
+  }
+  else { // when copy is not to the display
+    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;
+  }
+}
+
 #if defined(USE_X11)
 
+static void fl_copy_offscreen_to_display(int x, int y, int w, int h, 
Fl_Offscreen pixmap, int srcx, int srcy) {
+    XCopyArea(fl_display, pixmap, fl_window, fl_gc, srcx, srcy, w, h, x, y);
+}
+
+
 // maybe someone feels inclined to implement alpha blending on X11?
 char fl_can_do_alpha_blending() {
   return 0;
@@ -134,7 +154,7 @@
   return new_gc;
 }
 
-void fl_copy_offscreen(int x,int y,int w,int h,HBITMAP bitmap,int srcx,int 
srcy) {
+static void fl_copy_offscreen_to_display(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);
@@ -195,7 +215,7 @@
   if(count == 1) free((void*)data);
 }
 
-void fl_copy_offscreen(int x,int y,int w,int h,Fl_Offscreen osrc,int srcx,int 
srcy) {
+static void fl_copy_offscreen_to_display(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);
@@ -230,8 +250,11 @@
 static int stack_ix = 0;
 static CGContextRef stack_gc[stack_max];
 static Window stack_window[stack_max];
+static Fl_Surface_Device *_ss;
 
 void fl_begin_offscreen(Fl_Offscreen ctx) {
+  _ss = fl_surface; 
+  fl_display_device->set_current();
   if (stack_ix<stack_max) {
     stack_gc[stack_ix] = fl_gc;
     stack_window[stack_ix] = fl_window;
@@ -256,6 +279,7 @@
     fl_gc = stack_gc[stack_ix];
     fl_window = stack_window[stack_ix];
   }
+  _ss->set_current();
 }
 
 extern void fl_restore_clip();

_______________________________________________
fltk-commit mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk-commit

Reply via email to