Add menu bar toggle (#1472)

* Add menu bar toggle

* Add menu bar toggle (fix)

* Add menu bar toggle (Alt+Tab fix)
This commit is contained in:
SortAnon
2022-06-18 01:39:33 +02:00
committed by GitHub
parent a0246f639a
commit f212de86dc
3 changed files with 18 additions and 2 deletions
+1
View File
@@ -92,6 +92,7 @@ int InitMainDisplay(int width, int height, const char* title, GfxSettings& setti
lg::error("Failed to make main display.");
return 1;
}
display->set_imgui_visible(true);
set_main_display(display);
return 0;
}
+3
View File
@@ -32,6 +32,7 @@ class GfxDisplay {
GfxDisplayMode m_last_fullscreen_mode;
int m_fullscreen_screen;
int m_fullscreen_target_screen;
bool m_imgui_visible;
protected:
bool m_main;
@@ -65,6 +66,8 @@ class GfxDisplay {
void update_last_fullscreen_mode() { m_last_fullscreen_mode = get_fullscreen(); }
GfxDisplayMode last_fullscreen_mode() const { return m_last_fullscreen_mode; }
int fullscreen_screen() const { return m_fullscreen_screen; }
void set_imgui_visible(bool visible) { m_imgui_visible = visible; }
bool is_imgui_visible() const { return m_imgui_visible; }
bool windowed() { return get_fullscreen() == GfxDisplayMode::Windowed; }
void backup_params();
int width_backup() const { return m_width; }
+14 -2
View File
@@ -74,13 +74,20 @@ std::unique_ptr<GraphicsData> g_gfx_data;
void SetDisplayCallbacks(GLFWwindow* d) {
glfwSetKeyCallback(
d, [](GLFWwindow* /*window*/, int key, int /*scancode*/, int action, int /*mods*/) {
d, [](GLFWwindow* window, int key, int /*scancode*/, int action, int /*mods*/) {
if (action == GlfwKeyAction::Press) {
// lg::debug("KEY PRESS: key: {} scancode: {} mods: {:X}", key, scancode, mods);
Pad::OnKeyPress(key);
} else if (action == GlfwKeyAction::Release) {
// lg::debug("KEY RELEASE: key: {} scancode: {} mods: {:X}", key, scancode, mods);
Pad::OnKeyRelease(key);
GLDisplay* display = reinterpret_cast<GLDisplay*>(glfwGetWindowUserPointer(window));
if (display != NULL) { // toggle ImGui when pressing Alt
if ((key == GLFW_KEY_LEFT_ALT || key == GLFW_KEY_RIGHT_ALT) &&
glfwGetWindowAttrib(window, GLFW_FOCUSED)) {
display->set_imgui_visible(!display->is_imgui_visible());
}
}
}
});
}
@@ -236,9 +243,11 @@ static std::shared_ptr<GfxDisplay> gl_make_display(int width,
GLDisplay::GLDisplay(GLFWwindow* window, bool is_main) : m_window(window) {
m_main = is_main;
glfwSetWindowUserPointer(window, reinterpret_cast<void*>(this));
}
GLDisplay::~GLDisplay() {
glfwSetWindowUserPointer(m_window, nullptr);
ImGui_ImplOpenGL3_Shutdown();
ImGui_ImplGlfw_Shutdown();
ImGui::DestroyContext();
@@ -341,6 +350,7 @@ void GLDisplay::update_fullscreen(GfxDisplayMode mode, int /*screen*/) {
glfwSetWindowAttrib(m_window, GLFW_FLOATING, GLFW_FALSE);
glfwSetWindowMonitor(m_window, NULL, xpos_backup(), ypos_backup(), width_backup(),
height_backup(), GLFW_DONT_CARE);
set_imgui_visible(true);
} break;
case GfxDisplayMode::Fullscreen: {
// fullscreen
@@ -352,6 +362,7 @@ void GLDisplay::update_fullscreen(GfxDisplayMode mode, int /*screen*/) {
glfwSetWindowFocusCallback(m_window, NULL);
glfwSetWindowAttrib(m_window, GLFW_FLOATING, GLFW_FALSE);
glfwSetWindowMonitor(m_window, monitor, 0, 0, vmode->width, vmode->height, 60);
set_imgui_visible(false);
} break;
case GfxDisplayMode::Borderless: {
// borderless fullscreen
@@ -369,6 +380,7 @@ void GLDisplay::update_fullscreen(GfxDisplayMode mode, int /*screen*/) {
#else
glfwSetWindowMonitor(m_window, NULL, x, y, vmode->width, vmode->height, GLFW_DONT_CARE);
#endif
set_imgui_visible(false);
} break;
}
}
@@ -471,7 +483,7 @@ void GLDisplay::render() {
}
// render debug
{
if (is_imgui_visible()) {
auto p = scoped_prof("debug-gui");
g_gfx_data->debug_gui.draw(g_gfx_data->dma_copier.get_last_result().stats);
}