Преглед на файлове

Tiny Player can be fullscreen now.

jcsyshc преди 1 година
родител
ревизия
835d1d9077

+ 4 - 2
src/impl/apps/app_selector/app_selector.cpp

@@ -54,12 +54,14 @@ void app_selector::load_app(const std::string &conf_path) {
         app = std::make_unique<app_tiny_player>(create_conf);
     }
 
+    // change window title
+    auto window = glfwGetCurrentContext();
+    glfwSetWindowTitle(window, app->window_name());
+
     // replace application
     assert(app != nullptr);
     auto app_ptr = conf.app_ptr;
-    auto window = conf.window;
     post(*conf.asio_ctx, [=, app = std::move(app)]() mutable {
-        glfwSetWindowTitle(window, app->window_name());
         *app_ptr = std::move(app);
     });
 }

+ 0 - 3
src/impl/apps/app_selector/app_selector.h

@@ -5,15 +5,12 @@
 
 #include <ImGuiFileDialog.h>
 
-class GLFWwindow;
-
 class app_selector : public app_base {
 public:
 
     using base_config = app_base::create_config;
     struct create_config : base_config {
         std::unique_ptr<app_base> *app_ptr = nullptr;
-        GLFWwindow *window = nullptr;
     };
 
     explicit app_selector(const create_config &conf);

+ 78 - 1
src/impl/apps/tiny_player/tiny_player.cpp

@@ -1,4 +1,7 @@
 #include "tiny_player.h"
+#include "core/imgui_utility.hpp"
+
+#include <GLFW/glfw3.h>
 
 app_tiny_player::app_tiny_player(const create_config &_conf) {
     conf = _conf;
@@ -23,8 +26,82 @@ app_tiny_player::app_tiny_player(const create_config &_conf) {
     bg_viewer = std::make_unique<image_viewer>(bg_viewer_conf);
 }
 
+void app_tiny_player::recorde_window_info() {
+    auto win = glfwGetCurrentContext();
+    glfwGetWindowPos(win, &win_info.x_pos, &win_info.y_pos);
+    glfwGetWindowSize(win, &win_info.width, &win_info.height);
+}
+
+void app_tiny_player::update_display() {
+    auto win = glfwGetCurrentContext();
+    if (!full_screen) {
+        glfwSetWindowMonitor(win, nullptr, win_info.x_pos, win_info.y_pos,
+                             win_info.width, win_info.height, GLFW_DONT_CARE);
+    } else {
+        assert(full_screen);
+        int monitor_num = 0;
+        auto monitors = glfwGetMonitors(&monitor_num);
+        assert(chose_monitor < monitor_num);
+        auto monitor = monitors[chose_monitor];
+        auto mode = glfwGetVideoMode(monitor);
+        glfwSetWindowMonitor(win, monitor, 0, 0, mode->width, mode->height, mode->refreshRate);
+    }
+}
+
+void app_tiny_player::show_display_configs() {
+    // display mode
+    if (ImGui::RadioButton("Windowed", !full_screen)) {
+        if (full_screen) {
+            full_screen = false;
+            update_display();
+        }
+    }
+    ImGui::SameLine();
+    if (ImGui::RadioButton("Full Screen", full_screen)) {
+        if (!full_screen) {
+            recorde_window_info();
+            full_screen = true;
+            update_display();
+        }
+    }
+
+    if (full_screen) {
+        int monitor_count;
+        auto monitors = glfwGetMonitors(&monitor_count);
+        if (chose_monitor >= monitor_count) {
+            chose_monitor = 0;
+        }
+        auto monitor_name_preview = glfwGetMonitorName(monitors[chose_monitor]);
+        if (ImGui::BeginCombo("Monitor", monitor_name_preview)) { // let user select monitors
+            for (int k = 0; k < monitor_count; ++k) {
+                auto is_selected = (chose_monitor == k);
+                auto monitor_name = fmt::format("{} - {}", k, glfwGetMonitorName(monitors[k]));
+                if (ImGui::Selectable(monitor_name.c_str(), is_selected)) {
+                    if (chose_monitor != k) {
+                        chose_monitor = k;
+                        update_display();
+                    }
+                }
+                if (is_selected) {
+                    ImGui::SetItemDefaultFocus();
+                }
+            }
+            ImGui::EndCombo();
+        }
+    }
+}
+
 void app_tiny_player::show_ui() {
-    in_player->show();
+    if (ImGui::Begin("Tiny Player Control")) {
+        ImGui::PushItemWidth(200);
+        in_player->show();
+
+        ImGui::SeparatorText("Display Configs");
+        show_display_configs();
+
+        ImGui::PopItemWidth();
+    }
+    ImGui::End();
 }
 
 void app_tiny_player::render_background() {

+ 14 - 0
src/impl/apps/tiny_player/tiny_player.h

@@ -29,6 +29,20 @@ private:
     std::unique_ptr<image_viewer> bg_viewer; // background viewer
     std::unique_ptr<image_player> in_player; // input player
 
+    bool full_screen = false;
+    int chose_monitor = 0;
+
+    struct {
+        int x_pos, y_pos;
+        int width, height;
+    } win_info; // windowed mode info
+
+    void recorde_window_info();
+
+    void update_display();
+
+    void show_display_configs();
+
 };
 
 

+ 15 - 2
src/impl/main_impl.cpp

@@ -33,6 +33,8 @@ std::chrono::milliseconds ui_interval;
 
 std::unique_ptr<app_base> app;
 
+bool hide_app_ui = false;
+
 void init_cuda() {
     cuInit(0);
 
@@ -125,7 +127,6 @@ void init_all() {
     app_conf.asio_ctx = main_ctx;
     app_conf.cuda_ctx = &cuda_ctx;
     app_conf.app_ptr = &app;
-    app_conf.window = window;
     app = std::make_unique<app_selector>(app_conf);
 
     glfwSetWindowTitle(window, app->window_name());
@@ -134,6 +135,15 @@ void init_all() {
     ui_timer->async_wait(ui_timer_func);
 }
 
+void process_keys() {
+    auto &io = ImGui::GetIO();
+    if (io.WantCaptureKeyboard) return;
+
+    if (io.KeyCtrl && ImGui::IsKeyPressed(ImGuiKey_H)) { // Ctrl+H
+        hide_app_ui ^= true;
+    }
+}
+
 void show_ui() {
     glfwPollEvents();
     ImGui_ImplOpenGL3_NewFrame();
@@ -145,9 +155,12 @@ void show_ui() {
         main_ctx->stop();
         return;
     }
+    process_keys();
 
     assert(app != nullptr);
-    app->show_ui();
+    if (!hide_app_ui) {
+        app->show_ui();
+    }
     ImGui::Render();
 
     cv::Size frame_size;