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

  1. /*===========================================================================*\
  2. |
  3. |  File:        cgoption.cpp
  4. |
  5. |  Description: 
  6. |   Routines to display lines of text (from resource strings) overlayed on 
  7. |   a bitmap.  The text will be sized appropriately to fit within the 
  8. |   rectangle specified in the profile.  The user may hilight a particular 
  9. |   line and the index of the line will be returned to the caller.
  10. |       
  11. |-----------------------------------------------------------------------------
  12. |
  13. |  Copyright (C) 1995-1996 Microsoft Corporation.  All Rights Reserved.
  14. |
  15. |  Written by Moss Bay Engineering, Inc. under contract to Microsoft Corporation
  16. |
  17. \*===========================================================================*/
  18.  
  19. /**************************************************************************
  20.  
  21.     (C) Copyright 1995-1996 Microsoft Corp.  All rights reserved.
  22.  
  23.     You have a royalty-free right to use, modify, reproduce and 
  24.     distribute the Sample Files (and/or any modified version) in 
  25.     any way you find useful, provided that you agree that 
  26.     Microsoft has no warranty obligations or liability for any 
  27.     Sample Application Files which are modified. 
  28.  
  29.     we do not recomend you base your game on IKlowns, start with one of
  30.     the other simpler sample apps in the GDK
  31.  
  32.  **************************************************************************/
  33.  
  34. #include <windows.h>
  35. #include "cgglobl.h"
  36. #include "strrec.h"
  37. #include "cgdib.h"
  38. #include "cgscreen.h"
  39. #include "cgmidi.h"
  40. #include "cgsound.h"
  41. #include "cgload.h"
  42. #include "cgimage.h"
  43.  
  44. #define BASE_HWND   ghMainWnd
  45.  
  46. extern HDC LoadBitmapFile (LPSTR pBitmapFile);
  47. extern LPSTR NewStringResource( HINSTANCE hInst, int idString);
  48.  
  49. // ----------------------------------------------------------
  50. // CLoadingScreen - 
  51. // ----------------------------------------------------------
  52. CLoadingScreen::CLoadingScreen(
  53.     CGameScreen* pScreen,
  54.     LPSTR       pBitmapName,    // bkgrnd bitmap
  55.     int     iTextId,    // resource text to overlay
  56.     POINT       pt,     // location of circle
  57.     TXTCOLOR    color,      // color of overlay texxt
  58.     RECT        rect,
  59.     CSoundEffect    *pSoundStart,   // sound effect to play
  60.     CSoundEffect    *pSoundUpdate,  // sound effect to play
  61.     CSoundEffect    *pSoundEnd, // sound effect to play
  62.     LPSTR       MidiFile
  63. ) : pText( NULL ),
  64.     mpLoadBuffer( NULL ),
  65.     mpScreen( pScreen )
  66. {
  67.     HBRUSH      hBrush;
  68.  
  69.     HDC hdcScreen = GetDC(BASE_HWND);
  70.     ShowCursor(FALSE);
  71.     PatBlt(hdcScreen, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, BLACKNESS);
  72.  
  73.     hdcLoading = CreateCompatibleDC(hdcScreen);
  74.  
  75.     CLoadingScreen::pSoundStart = pSoundStart;
  76.     CLoadingScreen::pSoundUpdate = pSoundUpdate;
  77.     CLoadingScreen::pSoundEnd = pSoundEnd;
  78.  
  79.     if ((MidiFile != NULL) && (gMusicOn))
  80.     {
  81.         playMusic(MidiFile, TRUE);
  82.     }
  83.  
  84.     CGameDIB loadDIB( pBitmapName );
  85.     mWidth = loadDIB.GetWidth();
  86.     mHeight = loadDIB.GetHeight();
  87.     mpLoadBuffer = new CGameDSBitBuffer( &loadDIB );
  88.  
  89.     // Load the bitmap
  90.     if (mpLoadBuffer)
  91.     {
  92.         SelectObject(hdcLoading, mpLoadBuffer->GetHBitmap());
  93.  
  94.         hBrush = CreateSolidBrush(COLOR_YELLOW);
  95.         SelectObject(hdcLoading, hBrush);
  96.         SetBkMode(hdcLoading, TRANSPARENT);
  97.  
  98.         if (pSoundStart != NULL) 
  99.         {
  100.             pSoundStart->Play();
  101.         }
  102.  
  103.         Origin = pt;
  104.  
  105.         // Create text to be overlayed 
  106.         pText = new CGameText(hdcLoading, &rect, 1, 1);
  107.         pText->AddLine(NewStringResource(ghInst, iTextId)
  108.         , color.main, color.shadow);
  109.  
  110. // Don't display initially, 'cause palette ain't right yet.
  111. #if 0
  112.         pText->TextBlt();
  113.         mpScreen->Render(0,0, mWidth, mHeight, mpLoadBuffer, 0, 0, SRCCOPY);
  114.         mpScreen->PageFlip();
  115. #endif
  116.     }
  117.  
  118.     ReleaseDC(BASE_HWND, hdcScreen);
  119.     curTotal = 0;
  120. }
  121.  
  122. #define MIN_RADIUS  5
  123. // ----------------------------------------------------------
  124. // Update - 
  125. // ----------------------------------------------------------
  126. void CLoadingScreen::Update(
  127.     int Increment
  128. )
  129. {
  130.     int radius;
  131.     RECT    rect;
  132.  
  133.     curTotal += Increment;
  134.     radius = curTotal;
  135.  
  136.     rect.left = Origin.x - radius;
  137.     rect.top = Origin.y - radius;
  138.     rect.right = Origin.x + radius;
  139.     rect.bottom = Origin.y + radius;
  140.  
  141.     Ellipse(hdcLoading, rect.left, rect.top, rect.right, rect.bottom);
  142.     pText->TextBlt();
  143.     mpScreen->Render(0,0, mWidth, mHeight, mpLoadBuffer, 0, 0, SRCCOPY);
  144.     mpScreen->PageFlip();
  145.  
  146. }
  147.  
  148. // ----------------------------------------------------------
  149. // Paint
  150. // ----------------------------------------------------------
  151. void CLoadingScreen::Paint()
  152. {
  153.     mpScreen->Render(0,0, mWidth, mHeight, mpLoadBuffer, 0, 0, SRCCOPY);
  154.     mpScreen->PageFlip();
  155. }
  156.  
  157. // ----------------------------------------------------------
  158. // ~CLoadingScreen - 
  159. // ----------------------------------------------------------
  160. CLoadingScreen::~CLoadingScreen()
  161. {
  162.     closeMusic();
  163.  
  164.     delete pText;
  165.  
  166.     if (pSoundStart != NULL)
  167.     {
  168.         delete pSoundStart;
  169.     }
  170.     if (pSoundUpdate != NULL)
  171.     {
  172.         delete pSoundUpdate;
  173.     }
  174.  
  175.     RECT    rect = {0,0, SCREEN_WIDTH-1, SCREEN_HEIGHT-1};
  176.     mpScreen->ColorFill(&rect, 0);
  177.     mpScreen->PageFlip();
  178.  
  179.     if (pSoundEnd != NULL)
  180.     {
  181.         pSoundEnd->Play();
  182.     }
  183.  
  184.     DeleteDC( hdcLoading );
  185.     delete mpLoadBuffer;
  186.     ShowCursor(TRUE);
  187. }
  188.