vidinitDlg.cpp 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. /*
  2. ** Command & Conquer Renegade(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. // vidinitDlg.cpp : implementation file
  19. //
  20. #include "stdafx.h"
  21. #include "vidinit.h"
  22. #include "vidinitDlg.h"
  23. #include "SurrenderWnd.h"
  24. #include "wwsaveload.h"
  25. #include <ww3d.h>
  26. #ifdef _DEBUG
  27. #define new DEBUG_NEW
  28. #undef THIS_FILE
  29. static char THIS_FILE[] = __FILE__;
  30. #endif
  31. //#define REGISTRY_KEY "Software\\Westwood Studios\\Earth and Beyond\\Render"
  32. #define REGISTRY_KEY "Software\\Westwood Studios\\Renegade\\Render"
  33. /////////////////////////////////////////////////////////////////////////////
  34. // CVidinitDlg dialog
  35. CVidinitDlg::CVidinitDlg(CWnd* pParent /*=NULL*/)
  36. : CDialog(CVidinitDlg::IDD, pParent),
  37. m_TestCWnd(0)
  38. {
  39. //{{AFX_DATA_INIT(CVidinitDlg)
  40. m_RunFullScreen = FALSE;
  41. //}}AFX_DATA_INIT
  42. // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
  43. m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  44. }
  45. void CVidinitDlg::DoDataExchange(CDataExchange* pDX)
  46. {
  47. CDialog::DoDataExchange(pDX);
  48. //{{AFX_DATA_MAP(CVidinitDlg)
  49. DDX_Control(pDX, IDC_RESOLUTIONS, m_Resolutions);
  50. DDX_Control(pDX, IDC_DRIVERS, m_Drivers);
  51. DDX_Check(pDX, IDC_CHECK1, m_RunFullScreen);
  52. //}}AFX_DATA_MAP
  53. }
  54. BEGIN_MESSAGE_MAP(CVidinitDlg, CDialog)
  55. //{{AFX_MSG_MAP(CVidinitDlg)
  56. ON_WM_PAINT()
  57. ON_WM_QUERYDRAGICON()
  58. ON_LBN_SELCHANGE(IDC_DRIVERS, OnSelchangeDrivers)
  59. ON_BN_CLICKED(IDTEST, OnTest)
  60. //}}AFX_MSG_MAP
  61. ON_MESSAGE(WM_USER+1, OnDeadBeef)
  62. END_MESSAGE_MAP()
  63. /////////////////////////////////////////////////////////////////////////////
  64. // CVidinitDlg message handlers
  65. BOOL CVidinitDlg::OnInitDialog()
  66. {
  67. CDialog::OnInitDialog();
  68. // Set the icon for this dialog. The framework does this automatically
  69. // when the application's main window is not a dialog
  70. SetIcon(m_hIcon, TRUE); // Set big icon
  71. SetIcon(m_hIcon, FALSE); // Set small icon
  72. // TODO: Add extra initialization here
  73. WW3D::Init(GetSafeHwnd());
  74. WWMath::Init();
  75. WWSaveLoad::Init();
  76. // HACK: Added throwaway variable for texture_depth to match new function interface. (DRM 6/01/00)
  77. // TODO: Add UI support for texture depth selection. (DRM, 6/1/00)
  78. int texture_depth;
  79. WW3D::Detect_Drivers(AfxGetInstanceHandle());
  80. WW3D::Registry_Load_Render_Device(REGISTRY_KEY, m_DeviceName, 255, m_DeviceWidth, m_DeviceHeight, m_DeviceDepth, m_DeviceWindowed, texture_depth);
  81. // Loop thought the different available render devices
  82. for (int lp = 0; lp < WW3D::Get_Render_Device_Count(); lp++) {
  83. const RenderDeviceDescClass &desc = WW3D::Get_Render_Device_Desc(lp);
  84. char temp[255];
  85. sprintf(temp, "%s", WW3D::Get_Render_Device_Name(lp));
  86. m_Drivers.AddString(temp);
  87. }
  88. int idx = m_Drivers.FindStringExact(0, m_DeviceName);
  89. if (idx != -1) {
  90. m_Drivers.SetCurSel(idx);
  91. OnSelchangeDrivers();
  92. char temp[255];
  93. sprintf(temp, "%d x %d in %d bit mode.", m_DeviceWidth, m_DeviceHeight, m_DeviceDepth);
  94. int idx = m_Resolutions.FindStringExact(0, temp);
  95. m_Resolutions.SetCurSel(idx);
  96. m_RunFullScreen = !m_DeviceWindowed;
  97. UpdateData(false);
  98. }
  99. return TRUE; // return TRUE unless you set the focus to a control
  100. }
  101. // If you add a minimize button to your dialog, you will need the code below
  102. // to draw the icon. For MFC applications using the document/view model,
  103. // this is automatically done for you by the framework.
  104. void CVidinitDlg::OnPaint()
  105. {
  106. if (IsIconic())
  107. {
  108. CPaintDC dc(this); // device context for painting
  109. SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
  110. // Center icon in client rectangle
  111. int cxIcon = GetSystemMetrics(SM_CXICON);
  112. int cyIcon = GetSystemMetrics(SM_CYICON);
  113. CRect rect;
  114. GetClientRect(&rect);
  115. int x = (rect.Width() - cxIcon + 1) / 2;
  116. int y = (rect.Height() - cyIcon + 1) / 2;
  117. // Draw the icon
  118. dc.DrawIcon(x, y, m_hIcon);
  119. }
  120. else
  121. {
  122. CDialog::OnPaint();
  123. }
  124. }
  125. // The system calls this to obtain the cursor to display while the user drags
  126. // the minimized window.
  127. HCURSOR CVidinitDlg::OnQueryDragIcon()
  128. {
  129. return (HCURSOR) m_hIcon;
  130. }
  131. void CVidinitDlg::OnOK()
  132. {
  133. // TODO: Add extra validation here
  134. UpdateData();
  135. int driver = m_Drivers.GetCurSel();
  136. if (driver == -1) return;
  137. int sel = m_Resolutions.GetCurSel();
  138. if (sel == -1) return;
  139. const RenderDeviceDescClass &desc = WW3D::Get_Render_Device_Desc(driver);
  140. const DynamicVectorClass<ResolutionDescClass>& res = desc.Enumerate_Resolutions();
  141. // HACK: using constant 32 for texture depth. (DRM, 6/1/00)
  142. // TODO: Add UI support for texture depth selection. (DRM, 6/1/00)
  143. WW3D::Registry_Save_Render_Device( REGISTRY_KEY, driver, res[sel].Width, res[sel].Height, res[sel].BitDepth, !m_RunFullScreen, 32);
  144. WW3D::Shutdown();
  145. WWMath::Shutdown();
  146. WWSaveLoad::Shutdown();
  147. CDialog::OnOK();
  148. }
  149. void CVidinitDlg::OnCancel()
  150. {
  151. // TODO: Add extra cleanup here
  152. WW3D::Shutdown();
  153. WWMath::Shutdown();
  154. WWSaveLoad::Shutdown();
  155. CDialog::OnCancel();
  156. }
  157. void CVidinitDlg::OnSelchangeDrivers()
  158. {
  159. // TODO: Add your control notification handler code here
  160. int driver = m_Drivers.GetCurSel();
  161. const RenderDeviceDescClass &desc = WW3D::Get_Render_Device_Desc(driver);
  162. SetDlgItemText(IDC_HARDWARE_NAME, desc.Get_Hardware_Name());
  163. SetDlgItemText(IDC_HARDWARE_VENDOR, desc.Get_Hardware_Vendor());
  164. SetDlgItemText(IDC_HARDWARE_CHIPSET, desc.Get_Hardware_Chipset());
  165. SetDlgItemText(IDC_DRIVER_NAME, desc.Get_Device_Name());
  166. SetDlgItemText(IDC_DRIVER_VENDOR, desc.Get_Device_Vendor());
  167. const DynamicVectorClass<ResolutionDescClass>& res = desc.Enumerate_Resolutions();
  168. while (m_Resolutions.GetCount()) {
  169. m_Resolutions.DeleteString(0);
  170. }
  171. for (int lp = 0; lp < res.Count(); lp++) {
  172. char temp[255];
  173. sprintf(temp, "%d x %d in %d bit mode.", res[lp].Width, res[lp].Height, res[lp].BitDepth);
  174. m_Resolutions.AddString(temp);
  175. }
  176. }
  177. void CVidinitDlg::OnTest()
  178. {
  179. UpdateData(true);
  180. // TODO: Add your control notification handler code here
  181. int driver = m_Drivers.GetCurSel();
  182. if (driver == -1) return;
  183. int sel = m_Resolutions.GetCurSel();
  184. if (sel == -1) return;
  185. const RenderDeviceDescClass &desc = WW3D::Get_Render_Device_Desc(driver);
  186. const DynamicVectorClass<ResolutionDescClass>& res = desc.Enumerate_Resolutions();
  187. m_TestCWnd = new CSurrenderWnd(this, driver, res[sel].Width, res[sel].Height, res[sel].BitDepth, !m_RunFullScreen);
  188. CWnd *wnd = GetDlgItem(IDTEST);
  189. wnd->EnableWindow(false);
  190. wnd = GetDlgItem(IDOK);
  191. wnd->EnableWindow(false);
  192. wnd = GetDlgItem(IDCANCEL);
  193. wnd->EnableWindow(false);
  194. }
  195. LRESULT CVidinitDlg::OnDeadBeef(WPARAM wParam, LPARAM lParam)
  196. {
  197. if (m_TestCWnd && wParam == 0xDEADBEEF && lParam == 0xDEADBEEF) {
  198. WW3D::Restore_Display_Mode();
  199. m_TestCWnd->RemoveSubclass();
  200. m_TestCWnd->PostMessage(WM_CLOSE);
  201. m_TestCWnd = 0;
  202. CWnd *wnd = GetDlgItem(IDTEST);
  203. wnd->EnableWindow(true);
  204. wnd = GetDlgItem(IDOK);
  205. wnd->EnableWindow(true);
  206. wnd = GetDlgItem(IDCANCEL);
  207. wnd->EnableWindow(true);
  208. }
  209. return 0;
  210. }