bool DolphinApp::OnInit() { std::lock_guard<std::mutex> lk(s_init_mutex); if (!wxApp::OnInit()) return false; Bind(wxEVT_QUERY_END_SESSION, &DolphinApp::OnEndSession, this); Bind(wxEVT_END_SESSION, &DolphinApp::OnEndSession, this); Bind(wxEVT_IDLE, &DolphinApp::OnIdle, this); Bind(wxEVT_ACTIVATE_APP, &DolphinApp::OnActivate, this); // Register message box and translation handlers RegisterMsgAlertHandler(&wxMsgAlert); RegisterStringTranslator(&wxStringTranslator); #if wxUSE_ON_FATAL_EXCEPTION wxHandleFatalExceptions(true); #endif UICommon::SetUserDirectory(m_user_path.ToStdString()); UICommon::CreateDirectories(); InitLanguageSupport(); // The language setting is loaded from the user directory UICommon::Init(); if (m_select_video_backend && !m_video_backend_name.empty()) SConfig::GetInstance().m_strVideoBackend = WxStrToStr(m_video_backend_name); if (m_select_audio_emulation) SConfig::GetInstance().bDSPHLE = (m_audio_emulation_name.Upper() == "HLE"); VideoBackendBase::ActivateBackend(SConfig::GetInstance().m_strVideoBackend); DolphinAnalytics::Instance()->ReportDolphinStart("wx"); wxToolTip::Enable(!SConfig::GetInstance().m_DisableTooltips); // Enable the PNG image handler for screenshots wxImage::AddHandler(new wxPNGHandler); // We have to copy the size and position out of SConfig now because CFrame's OnMove // handler will corrupt them during window creation (various APIs like SetMenuBar cause // event dispatch including WM_MOVE/WM_SIZE) wxRect window_geometry(SConfig::GetInstance().iPosX, SConfig::GetInstance().iPosY, SConfig::GetInstance().iWidth, SConfig::GetInstance().iHeight); main_frame = new CFrame(nullptr, wxID_ANY, StrToWxStr(scm_rev_str), window_geometry, m_use_debugger, m_batch_mode, m_use_logger); SetTopWindow(main_frame); AfterInit(); return true; }
// Prepare the GUI to start the game. void CFrame::StartGame(const std::string& filename) { if (m_bGameLoading) return; m_bGameLoading = true; GetToolBar()->EnableTool(IDM_PLAY, false); GetMenuBar()->FindItem(IDM_PLAY)->Enable(false); if (SConfig::GetInstance().bRenderToMain) { // Game has been started, hide the game list m_GameListCtrl->Disable(); m_GameListCtrl->Hide(); m_RenderParent = m_Panel; m_RenderFrame = this; if (SConfig::GetInstance().bKeepWindowOnTop) m_RenderFrame->SetWindowStyle(m_RenderFrame->GetWindowStyle() | wxSTAY_ON_TOP); else m_RenderFrame->SetWindowStyle(m_RenderFrame->GetWindowStyle() & ~wxSTAY_ON_TOP); // No, I really don't want TAB_TRAVERSAL being set behind my back, // thanks. (Note that calling DisableSelfFocus would prevent this flag // from being set for new children, but wouldn't reset the existing // flag.) m_RenderParent->SetWindowStyle(m_RenderParent->GetWindowStyle() & ~wxTAB_TRAVERSAL); } else { 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); 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->Bind(wxEVT_CLOSE_WINDOW, &CFrame::OnRenderParentClose, this); m_RenderFrame->Bind(wxEVT_ACTIVATE, &CFrame::OnActive, this); m_RenderFrame->Bind(wxEVT_MOVE, &CFrame::OnRenderParentMove, this); #ifdef _WIN32 // The renderer should use a top-level window for exclusive fullscreen support. m_RenderParent = m_RenderFrame; #else // To capture key events on Linux and Mac OS X the frame needs at least one child. m_RenderParent = new wxPanel(m_RenderFrame, IDM_MPANEL, wxDefaultPosition, wxDefaultSize, 0); #endif m_RenderFrame->Show(); } #if defined(__APPLE__) m_RenderFrame->EnableFullScreenView(true); #endif wxBusyCursor hourglass; DoFullscreen(SConfig::GetInstance().bFullscreen); if (!BootManager::BootCore(filename)) { DoFullscreen(false); // 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(); } else { #if defined(HAVE_X11) && HAVE_X11 if (SConfig::GetInstance().bDisableScreenSaver) X11Utils::InhibitScreensaver(X11Utils::XDisplayFromHandle(GetHandle()), X11Utils::XWindowFromHandle(GetHandle()), true); #endif #ifdef _WIN32 // Prevents Windows from sleeping, turning off the display, or idling EXECUTION_STATE shouldScreenSave = SConfig::GetInstance().bDisableScreenSaver ? ES_DISPLAY_REQUIRED : 0; SetThreadExecutionState(ES_CONTINUOUS | shouldScreenSave | ES_SYSTEM_REQUIRED); #endif m_RenderParent->SetFocus(); wxTheApp->Bind(wxEVT_KEY_DOWN, &CFrame::OnKeyDown, this); wxTheApp->Bind(wxEVT_RIGHT_DOWN, &CFrame::OnMouse, this); wxTheApp->Bind(wxEVT_RIGHT_UP, &CFrame::OnMouse, this); wxTheApp->Bind(wxEVT_MIDDLE_DOWN, &CFrame::OnMouse, this); wxTheApp->Bind(wxEVT_MIDDLE_UP, &CFrame::OnMouse, this); wxTheApp->Bind(wxEVT_MOTION, &CFrame::OnMouse, this); m_RenderParent->Bind(wxEVT_SIZE, &CFrame::OnRenderParentResize, this); } }