ResolutionDialog.cpp 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  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. // ResolutionDialog.cpp : implementation file
  19. //
  20. #include "stdafx.h"
  21. #include "w3dview.h"
  22. #include "ResolutionDialog.h"
  23. #include "WW3D.H"
  24. #include "Globals.h"
  25. #include "GraphicView.h"
  26. #include "Utils.h"
  27. #include "rddesc.h"
  28. #ifdef _DEBUG
  29. #define new DEBUG_NEW
  30. #undef THIS_FILE
  31. static char THIS_FILE[] = __FILE__;
  32. #endif
  33. /////////////////////////////////////////////////////////////////////////////
  34. //
  35. // ResolutionDialogClass
  36. //
  37. /////////////////////////////////////////////////////////////////////////////
  38. ResolutionDialogClass::ResolutionDialogClass(CWnd* pParent /*=NULL*/)
  39. : CDialog(ResolutionDialogClass::IDD, pParent)
  40. {
  41. //{{AFX_DATA_INIT(ResolutionDialogClass)
  42. // NOTE: the ClassWizard will add member initialization here
  43. //}}AFX_DATA_INIT
  44. return ;
  45. }
  46. /////////////////////////////////////////////////////////////////////////////
  47. //
  48. // DoDataExchange
  49. //
  50. /////////////////////////////////////////////////////////////////////////////
  51. void
  52. ResolutionDialogClass::DoDataExchange (CDataExchange* pDX)
  53. {
  54. CDialog::DoDataExchange(pDX);
  55. //{{AFX_DATA_MAP(ResolutionDialogClass)
  56. DDX_Control(pDX, IDC_RESOLUTION_LIST_CTRL, m_ListCtrl);
  57. //}}AFX_DATA_MAP
  58. return ;
  59. }
  60. BEGIN_MESSAGE_MAP(ResolutionDialogClass, CDialog)
  61. //{{AFX_MSG_MAP(ResolutionDialogClass)
  62. ON_NOTIFY(NM_DBLCLK, IDC_RESOLUTION_LIST_CTRL, OnDblclkResolutionListCtrl)
  63. //}}AFX_MSG_MAP
  64. END_MESSAGE_MAP()
  65. /////////////////////////////////////////////////////////////////////////////
  66. //
  67. // OnInitDialog
  68. //
  69. /////////////////////////////////////////////////////////////////////////////
  70. BOOL
  71. ResolutionDialogClass::OnInitDialog (void)
  72. {
  73. CDialog::OnInitDialog ();
  74. //
  75. // Configure the list control
  76. //
  77. m_ListCtrl.SetExtendedStyle (LVS_EX_FULLROWSELECT);
  78. m_ListCtrl.InsertColumn (0, "Resolution");
  79. m_ListCtrl.InsertColumn (1, "Bit Depth");
  80. //
  81. // Size the columns
  82. //
  83. CRect rect;
  84. m_ListCtrl.GetClientRect (&rect);
  85. m_ListCtrl.SetColumnWidth (0, (rect.Width () >> 1) - 4);
  86. m_ListCtrl.SetColumnWidth (1, (rect.Width () >> 1) - 4);
  87. //
  88. // Get information about the current render device
  89. //
  90. const RenderDeviceDescClass &device_info = WW3D::Get_Render_Device_Desc ();
  91. const DynamicVectorClass<ResolutionDescClass> &res_list = device_info.Enumerate_Resolutions ();
  92. //
  93. // Get the current resolution
  94. //
  95. int curr_width = 0;
  96. int curr_height = 0;
  97. int curr_bpp = 0;
  98. bool curr_windowed = false;
  99. WW3D::Get_Device_Resolution (curr_width, curr_height, curr_bpp, curr_windowed);
  100. SendDlgItemMessage (IDC_FULLSCREEN_CHECK, BM_SETCHECK, (WPARAM)(curr_windowed == false));
  101. //
  102. // Loop over all the resolutions available to us
  103. //
  104. bool found = false;
  105. int index = res_list.Count ();
  106. while (index --) {
  107. int width = res_list[index].Width;
  108. int height = res_list[index].Height;
  109. int bpp = res_list[index].BitDepth;
  110. //
  111. // Format description strings for this resolution
  112. //
  113. CString resolution_string;
  114. CString bit_depth_string;
  115. resolution_string.Format ("%d x %d", width, height);
  116. bit_depth_string.Format ("%d bpp (%d colors)", bpp, 1 << bpp);
  117. //
  118. // Add this resolution to the list ctrl
  119. //
  120. int list_index = m_ListCtrl.InsertItem (0, resolution_string, 0);
  121. if (list_index >= 0) {
  122. m_ListCtrl.SetItemText (list_index, 1, bit_depth_string);
  123. m_ListCtrl.SetItemData (list_index, index);
  124. //
  125. // Is this the current resolution? If so,
  126. // select this entry as the default...
  127. //
  128. if ( found == false &&
  129. curr_width == width &&
  130. curr_height == height &&
  131. curr_bpp == bpp)
  132. {
  133. m_ListCtrl.SetItemState (list_index, LVIS_SELECTED, LVIS_SELECTED);
  134. found = true;
  135. }
  136. }
  137. }
  138. //
  139. // Select the first entry by default (if necessary)
  140. //
  141. if (found == false) {
  142. m_ListCtrl.SetItemState (0, LVIS_SELECTED, LVIS_SELECTED);
  143. }
  144. return TRUE;
  145. }
  146. /////////////////////////////////////////////////////////////////////////////
  147. //
  148. // OnOK
  149. //
  150. /////////////////////////////////////////////////////////////////////////////
  151. void
  152. ResolutionDialogClass::OnOK (void)
  153. {
  154. CDialog::OnOK ();
  155. //
  156. // Get the current selection
  157. //
  158. int list_index = m_ListCtrl.GetNextItem (-1, LVNI_ALL | LVNI_SELECTED);
  159. if (list_index >= 0) {
  160. //
  161. // Index into the resolution list for this device...
  162. //
  163. int index = m_ListCtrl.GetItemData (list_index);
  164. if (index >= 0) {
  165. //
  166. // Lookup the selected resolution information
  167. //
  168. const RenderDeviceDescClass &device_info = WW3D::Get_Render_Device_Desc ();
  169. const DynamicVectorClass<ResolutionDescClass> &res_list = device_info.Enumerate_Resolutions ();
  170. g_iWidth = res_list[index].Width;
  171. g_iHeight = res_list[index].Height;
  172. g_iBitsPerPixel = res_list[index].BitDepth;
  173. //
  174. // Cache this information in the registry
  175. //
  176. theApp.WriteProfileInt ("Config", "DeviceWidth", g_iWidth);
  177. theApp.WriteProfileInt ("Config", "DeviceHeight", g_iHeight);
  178. theApp.WriteProfileInt ("Config", "DeviceBitsPerPix", g_iBitsPerPixel);
  179. //
  180. // Reset the display
  181. //
  182. bool fullscreen = (SendDlgItemMessage (IDC_FULLSCREEN_CHECK, BM_GETCHECK) == 1);
  183. ::Get_Graphic_View ()->Set_Fullscreen (fullscreen);
  184. }
  185. }
  186. return ;
  187. }
  188. /////////////////////////////////////////////////////////////////////////////
  189. //
  190. // OnDblclkResolutionListCtrl
  191. //
  192. /////////////////////////////////////////////////////////////////////////////
  193. void
  194. ResolutionDialogClass::OnDblclkResolutionListCtrl
  195. (
  196. NMHDR * pNMHDR,
  197. LRESULT * pResult
  198. )
  199. {
  200. int list_index = m_ListCtrl.GetNextItem (-1, LVNI_ALL | LVNI_SELECTED);
  201. if (list_index >= 0) {
  202. OnOK ();
  203. }
  204. (*pResult) = 0;
  205. return ;
  206. }