summaryrefslogtreecommitdiff
path: root/src/drivers/Quartz
diff options
context:
space:
mode:
Diffstat (limited to 'src/drivers/Quartz')
-rw-r--r--src/drivers/Quartz/Fl_Quartz_Image_Surface.cxx67
1 files changed, 41 insertions, 26 deletions
diff --git a/src/drivers/Quartz/Fl_Quartz_Image_Surface.cxx b/src/drivers/Quartz/Fl_Quartz_Image_Surface.cxx
index c2b6eb534..0914eda90 100644
--- a/src/drivers/Quartz/Fl_Quartz_Image_Surface.cxx
+++ b/src/drivers/Quartz/Fl_Quartz_Image_Surface.cxx
@@ -16,19 +16,37 @@
// http://www.fltk.org/str.php
//
-#include <FL/fl_draw.H>
-
#include "../../config_lib.h"
-
#ifdef FL_CFG_GFX_QUARTZ
+#include <FL/fl_draw.H>
+#include <FL/Fl_Image_Surface.H>
#include "Fl_Quartz_Graphics_Driver.H"
-#include "Fl_Quartz_Image_Surface.H"
-
#include <ApplicationServices/ApplicationServices.h>
+class Fl_Quartz_Image_Surface_Driver : public Fl_Image_Surface_Driver {
+ friend class Fl_Image_Surface;
+public:
+ Fl_Surface_Device *previous;
+ Window pre_window;
+ int was_high;
+ Fl_Quartz_Image_Surface_Driver(int w, int h, int high_res);
+ ~Fl_Quartz_Image_Surface_Driver();
+ void set_current();
+ void translate(int x, int y);
+ void untranslate();
+ Fl_RGB_Image *image();
+ void end_current();
+};
+
+
+Fl_Image_Surface_Driver *Fl_Image_Surface_Driver::newImageSurfaceDriver(int w, int h, int high_res, Fl_Offscreen)
+{
+ return new Fl_Quartz_Image_Surface_Driver(w, h, high_res);
+}
-Fl_Image_Surface::Helper::Helper(int w, int h, int high_res) : Fl_Widget_Surface(NULL), width(w), height(h) {
+
+Fl_Quartz_Image_Surface_Driver::Fl_Quartz_Image_Surface_Driver(int w, int h, int high_res) : Fl_Image_Surface_Driver(w, h, high_res, 0) {
previous = 0;
int W = high_res ? 2*w : w;
int H = high_res ? 2*h : h;
@@ -48,15 +66,15 @@ Fl_Image_Surface::Helper::Helper(int w, int h, int high_res) : Fl_Widget_Surface
CGContextFillRect(offscreen, CGRectMake(0,0,w,h));
}
-Fl_Image_Surface::Helper::~Helper() {
+Fl_Quartz_Image_Surface_Driver::~Fl_Quartz_Image_Surface_Driver() {
if (offscreen) {
- void *data = CGBitmapContextGetData((CGContextRef)offscreen);
+ void *data = CGBitmapContextGetData(offscreen);
free(data);
CGContextRelease((CGContextRef)offscreen);
}
}
-void Fl_Image_Surface::Helper::set_current() {
+void Fl_Quartz_Image_Surface_Driver::set_current() {
pre_window = fl_window;
if (!previous) previous = Fl_Surface_Device::surface();
driver()->gc(offscreen);
@@ -66,34 +84,31 @@ void Fl_Image_Surface::Helper::set_current() {
Fl_X::set_high_resolution( CGBitmapContextGetWidth(offscreen) > width );
}
-void Fl_Image_Surface::Helper::translate(int x, int y) {
- CGContextRef gc = (CGContextRef)driver()->gc();
- CGContextRestoreGState(gc);
- CGContextSaveGState(gc);
- CGContextTranslateCTM(gc, x, -y);
- CGContextSaveGState(gc);
- CGContextTranslateCTM(gc, 0, height);
- CGContextScaleCTM(gc, 1.0f, -1.0f);
+void Fl_Quartz_Image_Surface_Driver::translate(int x, int y) {
+ CGContextRestoreGState(offscreen);
+ CGContextSaveGState(offscreen);
+ CGContextTranslateCTM(offscreen, x, -y);
+ CGContextSaveGState(offscreen);
+ CGContextTranslateCTM(offscreen, 0, height);
+ CGContextScaleCTM(offscreen, 1.0f, -1.0f);
}
-void Fl_Image_Surface::Helper::untranslate() {
- CGContextRestoreGState((CGContextRef)driver()->gc());
+void Fl_Quartz_Image_Surface_Driver::untranslate() {
+ CGContextRestoreGState(offscreen);
}
-Fl_RGB_Image* Fl_Image_Surface::Helper::image()
+Fl_RGB_Image* Fl_Quartz_Image_Surface_Driver::image()
{
- unsigned char *data;
- int W = width, H = height;
CGContextFlush(offscreen);
- W = CGBitmapContextGetWidth(offscreen);
- H = CGBitmapContextGetHeight(offscreen);
- data = fl_read_image(NULL, 0, 0, W, H, 0);
+ int W = CGBitmapContextGetWidth(offscreen);
+ int H = CGBitmapContextGetHeight(offscreen);
+ unsigned char *data = fl_read_image(NULL, 0, 0, W, H, 0);
Fl_RGB_Image *image = new Fl_RGB_Image(data, W, H);
image->alloc_array = 1;
return image;
}
-void Fl_Image_Surface::Helper::end_current()
+void Fl_Quartz_Image_Surface_Driver::end_current()
{
Fl_X::set_high_resolution(was_high);
previous->Fl_Surface_Device::set_current();