diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/Fl_Copy_Surface.cxx | 41 | ||||
| -rw-r--r-- | src/drivers/GDI/Fl_GDI_Copy_Surface.cxx | 41 | ||||
| -rw-r--r-- | src/drivers/Quartz/Fl_Quartz_Copy_Surface.cxx | 43 | ||||
| -rw-r--r-- | src/drivers/Xlib/Fl_Xlib_Copy_Surface.cxx | 50 |
4 files changed, 116 insertions, 59 deletions
diff --git a/src/Fl_Copy_Surface.cxx b/src/Fl_Copy_Surface.cxx index 204f1d7f3..7e07928ab 100644 --- a/src/Fl_Copy_Surface.cxx +++ b/src/Fl_Copy_Surface.cxx @@ -16,44 +16,21 @@ // http://www.fltk.org/str.php // -#include "config_lib.h" #include <FL/Fl_Copy_Surface.H> -#ifdef FL_CFG_GFX_QUARTZ -#include <src/drivers/Quartz/Fl_Quartz_Copy_Surface.H> +#if defined(FL_PORTING) +# pragma message "FL_PORTING: implement class Fl_XXX_Copy_Surface_Driver for your platform" -#elif defined(FL_CFG_GFX_GDI) -#include <src/drivers/GDI/Fl_GDI_Copy_Surface.H> - -#elif defined(USE_SDL) -#include <src/drivers/PicoSDL/Fl_PicoSDL_Copy_Surface.H> - -#elif defined(FL_PORTING) || defined(USE_SDL) -# pragma message "FL_PORTING: implement class Fl_Copy_Surface::Helper for your platform" - -class Fl_Copy_Surface::Helper : public Fl_Widget_Surface { // class model - friend class Fl_Copy_Surface; -private: - int width; - int height; - Helper(int w, int h) : Fl_Widget_Surface(NULL), width(w), height(h) {} // to implement - ~Helper() {} // to implement - void set_current(){} // to implement - void translate(int x, int y) {} // to implement - void untranslate() {} // to implement - int w() {return width;} - int h() {return height;} - int printable_rect(int *w, int *h) {*w = width; *h = height; return 0;} -}; - -#elif defined(FL_CFG_GFX_XLIB) -#include <src/drivers/Xlib/Fl_Xlib_Copy_Surface.H> +Fl_Copy_Surface_Driver *Fl_Copy_Surface_Driver::newCopySurfaceDriver(int w, int h) +{ + return NULL; +} #endif /** the constructor */ Fl_Copy_Surface::Fl_Copy_Surface(int w, int h) : Fl_Widget_Surface(NULL) { - platform_surface = new Helper(w, h); + platform_surface = Fl_Copy_Surface_Driver::newCopySurfaceDriver(w, h); driver(platform_surface->driver()); } @@ -69,9 +46,9 @@ void Fl_Copy_Surface::translate(int x, int y) {platform_surface->translate(x, y) void Fl_Copy_Surface::untranslate() {platform_surface->untranslate();} -int Fl_Copy_Surface::w() {return platform_surface->w();} +int Fl_Copy_Surface::w() {return platform_surface->width;} -int Fl_Copy_Surface::h() {return platform_surface->h();} +int Fl_Copy_Surface::h() {return platform_surface->height;} int Fl_Copy_Surface::printable_rect(int *w, int *h) {return platform_surface->printable_rect(w, h);} diff --git a/src/drivers/GDI/Fl_GDI_Copy_Surface.cxx b/src/drivers/GDI/Fl_GDI_Copy_Surface.cxx index aa8e93682..1f6149052 100644 --- a/src/drivers/GDI/Fl_GDI_Copy_Surface.cxx +++ b/src/drivers/GDI/Fl_GDI_Copy_Surface.cxx @@ -18,11 +18,34 @@ #include "../../config_lib.h" - #ifdef FL_CFG_GFX_GDI -#include "Fl_GDI_Copy_Surface.H" +#include <FL/Fl_Copy_Surface.H> +#include "Fl_GDI_Graphics_Driver.H" +#include <windows.h> + +class Fl_GDI_Copy_Surface_Driver : public Fl_Copy_Surface_Driver { + friend class Fl_Copy_Surface_Driver; +protected: + HDC oldgc; + HDC gc; + Fl_GDI_Copy_Surface_Driver(int w, int h); + ~Fl_GDI_Copy_Surface_Driver(); + void set_current(); + void translate(int x, int y); + void untranslate(); + int w() {return width;} + int h() {return height;} + int printable_rect(int *w, int *h) {*w = width; *h = height; return 0;} +}; + + +Fl_Copy_Surface_Driver *Fl_Copy_Surface_Driver::newCopySurfaceDriver(int w, int h) +{ + return new Fl_GDI_Copy_Surface_Driver(w, h); +} -Fl_Copy_Surface::Helper::Helper(int w, int h) : Fl_Widget_Surface(NULL), width(w), height(h) { + +Fl_GDI_Copy_Surface_Driver::Fl_GDI_Copy_Surface_Driver(int w, int h) : Fl_Copy_Surface_Driver(w, h) { driver(new Fl_Translated_GDI_Graphics_Driver); oldgc = (HDC)Fl_Surface_Device::surface()->driver()->gc(); // exact computation of factor from screen units to EnhMetaFile units (0.01 mm) @@ -43,7 +66,8 @@ Fl_Copy_Surface::Helper::Helper(int w, int h) : Fl_Widget_Surface(NULL), width(w } } -Fl_Copy_Surface::Helper::~Helper() { + +Fl_GDI_Copy_Surface_Driver::~Fl_GDI_Copy_Surface_Driver() { if (oldgc == (HDC)Fl_Surface_Device::surface()->driver()->gc()) oldgc = NULL; HENHMETAFILE hmf = CloseEnhMetaFile (gc); if ( hmf != NULL ) { @@ -58,17 +82,20 @@ Fl_Copy_Surface::Helper::~Helper() { Fl_Surface_Device::surface()->driver()->gc(oldgc); } -void Fl_Copy_Surface::Helper::set_current() { + +void Fl_GDI_Copy_Surface_Driver::set_current() { driver()->gc(gc); fl_window = (Window)1; Fl_Surface_Device::set_current(); } -void Fl_Copy_Surface::Helper::translate(int x, int y) { + +void Fl_GDI_Copy_Surface_Driver::translate(int x, int y) { ((Fl_Translated_GDI_Graphics_Driver*)driver())->translate_all(x, y); } -void Fl_Copy_Surface::Helper::untranslate() { + +void Fl_GDI_Copy_Surface_Driver::untranslate() { ((Fl_Translated_GDI_Graphics_Driver*)driver())->untranslate_all(); } #endif // FL_CFG_GFX_GDI diff --git a/src/drivers/Quartz/Fl_Quartz_Copy_Surface.cxx b/src/drivers/Quartz/Fl_Quartz_Copy_Surface.cxx index e138f3c4d..8488d5b8e 100644 --- a/src/drivers/Quartz/Fl_Quartz_Copy_Surface.cxx +++ b/src/drivers/Quartz/Fl_Quartz_Copy_Surface.cxx @@ -19,32 +19,55 @@ #include "../../config_lib.h" #ifdef FL_CFG_GFX_QUARTZ -#include "Fl_Quartz_Copy_Surface.H" +#include <FL/Fl_Copy_Surface.H> #include "Fl_Quartz_Graphics_Driver.H" -Fl_Copy_Surface::Helper::Helper(int w, int h) : Fl_Widget_Surface(NULL), width(w), height(h) { +class Fl_Quartz_Copy_Surface_Driver : public Fl_Copy_Surface_Driver { + friend class Fl_Copy_Surface_Driver; +protected: + CFMutableDataRef pdfdata; + CGContextRef gc; + void prepare_copy_pdf_and_tiff(int w, int h); + void init_PDF_context(int w, int h); + static size_t MyPutBytes(void* info, const void* buffer, size_t count); + Fl_Quartz_Copy_Surface_Driver(int w, int h); + ~Fl_Quartz_Copy_Surface_Driver(); + void set_current(); + void translate(int x, int y); + void untranslate(); + int w() {return width;} + int h() {return height;} + int printable_rect(int *w, int *h) {*w = width; *h = height; return 0;} +}; + +Fl_Copy_Surface_Driver *Fl_Copy_Surface_Driver::newCopySurfaceDriver(int w, int h) +{ + return new Fl_Quartz_Copy_Surface_Driver(w, h); +} + +Fl_Quartz_Copy_Surface_Driver::Fl_Quartz_Copy_Surface_Driver(int w, int h) : Fl_Copy_Surface_Driver(w, h) { driver(new Fl_Quartz_Graphics_Driver); prepare_copy_pdf_and_tiff(w, h); } -Fl_Copy_Surface::Helper::~Helper() { +Fl_Quartz_Copy_Surface_Driver::~Fl_Quartz_Copy_Surface_Driver() { // that code is implemented in Fl_cocoa.mm because it uses some Objective-c Fl_X::complete_copy_pdf_and_tiff(gc, pdfdata); } -void Fl_Copy_Surface::Helper::set_current() { +void Fl_Quartz_Copy_Surface_Driver::set_current() { driver()->gc(gc); fl_window = (Window)1; Fl_Surface_Device::set_current(); } -size_t Fl_Copy_Surface::Helper::MyPutBytes(void* info, const void* buffer, size_t count) +size_t Fl_Quartz_Copy_Surface_Driver::MyPutBytes(void* info, const void* buffer, size_t count) { CFDataAppendBytes ((CFMutableDataRef) info, (const UInt8 *)buffer, count); return count; } -void Fl_Copy_Surface::Helper::init_PDF_context(int w, int h) +void Fl_Quartz_Copy_Surface_Driver::init_PDF_context(int w, int h) { CGRect bounds = CGRectMake(0, 0, w, h ); pdfdata = CFDataCreateMutable(NULL, 0); @@ -56,14 +79,14 @@ void Fl_Copy_Surface::Helper::init_PDF_context(int w, int h) else #endif { - static CGDataConsumerCallbacks callbacks = { Fl_Copy_Surface::Helper::MyPutBytes, NULL }; + static CGDataConsumerCallbacks callbacks = { Fl_Quartz_Copy_Surface_Driver::MyPutBytes, NULL }; myconsumer = CGDataConsumerCreate ((void*) pdfdata, &callbacks); } gc = CGPDFContextCreate (myconsumer, &bounds, NULL); CGDataConsumerRelease (myconsumer); } -void Fl_Copy_Surface::Helper::prepare_copy_pdf_and_tiff(int w, int h) +void Fl_Quartz_Copy_Surface_Driver::prepare_copy_pdf_and_tiff(int w, int h) { init_PDF_context(w, h); if (gc == NULL) return; @@ -74,14 +97,14 @@ void Fl_Copy_Surface::Helper::prepare_copy_pdf_and_tiff(int w, int h) CGContextSaveGState(gc); } -void Fl_Copy_Surface::Helper::translate(int x, int y) { +void Fl_Quartz_Copy_Surface_Driver::translate(int x, int y) { CGContextRestoreGState(gc); CGContextSaveGState(gc); CGContextTranslateCTM(gc, x, y); CGContextSaveGState(gc); } -void Fl_Copy_Surface::Helper::untranslate() { +void Fl_Quartz_Copy_Surface_Driver::untranslate() { CGContextRestoreGState(gc); } diff --git a/src/drivers/Xlib/Fl_Xlib_Copy_Surface.cxx b/src/drivers/Xlib/Fl_Xlib_Copy_Surface.cxx index 796fdf5af..8615fbb8b 100644 --- a/src/drivers/Xlib/Fl_Xlib_Copy_Surface.cxx +++ b/src/drivers/Xlib/Fl_Xlib_Copy_Surface.cxx @@ -19,24 +19,51 @@ #include "../../config_lib.h" #ifdef FL_CFG_GFX_XLIB -#include "Fl_Xlib_Copy_Surface.H" +#include <FL/Fl_Copy_Surface.H> #include <FL/Fl.H> #include <FL/fl_draw.H> +#include "Fl_Translated_Xlib_Graphics_Driver.H" -Fl_Copy_Surface::Helper::Helper(int w, int h) : Fl_Widget_Surface(NULL), width(w), height(h) { +class Fl_Xlib_Copy_Surface_Driver : public Fl_Copy_Surface_Driver { + friend class Fl_Copy_Surface_Driver; +protected: + Fl_Offscreen xid; + Window oldwindow; + Fl_Surface_Device *_ss; + Fl_Xlib_Copy_Surface_Driver(int w, int h); + ~Fl_Xlib_Copy_Surface_Driver(); + void set_current(); + void translate(int x, int y); + void untranslate(); + int w() {return width;} + int h() {return height;} + int printable_rect(int *w, int *h) {*w = width; *h = height; return 0;} +}; + + +Fl_Copy_Surface_Driver *Fl_Copy_Surface_Driver::newCopySurfaceDriver(int w, int h) +{ + return new Fl_Xlib_Copy_Surface_Driver(w, h); +} + + +Fl_Xlib_Copy_Surface_Driver::Fl_Xlib_Copy_Surface_Driver(int w, int h) : Fl_Copy_Surface_Driver(w, h) { driver(new Fl_Translated_Xlib_Graphics_Driver()); Fl::first_window()->make_current(); oldwindow = fl_xid(Fl::first_window()); xid = fl_create_offscreen(w,h); _ss = NULL; Fl_Surface_Device *present_surface = Fl_Surface_Device::surface(); - set_current(); - fl_color(FL_WHITE); - fl_rectf(0, 0, w, h); + Fl_Surface_Device::set_current(); + fl_window = xid; + driver()->color(FL_WHITE); + driver()->rectf(0, 0, w, h); present_surface->set_current(); + fl_window = oldwindow; } -Fl_Copy_Surface::Helper::~Helper() { + +Fl_Xlib_Copy_Surface_Driver::~Fl_Xlib_Copy_Surface_Driver() { fl_pop_clip(); unsigned char *data = fl_read_image(NULL,0,0,width,height,0); fl_window = oldwindow; @@ -46,18 +73,21 @@ Fl_Copy_Surface::Helper::~Helper() { fl_delete_offscreen(xid); } -void Fl_Copy_Surface::Helper::set_current() { - fl_window=xid; + +void Fl_Xlib_Copy_Surface_Driver::set_current() { + fl_window = xid; if (!_ss) _ss = Fl_Surface_Device::surface(); Fl_Surface_Device::set_current(); fl_push_no_clip(); } -void Fl_Copy_Surface::Helper::translate(int x, int y) { + +void Fl_Xlib_Copy_Surface_Driver::translate(int x, int y) { ((Fl_Translated_Xlib_Graphics_Driver*)driver())->translate_all(x, y); } -void Fl_Copy_Surface::Helper::untranslate() { + +void Fl_Xlib_Copy_Surface_Driver::untranslate() { ((Fl_Translated_Xlib_Graphics_Driver*)driver())->untranslate_all(); } |
