From 1fc01c7cbb23fe21b1cf07261659badfb1dd3fb9 Mon Sep 17 00:00:00 2001 From: Manolo Gouy Date: Wed, 14 Dec 2016 18:54:12 +0000 Subject: Implement a platform-independent version of Fl_Graphics_Driver::copy_offscreen() usable when drawing to PostScript. git-svn-id: file:///fltk/svn/fltk/branches/branch-1.4@12147 ea41ed52-d2ee-0310-a9c1-e6b18d33e121 --- FL/Fl_Screen_Driver.H | 2 ++ src/Fl_Graphics_Driver.cxx | 18 +++++++++++++++++- src/drivers/Cocoa/Fl_Cocoa_Screen_Driver.H | 2 ++ src/drivers/Cocoa/Fl_Cocoa_Screen_Driver.cxx | 6 ++++++ src/drivers/WinAPI/Fl_WinAPI_Screen_Driver.H | 1 + src/drivers/WinAPI/Fl_WinAPI_Screen_Driver.cxx | 9 +++++++++ src/drivers/X11/Fl_X11_Screen_Driver.H | 2 ++ src/drivers/X11/Fl_X11_Screen_Driver.cxx | 11 +++++++++++ 8 files changed, 50 insertions(+), 1 deletion(-) diff --git a/FL/Fl_Screen_Driver.H b/FL/Fl_Screen_Driver.H index e857930a7..57a8bfee0 100644 --- a/FL/Fl_Screen_Driver.H +++ b/FL/Fl_Screen_Driver.H @@ -140,6 +140,8 @@ public: virtual void open_display() {} // optional method to close display access virtual void close_display() {} + // compute dimensions of an Fl_Offscreen + virtual void offscreen_size(Fl_Offscreen off, int &width, int &height) {} }; diff --git a/src/Fl_Graphics_Driver.cxx b/src/Fl_Graphics_Driver.cxx index ab45bcf6e..0429eac0c 100644 --- a/src/Fl_Graphics_Driver.cxx +++ b/src/Fl_Graphics_Driver.cxx @@ -19,6 +19,7 @@ #include #include "config_lib.h" #include +#include #include #include @@ -74,7 +75,22 @@ int Fl_Graphics_Driver::draw_scaled(Fl_Image *img, int X, int Y, int W, int H) { /** 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) { - // nothing to do, reimplement in driver if needed + // This platform-independent version is used when the current graphics driver is PostScript. + // It requires that pixmap has been created by fl_create_offscreen(). + int px_width = w, px_height = h; + Fl::screen_driver()->offscreen_size(pixmap, px_width, px_height); + int px = srcx, py = srcy, pw = w, ph = h; + if (px < 0) {px = 0; pw += srcx; x -= srcx;} + if (py < 0) {py = 0; ph += srcy; y -= srcy;} + if (px + pw > px_width) {pw = px_width - px;} + if (py + ph > px_height) {ph = px_height - py;} + fl_begin_offscreen(pixmap); + uchar *img = fl_read_image(NULL, px, py, pw, ph, 0); + fl_end_offscreen(); + if (img) { + fl_draw_image(img, x, y, pw, ph, 3, 0); + delete[] img; + } } /** see fl_set_spot() */ diff --git a/src/drivers/Cocoa/Fl_Cocoa_Screen_Driver.H b/src/drivers/Cocoa/Fl_Cocoa_Screen_Driver.H index 29ae7570e..d825e6580 100644 --- a/src/drivers/Cocoa/Fl_Cocoa_Screen_Driver.H +++ b/src/drivers/Cocoa/Fl_Cocoa_Screen_Driver.H @@ -94,6 +94,8 @@ public: virtual void enable_im(); virtual void disable_im(); virtual void open_display(); + // --- compute dimensions of an Fl_Offscreen + virtual void offscreen_size(Fl_Offscreen o, int &width, int &height); }; diff --git a/src/drivers/Cocoa/Fl_Cocoa_Screen_Driver.cxx b/src/drivers/Cocoa/Fl_Cocoa_Screen_Driver.cxx index 71a64292d..8856f8cfe 100644 --- a/src/drivers/Cocoa/Fl_Cocoa_Screen_Driver.cxx +++ b/src/drivers/Cocoa/Fl_Cocoa_Screen_Driver.cxx @@ -400,6 +400,12 @@ int Fl_Cocoa_Screen_Driver::input_widget_handle_key(int key, unsigned mods, unsi return -1; } +void Fl_Cocoa_Screen_Driver::offscreen_size(Fl_Offscreen off, int &width, int &height) +{ + width = CGBitmapContextGetWidth(off); + height = CGBitmapContextGetHeight(off); +} + // // End of "$Id$". // diff --git a/src/drivers/WinAPI/Fl_WinAPI_Screen_Driver.H b/src/drivers/WinAPI/Fl_WinAPI_Screen_Driver.H index 80529138f..5c016ce73 100644 --- a/src/drivers/WinAPI/Fl_WinAPI_Screen_Driver.H +++ b/src/drivers/WinAPI/Fl_WinAPI_Screen_Driver.H @@ -77,6 +77,7 @@ public: virtual void enable_im(); virtual void disable_im(); virtual void open_display(); + virtual void offscreen_size(Fl_Offscreen off, int &width, int &height); }; diff --git a/src/drivers/WinAPI/Fl_WinAPI_Screen_Driver.cxx b/src/drivers/WinAPI/Fl_WinAPI_Screen_Driver.cxx index 6c3e99dca..2b1f65e0a 100644 --- a/src/drivers/WinAPI/Fl_WinAPI_Screen_Driver.cxx +++ b/src/drivers/WinAPI/Fl_WinAPI_Screen_Driver.cxx @@ -638,6 +638,15 @@ float Fl_WinAPI_Screen_Driver::desktop_scaling_factor() { return scaling; } +void Fl_WinAPI_Screen_Driver::offscreen_size(Fl_Offscreen off, int &width, int &height) +{ + BITMAP bitmap; + if ( GetObject(off, sizeof(BITMAP), &bitmap) ) { + width = bitmap.bmWidth; + height = bitmap.bmHeight; + } +} + // // End of "$Id$". // diff --git a/src/drivers/X11/Fl_X11_Screen_Driver.H b/src/drivers/X11/Fl_X11_Screen_Driver.H index 8f3638718..2be26a1ee 100644 --- a/src/drivers/X11/Fl_X11_Screen_Driver.H +++ b/src/drivers/X11/Fl_X11_Screen_Driver.H @@ -87,6 +87,8 @@ public: virtual void disable_im(); virtual void open_display(); virtual void close_display(); + // --- compute dimensions of an Fl_Offscreen + virtual void offscreen_size(Fl_Offscreen o, int &width, int &height); }; diff --git a/src/drivers/X11/Fl_X11_Screen_Driver.cxx b/src/drivers/X11/Fl_X11_Screen_Driver.cxx index d28859949..7095ea948 100644 --- a/src/drivers/X11/Fl_X11_Screen_Driver.cxx +++ b/src/drivers/X11/Fl_X11_Screen_Driver.cxx @@ -1143,6 +1143,17 @@ Fl_RGB_Image *Fl_X11_Screen_Driver::read_win_rectangle(uchar *p, int X, int Y, i return rgb; } + +void Fl_X11_Screen_Driver::offscreen_size(Fl_Offscreen off, int &width, int &height) +{ + int px, py; + unsigned w, h, b, d; + Window root; + XGetGeometry(fl_display, off, &root, &px, &py, &w, &h, &b, &d); + width = (int)w; + height = (int)h; +} + // // End of "$Id$". // -- cgit v1.2.3