W3DStaticText.cpp 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. /*
  2. ** Command & Conquer Generals(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. if( tData->centered )
  106. {
  107. textPos.x = origin.x + (size.x / 2) - (textWidth / 2);
  108. textPos.y = origin.y + (size.y / 2) - (textHeight / 2);
  109. text->setClipRegion(&clipRegion);
  110. text->draw( textPos.x, textPos.y, textColor, textDropColor );
  111. } // end if
  112. else
  113. {
  114. // draw the text
  115. textPos.x = origin.x + 7;
  116. textPos.y = origin.y + (size.y / 2) - (textHeight / 2);
  117. text->setClipRegion(&clipRegion);
  118. text->draw( textPos.x, textPos.y, textColor, textDropColor );
  119. } // end else
  120. } // end drawStaticTextText
  121. ///////////////////////////////////////////////////////////////////////////////
  122. // PUBLIC FUNCTIONS ///////////////////////////////////////////////////////////
  123. ///////////////////////////////////////////////////////////////////////////////
  124. // W3DGadgetStaticTextDraw ====================================================
  125. /** Draw colored text field using standard graphics */
  126. //=============================================================================
  127. void W3DGadgetStaticTextDraw( GameWindow *window, WinInstanceData *instData )
  128. {
  129. TextData *tData = (TextData *)window->winGetUserData();
  130. Color backColor, backBorder, textColor, textOutlineColor;
  131. ICoord2D size, origin, start, end;
  132. // get window position and size
  133. window->winGetScreenPosition( &origin.x, &origin.y );
  134. window->winGetSize( &size.x, &size.y );
  135. // get the colors we will use
  136. if( BitTest( window->winGetStatus(), WIN_STATUS_ENABLED ) == FALSE )
  137. {
  138. backColor = GadgetStaticTextGetDisabledColor( window );
  139. backBorder = GadgetStaticTextGetDisabledBorderColor( window );
  140. textColor = window->winGetDisabledTextColor();
  141. textOutlineColor = window->winGetDisabledTextBorderColor();
  142. } // end if, disabled
  143. else
  144. {
  145. backColor = GadgetStaticTextGetEnabledColor( window );
  146. backBorder = GadgetStaticTextGetEnabledBorderColor( window );
  147. textColor = window->winGetEnabledTextColor();
  148. textOutlineColor = window->winGetEnabledTextBorderColor();
  149. } // end else, enabled
  150. // draw the back border
  151. if( backBorder != WIN_COLOR_UNDEFINED )
  152. {
  153. start.x = origin.x;
  154. start.y = origin.y;
  155. end.x = start.x + size.x;
  156. end.y = start.y + size.y;
  157. TheWindowManager->winOpenRect( backBorder, WIN_DRAW_LINE_WIDTH,
  158. start.x, start.y, end.x, end.y );
  159. } // end if
  160. // draw the back fill area
  161. if( backColor != WIN_COLOR_UNDEFINED )
  162. {
  163. start.x = origin.x + 1;
  164. start.y = origin.y + 1;
  165. end.x = start.x + size.x - 2;
  166. end.y = start.y + size.y - 2;
  167. TheWindowManager->winFillRect( backColor, WIN_DRAW_LINE_WIDTH,
  168. start.x, start.y, end.x, end.y );
  169. } // end if
  170. // draw the text
  171. if( tData->text && (textColor != WIN_COLOR_UNDEFINED) )
  172. drawStaticTextText( window, instData, textColor, textOutlineColor );
  173. } // end W3DGadgetStaticTextDraw
  174. // W3DGadgetStaticTextImageDraw ===============================================
  175. /** Draw colored text field with user supplied images */
  176. //=============================================================================
  177. void W3DGadgetStaticTextImageDraw( GameWindow *window, WinInstanceData *instData )
  178. {
  179. TextData *tData = (TextData *)window->winGetUserData();
  180. Color textColor, textOutlineColor;
  181. ICoord2D size, origin, start, end;
  182. const Image *image;
  183. // get window position and size
  184. window->winGetScreenPosition( &origin.x, &origin.y );
  185. window->winGetSize( &size.x, &size.y );
  186. // get the colors we will use
  187. if( BitTest( window->winGetStatus(), WIN_STATUS_ENABLED ) == FALSE )
  188. {
  189. image = GadgetStaticTextGetDisabledImage( window );
  190. textColor = window->winGetDisabledTextColor();
  191. textOutlineColor = window->winGetDisabledTextBorderColor();
  192. } // end if, disabled
  193. else
  194. {
  195. image = GadgetStaticTextGetEnabledImage( window );
  196. textColor = window->winGetEnabledTextColor();
  197. textOutlineColor = window->winGetEnabledTextBorderColor();
  198. } // end else, enabled
  199. // draw the back image
  200. if( image )
  201. {
  202. start.x = origin.x + instData->m_imageOffset.x;
  203. start.y = origin.y + instData->m_imageOffset.y;
  204. end.x = start.x + size.x;
  205. end.y = start.y + size.y;
  206. TheWindowManager->winDrawImage( image, start.x, start.y, end.x, end.y );
  207. } // end if
  208. // draw the text
  209. if( tData->text && (textColor != WIN_COLOR_UNDEFINED) )
  210. drawStaticTextText( window, instData, textColor, textOutlineColor );
  211. } // end W3DGadgetStaticTextImageDraw