Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

152 lines
2.8 KiB

  1. /*==========================================================================
  2. *
  3. * Copyright (c) 1995 - 1997 Microsoft Corporation. All Rights Reserved.
  4. * Copyright (C) 1994-1995 ATI Technologies Inc. All Rights Reserved.
  5. *
  6. * File: tile.c
  7. * Content: tile loading and initialization functions
  8. *
  9. ***************************************************************************/
  10. #include "foxbear.h"
  11. /*
  12. * CreateTiles
  13. */
  14. HBITMAPLIST *CreateTiles( HBITMAPLIST *phBitmapList, USHORT n )
  15. {
  16. HBITMAPLIST *hTileList;
  17. USHORT i;
  18. hTileList = CMemAlloc( n, sizeof (HBITMAPLIST) );
  19. if( hTileList == NULL )
  20. {
  21. ErrorMessage( "hTileList in CreateTiles" );
  22. }
  23. for( i = 0; i < n; ++i )
  24. {
  25. hTileList[i].hBM = phBitmapList[i].hBM;
  26. }
  27. return hTileList;
  28. } /* CreateTiles */
  29. /*
  30. * DestroyTiles
  31. */
  32. BOOL DestroyTiles( HBITMAPLIST *phTileList )
  33. {
  34. MemFree( phTileList );
  35. return TRUE;
  36. } /* DestroyTiles */
  37. /*
  38. * getData
  39. */
  40. LPSTR getData(LPSTR fileName)
  41. {
  42. LPSTR p = NULL;
  43. HRSRC hRes;
  44. hRes = FindResource(NULL, fileName, RT_RCDATA);
  45. if( hRes != NULL )
  46. {
  47. p = LockResource(LoadResource(NULL, hRes));
  48. }
  49. return p;
  50. } /* getData */
  51. /*
  52. * CreatePosList
  53. */
  54. HPOSLIST *CreatePosList( LPSTR fileName, USHORT width, USHORT height )
  55. {
  56. HPOSLIST *hPosList;
  57. USHORT pos;
  58. LPSTR p;
  59. p = getData( fileName );
  60. if( p == NULL )
  61. {
  62. ErrorMessage( "p in CreatePosList" );
  63. }
  64. hPosList = CMemAlloc( width * height, sizeof (USHORT) );
  65. if( hPosList == NULL )
  66. {
  67. ErrorMessage( "posList in CreatePosList" );
  68. }
  69. for( pos = 0; pos < width * height; ++pos )
  70. {
  71. hPosList[pos] = (USHORT) getint(&p, 0) - 1;
  72. }
  73. return hPosList;
  74. } /* CreatePosList */
  75. /*
  76. * CreateSurfaceList
  77. */
  78. HSURFACELIST *CreateSurfaceList( LPSTR fileName, USHORT width, USHORT height )
  79. {
  80. HSURFACELIST *hSurfaceList;
  81. USHORT pos;
  82. USHORT value;
  83. LPSTR p;
  84. p = getData( fileName );
  85. if( p == NULL )
  86. {
  87. ErrorMessage( "p in CreateSurfaceList" );
  88. }
  89. hSurfaceList = CMemAlloc( width * height, sizeof (HSURFACELIST) );
  90. if( hSurfaceList == NULL )
  91. {
  92. ErrorMessage( "posList in CreateSurfaceList" );
  93. }
  94. for( pos = 0; pos < width * height; ++pos )
  95. {
  96. value = (USHORT) getint(&p, 0);
  97. if( value == 0 )
  98. {
  99. hSurfaceList[pos] = FALSE;
  100. }
  101. else
  102. {
  103. hSurfaceList[pos] = TRUE;
  104. }
  105. }
  106. return hSurfaceList;
  107. } /* CreateSurfaceList */
  108. /*
  109. * DestoryPosList
  110. */
  111. BOOL DestroyPosList ( HPOSLIST *posList )
  112. {
  113. if( posList == NULL )
  114. {
  115. ErrorMessage( "posList in DestroyPosList" );
  116. }
  117. MemFree( posList );
  118. return TRUE;
  119. } /* DestroyPosList */