Menu bg
This commit is contained in:
parent
e4aded6099
commit
35008f9304
@ -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)
|
||||
{
|
||||
|
||||
@ -1,11 +1,13 @@
|
||||
#include "context.hpp"
|
||||
|
||||
#include "assets/cache.hpp"
|
||||
|
||||
gui::Context::Context(gfx::DrawList& dlist, std::shared_ptr<const Font> 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;
|
||||
}
|
||||
|
||||
@ -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<const Font> font_;
|
||||
gfx::VertexArray va_;
|
||||
|
||||
// assets
|
||||
std::shared_ptr<const Font> font_;
|
||||
std::shared_ptr<const gfx::Texture> white_tex_;
|
||||
|
||||
// building
|
||||
std::vector<GuiVertex> vertices_;
|
||||
|
||||
@ -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));
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user