DIALOG.CPP 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998
  1. /*
  2. ** Command & Conquer Red Alert(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. /* $Header: /CounterStrike/DIALOG.CPP 1 3/03/97 10:24a Joe_bostic $ */
  19. /***********************************************************************************************
  20. *** 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 ***
  21. ***********************************************************************************************
  22. * *
  23. * Project Name : Command & Conquer *
  24. * *
  25. * File Name : DIALOG.CPP *
  26. * *
  27. * Programmer : Joe L. Bostic *
  28. * *
  29. * Start Date : September 10, 1993 *
  30. * *
  31. * Last Update : July 31, 1996 [JLB] *
  32. * *
  33. *---------------------------------------------------------------------------------------------*
  34. * Functions: *
  35. * Clip_Text_Print -- Prints text with clipping and <TAB> support. *
  36. * Dialog_Box -- draws a dialog background box *
  37. * Display_Place_Building -- Displays the "place building" dialog box. *
  38. * Display_Select_Target -- Displays the "choose target" prompt. *
  39. * Display_Status -- Display the player scenario status box. *
  40. * Draw_Box -- Displays a highlighted box. *
  41. * Draw_Caption -- Draws a caption on a dialog box. *
  42. * Fancy_Text_Print -- Prints text with a drop shadow. *
  43. * Plain_Text_Print -- Prints text without using a color scheme *
  44. * Redraw_Needed -- Determine if sidebar needs to be redrawn. *
  45. * Render_Bar_Graph -- Renders a specified bargraph. *
  46. * Simple_Text_Print -- Prints text with a drop shadow. *
  47. * Window_Box -- Draws a fancy box over the specified window. *
  48. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  49. #include "function.h"
  50. #include "defines.h" //VG 10/17/96
  51. unsigned char * Font_Palette(int color);
  52. /***********************************************************************************************
  53. * Dialog_Box -- draws a dialog background box *
  54. * *
  55. * INPUT: *
  56. * x,y,w,h the usual *
  57. * *
  58. * OUTPUT: *
  59. * none. *
  60. * *
  61. * WARNINGS: *
  62. * none. *
  63. * *
  64. * HISTORY: *
  65. * 01/26/1995 BR : Created. *
  66. * 07/31/1996 JLB : Uses shapes to draw the box. *
  67. *=============================================================================================*/
  68. void Dialog_Box(int x, int y, int w, int h)
  69. {
  70. // Try to expand the box a little taller and a little wider to make room for
  71. // the dialog box graphics in the DOS version.
  72. #ifndef WIN32
  73. x = max(0, x-4);
  74. y = max(0, y-4);
  75. w = min(w+8, 320-x);
  76. h = min(h+8, 200-y);
  77. #endif
  78. WindowList[WINDOW_PARTIAL][WINDOWX] = x;
  79. WindowList[WINDOW_PARTIAL][WINDOWY] = y;
  80. WindowList[WINDOW_PARTIAL][WINDOWWIDTH] = w;
  81. WindowList[WINDOW_PARTIAL][WINDOWHEIGHT] = h;
  82. /*
  83. ** Always draw to the hidpage and then blit forward.
  84. */
  85. #ifdef WIN32
  86. GraphicViewPortClass * oldpage = Set_Logic_Page(HidPage);
  87. #else
  88. GraphicBufferClass * oldpage = Set_Logic_Page(HidPage);
  89. #endif
  90. /*
  91. ** Draw the background block.
  92. */
  93. int cx = w/2;
  94. int cy = h/2;
  95. void const * shapedata = MFCD::Retrieve("DD-BKGND.SHP");
  96. #ifdef WIN32
  97. CC_Draw_Shape(shapedata, 0, cx-312, cy-192, WINDOW_PARTIAL, SHAPE_WIN_REL);
  98. CC_Draw_Shape(shapedata, 1, cx, cy-192, WINDOW_PARTIAL, SHAPE_WIN_REL);
  99. CC_Draw_Shape(shapedata, 2, cx-312, cy, WINDOW_PARTIAL, SHAPE_WIN_REL);
  100. CC_Draw_Shape(shapedata, 3, cx, cy, WINDOW_PARTIAL, SHAPE_WIN_REL);
  101. #else
  102. CC_Draw_Shape(shapedata, 0, cx-156, cy-96, WINDOW_PARTIAL, SHAPE_WIN_REL);
  103. #endif
  104. /*
  105. ** Draw the side strips.
  106. */
  107. shapedata = MFCD::Retrieve("DD-EDGE.SHP");
  108. for (int yy = 0; yy < h; yy += 6) {
  109. CC_Draw_Shape(shapedata, 0, 7*RESFACTOR, yy, WINDOW_PARTIAL, SHAPE_WIN_REL);
  110. CC_Draw_Shape(shapedata, 1, w-((7+8)*RESFACTOR), yy, WINDOW_PARTIAL, SHAPE_WIN_REL);
  111. }
  112. /*
  113. ** Draw the border bars.
  114. */
  115. shapedata = MFCD::Retrieve("DD-LEFT.SHP");
  116. CC_Draw_Shape(shapedata, 0, 0, cy-100*RESFACTOR, WINDOW_PARTIAL, SHAPE_WIN_REL);
  117. CC_Draw_Shape(shapedata, 0, 0, cy, WINDOW_PARTIAL, SHAPE_WIN_REL);
  118. shapedata = MFCD::Retrieve("DD-RIGHT.SHP");
  119. int rightx = w - (7*RESFACTOR);
  120. #ifndef WIN32
  121. rightx--;
  122. #endif
  123. CC_Draw_Shape(shapedata, 0, rightx, cy-100*RESFACTOR, WINDOW_PARTIAL, SHAPE_WIN_REL);
  124. CC_Draw_Shape(shapedata, 0, rightx, cy, WINDOW_PARTIAL, SHAPE_WIN_REL);
  125. shapedata = MFCD::Retrieve("DD-BOTM.SHP");
  126. CC_Draw_Shape(shapedata, 0, cx-160*RESFACTOR, h-8*RESFACTOR, WINDOW_PARTIAL, SHAPE_WIN_REL);
  127. CC_Draw_Shape(shapedata, 0, cx, h-8*RESFACTOR, WINDOW_PARTIAL, SHAPE_WIN_REL);
  128. shapedata = MFCD::Retrieve("DD-TOP.SHP");
  129. CC_Draw_Shape(shapedata, 0, cx-160*RESFACTOR, 0, WINDOW_PARTIAL, SHAPE_WIN_REL);
  130. CC_Draw_Shape(shapedata, 0, cx, 0, WINDOW_PARTIAL, SHAPE_WIN_REL);
  131. /*
  132. ** Draw the corner caps.
  133. */
  134. shapedata = MFCD::Retrieve("DD-CRNR.SHP");
  135. CC_Draw_Shape(shapedata, 0, 0, 0, WINDOW_PARTIAL, SHAPE_WIN_REL);
  136. CC_Draw_Shape(shapedata, 1, w-(12*RESFACTOR-1), 0, WINDOW_PARTIAL, SHAPE_WIN_REL);
  137. CC_Draw_Shape(shapedata, 2, 0, h-(12*RESFACTOR), WINDOW_PARTIAL, SHAPE_WIN_REL);
  138. CC_Draw_Shape(shapedata, 3, w-(12*RESFACTOR-1), h-(12*RESFACTOR), WINDOW_PARTIAL, SHAPE_WIN_REL);
  139. #ifdef WIN32
  140. WWMouse->Draw_Mouse(&HidPage);
  141. HidPage.Blit(SeenBuff, x, y, x, y, w, h, false);
  142. WWMouse->Erase_Mouse(&HidPage, FALSE);
  143. #else
  144. // Shadow_Blit(0, 0, 320, 200, HidPage, SeenPage, Map.ShadowPage->Get_Buffer());
  145. Hide_Mouse();
  146. HidPage.Blit(SeenBuff);
  147. Show_Mouse();
  148. // Shadow_Blit(0, 0, 320, 200, HidPage, SeenPage, ((GraphicBufferClass*)Map.Shadow_Address())->Get_Buffer());
  149. #endif
  150. Set_Logic_Page(oldpage);
  151. }
  152. /***********************************************************************************************
  153. * Draw_Box -- Displays a highlighted box. *
  154. * *
  155. * This will draw a highlighted box to the logicpage. It can *
  156. * optionally fill the box with a color as well. This is a low level *
  157. * function and thus, it doesn't do any graphic mode color adjustments. *
  158. * *
  159. * INPUT: x,y -- Upper left corner of the box to be drawn (pixels). *
  160. * *
  161. * w,h -- Width and height of box (in pixels). *
  162. * *
  163. * up -- Is the box rendered in the "up" stated? *
  164. * *
  165. * filled-- Is the box to be filled. *
  166. * *
  167. * OUTPUT: none *
  168. * *
  169. * WARNINGS: none *
  170. * *
  171. * HISTORY: *
  172. * 05/28/1991 JLB : Created. *
  173. * 05/30/1992 JLB : Embedded color codes. *
  174. * 07/31/1992 JLB : Depressed option added. *
  175. *=============================================================================================*/
  176. void Draw_Box(int x, int y, int w, int h, BoxStyleEnum up, bool filled)
  177. {
  178. RemapControlType * scheme = GadgetClass::Get_Color_Scheme();
  179. // Filler, Shadow, Hilite, Corner colors
  180. BoxStyleType const ButtonColors[BOXSTYLE_COUNT] = {
  181. { scheme->Background, scheme->Highlight, scheme->Shadow, scheme->Corners}, // Down
  182. { scheme->Background, scheme->Shadow, scheme->Highlight, scheme->Corners}, // Raised
  183. { DKGREY, WHITE, BLACK, DKGREY}, // Disabled down
  184. { DKGREY, BLACK, LTGREY, DKGREY}, // Disabled up
  185. { BLACK, scheme->Box, scheme->Box, BLACK}, // List box
  186. { BLACK, scheme->Box, scheme->Box, BLACK}, // Dialog box
  187. };
  188. w--;
  189. h--;
  190. BoxStyleType const &style = ButtonColors[up];
  191. if (filled) {
  192. LogicPage->Fill_Rect( x, y, x+w, y+h, style.Filler);
  193. }
  194. switch (up) {
  195. case (BOXSTYLE_BOX):
  196. LogicPage->Draw_Rect(x, y, x+w, y+h, style.Highlight);
  197. break;
  198. case (BOXSTYLE_BORDER):
  199. LogicPage->Draw_Rect(x+1, y+1, x+w-1, y+h-1, style.Highlight);
  200. break;
  201. default:
  202. LogicPage->Draw_Line(x, y+h, x+w, y+h, style.Shadow);
  203. LogicPage->Draw_Line(x+w, y, x+w, y+h, style.Shadow);
  204. LogicPage->Draw_Line(x, y, x+w, y, style.Highlight);
  205. LogicPage->Draw_Line(x, y, x, y+h, style.Highlight);
  206. LogicPage->Put_Pixel(x, y+h, style.Corner);
  207. LogicPage->Put_Pixel(x+w, y, style.Corner);
  208. break;
  209. }
  210. }
  211. /***********************************************************************************************
  212. * Format_Window_String -- Separates a String into Lines. *
  213. * This function will take a long string and break it up into lines *
  214. * which are not longer then the window width. Any character < ' ' is *
  215. * considered a new line marker and will be replaced by a NULL. *
  216. * *
  217. * INPUT: char *String - string to be formated. *
  218. * int maxlinelen - Max length of any line in pixels. *
  219. * *
  220. * OUTPUT: int - number of lines string is. *
  221. * *
  222. * WARNINGS: The string passed in will be modified - NULLs will be put *
  223. * into each position that will be a new line. *
  224. * *
  225. * HISTORY: *
  226. * 03/27/1992 SB : Created. *
  227. * 05/18/1995 JLB : Greatly revised for new font system. *
  228. * 09/04/1996 BWG : Added '@' is treated as a carriage return for width calculations. *
  229. *=============================================================================================*/
  230. int Format_Window_String(char * string, int maxlinelen, int & width, int & height)
  231. {
  232. int linelen;
  233. int lines = 0;
  234. width = 0;
  235. height = 0;
  236. // In no string was passed in, then there are no lines.
  237. if (!string) return(0);
  238. // While there are more letters left divide the line up.
  239. while (*string) {
  240. linelen = 0;
  241. height += FontHeight + FontYSpacing;
  242. lines++;
  243. /*
  244. ** Look for special line break character and force a line break when it is
  245. ** discovered.
  246. */
  247. if (*string == '@') {
  248. *string = '\r';
  249. }
  250. // While the current line is less then the max length...
  251. while (linelen < maxlinelen && *string != '\r' && *string != '\0' && *string != '@') {
  252. linelen += Char_Pixel_Width(*string++);
  253. }
  254. // if the line is to long...
  255. if (linelen >= maxlinelen) {
  256. /*
  257. ** Back up to an appropriate location to break.
  258. */
  259. while (*string != ' ' && *string != '\r' && *string != '\0' && *string != '@') {
  260. linelen -= Char_Pixel_Width(*string--);
  261. }
  262. }
  263. /*
  264. ** Record the largest width of the worst case string.
  265. */
  266. if (linelen > width) {
  267. width = linelen;
  268. }
  269. /*
  270. ** Force a break at the end of the line.
  271. */
  272. if (*string) {
  273. *string++ = '\r';
  274. }
  275. }
  276. return(lines);
  277. }
  278. /***********************************************************************************************
  279. * Window_Box -- Draws a fancy box over the specified window. *
  280. * *
  281. * This routine will draw a fancy (shaded) box over the specified *
  282. * window. This is the effect used to give the polished look to *
  283. * screen rectangles without having to use art. *
  284. * *
  285. * INPUT: window -- Specified window to fill and border. *
  286. * *
  287. * style -- The style to render the window. *
  288. * *
  289. * OUTPUT: none *
  290. * *
  291. * WARNINGS: The rendering is done to the LogicPage. *
  292. * *
  293. * HISTORY: *
  294. * 03/03/1992 JLB : Created. *
  295. * 07/31/1992 JLB : Cool raised border effect. *
  296. * 06/08/1994 JLB : Takes appropriate enumeration parameters. *
  297. *=============================================================================================*/
  298. void Window_Box(WindowNumberType window, BoxStyleEnum style)
  299. {
  300. int x = WindowList[window][WINDOWX];
  301. int y = WindowList[window][WINDOWY];
  302. int w = WindowList[window][WINDOWWIDTH];
  303. int h = WindowList[window][WINDOWHEIGHT];
  304. /*
  305. ** If it is to be rendered to the seenpage, then
  306. ** hide the mouse.
  307. */
  308. if (LogicPage == (&SeenBuff)) Conditional_Hide_Mouse(x ,y, x+w, y+h);
  309. Draw_Box(x, y, w, h, style, true);
  310. /*
  311. ** Restore the mouse if it has been hidden and return.
  312. */
  313. if (LogicPage == &SeenBuff) Conditional_Show_Mouse();
  314. }
  315. /***********************************************************************************************
  316. * Simple_Text_Print -- Prints text with a drop shadow. *
  317. * *
  318. * This routine functions like Text_Print, but will render a drop *
  319. * shadow (in black). *
  320. * *
  321. * The C&C gradient font colors are as follows: *
  322. * 0 transparent (background) *
  323. * 1 foreground color for mono-color fonts only *
  324. * 2 shadow under characters ("drop shadow") *
  325. * 3 shadow all around characters ("full shadow") *
  326. * 4-10 unused *
  327. * 11 top row *
  328. * 12 next row *
  329. * 13 next row *
  330. * 14 next row *
  331. * 15 bottom row *
  332. * *
  333. * INPUT: text -- Pointer to text to render. *
  334. * *
  335. * x,y -- Pixel coordinate for to print text. *
  336. * *
  337. * fore -- Foreground color. *
  338. * *
  339. * back -- Background color. *
  340. * *
  341. * flag -- Text print control flags. *
  342. * *
  343. * OUTPUT: none *
  344. * *
  345. * WARNINGS: none *
  346. * *
  347. * HISTORY: *
  348. * 12/24/1991 JLB : Created. *
  349. * 10/26/94 JLB : Handles font X spacing in a more friendly manner. *
  350. *=============================================================================================*/
  351. void Simple_Text_Print(char const * text, unsigned x, unsigned y, RemapControlType * fore, unsigned back, TextPrintType flag)
  352. {
  353. static int yspace=0; // Y spacing adjustment for font.
  354. static int xspace=0; // Spacing adjustment for font.
  355. void const * font=0; // Font to use.
  356. int shadow; // Requested shadow value.
  357. unsigned char fontpalette[16]; // Working font palette array.
  358. int forecolor;
  359. if (fore == NULL) {
  360. fore = &ColorRemaps[PCOLOR_RED];
  361. }
  362. /*
  363. ** Init the font palette to the given background color
  364. */
  365. memset(&fontpalette[0], back, 16);
  366. forecolor = fore->Color;
  367. /*
  368. ** A gradient font always requires special fixups for the palette
  369. */
  370. int point = (flag & (TextPrintType)0x000F);
  371. if (point == TPF_VCR || point == TPF_6PT_GRAD || point == TPF_METAL12 || point == TPF_EFNT || point == TPF_TYPE) {
  372. /*
  373. ** If a gradient palette is specified, copy the remap table directly, otherwise
  374. ** use the foreground color as the entire font remap color.
  375. */
  376. if (flag & TPF_USE_GRAD_PAL) {
  377. memcpy(fontpalette, fore->FontRemap, 16);
  378. forecolor = fore->Color;
  379. if (point == TPF_TYPE) {
  380. forecolor = fontpalette[1];
  381. }
  382. } else {
  383. memset(&fontpalette[4], fore->Color, 12);
  384. forecolor = fore->Color;
  385. }
  386. /*
  387. ** Medium color: set all font colors to a medium value. This flag
  388. ** overrides any gradient effects.
  389. */
  390. if (flag & TPF_MEDIUM_COLOR) {
  391. forecolor = fore->Color;
  392. memset(&fontpalette[4], fore->Color, 12);
  393. }
  394. /*
  395. ** Bright color: set all font colors to a bright value. This flag
  396. ** overrides any gradient effects.
  397. */
  398. if (flag & TPF_BRIGHT_COLOR) {
  399. forecolor = fore->Bright;
  400. memset(&fontpalette[4], fore->BrightColor, 12);
  401. }
  402. }
  403. /*
  404. ** Change the current font if it differs from the font desired.
  405. */
  406. #ifdef WIN32
  407. xspace = 1;
  408. #else
  409. xspace = 0;
  410. #endif
  411. yspace = 0;
  412. switch (point) {
  413. case TPF_SCORE:
  414. font = ScoreFontPtr;
  415. break;
  416. case TPF_METAL12:
  417. font = Metal12FontPtr;
  418. //xspace += 1;
  419. break;
  420. case TPF_MAP:
  421. font = MapFontPtr;
  422. xspace -= 1;
  423. break;
  424. case TPF_VCR:
  425. font = VCRFontPtr;
  426. break;
  427. case TPF_6PT_GRAD:
  428. font = GradFont6Ptr;
  429. xspace -= 1;
  430. break;
  431. case TPF_3POINT:
  432. xspace += 1;
  433. font = Font3Ptr;
  434. flag = flag & ~(TPF_DROPSHADOW|TPF_FULLSHADOW|TPF_NOSHADOW);
  435. break;
  436. case TPF_6POINT:
  437. font = Font6Ptr;
  438. xspace -= 1;
  439. break;
  440. case TPF_EFNT:
  441. font = EditorFont;
  442. #ifdef WIN32
  443. yspace += 1;
  444. xspace -= 1;
  445. #endif
  446. xspace -= 1;
  447. break;
  448. case TPF_8POINT:
  449. font = Font8Ptr;
  450. #ifdef WIN32
  451. xspace -= 2;
  452. yspace -= 4;
  453. #else
  454. xspace -= 1;
  455. yspace -= 2;
  456. #endif
  457. break;
  458. case TPF_LED:
  459. #ifdef WIN32
  460. xspace -= 4;
  461. #else
  462. xspace -= 2;
  463. #endif
  464. font = FontLEDPtr;
  465. break;
  466. case TPF_TYPE:
  467. font = TypeFontPtr;
  468. xspace -= 1;
  469. #ifdef WOLAPI_INTEGRATION
  470. xspace -= 2;
  471. yspace += 2;
  472. #else // I am implicitly assuming that TPF_TYPE was no longer being used, before I came along, despite the following. ajw
  473. #ifdef GERMAN
  474. yspace += 4; //VG 10/17/96
  475. #endif
  476. #endif
  477. break;
  478. default:
  479. font = FontPtr;
  480. break;
  481. }
  482. /*
  483. ** Change the current font palette according to the dropshadow flags.
  484. */
  485. shadow = (flag & (TPF_NOSHADOW|TPF_DROPSHADOW|TPF_FULLSHADOW|TPF_LIGHTSHADOW));
  486. switch (shadow) {
  487. /*
  488. ** The text is rendered plain.
  489. */
  490. case TPF_NOSHADOW:
  491. fontpalette[2] = back;
  492. fontpalette[3] = back;
  493. xspace -= 1;
  494. #ifdef WIN32
  495. yspace -= 2;
  496. #else
  497. yspace -= 1;
  498. #endif
  499. break;
  500. /*
  501. ** The text is rendered with a simple
  502. ** drop shadow.
  503. */
  504. case TPF_DROPSHADOW:
  505. fontpalette[2] = BLACK;
  506. fontpalette[3] = back;
  507. xspace -= 1;
  508. break;
  509. /*
  510. ** Special engraved text look for the options
  511. ** dialog system.
  512. */
  513. case TPF_LIGHTSHADOW:
  514. fontpalette[2] = ((14 * 16) + 7)+1;
  515. fontpalette[3] = back;
  516. xspace -= 1;
  517. break;
  518. /*
  519. ** Each letter is surrounded by black. This is used
  520. ** when the text will be over a non-plain background.
  521. */
  522. case TPF_FULLSHADOW:
  523. fontpalette[2] = BLACK;
  524. fontpalette[3] = BLACK;
  525. xspace -= 1;
  526. break;
  527. default:
  528. break;
  529. }
  530. if (point != TPF_TYPE) {
  531. fontpalette[0] = back;
  532. fontpalette[1] = fore->Color;
  533. }
  534. /*
  535. ** Set the font and spacing according to the values they should be.
  536. */
  537. FontXSpacing = xspace;
  538. FontYSpacing = yspace;
  539. Set_Font(font);
  540. Set_Font_Palette(fontpalette);
  541. /*
  542. ** Display the (centered) message if there is one.
  543. */
  544. if (text && *text) {
  545. switch (flag & (TPF_CENTER|TPF_RIGHT)) {
  546. case TPF_CENTER:
  547. x -= String_Pixel_Width(text)>>1;
  548. break;
  549. case TPF_RIGHT:
  550. x -= String_Pixel_Width(text);
  551. break;
  552. default:
  553. break;
  554. }
  555. if ((unsigned)x < LogicPage->Get_Width() && (unsigned)y < LogicPage->Get_Height()) {
  556. LogicPage->Print(text, x, y, forecolor, back);
  557. // LogicPage->Print(text, x, y, fore->Color, back);
  558. }
  559. }
  560. }
  561. /***********************************************************************************************
  562. * Fancy_Text_Print -- Prints text with a drop shadow. *
  563. * *
  564. * This routine functions like Text_Print, but will render a drop *
  565. * shadow (in black). *
  566. * *
  567. * INPUT: text -- Text number to print. *
  568. * *
  569. * x,y -- Pixel coordinate for to print text. *
  570. * *
  571. * fore -- Foreground color. *
  572. * *
  573. * back -- Background color. *
  574. * *
  575. * flag -- Text print control flags. *
  576. * *
  577. * OUTPUT: none *
  578. * *
  579. * WARNINGS: This routine is much slower than normal text print and *
  580. * if rendered to the SEENPAGE, the intermediate rendering *
  581. * steps could be visible. *
  582. * *
  583. * HISTORY: *
  584. * 11/29/1994 JLB : Created *
  585. *=============================================================================================*/
  586. void Fancy_Text_Print(int text, unsigned x, unsigned y, RemapControlType * fore, unsigned back, TextPrintType flag, ...)
  587. {
  588. char buffer[512]; // Working staging buffer.
  589. va_list arg; // Argument list var.
  590. /*
  591. ** If the text number is valid, then process it.
  592. */
  593. if (text != TXT_NONE) {
  594. va_start(arg, flag);
  595. /*
  596. ** The text string must be locked since the vsprintf function doesn't know
  597. ** how to handle EMS pointers.
  598. */
  599. char const * tptr = Text_String(text);
  600. vsprintf(buffer, tptr, arg);
  601. va_end(arg);
  602. Simple_Text_Print(buffer, x, y, fore, back, flag);
  603. } else {
  604. /*
  605. ** Just the flags are to be changed, since the text number is TXT_NONE.
  606. */
  607. Simple_Text_Print((char const *)0, x, y, fore, back, flag);
  608. }
  609. }
  610. /***********************************************************************************************
  611. * Fancy_Text_Print -- Prints text with a drop shadow. *
  612. * *
  613. * This routine functions like Text_Print, but will render a drop *
  614. * shadow (in black). *
  615. * *
  616. * INPUT: text -- Pointer to text to render. *
  617. * *
  618. * x,y -- Pixel coordinate for to print text. *
  619. * *
  620. * fore -- Foreground color. *
  621. * *
  622. * back -- Background color. *
  623. * *
  624. * flag -- Text print control flags. *
  625. * *
  626. * OUTPUT: none *
  627. * *
  628. * WARNINGS: This routine is much slower than normal text print and *
  629. * if rendered to the SEENPAGE, the intermediate rendering *
  630. * steps could be visible. *
  631. * *
  632. * HISTORY: *
  633. * 12/24/1991 JLB : Created. *
  634. * 10/26/94 JLB : Handles font X spacing in a more friendly manner. *
  635. * 11/29/1994 JLB : Separated actual draw action. *
  636. *=============================================================================================*/
  637. void Fancy_Text_Print(char const * text, unsigned x, unsigned y, RemapControlType * fore, unsigned back, TextPrintType flag, ...)
  638. {
  639. char buffer[512]; // Working staging buffer.
  640. va_list arg; // Argument list var.
  641. /*
  642. ** If there is a valid text string pointer then build the final string into the
  643. ** working buffer before sending it to the simple string printing routine.
  644. */
  645. if (text) {
  646. /*
  647. ** Since vsprintf doesn't know about EMS pointers, be sure to surround this
  648. ** call with locking code.
  649. */
  650. va_start(arg, flag);
  651. vsprintf(buffer, text, arg);
  652. va_end(arg);
  653. Simple_Text_Print(buffer, x, y, fore, back, flag);
  654. } else {
  655. /*
  656. ** Just the flags are desired to be changed, so call the simple print routine with
  657. ** a NULL text pointer.
  658. */
  659. Simple_Text_Print((char const *)0, x, y, fore, back, flag);
  660. }
  661. }
  662. /***********************************************************************************************
  663. * Clip_Text_Print -- Prints text with clipping and <TAB> support. *
  664. * *
  665. * Use this routine to print text that that should be clipped at an arbitrary right margin *
  666. * as well as possibly recognizing <TAB> characters. Typical users of this routine would *
  667. * be list boxes. *
  668. * *
  669. * INPUT: text -- Reference to the text to print. *
  670. * *
  671. * x,y -- Pixel coordinate of the upper left corner of the text position. *
  672. * *
  673. * fore -- The foreground color to use. *
  674. * *
  675. * back -- The background color to use. *
  676. * *
  677. * flag -- The text print flags to use. *
  678. * *
  679. * width -- The maximum pixel width to draw the text. Extra characters beyond this *
  680. * point will not be printed. *
  681. * *
  682. * tabs -- Optional pointer to a series of pixel tabstop positions. *
  683. * *
  684. * OUTPUT: none *
  685. * *
  686. * WARNINGS: none *
  687. * *
  688. * HISTORY: *
  689. * 01/21/1995 JLB : Created. *
  690. *=============================================================================================*/
  691. void Conquer_Clip_Text_Print(char const * text, unsigned x, unsigned y, RemapControlType * fore, unsigned back, TextPrintType flag, int width, int const * tabs)
  692. {
  693. char buffer[512];
  694. if (text) {
  695. strcpy(buffer, text);
  696. /*
  697. ** Set the font and spacing characteristics according to the flag
  698. ** value passed in.
  699. */
  700. Simple_Text_Print(TXT_NONE, 0, 0, TBLACK, TBLACK, flag);
  701. char * source = &buffer[0];
  702. unsigned offset = 0;
  703. int processing = true;
  704. while (processing && offset < width) {
  705. char * ptr = strchr(source, '\t');
  706. /*
  707. ** Zap the tab character. It will be processed later.
  708. */
  709. if (ptr) {
  710. *ptr = '\0';
  711. }
  712. if (*source) {
  713. /*
  714. ** Scan forward until the end of the string is reached or the
  715. ** maximum width, whichever comes first.
  716. */
  717. int w = 0;
  718. char * bptr = source;
  719. do {
  720. w += Char_Pixel_Width(*bptr++);
  721. } while (*bptr && offset+w < width);
  722. /*
  723. ** If the maximum width has been exceeded, then remove the last
  724. ** character and signal that further processing is not necessary.
  725. */
  726. if (offset+w >= width) {
  727. bptr--;
  728. w -= Char_Pixel_Width(*bptr);
  729. *bptr = '\0';
  730. processing = 0;
  731. }
  732. /*
  733. ** Print this text block and advance the offset accordingly.
  734. */
  735. Simple_Text_Print(source, x+offset, y, fore, back, flag);
  736. offset += w;
  737. }
  738. /*
  739. ** If a <TAB> was the terminator for this text block, then advance
  740. ** to the next tabstop.
  741. */
  742. if (ptr) {
  743. if (tabs) {
  744. while (offset > *tabs) {
  745. tabs++;
  746. }
  747. offset = *tabs;
  748. } else {
  749. offset = ((offset+1 / 50) + 1) * 50;
  750. }
  751. source = ptr+1;
  752. } else {
  753. break;
  754. }
  755. }
  756. }
  757. }
  758. /***************************************************************************
  759. * Plain_Text_Print -- Prints text without using a color scheme *
  760. * *
  761. * INPUT: *
  762. * text text to print *
  763. * x,y coords to print at *
  764. * fore desired foreground color *
  765. * back desired background color *
  766. * flag text print control flags *
  767. * *
  768. * OUTPUT: *
  769. * none. *
  770. * *
  771. * WARNINGS: *
  772. * Do not use the gradient control flag with this routine! For *
  773. * a gradient appearance, use Fancy_Text_Print. *
  774. * Despite this routine's name, it is actually faster to call *
  775. * Fancy_Text_Print than this routine. *
  776. * *
  777. * HISTORY: *
  778. * 01/05/1996 BRR : Created. *
  779. *=========================================================================*/
  780. void Plain_Text_Print(int text, unsigned x, unsigned y, unsigned fore, unsigned back, TextPrintType flag, ...)
  781. {
  782. RemapControlType scheme;
  783. memset(&scheme, 0, sizeof(RemapControlType));
  784. memset(&(scheme.FontRemap[4]), fore, 12);
  785. scheme.BrightColor = fore;
  786. scheme.Color = fore;
  787. scheme.Shadow = fore;
  788. scheme.Background = fore;
  789. scheme.Corners = fore;
  790. scheme.Highlight = fore;
  791. scheme.Box = fore;
  792. scheme.Bright = fore;
  793. scheme.Underline = fore;
  794. scheme.Bar = fore;
  795. Fancy_Text_Print(text, x, y, &scheme, back, flag);
  796. }
  797. /***************************************************************************
  798. * Plain_Text_Print -- Prints text without using a color scheme *
  799. * *
  800. * INPUT: *
  801. * text text to print *
  802. * x,y coords to print at *
  803. * fore desired foreground color *
  804. * back desired background color *
  805. * flag text print control flags *
  806. * *
  807. * OUTPUT: *
  808. * none. *
  809. * *
  810. * WARNINGS: *
  811. * Do not use the gradient control flag with this routine! For *
  812. * a gradient appearance, use Fancy_Text_Print. *
  813. * Despite this routine's name, it is actually faster to call *
  814. * Fancy_Text_Print than this routine. *
  815. * *
  816. * HISTORY: *
  817. * 01/05/1996 BRR : Created. *
  818. *=========================================================================*/
  819. void Plain_Text_Print(char const * text, unsigned x, unsigned y, unsigned fore, unsigned back, TextPrintType flag, ...)
  820. {
  821. RemapControlType scheme;
  822. memset(&scheme, 0, sizeof(RemapControlType));
  823. memset(&(scheme.FontRemap[4]), fore, 12);
  824. scheme.BrightColor = fore;
  825. scheme.Color = fore;
  826. scheme.Shadow = fore;
  827. scheme.Background = fore;
  828. scheme.Corners = fore;
  829. scheme.Highlight = fore;
  830. scheme.Box = fore;
  831. scheme.Bright = fore;
  832. scheme.Underline = fore;
  833. scheme.Bar = fore;
  834. Fancy_Text_Print(text, x, y, &scheme, back, flag);
  835. }
  836. unsigned char * Font_Palette(int color)
  837. {
  838. static unsigned char _fpalette[16];
  839. memset(_fpalette, '\0', sizeof(_fpalette));
  840. memset(&_fpalette[11], color, 5);
  841. return(_fpalette);
  842. }
  843. /***********************************************************************************************
  844. * Draw_Caption -- Draws a caption on a dialog box. *
  845. * *
  846. * This routine draws the caption text and any fancy filigree that the dialog may require. *
  847. * *
  848. * INPUT: text -- The text of the caption. This is the text number. *
  849. * *
  850. * x,y -- The dialog box X and Y pixel coordinate of the upper left corner. *
  851. * *
  852. * w -- The width of the dialog box (in pixels). *
  853. * *
  854. * OUTPUT: none *
  855. * *
  856. * WARNINGS: none *
  857. * *
  858. * HISTORY: *
  859. * 06/23/1995 JLB : Created. *
  860. *=============================================================================================*/
  861. void Draw_Caption(int text, int x, int y, int w)
  862. {
  863. Draw_Caption(Text_String(text), x, y, w);
  864. }
  865. void Draw_Caption(char const * text, int x, int y, int w)
  866. {
  867. /*
  868. ** Draw the caption.
  869. */
  870. if (text != NULL && *text != '\0') {
  871. if (Debug_Map) {
  872. Fancy_Text_Print(text, w/2 + x, (2 * RESFACTOR) + y, GadgetClass::Get_Color_Scheme(), TBLACK, TPF_CENTER|TPF_EFNT|TPF_USE_GRAD_PAL|TPF_NOSHADOW);
  873. } else {
  874. Fancy_Text_Print(text, w/2 + x, (8 * RESFACTOR) + y, GadgetClass::Get_Color_Scheme(), TBLACK, TPF_CENTER|TPF_TEXT);
  875. int length = String_Pixel_Width(text);
  876. LogicPage->Draw_Line((x+(w/2))-(length/2), y+FontHeight+FontYSpacing + (8 * RESFACTOR), (x+(w/2))+(length/2),
  877. y+FontHeight+FontYSpacing + (8 * RESFACTOR), GadgetClass::Get_Color_Scheme()->Box);
  878. }
  879. }
  880. }