Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

83 lines
2.2 KiB

  1. /*==========================================================================
  2. *
  3. * Copyright (C) 1995 Microsoft Corporation. All Rights Reserved.
  4. *
  5. * File: cliprgn.c
  6. * Content: Clip a region to a rectangle
  7. *
  8. * History:
  9. * Date By Reason
  10. * ==== == ======
  11. * 23-jun-95 craige initial implementation
  12. * 05-jul-95 kylej change ClipRgnToRect to assume that the clipping
  13. * rect is in screen space coordinates instead of
  14. * window coordinates.
  15. * 05-feb-97 ketand Remove the previous optimization that assumed that
  16. * GetVisRgn was smaller than or equal to the ClientRect
  17. * Replace with a different faster optimization.
  18. *
  19. ***************************************************************************/
  20. #include "ddrawpr.h"
  21. /*
  22. * ClipRgnToRect
  23. */
  24. void ClipRgnToRect( LPRECT prect, LPRGNDATA prd )
  25. {
  26. RECT rect;
  27. int i;
  28. int n;
  29. LPRECTL prectlD;
  30. LPRECTL prectlS;
  31. if( prect == NULL || prd == NULL )
  32. {
  33. return;
  34. }
  35. // If the bounding rect of the region is exactly equal to
  36. // or inside of the Restricting rect then we know
  37. // we don't have to do any more work.
  38. //
  39. // In the common case, the rcBound will be the client
  40. // area of a window and so will the restricting rect.
  41. if( prect->top <= prd->rdh.rcBound.top &&
  42. prect->bottom >= prd->rdh.rcBound.bottom &&
  43. prect->left <= prd->rdh.rcBound.left &&
  44. prect->right >= prd->rdh.rcBound.right)
  45. {
  46. return;
  47. }
  48. // If the bounding rect doesn't equal the prect then
  49. // we might have to do some clipping.
  50. rect = *prect;
  51. prectlD = (LPRECTL) prd->Buffer;
  52. prectlS = (LPRECTL) prd->Buffer;
  53. n = (int)prd->rdh.nCount;
  54. for( i=0; i<n; i++ )
  55. {
  56. prectlD->left = max(prectlS->left, rect.left);
  57. prectlD->right = min(prectlS->right, rect.right);
  58. prectlD->top = max(prectlS->top, rect.top);
  59. prectlD->bottom= min(prectlS->bottom, rect.bottom);
  60. prectlS++;
  61. if( (prectlD->bottom - prectlD->top <= 0) ||
  62. (prectlD->right - prectlD->left <= 0) )
  63. {
  64. prd->rdh.nCount--; // dont count empty rect.
  65. }
  66. else
  67. {
  68. prectlD++;
  69. }
  70. }
  71. return;
  72. } /* ClipRgnToRect */