mod/maxgui.mod/fltkmaxgui.mod/src/fl_rect.cxx
int Fl_Graphics_Driver::clip_box(int x, int y, int w, int h, int& X, int& Y, int& W, int& H){
  X = x; Y = y; W = w; H = h;
  Fl_Region r = rstack[rstackptr];
  if (!r) return 0;
#if defined(USE_X11)
  switch (XRectInRegion(r, x, y, w, h)) {
  case 0: // completely outside
    W = H = 0;
    return 2;
  case 1: // completely inside:
    return 0;
  default: // partial:
    break;
  }
  Fl_Region rr = XRectangleRegion(x,y,w,h);
  Fl_Region temp = XCreateRegion();
  XIntersectRegion(r, rr, temp);
  XRectangle rect;
  XClipBox(temp, &rect);
  X = rect.x; Y = rect.y; W = rect.width; H = rect.height;
  XDestroyRegion(temp);
  XDestroyRegion(rr);
  return 1;
#elif defined(WIN32)
// The win32 API makes no distinction between partial and complete
// intersection, so we have to check for partial intersection ourselves.
// However, given that the regions may be composite, we have to do
// some voodoo stuff...
  Fl_Region rr = XRectangleRegion(x,y,w,h);
  Fl_Region temp = CreateRectRgn(0,0,0,0);
  int ret;
  if (CombineRgn(temp, rr, r, RGN_AND) == NULLREGION) { // disjoint
    W = H = 0;
    ret = 2;
  } else if (EqualRgn(temp, rr)) { // complete
    ret = 0;
  } else {	// partial intersection
    RECT rect;
    GetRgnBox(temp, &rect);
    if(Fl_Surface_Device::surface()->type() == Fl_Printer::device_type) { // if print context, convert coords from device to logical
      POINT pt[2] = { {rect.left, rect.top}, {rect.right, rect.bottom} };
      DPtoLP(fl_gc, pt, 2);
      X = pt[0].x; Y = pt[0].y; W = pt[1].x - X; H = pt[1].y - Y;
    }
    else {
      X = rect.left; Y = rect.top; W = rect.right - X; H = rect.bottom - Y;
      }
    ret = 1;
  }
  DeleteObject(temp);
  DeleteObject(rr);
  return ret;
#elif defined(__APPLE_QUARTZ__)
  CGRect arg = fl_cgrectmake_cocoa(x, y, w, h);
  CGRect u = CGRectMake(0,0,0,0);
  CGRect test;
  for(int i = 0; i < r->count; i++) {
    test = CGRectIntersection(r->rects[i], arg);
    if( ! CGRectIsEmpty(test) ) {
      if(CGRectIsEmpty(u)) u = test;
      else u = CGRectUnion(u, test);
    }
  }
  X = int(u.origin.x);
  Y = int(u.origin.y);
  W = int(u.size.width + 1);
  H = int(u.size.height + 1);
  if(CGRectIsEmpty(u)) W = H = 0;
  return ! CGRectEqualToRect(arg, u);
#else
# error unsupported platform
#endif
}
// return rectangle surrounding intersection of this rectangle and clip:
return rectangle surrounding intersection of this rectangle and clip.
return rectangle surrounding intersection of this rectangle and clip .
int Fl_Graphics_Driver::clip_box(int x, int y, int w, int h, int& X, int& Y, int& W, int& H){
  X = x; Y = y; W = w; H = h;
  Fl_Region r = rstack[rstackptr];
  if (!r) return 0;
#if defined(USE_X11)
  switch (XRectInRegion(r, x, y, w, h)) {
  case 0: 
    W = H = 0;
    return 2;
  case 1: 
    return 0;
  default: 
    break;
  }
  Fl_Region rr = XRectangleRegion(x,y,w,h);
  Fl_Region temp = XCreateRegion();
  XIntersectRegion(r, rr, temp);
  XRectangle rect;
  XClipBox(temp, &rect);
  X = rect.x; Y = rect.y; W = rect.width; H = rect.height;
  XDestroyRegion(temp);
  XDestroyRegion(rr);
  return 1;
#elif defined(WIN32)
  Fl_Region rr = XRectangleRegion(x,y,w,h);
  Fl_Region temp = CreateRectRgn(0,0,0,0);
  int ret;
  if (CombineRgn(temp, rr, r, RGN_AND) == NULLREGION) { 
    W = H = 0;
    ret = 2;
  } else if (EqualRgn(temp, rr)) { 
    ret = 0;
  } else {	
    RECT rect;
    GetRgnBox(temp, &rect);
    if(Fl_Surface_Device::surface()->type() == Fl_Printer::device_type) { 
      POINT pt[2] = { {rect.left, rect.top}, {rect.right, rect.bottom} };
      DPtoLP(fl_gc, pt, 2);
      X = pt[0].x; Y = pt[0].y; W = pt[1].x - X; H = pt[1].y - Y;
    }
    else {
      X = rect.left; Y = rect.top; W = rect.right - X; H = rect.bottom - Y;
      }
    ret = 1;
  }
  DeleteObject(temp);
  DeleteObject(rr);
  return ret;
#elif defined(__APPLE_QUARTZ__)
  CGRect arg = fl_cgrectmake_cocoa(x, y, w, h);
  CGRect u = CGRectMake(0,0,0,0);
  CGRect test;
  for(int i = 0; i < r->count; i++) {
    test = CGRectIntersection(r->rects[i], arg);
    if( ! CGRectIsEmpty(test) ) {
      if(CGRectIsEmpty(u)) u = test;
      else u = CGRectUnion(u, test);
    }
  }
  X = int(u.origin.x);
  Y = int(u.origin.y);
  W = int(u.size.width + 1);
  H = int(u.size.height + 1);
  if(CGRectIsEmpty(u)) W = H = 0;
  return ! CGRectEqualToRect(arg, u);
#else
# error unsupported platform
#endif
}
int Fl_Graphics_Driver :: clip_box ( int x , int y , int w , int h , int & X , int & Y , int & W , int & H ) { X = x ; Y = y ; W = w ; H = h ; Fl_Region r = rstack [ rstackptr ] ; if ( ! r ) return 0 ; #if defined ( USE_X11 ) switch ( XRectInRegion ( r , x , y , w , h ) ) { case 0 : W = H = 0 ; return 2 ; case 1 : return 0 ; default : break ; } Fl_Region rr = XRectangleRegion ( x , y , w , h ) ; Fl_Region temp = XCreateRegion ( ) ; XIntersectRegion ( r , rr , temp ) ; XRectangle rect ; XClipBox ( temp , & rect ) ; X = rect . x ; Y = rect . y ; W = rect . width ; H = rect . height ; XDestroyRegion ( temp ) ; XDestroyRegion ( rr ) ; return 1 ; #elif defined ( WIN32 ) Fl_Region rr = XRectangleRegion ( x , y , w , h ) ; Fl_Region temp = CreateRectRgn ( 0 , 0 , 0 , 0 ) ; int ret ; if ( CombineRgn ( temp , rr , r , RGN_AND ) == NULLREGION ) { W = H = 0 ; ret = 2 ; } else if ( EqualRgn ( temp , rr ) ) { ret = 0 ; } else { RECT rect ; GetRgnBox ( temp , & rect ) ; if ( Fl_Surface_Device :: surface ( ) -> type ( ) == Fl_Printer :: device_type ) { POINT pt [ 2 ] = { { rect . left , rect . top } , { rect . right , rect . bottom } } ; DPtoLP ( fl_gc , pt , 2 ) ; X = pt [ 0 ] . x ; Y = pt [ 0 ] . y ; W = pt [ 1 ] . x - X ; H = pt [ 1 ] . y - Y ; } else { X = rect . left ; Y = rect . top ; W = rect . right - X ; H = rect . bottom - Y ; } ret = 1 ; } DeleteObject ( temp ) ; DeleteObject ( rr ) ; return ret ; #elif defined ( __APPLE_QUARTZ__ ) CGRect arg = fl_cgrectmake_cocoa ( x , y , w , h ) ; CGRect u = CGRectMake ( 0 , 0 , 0 , 0 ) ; CGRect test ; for ( int i = 0 ; i < r -> count ; i ++ ) { test = CGRectIntersection ( r -> rects [ i ] , arg ) ; if ( ! CGRectIsEmpty ( test ) ) { if ( CGRectIsEmpty ( u ) ) u = test ; else u = CGRectUnion ( u , test ) ; } } X = int ( u . origin . x ) ; Y = int ( u . origin . y ) ; W = int ( u . size . width + 1 ) ; H = int ( u . size . height + 1 ) ; if ( CGRectIsEmpty ( u ) ) W = H = 0 ; return ! CGRectEqualToRect ( arg , u ) ; #else # error  unsupported platform #endif }
return rectangle surrounding intersection of this rectangle and clip:
return rectangle surrounding intersection of this rectangle and clip :
// completely outside // completely inside: // partial: // The win32 API makes no distinction between partial and complete // intersection, so we have to check for partial intersection ourselves. // However, given that the regions may be composite, we have to do // some voodoo stuff... // disjoint // complete // partial intersection // if print context, convert coords from device to logical