mirror of
https://github.com/Mauler125/r5sdk.git
synced 2025-02-09 19:15:03 +01:00
ImGui: create dedicated file for wrappers and implement RenderText
All future wrappers go here.
This commit is contained in:
parent
9623c1640d
commit
f964db2ccf
2
src/thirdparty/imgui/CMakeLists.txt
vendored
2
src/thirdparty/imgui/CMakeLists.txt
vendored
@ -42,6 +42,8 @@ add_sources( SOURCE_GROUP "Misc"
|
||||
"misc/imgui_style.h"
|
||||
"misc/imgui_utility.cpp"
|
||||
"misc/imgui_utility.h"
|
||||
"misc/imgui_wrapper.cpp"
|
||||
"misc/imgui_wrapper.h"
|
||||
"misc/cpp/imgui_stdlib.cpp"
|
||||
"misc/cpp/imgui_stdlib.h"
|
||||
)
|
||||
|
34
src/thirdparty/imgui/misc/imgui_wrapper.cpp
vendored
Normal file
34
src/thirdparty/imgui/misc/imgui_wrapper.cpp
vendored
Normal file
@ -0,0 +1,34 @@
|
||||
//============================================================================//
|
||||
//
|
||||
// Purpose: Set of Dear ImGui wrappers
|
||||
//
|
||||
//============================================================================//
|
||||
#include "imgui.h"
|
||||
#include "imgui_wrapper.h"
|
||||
|
||||
#include "stdio.h"
|
||||
|
||||
void ImGui_RenderText(const ImGuiTextAlign_e align, const ImVec2 pos, const ImVec4& color, const char* const fmt, ...)
|
||||
{
|
||||
ImDrawList* const drawList = ImGui::GetBackgroundDrawList();
|
||||
assert(drawList);
|
||||
|
||||
va_list argsCopy;
|
||||
va_start(argsCopy, fmt);
|
||||
|
||||
char textBuffer[2048];
|
||||
|
||||
const int numChars = vsnprintf(textBuffer, sizeof(textBuffer), fmt, argsCopy);
|
||||
va_end(argsCopy);
|
||||
|
||||
// nb(amos): 'vsnprintf' does not count the terminating null, so no -1 here.
|
||||
const char* const textEnd = &textBuffer[numChars];
|
||||
ImVec2 alignedPos = pos;
|
||||
|
||||
if (align == ImGuiTextAlign_e::kAlignCenter)
|
||||
alignedPos.x -= ImGui::CalcTextSize(textBuffer, textEnd).x / 2;
|
||||
else if (align == ImGuiTextAlign_e::kAlignRight)
|
||||
alignedPos.x -= ImGui::CalcTextSize(textBuffer, textEnd).x;
|
||||
|
||||
drawList->AddText(alignedPos, ImGui::ColorConvertFloat4ToU32(color), textBuffer, textEnd);
|
||||
}
|
13
src/thirdparty/imgui/misc/imgui_wrapper.h
vendored
Normal file
13
src/thirdparty/imgui/misc/imgui_wrapper.h
vendored
Normal file
@ -0,0 +1,13 @@
|
||||
#ifndef IMGUI_WRAPPER_H
|
||||
#define IMGUI_WRAPPER_H
|
||||
|
||||
enum class ImGuiTextAlign_e
|
||||
{
|
||||
kAlignLeft,
|
||||
kAlignCenter,
|
||||
kAlignRight,
|
||||
};
|
||||
|
||||
extern void ImGui_RenderText(const ImGuiTextAlign_e align, const ImVec2 pos, const ImVec4& color, const char* const fmt, ...);
|
||||
|
||||
#endif // IMGUI_WRAPPER_H
|
Loading…
x
Reference in New Issue
Block a user