home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / ool.zip / OOL / source / xblitter.cpp < prev    next >
C/C++ Source or Header  |  1997-04-02  |  5KB  |  164 lines

  1. #include "xblitter.h"
  2.  
  3.  
  4. /*DOC
  5. CLASS    XBlitter
  6. FUNCTION XBlitter
  7. GROUP    x-games/constructors/destructor
  8. REMARKS  Makes basic initialization of the blitter; throws a XGameException in case of an error.
  9. */
  10. XBlitter::XBlitter( void ) : XObject()
  11. {
  12.         ULONG rc;
  13.  
  14.         // Get the screen capabilities
  15.         DiveCaps.pFormatData    = fccFormats;
  16.         DiveCaps.ulFormatLength = 120;
  17.         DiveCaps.ulStructLen = sizeof( DIVE_CAPS );
  18.         if( DiveQueryCaps ( &DiveCaps, DIVE_BUFFER_SCREEN ) )
  19.                 throw XGameException( "XBlitter: unable to query screen capabilities",
  20.                                       XGameException::XGERR_SCREEN_CAPS                 );
  21.  
  22.         // we need a color depth of at least 8 bits per pixel
  23.         if( DiveCaps.ulDepth < 8 )
  24.                 throw XGameException( "XBlitter: a color mode with at least 256 colors is required",
  25.                                       XGameException::XGERR_COLOR_DEPTH                             );
  26.  
  27.         // now open a DIVE instance
  28.         if( (rc = DiveOpen( &hDive, FALSE, NULL )) != 0 ) //()!=, svb
  29.                 throw XGameException( "XBlitter: unable to open a DIVE instance", rc );
  30. } // XBlitter::XBlitter
  31.  
  32.  
  33. /*DOC
  34. CLASS    XBlitter
  35. FUNCTION ~XBlitter
  36. GROUP    x-games/constructors/destructor
  37. REMARKS  Destroys the blitter.
  38. */
  39. XBlitter::~XBlitter()
  40. {
  41.         DisassociateVirtualScreen();
  42.  
  43.         // close the DIVE instance
  44.         DiveClose( hDive );
  45. } // XBlitter::~XBlitter
  46.  
  47.  
  48. /*DOC
  49. CLASS    XBlitter
  50. FUNCTION AssociateVirtualScreen
  51. GROUP    x-games
  52. REMARKS  Associates a virtual screen to the blitter; throws a XGameException in case of an error.
  53. */
  54. void XBlitter::AssociateVirtualScreen( XVirtualScreen* pVScr )
  55. {
  56.         ULONG rc;
  57.  
  58.         DisassociateVirtualScreen();
  59.         pVScreen = pVScr;
  60.  
  61.         rc = DiveAllocImageBuffer( hDive,
  62.                                    &ulBufferNumber,
  63.                                    FOURCC_LUT8,
  64.                                    pVScreen->GetWidth(),
  65.                                    pVScreen->GetHeight(),
  66.                                    0, pVScreen->GetBuffer()    );
  67.         if( rc )
  68.                 throw XGameException( "XBlitter: unable to associate virtual screen", rc );
  69. } // XBlitter::AssociateVirtualScreen
  70.  
  71.  
  72. /*DOC
  73. CLASS    XBlitter
  74. FUNCTION DisassociateVirtualScreen
  75. GROUP    x-games
  76. REMARKS  Disassociates the current virtual screen.
  77. */
  78. void XBlitter::DisassociateVirtualScreen( void )
  79. {
  80.         if( pVScreen && ulBufferNumber )
  81.         {
  82.                 DiveFreeImageBuffer( hDive, ulBufferNumber );
  83.                 pVScreen       = NULL;
  84.                 ulBufferNumber = 0;
  85.         } // if
  86. } // XBlitter::DisassociateVirtualScreen
  87.  
  88.  
  89. /*DOC
  90. CLASS    XBlitter
  91. FUNCTION SetPalette
  92. GROUP    x-games
  93. REMARKS  Sets the Palette for this DIVE instance; throws a XGameException in case of an error.
  94. PARAMETERS XPalette* xpal       pointer to a palette object
  95. */
  96. void XBlitter::SetPalette( XPalette* xpal )
  97. {
  98.         if( DiveCaps.ulDepth > 8 )
  99.                 DiveSetSourcePalette( hDive, 0, 256, (PBYTE)xpal->aulData );
  100.         else
  101.         {
  102.                 //DiveSetSourcePalette( hDive, 0, 256, (PBYTE)xpal->aulData );
  103.                 //DiveSetDestinationPalette( hDive, 0, 256, (PBYTE)xpal->aulData );
  104.                 xpal->Enable();
  105.         } // else
  106.  
  107.         pPalette = xpal;
  108. } // XBlitter::SetSourcePalette
  109.  
  110.  
  111. /*DOC
  112. CLASS    XBlitter
  113. FUNCTION Setup
  114. GROUP    x-games
  115. REMARKS  Setups the blitter with new values.
  116. PARAMETERS const PSETUP_BLITTER pSetupBlitter  Pointer to the setup structure; if pSetupBlitter
  117.                                                equals NULL, DiveSetupBlitter will also be called
  118.                                                with NULL as parameter
  119. */
  120. void XBlitter::Setup( PSETUP_BLITTER pSetupBlitter )
  121. {
  122.         if( NULL == pSetupBlitter )
  123.                 DiveSetupBlitter( hDive, NULL );
  124.         else if( pVScreen )
  125.         {
  126.                 ULONG rc;
  127.  
  128.                 pSetupBlitter->fccSrcColorFormat = FOURCC_LUT8;
  129.                 pSetupBlitter->ulSrcWidth        = pVScreen->GetWidth();
  130.                 pSetupBlitter->ulSrcHeight       = pVScreen->GetHeight();
  131.                 pSetupBlitter->ulSrcPosX         = 0;
  132.                 pSetupBlitter->ulSrcPosY         = 0;
  133.  
  134.                 if( (rc = DiveSetupBlitter( hDive, pSetupBlitter )) != 0 )//()!=, svb
  135.                         throw XGameException( "XBlitter: unable to setup blitter", rc );
  136.         } // else
  137. } // XBlitter::Setup
  138.  
  139.  
  140. /*DOC
  141. CLASS    XBlitter
  142. FUNCTION Blit
  143. GROUP    x-games
  144. REMARKS  Blitts the associated virtual screen; throws a XGameException in case of an error.
  145. */
  146. void XBlitter::Blit( void )
  147. {
  148.         ULONG rc;
  149.  
  150.         if( pVScreen )
  151.                 if( (rc = DiveBlitImage( hDive, ulBufferNumber, DIVE_BUFFER_SCREEN )) != 0 )//()!=, svb
  152.                         throw XGameException( "XBlitter: unable to blit", rc );
  153. } // XBlitter::Blit
  154.  
  155.  
  156. /*DOC
  157. CLASS    XBlitter
  158. FUNCTION GetVirtualScreen
  159. GROUP    x-games
  160. REMARKS  Returns the pointer to the associated virtual screen.
  161. RETURNS  XVirtualScreen* pVScreen       pointer to the virtual screen
  162. */
  163.  
  164.