Upload UI
[lsnes.git] / src / platform / wxwidgets / editor-sounddev.cpp
blobe41b264a3efc6265f32c0a3f52da4c8eed6be3c7
1 #include "core/window.hpp"
2 #include "core/audioapi.hpp"
4 #include "platform/wxwidgets/platform.hpp"
6 #include <wx/wx.h>
7 #include <wx/event.h>
8 #include <wx/control.h>
9 #include <wx/combobox.h>
11 class wxeditor_sounddev : public wxDialog
13 public:
14 wxeditor_sounddev(wxWindow* parent);
15 bool ShouldPreventAppExit() const;
16 void on_cancel(wxCommandEvent& e);
17 void on_ok(wxCommandEvent& e);
18 private:
19 wxComboBox* rdev;
20 wxComboBox* pdev;
21 wxButton* okbutton;
22 wxButton* cancel;
25 wxeditor_sounddev::wxeditor_sounddev(wxWindow* parent)
26 : wxDialog(parent, wxID_ANY, wxT("lsnes: Choose sound device"), wxDefaultPosition, wxSize(-1, -1))
28 Centre();
29 wxFlexGridSizer* top_s = new wxFlexGridSizer(2, 1, 0, 0);
30 SetSizer(top_s);
32 auto pdev_map = audioapi_driver_get_devices(false);
33 auto rdev_map = audioapi_driver_get_devices(true);
34 std::string current_pdev = pdev_map[audioapi_driver_get_device(false)];
35 std::string current_rdev = rdev_map[audioapi_driver_get_device(true)];
36 std::vector<wxString> available_pdevs;
37 std::vector<wxString> available_rdevs;
38 for(auto i : pdev_map)
39 available_pdevs.push_back(towxstring(i.second));
40 for(auto i : rdev_map)
41 available_rdevs.push_back(towxstring(i.second));
43 wxFlexGridSizer* c_s = new wxFlexGridSizer(2, 2, 0, 0);
44 c_s->Add(new wxStaticText(this, wxID_ANY, wxT("Input device:")), 0, wxGROW);
45 c_s->Add(rdev = new wxComboBox(this, wxID_ANY, towxstring(current_rdev), wxDefaultPosition,
46 wxSize(400, -1), available_rdevs.size(), &available_rdevs[0], wxCB_READONLY), 1, wxGROW);
47 c_s->Add(new wxStaticText(this, wxID_ANY, wxT("Output device:")), 0, wxGROW);
48 c_s->Add(pdev = new wxComboBox(this, wxID_ANY, towxstring(current_pdev), wxDefaultPosition,
49 wxSize(400, -1), available_pdevs.size(), &available_pdevs[0], wxCB_READONLY), 1, wxGROW);
50 top_s->Add(c_s);
52 if(available_pdevs.size() < 2)
53 pdev->Disable();
54 if(available_rdevs.size() < 2)
55 rdev->Disable();
57 wxBoxSizer* pbutton_s = new wxBoxSizer(wxHORIZONTAL);
58 pbutton_s->AddStretchSpacer();
59 pbutton_s->Add(okbutton = new wxButton(this, wxID_OK, wxT("OK")), 0, wxGROW);
60 pbutton_s->Add(cancel = new wxButton(this, wxID_CANCEL, wxT("Cancel")), 0, wxGROW);
61 okbutton->Connect(wxEVT_COMMAND_BUTTON_CLICKED,
62 wxCommandEventHandler(wxeditor_sounddev::on_ok), NULL, this);
63 cancel->Connect(wxEVT_COMMAND_BUTTON_CLICKED,
64 wxCommandEventHandler(wxeditor_sounddev::on_cancel), NULL, this);
65 top_s->Add(pbutton_s, 0, wxGROW);
67 c_s->SetSizeHints(this);
68 top_s->SetSizeHints(this);
69 Fit();
72 bool wxeditor_sounddev::ShouldPreventAppExit() const
74 return false;
77 void wxeditor_sounddev::on_cancel(wxCommandEvent& e)
79 EndModal(wxID_CANCEL);
82 void wxeditor_sounddev::on_ok(wxCommandEvent& e)
84 std::string newpdev = tostdstring(pdev->GetValue());
85 std::string newrdev = tostdstring(rdev->GetValue());
86 std::string _newpdev = "null";
87 std::string _newrdev = "null";
88 for(auto i : audioapi_driver_get_devices(false))
89 if(i.second == newpdev)
90 _newpdev = i.first;
91 for(auto i : audioapi_driver_get_devices(true))
92 if(i.second == newrdev)
93 _newrdev = i.first;
94 platform::set_sound_device(_newpdev, _newrdev);
95 EndModal(wxID_OK);
98 void wxeditor_sounddev_display(wxWindow* parent)
100 modal_pause_holder hld;
101 wxDialog* editor;
102 try {
103 editor = new wxeditor_sounddev(parent);
104 editor->ShowModal();
105 } catch(...) {
107 editor->Destroy();