home *** CD-ROM | disk | FTP | other *** search
/ NEXT Generation 27 / NEXT27.iso / pc / demos / emperor / dx3.exe / SDK / SAMPLES / IKLOWNS / CGSCREEN.H < prev    next >
C/C++ Source or Header  |  1996-08-28  |  6KB  |  209 lines

  1. /*===========================================================================*\
  2. |
  3. |  File:        cgscreen.h
  4. |
  5. |  Description: 
  6. |       
  7. |-----------------------------------------------------------------------------
  8. |
  9. |  Copyright (C) 1995-1996 Microsoft Corporation.  All Rights Reserved.
  10. |
  11. |  Written by Moss Bay Engineering, Inc. under contract to Microsoft Corporation
  12. |
  13. \*===========================================================================*/
  14.  
  15. /**************************************************************************
  16.  
  17.     (C) Copyright 1995-1996 Microsoft Corp.  All rights reserved.
  18.  
  19.     You have a royalty-free right to use, modify, reproduce and 
  20.     distribute the Sample Files (and/or any modified version) in 
  21.     any way you find useful, provided that you agree that 
  22.     Microsoft has no warranty obligations or liability for any 
  23.     Sample Application Files which are modified. 
  24.  
  25.     we do not recomend you base your game on IKlowns, start with one of
  26.     the other simpler sample apps in the GDK
  27.  
  28.  **************************************************************************/
  29.  
  30. #ifndef CGSCREEN_H
  31. #define CGSCREEN_H
  32.  
  33. #include <windows.h>
  34. #include <ddraw.h>
  35. #include "cgbitbuf.h"
  36.  
  37. enum ST_TYPE
  38. {
  39.     ST_ROOT,    // CGameScreen -- abstract base class
  40.     ST_DDraw,   // CGameDDrawScreen -- Direct Draw screen
  41.     ST_DS       // CGameDSScreen    -- DIBSections screen
  42. };
  43.  
  44. class CGameScreen
  45. {
  46. public:
  47.     CGameScreen(HWND hwnd, int logWidth, int logHeight, int orgX=0, int orgY=0);
  48.     virtual ~CGameScreen();
  49.  
  50.     virtual void SetPalette(HPALETTE);
  51.     virtual void SetPalette( char* ) = 0;
  52.     
  53.     virtual void Render(
  54.             int xDest,
  55.             int yDest,
  56.             int wDest,
  57.             int hDest,
  58.             CGameBitBuffer* pSrcBuffer,
  59.             int xSrc,
  60.             int ySrc,
  61.             DWORD rop
  62.             ){};
  63.  
  64.     // render with transparency mask
  65.     virtual void TransRender(
  66.         int xDest,
  67.         int yDest,
  68.         int wDest,
  69.         int hDest,
  70.         CGameBitBuffer* pSrcBuffer,
  71.         int xSrc,
  72.         int ySrc
  73.         ) = 0;
  74.  
  75.     virtual void PageFlip()=0;
  76.     virtual void SetMode( int width, int height, int bits )=0;
  77.     virtual void RestoreMode()=0;
  78.  
  79.     virtual void ColorFill( LPRECT pRect, int palIndex )=0;
  80.  
  81.     // report this object's type
  82.     virtual ST_TYPE TypeID()
  83.     {
  84.         return ST_ROOT;
  85.     }
  86.  
  87.     virtual void Refresh()
  88.     {
  89.     }
  90.  
  91. protected:
  92.     HWND mhwnd;             // parent window
  93.     int mOutWidth;          // width of output screen
  94.     int mOutHeight;         // height of output screen
  95.     RECT mScreenRect;       // describes entire screen
  96.  
  97.     int mxCurrent;          // current x scroll position
  98.     int myCurrent;          // current y scroll position
  99.  
  100.     HPALETTE mOldPalette;   // saved to restore when object goes away
  101. };
  102.  
  103. class CGameDDrawScreen : public CGameScreen
  104. {
  105. public:
  106.     CGameDDrawScreen(HWND hwnd, int logWidth, int logHeight, int orgX=0, int orgY=0);
  107.     virtual ~CGameDDrawScreen();
  108.  
  109.     virtual void Render(
  110.         int xDest,
  111.         int yDest,
  112.         int wDest,
  113.         int hDest,
  114.         CGameBitBuffer* pSrcBuffer,
  115.         int xSrc,
  116.         int ySrc,
  117.         DWORD rop
  118.         );
  119.  
  120.     // render with transparency mask
  121.     virtual void TransRender(
  122.         int xDest,
  123.         int yDest,
  124.         int wDest,
  125.         int hDest,
  126.         CGameBitBuffer* pSrcBuffer,
  127.         int xSrc,
  128.         int ySrc
  129.         );
  130.  
  131.     virtual void PageFlip();
  132.     virtual void SetMode( int width, int height, int bits );
  133.     virtual void ShowGDIPage();
  134.     virtual void RestoreMode();
  135.     virtual void ColorFill( LPRECT pRect, int palIndex );
  136.  
  137.     virtual void SetPalette( char* );
  138.  
  139.     // use direct draw to determine total video memory
  140.     int GetVideoMemory();
  141.  
  142.     // report this object's type
  143.     virtual ST_TYPE TypeID()
  144.     {
  145.         return ST_DDraw;
  146.     }
  147.  
  148.     virtual void Refresh();
  149.  
  150. protected:
  151.     CGameDDrawScreenBuffer* mpSurfaces[2];  // ptrs to front & back buffer
  152.     int mBackSurface;           // index to current back buffer
  153. };
  154.  
  155. // use CreateDIBSection for accessing bits
  156. class CGameDSScreen : public CGameScreen
  157. {
  158. public:
  159.     CGameDSScreen(HWND hwnd, int logWidth, int logHeight, int orgX=0, int orgY=0);
  160.     virtual ~CGameDSScreen();
  161.  
  162.     virtual void Render(
  163.         int xDest,
  164.         int yDest,
  165.         int wDest,
  166.         int hDest,
  167.         CGameBitBuffer* pSrcBuffer,
  168.         int xSrc,
  169.         int ySrc,
  170.         DWORD rop
  171.         );
  172.  
  173.     // render with transparency mask
  174.     virtual void TransRender(
  175.         int xDest,
  176.         int yDest,
  177.         int wDest,
  178.         int hDest,
  179.         CGameBitBuffer* pSrcBuffer,
  180.         int xSrc,
  181.         int ySrc
  182.         );
  183.  
  184.     virtual void PageFlip();
  185.     virtual void SetMode( int width, int height, int bits ){};
  186.     virtual void ShowGDIPage(){};
  187.     virtual void RestoreMode(){};
  188.     virtual void SetPalette(HPALETTE);
  189.     virtual void SetPalette( char* );
  190.     virtual void ColorFill( LPRECT pRect, int palIndex );
  191.  
  192.     // report this object's type
  193.     virtual ST_TYPE TypeID()
  194.     {
  195.         return ST_DS;
  196.     }
  197.  
  198. protected:
  199.     HDC mhdcOut;            // keep output hdc around (assumes window is CS_OWNDC!)
  200.     HDC mhdcBackBuffer;     // for holding backbuffer
  201.  
  202.     CGameDIB* mpBufferDIB;      // ptr to back buffer
  203.     CGameDIB* mpScreenDIB;      // ptr to screen
  204.  
  205.     HBITMAP mhbmOld;        // for restoring screen's bitmap
  206. };
  207.  
  208. #endif // CGSCREEN_H
  209.