From 06cce2fcbf4cb51d85860c5015d91fd52c3968aa Mon Sep 17 00:00:00 2001 From: Kai Yan Date: Mon, 20 Feb 2023 16:02:06 +0800 Subject: [PATCH 1/4] Added SetFullScreen to GUI::Window and GLFWWindowSystem --- .../visualization/gui/GLFWWindowSystem.cpp | 17 +++++++++++++++++ cpp/open3d/visualization/gui/GLFWWindowSystem.h | 7 +++++++ cpp/open3d/visualization/gui/Window.cpp | 6 ++++++ cpp/open3d/visualization/gui/Window.h | 2 ++ cpp/open3d/visualization/gui/WindowSystem.h | 3 +++ 5 files changed, 35 insertions(+) diff --git a/cpp/open3d/visualization/gui/GLFWWindowSystem.cpp b/cpp/open3d/visualization/gui/GLFWWindowSystem.cpp index f5f5cb8ada8..86652db3c8c 100644 --- a/cpp/open3d/visualization/gui/GLFWWindowSystem.cpp +++ b/cpp/open3d/visualization/gui/GLFWWindowSystem.cpp @@ -565,6 +565,23 @@ MenuBase* GLFWWindowSystem::CreateOSMenu() { #endif } +void GLFWWindowSystem::SetFullScreen(OSWindow w, bool bFullScreen) +{ + if (!bFullScreen) { + glfwSetWindowMonitor((GLFWwindow*)w, + NULL, + winX,winY, + winW,winH, + GLFW_DONT_CARE); + } else { + glfwGetWindowSize((GLFWwindow*)w, &winW, &winH); + glfwGetWindowPos((GLFWwindow*)w, &winX, &winY); + GLFWmonitor *monitor = glfwGetPrimaryMonitor(); + const GLFWvidmode *mode = glfwGetVideoMode(monitor); + glfwSetWindowMonitor((GLFWwindow*)w, monitor, 0, 0, mode->width, mode->height, mode->refreshRate); + } +} + } // namespace gui } // namespace visualization } // namespace open3d diff --git a/cpp/open3d/visualization/gui/GLFWWindowSystem.h b/cpp/open3d/visualization/gui/GLFWWindowSystem.h index 93aa172296f..20e8c228ce9 100644 --- a/cpp/open3d/visualization/gui/GLFWWindowSystem.h +++ b/cpp/open3d/visualization/gui/GLFWWindowSystem.h @@ -88,6 +88,8 @@ class GLFWWindowSystem : public WindowSystem { rendering::FilamentRenderer* renderer) override; MenuBase* CreateOSMenu() override; + + void SetFullScreen(OSWindow w, bool bFullScreen) override; private: static void DrawCallback(GLFWwindow* window); @@ -105,6 +107,11 @@ class GLFWWindowSystem : public WindowSystem { static void CharCallback(GLFWwindow* window, unsigned int utf32char); static void DragDropCallback(GLFWwindow*, int count, const char* paths[]); static void CloseCallback(GLFWwindow* window); + + int winW; + int winH; + int winX; + int winY; }; } // namespace gui diff --git a/cpp/open3d/visualization/gui/Window.cpp b/cpp/open3d/visualization/gui/Window.cpp index c521178da64..14b60b079b5 100644 --- a/cpp/open3d/visualization/gui/Window.cpp +++ b/cpp/open3d/visualization/gui/Window.cpp @@ -695,6 +695,12 @@ void Window::ShowMenu(bool show) { SetNeedsLayout(); } +void Window::SetFullScreen(bool bFullScreen) +{ + auto& ws = Application::GetInstance().GetWindowSystem(); + ws.SetFullScreen(GetOSWindow(), bFullScreen); +} + LayoutContext Window::GetLayoutContext() { return {GetTheme(), impl_->imgui_}; } void Window::Layout(const LayoutContext& context) { diff --git a/cpp/open3d/visualization/gui/Window.h b/cpp/open3d/visualization/gui/Window.h index fa65c4d5e9b..41b48b51f6d 100644 --- a/cpp/open3d/visualization/gui/Window.h +++ b/cpp/open3d/visualization/gui/Window.h @@ -180,6 +180,8 @@ class Window { /// use. Returns "window_undefined" if the window system is not /// WebRTCWindowSystem. std::string GetWebRTCUID() const; + + void SetFullScreen(bool bFullScreen); protected: /// Returns the preferred size of the window. The window is not diff --git a/cpp/open3d/visualization/gui/WindowSystem.h b/cpp/open3d/visualization/gui/WindowSystem.h index dd88bf6215a..b32ef179949 100644 --- a/cpp/open3d/visualization/gui/WindowSystem.h +++ b/cpp/open3d/visualization/gui/WindowSystem.h @@ -104,6 +104,9 @@ class WindowSystem { rendering::FilamentRenderer* renderer) = 0; virtual MenuBase* CreateOSMenu() = 0; + + virtual void SetFullScreen(OSWindow w, bool bFullScreen) = 0; + }; } // namespace gui From e22ba858ff8dc92ba4b0fe2e8b3b75407f49a46b Mon Sep 17 00:00:00 2001 From: Sameer Sheorey Date: Tue, 26 Dec 2023 14:41:41 -0800 Subject: [PATCH 2/4] Ad python binding, no-op for BitmapWindowSystem, rename vars for style. --- .../visualization/gui/BitmapWindowSystem.h | 3 +++ .../visualization/gui/GLFWWindowSystem.cpp | 21 ++++++++----------- .../visualization/gui/GLFWWindowSystem.h | 12 +++++------ cpp/pybind/visualization/gui/gui.cpp | 3 +++ 4 files changed, 21 insertions(+), 18 deletions(-) diff --git a/cpp/open3d/visualization/gui/BitmapWindowSystem.h b/cpp/open3d/visualization/gui/BitmapWindowSystem.h index 9ad1e8aadc4..36aef67869e 100644 --- a/cpp/open3d/visualization/gui/BitmapWindowSystem.h +++ b/cpp/open3d/visualization/gui/BitmapWindowSystem.h @@ -111,6 +111,9 @@ class BitmapWindowSystem : public WindowSystem { MenuBase* CreateOSMenu() override; + /// SetFullScreen is a no-op + void SetFullScreen(OSWindow, bool) override{}; + private: struct Impl; std::unique_ptr impl_; diff --git a/cpp/open3d/visualization/gui/GLFWWindowSystem.cpp b/cpp/open3d/visualization/gui/GLFWWindowSystem.cpp index 86652db3c8c..857762ebca8 100644 --- a/cpp/open3d/visualization/gui/GLFWWindowSystem.cpp +++ b/cpp/open3d/visualization/gui/GLFWWindowSystem.cpp @@ -565,20 +565,17 @@ MenuBase* GLFWWindowSystem::CreateOSMenu() { #endif } -void GLFWWindowSystem::SetFullScreen(OSWindow w, bool bFullScreen) -{ +void GLFWWindowSystem::SetFullScreen(OSWindow w, bool bFullScreen) { if (!bFullScreen) { - glfwSetWindowMonitor((GLFWwindow*)w, - NULL, - winX,winY, - winW,winH, - GLFW_DONT_CARE); + glfwSetWindowMonitor((GLFWwindow*)w, NULL, win_x_, win_y_, win_width_, + win_height_, GLFW_DONT_CARE); } else { - glfwGetWindowSize((GLFWwindow*)w, &winW, &winH); - glfwGetWindowPos((GLFWwindow*)w, &winX, &winY); - GLFWmonitor *monitor = glfwGetPrimaryMonitor(); - const GLFWvidmode *mode = glfwGetVideoMode(monitor); - glfwSetWindowMonitor((GLFWwindow*)w, monitor, 0, 0, mode->width, mode->height, mode->refreshRate); + glfwGetWindowSize((GLFWwindow*)w, &win_width_, &win_height_); + glfwGetWindowPos((GLFWwindow*)w, &win_x_, &win_y_); + GLFWmonitor* monitor = glfwGetPrimaryMonitor(); + const GLFWvidmode* mode = glfwGetVideoMode(monitor); + glfwSetWindowMonitor((GLFWwindow*)w, monitor, 0, 0, mode->width, + mode->height, mode->refreshRate); } } diff --git a/cpp/open3d/visualization/gui/GLFWWindowSystem.h b/cpp/open3d/visualization/gui/GLFWWindowSystem.h index 20e8c228ce9..1073e2269c1 100644 --- a/cpp/open3d/visualization/gui/GLFWWindowSystem.h +++ b/cpp/open3d/visualization/gui/GLFWWindowSystem.h @@ -88,7 +88,7 @@ class GLFWWindowSystem : public WindowSystem { rendering::FilamentRenderer* renderer) override; MenuBase* CreateOSMenu() override; - + void SetFullScreen(OSWindow w, bool bFullScreen) override; private: @@ -107,11 +107,11 @@ class GLFWWindowSystem : public WindowSystem { static void CharCallback(GLFWwindow* window, unsigned int utf32char); static void DragDropCallback(GLFWwindow*, int count, const char* paths[]); static void CloseCallback(GLFWwindow* window); - - int winW; - int winH; - int winX; - int winY; + + int win_width_; + int win_height_; + int win_x_; + int win_y_; }; } // namespace gui diff --git a/cpp/pybind/visualization/gui/gui.cpp b/cpp/pybind/visualization/gui/gui.cpp index b0d5b5fd759..f87022f1486 100644 --- a/cpp/pybind/visualization/gui/gui.cpp +++ b/cpp/pybind/visualization/gui/gui.cpp @@ -503,6 +503,9 @@ void pybind_gui_classes(py::module &m) { "show_menu(show): shows or hides the menu in the window, " "except on macOS since the menubar is not in the window " "and all applications must have a menubar.") + .def("set_full_screen", &PyWindow::SetFullScreen, + "Make the window fullscreen or reset to previous state.", + "fullscreen"_a = true) .def_property_readonly( "renderer", &PyWindow::GetRenderer, "Gets the rendering.Renderer object for the Window"); From 4003d8c4cf217b233d32c223846ac412a3210ca1 Mon Sep 17 00:00:00 2001 From: Sameer Sheorey Date: Tue, 26 Dec 2023 15:06:46 -0800 Subject: [PATCH 3/4] Add full screen mode to vis_gui.py macOS crash when enabling full screen. --- examples/python/visualization/vis_gui.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/examples/python/visualization/vis_gui.py b/examples/python/visualization/vis_gui.py index 3cf28e29684..07a6110a443 100644 --- a/examples/python/visualization/vis_gui.py +++ b/examples/python/visualization/vis_gui.py @@ -279,6 +279,11 @@ def __init__(self, width, height): h.add_stretch() view_ctrls.add_child(h) + self._fullscreen = gui.Checkbox("Fullscreen") + self._fullscreen.set_on_checked(w.set_full_screen) + view_ctrls.add_fixed(separation_height) + view_ctrls.add_child(self._fullscreen) + self._show_skybox = gui.Checkbox("Show skymap") self._show_skybox.set_on_checked(self._on_show_skybox) view_ctrls.add_fixed(separation_height) From a8863a07533cdd519d9080cb3d59ad38b5cb901d Mon Sep 17 00:00:00 2001 From: Sameer Sheorey Date: Tue, 26 Dec 2023 15:11:03 -0800 Subject: [PATCH 4/4] style fix --- cpp/open3d/visualization/gui/Window.cpp | 3 +-- cpp/open3d/visualization/gui/Window.h | 2 +- cpp/open3d/visualization/gui/WindowSystem.h | 3 +-- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/cpp/open3d/visualization/gui/Window.cpp b/cpp/open3d/visualization/gui/Window.cpp index 93e1c1d1d94..2952272e082 100644 --- a/cpp/open3d/visualization/gui/Window.cpp +++ b/cpp/open3d/visualization/gui/Window.cpp @@ -676,8 +676,7 @@ void Window::ShowMenu(bool show) { SetNeedsLayout(); } -void Window::SetFullScreen(bool bFullScreen) -{ +void Window::SetFullScreen(bool bFullScreen) { auto& ws = Application::GetInstance().GetWindowSystem(); ws.SetFullScreen(GetOSWindow(), bFullScreen); } diff --git a/cpp/open3d/visualization/gui/Window.h b/cpp/open3d/visualization/gui/Window.h index a0811f9b014..656e2936aca 100644 --- a/cpp/open3d/visualization/gui/Window.h +++ b/cpp/open3d/visualization/gui/Window.h @@ -161,7 +161,7 @@ class Window { /// use. Returns "window_undefined" if the window system is not /// WebRTCWindowSystem. std::string GetWebRTCUID() const; - + void SetFullScreen(bool bFullScreen); protected: diff --git a/cpp/open3d/visualization/gui/WindowSystem.h b/cpp/open3d/visualization/gui/WindowSystem.h index 624cf509d1b..ab01b0b8108 100644 --- a/cpp/open3d/visualization/gui/WindowSystem.h +++ b/cpp/open3d/visualization/gui/WindowSystem.h @@ -85,9 +85,8 @@ class WindowSystem { rendering::FilamentRenderer* renderer) = 0; virtual MenuBase* CreateOSMenu() = 0; - + virtual void SetFullScreen(OSWindow w, bool bFullScreen) = 0; - }; } // namespace gui