Move and improve time_to_string and date_time_string functions to

GstToolkit
This commit is contained in:
brunoherbelin
2020-03-24 00:03:31 +01:00
parent cf6ef69342
commit 29507bfc09
4 changed files with 36 additions and 33 deletions

View File

@@ -1,27 +1,44 @@
#include <sstream>
#include <iomanip>
#include <ctime>
using namespace std;
#include <gst/gst.h>
#include "GstToolkit.h"
string GstToolkit::date_time_string()
{
std::time_t t = std::time(0); // get time now
std::tm* now = std::localtime(&t);
string GstToolkit::to_string(guint64 t) {
ostringstream oss;
oss << std::to_string(now->tm_year + 1900);
oss << std::to_string(now->tm_mon + 1);
oss << setw(2) << setfill('0') << std::to_string(now->tm_mday );
oss << setw(2) << setfill('0') << std::to_string(now->tm_hour );
oss << setw(2) << setfill('0') << std::to_string(now->tm_min );
oss << setw(2) << setfill('0') << std::to_string(now->tm_sec );
return oss.str();
}
string GstToolkit::time_to_string(guint64 t)
{
if (t == GST_CLOCK_TIME_NONE)
return "00:00:00.00";
guint ms = GST_TIME_AS_MSECONDS(t);
guint s = ms / 1000;
std::ostringstream oss;
ostringstream oss;
if (s / 3600)
oss << std::setw(2) << std::setfill('0') << s / 3600 << ':';
oss << setw(2) << setfill('0') << s / 3600 << ':';
if ((s % 3600) / 60)
oss << std::setw(2) << std::setfill('0') << (s % 3600) / 60 << ':';
oss << std::setw(2) << std::setfill('0') << (s % 3600) % 60 << '.';
oss << std::setw(2) << std::setfill('0') << (ms % 1000) / 10;
oss << setw(2) << setfill('0') << (s % 3600) / 60 << ':';
oss << setw(2) << setfill('0') << (s % 3600) % 60 << '.';
oss << setw(2) << setfill('0') << (ms % 1000) / 10;
return oss.str();
}
@@ -88,7 +105,7 @@ string GstToolkit::gst_version()
{
std::ostringstream oss;
oss << GST_VERSION_MAJOR << '.' << GST_VERSION_MINOR << '.';
oss << std::setw(2) << std::setfill('0') << GST_VERSION_MICRO ;
oss << std::setw(2) << setfill('0') << GST_VERSION_MICRO ;
if (GST_VERSION_NANO > 0)
oss << ( (GST_VERSION_NANO < 2 ) ? " - (CVS)" : " - (Prerelease)");

View File

@@ -3,20 +3,19 @@
#include <string>
#include <list>
using namespace std;
namespace GstToolkit
{
string to_string(guint64 t);
std::string date_time_string();
std::string time_to_string(guint64 t);
list<string> all_plugins();
list<string> all_plugin_features(string pluginname);
std::string gst_version();
std::list<std::string> all_plugins();
std::list<std::string> all_plugin_features(std::string pluginname);
bool enable_feature (string name, bool enable);
string gst_version();
bool enable_feature (std::string name, bool enable);
}

View File

@@ -1,6 +1,5 @@
#include <map>
#include <ctime>
#ifdef _WIN32
# include <windows.h>
@@ -21,19 +20,8 @@
#include "ImGuiToolkit.h"
#include "GstToolkit.h"
static unsigned int textureicons = 0;
static std::map <ImGuiToolkit::font_style, ImFont*>fontmap;
std::string ImGuiToolkit::DateTime(){
std::time_t t = std::time(0); // get time now
std::tm* now = std::localtime(&t);
std::string datetime = std::to_string(now->tm_year + 1900) +
std::to_string(now->tm_mon + 1) + std::to_string(now->tm_mday) +
std::to_string(now->tm_hour) + std::to_string(now->tm_min) +
std::to_string(now->tm_sec);
return datetime;
}
unsigned int textureicons = 0;
std::map <ImGuiToolkit::font_style, ImFont*>fontmap;
void ImGuiToolkit::OpenWebpage( const char* url )
@@ -248,13 +236,13 @@ bool ImGuiToolkit::TimelineSlider(const char* label, guint64 *time, guint64 dura
// render text : duration and current time
char overlay_buf[24];
ImVec2 overlay_size = ImVec2(0.f, 0.f);
ImFormatString(overlay_buf, IM_ARRAYSIZE(overlay_buf), "%s", GstToolkit::to_string(duration).c_str());
ImFormatString(overlay_buf, IM_ARRAYSIZE(overlay_buf), "%s", GstToolkit::time_to_string(duration).c_str());
overlay_size = ImGui::CalcTextSize(overlay_buf, NULL);
overlay_size += ImVec2(3.f, 3.f);
if (overlay_size.x > 0.0f)
ImGui::RenderTextClipped( bbox.GetBR() - overlay_size, bbox.Max, overlay_buf, NULL, &overlay_size);
ImFormatString(overlay_buf, IM_ARRAYSIZE(overlay_buf), "%s", GstToolkit::to_string(*time).c_str());
ImFormatString(overlay_buf, IM_ARRAYSIZE(overlay_buf), "%s", GstToolkit::time_to_string(*time).c_str());
overlay_size = ImGui::CalcTextSize(overlay_buf, NULL);
overlay_size = ImVec2(3.f, -3.f - overlay_size.y);
if (overlay_size.x > 0.0f)
@@ -452,13 +440,13 @@ bool ImGuiToolkit::TimelineSliderEdit(const char* label, guint64 *time, guint64
// render text : duration and current time
char overlay_buf[24];
ImVec2 overlay_size = ImVec2(0.f, 0.f);
ImFormatString(overlay_buf, IM_ARRAYSIZE(overlay_buf), "%s", GstToolkit::to_string(duration).c_str());
ImFormatString(overlay_buf, IM_ARRAYSIZE(overlay_buf), "%s", GstToolkit::time_to_string(duration).c_str());
overlay_size = ImGui::CalcTextSize(overlay_buf, NULL);
overlay_size += ImVec2(3.f, 3.f);
if (overlay_size.x > 0.0f)
ImGui::RenderTextClipped( bbox.GetBR() - overlay_size, bbox.Max, overlay_buf, NULL, &overlay_size);
ImFormatString(overlay_buf, IM_ARRAYSIZE(overlay_buf), "%s", GstToolkit::to_string(*time).c_str());
ImFormatString(overlay_buf, IM_ARRAYSIZE(overlay_buf), "%s", GstToolkit::time_to_string(*time).c_str());
overlay_size = ImGui::CalcTextSize(overlay_buf, NULL);
overlay_size = ImVec2(3.f, -3.f - overlay_size.y);
if (overlay_size.x > 0.0f)

View File

@@ -37,7 +37,6 @@ namespace ImGuiToolkit
} accent_color;
void SetAccentColor(accent_color color);
std::string DateTime();
void OpenWebpage( const char* url );
}