From 9da19582b5feb93258cc4e71fea05cd8f93d7588 Mon Sep 17 00:00:00 2001 From: orange Date: Fri, 13 Mar 2026 20:51:59 +0300 Subject: [PATCH] added files --- include/omath/hud/canvas_box.hpp | 23 ++++++ include/omath/hud/entity_overlay.hpp | 72 +++++++++++++++++++ include/omath/hud/hud_renderer_interface.hpp | 27 +++++++ .../renderer_realizations/imgui_renderer.hpp | 20 ++++++ source/hud/canvas_box.cpp | 27 +++++++ source/hud/entity_overlay.cpp | 9 +++ .../renderer_realizations/imgui_renderer.cpp | 9 +++ 7 files changed, 187 insertions(+) create mode 100644 include/omath/hud/canvas_box.hpp create mode 100644 include/omath/hud/entity_overlay.hpp create mode 100644 include/omath/hud/hud_renderer_interface.hpp create mode 100644 include/omath/hud/renderer_realizations/imgui_renderer.hpp create mode 100644 source/hud/canvas_box.cpp create mode 100644 source/hud/entity_overlay.cpp create mode 100644 source/hud/renderer_realizations/imgui_renderer.cpp diff --git a/include/omath/hud/canvas_box.hpp b/include/omath/hud/canvas_box.hpp new file mode 100644 index 0000000..021a775 --- /dev/null +++ b/include/omath/hud/canvas_box.hpp @@ -0,0 +1,23 @@ +// +// Created by orange on 13.03.2026. +// +#pragma once +#include "omath/linear_algebra/vector2.hpp" + +namespace omath::hud +{ + class CanvasBox final + { + public: + CanvasBox(Vector2 top, Vector2 bottom, float ratio = 4.f); + + [[nodiscard]] + std::array, 4> as_array() const; + + Vector2 top_left_corner; + Vector2 top_right_corner; + + Vector2 bottom_left_corner; + Vector2 bottom_right_corner; + }; +} // namespace omath::hud \ No newline at end of file diff --git a/include/omath/hud/entity_overlay.hpp b/include/omath/hud/entity_overlay.hpp new file mode 100644 index 0000000..fd120e1 --- /dev/null +++ b/include/omath/hud/entity_overlay.hpp @@ -0,0 +1,72 @@ +// +// Created by orange on 13.03.2026. +// +#pragma once +#include "canvas_box.hpp" +#include "hud_renderer_interface.hpp" +#include "omath/linear_algebra/vector2.hpp" +#include "omath/utility/color.hpp" +#include +#include +namespace omath::hud +{ + enum class SnapLineStartPosition + { + SCREEN_BOTTOM, + SCREEN_TOP, + SCREEN_CENTER, + }; + class EntityOverlay + { + public: + EntityOverlay(const Vector2& top, const Vector2& bottom, + const std::shared_ptr& renderer); + + void add_2d_box(const Color& box_color, const Color& fill_color = Color{0.f, 0.f, 0.f, 0.f}, + float thickness = 1.f) const; + + void add_cornered_2d_box(const Color& box_color, const Color& fill_color = Color{0.f, 0.f, 0.f, 0.f}, + float corner_ratio_len = 0.2f, float thickness = 1.f) const; + + void add_right_bar(const Color& color, const Color& outline_color, const Color& bg_color, float width, + float ratio, float offset = 5.f); + + void add_left_bar(const Color& color, const Color& outline_color, const Color& bg_color, float width, + float ratio, float offset = 5.f) const; + + template + void add_right_label(const Color& color, const float offset, const bool outlined, + std::format_string fmt, Args&&... args) + { + const std::string label = std::vformat(fmt.get(), std::make_format_args(args...)); + + add_right_label(color, offset, outlined, std::string_view{label}); + } + + void add_right_label(const Color& color, float offset, bool outlined, const std::string_view& text); + + template + void add_top_label(const Color& color, const float offset, const bool outlined, std::format_string fmt, + Args&&... args) + { + const std::string label = std::vformat(fmt.get(), std::make_format_args(args...)); + + add_top_label(color, offset, outlined, std::string_view{label}); + } + + void add_top_label(const Color& color, float offset, bool outlined, std::string_view text); + + void add_top_bar(const Color& color, const Color& outline_color, const Color& bg_color, float height, + float ratio, float offset = 5.f); + + void add_snap_line(const SnapLineStartPosition& start_pos, const Color& color, float width); + + private: + static void draw_outlined_text(const Vector2& position, const Color& color, + const std::string_view& text); + CanvasBox m_canvas; + Vector2 m_text_cursor_right; + Vector2 m_text_cursor_top; + std::shared_ptr renderer; + }; +} // namespace omath::hud \ No newline at end of file diff --git a/include/omath/hud/hud_renderer_interface.hpp b/include/omath/hud/hud_renderer_interface.hpp new file mode 100644 index 0000000..4891e1e --- /dev/null +++ b/include/omath/hud/hud_renderer_interface.hpp @@ -0,0 +1,27 @@ +// +// Created by orange on 13.03.2026. +// +#pragma once +#include "omath/linear_algebra/vector2.hpp" +#include "omath/utility/color.hpp" + +namespace omath::hud +{ + class HudRendererInterface + { + public: + virtual ~HudRendererInterface() = default; + virtual void add_line(const Vector2& line_start, const Vector2& line_end, const Color& color, + float thickness) = 0; + + virtual void add_polyline(const std::span>& vertexes, float thickness) = 0; + + virtual void add_filled_polyline(const std::span>& vertexes, float thickness) = 0; + + virtual void add_rectangle(const Vector2& min, const Vector2& max, const Color& color) = 0; + + virtual void add_filled_rectangle(const Vector2& min, const Vector2& max, const Color& color) = 0; + + virtual void add_text(const Vector2& position, const Color& color, const std::string_view& text) = 0; + }; +} // namespace omath::hud diff --git a/include/omath/hud/renderer_realizations/imgui_renderer.hpp b/include/omath/hud/renderer_realizations/imgui_renderer.hpp new file mode 100644 index 0000000..3e0d608 --- /dev/null +++ b/include/omath/hud/renderer_realizations/imgui_renderer.hpp @@ -0,0 +1,20 @@ +// +// Created by orange on 13.03.2026. +// +#pragma once +#include +namespace omath::hud +{ + class ImguiHudRenderer final : public HudRendererInterface + { + public: + ~ImguiHudRenderer() override; + void add_line(const Vector2& line_start, const Vector2& line_end, const Color& color, + float thickness) override; + void add_polyline(const std::span>& vertexes, float thickness) override; + void add_filled_polyline(const std::span>& vertexes, float thickness) override; + void add_rectangle(const Vector2& min, const Vector2& max, const Color& color) override; + void add_filled_rectangle(const Vector2& min, const Vector2& max, const Color& color) override; + void add_text(const Vector2& position, const Color& color, const std::string_view& text) override; + }; +} \ No newline at end of file diff --git a/source/hud/canvas_box.cpp b/source/hud/canvas_box.cpp new file mode 100644 index 0000000..ac3b38f --- /dev/null +++ b/source/hud/canvas_box.cpp @@ -0,0 +1,27 @@ +// +// Created by orange on 13.03.2026. +// +// +// Created by Vlad on 6/17/2025. +// +#include "omath/hud/canvas_box.hpp" + +namespace omath::hud +{ + + CanvasBox::CanvasBox(const Vector2 top, Vector2 bottom, const float ratio) + { + bottom.x = top.x; + const auto height = std::abs(top.y - bottom.y); + + top_left_corner = top - Vector2{height / ratio, 0}; + top_right_corner = top + Vector2{height / ratio, 0}; + + bottom_left_corner = bottom - Vector2{height / ratio, 0}; + bottom_right_corner = bottom + Vector2{height / ratio, 0}; + } + std::array, 4> CanvasBox::as_array() const + { + return {top_left_corner, top_right_corner, bottom_right_corner, bottom_left_corner}; + } +} // namespace ohud \ No newline at end of file diff --git a/source/hud/entity_overlay.cpp b/source/hud/entity_overlay.cpp new file mode 100644 index 0000000..11f6c95 --- /dev/null +++ b/source/hud/entity_overlay.cpp @@ -0,0 +1,9 @@ +// +// Created by orange on 13.03.2026. +// +#include "omath/hud/entity_overlay.hpp" + +namespace omath::hud +{ + +} \ No newline at end of file diff --git a/source/hud/renderer_realizations/imgui_renderer.cpp b/source/hud/renderer_realizations/imgui_renderer.cpp new file mode 100644 index 0000000..525a014 --- /dev/null +++ b/source/hud/renderer_realizations/imgui_renderer.cpp @@ -0,0 +1,9 @@ +// +// Created by orange on 13.03.2026. +// +#include "omath/hud/renderer_realizations/imgui_renderer.hpp" + +namespace omath::hud +{ + +} \ No newline at end of file