mirror of
https://github.com/brunoherbelin/vimix.git
synced 2025-12-09 09:19:58 +01:00
Move and improve time_to_string and date_time_string functions to
GstToolkit
This commit is contained in:
@@ -1,27 +1,44 @@
|
|||||||
|
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
|
#include <ctime>
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
#include <gst/gst.h>
|
#include <gst/gst.h>
|
||||||
|
|
||||||
#include "GstToolkit.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)
|
if (t == GST_CLOCK_TIME_NONE)
|
||||||
return "00:00:00.00";
|
return "00:00:00.00";
|
||||||
|
|
||||||
guint ms = GST_TIME_AS_MSECONDS(t);
|
guint ms = GST_TIME_AS_MSECONDS(t);
|
||||||
guint s = ms / 1000;
|
guint s = ms / 1000;
|
||||||
|
|
||||||
std::ostringstream oss;
|
ostringstream oss;
|
||||||
if (s / 3600)
|
if (s / 3600)
|
||||||
oss << std::setw(2) << std::setfill('0') << s / 3600 << ':';
|
oss << setw(2) << setfill('0') << s / 3600 << ':';
|
||||||
if ((s % 3600) / 60)
|
if ((s % 3600) / 60)
|
||||||
oss << std::setw(2) << std::setfill('0') << (s % 3600) / 60 << ':';
|
oss << setw(2) << setfill('0') << (s % 3600) / 60 << ':';
|
||||||
oss << std::setw(2) << std::setfill('0') << (s % 3600) % 60 << '.';
|
oss << setw(2) << setfill('0') << (s % 3600) % 60 << '.';
|
||||||
oss << std::setw(2) << std::setfill('0') << (ms % 1000) / 10;
|
oss << setw(2) << setfill('0') << (ms % 1000) / 10;
|
||||||
|
|
||||||
return oss.str();
|
return oss.str();
|
||||||
}
|
}
|
||||||
@@ -88,7 +105,7 @@ string GstToolkit::gst_version()
|
|||||||
{
|
{
|
||||||
std::ostringstream oss;
|
std::ostringstream oss;
|
||||||
oss << GST_VERSION_MAJOR << '.' << GST_VERSION_MINOR << '.';
|
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)
|
if (GST_VERSION_NANO > 0)
|
||||||
oss << ( (GST_VERSION_NANO < 2 ) ? " - (CVS)" : " - (Prerelease)");
|
oss << ( (GST_VERSION_NANO < 2 ) ? " - (CVS)" : " - (Prerelease)");
|
||||||
|
|
||||||
|
|||||||
13
GstToolkit.h
13
GstToolkit.h
@@ -3,20 +3,19 @@
|
|||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <list>
|
#include <list>
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
|
|
||||||
namespace GstToolkit
|
namespace GstToolkit
|
||||||
{
|
{
|
||||||
|
|
||||||
string to_string(guint64 t);
|
std::string date_time_string();
|
||||||
|
std::string time_to_string(guint64 t);
|
||||||
|
|
||||||
list<string> all_plugins();
|
std::string gst_version();
|
||||||
list<string> all_plugin_features(string pluginname);
|
std::list<std::string> all_plugins();
|
||||||
|
std::list<std::string> all_plugin_features(std::string pluginname);
|
||||||
|
|
||||||
bool enable_feature (string name, bool enable);
|
bool enable_feature (std::string name, bool enable);
|
||||||
|
|
||||||
string gst_version();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <ctime>
|
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
# include <windows.h>
|
# include <windows.h>
|
||||||
@@ -21,19 +20,8 @@
|
|||||||
#include "ImGuiToolkit.h"
|
#include "ImGuiToolkit.h"
|
||||||
#include "GstToolkit.h"
|
#include "GstToolkit.h"
|
||||||
|
|
||||||
static unsigned int textureicons = 0;
|
unsigned int textureicons = 0;
|
||||||
static std::map <ImGuiToolkit::font_style, ImFont*>fontmap;
|
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void ImGuiToolkit::OpenWebpage( const char* url )
|
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
|
// render text : duration and current time
|
||||||
char overlay_buf[24];
|
char overlay_buf[24];
|
||||||
ImVec2 overlay_size = ImVec2(0.f, 0.f);
|
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 = ImGui::CalcTextSize(overlay_buf, NULL);
|
||||||
overlay_size += ImVec2(3.f, 3.f);
|
overlay_size += ImVec2(3.f, 3.f);
|
||||||
if (overlay_size.x > 0.0f)
|
if (overlay_size.x > 0.0f)
|
||||||
ImGui::RenderTextClipped( bbox.GetBR() - overlay_size, bbox.Max, overlay_buf, NULL, &overlay_size);
|
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 = ImGui::CalcTextSize(overlay_buf, NULL);
|
||||||
overlay_size = ImVec2(3.f, -3.f - overlay_size.y);
|
overlay_size = ImVec2(3.f, -3.f - overlay_size.y);
|
||||||
if (overlay_size.x > 0.0f)
|
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
|
// render text : duration and current time
|
||||||
char overlay_buf[24];
|
char overlay_buf[24];
|
||||||
ImVec2 overlay_size = ImVec2(0.f, 0.f);
|
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 = ImGui::CalcTextSize(overlay_buf, NULL);
|
||||||
overlay_size += ImVec2(3.f, 3.f);
|
overlay_size += ImVec2(3.f, 3.f);
|
||||||
if (overlay_size.x > 0.0f)
|
if (overlay_size.x > 0.0f)
|
||||||
ImGui::RenderTextClipped( bbox.GetBR() - overlay_size, bbox.Max, overlay_buf, NULL, &overlay_size);
|
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 = ImGui::CalcTextSize(overlay_buf, NULL);
|
||||||
overlay_size = ImVec2(3.f, -3.f - overlay_size.y);
|
overlay_size = ImVec2(3.f, -3.f - overlay_size.y);
|
||||||
if (overlay_size.x > 0.0f)
|
if (overlay_size.x > 0.0f)
|
||||||
|
|||||||
@@ -37,7 +37,6 @@ namespace ImGuiToolkit
|
|||||||
} accent_color;
|
} accent_color;
|
||||||
void SetAccentColor(accent_color color);
|
void SetAccentColor(accent_color color);
|
||||||
|
|
||||||
std::string DateTime();
|
|
||||||
void OpenWebpage( const char* url );
|
void OpenWebpage( const char* url );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user