From 7b37960d9520861bb53fdfcaa310bb509d346368 Mon Sep 17 00:00:00 2001 From: Manolo Gouy Date: Sat, 2 Apr 2016 06:42:34 +0000 Subject: Move intersect_region_and_rect() to the Quartz driver code where it belongs. git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3-porting@11500 ea41ed52-d2ee-0310-a9c1-e6b18d33e121 --- .../Quartz/Fl_Quartz_Graphics_Driver_rect.cxx | 27 +++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) (limited to 'src/drivers') diff --git a/src/drivers/Quartz/Fl_Quartz_Graphics_Driver_rect.cxx b/src/drivers/Quartz/Fl_Quartz_Graphics_Driver_rect.cxx index 41c4c5cdd..be31149f9 100644 --- a/src/drivers/Quartz/Fl_Quartz_Graphics_Driver_rect.cxx +++ b/src/drivers/Quartz/Fl_Quartz_Graphics_Driver_rect.cxx @@ -199,6 +199,31 @@ void Fl_Quartz_Graphics_Driver::polygon(int x, int y, int x1, int y1, int x2, in // --- clipping +// intersects current and x,y,w,h rectangle and returns result as a new Fl_Region +static Fl_Region intersect_region_and_rect(Fl_Region current, int x,int y,int w, int h) +{ + if (current == NULL) return Fl_Graphics_Driver::XRectangleRegion(x,y,w,h); + CGRect r = Fl_Quartz_Graphics_Driver::fl_cgrectmake_cocoa(x, y, w, h); + Fl_Region outr = (Fl_Region)malloc(sizeof(*outr)); + outr->count = current->count; + outr->rects =(CGRect*)malloc(outr->count * sizeof(CGRect)); + int j = 0; + for(int i = 0; i < current->count; i++) { + CGRect test = CGRectIntersection(current->rects[i], r); + if (!CGRectIsEmpty(test)) outr->rects[j++] = test; + } + if (j) { + outr->count = j; + outr->rects = (CGRect*)realloc(outr->rects, outr->count * sizeof(CGRect)); + } + else { + Fl_Graphics_Driver::XDestroyRegion(outr); + outr = Fl_Graphics_Driver::XRectangleRegion(0,0,0,0); + } + return outr; +} + + void Fl_Quartz_Graphics_Driver::push_clip(int x, int y, int w, int h) { Fl_Region r; if (w > 0 && h > 0) { @@ -206,7 +231,7 @@ void Fl_Quartz_Graphics_Driver::push_clip(int x, int y, int w, int h) { Fl_Region current = rstack[rstackptr]; if (current) { XDestroyRegion(r); - r = Fl_X::intersect_region_and_rect(current, x,y,w,h); + r = intersect_region_and_rect(current, x,y,w,h); } } else { // make empty clip region: r = XRectangleRegion(0,0,0,0); -- cgit v1.2.3