COLRLIST.CPP 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  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/COLRLIST.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 : COLRLIST.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. Style(SELECT_HIGHLIGHT),
  62. SelectColor(NULL)
  63. {
  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. SelectColor = 0;
  84. }
  85. /***************************************************************************
  86. * ColorListClass::Add_Item -- Adds an item to the list *
  87. * *
  88. * INPUT: *
  89. * text text to add to list *
  90. * color color for item *
  91. * *
  92. * OUTPUT: *
  93. * position of item in the list *
  94. * *
  95. * WARNINGS: *
  96. * none. *
  97. * *
  98. * HISTORY: *
  99. * 04/19/1995 BRR : Created. *
  100. *=========================================================================*/
  101. int ColorListClass::Add_Item(char const * text, RemapControlType * color)
  102. {
  103. Colors.Add(color);
  104. return(ListClass::Add_Item(text));
  105. }
  106. /***************************************************************************
  107. * ColorListClass::Add_Item -- Adds an item to the list *
  108. * *
  109. * INPUT: *
  110. * text text to add to list *
  111. * color color for item *
  112. * *
  113. * OUTPUT: *
  114. * position of item in the list *
  115. * *
  116. * WARNINGS: *
  117. * none. *
  118. * *
  119. * HISTORY: *
  120. * 04/19/1995 BRR : Created. *
  121. *=========================================================================*/
  122. int ColorListClass::Add_Item(int text, RemapControlType * color)
  123. {
  124. Colors.Add(color);
  125. return(ListClass::Add_Item(text));
  126. }
  127. /***************************************************************************
  128. * ColorListClass::Remove_Item -- Removes an item from the list *
  129. * *
  130. * INPUT: *
  131. * text ptr to item to remove *
  132. * *
  133. * OUTPUT: *
  134. * none. *
  135. * *
  136. * WARNINGS: *
  137. * *
  138. * HISTORY: *
  139. * 04/19/1995 BRR : Created. *
  140. *=========================================================================*/
  141. void ColorListClass::Remove_Item(char const * text)
  142. {
  143. int index = List.ID(text);
  144. if (index != -1) {
  145. Colors.Delete(index);
  146. ListClass::Remove_Item(text);
  147. }
  148. }
  149. /***************************************************************************
  150. * ColorListClass::Set_Selected_Style -- tells how to draw selected item *
  151. * *
  152. * INPUT: *
  153. * style style to draw *
  154. * color color to draw the special style in; -1 = use item's color *
  155. * *
  156. * OUTPUT: *
  157. * none. *
  158. * *
  159. * WARNINGS: *
  160. * none. *
  161. * *
  162. * HISTORY: *
  163. * 04/19/1995 BRR : Created. *
  164. *=========================================================================*/
  165. void ColorListClass::Set_Selected_Style(SelectStyleType style, RemapControlType * color)
  166. {
  167. Style = style;
  168. SelectColor = color;
  169. }
  170. /***************************************************************************
  171. * ColorListClass::Draw_Entry -- Draws one text line *
  172. * *
  173. * INPUT: *
  174. * index index into List of item to draw *
  175. * x,y x,y coords to draw at *
  176. * width maximum width allowed for text *
  177. * selected true = this item is selected *
  178. * *
  179. * OUTPUT: *
  180. * none. *
  181. * *
  182. * WARNINGS: *
  183. * none. *
  184. * *
  185. * HISTORY: *
  186. * 04/19/1995 BRR : Created. *
  187. *=========================================================================*/
  188. void ColorListClass::Draw_Entry(int index, int x, int y, int width, int selected)
  189. {
  190. RemapControlType * color;
  191. /*
  192. ** Draw a non-selected item in its color
  193. */
  194. if (!selected) {
  195. Conquer_Clip_Text_Print(List[index], x, y, Colors[index], TBLACK, TextFlags, width, Tabs);
  196. return;
  197. }
  198. /*
  199. ** For selected items, choose the right color & style:
  200. */
  201. if (SelectColor == NULL) {
  202. color = Colors[index];
  203. } else {
  204. color = SelectColor;
  205. }
  206. switch (Style) {
  207. /*
  208. ** NONE: Just print the string in its native color
  209. */
  210. case SELECT_NORMAL:
  211. Conquer_Clip_Text_Print(List[index], x, y, Colors[index], TBLACK,
  212. TextFlags, width, Tabs);
  213. break;
  214. /*
  215. ** HIGHLIGHT: Draw the string in the highlight color (SelectColor must
  216. ** be set)
  217. */
  218. case SELECT_HIGHLIGHT:
  219. if (TextFlags & TPF_6PT_GRAD) {
  220. Conquer_Clip_Text_Print(List[index], x, y, color, TBLACK, TextFlags | TPF_BRIGHT_COLOR, width, Tabs);
  221. } else {
  222. Conquer_Clip_Text_Print(List[index], x, y, color, TBLACK, TextFlags, width, Tabs);
  223. }
  224. break;
  225. /*
  226. ** BOX: Draw a box around the item in the current select color
  227. */
  228. case SELECT_BOX:
  229. LogicPage->Draw_Rect (x, y, x + width - 2, y + LineHeight - 2, color->Color);
  230. Conquer_Clip_Text_Print(List[index], x, y, Colors[index], TBLACK, TextFlags, width, Tabs);
  231. break;
  232. /*
  233. ** BAR: draw a color bar under the text
  234. */
  235. case SELECT_BAR:
  236. if (TextFlags & TPF_6PT_GRAD) {
  237. LogicPage->Fill_Rect(x, y, x + width - 1, y + LineHeight - 1, color->Color);
  238. Conquer_Clip_Text_Print(List[index], x, y, Colors[index], TBLACK, TextFlags | TPF_BRIGHT_COLOR, width, Tabs);
  239. } else {
  240. LogicPage->Fill_Rect(x, y, x + width - 2, y + LineHeight - 2, color->Color);
  241. Conquer_Clip_Text_Print(List[index], x, y, Colors[index], TBLACK, TextFlags, width, Tabs);
  242. }
  243. break;
  244. /*
  245. ** INVERT: Draw text as the background color on foreground color
  246. */
  247. case SELECT_INVERT:
  248. LogicPage->Fill_Rect (x, y, x + width - 1, y + LineHeight - 1, Colors[index]->Color);
  249. break;
  250. }
  251. }