home *** CD-ROM | disk | FTP | other *** search
/ Windows Graphics Programming / Feng_Yuan_Win32_GDI_DirectX.iso / Samples / include / ddwrap.h < prev    next >
Encoding:
C/C++ Source or Header  |  2000-05-12  |  3.9 KB  |  150 lines

  1. #pragma once
  2.  
  3. //-----------------------------------------------------------------------------------//
  4. //              Windows Graphics Programming: Win32 GDI and DirectDraw               //
  5. //                             ISBN  0-13-086985-6                                   //
  6. //                                                                                   //
  7. //  Written            by  Yuan, Feng                             www.fengyuan.com   //
  8. //  Copyright (c) 2000 by  Hewlett-Packard Company                www.hp.com         //
  9. //  Published          by  Prentice Hall PTR, Prentice-Hall, Inc. www.phptr.com      //
  10. //                                                                                   //
  11. //  FileName   : ddwrap.h                                                             //
  12. //  Description: DirectDraw/Direct3D wrapper                                         //
  13. //  Version    : 1.00.000, May 31, 2000                                              //
  14. //-----------------------------------------------------------------------------------//
  15.  
  16. //////////////////////////////////////////
  17.  
  18. class KDDPalette
  19. {
  20. protected:
  21.     IDirectDrawPalette   * m_pPalette;
  22.  
  23. public:
  24.     KDDPalette()
  25.     {
  26.         m_pPalette = NULL;
  27.     }
  28.  
  29.     ~KDDPalette()
  30.     {
  31.         SAFE_RELEASE(m_pPalette);
  32.     }
  33.  
  34.     HRESULT LoadPalette(IDirectDraw7 * pDD, const BITMAPINFO * pDIB);
  35. };
  36.  
  37. /////////////////////////////////////////
  38.  
  39. // Wrapper for IDirectDraw7 interface, supporting primary surface
  40. class KDirectDraw
  41. {
  42. protected:
  43.     IDirectDraw7  *    m_pDD;
  44.     
  45.     RECT            m_rcDest;    // destination rectangle
  46.     KDDSurface        m_primary;
  47.  
  48.     virtual HRESULT Discharge(void);
  49.  
  50. public:
  51.  
  52.     KDirectDraw(void);
  53.     
  54.     virtual ~KDirectDraw(void)
  55.     {
  56.         Discharge();
  57.     }
  58.  
  59.     void SetClientRect(HWND hWnd);
  60.  
  61.     virtual HRESULT SetupDirectDraw(HWND hTop, HWND hWnd, int nBufferCount=0,
  62.                         bool bFullScreen = false, int width=0, int height=0, int bpp=0);
  63. };
  64.  
  65. //////////////////////////////////
  66.  
  67. RGNDATA * GetClipRegionData(HRGN hRgn);
  68. HRGN      GetClipRegion(IDirectDrawClipper * pClipper);
  69. BOOL      SetClipRegion(IDirectDrawClipper * pClipper, HRGN hRgn);
  70.  
  71. class KRgnClipper
  72. {
  73.     IDirectDrawClipper  * m_pNew;
  74.     IDirectDrawClipper  * m_pOld;
  75.     IDirectDrawSurface7 * m_pSrf;
  76.  
  77. public:
  78.     KRgnClipper(IDirectDraw7 * pDD, IDirectDrawSurface7 * pSrf, HRGN hRgn)
  79.     {
  80.         pDD->CreateClipper(0, & m_pNew, NULL); // create new clipper
  81.  
  82.         SetClipRegion(m_pNew, hRgn);           // set clip list from region
  83.  
  84.         m_pSrf = pSrf;
  85.         pSrf->GetClipper(& m_pOld);            // get old clipper
  86.         pSrf->SetClipper(m_pNew);              // replace with new clipper
  87.     }
  88.     
  89.     ~KRgnClipper()
  90.     {
  91.         m_pSrf->SetClipper(m_pOld);               // restore old clipper
  92.         m_pOld->Release();                     // release old clipper
  93.         m_pNew->Release();                     // release new clipper
  94.     }
  95. };
  96.  
  97. //////////////////////////////////////////////////////
  98.  
  99. // Wrapper for IDirect3D7, IDirect3DDevice7
  100.  
  101. class KDirect3D : public KDirectDraw
  102. {
  103. protected:
  104.     IDirect3D7       *    m_pD3D;
  105.     IDirect3DDevice7 *  m_pD3DDevice;
  106.  
  107.     KOffScreenSurface    m_backsurface;
  108.     KOffScreenSurface   m_zbuffer;
  109.     bool                m_bReady;
  110.  
  111.     virtual HRESULT  Discharge(void);
  112.  
  113.     virtual HRESULT OnRender(void)
  114.     {
  115.         return S_OK;
  116.     }
  117.  
  118.     virtual HRESULT OnInit(HINSTANCE hInst)
  119.     {
  120.         m_bReady = true;
  121.  
  122.         return S_OK;
  123.     }
  124.  
  125.     virtual HRESULT OnDischarge(void)
  126.     {
  127.         m_bReady = false;
  128.         return S_OK;
  129.     }
  130.     
  131. public:
  132.  
  133.     KDirect3D(void);
  134.     
  135.     ~KDirect3D(void)
  136.     {
  137.         Discharge();
  138.     }
  139.  
  140.     virtual HRESULT SetupDirectDraw(HWND hWnd, HWND hTop, int nBufferCount=0,
  141.                 bool bFullScreen=false, int width=0, int height=0, int bpp=0);
  142.  
  143.     virtual HRESULT ShowFrame(HWND hWnd);
  144.     virtual HRESULT RestoreSurfaces(void);
  145.  
  146.     virtual HRESULT Render(HWND hWnd);
  147.     virtual HRESULT ReCreate(HINSTANCE hInst, HWND hTop, HWND hWnd);
  148.     virtual HRESULT OnResize(HINSTANCE hInst, int width, int height, HWND hTop, HWND hWnd);
  149. };
  150.