From 252ed1c6f206e0fc6563c699c40fab230b59e8c7 Mon Sep 17 00:00:00 2001 From: Bruno Herbelin Date: Tue, 3 May 2022 00:39:10 +0200 Subject: [PATCH] Added slider to show source pre-post processed in Player --- ImGuiToolkit.cpp | 47 +++++++++++++++++++++++++++++++++++++++ ImGuiToolkit.h | 1 + UserInterfaceManager.cpp | 40 +++++++++++++++++++++++++++------ UserInterfaceManager.h | 3 ++- rsc/images/icons.dds | Bin 1638528 -> 1638528 bytes 5 files changed, 83 insertions(+), 8 deletions(-) diff --git a/ImGuiToolkit.cpp b/ImGuiToolkit.cpp index 7a7c28a..7643770 100644 --- a/ImGuiToolkit.cpp +++ b/ImGuiToolkit.cpp @@ -1086,6 +1086,53 @@ bool ImGuiToolkit::InvisibleSliderInt (const char* label, uint *index, uint min, return value_changed; } +bool ImGuiToolkit::InvisibleSliderFloat (const char* label, float *index, float min, float max, ImVec2 size) +{ + // get window + ImGuiWindow* window = ImGui::GetCurrentWindow(); + if (window->SkipItems) + return false; + + // get id + const ImGuiID id = window->GetID(label); + + ImVec2 pos = window->DC.CursorPos; + ImRect bbox(pos, pos + size); + ImGui::ItemSize(size); + if (!ImGui::ItemAdd(bbox, id)) + return false; + + // read user input from system + const bool left_mouse_press = ImGui::IsMouseDown(ImGuiMouseButton_Left); + const bool hovered = ImGui::ItemHoverable(bbox, id); + bool temp_input_is_active = ImGui::TempInputIsActive(id); + if (!temp_input_is_active) + { + const bool focus_requested = ImGui::FocusableItemRegister(window, id); + if (focus_requested || (hovered && left_mouse_press) ) + { + ImGui::SetActiveID(id, window); + ImGui::SetFocusID(id, window); + ImGui::FocusWindow(window); + } + } + else + return false; + + bool value_changed = false; + + if (ImGui::GetActiveID() == id) { + // Slider behavior + ImRect grab_slider_bb; + float _zero = min; + float _end = max; + value_changed = ImGui::SliderBehavior(bbox, id, ImGuiDataType_Float, index, &_zero, + &_end, "%f", 1.f, ImGuiSliderFlags_None, &grab_slider_bb); + } + + return value_changed; +} + bool ImGuiToolkit::EditPlotLines (const char* label, float *array, int values_count, float values_min, float values_max, const ImVec2 size) { bool array_changed = false; diff --git a/ImGuiToolkit.h b/ImGuiToolkit.h index b2dd1fc..8ef12dc 100644 --- a/ImGuiToolkit.h +++ b/ImGuiToolkit.h @@ -50,6 +50,7 @@ namespace ImGuiToolkit void RenderTimeline (ImVec2 min_bbox, ImVec2 max_bbox, guint64 begin, guint64 end, guint64 step, bool verticalflip = false); void RenderTimelineBPM (ImVec2 min_bbox, ImVec2 max_bbox, double tempo, double quantum, guint64 begin, guint64 end, guint64 step, bool verticalflip = false); bool InvisibleSliderInt(const char* label, uint *index, uint min, uint max, const ImVec2 size); + bool InvisibleSliderFloat(const char* label, float *index, float min, float max, const ImVec2 size); bool EditPlotLines(const char* label, float *array, int values_count, float values_min, float values_max, const ImVec2 size); bool EditPlotHistoLines(const char* label, float *histogram_array, float *lines_array, int values_count, float values_min, float values_max, guint64 begin, guint64 end, bool cut, bool *released, const ImVec2 size); void ShowPlotHistoLines(const char* label, float *histogram_array, float *lines_array, int values_count, float values_min, float values_max, const ImVec2 size); diff --git a/UserInterfaceManager.cpp b/UserInterfaceManager.cpp index c3f7663..d0725b5 100644 --- a/UserInterfaceManager.cpp +++ b/UserInterfaceManager.cpp @@ -2062,7 +2062,7 @@ void WorkspaceWindow::Update() /// SourceController::SourceController() : WorkspaceWindow("SourceController"), min_width_(0.f), h_space_(0.f), v_space_(0.f), scrollbar_(0.f), - timeline_height_(0.f), mediaplayer_height_(0.f), buttons_width_(0.f), buttons_height_(0.f), + timeline_height_(0.f), mediaplayer_height_(0.f), buttons_width_(0.f), buttons_height_(0.f), filter_slider_(0.9), play_toggle_request_(false), replay_request_(false), pending_(false), active_label_(LABEL_AUTO_MEDIA_PLAYER), active_selection_(-1), selection_context_menu_(false), selection_mediaplayer_(nullptr), selection_target_slower_(0), selection_target_faster_(0), @@ -2195,6 +2195,15 @@ void SourceController::Render() if (ImGui::MenuItem( ICON_FA_PLAY " Play | Pause", "Space")) play_toggle_request_ = true; + if (ImGui::BeginMenu( ICON_FA_IMAGE " Show")) + { + if (ImGuiToolkit::MenuItemIcon(7, 9, "Pre-processed input")) + filter_slider_ = 1.0; + if (ImGuiToolkit::MenuItemIcon(8, 9, "Post-processed image")) + filter_slider_ = 0.0; + ImGui::EndMenu(); + } + // Menu section for list ImGui::Separator(); if (ImGui::MenuItem( ICON_FA_TH " List all")) { @@ -2962,10 +2971,12 @@ void SourceController::RenderSingleSource(Source *s) // in case of a MediaSource MediaSource *ms = dynamic_cast(s); if ( ms != nullptr ) { - RenderMediaPlayer( ms->mediaplayer() ); + RenderMediaPlayer( ms ); } else { + ImDrawList* draw_list = ImGui::GetWindowDrawList(); + ImVec2 top = ImGui::GetCursorScreenPos(); ImVec2 rendersize = ImGui::GetContentRegionAvail() - ImVec2(0, buttons_height_ + scrollbar_ + v_space_); ImVec2 bottom = ImVec2(top.x, top.y + rendersize.y + v_space_); @@ -2991,7 +3002,15 @@ void SourceController::RenderSingleSource(Source *s) /// top += corner; ImGui::SetCursorScreenPos(top); - ImGui::Image((void*)(uintptr_t) s->texture(), framesize); + ImGui::Image((void*)(uintptr_t) s->texture(), framesize * ImVec2(filter_slider_,1.f), ImVec2(0.f,0.f), ImVec2(filter_slider_,1.f)); + + ImGui::SetCursorScreenPos(top + ImVec2(filter_slider_ * framesize.x, 0.f)); + ImGui::Image((void*)(uintptr_t) s->frame()->texture(), framesize * ImVec2(1.f-filter_slider_,1.f), ImVec2(filter_slider_,0.f), ImVec2(1.f,1.f)); + + ImGui::SetCursorScreenPos(top + ImVec2(0.f, 0.5f * framesize.y - 20.0f)); + ImGuiToolkit::InvisibleSliderFloat("#filter_slider", &filter_slider_, 0.f, 1.f, ImVec2(framesize.x, 40.0f) ); + draw_list->AddCircleFilled(top + framesize * ImVec2(filter_slider_,0.5f), 20.f, IM_COL32(255, 255, 255, 150), 26); + draw_list->AddLine(top + framesize * ImVec2(filter_slider_,0.0f), top + framesize * ImVec2(filter_slider_,1.f), IM_COL32(255, 255, 255, 150), 1); /// /// Info overlays @@ -3003,7 +3022,6 @@ void SourceController::RenderSingleSource(Source *s) s->accept(info_); // draw overlay frame and text float tooltip_height = 3.f * ImGui::GetTextLineHeightWithSpacing(); - ImDrawList* draw_list = ImGui::GetWindowDrawList(); draw_list->AddRectFilled(top, top + ImVec2(framesize.x, tooltip_height), IMGUI_COLOR_OVERLAY); ImGui::SetCursorScreenPos(top + ImVec2(h_space_, v_space_)); ImGui::Text("%s", info_.str().c_str()); @@ -3033,9 +3051,9 @@ void SourceController::RenderSingleSource(Source *s) } } -void SourceController::RenderMediaPlayer(MediaPlayer *mp) +void SourceController::RenderMediaPlayer(MediaSource *ms) { - mediaplayer_active_ = mp; + mediaplayer_active_ = ms->mediaplayer(); // for action manager std::ostringstream oss; @@ -3069,7 +3087,15 @@ void SourceController::RenderMediaPlayer(MediaPlayer *mp) /// const ImVec2 top_image = top + corner; ImGui::SetCursorScreenPos(top_image); - ImGui::Image((void*)(uintptr_t) mediaplayer_active_->texture(), framesize); + ImGui::Image((void*)(uintptr_t) ms->texture(), framesize * ImVec2(filter_slider_,1.f), ImVec2(0.f,0.f), ImVec2(filter_slider_,1.f)); + + ImGui::SetCursorScreenPos(top_image + ImVec2(filter_slider_ * framesize.x, 0.f)); + ImGui::Image((void*)(uintptr_t) ms->frame()->texture(), framesize * ImVec2(1.f-filter_slider_,1.f), ImVec2(filter_slider_,0.f), ImVec2(1.f,1.f)); + + ImGui::SetCursorScreenPos(top_image + ImVec2(0.f, 0.5f * framesize.y - 20.0f)); + ImGuiToolkit::InvisibleSliderFloat("#filter_slider_2", &filter_slider_, 0.f, 1.f, ImVec2(framesize.x, 40.0f) ); + draw_list->AddCircleFilled(top_image + framesize * ImVec2(filter_slider_,0.5f), 20.f, IM_COL32(255, 255, 255, 150), 26); + draw_list->AddLine(top_image + framesize * ImVec2(filter_slider_,0.0f), top_image + framesize * ImVec2(filter_slider_,1.f), IM_COL32(255, 255, 255, 150), 1); /// /// Info overlays diff --git a/UserInterfaceManager.h b/UserInterfaceManager.h index 2a1430c..1408a13 100644 --- a/UserInterfaceManager.h +++ b/UserInterfaceManager.h @@ -268,6 +268,7 @@ class SourceController : public WorkspaceWindow float mediaplayer_height_; float buttons_width_; float buttons_height_; + float filter_slider_; bool play_toggle_request_, replay_request_; bool pending_; @@ -301,7 +302,7 @@ class SourceController : public WorkspaceWindow bool mediaplayer_mode_; bool mediaplayer_slider_pressed_; float mediaplayer_timeline_zoom_; - void RenderMediaPlayer(MediaPlayer *mp); + void RenderMediaPlayer(MediaSource *ms); public: SourceController(); diff --git a/rsc/images/icons.dds b/rsc/images/icons.dds index 73f0d47eb22ee29a52650f2b1fd342682cb31960..1f0a866be4015627b39538aa809525be2b1497d1 100644 GIT binary patch delta 1806 zcmcIkUuaWT82@tbnxs9^=4Pp>9pV*-TK3Rb_n@W2JVY4uwq%cjVSg-Ca17Izy{*l| z?fS5X{1J|Il-0_>mB~~pmuVpz9Wn;f>6Q*b3_eIiS;N?vtLe?R@7(m9uG2k<-{phz z`~IKbIp>aNhsU$Sxjp)kRz1J>m3+dVwQS30Tbga@w)K*2wb+*5wgR>lw5?X#YP)Q) zEhn7!M*aJI{Lmkvlyg7B-ih!-6aIm*fn+PRjkYZ!$s9>C2{1WXTi%G5UlcyP*6_I- zG}OTJklQ`eKf{mN!7*OVurHnB1lwukC&K*NN%ljyZL#^ugyJ_NyR`FP^Y7=hQ^9`9 z6rale!pWUx9R~mW9D9`dZ>lIEMUaPI;TzbAF<}!}4}&KXFJT4~ZrqiaT90pR=~U0N zD+WKaz~&=i(~*ITxQJzR`AAIf_NM46FQ_UaNQyT_7k+@1rbS>e!kb6$-VqjoQ;k`y zH{BklDRyqF(d>gV;zt~5?05pdNK6q4LsBD+Sj-%ZI`+40Fv4&B#Cm-fdCN_fIBr5* zh7_(>yRT}~An}xIoP{_jjDX-mU15R<6)4I0%2c1B)ASOrVgb!MtVk>-PuH-7X=y?H z4Uf9;-8vSlrii`Qf+cMT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