From 552c09d377888c0151ecfbed5af97d35214c9333 Mon Sep 17 00:00:00 2001 From: Bruno Date: Sun, 30 May 2021 22:56:13 +0200 Subject: [PATCH] Minor improvements timeline display --- ImGuiToolkit.cpp | 16 +++++++++++++--- UserInterfaceManager.cpp | 36 ++++++++++++++++++++---------------- 2 files changed, 33 insertions(+), 19 deletions(-) diff --git a/ImGuiToolkit.cpp b/ImGuiToolkit.cpp index b35a5ed..05aeecc 100644 --- a/ImGuiToolkit.cpp +++ b/ImGuiToolkit.cpp @@ -532,7 +532,17 @@ bool ImGuiToolkit::TimelineSlider(const char* label, guint64 *time, guint64 star if (tick_step_pixels > 5.f) { large_tick_step = 10 * step; - label_tick_step = 30 * step; + + if (step > 0) { + // try to put a label every second + if ( 1000000000 % step < 1000) + label_tick_step = (1000000000 / step) * step; + // not a round framerate: probalby best to use 10 frames interval + else + label_tick_step = 10 * step; + } + else + label_tick_step = 30 * step; } else { // while there is less than 5 pixels between two tick marks (or at last optimal tick mark) @@ -569,9 +579,9 @@ bool ImGuiToolkit::TimelineSlider(const char* label, guint64 *time, guint64 star // label tick mark if ( !(tick%label_tick_step) ) { tick_length = fontsize; - + guint64 ticklabel = 100 * (guint64) round( (double)( tick ) / 100.0); // round value to avoid '0.99' and alike ImFormatString(overlay_buf, IM_ARRAYSIZE(overlay_buf), "%s", - GstToolkit::time_to_string(tick, GstToolkit::TIME_STRING_MINIMAL).c_str()); + GstToolkit::time_to_string(ticklabel, GstToolkit::TIME_STRING_MINIMAL).c_str()); overlay_size = ImGui::CalcTextSize(overlay_buf, NULL); ImVec2 mini = ImVec2( pos.x - overlay_size.x / 2.f, pos.y + tick_length ); ImVec2 maxi = ImVec2( pos.x + overlay_size.x / 2.f, pos.y + tick_length + overlay_size.y ); diff --git a/UserInterfaceManager.cpp b/UserInterfaceManager.cpp index 5f4c7c4..34a3f82 100644 --- a/UserInterfaceManager.cpp +++ b/UserInterfaceManager.cpp @@ -2421,7 +2421,7 @@ void SourceController::RenderSingleSource(Source *s) ImGui::Text("%s", info_.str().c_str()); StreamSource *sts = dynamic_cast(s); - if (sts) { + if (sts && s->playing()) { ImGui::SetCursorScreenPos(top + ImVec2( framesize.x - 1.5f * _buttons_height, 0.5f * tooltip_height)); ImGui::Text("%.1f Hz", sts->stream()->updateFrameRate()); } @@ -2483,8 +2483,10 @@ void SourceController::RenderMediaPlayer(MediaPlayer *mp) ImGui::SetCursorScreenPos(top + ImVec2(_h_space, _v_space)); ImGui::Text("%s", info_.str().c_str()); - ImGui::SetCursorScreenPos(top + ImVec2( framesize.x - 1.5f * _buttons_height, 0.666f * tooltip_height)); - ImGui::Text("%.1f Hz", mp->updateFrameRate()); + if (mp->isPlaying()) { + ImGui::SetCursorScreenPos(top + ImVec2( framesize.x - 1.5f * _buttons_height, 0.666f * tooltip_height)); + ImGui::Text("%.1f Hz", mp->updateFrameRate()); + } } /// @@ -2627,21 +2629,23 @@ void SourceController::RenderMediaPlayer(MediaPlayer *mp) size.x *= timeline_zoom; bool released = false; - if ( ImGuiToolkit::EditPlotHistoLines("##TimelineArray", - mp->timeline()->gapsArray(), - mp->timeline()->fadingArray(), - MAX_TIMELINE_ARRAY, 0.f, 1.f, - Settings::application.widget.timeline_editmode, &released, size) ) { - mp->timeline()->update(); - } - else if (released) { - Action::manager().store("Timeline change"); - } + Timeline *tl = mp->timeline(); + if (tl->is_valid()) + { + if ( ImGuiToolkit::EditPlotHistoLines("##TimelineArray", tl->gapsArray(), tl->fadingArray(), + MAX_TIMELINE_ARRAY, 0.f, 1.f, + Settings::application.widget.timeline_editmode, &released, size) ) { + tl->update(); + } + else if (released) { + Action::manager().store("Timeline change"); + } - // custom timeline slider - slider_pressed_ = ImGuiToolkit::TimelineSlider("##timeline", &seek_t, mp->timeline()->begin(), - mp->timeline()->end(), mp->timeline()->step(), size.x); + // custom timeline slider + slider_pressed_ = ImGuiToolkit::TimelineSlider("##timeline", &seek_t, tl->begin(), + tl->end(), tl->step(), size.x); + } } ImGui::EndChild();