VISUDLG.CPP 13 KB

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