mirror of
https://github.com/hedge-dev/UnleashedRecomp.git
synced 2026-05-20 01:48:23 -05:00
cdcacff53b
* Initial SDF font generation work. * Text now correctly displaying with proper spacing. * Fix untextured draws, implement custom rectangles. * Fix regular image display. * Slightly refactor ImGui rendering. * Implement outlines. * Implement bevel. * Create host device after loading the module if the installer wasn't run. * Move ImGui files to its own folder. * Fix outline sizes. * Fix default ImGui font and font scales. * Update font atlas files.
63 lines
1.9 KiB
C++
63 lines
1.9 KiB
C++
#pragma once
|
|
|
|
// https://github.com/ocornut/imgui/issues/1860#issuecomment-1927630727
|
|
|
|
// Usage:
|
|
// static ImDrawDataSnapshot snapshot; // Important: make persistent accross frames to reuse buffers.
|
|
// snapshot.SnapUsingSwap(ImGui::GetDrawData(), ImGui::GetTime());
|
|
// [...]
|
|
// ImGui_ImplDX11_RenderDrawData(&snapshot.DrawData);
|
|
|
|
struct ImDrawDataSnapshotEntry
|
|
{
|
|
ImDrawList* SrcCopy = NULL;
|
|
ImDrawList* OurCopy = NULL;
|
|
double LastUsedTime = 0.0;
|
|
};
|
|
|
|
struct ImDrawDataSnapshot
|
|
{
|
|
// Members
|
|
ImDrawData DrawData;
|
|
ImPool<ImDrawDataSnapshotEntry> Cache;
|
|
float MemoryCompactTimer = 20.0f; // Discard unused data after 20 seconds
|
|
|
|
~ImDrawDataSnapshot() { Clear(); }
|
|
void Clear();
|
|
void SnapUsingSwap(ImDrawData* src, double current_time); // Efficient snapshot by swapping data, meaning "src_list" is unusable.
|
|
|
|
// Internals
|
|
ImGuiID GetDrawListID(ImDrawList* src_list) { return ImHashData(&src_list, sizeof(src_list)); } // Hash pointer
|
|
ImDrawDataSnapshotEntry* GetOrAddEntry(ImDrawList* src_list) { return Cache.GetOrAddByKey(GetDrawListID(src_list)); }
|
|
};
|
|
|
|
// Undefine this to generate a font atlas file in working directory.
|
|
// You also need to do this if you are testing localization, as only
|
|
// characters in the locale get added to the atlas.
|
|
#define ENABLE_IM_FONT_ATLAS_SNAPSHOT
|
|
|
|
struct ImFontAtlasSnapshot
|
|
{
|
|
std::vector<uint8_t> data;
|
|
ankerl::unordered_dense::map<const void*, size_t> objects;
|
|
std::vector<uint32_t> offsets;
|
|
|
|
template<typename T1, typename T2>
|
|
void SnapPointer(size_t offset, const T1& value, const T2& ptr, size_t count);
|
|
|
|
template<typename T>
|
|
void Traverse(size_t offset, const T& value);
|
|
|
|
template<typename T>
|
|
size_t Snap(const T& value);
|
|
|
|
void Snap();
|
|
|
|
static ImFontAtlas* Load();
|
|
|
|
static void GenerateGlyphRanges();
|
|
|
|
// When ENABLE_IM_FONT_ATLAS_SNAPSHOT is undefined, this creates the font runtime instead.
|
|
static ImFont* GetFont(const char* name);
|
|
};
|