diff options
| author | shuffle2 <godisgovernment@gmail.com> | 2016-10-03 20:06:08 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2016-10-03 20:06:08 -0700 |
| commit | b8731eb8180d76b4663eaf4188f985b9c5fa6fb2 (patch) | |
| tree | 40f57e85be3073d528e9e5a5776a905170a3a7ac /Source/Core/DolphinWX/NetPlay/NetWindow.cpp | |
| parent | 4573cc89fa65a867f991c1e592ad47382f1ee0a5 (diff) | |
| parent | c4f5ced37ca9eff6a5c62c08f1cc7a9e6dc47f7d (diff) | |
Merge pull request #4068 from EmptyChaos/wx-hidpi
WX: Comprehensive HiDPI Patch
Diffstat (limited to 'Source/Core/DolphinWX/NetPlay/NetWindow.cpp')
| -rw-r--r-- | Source/Core/DolphinWX/NetPlay/NetWindow.cpp | 194 |
1 files changed, 131 insertions, 63 deletions
diff --git a/Source/Core/DolphinWX/NetPlay/NetWindow.cpp b/Source/Core/DolphinWX/NetPlay/NetWindow.cpp index 18dabd91e2..90f60e3c1b 100644 --- a/Source/Core/DolphinWX/NetPlay/NetWindow.cpp +++ b/Source/Core/DolphinWX/NetPlay/NetWindow.cpp @@ -4,6 +4,7 @@ #include <algorithm> #include <cstddef> +#include <limits> #include <sstream> #include <string> #include <tuple> @@ -21,6 +22,7 @@ #include <wx/panel.h> #include <wx/sizer.h> #include <wx/spinctrl.h> +#include <wx/statbox.h> #include <wx/stattext.h> #include <wx/string.h> #include <wx/textctrl.h> @@ -67,12 +69,52 @@ NetPlayDialog::NetPlayDialog(wxWindow* const parent, const CGameListCtrl* const m_host_copy_btn_is_retry(false), m_is_hosting(is_hosting), m_game_list(game_list) { Bind(wxEVT_THREAD, &NetPlayDialog::OnThread, this); + CreateGUI(); + SetIcons(WxUtils::GetDolphinIconBundle()); + Center(); + // Remember the window size and position for NetWindow + { + IniFile inifile; + inifile.Load(File::GetUserPath(F_DOLPHINCONFIG_IDX)); + IniFile::Section& netplay_section = *inifile.GetOrCreateSection("NetPlay"); + + int winPosX, winPosY, winWidth, winHeight; + netplay_section.Get("NetWindowPosX", &winPosX, std::numeric_limits<int>::min()); + netplay_section.Get("NetWindowPosY", &winPosY, std::numeric_limits<int>::min()); + netplay_section.Get("NetWindowWidth", &winWidth, -1); + netplay_section.Get("NetWindowHeight", &winHeight, -1); + + WxUtils::SetWindowSizeAndFitToScreen(this, wxPoint(winPosX, winPosY), + wxSize(winWidth, winHeight), GetSize()); + } +} + +void NetPlayDialog::CreateGUI() +{ + const int space5 = FromDIP(5); + + // NOTE: The design operates top down. Margins / padding are handled by the outermost + // sizers, this makes the design easier to change. Inner sizers should only pad between + // widgets, they should never have prepended or appended margins/spacers. wxPanel* const panel = new wxPanel(this); + wxBoxSizer* const main_szr = new wxBoxSizer(wxVERTICAL); + main_szr->AddSpacer(space5); + main_szr->Add(CreateTopGUI(panel), 0, wxEXPAND | wxLEFT | wxRIGHT, space5); + main_szr->AddSpacer(space5); + main_szr->Add(CreateMiddleGUI(panel), 1, wxEXPAND | wxLEFT | wxRIGHT, space5); + main_szr->AddSpacer(space5); + main_szr->Add(CreateBottomGUI(panel), 0, wxEXPAND | wxLEFT | wxRIGHT, space5); + main_szr->AddSpacer(space5); - wxBoxSizer* const top_szr = new wxBoxSizer(wxHORIZONTAL); + panel->SetSizerAndFit(main_szr); + main_szr->SetSizeHints(this); + SetSize(FromDIP(wxSize(768, 768 - 128))); +} - m_game_btn = new wxButton(panel, wxID_ANY, StrToWxStr(m_selected_game).Prepend(_(" Game : ")), +wxSizer* NetPlayDialog::CreateTopGUI(wxWindow* parent) +{ + m_game_btn = new wxButton(parent, wxID_ANY, _(" Game : ") + StrToWxStr(m_selected_game), wxDefaultPosition, wxDefaultSize, wxBU_LEFT); if (m_is_hosting) @@ -80,11 +122,12 @@ NetPlayDialog::NetPlayDialog(wxWindow* const parent, const CGameListCtrl* const else m_game_btn->Disable(); - top_szr->Add(m_game_btn, 1, wxALL | wxEXPAND); + wxBoxSizer* top_szr = new wxBoxSizer(wxHORIZONTAL); + top_szr->Add(m_game_btn, 1, wxEXPAND); if (m_is_hosting) { - m_MD5_choice = new wxChoice(panel, wxID_ANY, wxDefaultPosition, wxSize(150, -1)); + m_MD5_choice = new wxChoice(parent, wxID_ANY, wxDefaultPosition, FromDIP(wxSize(150, -1))); m_MD5_choice->Bind(wxEVT_CHOICE, &NetPlayDialog::OnMD5ComputeRequested, this); m_MD5_choice->Append(_("MD5 check...")); m_MD5_choice->Append(_("Current game")); @@ -92,59 +135,89 @@ NetPlayDialog::NetPlayDialog(wxWindow* const parent, const CGameListCtrl* const m_MD5_choice->Append(_("SD card")); m_MD5_choice->SetSelection(0); - top_szr->Add(m_MD5_choice, 0, wxALL); + top_szr->Add(m_MD5_choice, 0, wxALIGN_CENTER_VERTICAL); } - // middle crap + return top_szr; +} - // chat - m_chat_text = new wxTextCtrl(panel, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, +wxSizer* NetPlayDialog::CreateMiddleGUI(wxWindow* parent) +{ + const int space5 = FromDIP(5); + + wxBoxSizer* const mid_szr = new wxBoxSizer(wxHORIZONTAL); + mid_szr->Add(CreateChatGUI(parent), 1, wxEXPAND); + mid_szr->Add(CreatePlayerListGUI(parent), 0, wxEXPAND | wxLEFT, space5); + return mid_szr; +} + +wxSizer* NetPlayDialog::CreateChatGUI(wxWindow* parent) +{ + const int space5 = FromDIP(5); + + wxStaticBoxSizer* const chat_szr = new wxStaticBoxSizer(wxVERTICAL, parent, _("Chat")); + parent = chat_szr->GetStaticBox(); + + m_chat_text = new wxTextCtrl(parent, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_READONLY | wxTE_MULTILINE); - m_chat_msg_text = new wxTextCtrl(panel, wxID_ANY, wxEmptyString, wxDefaultPosition, - wxSize(-1, 25), wxTE_PROCESS_ENTER); + m_chat_msg_text = new wxTextCtrl(parent, wxID_ANY, wxEmptyString, wxDefaultPosition, + wxDefaultSize, wxTE_PROCESS_ENTER); m_chat_msg_text->Bind(wxEVT_TEXT_ENTER, &NetPlayDialog::OnChat, this); m_chat_msg_text->SetMaxLength(2000); wxButton* const chat_msg_btn = - new wxButton(panel, wxID_ANY, _("Send"), wxDefaultPosition, wxSize(-1, 26)); + new wxButton(parent, wxID_ANY, _("Send"), wxDefaultPosition, + wxSize(-1, m_chat_msg_text->GetBestSize().GetHeight())); chat_msg_btn->Bind(wxEVT_BUTTON, &NetPlayDialog::OnChat, this); wxBoxSizer* const chat_msg_szr = new wxBoxSizer(wxHORIZONTAL); - chat_msg_szr->Add(m_chat_msg_text, 1); - chat_msg_szr->Add(chat_msg_btn, 0); + // NOTE: Remember that fonts are configurable, setting sizes of anything that contains + // text in pixels is dangerous because the text may end up being clipped. + chat_msg_szr->Add(WxUtils::GiveMinSizeDIP(m_chat_msg_text, wxSize(-1, 25)), 1, + wxALIGN_CENTER_VERTICAL); + chat_msg_szr->Add(chat_msg_btn, 0, wxEXPAND); - wxStaticBoxSizer* const chat_szr = new wxStaticBoxSizer(wxVERTICAL, panel, _("Chat")); chat_szr->Add(m_chat_text, 1, wxEXPAND); - chat_szr->Add(chat_msg_szr, 0, wxEXPAND | wxTOP, 5); + chat_szr->Add(chat_msg_szr, 0, wxEXPAND | wxTOP, space5); + return chat_szr; +} - m_player_lbox = new wxListBox(panel, wxID_ANY, wxDefaultPosition, wxSize(256, -1)); +wxSizer* NetPlayDialog::CreatePlayerListGUI(wxWindow* parent) +{ + const int space5 = FromDIP(5); - wxStaticBoxSizer* const player_szr = new wxStaticBoxSizer(wxVERTICAL, panel, _("Players")); + wxStaticBoxSizer* const player_szr = new wxStaticBoxSizer(wxVERTICAL, parent, _("Players")); + // Static box is a widget, new widgets should be children instead of siblings to avoid various + // flickering problems. + parent = player_szr->GetStaticBox(); + + m_player_lbox = new wxListBox(parent, wxID_ANY, wxDefaultPosition, FromDIP(wxSize(256, -1)), 0, + nullptr, wxLB_HSCROLL); - // player list if (m_is_hosting && g_TraversalClient) { - wxBoxSizer* const host_szr = new wxBoxSizer(wxHORIZONTAL); - m_host_type_choice = new wxChoice(panel, wxID_ANY, wxDefaultPosition, wxSize(76, -1)); + m_host_type_choice = new wxChoice(parent, wxID_ANY, wxDefaultPosition, FromDIP(wxSize(76, -1))); m_host_type_choice->Bind(wxEVT_CHOICE, &NetPlayDialog::OnChoice, this); m_host_type_choice->Append(_("Room ID:")); - host_szr->Add(m_host_type_choice); + m_host_type_choice->Select(0); - m_host_label = new wxStaticText(panel, wxID_ANY, "555.555.555.555:55555", wxDefaultPosition, - wxDefaultSize, wxST_NO_AUTORESIZE | wxALIGN_LEFT); + m_host_label = new wxStaticText(parent, wxID_ANY, "555.555.555.555:55555", wxDefaultPosition, + wxDefaultSize, wxST_NO_AUTORESIZE); // Update() should fix this immediately. m_host_label->SetLabel(""); - host_szr->Add(m_host_label, 1, wxLEFT | wxCENTER, 5); - m_host_copy_btn = new wxButton(panel, wxID_ANY, _("Copy")); + m_host_copy_btn = new wxButton(parent, wxID_ANY, _("Copy")); m_host_copy_btn->Bind(wxEVT_BUTTON, &NetPlayDialog::OnCopyIP, this); m_host_copy_btn->Disable(); - host_szr->Add(m_host_copy_btn, 0, wxLEFT | wxCENTER, 5); - player_szr->Add(host_szr, 0, wxEXPAND | wxBOTTOM, 5); - m_host_type_choice->Select(0); UpdateHostLabel(); + + wxBoxSizer* const host_szr = new wxBoxSizer(wxHORIZONTAL); + host_szr->Add(m_host_type_choice); + host_szr->Add(m_host_label, 1, wxALIGN_CENTER_VERTICAL | wxLEFT, space5); + host_szr->Add(m_host_copy_btn, 0, wxALIGN_CENTER_VERTICAL | wxLEFT, space5); + player_szr->Add(host_szr, 0, wxEXPAND, space5); } player_szr->Add(m_player_lbox, 1, wxEXPAND); @@ -152,59 +225,54 @@ NetPlayDialog::NetPlayDialog(wxWindow* const parent, const CGameListCtrl* const if (m_is_hosting) { m_player_lbox->Bind(wxEVT_LISTBOX, &NetPlayDialog::OnPlayerSelect, this); - m_kick_btn = new wxButton(panel, wxID_ANY, _("Kick Player")); + m_kick_btn = new wxButton(parent, wxID_ANY, _("Kick Player")); m_kick_btn->Bind(wxEVT_BUTTON, &NetPlayDialog::OnKick, this); - player_szr->Add(m_kick_btn, 0, wxEXPAND | wxTOP, 5); m_kick_btn->Disable(); - m_player_config_btn = new wxButton(panel, wxID_ANY, _("Assign Controller Ports")); + m_player_config_btn = new wxButton(parent, wxID_ANY, _("Assign Controller Ports")); m_player_config_btn->Bind(wxEVT_BUTTON, &NetPlayDialog::OnAssignPads, this); - player_szr->Add(m_player_config_btn, 0, wxEXPAND | wxTOP, 5); - } - wxBoxSizer* const mid_szr = new wxBoxSizer(wxHORIZONTAL); - mid_szr->Add(chat_szr, 1, wxEXPAND | wxRIGHT, 5); - mid_szr->Add(player_szr, 0, wxEXPAND); + player_szr->Add(m_kick_btn, 0, wxEXPAND | wxTOP, space5); + player_szr->Add(m_player_config_btn, 0, wxEXPAND | wxTOP, space5); + } + return player_szr; +} - // bottom crap - wxButton* const quit_btn = new wxButton(panel, wxID_ANY, _("Quit Netplay")); - quit_btn->Bind(wxEVT_BUTTON, &NetPlayDialog::OnQuit, this); +wxSizer* NetPlayDialog::CreateBottomGUI(wxWindow* parent) +{ + const int space5 = FromDIP(5); wxBoxSizer* const bottom_szr = new wxBoxSizer(wxHORIZONTAL); - if (is_hosting) + if (m_is_hosting) { - m_start_btn = new wxButton(panel, wxID_ANY, _("Start")); + m_start_btn = new wxButton(parent, wxID_ANY, _("Start")); m_start_btn->Bind(wxEVT_BUTTON, &NetPlayDialog::OnStart, this); - bottom_szr->Add(m_start_btn); - bottom_szr->Add(new wxStaticText(panel, wxID_ANY, _("Buffer:")), 0, wxLEFT | wxCENTER, 5); + wxStaticText* buffer_lbl = new wxStaticText(parent, wxID_ANY, _("Buffer:")); wxSpinCtrl* const padbuf_spin = - new wxSpinCtrl(panel, wxID_ANY, std::to_string(INITIAL_PAD_BUFFER_SIZE), wxDefaultPosition, - wxSize(64, -1), wxSP_ARROW_KEYS, 0, 200, INITIAL_PAD_BUFFER_SIZE); + new wxSpinCtrl(parent, wxID_ANY, std::to_string(INITIAL_PAD_BUFFER_SIZE), wxDefaultPosition, + wxDefaultSize, wxSP_ARROW_KEYS, 0, 200, INITIAL_PAD_BUFFER_SIZE); padbuf_spin->Bind(wxEVT_SPINCTRL, &NetPlayDialog::OnAdjustBuffer, this); - bottom_szr->AddSpacer(3); - bottom_szr->Add(padbuf_spin, 0, wxCENTER); - bottom_szr->AddSpacer(5); - m_memcard_write = new wxCheckBox(panel, wxID_ANY, _("Write to memcards/SD")); - bottom_szr->Add(m_memcard_write, 0, wxCENTER); - } + padbuf_spin->SetMinSize(WxUtils::GetTextWidgetMinSize(padbuf_spin)); - bottom_szr->AddSpacer(5); - m_record_chkbox = new wxCheckBox(panel, wxID_ANY, _("Record inputs")); - bottom_szr->Add(m_record_chkbox, 0, wxCENTER); + m_memcard_write = new wxCheckBox(parent, wxID_ANY, _("Write to memcards/SD")); - bottom_szr->AddStretchSpacer(1); - bottom_szr->Add(quit_btn); + bottom_szr->Add(m_start_btn, 0, wxALIGN_CENTER_VERTICAL); + bottom_szr->Add(buffer_lbl, 0, wxALIGN_CENTER_VERTICAL | wxLEFT, space5); + bottom_szr->Add(padbuf_spin, 0, wxALIGN_CENTER_VERTICAL | wxLEFT, space5); + bottom_szr->Add(m_memcard_write, 0, wxALIGN_CENTER_VERTICAL | wxLEFT, space5); + bottom_szr->AddSpacer(space5); + } - // main sizer - wxBoxSizer* const main_szr = new wxBoxSizer(wxVERTICAL); - main_szr->Add(top_szr, 0, wxEXPAND | wxALL, 5); - main_szr->Add(mid_szr, 1, wxEXPAND | wxLEFT | wxRIGHT, 5); - main_szr->Add(bottom_szr, 0, wxEXPAND | wxALL, 5); + m_record_chkbox = new wxCheckBox(parent, wxID_ANY, _("Record inputs")); - panel->SetSizerAndFit(main_szr); + wxButton* quit_btn = new wxButton(parent, wxID_ANY, _("Quit Netplay")); + quit_btn->Bind(wxEVT_BUTTON, &NetPlayDialog::OnQuit, this); - main_szr->SetSizeHints(this); + bottom_szr->Add(m_record_chkbox, 0, wxALIGN_CENTER_VERTICAL); + bottom_szr->AddStretchSpacer(); + bottom_szr->Add(quit_btn); + return bottom_szr; } NetPlayDialog::~NetPlayDialog() |
