DIALOG.CPP 43 KB

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