W3DCheckBox.cpp 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  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: W3DCheckBox.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: W3DCheckBox.cpp
  36. //
  37. // Created: Colin Day, June 2001
  38. //
  39. // Desc: W3D methods needed to implement the checkbox UI control
  40. //
  41. //-----------------------------------------------------------------------------
  42. ///////////////////////////////////////////////////////////////////////////////
  43. // SYSTEM INCLUDES ////////////////////////////////////////////////////////////
  44. #include <stdlib.h>
  45. // USER INCLUDES //////////////////////////////////////////////////////////////
  46. #include "GameClient/GadgetCheckBox.h"
  47. #include "GameClient/GameWindowGlobal.h"
  48. #include "GameClient/GameWindowManager.h"
  49. #include "W3DDevice/GameClient/W3DGadget.h"
  50. #include "W3DDevice/GameClient/W3DDisplay.h"
  51. // DEFINES ////////////////////////////////////////////////////////////////////
  52. // PRIVATE TYPES //////////////////////////////////////////////////////////////
  53. // PRIVATE DATA ///////////////////////////////////////////////////////////////
  54. // PUBLIC DATA ////////////////////////////////////////////////////////////////
  55. // PRIVATE PROTOTYPES /////////////////////////////////////////////////////////
  56. // drawCheckBoxText ===========================================================
  57. /** Draw the text for a checkbox */
  58. //=============================================================================
  59. static void drawCheckBoxText( GameWindow *window, WinInstanceData *instData )
  60. {
  61. ICoord2D origin, size, textPos;
  62. Int width, height;
  63. Color textColor, dropColor;
  64. DisplayString *text = instData->getTextDisplayString();
  65. // sanity
  66. if( text == NULL || text->getTextLength() == 0 )
  67. return;
  68. // get window position and size
  69. window->winGetScreenPosition( &origin.x, &origin.y );
  70. window->winGetSize( &size.x, &size.y );
  71. // get the right text color
  72. if( BitTest( window->winGetStatus(), WIN_STATUS_ENABLED ) == FALSE )
  73. {
  74. textColor = window->winGetDisabledTextColor();
  75. dropColor = window->winGetDisabledTextBorderColor();
  76. } // end if, disabled
  77. else if( BitTest( instData->getState(), WIN_STATE_HILITED ) )
  78. {
  79. textColor = window->winGetHiliteTextColor();
  80. dropColor = window->winGetHiliteTextBorderColor();
  81. } // end else if, hilited
  82. else
  83. {
  84. textColor = window->winGetEnabledTextColor();
  85. dropColor = window->winGetEnabledTextBorderColor();
  86. } // end enabled only
  87. // set our font to that of our parent if not the same
  88. if( text->getFont() != window->winGetFont() )
  89. text->setFont( window->winGetFont() );
  90. // get text size
  91. text->getSize( &width, &height );
  92. // where to draw
  93. textPos.x = origin.x + size.y;//(size.x / 2) - (width / 2);
  94. textPos.y = origin.y + (size.y / 2) - (height / 2);
  95. // draw it
  96. text->draw( textPos.x, textPos.y, textColor, dropColor );
  97. } // end drawCheckBoxText
  98. // PRIVATE FUNCTIONS //////////////////////////////////////////////////////////
  99. ///////////////////////////////////////////////////////////////////////////////
  100. // PUBLIC FUNCTIONS ///////////////////////////////////////////////////////////
  101. ///////////////////////////////////////////////////////////////////////////////
  102. // W3DGadgetCheckBoxDraw ======================================================
  103. /** Draw colored check box using standard graphics */
  104. //=============================================================================
  105. void W3DGadgetCheckBoxDraw( GameWindow *window, WinInstanceData *instData )
  106. {
  107. Int checkOffsetFromLeft;
  108. Color backColor,
  109. backBorder,
  110. boxColor,
  111. boxBorder;
  112. ICoord2D origin, size, start, end;
  113. // get window position and size
  114. window->winGetScreenPosition( &origin.x, &origin.y );
  115. window->winGetSize( &size.x, &size.y );
  116. // compute start of check offset
  117. checkOffsetFromLeft = size.x / 16;
  118. //
  119. // get the colors we should be using to draw, see GadgetCheckBox.h
  120. // draw appropriate state, see GadgetCheckBox.h for info
  121. //
  122. if( BitTest( window->winGetStatus(), WIN_STATUS_ENABLED ) == FALSE )
  123. {
  124. // disabled background
  125. backColor = GadgetCheckBoxGetDisabledColor( window );
  126. backBorder = GadgetCheckBoxGetDisabledBorderColor( window );
  127. // check box
  128. if( BitTest( instData->getState(), WIN_STATE_SELECTED ) )
  129. {
  130. boxColor = GadgetCheckBoxGetDisabledCheckedBoxColor( window );
  131. boxBorder = GadgetCheckBoxGetDisabledCheckedBoxBorderColor( window );
  132. }
  133. else
  134. {
  135. boxColor = GadgetCheckBoxGetDisabledUncheckedBoxColor( window );
  136. boxBorder = GadgetCheckBoxGetDisabledUncheckedBoxBorderColor( window );
  137. }
  138. } // end if
  139. else if( BitTest( instData->getState(), WIN_STATE_HILITED ) )
  140. {
  141. // hilited background
  142. backColor = GadgetCheckBoxGetHiliteColor( window );
  143. backBorder = GadgetCheckBoxGetHiliteBorderColor( window );
  144. // check box
  145. if( BitTest( instData->getState(), WIN_STATE_SELECTED ) )
  146. {
  147. boxColor = GadgetCheckBoxGetHiliteCheckedBoxColor( window );
  148. boxBorder = GadgetCheckBoxGetHiliteCheckedBoxBorderColor( window );
  149. }
  150. else
  151. {
  152. boxColor = GadgetCheckBoxGetHiliteUncheckedBoxColor( window );
  153. boxBorder = GadgetCheckBoxGetHiliteUncheckedBoxBorderColor( window );
  154. }
  155. } // end else if
  156. else
  157. {
  158. // enabled background
  159. backColor = GadgetCheckBoxGetEnabledColor( window );
  160. backBorder = GadgetCheckBoxGetEnabledBorderColor( window );
  161. // check box
  162. if( BitTest( instData->getState(), WIN_STATE_SELECTED ) )
  163. {
  164. boxColor = GadgetCheckBoxGetEnabledCheckedBoxColor( window );
  165. boxBorder = GadgetCheckBoxGetEnabledCheckedBoxBorderColor( window );
  166. }
  167. else
  168. {
  169. boxColor = GadgetCheckBoxGetEnabledUncheckedBoxColor( window );
  170. boxBorder = GadgetCheckBoxGetEnabledUncheckedBoxBorderColor( window );
  171. }
  172. } // end else
  173. // draw background border
  174. start.x = origin.x;
  175. start.y = origin.y;
  176. end.x = start.x + size.x;
  177. end.y = start.y + size.y;
  178. TheWindowManager->winOpenRect( backBorder, WIN_DRAW_LINE_WIDTH,
  179. start.x, start.y, end.x, end.y );
  180. // draw the background
  181. start.x++;
  182. start.y++;
  183. end.x--;
  184. end.y--;
  185. TheWindowManager->winFillRect( backColor, WIN_DRAW_LINE_WIDTH,
  186. start.x, start.y, end.x, end.y );
  187. // draw box border
  188. start.x = origin.x + checkOffsetFromLeft;
  189. start.y = origin.y + (size.y / 3);
  190. end.x = start.x + (size.y / 3);
  191. end.y = start.y + (size.y / 3);
  192. TheWindowManager->winOpenRect( boxBorder, WIN_DRAW_LINE_WIDTH,
  193. start.x, start.y, end.x, end.y );
  194. // draw "x" for button
  195. if( boxColor != WIN_COLOR_UNDEFINED )
  196. {
  197. TheWindowManager->winDrawLine( boxColor, WIN_DRAW_LINE_WIDTH,
  198. start.x, start.y, end.x, end.y );
  199. TheWindowManager->winDrawLine( boxColor, WIN_DRAW_LINE_WIDTH,
  200. start.x, end.y, end.x, start.y );
  201. } // end if
  202. // draw the button text
  203. if( instData->getTextLength() )
  204. drawCheckBoxText( window, instData );
  205. } // end W3DGadgetCheckBoxDraw
  206. // W3DGadgetCheckBoxImageDraw =================================================
  207. /** Draw check box with user supplied images */
  208. //=============================================================================
  209. void W3DGadgetCheckBoxImageDraw( GameWindow *window, WinInstanceData *instData )
  210. {
  211. Int checkOffsetFromLeft;
  212. const Image *boxImage = NULL;//*backgroundImage = NULL,
  213. ICoord2D origin, start, end, size;
  214. // get window position and size
  215. window->winGetScreenPosition( &origin.x, &origin.y );
  216. window->winGetSize( &size.x, &size.y );
  217. // compute screen coords
  218. start.x = origin.x + instData->m_imageOffset.x;
  219. start.y = origin.y + instData->m_imageOffset.y;
  220. end.x = start.x + size.x;
  221. end.y = start.y + size.y;
  222. // compute start of check offset
  223. checkOffsetFromLeft = 0;
  224. //
  225. // get the colors we should be using to draw, see GadgetCheckBoxButton.h
  226. // draw appropriate state, see GadgetCheckBoxButton.h for info
  227. //
  228. if( BitTest( window->winGetStatus(), WIN_STATUS_ENABLED ) == FALSE )
  229. {
  230. // disabled background
  231. // backgroundImage = GadgetCheckBoxGetDisabledImage( window );
  232. // check box
  233. if( BitTest( instData->getState(), WIN_STATE_SELECTED ) )
  234. boxImage = GadgetCheckBoxGetDisabledCheckedBoxImage( window );
  235. else
  236. boxImage = GadgetCheckBoxGetDisabledUncheckedBoxImage( window );
  237. } // end if
  238. else if( BitTest( instData->getState(), WIN_STATE_HILITED ) )
  239. {
  240. // hilited background
  241. // backgroundImage = GadgetCheckBoxGetHiliteImage( window );
  242. // check box
  243. if( BitTest( instData->getState(), WIN_STATE_SELECTED ) )
  244. boxImage = GadgetCheckBoxGetHiliteCheckedBoxImage( window );
  245. else
  246. boxImage = GadgetCheckBoxGetHiliteUncheckedBoxImage( window );
  247. } // end else if
  248. else
  249. {
  250. // enabled background
  251. // backgroundImage = GadgetCheckBoxGetEnabledImage( window );
  252. // check box
  253. if( BitTest( instData->getState(), WIN_STATE_SELECTED ) )
  254. boxImage = GadgetCheckBoxGetEnabledCheckedBoxImage( window );
  255. else
  256. boxImage = GadgetCheckBoxGetEnabledUncheckedBoxImage( window );
  257. } // end else
  258. // draw background image
  259. // if( backgroundImage )
  260. // TheWindowManager->winDrawImage( backgroundImage, start.x, start.y,
  261. // end.x, end.y );
  262. // draw the box image
  263. if( boxImage )
  264. {
  265. start.x = origin.x + instData->m_imageOffset.x + checkOffsetFromLeft;
  266. start.y = origin.y + 3;
  267. end.x = start.x + (size.y - 6);
  268. end.y = start.y + (size.y - 6);
  269. TheWindowManager->winDrawImage( boxImage, start.x, start.y,
  270. end.x, end.y );
  271. } // end if
  272. // draw the text
  273. if( instData->getTextLength() )
  274. drawCheckBoxText( window, instData );
  275. } // end W3DGadgetCheckBoxImageDraw