COLRLIST.CPP 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  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: F:\projects\c&c\vcs\code\colrlist.cpv 1.9 16 Oct 1995 16:50:02 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 : LIST.CPP *
  22. * *
  23. * Programmer : Joe L. Bostic *
  24. * *
  25. * Start Date : 01/15/95 *
  26. * *
  27. * Last Update : April 19, 1995 [BRR] *
  28. * *
  29. *---------------------------------------------------------------------------------------------*
  30. * Functions: *
  31. * ColorListClass::Add_Item -- Adds an item to the list *
  32. * ColorListClass::ColorListClass -- Class constructor *
  33. * ColorListClass::Draw_Entry -- Draws one text line *
  34. * ColorListClass::Remove_Item -- Removes an item from the list *
  35. * ColorListClass::Set_Selected_Style -- tells how to draw selected item *
  36. * ColorListClass::~ColorListClass -- Class destructor *
  37. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  38. #include "function.h"
  39. /***************************************************************************
  40. * ColorListClass::ColorListClass -- class constructor *
  41. * *
  42. * INPUT: *
  43. * id button ID *
  44. * x,y upper-left corner, in pixels *
  45. * w,h width, height, in pixels *
  46. * list ptr to array of char strings to list *
  47. * flags flags for mouse, style of listbox *
  48. * up,down pointers to shapes for up/down buttons *
  49. * *
  50. * OUTPUT: *
  51. * none. *
  52. * *
  53. * WARNINGS: *
  54. * none. *
  55. * *
  56. * HISTORY: 01/05/1995 MML : Created. *
  57. *=========================================================================*/
  58. ColorListClass::ColorListClass (int id, int x, int y, int w, int h,
  59. TextPrintType flags, void const * up, void const * down) :
  60. ListClass (id, x, y, w, h, flags, up, down)
  61. {
  62. Style = SELECT_HIGHLIGHT;
  63. SelectColor = -1;
  64. }
  65. /***************************************************************************
  66. * ColorListClass::~ColorListClass -- Class destructor *
  67. * *
  68. * INPUT: *
  69. * none. *
  70. * *
  71. * OUTPUT: *
  72. * none. *
  73. * *
  74. * WARNINGS: *
  75. * none. *
  76. * *
  77. * HISTORY: *
  78. * 04/19/1995 BRR : Created. *
  79. *=========================================================================*/
  80. ColorListClass::~ColorListClass(void)
  81. {
  82. Colors.Clear();
  83. }
  84. /***************************************************************************
  85. * ColorListClass::Add_Item -- Adds an item to the list *
  86. * *
  87. * INPUT: *
  88. * text text to add to list *
  89. * color color for item *
  90. * *
  91. * OUTPUT: *
  92. * position of item in the list *
  93. * *
  94. * WARNINGS: *
  95. * none. *
  96. * *
  97. * HISTORY: *
  98. * 04/19/1995 BRR : Created. *
  99. *=========================================================================*/
  100. int ColorListClass::Add_Item(char const * text, char color)
  101. {
  102. Colors.Add(color);
  103. return(ListClass::Add_Item(text));
  104. }
  105. /***************************************************************************
  106. * ColorListClass::Add_Item -- Adds an item to the list *
  107. * *
  108. * INPUT: *
  109. * text text to add to list *
  110. * color color for item *
  111. * *
  112. * OUTPUT: *
  113. * position of item in the list *
  114. * *
  115. * WARNINGS: *
  116. * none. *
  117. * *
  118. * HISTORY: *
  119. * 04/19/1995 BRR : Created. *
  120. *=========================================================================*/
  121. int ColorListClass::Add_Item(int text, char color)
  122. {
  123. Colors.Add(color);
  124. return(ListClass::Add_Item(text));
  125. }
  126. /***************************************************************************
  127. * ColorListClass::Remove_Item -- Removes an item from the list *
  128. * *
  129. * INPUT: *
  130. * text ptr to item to remove *
  131. * *
  132. * OUTPUT: *
  133. * none. *
  134. * *
  135. * WARNINGS: *
  136. * *
  137. * HISTORY: *
  138. * 04/19/1995 BRR : Created. *
  139. *=========================================================================*/
  140. void ColorListClass::Remove_Item(char const * text)
  141. {
  142. int index = List.ID(text);
  143. if (index != -1) {
  144. Colors.Delete(index);
  145. ListClass::Remove_Item(text);
  146. }
  147. }
  148. /***************************************************************************
  149. * ColorListClass::Set_Selected_Style -- tells how to draw selected item *
  150. * *
  151. * INPUT: *
  152. * style style to draw *
  153. * color color to draw the special style in; -1 = use item's color*
  154. * *
  155. * OUTPUT: *
  156. * none. *
  157. * *
  158. * WARNINGS: *
  159. * none. *
  160. * *
  161. * HISTORY: *
  162. * 04/19/1995 BRR : Created. *
  163. *=========================================================================*/
  164. void ColorListClass::Set_Selected_Style(SelectStyleType style, int color)
  165. {
  166. Style = style;
  167. SelectColor = color;
  168. }
  169. /***************************************************************************
  170. * ColorListClass::Draw_Entry -- Draws one text line *
  171. * *
  172. * INPUT: *
  173. * index index into List of item to draw *
  174. * x,y x,y coords to draw at *
  175. * width maximum width allowed for text *
  176. * selected true = this item is selected *
  177. * *
  178. * OUTPUT: *
  179. * none. *
  180. * *
  181. * WARNINGS: *
  182. * none. *
  183. * *
  184. * HISTORY: *
  185. * 04/19/1995 BRR : Created. *
  186. *=========================================================================*/
  187. void ColorListClass::Draw_Entry(int index, int x, int y, int width, int selected)
  188. {
  189. int color;
  190. /*
  191. ** Draw a non-selected item in its color
  192. */
  193. if (!selected) {
  194. Conquer_Clip_Text_Print(List[index], x, y, Colors[index], TBLACK, TextFlags, width, Tabs);
  195. return;
  196. }
  197. /*
  198. ** For selected items, choose the right color & style:
  199. */
  200. if (SelectColor==-1) {
  201. color = Colors[index];
  202. } else {
  203. color = SelectColor;
  204. }
  205. switch (Style) {
  206. /*
  207. ** NONE: Just print the string in its native color
  208. */
  209. case SELECT_NONE:
  210. Conquer_Clip_Text_Print(List[index], x, y, Colors[index], TBLACK, TextFlags, width, Tabs);
  211. break;
  212. /*
  213. ** HIGHLIGHT: Draw the string in the highlight color (SelectColor must
  214. ** be set)
  215. */
  216. case SELECT_HIGHLIGHT:
  217. if (TextFlags & TPF_6PT_GRAD) {
  218. Conquer_Clip_Text_Print(List[index], x, y, color, TBLACK, TextFlags | TPF_BRIGHT_COLOR, width, Tabs);
  219. } else {
  220. Conquer_Clip_Text_Print(List[index], x, y, color, TBLACK, TextFlags, width, Tabs);
  221. }
  222. break;
  223. /*
  224. ** BOX: Draw a box around the item in the current select color
  225. */
  226. case SELECT_BOX:
  227. LogicPage->Draw_Rect (x, y, x + width - 2, y + LineHeight - 2, color);
  228. Conquer_Clip_Text_Print(List[index], x, y, Colors[index], TBLACK, TextFlags, width, Tabs);
  229. break;
  230. /*
  231. ** BAR: draw a color bar under the text
  232. */
  233. case SELECT_BAR:
  234. if (TextFlags & TPF_6PT_GRAD) {
  235. LogicPage->Fill_Rect (x, y, x + width - 1, y + LineHeight - 1, SelectColor);
  236. Conquer_Clip_Text_Print(List[index], x, y, Colors[index], TBLACK, TextFlags | TPF_BRIGHT_COLOR, width, Tabs);
  237. } else {
  238. LogicPage->Fill_Rect (x, y, x + width - 2, y + LineHeight - 2, SelectColor);
  239. Conquer_Clip_Text_Print(List[index], x, y, Colors[index], TBLACK, TextFlags, width, Tabs);
  240. }
  241. break;
  242. /*
  243. ** INVERT: Draw text as the background color on foreground color
  244. */
  245. case SELECT_INVERT:
  246. if (TextFlags & TPF_6PT_GRAD) {
  247. LogicPage->Fill_Rect (x, y, x + width - 1, y + LineHeight - 1, Colors[index]);
  248. Conquer_Clip_Text_Print(List[index], x, y, BLACK, TBLACK, TextFlags, width, Tabs);
  249. } else {
  250. LogicPage->Fill_Rect (x, y, x + width - 2, y + LineHeight - 2, Colors[index]);
  251. Conquer_Clip_Text_Print(List[index], x, y, LTGREY, TBLACK, TextFlags, width, Tabs);
  252. }
  253. break;
  254. }
  255. }