WX: HiDPI: Dolphin Main UI (CFrame)

This commit is contained in:
EmptyChaos
2016-08-14 19:54:01 +00:00
parent 73a20551df
commit 107d4afb08
10 changed files with 169 additions and 203 deletions

View File

@ -2,6 +2,7 @@
// Licensed under GPLv2+
// Refer to the license.txt file included.
#include <array>
#include <cstdarg>
#include <cstdio>
#include <mutex>
@ -77,21 +78,6 @@
#include "VideoCommon/VideoBackendBase.h"
#include "VideoCommon/VideoConfig.h"
#ifdef _WIN32
#ifndef SM_XVIRTUALSCREEN
#define SM_XVIRTUALSCREEN 76
#endif
#ifndef SM_YVIRTUALSCREEN
#define SM_YVIRTUALSCREEN 77
#endif
#ifndef SM_CXVIRTUALSCREEN
#define SM_CXVIRTUALSCREEN 78
#endif
#ifndef SM_CYVIRTUALSCREEN
#define SM_CYVIRTUALSCREEN 79
#endif
#endif
class InputConfig;
class wxFrame;
@ -108,6 +94,11 @@ wxMenuBar* CFrame::GetMenuBar() const
}
}
const wxSize& CFrame::GetToolbarBitmapSize() const
{
return m_toolbar_bitmap_size;
}
// Create menu items
// ---------------------
wxMenuBar* CFrame::CreateMenu()
@ -528,9 +519,6 @@ wxString CFrame::GetMenuLabel(int Id)
// ---------------------
void CFrame::PopulateToolbar(wxToolBar* ToolBar)
{
int w = m_Bitmaps[Toolbar_FileOpen].GetWidth(), h = m_Bitmaps[Toolbar_FileOpen].GetHeight();
ToolBar->SetToolBitmapSize(wxSize(w, h));
WxUtils::AddToolbarButton(ToolBar, wxID_OPEN, _("Open"), m_Bitmaps[Toolbar_FileOpen],
_("Open file..."));
WxUtils::AddToolbarButton(ToolBar, wxID_REFRESH, _("Refresh"), m_Bitmaps[Toolbar_Refresh],
@ -554,7 +542,7 @@ void CFrame::PopulateToolbar(wxToolBar* ToolBar)
// Delete and recreate the toolbar
void CFrame::RecreateToolbar()
{
static const long TOOLBAR_STYLE = wxTB_DEFAULT_STYLE | wxTB_TEXT | wxTB_FLAT;
static constexpr long TOOLBAR_STYLE = wxTB_DEFAULT_STYLE | wxTB_TEXT | wxTB_FLAT;
if (m_ToolBar != nullptr)
{
@ -563,6 +551,7 @@ void CFrame::RecreateToolbar()
}
m_ToolBar = CreateToolBar(TOOLBAR_STYLE, wxID_ANY);
m_ToolBar->SetToolBitmapSize(m_toolbar_bitmap_size);
if (g_pCodeWindow)
{
@ -580,18 +569,11 @@ void CFrame::RecreateToolbar()
void CFrame::InitBitmaps()
{
auto const dir = StrToWxStr(File::GetThemeDir(SConfig::GetInstance().theme_name));
m_Bitmaps[Toolbar_FileOpen].LoadFile(dir + "open.png", wxBITMAP_TYPE_PNG);
m_Bitmaps[Toolbar_Refresh].LoadFile(dir + "refresh.png", wxBITMAP_TYPE_PNG);
m_Bitmaps[Toolbar_Play].LoadFile(dir + "play.png", wxBITMAP_TYPE_PNG);
m_Bitmaps[Toolbar_Stop].LoadFile(dir + "stop.png", wxBITMAP_TYPE_PNG);
m_Bitmaps[Toolbar_Pause].LoadFile(dir + "pause.png", wxBITMAP_TYPE_PNG);
m_Bitmaps[Toolbar_ConfigMain].LoadFile(dir + "config.png", wxBITMAP_TYPE_PNG);
m_Bitmaps[Toolbar_ConfigGFX].LoadFile(dir + "graphics.png", wxBITMAP_TYPE_PNG);
m_Bitmaps[Toolbar_Controller].LoadFile(dir + "classic.png", wxBITMAP_TYPE_PNG);
m_Bitmaps[Toolbar_Screenshot].LoadFile(dir + "screenshot.png", wxBITMAP_TYPE_PNG);
m_Bitmaps[Toolbar_FullScreen].LoadFile(dir + "fullscreen.png", wxBITMAP_TYPE_PNG);
static constexpr std::array<const char* const, EToolbar_Max> s_image_names{
{"open", "refresh", "play", "stop", "pause", "screenshot", "fullscreen", "config", "graphics",
"classic"}};
for (std::size_t i = 0; i < s_image_names.size(); ++i)
m_Bitmaps[i] = WxUtils::LoadScaledThemeBitmap(s_image_names[i], this, m_toolbar_bitmap_size);
// Update in case the bitmap has been updated
if (m_ToolBar != nullptr)
@ -606,7 +588,7 @@ void CFrame::OpenGeneralConfiguration(int tab)
HotkeyManagerEmu::Enable(false);
if (config_main.ShowModal() == wxID_OK)
m_GameListCtrl->Update();
UpdateGameList();
HotkeyManagerEmu::Enable(true);
UpdateGUI();
@ -987,36 +969,29 @@ void CFrame::StartGame(const std::string& filename)
}
else
{
wxPoint position(SConfig::GetInstance().iRenderWindowXPos,
SConfig::GetInstance().iRenderWindowYPos);
#ifdef __APPLE__
// On OS X, the render window's title bar is not visible,
// and the window therefore not easily moved, when the
// position is 0,0. Weed out the 0's from existing configs.
if (position == wxPoint(0, 0))
position = wxDefaultPosition;
#endif
wxRect window_geometry(
SConfig::GetInstance().iRenderWindowXPos, SConfig::GetInstance().iRenderWindowYPos,
SConfig::GetInstance().iRenderWindowWidth, SConfig::GetInstance().iRenderWindowHeight);
// Set window size in framebuffer pixels since the 3D rendering will be operating at
// that level.
wxSize default_size{wxSize(640, 480) * (1.0 / GetContentScaleFactor())};
m_RenderFrame = new CRenderFrame(this, wxID_ANY, _("Dolphin"), wxDefaultPosition, default_size);
// Convert ClientSize coordinates to frame sizes.
wxSize decoration_fudge = m_RenderFrame->GetSize() - m_RenderFrame->GetClientSize();
default_size += decoration_fudge;
if (!window_geometry.IsEmpty())
window_geometry.SetSize(window_geometry.GetSize() + decoration_fudge);
WxUtils::SetWindowSizeAndFitToScreen(m_RenderFrame, window_geometry.GetPosition(),
window_geometry.GetSize(), default_size);
wxSize size(SConfig::GetInstance().iRenderWindowWidth,
SConfig::GetInstance().iRenderWindowHeight);
#ifdef _WIN32
// Out of desktop check
int leftPos = GetSystemMetrics(SM_XVIRTUALSCREEN);
int topPos = GetSystemMetrics(SM_YVIRTUALSCREEN);
int width = GetSystemMetrics(SM_CXVIRTUALSCREEN);
int height = GetSystemMetrics(SM_CYVIRTUALSCREEN);
if ((leftPos + width) < (position.x + size.GetWidth()) || leftPos > position.x ||
(topPos + height) < (position.y + size.GetHeight()) || topPos > position.y)
position.x = position.y = wxDefaultCoord;
#endif
m_RenderFrame = new CRenderFrame((wxFrame*)this, wxID_ANY, _("Dolphin"), position);
if (SConfig::GetInstance().bKeepWindowOnTop)
m_RenderFrame->SetWindowStyle(m_RenderFrame->GetWindowStyle() | wxSTAY_ON_TOP);
else
m_RenderFrame->SetWindowStyle(m_RenderFrame->GetWindowStyle() & ~wxSTAY_ON_TOP);
m_RenderFrame->SetBackgroundColour(*wxBLACK);
m_RenderFrame->SetClientSize(size.GetWidth(), size.GetHeight());
m_RenderFrame->Bind(wxEVT_CLOSE_WINDOW, &CFrame::OnRenderParentClose, this);
m_RenderFrame->Bind(wxEVT_ACTIVATE, &CFrame::OnActive, this);
m_RenderFrame->Bind(wxEVT_MOVE, &CFrame::OnRenderParentMove, this);
@ -1035,7 +1010,7 @@ void CFrame::StartGame(const std::string& filename)
m_RenderFrame->EnableFullScreenView(true);
#endif
wxBeginBusyCursor();
wxBusyCursor hourglass;
DoFullscreen(SConfig::GetInstance().bFullscreen);
@ -1045,6 +1020,7 @@ void CFrame::StartGame(const std::string& filename)
// Destroy the renderer frame when not rendering to main
if (!SConfig::GetInstance().bRenderToMain)
m_RenderFrame->Destroy();
m_RenderFrame = nullptr;
m_RenderParent = nullptr;
m_bGameLoading = false;
UpdateGUI();
@ -1076,8 +1052,6 @@ void CFrame::StartGame(const std::string& filename)
wxTheApp->Bind(wxEVT_KILL_FOCUS, &CFrame::OnFocusChange, this);
m_RenderParent->Bind(wxEVT_SIZE, &CFrame::OnRenderParentResize, this);
}
wxEndBusyCursor();
}
void CFrame::OnBootDrive(wxCommandEvent& event)
@ -1088,10 +1062,7 @@ void CFrame::OnBootDrive(wxCommandEvent& event)
// Refresh the file list and browse for a favorites directory
void CFrame::OnRefresh(wxCommandEvent& WXUNUSED(event))
{
if (m_GameListCtrl)
{
m_GameListCtrl->Update();
}
UpdateGameList();
}
// Create screenshot
@ -1912,7 +1883,8 @@ void CFrame::UpdateGUI()
void CFrame::UpdateGameList()
{
m_GameListCtrl->Update();
if (m_GameListCtrl)
m_GameListCtrl->ReloadList();
}
void CFrame::GameListChanged(wxCommandEvent& event)
@ -1987,11 +1959,7 @@ void CFrame::GameListChanged(wxCommandEvent& event)
break;
}
// Update gamelist
if (m_GameListCtrl)
{
m_GameListCtrl->Update();
}
UpdateGameList();
}
// Enable and disable the toolbar
@ -2047,6 +2015,6 @@ void CFrame::OnChangeColumnsVisible(wxCommandEvent& event)
default:
return;
}
m_GameListCtrl->Update();
UpdateGameList();
SConfig::GetInstance().SaveSettings();
}