Source code of Windows XP (NT5)
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.

143 lines
5.1 KiB

  1. //-------------------------------------------------------------------------//
  2. // BmpRgn.h - Bitmap-to-Region transforms
  3. //
  4. // History:
  5. // 01/31/2000 scotthan created
  6. //-------------------------------------------------------------------------//
  7. #ifndef __RGN_H__
  8. #define __RGN_H__
  9. //-----------------------------------------------------------------------
  10. typedef struct _MARGINS
  11. {
  12. int cxLeftWidth; // width of left border that retains its size
  13. int cxRightWidth; // width of right border that retains its size
  14. int cyTopHeight; // height of top border that retains its size
  15. int cyBottomHeight; // height of bottom border that retains its size
  16. } MARGINS, *PMARGINS;
  17. //---------------------------------------------------------------------------
  18. enum GRIDNUM
  19. {
  20. GN_LEFTTOP = 0,
  21. GN_MIDDLETOP = 1,
  22. GN_RIGHTTOP = 2,
  23. GN_LEFTMIDDLE = 3,
  24. GN_MIDDLEMIDDLE = 4,
  25. GN_RIGHTMIDDLE = 5,
  26. GN_LEFTBOTTOM = 6,
  27. GN_MIDDLEBOTTOM = 7,
  28. GN_RIGHTBOTTOM = 8
  29. };
  30. #define REVERSE3(c) ((RED(c) << 16) | (GREEN(c) << 8) | BLUE(c))
  31. #define RED(c) GetRValue(c)
  32. #define GREEN(c) GetGValue(c)
  33. #define BLUE(c) GetBValue(c)
  34. #define ALPHACHANNEL(c) BYTE((c) >> 24)
  35. #define DIBDATA(infohdr) (((BYTE *)(infohdr)) + infohdr->biSize + \
  36. infohdr->biClrUsed*sizeof(RGBQUAD))
  37. //------------------------------------------------------------------------------------
  38. class CBitmapPixels
  39. {
  40. public:
  41. CBitmapPixels();
  42. ~CBitmapPixels();
  43. //---- "OpenBitmap()" returns a ptr to pixel values in bitmap. ----
  44. //---- Rows go from bottom to top; Colums go from left to right. ----
  45. //---- IMPORTANT: pixel DWORDS have RGB bytes reversed from COLORREF ----
  46. HRESULT OpenBitmap(HDC hdc, HBITMAP bitmap, BOOL fForceRGB32,
  47. DWORD OUT **pPixels, OPTIONAL OUT int *piWidth=NULL, OPTIONAL OUT int *piHeight=NULL,
  48. OPTIONAL OUT int *piBytesPerPixel=NULL, OPTIONAL OUT int *piBytesPerRow=NULL);
  49. void CloseBitmap(HDC hdc, HBITMAP hBitmap);
  50. //---- public data ----
  51. BITMAPINFOHEADER *_hdrBitmap;
  52. protected:
  53. //---- private data ----
  54. int _iWidth;
  55. int _iHeight;
  56. };
  57. //-------------------------------------------------------------------------//
  58. // CreateBitmapRgn
  59. //
  60. // Creates a region based on an arbitrary bitmap, transparency-keyed on a
  61. // RGB value within a specified tolerance. The key value is optional (-1 ==
  62. // use the value of the first pixel as the key).
  63. //
  64. EXTERN_C HRESULT WINAPI CreateBitmapRgn(
  65. HBITMAP hbm, int cxOffset, int cyOffset,
  66. int cx, int cy, BOOL fAlphaChannel, int iAlphaThreshold, COLORREF rgbMask,
  67. int nMaskTolerance, OUT HRGN *phrgn);
  68. //-------------------------------------------------------------------------//
  69. // CreateScaledBitmapRgn
  70. //
  71. // Behaves in the same manner as CreateBitmapRgn,
  72. // except builds a region based on a +scaled+ arbitrary bitmap.
  73. EXTERN_C HRGN WINAPI CreateScaledBitmapRgn(
  74. HBITMAP hbm, int cx, int cy, COLORREF rgbMask, int nMaskTolerance );
  75. //-------------------------------------------------------------------------//
  76. // CreateTextRgn
  77. //
  78. // Creates a region based on a text string in the indicated font.
  79. //
  80. EXTERN_C HRGN WINAPI CreateTextRgn( HFONT hf, LPCTSTR pszText );
  81. //-------------------------------------------------------------------------//
  82. // AddToCompositeRgn
  83. //
  84. // Wraps CombineRgn by managing composite creation and positioning
  85. // the source region (which is permanently offset). Returns one of:
  86. // NULLREGION, SIMPLEREGION, COMPLEXREGION, ERROR.
  87. //
  88. EXTERN_C int WINAPI AddToCompositeRgn(
  89. HRGN* phrgnComposite, HRGN hrgnSrc, int cxOffset, int cyOffset );
  90. //-------------------------------------------------------------------------//
  91. // RemoveFromCompositeRgn
  92. //
  93. // Wraps CombineRgn by managing removal of rectangular region from
  94. // an existing destination region. Returns one of:
  95. // NULLREGION, SIMPLEREGION, COMPLEXREGION, ERROR.
  96. //
  97. EXTERN_C int WINAPI RemoveFromCompositeRgn( HRGN hrgnDest, LPCRECT prcRemove );
  98. //-------------------------------------------------------------------------//
  99. // CreateTiledRectRgn
  100. //
  101. // Returns a rectangular region composed of region tiles.
  102. //
  103. EXTERN_C HRGN WINAPI CreateTiledRectRgn(
  104. HRGN hrgnTile, int cxTile, int cyTile, int cxBound, int cyBound );
  105. //-------------------------------------------------------------------------//
  106. // Region utilities:
  107. //
  108. EXTERN_C HRGN WINAPI _DupRgn( HRGN hrgnSrc );
  109. //-------------------------------------------------------------------------//
  110. // hit-testing
  111. EXTERN_C WORD WINAPI _HitTestRgn( HRGN hrgn, POINT pt, WORD wSegmentHTCode,
  112. BOOL fHasCaption, UINT cxMargin, UINT cyMargin );
  113. EXTERN_C WORD WINAPI _DefaultHitCodeFromSegCode( BOOL fHasCaption, WORD wSegHTcode );
  114. //-------------------------------------------------------------------------//
  115. // Stretch/Tile rects from original region and create a new one
  116. EXTERN_C HRESULT WINAPI _ScaleRectsAndCreateRegion(RGNDATA *pCustomRgnData,
  117. const RECT *pBoundRect, MARGINS *pMargins, HRGN *pHrgn);
  118. //-------------------------------------------------------------------------//
  119. #ifdef _DEBUG
  120. void RegionDebug(HRGN hrgn);
  121. #endif
  122. #endif __RGN_H__