VISUDLG.CPP (13640B)
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: /CounterStrike/VISUDLG.CPP 1 3/03/97 10:26a 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 : VISUDLG.CPP * 24 * * 25 * Programmer : Maria del Mar McCready Legg * 26 * Joe L. Bostic * 27 * * 28 * Start Date : Jan 8, 1995 * 29 * * 30 * Last Update : June 18, 1995 [JLB] * 31 * * 32 *---------------------------------------------------------------------------------------------* 33 * Functions: * 34 * VisualControlsClass::Process -- Process the visual control dialog box. * 35 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ 36 37 #include "function.h" 38 #include "visudlg.h" 39 40 41 /*********************************************************************************************** 42 * VisualControlsClass::Process -- Process the visual control dialog box. * 43 * * 44 * This routine displays and processes the visual controls dialog box. * 45 * * 46 * INPUT: none * 47 * * 48 * OUTPUT: none * 49 * * 50 * WARNINGS: none * 51 * * 52 * HISTORY: * 53 * 06/18/1995 JLB : Created. * 54 *=============================================================================================*/ 55 void VisualControlsClass::Process(void) 56 { 57 static int _titles[4] = { 58 TXT_BRIGHTNESS, 59 TXT_COLOR, 60 TXT_CONTRAST, 61 TXT_TINT 62 }; 63 64 enum { 65 NUM_OF_BUTTONS = 6, 66 }; 67 68 /* 69 ** Make em resolution independent 70 */ 71 int option_width = OPTION_WIDTH * RESFACTOR; // Width of dialog box. 72 int option_height = OPTION_HEIGHT * RESFACTOR; // Height of dialog box. 73 int option_x = OPTION_X * RESFACTOR; 74 int option_y = OPTION_Y * RESFACTOR; 75 int text_x = TEXT_X * RESFACTOR; 76 int text_y = TEXT_Y * RESFACTOR; 77 int slider_x = SLIDER_X * RESFACTOR; 78 int slider_y = SLIDER_Y * RESFACTOR; 79 int slider_width = SLIDER_WIDTH * RESFACTOR; // Width of each control slider. 80 int slider_height = SLIDER_HEIGHT * RESFACTOR; // Height of each control slider. 81 int slider_y_spacing = SLIDER_Y_SPACING * RESFACTOR; // Vertical spacing between sliders. 82 int button_x = BUTTON_X * RESFACTOR; // Options button x pos 83 int button_y = BUTTON_Y * RESFACTOR; // Options button y pos 84 85 86 /* 87 ** Variables. 88 */ 89 int selection; 90 bool pressed; 91 int curbutton; 92 TextButtonClass * buttons[NUM_OF_BUTTONS]; 93 SliderClass * buttonsliders[NUM_OF_BUTTONS]; 94 95 Set_Logic_Page(SeenBuff); 96 97 /* 98 ** Create Buttons. Button coords are in pixels, but are window-relative. 99 */ 100 TextButtonClass optionsbtn(BUTTON_OPTIONS, TXT_OK, TPF_BUTTON, 0, button_y, 60*RESFACTOR); 101 // TextButtonClass optionsbtn(BUTTON_OPTIONS, TXT_OPTIONS_MENU, TPF_BUTTON, 0, button_y); 102 TextButtonClass resetbtn(BUTTON_RESET, TXT_RESET_MENU, TPF_BUTTON, 0, button_y, 80*RESFACTOR); 103 104 /* 105 ** Centers options button. 106 */ 107 optionsbtn.X = option_x + (option_width - optionsbtn.Width - (17 * RESFACTOR)); 108 resetbtn.X = option_x + (17 * RESFACTOR); 109 110 resetbtn.Add_Tail(optionsbtn); 111 112 /* 113 ** Brightness (value) control. 114 */ 115 SliderClass brightness(BUTTON_BRIGHTNESS, slider_x, slider_y + (slider_y_spacing*0), slider_width, slider_height, true); 116 brightness.Set_Thumb_Size(20 * RESFACTOR); 117 brightness.Set_Value(Options.Get_Brightness() * 256); 118 brightness.Add_Tail(optionsbtn); 119 120 /* 121 ** Color (saturation) control. 122 */ 123 SliderClass color(BUTTON_COLOR, slider_x, slider_y + (slider_y_spacing*1), slider_width, slider_height, true); 124 color.Set_Thumb_Size(20 * RESFACTOR); 125 color.Set_Value(Options.Get_Saturation() * 256); 126 color.Add_Tail(optionsbtn); 127 128 /* 129 ** Contrast control. 130 */ 131 SliderClass contrast(BUTTON_CONTRAST, slider_x, slider_y + (slider_y_spacing*2), slider_width, slider_height, true); 132 contrast.Set_Thumb_Size(20 * RESFACTOR); 133 contrast.Set_Value(Options.Get_Contrast() * 256); 134 contrast.Add_Tail(optionsbtn); 135 136 /* 137 ** Tint (hue) control. 138 */ 139 SliderClass tint(BUTTON_TINT, slider_x, slider_y + (slider_y_spacing*3), slider_width, slider_height, true); 140 tint.Set_Thumb_Size(20 * RESFACTOR); 141 tint.Set_Value(Options.Get_Tint() * 256); 142 tint.Add_Tail(optionsbtn); 143 144 /* 145 ** This causes left mouse button clicking within the confines of the dialog to 146 ** be ignored if it wasn't recognized by any other button or slider. 147 */ 148 GadgetClass dialog(option_x, option_y, option_width, option_height, GadgetClass::LEFTPRESS); 149 dialog.Add_Tail(optionsbtn); 150 151 /* 152 ** This causes a right click anywhere or a left click outside the dialog region 153 ** to be equivalent to clicking on the return to options dialog. 154 */ 155 ControlClass background(BUTTON_OPTIONS, 0, 0, SeenBuff.Get_Width(), SeenBuff.Get_Height(), 156 GadgetClass::LEFTPRESS|GadgetClass::RIGHTPRESS); 157 background.Add_Tail(optionsbtn); 158 159 curbutton = 0; 160 buttons[0] = NULL; 161 buttons[1] = NULL; 162 buttons[2] = NULL; 163 buttons[3] = NULL; 164 buttons[4] = &resetbtn; 165 buttons[5] = &optionsbtn; 166 167 buttonsliders[0] = &brightness; 168 buttonsliders[1] = &color; 169 buttonsliders[2] = &contrast; 170 buttonsliders[3] = ∭ 171 buttonsliders[4] = NULL; 172 buttonsliders[5] = NULL; 173 174 /* 175 ** Main Processing Loop. 176 */ 177 bool display = true; 178 bool process = true; 179 bool partial = true; 180 pressed = false; 181 while (process) { 182 183 /* 184 ** Invoke game callback. 185 */ 186 if (Session.Type == GAME_NORMAL || Session.Type == GAME_SKIRMISH) { 187 Call_Back(); 188 } else { 189 if (Main_Loop()) { 190 process = false; 191 } 192 } 193 194 #ifdef WIN32 195 /* 196 ** If we have just received input focus again after running in the background then 197 ** we need to redraw. 198 */ 199 if (AllSurfaces.SurfacesRestored) { 200 AllSurfaces.SurfacesRestored=FALSE; 201 display = true; 202 } 203 #endif 204 /* 205 ** Refresh display if needed. 206 */ 207 if (display) { 208 Hide_Mouse(); 209 Dialog_Box(option_x, option_y, option_width, option_height); 210 Draw_Caption(TXT_VISUAL_CONTROLS, option_x, option_y, option_width); 211 Show_Mouse(); 212 display = false; 213 partial = true; 214 } 215 216 /* 217 ** If just the buttons and captions need to be redrawn, then do so now. 218 */ 219 if (partial) { 220 Hide_Mouse(); 221 222 /* 223 ** Draw the titles. 224 */ 225 for (int i = 0; i < (sizeof(_titles)/sizeof(_titles[0])); i++) { 226 Fancy_Text_Print(_titles[i], slider_x - (8 * RESFACTOR), text_y + (i*slider_y_spacing), 227 GadgetClass::Get_Color_Scheme(), TBLACK, TPF_TEXT|TPF_RIGHT| ((curbutton == i) ? TPF_BRIGHT_COLOR : TPF_TEXT)); 228 } 229 optionsbtn.Draw_All(); 230 Show_Mouse(); 231 partial = false; 232 } 233 234 /* 235 ** Get and process player input. 236 */ 237 KeyNumType input = optionsbtn.Input(); 238 switch (input) { 239 case (BUTTON_BRIGHTNESS | KN_BUTTON): 240 Options.Set_Brightness(fixed(brightness.Get_Value(), 256)); 241 break; 242 243 case (BUTTON_COLOR | KN_BUTTON): 244 Options.Set_Saturation(fixed(color.Get_Value(), 256)); 245 break; 246 247 case (BUTTON_CONTRAST | KN_BUTTON): 248 Options.Set_Contrast(fixed(contrast.Get_Value(), 256)); 249 break; 250 251 case (BUTTON_TINT | KN_BUTTON): 252 Options.Set_Tint(fixed(tint.Get_Value(), 256)); 253 break; 254 255 case (BUTTON_RESET | KN_BUTTON): 256 selection = BUTTON_RESET; 257 pressed = true; 258 break; 259 260 case KN_ESC: 261 case BUTTON_OPTIONS|KN_BUTTON: 262 selection = BUTTON_OPTIONS; 263 pressed = true; 264 break; 265 266 case (KN_LEFT): 267 if (curbutton <= (BUTTON_TINT - BUTTON_BRIGHTNESS)) { 268 buttonsliders[curbutton]->Bump(1); 269 switch (curbutton) { 270 case (BUTTON_BRIGHTNESS - BUTTON_BRIGHTNESS): 271 Options.Set_Brightness(fixed(brightness.Get_Value(), 256)); 272 break; 273 274 case (BUTTON_COLOR - BUTTON_BRIGHTNESS): 275 Options.Set_Saturation(fixed(color.Get_Value(), 256)); 276 break; 277 278 case (BUTTON_CONTRAST - BUTTON_BRIGHTNESS): 279 Options.Set_Contrast(fixed(contrast.Get_Value(), 256)); 280 break; 281 282 case (BUTTON_TINT - BUTTON_BRIGHTNESS): 283 Options.Set_Tint(fixed(tint.Get_Value(), 256)); 284 break; 285 } 286 } else { 287 buttons[curbutton]->Turn_Off(); 288 buttons[curbutton]->Flag_To_Redraw(); 289 290 curbutton--; 291 if (curbutton < (BUTTON_RESET - BUTTON_BRIGHTNESS) ) { 292 curbutton = (BUTTON_OPTIONS - BUTTON_BRIGHTNESS); 293 } 294 295 buttons[curbutton]->Turn_On(); 296 buttons[curbutton]->Flag_To_Redraw(); 297 } 298 break; 299 300 case (KN_RIGHT): 301 if (curbutton <= (BUTTON_TINT - BUTTON_BRIGHTNESS)) { 302 buttonsliders[curbutton]->Bump(0); 303 switch (curbutton) { 304 case (BUTTON_BRIGHTNESS - BUTTON_BRIGHTNESS): 305 Options.Set_Brightness(fixed(brightness.Get_Value(), 256)); 306 break; 307 308 case (BUTTON_COLOR - BUTTON_BRIGHTNESS): 309 Options.Set_Saturation(fixed(color.Get_Value(), 256)); 310 break; 311 312 case (BUTTON_CONTRAST - BUTTON_BRIGHTNESS): 313 Options.Set_Contrast(fixed(contrast.Get_Value(), 256)); 314 break; 315 316 case (BUTTON_TINT - BUTTON_BRIGHTNESS): 317 Options.Set_Tint(fixed(tint.Get_Value(), 256)); 318 break; 319 } 320 } else { 321 buttons[curbutton]->Turn_Off(); 322 buttons[curbutton]->Flag_To_Redraw(); 323 324 curbutton++; 325 if (curbutton > (BUTTON_OPTIONS - BUTTON_BRIGHTNESS) ) { 326 curbutton = (BUTTON_RESET - BUTTON_BRIGHTNESS); 327 } 328 329 buttons[curbutton]->Turn_On(); 330 buttons[curbutton]->Flag_To_Redraw(); 331 } 332 break; 333 334 case (KN_UP): 335 if (curbutton <= (BUTTON_TINT - BUTTON_BRIGHTNESS) ) { 336 partial = true; 337 } else { 338 buttons[curbutton]->Turn_Off(); 339 buttons[curbutton]->Flag_To_Redraw(); 340 } 341 342 curbutton--; 343 if (curbutton == (BUTTON_RESET - BUTTON_BRIGHTNESS) ) { 344 curbutton--; 345 } 346 347 if (curbutton < 0) { 348 curbutton = (BUTTON_RESET - BUTTON_BRIGHTNESS); 349 } 350 351 if (curbutton <= (BUTTON_TINT - BUTTON_BRIGHTNESS) ) { 352 partial = true; 353 } else { 354 buttons[curbutton]->Turn_On(); 355 buttons[curbutton]->Flag_To_Redraw(); 356 } 357 break; 358 359 case (KN_DOWN): 360 if (curbutton <= (BUTTON_TINT - BUTTON_BRIGHTNESS) ) { 361 partial = true; 362 } else { 363 buttons[curbutton]->Turn_Off(); 364 buttons[curbutton]->Flag_To_Redraw(); 365 } 366 367 curbutton++; 368 if (curbutton > (BUTTON_RESET - BUTTON_BRIGHTNESS) ) { 369 curbutton = 0; 370 } 371 372 if (curbutton <= (BUTTON_TINT - BUTTON_BRIGHTNESS) ) { 373 partial = true; 374 } else { 375 buttons[curbutton]->Turn_On(); 376 buttons[curbutton]->Flag_To_Redraw(); 377 } 378 break; 379 380 case (KN_RETURN): 381 selection = curbutton + BUTTON_BRIGHTNESS; 382 pressed = true; 383 break; 384 385 default: 386 break; 387 } 388 389 390 if (pressed) { 391 switch (selection) { 392 case (BUTTON_RESET): 393 brightness.Set_Value(128); 394 contrast.Set_Value(128); 395 color.Set_Value(128); 396 tint.Set_Value(128); 397 398 Options.Set_Brightness(fixed::_1_2); 399 Options.Set_Contrast(fixed::_1_2); 400 Options.Set_Saturation(fixed::_1_2); 401 Options.Set_Tint(fixed::_1_2); 402 break; 403 404 case (BUTTON_OPTIONS): 405 process = false; 406 break; 407 } 408 409 pressed = false; 410 } 411 } 412 } 413