mirror of
https://github.com/brunoherbelin/vimix.git
synced 2025-12-13 03:09:57 +01:00
improved text display of time with 3 modes depending on the needs.
This commit is contained in:
@@ -4,19 +4,26 @@ using namespace std;
|
||||
|
||||
#include "GstToolkit.h"
|
||||
|
||||
string GstToolkit::time_to_string(guint64 t, bool stripped)
|
||||
string GstToolkit::time_to_string(guint64 t, time_string_mode m)
|
||||
{
|
||||
if (t == GST_CLOCK_TIME_NONE)
|
||||
return "00:00:00.00";
|
||||
if (t == GST_CLOCK_TIME_NONE) {
|
||||
switch (m) {
|
||||
case TIME_STRING_FIXED:
|
||||
return "00:00:00.00";
|
||||
case TIME_STRING_MINIMAL:
|
||||
return "0.0";
|
||||
default:
|
||||
return "00.00";
|
||||
}
|
||||
}
|
||||
|
||||
guint ms = GST_TIME_AS_MSECONDS(t);
|
||||
guint s = ms / 1000;
|
||||
|
||||
ostringstream oss;
|
||||
|
||||
if (stripped) {
|
||||
// MINIMAL: keep only the 2 higher values (most significant)
|
||||
if (m == TIME_STRING_MINIMAL) {
|
||||
int count = 0;
|
||||
|
||||
if (s / 3600) {
|
||||
oss << s / 3600 << ':';
|
||||
count++;
|
||||
@@ -31,19 +38,18 @@ string GstToolkit::time_to_string(guint64 t, bool stripped)
|
||||
}
|
||||
if (count < 2 )
|
||||
oss << '.'<< setw(1) << setfill('0') << (ms % 1000) / 10;
|
||||
|
||||
}
|
||||
else {
|
||||
if (s / 3600)
|
||||
// TIME_STRING_FIXED : fixed length string (11 chars) HH:mm:ss.ii"
|
||||
// TIME_STRING_RIGHT : always show the right part (seconds), not the min or hours if none
|
||||
if (m == TIME_STRING_FIXED || (s / 3600) )
|
||||
oss << setw(2) << setfill('0') << s / 3600 << ':';
|
||||
if ((s % 3600) / 60)
|
||||
if (m == TIME_STRING_FIXED || ((s % 3600) / 60) )
|
||||
oss << setw(2) << setfill('0') << (s % 3600) / 60 << ':';
|
||||
oss << setw(2) << setfill('0') << (s % 3600) % 60 << '.';
|
||||
oss << setw(2) << setfill('0') << (ms % 1000) / 10;
|
||||
}
|
||||
|
||||
// non-stripped : fixed length string (11 chars) HH:mm:ss.ii"
|
||||
// stripped : adapted to precision
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
|
||||
16
GstToolkit.h
16
GstToolkit.h
@@ -9,13 +9,19 @@
|
||||
namespace GstToolkit
|
||||
{
|
||||
|
||||
std::string time_to_string(guint64 t, bool stripped = false);
|
||||
typedef enum {
|
||||
TIME_STRING_FIXED = 0,
|
||||
TIME_STRING_ADJUSTED,
|
||||
TIME_STRING_MINIMAL
|
||||
} time_string_mode;
|
||||
|
||||
std::string gst_version();
|
||||
std::list<std::string> all_plugins();
|
||||
std::list<std::string> all_plugin_features(std::string pluginname);
|
||||
std::string time_to_string(guint64 t, time_string_mode m = TIME_STRING_ADJUSTED);
|
||||
|
||||
bool enable_feature (std::string name, bool enable);
|
||||
std::string gst_version();
|
||||
std::list<std::string> all_plugins();
|
||||
std::list<std::string> all_plugin_features(std::string pluginname);
|
||||
|
||||
bool enable_feature (std::string name, bool enable);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -400,22 +400,25 @@ bool ImGuiToolkit::TimelineSlider(const char* label, guint64 *time, guint64 dura
|
||||
ImVec2 maxi = ImVec2(0.f, 0.f);
|
||||
|
||||
// render text duration
|
||||
ImFormatString(overlay_buf, IM_ARRAYSIZE(overlay_buf), "%s", GstToolkit::time_to_string(duration).c_str());
|
||||
ImFormatString(overlay_buf, IM_ARRAYSIZE(overlay_buf), "%s",
|
||||
GstToolkit::time_to_string(duration, GstToolkit::TIME_STRING_MINIMAL).c_str());
|
||||
overlay_size = ImGui::CalcTextSize(overlay_buf, NULL);
|
||||
ImVec2 duration_label = bbox.GetBR() - overlay_size - ImVec2(3.f, 3.f);
|
||||
if (overlay_size.x > 0.0f)
|
||||
ImGui::RenderTextClipped( duration_label, bbox.Max, overlay_buf, NULL, &overlay_size);
|
||||
|
||||
|
||||
// render tick marks
|
||||
while ( tick < duration)
|
||||
{
|
||||
// large tick mark every large tick
|
||||
// large tick mark
|
||||
float tick_length = !(tick%large_tick_step) ? fontsize - style.FramePadding.y : style.FramePadding.y;
|
||||
|
||||
// label tick mark
|
||||
if ( !(tick%label_tick_step) ) {
|
||||
tick_length = fontsize;
|
||||
|
||||
ImFormatString(overlay_buf, IM_ARRAYSIZE(overlay_buf), "%s", GstToolkit::time_to_string(tick, true).c_str());
|
||||
ImFormatString(overlay_buf, IM_ARRAYSIZE(overlay_buf), "%s",
|
||||
GstToolkit::time_to_string(tick, GstToolkit::TIME_STRING_MINIMAL).c_str());
|
||||
overlay_size = ImGui::CalcTextSize(overlay_buf, NULL);
|
||||
mini = ImVec2( pos.x - overlay_size.x / 2.f, pos.y + tick_length );
|
||||
maxi = ImVec2( pos.x + overlay_size.x / 2.f, pos.y + tick_length + overlay_size.y );
|
||||
@@ -424,7 +427,7 @@ bool ImGuiToolkit::TimelineSlider(const char* label, guint64 *time, guint64 dura
|
||||
ImGui::RenderTextClipped(mini, maxi, overlay_buf, NULL, &overlay_size);
|
||||
}
|
||||
|
||||
// draw a tick mark each step
|
||||
// draw the tick mark each step
|
||||
window->DrawList->AddLine( pos, pos + ImVec2(0.f, tick_length), color);
|
||||
|
||||
// next tick
|
||||
|
||||
@@ -1168,7 +1168,7 @@ void MediaController::Render()
|
||||
// display time
|
||||
ImGuiToolkit::PushFont(ImGuiToolkit::FONT_LARGE);
|
||||
ImGui::SetCursorPos( ImVec2(return_to_pos.x + 5, return_to_pos.y - ImGui::GetTextLineHeightWithSpacing()) );
|
||||
ImGui::Text("%s", GstToolkit::time_to_string(mp_->position()).c_str());
|
||||
ImGui::Text("%s", GstToolkit::time_to_string(mp_->position(), GstToolkit::TIME_STRING_FIXED).c_str());
|
||||
ImGui::PopFont();
|
||||
|
||||
ImGui::SetCursorPos(return_to_pos);
|
||||
|
||||
Reference in New Issue
Block a user