Move Fl_X::set_high_resolution() to classes Fl_Graphics_Driver and Fl_Quartz_Graphics_Driver

git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3-porting@11656 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
This commit is contained in:
Manolo Gouy 2016-04-19 12:46:07 +00:00
parent 366f4bfbc9
commit 034cfc94a3
9 changed files with 22 additions and 27 deletions

View File

@ -81,14 +81,12 @@ public:
There is no need to create any other object of this class. There is no need to create any other object of this class.
*/ */
class FL_EXPORT Fl_Display_Device : public Fl_Surface_Device { class FL_EXPORT Fl_Display_Device : public Fl_Surface_Device {
friend class Fl_X;
friend class Fl_Graphics_Driver; friend class Fl_Graphics_Driver;
static Fl_Display_Device *_display; // the platform display device static Fl_Display_Device *_display; // the platform display device
static bool high_res_window_; //< true when drawing to a window of a retina display (Mac OS X only)
public: public:
Fl_Display_Device(Fl_Graphics_Driver *graphics_driver); Fl_Display_Device(Fl_Graphics_Driver *graphics_driver);
static Fl_Display_Device *display_device(); static Fl_Display_Device *display_device();
static bool high_resolution() {return high_res_window_;} static bool high_resolution();
}; };
/** /**

View File

@ -249,7 +249,8 @@ public:
virtual void add_rectangle_to_region(Fl_Region r, int x, int y, int w, int h); virtual void add_rectangle_to_region(Fl_Region r, int x, int y, int w, int h);
virtual Fl_Region XRectangleRegion(int x, int y, int w, int h); virtual Fl_Region XRectangleRegion(int x, int y, int w, int h);
virtual void XDestroyRegion(Fl_Region r); virtual void XDestroyRegion(Fl_Region r);
// the default implementation may be enough
virtual bool high_resolution() { return false; }
protected: protected:
// --- implementation is in src/fl_vertex.cxx which includes src/cfg_gfx/xxx_rect.cxx // --- implementation is in src/fl_vertex.cxx which includes src/cfg_gfx/xxx_rect.cxx
virtual void global_gc(); virtual void global_gc();

View File

@ -130,7 +130,6 @@ public:
static Fl_X* first; static Fl_X* first;
static Fl_X* i(const Fl_Window* w) {return (Fl_X*)w->i;} static Fl_X* i(const Fl_Window* w) {return (Fl_X*)w->i;}
static void make(Fl_Window*); static void make(Fl_Window*);
static void set_high_resolution(bool);
CGRect* subRect() { return subRect_; } // getter CGRect* subRect() { return subRect_; } // getter
void subRect(CGRect *r) { subRect_ = r; } // setter void subRect(CGRect *r) { subRect_ = r; } // setter
bool mapped_to_retina(); // is window mapped to retina display? bool mapped_to_retina(); // is window mapped to retina display?

View File

@ -48,8 +48,6 @@ TODO:
*/ */
bool Fl_Display_Device::high_res_window_ = false;
/** \brief Make this surface the current drawing surface. /** \brief Make this surface the current drawing surface.
This surface will receive all future graphics requests. */ This surface will receive all future graphics requests. */
@ -80,6 +78,10 @@ Fl_Display_Device *Fl_Display_Device::display_device() {
return display; return display;
}; };
bool Fl_Display_Device::high_resolution()
{
return Fl_Display_Device::display_device()->driver()->high_resolution();
}
Fl_Surface_Device *Fl_Surface_Device::default_surface() Fl_Surface_Device *Fl_Surface_Device::default_surface()
{ {

View File

@ -3251,7 +3251,7 @@ void Fl_Cocoa_Window_Driver::make_current()
q_release_context(); q_release_context();
Fl_X *i = Fl_X::i(pWindow); Fl_X *i = Fl_X::i(pWindow);
fl_window = i->xid; fl_window = i->xid;
Fl_X::set_high_resolution( i->mapped_to_retina() ); ((Fl_Quartz_Graphics_Driver*)Fl_Display_Device::display_device()->driver())->high_resolution( i->mapped_to_retina() );
NSGraphicsContext *nsgc; NSGraphicsContext *nsgc;
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
@ -3294,7 +3294,6 @@ void Fl_Cocoa_Window_Driver::q_release_context(Fl_Cocoa_Window_Driver *x) {
if (!gc) return; if (!gc) return;
CGContextRestoreGState(gc); // match the CGContextSaveGState's of make_current CGContextRestoreGState(gc); // match the CGContextSaveGState's of make_current
CGContextRestoreGState(gc); CGContextRestoreGState(gc);
// Fl_X::set_high_resolution(false);
CGContextFlush(gc); CGContextFlush(gc);
Fl_Display_Device::display_device()->driver()->gc(0); Fl_Display_Device::display_device()->driver()->gc(0);
#if defined(FLTK_USE_CAIRO) #if defined(FLTK_USE_CAIRO)
@ -3302,11 +3301,6 @@ void Fl_Cocoa_Window_Driver::q_release_context(Fl_Cocoa_Window_Driver *x) {
#endif #endif
} }
void Fl_X::set_high_resolution(bool new_val)
{
Fl_Display_Device::high_res_window_ = new_val;
}
Fl_Quartz_Copy_Surface_Driver::~Fl_Quartz_Copy_Surface_Driver() Fl_Quartz_Copy_Surface_Driver::~Fl_Quartz_Copy_Surface_Driver()
{ {
CGContextRestoreGState(gc); CGContextRestoreGState(gc);

View File

@ -39,8 +39,11 @@ protected:
int p_size; int p_size;
typedef struct { float x; float y; } XPOINT; typedef struct { float x; float y; } XPOINT;
XPOINT *p; XPOINT *p;
bool high_resolution_;
public: public:
Fl_Quartz_Graphics_Driver() : Fl_Graphics_Driver(), gc_(NULL), p_size(0), p(NULL) {} Fl_Quartz_Graphics_Driver() : Fl_Graphics_Driver(), gc_(NULL), p_size(0), p(NULL) {
high_resolution_ = false;
}
virtual ~Fl_Quartz_Graphics_Driver() { if (p) free(p); } virtual ~Fl_Quartz_Graphics_Driver() { if (p) free(p); }
virtual int has_feature(driver_feature mask) { return mask & NATIVE; } virtual int has_feature(driver_feature mask) { return mask & NATIVE; }
virtual void gc(void *ctxt) {if (ctxt != gc_) global_gc(); gc_ = (CGContextRef)ctxt; } virtual void gc(void *ctxt) {if (ctxt != gc_) global_gc(); gc_ = (CGContextRef)ctxt; }
@ -67,6 +70,7 @@ public:
void add_rectangle_to_region(Fl_Region r, int x, int y, int w, int h); void add_rectangle_to_region(Fl_Region r, int x, int y, int w, int h);
Fl_Region XRectangleRegion(int x, int y, int w, int h); Fl_Region XRectangleRegion(int x, int y, int w, int h);
void XDestroyRegion(Fl_Region r); void XDestroyRegion(Fl_Region r);
void high_resolution(bool b) { high_resolution_ = b; }
protected: protected:
void transformed_vertex0(float x, float y); void transformed_vertex0(float x, float y);
void fixloop(); void fixloop();
@ -127,7 +131,7 @@ protected:
void text_extents(const char*, int n, int& dx, int& dy, int& w, int& h); void text_extents(const char*, int n, int& dx, int& dy, int& w, int& h);
int height(); int height();
int descent(); int descent();
protected: virtual bool high_resolution() { return high_resolution_; }
virtual void global_gc(); virtual void global_gc();
}; };

View File

@ -293,7 +293,7 @@ void Fl_Quartz_Graphics_Driver::draw_CGImage(CGImageRef cgimg, int x, int y, int
doit = true; doit = true;
} else if (at.a == 0.5) { } else if (at.a == 0.5) {
doit = true; doit = true;
if (Fl_Display_Device::high_resolution()) { // make .tx and .ty have int or half-int values if (high_resolution()) { // make .tx and .ty have int or half-int values
deltax = -(at.tx*2 - round(at.tx*2)); deltax = -(at.tx*2 - round(at.tx*2));
deltay = (at.ty*2 - round(at.ty*2)); deltay = (at.ty*2 - round(at.ty*2));
} else { // make .tx and .ty have integral values } else { // make .tx and .ty have integral values

View File

@ -78,7 +78,7 @@ void Fl_Quartz_Graphics_Driver::xyline(int x, int y, int x1) {
CGContextMoveToPoint(gc_, x, y); CGContextMoveToPoint(gc_, x, y);
CGContextAddLineToPoint(gc_, x1, y); CGContextAddLineToPoint(gc_, x1, y);
CGContextStrokePath(gc_); CGContextStrokePath(gc_);
if (Fl_Display_Device::high_resolution()) { if (high_resolution()) {
/* On retina displays, all xyline() and yxline() functions produce lines that are half-unit /* On retina displays, all xyline() and yxline() functions produce lines that are half-unit
(or one pixel) too short at both ends. This is corrected by filling at both ends rectangles (or one pixel) too short at both ends. This is corrected by filling at both ends rectangles
of size one unit by line-width. of size one unit by line-width.
@ -95,7 +95,7 @@ void Fl_Quartz_Graphics_Driver::xyline(int x, int y, int x1, int y2) {
CGContextAddLineToPoint(gc_, x1, y); CGContextAddLineToPoint(gc_, x1, y);
CGContextAddLineToPoint(gc_, x1, y2); CGContextAddLineToPoint(gc_, x1, y2);
CGContextStrokePath(gc_); CGContextStrokePath(gc_);
if (Fl_Display_Device::high_resolution()) { if (high_resolution()) {
CGContextFillRect(gc_, CGRectMake(x-0.5, y - fl_quartz_line_width_/2, 1 , fl_quartz_line_width_)); CGContextFillRect(gc_, CGRectMake(x-0.5, y - fl_quartz_line_width_/2, 1 , fl_quartz_line_width_));
CGContextFillRect(gc_, CGRectMake(x1 - fl_quartz_line_width_/2, y2-0.5, fl_quartz_line_width_, 1)); CGContextFillRect(gc_, CGRectMake(x1 - fl_quartz_line_width_/2, y2-0.5, fl_quartz_line_width_, 1));
} }
@ -109,7 +109,7 @@ void Fl_Quartz_Graphics_Driver::xyline(int x, int y, int x1, int y2, int x3) {
CGContextAddLineToPoint(gc_, x1, y2); CGContextAddLineToPoint(gc_, x1, y2);
CGContextAddLineToPoint(gc_, x3, y2); CGContextAddLineToPoint(gc_, x3, y2);
CGContextStrokePath(gc_); CGContextStrokePath(gc_);
if (Fl_Display_Device::high_resolution()) { if (high_resolution()) {
CGContextFillRect(gc_, CGRectMake(x-0.5, y - fl_quartz_line_width_/2, 1 , fl_quartz_line_width_)); CGContextFillRect(gc_, CGRectMake(x-0.5, y - fl_quartz_line_width_/2, 1 , fl_quartz_line_width_));
CGContextFillRect(gc_, CGRectMake(x3-0.5, y2 - fl_quartz_line_width_/2, 1 , fl_quartz_line_width_)); CGContextFillRect(gc_, CGRectMake(x3-0.5, y2 - fl_quartz_line_width_/2, 1 , fl_quartz_line_width_));
} }
@ -121,7 +121,7 @@ void Fl_Quartz_Graphics_Driver::yxline(int x, int y, int y1) {
CGContextMoveToPoint(gc_, x, y); CGContextMoveToPoint(gc_, x, y);
CGContextAddLineToPoint(gc_, x, y1); CGContextAddLineToPoint(gc_, x, y1);
CGContextStrokePath(gc_); CGContextStrokePath(gc_);
if (Fl_Display_Device::high_resolution()) { if (high_resolution()) {
CGContextFillRect(gc_, CGRectMake(x - fl_quartz_line_width_/2, y-0.5, fl_quartz_line_width_, 1)); CGContextFillRect(gc_, CGRectMake(x - fl_quartz_line_width_/2, y-0.5, fl_quartz_line_width_, 1));
CGContextFillRect(gc_, CGRectMake(x - fl_quartz_line_width_/2, y1-0.5, fl_quartz_line_width_, 1)); CGContextFillRect(gc_, CGRectMake(x - fl_quartz_line_width_/2, y1-0.5, fl_quartz_line_width_, 1));
} }
@ -134,7 +134,7 @@ void Fl_Quartz_Graphics_Driver::yxline(int x, int y, int y1, int x2) {
CGContextAddLineToPoint(gc_, x, y1); CGContextAddLineToPoint(gc_, x, y1);
CGContextAddLineToPoint(gc_, x2, y1); CGContextAddLineToPoint(gc_, x2, y1);
CGContextStrokePath(gc_); CGContextStrokePath(gc_);
if (Fl_Display_Device::high_resolution()) { if (high_resolution()) {
CGContextFillRect(gc_, CGRectMake(x - fl_quartz_line_width_/2, y-0.5, fl_quartz_line_width_, 1)); CGContextFillRect(gc_, CGRectMake(x - fl_quartz_line_width_/2, y-0.5, fl_quartz_line_width_, 1));
CGContextFillRect(gc_, CGRectMake(x2-0.5, y1 - fl_quartz_line_width_/2, 1 , fl_quartz_line_width_)); CGContextFillRect(gc_, CGRectMake(x2-0.5, y1 - fl_quartz_line_width_/2, 1 , fl_quartz_line_width_));
} }
@ -148,7 +148,7 @@ void Fl_Quartz_Graphics_Driver::yxline(int x, int y, int y1, int x2, int y3) {
CGContextAddLineToPoint(gc_, x2, y1); CGContextAddLineToPoint(gc_, x2, y1);
CGContextAddLineToPoint(gc_, x2, y3); CGContextAddLineToPoint(gc_, x2, y3);
CGContextStrokePath(gc_); CGContextStrokePath(gc_);
if (Fl_Display_Device::high_resolution()) { if (high_resolution()) {
CGContextFillRect(gc_, CGRectMake(x - fl_quartz_line_width_/2, y-0.5, fl_quartz_line_width_, 1)); CGContextFillRect(gc_, CGRectMake(x - fl_quartz_line_width_/2, y-0.5, fl_quartz_line_width_, 1));
CGContextFillRect(gc_, CGRectMake(x2 - fl_quartz_line_width_/2, y3-0.5, fl_quartz_line_width_, 1)); CGContextFillRect(gc_, CGRectMake(x2 - fl_quartz_line_width_/2, y3-0.5, fl_quartz_line_width_, 1));
} }

View File

@ -30,7 +30,6 @@ class Fl_Quartz_Image_Surface_Driver : public Fl_Image_Surface_Driver {
public: public:
Fl_Surface_Device *previous; Fl_Surface_Device *previous;
Window pre_window; Window pre_window;
int was_high;
Fl_Quartz_Image_Surface_Driver(int w, int h, int high_res); Fl_Quartz_Image_Surface_Driver(int w, int h, int high_res);
~Fl_Quartz_Image_Surface_Driver(); ~Fl_Quartz_Image_Surface_Driver();
void set_current(); void set_current();
@ -81,8 +80,7 @@ void Fl_Quartz_Image_Surface_Driver::set_current() {
driver()->gc(offscreen); driver()->gc(offscreen);
fl_window = 0; fl_window = 0;
Fl_Surface_Device::set_current(); Fl_Surface_Device::set_current();
was_high = Fl_Display_Device::high_resolution(); ((Fl_Quartz_Graphics_Driver*)driver())->high_resolution( CGBitmapContextGetWidth(offscreen) > width );
Fl_X::set_high_resolution( CGBitmapContextGetWidth(offscreen) > width );
} }
void Fl_Quartz_Image_Surface_Driver::translate(int x, int y) { void Fl_Quartz_Image_Surface_Driver::translate(int x, int y) {
@ -111,7 +109,6 @@ Fl_RGB_Image* Fl_Quartz_Image_Surface_Driver::image()
void Fl_Quartz_Image_Surface_Driver::end_current() void Fl_Quartz_Image_Surface_Driver::end_current()
{ {
Fl_X::set_high_resolution(was_high);
previous->Fl_Surface_Device::set_current(); previous->Fl_Surface_Device::set_current();
fl_window = pre_window; fl_window = pre_window;
} }