W3DControlBar.cpp 33 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028
  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: W3DControlBar.cpp ////////////////////////////////////////////////////////////////////////
  24. // Author: Colin Day
  25. // Desc: Control bar callbacks
  26. ///////////////////////////////////////////////////////////////////////////////////////////////////
  27. #include "Common/GlobalData.h"
  28. #include "Common/Radar.h"
  29. #include "Common/Player.h"
  30. #include "Common/PlayerList.h"
  31. #include "GameClient/GameWindow.h"
  32. #include "W3DDevice/GameClient/W3DGameWindow.h"
  33. #include "GameClient/InGameUI.h"
  34. #include "GameClient/Display.h"
  35. #include "GameClient/ControlBar.h"
  36. #include "GameClient/GameWindowManager.h"
  37. #include "GameClient/ControlBarScheme.h"
  38. #include "GameClient/MapUtil.h"
  39. #include "GameLogic/GameLogic.h"
  40. #ifdef _INTERNAL
  41. // for occasional debugging...
  42. //#pragma optimize("", off)
  43. //#pragma MESSAGE("************************************** WARNING, optimization disabled for debugging purposes")
  44. #endif
  45. //-------------------------------------------------------------------------------------------------
  46. void W3DCameoMovieDraw( GameWindow *window, WinInstanceData *instData )
  47. {
  48. // draw video buffer
  49. VideoBuffer *video = TheInGameUI->cameoVideoBuffer();
  50. if ( video )
  51. {
  52. ICoord2D pos, size;
  53. window->winGetScreenPosition( &pos.x, &pos.y );
  54. window->winGetSize( &size.x, &size.y );
  55. TheDisplay->drawVideoBuffer( video, pos.x, pos.y, pos.x + size.x, pos.y + size.y );
  56. }
  57. } // end W3DLeftHUDDraw
  58. //-------------------------------------------------------------------------------------------------
  59. void W3DLeftHUDDraw( GameWindow *window, WinInstanceData *instData )
  60. {
  61. // draw the default stuff
  62. //
  63. Player *player = ThePlayerList->getLocalPlayer();
  64. // draw video buffer
  65. VideoBuffer *video = TheInGameUI->videoBuffer();
  66. if ( video )
  67. {
  68. ICoord2D pos, size;
  69. window->winGetScreenPosition( &pos.x, &pos.y );
  70. window->winGetSize( &size.x, &size.y );
  71. TheDisplay->drawVideoBuffer( video, pos.x, pos.y, pos.x + size.x, pos.y + size.y );
  72. }
  73. else if( TheRadar->isRadarForced() || ( TheRadar->isRadarHidden() == false && player->hasRadar() ) )
  74. {
  75. ICoord2D pos, size;
  76. //W3DGameWinDefaultDraw( window, instData );
  77. // window position and size on the display
  78. window->winGetScreenPosition( &pos.x, &pos.y );
  79. window->winGetSize( &size.x, &size.y );
  80. //TheDisplay->drawOpenRect(pos.x, pos.y, size.x,size.y, 1,GameMakeColor(100,100,255,255));
  81. // draw the radar on the screen now
  82. TheRadar->draw( pos.x + 1, pos.y + 1, size.x - 2, size.y - 2 );
  83. } // end else if
  84. } // end W3DLeftHUDDraw
  85. //-------------------------------------------------------------------------------------------------
  86. //-------------------------------------------------------------------------------------------------
  87. void W3DRightHUDDraw( GameWindow *window, WinInstanceData *instData )
  88. {
  89. // draw the default stuff
  90. if( BitTest(window->winGetStatus(), WIN_STATUS_IMAGE ))
  91. W3DGameWinDefaultDraw( window, instData );
  92. } // end W3DRightHUDDraw
  93. Real logN(Real value, Real logBase)
  94. {
  95. return (Real)log10(value)/ log10(logBase);
  96. }
  97. //-------------------------------------------------------------------------------------------------
  98. /** Temporary power meter drawing ... there are some problems with this meter, that is
  99. * what to do when the player doesn't have power, builds a building before a power plant
  100. * etc, but I don't want to spend time on this since it's not a task right now and I'm
  101. * sure it will be in the future. This is just down and dirty to see SOMETHING (CD) */
  102. //-------------------------------------------------------------------------------------------------
  103. void W3DPowerDraw( GameWindow *window, WinInstanceData *instData )
  104. {
  105. //static const Image *endBarYellow = TheMappedImageCollection->findImageByName("PowerBarYellowEndR");
  106. //static const Image *beginBarYellow = TheMappedImageCollection->findImageByName("PowerBarYellowEndL");
  107. static const Image *centerBarYellow = TheMappedImageCollection->findImageByName("PowerPointY");
  108. //static const Image *endBarRed = TheMappedImageCollection->findImageByName("PowerBarRedEndR");
  109. //static const Image *beginBarRed = TheMappedImageCollection->findImageByName("PowerBarRedEndL");
  110. static const Image *centerBarRed = TheMappedImageCollection->findImageByName("PowerPointR");
  111. //static const Image *endBarGreen = TheMappedImageCollection->findImageByName("PowerBarGreenEndR");
  112. //static const Image *beginBarGreen = TheMappedImageCollection->findImageByName("PowerBarGreenEndL");
  113. static const Image *centerBarGreen = TheMappedImageCollection->findImageByName("PowerPointG");
  114. //const Image *endBar = NULL;
  115. //const Image *beginBar = NULL;
  116. const Image *centerBar = NULL;
  117. static const Image *slider = TheMappedImageCollection->findImageByName("PowerBarSlider");
  118. Player *player = NULL;
  119. if(TheControlBar->isObserverControlBarOn())
  120. {
  121. player = TheControlBar->getObserverLookAtPlayer();
  122. }
  123. else
  124. player = ThePlayerList->getLocalPlayer();
  125. if(!player || !TheGlobalData)
  126. return;
  127. Energy *energy = player->getEnergy();
  128. if( energy == NULL )
  129. return;
  130. Int consumption = energy->getConsumption();
  131. Int production = energy->getProduction();
  132. ICoord2D pos, size;
  133. window->winGetScreenPosition( &pos.x, &pos.y );
  134. window->winGetSize( &size.x, &size.y );
  135. static Real pixelsPerInterval = size.x / TheGlobalData->m_powerBarIntervals;
  136. Int delta = TheGlobalData->m_powerBarYellowRange;
  137. if((consumption > energy->getProduction() - delta) && (consumption <= energy->getProduction()))
  138. {
  139. // 6 and 1 is Green, 6 and 2 is yellow, 6 and 6 is yellow
  140. //endBar = endBarYellow;
  141. //beginBar = beginBarYellow;
  142. centerBar = centerBarYellow;
  143. }
  144. else if( consumption > production)
  145. {
  146. // endBar = endBarRed;
  147. // beginBar = beginBarRed;
  148. centerBar = centerBarRed;
  149. }
  150. else
  151. {
  152. // endBar = endBarGreen;
  153. // beginBar = beginBarGreen;
  154. centerBar = centerBarGreen;
  155. }
  156. //slider = TheMappedImageCollection->findImageByName("PowerBarSlider");
  157. if( !slider || !centerBar)
  158. return;
  159. Int range;
  160. range = logN(production, TheGlobalData->m_powerBarBase) * (size.x / TheGlobalData->m_powerBarIntervals);
  161. if(range >= size.x)
  162. range = size.x;
  163. // if(range < endBar->getImageWidth() + beginBar->getImageWidth())
  164. // range = endBar->getImageWidth() + beginBar->getImageWidth();
  165. // // get image sizes for the ends
  166. // ICoord2D leftSize, rightSize, start, end;
  167. // leftSize.x = beginBar->getImageWidth();
  168. // leftSize.y = beginBar->getImageHeight();
  169. // rightSize.x = endBar->getImageWidth();
  170. // rightSize.y = endBar->getImageHeight();
  171. //
  172. // // get two key points used in the end drawing
  173. // ICoord2D leftEnd, rightStart;
  174. // leftEnd.x = pos.x + leftSize.x;
  175. // leftEnd.y = pos.y + size.y;
  176. // rightStart.x = pos.x + range - rightSize.x;
  177. // rightStart.y = pos.y;
  178. // draw the center repeating bar
  179. Int centerWidth, pieces;
  180. // get width we have to draw our repeating center in
  181. centerWidth = range; //rightStart.x - leftEnd.x;
  182. if( centerWidth > 0)
  183. {
  184. // how many whole repeating pieces will fit in that width
  185. pieces = centerWidth / centerBar->getImageWidth();
  186. ICoord2D start, end;
  187. // draw the pieces
  188. start.x = pos.x;
  189. start.y = pos.y;
  190. end.y = start.y + size.y;// + yOffset;
  191. for( Int i = 0; i < pieces; i++ )
  192. {
  193. end.x = start.x + centerBar->getImageWidth();
  194. TheWindowManager->winDrawImage( centerBar,
  195. start.x, start.y,
  196. end.x, end.y );
  197. start.x += centerBar->getImageWidth();
  198. } // end for i
  199. // we will draw the image but clip the parts we don't want to show
  200. IRegion2D reg;
  201. reg.lo.x = start.x;
  202. reg.lo.y = start.y;
  203. reg.hi.x = pos.x + size.x;//rightStart.x;
  204. reg.hi.y = pos.y + size.y;
  205. centerWidth = pos.x +size.x - start.x;
  206. if( centerWidth > 0)
  207. {
  208. TheDisplay->setClipRegion(&reg);
  209. end.x = start.x + centerBar->getImageWidth();
  210. TheWindowManager->winDrawImage( centerBar,
  211. start.x, start.y,
  212. end.x, end.y );
  213. TheDisplay->enableClipping(FALSE);
  214. }
  215. // // draw left end
  216. // start.x = pos.x;
  217. // start.y = pos.y;
  218. // end = leftEnd;
  219. // TheWindowManager->winDrawImage(beginBar, start.x, start.y, end.x, end.y);
  220. //
  221. // // draw right end
  222. // start = rightStart;
  223. // end.x = start.x + rightSize.x;
  224. // end.y = start.y + size.y;
  225. // TheWindowManager->winDrawImage(endBar, start.x, start.y, end.x, end.y);
  226. }
  227. Int posXstart;
  228. Int posXend;
  229. Real consumptionForNeedle = (consumption == 1) ? 1.5f : INT_TO_REAL(consumption);//Log(1) == 0, but we need to show something for 1 power used.
  230. range = logN(consumptionForNeedle, TheGlobalData->m_powerBarBase) * (size.x / TheGlobalData->m_powerBarIntervals);
  231. if(centerWidth <= 0 && range <= 0)
  232. return;
  233. if(range >= size.x)
  234. {
  235. posXstart = pos.x + size.x - slider->getImageWidth();
  236. posXend = pos.x + size.x;
  237. }
  238. else
  239. {
  240. posXstart = pos.x + range - slider->getImageWidth()/2;
  241. posXend = pos.x + range + slider->getImageWidth()/2;
  242. }
  243. if(posXstart <=pos.x)
  244. {
  245. posXstart = pos.x;
  246. posXend = pos.x + slider->getImageWidth();
  247. }
  248. TheWindowManager->winDrawImage(slider, posXstart, pos.y + size.y - slider->getImageHeight(), posXend, pos.y + size.y);
  249. }
  250. void W3DPowerDrawA( GameWindow *window, WinInstanceData *instData )
  251. {
  252. static const Image *endBarYellow = TheMappedImageCollection->findImageByName("PowerBarYellowEndR");
  253. static const Image *beginBarYellow = TheMappedImageCollection->findImageByName("PowerBarYellowEndL");
  254. static const Image *centerBarYellow = TheMappedImageCollection->findImageByName("PowerBarYellow");
  255. static const Image *endBarRed = TheMappedImageCollection->findImageByName("PowerBarRedEndR");
  256. static const Image *beginBarRed = TheMappedImageCollection->findImageByName("PowerBarRedEndL");
  257. static const Image *centerBarRed = TheMappedImageCollection->findImageByName("PowerBarRed");
  258. static const Image *endBarGreen = TheMappedImageCollection->findImageByName("PowerBarGreenEndR");
  259. static const Image *beginBarGreen = TheMappedImageCollection->findImageByName("PowerBarGreenEndL");
  260. static const Image *centerBarGreen = TheMappedImageCollection->findImageByName("PowerBarGreen");
  261. const Image *endBar = NULL;
  262. const Image *beginBar = NULL;
  263. const Image *centerBar = NULL;
  264. static const Image *slider = TheMappedImageCollection->findImageByName("PowerBarSlider");
  265. Player *player = NULL;
  266. if(TheControlBar->isObserverControlBarOn())
  267. {
  268. player = TheControlBar->getObserverLookAtPlayer();
  269. }
  270. else
  271. player = ThePlayerList->getLocalPlayer();
  272. if(!player || !TheGlobalData)
  273. return;
  274. Energy *energy = player->getEnergy();
  275. if( energy == NULL )
  276. return;
  277. Int consumption = energy->getConsumption();
  278. Int production = energy->getProduction();
  279. ICoord2D pos, size;
  280. window->winGetScreenPosition( &pos.x, &pos.y );
  281. window->winGetSize( &size.x, &size.y );
  282. static Real pixelsPerInterval = size.x / TheGlobalData->m_powerBarIntervals;
  283. Int delta = TheGlobalData->m_powerBarYellowRange;
  284. if((consumption > energy->getProduction() - delta) && (consumption <= energy->getProduction()))
  285. {
  286. // 6 and 1 is Green, 6 and 2 is yellow, 6 and 6 is yellow
  287. endBar = endBarYellow;
  288. beginBar = beginBarYellow;
  289. centerBar = centerBarYellow;
  290. }
  291. else if( consumption > production)
  292. {
  293. endBar = endBarRed;
  294. beginBar = beginBarRed;
  295. centerBar = centerBarRed;
  296. }
  297. else
  298. {
  299. endBar = endBarGreen;
  300. beginBar = beginBarGreen;
  301. centerBar = centerBarGreen;
  302. }
  303. //slider = TheMappedImageCollection->findImageByName("PowerBarSlider");
  304. if( !slider || !endBar || !beginBar || !centerBar)
  305. return;
  306. Int range;
  307. range = logN(production, TheGlobalData->m_powerBarBase) * (size.x / TheGlobalData->m_powerBarIntervals);
  308. if(range >= size.x)
  309. range = size.x;
  310. if(range < endBar->getImageWidth() + beginBar->getImageWidth())
  311. range = endBar->getImageWidth() + beginBar->getImageWidth();
  312. // get image sizes for the ends
  313. ICoord2D leftSize, rightSize, start, end;
  314. leftSize.x = beginBar->getImageWidth();
  315. leftSize.y = beginBar->getImageHeight();
  316. rightSize.x = endBar->getImageWidth();
  317. rightSize.y = endBar->getImageHeight();
  318. // get two key points used in the end drawing
  319. ICoord2D leftEnd, rightStart;
  320. leftEnd.x = pos.x + leftSize.x;
  321. leftEnd.y = pos.y + size.y;
  322. rightStart.x = pos.x + range - rightSize.x;
  323. rightStart.y = pos.y;
  324. // draw the center repeating bar
  325. Int centerWidth, pieces;
  326. // get width we have to draw our repeating center in
  327. centerWidth = rightStart.x - leftEnd.x;
  328. if( centerWidth <= 0)
  329. {
  330. // draw left end
  331. start.x = pos.x;
  332. start.y = pos.y;
  333. end.y = leftEnd.y;
  334. end.x = pos.x + range/2;
  335. TheWindowManager->winDrawImage(beginBar, start.x, start.y, end.x, end.y);
  336. // draw right end
  337. start.y = rightStart.y;
  338. start.x = end.x;
  339. end.x = pos.x + range;
  340. end.y = start.y + size.y;
  341. TheWindowManager->winDrawImage(endBar, start.x, start.y, end.x, end.y);
  342. }
  343. else
  344. {
  345. // how many whole repeating pieces will fit in that width
  346. pieces = centerWidth / centerBar->getImageWidth();
  347. // draw the pieces
  348. start.x = leftEnd.x;
  349. start.y = pos.y;
  350. end.y = start.y + size.y; //centerImage->getImageHeight() + yOffset;
  351. for( Int i = 0; i < pieces; i++ )
  352. {
  353. end.x = start.x + centerBar->getImageWidth();
  354. TheWindowManager->winDrawImage( centerBar,
  355. start.x, start.y,
  356. end.x, end.y );
  357. start.x += centerBar->getImageWidth();
  358. } // end for i
  359. // we will draw the image but clip the parts we don't want to show
  360. IRegion2D reg;
  361. reg.lo.x = start.x;
  362. reg.lo.y = start.y;
  363. reg.hi.x = rightStart.x;
  364. reg.hi.y = end.y;
  365. centerWidth = rightStart.x - start.x;
  366. if( centerWidth > 0)
  367. {
  368. TheDisplay->setClipRegion(&reg);
  369. end.x = start.x + centerBar->getImageWidth();
  370. TheWindowManager->winDrawImage( centerBar,
  371. start.x, start.y,
  372. end.x, end.y );
  373. TheDisplay->enableClipping(FALSE);
  374. }
  375. // draw left end
  376. start.x = pos.x;
  377. start.y = pos.y;
  378. end = leftEnd;
  379. TheWindowManager->winDrawImage(beginBar, start.x, start.y, end.x, end.y);
  380. // draw right end
  381. start = rightStart;
  382. end.x = start.x + rightSize.x;
  383. end.y = start.y + size.y;
  384. TheWindowManager->winDrawImage(endBar, start.x, start.y, end.x, end.y);
  385. }
  386. Int posXstart;
  387. Int posXend;
  388. Real consumptionForNeedle = (consumption == 1) ? 1.5f : INT_TO_REAL(consumption);//Log(1) == 0, but we need to show something for 1 power used.
  389. range = logN(consumptionForNeedle, TheGlobalData->m_powerBarBase) * (size.x / TheGlobalData->m_powerBarIntervals);
  390. if(range >= size.x)
  391. {
  392. posXstart = pos.x + size.x - slider->getImageWidth();
  393. posXend = pos.x + size.x;
  394. }
  395. else
  396. {
  397. posXstart = pos.x + range - slider->getImageWidth()/2;
  398. posXend = pos.x + range + slider->getImageWidth()/2;
  399. }
  400. if(posXstart <=pos.x)
  401. {
  402. posXstart = pos.x;
  403. posXend = pos.x + slider->getImageWidth();
  404. }
  405. TheWindowManager->winDrawImage(slider, posXstart, pos.y + size.y - slider->getImageHeight(), posXend, pos.y + size.y);
  406. }
  407. void W3DCommandBarGridDraw( GameWindow *window, WinInstanceData *instData )
  408. {
  409. if( BitTest(window->winGetStatus(), WIN_STATUS_IMAGE ))
  410. {
  411. W3DGameWinDefaultDraw( window, instData );
  412. return;
  413. }
  414. ICoord2D pos, size;
  415. window->winGetScreenPosition( &pos.x, &pos.y );
  416. window->winGetSize( &size.x, &size.y );
  417. Color color = TheControlBar->getBorderColor();
  418. window->winSetEnabledBorderColor(0, color);
  419. W3DGameWinDefaultDraw( window, instData );
  420. TheDisplay->drawLine(pos.x, pos.y + size.y * .33, pos.x + size.x, pos.y+ size.y*.33, 1,color);
  421. TheDisplay->drawLine(pos.x, pos.y + size.y * .66, pos.x + size.x, pos.y+ size.y*.66, 1,color);
  422. TheDisplay->drawLine(pos.x + size.x * .33, pos.y, pos.x + size.x *.33, pos.y +size.y, 1,color);
  423. TheDisplay->drawLine(pos.x + size.x * .66, pos.y, pos.x + size.x *.66, pos.y + size.y, 1,color);
  424. }
  425. void W3DCommandBarGenExpDraw( GameWindow *window, WinInstanceData *instData )
  426. {
  427. Player *player = ThePlayerList->getLocalPlayer();
  428. if(!player->isPlayerActive())
  429. return;
  430. static const Image *endBar = TheMappedImageCollection->findImageByName("GenExpBarTop1");
  431. static const Image *beginBar = TheMappedImageCollection->findImageByName("GenExpBarBottom1");
  432. static const Image *centerBar = TheMappedImageCollection->findImageByName("GenExpBar1");
  433. Int progress;
  434. progress = ((player->getSkillPoints() - player->getSkillPointsLevelDown()) * 100) /(player->getSkillPointsLevelUp() - player->getSkillPointsLevelDown());
  435. if(progress <= 0)
  436. return;
  437. // GS This should never be necessary, but scripts can change the points required or even disable a level.
  438. // A disabled level will be -1 for points required. Just be totally safe and bind to 100, and we will
  439. // fix the scripts to bind the points gained later.
  440. if( progress > 100 )
  441. progress = 100;
  442. ICoord2D pos, size;
  443. window->winGetScreenPosition( &pos.x, &pos.y );
  444. window->winGetSize( &size.x, &size.y );
  445. if( !endBar || !beginBar || !centerBar)
  446. return;
  447. Int range;
  448. range = size.y * progress / 100;
  449. // get image sizes for the ends
  450. ICoord2D topSize, bottomSize, start, end;
  451. bottomSize.x = beginBar->getImageWidth();
  452. bottomSize.y = beginBar->getImageHeight();
  453. topSize.x = endBar->getImageWidth();
  454. topSize.y = endBar->getImageHeight();
  455. // get two key points used in the end drawing
  456. ICoord2D bottomEnd, topStart;
  457. bottomEnd.x = pos.x + size.x;
  458. bottomEnd.y = pos.y + size.y - bottomSize.y;
  459. topStart.x = pos.x;
  460. topStart.y = pos.y +size.y - range - topSize.y;
  461. // draw the center repeating bar
  462. Int centerWidth, pieces;
  463. // get width we have to draw our repeating center in
  464. centerWidth = bottomEnd.y - topStart.y;
  465. if( centerWidth <= 0)
  466. {
  467. // draw left end
  468. start.x = pos.x;
  469. start.y = pos.y + size.y - bottomSize.y;
  470. end.y = pos.y + size.y;
  471. end.x = pos.x + size.x;
  472. TheWindowManager->winDrawImage(beginBar, start.x, start.y, end.x, end.y);
  473. // draw right end
  474. start.y = pos.y + size.y - bottomSize.y - topSize.y;
  475. start.x = pos.x;
  476. end.x = pos.x + size.x;
  477. end.y = start.y + topSize.y;
  478. TheWindowManager->winDrawImage(endBar, start.x, start.y, end.x, end.y);
  479. }
  480. else
  481. {
  482. // how many whole repeating pieces will fit in that width
  483. pieces = centerWidth / centerBar->getImageHeight();
  484. // draw the pieces
  485. start.x = pos.x;
  486. start.y = topStart.y;
  487. end.x = start.x + size.x; //centerImage->getImageHeight() + yOffset;
  488. for( Int i = 0; i < pieces; i++ )
  489. {
  490. end.y = start.y + centerBar->getImageHeight();
  491. TheWindowManager->winDrawImage( centerBar,
  492. start.x, start.y,
  493. end.x, end.y );
  494. start.y += centerBar->getImageHeight();
  495. } // end for i
  496. // we will draw the image but clip the parts we don't want to show
  497. IRegion2D reg;
  498. reg.lo.x = start.x;
  499. reg.lo.y = start.y;
  500. reg.hi.x = bottomEnd.x;
  501. reg.hi.y = bottomEnd.y;
  502. centerWidth = bottomEnd.y - start.y;
  503. if( centerWidth > 0)
  504. {
  505. TheDisplay->setClipRegion(&reg);
  506. end.y = start.y + centerBar->getImageHeight();
  507. TheWindowManager->winDrawImage( centerBar,
  508. start.x, start.y,
  509. end.x, end.y );
  510. TheDisplay->enableClipping(FALSE);
  511. }
  512. // draw left end
  513. end.x = pos.x + size.x;
  514. end.y = pos.y + size.y;
  515. start.x = pos.x;
  516. start.y = bottomEnd.y;
  517. TheWindowManager->winDrawImage(beginBar, start.x, start.y, end.x, end.y);
  518. // draw right end
  519. start.x = pos.x;
  520. start.y = pos.y +size.y - range;
  521. end.x = pos.x + size.x;
  522. end.y = pos.y +size.y - range - topSize.y;
  523. TheWindowManager->winDrawImage(endBar, start.x, start.y, end.x, end.y);
  524. }
  525. }
  526. void W3DCommandBarTopDraw( GameWindow *window, WinInstanceData *instData )
  527. {
  528. GameWindow *win = TheWindowManager->winGetWindowFromId(NULL, TheNameKeyGenerator->nameToKey("ControlBar.wnd:ButtonGeneral"));
  529. if(!win || win->winIsHidden() || !ThePlayerList->getLocalPlayer()->isPlayerActive())
  530. return;
  531. // TheControlBar->drawTransitionHandler();
  532. // ICoord2D pos, size, imageStart, imageEnd;
  533. // win->winGetScreenPosition(&pos.x, &pos.y);
  534. // win->winGetSize(&size.x, &size.y);
  535. //// const Image *image =TheControlBar->getStarImage();
  536. // imageStart.x = pos.x + size.x/2 - image->getImageWidth()/2;
  537. // imageStart.y = pos.y + size.y/2 - image->getImageHeight()/2;
  538. // imageEnd.x = imageStart.x + image->getImageWidth();
  539. // imageEnd.y = imageStart.y + image->getImageHeight();
  540. // TheDisplay->drawImage(TheControlBar->getStarImage(), imageStart.x, imageStart.y, imageEnd.x, imageEnd.y);
  541. }
  542. void W3DCommandBarBackgroundDraw( GameWindow *window, WinInstanceData *instData )
  543. {
  544. ControlBarSchemeManager *man = TheControlBar->getControlBarSchemeManager();
  545. if(!man)
  546. return;
  547. static NameKeyType winNamekey = TheNameKeyGenerator->nameToKey( AsciiString( "ControlBar.wnd:BackgroundMarker" ) );
  548. GameWindow *win = TheWindowManager->winGetWindowFromId(NULL,winNamekey);
  549. static ICoord2D basePos;
  550. if(!win)
  551. {
  552. return;
  553. //win = TheWindowManager->winGetWindowFromId(NULL,TheNameKeyGenerator->nameToKey( AsciiString( "ControlBar.wnd:BackgroundMarker" ) ));
  554. }
  555. TheControlBar->getBackgroundMarkerPos(&basePos.x, &basePos.y);
  556. ICoord2D pos, offset;
  557. win->winGetScreenPosition(&pos.x,&pos.y);
  558. offset.x = pos.x - basePos.x;
  559. offset.y = pos.y - basePos.y;
  560. man->drawBackground(offset);
  561. }
  562. void W3DCommandBarForegroundDraw( GameWindow *window, WinInstanceData *instData )
  563. {
  564. ControlBarSchemeManager *man = TheControlBar->getControlBarSchemeManager();
  565. if(!man)
  566. return;
  567. static NameKeyType winNamekey = TheNameKeyGenerator->nameToKey( AsciiString( "ControlBar.wnd:BackgroundMarker" ) );
  568. GameWindow *win = TheWindowManager->winGetWindowFromId(NULL,winNamekey);
  569. static ICoord2D basePos;
  570. if(!win)
  571. {
  572. return;
  573. //win = TheWindowManager->winGetWindowFromId(NULL,TheNameKeyGenerator->nameToKey( AsciiString( "ControlBar.wnd:BackgroundMarker" ) ));
  574. }
  575. TheControlBar->getForegroundMarkerPos(&basePos.x, &basePos.y);
  576. ICoord2D pos, offset;
  577. win->winGetScreenPosition(&pos.x,&pos.y);
  578. offset.x = pos.x - basePos.x;
  579. offset.y = pos.y - basePos.y;
  580. man->drawForeground(offset);
  581. }
  582. void W3DNoDraw( GameWindow *window, WinInstanceData *instData )
  583. {
  584. // draw the default stuff
  585. // W3DGameWinDefaultDraw( window, instData );
  586. } // end W3DRightHUDDraw
  587. void drawSkinnyBorder( Int x, Int y, Int width, Int height);
  588. void W3DDrawMapPreview( GameWindow *window, WinInstanceData *instData)
  589. {
  590. MapMetaData *mmData = (MapMetaData *)window->winGetUserData();
  591. Int pixelX, pixelY, width, height;
  592. // if the local player does not have a radar then we can't draw anything
  593. window->winGetScreenPosition(&pixelX, &pixelY);
  594. window->winGetSize(&width, &height);
  595. if(!mmData)
  596. {
  597. W3DGameWinDefaultDraw( window, instData );
  598. drawSkinnyBorder(pixelX - 1, pixelY - 1, width + 2, height + 2);
  599. return;
  600. }
  601. //
  602. // given a upper left corner at pixelX|Y and a width and height to draw into, figure out
  603. // where we should start and end the image so that the final drawn image has the
  604. // same ratio as the map and isn't stretched or distorted
  605. //
  606. ICoord2D ul, lr;
  607. findDrawPositions( pixelX, pixelY, width, height, mmData->m_extent, &ul, &lr );
  608. // Int scaledWidth = lr.x - ul.x;
  609. // Int scaledHeight = lr.y - ul.y;
  610. // draw black border areas where we need map
  611. Color fillColor = GameMakeColor( 0, 0, 0, 255 );
  612. Color lineColor = GameMakeColor( 50, 50, 50, 255 );
  613. if( mmData->m_extent.width()/width >= mmData->m_extent.height()/height )
  614. {
  615. // draw horizontal bars at top and bottom
  616. TheDisplay->drawFillRect( pixelX, pixelY, width, ul.y - pixelY - 1, fillColor );
  617. TheDisplay->drawFillRect( pixelX, lr.y + 1, width, pixelY + height - lr.y - 1, fillColor);
  618. TheDisplay->drawLine(pixelX, ul.y, pixelX + width, ul.y, 1, lineColor);
  619. TheDisplay->drawLine(pixelX, lr.y + 1, pixelX + width, lr.y + 1, 1, lineColor);
  620. } // end if
  621. else
  622. {
  623. // draw vertical bars to the left and right
  624. TheDisplay->drawFillRect( pixelX, pixelY, ul.x - pixelX - 1, height, fillColor );
  625. TheDisplay->drawFillRect( lr.x + 1, pixelY, width - (lr.x - pixelX) - 1, height, fillColor );
  626. TheDisplay->drawLine(ul.x, pixelY, ul.x, pixelY + height, 1, lineColor);
  627. TheDisplay->drawLine(lr.x + 1, pixelY, lr.x + 1, pixelY + height, 1, lineColor);
  628. } // end else
  629. if(!BitTest(window->winGetStatus(), WIN_STATUS_IMAGE) || !window->winGetEnabledImage(0))
  630. TheDisplay->drawFillRect(ul.x, ul.y, lr.x -ul.x, lr.y-ul.y, lineColor);
  631. else
  632. TheDisplay->drawImage(window->winGetEnabledImage(0) , ul.x, ul.y, lr.x, lr.y );
  633. const Image *image = TheMappedImageCollection->findImageByName("TecBuilding");
  634. ICoord2DList::iterator it = TheSupplyAndTechImageLocations.m_techPosList.begin();
  635. if(image)
  636. while(it != TheSupplyAndTechImageLocations.m_techPosList.end())
  637. {
  638. TheDisplay->drawImage(image, pixelX + it->x, pixelY + it->y, pixelX + it->x + SUPPLY_TECH_SIZE, pixelY + it->y +SUPPLY_TECH_SIZE);
  639. it++;
  640. }
  641. image = TheMappedImageCollection->findImageByName("Cash");
  642. it = TheSupplyAndTechImageLocations.m_supplyPosList.begin();
  643. if(image)
  644. while(it != TheSupplyAndTechImageLocations.m_supplyPosList.end())
  645. {
  646. TheDisplay->drawImage(image, pixelX + it->x, pixelY + it->y, pixelX + it->x + SUPPLY_TECH_SIZE, pixelY + it->y +SUPPLY_TECH_SIZE);
  647. it++;
  648. }
  649. drawSkinnyBorder(pixelX - 1, pixelY - 1, width + 2, height + 2);
  650. }
  651. void drawSkinnyBorder( Int x, Int y, Int width, Int height)
  652. {
  653. enum
  654. {
  655. BORDER_CORNER_SIZE = 5,
  656. BORDER_LINE_SIZE = 5,
  657. };
  658. Int Offset = 2;
  659. Int OffsetLower = 5;
  660. // save original x, y
  661. Int originalX = x;
  662. Int originalY = y;
  663. Int maxX = x + width;
  664. Int maxY = y + height;
  665. Int x2, y2; // used for simultaneous drawing of line pairs
  666. Int size = 5;
  667. Int halfSize = size / 2;
  668. const Image *image1, *image2;
  669. // Draw Horizontal Lines
  670. // All border pieces are based on a 10 pixel offset from the centerline
  671. y = originalY - Offset;
  672. y2 = maxY - OffsetLower;
  673. x2 = maxX - (OffsetLower + BORDER_LINE_SIZE);
  674. image1 = TheMappedImageCollection->findImageByName("FrameT");
  675. image2 = TheMappedImageCollection->findImageByName("FrameB");
  676. for( x=(originalX + 3); x <= x2; x += BORDER_LINE_SIZE )
  677. {
  678. TheDisplay->drawImage( image1,
  679. x, y, x + size, y + size );
  680. TheDisplay->drawImage( image2,
  681. x, y2, x + size, y2 + size );
  682. }
  683. x2 = maxX - 5;//BORDER_CORNER_SIZE;
  684. // x == place to draw remainder if any
  685. if( (x2 - x) >= (BORDER_LINE_SIZE / 2) )
  686. {
  687. //Blit Half piece
  688. TheDisplay->drawImage( image1,
  689. x, y, x + halfSize, y + size );
  690. TheDisplay->drawImage( image2,
  691. x, y2, x + halfSize, y2 + size );
  692. x += (BORDER_LINE_SIZE / 2);
  693. }
  694. // x2 - x ... must now be less than a half piece
  695. // check for equals and if not blit an adjusted half piece border pieces have
  696. // a two pixel repeat so we will blit one pixel over if necessary to line up
  697. // the art, but we'll cover-up the overlap with the corners
  698. if( x < x2 )
  699. {
  700. x -= ((BORDER_LINE_SIZE / 2) - (((x2 - x) + 1) & ~1));
  701. //Blit Half piece
  702. TheDisplay->drawImage(image1,
  703. x, y, x + halfSize, y + size );
  704. TheDisplay->drawImage( image2,
  705. x, y2, x + halfSize, y2 + size );
  706. }
  707. // Draw Vertical Lines
  708. // All border pieces are based on a 10 pixel offset from the centerline
  709. image1 = TheMappedImageCollection->findImageByName("FrameL");
  710. image2 = TheMappedImageCollection->findImageByName("FrameR");
  711. x = originalX - Offset;
  712. x2 = maxX - OffsetLower;
  713. y2 = maxY - (OffsetLower + BORDER_LINE_SIZE);
  714. for( y=(originalY + 3); y <= y2; y += BORDER_LINE_SIZE )
  715. {
  716. TheDisplay->drawImage( image1,
  717. x, y, x + size, y + size );
  718. TheDisplay->drawImage( image2,
  719. x2, y, x2 + size, y + size );
  720. }
  721. y2 = maxY - OffsetLower;//BORDER_CORNER_SIZE;
  722. // y == place to draw remainder if any
  723. if( (y2 - y) >= (BORDER_LINE_SIZE / 2) )
  724. {
  725. //Blit Half piece
  726. TheDisplay->drawImage( image1,
  727. x, y, x + size, y + halfSize );
  728. TheDisplay->drawImage( image2,
  729. x2, y, x2 + size, y + halfSize );
  730. y += (BORDER_LINE_SIZE / 2);
  731. }
  732. // y2 - y ... must now be less than a half piece
  733. // check for equals and if not blit an adjusted half piece border pieces have
  734. // a two pixel repeat so we will blit one pixel over if necessary to line up
  735. // the art, but we'll cover-up the overlap with the corners
  736. if( y < y2 )
  737. {
  738. y -= ((BORDER_LINE_SIZE / 2) - (((y2 - y) + 1) & ~1));
  739. //Blit Half piece
  740. TheDisplay->drawImage( image1,
  741. x, y, x + size, y + halfSize );
  742. TheDisplay->drawImage( image2,
  743. x2, y, x2 + size, y + halfSize );
  744. }
  745. // Draw Corners
  746. x = originalX - 2;//BORDER_CORNER_SIZE ;
  747. y = originalY - 2;//BORDER_CORNER_SIZE;
  748. image1 = TheMappedImageCollection->findImageByName("FrameCornerUL");
  749. TheDisplay->drawImage( image1,
  750. x, y, x + size, y + size );
  751. x = maxX - 5;//BORDER_CORNER_SIZE;
  752. y = originalY - 2;//BORDER_CORNER_SIZE;
  753. image1 = TheMappedImageCollection->findImageByName("FrameCornerUR");
  754. TheDisplay->drawImage(image1,
  755. x, y, x + size, y + size );
  756. x = originalX - 2;//BORDER_CORNER_SIZE;
  757. y = maxY - 5;//BORDER_CORNER_SIZE;
  758. image1 = TheMappedImageCollection->findImageByName("FrameCornerLL");
  759. TheDisplay->drawImage( image1,
  760. x, y, x + size, y + size );
  761. x = maxX - 5;//BORDER_CORNER_SIZE;
  762. y = maxY - 5;//BORDER_CORNER_SIZE;
  763. image1 = TheMappedImageCollection->findImageByName("FrameCornerLR");
  764. TheDisplay->drawImage(image1,
  765. x, y, x + size, y + size );
  766. }
  767. void W3DCommandBarHelpPopupDraw( GameWindow *window, WinInstanceData *instData )
  768. {
  769. static const Image *endBar = TheMappedImageCollection->findImageByName("Helpbox-top");
  770. static const Image *beginBar = TheMappedImageCollection->findImageByName("Helpbox-bottom");
  771. static const Image *centerBar = TheMappedImageCollection->findImageByName("Helpbox-middle");
  772. ICoord2D pos, size;
  773. window->winGetScreenPosition( &pos.x, &pos.y );
  774. window->winGetSize( &size.x, &size.y );
  775. if( !endBar || !beginBar || !centerBar)
  776. return;
  777. // Int range;
  778. // range = size.y;
  779. // get image sizes for the ends
  780. ICoord2D topSize, bottomSize, start, end;
  781. bottomSize.x = beginBar->getImageWidth();
  782. bottomSize.y = beginBar->getImageHeight();
  783. topSize.x = endBar->getImageWidth();
  784. topSize.y = endBar->getImageHeight();
  785. // get two key points used in the end drawing
  786. ICoord2D bottomEnd, topStart;
  787. bottomEnd.x = pos.x + size.x;
  788. bottomEnd.y = pos.y + size.y - bottomSize.y;
  789. topStart.x = pos.x;
  790. topStart.y = pos.y +size.y - topSize.y;
  791. // draw the center repeating bar
  792. Int centerWidth, pieces;
  793. // get width we have to draw our repeating center in
  794. centerWidth = size.y - topSize.y - bottomSize.y;
  795. if( centerWidth <= 0)
  796. {
  797. // draw left end
  798. start.x = pos.x;
  799. start.y = pos.y + size.y - bottomSize.y;
  800. end.y = pos.y + size.y;
  801. end.x = pos.x + size.x;
  802. TheWindowManager->winDrawImage(beginBar, start.x, start.y, end.x, end.y);
  803. // draw right end
  804. start.y = pos.y + size.y - bottomSize.y - topSize.y;
  805. start.x = pos.x;
  806. end.x = pos.x + size.x;
  807. end.y = start.y + topSize.y;
  808. TheWindowManager->winDrawImage(endBar, start.x, start.y, end.x, end.y);
  809. }
  810. else
  811. {
  812. // how many whole repeating pieces will fit in that width
  813. pieces = centerWidth / centerBar->getImageHeight();
  814. // draw the pieces
  815. start.x = pos.x;
  816. start.y = pos.y + topSize.y ;
  817. end.x = start.x + size.x; //centerImage->getImageHeight() + yOffset;
  818. for( Int i = 0; i < pieces; i++ )
  819. {
  820. end.y = start.y + centerBar->getImageHeight();
  821. TheWindowManager->winDrawImage( centerBar,
  822. start.x, start.y,
  823. end.x, end.y );
  824. start.y += centerBar->getImageHeight();
  825. } // end for i
  826. // we will draw the image but clip the parts we don't want to show
  827. IRegion2D reg;
  828. reg.lo.x = start.x;
  829. reg.lo.y = start.y;
  830. reg.hi.x = pos.x + size.x;
  831. reg.hi.y = pos.y + size.y - bottomSize.y;
  832. centerWidth = pos.y + size.y - bottomSize.y - start.y;
  833. if( centerWidth > 0)
  834. {
  835. TheDisplay->setClipRegion(&reg);
  836. end.y = start.y + centerBar->getImageHeight();
  837. TheWindowManager->winDrawImage( centerBar,
  838. start.x, start.y,
  839. end.x, end.y );
  840. TheDisplay->enableClipping(FALSE);
  841. }
  842. // draw left end
  843. end.x = pos.x + size.x;
  844. end.y = pos.y + size.y;
  845. start.x = pos.x;
  846. start.y = pos.y + size.y - bottomSize.y;
  847. TheWindowManager->winDrawImage(beginBar, start.x, start.y, end.x, end.y);
  848. // draw right end
  849. start.x = pos.x;
  850. start.y = pos.y ;
  851. end.x = pos.x + size.x;
  852. end.y = pos.y + topSize.y;
  853. TheWindowManager->winDrawImage(endBar, start.x, start.y, end.x, end.y);
  854. }
  855. }