W3DHorizontalSlider.cpp 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484
  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/GameWindowGlobal.h"
  47. #include "GameClient/GameWindowManager.h"
  48. #include "GameClient/GadgetSlider.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. #ifdef _INTERNAL
  61. // for occasional debugging...
  62. //#pragma optimize("", off)
  63. //#pragma MESSAGE("************************************** WARNING, optimization disabled for debugging purposes")
  64. #endif
  65. // W3DGadgetHorizontalSliderDraw ==============================================
  66. /** Draw colored horizontal slider using standard graphics */
  67. //=============================================================================
  68. void W3DGadgetHorizontalSliderDraw( GameWindow *window, WinInstanceData *instData )
  69. {
  70. Color backBorder, backColor;
  71. ICoord2D origin, size, start, end;
  72. // get screen position and size
  73. window->winGetScreenPosition( &origin.x, &origin.y );
  74. window->winGetSize( &size.x, &size.y );
  75. // get the right colors
  76. if( BitTest( window->winGetStatus(), WIN_STATUS_ENABLED ) == FALSE )
  77. {
  78. backBorder = GadgetSliderGetDisabledBorderColor( window );
  79. backColor = GadgetSliderGetDisabledColor( window );
  80. } // end if, disabled
  81. else if( BitTest( instData->getState(), WIN_STATE_HILITED ) )
  82. {
  83. backBorder = GadgetSliderGetHiliteBorderColor( window );
  84. backColor = GadgetSliderGetHiliteColor( window );
  85. } // end else if, hilited
  86. else
  87. {
  88. backBorder = GadgetSliderGetEnabledBorderColor( window );
  89. backColor = GadgetSliderGetEnabledColor( window );
  90. } // end else, enabled
  91. // draw background border and rect over whole control
  92. if( backBorder != WIN_COLOR_UNDEFINED )
  93. {
  94. start.x = origin.x;
  95. start.y = origin.y;
  96. end.x = start.x + size.x;
  97. end.y = start.y + size.y;
  98. TheWindowManager->winOpenRect( backBorder, WIN_DRAW_LINE_WIDTH,
  99. start.x, start.y, end.x, end.y );
  100. } // end if
  101. if( backColor != WIN_COLOR_UNDEFINED )
  102. {
  103. start.x = origin.x + 1;
  104. start.y = origin.y + 1;
  105. end.x = start.x + size.x - 2;
  106. end.y = start.y + size.y - 2;
  107. TheWindowManager->winFillRect( backColor, WIN_DRAW_LINE_WIDTH,
  108. start.x, start.y, end.x, end.y );
  109. } // end if
  110. } // end W3DGadgetHorizontalSliderDraw
  111. // W3DGadgetHorizontalSliderImageDraw =========================================
  112. /** Draw horizontal slider with user supplied images */
  113. //=============================================================================
  114. void W3DGadgetHorizontalSliderImageDraw( GameWindow *window,
  115. WinInstanceData *instData )
  116. {
  117. const Image *fillSquare, *blankSquare, *highlightSquare;
  118. ICoord2D origin, size, start, end, highlightOffset;
  119. // get screen position and size
  120. window->winGetScreenPosition( &origin.x, &origin.y );
  121. window->winGetSize( &size.x, &size.y );
  122. highlightSquare = GadgetSliderGetHiliteImageLeft( window );
  123. blankSquare = GadgetSliderGetDisabledImageRight( window );
  124. fillSquare = GadgetSliderGetDisabledImageLeft( window );
  125. SliderData *s = (SliderData *)window->winGetUserData();
  126. Real xMulti = INT_TO_REAL(TheDisplay->getWidth()) / 800;
  127. // figure out how many boxes we draw for this slider
  128. Int numBoxes = 0;
  129. Int numSelectedBoxes = 0;
  130. Int numHighlightBoxes = 0;
  131. Int boxWidth = fillSquare->getImageWidth()* xMulti;
  132. Int boxPadding = 2;
  133. start.x = origin.x;
  134. end.x = start.x + boxWidth;
  135. Real selectedPercent = (s->position - s->minVal)/INT_TO_REAL((s->maxVal - s->minVal));
  136. Int maxSelectedX = origin.x + REAL_TO_INT(selectedPercent * size.x);
  137. while(end.x < origin.x + size.x )
  138. {
  139. if (start.x <= maxSelectedX && end.x < origin.x + size.x && s->position != s->minVal)
  140. ++numSelectedBoxes;
  141. start.x = end.x + boxPadding;
  142. end.x = start.x + boxWidth;
  143. ++numBoxes;
  144. }
  145. numHighlightBoxes = numBoxes + 1;
  146. Int distanceCovered = end.x - origin.x - boxWidth;
  147. highlightOffset.x = -(boxWidth + boxPadding)/2;
  148. highlightOffset.y = boxWidth/3;
  149. Int blankness = size.x - distanceCovered;
  150. origin.x += blankness/2;
  151. Int i;
  152. if( BitTest( instData->getState(), WIN_STATE_HILITED ) )
  153. {
  154. ICoord2D backgroundStart, backgroundEnd;
  155. backgroundStart.y = origin.y + highlightOffset.y;
  156. backgroundEnd.y = backgroundStart.y + boxWidth + boxPadding;
  157. for (i=0; i<numHighlightBoxes; ++i)
  158. {
  159. backgroundStart.x = origin.x + highlightOffset.x + i*(boxWidth+boxPadding);
  160. backgroundEnd.x = backgroundStart.x + boxWidth + boxPadding;
  161. TheWindowManager->winDrawImage( highlightSquare,
  162. backgroundStart.x, backgroundStart.y,
  163. backgroundEnd.x, backgroundEnd.y );
  164. }
  165. }
  166. start.y = origin.y;
  167. end.y = start.y + boxWidth;
  168. for (i=0; i<numSelectedBoxes; ++i)
  169. {
  170. start.x = origin.x + i*(boxWidth+boxPadding);
  171. end.x = start.x + boxWidth;
  172. TheWindowManager->winDrawImage( fillSquare,
  173. start.x, start.y,
  174. end.x, end.y );
  175. }
  176. for (i=numSelectedBoxes; i<numBoxes; ++i)
  177. {
  178. start.x = origin.x + i*(boxWidth+boxPadding);
  179. end.x = start.x + boxWidth;
  180. TheWindowManager->winDrawImage( blankSquare,
  181. start.x, start.y,
  182. end.x, end.y );
  183. }
  184. }
  185. // W3DGadgetHorizontalSliderImageDraw =========================================
  186. /** Draw horizontal slider with user supplied images */
  187. //=============================================================================
  188. void W3DGadgetHorizontalSliderImageDrawB( GameWindow *window,
  189. WinInstanceData *instData )
  190. {
  191. const Image *fillSquare, *blankSquare, *highlightSquare;//, *progressArrow;
  192. ICoord2D origin, size, start, end;
  193. Int xOffset, yOffset;
  194. // get screen position and size
  195. window->winGetScreenPosition( &origin.x, &origin.y );
  196. window->winGetSize( &size.x, &size.y );
  197. SliderData *s = (SliderData *)window->winGetUserData();
  198. Real xMulti = INT_TO_REAL(TheDisplay->getWidth()) / 800;
  199. Real yMulti = INT_TO_REAL(TheDisplay->getHeight())/ 600;
  200. // get image offset
  201. xOffset = instData->m_imageOffset.x;
  202. yOffset = instData->m_imageOffset.y;
  203. UnicodeString tooltip, tmp;
  204. tooltip.format(L"mult:%g/%g, img offset:%d,%d", xMulti, yMulti, xOffset, yOffset);
  205. tmp.format(L"\norigin: %d,%d size:%d,%d", origin.x, origin.y, size.x, size.y);
  206. tooltip.concat(tmp);
  207. tmp.format(L"\ns= %d <--> %d, numTicks=%g, pos = %d", s->minVal, s->maxVal, s->numTicks, s->position);
  208. tooltip.concat(tmp);
  209. if( BitTest( instData->getState(), WIN_STATE_HILITED ) )
  210. {
  211. highlightSquare = GadgetSliderGetHiliteImageLeft( window );
  212. ICoord2D backgroundStart, backgroundEnd;
  213. backgroundStart.x = origin.x - (highlightSquare->getImageWidth() * xMulti)/2;
  214. backgroundStart.y = origin.y + (highlightSquare->getImageHeight() *yMulti)/3;
  215. backgroundEnd.y = backgroundStart.y + highlightSquare->getImageHeight()* yMulti;
  216. backgroundEnd.x = backgroundStart.x + highlightSquare->getImageWidth() * xMulti;
  217. tmp.format(L"\nHighlighted: (%d,%d) -> (%d,%d), step %d/%g, full %d/%d", backgroundStart.x, backgroundStart.y,
  218. backgroundEnd.x, backgroundEnd.y, highlightSquare->getImageWidth(), highlightSquare->getImageWidth() * xMulti,
  219. origin.x, size.x);
  220. tooltip.concat(tmp);
  221. while(backgroundStart.x < origin.x + size.x)
  222. {
  223. TheWindowManager->winDrawImage( highlightSquare,
  224. backgroundStart.x, backgroundStart.y,
  225. backgroundEnd.x, backgroundEnd.y );
  226. backgroundStart.x = backgroundEnd.x;
  227. backgroundEnd.x = backgroundStart.x + highlightSquare->getImageWidth() * xMulti;
  228. }
  229. tmp.format(L"\n bsX = %d, beX = %d (%d < %d+%d or %d?)", backgroundStart.x, backgroundEnd.x,
  230. backgroundStart.x, origin.x, size.x, origin.x + size.x);
  231. tooltip.concat(tmp);
  232. }
  233. fillSquare = GadgetSliderGetDisabledImageLeft( window );
  234. start.x = origin.x;
  235. start.y = origin.y;
  236. end.y = start.y + fillSquare->getImageHeight() * yMulti;
  237. end.x = start.x + fillSquare->getImageWidth()* xMulti;
  238. tmp.format(L"\ntop: start=%d,%d, end=%d,%d", start.x, start.y, end.x, end.y);
  239. tooltip.concat(tmp);
  240. while(start.x <= origin.x + (s->numTicks * (s->position - s->minVal)) && end.x < origin.x + size.x && s->position != s->minVal)
  241. {
  242. TheWindowManager->winDrawImage( fillSquare,
  243. start.x, start.y,
  244. end.x, end.y );
  245. start.x = end.x + 2;
  246. end.x = start.x + fillSquare->getImageWidth()* xMulti;
  247. }
  248. blankSquare = GadgetSliderGetDisabledImageRight( window );
  249. end.x = start.x + blankSquare->getImageWidth()* xMulti;
  250. while(end.x < origin.x + size.x )
  251. {
  252. TheWindowManager->winDrawImage( blankSquare,
  253. start.x, start.y,
  254. end.x, end.y );
  255. start.x = end.x + 2;
  256. end.x = start.x + blankSquare->getImageWidth()* xMulti;
  257. }
  258. instData->setTooltipText(tooltip);
  259. // if( BitTest( instData->getState(), WIN_STATE_HILITED ) )
  260. // {
  261. // progressArrow = GadgetSliderGetHiliteImageRight( window );
  262. // if(!progressArrow)
  263. // return;
  264. // Int transPos = (s->numTicks * (s->position - s->minVal)) - progressArrow->getImageWidth() /2;
  265. // start.x = origin.x + transPos;
  266. // start.y = origin.y + fillSquare->getImageHeight()/3*2;
  267. // end.y = start.y + progressArrow->getImageHeight();
  268. // end.x = start.x + progressArrow->getImageWidth();
  269. // TheWindowManager->winDrawImage( progressArrow,
  270. // start.x, start.y,
  271. // end.x, end.y );
  272. // }
  273. }
  274. // W3DGadgetHorizontalSliderImageDraw =========================================
  275. /** Draw horizontal slider with user supplied images */
  276. //=============================================================================
  277. void W3DGadgetHorizontalSliderImageDrawA( GameWindow *window,
  278. WinInstanceData *instData )
  279. {
  280. const Image *leftImageLeft, *rightImageLeft, *centerImageLeft, *smallCenterImageLeft;
  281. const Image *leftImageRight, *rightImageRight, *centerImageRight, *smallCenterImageRight;
  282. ICoord2D origin, size, start, end;
  283. Int xOffset, yOffset;
  284. Int i;
  285. // get screen position and size
  286. window->winGetScreenPosition( &origin.x, &origin.y );
  287. window->winGetSize( &size.x, &size.y );
  288. SliderData *s = (SliderData *)window->winGetUserData();
  289. Int transPos = (s->numTicks * (s->position - s->minVal)) + HORIZONTAL_SLIDER_THUMB_WIDTH/2;
  290. IRegion2D clipLeft, clipRight;
  291. // get image offset
  292. xOffset = instData->m_imageOffset.x;
  293. yOffset = instData->m_imageOffset.y;
  294. // get the right images
  295. if( BitTest( window->winGetStatus(), WIN_STATUS_ENABLED ) == FALSE )
  296. {
  297. leftImageRight = leftImageLeft = GadgetSliderGetDisabledImageLeft( window );
  298. rightImageRight = rightImageLeft = GadgetSliderGetDisabledImageRight( window );
  299. // centerImageRight = centerImageLeft = GadgetSliderGetDisabledImageCenter( window );
  300. // smallCenterImageRight = smallCenterImageLeft = GadgetSliderGetDisabledImageSmallCenter( window );
  301. } // end if, disabled
  302. else //if( BitTest( instData->getState(), WIN_STATE_HILITED ) )
  303. {
  304. leftImageLeft = GadgetSliderGetHiliteImageLeft( window );
  305. rightImageLeft = GadgetSliderGetHiliteImageRight( window );
  306. centerImageLeft = GadgetSliderGetHiliteImageCenter( window );
  307. smallCenterImageLeft = GadgetSliderGetHiliteImageSmallCenter( window );
  308. leftImageRight = GadgetSliderGetEnabledImageLeft( window );
  309. rightImageRight = GadgetSliderGetEnabledImageRight( window );
  310. centerImageRight = GadgetSliderGetEnabledImageCenter( window );
  311. smallCenterImageRight = GadgetSliderGetEnabledImageSmallCenter( window );
  312. } // end else, enabled
  313. // sanity, we need to have these images to make it look right
  314. if( leftImageLeft == NULL || rightImageLeft == NULL ||
  315. centerImageLeft == NULL || smallCenterImageLeft == NULL ||
  316. leftImageRight == NULL || rightImageRight == NULL ||
  317. centerImageRight == NULL || smallCenterImageRight == NULL )
  318. return;
  319. // get image sizes for the ends
  320. ICoord2D leftSize, rightSize;
  321. leftSize.x = leftImageLeft->getImageWidth();
  322. leftSize.y = leftImageLeft->getImageHeight();
  323. rightSize.x = rightImageLeft->getImageWidth();
  324. rightSize.y = rightImageLeft->getImageHeight();
  325. // get two key points used in the end drawing
  326. ICoord2D leftEnd, rightStart;
  327. leftEnd.x = origin.x + leftSize.x + xOffset;
  328. leftEnd.y = origin.y + size.y + yOffset;
  329. rightStart.x = origin.x + size.x - rightSize.x + xOffset;
  330. rightStart.y = origin.y + size.y - leftSize.y + yOffset;
  331. // draw the center repeating bar
  332. Int centerWidth, pieces;
  333. // get width we have to draw our repeating center in
  334. centerWidth = rightStart.x - leftEnd.x;
  335. // how many whole repeating pieces will fit in that width
  336. pieces = centerWidth / centerImageLeft->getImageWidth();
  337. // draw the pieces
  338. start.x = leftEnd.x;
  339. start.y = origin.y + size.y - leftSize.y + yOffset;
  340. end.y =origin.y + size.y + yOffset;
  341. clipLeft.lo.x = origin.x;
  342. clipLeft.lo.y = rightStart.y;
  343. clipLeft.hi.y = leftEnd.y;
  344. clipLeft.hi.x = origin.x + transPos;
  345. clipRight.lo.x = origin.x + transPos;
  346. clipRight.lo.y = rightStart.y;
  347. clipRight.hi.y = leftEnd.y;
  348. clipRight.hi.x = origin.x + size.x;
  349. for( i = 0; i < pieces; i++ )
  350. {
  351. end.x = start.x + centerImageLeft->getImageWidth();
  352. TheDisplay->setClipRegion(&clipLeft);
  353. TheWindowManager->winDrawImage( centerImageLeft,
  354. start.x, start.y,
  355. end.x, end.y );
  356. TheDisplay->setClipRegion(&clipRight);
  357. TheWindowManager->winDrawImage( centerImageRight,
  358. start.x, start.y,
  359. end.x, end.y );
  360. start.x += centerImageLeft->getImageWidth();
  361. } // end for i
  362. //
  363. // how many small repeating pieces will fit in the gap from where the
  364. // center repeating bar stopped and the right image, draw them
  365. // and overlapping underneath where the right end will go
  366. //
  367. centerWidth = rightStart.x - start.x;
  368. pieces = centerWidth / smallCenterImageLeft->getImageWidth() + 1;
  369. end.y = leftEnd.y;//start.y + smallCenterImageLeft->getImageHeight();
  370. for( i = 0; i < pieces; i++ )
  371. {
  372. end.x = start.x + smallCenterImageLeft->getImageWidth();
  373. TheDisplay->setClipRegion(&clipLeft);
  374. TheWindowManager->winDrawImage( smallCenterImageLeft,
  375. start.x, start.y,
  376. end.x, end.y );
  377. TheDisplay->setClipRegion(&clipRight);
  378. TheWindowManager->winDrawImage( smallCenterImageRight,
  379. start.x, start.y,
  380. end.x, end.y );
  381. start.x += smallCenterImageLeft->getImageWidth();
  382. } // end for i
  383. // draw left end
  384. start.x = origin.x + xOffset;
  385. start.y = rightStart.y;
  386. end = leftEnd;
  387. TheDisplay->setClipRegion(&clipLeft);
  388. TheWindowManager->winDrawImage(leftImageLeft, start.x, start.y, end.x, end.y);
  389. TheDisplay->setClipRegion(&clipRight);
  390. TheWindowManager->winDrawImage(leftImageRight, start.x, start.y, end.x, end.y);
  391. // draw right end
  392. start = rightStart;
  393. end.x = start.x + rightSize.x;
  394. end.y = leftEnd.y;
  395. TheDisplay->setClipRegion(&clipLeft);
  396. TheWindowManager->winDrawImage(rightImageLeft, start.x, start.y, end.x, end.y);
  397. TheDisplay->setClipRegion(&clipRight);
  398. TheWindowManager->winDrawImage(rightImageRight, start.x, start.y, end.x, end.y);
  399. TheDisplay->enableClipping(FALSE);
  400. } // end W3DGadgetHorizontalSliderImageDraw