draw.cpp 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. /*
  2. ** Command & Conquer Renegade(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /***********************************************************************************************
  19. *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
  20. ***********************************************************************************************
  21. * *
  22. * Project Name : Command & Conquer *
  23. * *
  24. * $Archive:: /Commando/Library/Draw.cpp $*
  25. * *
  26. * $Author:: Greg_h $*
  27. * *
  28. * $Modtime:: 7/22/97 11:37a $*
  29. * *
  30. * $Revision:: 1 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * Blit_Block -- Blit a block of data to the surface. *
  35. * Draw_Shape -- Draw a shape to the surface. *
  36. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  37. #include "always.h"
  38. #include "blit.h"
  39. #include "blitblit.h"
  40. #include "blitter.h"
  41. #include "bsurface.h"
  42. #include "draw.h"
  43. #include "dsurface.h"
  44. #include "hsv.h"
  45. #include "rlerle.h"
  46. #include "shapeset.h"
  47. /***********************************************************************************************
  48. * Draw_Shape -- Draw a shape to the surface. *
  49. * *
  50. * This is the largely general purpose shape drawing routine for the game. All non-voxel *
  51. * shape drawing will pass through this routine. *
  52. * *
  53. * INPUT: surface -- The destination surface for the draw. *
  54. * *
  55. * convert -- The converter to use for the pixel transformation. *
  56. * *
  57. * shapefile -- Pointer to the shapefile data block. *
  58. * *
  59. * shapenum -- The shape number within the shape file data block specified. *
  60. * *
  61. * point -- The draw point for this shape on the destination surface. This point *
  62. * is relative to the clipping window. *
  63. * *
  64. * window -- The clipping window to use for this draw. *
  65. * *
  66. * flags -- Shape draw control flags. These flags are used to extract the *
  67. * proper blitter from the converter object. *
  68. * *
  69. * remap -- Auxiliary remap table used for the draw process. House ownership can *
  70. * be controlled with this parameter. *
  71. * *
  72. * OUTPUT: none *
  73. * *
  74. * WARNINGS: none *
  75. * *
  76. * HISTORY: *
  77. * 05/27/1997 JLB : Created. *
  78. *=============================================================================================*/
  79. void Draw_Shape(Surface & surface, ConvertClass & convert, ShapeSet const * shapefile, int shapenum, Point2D const & point, Rect const & window, ShapeFlags_Type flags, unsigned char const * remap)
  80. {
  81. assert((flags & SHAPE_PREDATOR) == 0); // Not yet supported.
  82. assert(shapefile != NULL);
  83. assert(shapenum != -1);
  84. convert.Set_Remap(remap);
  85. int x = point.X;
  86. int y = point.Y;
  87. Rect rect = shapefile->Get_Rect(shapenum);
  88. void const * buffer = shapefile->Get_Data(shapenum);
  89. int width = shapefile->Get_Width();
  90. int height = shapefile->Get_Height();
  91. BSurface const shape(rect.Width, rect.Height, 1, (void *)buffer);
  92. /*
  93. ** Centered shapes must have their start position adjusted
  94. ** according to their width and height.
  95. */
  96. if (flags & SHAPE_CENTER) {
  97. x -= width/2;
  98. y -= height/2;
  99. }
  100. /*
  101. ** Factor the offset of the shape data (logical) into the draw
  102. ** position. Since the actual embedded shape pixels have no
  103. ** (transparent) offset, remove the offset coefficient.
  104. */
  105. x += rect.X;
  106. y += rect.Y;
  107. rect.X = 0;
  108. rect.Y = 0;
  109. /*
  110. ** If the remap table supplied is not NULL, then set the remap flag so that
  111. ** the appropriate blitter will be selected.
  112. */
  113. if (remap != NULL) {
  114. flags = ShapeFlags_Type(flags | SHAPE_REMAP);
  115. }
  116. /*
  117. ** Blit the pixels according to the flags specified and whether this is
  118. ** an RLE compressed shape. RLE compression uses different blitter routines
  119. ** than the normal method.
  120. */
  121. if (shapefile->Is_RLE_Compressed(shapenum)) {
  122. RLEBlitter const * blitter = convert.RLEBlitter_From_Flags(flags);
  123. if (blitter != NULL) {
  124. RLE_Blit(surface, window, Rect(x, y, rect.Width, rect.Height), shape, rect, rect, *blitter);
  125. }
  126. } else {
  127. Blitter const * blitter = convert.Blitter_From_Flags(flags);
  128. if (blitter != NULL) {
  129. Bit_Blit(surface, window, Rect(x, y, rect.Width, rect.Height), shape, shape.Get_Rect(), rect, *blitter);
  130. }
  131. }
  132. }
  133. /***********************************************************************************************
  134. * Blit_Block -- Blit a block of data to the surface. *
  135. * *
  136. * This function serves as a wrapper to the normal Bit_Blit function. It is used to control *
  137. * the blitter according to remap parameter specified. *
  138. * *
  139. * INPUT: surface -- The destination surface of this blit. *
  140. * *
  141. * convert -- The convert class for pixel transformation. *
  142. * *
  143. * source -- The source surface to blit from. *
  144. * *
  145. * sourcerect -- The source rectangle within the source surface to blit from. *
  146. * *
  147. * point -- The draw point of this blit (upper left corner). *
  148. * *
  149. * window -- The clipping window for this blit. The destination rectangle is *
  150. * relative to this clipping window. *
  151. * *
  152. * remap -- The remapping table pointer (optional) to be used for ownership *
  153. * remapping control. *
  154. * *
  155. * blitter -- Preexisting blitter to use. If this parameter is NULL, then a blitter *
  156. * object is created from the convert object supplied. *
  157. * *
  158. * OUTPUT: none *
  159. * *
  160. * WARNINGS: none *
  161. * *
  162. * HISTORY: *
  163. * 05/27/1997 JLB : Created. *
  164. *=============================================================================================*/
  165. void Blit_Block(Surface & surface, ConvertClass & convert, Surface const & source, Rect const & sourcerect, Point2D const & point, Rect const & window, unsigned char const * remap, Blitter const * blitter)
  166. {
  167. convert.Set_Remap(remap);
  168. if (blitter == NULL) {
  169. blitter = convert.Blitter_From_Flags((remap != NULL) ? SHAPE_REMAP : SHAPE_NORMAL);
  170. }
  171. /*
  172. ** Submit the image to the destination surface.
  173. */
  174. Bit_Blit(surface, window, Rect(point.X, point.Y, sourcerect.Width, sourcerect.Height), source, source.Get_Rect(), sourcerect, *blitter);
  175. }