W3DVerticalSlider.cpp 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  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: .cpp /////////////////////////////////////////////////////////////////
  24. //-----------------------------------------------------------------------------
  25. //
  26. // Westwood Studios Pacific.
  27. //
  28. // Confidential Information
  29. // Copyright (C) 2001 - All Rights Reserved
  30. //
  31. //-----------------------------------------------------------------------------
  32. //
  33. // Project:
  34. //
  35. // File name: .cpp
  36. //
  37. // Created:
  38. //
  39. // Desc:
  40. //
  41. //-----------------------------------------------------------------------------
  42. ///////////////////////////////////////////////////////////////////////////////
  43. // SYSTEM INCLUDES ////////////////////////////////////////////////////////////
  44. #include <stdlib.h>
  45. // USER INCLUDES //////////////////////////////////////////////////////////////
  46. #include "GameClient/GadgetSlider.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. // PRIVATE FUNCTIONS //////////////////////////////////////////////////////////
  57. ///////////////////////////////////////////////////////////////////////////////
  58. // PUBLIC FUNCTIONS ///////////////////////////////////////////////////////////
  59. ///////////////////////////////////////////////////////////////////////////////
  60. // W3DGadgetVerticalSliderDraw ================================================
  61. /** Draw colored vertical slider using standard graphics */
  62. //=============================================================================
  63. void W3DGadgetVerticalSliderDraw( GameWindow *window,
  64. WinInstanceData *instData )
  65. {
  66. Color backBorder, backColor;
  67. ICoord2D origin, size, start, end;
  68. // get screen position and size
  69. window->winGetScreenPosition( &origin.x, &origin.y );
  70. window->winGetSize( &size.x, &size.y );
  71. // get the right colors
  72. if( BitTest( window->winGetStatus(), WIN_STATUS_ENABLED ) == FALSE )
  73. {
  74. backBorder = GadgetSliderGetDisabledBorderColor( window );
  75. backColor = GadgetSliderGetDisabledColor( window );
  76. } // end if, disabled
  77. else if( BitTest( instData->getState(), WIN_STATE_HILITED ) )
  78. {
  79. backBorder = GadgetSliderGetHiliteBorderColor( window );
  80. backColor = GadgetSliderGetHiliteColor( window );
  81. } // end else if, hilited
  82. else
  83. {
  84. backBorder = GadgetSliderGetEnabledBorderColor( window );
  85. backColor = GadgetSliderGetEnabledColor( window );
  86. } // end else, enabled
  87. // draw background border and rect over whole control
  88. if( backBorder != WIN_COLOR_UNDEFINED )
  89. {
  90. start.x = origin.x;
  91. start.y = origin.y;
  92. end.x = start.x + size.x;
  93. end.y = start.y + size.y;
  94. TheWindowManager->winOpenRect( backBorder, WIN_DRAW_LINE_WIDTH,
  95. start.x, start.y, end.x, end.y );
  96. } // end if
  97. if( backColor != WIN_COLOR_UNDEFINED )
  98. {
  99. start.x = origin.x + 1;
  100. start.y = origin.y + 1;
  101. end.x = start.x + size.x - 2;
  102. end.y = start.y + size.y - 2;
  103. TheWindowManager->winFillRect( backColor, WIN_DRAW_LINE_WIDTH,
  104. start.x, start.y, end.x, end.y );
  105. } // end if
  106. } // end W3DGadgetVerticalSliderDraw
  107. // W3DGadgetVerticalSliderImageDraw ===========================================
  108. /** Draw vertical slider with user supplied images */
  109. //=============================================================================
  110. void W3DGadgetVerticalSliderImageDraw( GameWindow *window,
  111. WinInstanceData *instData )
  112. {
  113. const Image *topImage, *bottomImage, *centerImage, *smallCenterImage;
  114. ICoord2D origin, size, start, end;
  115. Int xOffset, yOffset;
  116. Int i;
  117. // get screen position and size
  118. window->winGetScreenPosition( &origin.x, &origin.y );
  119. window->winGetSize( &size.x, &size.y );
  120. // get image offset
  121. xOffset = instData->m_imageOffset.x;
  122. yOffset = instData->m_imageOffset.y;
  123. // get the right images
  124. if( BitTest( window->winGetStatus(), WIN_STATUS_ENABLED ) == FALSE )
  125. {
  126. topImage = GadgetSliderGetDisabledImageTop( window );
  127. bottomImage = GadgetSliderGetDisabledImageBottom( window );
  128. centerImage = GadgetSliderGetDisabledImageCenter( window );
  129. smallCenterImage = GadgetSliderGetDisabledImageSmallCenter( window );
  130. } // end if, disabled
  131. else if( BitTest( instData->getState(), WIN_STATE_HILITED ) )
  132. {
  133. topImage = GadgetSliderGetHiliteImageTop( window );
  134. bottomImage = GadgetSliderGetHiliteImageBottom( window );
  135. centerImage = GadgetSliderGetHiliteImageCenter( window );
  136. smallCenterImage = GadgetSliderGetHiliteImageSmallCenter( window );
  137. } // end else if, hilited
  138. else
  139. {
  140. topImage = GadgetSliderGetEnabledImageTop( window );
  141. bottomImage = GadgetSliderGetEnabledImageBottom( window );
  142. centerImage = GadgetSliderGetEnabledImageCenter( window );
  143. smallCenterImage = GadgetSliderGetEnabledImageSmallCenter( window );
  144. } // end else, enabled
  145. // sanity, we need to have these images to make it look right
  146. if( topImage == NULL || bottomImage == NULL ||
  147. centerImage == NULL || smallCenterImage == NULL )
  148. return;
  149. // get image sizes for the ends
  150. ICoord2D topSize, bottomSize;
  151. topSize.x = topImage->getImageWidth();
  152. topSize.y = topImage->getImageHeight();
  153. bottomSize.x = bottomImage->getImageWidth();
  154. bottomSize.y = bottomImage->getImageHeight();
  155. if(topSize.y + bottomSize.y >= size.y)
  156. {
  157. // draw top end
  158. start.x = origin.x + xOffset;
  159. start.y = origin.y + yOffset;
  160. end.x = origin.x + xOffset + topSize.x;
  161. end.y = origin.y + size.y /2;
  162. TheWindowManager->winDrawImage(topImage, start.x, start.y, end.x, end.y);
  163. // draw bottom end
  164. start.y = origin.y + size.y /2;
  165. end.x = origin.x + xOffset + bottomSize.x;
  166. end.y = origin.y + yOffset + size.y;
  167. TheWindowManager->winDrawImage(bottomImage, start.x, start.y, end.x, end.y);
  168. }
  169. else
  170. {
  171. // get two key points used in the end drawing
  172. ICoord2D topEnd, bottomStart;
  173. topEnd.x = origin.x + topSize.x + xOffset;
  174. topEnd.y = origin.y + topSize.y + yOffset;
  175. bottomStart.x = origin.x + xOffset;
  176. bottomStart.y = origin.y + size.y - bottomSize.y + yOffset;
  177. // draw the center repeating bar
  178. Int centerHeight, pieces;
  179. // get size we have to draw our repeating center in
  180. centerHeight = bottomStart.y - topEnd.y;
  181. // how many whole repeating pieces will fit in that size
  182. pieces = centerHeight / centerImage->getImageHeight();
  183. // draw the pieces
  184. start.x = origin.x + xOffset;
  185. start.y = topEnd.y;
  186. end.x = start.x + centerImage->getImageWidth();
  187. end.y = start.y + centerImage->getImageHeight();
  188. for( i = 0; i < pieces; i++ )
  189. {
  190. TheWindowManager->winDrawImage( centerImage,
  191. start.x, start.y,
  192. end.x, end.y );
  193. start.y += centerImage->getImageHeight();
  194. end.y += centerImage->getImageHeight();
  195. } // end for i
  196. //
  197. // how many small repeating pieces will fit in the gap from where the
  198. // center repeating bar stopped and the bottom image, draw them
  199. // and overlapping underneath where the bottom end will go
  200. //
  201. centerHeight = bottomStart.y - start.y;
  202. pieces = centerHeight / smallCenterImage->getImageHeight() + 1;
  203. end.y = start.y + smallCenterImage->getImageHeight();
  204. for( i = 0; i < pieces; i++ )
  205. {
  206. TheWindowManager->winDrawImage( smallCenterImage,
  207. start.x, start.y,
  208. end.x, end.y );
  209. start.y += smallCenterImage->getImageHeight();
  210. end.y += smallCenterImage->getImageHeight();
  211. } // end for i
  212. // draw top end
  213. start.x = origin.x + xOffset;
  214. start.y = origin.y + yOffset;
  215. end = topEnd;
  216. TheWindowManager->winDrawImage(topImage, start.x, start.y, end.x, end.y);
  217. // draw bottom end
  218. start = bottomStart;
  219. end.x = start.x + bottomSize.x;
  220. end.y = start.y + bottomSize.y;
  221. TheWindowManager->winDrawImage(bottomImage, start.x, start.y, end.x, end.y);
  222. }
  223. } // end W3DGadgetVerticalSliderImageDraw