ddutil.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. //-----------------------------------------------------------------------------
  2. // File: ddutil.cpp
  3. //
  4. // Desc: Routines for loading bitmap and palettes from resources
  5. //
  6. // Copyright (C) 1998-2001 Microsoft Corporation. All Rights Reserved.
  7. //-----------------------------------------------------------------------------
  8. #ifndef DDUTIL_H
  9. #define DDUTIL_H
  10. #include <ddraw.h>
  11. #include <d3d.h>
  12. #include "apak.h"
  13. //-----------------------------------------------------------------------------
  14. // Classes defined in this header file
  15. //-----------------------------------------------------------------------------
  16. class CDisplay;
  17. class CSurface;
  18. //-----------------------------------------------------------------------------
  19. // Flags for the CDisplay and CSurface methods
  20. //-----------------------------------------------------------------------------
  21. #define DSURFACELOCK_READ
  22. #define DSURFACELOCK_WRITE
  23. //-----------------------------------------------------------------------------
  24. // Name: class CDisplay
  25. // Desc: Class to handle all DDraw aspects of a display, including creation of
  26. // front and back buffers, creating offscreen surfaces and palettes,
  27. // and blitting surface and displaying bitmaps.
  28. //-----------------------------------------------------------------------------
  29. class CDisplay
  30. {
  31. protected:
  32. LPDIRECTDRAW7 m_pDD;
  33. LPDIRECTDRAWSURFACE7 m_pddsFrontBuffer;
  34. LPDIRECTDRAWSURFACE7 m_pddsBackBuffer;
  35. LPDIRECTDRAWSURFACE7 m_pddsBackBufferLeft; // For stereo modes
  36. HWND m_hWnd;
  37. RECT m_rcWindow;
  38. BOOL m_bWindowed;
  39. BOOL m_bStereo;
  40. int i_CursorX[2];
  41. int i_CursorY[2];
  42. int i_ActBuffer;
  43. public:
  44. CDisplay();
  45. ~CDisplay();
  46. // Access functions
  47. HWND GetHWnd()
  48. {
  49. return m_hWnd;
  50. }
  51. LPDIRECTDRAW7 GetDirectDraw()
  52. {
  53. return m_pDD;
  54. }
  55. LPDIRECTDRAWSURFACE7 GetFrontBuffer()
  56. {
  57. return m_pddsFrontBuffer;
  58. }
  59. LPDIRECTDRAWSURFACE7 GetBackBuffer()
  60. {
  61. return m_pddsBackBuffer;
  62. }
  63. LPDIRECTDRAWSURFACE7 GetBackBufferLeft()
  64. {
  65. return m_pddsBackBufferLeft;
  66. }
  67. int GetCursorX(int i)
  68. {
  69. return i_CursorX[i];
  70. }
  71. int GetCursorY(int i)
  72. {
  73. return i_CursorY[i];
  74. }
  75. VOID SetCursorX(int i, int x)
  76. {
  77. i_CursorX[i] = x;
  78. }
  79. VOID SetCursorY(int i, int y)
  80. {
  81. i_CursorY[i] = y;
  82. }
  83. int GetActBuffer()
  84. {
  85. return i_ActBuffer;
  86. }
  87. // Status functions
  88. BOOL IsWindowed()
  89. {
  90. return m_bWindowed;
  91. }
  92. BOOL IsStereo()
  93. {
  94. return m_bStereo;
  95. }
  96. // Creation/destruction methods
  97. HRESULT CreateFullScreenDisplay(HWND hWnd, DWORD dwWidth, DWORD dwHeight,
  98. DWORD dwBPP);
  99. HRESULT CreateWindowedDisplay(HWND hWnd, DWORD dwWidth, DWORD dwHeight);
  100. HRESULT InitClipper();
  101. HRESULT UpdateBounds();
  102. virtual HRESULT DestroyObjects();
  103. // Methods to create child objects
  104. VOID AddBufferCounter();
  105. INT CheckFlipMode();
  106. HRESULT CreateSurface(CSurface ** ppSurface, DWORD dwWidth, DWORD dwHeight);
  107. HRESULT CreateSurfaceFromBitmap(CSurface ** ppSurface, TCHAR * strBMP,
  108. DWORD dwDesiredWidth, DWORD dwDesiredHeight);
  109. HRESULT CDisplay::CreateSurfaceFromBitmapArchive(CSurface ** ppSurface,
  110. TCHAR * strBMP, APAK_HANDLE * pArchive);
  111. HRESULT CreateSurfaceFromText(CSurface ** ppSurface, HFONT hFont,
  112. TCHAR * strText, COLORREF crBackground, COLORREF crForeground);
  113. HRESULT CreatePaletteFromBitmap(LPDIRECTDRAWPALETTE * ppPalette,
  114. const TCHAR * strBMP);
  115. HRESULT CDisplay::CreateCursurBackSurcafe(int x, int y,
  116. COLORREF dwColorKey);
  117. // Display methods
  118. HRESULT SetColorKey(COLORREF dwColorKey);
  119. DWORD ConvertGDIColor(COLORREF dwGDIColor);
  120. HRESULT Clear(DWORD dwColor = 0L);
  121. HRESULT ColorKeyBlt(DWORD x, DWORD y, LPDIRECTDRAWSURFACE7 pdds,
  122. RECT * prc = NULL);
  123. HRESULT Blt(DWORD x, DWORD y, LPDIRECTDRAWSURFACE7 pdds,
  124. RECT * prc = NULL, DWORD dwFlags = 0);
  125. HRESULT Blt(DWORD x, DWORD y, CSurface * pSurface, RECT * prc = NULL);
  126. HRESULT StretchBlt(RECT * dprc, CSurface * pSurface, RECT * sprc);
  127. HRESULT ShowBitmap(HBITMAP hbm, LPDIRECTDRAWPALETTE pPalette = NULL);
  128. HRESULT SetPalette(LPDIRECTDRAWPALETTE pPalette);
  129. HRESULT Present();
  130. HRESULT FillRect(RECT * prc, DWORD dwColor);
  131. HRESULT Save(FILE * file, int x, int y, int idx);
  132. };
  133. //-----------------------------------------------------------------------------
  134. // Name: class CSurface
  135. // Desc: Class to handle aspects of a DirectDrawSurface.
  136. //-----------------------------------------------------------------------------
  137. class CSurface
  138. {
  139. LPDIRECTDRAWSURFACE7 m_pdds;
  140. DDSURFACEDESC2 m_ddsd;
  141. BOOL m_bColorKeyed;
  142. DWORD dw_ColorKey;
  143. public:
  144. LPDIRECTDRAWSURFACE7 GetDDrawSurface()
  145. {
  146. return m_pdds;
  147. }
  148. LPDDSURFACEDESC2 GetDDrawSurfaceDesc()
  149. {
  150. return &m_ddsd;
  151. }
  152. BOOL IsColorKeyed()
  153. {
  154. return m_bColorKeyed;
  155. }
  156. HRESULT DrawBitmap(HBITMAP hBMP, DWORD dwBMPOriginX =
  157. 0, DWORD dwBMPOriginY = 0, DWORD dwBMPWidth = 0, DWORD dwBMPHeight = 0);
  158. HRESULT DrawBitmap(TCHAR * strBMP, DWORD dwDesiredWidth,
  159. DWORD dwDesiredHeight);
  160. HRESULT DrawText(HFONT hFont, TCHAR * strText, DWORD dwOriginX,
  161. DWORD dwOriginY, COLORREF crBackground, COLORREF crForeground);
  162. HRESULT ColorKeyBlt(DWORD x, DWORD y, LPDIRECTDRAWSURFACE7 pdds,
  163. RECT * prc);
  164. HRESULT Blt(DWORD x, DWORD y, LPDIRECTDRAWSURFACE7 pdds,
  165. RECT * prc = NULL, DWORD dwFlags = 0);
  166. HRESULT MyStretchBlt(RECT * dprc, CSurface * pSurface, RECT * sprc);
  167. HRESULT FillRect(RECT * prc = NULL, DWORD dwColor = 0);
  168. HRESULT Blt(DWORD x, DWORD y, CSurface * pSurface, RECT * prc = NULL);
  169. HRESULT Clear(DWORD dwColor);
  170. HRESULT SetColorKey(COLORREF dwColorKey);
  171. DWORD ConvertGDIColor(COLORREF dwGDIColor);
  172. static HRESULT GetBitMaskInfo(DWORD dwBitMask, DWORD * pdwShift,
  173. DWORD * pdwBits);
  174. HRESULT Save(FILE * file, int x, int y);
  175. HRESULT Create(LPDIRECTDRAW7 pDD, DDSURFACEDESC2 * pddsd);
  176. HRESULT Create(LPDIRECTDRAWSURFACE7 pdds);
  177. HRESULT Destroy();
  178. CSurface();
  179. ~CSurface();
  180. };
  181. #endif // DDUTIL_H