Updated behavior of TimelineSlider

This commit is contained in:
brunoherbelin
2020-03-09 21:57:11 +01:00
parent 1d97b6e445
commit 26b1d79478
3 changed files with 52 additions and 23 deletions

View File

@@ -100,12 +100,13 @@ bool ImGuiToolkit::TimelineSlider(const char* label, guint64 *time, guint64 begi
static guint64 optimal_tick_marks[] = { 100 * MILISECOND, 500 * MILISECOND, 1 * SECOND, 2 * SECOND, 5 * SECOND, 10 * SECOND, 20 * SECOND, 1 * MINUTE, 2 * MINUTE, 5 * MINUTE, 10 * MINUTE, 60 * MINUTE };
bool value_changed = false;
bool value_return = false;
// get window
ImGuiWindow* window = ImGui::GetCurrentWindow();
if (window->SkipItems)
return value_changed;
if (window->SkipItems) {
return value_return;
}
// get style
const ImGuiStyle& style = ImGui::GetStyle();
@@ -119,7 +120,7 @@ bool ImGuiToolkit::TimelineSlider(const char* label, guint64 *time, guint64 begi
ImRect bbox(pos, pos + size);
ImGui::ItemSize(size, style.FramePadding.y);
if (!ImGui::ItemAdd(bbox, id))
return value_changed;
return value_return;
// cursor size
const float cursor_scale = 1.f;
@@ -138,6 +139,7 @@ bool ImGuiToolkit::TimelineSlider(const char* label, guint64 *time, guint64 begi
ImGui::SetFocusID(id, window);
ImGui::FocusWindow(window);
}
value_return = hovered && (clicked || g.IO.MouseDownDuration[0] > 0.f);
}
// Render bounding box
@@ -215,7 +217,7 @@ bool ImGuiToolkit::TimelineSlider(const char* label, guint64 *time, guint64 begi
float time_slider = time_;
float time_zero = 0.f;
float time_end = 1.f;
value_changed = ImGui::SliderBehavior(slider_bbox, id, ImGuiDataType_Float, &time_slider, &time_zero,
bool value_changed = ImGui::SliderBehavior(slider_bbox, id, ImGuiDataType_Float, &time_slider, &time_zero,
&time_end, "%.2f", 1.f, ImGuiSliderFlags_None, &grab_bb);
if (value_changed){
//ImGuiToolkit::Log("slider %f %ld \n", time_slider, static_cast<guint64> ( static_cast<double>(time_slider) * static_cast<double>(duration) ));
@@ -233,7 +235,7 @@ bool ImGuiToolkit::TimelineSlider(const char* label, guint64 *time, guint64 begi
pos = ImLerp(timeline_bbox.GetTL(), timeline_bbox.GetTR(), time_) - ImVec2(cursor_width * 0.5f, 0.f);
ImGui::RenderArrow(window->DrawList, pos, color, ImGuiDir_Up, cursor_scale);
return value_changed;
return value_return;
}

View File

@@ -13,7 +13,8 @@ namespace ImGuiToolkit
void ShowIconsWindow(bool* p_open);
void ToggleButton( const char* label, bool& toggle );
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 begin, guint64 end, guint64 duration, guint64 step);
bool TimelineSlider(const char* label, guint64 *time,
guint64 begin, guint64 end, guint64 duration, guint64 step);
// fonts from ressources 'fonts/'
typedef enum {
@@ -36,4 +37,4 @@ namespace ImGuiToolkit
std::string DateTime();
};
#endif // __IMGUI_TOOLKIT_H_
#endif // __IMGUI_TOOLKIT_H_

View File

@@ -213,26 +213,34 @@ void drawMediaPlayer()
ImVec2 imagesize ( width, width / testmedia.AspectRatio());
ImGui::Image((void*)(intptr_t)testmedia.Texture(), imagesize);
if (ImGuiToolkit::ButtonIcon(17, 7)) testmedia.Rewind();
if (ImGui::Button(ICON_FA_FAST_BACKWARD))
testmedia.Rewind();
ImGui::SameLine(0, spacing);
if (testmedia.isPlaying()) {
// if (ImGuiToolkit::ButtonIcon(2, 8))
static bool media_playing = testmedia.isPlaying();
// display buttons Play/Stop depending on current playing state
if (media_playing) {
if (ImGui::Button(ICON_FA_STOP " Stop") )
testmedia.Play(false);
ImGui::SameLine(0, spacing);
ImGui::PushButtonRepeat(true);
// if (ImGui::Button(ICON_FA_FAST_FORWARD))
if (ImGuiToolkit::ButtonIcon(14, 7))
{
if (ImGui::Button(ICON_FA_FORWARD))
testmedia.FastForward ();
}
ImGui::PopButtonRepeat();
} else {
// if (ImGuiToolkit::ButtonIcon(9, 7))
}
else {
if (ImGui::Button(ICON_FA_PLAY " Play") )
testmedia.Play(true);
ImGui::SameLine(0, spacing);
if (ImGuiToolkit::ButtonIcon(8, 0)) testmedia.SeekNextFrame();
ImGui::PushButtonRepeat(true);
if (ImGui::Button(ICON_FA_STEP_FORWARD))
testmedia.SeekNextFrame();
ImGui::PopButtonRepeat();
}
ImGui::SameLine(0, spacing * 2.f);
@@ -264,15 +272,33 @@ void drawMediaPlayer()
//ImGuiToolkit::Bar(0.6f, 0.1, 0.8, 0.0, 1.0, "time", true);
guint64 t = testmedia.Position();
guint64 current_t = testmedia.Position();
guint64 t = current_t;
guint64 begin = testmedia.Duration() / 5;
guint64 end = 4 * testmedia.Duration() / 5;
if (ImGuiToolkit::TimelineSlider( "timeline", &t, begin, end, testmedia.Duration(), testmedia.FrameDuration()) )
{
static bool slider_was_pressed = false;
bool slider_pressed = ImGuiToolkit::TimelineSlider( "timeline", &t, begin, end,
testmedia.Duration(), testmedia.FrameDuration());
// change status only
if (slider_pressed != slider_was_pressed) {
// if was playing, pause during slider press
if ( media_playing )
testmedia.Play( !slider_pressed );
slider_was_pressed = slider_pressed;
}
// normal update of media status
if (!slider_was_pressed)
media_playing = testmedia.isPlaying();
// seek only if position is new
if (current_t != t)
testmedia.SeekTo(t);
}
// display info
ImGui::Text("Dimension %d x %d", testmedia.Width(), testmedia.Height());
ImGui::Text("Framerate %.2f / %.2f", testmedia.UpdateFrameRate() , testmedia.FrameRate() );