mirror of
https://github.com/orange-cpp/omath.git
synced 2026-04-18 23:03:27 +00:00
added files
This commit is contained in:
23
include/omath/hud/canvas_box.hpp
Normal file
23
include/omath/hud/canvas_box.hpp
Normal file
@@ -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<float> top, Vector2<float> bottom, float ratio = 4.f);
|
||||
|
||||
[[nodiscard]]
|
||||
std::array<Vector2<float>, 4> as_array() const;
|
||||
|
||||
Vector2<float> top_left_corner;
|
||||
Vector2<float> top_right_corner;
|
||||
|
||||
Vector2<float> bottom_left_corner;
|
||||
Vector2<float> bottom_right_corner;
|
||||
};
|
||||
} // namespace omath::hud
|
||||
72
include/omath/hud/entity_overlay.hpp
Normal file
72
include/omath/hud/entity_overlay.hpp
Normal file
@@ -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 <memory>
|
||||
#include <string_view>
|
||||
namespace omath::hud
|
||||
{
|
||||
enum class SnapLineStartPosition
|
||||
{
|
||||
SCREEN_BOTTOM,
|
||||
SCREEN_TOP,
|
||||
SCREEN_CENTER,
|
||||
};
|
||||
class EntityOverlay
|
||||
{
|
||||
public:
|
||||
EntityOverlay(const Vector2<float>& top, const Vector2<float>& bottom,
|
||||
const std::shared_ptr<HudRendererInterface>& 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<typename... Args>
|
||||
void add_right_label(const Color& color, const float offset, const bool outlined,
|
||||
std::format_string<Args...> 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<typename... Args>
|
||||
void add_top_label(const Color& color, const float offset, const bool outlined, std::format_string<Args...> 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<float>& position, const Color& color,
|
||||
const std::string_view& text);
|
||||
CanvasBox m_canvas;
|
||||
Vector2<float> m_text_cursor_right;
|
||||
Vector2<float> m_text_cursor_top;
|
||||
std::shared_ptr<HudRendererInterface> renderer;
|
||||
};
|
||||
} // namespace omath::hud
|
||||
27
include/omath/hud/hud_renderer_interface.hpp
Normal file
27
include/omath/hud/hud_renderer_interface.hpp
Normal file
@@ -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<float>& line_start, const Vector2<float>& line_end, const Color& color,
|
||||
float thickness) = 0;
|
||||
|
||||
virtual void add_polyline(const std::span<const Vector2<float>>& vertexes, float thickness) = 0;
|
||||
|
||||
virtual void add_filled_polyline(const std::span<const Vector2<float>>& vertexes, float thickness) = 0;
|
||||
|
||||
virtual void add_rectangle(const Vector2<float>& min, const Vector2<float>& max, const Color& color) = 0;
|
||||
|
||||
virtual void add_filled_rectangle(const Vector2<float>& min, const Vector2<float>& max, const Color& color) = 0;
|
||||
|
||||
virtual void add_text(const Vector2<float>& position, const Color& color, const std::string_view& text) = 0;
|
||||
};
|
||||
} // namespace omath::hud
|
||||
20
include/omath/hud/renderer_realizations/imgui_renderer.hpp
Normal file
20
include/omath/hud/renderer_realizations/imgui_renderer.hpp
Normal file
@@ -0,0 +1,20 @@
|
||||
//
|
||||
// Created by orange on 13.03.2026.
|
||||
//
|
||||
#pragma once
|
||||
#include <omath/hud/hud_renderer_interface.hpp>
|
||||
namespace omath::hud
|
||||
{
|
||||
class ImguiHudRenderer final : public HudRendererInterface
|
||||
{
|
||||
public:
|
||||
~ImguiHudRenderer() override;
|
||||
void add_line(const Vector2<float>& line_start, const Vector2<float>& line_end, const Color& color,
|
||||
float thickness) override;
|
||||
void add_polyline(const std::span<const Vector2<float>>& vertexes, float thickness) override;
|
||||
void add_filled_polyline(const std::span<const Vector2<float>>& vertexes, float thickness) override;
|
||||
void add_rectangle(const Vector2<float>& min, const Vector2<float>& max, const Color& color) override;
|
||||
void add_filled_rectangle(const Vector2<float>& min, const Vector2<float>& max, const Color& color) override;
|
||||
void add_text(const Vector2<float>& position, const Color& color, const std::string_view& text) override;
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user