VideoConfigDiag.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. // Copyright 2010 Dolphin Emulator Project
  2. // Licensed under GPLv2+
  3. // Refer to the license.txt file included.
  4. #pragma once
  5. #include <cstddef>
  6. #include <map>
  7. #include <string>
  8. #include <vector>
  9. #include <wx/button.h>
  10. #include <wx/checkbox.h>
  11. #include <wx/choice.h>
  12. #include <wx/dialog.h>
  13. #include <wx/msgdlg.h>
  14. #include <wx/radiobut.h>
  15. #include <wx/spinctrl.h>
  16. #include <wx/stattext.h>
  17. #include "Common/CommonTypes.h"
  18. #include "Common/SysConf.h"
  19. #include "Core/ConfigManager.h"
  20. #include "Core/Core.h"
  21. #include "Core/CoreParameter.h"
  22. #include "DolphinWX/PostProcessingConfigDiag.h"
  23. #include "DolphinWX/WxUtils.h"
  24. #include "VideoCommon/PostProcessing.h"
  25. #include "VideoCommon/VideoBackendBase.h"
  26. #include "VideoCommon/VideoConfig.h"
  27. class wxBoxSizer;
  28. class wxControl;
  29. class wxPanel;
  30. template <typename W>
  31. class BoolSetting : public W
  32. {
  33. public:
  34. BoolSetting(wxWindow* parent, const wxString& label, const wxString& tooltip, bool &setting, bool reverse = false, long style = 0);
  35. void UpdateValue(wxCommandEvent& ev)
  36. {
  37. m_setting = (ev.GetInt() != 0) ^ m_reverse;
  38. ev.Skip();
  39. }
  40. private:
  41. bool &m_setting;
  42. const bool m_reverse;
  43. };
  44. typedef BoolSetting<wxCheckBox> SettingCheckBox;
  45. typedef BoolSetting<wxRadioButton> SettingRadioButton;
  46. template <typename T>
  47. class IntegerSetting : public wxSpinCtrl
  48. {
  49. public:
  50. IntegerSetting(wxWindow* parent, const wxString& label, T& setting, int minVal, int maxVal, long style = 0);
  51. void UpdateValue(wxCommandEvent& ev)
  52. {
  53. m_setting = ev.GetInt();
  54. ev.Skip();
  55. }
  56. private:
  57. T& m_setting;
  58. };
  59. typedef IntegerSetting<u32> U32Setting;
  60. class SettingChoice : public wxChoice
  61. {
  62. public:
  63. SettingChoice(wxWindow* parent, int &setting, const wxString& tooltip, int num = 0, const wxString choices[] = nullptr, long style = 0);
  64. void UpdateValue(wxCommandEvent& ev);
  65. private:
  66. int &m_setting;
  67. };
  68. class VideoConfigDiag : public wxDialog
  69. {
  70. public:
  71. VideoConfigDiag(wxWindow* parent, const std::string &title, const std::string& ininame);
  72. protected:
  73. void Event_Backend(wxCommandEvent &ev)
  74. {
  75. VideoBackend* new_backend = g_available_video_backends[ev.GetInt()];
  76. if (g_video_backend != new_backend)
  77. {
  78. bool do_switch = !Core::IsRunning();
  79. if (new_backend->GetName() == "Software Renderer")
  80. {
  81. do_switch = (wxYES == wxMessageBox(_("Software rendering is an order of magnitude slower than using the other backends.\nIt's only useful for debugging purposes.\nDo you really want to enable software rendering? If unsure, select 'No'."),
  82. _("Warning"), wxYES_NO | wxNO_DEFAULT | wxICON_EXCLAMATION, wxWindow::FindFocus()));
  83. }
  84. if (do_switch)
  85. {
  86. // TODO: Only reopen the dialog if the software backend is
  87. // selected (make sure to reinitialize backend info)
  88. // reopen the dialog
  89. Close();
  90. g_video_backend = new_backend;
  91. SConfig::GetInstance().m_LocalCoreStartupParameter.m_strVideoBackend = g_video_backend->GetName();
  92. g_video_backend->ShowConfig(GetParent());
  93. }
  94. else
  95. {
  96. // Select current backend again
  97. choice_backend->SetStringSelection(StrToWxStr(g_video_backend->GetName()));
  98. }
  99. }
  100. ev.Skip();
  101. }
  102. void Event_Adapter(wxCommandEvent &ev) { ev.Skip(); } // TODO
  103. void Event_DisplayResolution(wxCommandEvent &ev);
  104. void Event_ProgressiveScan(wxCommandEvent &ev)
  105. {
  106. SConfig::GetInstance().m_SYSCONF->SetData("IPL.PGS", ev.GetInt());
  107. SConfig::GetInstance().m_LocalCoreStartupParameter.bProgressive = ev.IsChecked();
  108. ev.Skip();
  109. }
  110. void Event_Stc(wxCommandEvent &ev)
  111. {
  112. int samples[] = { 0, 512, 128 };
  113. vconfig.iSafeTextureCache_ColorSamples = samples[ev.GetInt()];
  114. ev.Skip();
  115. }
  116. void Event_PPShader(wxCommandEvent &ev)
  117. {
  118. const int sel = ev.GetInt();
  119. if (sel)
  120. vconfig.sPostProcessingShader = WxStrToStr(ev.GetString());
  121. else
  122. vconfig.sPostProcessingShader.clear();
  123. // Should we enable the configuration button?
  124. PostProcessingShaderConfiguration postprocessing_shader;
  125. postprocessing_shader.LoadShader(vconfig.sPostProcessingShader);
  126. button_config_pp->Enable(postprocessing_shader.HasOptions());
  127. ev.Skip();
  128. }
  129. void Event_ConfigurePPShader(wxCommandEvent &ev)
  130. {
  131. PostProcessingConfigDiag dialog(this, vconfig.sPostProcessingShader);
  132. dialog.ShowModal();
  133. ev.Skip();
  134. }
  135. void Event_StereoDepth(wxCommandEvent &ev)
  136. {
  137. vconfig.iStereoDepth = ev.GetInt();
  138. ev.Skip();
  139. }
  140. void Event_StereoConvergence(wxCommandEvent &ev)
  141. {
  142. vconfig.iStereoConvergence = ev.GetInt();
  143. ev.Skip();
  144. }
  145. void Event_StereoMode(wxCommandEvent &ev)
  146. {
  147. if (vconfig.backend_info.bSupportsPostProcessing)
  148. {
  149. // Anaglyph overrides post-processing shaders
  150. choice_ppshader->Clear();
  151. }
  152. ev.Skip();
  153. }
  154. void Event_ClickClose(wxCommandEvent&);
  155. void Event_Close(wxCloseEvent&);
  156. // Enables/disables UI elements depending on current config
  157. void OnUpdateUI(wxUpdateUIEvent& ev)
  158. {
  159. // Anti-aliasing
  160. choice_aamode->Enable(vconfig.backend_info.AAModes.size() > 1);
  161. text_aamode->Enable(vconfig.backend_info.AAModes.size() > 1);
  162. // XFB
  163. virtual_xfb->Enable(vconfig.bUseXFB);
  164. real_xfb->Enable(vconfig.bUseXFB);
  165. // custom textures
  166. cache_hires_textures->Enable(vconfig.bHiresTextures);
  167. // Repopulating the post-processing shaders can't be done from an event
  168. if (choice_ppshader && choice_ppshader->IsEmpty())
  169. PopulatePostProcessingShaders();
  170. // Things which shouldn't be changed during emulation
  171. if (Core::IsRunning())
  172. {
  173. choice_backend->Disable();
  174. label_backend->Disable();
  175. // D3D only
  176. if (vconfig.backend_info.Adapters.size())
  177. {
  178. choice_adapter->Disable();
  179. label_adapter->Disable();
  180. }
  181. #ifndef __APPLE__
  182. // This isn't supported on OS X.
  183. choice_display_resolution->Disable();
  184. label_display_resolution->Disable();
  185. #endif
  186. progressive_scan_checkbox->Disable();
  187. render_to_main_checkbox->Disable();
  188. }
  189. ev.Skip();
  190. }
  191. // Creates controls and connects their enter/leave window events to Evt_Enter/LeaveControl
  192. SettingCheckBox* CreateCheckBox(wxWindow* parent, const wxString& label, const wxString& description, bool &setting, bool reverse = false, long style = 0);
  193. SettingChoice* CreateChoice(wxWindow* parent, int& setting, const wxString& description, int num = 0, const wxString choices[] = nullptr, long style = 0);
  194. SettingRadioButton* CreateRadioButton(wxWindow* parent, const wxString& label, const wxString& description, bool &setting, bool reverse = false, long style = 0);
  195. // Same as above but only connects enter/leave window events
  196. wxControl* RegisterControl(wxControl* const control, const wxString& description);
  197. void Evt_EnterControl(wxMouseEvent& ev);
  198. void Evt_LeaveControl(wxMouseEvent& ev);
  199. void CreateDescriptionArea(wxPanel* const page, wxBoxSizer* const sizer);
  200. void PopulatePostProcessingShaders();
  201. wxChoice* choice_backend;
  202. wxChoice* choice_adapter;
  203. wxChoice* choice_display_resolution;
  204. wxStaticText* label_backend;
  205. wxStaticText* label_adapter;
  206. wxStaticText* text_aamode;
  207. SettingChoice* choice_aamode;
  208. wxStaticText* label_display_resolution;
  209. wxButton* button_config_pp;
  210. SettingCheckBox* borderless_fullscreen;
  211. SettingCheckBox* render_to_main_checkbox;
  212. SettingRadioButton* virtual_xfb;
  213. SettingRadioButton* real_xfb;
  214. SettingCheckBox* cache_hires_textures;
  215. wxCheckBox* progressive_scan_checkbox;
  216. wxChoice* choice_ppshader;
  217. std::map<wxWindow*, wxString> ctrl_descs; // maps setting controls to their descriptions
  218. std::map<wxWindow*, wxStaticText*> desc_texts; // maps dialog tabs (which are the parents of the setting controls) to their description text objects
  219. VideoConfig &vconfig;
  220. std::string ininame;
  221. };