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