From 3bd8a47dae034f06380048e4c85f68b4452ebcbe Mon Sep 17 00:00:00 2001 From: Andrew Belt Date: Thu, 7 Jun 2018 09:37:14 -0400 Subject: [PATCH] Toggle full screen with F11 --- include/events.hpp | 1 + include/window.hpp | 2 ++ src/app/RackScene.cpp | 3 +++ src/widgets/Widget.cpp | 7 +++---- src/window.cpp | 23 +++++++++++++++++++++++ 5 files changed, 32 insertions(+), 4 deletions(-) diff --git a/include/events.hpp b/include/events.hpp index 48a6bedb..8b5ceafa 100644 --- a/include/events.hpp +++ b/include/events.hpp @@ -28,6 +28,7 @@ struct EventMouseDown : EventPosition { }; struct EventMouseUp : EventPosition { + /** 0 for left mouse button, 1 for right, 2 for middle */ int button; Widget *target = NULL; }; diff --git a/include/window.hpp b/include/window.hpp index 116088a9..4becb35a 100644 --- a/include/window.hpp +++ b/include/window.hpp @@ -45,6 +45,8 @@ Vec windowGetWindowPos(); void windowSetWindowPos(Vec pos); bool windowIsMaximized(); void windowSetTheme(NVGcolor bg, NVGcolor fg); +void windowSetFullScreen(bool fullScreen); +bool windowGetFullScreen(); } // namespace rack diff --git a/src/app/RackScene.cpp b/src/app/RackScene.cpp index 6448705f..2ebc9657 100644 --- a/src/app/RackScene.cpp +++ b/src/app/RackScene.cpp @@ -84,6 +84,9 @@ void RackScene::onHoverKey(EventHoverKey &e) { appModuleBrowserCreate(); e.consumed = true; } break; + case GLFW_KEY_F11: { + windowSetFullScreen(!windowGetFullScreen()); + } } } } diff --git a/src/widgets/Widget.cpp b/src/widgets/Widget.cpp index 935d44d5..9f5ffd3e 100644 --- a/src/widgets/Widget.cpp +++ b/src/widgets/Widget.cpp @@ -62,10 +62,9 @@ void Widget::addChild(Widget *widget) { void Widget::removeChild(Widget *widget) { assert(widget->parent == this); auto it = std::find(children.begin(), children.end(), widget); - if (it != children.end()) { - children.erase(it); - widget->parent = NULL; - } + assert(it != children.end()); + children.erase(it); + widget->parent = NULL; } void Widget::clearChildren() { diff --git a/src/window.cpp b/src/window.cpp index 986ba294..bfba3a99 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -607,6 +607,29 @@ void windowSetTheme(NVGcolor bg, NVGcolor fg) { bndSetTheme(t); } +static int windowX = 0; +static int windowY = 0; +static int windowWidth = 0; +static int windowHeight = 0; + +void windowSetFullScreen(bool fullScreen) { + if (windowGetFullScreen()) { + glfwSetWindowMonitor(gWindow, NULL, windowX, windowY, windowWidth, windowHeight, GLFW_DONT_CARE); + } + else { + glfwGetWindowPos(gWindow, &windowX, &windowY); + glfwGetWindowSize(gWindow, &windowWidth, &windowHeight); + GLFWmonitor *monitor = glfwGetPrimaryMonitor(); + const GLFWvidmode* mode = glfwGetVideoMode(monitor); + glfwSetWindowMonitor(gWindow, monitor, 0, 0, mode->width, mode->height, mode->refreshRate); + } +} + +bool windowGetFullScreen() { + GLFWmonitor *monitor = glfwGetWindowMonitor(gWindow); + return monitor != NULL; +} + //////////////////// // resources