mirror of
https://github.com/brunoherbelin/vimix.git
synced 2025-12-11 18:34:58 +01:00
New GUI buttons and clean media player
This commit is contained in:
111
ImGuiToolkit.cpp
111
ImGuiToolkit.cpp
@@ -1,5 +1,6 @@
|
|||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
# include <windows.h>
|
# include <windows.h>
|
||||||
@@ -24,21 +25,66 @@ unsigned int textureicons = 0;
|
|||||||
std::map <ImGuiToolkit::font_style, ImFont*>fontmap;
|
std::map <ImGuiToolkit::font_style, ImFont*>fontmap;
|
||||||
|
|
||||||
|
|
||||||
void ImGuiToolkit::OpenWebpage( const char* url )
|
void ImGuiToolkit::ButtonOpenWebpage( const char* url )
|
||||||
{
|
{
|
||||||
|
char label[512];
|
||||||
|
sprintf( label, "%s %s", ICON_FA_EXTERNAL_LINK_ALT, url );
|
||||||
|
|
||||||
|
if ( ImGui::Button(label) )
|
||||||
|
{
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
ShellExecuteA( nullptr, nullptr, url, nullptr, nullptr, 0 );
|
ShellExecuteA( nullptr, nullptr, url, nullptr, nullptr, 0 );
|
||||||
#elif defined __APPLE__
|
#elif defined __APPLE__
|
||||||
char buf[1024];
|
char buf[1024];
|
||||||
sprintf( buf, "open %s", url );
|
sprintf( buf, "open %s", url );
|
||||||
system( buf );
|
system( buf );
|
||||||
#else
|
#else
|
||||||
char buf[1024];
|
char buf[1024];
|
||||||
sprintf( buf, "xdg-open %s", url );
|
sprintf( buf, "xdg-open %s", url );
|
||||||
system( buf );
|
system( buf );
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ImGuiToolkit::ButtonToggle(const char* str_id, bool* toggle)
|
||||||
|
{
|
||||||
|
ImVec4* colors = ImGui::GetStyle().Colors;
|
||||||
|
ImVec2 p = ImGui::GetCursorScreenPos();
|
||||||
|
ImDrawList* draw_list = ImGui::GetWindowDrawList();
|
||||||
|
|
||||||
|
float height = ImGui::GetFrameHeight() * 0.75f;
|
||||||
|
float width = height * 1.6f;
|
||||||
|
float radius = height * 0.50f;
|
||||||
|
|
||||||
|
ImGui::InvisibleButton(str_id, ImVec2(width, height));
|
||||||
|
if (ImGui::IsItemClicked())
|
||||||
|
*toggle = !*toggle;
|
||||||
|
|
||||||
|
float t = *toggle ? 1.0f : 0.0f;
|
||||||
|
|
||||||
|
ImGuiContext& g = *GImGui;
|
||||||
|
float ANIM_SPEED = 0.1f;
|
||||||
|
if (g.LastActiveId == g.CurrentWindow->GetID(str_id))// && g.LastActiveIdTimer < ANIM_SPEED)
|
||||||
|
{
|
||||||
|
float t_anim = ImSaturate(g.LastActiveIdTimer / ANIM_SPEED);
|
||||||
|
t = *toggle ? (t_anim) : (1.0f - t_anim);
|
||||||
|
}
|
||||||
|
|
||||||
|
ImU32 col_bg;
|
||||||
|
if (ImGui::IsItemHovered())
|
||||||
|
col_bg = ImGui::GetColorU32(ImLerp(colors[ImGuiCol_FrameBgHovered], colors[ImGuiCol_TabHovered], t));
|
||||||
|
else
|
||||||
|
col_bg = ImGui::GetColorU32(ImLerp(colors[ImGuiCol_FrameBg], colors[ImGuiCol_TabActive], t));
|
||||||
|
|
||||||
|
draw_list->AddRectFilled(p, ImVec2(p.x + width, p.y + height), col_bg, height * 0.5f);
|
||||||
|
draw_list->AddCircleFilled(ImVec2(p.x + radius + t * (width - radius * 2.0f), p.y + radius), radius - 1.5f, IM_COL32(255, 255, 255, 250));
|
||||||
|
ImGui::SameLine(0,10);
|
||||||
|
ImGui::Text(str_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void ImGuiToolkit::Icon(int i, int j)
|
void ImGuiToolkit::Icon(int i, int j)
|
||||||
{
|
{
|
||||||
// icons.dds is a 20 x 20 grid of icons
|
// icons.dds is a 20 x 20 grid of icons
|
||||||
@@ -66,6 +112,55 @@ bool ImGuiToolkit::ButtonIcon(int i, int j)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ImGuiToolkit::ButtonIconToggle(int i, int j, int i_toggle, int j_toggle, bool* toggle)
|
||||||
|
{
|
||||||
|
bool ret = false;
|
||||||
|
ImGui::PushID( i * 20 + j + i_toggle * 20 + j_toggle);
|
||||||
|
|
||||||
|
if (*toggle) {
|
||||||
|
if ( ButtonIcon(i_toggle, j_toggle)) {
|
||||||
|
*toggle = false;
|
||||||
|
ret = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if ( ButtonIcon(i, j)) {
|
||||||
|
*toggle = true;
|
||||||
|
ret = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ImGui::PopID();
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct Sum
|
||||||
|
{
|
||||||
|
void operator()(std::pair<int, int> n) { sum += n.first * 20 + n.second; }
|
||||||
|
int sum{0};
|
||||||
|
};
|
||||||
|
|
||||||
|
bool ImGuiToolkit::ButtonIconMultistate(std::vector<std::pair<int, int> > icons, int* state)
|
||||||
|
{
|
||||||
|
bool ret = false;
|
||||||
|
Sum id = std::for_each(icons.begin(), icons.end(), Sum());
|
||||||
|
ImGui::PushID( id.sum );
|
||||||
|
|
||||||
|
int s = CLAMP(*state, 0, icons.size() - 1);
|
||||||
|
if ( ButtonIcon( icons[s].first, icons[s].second ) ){
|
||||||
|
++s;
|
||||||
|
if (s > icons.size() -1)
|
||||||
|
*state = 0;
|
||||||
|
else
|
||||||
|
*state = s;
|
||||||
|
ret = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
ImGui::PopID();
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void ImGuiToolkit::ShowIconsWindow(bool* p_open)
|
void ImGuiToolkit::ShowIconsWindow(bool* p_open)
|
||||||
{
|
{
|
||||||
if (textureicons == 0)
|
if (textureicons == 0)
|
||||||
|
|||||||
@@ -4,18 +4,25 @@
|
|||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <list>
|
#include <list>
|
||||||
|
#include <vector>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include "rsc/fonts/IconsFontAwesome5.h"
|
#include "rsc/fonts/IconsFontAwesome5.h"
|
||||||
|
|
||||||
namespace ImGuiToolkit
|
namespace ImGuiToolkit
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
// Icons from resource icon.dds
|
// Icons from resource icon.dds
|
||||||
void Icon(int i, int j);
|
void Icon(int i, int j);
|
||||||
bool ButtonIcon(int i, int j);
|
|
||||||
void ShowIconsWindow(bool* p_open);
|
void ShowIconsWindow(bool* p_open);
|
||||||
void ToggleButton( const char* label, bool& toggle );
|
|
||||||
|
// utility buttons
|
||||||
|
bool ButtonIcon(int i, int j);
|
||||||
|
bool ButtonIconToggle(int i, int j, int i_toggle, int j_toggle, bool* toggle);
|
||||||
|
bool ButtonIconMultistate(std::vector<std::pair<int, int> > icons, int* state);
|
||||||
|
void ButtonToggle( const char* label, bool* toggle );
|
||||||
|
void ButtonOpenWebpage( const char* url );
|
||||||
|
|
||||||
|
// utility sliders
|
||||||
void Bar(float value, float in, float out, float min, float max, const char* title, bool expand);
|
void Bar(float value, float in, float out, float min, float max, const char* title, bool expand);
|
||||||
bool TimelineSlider(const char* label, guint64 *time, guint64 duration, guint64 step);
|
bool TimelineSlider(const char* label, guint64 *time, guint64 duration, guint64 step);
|
||||||
bool TimelineSliderEdit(const char* label, guint64 *time, guint64 duration, guint64 step,
|
bool TimelineSliderEdit(const char* label, guint64 *time, guint64 duration, guint64 step,
|
||||||
@@ -39,7 +46,6 @@ namespace ImGuiToolkit
|
|||||||
} accent_color;
|
} accent_color;
|
||||||
void SetAccentColor(accent_color color);
|
void SetAccentColor(accent_color color);
|
||||||
|
|
||||||
void OpenWebpage( const char* url );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // __IMGUI_TOOLKIT_H_
|
#endif // __IMGUI_TOOLKIT_H_
|
||||||
|
|||||||
@@ -116,10 +116,6 @@ void ImGuiVisitor::visit(Shader &n)
|
|||||||
|
|
||||||
ImGui::PushID(n.id());
|
ImGui::PushID(n.id());
|
||||||
|
|
||||||
// if (ImGuiToolkit::ButtonIcon(14, 8)) n.color = glm::vec4(1.f, 1.f, 1.f, 1.f);
|
|
||||||
// ImGui::SameLine(0, 10);
|
|
||||||
// ImGui::ColorEdit3("Color", glm::value_ptr(n.color) ) ;
|
|
||||||
|
|
||||||
if (ImGuiToolkit::ButtonIcon(10, 2)) {
|
if (ImGuiToolkit::ButtonIcon(10, 2)) {
|
||||||
n.blending = Shader::BLEND_OPACITY;
|
n.blending = Shader::BLEND_OPACITY;
|
||||||
n.color = glm::vec4(1.f, 1.f, 1.f, 1.f);
|
n.color = glm::vec4(1.f, 1.f, 1.f, 1.f);
|
||||||
|
|||||||
@@ -536,15 +536,14 @@ static void ShowAboutOpengl(bool* p_open)
|
|||||||
ImGui::PopFont();
|
ImGui::PopFont();
|
||||||
ImGui::Separator();
|
ImGui::Separator();
|
||||||
ImGui::Text("OpenGL is the premier environment for developing portable, \ninteractive 2D and 3D graphics applications.");
|
ImGui::Text("OpenGL is the premier environment for developing portable, \ninteractive 2D and 3D graphics applications.");
|
||||||
|
ImGuiToolkit::ButtonOpenWebpage("https://www.opengl.org");
|
||||||
if ( ImGui::Button( ICON_FA_EXTERNAL_LINK_ALT " https://www.opengl.org") )
|
|
||||||
ImGuiToolkit::OpenWebpage("https://www.opengl.org");
|
|
||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
|
|
||||||
// static std::string allextensions( glGetString(GL_EXTENSIONS) );
|
// static std::string allextensions( glGetString(GL_EXTENSIONS) );
|
||||||
|
|
||||||
static bool show_opengl_info = false;
|
static bool show_opengl_info = false;
|
||||||
ImGui::Checkbox( "Show details " ICON_FA_CHEVRON_DOWN, &show_opengl_info);
|
ImGuiToolkit::ButtonIconToggle(10,0,13,14,&show_opengl_info);
|
||||||
|
ImGui::SameLine(); ImGui::Text("Details");
|
||||||
if (show_opengl_info)
|
if (show_opengl_info)
|
||||||
{
|
{
|
||||||
ImGui::Separator();
|
ImGui::Separator();
|
||||||
@@ -604,13 +603,12 @@ static void ShowAboutGStreamer(bool* p_open)
|
|||||||
ImGui::Separator();
|
ImGui::Separator();
|
||||||
ImGui::Text("A flexible, fast and multiplatform multimedia framework.");
|
ImGui::Text("A flexible, fast and multiplatform multimedia framework.");
|
||||||
ImGui::Text("GStreamer is licensed under the LGPL License.");
|
ImGui::Text("GStreamer is licensed under the LGPL License.");
|
||||||
|
ImGuiToolkit::ButtonOpenWebpage("https://gstreamer.freedesktop.org/");
|
||||||
if ( ImGui::Button( ICON_FA_EXTERNAL_LINK_ALT " https://gstreamer.freedesktop.org") )
|
|
||||||
ImGuiToolkit::OpenWebpage("https://gstreamer.freedesktop.org/");
|
|
||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
|
|
||||||
static bool show_config_info = false;
|
static bool show_config_info = false;
|
||||||
ImGui::Checkbox("Show details " ICON_FA_CHEVRON_DOWN , &show_config_info);
|
ImGuiToolkit::ButtonIconToggle(10,0,13,14,&show_config_info);
|
||||||
|
ImGui::SameLine(); ImGui::Text("Details");
|
||||||
if (show_config_info)
|
if (show_config_info)
|
||||||
{
|
{
|
||||||
ImGui::Separator();
|
ImGui::Separator();
|
||||||
@@ -691,11 +689,14 @@ void MainWindow::Render()
|
|||||||
{
|
{
|
||||||
if (ImGui::BeginMenu("File"))
|
if (ImGui::BeginMenu("File"))
|
||||||
{
|
{
|
||||||
if (ImGui::MenuItem( ICON_FA_FILE " New")) {
|
|
||||||
|
|
||||||
}
|
|
||||||
if (ImGui::MenuItem( ICON_FA_FILE_UPLOAD " Open", "Ctrl+O")) {
|
if (ImGui::MenuItem( ICON_FA_FILE_UPLOAD " Open", "Ctrl+O")) {
|
||||||
UserInterface::manager().OpenFileMedia();
|
UserInterface::manager().OpenFileMedia();
|
||||||
|
}
|
||||||
|
if (ImGui::MenuItem( ICON_FA_FILE_DOWNLOAD " Save", "Ctrl+S")) {
|
||||||
|
UserInterface::manager().OpenFileMedia();
|
||||||
|
}
|
||||||
|
if (ImGui::MenuItem( ICON_FA_FILE " Close", "Ctrl+W")) {
|
||||||
|
|
||||||
}
|
}
|
||||||
if (ImGui::MenuItem( ICON_FA_POWER_OFF " Quit", "Ctrl+Q")) {
|
if (ImGui::MenuItem( ICON_FA_POWER_OFF " Quit", "Ctrl+Q")) {
|
||||||
Rendering::manager().Close();
|
Rendering::manager().Close();
|
||||||
@@ -736,7 +737,10 @@ void MainWindow::Render()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// content
|
// content
|
||||||
// ImGuiToolkit::Icon(7, 1);
|
// static bool on;
|
||||||
|
// ImGuiToolkit::ButtonToggle("Active", &on);
|
||||||
|
// ImGui::SameLine();
|
||||||
|
// ImGuiToolkit::ButtonIconToggle(12,11,14,1,&on);
|
||||||
// ImGui::SameLine(0, 10);
|
// ImGui::SameLine(0, 10);
|
||||||
// ImGuiToolkit::PushFont(ImGuiToolkit::FONT_ITALIC);
|
// ImGuiToolkit::PushFont(ImGuiToolkit::FONT_ITALIC);
|
||||||
// ImGui::Text("This is some useful text."); // Display some text (you can use a format strings too)
|
// ImGui::Text("This is some useful text."); // Display some text (you can use a format strings too)
|
||||||
|
|||||||
51
main.cpp
51
main.cpp
@@ -43,20 +43,6 @@
|
|||||||
|
|
||||||
#define PI 3.14159265358979323846
|
#define PI 3.14159265358979323846
|
||||||
|
|
||||||
// test scene
|
|
||||||
|
|
||||||
//// ("file:///home/bhbn/Videos/MOV001.MOD");
|
|
||||||
//// ("file:///home/bhbn/Videos/TestFormats/Commodore64GameReviewMoondust.flv");
|
|
||||||
//// ("file:///home/bhbn/Videos/fish.mp4");
|
|
||||||
//// ("file:///home/bhbn/Videos/jean/Solitude1080p.mov");
|
|
||||||
//// ("file:///home/bhbn/Videos/TearsOfSteel_720p_h265.mkv");
|
|
||||||
//// ("file:///home/bhbn/Videos/TestFormats/_h264GoldenLamps.mkv");
|
|
||||||
//// ("file:///home/bhbn/Videos/TestEncoding/vpxvp9high.webm");
|
|
||||||
//// ("file:///home/bhbn/Videos/iss.mov");
|
|
||||||
//// ("file:///home/bhbn/Videos//iss.mov");
|
|
||||||
//// ("file:///Users/Herbelin/Movies/mp2test.mpg");
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void drawMediaPlayer()
|
void drawMediaPlayer()
|
||||||
{
|
{
|
||||||
@@ -95,7 +81,7 @@ void drawMediaPlayer()
|
|||||||
ImGui::SameLine(0, spacing);
|
ImGui::SameLine(0, spacing);
|
||||||
|
|
||||||
// remember playing mode of the GUI
|
// remember playing mode of the GUI
|
||||||
static bool media_playing_mode = mp->isPlaying();
|
bool media_playing_mode = mp->isPlaying();
|
||||||
|
|
||||||
// display buttons Play/Stop depending on current playing mode
|
// display buttons Play/Stop depending on current playing mode
|
||||||
if (media_playing_mode) {
|
if (media_playing_mode) {
|
||||||
@@ -121,31 +107,26 @@ void drawMediaPlayer()
|
|||||||
ImGui::PopButtonRepeat();
|
ImGui::PopButtonRepeat();
|
||||||
}
|
}
|
||||||
|
|
||||||
ImGui::SameLine(0, spacing * 2.f);
|
ImGui::SameLine(0, spacing * 4.f);
|
||||||
ImGui::Dummy(ImVec2(width - 700.0, 0)); // right align
|
// ImGui::Dummy(ImVec2(width - 700.0, 0)); // right align
|
||||||
|
|
||||||
static int current_loop = 1;
|
static int current_loop = 0;
|
||||||
static const char* loop_names[3] = { "Stop", "Rewind", "Bounce" };
|
static std::vector< std::pair<int, int> > iconsloop = { {0,15}, {1,15}, {19,14} };
|
||||||
const char* current_loop_name = loop_names[current_loop];
|
current_loop = (int) mp->loop();
|
||||||
ImGui::SameLine(0, spacing);
|
if ( ImGuiToolkit::ButtonIconMultistate(iconsloop, ¤t_loop) )
|
||||||
if (current_loop == 0) ImGuiToolkit::Icon(0, 15);
|
|
||||||
else if (current_loop == 1) ImGuiToolkit::Icon(1, 15);
|
|
||||||
else ImGuiToolkit::Icon(19, 14);
|
|
||||||
ImGui::SameLine(0, spacing);
|
|
||||||
ImGui::SetNextItemWidth(90);
|
|
||||||
if ( ImGui::SliderInt("", ¤t_loop, 0, 2, current_loop_name) )
|
|
||||||
mp->setLoop( (MediaPlayer::LoopMode) current_loop );
|
mp->setLoop( (MediaPlayer::LoopMode) current_loop );
|
||||||
|
|
||||||
float speed = static_cast<float>(mp->playSpeed());
|
float speed = static_cast<float>(mp->playSpeed());
|
||||||
ImGui::SameLine(0, spacing);
|
ImGui::SameLine(0, spacing);
|
||||||
ImGui::SetNextItemWidth(270);
|
ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x - 40.0);
|
||||||
// ImGui::SetNextItemWidth(width - 90.0);
|
// ImGui::SetNextItemWidth(width - 90.0);
|
||||||
if (ImGui::SliderFloat( "Speed", &speed, -10.f, 10.f, "x %.1f", 2.f))
|
if (ImGui::DragFloat( "##Speed", &speed, 0.01f, -10.f, 10.f, "Speed x %.1f", 2.f))
|
||||||
mp->setPlaySpeed( static_cast<double>(speed) );
|
mp->setPlaySpeed( static_cast<double>(speed) );
|
||||||
ImGui::SameLine(0, spacing);
|
ImGui::SameLine(0, spacing);
|
||||||
if (ImGuiToolkit::ButtonIcon(19, 15)) {
|
if (ImGuiToolkit::ButtonIcon(12, 14)) {
|
||||||
speed = 1.f;
|
speed = 1.f;
|
||||||
mp->setPlaySpeed( static_cast<double>(speed) );
|
mp->setPlaySpeed( static_cast<double>(speed) );
|
||||||
|
mp->setLoop( MediaPlayer::LOOP_REWIND );
|
||||||
}
|
}
|
||||||
|
|
||||||
guint64 current_t = mp->position();
|
guint64 current_t = mp->position();
|
||||||
@@ -174,8 +155,8 @@ void drawMediaPlayer()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// display info
|
// display info
|
||||||
ImGui::Text("%s %d x %d", mp->codec().c_str(), mp->width(), mp->height());
|
// ImGui::Text("%s %d x %d", mp->codec().c_str(), mp->width(), mp->height());
|
||||||
ImGui::Text("Framerate %.2f / %.2f", mp->updateFrameRate() , mp->frameRate() );
|
// ImGui::Text("Framerate %.2f / %.2f", mp->updateFrameRate() , mp->frameRate() );
|
||||||
|
|
||||||
ImGui::End();
|
ImGui::End();
|
||||||
}
|
}
|
||||||
@@ -183,7 +164,7 @@ void drawMediaPlayer()
|
|||||||
|
|
||||||
void drawScene()
|
void drawScene()
|
||||||
{
|
{
|
||||||
Mixer::manager().update();
|
// Mixer::manager().update();
|
||||||
|
|
||||||
Mixer::manager().draw();
|
Mixer::manager().draw();
|
||||||
|
|
||||||
@@ -256,8 +237,6 @@ int main(int, char**)
|
|||||||
Rendering::manager().PushFrontDrawCallback(drawScene);
|
Rendering::manager().PushFrontDrawCallback(drawScene);
|
||||||
|
|
||||||
// init elements to the scene
|
// init elements to the scene
|
||||||
//testnode3.getShader()->blending = Shader::BLEND_OPACITY;
|
|
||||||
|
|
||||||
Mixer::manager().createSourceMedia("file:///home/bhbn/Videos/iss.mov");
|
Mixer::manager().createSourceMedia("file:///home/bhbn/Videos/iss.mov");
|
||||||
Mixer::manager().createSourceMedia("file:///home/bhbn/Videos/fish.mp4");
|
Mixer::manager().createSourceMedia("file:///home/bhbn/Videos/fish.mp4");
|
||||||
|
|
||||||
@@ -282,6 +261,8 @@ int main(int, char**)
|
|||||||
///
|
///
|
||||||
while ( Rendering::manager().isActive() )
|
while ( Rendering::manager().isActive() )
|
||||||
{
|
{
|
||||||
|
Mixer::manager().update();
|
||||||
|
|
||||||
Rendering::manager().Draw();
|
Rendering::manager().Draw();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user