stylemgr.cpp 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143
  1. /*
  2. ** Command & Conquer Renegade(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. *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
  20. ***********************************************************************************************
  21. * *
  22. * Project Name : Combat *
  23. * *
  24. * $Archive:: /Commando/Code/wwui/stylemgr.cpp $*
  25. * *
  26. * Author:: Patrick Smith *
  27. * *
  28. * $Modtime:: 1/26/02 1:23p $*
  29. * *
  30. * $Revision:: 33 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. // Disable warning about exception handling not being enabled. It's used as part of STL - in a part of STL we don't use.
  36. #pragma warning(disable : 4530)
  37. #include "stylemgr.h"
  38. #include "render2d.h"
  39. #include "assetmgr.h"
  40. #include "texture.h"
  41. #include "font3d.h"
  42. #include "render2dsentence.h"
  43. #include "ini.h"
  44. #include "ffactory.h"
  45. #include "wwaudio.h"
  46. ////////////////////////////////////////////////////////////////
  47. // Local constants
  48. ////////////////////////////////////////////////////////////////
  49. static const char * DEFAULT_BACKDROP_NAME = "GRADENT_TEST.TGA";
  50. struct FONT_DESC
  51. {
  52. const char * name;
  53. int point_size;
  54. bool is_bold;
  55. };
  56. static FONT_DESC DEFAULT_FONTS[StyleMgrClass::FONT_MAX] =
  57. {
  58. { "Regatta Condensed LET", 52, false },
  59. { "Arial MT", 12, true },
  60. { "Arial MT", 8, true },
  61. { "Arial MT", 8, false },
  62. { "Arial MT", 8, false },
  63. { "Regatta Condensed LET", 32, false },
  64. { "Regatta Condensed LET", 20, false },
  65. { "Arial MT", 9, true },
  66. { "Arial MT", 12, true },
  67. { "Arial MT", 10, false },
  68. { "Arial MT", 10, true },
  69. { "Arial MT", 8, false },
  70. { "Arial MT", 16, false },
  71. { "Arial MT", 14, false },
  72. { "Arial MT", 9, true }
  73. /*{ "Arial Unicode MS", 52, false },
  74. { "Arial Unicode MS", 12, true },
  75. { "Arial Unicode MS", 12, true },
  76. { "Arial Unicode MS", 12, false },
  77. { "Arial Unicode MS", 12, false },
  78. { "Arial Unicode MS", 32, false },
  79. { "Arial Unicode MS", 20, false },
  80. { "Arial Unicode MS", 13, true },
  81. { "Arial Unicode MS", 14, true }*/
  82. };
  83. ////////////////////////////////////////////////////////////////
  84. // Local constants
  85. ////////////////////////////////////////////////////////////////
  86. TextureClass * StyleMgrClass::BackdropTexture = NULL;
  87. uint32 StyleMgrClass::TitleColor = RGB_TO_INT32 (255, 255, 255);
  88. uint32 StyleMgrClass::TitleHilightColor = RGB_TO_INT32 (255, 255, 0);
  89. uint32 StyleMgrClass::TitleShadowColor = RGB_TO_INT32 (0, 0, 0);
  90. uint32 StyleMgrClass::TextColor = RGB_TO_INT32 (255, 213, 40);
  91. uint32 StyleMgrClass::TextShadowColor = RGBA_TO_INT32 (0, 0, 0, 200);
  92. uint32 StyleMgrClass::LineColor = RGB_TO_INT32 (255, 174, 40);
  93. uint32 StyleMgrClass::BkColor = RGBA_TO_INT32 (255, 174, 40, 40);
  94. uint32 StyleMgrClass::DisabledTextColor = RGBA_TO_INT32 (255, 213, 40, 140);
  95. uint32 StyleMgrClass::DisabledTextShadowColor = RGBA_TO_INT32 (0, 0, 0, 96);
  96. uint32 StyleMgrClass::DisabledLineColor = RGBA_TO_INT32 (230, 160, 35, 128);
  97. uint32 StyleMgrClass::DisabledBkColor = RGBA_TO_INT32 (255, 174, 40, 30);
  98. uint32 StyleMgrClass::HilightColor = RGB_TO_INT32 (70, 70, 70);
  99. uint32 StyleMgrClass::TabTextColor = RGB_TO_INT32 (255, 255, 255);
  100. uint32 StyleMgrClass::TabGlowColor = RGB_TO_INT32 (16, 10, 0);
  101. FontCharsClass * StyleMgrClass::Fonts[FONT_MAX] = { NULL };
  102. float StyleMgrClass::ScaleX = 1.0F;
  103. float StyleMgrClass::ScaleY = 1.0F;
  104. DynamicVectorClass<StringClass> StyleMgrClass::FontFileList;
  105. StringClass StyleMgrClass::EventAudioList[StyleMgrClass::EVENT_AUDIO_MAX];
  106. ////////////////////////////////////////////////////////////////
  107. //
  108. // Initialize
  109. //
  110. ////////////////////////////////////////////////////////////////
  111. void
  112. StyleMgrClass::Initialize (void)
  113. {
  114. //
  115. // Compute the scale
  116. //
  117. ScaleX = Render2DClass::Get_Screen_Resolution().Width () / 800.0F;
  118. ScaleY = Render2DClass::Get_Screen_Resolution().Height () / 600.0F;
  119. //
  120. // Load each font
  121. //
  122. for (int index = 0; index < FONT_MAX; index ++) {
  123. //
  124. // Scale the point size to fit this resolution
  125. //
  126. float point_size = ((float)DEFAULT_FONTS[index].point_size) * ScaleY;
  127. //
  128. // Create the font
  129. //
  130. Fonts[index] = WW3DAssetManager::Get_Instance()->Get_FontChars (DEFAULT_FONTS[index].name,
  131. point_size, DEFAULT_FONTS[index].is_bold);
  132. }
  133. //
  134. // Load the backdrop texture name
  135. //
  136. BackdropTexture = WW3DAssetManager::Get_Instance()->Get_Texture (DEFAULT_BACKDROP_NAME, TextureClass::MIP_LEVELS_1);
  137. return ;
  138. }
  139. ////////////////////////////////////////////////////////////////
  140. //
  141. // Initialize_From_INI
  142. //
  143. ////////////////////////////////////////////////////////////////
  144. void
  145. StyleMgrClass::Initialize_From_INI (const char *filename)
  146. {
  147. Shutdown ();
  148. //
  149. // Compute the scale
  150. //
  151. ScaleX = Render2DClass::Get_Screen_Resolution().Width () / 800.0F;
  152. ScaleY = Render2DClass::Get_Screen_Resolution().Height () / 600.0F;
  153. //
  154. // Get the INI file
  155. //
  156. INIClass *ini_file = NULL;
  157. FileClass *file_obj = _TheFileFactory->Get_File (filename);
  158. if (file_obj != NULL && file_obj->Is_Available( ) ) {
  159. ini_file = new INIClass (*file_obj);
  160. _TheFileFactory->Return_File (file_obj);
  161. }
  162. if (ini_file != NULL) {
  163. const char *FONT_FILE_SECTION = "Font File List";
  164. const char *FONT_NAME_SECTION = "Font Names";
  165. const char *FONT_INI_ENTRIES[FONT_MAX] =
  166. {
  167. "FONT_TITLE",
  168. "FONT_LG_CONTROLS",
  169. "FONT_CONTROLS",
  170. "FONT_LISTS",
  171. "FONT_TOOLTIPS",
  172. "FONT_MENU",
  173. "FONT_SM_MENU",
  174. "FONT_HEADER",
  175. "FONT_BIG_HEADER",
  176. "FONT_CREDITS",
  177. "FONT_CREDITS_BOLD",
  178. "FONT_INGAME_TXT",
  179. "FONT_INGAME_BIG_TXT",
  180. "FONT_INGAME_SUBTITLE_TXT",
  181. "FONT_INGAME_HEADER_TXT"
  182. };
  183. //
  184. // Load each font into windows
  185. //
  186. int count = ini_file->Entry_Count (FONT_FILE_SECTION);
  187. for (int index = 0; index < count; index ++) {
  188. StringClass filename (0, true);
  189. ini_file->Get_String (filename, FONT_FILE_SECTION, ini_file->Get_Entry (FONT_FILE_SECTION, index));
  190. //
  191. // Install the font into windows
  192. //
  193. ::AddFontResource (filename);
  194. FontFileList.Add (filename);
  195. }
  196. //
  197. // Read information about each font and load it into the system
  198. //
  199. for (index = 0; index < FONT_MAX; index ++) {
  200. //
  201. // Read information about this font
  202. //
  203. StringClass font_entry;
  204. ini_file->Get_String (font_entry, FONT_NAME_SECTION, FONT_INI_ENTRIES[index]);
  205. //
  206. // Parse the information
  207. //
  208. StringClass font_name = ::strtok (font_entry.Peek_Buffer (), ",");
  209. StringClass font_size = ::strtok (NULL, ",");
  210. StringClass font_bold = ::strtok (NULL, ",");
  211. bool is_bold = (::atoi (font_bold) != 0);
  212. //
  213. // Scale the point size to fit this resolution
  214. //
  215. float point_size = ((float)::atoi (font_size)) * ScaleY;
  216. //
  217. // Remove bold from "small" fonts if they're scaled down
  218. //
  219. point_size = max (point_size, 8.0F);
  220. if (point_size < 10.0F && ScaleY < 1.0F) {
  221. is_bold = false;
  222. }
  223. //
  224. // Create the font
  225. //
  226. Fonts[index] = WW3DAssetManager::Get_Instance()->Get_FontChars (font_name,
  227. point_size, is_bold);
  228. }
  229. //
  230. // Audio section constants
  231. //
  232. const char *AUDIO_SECTION = "Audio";
  233. const char *AUDIO_CLICK = "AUDIO_CLICK";
  234. const char *AUDIO_MOUSEOVER = "AUDIO_MOUSEOVER";
  235. const char *AUDIO_BACK = "AUDIO_BACK";
  236. const char *AUDIO_POPUP = "AUDIO_POPUP";
  237. //
  238. // Read information about the sound effects
  239. //
  240. ini_file->Get_String (EventAudioList[EVENT_MOUSE_CLICK], AUDIO_SECTION, AUDIO_CLICK);
  241. ini_file->Get_String (EventAudioList[EVENT_MOUSE_OVER], AUDIO_SECTION, AUDIO_MOUSEOVER);
  242. ini_file->Get_String (EventAudioList[EVENT_MENU_BACK], AUDIO_SECTION, AUDIO_BACK);
  243. ini_file->Get_String (EventAudioList[EVENT_POPUP], AUDIO_SECTION, AUDIO_POPUP);
  244. //
  245. // Free the ini file
  246. //
  247. delete ini_file;
  248. ini_file = NULL;
  249. }
  250. return ;
  251. }
  252. ////////////////////////////////////////////////////////////////
  253. //
  254. // Shutdown
  255. //
  256. ////////////////////////////////////////////////////////////////
  257. void
  258. StyleMgrClass::Shutdown (void)
  259. {
  260. //
  261. // Free each font
  262. //
  263. for (int index = 0; index < FONT_MAX; index ++) {
  264. REF_PTR_RELEASE (Fonts[index]);
  265. }
  266. //
  267. // Unregister this font with windows
  268. //
  269. for (index = 0; index < FontFileList.Count (); index ++) {
  270. ::RemoveFontResource (FontFileList[index]);
  271. }
  272. //
  273. // Free the backdrop texture
  274. //
  275. REF_PTR_RELEASE (BackdropTexture);
  276. return ;
  277. }
  278. ////////////////////////////////////////////////////////////////
  279. //
  280. // Get_Font
  281. //
  282. ////////////////////////////////////////////////////////////////
  283. FontCharsClass *
  284. StyleMgrClass::Get_Font (FONT_STYLE style)
  285. {
  286. FontCharsClass *font = Fonts[style];
  287. if (font != NULL) {
  288. font->Add_Ref ();
  289. }
  290. return font;
  291. }
  292. ////////////////////////////////////////////////////////////////
  293. //
  294. // Render_Backdrop
  295. //
  296. ////////////////////////////////////////////////////////////////
  297. void
  298. StyleMgrClass::Render_Backdrop (Render2DClass *renderer, const RectClass &rect)
  299. {
  300. //
  301. // Simply set the texture, and render a quad filling the rectangle
  302. //
  303. renderer->Set_Texture (BackdropTexture);
  304. renderer->Add_Quad (rect, RectClass (0, 0, 1, 1));
  305. return ;
  306. }
  307. ////////////////////////////////////////////////////////////////
  308. //
  309. // Assign_Font
  310. //
  311. ////////////////////////////////////////////////////////////////
  312. void
  313. StyleMgrClass::Assign_Font (Render2DSentenceClass *renderer, FONT_STYLE style)
  314. {
  315. renderer->Set_Font (Fonts[style]);
  316. return ;
  317. }
  318. ////////////////////////////////////////////////////////////////
  319. //
  320. // Render_Text
  321. //
  322. ////////////////////////////////////////////////////////////////
  323. /*void
  324. StyleMgrClass::Render_Text
  325. (
  326. const WCHAR * text,
  327. Render2DTextClass * renderer,
  328. int x_pos,
  329. int y_pos,
  330. bool do_shadow,
  331. const RectClass * clipping_rect,
  332. bool is_enabled
  333. )
  334. {
  335. //
  336. // If necessary, assign the clipping rectangle
  337. //
  338. if (clipping_rect != NULL) {
  339. renderer->Set_Clipping_Rect (*clipping_rect);
  340. }
  341. //
  342. // Determine what color to render the text in
  343. //
  344. int text_color = TextColor;
  345. int shadow_color = TextShadowColor;
  346. if (is_enabled == false) {
  347. text_color = DisabledTextColor;
  348. shadow_color = DisabledTextShadowColor;
  349. }
  350. //
  351. // Render the shadow (if necessary)
  352. //
  353. if (do_shadow) {
  354. renderer->Set_Location (Vector2 (x_pos - 1, y_pos + 1));
  355. renderer->Draw_Text (text, shadow_color);
  356. }
  357. //
  358. // Set the position where text will be drawn
  359. //
  360. renderer->Set_Location (Vector2 (x_pos, y_pos));
  361. //
  362. // Draw the text
  363. //
  364. renderer->Draw_Text (text, text_color);
  365. return ;
  366. }*/
  367. ////////////////////////////////////////////////////////////////
  368. //
  369. // Render_Title_Text
  370. //
  371. ////////////////////////////////////////////////////////////////
  372. void
  373. StyleMgrClass::Render_Title_Text
  374. (
  375. const WCHAR * text,
  376. Render2DSentenceClass * renderer,
  377. const RectClass & rect
  378. )
  379. {
  380. //
  381. // Set the clipping rectangle
  382. //
  383. //renderer->Set_Clipping_Rect (rect);
  384. //
  385. // Get the extents of the text we will be drawing
  386. //
  387. Vector2 text_extent = renderer->Get_Text_Extents (text);
  388. //
  389. // Center the text
  390. //
  391. int x_pos = int(rect.Left + (rect.Width () / 2) - (text_extent.X / 2));
  392. int y_pos = int(rect.Top + (rect.Height () / 2) - (text_extent.Y / 2));
  393. //
  394. // Build the textures for the text we'll be drawing
  395. //
  396. renderer->Build_Sentence (text);
  397. //
  398. // Draw the shadow
  399. //
  400. renderer->Set_Location (Vector2 (x_pos - 1, y_pos - 1));
  401. renderer->Draw_Sentence (TitleShadowColor);
  402. //
  403. // Draw the hilight
  404. //
  405. renderer->Set_Location (Vector2 (x_pos + 1, y_pos + 1));
  406. renderer->Draw_Sentence (TitleHilightColor);
  407. //
  408. // Draw the text
  409. //
  410. renderer->Set_Location (Vector2 (x_pos, y_pos));
  411. renderer->Draw_Sentence (TitleColor);
  412. return ;
  413. }
  414. ////////////////////////////////////////////////////////////////
  415. //
  416. // Render_Text
  417. //
  418. ////////////////////////////////////////////////////////////////
  419. void
  420. StyleMgrClass::Render_Text
  421. (
  422. const WCHAR * text,
  423. Render2DSentenceClass * renderer,
  424. const RectClass & rect,
  425. bool do_shadow,
  426. bool do_clip,
  427. JUSTIFICATION justify,
  428. bool is_enabled,
  429. bool is_vcentered
  430. )
  431. {
  432. //
  433. // Determine what color to render the text in
  434. //
  435. int text_color = TextColor;
  436. int shadow_color = TextShadowColor;
  437. if (is_enabled == false) {
  438. text_color = DisabledTextColor;
  439. shadow_color = DisabledTextShadowColor;
  440. }
  441. Render_Text (text, renderer, text_color, shadow_color, rect, do_shadow, do_clip, justify, is_vcentered);
  442. return ;
  443. }
  444. ////////////////////////////////////////////////////////////////
  445. //
  446. // Render_Text
  447. //
  448. ////////////////////////////////////////////////////////////////
  449. void
  450. StyleMgrClass::Render_Text
  451. (
  452. const WCHAR * text,
  453. Render2DSentenceClass * renderer,
  454. uint32 text_color,
  455. uint32 shadow_color,
  456. const RectClass & rect,
  457. bool do_shadow,
  458. bool do_clip,
  459. JUSTIFICATION justify,
  460. bool is_vcentered
  461. )
  462. {
  463. //
  464. // If necessary, assign the clipping rectangle
  465. //
  466. if (do_clip) {
  467. renderer->Set_Clipping_Rect (rect);
  468. }
  469. //
  470. // Get the extents of the text we will be drawing
  471. //
  472. Vector2 text_extent = renderer->Get_Text_Extents (text);
  473. //
  474. // Assume left justification
  475. //
  476. int x_pos = rect.Left + 1;
  477. int y_pos = int(rect.Top + (rect.Height () / 2) - (text_extent.Y / 2));
  478. if (is_vcentered == false) {
  479. y_pos = rect.Top;
  480. }
  481. //
  482. // Handle other justifications
  483. //
  484. if (justify == RIGHT_JUSTIFY) {
  485. //
  486. // Caclulate right justification
  487. //
  488. x_pos = int(rect.Right - text_extent.X);
  489. } else if (justify == CENTER_JUSTIFY) {
  490. //
  491. // Calculate center justification
  492. //
  493. x_pos = int(rect.Left + (rect.Width () / 2) - (text_extent.X / 2));
  494. }
  495. //
  496. // Construct the textures needed to render the text
  497. //
  498. renderer->Build_Sentence (text);
  499. //
  500. // Render the shadow (if necessary)
  501. //
  502. if (do_shadow) {
  503. renderer->Set_Location (Vector2 (x_pos - 1, y_pos + 1));
  504. renderer->Draw_Sentence (shadow_color);
  505. }
  506. //
  507. // Render the text
  508. //
  509. renderer->Set_Location (Vector2 (x_pos, y_pos));
  510. renderer->Draw_Sentence (text_color);
  511. return ;
  512. }
  513. ////////////////////////////////////////////////////////////////
  514. //
  515. // Render_Text
  516. //
  517. ////////////////////////////////////////////////////////////////
  518. /*void
  519. StyleMgrClass::Render_Text
  520. (
  521. const WCHAR * text,
  522. Render2DTextClass * renderer,
  523. uint32 text_color,
  524. uint32 shadow_color,
  525. const RectClass & rect,
  526. bool do_shadow,
  527. bool do_clip,
  528. JUSTIFICATION justify
  529. )
  530. {
  531. //
  532. // If necessary, assign the clipping rectangle
  533. //
  534. if (do_clip) {
  535. renderer->Set_Clipping_Rect (rect);
  536. }
  537. //
  538. // Get the extents of the text we will be drawing
  539. //
  540. Vector2 text_extent = renderer->Get_Text_Extents (text);
  541. //
  542. // Assume left justification
  543. //
  544. int x_pos = rect.Left + 1;
  545. int y_pos = int(rect.Top + (rect.Height () / 2) - (text_extent.Y / 2));
  546. //
  547. // Handle other justifications
  548. //
  549. if (justify == RIGHT_JUSTIFY) {
  550. //
  551. // Caclulate right justification
  552. //
  553. x_pos = int(rect.Right - text_extent.X);
  554. } else if (justify == CENTER_JUSTIFY) {
  555. //
  556. // Calculate center justification
  557. //
  558. x_pos = int(rect.Left + (rect.Width () / 2) - (text_extent.X / 2));
  559. }
  560. //
  561. // Render the shadow (if necessary)
  562. //
  563. if (do_shadow) {
  564. renderer->Set_Location (Vector2 (x_pos - 1, y_pos + 1));
  565. renderer->Draw_Text (text, shadow_color);
  566. }
  567. //
  568. // Render the text
  569. //
  570. renderer->Set_Location (Vector2 (x_pos, y_pos));
  571. renderer->Draw_Text (text, text_color);
  572. return ;
  573. }*/
  574. ////////////////////////////////////////////////////////////////
  575. //
  576. // Render_Text
  577. //
  578. ////////////////////////////////////////////////////////////////
  579. /*void
  580. StyleMgrClass::Render_Text
  581. (
  582. const WCHAR * text,
  583. Render2DSentenceClass * renderer,
  584. uint32 text_color,
  585. uint32 shadow_color,
  586. const RectClass & rect,
  587. bool do_shadow,
  588. bool do_clip,
  589. JUSTIFICATION justify
  590. )
  591. {
  592. //
  593. // If necessary, assign the clipping rectangle
  594. //
  595. if (do_clip) {
  596. renderer->Set_Clipping_Rect (rect);
  597. }
  598. //
  599. // Get the extents of the text we will be drawing
  600. //
  601. Vector2 text_extent = renderer->Get_Text_Extents (text);
  602. //
  603. // Assume left justification
  604. //
  605. int x_pos = rect.Left + 1;
  606. int y_pos = int(rect.Top + (rect.Height () / 2) - (text_extent.Y / 2));
  607. //
  608. // Handle other justifications
  609. //
  610. if (justify == RIGHT_JUSTIFY) {
  611. //
  612. // Caclulate right justification
  613. //
  614. x_pos = int(rect.Right - text_extent.X);
  615. } else if (justify == CENTER_JUSTIFY) {
  616. //
  617. // Calculate center justification
  618. //
  619. x_pos = int(rect.Left + (rect.Width () / 2) - (text_extent.X / 2));
  620. }
  621. //
  622. // Build up the text we want to render
  623. //
  624. renderer->Build_Sentence (text);
  625. //
  626. // Render the shadow (if necessary)
  627. //
  628. if (do_shadow) {
  629. renderer->Set_Location (Vector2 (x_pos - 1, y_pos + 1));
  630. renderer->Draw_Sentence (shadow_color);
  631. }
  632. //
  633. // Render the text
  634. //
  635. renderer->Set_Location (Vector2 (x_pos, y_pos));
  636. renderer->Draw_Sentence (text_color);
  637. return ;
  638. }*/
  639. ////////////////////////////////////////////////////////////////
  640. //
  641. // Render_Wrapped_Text
  642. //
  643. ////////////////////////////////////////////////////////////////
  644. void
  645. StyleMgrClass::Render_Wrapped_Text
  646. (
  647. const WCHAR * text,
  648. Render2DSentenceClass * renderer,
  649. const RectClass & rect,
  650. bool do_shadow,
  651. bool do_vcenter,
  652. bool is_enabled
  653. )
  654. {
  655. //
  656. // Determine what color to render the text in
  657. //
  658. int text_color = TextColor;
  659. int shadow_color = TextShadowColor;
  660. if (is_enabled == false) {
  661. text_color = DisabledTextColor;
  662. shadow_color = DisabledTextShadowColor;
  663. }
  664. //
  665. // Render the text
  666. //
  667. Render_Wrapped_Text (text, renderer, text_color, shadow_color, rect, do_shadow, do_vcenter);
  668. return ;
  669. }
  670. ////////////////////////////////////////////////////////////////
  671. //
  672. // Render_Wrapped_Text
  673. //
  674. ////////////////////////////////////////////////////////////////
  675. void
  676. StyleMgrClass::Render_Wrapped_Text_Ex
  677. (
  678. const WCHAR * text,
  679. Render2DSentenceClass * renderer,
  680. const RectClass & rect,
  681. bool do_shadow,
  682. bool do_vcenter,
  683. bool is_enabled,
  684. JUSTIFICATION justify
  685. )
  686. {
  687. //
  688. // Determine what color to render the text in
  689. //
  690. int text_color = TextColor;
  691. int shadow_color = TextShadowColor;
  692. if (is_enabled == false) {
  693. text_color = DisabledTextColor;
  694. shadow_color = DisabledTextShadowColor;
  695. }
  696. //
  697. // Render the text
  698. //
  699. Render_Wrapped_Text_Ex (text, renderer, text_color, shadow_color, rect,
  700. do_shadow, do_vcenter, justify);
  701. return ;
  702. }
  703. ////////////////////////////////////////////////////////////////
  704. //
  705. // Render_Wrapped_Text
  706. //
  707. ////////////////////////////////////////////////////////////////
  708. void
  709. StyleMgrClass::Render_Wrapped_Text_Ex
  710. (
  711. const WCHAR * text,
  712. Render2DSentenceClass * renderer,
  713. uint32 text_color,
  714. uint32 shadow_color,
  715. const RectClass & rect,
  716. bool do_shadow,
  717. bool do_vcenter,
  718. JUSTIFICATION justify
  719. )
  720. {
  721. //
  722. // Enable wrapping
  723. //
  724. renderer->Set_Wrapping_Width (rect.Width ());
  725. renderer->Set_Clipping_Rect (rect);
  726. //
  727. // First, get the number of lines of text
  728. //
  729. int row_count = 0;
  730. renderer->Get_Formatted_Text_Extents (text, &row_count);
  731. //
  732. // Calculate where to start spitting out the text
  733. //
  734. float text_height = renderer->Peek_Font ()->Get_Char_Height ();
  735. RectClass curr_rect = rect;
  736. if (do_vcenter) {
  737. curr_rect.Top = int(rect.Center ().Y - ((row_count * text_height) * 0.5F));
  738. }
  739. //
  740. // Handy macro
  741. //
  742. #define COPY_LINE(dest, src_start, src_end) \
  743. if (src_end == NULL) { \
  744. dest = src_start; \
  745. } else { \
  746. uint32 bytes = ((uint32)src_end - (uint32)src_start); \
  747. uint32 len = bytes / sizeof (WCHAR); \
  748. ::memcpy (dest.Get_Buffer (len + 1), src_start, bytes); \
  749. dest.Peek_Buffer ()[len] = 0; \
  750. }
  751. //
  752. // Loop over all the lines of text and check for wrapping...
  753. //
  754. const WCHAR *line_start = renderer->Find_Row_Start (text, 0);
  755. while (line_start != NULL) {
  756. //
  757. // Lookup the start of the next line...
  758. //
  759. const WCHAR *line_end = renderer->Find_Row_Start (line_start, 1);
  760. //
  761. // Copy this line of text into the control
  762. //
  763. WideStringClass curr_text;
  764. COPY_LINE (curr_text, line_start, line_end);
  765. //
  766. // Render this row of text
  767. //
  768. Render_Text (curr_text, renderer, text_color, shadow_color, curr_rect,
  769. do_shadow, false, justify, false);
  770. //
  771. // Advance to the next line...
  772. //
  773. line_start = line_end;
  774. curr_rect.Top += text_height;
  775. }
  776. return ;
  777. }
  778. ////////////////////////////////////////////////////////////////
  779. //
  780. // Render_Wrapped_Text
  781. //
  782. ////////////////////////////////////////////////////////////////
  783. void
  784. StyleMgrClass::Render_Wrapped_Text
  785. (
  786. const WCHAR * text,
  787. Render2DSentenceClass * renderer,
  788. uint32 text_color,
  789. uint32 shadow_color,
  790. const RectClass & rect,
  791. bool do_shadow,
  792. bool do_vcenter
  793. )
  794. {
  795. //
  796. // Enable wrapping
  797. //
  798. renderer->Set_Wrapping_Width (rect.Width ());
  799. renderer->Set_Clipping_Rect (rect);
  800. //
  801. // Assume left justification
  802. //
  803. int x_pos = rect.Left + 1;
  804. int y_pos = rect.Top + 1;
  805. //
  806. // Center the text vertically if necessary
  807. //
  808. if (do_vcenter) {
  809. Vector2 extents = renderer->Get_Formatted_Text_Extents (text);
  810. y_pos = rect.Top + (rect.Height () / 2.0F) - (extents.Y / 2.0F);
  811. }
  812. //
  813. // Build the textures for the text we'll be drawing
  814. //
  815. renderer->Build_Sentence (text);
  816. //
  817. // Render the shadow (if necessary)
  818. //
  819. if (do_shadow) {
  820. renderer->Set_Location (Vector2 (x_pos - 1, y_pos + 1));
  821. renderer->Draw_Sentence (shadow_color);
  822. }
  823. //
  824. // Render the text
  825. //
  826. renderer->Set_Location (Vector2 (x_pos, y_pos));
  827. renderer->Draw_Sentence (text_color);
  828. return ;
  829. }
  830. ////////////////////////////////////////////////////////////////
  831. //
  832. // Configure_Hilighter
  833. //
  834. ////////////////////////////////////////////////////////////////
  835. void
  836. StyleMgrClass::Configure_Hilighter (Render2DClass *renderer)
  837. {
  838. renderer->Enable_Alpha (false);
  839. renderer->Enable_Texturing (false);
  840. //
  841. // Setup an additive shader
  842. //
  843. ShaderClass *shader = renderer->Get_Shader ();
  844. shader->Set_Dst_Blend_Func (ShaderClass::DSTBLEND_ONE);
  845. shader->Set_Src_Blend_Func (ShaderClass::SRCBLEND_ONE);
  846. //shader->Set_Primary_Gradient (ShaderClass::GRADIENT_ADD);
  847. //shader->Set_Secondary_Gradient (ShaderClass::SECONDARY_GRADIENT_DISABLE);
  848. return ;
  849. }
  850. ////////////////////////////////////////////////////////////////
  851. //
  852. // Render_Hilight
  853. //
  854. ////////////////////////////////////////////////////////////////
  855. void
  856. StyleMgrClass::Render_Hilight (Render2DClass *renderer, const RectClass &rect)
  857. {
  858. renderer->Add_Quad (rect, HilightColor);
  859. return ;
  860. }
  861. ////////////////////////////////////////////////////////////////
  862. //
  863. // Render_Glow
  864. //
  865. ////////////////////////////////////////////////////////////////
  866. void
  867. StyleMgrClass::Render_Glow
  868. (
  869. const WCHAR * text,
  870. Render2DSentenceClass * renderer,
  871. const RectClass & rect,
  872. int radius_x,
  873. int radius_y,
  874. int color,
  875. JUSTIFICATION justify
  876. )
  877. {
  878. //
  879. // Get the extents of the text we will be drawing
  880. //
  881. Vector2 text_extent = renderer->Get_Text_Extents (text);
  882. //
  883. // Assume centered text
  884. //
  885. int x_pos = int(rect.Left + (rect.Width () / 2) - (text_extent.X / 2));
  886. int y_pos = int(rect.Top + (rect.Height () / 2) - (text_extent.Y / 2));
  887. if (justify == LEFT_JUSTIFY) {
  888. //
  889. // Caclulate left justification
  890. //
  891. x_pos = int(rect.Left + 1);
  892. } else if (justify == RIGHT_JUSTIFY) {
  893. //
  894. // Caclulate right justification
  895. //
  896. x_pos = int(rect.Right - text_extent.X);
  897. }
  898. //
  899. // Setup an additive shader
  900. //
  901. renderer->Make_Additive ();
  902. //
  903. // Figure out how many passes we should do to get the
  904. // desired result
  905. //
  906. float max_radius = max (radius_x, radius_y);
  907. int pass_count = 4;//max_radius / 3;
  908. //pass_count = min (pass_count, 5);
  909. //pass_count = max (pass_count, 3);
  910. int step_count = 7;//max_radius;
  911. //step_count = min (step_count, 10);
  912. //step_count = max (step_count, 4);
  913. float angle_inc = DEG_TO_RADF (360) / step_count;
  914. float x_inc = radius_x / pass_count;
  915. float y_inc = radius_y / pass_count;
  916. float curr_radiusx = 2.0F;
  917. float curr_radiusy = 2.0F;
  918. //
  919. // Do four passes to get from the inner radius to the outer radius
  920. //
  921. for (int pass_index = 0; pass_index < pass_count; pass_index ++) {
  922. //
  923. // Circle the characters around using the given radius
  924. //
  925. float angle = 0;
  926. for (int index = 0; index < step_count; index ++) {
  927. float new_x_pos = float(x_pos + (WWMath::Cos(angle) * curr_radiusx));
  928. float new_y_pos = float(y_pos + (WWMath::Sin(angle) * curr_radiusy));
  929. angle += angle_inc;
  930. //
  931. // Render the text
  932. //
  933. renderer->Set_Location (Vector2 (new_x_pos, new_y_pos));
  934. renderer->Draw_Sentence (color);
  935. }
  936. curr_radiusx += x_inc;
  937. curr_radiusy += y_inc;
  938. }
  939. return ;
  940. }
  941. ////////////////////////////////////////////////////////////////
  942. //
  943. // Configure_Renderer
  944. //
  945. ////////////////////////////////////////////////////////////////
  946. void
  947. StyleMgrClass::Configure_Renderer (Render2DClass *renderer)
  948. {
  949. //
  950. // Set the coordinate range for the renderer
  951. //
  952. renderer->Set_Coordinate_Range (Render2DClass::Get_Screen_Resolution ());
  953. //
  954. // Turn depth-buffer reading on for this renderer
  955. //
  956. //ShaderClass *shader = renderer->Get_Shader ();
  957. //shader->Set_Depth_Compare (ShaderClass::PASS_LEQUAL);
  958. return ;
  959. }
  960. ////////////////////////////////////////////////////////////////
  961. //
  962. // Play_Sound
  963. //
  964. ////////////////////////////////////////////////////////////////
  965. void
  966. StyleMgrClass::Play_Sound (EVENT_AUDIO event)
  967. {
  968. if ( WWAudioClass::Get_Instance () == NULL ||
  969. EventAudioList[event].Get_Length () == 0)
  970. {
  971. return ;
  972. }
  973. //
  974. // Parse the information
  975. //
  976. StringClass tmp_copy (EventAudioList[event], true);
  977. StringClass filename = ::strtok (tmp_copy.Peek_Buffer (), ",");
  978. StringClass vol_string = ::strtok (NULL, ",");
  979. float volume = ::atoi (vol_string) / 100.0F;
  980. //
  981. // Play the sound effect
  982. //
  983. WWAudioClass::Get_Instance ()->Simple_Play_2D_Sound_Effect (filename, 1.0F, volume);
  984. return ;
  985. }