home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / mnth0108.zip / Timur / bitmap.c next >
Text File  |  1993-03-14  |  3KB  |  85 lines

  1. /* BITMAP.C - Global Bitmap resource manager
  2.  
  3. Copyright (c) 1993 Timur Tabi
  4. Copyright (c) 1993 Fasa Corporation
  5.  
  6. The following trademarks are the property of Fasa Corporation:
  7. BattleTech, CityTech, AeroTech, MechWarrior, BattleMech, and 'Mech.
  8. The use of these trademarks should not be construed as a challenge to these marks.
  9.  
  10. */
  11.  
  12. #define INCL_DEV
  13. #define INCL_GPICONTROL
  14. #define INCL_GPIBITMAPS
  15. #define INCL_WINWINDOWMGR
  16. #define INCL_WINDIALOGS
  17. #include <os2.h>
  18. #include <stdio.h>
  19.  
  20. #include "header.h"
  21. #include "window.h"
  22.  
  23. static HDC hdcMemory=NULLHANDLE;
  24. static HPS hpsMemory;
  25.  
  26. void BitmapShutdown(void) {
  27. /* Releases the resouces allocated by BitmapInit()
  28. */
  29.   GpiDestroyPS(hpsMemory);
  30.   DevCloseDC(hdcMemory);
  31. }
  32.  
  33. HBITMAP BitmapLoad(ULONG ulBitmapID) {
  34. /* Loads a bitmap into the Bitmap Memory PS.  Also initializes the bitmap routine if needed.
  35. */
  36.   SIZEL sizel={0,0};
  37.   HBITMAP hbm;
  38.   char sz[60];
  39.  
  40. // Is this the first call to BitmapLoad() ?
  41.   if (hdcMemory==NULLHANDLE) {
  42. // Yes, so init the module.  First, create the memory device context
  43.     hdcMemory=DevOpenDC(hab,OD_MEMORY,"*",0,NULL,NULLHANDLE);
  44.     if (hdcMemory==NULLHANDLE) {
  45.       sprintf(sz,"Cannot open memory DC for bitmap %lu",ulBitmapID);
  46.       WinMessageBox(HWND_DESKTOP,hwndClient,sz,NULL,0,MB_ENTER|MB_ICONEXCLAMATION);
  47.       return NULLHANDLE;
  48.     }
  49. // Then create the accompanying presentation space
  50.     hpsMemory=GpiCreatePS(hab,hdcMemory,&sizel,PU_PELS | GPIF_DEFAULT | GPIT_MICRO | GPIA_ASSOC);
  51.     if (hpsMemory==NULLHANDLE) {
  52.       sprintf(sz,"Cannot create memory presentation space for bitmap %lu",ulBitmapID);
  53.       WinMessageBox(HWND_DESKTOP,hwndClient,sz,NULL,0,MB_ENTER|MB_ICONEXCLAMATION);
  54.       return NULLHANDLE;
  55.     }
  56.   }
  57.  
  58.   hbm=GpiLoadBitmap(hpsMemory,NULLHANDLE,ulBitmapID,0,0);
  59.   if (hbm==NULLHANDLE) {
  60.     sprintf(sz,"Cannot load bitmap %lu",ulBitmapID);
  61.     WinMessageBox(HWND_DESKTOP,hwndClient,sz,NULL,0,MB_ENTER|MB_ICONEXCLAMATION);
  62.     return NULLHANDLE;
  63.   }
  64.   return hbm;
  65. }
  66.  
  67. void BitmapDraw(HBITMAP hbm, HBITMAP hbmMask, POINTL ptl) {
  68.   POINTL aptl[3];
  69.   HPS hps=WinGetPS(hwndClient);
  70.  
  71. // First, mask out the background
  72.   GpiSetBitmap(hpsMemory,hbmMask);
  73.   aptl[0]=ptl;
  74.   aptl[1].x=aptl[0].x+29;
  75.   aptl[1].y=aptl[0].y+25;
  76.   aptl[2].x=0;
  77.   aptl[2].y=0;
  78.   GpiBitBlt(hps,hpsMemory,3L,aptl,ROP_SRCAND,0);
  79.  
  80. // Now, draw the bitmap
  81.   GpiSetBitmap(hpsMemory,hbm);
  82.   GpiBitBlt(hps,hpsMemory,3L,aptl,ROP_SRCPAINT,0);
  83.   WinReleasePS(hps);
  84. }
  85.