Make time display show a time code and silence warnings
This commit is contained in:
parent
3c193916e7
commit
fd32101a41
2 changed files with 40 additions and 3 deletions
41
main.cpp
41
main.cpp
|
@ -13,6 +13,7 @@
|
||||||
#include <numbers>
|
#include <numbers>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
#include <string>
|
||||||
#include <SDL.h>
|
#include <SDL.h>
|
||||||
#include <SDL_image.h>
|
#include <SDL_image.h>
|
||||||
#if defined(IMGUI_IMPL_OPENGL_ES2)
|
#if defined(IMGUI_IMPL_OPENGL_ES2)
|
||||||
|
@ -26,6 +27,7 @@ static const char* NAME = "Neko Player";
|
||||||
#endif
|
#endif
|
||||||
using namespace std::filesystem;
|
using namespace std::filesystem;
|
||||||
using namespace std::numbers;
|
using namespace std::numbers;
|
||||||
|
using std::string;
|
||||||
static float accent_color = 280.0;
|
static float accent_color = 280.0;
|
||||||
float GetHue(ImVec4 rgba){
|
float GetHue(ImVec4 rgba){
|
||||||
float r = rgba.x, g = rgba.y, b = rgba.z;
|
float r = rgba.x, g = rgba.y, b = rgba.z;
|
||||||
|
@ -83,6 +85,39 @@ void UpdateStyle(bool dark) {
|
||||||
change_accent_color(color, accent_color);
|
change_accent_color(color, accent_color);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
string PadZeros(string input, size_t required_length) {
|
||||||
|
return std::string(required_length - std::min(required_length, input.length()), '0') + input;
|
||||||
|
}
|
||||||
|
uint8_t TimeToComponentCount(double time_code) {
|
||||||
|
int seconds = (int)time_code;
|
||||||
|
int minutes = seconds / 60;
|
||||||
|
seconds -= minutes * 60;
|
||||||
|
int hours = minutes / 60;
|
||||||
|
minutes -= hours * 60;
|
||||||
|
if (hours > 0) {
|
||||||
|
return 3;
|
||||||
|
} else if (minutes > 0) {
|
||||||
|
return 2;
|
||||||
|
} else {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
string TimeToString(double time_code, uint8_t min_components = 1) {
|
||||||
|
uint8_t components = std::max(TimeToComponentCount(time_code), min_components);
|
||||||
|
int seconds = (int)time_code;
|
||||||
|
int minutes = seconds / 60;
|
||||||
|
seconds -= minutes * 60;
|
||||||
|
int hours = minutes / 60;
|
||||||
|
minutes -= hours * 60;
|
||||||
|
string output = PadZeros(std::to_string(seconds), components < 2 ? 1 : 2);
|
||||||
|
if (components >= 2) {
|
||||||
|
output = PadZeros(std::to_string(minutes), components == 2 ? 1 : 2) + ":" + output;
|
||||||
|
}
|
||||||
|
if (components >= 3) {
|
||||||
|
output = PadZeros(std::to_string(hours), components == 3 ? 1 : 2) + ":" + output;
|
||||||
|
}
|
||||||
|
return output;
|
||||||
|
}
|
||||||
// Main code
|
// Main code
|
||||||
int main(int, char**)
|
int main(int, char**)
|
||||||
{
|
{
|
||||||
|
@ -314,7 +349,9 @@ int main(int, char**)
|
||||||
}
|
}
|
||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
ImGui::SetNextItemWidth(ImGui::GetWindowWidth() - (ImGui::GetFontSize() * 22) - (ImGui::GetStyle().FramePadding.x * 10));
|
ImGui::SetNextItemWidth(ImGui::GetWindowWidth() - (ImGui::GetFontSize() * 22) - (ImGui::GetStyle().FramePadding.x * 10));
|
||||||
if (ImGui::SliderFloat("##Seek", &position, 0.0f, playback->GetLength(), "%.0fs", ImGuiSliderFlags_NoRoundToFormat))
|
uint8_t components = TimeToComponentCount(playback->GetLength());
|
||||||
|
string time_str = TimeToString(position, components);
|
||||||
|
if (ImGui::SliderFloat("##Seek", &position, 0.0f, playback->GetLength(), time_str.c_str(), ImGuiSliderFlags_NoRoundToFormat))
|
||||||
playback->Seek(position);
|
playback->Seek(position);
|
||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
if (ImGui::Button(ICON_FK_STOP "##Stop")) {
|
if (ImGui::Button(ICON_FK_STOP "##Stop")) {
|
||||||
|
@ -339,7 +376,7 @@ int main(int, char**)
|
||||||
min_size.x = ImGui::GetFontSize() * 18;
|
min_size.x = ImGui::GetFontSize() * 18;
|
||||||
min_size.y = (ImGui::GetStyle().FramePadding.y * 5) + (ImGui::GetFontSize() * 5);
|
min_size.y = (ImGui::GetStyle().FramePadding.y * 5) + (ImGui::GetFontSize() * 5);
|
||||||
ImVec2 max_size;
|
ImVec2 max_size;
|
||||||
max_size.x = 99999999999;
|
max_size.x = 99999997952; // The compiler says that if this were just 9s it would be turned into this anyways.
|
||||||
max_size.y = min_size.y;
|
max_size.y = min_size.y;
|
||||||
ImGui::SetNextWindowSizeConstraints(min_size, max_size);
|
ImGui::SetNextWindowSizeConstraints(min_size, max_size);
|
||||||
ImGui::Begin("Preferences...", &prefs_window);
|
ImGui::Begin("Preferences...", &prefs_window);
|
||||||
|
|
|
@ -5,7 +5,7 @@ project('neko-player', ['c', 'cpp'],
|
||||||
if get_option('debug')
|
if get_option('debug')
|
||||||
add_global_arguments('-DDEBUG', language: 'cpp')
|
add_global_arguments('-DDEBUG', language: 'cpp')
|
||||||
endif
|
endif
|
||||||
raudio_lib = static_library('raudio', 'raudio/src/raudio.c', c_args: ['-DRAUDIO_STANDALONE', '-DSUPPORT_MODULE_RAUDIO', '-DSUPPORT_FILEFORMAT_WAV', '-DSUPPORT_FILEFORMAT_OGG', '-DSUPPORT_FILEFORMAT_MP3', '-DSUPPORT_FILEFORMAT_QOA', '-DSUPPORT_FILEFORMAT_FLAC', '-DSUPPORT_FILEFORMAT_XM', '-DSUPPORT_FILEFORMAT_MOD'])
|
raudio_lib = static_library('raudio', 'raudio/src/raudio.c', c_args: ['-DRAUDIO_STANDALONE', '-DSUPPORT_MODULE_RAUDIO', '-DSUPPORT_FILEFORMAT_WAV', '-DSUPPORT_FILEFORMAT_OGG', '-DSUPPORT_FILEFORMAT_MP3', '-DSUPPORT_FILEFORMAT_QOA', '-DSUPPORT_FILEFORMAT_FLAC', '-DSUPPORT_FILEFORMAT_XM', '-DSUPPORT_FILEFORMAT_MOD', '-w'])
|
||||||
raudio_include = include_directories('raudio/src')
|
raudio_include = include_directories('raudio/src')
|
||||||
raudio_dep = declare_dependency(include_directories: raudio_include, link_with: raudio_lib)
|
raudio_dep = declare_dependency(include_directories: raudio_include, link_with: raudio_lib)
|
||||||
deps = [
|
deps = [
|
||||||
|
|
Loading…
Reference in a new issue