VISUDLG.CPP 13 KB

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