DeviceSelectionDialog.cpp 7.0 KB

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