W3DComboBox.cpp 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  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: W3DComboBox.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: W3DComboBox.cpp
  36. //
  37. // Created: Colin Day, June 2001
  38. //
  39. // Desc: W3D implementation for the Combo box 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/GadgetComboBox.h"
  49. #include "GameClient/GadgetListBox.h"
  50. #include "W3DDevice/GameClient/W3DGadget.h"
  51. #include "W3DDevice/GameClient/W3DDisplay.h"
  52. // DEFINES ////////////////////////////////////////////////////////////////////
  53. // PRIVATE TYPES //////////////////////////////////////////////////////////////
  54. // PRIVATE DATA ///////////////////////////////////////////////////////////////
  55. // PUBLIC DATA ////////////////////////////////////////////////////////////////
  56. // PRIVATE PROTOTYPES /////////////////////////////////////////////////////////
  57. ///////////////////////////////////////////////////////////////////////////////
  58. // PRIVATE FUNCTIONS //////////////////////////////////////////////////////////
  59. ///////////////////////////////////////////////////////////////////////////////
  60. ///////////////////////////////////////////////////////////////////////////////
  61. // PUBLIC FUNCTIONS ///////////////////////////////////////////////////////////
  62. ///////////////////////////////////////////////////////////////////////////////
  63. // W3DGadgetComboBoxDraw =======================================================
  64. /** Draw colored list box using standard graphics */
  65. //=============================================================================
  66. void W3DGadgetComboBoxDraw( GameWindow *window, WinInstanceData *instData )
  67. {
  68. Int width, height, fontHeight, x, y;
  69. Color background, border, titleColor, titleBorder;
  70. // ComboBoxData *combo = (ComboBoxData *)window->winGetUserData();
  71. ICoord2D size;
  72. DisplayString *title = instData->getTextDisplayString();
  73. // get window position and size
  74. window->winGetScreenPosition( &x, &y );
  75. window->winGetSize( &size.x, &size.y );
  76. // get font height
  77. fontHeight = TheWindowManager->winFontHeight( instData->getFont() );
  78. // alias width and height from size
  79. width = size.x;
  80. height = size.y;
  81. // get the right colors
  82. if( BitTest( window->winGetStatus(), WIN_STATUS_ENABLED ) == FALSE )
  83. {
  84. background = GadgetComboBoxGetDisabledColor( window );
  85. border = GadgetComboBoxGetDisabledBorderColor( window );
  86. titleColor = window->winGetDisabledTextColor();
  87. titleBorder = window->winGetDisabledTextBorderColor();
  88. } // end if, disabled
  89. else if( BitTest( instData->getState(), WIN_STATE_HILITED ) )
  90. {
  91. background = GadgetComboBoxGetHiliteColor( window );
  92. border = GadgetComboBoxGetHiliteBorderColor( window );
  93. titleColor = window->winGetHiliteTextColor();
  94. titleBorder = window->winGetHiliteTextBorderColor();
  95. } // end else if, hilited
  96. else
  97. {
  98. background = GadgetComboBoxGetEnabledColor( window );
  99. border = GadgetComboBoxGetEnabledBorderColor( window );
  100. titleColor = window->winGetEnabledTextColor();
  101. titleBorder = window->winGetEnabledTextBorderColor();
  102. } // end else, enabled
  103. // Draw the title
  104. if( title && title->getTextLength() )
  105. {
  106. // set the font of this text to that of the window if not already
  107. if( title->getFont() != window->winGetFont() )
  108. title->setFont( window->winGetFont() );
  109. // draw the text
  110. title->draw( x + 1, y, titleColor, titleBorder );
  111. y += fontHeight + 1;
  112. height -= fontHeight + 1;
  113. } // end if
  114. // draw the back border
  115. if( border != WIN_COLOR_UNDEFINED )
  116. TheWindowManager->winOpenRect( border, WIN_DRAW_LINE_WIDTH,
  117. x, y, x + width, y + height );
  118. // draw background
  119. if( background != WIN_COLOR_UNDEFINED )
  120. TheWindowManager->winFillRect( background, WIN_DRAW_LINE_WIDTH,
  121. x + 1, y + 1,
  122. x + width - 1, y + height - 1 );
  123. } // end W3DGadgetComboBoxDraw
  124. // W3DGadgetComboBoxImageDraw ==================================================
  125. /** Draw combo box with user supplied images */
  126. //=============================================================================
  127. void W3DGadgetComboBoxImageDraw( GameWindow *window, WinInstanceData *instData )
  128. {
  129. Int width, height, x, y;
  130. const Image *image;
  131. // ComboBoxData *combo = (ComboBoxData *)window->winGetUserData();
  132. ICoord2D size;
  133. Color titleColor, titleBorder;
  134. DisplayString *title = instData->getTextDisplayString();
  135. // get window position and size
  136. window->winGetScreenPosition( &x, &y );
  137. window->winGetSize( &size.x, &size.y );
  138. // save off width and height so we can change them
  139. width = size.x;
  140. height = size.y;
  141. // get the image
  142. if( BitTest( window->winGetStatus(), WIN_STATUS_ENABLED ) == FALSE )
  143. {
  144. image = GadgetComboBoxGetDisabledImage( window );
  145. titleColor = window->winGetDisabledTextColor();
  146. titleBorder = window->winGetDisabledTextBorderColor();
  147. }
  148. else if( BitTest( instData->getState(), WIN_STATE_HILITED ) )
  149. {
  150. image = GadgetComboBoxGetHiliteImage( window );
  151. titleColor = window->winGetHiliteTextColor();
  152. titleBorder = window->winGetHiliteTextBorderColor();
  153. }
  154. else
  155. {
  156. image = GadgetComboBoxGetEnabledImage( window );
  157. titleColor = window->winGetEnabledTextColor();
  158. titleBorder = window->winGetEnabledTextBorderColor();
  159. }
  160. // draw the back image
  161. if( image )
  162. {
  163. ICoord2D start, end;
  164. start.x = x + instData->m_imageOffset.x;
  165. start.y = y + instData->m_imageOffset.y;
  166. end.x = start.x + width;
  167. end.y = start.y + height;
  168. TheWindowManager->winDrawImage( image,
  169. start.x, start.y,
  170. end.x, end.y );
  171. } // end if
  172. // Draw the title
  173. if( title && title->getTextLength() )
  174. {
  175. // set font to font of the window if not already
  176. if( title->getFont() != window->winGetFont() )
  177. title->setFont( window->winGetFont() );
  178. // draw the text
  179. title->draw( x + 1, y, titleColor, titleBorder );
  180. y += TheWindowManager->winFontHeight( instData->getFont() );
  181. height -= TheWindowManager->winFontHeight( instData->getFont() ) + 1;
  182. } // end if
  183. } // end W3DGadgetComboBoxImageDraw