DeviceSelectionDialog.cpp 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  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. // DeviceSelectionDialog.cpp : implementation file
  19. //
  20. #include "StdAfx.H"
  21. #include "W3DView.h"
  22. #include "DeviceSelectionDialog.h"
  23. #include "WW3D.H"
  24. #include "Resource.H"
  25. #include "Globals.h"
  26. #include "W3DView.H"
  27. #include "Utils.H"
  28. #include "rddesc.h"
  29. #ifdef _DEBUG
  30. #define new DEBUG_NEW
  31. #undef THIS_FILE
  32. static char THIS_FILE[] = __FILE__;
  33. #endif
  34. /////////////////////////////////////////////////////////////////////////////
  35. // CDeviceSelectionDialog dialog
  36. ////////////////////////////////////////////////////////////////////
  37. //
  38. // CDeviceSelectionDialog
  39. //
  40. CDeviceSelectionDialog::CDeviceSelectionDialog
  41. (
  42. BOOL bLookupCachedInfo,
  43. CWnd* pParent /*=NULL*/
  44. )
  45. : m_iDeviceIndex (1),
  46. m_iBitsPerPixel (16),
  47. m_bLookupCachedInfo (bLookupCachedInfo),
  48. CDialog(CDeviceSelectionDialog::IDD, pParent)
  49. {
  50. //{{AFX_DATA_INIT(CDeviceSelectionDialog)
  51. // NOTE: the ClassWizard will add member initialization here
  52. //}}AFX_DATA_INIT
  53. return ;
  54. }
  55. ////////////////////////////////////////////////////////////////////
  56. //
  57. // DoDataExchange
  58. //
  59. void
  60. CDeviceSelectionDialog::DoDataExchange (CDataExchange* pDX)
  61. {
  62. // Allow the base class to process this message
  63. CDialog::DoDataExchange(pDX);
  64. //{{AFX_DATA_MAP(CDeviceSelectionDialog)
  65. DDX_Control(pDX, IDC_RENDER_DEVICE_COMBO, m_deviceListComboBox);
  66. //}}AFX_DATA_MAP
  67. return ;
  68. }
  69. BEGIN_MESSAGE_MAP(CDeviceSelectionDialog, CDialog)
  70. //{{AFX_MSG_MAP(CDeviceSelectionDialog)
  71. ON_CBN_SELCHANGE(IDC_RENDER_DEVICE_COMBO, OnSelchangeRenderDeviceCombo)
  72. //}}AFX_MSG_MAP
  73. END_MESSAGE_MAP()
  74. /////////////////////////////////////////////////////////////////////////////
  75. // CDeviceSelectionDialog message handlers
  76. ////////////////////////////////////////////////////////////////////
  77. //
  78. // OnInitDialog
  79. //
  80. BOOL
  81. CDeviceSelectionDialog::OnInitDialog (void)
  82. {
  83. CDialog::OnInitDialog();
  84. //
  85. // Loop through all the devices and add them to the combobox
  86. //
  87. int device_count = WW3D::Get_Render_Device_Count ();
  88. int selected_index = 0;
  89. for (int index = 0; index < device_count; index ++) {
  90. //
  91. // Add this device to the combobox
  92. //
  93. const char *name = WW3D::Get_Render_Device_Name(index);
  94. int combo_index = m_deviceListComboBox.InsertString (index, name);
  95. if (m_DriverName.CompareNoCase (name) == 0) {
  96. selected_index = combo_index;
  97. }
  98. // Associate the index of this device with the item we just inserted
  99. m_deviceListComboBox.SetItemData (combo_index, index);
  100. }
  101. // Check the '16bpp' radio by default
  102. SendDlgItemMessage (IDC_COLORDEPTH_16, BM_SETCHECK, (WPARAM)TRUE);
  103. // Force the first entry in the combobox to be selected.
  104. //m_deviceListComboBox.SetCurSel (0);
  105. m_deviceListComboBox.SetCurSel (selected_index);
  106. // Update the static controls on the dialog to reflect the device
  107. UpdateDeviceDescription ();
  108. return TRUE;
  109. }
  110. ////////////////////////////////////////////////////////////////////
  111. //
  112. // OnSelchangeRenderDeviceCombo
  113. //
  114. void
  115. CDeviceSelectionDialog::OnSelchangeRenderDeviceCombo (void)
  116. {
  117. int index = m_deviceListComboBox.GetCurSel ();
  118. if (index != CB_ERR) {
  119. //WW3D::Set_Render_Device ();
  120. // Update the static controls with the information from the device
  121. UpdateDeviceDescription ();
  122. }
  123. return ;
  124. }
  125. ////////////////////////////////////////////////////////////////////
  126. //
  127. // UpdateDeviceDescription
  128. //
  129. void
  130. CDeviceSelectionDialog::UpdateDeviceDescription (void)
  131. {
  132. const RenderDeviceDescClass &device_desc = WW3D::Get_Render_Device_Desc ();
  133. //
  134. // Reload the static text controls on the dialog
  135. //
  136. SetDlgItemText (IDC_DRIVER_NAME, m_DriverName);
  137. SetDlgItemText (IDC_DEVICE_NAME_STATIC, device_desc.Get_Device_Name());
  138. SetDlgItemText (IDC_DEVICE_VENDOR_STATIC, device_desc.Get_Device_Vendor());
  139. SetDlgItemText (IDC_DEVICE_PLATFORM_STATIC, device_desc.Get_Device_Platform());
  140. SetDlgItemText (IDC_DRIVER_NAME_STATIC, device_desc.Get_Driver_Name());
  141. SetDlgItemText (IDC_DRIVER_VENDOR_STATIC, device_desc.Get_Driver_Vendor());
  142. SetDlgItemText (IDC_DRIVER_VERSION_STATIC, device_desc.Get_Driver_Version());
  143. SetDlgItemText (IDC_HARDWARE_NAME_STATIC, device_desc.Get_Hardware_Name());
  144. SetDlgItemText (IDC_HARDWARE_VENDOR_STATIC, device_desc.Get_Hardware_Vendor());
  145. SetDlgItemText (IDC_HARDWARE_CHIPSET_STATIC, device_desc.Get_Hardware_Chipset());
  146. return ;
  147. }
  148. ////////////////////////////////////////////////////////////////////
  149. //
  150. // OnOK
  151. //
  152. void
  153. CDeviceSelectionDialog::OnOK (void)
  154. {
  155. // Ask the combobox for its current selection
  156. m_iDeviceIndex = m_deviceListComboBox.GetItemData (m_deviceListComboBox.GetCurSel ());
  157. m_iBitsPerPixel = (SendDlgItemMessage (IDC_COLORDEPTH_16, BM_GETCHECK) == TRUE) ? 16 : 24;
  158. // Get the device name of the currently selected device
  159. CString stringDeviceName;
  160. m_deviceListComboBox.GetLBText (m_deviceListComboBox.GetCurSel (), stringDeviceName);
  161. m_DriverName = stringDeviceName;
  162. // Cache this information in the registry
  163. theApp.WriteProfileString ("Config", "DeviceName", stringDeviceName);
  164. theApp.WriteProfileInt ("Config", "DeviceBitsPerPix", m_iBitsPerPixel);
  165. // Allow the base class to process this message
  166. CDialog::OnOK();
  167. return ;
  168. }
  169. ////////////////////////////////////////////////////////////////////
  170. //
  171. // DoModal
  172. //
  173. int
  174. CDeviceSelectionDialog::DoModal (void)
  175. {
  176. BOOL bFoundDevice = FALSE;
  177. int iReturn = IDOK;
  178. // Get the name of the last used device driver from the registry
  179. m_DriverName = theApp.GetProfileString ("Config", "DeviceName");
  180. if (m_bLookupCachedInfo &&
  181. (m_DriverName.GetLength () > 0) &&
  182. !(::GetKeyState (VK_SHIFT) & 0xF000)) {
  183. //
  184. // Loop through all the devices and see if we can find the right one
  185. //
  186. int device_count = WW3D::Get_Render_Device_Count ();
  187. for (int index = 0; (index < device_count) && !bFoundDevice; index ++) {
  188. //
  189. // Is this the device we are looking for?
  190. //
  191. const char *name = WW3D::Get_Render_Device_Name (index);
  192. if (m_DriverName.CompareNoCase (name) == 0) {
  193. //
  194. // Set the internal device information to simulate 'showing' the dialog
  195. //
  196. m_iDeviceIndex = index;
  197. m_iBitsPerPixel = theApp.GetProfileInt ("Config", "DeviceBitsPerPix", 16);
  198. // Found it!
  199. bFoundDevice = TRUE;
  200. }
  201. }
  202. }
  203. // Show the dialog and allow the user to select the device
  204. if (bFoundDevice == FALSE) {
  205. iReturn = CDialog::DoModal ();
  206. }
  207. // Return the integer return code
  208. return iReturn;
  209. }