Menu bg
This commit is contained in:
parent
e4aded6099
commit
35008f9304
@ -123,7 +123,7 @@ void App::Disconnected(const std::string& reason)
|
|||||||
session_.reset();
|
session_.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool InputToMenuInput(game::PlayerInputType& in, gui::MenuInput& mi)
|
static bool InputToMenuInput(game::PlayerInputType in, gui::MenuInput& mi)
|
||||||
{
|
{
|
||||||
switch (in)
|
switch (in)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -1,11 +1,13 @@
|
|||||||
#include "context.hpp"
|
#include "context.hpp"
|
||||||
|
|
||||||
|
#include "assets/cache.hpp"
|
||||||
|
|
||||||
gui::Context::Context(gfx::DrawList& dlist, std::shared_ptr<const Font> default_font) :
|
gui::Context::Context(gfx::DrawList& dlist, std::shared_ptr<const Font> default_font) :
|
||||||
dlist_(dlist),
|
dlist_(dlist),
|
||||||
font_(std::move(default_font)),
|
font_(std::move(default_font)),
|
||||||
va_(gfx::VA_POSITION | gfx::VA_UV | gfx::VA_COLOR, gfx::VF_CREATE_EBO | gfx::VF_DYNAMIC)
|
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()
|
void gui::Context::Begin()
|
||||||
@ -15,6 +17,12 @@ void gui::Context::Begin()
|
|||||||
ranges_.clear();
|
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)
|
static uint32_t DecodeUTF8Codepoint(const char*& p, const char* end)
|
||||||
{
|
{
|
||||||
if (p == end)
|
if (p == end)
|
||||||
@ -227,7 +235,7 @@ void gui::Context::BeginTexture(const gfx::Texture* texture)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
auto& range = ranges_.emplace_back();
|
auto& range = ranges_.emplace_back();
|
||||||
range.start = indices_.size();
|
range.start = indices_.size() / 3;
|
||||||
range.count = 0;
|
range.count = 0;
|
||||||
range.texture = texture;
|
range.texture = texture;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -34,6 +34,8 @@ public:
|
|||||||
|
|
||||||
void Begin();
|
void Begin();
|
||||||
|
|
||||||
|
void DrawRect(const glm::vec2& p0, const glm::vec2& p1, uint32_t color);
|
||||||
|
|
||||||
glm::vec2 MeasureText(std::string_view text);
|
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 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);
|
void DrawTextAligned(std::string_view text, const glm::vec2& pos, const glm::vec2& align, uint32_t color = 0xFFFFFFFF, float scale = 1.0f);
|
||||||
@ -48,9 +50,12 @@ private:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
gfx::DrawList& dlist_;
|
gfx::DrawList& dlist_;
|
||||||
std::shared_ptr<const Font> font_;
|
|
||||||
gfx::VertexArray va_;
|
gfx::VertexArray va_;
|
||||||
|
|
||||||
|
// assets
|
||||||
|
std::shared_ptr<const Font> font_;
|
||||||
|
std::shared_ptr<const gfx::Texture> white_tex_;
|
||||||
|
|
||||||
// building
|
// building
|
||||||
std::vector<GuiVertex> vertices_;
|
std::vector<GuiVertex> vertices_;
|
||||||
std::vector<uint32_t> indices_;
|
std::vector<uint32_t> indices_;
|
||||||
|
|||||||
@ -6,10 +6,11 @@
|
|||||||
|
|
||||||
void gui::Menu::Draw(Context& ctx, const glm::vec2& pos) const
|
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;
|
glm::vec2 cursor = pos;
|
||||||
|
|
||||||
for (size_t i = 0; i < items_.size(); ++i)
|
for (size_t i = 0; i < items_.size(); ++i)
|
||||||
{
|
{
|
||||||
items_[i]->Draw(DrawMenuItemArgs(ctx, cursor, focus_ == i));
|
items_[i]->Draw(DrawMenuItemArgs(ctx, cursor, focus_ == i));
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user