mirror of
https://github.com/orange-cpp/omath.git
synced 2026-08-08 14:02:06 +00:00
Compare commits
11 Commits
fb1ffac240
..
v5.5.1
| Author | SHA1 | Date | |
|---|---|---|---|
| 335096d0c8 | |||
| 9f4cc99790 | |||
| f2ff761823 | |||
| 4cd5e8f829 | |||
| eac3adba2a | |||
| 4e413d977a | |||
| d4c86dacc7 | |||
| 945f80241c | |||
| 238d6aef4e | |||
| feb26e01c6 | |||
| 2c6d7c2dfa |
@@ -245,72 +245,37 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
./out/Debug/unit_tests.exe
|
./out/Debug/unit_tests.exe
|
||||||
|
|
||||||
- name: Process Coverage (llvm-profdata & llvm-cov)
|
- name: Process and render coverage
|
||||||
if: ${{ matrix.triplet == 'x64-windows' }}
|
if: ${{ matrix.triplet == 'x64-windows' }}
|
||||||
shell: pwsh
|
shell: pwsh
|
||||||
run: |
|
run: |
|
||||||
$BUILD_DIR = "cmake-build/build/${{ matrix.preset }}"
|
$buildDir = "cmake-build/build/${{ matrix.preset }}"
|
||||||
$EXE_PATH = "./out/Debug/unit_tests.exe"
|
$exePath = "./out/Debug/unit_tests.exe"
|
||||||
|
$profile = "$buildDir/unit_tests.profdata"
|
||||||
# 1. Merge raw profile data (essential step)
|
$htmlDir = "$buildDir/coverage-html"
|
||||||
|
|
||||||
& "C:/Program Files/LLVM/bin/llvm-profdata.exe" merge `
|
& "C:/Program Files/LLVM/bin/llvm-profdata.exe" merge `
|
||||||
-sparse "$BUILD_DIR/unit_tests.profraw" `
|
-sparse "$buildDir/unit_tests.profraw" `
|
||||||
-o "$BUILD_DIR/unit_tests.profdata"
|
-o $profile
|
||||||
|
|
||||||
# 2. Export to LCOV format
|
if ($LASTEXITCODE -ne 0) {
|
||||||
# NOTE: We explicitly ignore vcpkg_installed and system headers
|
exit $LASTEXITCODE
|
||||||
& "C:/Program Files/LLVM/bin/llvm-cov.exe" export "$EXE_PATH" `
|
|
||||||
-instr-profile="$BUILD_DIR/unit_tests.profdata" `
|
|
||||||
-format=lcov `
|
|
||||||
-ignore-filename-regex="vcpkg_installed|external|tests" `
|
|
||||||
> "$BUILD_DIR/lcov.info"
|
|
||||||
|
|
||||||
if (Test-Path "$BUILD_DIR/lcov.info") {
|
|
||||||
Write-Host "✅ LCOV info created at $BUILD_DIR/lcov.info"
|
|
||||||
} else {
|
|
||||||
Write-Error "Failed to create LCOV info"
|
|
||||||
exit 1
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- name: Install LCOV (for genhtml)
|
& "C:/Program Files/LLVM/bin/llvm-cov.exe" show $exePath `
|
||||||
if: ${{ matrix.triplet == 'x64-windows' }}
|
"-instr-profile=$profile" `
|
||||||
run: choco install lcov -y
|
"-format=html" `
|
||||||
|
"-output-dir=$htmlDir" `
|
||||||
|
"-ignore-filename-regex=vcpkg_installed|external|tests" `
|
||||||
|
"-show-branches=count"
|
||||||
|
|
||||||
- name: Generate HTML Report
|
if ($LASTEXITCODE -ne 0) {
|
||||||
if: ${{ matrix.triplet == 'x64-windows' }}
|
exit $LASTEXITCODE
|
||||||
shell: bash
|
}
|
||||||
run: |
|
|
||||||
BUILD_DIR="cmake-build/build/${{ matrix.preset }}"
|
|
||||||
LCOV_INFO="${BUILD_DIR}/lcov.info"
|
|
||||||
HTML_DIR="${BUILD_DIR}/coverage-html"
|
|
||||||
|
|
||||||
# Fix paths for genhtml (Perl hates backslashes)
|
if (-not (Test-Path "$htmlDir/index.html")) {
|
||||||
sed -i 's|\\|/|g' "${LCOV_INFO}"
|
throw "LLVM coverage report was not generated"
|
||||||
|
}
|
||||||
# Locate genhtml provided by 'choco install lcov'
|
|
||||||
# It is typically in ProgramData/chocolatey/lib/lcov/tools/bin
|
|
||||||
GENHTML=$(find /c/ProgramData/chocolatey -name genhtml -print -quit)
|
|
||||||
|
|
||||||
if [ -z "$GENHTML" ]; then
|
|
||||||
echo "Error: genhtml executable not found"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "Using genhtml: $GENHTML"
|
|
||||||
mkdir -p "$HTML_DIR"
|
|
||||||
|
|
||||||
# Run genhtml
|
|
||||||
# Added --demangle-cpp if your version supports it, otherwise remove it
|
|
||||||
perl "$GENHTML" \
|
|
||||||
"${LCOV_INFO}" \
|
|
||||||
--output-directory "$HTML_DIR" \
|
|
||||||
--title "OMath Coverage Report" \
|
|
||||||
--legend \
|
|
||||||
--show-details \
|
|
||||||
--branch-coverage \
|
|
||||||
--ignore-errors source
|
|
||||||
|
|
||||||
echo "✅ LCOV HTML report generated at $HTML_DIR"
|
|
||||||
|
|
||||||
- name: Upload Coverage (HTML Report)
|
- name: Upload Coverage (HTML Report)
|
||||||
if: ${{ matrix.triplet == 'x64-windows' }}
|
if: ${{ matrix.triplet == 'x64-windows' }}
|
||||||
|
|||||||
@@ -6,6 +6,17 @@ if (@OMATH_IMGUI_INTEGRATION@)
|
|||||||
find_dependency(imgui CONFIG)
|
find_dependency(imgui CONFIG)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
if (@OMATH_ENABLE_LUA@)
|
||||||
|
find_dependency(Lua)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if (@OMATH_ENABLE_HOOKING@)
|
||||||
|
find_dependency(safetyhook CONFIG)
|
||||||
|
if (NOT WIN32 AND (UNIX AND NOT APPLE))
|
||||||
|
find_dependency(OpenGL)
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
# Load the targets for the omath library
|
# Load the targets for the omath library
|
||||||
include("${CMAKE_CURRENT_LIST_DIR}/omathTargets.cmake")
|
include("${CMAKE_CURRENT_LIST_DIR}/omathTargets.cmake")
|
||||||
check_required_components(omath)
|
check_required_components(omath)
|
||||||
|
|||||||
@@ -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);
|
||||||
@@ -237,6 +243,44 @@ namespace imgui_desktop::gui
|
|||||||
const auto* vp = ImGui::GetMainViewport();
|
const auto* vp = ImGui::GetMainViewport();
|
||||||
const DashedBar dbar{m_bar_color, m_bar_outline_color, m_bar_bg_color, m_bar_width,
|
const DashedBar dbar{m_bar_color, m_bar_outline_color, m_bar_bg_color, m_bar_width,
|
||||||
m_bar_value, m_bar_dash_len, m_bar_dash_gap, m_bar_offset};
|
m_bar_value, m_bar_dash_len, m_bar_dash_gap, m_bar_offset};
|
||||||
|
const float entity_height = m_entity_bottom_y - m_entity_top_y;
|
||||||
|
const float entity_half_width = entity_height / m_entity_aspect;
|
||||||
|
const auto joint = [&](const float x, const float y)
|
||||||
|
{
|
||||||
|
return omath::Vector2<float>{m_entity_x + (x * 2.f - 1.f) * entity_half_width,
|
||||||
|
m_entity_top_y + y * entity_height};
|
||||||
|
};
|
||||||
|
const auto head = joint(0.5f, 0.1f);
|
||||||
|
const auto neck = joint(0.5f, 0.22f);
|
||||||
|
const auto torso = joint(0.5f, 0.5f);
|
||||||
|
const auto left_shoulder = joint(0.3f, 0.25f);
|
||||||
|
const auto right_shoulder = joint(0.7f, 0.25f);
|
||||||
|
const auto left_elbow = joint(0.18f, 0.42f);
|
||||||
|
const auto right_elbow = joint(0.82f, 0.42f);
|
||||||
|
const auto left_hand = joint(0.1f, 0.58f);
|
||||||
|
const auto right_hand = joint(0.9f, 0.58f);
|
||||||
|
const auto left_hip = joint(0.4f, 0.55f);
|
||||||
|
const auto right_hip = joint(0.6f, 0.55f);
|
||||||
|
const auto left_knee = joint(0.36f, 0.75f);
|
||||||
|
const auto right_knee = joint(0.64f, 0.75f);
|
||||||
|
const auto left_foot = joint(0.3f, 0.95f);
|
||||||
|
const auto right_foot = joint(0.7f, 0.95f);
|
||||||
|
const std::array skeleton_bones = {
|
||||||
|
Bone{head, neck},
|
||||||
|
Bone{neck, torso},
|
||||||
|
Bone{neck, left_shoulder},
|
||||||
|
Bone{left_shoulder, left_elbow},
|
||||||
|
Bone{left_elbow, left_hand},
|
||||||
|
Bone{neck, right_shoulder},
|
||||||
|
Bone{right_shoulder, right_elbow},
|
||||||
|
Bone{right_elbow, right_hand},
|
||||||
|
Bone{torso, left_hip},
|
||||||
|
Bone{left_hip, left_knee},
|
||||||
|
Bone{left_knee, left_foot},
|
||||||
|
Bone{torso, right_hip},
|
||||||
|
Bone{right_hip, right_knee},
|
||||||
|
Bone{right_knee, right_foot},
|
||||||
|
};
|
||||||
const auto animated_color = [&](const omath::Color& color, const float hue_offset)
|
const auto animated_color = [&](const omath::Color& color, const float hue_offset)
|
||||||
{
|
{
|
||||||
if (!m_animate_gradients)
|
if (!m_animate_gradients)
|
||||||
@@ -251,7 +295,6 @@ namespace imgui_desktop::gui
|
|||||||
const auto box_gradient_bottom = animated_color(m_box_gradient_bottom, 0.5f);
|
const auto box_gradient_bottom = animated_color(m_box_gradient_bottom, 0.5f);
|
||||||
const auto red = omath::Color{1.f, 0.f, 0.f, 1.f};
|
const auto red = omath::Color{1.f, 0.f, 0.f, 1.f};
|
||||||
const auto green = omath::Color{0.f, 1.f, 0.f, 1.f};
|
const auto green = omath::Color{0.f, 1.f, 0.f, 1.f};
|
||||||
const auto bar_value_color = omath::Color{red.value() * (1.f - m_bar_value) + green.value() * m_bar_value};
|
|
||||||
const auto make_glow = [](const GlowSettings& settings) -> std::optional<Glow>
|
const auto make_glow = [](const GlowSettings& settings) -> std::optional<Glow>
|
||||||
{
|
{
|
||||||
if (!settings.enabled)
|
if (!settings.enabled)
|
||||||
@@ -263,16 +306,8 @@ namespace imgui_desktop::gui
|
|||||||
const auto bar_glow = make_glow(m_bar_glow);
|
const auto bar_glow = make_glow(m_bar_glow);
|
||||||
const auto label_glow = make_glow(m_label_glow);
|
const auto label_glow = make_glow(m_label_glow);
|
||||||
const auto canvas_glow = make_glow(m_canvas_glow);
|
const auto canvas_glow = make_glow(m_canvas_glow);
|
||||||
const Paint vertical_bar_color =
|
const BarPaint bar_color = m_gradient_bars ? BarPaint{BarGradient{red, green}} : BarPaint{m_bar_color};
|
||||||
m_gradient_bars ? Paint{omath::hud::Gradient{bar_value_color, bar_value_color, red, red}}
|
const Bar bar{bar_color, m_bar_outline_color, m_bar_bg_color, m_bar_width, m_bar_value, m_bar_offset, bar_glow};
|
||||||
: Paint{m_bar_color};
|
|
||||||
const Paint horizontal_bar_color =
|
|
||||||
m_gradient_bars ? Paint{omath::hud::Gradient{red, bar_value_color, bar_value_color, red}}
|
|
||||||
: Paint{m_bar_color};
|
|
||||||
const Bar vertical_bar{vertical_bar_color, m_bar_outline_color, m_bar_bg_color, m_bar_width,
|
|
||||||
m_bar_value, m_bar_offset, bar_glow};
|
|
||||||
const Bar horizontal_bar{horizontal_bar_color, m_bar_outline_color, m_bar_bg_color, m_bar_width,
|
|
||||||
m_bar_value, m_bar_offset, bar_glow};
|
|
||||||
const Paint box_fill = m_gradient_box_fill
|
const Paint box_fill = m_gradient_box_fill
|
||||||
? Paint{omath::hud::Gradient{box_gradient_top, box_gradient_top,
|
? Paint{omath::hud::Gradient{box_gradient_top, box_gradient_top,
|
||||||
box_gradient_bottom, box_gradient_bottom}}
|
box_gradient_bottom, box_gradient_bottom}}
|
||||||
@@ -280,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
|
||||||
@@ -299,7 +335,7 @@ namespace imgui_desktop::gui
|
|||||||
m_corner_ratio, m_box_thickness, cornered_box_glow}),
|
m_corner_ratio, m_box_thickness, cornered_box_glow}),
|
||||||
when(m_show_dashed_box, DashedBox{m_dash_color, m_dash_len, m_dash_gap, m_dash_thickness}),
|
when(m_show_dashed_box, DashedBox{m_dash_color, m_dash_len, m_dash_gap, m_dash_thickness}),
|
||||||
RightSide{
|
RightSide{
|
||||||
when(m_show_right_bar, vertical_bar),
|
when(m_show_right_bar, bar),
|
||||||
when(m_show_right_dashed_bar, dbar),
|
when(m_show_right_dashed_bar, dbar),
|
||||||
when(m_show_right_labels, Label{{0.f, 1.f, 0.f, 1.f},
|
when(m_show_right_labels, Label{{0.f, 1.f, 0.f, 1.f},
|
||||||
m_label_offset,
|
m_label_offset,
|
||||||
@@ -319,7 +355,7 @@ namespace imgui_desktop::gui
|
|||||||
m_ring_thickness, m_ring_offset}),
|
m_ring_thickness, m_ring_offset}),
|
||||||
},
|
},
|
||||||
LeftSide{
|
LeftSide{
|
||||||
when(m_show_left_bar, vertical_bar),
|
when(m_show_left_bar, bar),
|
||||||
when(m_show_left_dashed_bar, dbar),
|
when(m_show_left_dashed_bar, dbar),
|
||||||
when(m_show_left_labels,
|
when(m_show_left_labels,
|
||||||
Label{omath::Color::from_rgba(255, 128, 0, 255), m_label_offset,
|
Label{omath::Color::from_rgba(255, 128, 0, 255), m_label_offset,
|
||||||
@@ -329,7 +365,7 @@ namespace imgui_desktop::gui
|
|||||||
outline_helper(m_outlined), "Level: 42"}),
|
outline_helper(m_outlined), "Level: 42"}),
|
||||||
},
|
},
|
||||||
TopSide{
|
TopSide{
|
||||||
when(m_show_top_bar, horizontal_bar),
|
when(m_show_top_bar, bar),
|
||||||
when(m_show_top_dashed_bar, dbar),
|
when(m_show_top_dashed_bar, dbar),
|
||||||
when(m_show_centered_top,
|
when(m_show_centered_top,
|
||||||
Centered{Label{omath::Color::from_rgba(0, 255, 255, 255), m_label_offset,
|
Centered{Label{omath::Color::from_rgba(0, 255, 255, 255), m_label_offset,
|
||||||
@@ -340,7 +376,7 @@ namespace imgui_desktop::gui
|
|||||||
outline_helper(m_outlined), "*BLEEDING*"}),
|
outline_helper(m_outlined), "*BLEEDING*"}),
|
||||||
},
|
},
|
||||||
BottomSide{
|
BottomSide{
|
||||||
when(m_show_bottom_bar, horizontal_bar),
|
when(m_show_bottom_bar, bar),
|
||||||
when(m_show_bottom_dashed_bar, dbar),
|
when(m_show_bottom_dashed_bar, dbar),
|
||||||
when(m_show_centered_bottom,
|
when(m_show_centered_bottom,
|
||||||
Centered{Label{centered_label_color, m_label_offset, outline_helper(m_outlined),
|
Centered{Label{centered_label_color, m_label_offset, outline_helper(m_outlined),
|
||||||
@@ -350,7 +386,7 @@ namespace imgui_desktop::gui
|
|||||||
},
|
},
|
||||||
when(m_show_aim, AimDot{{m_entity_x, m_entity_top_y + 40.f}, m_aim_color, m_aim_radius}),
|
when(m_show_aim, AimDot{{m_entity_x, m_entity_top_y + 40.f}, m_aim_color, m_aim_radius}),
|
||||||
when(m_show_scan, ScanMarker{m_scan_color, m_scan_outline, m_scan_outline_thickness}),
|
when(m_show_scan, ScanMarker{m_scan_color, m_scan_outline, m_scan_outline_thickness}),
|
||||||
when(m_show_skeleton, Skeleton{m_skel_color, m_skel_thickness}),
|
when(m_show_skeleton, Skeleton{skeleton_bones, m_skel_color, m_skel_thickness}),
|
||||||
when(m_show_proj, ProjectileAim{{m_proj_pos_x, m_proj_pos_y},
|
when(m_show_proj, ProjectileAim{{m_proj_pos_x, m_proj_pos_y},
|
||||||
m_proj_color,
|
m_proj_color,
|
||||||
m_proj_size,
|
m_proj_size,
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|||||||
@@ -41,19 +41,19 @@ namespace omath::hud
|
|||||||
float thickness = 1.f);
|
float thickness = 1.f);
|
||||||
|
|
||||||
// ── Bars ─────────────────────────────────────────────────────────
|
// ── Bars ─────────────────────────────────────────────────────────
|
||||||
EntityOverlay& add_right_bar(const widget::Paint& color, const Color& outline_color, const Color& bg_color,
|
EntityOverlay& add_right_bar(const widget::BarPaint& color, const Color& outline_color, const Color& bg_color,
|
||||||
float width, float ratio, float offset = 5.f,
|
float width, float ratio, float offset = 5.f,
|
||||||
const std::optional<widget::Glow>& glow = std::nullopt);
|
const std::optional<widget::Glow>& glow = std::nullopt);
|
||||||
|
|
||||||
EntityOverlay& add_left_bar(const widget::Paint& color, const Color& outline_color, const Color& bg_color,
|
EntityOverlay& add_left_bar(const widget::BarPaint& color, const Color& outline_color, const Color& bg_color,
|
||||||
float width, float ratio, float offset = 5.f,
|
float width, float ratio, float offset = 5.f,
|
||||||
const std::optional<widget::Glow>& glow = std::nullopt);
|
const std::optional<widget::Glow>& glow = std::nullopt);
|
||||||
|
|
||||||
EntityOverlay& add_top_bar(const widget::Paint& color, const Color& outline_color, const Color& bg_color,
|
EntityOverlay& add_top_bar(const widget::BarPaint& color, const Color& outline_color, const Color& bg_color,
|
||||||
float height, float ratio, float offset = 5.f,
|
float height, float ratio, float offset = 5.f,
|
||||||
const std::optional<widget::Glow>& glow = std::nullopt);
|
const std::optional<widget::Glow>& glow = std::nullopt);
|
||||||
|
|
||||||
EntityOverlay& add_bottom_bar(const widget::Paint& color, const Color& outline_color, const Color& bg_color,
|
EntityOverlay& add_bottom_bar(const widget::BarPaint& color, const Color& outline_color, const Color& bg_color,
|
||||||
float height, float ratio, float offset = 5.f,
|
float height, float ratio, float offset = 5.f,
|
||||||
const std::optional<widget::Glow>& glow = std::nullopt);
|
const std::optional<widget::Glow>& glow = std::nullopt);
|
||||||
|
|
||||||
@@ -184,6 +184,7 @@ namespace omath::hud
|
|||||||
EntityOverlay& add_snap_line(const Vector2<float>& start_pos, const Color& color, float width);
|
EntityOverlay& add_snap_line(const Vector2<float>& start_pos, const Color& color, float width);
|
||||||
|
|
||||||
EntityOverlay& add_skeleton(const Color& color, float thickness = 1.f);
|
EntityOverlay& add_skeleton(const Color& color, float thickness = 1.f);
|
||||||
|
EntityOverlay& add_skeleton(std::span<const widget::Bone> bones, const Color& color, float thickness = 1.f);
|
||||||
|
|
||||||
// ── Declarative interface ─────────────────────────────────────────
|
// ── Declarative interface ─────────────────────────────────────────
|
||||||
/// Pass any combination of widget:: descriptor structs (and std::optional<W>
|
/// Pass any combination of widget:: descriptor structs (and std::optional<W>
|
||||||
@@ -272,6 +273,8 @@ namespace omath::hud
|
|||||||
void draw_canvas_glow(const widget::CanvasGlow& canvas_glow) const;
|
void draw_canvas_glow(const widget::CanvasGlow& canvas_glow) const;
|
||||||
void draw_filled_rectangle(const Vector2<float>& min, const Vector2<float>& max,
|
void draw_filled_rectangle(const Vector2<float>& min, const Vector2<float>& max,
|
||||||
const widget::Paint& paint) const;
|
const widget::Paint& paint) const;
|
||||||
|
[[nodiscard]]
|
||||||
|
static widget::Paint resolve_bar_paint(const widget::BarPaint& paint, float ratio, bool vertical);
|
||||||
void draw_dashed_line(const Vector2<float>& from, const Vector2<float>& to, const Color& color, float dash_len,
|
void draw_dashed_line(const Vector2<float>& from, const Vector2<float>& to, const Color& color, float dash_len,
|
||||||
float gap_len, float thickness) const;
|
float gap_len, float thickness) const;
|
||||||
void draw_dashed_fill(const Vector2<float>& origin, const Vector2<float>& step_dir,
|
void draw_dashed_fill(const Vector2<float>& origin, const Vector2<float>& step_dir,
|
||||||
|
|||||||
@@ -6,10 +6,14 @@
|
|||||||
#include "omath/linear_algebra/vector2.hpp"
|
#include "omath/linear_algebra/vector2.hpp"
|
||||||
#include "omath/utility/color.hpp"
|
#include "omath/utility/color.hpp"
|
||||||
#include <any>
|
#include <any>
|
||||||
|
#include <array>
|
||||||
#include <initializer_list>
|
#include <initializer_list>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
|
#include <span>
|
||||||
#include <string_view>
|
#include <string_view>
|
||||||
|
#include <type_traits>
|
||||||
#include <variant>
|
#include <variant>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
namespace omath::hud::widget
|
namespace omath::hud::widget
|
||||||
{
|
{
|
||||||
@@ -23,6 +27,32 @@ namespace omath::hud::widget
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct BarGradient
|
||||||
|
{
|
||||||
|
Color empty_color;
|
||||||
|
Color full_color;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct BarPaint : std::variant<Color, Gradient, BarGradient>
|
||||||
|
{
|
||||||
|
using std::variant<Color, Gradient, BarGradient>::variant;
|
||||||
|
|
||||||
|
constexpr BarPaint(const float red, const float green, const float blue, const float alpha)
|
||||||
|
: std::variant<Color, Gradient, BarGradient>(Color{red, green, blue, alpha})
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
BarPaint(const Paint& paint)
|
||||||
|
{
|
||||||
|
std::visit(
|
||||||
|
[this](const auto& value)
|
||||||
|
{
|
||||||
|
this->template emplace<std::decay_t<decltype(value)>>(value);
|
||||||
|
},
|
||||||
|
paint);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// ── Overloaded helper for std::visit ──────────────────────────────────────
|
// ── Overloaded helper for std::visit ──────────────────────────────────────
|
||||||
template<typename... Ts>
|
template<typename... Ts>
|
||||||
struct Overloaded : Ts...
|
struct Overloaded : Ts...
|
||||||
@@ -79,10 +109,37 @@ namespace omath::hud::widget
|
|||||||
float thickness = 1.f;
|
float thickness = 1.f;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct Bone
|
||||||
|
{
|
||||||
|
Vector2<float> start;
|
||||||
|
Vector2<float> end;
|
||||||
|
};
|
||||||
|
|
||||||
struct Skeleton
|
struct Skeleton
|
||||||
{
|
{
|
||||||
|
std::vector<Bone> bones;
|
||||||
Color color;
|
Color color;
|
||||||
float thickness = 1.f;
|
float thickness = 1.f;
|
||||||
|
|
||||||
|
Skeleton(const Color& color, const float thickness = 1.f): color(color), thickness(thickness)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
Skeleton(const std::span<const Bone> bones, const Color& color, const float thickness = 1.f)
|
||||||
|
: bones(bones.begin(), bones.end()), color(color), thickness(thickness)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
Skeleton(const std::initializer_list<Bone> bones, const Color& color, const float thickness = 1.f)
|
||||||
|
: bones(bones), color(color), thickness(thickness)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
template<std::size_t Size>
|
||||||
|
Skeleton(const std::array<Bone, Size>& bones, const Color& color, const float thickness = 1.f)
|
||||||
|
: Skeleton(std::span<const Bone>{bones}, color, thickness)
|
||||||
|
{
|
||||||
|
}
|
||||||
};
|
};
|
||||||
struct SnapLine
|
struct SnapLine
|
||||||
{
|
{
|
||||||
@@ -124,7 +181,7 @@ namespace omath::hud::widget
|
|||||||
/// A filled bar. `size` is width for left/right sides, height for top/bottom.
|
/// A filled bar. `size` is width for left/right sides, height for top/bottom.
|
||||||
struct Bar
|
struct Bar
|
||||||
{
|
{
|
||||||
Paint color;
|
BarPaint color;
|
||||||
Color outline;
|
Color outline;
|
||||||
Color bg;
|
Color bg;
|
||||||
float size;
|
float size;
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -54,9 +54,6 @@ namespace omath
|
|||||||
return {value, Length - 1};
|
return {value, Length - 1};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
template<std::size_t N>
|
|
||||||
ConstevalPattern(const char (&)[N]) -> ConstevalPattern<N>;
|
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
static std::span<std::byte>::iterator scan_for_pattern(const std::span<std::byte>& range,
|
static std::span<std::byte>::iterator scan_for_pattern(const std::span<std::byte>& range,
|
||||||
const std::string_view& pattern);
|
const std::string_view& pattern);
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ namespace omath::hud
|
|||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
EntityOverlay& EntityOverlay::add_right_bar(const widget::Paint& color, const Color& outline_color,
|
EntityOverlay& EntityOverlay::add_right_bar(const widget::BarPaint& color, const Color& outline_color,
|
||||||
const Color& bg_color, const float width, float ratio,
|
const Color& bg_color, const float width, float ratio,
|
||||||
const float offset, const std::optional<widget::Glow>& glow)
|
const float offset, const std::optional<widget::Glow>& glow)
|
||||||
{
|
{
|
||||||
@@ -85,18 +85,20 @@ namespace omath::hud
|
|||||||
const auto max_bar_height = std::abs(m_canvas.top_right_corner.y - m_canvas.bottom_right_corner.y);
|
const auto max_bar_height = std::abs(m_canvas.top_right_corner.y - m_canvas.bottom_right_corner.y);
|
||||||
|
|
||||||
const auto bar_start = Vector2<float>{m_text_cursor_right.x + offset, m_canvas.bottom_right_corner.y};
|
const auto bar_start = Vector2<float>{m_text_cursor_right.x + offset, m_canvas.bottom_right_corner.y};
|
||||||
m_renderer->add_filled_rectangle(bar_start, bar_start + Vector2<float>(width, -max_bar_height), bg_color);
|
const auto bar_min = bar_start - Vector2<float>{0.f, max_bar_height};
|
||||||
|
const auto bar_max = bar_start + Vector2<float>{width, 0.f};
|
||||||
|
const auto fill_min = bar_start - Vector2<float>{0.f, max_bar_height * ratio};
|
||||||
|
m_renderer->add_filled_rectangle(bar_min, bar_max, bg_color);
|
||||||
|
|
||||||
draw_glow_rectangle(bar_start, bar_start + Vector2<float>(width, -max_bar_height * ratio), glow);
|
draw_glow_rectangle(fill_min, bar_max, glow);
|
||||||
draw_filled_rectangle(bar_start, bar_start + Vector2<float>(width, -max_bar_height * ratio), color);
|
draw_filled_rectangle(fill_min, bar_max, resolve_bar_paint(color, ratio, true));
|
||||||
m_renderer->add_rectangle(bar_start - Vector2<float>(1.f, 0.f),
|
m_renderer->add_rectangle(bar_min, bar_max, outline_color);
|
||||||
bar_start + Vector2<float>(width, -max_bar_height), outline_color);
|
|
||||||
|
|
||||||
m_text_cursor_right.x += offset + width;
|
m_text_cursor_right.x += offset + width;
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
EntityOverlay& EntityOverlay::add_left_bar(const widget::Paint& color, const Color& outline_color,
|
EntityOverlay& EntityOverlay::add_left_bar(const widget::BarPaint& color, const Color& outline_color,
|
||||||
const Color& bg_color, const float width, float ratio,
|
const Color& bg_color, const float width, float ratio,
|
||||||
const float offset, const std::optional<widget::Glow>& glow)
|
const float offset, const std::optional<widget::Glow>& glow)
|
||||||
{
|
{
|
||||||
@@ -104,12 +106,14 @@ namespace omath::hud
|
|||||||
const auto max_bar_height = std::abs(m_canvas.top_left_corner.y - m_canvas.bottom_right_corner.y);
|
const auto max_bar_height = std::abs(m_canvas.top_left_corner.y - m_canvas.bottom_right_corner.y);
|
||||||
|
|
||||||
const auto bar_start = Vector2<float>{m_text_cursor_left.x - (offset + width), m_canvas.bottom_left_corner.y};
|
const auto bar_start = Vector2<float>{m_text_cursor_left.x - (offset + width), m_canvas.bottom_left_corner.y};
|
||||||
m_renderer->add_filled_rectangle(bar_start, bar_start + Vector2<float>(width, -max_bar_height), bg_color);
|
const auto bar_min = bar_start - Vector2<float>{0.f, max_bar_height};
|
||||||
|
const auto bar_max = bar_start + Vector2<float>{width, 0.f};
|
||||||
|
const auto fill_min = bar_start - Vector2<float>{0.f, max_bar_height * ratio};
|
||||||
|
m_renderer->add_filled_rectangle(bar_min, bar_max, bg_color);
|
||||||
|
|
||||||
draw_glow_rectangle(bar_start, bar_start + Vector2<float>(width, -max_bar_height * ratio), glow);
|
draw_glow_rectangle(fill_min, bar_max, glow);
|
||||||
draw_filled_rectangle(bar_start, bar_start + Vector2<float>(width, -max_bar_height * ratio), color);
|
draw_filled_rectangle(fill_min, bar_max, resolve_bar_paint(color, ratio, true));
|
||||||
m_renderer->add_rectangle(bar_start - Vector2<float>(1.f, 0.f),
|
m_renderer->add_rectangle(bar_min, bar_max, outline_color);
|
||||||
bar_start + Vector2<float>(width, -max_bar_height), outline_color);
|
|
||||||
|
|
||||||
m_text_cursor_left.x -= offset + width;
|
m_text_cursor_left.x -= offset + width;
|
||||||
|
|
||||||
@@ -135,7 +139,7 @@ namespace omath::hud
|
|||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
EntityOverlay& EntityOverlay::add_top_bar(const widget::Paint& color, const Color& outline_color,
|
EntityOverlay& EntityOverlay::add_top_bar(const widget::BarPaint& color, const Color& outline_color,
|
||||||
const Color& bg_color, const float height, float ratio,
|
const Color& bg_color, const float height, float ratio,
|
||||||
const float offset, const std::optional<widget::Glow>& glow)
|
const float offset, const std::optional<widget::Glow>& glow)
|
||||||
{
|
{
|
||||||
@@ -143,11 +147,14 @@ namespace omath::hud
|
|||||||
const auto max_bar_width = std::abs(m_canvas.top_left_corner.x - m_canvas.bottom_right_corner.x);
|
const auto max_bar_width = std::abs(m_canvas.top_left_corner.x - m_canvas.bottom_right_corner.x);
|
||||||
|
|
||||||
const auto bar_start = Vector2<float>{m_canvas.top_left_corner.x, m_text_cursor_top.y - offset};
|
const auto bar_start = Vector2<float>{m_canvas.top_left_corner.x, m_text_cursor_top.y - offset};
|
||||||
m_renderer->add_filled_rectangle(bar_start, bar_start + Vector2<float>(max_bar_width, -height), bg_color);
|
const auto bar_min = bar_start - Vector2<float>{0.f, height};
|
||||||
|
const auto bar_max = bar_start + Vector2<float>{max_bar_width, 0.f};
|
||||||
|
const auto fill_max = Vector2<float>{bar_start.x + max_bar_width * ratio, bar_start.y};
|
||||||
|
m_renderer->add_filled_rectangle(bar_min, bar_max, bg_color);
|
||||||
|
|
||||||
draw_glow_rectangle(bar_start, bar_start + Vector2<float>(max_bar_width * ratio, -height), glow);
|
draw_glow_rectangle(bar_min, fill_max, glow);
|
||||||
draw_filled_rectangle(bar_start, bar_start + Vector2<float>(max_bar_width * ratio, -height), color);
|
draw_filled_rectangle(bar_min, fill_max, resolve_bar_paint(color, ratio, false));
|
||||||
m_renderer->add_rectangle(bar_start, bar_start + Vector2<float>(max_bar_width, -height), outline_color);
|
m_renderer->add_rectangle(bar_min, bar_max, outline_color);
|
||||||
|
|
||||||
m_text_cursor_top.y -= offset + height;
|
m_text_cursor_top.y -= offset + height;
|
||||||
|
|
||||||
@@ -330,6 +337,14 @@ namespace omath::hud
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
EntityOverlay& EntityOverlay::add_skeleton(const std::span<const widget::Bone> bones, const Color& color,
|
||||||
|
const float thickness)
|
||||||
|
{
|
||||||
|
for (const auto& bone : bones)
|
||||||
|
m_renderer->add_line(bone.start, bone.end, color, thickness);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
void EntityOverlay::draw_dashed_line(const Vector2<float>& from, const Vector2<float>& to, const Color& color,
|
void EntityOverlay::draw_dashed_line(const Vector2<float>& from, const Vector2<float>& to, const Color& color,
|
||||||
const float dash_len, const float gap_len, const float thickness) const
|
const float dash_len, const float gap_len, const float thickness) const
|
||||||
{
|
{
|
||||||
@@ -545,7 +560,33 @@ namespace omath::hud
|
|||||||
},
|
},
|
||||||
paint);
|
paint);
|
||||||
}
|
}
|
||||||
EntityOverlay& EntityOverlay::add_bottom_bar(const widget::Paint& color, const Color& outline_color,
|
|
||||||
|
widget::Paint EntityOverlay::resolve_bar_paint(const widget::BarPaint& paint, const float ratio,
|
||||||
|
const bool vertical)
|
||||||
|
{
|
||||||
|
return std::visit(
|
||||||
|
widget::Overloaded{
|
||||||
|
[](const Color& color) -> widget::Paint
|
||||||
|
{
|
||||||
|
return color;
|
||||||
|
},
|
||||||
|
[](const Gradient& gradient) -> widget::Paint
|
||||||
|
{
|
||||||
|
return gradient;
|
||||||
|
},
|
||||||
|
[&](const widget::BarGradient& gradient) -> widget::Paint
|
||||||
|
{
|
||||||
|
const float value = std::clamp(ratio, 0.f, 1.f);
|
||||||
|
const auto current = Color{gradient.empty_color.value() * (1.f - value)
|
||||||
|
+ gradient.full_color.value() * value};
|
||||||
|
if (vertical)
|
||||||
|
return Gradient{current, current, gradient.empty_color, gradient.empty_color};
|
||||||
|
return Gradient{gradient.empty_color, current, current, gradient.empty_color};
|
||||||
|
},
|
||||||
|
},
|
||||||
|
paint);
|
||||||
|
}
|
||||||
|
EntityOverlay& EntityOverlay::add_bottom_bar(const widget::BarPaint& color, const Color& outline_color,
|
||||||
const Color& bg_color, const float height, float ratio,
|
const Color& bg_color, const float height, float ratio,
|
||||||
const float offset, const std::optional<widget::Glow>& glow)
|
const float offset, const std::optional<widget::Glow>& glow)
|
||||||
{
|
{
|
||||||
@@ -553,10 +594,13 @@ namespace omath::hud
|
|||||||
const auto max_bar_width = std::abs(m_canvas.bottom_right_corner.x - m_canvas.bottom_left_corner.x);
|
const auto max_bar_width = std::abs(m_canvas.bottom_right_corner.x - m_canvas.bottom_left_corner.x);
|
||||||
|
|
||||||
const auto bar_start = Vector2<float>{m_canvas.bottom_left_corner.x, m_text_cursor_bottom.y + offset};
|
const auto bar_start = Vector2<float>{m_canvas.bottom_left_corner.x, m_text_cursor_bottom.y + offset};
|
||||||
m_renderer->add_filled_rectangle(bar_start, bar_start + Vector2<float>(max_bar_width, height), bg_color);
|
const auto bar_min = bar_start;
|
||||||
draw_glow_rectangle(bar_start, bar_start + Vector2<float>(max_bar_width * ratio, height), glow);
|
const auto bar_max = bar_start + Vector2<float>{max_bar_width, height};
|
||||||
draw_filled_rectangle(bar_start, bar_start + Vector2<float>(max_bar_width * ratio, height), color);
|
const auto fill_max = bar_start + Vector2<float>{max_bar_width * ratio, height};
|
||||||
m_renderer->add_rectangle(bar_start, bar_start + Vector2<float>(max_bar_width, height), outline_color);
|
m_renderer->add_filled_rectangle(bar_min, bar_max, bg_color);
|
||||||
|
draw_glow_rectangle(bar_min, fill_max, glow);
|
||||||
|
draw_filled_rectangle(bar_min, fill_max, resolve_bar_paint(color, ratio, false));
|
||||||
|
m_renderer->add_rectangle(bar_min, bar_max, outline_color);
|
||||||
|
|
||||||
m_text_cursor_bottom.y += offset + height;
|
m_text_cursor_bottom.y += offset + height;
|
||||||
|
|
||||||
@@ -812,7 +856,10 @@ namespace omath::hud
|
|||||||
|
|
||||||
void EntityOverlay::dispatch(const widget::Skeleton& skeleton)
|
void EntityOverlay::dispatch(const widget::Skeleton& skeleton)
|
||||||
{
|
{
|
||||||
add_skeleton(skeleton.color, skeleton.thickness);
|
if (skeleton.bones.empty())
|
||||||
|
add_skeleton(skeleton.color, skeleton.thickness);
|
||||||
|
else
|
||||||
|
add_skeleton(skeleton.bones, skeleton.color, skeleton.thickness);
|
||||||
}
|
}
|
||||||
|
|
||||||
void EntityOverlay::dispatch(const widget::SnapLine& snap_line)
|
void EntityOverlay::dispatch(const widget::SnapLine& snap_line)
|
||||||
|
|||||||
@@ -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