W3DStaticText.cpp 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  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. // FILE: W3DStaticText.cpp ////////////////////////////////////////////////////
  24. //-----------------------------------------------------------------------------
  25. //
  26. // Westwood Studios Pacific.
  27. //
  28. // Confidential Information
  29. // Copyright (C) 2001 - All Rights Reserved
  30. //
  31. //-----------------------------------------------------------------------------
  32. //
  33. // Project: RTS3
  34. //
  35. // File name: W3DStaticText.cpp
  36. //
  37. // Created: Colin Day, June 2001
  38. //
  39. // Desc: W3D implementation of the static text GUI control
  40. //
  41. //-----------------------------------------------------------------------------
  42. ///////////////////////////////////////////////////////////////////////////////
  43. // SYSTEM INCLUDES ////////////////////////////////////////////////////////////
  44. #include <stdlib.h>
  45. // USER INCLUDES //////////////////////////////////////////////////////////////
  46. #include "Common/GlobalData.h"
  47. #include "GameClient/GameWindowGlobal.h"
  48. #include "GameClient/GameWindowManager.h"
  49. #include "GameClient/GadgetStaticText.h"
  50. #include "W3DDevice/GameClient/W3DGameWindow.h"
  51. #include "W3DDevice/GameClient/W3DGadget.h"
  52. #include "W3DDevice/GameClient/W3DDisplay.h"
  53. // DEFINES ////////////////////////////////////////////////////////////////////
  54. // PRIVATE TYPES //////////////////////////////////////////////////////////////
  55. // PRIVATE DATA ///////////////////////////////////////////////////////////////
  56. //enum { DRAW_BUF_LEN = 2048 };
  57. //static WideChar drawBuf[ DRAW_BUF_LEN ];
  58. // PUBLIC DATA ////////////////////////////////////////////////////////////////
  59. // PRIVATE PROTOTYPES /////////////////////////////////////////////////////////
  60. ///////////////////////////////////////////////////////////////////////////////
  61. // PRIVATE FUNCTIONS //////////////////////////////////////////////////////////
  62. ///////////////////////////////////////////////////////////////////////////////
  63. #ifdef _INTERNAL
  64. // for occasional debugging...
  65. //#pragma optimize("", off)
  66. //#pragma MESSAGE("************************************** WARNING, optimization disabled for debugging purposes")
  67. #endif
  68. // drawStaticTextText =========================================================
  69. /** Draw the text for a static text window */
  70. //=============================================================================
  71. static void drawStaticTextText( GameWindow *window, WinInstanceData *instData,
  72. Color textColor, Color textDropColor )
  73. {
  74. TextData *tData = (TextData *)window->winGetUserData();
  75. Int textWidth, textHeight, wordWrap;
  76. DisplayString *text = tData->text;
  77. ICoord2D origin, size, textPos;
  78. IRegion2D clipRegion;
  79. // sanity
  80. if( text == NULL || text->getTextLength() == 0 )
  81. return;
  82. // get window position and size
  83. window->winGetScreenPosition( &origin.x, &origin.y );
  84. window->winGetSize( &size.x, &size.y );
  85. // Set the text Wrap width
  86. wordWrap = size.x - 10;
  87. //if(wordWrap == 89)
  88. // wordWrap = 95;
  89. text->setWordWrap(wordWrap);
  90. if( BitTest(window->winGetStatus(), WIN_STATUS_WRAP_CENTERED) )
  91. text->setWordWrapCentered(TRUE);
  92. else
  93. text->setWordWrapCentered(FALSE);
  94. if( BitTest( window->winGetStatus(), WIN_STATUS_HOTKEY_TEXT ) && TheGlobalData)
  95. text->setUseHotkey(TRUE, TheGlobalData->m_hotKeyTextColor);
  96. else
  97. text->setUseHotkey(FALSE, 0);
  98. // how much space will this text take up
  99. text->getSize( &textWidth, &textHeight );
  100. //Init the clip region
  101. clipRegion.lo.x = origin.x ;
  102. clipRegion.lo.y = origin.y ;
  103. clipRegion.hi.x = origin.x + size.x ;
  104. clipRegion.hi.y = origin.y + size.y;
  105. // horizontal centering?
  106. if( tData->centered )
  107. {
  108. textPos.x = origin.x + (size.x / 2) - (textWidth / 2);
  109. }
  110. else
  111. {
  112. textPos.x = origin.x + tData->leftMargin;
  113. }
  114. // vertical centering?
  115. if ( tData->centeredVertically )
  116. {
  117. textPos.y = origin.y + (size.y / 2) - (textHeight / 2);
  118. }
  119. else
  120. {
  121. textPos.y = origin.y + tData->topMargin;
  122. }
  123. // draw the text
  124. text->setClipRegion(&clipRegion);
  125. text->draw( textPos.x, textPos.y, textColor, textDropColor );
  126. } // end drawStaticTextText
  127. ///////////////////////////////////////////////////////////////////////////////
  128. // PUBLIC FUNCTIONS ///////////////////////////////////////////////////////////
  129. ///////////////////////////////////////////////////////////////////////////////
  130. // W3DGadgetStaticTextDraw ====================================================
  131. /** Draw colored text field using standard graphics */
  132. //=============================================================================
  133. void W3DGadgetStaticTextDraw( GameWindow *window, WinInstanceData *instData )
  134. {
  135. TextData *tData = (TextData *)window->winGetUserData();
  136. Color backColor, backBorder, textColor, textOutlineColor;
  137. ICoord2D size, origin, start, end;
  138. // get window position and size
  139. window->winGetScreenPosition( &origin.x, &origin.y );
  140. window->winGetSize( &size.x, &size.y );
  141. // get the colors we will use
  142. if( BitTest( window->winGetStatus(), WIN_STATUS_ENABLED ) == FALSE )
  143. {
  144. backColor = GadgetStaticTextGetDisabledColor( window );
  145. backBorder = GadgetStaticTextGetDisabledBorderColor( window );
  146. textColor = window->winGetDisabledTextColor();
  147. textOutlineColor = window->winGetDisabledTextBorderColor();
  148. } // end if, disabled
  149. else
  150. {
  151. backColor = GadgetStaticTextGetEnabledColor( window );
  152. backBorder = GadgetStaticTextGetEnabledBorderColor( window );
  153. textColor = window->winGetEnabledTextColor();
  154. textOutlineColor = window->winGetEnabledTextBorderColor();
  155. } // end else, enabled
  156. // draw the back border
  157. if( backBorder != WIN_COLOR_UNDEFINED )
  158. {
  159. start.x = origin.x;
  160. start.y = origin.y;
  161. end.x = start.x + size.x;
  162. end.y = start.y + size.y;
  163. TheWindowManager->winOpenRect( backBorder, WIN_DRAW_LINE_WIDTH,
  164. start.x, start.y, end.x, end.y );
  165. } // end if
  166. // draw the back fill area
  167. if( backColor != WIN_COLOR_UNDEFINED )
  168. {
  169. start.x = origin.x + 1;
  170. start.y = origin.y + 1;
  171. end.x = start.x + size.x - 2;
  172. end.y = start.y + size.y - 2;
  173. TheWindowManager->winFillRect( backColor, WIN_DRAW_LINE_WIDTH,
  174. start.x, start.y, end.x, end.y );
  175. } // end if
  176. // draw the text
  177. if( tData->text && (textColor != WIN_COLOR_UNDEFINED) )
  178. drawStaticTextText( window, instData, textColor, textOutlineColor );
  179. } // end W3DGadgetStaticTextDraw
  180. // W3DGadgetStaticTextImageDraw ===============================================
  181. /** Draw colored text field with user supplied images */
  182. //=============================================================================
  183. void W3DGadgetStaticTextImageDraw( GameWindow *window, WinInstanceData *instData )
  184. {
  185. TextData *tData = (TextData *)window->winGetUserData();
  186. Color textColor, textOutlineColor;
  187. ICoord2D size, origin, start, end;
  188. const Image *image;
  189. // get window position and size
  190. window->winGetScreenPosition( &origin.x, &origin.y );
  191. window->winGetSize( &size.x, &size.y );
  192. // get the colors we will use
  193. if( BitTest( window->winGetStatus(), WIN_STATUS_ENABLED ) == FALSE )
  194. {
  195. image = GadgetStaticTextGetDisabledImage( window );
  196. textColor = window->winGetDisabledTextColor();
  197. textOutlineColor = window->winGetDisabledTextBorderColor();
  198. } // end if, disabled
  199. else
  200. {
  201. image = GadgetStaticTextGetEnabledImage( window );
  202. textColor = window->winGetEnabledTextColor();
  203. textOutlineColor = window->winGetEnabledTextBorderColor();
  204. } // end else, enabled
  205. // draw the back image
  206. if( image )
  207. {
  208. start.x = origin.x + instData->m_imageOffset.x;
  209. start.y = origin.y + instData->m_imageOffset.y;
  210. end.x = start.x + size.x;
  211. end.y = start.y + size.y;
  212. TheWindowManager->winDrawImage( image, start.x, start.y, end.x, end.y );
  213. } // end if
  214. // draw the text
  215. if( tData->text && (textColor != WIN_COLOR_UNDEFINED) )
  216. drawStaticTextText( window, instData, textColor, textOutlineColor );
  217. } // end W3DGadgetStaticTextImageDraw