From 35008f9304e2f7d2d08224fe50eeb72026dcbc70 Mon Sep 17 00:00:00 2001 From: zbyv Date: Thu, 12 Mar 2026 22:35:08 +0100 Subject: [PATCH] Menu bg --- src/client/app.cpp | 2 +- src/gui/context.cpp | 12 ++++++++++-- src/gui/context.hpp | 7 ++++++- src/gui/menu.cpp | 5 +++-- 4 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/client/app.cpp b/src/client/app.cpp index 6595d30..e4259e9 100644 --- a/src/client/app.cpp +++ b/src/client/app.cpp @@ -123,7 +123,7 @@ void App::Disconnected(const std::string& reason) session_.reset(); } -static bool InputToMenuInput(game::PlayerInputType& in, gui::MenuInput& mi) +static bool InputToMenuInput(game::PlayerInputType in, gui::MenuInput& mi) { switch (in) { diff --git a/src/gui/context.cpp b/src/gui/context.cpp index f63f612..7c011a7 100644 --- a/src/gui/context.cpp +++ b/src/gui/context.cpp @@ -1,11 +1,13 @@ #include "context.hpp" +#include "assets/cache.hpp" + gui::Context::Context(gfx::DrawList& dlist, std::shared_ptr default_font) : dlist_(dlist), font_(std::move(default_font)), va_(gfx::VA_POSITION | gfx::VA_UV | gfx::VA_COLOR, gfx::VF_CREATE_EBO | gfx::VF_DYNAMIC) { - + white_tex_ = assets::CacheManager::GetTexture("data/white.png"); } void gui::Context::Begin() @@ -15,6 +17,12 @@ void gui::Context::Begin() ranges_.clear(); } +void gui::Context::DrawRect(const glm::vec2& p0, const glm::vec2& p1, uint32_t color) +{ + BeginTexture(white_tex_.get()); + PushRect(p0, glm::vec2(0.0f), p1, glm::vec2(1.0f), color); +} + static uint32_t DecodeUTF8Codepoint(const char*& p, const char* end) { if (p == end) @@ -227,7 +235,7 @@ void gui::Context::BeginTexture(const gfx::Texture* texture) return; auto& range = ranges_.emplace_back(); - range.start = indices_.size(); + range.start = indices_.size() / 3; range.count = 0; range.texture = texture; } diff --git a/src/gui/context.hpp b/src/gui/context.hpp index bf708ce..1be2f87 100644 --- a/src/gui/context.hpp +++ b/src/gui/context.hpp @@ -34,6 +34,8 @@ public: void Begin(); + void DrawRect(const glm::vec2& p0, const glm::vec2& p1, uint32_t color); + glm::vec2 MeasureText(std::string_view text); void DrawText(std::string_view text, const glm::vec2& pos, uint32_t color = 0xFFFFFFFF, float scale = 1.0f); void DrawTextAligned(std::string_view text, const glm::vec2& pos, const glm::vec2& align, uint32_t color = 0xFFFFFFFF, float scale = 1.0f); @@ -48,8 +50,11 @@ private: private: gfx::DrawList& dlist_; - std::shared_ptr font_; gfx::VertexArray va_; + + // assets + std::shared_ptr font_; + std::shared_ptr white_tex_; // building std::vector vertices_; diff --git a/src/gui/menu.cpp b/src/gui/menu.cpp index aa2fed6..c1d363e 100644 --- a/src/gui/menu.cpp +++ b/src/gui/menu.cpp @@ -6,10 +6,11 @@ void gui::Menu::Draw(Context& ctx, const glm::vec2& pos) const { - // TODO: draw bg + // background + auto size = MeasureSize(); + ctx.DrawRect(pos, pos + size, 0x55000000); glm::vec2 cursor = pos; - for (size_t i = 0; i < items_.size(); ++i) { items_[i]->Draw(DrawMenuItemArgs(ctx, cursor, focus_ == i));