CnC_Remastered_Collection

Command and Conquer: Red Alert
Log | Files | Refs | README | LICENSE

VISUDLG.CPP (13107B)


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