Fix zero luma corner case
[lsnes.git] / src / plat-wxwidgets / authorseditor.cpp
blob812e004f229d44d49404920fae9d2c65a8993343
1 #include "core/moviedata.hpp"
3 #include "plat-wxwidgets/authorseditor.hpp"
4 #include "plat-wxwidgets/common.hpp"
6 wx_authors_editor::wx_authors_editor(wxWindow* parent)
7 : wxDialog(parent, wxID_ANY, wxT("lsnes: Edit game name & authors"), wxDefaultPosition, wxSize(-1, -1))
9 Centre();
10 wxFlexGridSizer* top_s = new wxFlexGridSizer(4, 1, 0, 0);
11 SetSizer(top_s);
13 wxFlexGridSizer* c_s = new wxFlexGridSizer(1, 2, 0, 0);
14 c_s->Add(new wxStaticText(this, wxID_ANY, wxT("Game name:")), 0, wxGROW);
15 c_s->Add(projectname = new wxTextCtrl(this, wxID_ANY, wxT(""), wxDefaultPosition, wxSize(400, -1)), 1, wxGROW);
16 top_s->Add(c_s);
18 top_s->Add(new wxStaticText(this, wxID_ANY, wxT("Authors (one per line):")), 0, wxGROW);
19 top_s->Add(authors = new wxTextCtrl(this, wxID_ANY, wxT(""), wxDefaultPosition, wxDefaultSize,
20 wxTE_MULTILINE), 0, wxGROW);
21 authors->Connect(wxEVT_COMMAND_TEXT_UPDATED,
22 wxCommandEventHandler(wx_authors_editor::on_authors_change), NULL, this);
24 wxBoxSizer* pbutton_s = new wxBoxSizer(wxHORIZONTAL);
25 pbutton_s->AddStretchSpacer();
26 pbutton_s->Add(okbutton = new wxButton(this, wxID_OK, wxT("OK")), 0, wxGROW);
27 pbutton_s->Add(cancel = new wxButton(this, wxID_CANCEL, wxT("Cancel")), 0, wxGROW);
28 okbutton->Connect(wxEVT_COMMAND_BUTTON_CLICKED,
29 wxCommandEventHandler(wx_authors_editor::on_ok), NULL, this);
30 cancel->Connect(wxEVT_COMMAND_BUTTON_CLICKED,
31 wxCommandEventHandler(wx_authors_editor::on_cancel), NULL, this);
32 top_s->Add(pbutton_s, 0, wxGROW);
34 c_s->SetSizeHints(this);
35 top_s->SetSizeHints(this);
36 Fit();
38 projectname->SetValue(towxstring(our_movie.gamename));
39 std::string x;
40 for(auto i : our_movie.authors)
41 x = x + i.first + "|" + i.second + "\n";
42 authors->SetValue(towxstring(x));
45 bool wx_authors_editor::ShouldPreventAppExit() const
47 return false;
50 void wx_authors_editor::on_authors_change(wxCommandEvent& e)
52 try {
53 size_t lines = authors->GetNumberOfLines();
54 for(size_t i = 0; i < lines; i++) {
55 std::string l = tostdstring(authors->GetLineText(i));
56 if(l == "|")
57 throw 43;
59 okbutton->Enable();
60 } catch(...) {
61 okbutton->Disable();
65 void wx_authors_editor::on_cancel(wxCommandEvent& e)
67 EndModal(wxID_CANCEL);
70 void wx_authors_editor::on_ok(wxCommandEvent& e)
72 our_movie.gamename = tostdstring(projectname->GetValue());
73 std::vector<std::pair<std::string, std::string>> newauthors;
74 size_t lines = authors->GetNumberOfLines();
75 for(size_t i = 0; i < lines; i++) {
76 std::string l = tostdstring(authors->GetLineText(i));
77 if(l != "" && l != "|")
78 newauthors.push_back(split_author(l));
80 our_movie.authors = newauthors;
81 EndModal(wxID_OK);