IMECandidate.cpp 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  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: IMECandidate.cpp /////////////////////////////////////////////////////////////////////////
  24. // Author: TR November 2001
  25. // Desc: IME Candidate window callbacks
  26. ///////////////////////////////////////////////////////////////////////////////////////////////////
  27. // INCLUDES ///////////////////////////////////////////////////////////////////////////////////////
  28. #include "PreRTS.h" // This must go first in EVERY cpp file int the GameEngine
  29. #include "GameClient/GameWindow.h"
  30. #include "GameClient/Gadget.h"
  31. #include "GameClient/IMEManager.h"
  32. #include "GameClient/GameWindowManager.h"
  33. #include "GameClient/DisplayString.h"
  34. #include "GameClient/DisplayStringManager.h"
  35. Int IMECandidateWindowLineSpacing = 2;
  36. static DisplayString *Dstring = NULL;
  37. //-------------------------------------------------------------------------------------------------
  38. /** Input procedure for the candidate window */
  39. //-------------------------------------------------------------------------------------------------
  40. WindowMsgHandledType IMECandidateWindowInput( GameWindow *window, UnsignedInt msg,
  41. WindowMsgData mData1, WindowMsgData mData2 )
  42. {
  43. return MSG_HANDLED;
  44. } // end IMECandidateInput
  45. //-------------------------------------------------------------------------------------------------
  46. /** System callback for the IME Candidate widnow */
  47. //-------------------------------------------------------------------------------------------------
  48. WindowMsgHandledType IMECandidateWindowSystem( GameWindow *window, UnsignedInt msg,
  49. WindowMsgData mData1, WindowMsgData mData2 )
  50. {
  51. switch( msg )
  52. {
  53. case GWM_CREATE:
  54. if ( Dstring == NULL )
  55. {
  56. Dstring = TheDisplayStringManager->newDisplayString();
  57. }
  58. break;
  59. case GWM_DESTROY:
  60. if ( Dstring != NULL )
  61. {
  62. TheDisplayStringManager->freeDisplayString( Dstring );
  63. Dstring = NULL;
  64. }
  65. break;
  66. //---------------------------------------------------------------------------------------------
  67. default:
  68. return MSG_IGNORED;
  69. } // end switch( msg )
  70. return MSG_HANDLED;
  71. } // end IMECandidateWidnowSystem
  72. // IMECandidateDraw ================================================================
  73. /** Draw function for the IME candidate window */
  74. //=============================================================================
  75. void IMECandidateTextAreaDraw( GameWindow *window, WinInstanceData *instData )
  76. {
  77. // set up for rendering
  78. ICoord2D origin, size, start, end;
  79. Color textColor,
  80. textBorder,
  81. textSelectColor,
  82. textSelectBorder;
  83. IRegion2D textRegion;
  84. Color black = GameMakeColor( 0, 0, 0, 255);
  85. // get window position and size
  86. window->winGetScreenPosition( &origin.x, &origin.y );
  87. window->winGetSize( &size.x, &size.y );
  88. // get a nice region from the positions
  89. textRegion.lo.x = origin.x;
  90. textRegion.lo.y = origin.y;
  91. textRegion.hi.x = origin.x + size.x;
  92. textRegion.hi.y = origin.y + size.y;
  93. // get the right colors for drawing
  94. if( BitTest( window->winGetStatus(), WIN_STATUS_ENABLED ) == FALSE )
  95. {
  96. textSelectColor = window->winGetDisabledTextColor();
  97. textSelectBorder = window->winGetDisabledTextBorderColor();
  98. textColor = window->winGetDisabledTextColor();
  99. textBorder = window->winGetDisabledTextBorderColor();
  100. } // end if, disabled
  101. else if( BitTest( instData->getState(), WIN_STATE_HILITED ) )
  102. {
  103. textColor = window->winGetEnabledTextColor();
  104. textBorder = window->winGetEnabledTextBorderColor();
  105. textSelectColor = window->winGetHiliteTextColor();
  106. textSelectBorder = window->winGetHiliteTextBorderColor();
  107. } // end else if, hilited
  108. else
  109. {
  110. textSelectColor = window->winGetHiliteTextColor();
  111. textSelectBorder = window->winGetHiliteTextBorderColor();
  112. textColor = window->winGetEnabledTextColor();
  113. textBorder = window->winGetEnabledTextBorderColor();
  114. } // end else, just enabled
  115. {
  116. Real borderWidth = 1.0f;
  117. start.x = origin.x;
  118. start.y = origin.y;
  119. end.x = start.x + size.x;
  120. end.y = start.y + size.y;
  121. TheWindowManager->winOpenRect( black, borderWidth,
  122. start.x, start.y, end.x, end.y );
  123. }
  124. if ( Dstring == NULL )
  125. {
  126. return;
  127. }
  128. IMEManagerInterface *ime = (IMEManagerInterface*)window->winGetUserData();
  129. if ( ime == NULL )
  130. {
  131. return;
  132. }
  133. GameFont *font = window->winGetFont() ;
  134. Int height;
  135. // set the font
  136. Dstring->setFont( font );
  137. // cacl line height
  138. height = font->height + IMECandidateWindowLineSpacing;
  139. // set the clip region
  140. Dstring->setClipRegion( &textRegion );
  141. Int first = ime->getCandidatePageStart();
  142. Int total = ime->getCandidateCount();
  143. Int pageSize = ime->getCandidatePageSize();
  144. Int selected = ime->getSelectedCandidateIndex();
  145. Int count = pageSize;
  146. if ( count + first > total )
  147. {
  148. count = total - first;
  149. }
  150. selected = selected - first;
  151. UnicodeString number;
  152. // calulate the widest number text
  153. Int width;
  154. Dstring->setText(UnicodeString(L"00:"));
  155. width = Dstring->getWidth();
  156. // calc y start pos
  157. Int y = origin.y;
  158. Int leftEdge = origin.x + 10 + width;
  159. for ( Int i = 0; i < count; i++, y+= height )
  160. {
  161. UnicodeString *candidate = ime->getCandidate( first + i );
  162. Int tcolor, bcolor;
  163. if ( i == selected )
  164. {
  165. tcolor = textSelectColor;
  166. bcolor = textSelectBorder;
  167. }
  168. else
  169. {
  170. tcolor = textColor;
  171. bcolor = textBorder;
  172. }
  173. // draw number tab first
  174. number.format( L"%d:", i + ime->getIndexBase());
  175. Dstring->setText( number );
  176. width = Dstring->getWidth();
  177. Dstring->draw( leftEdge - width, y, tcolor, black);
  178. // draw candidate
  179. Dstring->setText( *candidate );
  180. Dstring->draw( leftEdge, y, tcolor, black );
  181. }
  182. }
  183. // IMECandidateDraw ================================================================
  184. /** Draw function for the IME candidate window */
  185. //=============================================================================
  186. void IMECandidateMainDraw( GameWindow *window, WinInstanceData *instData )
  187. {
  188. // set up for rendering
  189. ICoord2D origin, size, start, end;
  190. Color backColor,
  191. backBorder;
  192. Real borderWidth = 1.0f;
  193. // get window position and size
  194. window->winGetScreenPosition( &origin.x, &origin.y );
  195. window->winGetSize( &size.x, &size.y );
  196. // get the right colors for drawing
  197. if( BitTest( window->winGetStatus(), WIN_STATUS_ENABLED ) == FALSE )
  198. {
  199. backColor = window->winGetDisabledColor( 0 );
  200. backBorder = window->winGetDisabledBorderColor( 0 );
  201. } // end if, disabled
  202. else if( BitTest( instData->getState(), WIN_STATE_HILITED ) )
  203. {
  204. backColor = window->winGetHiliteColor( 0 );
  205. backBorder = window->winGetHiliteBorderColor( 0 );
  206. } // end else if, hilited
  207. else
  208. {
  209. backColor = window->winGetEnabledColor( 0 );
  210. backBorder = window->winGetEnabledBorderColor( 0 );
  211. } // end else, just enabled
  212. // draw the back border
  213. if( backBorder != WIN_COLOR_UNDEFINED )
  214. {
  215. start.x = origin.x;
  216. start.y = origin.y;
  217. end.x = start.x + size.x;
  218. end.y = start.y + size.y;
  219. TheWindowManager->winOpenRect( backBorder, borderWidth,
  220. start.x, start.y, end.x, end.y );
  221. } // end if
  222. // draw the filled back
  223. if( backColor != WIN_COLOR_UNDEFINED )
  224. {
  225. start.x = origin.x + 1;
  226. start.y = origin.y + 1;
  227. end.x = start.x + size.x - 2;
  228. end.y = start.y + size.y - 2;
  229. TheWindowManager->winFillRect( backColor, 0, start.x, start.y, end.x, end.y );
  230. } // end if
  231. }