W3DRadioButton.cpp 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387
  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: W3DRadioButton.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: W3DRadioButton.cpp
  36. //
  37. // Created: Colin Day, June 2001
  38. //
  39. // Desc: W3D methods needed to implement the RadioButton UI control
  40. //
  41. //-----------------------------------------------------------------------------
  42. ///////////////////////////////////////////////////////////////////////////////
  43. // SYSTEM INCLUDES ////////////////////////////////////////////////////////////
  44. #include <stdlib.h>
  45. // USER INCLUDES //////////////////////////////////////////////////////////////
  46. #include "GameClient/GameWindowGlobal.h"
  47. #include "GameClient/GameWindowManager.h"
  48. #include "GameClient/GadgetRadioButton.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. // drawRadioButtonText ========================================================
  57. /** Draw the text for a RadioButton */
  58. //=============================================================================
  59. static void drawRadioButtonText( 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. // set the location for our text
  93. textPos.x = origin.x + (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 drawRadioButtonText
  98. // PRIVATE FUNCTIONS //////////////////////////////////////////////////////////
  99. ///////////////////////////////////////////////////////////////////////////////
  100. // PUBLIC FUNCTIONS ///////////////////////////////////////////////////////////
  101. ///////////////////////////////////////////////////////////////////////////////
  102. // W3DGadgetRadioButtonDraw ===================================================
  103. /** Draw colored check box using standard graphics */
  104. //=============================================================================
  105. void W3DGadgetRadioButtonDraw( 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 GadgetRadioButton.h
  120. // draw appropriate state, see GadgetRadioButton.h for info
  121. //
  122. if( BitTest( window->winGetStatus(), WIN_STATUS_ENABLED ) == FALSE )
  123. {
  124. // disabled background
  125. backColor = GadgetRadioGetDisabledColor( window );
  126. backBorder = GadgetRadioGetDisabledBorderColor( window );
  127. // check box
  128. if( BitTest( instData->getState(), WIN_STATE_SELECTED ) )
  129. {
  130. boxColor = GadgetRadioGetDisabledCheckedBoxColor( window );
  131. boxBorder = GadgetRadioGetDisabledCheckedBoxBorderColor( window );
  132. }
  133. else
  134. {
  135. boxColor = GadgetRadioGetDisabledUncheckedBoxColor( window );
  136. boxBorder = GadgetRadioGetDisabledUncheckedBoxBorderColor( window );
  137. }
  138. } // end if
  139. else if( BitTest( instData->getState(), WIN_STATE_HILITED ) )
  140. {
  141. // hilited background
  142. backColor = GadgetRadioGetHiliteColor( window );
  143. backBorder = GadgetRadioGetHiliteBorderColor( window );
  144. // check box
  145. if( BitTest( instData->getState(), WIN_STATE_SELECTED ) )
  146. {
  147. boxColor = GadgetRadioGetHiliteCheckedBoxColor( window );
  148. boxBorder = GadgetRadioGetHiliteCheckedBoxBorderColor( window );
  149. }
  150. else
  151. {
  152. boxColor = GadgetRadioGetHiliteUncheckedBoxColor( window );
  153. boxBorder = GadgetRadioGetHiliteUncheckedBoxBorderColor( window );
  154. }
  155. } // end else if
  156. else
  157. {
  158. // enabled background
  159. backColor = GadgetRadioGetEnabledColor( window );
  160. backBorder = GadgetRadioGetEnabledBorderColor( window );
  161. // check box
  162. if( BitTest( instData->getState(), WIN_STATE_SELECTED ) )
  163. {
  164. boxColor = GadgetRadioGetEnabledCheckedBoxColor( window );
  165. boxBorder = GadgetRadioGetEnabledCheckedBoxBorderColor( window );
  166. }
  167. else
  168. {
  169. boxColor = GadgetRadioGetEnabledUncheckedBoxColor( window );
  170. boxBorder = GadgetRadioGetEnabledUncheckedBoxBorderColor( 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 + size.y;
  189. start.y = origin.y;
  190. end.x = start.x;
  191. end.y = start.y + size.y;
  192. TheWindowManager->winDrawLine( backBorder, WIN_DRAW_LINE_WIDTH,
  193. start.x, start.y, end.x, end.y );
  194. // draw box for button
  195. start.x = origin.x + 1;
  196. start.y = origin.y + 1;
  197. end.x = origin.x + size.y -1;
  198. end.y = origin.y + size.y -1;
  199. TheWindowManager->winFillRect( boxColor, WIN_DRAW_LINE_WIDTH,
  200. start.x, start.y, end.x, end.y );
  201. // draw box border
  202. start.x = origin.x + size.x - size.y;
  203. start.y = origin.y;
  204. end.x = start.x;
  205. end.y = start.y + size.y;
  206. TheWindowManager->winDrawLine( backBorder, WIN_DRAW_LINE_WIDTH,
  207. start.x, start.y, end.x, end.y );
  208. // draw box for button
  209. start.x = origin.x + size.x - size.y;
  210. start.y = origin.y + 1;
  211. end.x = origin.x + size.x -1;
  212. end.y = origin.y + size.y -1;
  213. TheWindowManager->winFillRect( boxColor, WIN_DRAW_LINE_WIDTH,
  214. start.x, start.y, end.x, end.y );
  215. // draw the button text
  216. if( instData->getTextLength() )
  217. drawRadioButtonText( window, instData );
  218. } // end W3DGadgetRadioButtonDraw
  219. void W3DGadgetRadioButtonImageDraw( GameWindow *window,
  220. WinInstanceData *instData )
  221. {
  222. const Image *leftImage, *rightImage, *centerImage;
  223. ICoord2D origin, size, start, end;
  224. Int xOffset, yOffset;
  225. Int i;
  226. // get screen position and size
  227. window->winGetScreenPosition( &origin.x, &origin.y );
  228. window->winGetSize( &size.x, &size.y );
  229. IRegion2D clipLeft;
  230. // get image offset
  231. xOffset = instData->m_imageOffset.x;
  232. yOffset = instData->m_imageOffset.y;
  233. if( BitTest( instData->getState(), WIN_STATE_SELECTED ) )
  234. {
  235. //backgroundImage = GadgetRadioGetEnabledCheckedBoxImage( window );
  236. leftImage = GadgetRadioGetSelectedImage( window );
  237. centerImage = GadgetRadioGetSelectedUncheckedBoxImage( window );
  238. rightImage = GadgetRadioGetSelectedCheckedBoxImage( window );
  239. }
  240. else if( BitTest( window->winGetStatus(), WIN_STATUS_ENABLED ) == FALSE )
  241. {
  242. // disabled background
  243. leftImage = GadgetRadioGetDisabledImage( window );
  244. centerImage = GadgetRadioGetDisabledUncheckedBoxImage( window );
  245. rightImage = GadgetRadioGetDisabledCheckedBoxImage( window );
  246. } // end if
  247. else if( BitTest( instData->getState(), WIN_STATE_HILITED ) )
  248. {
  249. // hilited background
  250. leftImage = GadgetRadioGetHiliteImage( window );
  251. centerImage = GadgetRadioGetHiliteUncheckedBoxImage( window );
  252. rightImage = GadgetRadioGetHiliteCheckedBoxImage( window );
  253. } // end else if
  254. else
  255. {
  256. // enabled background
  257. leftImage = GadgetRadioGetEnabledImage( window );
  258. centerImage = GadgetRadioGetEnabledUncheckedBoxImage( window );
  259. rightImage = GadgetRadioGetEnabledCheckedBoxImage( window );
  260. } // end else
  261. // sanity, we need to have these images to make it look right
  262. if( leftImage == NULL || centerImage == NULL ||
  263. rightImage == NULL )
  264. return;
  265. // get image sizes for the ends
  266. ICoord2D leftSize, rightSize;
  267. leftSize.x = leftImage->getImageWidth();
  268. leftSize.y = leftImage->getImageHeight();
  269. rightSize.x = rightImage->getImageWidth();
  270. rightSize.y = rightImage->getImageHeight();
  271. // get two key points used in the end drawing
  272. ICoord2D leftEnd, rightStart;
  273. leftEnd.x = origin.x + leftSize.x + xOffset;
  274. leftEnd.y = origin.y + size.y + yOffset;
  275. rightStart.x = origin.x + size.x - rightSize.x + xOffset;
  276. rightStart.y = origin.y + size.y + yOffset;
  277. // draw the center repeating bar
  278. Int centerWidth, pieces;
  279. // get width we have to draw our repeating center in
  280. centerWidth = rightStart.x - leftEnd.x;
  281. // how many whole repeating pieces will fit in that width
  282. pieces = centerWidth / centerImage->getImageWidth();
  283. pieces++;
  284. // draw the pieces
  285. start.x = leftEnd.x;
  286. start.y = origin.y + yOffset;
  287. end.y =origin.y + size.y + yOffset;
  288. clipLeft.lo.x = leftEnd.x;
  289. clipLeft.lo.y = origin.y;
  290. clipLeft.hi.y = leftEnd.y;
  291. clipLeft.hi.x = rightStart.x ;
  292. TheDisplay->setClipRegion(&clipLeft);
  293. for( i = 0; i < pieces; i++ )
  294. {
  295. end.x = start.x + centerImage->getImageWidth();
  296. TheWindowManager->winDrawImage( centerImage,
  297. start.x, start.y,
  298. end.x, end.y );
  299. start.x += centerImage->getImageWidth();
  300. } // end for i
  301. TheDisplay->enableClipping(FALSE);
  302. // draw left end
  303. start.x = origin.x + xOffset;
  304. start.y = origin.y + yOffset;
  305. end = leftEnd;
  306. TheWindowManager->winDrawImage(leftImage, start.x, start.y, end.x, end.y);
  307. // draw right end
  308. start.x = rightStart.x;
  309. start.y = origin.y + yOffset;
  310. end.x = origin.x + size.x;
  311. end.y = leftEnd.y;
  312. TheWindowManager->winDrawImage(rightImage, start.x, start.y, end.x, end.y);
  313. // draw the text
  314. if( instData->getTextLength() )
  315. drawRadioButtonText( window, instData );
  316. } // end W3DGadgetHorizontalSliderImageDraw