OIMGRES.cpp 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. /*
  2. * Seven Kingdoms: Ancient Adversaries
  3. *
  4. * Copyright 1997,1998 Enlight Software Ltd.
  5. *
  6. * This program is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. *
  19. */
  20. //Filename : OIMGES.CPP
  21. //Description : Object ImageRes
  22. #include <string.h>
  23. #include <ALL.h>
  24. #include <OVGA.h>
  25. #include <OMOUSE.h>
  26. #include <OIMGRES.h>
  27. //--------- Format of RES file ------------//
  28. //
  29. // In the resource file, contain many compressed images, each image
  30. // has the following data
  31. //
  32. // <char[8]> = the name of the image
  33. // <int> = the widht of the image
  34. // <int> = the height of the image
  35. // <char...> = the bitmap of the image
  36. //
  37. //--------------------------------------------//
  38. //------- Start of function ImageRes::ImageRes -------//
  39. //
  40. // <char*> resName = name of the resource file (e.g. "GIF.RES")
  41. // [int] readAll = whether read all data into the buffer or read one each time
  42. // (default:0)
  43. // [int] useCommonBuf = whether use the sys common buffer to store the data or not
  44. // (default:0)
  45. //
  46. ImageRes::ImageRes(char* resFile, int readAll, int useCommonBuf) :
  47. ResourceIdx(resFile, readAll, useCommonBuf)
  48. {
  49. }
  50. //--------- End of function ImageRes::ImageRes -------//
  51. //-------- Start of function ImageRes::put_front --------//
  52. //
  53. // int x,y = the location of the image
  54. // char* imageName = name of the image
  55. // [int] compressFlag = compress flag
  56. // (default: 0)
  57. //
  58. void ImageRes::put_front(int x, int y, char* imageName, int compressFlag)
  59. {
  60. char* bitmapPtr = ResourceIdx::read(imageName);
  61. if(!bitmapPtr)
  62. return;
  63. mouse.hide_area( x, y, x+*((short*)bitmapPtr)-1, y+*(((short*)bitmapPtr)+1)-1 );
  64. if( compressFlag )
  65. vga_front.put_bitmap_trans_decompress( x, y, bitmapPtr );
  66. else
  67. vga_front.put_bitmap_trans( x, y, bitmapPtr );
  68. mouse.show_area();
  69. }
  70. //---------- End of function ImageRes::put_front --------//
  71. //-------- Start of function ImageRes::put_back --------//
  72. //
  73. // int x,y = the location of the image
  74. // char* imageName = name of the image
  75. // [int] compressFlag = compress flag
  76. // (default: 0)
  77. //
  78. void ImageRes::put_back(int x, int y, char* imageName, int compressFlag)
  79. {
  80. char* bitmapPtr = ResourceIdx::read(imageName);
  81. if( bitmapPtr )
  82. {
  83. if( compressFlag )
  84. vga_back.put_bitmap_trans_decompress( x, y, bitmapPtr );
  85. else
  86. vga_back.put_bitmap_trans( x, y, bitmapPtr );
  87. }
  88. }
  89. //---------- End of function ImageRes::put_back --------//
  90. //-------- Start of function ImageRes::put_front --------//
  91. //
  92. // int x,y = the location of the image
  93. // int bitmapId = id. of the bitmap
  94. // [int] compressFlag = compress flag
  95. // (default: 0)
  96. //
  97. void ImageRes::put_front(int x, int y, int bitmapId, int compressFlag)
  98. {
  99. char* bitmapPtr = ResourceIdx::get_data(bitmapId);
  100. if( !bitmapPtr )
  101. return;
  102. mouse.hide_area( x, y, x+*((short*)bitmapPtr)-1, y+*(((short*)bitmapPtr)+1)-1 );
  103. if( compressFlag )
  104. vga_front.put_bitmap_trans_decompress( x, y, bitmapPtr );
  105. else
  106. vga_front.put_bitmap_trans( x, y, bitmapPtr );
  107. mouse.show_area();
  108. }
  109. //---------- End of function ImageRes::put_front --------//
  110. //-------- Start of function ImageRes::put_back --------//
  111. //
  112. // int ,y = the location of the image
  113. // int bitmapId = id. of the bitmap
  114. // [int] compressFlag = compress flag
  115. // (default: 0)
  116. //
  117. void ImageRes::put_back(int x, int y, int bitmapId, int compressFlag)
  118. {
  119. char* bitmapPtr = ResourceIdx::get_data(bitmapId);
  120. if( bitmapPtr )
  121. {
  122. if( compressFlag )
  123. vga_back.put_bitmap_trans_decompress( x, y, bitmapPtr );
  124. else
  125. vga_back.put_bitmap_trans( x, y, bitmapPtr );
  126. }
  127. }
  128. //---------- End of function ImageRes::put_back --------//
  129. //-------- Start of function ImageRes::put_join --------//
  130. //
  131. // int x,y = the location of the image
  132. // char* imageName = name of the image
  133. //
  134. void ImageRes::put_join(int x, int y, char* imageName)
  135. {
  136. char* bitmapPtr = ResourceIdx::read(imageName);
  137. if( !bitmapPtr )
  138. return;
  139. mouse.hide_area( x, y, x+*((short*)bitmapPtr)-1, y+*(((short*)bitmapPtr)+1)-1 );
  140. if( bitmapPtr )
  141. IMGjoinTrans( vga_front.buf_ptr(), vga_front.buf_pitch(),
  142. vga_back.buf_ptr(), vga_back.buf_pitch(), x, y, bitmapPtr );
  143. mouse.show_area();
  144. }
  145. //---------- End of function ImageRes::put_join --------//
  146. //-------- Start of function ImageRes::put_large --------//
  147. //
  148. // When a picture file is > 64K, which cannot be read into a single
  149. // memory buffer.
  150. //
  151. // It will call vga.put_pict() which will continously read the file
  152. // and put to the screen until completion.
  153. //
  154. // <VgaBuf*> vgaBuf = the vga buffer for display
  155. // <int> x,y = the location of the image
  156. // <char*> imageName = name of the image
  157. //
  158. void ImageRes::put_large(VgaBuf* vgaBuf, int x, int y, char* imageName)
  159. {
  160. int dataSize;
  161. vgaBuf->put_large_bitmap( x, y, ResourceIdx::get_file(imageName, dataSize) );
  162. }
  163. //---------- End of function ImageRes::put_large --------//
  164. //-------- Start of function ImageRes::put_large --------//
  165. //
  166. // When a picture file is > 64K, which cannot be read into a single
  167. // memory buffer.
  168. //
  169. // It will call vga.put_pict() which will continously read the file
  170. // and put to the screen until completion.
  171. //
  172. // <VgaBuf*> vgaBuf = the vga buffer for display
  173. // <int> x,y = the location of the image
  174. // <int> bitmapId = id. of the bitmap in the bitmap resource file.
  175. //
  176. void ImageRes::put_large(VgaBuf* vgaBuf, int x, int y, int bitmapId)
  177. {
  178. int dataSize;
  179. vgaBuf->put_large_bitmap( x, y, ResourceIdx::get_file(bitmapId, dataSize) );
  180. }
  181. //---------- End of function ImageRes::put_large --------//
  182. //-------- Start of function ImageRes::put_to_buf --------//
  183. //
  184. // Put the image to the specified Vga buffer.
  185. //
  186. // <VgaBuf*> vgaBufPtr = the pointer to the Vga buffer
  187. // <char*> imageName = name of the image
  188. //
  189. void ImageRes::put_to_buf(VgaBuf* vgaBufPtr, char* imageName)
  190. {
  191. set_user_buf( vgaBufPtr->buf_ptr(), vgaBufPtr->buf_size(), 4 ); // 4-by pass the width and height info of the source data, only read the bitmap into the buffer
  192. read(imageName);
  193. reset_user_buf();
  194. // ---------- move data if buf_pitch() > buf_width() ---------//
  195. if( vgaBufPtr->buf_pitch() > vgaBufPtr->buf_width() )
  196. {
  197. int y = vgaBufPtr->buf_height()-1;
  198. int p = vgaBufPtr->buf_pitch();
  199. int w = vgaBufPtr->buf_width();
  200. char *srcPtr = vgaBufPtr->buf_ptr() + w * y;
  201. char *destPtr = vgaBufPtr->buf_ptr() + p * y;
  202. for( ; y > 0; --y, srcPtr -= w, destPtr -= p ) // no need to move the first line
  203. memmove( destPtr, srcPtr, w );
  204. }
  205. }
  206. //---------- End of function ImageRes::put_to_buf --------//
  207. //-------- Start of function ImageRes::put_to_buf --------//
  208. //
  209. // Put the image to the specified Vga buffer.
  210. //
  211. // <VgaBuf*> vgaBufPtr = the pointer to the Vga buffer
  212. // <int> bitmapId = id. of the bitmap in the resource file.
  213. //
  214. void ImageRes::put_to_buf(VgaBuf* vgaBufPtr, int bitmapId)
  215. {
  216. set_user_buf( vgaBufPtr->buf_ptr(), vgaBufPtr->buf_size(), 4 ); // 4-by pass the width and height info of the source data, only read the bitmap into the buffer
  217. get_data(bitmapId);
  218. reset_user_buf();
  219. // ---------- move data if buf_pitch() > buf_width() ---------//
  220. if( vgaBufPtr->buf_pitch() > vgaBufPtr->buf_width() )
  221. {
  222. int y = vgaBufPtr->buf_height()-1;
  223. int p = vgaBufPtr->buf_pitch();
  224. int w = vgaBufPtr->buf_width();
  225. char *srcPtr = vgaBufPtr->buf_ptr() + w * y;
  226. char *destPtr = vgaBufPtr->buf_ptr() + p * y;
  227. for( ; y > 0; --y, srcPtr -= w, destPtr -= p ) // no need to move the first line
  228. memmove( destPtr, srcPtr, w );
  229. }
  230. }
  231. //---------- End of function ImageRes::put_to_buf --------//