Fixed Timeline display

This commit is contained in:
Bruno
2021-06-18 23:57:42 +02:00
parent 295ece79ae
commit e422a1b403

View File

@@ -465,35 +465,32 @@ void ImGuiToolkit::RenderTimeline (ImGuiWindow* window, ImRect timeline_bbox, gu
const float fontsize = g.FontSize; const float fontsize = g.FontSize;
const ImU32 text_color = ImGui::GetColorU32(ImGuiCol_Text); const ImU32 text_color = ImGui::GetColorU32(ImGuiCol_Text);
guint64 duration = end - start;
float step_ = static_cast<float> ( static_cast<double>(step) / static_cast<double>(duration) );
// by default, put a tick mark at every frame step and a large mark every second // by default, put a tick mark at every frame step and a large mark every second
guint64 tick_step = step; guint64 tick_step = step;
guint64 large_tick_step = optimal_tick_marks[1+LARGE_TICK_INCREMENT]; guint64 large_tick_step = optimal_tick_marks[1+LARGE_TICK_INCREMENT];
guint64 label_tick_step = optimal_tick_marks[1+LABEL_TICK_INCREMENT]; guint64 label_tick_step = optimal_tick_marks[1+LABEL_TICK_INCREMENT];
guint64 tick_delta = 0; guint64 tick_delta = 0;
// keep duration
const guint64 duration = end - start;
// how many pixels to represent one frame step? // how many pixels to represent one frame step?
const float step_ = static_cast<float> ( static_cast<double>(tick_step) / static_cast<double>(duration) );
float tick_step_pixels = timeline_bbox.GetWidth() * step_; float tick_step_pixels = timeline_bbox.GetWidth() * step_;
// large space // large space
if (tick_step_pixels > 5.f) if (tick_step_pixels > 5.f && step > 0)
{ {
// try to put a label ticks every second // try to put a label ticks every second
tick_delta = SECOND % step; label_tick_step = (SECOND / step) * step;
if ( tick_delta < 100) { large_tick_step = 5 * step;
label_tick_step = (SECOND / step) * step; tick_delta = SECOND - label_tick_step;
// try to put large ticks at half second
if ( (SECOND/2) % step < 1000 ) // round to nearest
large_tick_step = label_tick_step / 2; if (tick_delta > step / 2) {
else label_tick_step += step;
large_tick_step = step * 5; large_tick_step += step;
} tick_delta = SECOND - label_tick_step;
// not a round framerate: probalby best to use 10 frames interval
else {
label_tick_step = 10 * step;
large_tick_step = 5 * step;
} }
} }
else { else {
@@ -544,7 +541,7 @@ void ImGuiToolkit::RenderTimeline (ImGuiWindow* window, ImRect timeline_bbox, gu
ImVec2 pos = verticalflip ? timeline_bbox.GetBL() : timeline_bbox.GetTL(); ImVec2 pos = verticalflip ? timeline_bbox.GetBL() : timeline_bbox.GetTL();
// loop ticks from start to end // loop ticks from start to end
guint64 tick = (start / tick_step) * tick_step; guint64 tick = tick_step > 0 ? (start / tick_step) * tick_step : 0;
while ( tick < end ) while ( tick < end )
{ {
// large tick mark ? // large tick mark ?
@@ -557,7 +554,7 @@ void ImGuiToolkit::RenderTimeline (ImGuiWindow* window, ImRect timeline_bbox, gu
tick_length = fontsize; tick_length = fontsize;
// correct tick value for delta for approximation to rounded second marks // correct tick value for delta for approximation to rounded second marks
guint64 ticklabel = tick + ( tick_delta * tick / label_tick_step); guint64 ticklabel = tick + ( tick_delta * tick / label_tick_step);
ImFormatString(text_buf, IM_ARRAYSIZE(text_buf), "%s", ImFormatString(text_buf, IM_ARRAYSIZE(text_buf), "%s",
GstToolkit::time_to_string(ticklabel, GstToolkit::TIME_STRING_MINIMAL).c_str()); GstToolkit::time_to_string(ticklabel, GstToolkit::TIME_STRING_MINIMAL).c_str());
ImVec2 label_size = ImGui::CalcTextSize(text_buf, NULL); ImVec2 label_size = ImGui::CalcTextSize(text_buf, NULL);