DebugDisplay.cpp 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. /*
  2. ** Command & Conquer Generals Zero Hour(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. // //
  20. // (c) 2001-2003 Electronic Arts Inc. //
  21. // //
  22. ////////////////////////////////////////////////////////////////////////////////
  23. //----------------------------------------------------------------------------
  24. //
  25. // Westwood Studios Pacific.
  26. //
  27. // Confidential Information
  28. // Copyright (C) 2001 - All Rights Reserved
  29. //
  30. //----------------------------------------------------------------------------
  31. //
  32. // Project: Generals
  33. //
  34. // Module: Debug
  35. //
  36. // File name: DebugDisplay.cpp
  37. //
  38. // Created: 11/13/01 TR
  39. //
  40. //----------------------------------------------------------------------------
  41. //----------------------------------------------------------------------------
  42. // Includes
  43. //----------------------------------------------------------------------------
  44. #include "PreRTS.h" // This must go first in EVERY cpp file int the GameEngine
  45. #include "GameClient/DebugDisplay.h"
  46. //----------------------------------------------------------------------------
  47. // Externals
  48. //----------------------------------------------------------------------------
  49. //----------------------------------------------------------------------------
  50. // Defines
  51. //----------------------------------------------------------------------------
  52. //----------------------------------------------------------------------------
  53. // Private Types
  54. //----------------------------------------------------------------------------
  55. //----------------------------------------------------------------------------
  56. // Private Data
  57. //----------------------------------------------------------------------------
  58. //----------------------------------------------------------------------------
  59. // Public Data
  60. //----------------------------------------------------------------------------
  61. //----------------------------------------------------------------------------
  62. // Private Prototypes
  63. //----------------------------------------------------------------------------
  64. //----------------------------------------------------------------------------
  65. // Private Functions
  66. //----------------------------------------------------------------------------
  67. //----------------------------------------------------------------------------
  68. // Public Functions
  69. //----------------------------------------------------------------------------
  70. //============================================================================
  71. // DebugDisplay::DebugDisplay
  72. //============================================================================
  73. DebugDisplay::DebugDisplay()
  74. : m_width(0),
  75. m_height(0)
  76. {
  77. reset();
  78. }
  79. //============================================================================
  80. // DebugDisplay::reset
  81. //============================================================================
  82. void DebugDisplay::reset( void )
  83. {
  84. setCursorPos( 0, 0 );
  85. setTextColor( WHITE );
  86. setRightMargin( 0 );
  87. setLeftMargin( getWidth() );
  88. }
  89. //============================================================================
  90. // DebugDisplay::setCursorPos
  91. //============================================================================
  92. void DebugDisplay::setCursorPos( Int x, Int y )
  93. {
  94. m_xPos = x;
  95. m_yPos = y;
  96. }
  97. //============================================================================
  98. // DebugDisplay::getCursorXPos
  99. //============================================================================
  100. Int DebugDisplay::getCursorXPos( void )
  101. {
  102. return m_xPos;
  103. }
  104. //============================================================================
  105. // DebugDisplay::getCursorYPos
  106. //============================================================================
  107. Int DebugDisplay::getCursorYPos( void )
  108. {
  109. return m_yPos;
  110. }
  111. //============================================================================
  112. // DebugDisplay::getWidth
  113. //============================================================================
  114. Int DebugDisplay::getWidth( void )
  115. {
  116. return m_width;
  117. }
  118. //============================================================================
  119. // DebugDisplay::getHeight
  120. //============================================================================
  121. Int DebugDisplay::getHeight( void )
  122. {
  123. return m_height;
  124. }
  125. //============================================================================
  126. // DebugDisplay::setTextColor
  127. //============================================================================
  128. void DebugDisplay::setTextColor( Color color )
  129. {
  130. m_textColor = color;
  131. }
  132. //============================================================================
  133. // DebugDisplay::setRightMargin
  134. //============================================================================
  135. void DebugDisplay::setRightMargin( Int rightPos )
  136. {
  137. m_rightMargin = rightPos;
  138. }
  139. //============================================================================
  140. // DebugDisplay::setLeftMargin
  141. //============================================================================
  142. void DebugDisplay::setLeftMargin( Int leftPos )
  143. {
  144. m_leftMargin = leftPos;
  145. }
  146. //============================================================================
  147. // DebugDisplay::printf
  148. //============================================================================
  149. void DebugDisplay::printf( Char *format, ...)
  150. {
  151. va_list args;
  152. int result;
  153. static char text[5*1024];
  154. va_start( args, format );
  155. result = vsprintf( text, format, args );
  156. va_end( args );
  157. if ( result < 0 )
  158. {
  159. // error while printing string
  160. return;
  161. }
  162. DEBUG_ASSERTCRASH( result < sizeof(text), ("text overflow in DebugDisplay::printf() - string too long"));
  163. // find every line and print it
  164. Char *ptr = text;;
  165. Char *lineStart = ptr;
  166. Int lineLen = 0;
  167. Char ch;
  168. while ( (ch = *ptr++) != 0 )
  169. {
  170. switch ( ch )
  171. {
  172. case '\n':
  173. {
  174. if ( lineLen > 0 )
  175. {
  176. *(ptr -1) = 0; // replace '/n' with null
  177. drawText( m_rightMargin + m_xPos, m_yPos, lineStart );
  178. lineLen = 0;
  179. }
  180. lineStart = ptr;
  181. m_yPos++;
  182. m_xPos = 0;
  183. break;
  184. }
  185. default:
  186. {
  187. lineLen++;
  188. break;
  189. }
  190. }
  191. }
  192. if ( lineLen > 0 )
  193. {
  194. drawText( m_rightMargin + m_xPos, m_yPos, lineStart );
  195. m_xPos += lineLen;
  196. }
  197. }