Starshatter_Open
Open source Starshatter engine
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
VidDlg.cpp
Go to the documentation of this file.
1 /* Project Starshatter 4.5
2  Destroyer Studios LLC
3  Copyright © 1997-2004. All Rights Reserved.
4 
5  SUBSYSTEM: Stars.exe
6  FILE: VidDlg.cpp
7  AUTHOR: John DiCamillo
8 
9 
10  OVERVIEW
11  ========
12  Main Menu Dialog Active Window class
13 */
14 
15 #include "MemDebug.h"
16 #include "VidDlg.h"
17 #include "BaseScreen.h"
18 #include "Starshatter.h"
19 #include "Ship.h"
20 #include "Terrain.h"
21 #include "CameraDirector.h"
22 
23 #include "DataLoader.h"
24 #include "Button.h"
25 #include "ListBox.h"
26 #include "Slider.h"
27 #include "Video.h"
28 #include "VideoSettings.h"
29 #include "Keyboard.h"
30 #include "MachineInfo.h"
31 
32 // +--------------------------------------------------------------------+
33 // DECLARE MAPPING FUNCTIONS:
34 
35 DEF_MAP_CLIENT(VidDlg, OnTexSize);
36 DEF_MAP_CLIENT(VidDlg, OnMode);
37 DEF_MAP_CLIENT(VidDlg, OnDetail);
38 DEF_MAP_CLIENT(VidDlg, OnTexture);
39 DEF_MAP_CLIENT(VidDlg, OnGamma);
40 DEF_MAP_CLIENT(VidDlg, OnApply);
41 DEF_MAP_CLIENT(VidDlg, OnCancel);
42 DEF_MAP_CLIENT(VidDlg, OnAudio);
43 DEF_MAP_CLIENT(VidDlg, OnVideo);
44 DEF_MAP_CLIENT(VidDlg, OnOptions);
45 DEF_MAP_CLIENT(VidDlg, OnControls);
46 DEF_MAP_CLIENT(VidDlg, OnMod);
47 
48 // +--------------------------------------------------------------------+
49 
51 : FormWindow(s, 0, 0, s->Width(), s->Height()), manager(mgr),
52 selected_mode(0), selected_detail(0), orig_gamma(128),
53 selected_card(0), selected_tex_size(0), selected_render(0), selected_texture(0),
54 mode(0), tex_size(0), detail(0), texture(0), gamma(0), shadows(0), spec_maps(0),
55 bump_maps(0), lens_flare(0), corona(0), nebula(0), dust(0),
56 apply(0), cancel(0), vid_btn(0), aud_btn(0), ctl_btn(0), opt_btn(0), mod_btn(0),
57 closed(true)
58 {
60 
61  Init(def);
63 }
64 
66 {
67 }
68 
69 // +--------------------------------------------------------------------+
70 
71 void
73 {
74  if (apply)
75  return;
76 
77  mode = (ComboBox*) FindControl(203);
79 
80  tex_size = (ComboBox*) FindControl(204);
82 
83  detail = (ComboBox*) FindControl(205);
85 
86  texture = (ComboBox*) FindControl(206);
88 
89  gamma = (Slider*) FindControl(215);
90 
91  if (gamma) {
92  gamma->SetRangeMin(32);
93  gamma->SetRangeMax(224);
94  gamma->SetStepSize(16);
95 
97  }
98 
100  corona = (ComboBox*) FindControl(212);
101  nebula = (ComboBox*) FindControl(213);
102  dust = (ComboBox*) FindControl(214);
103  shadows = (ComboBox*) FindControl(222);
104  spec_maps = (ComboBox*) FindControl(223);
105  bump_maps = (ComboBox*) FindControl(224);
106 
107  apply = (Button*) FindControl(1);
109 
110  cancel = (Button*) FindControl(2);
112 
113  vid_btn = (Button*) FindControl(901);
115 
116  aud_btn = (Button*) FindControl(902);
118 
119  ctl_btn = (Button*) FindControl(903);
121 
122  opt_btn = (Button*) FindControl(904);
124 
125  mod_btn = (Button*) FindControl(905);
126  if (mod_btn)
128 }
129 
130 // +--------------------------------------------------------------------+
131 
132 void
134 {
136 
137  if (closed) {
138  bool fullscreen = true;
139 
140  if (stars) {
141  selected_render = 9;
142  selected_card = 0;
143 
144  int n = stars->MaxTexSize();
145 
146  for (int i = 0; i < 7; i++) {
147  if (n <= pow(2.0f, i+6)) {
148  selected_tex_size = i;
149  break;
150  }
151  }
152 
153  Video* video = Game::GetVideo();
154 
155  if (video) {
156  if (shadows)
158 
159  if (spec_maps)
161 
162  if (bump_maps)
164 
165  fullscreen = video->IsFullScreen();
166  }
167 
168  if (lens_flare)
170 
171  if (corona)
173 
174  if (nebula)
176 
177  if (dust)
179  }
180 
182  selected_texture = true;
183 
184  if (mode) {
185  BuildModeList();
187  mode->SetEnabled(fullscreen);
188  }
189 
190  if (tex_size)
192 
193  if (detail)
195 
196  if (texture)
198 
199 
200  if (gamma) {
203  }
204  }
205 
206  if (vid_btn) vid_btn->SetButtonState(1);
207  if (aud_btn) aud_btn->SetButtonState(0);
208  if (ctl_btn) ctl_btn->SetButtonState(0);
209  if (opt_btn) opt_btn->SetButtonState(0);
210  if (mod_btn) mod_btn->SetButtonState(0);
211 
212  closed = false;
213 }
214 
215 // +--------------------------------------------------------------------+
216 
217 void
219 {
220  if (Keyboard::KeyDown(VK_RETURN)) {
221  OnApply(0);
222  }
223 }
224 
225 // +--------------------------------------------------------------------+
226 
227 void
229 {
231 }
232 
233 void
235 {
237 }
238 
239 void
241 {
243 }
244 
245 void
247 {
249 }
250 
251 void
253 {
254  int g = gamma->GetValue();
255 
256  if (g >= 0 && g <= 255) {
258  }
259 }
260 
261 // +--------------------------------------------------------------------+
262 
268 
269 // +--------------------------------------------------------------------+
270 
271 void
273 {
275 }
276 
277 void
279 {
281 }
282 
283 // +--------------------------------------------------------------------+
284 
285 void
287 {
288  if (closed) return;
289 
290  int w = 800;
291  int h = 600;
292  int d = 32;
293  int a = 1;
294  int g = 128;
295  int t = 2048;
296  float bias = 0;
297 
298  const char* mode_desc = mode->GetSelectedItem();
299 
300  if (strstr(mode_desc, "800 x 600")) {
301  w = 800;
302  h = 600;
303  }
304  else if (strstr(mode_desc, "1024 x 768")) {
305  w = 1024;
306  h = 768;
307  }
308  else if (strstr(mode_desc, "1152 x 864")) {
309  w = 1152;
310  h = 864;
311  }
312  else if (strstr(mode_desc, "1280 x 800")) {
313  w = 1280;
314  h = 800;
315  }
316  else if (strstr(mode_desc, "1280 x 960")) {
317  w = 1280;
318  h = 960;
319  }
320  else if (strstr(mode_desc, "1280 x 1024")) {
321  w = 1280;
322  h = 1024;
323  }
324  else if (strstr(mode_desc, "1440 x 900")) {
325  w = 1440;
326  h = 900;
327  }
328  else if (strstr(mode_desc, "1600 x 900")) {
329  w = 1600;
330  h = 900;
331  }
332  else if (strstr(mode_desc, "1600 x 1200")) {
333  w = 1600;
334  h = 1200;
335  }
336 
337  if (strstr(mode_desc, "x 16"))
338  d = 16;
339  else if (strstr(mode_desc, "x 32"))
340  d = 32;
341 
342  if (selected_tex_size)
343  t = (int) pow(2.0f, selected_tex_size + 6);
344 
345  bool video_change = false;
346 
347  Video* video = Game::GetVideo();
348  if (video) {
349  const VideoSettings* vs = video->GetVideoSettings();
350 
351  if (vs)
352  bias = vs->depth_bias;
353 
354  if (video->IsFullScreen()) {
355  if (video->Width() != w)
356  video_change = true;
357 
358  if (video->Height() != h)
359  video_change = true;
360 
361  if (video->Depth() != d)
362  video_change = true;
363  }
364  else if (vs) {
365  w = vs->fullscreen_mode.width;
366  h = vs->fullscreen_mode.height;
367 
370  d = 16;
371  else
372  d = 32;
373  }
374 
375  if (Game::MaxTexSize() != t)
376  video_change = true;
377  }
378 
379  FILE* f = 0;
380 
381  if (video_change)
382  fopen_s(&f, "video2.cfg", "w");
383  else
384  fopen_s(&f, "video.cfg", "w");
385 
386  if (gamma) {
387  g = gamma->GetValue();
388  }
389 
390  if (f) {
391  fprintf(f, "VIDEO\n\n");
392  fprintf(f, "width: %4d\n", w);
393  fprintf(f, "height: %4d\n", h);
394  fprintf(f, "depth: %4d\n", d);
395  fprintf(f, "\n");
396  fprintf(f, "max_tex: %d\n", (int) pow(2.0f, 6 + selected_tex_size));
397  fprintf(f, "primary3D: %s\n", (a>0)?"true":"false");
398  fprintf(f, "gamma: %4d\n", g);
399  fprintf(f, "\n");
400  fprintf(f, "terrain_detail_level: %d\n", selected_detail + 2);
401  fprintf(f, "terrain_texture_enable: %s\n", selected_texture ? "true" : "false");
402  fprintf(f, "\n");
403  fprintf(f, "shadows: %s\n", shadows->GetSelectedIndex() ? "true" : "false");
404  fprintf(f, "spec_maps: %s\n", spec_maps->GetSelectedIndex() ? "true" : "false");
405  fprintf(f, "bump_maps: %s\n", bump_maps->GetSelectedIndex() ? "true" : "false");
406  fprintf(f, "bias: %f\n", bias);
407  fprintf(f, "\n");
408  fprintf(f, "flare: %s\n", lens_flare->GetSelectedIndex() ? "true" : "false");
409  fprintf(f, "corona: %s\n", corona->GetSelectedIndex() ? "true" : "false");
410  fprintf(f, "nebula: %s\n", nebula->GetSelectedIndex() ? "true" : "false");
411  fprintf(f, "dust: %d\n", dust->GetSelectedIndex());
412 
413  if (CameraDirector::GetRangeLimit() != 300e3)
414  fprintf(f, " cam_range_max: %f,\n", CameraDirector::GetRangeLimit());
415 
416  fclose(f);
417  }
418 
420 
421  if (stars) {
422  if (video_change)
423  stars->RequestChangeVideo();
424  else
425  stars->LoadVideoConfig("video.cfg");
426  }
427 
428  closed = true;
429 }
430 
431 void
433 {
435  closed = true;
436 }
437 
438 // +--------------------------------------------------------------------+
439 
440 void
442 {
443  char mode_desc[32];
445 
446  mode->ClearItems();
447  selected_mode = 0;
448 
449  if (Game::DisplayModeSupported( 800, 600, 16)) mode->AddItem("800 x 600 x 16");
450  if (Game::DisplayModeSupported( 800, 600, 32)) mode->AddItem("800 x 600 x 32");
451 
452  if (Game::DisplayModeSupported(1024, 768, 16)) mode->AddItem("1024 x 768 x 16");
453  if (Game::DisplayModeSupported(1024, 768, 32)) mode->AddItem("1024 x 768 x 32");
454 
455  if (Game::DisplayModeSupported(1152, 864, 16)) mode->AddItem("1152 x 864 x 16");
456  if (Game::DisplayModeSupported(1152, 864, 32)) mode->AddItem("1152 x 864 x 32");
457 
458  if (Game::DisplayModeSupported(1280, 800, 16)) mode->AddItem("1280 x 800 x 16");
459  if (Game::DisplayModeSupported(1280, 800, 32)) mode->AddItem("1280 x 800 x 32");
460 
461  if (Game::DisplayModeSupported(1280, 960, 16)) mode->AddItem("1280 x 960 x 16");
462  if (Game::DisplayModeSupported(1280, 960, 32)) mode->AddItem("1280 x 960 x 32");
463 
464  if (Game::DisplayModeSupported(1280,1024, 16)) mode->AddItem("1280 x 1024 x 16");
465  if (Game::DisplayModeSupported(1280,1024, 32)) mode->AddItem("1280 x 1024 x 32");
466 
467  if (Game::DisplayModeSupported(1440, 900, 16)) mode->AddItem("1440 x 900 x 16");
468  if (Game::DisplayModeSupported(1440, 900, 32)) mode->AddItem("1440 x 900 x 32");
469 
470  if (Game::DisplayModeSupported(1600, 900, 16)) mode->AddItem("1600 x 900 x 16");
471  if (Game::DisplayModeSupported(1600, 900, 32)) mode->AddItem("1600 x 900 x 32");
472 
473  if (Game::DisplayModeSupported(1600,1200, 16)) mode->AddItem("1600 x 1200 x 16");
474  if (Game::DisplayModeSupported(1600,1200, 32)) mode->AddItem("1600 x 1200 x 32");
475 
476  if (Game::DisplayModeSupported(1680,1050, 16)) mode->AddItem("1680 x 1050 x 16");
477  if (Game::DisplayModeSupported(1680,1050, 32)) mode->AddItem("1680 x 1050 x 32");
478 
479  Video* video = Game::GetVideo();
480 
481  if (stars && video) {
482  switch (video->Width()) {
483  case 800: strcpy_s(mode_desc, "800 x 600 x "); break;
484  default:
485  case 1024: strcpy_s(mode_desc, "1024 x 768 x "); break;
486  case 1152: strcpy_s(mode_desc, "1152 x 864 x "); break;
487  case 1280:
488  if (video->Height() < 900)
489  strcpy_s(mode_desc, "1280 x 800 x ");
490  if (video->Height() < 1000)
491  strcpy_s(mode_desc, "1280 x 960 x ");
492  else
493  strcpy_s(mode_desc, "1280 x 1024 x ");
494  break;
495  case 1440: strcpy_s(mode_desc, "1440 x 900 x "); break;
496  case 1600:
497  if (video->Height() < 1000)
498  strcpy_s(mode_desc, "1600 x 900 x ");
499  else
500  strcpy_s(mode_desc, "1600 x 1200 x ");
501  break;
502  }
503 
504  switch (video->Depth()) {
505  default:
506  case 8: strcat_s(mode_desc, "8"); break;
507  case 16: strcat_s(mode_desc, "16"); break;
508  case 32: strcat_s(mode_desc, "32"); break;
509  }
510 
511  for (int i = 0; i < mode->GetCount(); i++) {
512  if (!strcmp(mode->GetItem(i), mode_desc))
513  selected_mode = i;
514  }
515  }
516 }