mirror of
https://github.com/Kelsidavis/WoWee.git
synced 2026-08-04 03:45:03 -04:00
A backdrop's insets and edge size are authored in interface units like everything else, but were used directly against a rect already converted to pixels. On a 1528-tall display that is a border half its proper thickness and insets half as deep, and it would be too thick on a short one; a tiled background repeated at a rate that changed with the window. Adds layout tests for what the display actually changes: only the height sets the scale, the width follows from it, and a frame keeps its authored size in units on a 4:3, an ultrawide and a portrait monitor alike.
71 lines
2.7 KiB
C++
71 lines
2.7 KiB
C++
#pragma once
|
|
|
|
// Draws a WidgetTree.
|
|
//
|
|
// Kept apart from the tree itself so the layout rules stay testable without a
|
|
// Vulkan device. This half is the part that needs one.
|
|
//
|
|
// Textures come from the game's own Interface\ art through the existing asset
|
|
// path — read the BLP, upload it, hand ImGui the descriptor set — which is the
|
|
// same route the action bar already takes for its backpack button. Nothing new
|
|
// is shipped; it is the player's own install being drawn.
|
|
|
|
#include <cstdint>
|
|
#include <string>
|
|
#include <unordered_map>
|
|
|
|
#include <vulkan/vulkan.h>
|
|
|
|
struct ImDrawList; // global, as ImGui declares it
|
|
|
|
namespace wowee {
|
|
namespace pipeline { class AssetManager; }
|
|
namespace rendering { class VkContext; }
|
|
|
|
namespace ui {
|
|
|
|
class WidgetTree;
|
|
struct Widget;
|
|
|
|
class WidgetRenderer {
|
|
public:
|
|
void initialize(pipeline::AssetManager* assets, rendering::VkContext* vkCtx);
|
|
|
|
/// Lay the tree out for this screen and draw it. Safe to call with no
|
|
/// device or assets — it simply does nothing, which is what the headless
|
|
/// tests want.
|
|
void render(WidgetTree& tree, float screenW, float screenH);
|
|
|
|
/// Number of distinct textures resident. Cheap diagnostic; the cache never
|
|
/// evicts, because Interface\ art is small, bounded and reused constantly.
|
|
size_t textureCount() const { return textures_.size(); }
|
|
|
|
private:
|
|
/// Descriptor set for an Interface\ path, loading it on first use. Returns
|
|
/// VK_NULL_HANDLE for anything missing, and remembers the failure so a
|
|
/// mistyped path is not re-read every frame.
|
|
VkDescriptorSet texture(const std::string& path, bool add = false);
|
|
/// Already-uploaded texture for a path, without triggering an upload.
|
|
VkDescriptorSet resident(const std::string& path, bool add = false) const;
|
|
|
|
/// scale is pixels per interface unit. The rect arrives in pixels, but a
|
|
/// backdrop's insets and edge size are authored in units like everything
|
|
/// else, so they have to make the same trip or a border comes out the
|
|
/// wrong thickness on any display that is not 768 pixels tall.
|
|
void drawBackdrop(ImDrawList* dl, const Widget& w, float scale,
|
|
float x0, float y0, float x1, float y1);
|
|
void drawStatusBar(ImDrawList* dl, const Widget& w,
|
|
float x0, float y0, float x1, float y1);
|
|
void drawSlider(ImDrawList* dl, const Widget& w,
|
|
float x0, float y0, float x1, float y1);
|
|
void drawCooldown(ImDrawList* dl, const Widget& w,
|
|
float x0, float y0, float x1, float y1);
|
|
|
|
pipeline::AssetManager* assets_ = nullptr;
|
|
rendering::VkContext* vkCtx_ = nullptr;
|
|
std::unordered_map<std::string, VkDescriptorSet> textures_;
|
|
};
|
|
|
|
} // namespace ui
|
|
} // namespace wowee
|