VISUDLG.CPP 13 KB

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