3#include <misc/cpp/imgui_stdlib.h>
10#include <unordered_map>
14void BeginPanel(
const char* name,
float x,
float y,
float bgAlpha,
int flags) {
17 if (x != 0.0f || y != 0.0f) {
18 ImGuiCond posCond = (flags &
PanelFlags_NoMove) ? ImGuiCond_Always : ImGuiCond_FirstUseEver;
19 ImGui::SetNextWindowPos(ImVec2(x, y), posCond);
21 ImGui::SetNextWindowBgAlpha(bgAlpha);
23 ImGuiWindowFlags imFlags = 0;
30 ImGui::Begin(name,
nullptr, imFlags);
37void Text(
const char* fmt, ...) {
40 ImGui::TextV(fmt, args);
44void TextColored(
float r,
float g,
float b,
float a,
const char* fmt, ...) {
47 ImGui::TextColoredV(ImVec4(r, g, b, a), fmt, args);
54 ImGui::TextDisabledV(fmt, args);
59 return ImGui::Checkbox(label, value);
63 return ImGui::Button(label);
66bool DragFloat(
const char* label,
float* value,
float speed,
float min,
float max) {
67 return ImGui::DragFloat(label, value, speed, min, max);
70bool Combo(
const char* label,
int* current,
const char*
const items[],
int count) {
71 return ImGui::Combo(label, current, items, count);
91 ImGui::BeginChild(name, {0, 0}, ImGuiChildFlags_AutoResizeY);
95 ImGui::BeginChild(name, {
width,
height}, ImGuiChildFlags_AutoResizeY);
103 return ImGui::GetMainViewport()->Size.x;
107 return ImGui::GetMainViewport()->Size.y;
110void DrawLine(
float x1,
float y1,
float x2,
float y2,
111 float r,
float g,
float b,
float a,
float thickness) {
112 ImGui::GetForegroundDrawList()->AddLine(
113 ImVec2(x1, y1), ImVec2(x2, y2), ImColor(r, g, b, a), thickness);
117 float r,
float g,
float b,
float a,
float thickness,
119 ImGui::GetForegroundDrawList()->AddRect(
120 ImVec2(x, y), ImVec2(x + w, y + h), ImColor(r, g, b, a), rounding, 0, thickness);
124 float r,
float g,
float b,
float a,
126 ImGui::GetForegroundDrawList()->AddRectFilled(
127 ImVec2(x, y), ImVec2(x + w, y + h), ImColor(r, g, b, a), rounding);
131 float r,
float g,
float b,
float a) {
132 ImGui::GetForegroundDrawList()->AddText(
133 ImVec2(x, y), ImColor(r, g, b, a), text);
136bool InputText(
const char* label,
char* buf,
size_t bufSize) {
137 return ImGui::InputText(label, buf, bufSize);
141 return ImGui::InputText(label, str);
145 return ImGui::Button(label, ImVec2(
width,
height));
149 return ImGui::Selectable(label, selected);
153 ImGui::SetNextItemWidth(
width);
165 ImGui::PushStyleColor(
static_cast<ImGuiCol
>(idx), ImVec4(r, g, b, a));
169 ImGui::PopStyleColor(count);
173 ImGui::PushStyleVar(
static_cast<ImGuiStyleVar
>(idx), val);
177 ImGui::PushStyleVar(
static_cast<ImGuiStyleVar
>(idx), ImVec2(x, y));
181 ImGui::PopStyleVar(count);
185 return ImGui::BeginListBox(label, ImVec2(
width,
height));
193 ImGui::SetCursorPosX(x);
197 ImGui::SetCursorPosY(y);
201 return ImGui::GetCursorPosY();
205 return ImGui::GetContentRegionAvail().x;
209 ImGui::SetNextWindowPos(ImVec2(x, y), always ? ImGuiCond_Always : ImGuiCond_FirstUseEver);
213 ImGui::SetNextWindowSize(ImVec2(w, h), always ? ImGuiCond_Always : ImGuiCond_FirstUseEver);
217 ImGui::ProgressBar(fraction, ImVec2(
width,
height), overlay);
223 ImGui::TextWrappedV(fmt, args);
231 if (app && app->GetRenderer() &&
235 ImVec2 uv0 = flipY ? ImVec2(0, 1) : ImVec2(0, 0);
236 ImVec2 uv1 = flipY ? ImVec2(1, 0) : ImVec2(1, 1);
237 ImGui::Image(
static_cast<ImTextureID
>(textureID), ImVec2(
width,
height), uv0, uv1);
243 if (app && app->GetRenderer() &&
247 ImVec2 uv0 = flipY ? ImVec2(0, 1) : ImVec2(0, 0);
248 ImVec2 uv1 = flipY ? ImVec2(1, 0) : ImVec2(1, 1);
249 ImGui::GetForegroundDrawList()->AddImage(
250 static_cast<ImTextureID
>(textureID),
251 ImVec2(x, y), ImVec2(x +
width, y +
height), uv0, uv1);
259 if (outWidth) *outWidth =
static_cast<float>(it->second->GetWidth());
260 if (outHeight) *outHeight =
static_cast<float>(it->second->GetHeight());
261 return it->second->GetImGuiTextureID();
268 if (outWidth) *outWidth =
static_cast<float>(tex->GetWidth());
269 if (outHeight) *outHeight =
static_cast<float>(tex->GetHeight());
270 return tex->GetImGuiTextureID();
286 return stbi_load(path, w, h, &channels, 4);
290 stbi_image_free(pixels);
static Application * GetInstance()
The one Application for this process, or null before construction.
static Sleak::Texture * CreateTexture(const std::string &TexturePath)
Loads a texture via the currently registered backend factory.
static Sleak::Texture * CreateTextureFromMemory(const void *data, uint32_t width, uint32_t height, TextureFormat format, uint32_t maxMipLevels=0)
Creates a texture from raw pixel data via the currently registered backend factory.
@ PanelFlags_NoFocusOnAppear
Immediate-mode UI calls available to game code.
ENGINE_API void ShutdownTextureCache()
ENGINE_API void DrawText(const char *text, float x, float y, float r, float g, float b, float a=1.0f)
ENGINE_API void Separator()
ENGINE_API float GetViewportHeight()
ENGINE_API uint64_t LoadTextureForUI(const std::string &filePath, float *outWidth=nullptr, float *outHeight=nullptr)
Loads an image file and caches it as a UI-bindable texture id, reusing the cache on repeat calls for ...
ENGINE_API bool Button(const char *label)
ENGINE_API float GetViewportWidth()
ENGINE_API void ProgressBar(float fraction, float width=-1.0f, float height=0.0f, const char *overlay=nullptr)
ENGINE_API void PushStyleColor(int idx, float r, float g, float b, float a)
ENGINE_API void FreeImagePixels(unsigned char *pixels)
ENGINE_API void BeginGroup()
ENGINE_API void SetCursorPosY(float y)
ENGINE_API void PushStyleVar(int idx, float val)
ENGINE_API void TextColored(float r, float g, float b, float a, const char *fmt,...)
ENGINE_API unsigned char * LoadImagePixels(const char *path, int *w, int *h)
Load image file into RGBA pixels (caller must free with FreeImagePixels).
ENGINE_API void EndGroup()
ENGINE_API void DrawLine(float x1, float y1, float x2, float y2, float r, float g, float b, float a=1.0f, float thickness=1.0f)
ENGINE_API Sleak::Texture * CreateTextureFromPixels(uint32_t width, uint32_t height, const void *rgbaPixels, uint32_t maxMipLevels=0)
Create a texture from raw RGBA pixel data (for runtime atlas building etc.).
ENGINE_API void PopStyleVar(int count=1)
ENGINE_API void BeginChild(const char *name)
ENGINE_API float GetCursorPosY()
ENGINE_API bool InputText(const char *label, char *buf, size_t bufSize)
ENGINE_API void EndChild()
ENGINE_API void Spacing()
ENGINE_API void SetNextItemWidth(float width)
ENGINE_API void Text(const char *fmt,...)
ENGINE_API bool ButtonSized(const char *label, float width, float height=0.0f)
ENGINE_API void DrawFilledRect(float x, float y, float w, float h, float r, float g, float b, float a=1.0f, float rounding=0.0f)
ENGINE_API void TextDisabled(const char *fmt,...)
ENGINE_API void Dummy(float width, float height)
ENGINE_API void SameLine()
ENGINE_API bool Selectable(const char *label, bool selected)
ENGINE_API void SetNextWindowPos(float x, float y, bool always=false)
ENGINE_API void EndListBox()
ENGINE_API void SetNextWindowSize(float w, float h, bool always=false)
ENGINE_API bool BeginListBox(const char *label, float width, float height)
ENGINE_API void PopStyleColor(int count=1)
ENGINE_API void DrawImage(uint64_t textureID, float x, float y, float width, float height)
ENGINE_API void SetCursorPosX(float x)
static std::unordered_map< std::string, Sleak::Texture * > s_uiTextures
ENGINE_API void BeginChildSized(const char *name, float width, float height=0.0f)
ENGINE_API void TextWrapped(const char *fmt,...)
ENGINE_API void BeginPanel(const char *name, float x, float y, float bgAlpha=0.4f, int flags=PanelFlags_NoTitleBar|PanelFlags_AutoResize|PanelFlags_NoMove|PanelFlags_NoInput|PanelFlags_NoFocusOnAppear)
Opens a floating overlay window at (x, y); pair with EndPanel.
ENGINE_API bool Checkbox(const char *label, bool *value)
ENGINE_API void Image(uint64_t textureID, float width, float height)
ENGINE_API void DrawRect(float x, float y, float w, float h, float r, float g, float b, float a=1.0f, float thickness=1.0f, float rounding=0.0f)
ENGINE_API void PushStyleVarVec(int idx, float x, float y)
ENGINE_API bool InputTextString(const char *label, std::string *str)
ENGINE_API float GetContentRegionAvailWidth()
ENGINE_API bool Combo(const char *label, int *current, const char *const items[], int count)
ENGINE_API void EndPanel()
ENGINE_API bool DragFloat(const char *label, float *value, float speed=1.0f, float min=0.0f, float max=0.0f)