VBUFFER.CPP 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. /*
  2. ** Command & Conquer Red Alert(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 : Westwood 32 bit Library *
  23. * *
  24. * File Name : VBUFFER.CPP *
  25. * *
  26. * Programmer : Phil W. Gorrow *
  27. * *
  28. * Start Date : January 9, 1995 *
  29. * *
  30. * Last Update : January 9, 1995 [PWG] *
  31. * *
  32. * This module contains the C++ class definitions for the video buffer *
  33. * class. This include routines for class creation and modification *
  34. *-------------------------------------------------------------------------*
  35. * Functions: *
  36. * VVPC::VideoViewPortClass -- Constructor for basic view port class *
  37. * VVPC::VideoViewPortClass -- Default constructor for view port class *
  38. * VVPC::~VideoViewPortClass -- Destructor for GraphicViewPortClass *
  39. * VVPC::Attach -- Attaches a viewport to a buffer class *
  40. * VVPC::Change -- Changes position and size of a Video View Port *
  41. * VBC::VideoBufferClass -- Default constuctor for video buffers *
  42. * VBC::VideoBufferClass -- Lowlevel constructor for video buffer class *
  43. * VBC::~VideoBufferClass -- Destructor for the video buffer class *
  44. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  45. #include "vbuffer.h"
  46. /*=========================================================================*/
  47. /* The following PRIVATE functions are in this file: */
  48. /*=========================================================================*/
  49. /*= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =*/
  50. /***************************************************************************
  51. * VVPC::VIDEOVIEWPORTCLASS -- Constructor for basic view port class *
  52. * *
  53. * INPUT: VideoBufferClass * vbuffer - buffer to attach to *
  54. * WORD x - x offset into buffer *
  55. * WORD y - y offset into buffer *
  56. * WORD w - view port width in pixels *
  57. * WORD h - view port height in pixels *
  58. * *
  59. * OUTPUT: Constructors may not have a return value *
  60. * *
  61. * HISTORY: *
  62. * 05/09/1994 PWG : Created. *
  63. *=========================================================================*/
  64. VideoViewPortClass::VideoViewPortClass(VideoBufferClass *vbuffer, int x, int y, int w, int h)
  65. {
  66. Attach(vbuffer, x, y, w, h);
  67. }
  68. /***************************************************************************
  69. * VVPC::VIDEOVIEWPORTCLASS -- Default constructor for view port class *
  70. * *
  71. * INPUT: none *
  72. * *
  73. * OUTPUT: none *
  74. * *
  75. * HISTORY: *
  76. * 05/09/1994 PWG : Created. *
  77. *=========================================================================*/
  78. VideoViewPortClass::VideoViewPortClass(void)
  79. {
  80. }
  81. /***************************************************************************
  82. * VVPC::~VIDEOVIEWPORTCLASS -- Destructor for GraphicViewPortClass *
  83. * *
  84. * INPUT: none *
  85. * *
  86. * OUTPUT: A destructor may not return a value. *
  87. * *
  88. * HISTORY: *
  89. * 05/10/1994 PWG : Created. *
  90. *=========================================================================*/
  91. VideoViewPortClass::~VideoViewPortClass(void)
  92. {
  93. }
  94. /***************************************************************************
  95. * VVPC::ATTACH -- Attaches a viewport to a buffer class *
  96. * *
  97. * INPUT: GraphicBufferClass *g_buff - pointer to gbuff to attach to *
  98. * WORD x - x position to attach to *
  99. * WORD y - y position to attach to *
  100. * WORD w - width of the view port *
  101. * WORD h - height of the view port *
  102. * *
  103. * OUTPUT: none *
  104. * *
  105. * HISTORY: *
  106. * 05/10/1994 PWG : Created. *
  107. *=========================================================================*/
  108. void VideoViewPortClass::Attach(VideoBufferClass *vbuffer, int x, int y, int w, int h)
  109. {
  110. /*======================================================================*/
  111. /* Verify that the x and y coordinates are valid and placed within the */
  112. /* physical buffer. */
  113. /*======================================================================*/
  114. if (x < 0) // you cannot place view port off
  115. x = 0; // the left edge of physical buf
  116. if (x >= vbuffer->Get_Width()) // you cannot place left edge off
  117. x = vbuffer->Get_Width() - 1; // the right edge of physical buf
  118. if (y < 0) // you cannot place view port off
  119. y = 0; // the top edge of physical buf
  120. if (y >= vbuffer->Get_Height()) // you cannot place view port off
  121. y = vbuffer->Get_Height() - 1; // bottom edge of physical buf
  122. /*======================================================================*/
  123. /* Adjust the width and height of necessary */
  124. /*======================================================================*/
  125. if (x + w > vbuffer->Get_Width()) // if the x plus width is larger
  126. w = vbuffer->Get_Width() - x; // than physical, fix width
  127. if (y + h > vbuffer->Get_Height()) // if the y plus height is larger
  128. h = vbuffer->Get_Height() - y; // than physical, fix height
  129. /*======================================================================*/
  130. /* Get a pointer to the top left edge of the buffer. */
  131. /*======================================================================*/
  132. Offset = vbuffer->Get_Offset() + (vbuffer->Get_Width() * y) + x;
  133. /*======================================================================*/
  134. /* Copy over all of the variables that we need to store. */
  135. /*======================================================================*/
  136. XPos = x;
  137. YPos = y;
  138. XAdd = vbuffer->Get_Width() - w;
  139. Width = w;
  140. Height = h;
  141. VideoBuff = vbuffer;
  142. }
  143. /***************************************************************************
  144. * VVPC::CHANGE -- Changes position and size of a Video View Port *
  145. * *
  146. * INPUT: WORD the new x pixel position of the Video view port *
  147. * WORD the new y pixel position of the Video view port *
  148. * WORD the new width of the viewport in pixels *
  149. * WORD the new height of the viewport in pixels *
  150. * *
  151. * OUTPUT: BOOL whether the Video View Port could be sucessfully *
  152. * resized. *
  153. * *
  154. * WARNINGS: You may not resize a Video View Port which is derived *
  155. * from a Video View Port Buffer, *
  156. * *
  157. * HISTORY: *
  158. * 09/14/1994 SKB : Created. *
  159. *=========================================================================*/
  160. BOOL VideoViewPortClass::Change(int x, int y, int w, int h)
  161. {
  162. /*======================================================================*/
  163. /* Can not change a Video View Port if it is actually the physical */
  164. /* representation of a Video Buffer. */
  165. /*======================================================================*/
  166. if (this == Get_Video_Buffer()) {
  167. return(FALSE);
  168. }
  169. /*======================================================================*/
  170. /* Since there is no allocated information, just re-attach it to the */
  171. /* existing Video buffer as if we were creating the */
  172. /* VideoViewPort. */
  173. /*======================================================================*/
  174. Attach(Get_Video_Buffer(), x, y, w, h);
  175. return(TRUE);
  176. }
  177. /***************************************************************************
  178. * VBC::VIDEOBUFFERCLASS -- Default constuctor for video buffers *
  179. * *
  180. * INPUT: WORD w - width of buffer in pixels (default = 320) *
  181. * WORD h - height of buffer in pixels (default = 200) *
  182. * *
  183. * OUTPUT: none *
  184. * *
  185. * HISTORY: *
  186. * 05/13/1994 PWG : Created. *
  187. *=========================================================================*/
  188. VideoBufferClass::VideoBufferClass(int w, int h)
  189. {
  190. Offset = 0xa0000; // Get offset to the buffer
  191. Width = w; // Record width of Buffer
  192. Height = h; // Record height of Buffer
  193. XAdd = 0; // Record XAdd of Buffer
  194. XPos = 0; // Record XPos of Buffer
  195. YPos = 0; // Record YPos of Buffer
  196. VideoBuff = this; // Get a pointer to our self
  197. }
  198. /***************************************************************************
  199. * VBC::VIDEOBUFFERCLASS -- Lowlevel constructor for video buffer class *
  200. * *
  201. * INPUT: UWORD the selector of the memory reference *
  202. * long the offset of the memory reference *
  203. * WORD the width of the video buffer *
  204. * WORD the height of the video buffer *
  205. * *
  206. * OUTPUT: none *
  207. * *
  208. * HISTORY: *
  209. * 06/07/1994 PWG : Created. *
  210. *=========================================================================*/
  211. VideoBufferClass::VideoBufferClass(unsigned short selector, long offset, int w, int h)
  212. {
  213. Offset = offset; // Get offset to the buffer
  214. Width = w; // Record width of Buffer
  215. Height = h; // Record height of Buffer
  216. XAdd = 0; // Record XAdd of Buffer
  217. XPos = 0; // Record XPos of Buffer
  218. YPos = 0; // Record YPos of Buffer
  219. VideoBuff = this; // Get a pointer to our self
  220. }
  221. /*=========================================================================*
  222. * VBC::~VIDEOBUFFERCLASS -- Destructor for the video buffer class *
  223. * *
  224. * INPUT: none *
  225. * *
  226. * OUTPUT: none *
  227. * *
  228. * HISTORY: *
  229. * 05/03/1994 PWG : Created. *
  230. *=========================================================================*/
  231. VideoBufferClass::~VideoBufferClass()
  232. {
  233. }