mirror of
https://github.com/orange-cpp/omath.git
synced 2026-08-08 05:52:07 +00:00
added gradient dir
This commit is contained in:
@@ -161,6 +161,12 @@ namespace imgui_desktop::gui
|
|||||||
ImGuiColorEditFlags_NoInputs);
|
ImGuiColorEditFlags_NoInputs);
|
||||||
ImGui::ColorEdit4("Gradient right##lbl", reinterpret_cast<float*>(&m_label_gradient_right),
|
ImGui::ColorEdit4("Gradient right##lbl", reinterpret_cast<float*>(&m_label_gradient_right),
|
||||||
ImGuiColorEditFlags_NoInputs);
|
ImGuiColorEditFlags_NoInputs);
|
||||||
|
if (m_animate_gradients)
|
||||||
|
{
|
||||||
|
int direction = static_cast<int>(m_label_gradient_direction);
|
||||||
|
if (ImGui::Combo("Direction##lbl", &direction, "Right to left\0Left to right\0"))
|
||||||
|
m_label_gradient_direction = static_cast<omath::hud::GradientDirection>(direction);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
ImGui::SliderFloat("Offset##lbl", &m_label_offset, 0.f, 15.f);
|
ImGui::SliderFloat("Offset##lbl", &m_label_offset, 0.f, 15.f);
|
||||||
ImGui::Checkbox("Right##lbl", &m_show_right_labels);
|
ImGui::Checkbox("Right##lbl", &m_show_right_labels);
|
||||||
@@ -309,7 +315,8 @@ namespace imgui_desktop::gui
|
|||||||
const Paint centered_label_color =
|
const Paint centered_label_color =
|
||||||
m_gradient_label ? Paint{omath::hud::Gradient{m_label_gradient_left, m_label_gradient_right,
|
m_gradient_label ? Paint{omath::hud::Gradient{m_label_gradient_left, m_label_gradient_right,
|
||||||
m_label_gradient_right, m_label_gradient_left,
|
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)};
|
: Paint{omath::Color::from_rgba(255, 255, 255, 255)};
|
||||||
|
|
||||||
auto outline_helper = [](const bool is_outline) -> Outlined
|
auto outline_helper = [](const bool is_outline) -> Outlined
|
||||||
|
|||||||
@@ -68,6 +68,7 @@ namespace imgui_desktop::gui
|
|||||||
omath::Color m_label_gradient_right{1.f, 0.2f, 0.7f, 1.f};
|
omath::Color m_label_gradient_right{1.f, 0.2f, 0.7f, 1.f};
|
||||||
bool m_outlined = true;
|
bool m_outlined = true;
|
||||||
bool m_gradient_label = 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_right_labels = true, m_show_left_labels = true;
|
||||||
bool m_show_top_labels = true, m_show_bottom_labels = true;
|
bool m_show_top_labels = true, m_show_bottom_labels = true;
|
||||||
bool m_show_centered_top = true, m_show_centered_bottom = true;
|
bool m_show_centered_top = true, m_show_centered_bottom = true;
|
||||||
|
|||||||
@@ -3,6 +3,12 @@
|
|||||||
|
|
||||||
namespace omath::hud
|
namespace omath::hud
|
||||||
{
|
{
|
||||||
|
enum class GradientDirection
|
||||||
|
{
|
||||||
|
RightToLeft,
|
||||||
|
LeftToRight,
|
||||||
|
};
|
||||||
|
|
||||||
struct Gradient
|
struct Gradient
|
||||||
{
|
{
|
||||||
Color top_left;
|
Color top_left;
|
||||||
@@ -12,5 +18,6 @@ namespace omath::hud
|
|||||||
bool animated = false;
|
bool animated = false;
|
||||||
float animation_speed = 4.f;
|
float animation_speed = 4.f;
|
||||||
float animation_spread = 0.7f;
|
float animation_spread = 0.7f;
|
||||||
|
GradientDirection direction = GradientDirection::RightToLeft;
|
||||||
};
|
};
|
||||||
} // namespace omath::hud
|
} // namespace omath::hud
|
||||||
|
|||||||
@@ -103,6 +103,7 @@ namespace omath::hud
|
|||||||
if (gradient.animated)
|
if (gradient.animated)
|
||||||
{
|
{
|
||||||
const float animation_offset = static_cast<float>(ImGui::GetTime()) * gradient.animation_speed;
|
const float animation_offset = static_cast<float>(ImGui::GetTime()) * gradient.animation_speed;
|
||||||
|
const float direction = gradient.direction == GradientDirection::RightToLeft ? 1.f : -1.f;
|
||||||
float cursor_x = position.x;
|
float cursor_x = position.x;
|
||||||
const char* glyph_start = text.data();
|
const char* glyph_start = text.data();
|
||||||
const char* const text_end = text.data() + text.size();
|
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 char* const glyph_end = glyph_start + glyph_size;
|
||||||
const float blend =
|
const float blend =
|
||||||
(std::sin(animation_offset + static_cast<float>(glyph_index) * gradient.animation_spread) + 1.f)
|
(std::sin(animation_offset + direction * static_cast<float>(glyph_index)
|
||||||
|
* gradient.animation_spread)
|
||||||
|
+ 1.f)
|
||||||
* 0.5f;
|
* 0.5f;
|
||||||
const auto color = gradient.top_left.value() * (1.f - blend) + gradient.top_right.value() * blend;
|
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);
|
draw_list->AddText({cursor_x, position.y}, Color{color}.to_im_color(), glyph_start, glyph_end);
|
||||||
|
|||||||
Reference in New Issue
Block a user