From e52785a8b4e3ab56eb29e3edf14c0dee88f7da15 Mon Sep 17 00:00:00 2001 From: Bruno Herbelin Date: Sun, 16 Jan 2022 17:47:43 +0100 Subject: [PATCH] Cleanup UI for source info, cleanup code --- CloneSource.cpp | 7 +++---- ImGuiVisitor.cpp | 36 ++++++++++++++++++++++++++++++++---- InfoVisitor.cpp | 39 +++++++++++++++++++++------------------ RenderSource.cpp | 6 +++--- Session.cpp | 2 +- SessionSource.cpp | 3 ++- SessionVisitor.cpp | 30 ++++++++++++++++-------------- 7 files changed, 78 insertions(+), 45 deletions(-) diff --git a/CloneSource.cpp b/CloneSource.cpp index 12c9786..ffb5963 100644 --- a/CloneSource.cpp +++ b/CloneSource.cpp @@ -141,7 +141,9 @@ void CloneSource::setActive (bool on) void CloneSource::update(float dt) { - if (active_ && !paused_ && origin_ && cloningsurface_ != nullptr) { + Source::update(dt); + + if (!paused_ && origin_ && cloningsurface_ != nullptr) { double now = g_timer_elapsed (timer_, NULL) ; @@ -179,10 +181,7 @@ void CloneSource::update(float dt) // update the source surface to be rendered texturesurface_->setTextureIndex( stack_[read_index_]->texture() ); - } - - Source::update(dt); } diff --git a/ImGuiVisitor.cpp b/ImGuiVisitor.cpp index 9c76b52..7f3175a 100644 --- a/ImGuiVisitor.cpp +++ b/ImGuiVisitor.cpp @@ -702,10 +702,23 @@ void ImGuiVisitor::visit (RenderSource& s) ImGuiToolkit::Icon(s.icon().x, s.icon().y); ImGui::SameLine(0, IMGUI_SAME_LINE); ImGui::Text("Rendering Output"); - if ( ImGui::Button(ICON_FA_DESKTOP " Show window", ImVec2(IMGUI_RIGHT_ALIGN, 0)) ) + + // info + ImGui::PushTextWrapPos(ImGui::GetCursorPos().x + ImGui::GetContentRegionAvail().x IMGUI_RIGHT_ALIGN); + s.accept(info); + ImGui::Text("%s", info.str().c_str()); + ImGui::PopTextWrapPos(); + + // icon (>) to open player + ImVec2 pos = ImGui::GetCursorPos(); + ImGui::SameLine(0, 0); + ImGui::SameLine(0, 10.f + ImGui::GetContentRegionAvail().x IMGUI_RIGHT_ALIGN); + if (ImGuiToolkit::IconButton(ICON_FA_PLAY_CIRCLE, "Open in Player")) + UserInterface::manager().showSourceEditor(&s); + ImGui::SameLine(); + if (ImGuiToolkit::IconButton(ICON_FA_DESKTOP, "Show Output")) Settings::application.widget.preview = true; - ImGui::SameLine(0, IMGUI_SAME_LINE); - ImGui::Text("Output"); + ImGui::SetCursorPos(pos); ImGui::SetNextItemWidth(IMGUI_RIGHT_ALIGN); int m = (int) s.renderingProvenance(); @@ -719,10 +732,25 @@ void ImGuiVisitor::visit (CloneSource& s) ImGuiToolkit::Icon(s.icon().x, s.icon().y); ImGui::SameLine(0, IMGUI_SAME_LINE); ImGui::Text("Clone"); + + // info + ImGui::PushTextWrapPos(ImGui::GetCursorPos().x + ImGui::GetContentRegionAvail().x IMGUI_RIGHT_ALIGN); + s.accept(info); + ImGui::Text("%s", info.str().c_str()); + ImGui::PopTextWrapPos(); + + // icon (>) to open player + ImVec2 pos = ImGui::GetCursorPos(); + ImGui::SameLine(0, 0); + ImGui::SameLine(0, 10.f + ImGui::GetContentRegionAvail().x IMGUI_RIGHT_ALIGN); + if (ImGuiToolkit::IconButton(ICON_FA_PLAY_CIRCLE, "Open in Player")) + UserInterface::manager().showSourceEditor(&s); + ImGui::SetCursorPos(pos); + if ( ImGui::Button(s.origin()->name().c_str(), ImVec2(IMGUI_RIGHT_ALIGN, 0)) ) Mixer::manager().setCurrentSource(s.origin()); ImGui::SameLine(0, IMGUI_SAME_LINE); - ImGui::Text("Source"); + ImGui::Text("Origin"); ImGui::SetNextItemWidth(IMGUI_RIGHT_ALIGN); int m = (int) s.cloningProvenance(); diff --git a/InfoVisitor.cpp b/InfoVisitor.cpp index eb28e7e..f1702c7 100644 --- a/InfoVisitor.cpp +++ b/InfoVisitor.cpp @@ -174,16 +174,15 @@ void InfoVisitor::visit (RenderSource& s) return; std::ostringstream oss; - oss << "Rendering Output ("; - oss << RenderSource::rendering_provenance_label[s.renderingProvenance()]; - oss << ") " << std::endl; + if (!brief_) { + oss << "Rendering Output ("; + oss << RenderSource::rendering_provenance_label[s.renderingProvenance()]; + oss << ") " << std::endl; + } if (s.frame()){ oss << s.frame()->width() << " x " << s.frame()->height() << ", "; - if (s.frame()->use_alpha()) - oss << "RGBA"; - else - oss << "RGB"; + oss << (s.frame()->use_alpha() ? "RGBA" : "RGB"); } information_ = oss.str(); @@ -196,16 +195,15 @@ void InfoVisitor::visit (CloneSource& s) return; std::ostringstream oss; - oss << "Clone of '" << s.origin()->name() << "' ("; - oss << CloneSource::cloning_provenance_label[s.cloningProvenance()]; - oss << ") " << std::endl; + if (!brief_) { + oss << "Clone of '" << s.origin()->name() << "' ("; + oss << CloneSource::cloning_provenance_label[s.cloningProvenance()]; + oss << ") " << std::endl; + } if (s.frame()){ oss << s.frame()->width() << " x " << s.frame()->height() << ", "; - if (s.frame()->use_alpha()) - oss << "RGBA"; - else - oss << "RGB"; + oss << (s.frame()->use_alpha() ? "RGBA" : "RGB"); } information_ = oss.str(); @@ -218,10 +216,12 @@ void InfoVisitor::visit (PatternSource& s) return; std::ostringstream oss; - oss << Pattern::get(s.pattern()->type()).label << std::endl; + if (!brief_) + oss << Pattern::get(s.pattern()->type()).label << " pattern" << std::endl; + if (s.pattern()) { oss << s.pattern()->width() << " x " << s.pattern()->height(); - oss << ", RGB"; + oss << ", RGBA"; } information_ = oss.str(); @@ -313,10 +313,13 @@ void InfoVisitor::visit (GenericStreamSource& s) std::ostringstream oss; if (s.stream()) { std::string src_element = s.gstElements().front(); - src_element = src_element.substr(0, src_element.find(" ")); + + if (brief_) + src_element = src_element.substr(0, src_element.find(" ")); + oss << "gstreamer '" << src_element << "'" << std::endl; oss << s.stream()->width() << " x " << s.stream()->height(); - oss << ", RGB"; + oss << ", RGBA"; } else oss << "Undefined"; diff --git a/RenderSource.cpp b/RenderSource.cpp index e806336..9d39ce2 100644 --- a/RenderSource.cpp +++ b/RenderSource.cpp @@ -102,14 +102,15 @@ void RenderSource::init() void RenderSource::update(float dt) { - static glm::mat4 projection = glm::ortho(-1.f, 1.f, 1.f, -1.f, -SCENE_DEPTH, 1.f); + Source::update(dt); - if (active_ && !paused_ && session_ && rendered_output_) { + if (!paused_ && session_ && rendered_output_) { if (provenance_ == RENDER_EXCLUSIVE) { // temporarily exclude this RenderSource from the rendering groups_[View::RENDERING]->visible_ = false; // simulate a rendering of the session in a framebuffer + static glm::mat4 projection = glm::ortho(-1.f, 1.f, 1.f, -1.f, -SCENE_DEPTH, 1.f); glm::mat4 P = glm::scale( projection, glm::vec3(1.f / rendered_output_->aspectRatio(), 1.f, 1.f)); rendered_output_->begin(); // access to private RenderView in the session to call draw on the root of the scene @@ -128,7 +129,6 @@ void RenderSource::update(float dt) // rendered_output_->end(); } - Source::update(dt); } void RenderSource::play (bool on) diff --git a/Session.cpp b/Session.cpp index 411e4b9..e5ec272 100644 --- a/Session.cpp +++ b/Session.cpp @@ -133,7 +133,7 @@ void Session::update(float dt) // update the source (*it)->setActive(activation_threshold_); (*it)->update(dt); - // render the source // TODO: verify ok to render after update + // render the source (*it)->render(); } } diff --git a/SessionSource.cpp b/SessionSource.cpp index 5ec30cf..1331dc0 100644 --- a/SessionSource.cpp +++ b/SessionSource.cpp @@ -98,6 +98,8 @@ void SessionSource::setActive (bool on) void SessionSource::update(float dt) { + Source::update(dt); + if (session_ == nullptr) return; @@ -115,7 +117,6 @@ void SessionSource::update(float dt) failed_ = true; } - Source::update(dt); } void SessionSource::replay () diff --git a/SessionVisitor.cpp b/SessionVisitor.cpp index e7a2a3c..5fcdda3 100644 --- a/SessionVisitor.cpp +++ b/SessionVisitor.cpp @@ -616,15 +616,15 @@ void SessionVisitor::visit (SessionGroupSource& s) xmlCurrent_->SetAttribute("type", "GroupSource"); Session *se = s.session(); + if (se) { + XMLElement *sessionNode = xmlDoc_->NewElement("Session"); + xmlCurrent_->InsertEndChild(sessionNode); - XMLElement *sessionNode = xmlDoc_->NewElement("Session"); - xmlCurrent_->InsertEndChild(sessionNode); - - for (auto iter = se->begin(); iter != se->end(); ++iter){ - setRoot(sessionNode); - (*iter)->accept(*this); + for (auto iter = se->begin(); iter != se->end(); ++iter){ + setRoot(sessionNode); + (*iter)->accept(*this); + } } - } void SessionVisitor::visit (RenderSource& s) @@ -636,16 +636,18 @@ void SessionVisitor::visit (RenderSource& s) void SessionVisitor::visit (CloneSource& s) { xmlCurrent_->SetAttribute("type", "CloneSource"); - xmlCurrent_->SetAttribute("provenance", (int) s.cloningProvenance()); - xmlCurrent_->SetAttribute("delay", (double) s.delay()); - XMLElement *origin = xmlDoc_->NewElement("origin"); - origin->SetAttribute("id", s.origin()->id()); + if (s.origin()) { + xmlCurrent_->SetAttribute("provenance", (int) s.cloningProvenance()); + xmlCurrent_->SetAttribute("delay", (double) s.delay()); - xmlCurrent_->InsertEndChild(origin); - XMLText *text = xmlDoc_->NewText( s.origin()->name().c_str() ); - origin->InsertEndChild( text ); + XMLElement *origin = xmlDoc_->NewElement("origin"); + origin->SetAttribute("id", s.origin()->id()); + xmlCurrent_->InsertEndChild(origin); + XMLText *text = xmlDoc_->NewText( s.origin()->name().c_str() ); + origin->InsertEndChild( text ); + } } void SessionVisitor::visit (PatternSource& s)