mirror of https://github.com/fltk/fltk
Driver-based rewrite of the Fl_Copy_Surface class.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3-porting@11374 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
This commit is contained in:
parent
3dcc91d1f0
commit
f936eb1a96
|
@ -48,8 +48,7 @@
|
|||
*/
|
||||
class FL_EXPORT Fl_Copy_Surface : public Fl_Widget_Surface {
|
||||
private:
|
||||
class Helper;
|
||||
Helper *platform_surface;
|
||||
class Fl_Copy_Surface_Driver *platform_surface;
|
||||
protected:
|
||||
void translate(int x, int y);
|
||||
void untranslate();
|
||||
|
@ -66,6 +65,24 @@ public:
|
|||
int printable_rect(int *w, int *h);
|
||||
};
|
||||
|
||||
|
||||
class Fl_Copy_Surface_Driver : public Fl_Widget_Surface {
|
||||
friend class Fl_Copy_Surface;
|
||||
protected:
|
||||
int width;
|
||||
int height;
|
||||
Fl_Copy_Surface_Driver(int w, int h) : Fl_Widget_Surface(NULL), width(w), height(h) {}
|
||||
virtual ~Fl_Copy_Surface_Driver() {}
|
||||
virtual void set_current() {}
|
||||
virtual void translate(int x, int y) {}
|
||||
virtual void untranslate() {}
|
||||
int printable_rect(int *w, int *h) {*w = width; *h = height; return 0;}
|
||||
virtual Fl_RGB_Image *image() {return NULL;}
|
||||
virtual void end_current() {}
|
||||
static Fl_Copy_Surface_Driver *newCopySurfaceDriver(int w, int h);
|
||||
};
|
||||
|
||||
|
||||
#endif // Fl_Copy_Surface_H
|
||||
|
||||
//
|
||||
|
|
|
@ -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);}
|
||||
|
||||
|
|
|
@ -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>
|
||||
|
||||
Fl_Copy_Surface::Helper::Helper(int w, int h) : Fl_Widget_Surface(NULL), width(w), height(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_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
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue