From 59e1271259c5fbb94286f1ddc0ea947cdd53c994 Mon Sep 17 00:00:00 2001 From: brunoherbelin Date: Thu, 28 May 2020 00:01:05 +0200 Subject: [PATCH] Bugfix screenshot in userinterface. Minor cosmetics. --- Decorations.cpp | 4 +- Source.cpp | 6 +-- UserInterfaceManager.cpp | 93 +++++++++++++++++++++++++--------------- UserInterfaceManager.h | 5 ++- View.cpp | 5 +++ View.h | 4 ++ 6 files changed, 75 insertions(+), 42 deletions(-) diff --git a/Decorations.cpp b/Decorations.cpp index 24233db..e0b0629 100644 --- a/Decorations.cpp +++ b/Decorations.cpp @@ -181,8 +181,8 @@ void Handles::draw(glm::mat4 modelview, glm::mat4 projection) } else if ( type_ == ROTATE ){ // only once in upper top right corner - glm::vec4 pos = modelview * glm::vec4(1.08f, 1.08f, 0.f, 1.f); - ctm = GlmToolkit::transform(glm::vec3(pos), glm::vec3(0.f), glm::vec3(1.f)); + glm::vec4 pos = modelview * glm::vec4(1.0f, 1.0f, 0.f, 1.f); + ctm = GlmToolkit::transform(glm::vec3(pos) + glm::vec3(0.12f, 0.12f, 0.f), glm::vec3(0.f), glm::vec3(1.f)); handle_->draw( ctm, projection ); } diff --git a/Source.cpp b/Source.cpp index 8d88d0c..4f5fa15 100644 --- a/Source.cpp +++ b/Source.cpp @@ -245,10 +245,10 @@ bool hasNode::operator()(const Source* elem) const elem->group(View::GEOMETRY)->accept(sv); if (sv.found()) return true; - elem->group(View::RENDERING)->accept(sv); - if (sv.found()) - return sv.found(); elem->group(View::LAYER)->accept(sv); + if (sv.found()) + return true; + elem->group(View::RENDERING)->accept(sv); return sv.found(); } diff --git a/UserInterfaceManager.cpp b/UserInterfaceManager.cpp index 6cd762f..623171e 100644 --- a/UserInterfaceManager.cpp +++ b/UserInterfaceManager.cpp @@ -135,6 +135,7 @@ UserInterface::UserInterface() show_gst_about = false; show_opengl_about = false; currentTextEdit = ""; + screenshot_step = 0; } bool UserInterface::Init() @@ -261,7 +262,7 @@ void UserInterface::handleKeyboard() else if (ImGui::IsKeyPressed( GLFW_KEY_F11 )) Rendering::manager().ToggleFullscreen(); else if (ImGui::IsKeyPressed( GLFW_KEY_F12 )) - toolbox.StartScreenshot(); + StartScreenshot(); // normal keys // make sure no entry / window box is active else if ( !ImGui::IsAnyWindowFocused() ){ // Backspace to delete source @@ -295,6 +296,18 @@ void UserInterface::handleMouse() if ( !ImGui::IsAnyWindowHovered() && !ImGui::IsAnyWindowFocused() ) { ImGui::FocusWindow(0); + Source *current = Mixer::manager().currentSource(); + +// if (current) +// { +// glm::vec3 point = Rendering::manager().unProject(mousepos); +// PickingVisitor over(point); +// Mixer::manager().currentView()->scene.accept(over); +// // drag current source +// int c = Mixer::manager().currentView()->over(mousepos, current, over.picked().back()); +// ImGui::SetMouseCursor(c); +// } + // // Mouse wheel over background // @@ -302,6 +315,8 @@ void UserInterface::handleMouse() // scroll => zoom current view Mixer::manager().currentView()->zoom( io.MouseWheel ); } + // TODO : zoom with center on source if over current + // // RIGHT Mouse button // @@ -331,7 +346,6 @@ void UserInterface::handleMouse() // if ( ImGui::IsMouseDragging(ImGuiMouseButton_Left, 10.0f) ) { - Source *current = Mixer::manager().currentSource(); if (current) { // drag current source @@ -363,7 +377,9 @@ void UserInterface::handleMouse() if (pv.picked().empty()) Mixer::manager().unsetCurrentSource(); else { + // top-most Node picked pick = pv.picked().back(); + // find source containing the cliced Node Mixer::manager().setCurrentSource( pick.first ); } @@ -393,6 +409,7 @@ void UserInterface::NewFrame() // deal with keyboard and mouse events handleKeyboard(); handleMouse(); + handleScreenshot(); // handle FileDialog if (sessionFileDialogLoadFinished_) { @@ -536,16 +553,51 @@ ToolBox::ToolBox() { show_demo_window = false; show_icons_window = false; - screenshot_step = 0; } -void ToolBox::StartScreenshot() +void UserInterface::StartScreenshot() { screenshot_step = 1; } +void UserInterface::handleScreenshot() +{ + // taking screenshot is in 3 steps + // 1) wait 1 frame that the menu / action showing button to take screenshot disapears + // 2) wait 1 frame that rendering manager takes the actual screenshot + // 3) if rendering manager current screenshot is ok, save it + if (screenshot_step > 0) { + + switch(screenshot_step) { + case 1: + screenshot_step = 2; + break; + case 2: + Rendering::manager().RequestScreenshot(); + screenshot_step = 3; + break; + case 3: + { + if ( Rendering::manager().CurrentScreenshot()->IsFull() ){ + std::string filename = SystemToolkit::home_path() + SystemToolkit::date_time_string() + "_vmixcapture.png"; + Rendering::manager().CurrentScreenshot()->SaveFile( filename.c_str() ); + Rendering::manager().CurrentScreenshot()->Clear(); + Log::Notify("Screenshot saved %s", filename.c_str() ); + } + screenshot_step = 4; + } + break; + default: + screenshot_step = 0; + break; + } + + } +} + + void ToolBox::Render() { // first run @@ -564,7 +616,7 @@ void ToolBox::Render() if (ImGui::BeginMenu("Tools")) { if ( ImGui::MenuItem( ICON_FA_CAMERA_RETRO " Screenshot", NULL) ) - StartScreenshot(); + UserInterface::manager().StartScreenshot(); ImGui::MenuItem("Dev", NULL, false, false); ImGui::MenuItem("Icons", NULL, &show_icons_window); @@ -584,36 +636,7 @@ void ToolBox::Render() if (show_demo_window) ImGui::ShowDemoWindow(&show_demo_window); - // taking screenshot is in 3 steps - // 1) wait 1 frame that the menu / action showing button to take screenshot disapears - // 2) wait 1 frame that rendering manager takes the actual screenshot - // 3) if rendering manager current screenshot is ok, save it - if (screenshot_step > 0) { - - switch(screenshot_step) { - case 1: - screenshot_step = 2; - break; - case 2: - Rendering::manager().RequestScreenshot(); - screenshot_step = 3; - break; - case 3: - { - if ( Rendering::manager().CurrentScreenshot()->IsFull() ){ - std::string filename = SystemToolkit::date_time_string() + "_vmixcapture.png"; - Rendering::manager().CurrentScreenshot()->SaveFile( filename.c_str() ); - Rendering::manager().CurrentScreenshot()->Clear(); - } - screenshot_step = 4; - } - break; - default: - screenshot_step = 0; - break; - } - - } + } diff --git a/UserInterfaceManager.h b/UserInterfaceManager.h index e66a647..4646b66 100644 --- a/UserInterfaceManager.h +++ b/UserInterfaceManager.h @@ -67,12 +67,10 @@ class ToolBox { bool show_demo_window; bool show_icons_window; - unsigned int screenshot_step; public: ToolBox(); - void StartScreenshot(); void Render(); }; @@ -88,6 +86,7 @@ class UserInterface bool show_imgui_about; bool show_gst_about; bool show_opengl_about; + unsigned int screenshot_step; // typedef enum { @@ -125,6 +124,7 @@ public: // status querries inline bool keyboardModifier() { return keyboard_modifier_active; } + void StartScreenshot(); // TODO implement the shader editor std::string currentTextEdit; @@ -138,6 +138,7 @@ protected: void RenderShaderEditor(); void handleKeyboard(); void handleMouse(); + void handleScreenshot(); }; diff --git a/View.cpp b/View.cpp index be32750..f89adab 100644 --- a/View.cpp +++ b/View.cpp @@ -359,6 +359,11 @@ View::Cursor GeometryView::grab (glm::vec2 from, glm::vec2 to, Source *s, std::p return ret; } +View::Cursor GeometryView::over (glm::vec2, Source*, std::pair) +{ + +} + LayerView::LayerView() : View(LAYER), aspect_ratio(1.f) { // read default settings diff --git a/View.h b/View.h index d14b43b..2b97270 100644 --- a/View.h +++ b/View.h @@ -38,6 +38,9 @@ public: virtual Cursor grab (glm::vec2, glm::vec2, Source*, std::pair) { return Cursor_Arrow; } + virtual Cursor over (glm::vec2, Source*, std::pair) { + return Cursor_Arrow; + } virtual void restoreSettings(); virtual void saveSettings(); @@ -88,6 +91,7 @@ public: void update (float dt) override; void zoom (float factor) override; Cursor grab (glm::vec2 from, glm::vec2 to, Source *s, std::pair pick) override; + Cursor over (glm::vec2, Source*, std::pair) override; };