Updated ImGui.
This commit is contained in:
parent
fbf94681c3
commit
6f89c93255
44
3rdparty/ocornut-imgui/imgui.cpp
vendored
44
3rdparty/ocornut-imgui/imgui.cpp
vendored
@ -5,7 +5,7 @@
|
||||
// Newcomers, read 'Programmer guide' below for notes on how to setup ImGui in your codebase.
|
||||
// Get latest version at https://github.com/ocornut/imgui
|
||||
// Releases change-log at https://github.com/ocornut/imgui/releases
|
||||
// Gallery (please post your screenshots/video there!): https://github.com/ocornut/imgui/issues/772
|
||||
// Gallery (please post your screenshots/video there!): https://github.com/ocornut/imgui/issues/1269
|
||||
// Developed by Omar Cornut and every direct or indirect contributors to the GitHub.
|
||||
// This library is free but I need your support to sustain development and maintenance.
|
||||
// If you work for a company, please consider financial support, e.g: https://www.patreon.com/imgui
|
||||
@ -2130,16 +2130,9 @@ void ImGui::NewFrame()
|
||||
IM_ASSERT(g.Style.CurveTessellationTol > 0.0f); // Invalid style setting
|
||||
IM_ASSERT(g.Style.Alpha >= 0.0f && g.Style.Alpha <= 1.0f); // Invalid style setting. Alpha cannot be negative (allows us to avoid a few clamps in color computations)
|
||||
|
||||
// Initialize on first frame
|
||||
if (!g.Initialized)
|
||||
{
|
||||
// Initialize on first frame
|
||||
g.LogClipboard = (ImGuiTextBuffer*)ImGui::MemAlloc(sizeof(ImGuiTextBuffer));
|
||||
IM_PLACEMENT_NEW(g.LogClipboard) ImGuiTextBuffer();
|
||||
|
||||
IM_ASSERT(g.Settings.empty());
|
||||
LoadIniSettingsFromDisk(g.IO.IniFilename);
|
||||
g.Initialized = true;
|
||||
}
|
||||
ImGui::Initialize();
|
||||
|
||||
SetCurrentFont(GetDefaultFont());
|
||||
IM_ASSERT(g.Font->IsLoaded());
|
||||
@ -2158,11 +2151,10 @@ void ImGui::NewFrame()
|
||||
|
||||
// Update mouse input state
|
||||
// If mouse just appeared or disappeared (usually denoted by -FLT_MAX component, but in reality we test for -256000.0f) we cancel out movement in MouseDelta
|
||||
const float MOUSE_INVALID = -256000.0f;
|
||||
if ((g.IO.MousePos.x < MOUSE_INVALID && g.IO.MousePos.y < MOUSE_INVALID) || (g.IO.MousePosPrev.x < MOUSE_INVALID && g.IO.MousePosPrev.y < MOUSE_INVALID))
|
||||
g.IO.MouseDelta = ImVec2(0.0f, 0.0f);
|
||||
else
|
||||
if (IsMousePosValid(&g.IO.MousePos) && IsMousePosValid(&g.IO.MousePosPrev))
|
||||
g.IO.MouseDelta = g.IO.MousePos - g.IO.MousePosPrev;
|
||||
else
|
||||
g.IO.MouseDelta = ImVec2(0.0f, 0.0f);
|
||||
g.IO.MousePosPrev = g.IO.MousePos;
|
||||
for (int i = 0; i < IM_ARRAYSIZE(g.IO.MouseDown); i++)
|
||||
{
|
||||
@ -2356,7 +2348,18 @@ void ImGui::NewFrame()
|
||||
ImGui::Begin("Debug");
|
||||
}
|
||||
|
||||
// NB: behavior of ImGui after Shutdown() is not tested/guaranteed at the moment. This function is merely here to free heap allocations.
|
||||
void ImGui::Initialize()
|
||||
{
|
||||
ImGuiContext& g = *GImGui;
|
||||
g.LogClipboard = (ImGuiTextBuffer*)ImGui::MemAlloc(sizeof(ImGuiTextBuffer));
|
||||
IM_PLACEMENT_NEW(g.LogClipboard) ImGuiTextBuffer();
|
||||
|
||||
IM_ASSERT(g.Settings.empty());
|
||||
LoadIniSettingsFromDisk(g.IO.IniFilename);
|
||||
g.Initialized = true;
|
||||
}
|
||||
|
||||
// This function is merely here to free heap allocations.
|
||||
void ImGui::Shutdown()
|
||||
{
|
||||
ImGuiContext& g = *GImGui;
|
||||
@ -2365,7 +2368,7 @@ void ImGui::Shutdown()
|
||||
if (g.IO.Fonts) // Testing for NULL to allow user to NULLify in case of running Shutdown() on multiple contexts. Bit hacky.
|
||||
g.IO.Fonts->Clear();
|
||||
|
||||
// Cleanup of other data are conditional on actually having used ImGui.
|
||||
// Cleanup of other data are conditional on actually having initialize ImGui.
|
||||
if (!g.Initialized)
|
||||
return;
|
||||
|
||||
@ -3233,6 +3236,15 @@ ImVec2 ImGui::GetMousePosOnOpeningCurrentPopup()
|
||||
return g.IO.MousePos;
|
||||
}
|
||||
|
||||
// We typically use ImVec2(-FLT_MAX,-FLT_MAX) to denote an invalid mouse position
|
||||
bool ImGui::IsMousePosValid(const ImVec2* mouse_pos)
|
||||
{
|
||||
if (mouse_pos == NULL)
|
||||
mouse_pos = &GImGui->IO.MousePos;
|
||||
const float MOUSE_INVALID = -256000.0f;
|
||||
return mouse_pos->x >= MOUSE_INVALID && mouse_pos->y >= MOUSE_INVALID;
|
||||
}
|
||||
|
||||
ImVec2 ImGui::GetMouseDragDelta(int button, float lock_threshold)
|
||||
{
|
||||
ImGuiContext& g = *GImGui;
|
||||
|
11
3rdparty/ocornut-imgui/imgui.h
vendored
11
3rdparty/ocornut-imgui/imgui.h
vendored
@ -458,6 +458,7 @@ namespace ImGui
|
||||
IMGUI_API bool IsMouseReleased(int button); // did mouse button released (went from Down to !Down)
|
||||
IMGUI_API bool IsMouseDragging(int button = 0, float lock_threshold = -1.0f); // is mouse dragging. if lock_threshold < -1.0f uses io.MouseDraggingThreshold
|
||||
IMGUI_API bool IsMouseHoveringRect(const ImVec2& r_min, const ImVec2& r_max, bool clip = true); // is mouse hovering given bounding rect (in screen space). clipped by current clipping settings. disregarding of consideration of focus/window ordering/blocked by a popup.
|
||||
IMGUI_API bool IsMousePosValid(const ImVec2* mouse_pos = NULL); //
|
||||
IMGUI_API ImVec2 GetMousePos(); // shortcut to ImGui::GetIO().MousePos provided by user, to be consistent with other calls
|
||||
IMGUI_API ImVec2 GetMousePosOnOpeningCurrentPopup(); // retrieve backup of mouse positioning at the time of opening popup we have BeginPopup() into
|
||||
IMGUI_API ImVec2 GetMouseDragDelta(int button = 0, float lock_threshold = -1.0f); // dragging amount since clicking. if lock_threshold < -1.0f uses io.MouseDraggingThreshold
|
||||
@ -1325,15 +1326,17 @@ struct ImFontConfig
|
||||
{
|
||||
void* FontData; // // TTF/OTF data
|
||||
int FontDataSize; // // TTF/OTF data size
|
||||
bool FontDataOwnedByAtlas; // true // TTF/OTF data ownership taken by the container ImFontAtlas (will delete memory itself). Set to true
|
||||
bool FontDataOwnedByAtlas; // true // TTF/OTF data ownership taken by the container ImFontAtlas (will delete memory itself).
|
||||
int FontNo; // 0 // Index of font within TTF/OTF file
|
||||
float SizePixels; // // Size in pixels for rasterizer
|
||||
float SizePixels; // // Size in pixels for rasterizer.
|
||||
int OversampleH, OversampleV; // 3, 1 // Rasterize at higher quality for sub-pixel positioning. We don't use sub-pixel positions on the Y axis.
|
||||
bool PixelSnapH; // false // Align every glyph to pixel boundary. Useful e.g. if you are merging a non-pixel aligned font with the default font. If enabled, you can set OversampleH/V to 1.
|
||||
ImVec2 GlyphExtraSpacing; // 0, 0 // Extra spacing (in pixels) between glyphs. Only X axis is supported for now.
|
||||
ImVec2 GlyphOffset; // 0, 0 // Offset all glyphs from this font input
|
||||
const ImWchar* GlyphRanges; // // Pointer to a user-provided list of Unicode range (2 value per range, values are inclusive, zero-terminated list). THE ARRAY DATA NEEDS TO PERSIST AS LONG AS THE FONT IS ALIVE.
|
||||
ImVec2 GlyphOffset; // 0, 0 // Offset all glyphs from this font input.
|
||||
const ImWchar* GlyphRanges; // NULL // Pointer to a user-provided list of Unicode range (2 value per range, values are inclusive, zero-terminated list). THE ARRAY DATA NEEDS TO PERSIST AS LONG AS THE FONT IS ALIVE.
|
||||
bool MergeMode; // false // Merge into previous ImFont, so you can combine multiple inputs font into one ImFont (e.g. ASCII font + icons + Japanese glyphs). You may want to use GlyphOffset.y when merge font of different heights.
|
||||
unsigned int RasterizerFlags; // 0x00 // Settings for custom font rasterizer (e.g. ImGuiFreeType). Leave as zero if you aren't using one.
|
||||
float RasterizerMultiply; // 1.0f // Brighten (>1.0f) or darken (<1.0f) font output. Brightening small fonts may be a good workaround to make them more readable.
|
||||
|
||||
// [Internal]
|
||||
char Name[32]; // Name (strictly to ease debugging)
|
||||
|
41
3rdparty/ocornut-imgui/imgui_draw.cpp
vendored
41
3rdparty/ocornut-imgui/imgui_draw.cpp
vendored
@ -1053,8 +1053,10 @@ ImFontConfig::ImFontConfig()
|
||||
GlyphOffset = ImVec2(0.0f, 0.0f);
|
||||
GlyphRanges = NULL;
|
||||
MergeMode = false;
|
||||
DstFont = NULL;
|
||||
RasterizerFlags = 0x00;
|
||||
RasterizerMultiply = 1.0f;
|
||||
memset(Name, 0, sizeof(Name));
|
||||
DstFont = NULL;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
@ -1342,6 +1344,23 @@ bool ImFontAtlas::Build()
|
||||
return ImFontAtlasBuildWithStbTruetype(this);
|
||||
}
|
||||
|
||||
void ImFontAtlasBuildMultiplyCalcLookupTable(unsigned char out_table[256], float in_brighten_factor)
|
||||
{
|
||||
for (unsigned int i = 0; i < 256; i++)
|
||||
{
|
||||
unsigned int value = (unsigned int)(i * in_brighten_factor);
|
||||
out_table[i] = value > 255 ? 255 : (value & 0xFF);
|
||||
}
|
||||
}
|
||||
|
||||
void ImFontAtlasBuildMultiplyRectAlpha8(const unsigned char table[256], unsigned char* pixels, int x, int y, int w, int h, int stride)
|
||||
{
|
||||
unsigned char* data = pixels + x + y * stride;
|
||||
for (int j = h; j > 0; j--, data += stride)
|
||||
for (int i = 0; i < w; i++)
|
||||
data[i] = table[data[i]];
|
||||
}
|
||||
|
||||
bool ImFontAtlasBuildWithStbTruetype(ImFontAtlas* atlas)
|
||||
{
|
||||
IM_ASSERT(atlas->ConfigData.Size > 0);
|
||||
@ -1384,6 +1403,7 @@ bool ImFontAtlasBuildWithStbTruetype(ImFontAtlas* atlas)
|
||||
{
|
||||
stbtt_fontinfo FontInfo;
|
||||
stbrp_rect* Rects;
|
||||
int RectsCount;
|
||||
stbtt_pack_range* Ranges;
|
||||
int RangesCount;
|
||||
};
|
||||
@ -1436,6 +1456,7 @@ bool ImFontAtlasBuildWithStbTruetype(ImFontAtlas* atlas)
|
||||
|
||||
// Pack
|
||||
tmp.Rects = buf_rects + buf_rects_n;
|
||||
tmp.RectsCount = font_glyphs_count;
|
||||
buf_rects_n += font_glyphs_count;
|
||||
stbtt_PackSetOversampling(&spc, cfg.OversampleH, cfg.OversampleV);
|
||||
int n = stbtt_PackFontRangesGatherRects(&spc, &tmp.FontInfo, tmp.Ranges, tmp.RangesCount, tmp.Rects);
|
||||
@ -1465,6 +1486,14 @@ bool ImFontAtlasBuildWithStbTruetype(ImFontAtlas* atlas)
|
||||
ImFontTempBuildData& tmp = tmp_array[input_i];
|
||||
stbtt_PackSetOversampling(&spc, cfg.OversampleH, cfg.OversampleV);
|
||||
stbtt_PackFontRangesRenderIntoRects(&spc, &tmp.FontInfo, tmp.Ranges, tmp.RangesCount, tmp.Rects);
|
||||
if (cfg.RasterizerMultiply != 1.0f)
|
||||
{
|
||||
unsigned char multiply_table[256];
|
||||
ImFontAtlasBuildMultiplyCalcLookupTable(multiply_table, cfg.RasterizerMultiply);
|
||||
for (const stbrp_rect* r = tmp.Rects; r != tmp.Rects + tmp.RectsCount; r++)
|
||||
if (r->was_packed)
|
||||
ImFontAtlasBuildMultiplyRectAlpha8(multiply_table, spc.pixels, r->x, r->y, r->w, r->h, spc.stride_in_bytes);
|
||||
}
|
||||
tmp.Rects = NULL;
|
||||
}
|
||||
|
||||
@ -1480,15 +1509,15 @@ bool ImFontAtlasBuildWithStbTruetype(ImFontAtlas* atlas)
|
||||
ImFontTempBuildData& tmp = tmp_array[input_i];
|
||||
ImFont* dst_font = cfg.DstFont; // We can have multiple input fonts writing into a same destination font (when using MergeMode=true)
|
||||
|
||||
float font_scale = stbtt_ScaleForPixelHeight(&tmp.FontInfo, cfg.SizePixels);
|
||||
const float font_scale = stbtt_ScaleForPixelHeight(&tmp.FontInfo, cfg.SizePixels);
|
||||
int unscaled_ascent, unscaled_descent, unscaled_line_gap;
|
||||
stbtt_GetFontVMetrics(&tmp.FontInfo, &unscaled_ascent, &unscaled_descent, &unscaled_line_gap);
|
||||
|
||||
float ascent = unscaled_ascent * font_scale;
|
||||
float descent = unscaled_descent * font_scale;
|
||||
const float ascent = unscaled_ascent * font_scale;
|
||||
const float descent = unscaled_descent * font_scale;
|
||||
ImFontAtlasBuildSetupFont(atlas, dst_font, &cfg, ascent, descent);
|
||||
float off_x = cfg.GlyphOffset.x;
|
||||
float off_y = cfg.GlyphOffset.y + (float)(int)(dst_font->Ascent + 0.5f);
|
||||
const float off_x = cfg.GlyphOffset.x;
|
||||
const float off_y = cfg.GlyphOffset.y + (float)(int)(dst_font->Ascent + 0.5f);
|
||||
|
||||
dst_font->FallbackGlyph = NULL; // Always clear fallback so FindGlyph can return NULL. It will be set again in BuildLookupTable()
|
||||
for (int i = 0; i < tmp.RangesCount; i++)
|
||||
|
3
3rdparty/ocornut-imgui/imgui_internal.h
vendored
3
3rdparty/ocornut-imgui/imgui_internal.h
vendored
@ -741,6 +741,7 @@ namespace ImGui
|
||||
IMGUI_API ImGuiWindow* FindWindowByName(const char* name);
|
||||
IMGUI_API void FocusWindow(ImGuiWindow* window);
|
||||
|
||||
IMGUI_API void Initialize();
|
||||
IMGUI_API void EndFrame(); // Ends the ImGui frame. Automatically called by Render()! you most likely don't need to ever call that yourself directly. If you don't need to render you can call EndFrame() but you'll have wasted CPU already. If you don't need to render, don't create any windows instead!
|
||||
|
||||
IMGUI_API void SetActiveID(ImGuiID id, ImGuiWindow* window);
|
||||
@ -816,6 +817,8 @@ IMGUI_API void ImFontAtlasBuildRegisterDefaultCustomRects(ImFontAtl
|
||||
IMGUI_API void ImFontAtlasBuildSetupFont(ImFontAtlas* atlas, ImFont* font, ImFontConfig* font_config, float ascent, float descent);
|
||||
IMGUI_API void ImFontAtlasBuildPackCustomRects(ImFontAtlas* atlas, void* spc);
|
||||
IMGUI_API void ImFontAtlasBuildRenderDefaultTexData(ImFontAtlas* atlas);
|
||||
IMGUI_API void ImFontAtlasBuildMultiplyCalcLookupTable(unsigned char out_table[256], float in_multiply_factor);
|
||||
IMGUI_API void ImFontAtlasBuildMultiplyRectAlpha8(const unsigned char table[256], unsigned char* pixels, int x, int y, int w, int h, int stride);
|
||||
|
||||
#ifdef __clang__
|
||||
#pragma clang diagnostic pop
|
||||
|
Loading…
x
Reference in New Issue
Block a user