defined macro FL_CGRECTMAKE_COCOA that

contains the correct way to transform x,y,w,h into
a CGRect adequate for clipping

git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@7035 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
This commit is contained in:
Manolo Gouy 2010-01-29 21:16:20 +00:00
parent 7f518b9287
commit 4645ed9703
4 changed files with 15 additions and 17 deletions

View File

@ -54,7 +54,7 @@
#ifndef MAC_OS_X_VERSION_MAX_ALLOWED #ifndef MAC_OS_X_VERSION_MAX_ALLOWED
#define MAC_OS_X_VERSION_MAX_ALLOWED MAC_OS_X_VERSION_10_3 #define MAC_OS_X_VERSION_MAX_ALLOWED MAC_OS_X_VERSION_10_3
#endif #endif
#endif //__APPLE_COCOA__ #endif // __APPLE_COCOA__
#ifndef CGFLOAT_DEFINED //appears with 10.5 in CGBase.h #ifndef CGFLOAT_DEFINED //appears with 10.5 in CGBase.h
#if defined(__LP64__) && __LP64__ #if defined(__LP64__) && __LP64__
@ -62,7 +62,7 @@ typedef double CGFloat;
#else #else
typedef float CGFloat; typedef float CGFloat;
#endif #endif
#endif //CGFLOAT_DEFINED #endif // CGFLOAT_DEFINED
// Now make some fixes to the headers... // Now make some fixes to the headers...
@ -73,9 +73,11 @@ struct XPoint { int x, y; };
struct XRectangle {int x, y, width, height;}; struct XRectangle {int x, y, width, height;};
#ifdef __APPLE_COCOA__ #ifdef __APPLE_COCOA__
// necessary so a CGRect matches exactly what is denoted x,y,w,h for clipping purposes
#define FL_CGRECTMAKE_COCOA(x,y,w,h) CGRectMake(x, y, w > 0 ? w - 0.9 : 0, h > 0 ? h - 0.9 : 0)
typedef void *Window; //this is really a pter to the subclass FLWindow of NSWindow typedef void *Window; // this is really a pter to the subclass FLWindow of NSWindow
typedef struct flCocoaRegion{ typedef struct flCocoaRegion {
int count; int count;
CGRect *rects; CGRect *rects;
} *Fl_Region; // a region is the union of a series of rectangles } *Fl_Region; // a region is the union of a series of rectangles
@ -83,7 +85,7 @@ inline Fl_Region XRectangleRegion(int x, int y, int w, int h) {
Fl_Region R = (Fl_Region)malloc(sizeof(*R)); Fl_Region R = (Fl_Region)malloc(sizeof(*R));
R->count = 1; R->count = 1;
R->rects = (CGRect *)malloc(sizeof(CGRect)); R->rects = (CGRect *)malloc(sizeof(CGRect));
*(R->rects) = CGRectMake(x, y, w > 0 ? w - 0.9 : 0, h > 0 ? h - 0.9 : 0); *(R->rects) = FL_CGRECTMAKE_COCOA(x, y, w, h);
return R; return R;
} }
inline void XDestroyRegion(Fl_Region r) { inline void XDestroyRegion(Fl_Region r) {
@ -145,10 +147,6 @@ public:
void flush(); void flush();
// Quartz additions: // Quartz additions:
CGContextRef gc; // graphics context (NULL when using QD) CGContextRef gc; // graphics context (NULL when using QD)
#ifndef __APPLE_COCOA__
static ATSUTextLayout atsu_layout; // windows share a global font
static ATSUStyle atsu_style;
#endif
static void q_fill_context(); // fill a Quartz context with current FLTK state static void q_fill_context(); // fill a Quartz context with current FLTK state
static void q_clear_clipping(); // remove all clipping from a Quartz context static void q_clear_clipping(); // remove all clipping from a Quartz context
static void q_release_context(Fl_X *x=0); // free all resources associated with fl_gc static void q_release_context(Fl_X *x=0); // free all resources associated with fl_gc

View File

@ -1474,8 +1474,8 @@ void Fl_Widget::damage(uchar fl, int X, int Y, int W, int H) {
XDestroyRegion(R); XDestroyRegion(R);
#elif defined(__APPLE_QUARTZ__) #elif defined(__APPLE_QUARTZ__)
#ifdef __APPLE_COCOA__ #ifdef __APPLE_COCOA__
CGRect arg = CGRectMake(X, Y, W - 0.9, H - 0.9); CGRect arg = FL_CGRECTMAKE_COCOA(X, Y, W, H);
int j;//don't add a rectangle totally inside the Fl_Region int j; // don't add a rectangle totally inside the Fl_Region
for(j = 0; j < i->region->count; j++) { for(j = 0; j < i->region->count; j++) {
if(CGRectContainsRect(i->region->rects[j], arg)) break; if(CGRectContainsRect(i->region->rects[j], arg)) break;
} }

View File

@ -99,7 +99,7 @@ extern CGContextRef CreateNoneImage(void);
// converting cr lf converter function // converting cr lf converter function
static void convert_crlf(char * string, size_t len); static void convert_crlf(char * string, size_t len);
static void createAppleMenu(void); static void createAppleMenu(void);
Fl_Region MacRegionMinusRect(Fl_Region r, int x,int y,int w,int h); static Fl_Region MacRegionMinusRect(Fl_Region r, int x,int y,int w,int h);
static void cocoaMouseHandler(NSEvent *theEvent); static void cocoaMouseHandler(NSEvent *theEvent);
// public variables // public variables
@ -2620,14 +2620,14 @@ void MacUnmapWindow(Fl_Window *w, void *p) {
MacUnlinkWindow(Fl_X::i(w)); MacUnlinkWindow(Fl_X::i(w));
} }
Fl_Region MacRegionMinusRect(Fl_Region r, int x,int y,int w,int h) static Fl_Region MacRegionMinusRect(Fl_Region r, int x,int y,int w,int h)
/* removes x,y,w,h rectangle from region r and returns result as a new Fl_Region /* removes x,y,w,h rectangle from region r and returns result as a new Fl_Region
*/ */
{ {
Fl_Region outr = (Fl_Region)malloc(sizeof(*outr)); Fl_Region outr = (Fl_Region)malloc(sizeof(*outr));
outr->rects = (CGRect*)malloc(4 * r->count * sizeof(CGRect)); outr->rects = (CGRect*)malloc(4 * r->count * sizeof(CGRect));
outr->count = 0; outr->count = 0;
CGRect rect = CGRectMake(x,y,w - 0.9,h - 0.9); CGRect rect = FL_CGRECTMAKE_COCOA(x, y, w, h);
for( int i = 0; i < r->count; i++) { for( int i = 0; i < r->count; i++) {
CGRect A = r->rects[i]; CGRect A = r->rects[i];
CGRect test = CGRectIntersection(A, rect); CGRect test = CGRectIntersection(A, rect);
@ -2672,7 +2672,7 @@ Fl_Region MacRectRegionIntersect(Fl_Region current, int x,int y,int w, int h)
*/ */
{ {
if (current == NULL) return XRectangleRegion(x,y,w,h); if (current == NULL) return XRectangleRegion(x,y,w,h);
CGRect r = CGRectMake(x, y, w - 0.9, h - 0.9); CGRect r = FL_CGRECTMAKE_COCOA(x, y, w, h);
Fl_Region outr = (Fl_Region)malloc(sizeof(*outr)); Fl_Region outr = (Fl_Region)malloc(sizeof(*outr));
outr->count = current->count; outr->count = current->count;
outr->rects =(CGRect*)malloc(outr->count * sizeof(CGRect)); outr->rects =(CGRect*)malloc(outr->count * sizeof(CGRect));

View File

@ -747,7 +747,7 @@ int fl_not_clipped(int x, int y, int w, int h) {
#elif defined(__APPLE_QUARTZ__) #elif defined(__APPLE_QUARTZ__)
if (!r) return 1; if (!r) return 1;
#ifdef __APPLE_COCOA__ #ifdef __APPLE_COCOA__
CGRect arg = CGRectMake(x, y, w - 0.9, h - 0.9); CGRect arg = FL_CGRECTMAKE_COCOA(x, y, w, h);
for(int i = 0; i < r->count; i++) { for(int i = 0; i < r->count; i++) {
CGRect test = CGRectIntersection(r->rects[i], arg); CGRect test = CGRectIntersection(r->rects[i], arg);
if( ! CGRectIsEmpty(test)) return 1; if( ! CGRectIsEmpty(test)) return 1;
@ -825,7 +825,7 @@ int fl_clip_box(int x, int y, int w, int h, int& X, int& Y, int& W, int& H){
return ret; return ret;
#elif defined(__APPLE_QUARTZ__) #elif defined(__APPLE_QUARTZ__)
#ifdef __APPLE_COCOA__ #ifdef __APPLE_COCOA__
CGRect arg = CGRectMake(x, y, w - 0.9, h - 0.9); CGRect arg = FL_CGRECTMAKE_COCOA(x, y, w, h);
CGRect u = CGRectMake(0,0,0,0); CGRect u = CGRectMake(0,0,0,0);
CGRect test; CGRect test;
for(int i = 0; i < r->count; i++) { for(int i = 0; i < r->count; i++) {