diff --git a/examples/example_hud/gui/main_window.cpp b/examples/example_hud/gui/main_window.cpp index f36db28..86b17a5 100644 --- a/examples/example_hud/gui/main_window.cpp +++ b/examples/example_hud/gui/main_window.cpp @@ -161,6 +161,12 @@ namespace imgui_desktop::gui ImGuiColorEditFlags_NoInputs); ImGui::ColorEdit4("Gradient right##lbl", reinterpret_cast(&m_label_gradient_right), ImGuiColorEditFlags_NoInputs); + if (m_animate_gradients) + { + int direction = static_cast(m_label_gradient_direction); + if (ImGui::Combo("Direction##lbl", &direction, "Right to left\0Left to right\0")) + m_label_gradient_direction = static_cast(direction); + } } ImGui::SliderFloat("Offset##lbl", &m_label_offset, 0.f, 15.f); ImGui::Checkbox("Right##lbl", &m_show_right_labels); @@ -309,7 +315,8 @@ namespace imgui_desktop::gui const Paint centered_label_color = m_gradient_label ? Paint{omath::hud::Gradient{m_label_gradient_left, m_label_gradient_right, m_label_gradient_right, m_label_gradient_left, - m_animate_gradients}} + m_animate_gradients, 4.f, 0.7f, + m_label_gradient_direction}} : Paint{omath::Color::from_rgba(255, 255, 255, 255)}; auto outline_helper = [](const bool is_outline) -> Outlined diff --git a/examples/example_hud/gui/main_window.hpp b/examples/example_hud/gui/main_window.hpp index 2ed2e7f..5eedeb5 100644 --- a/examples/example_hud/gui/main_window.hpp +++ b/examples/example_hud/gui/main_window.hpp @@ -68,6 +68,7 @@ namespace imgui_desktop::gui omath::Color m_label_gradient_right{1.f, 0.2f, 0.7f, 1.f}; bool m_outlined = true; bool m_gradient_label = true; + omath::hud::GradientDirection m_label_gradient_direction = omath::hud::GradientDirection::RightToLeft; bool m_show_right_labels = true, m_show_left_labels = true; bool m_show_top_labels = true, m_show_bottom_labels = true; bool m_show_centered_top = true, m_show_centered_bottom = true; diff --git a/include/omath/hud/gradient.hpp b/include/omath/hud/gradient.hpp index 60665a3..e2b3a25 100644 --- a/include/omath/hud/gradient.hpp +++ b/include/omath/hud/gradient.hpp @@ -3,6 +3,12 @@ namespace omath::hud { + enum class GradientDirection + { + RightToLeft, + LeftToRight, + }; + struct Gradient { Color top_left; @@ -12,5 +18,6 @@ namespace omath::hud bool animated = false; float animation_speed = 4.f; float animation_spread = 0.7f; + GradientDirection direction = GradientDirection::RightToLeft; }; } // namespace omath::hud diff --git a/source/hud/renderer_realizations/imgui_renderer.cpp b/source/hud/renderer_realizations/imgui_renderer.cpp index 980b8a8..3e00b87 100644 --- a/source/hud/renderer_realizations/imgui_renderer.cpp +++ b/source/hud/renderer_realizations/imgui_renderer.cpp @@ -103,6 +103,7 @@ namespace omath::hud if (gradient.animated) { const float animation_offset = static_cast(ImGui::GetTime()) * gradient.animation_speed; + const float direction = gradient.direction == GradientDirection::RightToLeft ? 1.f : -1.f; float cursor_x = position.x; const char* glyph_start = text.data(); const char* const text_end = text.data() + text.size(); @@ -117,7 +118,9 @@ namespace omath::hud const char* const glyph_end = glyph_start + glyph_size; const float blend = - (std::sin(animation_offset + static_cast(glyph_index) * gradient.animation_spread) + 1.f) + (std::sin(animation_offset + direction * static_cast(glyph_index) + * gradient.animation_spread) + + 1.f) * 0.5f; const auto color = gradient.top_left.value() * (1.f - blend) + gradient.top_right.value() * blend; draw_list->AddText({cursor_x, position.y}, Color{color}.to_im_color(), glyph_start, glyph_end);