From a31e44b99afb54b3c9a3d531ace36bba0f229fb2 Mon Sep 17 00:00:00 2001 From: ocornut Date: Sun, 30 Nov 2014 12:21:50 +0000 Subject: [PATCH 001/108] Fixed Clang -Weverything warnings + TODO list entries --- imgui.cpp | 42 +++++++++++++++++++++++------------------- imgui.h | 7 +++---- stb_textedit.h | 8 ++++---- 3 files changed, 30 insertions(+), 27 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index b6871778..fb295d26 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -198,6 +198,7 @@ - text edit: add multi-line text edit - settings: write more decent code to allow saving/loading new fields - settings: api for per-tool simple persistent data (bool,int,float) in .ini file + - log: have more control over the log scope (e.g. stop logging when leaving current tree node scope) - log: be able to right-click and log a window or tree-node into tty/file/clipboard? - filters: set a current filter that tree node can automatically query to hide themselves - filters: handle wildcards (with implicit leading/trailing *), regexps @@ -212,6 +213,7 @@ - misc: provide a way to compile out the entire implementation while providing a dummy API (e.g. #define IMGUI_DUMMY_IMPL - misc: not thread-safe - misc: double-clicking on title bar to minimize isn't consistent, perhaps move to single-click on left-most collapse icon? + - misc: CalcTextSize() could benefit from having 'hide_text_after_double_hash' false by default for external use? - style editor: add a button to output C code. - examples: integrate dx11 example. - examples: integrate opengl 3/4 programmable pipeline example. @@ -438,7 +440,7 @@ static int ImStricmp(const char* str1, const char* str2) static int ImStrnicmp(const char* str1, const char* str2, int count) { - int d; + int d = 0; while (count > 0 && (d = toupper(*str2) - toupper(*str1)) == 0 && *str1) { str1++; str2++; count--; } return (count == 0) ? 0 : d; } @@ -725,7 +727,7 @@ struct ImGuiState bool Initialized; ImGuiIO IO; ImGuiStyle Style; - float FontSize; // == IO.FontGlobalScale * IO.Font->Scale * IO.Font->GetFontSize(). Vertical distance between two lines of text, aka == CalcTextSize(" ").y + float FontSize; // == IO.FontGlobalScale * IO.Font->Scale * IO.Font->Info->FontSize. Vertical distance between two lines of text, aka == CalcTextSize(" ").y ImVec2 FontTexUvForWhite; // == IO.Font->FontTexUvForWhite (cached copy) float Time; @@ -1369,7 +1371,7 @@ void ImGui::NewFrame() IM_ASSERT(g.IO.Font && g.IO.Font->IsLoaded()); // Font not loaded IM_ASSERT(g.IO.Font->Scale > 0.0f); - g.FontSize = g.IO.FontGlobalScale * g.IO.Font->GetFontSize() * g.IO.Font->Scale; + g.FontSize = g.IO.FontGlobalScale * (float)g.IO.Font->Info->FontSize * g.IO.Font->Scale; g.FontTexUvForWhite = g.IO.Font->TexUvForWhite; g.IO.Font->FallbackGlyph = g.IO.Font->FindGlyph(g.IO.Font->FallbackChar); @@ -1803,12 +1805,12 @@ static void RenderCollapseTriangle(ImVec2 p_min, bool open, float scale, bool sh // Calculate text size. Text can be multi-line. Optionally ignore text after a ## marker. // CalcTextSize("") should return ImVec2(0.0f, GImGui.FontSize) -ImVec2 ImGui::CalcTextSize(const char* text, const char* text_end, bool hide_text_after_hash, float wrap_width) +ImVec2 ImGui::CalcTextSize(const char* text, const char* text_end, bool hide_text_after_double_hash, float wrap_width) { ImGuiWindow* window = GetCurrentWindow(); const char* text_display_end; - if (hide_text_after_hash) + if (hide_text_after_double_hash) text_display_end = FindTextDisplayEnd(text, text_end); // Hide anything after a '##' string else text_display_end = text_end; @@ -4128,10 +4130,10 @@ static void STB_TEXTEDIT_DELETECHARS(STB_TEXTEDIT_STRING* obj, int pos, int n) static bool STB_TEXTEDIT_INSERTCHARS(STB_TEXTEDIT_STRING* obj, int pos, const ImWchar* new_text, int new_text_len) { const size_t text_len = ImStrlenW(obj->Text); - if (new_text_len + text_len + 1 >= obj->BufSize) + if ((size_t)new_text_len + text_len + 1 >= obj->BufSize) return false; - if (pos != text_len) + if (pos != (int)text_len) memmove(obj->Text + (size_t)pos + new_text_len, obj->Text + (size_t)pos, (text_len - (size_t)pos) * sizeof(ImWchar)); memcpy(obj->Text + (size_t)pos, new_text, (size_t)new_text_len * sizeof(ImWchar)); obj->Text[text_len + (size_t)new_text_len] = '\0'; @@ -4304,7 +4306,7 @@ bool ImGui::InputInt(const char* label, int *v, int step, int step_fast, ImGuiIn // Public API to manipulate UTF-8 text // We expose UTF-8 to the user (unlike the STB_TEXTEDIT_* functions which are manipulating wchar) -void ImGuiTextEditCallbackData::DeleteChars(size_t pos, size_t bytes_count) +void ImGuiTextEditCallbackData::DeleteChars(int pos, int bytes_count) { char* dst = Buf + pos; const char* src = Buf + pos + bytes_count; @@ -4313,31 +4315,32 @@ void ImGuiTextEditCallbackData::DeleteChars(size_t pos, size_t bytes_count) *dst = '\0'; BufDirty = true; - if ((size_t)CursorPos + bytes_count >= pos) + if (CursorPos + bytes_count >= pos) CursorPos -= bytes_count; - else if ((size_t)CursorPos >= pos) + else if (CursorPos >= pos) CursorPos = pos; SelectionStart = SelectionEnd = CursorPos; } -void ImGuiTextEditCallbackData::InsertChars(size_t pos, const char* new_text, const char* new_text_end) +void ImGuiTextEditCallbackData::InsertChars(int pos, const char* new_text, const char* new_text_end) { const size_t text_len = strlen(Buf); if (!new_text_end) new_text_end = new_text + strlen(new_text); - const size_t new_text_len = new_text_end - new_text; + const size_t new_text_len = (size_t)(new_text_end - new_text); if (new_text_len + text_len + 1 >= BufSize) return; - if (text_len != pos) - memmove(Buf + pos + new_text_len, Buf + pos, text_len - pos); - memcpy(Buf + pos, new_text, new_text_len * sizeof(char)); + size_t upos = (size_t)pos; + if (text_len != upos) + memmove(Buf + upos + new_text_len, Buf + upos, text_len - upos); + memcpy(Buf + upos, new_text, new_text_len * sizeof(char)); Buf[text_len + new_text_len] = '\0'; BufDirty = true; - if ((size_t)CursorPos >= pos) - CursorPos += new_text_len; + if (CursorPos >= pos) + CursorPos += (int)new_text_len; SelectionStart = SelectionEnd = CursorPos; } @@ -5796,6 +5799,7 @@ bool ImFont::LoadFromMemory(const void* data, size_t data_size) IM_ASSERT(Kerning == NULL && KerningCount == 0); Kerning = (FntKerning*)p; KerningCount = block_size / sizeof(FntKerning); + break; default: break; } @@ -7152,7 +7156,7 @@ struct ExampleAppConsole else if (candidates.size() == 1) { // Single match. Delete the beginning of the word and replace it entirely so we've got nice casing - data->DeleteChars(word_start - data->Buf, word_end-word_start); + data->DeleteChars(word_start-data->Buf, word_end-word_start); data->InsertChars(data->CursorPos, candidates[0]); data->InsertChars(data->CursorPos, " "); } @@ -7162,7 +7166,7 @@ struct ExampleAppConsole int match_len = word_end - word_start; while (true) { - char c; + int c = 0; bool all_candidates_matches = true; for (size_t i = 0; i < candidates.size() && all_candidates_matches; i++) { diff --git a/imgui.h b/imgui.h index 419631d8..c207815c 100644 --- a/imgui.h +++ b/imgui.h @@ -295,7 +295,7 @@ namespace ImGui IMGUI_API int GetFrameCount(); IMGUI_API const char* GetStyleColorName(ImGuiCol idx); IMGUI_API void GetDefaultFontData(const void** fnt_data, unsigned int* fnt_size, const void** png_data, unsigned int* png_size); - IMGUI_API ImVec2 CalcTextSize(const char* text, const char* text_end = NULL, bool hide_text_after_hash = true, float wrap_width = -1.0f); + IMGUI_API ImVec2 CalcTextSize(const char* text, const char* text_end = NULL, bool hide_text_after_double_hash = false, float wrap_width = -1.0f); } // namespace ImGui @@ -619,8 +619,8 @@ struct ImGuiTextEditCallbackData void* UserData; // What user passed to InputText() // NB: calling those function loses selection. - void DeleteChars(size_t pos, size_t bytes_count); - void InsertChars(size_t pos, const char* text, const char* text_end = NULL); + void DeleteChars(int pos, int bytes_count); + void InsertChars(int pos, const char* text, const char* text_end = NULL); }; //----------------------------------------------------------------------------- @@ -727,7 +727,6 @@ struct ImFont IMGUI_API void Clear(); IMGUI_API void BuildLookupTable(); IMGUI_API const FntGlyph* FindGlyph(unsigned short c) const; - IMGUI_API float GetFontSize() const { return (float)Info->FontSize; } // before scale! IMGUI_API bool IsLoaded() const { return Info != NULL && Common != NULL && Glyphs != NULL; } // 'max_width' stops rendering after a certain width (could be turned into a 2d size). FLT_MAX to disable. diff --git a/stb_textedit.h b/stb_textedit.h index 872012da..5aa79f02 100644 --- a/stb_textedit.h +++ b/stb_textedit.h @@ -1008,13 +1008,13 @@ static void stb_textedit_discard_undo(StbUndoState *state) int n = state->undo_rec[0].insert_length, i; // delete n characters from all other records state->undo_char_point = state->undo_char_point - (short) n; // vsnet05 - memmove(state->undo_char, state->undo_char + n, (size_t) (state->undo_char_point*sizeof(STB_TEXTEDIT_CHARTYPE))); + memmove(state->undo_char, state->undo_char + n, (size_t) ((size_t)state->undo_char_point*sizeof(STB_TEXTEDIT_CHARTYPE))); for (i=0; i < state->undo_point; ++i) if (state->undo_rec[i].char_storage >= 0) state->undo_rec[i].char_storage = state->undo_rec[i].char_storage - (short) n; // vsnet05 // @OPTIMIZE: get rid of char_storage and infer it } --state->undo_point; - memmove(state->undo_rec, state->undo_rec+1, (size_t) (state->undo_point*sizeof(state->undo_rec[0]))); + memmove(state->undo_rec, state->undo_rec+1, (size_t) ((size_t)state->undo_point*sizeof(state->undo_rec[0]))); } } @@ -1032,13 +1032,13 @@ static void stb_textedit_discard_redo(StbUndoState *state) int n = state->undo_rec[k].insert_length, i; // delete n characters from all other records state->redo_char_point = state->redo_char_point + (short) n; // vsnet05 - memmove(state->undo_char + state->redo_char_point, state->undo_char + state->redo_char_point-n, (size_t) ((STB_TEXTEDIT_UNDOSTATECOUNT - state->redo_char_point)*sizeof(STB_TEXTEDIT_CHARTYPE))); + memmove(state->undo_char + state->redo_char_point, state->undo_char + state->redo_char_point-n, (size_t) ((size_t)(STB_TEXTEDIT_UNDOSTATECOUNT - state->redo_char_point)*sizeof(STB_TEXTEDIT_CHARTYPE))); for (i=state->redo_point; i < k; ++i) if (state->undo_rec[i].char_storage >= 0) state->undo_rec[i].char_storage = state->undo_rec[i].char_storage + (short) n; // vsnet05 } ++state->redo_point; - memmove(state->undo_rec + state->redo_point-1, state->undo_rec + state->redo_point, (size_t) ((STB_TEXTEDIT_UNDOSTATECOUNT - state->redo_point)*sizeof(state->undo_rec[0]))); + memmove(state->undo_rec + state->redo_point-1, state->undo_rec + state->redo_point, (size_t) ((size_t)(STB_TEXTEDIT_UNDOSTATECOUNT - state->redo_point)*sizeof(state->undo_rec[0]))); } } From 214c967df8154d58ed969006dd2e97c30a4dc89c Mon Sep 17 00:00:00 2001 From: ocornut Date: Sun, 30 Nov 2014 12:28:21 +0000 Subject: [PATCH 002/108] Example code: warning fix + comments. --- examples/directx9_example/main.cpp | 4 ++-- examples/opengl_example/main.cpp | 2 +- imgui.h | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/directx9_example/main.cpp b/examples/directx9_example/main.cpp index 16141de2..d20836fa 100644 --- a/examples/directx9_example/main.cpp +++ b/examples/directx9_example/main.cpp @@ -154,8 +154,8 @@ LRESULT WINAPI MsgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) io.MouseDown[1] = false; return true; case WM_MOUSEWHEEL: - // Mouse wheel: -1,0,+1 - io.MouseWheel = GET_WHEEL_DELTA_WPARAM(wParam) > 0 ? +1 : -1; + // Mouse wheel uses integer on Windows + io.MouseWheel = GET_WHEEL_DELTA_WPARAM(wParam) > 0 ? +1.0f : -1.0f; return true; case WM_MOUSEMOVE: // Mouse position, in pixels (set to -1,-1 if no mouse / on another screen, etc.) diff --git a/examples/opengl_example/main.cpp b/examples/opengl_example/main.cpp index ff46b538..8dc96300 100644 --- a/examples/opengl_example/main.cpp +++ b/examples/opengl_example/main.cpp @@ -131,7 +131,7 @@ static void glfw_mouse_button_callback(GLFWwindow* window, int button, int actio static void glfw_scroll_callback(GLFWwindow* window, double xoffset, double yoffset) { ImGuiIO& io = ImGui::GetIO(); - io.MouseWheel = yoffset; // Use fractional mouse wheel, 1.0 unit 3 lines. + io.MouseWheel = (float)yoffset; // Use fractional mouse wheel, 1.0 unit 5 lines. } static void glfw_key_callback(GLFWwindow* window, int key, int scancode, int action, int mods) diff --git a/imgui.h b/imgui.h index 0e73e11c..3da2be43 100644 --- a/imgui.h +++ b/imgui.h @@ -488,7 +488,7 @@ struct ImGuiIO ImVec2 MousePos; // Mouse position, in pixels (set to -1,-1 if no mouse / on another screen, etc.) bool MouseDown[5]; // Mouse buttons. ImGui itself only uses button 0 (left button) but you can use others as storage for convenience. - float MouseWheel; // Mouse wheel: 1 unit scrolls about 3 lines text. + float MouseWheel; // Mouse wheel: 1 unit scrolls about 5 lines text. bool KeyCtrl; // Keyboard modifier pressed: Control bool KeyShift; // Keyboard modifier pressed: Shift bool KeysDown[512]; // Keyboard keys that are pressed (in whatever order user naturally has access to keyboard data) From 38164a410d754b96b588f051445b062776b19a67 Mon Sep 17 00:00:00 2001 From: ocornut Date: Sun, 30 Nov 2014 12:31:43 +0000 Subject: [PATCH 003/108] ImStrnicmp tweak --- imgui.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/imgui.cpp b/imgui.cpp index 2acc58e8..f45b9f2c 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -442,7 +442,7 @@ static int ImStrnicmp(const char* str1, const char* str2, int count) { int d = 0; while (count > 0 && (d = toupper(*str2) - toupper(*str1)) == 0 && *str1) { str1++; str2++; count--; } - return (count == 0) ? 0 : d; + return d; } static char* ImStrdup(const char *str) From b5acb16378c3786ce924669500e0225ee507f1fe Mon Sep 17 00:00:00 2001 From: ocornut Date: Sun, 30 Nov 2014 12:54:27 +0000 Subject: [PATCH 004/108] Examples: created single .sln solution for all example projects. --- ...xample.sln => imgui_examples_msvc2010.sln} | 8 +++++++- examples/opengl_example/opengl_example.sln | 20 ------------------- 2 files changed, 7 insertions(+), 21 deletions(-) rename examples/{directx9_example/directx9_example.sln => imgui_examples_msvc2010.sln} (58%) delete mode 100644 examples/opengl_example/opengl_example.sln diff --git a/examples/directx9_example/directx9_example.sln b/examples/imgui_examples_msvc2010.sln similarity index 58% rename from examples/directx9_example/directx9_example.sln rename to examples/imgui_examples_msvc2010.sln index facadec7..d5bb1848 100644 --- a/examples/directx9_example/directx9_example.sln +++ b/examples/imgui_examples_msvc2010.sln @@ -1,7 +1,9 @@  Microsoft Visual Studio Solution File, Format Version 11.00 # Visual Studio 2010 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "directx9_example", "directx9_example.vcxproj", "{4165A294-21F2-44CA-9B38-E3F935ABADF5}" +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "opengl_example", "opengl_example\opengl_example.vcxproj", "{9CDA7840-B7A5-496D-A527-E95571496D18}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "directx9_example", "directx9_example\directx9_example.vcxproj", "{4165A294-21F2-44CA-9B38-E3F935ABADF5}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -9,6 +11,10 @@ Global Release|Win32 = Release|Win32 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution + {9CDA7840-B7A5-496D-A527-E95571496D18}.Debug|Win32.ActiveCfg = Debug|Win32 + {9CDA7840-B7A5-496D-A527-E95571496D18}.Debug|Win32.Build.0 = Debug|Win32 + {9CDA7840-B7A5-496D-A527-E95571496D18}.Release|Win32.ActiveCfg = Release|Win32 + {9CDA7840-B7A5-496D-A527-E95571496D18}.Release|Win32.Build.0 = Release|Win32 {4165A294-21F2-44CA-9B38-E3F935ABADF5}.Debug|Win32.ActiveCfg = Debug|Win32 {4165A294-21F2-44CA-9B38-E3F935ABADF5}.Debug|Win32.Build.0 = Debug|Win32 {4165A294-21F2-44CA-9B38-E3F935ABADF5}.Release|Win32.ActiveCfg = Release|Win32 diff --git a/examples/opengl_example/opengl_example.sln b/examples/opengl_example/opengl_example.sln deleted file mode 100644 index b4905b1e..00000000 --- a/examples/opengl_example/opengl_example.sln +++ /dev/null @@ -1,20 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 11.00 -# Visual Studio 2010 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "opengl_example", "opengl_example.vcxproj", "{9CDA7840-B7A5-496D-A527-E95571496D18}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Win32 = Debug|Win32 - Release|Win32 = Release|Win32 - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {9CDA7840-B7A5-496D-A527-E95571496D18}.Debug|Win32.ActiveCfg = Debug|Win32 - {9CDA7840-B7A5-496D-A527-E95571496D18}.Debug|Win32.Build.0 = Debug|Win32 - {9CDA7840-B7A5-496D-A527-E95571496D18}.Release|Win32.ActiveCfg = Release|Win32 - {9CDA7840-B7A5-496D-A527-E95571496D18}.Release|Win32.Build.0 = Release|Win32 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection -EndGlobal From 9e1631738243654b3847baed58deb1578744d14b Mon Sep 17 00:00:00 2001 From: ocornut Date: Sun, 30 Nov 2014 14:59:21 +0000 Subject: [PATCH 005/108] Added DirectX11 example application (code is too long!) --- .../directx11_example.vcxproj | 82 +++ .../directx11_example.vcxproj.filters | 38 ++ examples/directx11_example/main.cpp | 627 ++++++++++++++++++ .../directx9_example/directx9_example.vcxproj | 4 +- examples/directx9_example/main.cpp | 28 +- examples/imgui_examples_msvc2010.sln | 6 + examples/opengl_example/main.cpp | 10 +- .../opengl_example/opengl_example.vcxproj | 2 +- .../opengl_example.vcxproj.filters | 6 +- examples/shared/README.txt | 3 + .../{opengl_example => shared}/stb_image.h | 0 11 files changed, 781 insertions(+), 25 deletions(-) create mode 100644 examples/directx11_example/directx11_example.vcxproj create mode 100644 examples/directx11_example/directx11_example.vcxproj.filters create mode 100644 examples/directx11_example/main.cpp create mode 100644 examples/shared/README.txt rename examples/{opengl_example => shared}/stb_image.h (100%) diff --git a/examples/directx11_example/directx11_example.vcxproj b/examples/directx11_example/directx11_example.vcxproj new file mode 100644 index 00000000..ae9e216a --- /dev/null +++ b/examples/directx11_example/directx11_example.vcxproj @@ -0,0 +1,82 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + + {9F316E83-5AE5-4939-A723-305A94F48005} + directx11_example + + + + Application + true + MultiByte + v110 + + + Application + false + true + MultiByte + v110 + + + + + + + + + + + + + + + Level3 + Disabled + + + true + d3d11.lib;d3dcompiler.lib;dxgi.lib;imm32.lib;%(AdditionalDependencies) + + + + + Level3 + MaxSpeed + true + true + + + true + true + true + d3d11.lib;d3dcompiler.lib;dxgi.lib;imm32.lib;%(AdditionalDependencies) + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/examples/directx11_example/directx11_example.vcxproj.filters b/examples/directx11_example/directx11_example.vcxproj.filters new file mode 100644 index 00000000..19429f4c --- /dev/null +++ b/examples/directx11_example/directx11_example.vcxproj.filters @@ -0,0 +1,38 @@ + + + + + {0587d7a3-f2ce-4d56-b84f-a0005d3bfce6} + + + {08e36723-ce4f-4cff-9662-c40801cf1acf} + + + + + imgui + + + imgui + + + imgui + + + sources + + + + + imgui + + + sources + + + + + imgui + + + \ No newline at end of file diff --git a/examples/directx11_example/main.cpp b/examples/directx11_example/main.cpp new file mode 100644 index 00000000..00835976 --- /dev/null +++ b/examples/directx11_example/main.cpp @@ -0,0 +1,627 @@ +#include +#include +#define STB_IMAGE_IMPLEMENTATION +#include "../shared/stb_image.h" // for .png loading +#include "../../imgui.h" + +// DirectX +#include +#include +#define DIRECTINPUT_VERSION 0x0800 +#include + +#pragma warning (disable: 4996) // 'This function or variable may be unsafe': strdup + +extern const char* vertexShader; // Implemented at the bottom +extern const char* pixelShader; + +static HWND hWnd; +static ID3D11Device* g_pd3dDevice = NULL; +static ID3D11DeviceContext* g_pd3dDeviceImmediateContext = NULL; +static IDXGISwapChain* g_pSwapChain = NULL; +static ID3D11Buffer* g_pVB = NULL; +static ID3D11RenderTargetView* g_mainRenderTargetView; + +static ID3D10Blob * g_pVertexShaderBlob = NULL; +static ID3D11VertexShader* g_pVertexShader = NULL; +static ID3D11InputLayout* g_pInputLayout = NULL; +static ID3D11Buffer* g_pVertexConstantBuffer = NULL; + +static ID3D10Blob * g_pPixelShaderBlob = NULL; +static ID3D11PixelShader* g_pPixelShader = NULL; + +static ID3D11ShaderResourceView*g_pFontTextureView = NULL; +static ID3D11SamplerState* g_pFontSampler = NULL; +static ID3D11BlendState* g_blendState = NULL; + +struct CUSTOMVERTEX +{ + float pos[2]; + float uv[2]; + unsigned int col; +}; + +struct VERTEX_CONSTANT_BUFFER +{ + float mvp[4][4]; +}; + +// This is the main rendering function that you have to implement and provide to ImGui (via setting up 'RenderDrawListsFn' in the ImGuiIO structure) +// If text or lines are blurry when integrating ImGui in your engine: +// - in your Render function, try translating your projection matrix by (0.5f,0.5f) or (0.375f,0.375f) +// - try adjusting ImGui::GetIO().PixelCenterOffset to 0.5f or 0.375f +static void ImImpl_RenderDrawLists(ImDrawList** const cmd_lists, int cmd_lists_count) +{ + size_t total_vtx_count = 0; + for (int n = 0; n < cmd_lists_count; n++) + total_vtx_count += cmd_lists[n]->vtx_buffer.size(); + if (total_vtx_count == 0) + return; + + // Copy and convert all vertices into a single contiguous buffer + D3D11_MAPPED_SUBRESOURCE mappedResource; + if (g_pd3dDeviceImmediateContext->Map(g_pVB, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource) != S_OK) + return; + CUSTOMVERTEX* vtx_dst = (CUSTOMVERTEX*)mappedResource.pData; + for (int n = 0; n < cmd_lists_count; n++) + { + const ImDrawList* cmd_list = cmd_lists[n]; + const ImDrawVert* vtx_src = &cmd_list->vtx_buffer[0]; + for (size_t i = 0; i < cmd_list->vtx_buffer.size(); i++) + { + vtx_dst->pos[0] = vtx_src->pos.x; + vtx_dst->pos[1] = vtx_src->pos.y; + vtx_dst->uv[0] = vtx_src->uv.x; + vtx_dst->uv[1] = vtx_src->uv.y; + vtx_dst->col = vtx_src->col; + vtx_dst++; + vtx_src++; + } + } + g_pd3dDeviceImmediateContext->Unmap(g_pVB, 0); + + // Setup orthographic projection matrix into our constant buffer + { + D3D11_MAPPED_SUBRESOURCE mappedResource; + if (g_pd3dDeviceImmediateContext->Map(g_pVertexConstantBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource) != S_OK) + return; + + VERTEX_CONSTANT_BUFFER* pConstantBuffer = (VERTEX_CONSTANT_BUFFER*)mappedResource.pData; + const float L = 0.5f; + const float R = ImGui::GetIO().DisplaySize.x + 0.5f; + const float B = ImGui::GetIO().DisplaySize.y + 0.5f; + const float T = 0.5f; + const float mvp[4][4] = + { + { 2.0f/(R-L), 0.0f, 0.0f, 0.0f}, + { 0.0f, 2.0f/(T-B), 0.0f, 0.0f,}, + { 0.0f, 0.0f, 0.5f, 0.0f }, // -1.0f + { (R+L)/(L-R), (T+B)/(B-T), 0.5f, 1.0f }, // 0.0f + }; + memcpy(&pConstantBuffer->mvp, mvp, sizeof(mvp)); + g_pd3dDeviceImmediateContext->Unmap(g_pVertexConstantBuffer, 0); + } + + // Setup viewport + { + D3D11_VIEWPORT vp; + memset(&vp, 0, sizeof(D3D11_VIEWPORT)); + vp.Width = ImGui::GetIO().DisplaySize.x; + vp.Height = ImGui::GetIO().DisplaySize.y; + vp.MinDepth = 0.0f; + vp.MaxDepth = 1.0f; + vp.TopLeftX = 0; + vp.TopLeftY = 0; + g_pd3dDeviceImmediateContext->RSSetViewports(1, &vp); + } + + // Bind shader and vertex buffers + g_pd3dDeviceImmediateContext->IASetInputLayout(g_pInputLayout); + unsigned int stride = sizeof(CUSTOMVERTEX); + unsigned int offset = 0; + g_pd3dDeviceImmediateContext->IASetVertexBuffers(0, 1, &g_pVB, &stride, &offset); + g_pd3dDeviceImmediateContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST); + + g_pd3dDeviceImmediateContext->VSSetShader(g_pVertexShader, NULL, 0); + g_pd3dDeviceImmediateContext->VSSetConstantBuffers(0, 1, &g_pVertexConstantBuffer); + + g_pd3dDeviceImmediateContext->PSSetShader(g_pPixelShader, NULL, 0); + g_pd3dDeviceImmediateContext->PSSetShaderResources(0, 1, &g_pFontTextureView); + g_pd3dDeviceImmediateContext->PSSetSamplers(0, 1, &g_pFontSampler); + + // Setup render state + const float blendFactor[4] = { 0.f, 0.f, 0.f, 0.f }; + const UINT sampleMask = 0xffffffff; + g_pd3dDeviceImmediateContext->OMSetBlendState(g_blendState, blendFactor, sampleMask); + + // Render command lists + int vtx_offset = 0; + for (int n = 0; n < cmd_lists_count; n++) + { + // Render command list + const ImDrawList* cmd_list = cmd_lists[n]; + for (size_t cmd_i = 0; cmd_i < cmd_list->commands.size(); cmd_i++) + { + const ImDrawCmd* pcmd = &cmd_list->commands[cmd_i]; + const D3D11_RECT r = { (LONG)pcmd->clip_rect.x, (LONG)pcmd->clip_rect.y, (LONG)pcmd->clip_rect.z, (LONG)pcmd->clip_rect.w }; + g_pd3dDeviceImmediateContext->RSSetScissorRects(1, &r); + g_pd3dDeviceImmediateContext->Draw(pcmd->vtx_count, vtx_offset); + vtx_offset += pcmd->vtx_count; + } + } + + // Restore modified state + g_pd3dDeviceImmediateContext->IASetInputLayout(NULL); + g_pd3dDeviceImmediateContext->PSSetShader(NULL, NULL, 0); + g_pd3dDeviceImmediateContext->VSSetShader(NULL, NULL, 0); +} + +HRESULT InitD3D(HWND hWnd) +{ + IDXGIFactory1* pFactory = NULL; + CreateDXGIFactory1(__uuidof(IDXGIFactory1), (void**)&pFactory); + + DXGI_SWAP_CHAIN_DESC sd; + // Setup the swap chain + { + // Setup swap chain + ZeroMemory(&sd, sizeof(sd)); + + sd.BufferCount = 2; + sd.BufferDesc.Width = (UINT)ImGui::GetIO().DisplaySize.x; + sd.BufferDesc.Height = (UINT)ImGui::GetIO().DisplaySize.y; + sd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; + sd.BufferDesc.RefreshRate.Numerator = 60; + sd.BufferDesc.RefreshRate.Denominator = 1; + sd.Flags = DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH; + sd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; + sd.OutputWindow = hWnd; + sd.SampleDesc.Count = 1; + sd.SampleDesc.Quality = 0; + sd.Windowed = TRUE; + sd.SwapEffect = DXGI_SWAP_EFFECT_DISCARD; + } + + UINT createDeviceFlags = 0; +#ifdef _DEBUG + createDeviceFlags |= D3D11_CREATE_DEVICE_DEBUG; +#endif + D3D_FEATURE_LEVEL featureLevel; + const D3D_FEATURE_LEVEL featureLevelArray[1] = { D3D_FEATURE_LEVEL_11_0, }; + if (D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, createDeviceFlags, featureLevelArray, 1, D3D11_SDK_VERSION, &sd, &g_pSwapChain, &g_pd3dDevice, &featureLevel, &g_pd3dDeviceImmediateContext) != S_OK) + return E_FAIL; + + // Setup rasterizer + { + D3D11_RASTERIZER_DESC RSDesc; + memset(&RSDesc, 0, sizeof(D3D11_RASTERIZER_DESC)); + RSDesc.FillMode = D3D11_FILL_SOLID; + RSDesc.CullMode = D3D11_CULL_NONE; + RSDesc.FrontCounterClockwise = FALSE; + RSDesc.DepthBias = 0; + RSDesc.SlopeScaledDepthBias = 0.0f; + RSDesc.DepthBiasClamp = 0; + RSDesc.DepthClipEnable = TRUE; + RSDesc.ScissorEnable = TRUE; + RSDesc.AntialiasedLineEnable = FALSE; + if (sd.SampleDesc.Count > 1) + RSDesc.MultisampleEnable = TRUE; + else + RSDesc.MultisampleEnable = FALSE; + + ID3D11RasterizerState* g_pRState = NULL; + g_pd3dDevice->CreateRasterizerState(&RSDesc, &g_pRState); + g_pd3dDeviceImmediateContext->RSSetState(g_pRState); + } + + // Create the render target + { + ID3D11Texture2D* g_pBackBuffer; + D3D11_RENDER_TARGET_VIEW_DESC render_target_view_desc; + ZeroMemory(&render_target_view_desc, sizeof(render_target_view_desc)); + render_target_view_desc.Format = sd.BufferDesc.Format; + render_target_view_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D; + + g_pSwapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), (LPVOID*)&g_pBackBuffer); + g_pd3dDevice->CreateRenderTargetView(g_pBackBuffer, &render_target_view_desc, &g_mainRenderTargetView); + + g_pd3dDeviceImmediateContext->OMSetRenderTargets(1, &g_mainRenderTargetView, NULL); + } + + + // Create the vertex shader + { + ID3D10Blob * pErrorBlob; + D3DCompile(vertexShader, strlen(vertexShader), NULL, NULL, NULL, "main", "vs_5_0", 0, 0, &g_pVertexShaderBlob, &pErrorBlob); + + if (g_pVertexShaderBlob == NULL) + { + const char* pError = (const char*)pErrorBlob->GetBufferPointer(); + pErrorBlob->Release(); + return E_FAIL; + } + + if (g_pd3dDevice->CreateVertexShader((DWORD*)g_pVertexShaderBlob->GetBufferPointer(), g_pVertexShaderBlob->GetBufferSize(), NULL, &g_pVertexShader) != S_OK) + return E_FAIL; + + if (pErrorBlob) + pErrorBlob->Release(); + + // Create the input layout + D3D11_INPUT_ELEMENT_DESC localLayout[] = { + { "POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, (size_t)(&((CUSTOMVERTEX*)0)->pos), D3D11_INPUT_PER_VERTEX_DATA, 0 }, + { "COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, (size_t)(&((CUSTOMVERTEX*)0)->col), D3D11_INPUT_PER_VERTEX_DATA, 0 }, + { "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, (size_t)(&((CUSTOMVERTEX*)0)->uv), D3D11_INPUT_PER_VERTEX_DATA, 0 }, + }; + + if (g_pd3dDevice->CreateInputLayout(localLayout, 3, g_pVertexShaderBlob->GetBufferPointer(), g_pVertexShaderBlob->GetBufferSize(), &g_pInputLayout) != S_OK) + return E_FAIL; + + // Create the constant buffer + { + D3D11_BUFFER_DESC cbDesc; + cbDesc.ByteWidth = sizeof(VERTEX_CONSTANT_BUFFER); + cbDesc.Usage = D3D11_USAGE_DYNAMIC; + cbDesc.BindFlags = D3D11_BIND_CONSTANT_BUFFER; + cbDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; + cbDesc.MiscFlags = 0; + g_pd3dDevice->CreateBuffer(&cbDesc, NULL, &g_pVertexConstantBuffer); + } + } + + // Create the pixel shader + { + ID3D10Blob * pErrorBlob; + D3DCompile(pixelShader, strlen(pixelShader), NULL, NULL, NULL, "main", "ps_5_0", 0, 0, &g_pPixelShaderBlob, &pErrorBlob); + + if (g_pPixelShaderBlob == NULL) + { + const char* pError = (const char*)pErrorBlob->GetBufferPointer(); + pErrorBlob->Release(); + return E_FAIL; + } + + if (g_pd3dDevice->CreatePixelShader((DWORD*)g_pPixelShaderBlob->GetBufferPointer(), g_pPixelShaderBlob->GetBufferSize(), NULL, &g_pPixelShader) != S_OK) + return E_FAIL; + + if (pErrorBlob) + pErrorBlob->Release(); + } + + // Create the blending setup + { + D3D11_BLEND_DESC desc; + ZeroMemory(&desc, sizeof(desc)); + desc.AlphaToCoverageEnable = false; + desc.RenderTarget[0].BlendEnable = true; + desc.RenderTarget[0].SrcBlend = D3D11_BLEND_SRC_ALPHA; + desc.RenderTarget[0].DestBlend = D3D11_BLEND_INV_SRC_ALPHA; + desc.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD; + desc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_INV_SRC_ALPHA; + desc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_ZERO; + desc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD; + desc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL; + g_pd3dDevice->CreateBlendState(&desc, &g_blendState); + } + + return S_OK; +} + +LRESULT WINAPI MsgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) +{ + ImGuiIO& io = ImGui::GetIO(); + switch (msg) + { + case WM_LBUTTONDOWN: + io.MouseDown[0] = true; + return true; + case WM_LBUTTONUP: + io.MouseDown[0] = false; + return true; + case WM_RBUTTONDOWN: + io.MouseDown[1] = true; + return true; + case WM_RBUTTONUP: + io.MouseDown[1] = false; + return true; + case WM_MOUSEWHEEL: + io.MouseWheel = GET_WHEEL_DELTA_WPARAM(wParam) > 0 ? +1.0f : -1.0f; + return true; + case WM_MOUSEMOVE: + // Mouse position, in pixels (set to -1,-1 if no mouse / on another screen, etc.) + io.MousePos.x = (signed short)(lParam); + io.MousePos.y = (signed short)(lParam >> 16); + return true; + case WM_CHAR: + // You can also use ToAscii()+GetKeyboardState() to retrieve characters. + if (wParam > 0 && wParam < 0x10000) + io.AddInputCharacter((unsigned short)wParam); + return true; + case WM_DESTROY: + PostQuitMessage(0); + return 0; + } + return DefWindowProc(hWnd, msg, wParam, lParam); +} + +// Notify OS Input Method Editor of text input position (e.g. when using Japanese/Chinese inputs, otherwise this isn't needed) +static void ImImpl_ImeSetInputScreenPosFn(int x, int y) +{ + if (HIMC himc = ImmGetContext(hWnd)) + { + COMPOSITIONFORM cf; + cf.ptCurrentPos.x = x; + cf.ptCurrentPos.y = y; + cf.dwStyle = CFS_FORCE_POSITION; + ImmSetCompositionWindow(himc, &cf); + } +} + +void InitImGui() +{ + RECT rect; + GetClientRect(hWnd, &rect); + + ImGuiIO& io = ImGui::GetIO(); + io.DisplaySize = ImVec2((float)(rect.right - rect.left), (float)(rect.bottom - rect.top)); // Display size, in pixels. For clamping windows positions. + io.DeltaTime = 1.0f/60.0f; // Time elapsed since last frame, in seconds (in this sample app we'll override this every frame because our timestep is variable) + io.PixelCenterOffset = 0.0f; // Align Direct3D Texels + io.KeyMap[ImGuiKey_Tab] = VK_TAB; // Keyboard mapping. ImGui will use those indices to peek into the io.KeyDown[] array that we will update during the application lifetime. + io.KeyMap[ImGuiKey_LeftArrow] = VK_LEFT; + io.KeyMap[ImGuiKey_RightArrow] = VK_RIGHT; + io.KeyMap[ImGuiKey_UpArrow] = VK_UP; + io.KeyMap[ImGuiKey_DownArrow] = VK_UP; + io.KeyMap[ImGuiKey_Home] = VK_HOME; + io.KeyMap[ImGuiKey_End] = VK_END; + io.KeyMap[ImGuiKey_Delete] = VK_DELETE; + io.KeyMap[ImGuiKey_Backspace] = VK_BACK; + io.KeyMap[ImGuiKey_Enter] = VK_RETURN; + io.KeyMap[ImGuiKey_Escape] = VK_ESCAPE; + io.KeyMap[ImGuiKey_A] = 'A'; + io.KeyMap[ImGuiKey_C] = 'C'; + io.KeyMap[ImGuiKey_V] = 'V'; + io.KeyMap[ImGuiKey_X] = 'X'; + io.KeyMap[ImGuiKey_Y] = 'Y'; + io.KeyMap[ImGuiKey_Z] = 'Z'; + + io.RenderDrawListsFn = ImImpl_RenderDrawLists; + io.ImeSetInputScreenPosFn = ImImpl_ImeSetInputScreenPosFn; + + // Create the vertex buffer + { + D3D11_BUFFER_DESC bufferDesc; + memset(&bufferDesc, 0, sizeof(D3D11_BUFFER_DESC)); + + bufferDesc.Usage = D3D11_USAGE_DYNAMIC; + bufferDesc.ByteWidth = 10000 * sizeof(CUSTOMVERTEX); + bufferDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER; + bufferDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; + bufferDesc.MiscFlags = 0; + + if (g_pd3dDevice->CreateBuffer(&bufferDesc, NULL, &g_pVB) < 0) + { + IM_ASSERT(0); + return; + } + } + + // Load font texture + // Default font (embedded in code) + const void* png_data; + unsigned int png_size; + ImGui::GetDefaultFontData(NULL, NULL, &png_data, &png_size); + int tex_x, tex_y, tex_comp; + void* tex_data = stbi_load_from_memory((const unsigned char*)png_data, (int)png_size, &tex_x, &tex_y, &tex_comp, 0); + IM_ASSERT(tex_data != NULL); + + { + D3D11_TEXTURE2D_DESC desc; + ZeroMemory(&desc, sizeof(desc)); + desc.Width = tex_x; + desc.Height = tex_y; + desc.MipLevels = 1; + desc.ArraySize = 1; + desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; + desc.SampleDesc.Count = 1; + desc.Usage = D3D11_USAGE_DEFAULT; + desc.BindFlags = D3D11_BIND_SHADER_RESOURCE; + desc.CPUAccessFlags = 0; + + ID3D11Texture2D *pTexture = NULL; + D3D11_SUBRESOURCE_DATA subResource; + subResource.pSysMem = tex_data; + subResource.SysMemPitch = tex_x * 4; + subResource.SysMemSlicePitch = 0; + g_pd3dDevice->CreateTexture2D(&desc, &subResource, &pTexture); + + // create texture view + D3D11_SHADER_RESOURCE_VIEW_DESC srvDesc; + ZeroMemory(&srvDesc, sizeof(srvDesc)); + srvDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; + srvDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D; + srvDesc.Texture2D.MipLevels = desc.MipLevels; + srvDesc.Texture2D.MostDetailedMip = 0; + g_pd3dDevice->CreateShaderResourceView(pTexture, &srvDesc, &g_pFontTextureView); + } + + // create texture sampler + { + D3D11_SAMPLER_DESC desc; + ZeroMemory(&desc, sizeof(desc)); + desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT; + desc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP; + desc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP; + desc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP; + desc.MipLODBias = 0.f; + desc.ComparisonFunc = D3D11_COMPARISON_ALWAYS; + desc.MinLOD = 0.f; + desc.MaxLOD = 0.f; + g_pd3dDevice->CreateSamplerState(&desc, &g_pFontSampler); + } +} + +INT64 ticks_per_second = 0; +INT64 time = 0; + +void UpdateImGui() +{ + ImGuiIO& io = ImGui::GetIO(); + + // Setup timestep + INT64 current_time; + QueryPerformanceCounter((LARGE_INTEGER *)¤t_time); + io.DeltaTime = (float)(current_time - time) / ticks_per_second; + time = current_time; + + // Setup inputs + // (we already got mouse position, buttons, wheel from the window message callback) + BYTE keystate[256]; + GetKeyboardState(keystate); + for (int i = 0; i < 256; i++) + io.KeysDown[i] = (keystate[i] & 0x80) != 0; + io.KeyCtrl = (keystate[VK_CONTROL] & 0x80) != 0; + io.KeyShift = (keystate[VK_SHIFT] & 0x80) != 0; + // io.MousePos : filled by WM_MOUSEMOVE event + // io.MouseDown : filled by WM_*BUTTON* events + // io.MouseWheel : filled by WM_MOUSEWHEEL events + + // Start the frame + ImGui::NewFrame(); +} + +int WINAPI wWinMain(HINSTANCE hInst, HINSTANCE, LPWSTR, int) +{ + // Register the window class + WNDCLASSEX wc = { sizeof(WNDCLASSEX), CS_CLASSDC, MsgProc, 0L, 0L, GetModuleHandle(NULL), NULL, NULL, NULL, NULL, "ImGui Example", NULL }; + RegisterClassEx(&wc); + + // Create the application's window + hWnd = CreateWindow("ImGui Example", "ImGui DirectX11 Example", WS_OVERLAPPEDWINDOW, 100, 100, 1280, 800, NULL, NULL, wc.hInstance, NULL); + + if (!QueryPerformanceFrequency((LARGE_INTEGER *)&ticks_per_second)) + return 1; + if (!QueryPerformanceCounter((LARGE_INTEGER *)&time)) + return 1; + + // Initialize Direct3D + if (InitD3D(hWnd) < 0) + { + UnregisterClass("ImGui Example", wc.hInstance); + return 1; + } + + // Show the window + ShowWindow(hWnd, SW_SHOWDEFAULT); + UpdateWindow(hWnd); + + InitImGui(); + + // Enter the message loop + MSG msg; + ZeroMemory(&msg, sizeof(msg)); + while (msg.message != WM_QUIT) + { + if (PeekMessage(&msg, NULL, 0U, 0U, PM_REMOVE)) + { + TranslateMessage(&msg); + DispatchMessage(&msg); + continue; + } + + UpdateImGui(); + + static bool show_test_window = true; + static bool show_another_window = false; + + // 1. Show a simple window + // Tip: if we don't call ImGui::Begin()/ImGui::End() the widgets appears in a window automatically called "Debug" + { + static float f; + ImGui::Text("Hello, world!"); + ImGui::SliderFloat("float", &f, 0.0f, 1.0f); + show_test_window ^= ImGui::Button("Test Window"); + show_another_window ^= ImGui::Button("Another Window"); + + // Calculate and show frame rate + static float ms_per_frame[120] = { 0 }; + static int ms_per_frame_idx = 0; + static float ms_per_frame_accum = 0.0f; + ms_per_frame_accum -= ms_per_frame[ms_per_frame_idx]; + ms_per_frame[ms_per_frame_idx] = ImGui::GetIO().DeltaTime * 1000.0f; + ms_per_frame_accum += ms_per_frame[ms_per_frame_idx]; + ms_per_frame_idx = (ms_per_frame_idx + 1) % 120; + const float ms_per_frame_avg = ms_per_frame_accum / 120; + ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", ms_per_frame_avg, 1000.0f / ms_per_frame_avg); + } + + // 2. Show another simple window, this time using an explicit Begin/End pair + if (show_another_window) + { + ImGui::Begin("Another Window", &show_another_window, ImVec2(200,100)); + ImGui::Text("Hello"); + ImGui::End(); + } + + // 3. Show the ImGui test window. Most of the sample code is in ImGui::ShowTestWindow() + if (show_test_window) + { + ImGui::SetNewWindowDefaultPos(ImVec2(650, 20)); // Normally user code doesn't need/want to call it because positions are saved in .ini file anyway. Here we just want to make the demo initial state a bit more friendly! + ImGui::ShowTestWindow(&show_test_window); + } + + // Rendering + float clearColor[4] = { 204 / 255.f, 153 / 255.f, 153 / 255.f }; + g_pd3dDeviceImmediateContext->ClearRenderTargetView(g_mainRenderTargetView, clearColor); + ImGui::Render(); + g_pSwapChain->Present(0, 0); + } + + ImGui::Shutdown(); + + UnregisterClass("ImGui Example", wc.hInstance); + return 0; +} + +static const char* vertexShader = "\ +cbuffer vertexBuffer : register(c0) \ +{\ + float4x4 ProjectionMatrix; \ +};\ +struct VS_INPUT\ +{\ + float2 pos : POSITION;\ + float4 col : COLOR0;\ + float2 uv : TEXCOORD0;\ +};\ +\ +struct PS_INPUT\ +{\ + float4 pos : SV_POSITION;\ + float4 col : COLOR0;\ + float2 uv : TEXCOORD0;\ +};\ +\ +PS_INPUT main(VS_INPUT input)\ +{\ + PS_INPUT output;\ + output.pos = mul( ProjectionMatrix, float4(input.pos.xy, 0.f, 1.f));\ + output.col = input.col;\ + output.uv = input.uv;\ + return output;\ +}"; + +static const char* pixelShader = "\ +struct PS_INPUT\ +{\ + float4 pos : SV_POSITION;\ + float4 col : COLOR0;\ + float2 uv : TEXCOORD0;\ +};\ +sampler sampler0;\ +Texture2D texture0;\ +\ +float4 main(PS_INPUT input) : SV_Target\ +{\ + float4 out_col = texture0.Sample(sampler0, input.uv);\ + return input.col * out_col;\ +}"; diff --git a/examples/directx9_example/directx9_example.vcxproj b/examples/directx9_example/directx9_example.vcxproj index df288311..60b70700 100644 --- a/examples/directx9_example/directx9_example.vcxproj +++ b/examples/directx9_example/directx9_example.vcxproj @@ -46,7 +46,7 @@ true $(DXSDK_DIR)Lib\x86;%(AdditionalLibraryDirectories) - d3d9.lib;d3dx9d.lib;dxerr.lib;dxguid.lib;winmm.lib;comctl32.lib;gdi32.lib;imm32.lib;user32.lib + d3d9.lib;d3dx9d.lib;dxerr.lib;dxguid.lib;imm32.lib;%(AdditionalDependencies) @@ -64,7 +64,7 @@ true true $(DXSDK_DIR)Lib\x86;%(AdditionalLibraryDirectories) - d3d9.lib;d3dx9d.lib;dxerr.lib;dxguid.lib;winmm.lib;comctl32.lib;gdi32.lib;imm32.lib;user32.lib + d3d9.lib;d3dx9d.lib;dxerr.lib;dxguid.lib;imm32.lib;%(AdditionalDependencies) diff --git a/examples/directx9_example/main.cpp b/examples/directx9_example/main.cpp index d20836fa..ac26ae28 100644 --- a/examples/directx9_example/main.cpp +++ b/examples/directx9_example/main.cpp @@ -1,23 +1,24 @@ #include #include -#include +#include "../../imgui.h" + +// DirectX #include #define DIRECTINPUT_VERSION 0x0800 #include -#include "../../imgui.h" #pragma warning (disable: 4996) // 'This function or variable may be unsafe': strdup -static HWND hWnd; +static HWND hWnd; static LPDIRECT3D9 g_pD3D = NULL; // Used to create the D3DDevice static LPDIRECT3DDEVICE9 g_pd3dDevice = NULL; // Our rendering device static LPDIRECT3DVERTEXBUFFER9 g_pVB = NULL; // Buffer to hold vertices static LPDIRECT3DTEXTURE9 g_pTexture = NULL; // Our texture struct CUSTOMVERTEX { - D3DXVECTOR3 position; - D3DCOLOR color; - float tu, tv; + D3DXVECTOR3 pos; + D3DCOLOR col; + D3DXVECTOR2 uv; }; #define D3DFVF_CUSTOMVERTEX (D3DFVF_XYZ|D3DFVF_DIFFUSE|D3DFVF_TEX1) @@ -43,12 +44,12 @@ static void ImImpl_RenderDrawLists(ImDrawList** const cmd_lists, int cmd_lists_c const ImDrawVert* vtx_src = &cmd_list->vtx_buffer[0]; for (size_t i = 0; i < cmd_list->vtx_buffer.size(); i++) { - vtx_dst->position.x = vtx_src->pos.x; - vtx_dst->position.y = vtx_src->pos.y; - vtx_dst->position.z = 0.0f; - vtx_dst->color = (vtx_src->col & 0xFF00FF00) | ((vtx_src->col & 0xFF0000)>>16) | ((vtx_src->col & 0xFF) << 16); // RGBA --> ARGB for DirectX9 - vtx_dst->tu = vtx_src->uv.x; - vtx_dst->tv = vtx_src->uv.y; + vtx_dst->pos.x = vtx_src->pos.x; + vtx_dst->pos.y = vtx_src->pos.y; + vtx_dst->pos.z = 0.0f; + vtx_dst->col = (vtx_src->col & 0xFF00FF00) | ((vtx_src->col & 0xFF0000)>>16) | ((vtx_src->col & 0xFF) << 16); // RGBA --> ARGB for DirectX9 + vtx_dst->uv.x = vtx_src->uv.x; + vtx_dst->uv.y = vtx_src->uv.y; vtx_dst++; vtx_src++; } @@ -154,7 +155,6 @@ LRESULT WINAPI MsgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) io.MouseDown[1] = false; return true; case WM_MOUSEWHEEL: - // Mouse wheel uses integer on Windows io.MouseWheel = GET_WHEEL_DELTA_WPARAM(wParam) > 0 ? +1.0f : -1.0f; return true; case WM_MOUSEMOVE: @@ -320,7 +320,7 @@ int WINAPI wWinMain(HINSTANCE hInst, HINSTANCE, LPWSTR, int) show_test_window ^= ImGui::Button("Test Window"); show_another_window ^= ImGui::Button("Another Window"); - // Calculate and show framerate + // Calculate and show frame rate static float ms_per_frame[120] = { 0 }; static int ms_per_frame_idx = 0; static float ms_per_frame_accum = 0.0f; diff --git a/examples/imgui_examples_msvc2010.sln b/examples/imgui_examples_msvc2010.sln index d5bb1848..05c018d2 100644 --- a/examples/imgui_examples_msvc2010.sln +++ b/examples/imgui_examples_msvc2010.sln @@ -5,6 +5,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "opengl_example", "opengl_ex EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "directx9_example", "directx9_example\directx9_example.vcxproj", "{4165A294-21F2-44CA-9B38-E3F935ABADF5}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "directx11_example", "directx11_example\directx11_example.vcxproj", "{9F316E83-5AE5-4939-A723-305A94F48005}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Win32 = Debug|Win32 @@ -19,6 +21,10 @@ Global {4165A294-21F2-44CA-9B38-E3F935ABADF5}.Debug|Win32.Build.0 = Debug|Win32 {4165A294-21F2-44CA-9B38-E3F935ABADF5}.Release|Win32.ActiveCfg = Release|Win32 {4165A294-21F2-44CA-9B38-E3F935ABADF5}.Release|Win32.Build.0 = Release|Win32 + {9F316E83-5AE5-4939-A723-305A94F48005}.Debug|Win32.ActiveCfg = Debug|Win32 + {9F316E83-5AE5-4939-A723-305A94F48005}.Debug|Win32.Build.0 = Debug|Win32 + {9F316E83-5AE5-4939-A723-305A94F48005}.Release|Win32.ActiveCfg = Release|Win32 + {9F316E83-5AE5-4939-A723-305A94F48005}.Release|Win32.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/examples/opengl_example/main.cpp b/examples/opengl_example/main.cpp index 8dc96300..2efacced 100644 --- a/examples/opengl_example/main.cpp +++ b/examples/opengl_example/main.cpp @@ -4,7 +4,7 @@ #include #endif #define STB_IMAGE_IMPLEMENTATION -#include "stb_image.h" // for .png loading +#include "../shared/stb_image.h" // for .png loading #include "../../imgui.h" // glew & glfw @@ -77,11 +77,11 @@ static void ImImpl_RenderDrawLists(ImDrawList** const cmd_lists, int cmd_lists_c vtx_offset += pcmd->vtx_count; } } - glDisableClientState(GL_COLOR_ARRAY); + + // Restore modified state + glDisableClientState(GL_COLOR_ARRAY); glDisableClientState(GL_TEXTURE_COORD_ARRAY); glDisableClientState(GL_VERTEX_ARRAY); - - // Restore modified state glMatrixMode(GL_MODELVIEW); glPopMatrix(); glMatrixMode(GL_PROJECTION); @@ -294,7 +294,7 @@ int main(int argc, char** argv) show_test_window ^= ImGui::Button("Test Window"); show_another_window ^= ImGui::Button("Another Window"); - // Calculate and show framerate + // Calculate and show frame rate static float ms_per_frame[120] = { 0 }; static int ms_per_frame_idx = 0; static float ms_per_frame_accum = 0.0f; diff --git a/examples/opengl_example/opengl_example.vcxproj b/examples/opengl_example/opengl_example.vcxproj index 0ff40ca9..e53123c0 100644 --- a/examples/opengl_example/opengl_example.vcxproj +++ b/examples/opengl_example/opengl_example.vcxproj @@ -75,7 +75,7 @@ - + diff --git a/examples/opengl_example/opengl_example.vcxproj.filters b/examples/opengl_example/opengl_example.vcxproj.filters index 4f657bf8..baab0575 100644 --- a/examples/opengl_example/opengl_example.vcxproj.filters +++ b/examples/opengl_example/opengl_example.vcxproj.filters @@ -18,9 +18,6 @@ - - sources - imgui @@ -30,6 +27,9 @@ imgui + + sources + diff --git a/examples/shared/README.txt b/examples/shared/README.txt new file mode 100644 index 00000000..b2b431a0 --- /dev/null +++ b/examples/shared/README.txt @@ -0,0 +1,3 @@ +stb_image.h is used to load the PNG texture data by + opengl_example + directx11_example diff --git a/examples/opengl_example/stb_image.h b/examples/shared/stb_image.h similarity index 100% rename from examples/opengl_example/stb_image.h rename to examples/shared/stb_image.h From 2e576de9caf1ca711e0f38b391678bc0268cd10e Mon Sep 17 00:00:00 2001 From: ocornut Date: Sun, 30 Nov 2014 15:00:07 +0000 Subject: [PATCH 006/108] Fix comments --- imgui.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index f45b9f2c..7c08b7a7 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -6568,8 +6568,8 @@ void ImGui::ShowTestWindow(bool* open) ImGui::PushItemWidth(ImGui::GetWindowWidth() * 0.65f); ImGui::Text("ImGui says hello."); - //ImGui::Text("MousePos (%g, %g)", g.IO.MousePos.x, g.IO.MousePos.y); - //ImGui::Text("MouseWheel %d", g.IO.MouseWheel); + //ImGui::Text("MousePos (%g, %g)", ImGui::GetIO().MousePos.x, ImGui::GetIO().MousePos.y); + //ImGui::Text("MouseWheel %d", ImGui::GetIO().MouseWheel); ImGui::Spacing(); if (ImGui::CollapsingHeader("Help")) From ae75553ba14336547ce1afbdf48c513c04564226 Mon Sep 17 00:00:00 2001 From: ocornut Date: Sun, 30 Nov 2014 15:01:08 +0000 Subject: [PATCH 007/108] Ignore list for new examples structure --- .gitignore | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.gitignore b/.gitignore index 94f4ef01..9c09a7cb 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,13 @@ ## Visual Studio files +examples/Debug/* +examples/Release/* +examples/ipch/* examples/directx9_example/Debug/* examples/directx9_example/Release/* examples/directx9_example/ipch/* +examples/directx11_example/Debug/* +examples/directx11_example/Release/* +examples/directx11_example/ipch/* examples/opengl_example/Debug/* examples/opengl_example/Release/* examples/opengl_example/ipch/* From e835ef1d90cd0ca024897daad14ae35934630f02 Mon Sep 17 00:00:00 2001 From: ocornut Date: Sun, 30 Nov 2014 15:19:39 +0000 Subject: [PATCH 008/108] Fix from incorrect change left-over in a31e44b99afb54b3c9a3d531ace36bba0f229fb2 --- imgui.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/imgui.h b/imgui.h index 3da2be43..f1592161 100644 --- a/imgui.h +++ b/imgui.h @@ -295,7 +295,7 @@ namespace ImGui IMGUI_API int GetFrameCount(); IMGUI_API const char* GetStyleColorName(ImGuiCol idx); IMGUI_API void GetDefaultFontData(const void** fnt_data, unsigned int* fnt_size, const void** png_data, unsigned int* png_size); - IMGUI_API ImVec2 CalcTextSize(const char* text, const char* text_end = NULL, bool hide_text_after_double_hash = false, float wrap_width = -1.0f); + IMGUI_API ImVec2 CalcTextSize(const char* text, const char* text_end = NULL, bool hide_text_after_double_hash = true, float wrap_width = -1.0f); } // namespace ImGui From df00fa81136d6f5e13c4c5be9852cfe165502b29 Mon Sep 17 00:00:00 2001 From: ocornut Date: Sun, 30 Nov 2014 15:33:57 +0000 Subject: [PATCH 009/108] Fixed DirectX11 example to compile with whatever Visual Studio version user has --- examples/directx11_example/directx11_example.vcxproj | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/examples/directx11_example/directx11_example.vcxproj b/examples/directx11_example/directx11_example.vcxproj index ae9e216a..b492b6d6 100644 --- a/examples/directx11_example/directx11_example.vcxproj +++ b/examples/directx11_example/directx11_example.vcxproj @@ -19,14 +19,12 @@ Application true MultiByte - v110 Application false true MultiByte - v110 @@ -43,10 +41,12 @@ Level3 Disabled + $(DXSDK_DIR)/Include;%(AdditionalIncludeDirectories) true d3d11.lib;d3dcompiler.lib;dxgi.lib;imm32.lib;%(AdditionalDependencies) + $(DXSDK_DIR)/Lib/x86;%(AdditionalLibraryDirectories) @@ -55,12 +55,14 @@ MaxSpeed true true + $(DXSDK_DIR);%(AdditionalIncludeDirectories) true true true d3d11.lib;d3dcompiler.lib;dxgi.lib;imm32.lib;%(AdditionalDependencies) + $(DXSDK_DIR)/Lib/x86;%(AdditionalLibraryDirectories) From 197b2763fcde6dd3b1899dd55dd9b821877ab4bb Mon Sep 17 00:00:00 2001 From: ocornut Date: Sun, 30 Nov 2014 15:51:42 +0000 Subject: [PATCH 010/108] Fixed DirectX11 example Release build include --- examples/directx11_example/directx11_example.vcxproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/directx11_example/directx11_example.vcxproj b/examples/directx11_example/directx11_example.vcxproj index b492b6d6..324a14e4 100644 --- a/examples/directx11_example/directx11_example.vcxproj +++ b/examples/directx11_example/directx11_example.vcxproj @@ -55,7 +55,7 @@ MaxSpeed true true - $(DXSDK_DIR);%(AdditionalIncludeDirectories) + $(DXSDK_DIR)/Include;%(AdditionalIncludeDirectories) true From a5a84a9b69ce09b5d774d39ccc62531be0c3b827 Mon Sep 17 00:00:00 2001 From: ocornut Date: Sun, 30 Nov 2014 15:53:47 +0000 Subject: [PATCH 011/108] Tab->Spaces :( --- examples/directx11_example/main.cpp | 558 ++++++++++++++-------------- examples/directx9_example/main.cpp | 12 +- examples/opengl_example/main.cpp | 8 +- imgui.cpp | 4 +- 4 files changed, 291 insertions(+), 291 deletions(-) diff --git a/examples/directx11_example/main.cpp b/examples/directx11_example/main.cpp index 00835976..bb5be23c 100644 --- a/examples/directx11_example/main.cpp +++ b/examples/directx11_example/main.cpp @@ -37,13 +37,13 @@ static ID3D11BlendState* g_blendState = NULL; struct CUSTOMVERTEX { float pos[2]; - float uv[2]; - unsigned int col; + float uv[2]; + unsigned int col; }; struct VERTEX_CONSTANT_BUFFER { - float mvp[4][4]; + float mvp[4][4]; }; // This is the main rendering function that you have to implement and provide to ImGui (via setting up 'RenderDrawListsFn' in the ImGuiIO structure) @@ -59,80 +59,80 @@ static void ImImpl_RenderDrawLists(ImDrawList** const cmd_lists, int cmd_lists_c return; // Copy and convert all vertices into a single contiguous buffer - D3D11_MAPPED_SUBRESOURCE mappedResource; - if (g_pd3dDeviceImmediateContext->Map(g_pVB, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource) != S_OK) - return; - CUSTOMVERTEX* vtx_dst = (CUSTOMVERTEX*)mappedResource.pData; + D3D11_MAPPED_SUBRESOURCE mappedResource; + if (g_pd3dDeviceImmediateContext->Map(g_pVB, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource) != S_OK) + return; + CUSTOMVERTEX* vtx_dst = (CUSTOMVERTEX*)mappedResource.pData; for (int n = 0; n < cmd_lists_count; n++) { const ImDrawList* cmd_list = cmd_lists[n]; const ImDrawVert* vtx_src = &cmd_list->vtx_buffer[0]; for (size_t i = 0; i < cmd_list->vtx_buffer.size(); i++) { - vtx_dst->pos[0] = vtx_src->pos.x; - vtx_dst->pos[1] = vtx_src->pos.y; - vtx_dst->uv[0] = vtx_src->uv.x; - vtx_dst->uv[1] = vtx_src->uv.y; - vtx_dst->col = vtx_src->col; + vtx_dst->pos[0] = vtx_src->pos.x; + vtx_dst->pos[1] = vtx_src->pos.y; + vtx_dst->uv[0] = vtx_src->uv.x; + vtx_dst->uv[1] = vtx_src->uv.y; + vtx_dst->col = vtx_src->col; vtx_dst++; vtx_src++; } } - g_pd3dDeviceImmediateContext->Unmap(g_pVB, 0); + g_pd3dDeviceImmediateContext->Unmap(g_pVB, 0); - // Setup orthographic projection matrix into our constant buffer - { - D3D11_MAPPED_SUBRESOURCE mappedResource; - if (g_pd3dDeviceImmediateContext->Map(g_pVertexConstantBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource) != S_OK) - return; + // Setup orthographic projection matrix into our constant buffer + { + D3D11_MAPPED_SUBRESOURCE mappedResource; + if (g_pd3dDeviceImmediateContext->Map(g_pVertexConstantBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource) != S_OK) + return; - VERTEX_CONSTANT_BUFFER* pConstantBuffer = (VERTEX_CONSTANT_BUFFER*)mappedResource.pData; - const float L = 0.5f; - const float R = ImGui::GetIO().DisplaySize.x + 0.5f; - const float B = ImGui::GetIO().DisplaySize.y + 0.5f; - const float T = 0.5f; - const float mvp[4][4] = - { - { 2.0f/(R-L), 0.0f, 0.0f, 0.0f}, - { 0.0f, 2.0f/(T-B), 0.0f, 0.0f,}, - { 0.0f, 0.0f, 0.5f, 0.0f }, // -1.0f - { (R+L)/(L-R), (T+B)/(B-T), 0.5f, 1.0f }, // 0.0f - }; - memcpy(&pConstantBuffer->mvp, mvp, sizeof(mvp)); - g_pd3dDeviceImmediateContext->Unmap(g_pVertexConstantBuffer, 0); - } - - // Setup viewport - { - D3D11_VIEWPORT vp; - memset(&vp, 0, sizeof(D3D11_VIEWPORT)); - vp.Width = ImGui::GetIO().DisplaySize.x; - vp.Height = ImGui::GetIO().DisplaySize.y; - vp.MinDepth = 0.0f; - vp.MaxDepth = 1.0f; - vp.TopLeftX = 0; - vp.TopLeftY = 0; - g_pd3dDeviceImmediateContext->RSSetViewports(1, &vp); - } + VERTEX_CONSTANT_BUFFER* pConstantBuffer = (VERTEX_CONSTANT_BUFFER*)mappedResource.pData; + const float L = 0.5f; + const float R = ImGui::GetIO().DisplaySize.x + 0.5f; + const float B = ImGui::GetIO().DisplaySize.y + 0.5f; + const float T = 0.5f; + const float mvp[4][4] = + { + { 2.0f/(R-L), 0.0f, 0.0f, 0.0f}, + { 0.0f, 2.0f/(T-B), 0.0f, 0.0f,}, + { 0.0f, 0.0f, 0.5f, 0.0f }, // -1.0f + { (R+L)/(L-R), (T+B)/(B-T), 0.5f, 1.0f }, // 0.0f + }; + memcpy(&pConstantBuffer->mvp, mvp, sizeof(mvp)); + g_pd3dDeviceImmediateContext->Unmap(g_pVertexConstantBuffer, 0); + } + + // Setup viewport + { + D3D11_VIEWPORT vp; + memset(&vp, 0, sizeof(D3D11_VIEWPORT)); + vp.Width = ImGui::GetIO().DisplaySize.x; + vp.Height = ImGui::GetIO().DisplaySize.y; + vp.MinDepth = 0.0f; + vp.MaxDepth = 1.0f; + vp.TopLeftX = 0; + vp.TopLeftY = 0; + g_pd3dDeviceImmediateContext->RSSetViewports(1, &vp); + } - // Bind shader and vertex buffers - g_pd3dDeviceImmediateContext->IASetInputLayout(g_pInputLayout); - unsigned int stride = sizeof(CUSTOMVERTEX); - unsigned int offset = 0; - g_pd3dDeviceImmediateContext->IASetVertexBuffers(0, 1, &g_pVB, &stride, &offset); - g_pd3dDeviceImmediateContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST); + // Bind shader and vertex buffers + g_pd3dDeviceImmediateContext->IASetInputLayout(g_pInputLayout); + unsigned int stride = sizeof(CUSTOMVERTEX); + unsigned int offset = 0; + g_pd3dDeviceImmediateContext->IASetVertexBuffers(0, 1, &g_pVB, &stride, &offset); + g_pd3dDeviceImmediateContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST); - g_pd3dDeviceImmediateContext->VSSetShader(g_pVertexShader, NULL, 0); - g_pd3dDeviceImmediateContext->VSSetConstantBuffers(0, 1, &g_pVertexConstantBuffer); + g_pd3dDeviceImmediateContext->VSSetShader(g_pVertexShader, NULL, 0); + g_pd3dDeviceImmediateContext->VSSetConstantBuffers(0, 1, &g_pVertexConstantBuffer); - g_pd3dDeviceImmediateContext->PSSetShader(g_pPixelShader, NULL, 0); - g_pd3dDeviceImmediateContext->PSSetShaderResources(0, 1, &g_pFontTextureView); - g_pd3dDeviceImmediateContext->PSSetSamplers(0, 1, &g_pFontSampler); + g_pd3dDeviceImmediateContext->PSSetShader(g_pPixelShader, NULL, 0); + g_pd3dDeviceImmediateContext->PSSetShaderResources(0, 1, &g_pFontTextureView); + g_pd3dDeviceImmediateContext->PSSetSamplers(0, 1, &g_pFontSampler); - // Setup render state - const float blendFactor[4] = { 0.f, 0.f, 0.f, 0.f }; - const UINT sampleMask = 0xffffffff; - g_pd3dDeviceImmediateContext->OMSetBlendState(g_blendState, blendFactor, sampleMask); + // Setup render state + const float blendFactor[4] = { 0.f, 0.f, 0.f, 0.f }; + const UINT sampleMask = 0xffffffff; + g_pd3dDeviceImmediateContext->OMSetBlendState(g_blendState, blendFactor, sampleMask); // Render command lists int vtx_offset = 0; @@ -140,171 +140,171 @@ static void ImImpl_RenderDrawLists(ImDrawList** const cmd_lists, int cmd_lists_c { // Render command list const ImDrawList* cmd_list = cmd_lists[n]; - for (size_t cmd_i = 0; cmd_i < cmd_list->commands.size(); cmd_i++) - { - const ImDrawCmd* pcmd = &cmd_list->commands[cmd_i]; - const D3D11_RECT r = { (LONG)pcmd->clip_rect.x, (LONG)pcmd->clip_rect.y, (LONG)pcmd->clip_rect.z, (LONG)pcmd->clip_rect.w }; - g_pd3dDeviceImmediateContext->RSSetScissorRects(1, &r); - g_pd3dDeviceImmediateContext->Draw(pcmd->vtx_count, vtx_offset); + for (size_t cmd_i = 0; cmd_i < cmd_list->commands.size(); cmd_i++) + { + const ImDrawCmd* pcmd = &cmd_list->commands[cmd_i]; + const D3D11_RECT r = { (LONG)pcmd->clip_rect.x, (LONG)pcmd->clip_rect.y, (LONG)pcmd->clip_rect.z, (LONG)pcmd->clip_rect.w }; + g_pd3dDeviceImmediateContext->RSSetScissorRects(1, &r); + g_pd3dDeviceImmediateContext->Draw(pcmd->vtx_count, vtx_offset); vtx_offset += pcmd->vtx_count; } } - // Restore modified state - g_pd3dDeviceImmediateContext->IASetInputLayout(NULL); - g_pd3dDeviceImmediateContext->PSSetShader(NULL, NULL, 0); - g_pd3dDeviceImmediateContext->VSSetShader(NULL, NULL, 0); + // Restore modified state + g_pd3dDeviceImmediateContext->IASetInputLayout(NULL); + g_pd3dDeviceImmediateContext->PSSetShader(NULL, NULL, 0); + g_pd3dDeviceImmediateContext->VSSetShader(NULL, NULL, 0); } HRESULT InitD3D(HWND hWnd) { - IDXGIFactory1* pFactory = NULL; - CreateDXGIFactory1(__uuidof(IDXGIFactory1), (void**)&pFactory); + IDXGIFactory1* pFactory = NULL; + CreateDXGIFactory1(__uuidof(IDXGIFactory1), (void**)&pFactory); - DXGI_SWAP_CHAIN_DESC sd; - // Setup the swap chain - { - // Setup swap chain - ZeroMemory(&sd, sizeof(sd)); + DXGI_SWAP_CHAIN_DESC sd; + // Setup the swap chain + { + // Setup swap chain + ZeroMemory(&sd, sizeof(sd)); - sd.BufferCount = 2; - sd.BufferDesc.Width = (UINT)ImGui::GetIO().DisplaySize.x; - sd.BufferDesc.Height = (UINT)ImGui::GetIO().DisplaySize.y; - sd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; - sd.BufferDesc.RefreshRate.Numerator = 60; - sd.BufferDesc.RefreshRate.Denominator = 1; - sd.Flags = DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH; - sd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; - sd.OutputWindow = hWnd; - sd.SampleDesc.Count = 1; - sd.SampleDesc.Quality = 0; - sd.Windowed = TRUE; - sd.SwapEffect = DXGI_SWAP_EFFECT_DISCARD; - } + sd.BufferCount = 2; + sd.BufferDesc.Width = (UINT)ImGui::GetIO().DisplaySize.x; + sd.BufferDesc.Height = (UINT)ImGui::GetIO().DisplaySize.y; + sd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; + sd.BufferDesc.RefreshRate.Numerator = 60; + sd.BufferDesc.RefreshRate.Denominator = 1; + sd.Flags = DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH; + sd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; + sd.OutputWindow = hWnd; + sd.SampleDesc.Count = 1; + sd.SampleDesc.Quality = 0; + sd.Windowed = TRUE; + sd.SwapEffect = DXGI_SWAP_EFFECT_DISCARD; + } - UINT createDeviceFlags = 0; + UINT createDeviceFlags = 0; #ifdef _DEBUG - createDeviceFlags |= D3D11_CREATE_DEVICE_DEBUG; + createDeviceFlags |= D3D11_CREATE_DEVICE_DEBUG; #endif - D3D_FEATURE_LEVEL featureLevel; - const D3D_FEATURE_LEVEL featureLevelArray[1] = { D3D_FEATURE_LEVEL_11_0, }; - if (D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, createDeviceFlags, featureLevelArray, 1, D3D11_SDK_VERSION, &sd, &g_pSwapChain, &g_pd3dDevice, &featureLevel, &g_pd3dDeviceImmediateContext) != S_OK) - return E_FAIL; + D3D_FEATURE_LEVEL featureLevel; + const D3D_FEATURE_LEVEL featureLevelArray[1] = { D3D_FEATURE_LEVEL_11_0, }; + if (D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, createDeviceFlags, featureLevelArray, 1, D3D11_SDK_VERSION, &sd, &g_pSwapChain, &g_pd3dDevice, &featureLevel, &g_pd3dDeviceImmediateContext) != S_OK) + return E_FAIL; - // Setup rasterizer - { - D3D11_RASTERIZER_DESC RSDesc; - memset(&RSDesc, 0, sizeof(D3D11_RASTERIZER_DESC)); - RSDesc.FillMode = D3D11_FILL_SOLID; - RSDesc.CullMode = D3D11_CULL_NONE; - RSDesc.FrontCounterClockwise = FALSE; - RSDesc.DepthBias = 0; - RSDesc.SlopeScaledDepthBias = 0.0f; - RSDesc.DepthBiasClamp = 0; - RSDesc.DepthClipEnable = TRUE; - RSDesc.ScissorEnable = TRUE; - RSDesc.AntialiasedLineEnable = FALSE; - if (sd.SampleDesc.Count > 1) - RSDesc.MultisampleEnable = TRUE; - else - RSDesc.MultisampleEnable = FALSE; + // Setup rasterizer + { + D3D11_RASTERIZER_DESC RSDesc; + memset(&RSDesc, 0, sizeof(D3D11_RASTERIZER_DESC)); + RSDesc.FillMode = D3D11_FILL_SOLID; + RSDesc.CullMode = D3D11_CULL_NONE; + RSDesc.FrontCounterClockwise = FALSE; + RSDesc.DepthBias = 0; + RSDesc.SlopeScaledDepthBias = 0.0f; + RSDesc.DepthBiasClamp = 0; + RSDesc.DepthClipEnable = TRUE; + RSDesc.ScissorEnable = TRUE; + RSDesc.AntialiasedLineEnable = FALSE; + if (sd.SampleDesc.Count > 1) + RSDesc.MultisampleEnable = TRUE; + else + RSDesc.MultisampleEnable = FALSE; - ID3D11RasterizerState* g_pRState = NULL; - g_pd3dDevice->CreateRasterizerState(&RSDesc, &g_pRState); - g_pd3dDeviceImmediateContext->RSSetState(g_pRState); - } + ID3D11RasterizerState* g_pRState = NULL; + g_pd3dDevice->CreateRasterizerState(&RSDesc, &g_pRState); + g_pd3dDeviceImmediateContext->RSSetState(g_pRState); + } - // Create the render target - { - ID3D11Texture2D* g_pBackBuffer; - D3D11_RENDER_TARGET_VIEW_DESC render_target_view_desc; - ZeroMemory(&render_target_view_desc, sizeof(render_target_view_desc)); - render_target_view_desc.Format = sd.BufferDesc.Format; - render_target_view_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D; + // Create the render target + { + ID3D11Texture2D* g_pBackBuffer; + D3D11_RENDER_TARGET_VIEW_DESC render_target_view_desc; + ZeroMemory(&render_target_view_desc, sizeof(render_target_view_desc)); + render_target_view_desc.Format = sd.BufferDesc.Format; + render_target_view_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D; - g_pSwapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), (LPVOID*)&g_pBackBuffer); - g_pd3dDevice->CreateRenderTargetView(g_pBackBuffer, &render_target_view_desc, &g_mainRenderTargetView); + g_pSwapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), (LPVOID*)&g_pBackBuffer); + g_pd3dDevice->CreateRenderTargetView(g_pBackBuffer, &render_target_view_desc, &g_mainRenderTargetView); - g_pd3dDeviceImmediateContext->OMSetRenderTargets(1, &g_mainRenderTargetView, NULL); - } + g_pd3dDeviceImmediateContext->OMSetRenderTargets(1, &g_mainRenderTargetView, NULL); + } - // Create the vertex shader - { - ID3D10Blob * pErrorBlob; - D3DCompile(vertexShader, strlen(vertexShader), NULL, NULL, NULL, "main", "vs_5_0", 0, 0, &g_pVertexShaderBlob, &pErrorBlob); + // Create the vertex shader + { + ID3D10Blob * pErrorBlob; + D3DCompile(vertexShader, strlen(vertexShader), NULL, NULL, NULL, "main", "vs_5_0", 0, 0, &g_pVertexShaderBlob, &pErrorBlob); - if (g_pVertexShaderBlob == NULL) - { - const char* pError = (const char*)pErrorBlob->GetBufferPointer(); - pErrorBlob->Release(); - return E_FAIL; - } + if (g_pVertexShaderBlob == NULL) + { + const char* pError = (const char*)pErrorBlob->GetBufferPointer(); + pErrorBlob->Release(); + return E_FAIL; + } - if (g_pd3dDevice->CreateVertexShader((DWORD*)g_pVertexShaderBlob->GetBufferPointer(), g_pVertexShaderBlob->GetBufferSize(), NULL, &g_pVertexShader) != S_OK) - return E_FAIL; + if (g_pd3dDevice->CreateVertexShader((DWORD*)g_pVertexShaderBlob->GetBufferPointer(), g_pVertexShaderBlob->GetBufferSize(), NULL, &g_pVertexShader) != S_OK) + return E_FAIL; - if (pErrorBlob) - pErrorBlob->Release(); + if (pErrorBlob) + pErrorBlob->Release(); - // Create the input layout - D3D11_INPUT_ELEMENT_DESC localLayout[] = { - { "POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, (size_t)(&((CUSTOMVERTEX*)0)->pos), D3D11_INPUT_PER_VERTEX_DATA, 0 }, - { "COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, (size_t)(&((CUSTOMVERTEX*)0)->col), D3D11_INPUT_PER_VERTEX_DATA, 0 }, - { "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, (size_t)(&((CUSTOMVERTEX*)0)->uv), D3D11_INPUT_PER_VERTEX_DATA, 0 }, - }; + // Create the input layout + D3D11_INPUT_ELEMENT_DESC localLayout[] = { + { "POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, (size_t)(&((CUSTOMVERTEX*)0)->pos), D3D11_INPUT_PER_VERTEX_DATA, 0 }, + { "COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, (size_t)(&((CUSTOMVERTEX*)0)->col), D3D11_INPUT_PER_VERTEX_DATA, 0 }, + { "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, (size_t)(&((CUSTOMVERTEX*)0)->uv), D3D11_INPUT_PER_VERTEX_DATA, 0 }, + }; - if (g_pd3dDevice->CreateInputLayout(localLayout, 3, g_pVertexShaderBlob->GetBufferPointer(), g_pVertexShaderBlob->GetBufferSize(), &g_pInputLayout) != S_OK) - return E_FAIL; + if (g_pd3dDevice->CreateInputLayout(localLayout, 3, g_pVertexShaderBlob->GetBufferPointer(), g_pVertexShaderBlob->GetBufferSize(), &g_pInputLayout) != S_OK) + return E_FAIL; - // Create the constant buffer - { - D3D11_BUFFER_DESC cbDesc; - cbDesc.ByteWidth = sizeof(VERTEX_CONSTANT_BUFFER); - cbDesc.Usage = D3D11_USAGE_DYNAMIC; - cbDesc.BindFlags = D3D11_BIND_CONSTANT_BUFFER; - cbDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; - cbDesc.MiscFlags = 0; - g_pd3dDevice->CreateBuffer(&cbDesc, NULL, &g_pVertexConstantBuffer); - } - } + // Create the constant buffer + { + D3D11_BUFFER_DESC cbDesc; + cbDesc.ByteWidth = sizeof(VERTEX_CONSTANT_BUFFER); + cbDesc.Usage = D3D11_USAGE_DYNAMIC; + cbDesc.BindFlags = D3D11_BIND_CONSTANT_BUFFER; + cbDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; + cbDesc.MiscFlags = 0; + g_pd3dDevice->CreateBuffer(&cbDesc, NULL, &g_pVertexConstantBuffer); + } + } - // Create the pixel shader - { - ID3D10Blob * pErrorBlob; - D3DCompile(pixelShader, strlen(pixelShader), NULL, NULL, NULL, "main", "ps_5_0", 0, 0, &g_pPixelShaderBlob, &pErrorBlob); + // Create the pixel shader + { + ID3D10Blob * pErrorBlob; + D3DCompile(pixelShader, strlen(pixelShader), NULL, NULL, NULL, "main", "ps_5_0", 0, 0, &g_pPixelShaderBlob, &pErrorBlob); - if (g_pPixelShaderBlob == NULL) - { - const char* pError = (const char*)pErrorBlob->GetBufferPointer(); - pErrorBlob->Release(); - return E_FAIL; - } + if (g_pPixelShaderBlob == NULL) + { + const char* pError = (const char*)pErrorBlob->GetBufferPointer(); + pErrorBlob->Release(); + return E_FAIL; + } - if (g_pd3dDevice->CreatePixelShader((DWORD*)g_pPixelShaderBlob->GetBufferPointer(), g_pPixelShaderBlob->GetBufferSize(), NULL, &g_pPixelShader) != S_OK) - return E_FAIL; + if (g_pd3dDevice->CreatePixelShader((DWORD*)g_pPixelShaderBlob->GetBufferPointer(), g_pPixelShaderBlob->GetBufferSize(), NULL, &g_pPixelShader) != S_OK) + return E_FAIL; - if (pErrorBlob) - pErrorBlob->Release(); - } + if (pErrorBlob) + pErrorBlob->Release(); + } - // Create the blending setup - { - D3D11_BLEND_DESC desc; - ZeroMemory(&desc, sizeof(desc)); - desc.AlphaToCoverageEnable = false; - desc.RenderTarget[0].BlendEnable = true; - desc.RenderTarget[0].SrcBlend = D3D11_BLEND_SRC_ALPHA; - desc.RenderTarget[0].DestBlend = D3D11_BLEND_INV_SRC_ALPHA; - desc.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD; - desc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_INV_SRC_ALPHA; - desc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_ZERO; - desc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD; - desc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL; - g_pd3dDevice->CreateBlendState(&desc, &g_blendState); - } + // Create the blending setup + { + D3D11_BLEND_DESC desc; + ZeroMemory(&desc, sizeof(desc)); + desc.AlphaToCoverageEnable = false; + desc.RenderTarget[0].BlendEnable = true; + desc.RenderTarget[0].SrcBlend = D3D11_BLEND_SRC_ALPHA; + desc.RenderTarget[0].DestBlend = D3D11_BLEND_INV_SRC_ALPHA; + desc.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD; + desc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_INV_SRC_ALPHA; + desc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_ZERO; + desc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD; + desc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL; + g_pd3dDevice->CreateBlendState(&desc, &g_blendState); + } - return S_OK; + return S_OK; } LRESULT WINAPI MsgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) @@ -325,7 +325,7 @@ LRESULT WINAPI MsgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) io.MouseDown[1] = false; return true; case WM_MOUSEWHEEL: - io.MouseWheel = GET_WHEEL_DELTA_WPARAM(wParam) > 0 ? +1.0f : -1.0f; + io.MouseWheel = GET_WHEEL_DELTA_WPARAM(wParam) > 0 ? +1.0f : -1.0f; return true; case WM_MOUSEMOVE: // Mouse position, in pixels (set to -1,-1 if no mouse / on another screen, etc.) @@ -385,79 +385,79 @@ void InitImGui() io.KeyMap[ImGuiKey_Z] = 'Z'; io.RenderDrawListsFn = ImImpl_RenderDrawLists; - io.ImeSetInputScreenPosFn = ImImpl_ImeSetInputScreenPosFn; + io.ImeSetInputScreenPosFn = ImImpl_ImeSetInputScreenPosFn; - // Create the vertex buffer - { - D3D11_BUFFER_DESC bufferDesc; - memset(&bufferDesc, 0, sizeof(D3D11_BUFFER_DESC)); + // Create the vertex buffer + { + D3D11_BUFFER_DESC bufferDesc; + memset(&bufferDesc, 0, sizeof(D3D11_BUFFER_DESC)); - bufferDesc.Usage = D3D11_USAGE_DYNAMIC; - bufferDesc.ByteWidth = 10000 * sizeof(CUSTOMVERTEX); - bufferDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER; - bufferDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; - bufferDesc.MiscFlags = 0; + bufferDesc.Usage = D3D11_USAGE_DYNAMIC; + bufferDesc.ByteWidth = 10000 * sizeof(CUSTOMVERTEX); + bufferDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER; + bufferDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; + bufferDesc.MiscFlags = 0; - if (g_pd3dDevice->CreateBuffer(&bufferDesc, NULL, &g_pVB) < 0) - { - IM_ASSERT(0); - return; - } - } + if (g_pd3dDevice->CreateBuffer(&bufferDesc, NULL, &g_pVB) < 0) + { + IM_ASSERT(0); + return; + } + } // Load font texture - // Default font (embedded in code) - const void* png_data; - unsigned int png_size; - ImGui::GetDefaultFontData(NULL, NULL, &png_data, &png_size); - int tex_x, tex_y, tex_comp; - void* tex_data = stbi_load_from_memory((const unsigned char*)png_data, (int)png_size, &tex_x, &tex_y, &tex_comp, 0); - IM_ASSERT(tex_data != NULL); + // Default font (embedded in code) + const void* png_data; + unsigned int png_size; + ImGui::GetDefaultFontData(NULL, NULL, &png_data, &png_size); + int tex_x, tex_y, tex_comp; + void* tex_data = stbi_load_from_memory((const unsigned char*)png_data, (int)png_size, &tex_x, &tex_y, &tex_comp, 0); + IM_ASSERT(tex_data != NULL); - { - D3D11_TEXTURE2D_DESC desc; - ZeroMemory(&desc, sizeof(desc)); - desc.Width = tex_x; - desc.Height = tex_y; - desc.MipLevels = 1; - desc.ArraySize = 1; - desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; - desc.SampleDesc.Count = 1; - desc.Usage = D3D11_USAGE_DEFAULT; - desc.BindFlags = D3D11_BIND_SHADER_RESOURCE; - desc.CPUAccessFlags = 0; + { + D3D11_TEXTURE2D_DESC desc; + ZeroMemory(&desc, sizeof(desc)); + desc.Width = tex_x; + desc.Height = tex_y; + desc.MipLevels = 1; + desc.ArraySize = 1; + desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; + desc.SampleDesc.Count = 1; + desc.Usage = D3D11_USAGE_DEFAULT; + desc.BindFlags = D3D11_BIND_SHADER_RESOURCE; + desc.CPUAccessFlags = 0; - ID3D11Texture2D *pTexture = NULL; - D3D11_SUBRESOURCE_DATA subResource; - subResource.pSysMem = tex_data; - subResource.SysMemPitch = tex_x * 4; - subResource.SysMemSlicePitch = 0; - g_pd3dDevice->CreateTexture2D(&desc, &subResource, &pTexture); + ID3D11Texture2D *pTexture = NULL; + D3D11_SUBRESOURCE_DATA subResource; + subResource.pSysMem = tex_data; + subResource.SysMemPitch = tex_x * 4; + subResource.SysMemSlicePitch = 0; + g_pd3dDevice->CreateTexture2D(&desc, &subResource, &pTexture); - // create texture view - D3D11_SHADER_RESOURCE_VIEW_DESC srvDesc; - ZeroMemory(&srvDesc, sizeof(srvDesc)); - srvDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; - srvDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D; - srvDesc.Texture2D.MipLevels = desc.MipLevels; - srvDesc.Texture2D.MostDetailedMip = 0; - g_pd3dDevice->CreateShaderResourceView(pTexture, &srvDesc, &g_pFontTextureView); - } + // create texture view + D3D11_SHADER_RESOURCE_VIEW_DESC srvDesc; + ZeroMemory(&srvDesc, sizeof(srvDesc)); + srvDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; + srvDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D; + srvDesc.Texture2D.MipLevels = desc.MipLevels; + srvDesc.Texture2D.MostDetailedMip = 0; + g_pd3dDevice->CreateShaderResourceView(pTexture, &srvDesc, &g_pFontTextureView); + } - // create texture sampler - { - D3D11_SAMPLER_DESC desc; - ZeroMemory(&desc, sizeof(desc)); - desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT; - desc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP; - desc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP; - desc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP; - desc.MipLODBias = 0.f; - desc.ComparisonFunc = D3D11_COMPARISON_ALWAYS; - desc.MinLOD = 0.f; - desc.MaxLOD = 0.f; - g_pd3dDevice->CreateSamplerState(&desc, &g_pFontSampler); - } + // create texture sampler + { + D3D11_SAMPLER_DESC desc; + ZeroMemory(&desc, sizeof(desc)); + desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT; + desc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP; + desc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP; + desc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP; + desc.MipLODBias = 0.f; + desc.ComparisonFunc = D3D11_COMPARISON_ALWAYS; + desc.MinLOD = 0.f; + desc.MaxLOD = 0.f; + g_pd3dDevice->CreateSamplerState(&desc, &g_pFontSampler); + } } INT64 ticks_per_second = 0; @@ -570,10 +570,10 @@ int WINAPI wWinMain(HINSTANCE hInst, HINSTANCE, LPWSTR, int) } // Rendering - float clearColor[4] = { 204 / 255.f, 153 / 255.f, 153 / 255.f }; - g_pd3dDeviceImmediateContext->ClearRenderTargetView(g_mainRenderTargetView, clearColor); + float clearColor[4] = { 204 / 255.f, 153 / 255.f, 153 / 255.f }; + g_pd3dDeviceImmediateContext->ClearRenderTargetView(g_mainRenderTargetView, clearColor); ImGui::Render(); - g_pSwapChain->Present(0, 0); + g_pSwapChain->Present(0, 0); } ImGui::Shutdown(); @@ -585,43 +585,43 @@ int WINAPI wWinMain(HINSTANCE hInst, HINSTANCE, LPWSTR, int) static const char* vertexShader = "\ cbuffer vertexBuffer : register(c0) \ {\ - float4x4 ProjectionMatrix; \ + float4x4 ProjectionMatrix; \ };\ struct VS_INPUT\ {\ - float2 pos : POSITION;\ - float4 col : COLOR0;\ - float2 uv : TEXCOORD0;\ + float2 pos : POSITION;\ + float4 col : COLOR0;\ + float2 uv : TEXCOORD0;\ };\ \ struct PS_INPUT\ {\ - float4 pos : SV_POSITION;\ - float4 col : COLOR0;\ - float2 uv : TEXCOORD0;\ + float4 pos : SV_POSITION;\ + float4 col : COLOR0;\ + float2 uv : TEXCOORD0;\ };\ \ PS_INPUT main(VS_INPUT input)\ {\ - PS_INPUT output;\ - output.pos = mul( ProjectionMatrix, float4(input.pos.xy, 0.f, 1.f));\ - output.col = input.col;\ - output.uv = input.uv;\ - return output;\ + PS_INPUT output;\ + output.pos = mul( ProjectionMatrix, float4(input.pos.xy, 0.f, 1.f));\ + output.col = input.col;\ + output.uv = input.uv;\ + return output;\ }"; static const char* pixelShader = "\ struct PS_INPUT\ {\ - float4 pos : SV_POSITION;\ - float4 col : COLOR0;\ - float2 uv : TEXCOORD0;\ + float4 pos : SV_POSITION;\ + float4 col : COLOR0;\ + float2 uv : TEXCOORD0;\ };\ sampler sampler0;\ Texture2D texture0;\ \ float4 main(PS_INPUT input) : SV_Target\ {\ - float4 out_col = texture0.Sample(sampler0, input.uv);\ - return input.col * out_col;\ + float4 out_col = texture0.Sample(sampler0, input.uv);\ + return input.col * out_col;\ }"; diff --git a/examples/directx9_example/main.cpp b/examples/directx9_example/main.cpp index ac26ae28..94249de9 100644 --- a/examples/directx9_example/main.cpp +++ b/examples/directx9_example/main.cpp @@ -18,7 +18,7 @@ struct CUSTOMVERTEX { D3DXVECTOR3 pos; D3DCOLOR col; - D3DXVECTOR2 uv; + D3DXVECTOR2 uv; }; #define D3DFVF_CUSTOMVERTEX (D3DFVF_XYZ|D3DFVF_DIFFUSE|D3DFVF_TEX1) @@ -48,8 +48,8 @@ static void ImImpl_RenderDrawLists(ImDrawList** const cmd_lists, int cmd_lists_c vtx_dst->pos.y = vtx_src->pos.y; vtx_dst->pos.z = 0.0f; vtx_dst->col = (vtx_src->col & 0xFF00FF00) | ((vtx_src->col & 0xFF0000)>>16) | ((vtx_src->col & 0xFF) << 16); // RGBA --> ARGB for DirectX9 - vtx_dst->uv.x = vtx_src->uv.x; - vtx_dst->uv.y = vtx_src->uv.y; + vtx_dst->uv.x = vtx_src->uv.x; + vtx_dst->uv.y = vtx_src->uv.y; vtx_dst++; vtx_src++; } @@ -93,9 +93,9 @@ static void ImImpl_RenderDrawLists(ImDrawList** const cmd_lists, int cmd_lists_c { // Render command list const ImDrawList* cmd_list = cmd_lists[n]; - for (size_t cmd_i = 0; cmd_i < cmd_list->commands.size(); cmd_i++) - { - const ImDrawCmd* pcmd = &cmd_list->commands[cmd_i]; + for (size_t cmd_i = 0; cmd_i < cmd_list->commands.size(); cmd_i++) + { + const ImDrawCmd* pcmd = &cmd_list->commands[cmd_i]; const RECT r = { (LONG)pcmd->clip_rect.x, (LONG)pcmd->clip_rect.y, (LONG)pcmd->clip_rect.z, (LONG)pcmd->clip_rect.w }; g_pd3dDevice->SetScissorRect(&r); g_pd3dDevice->DrawPrimitive(D3DPT_TRIANGLELIST, vtx_offset, pcmd->vtx_count/3); diff --git a/examples/opengl_example/main.cpp b/examples/opengl_example/main.cpp index 2efacced..dbf29e26 100644 --- a/examples/opengl_example/main.cpp +++ b/examples/opengl_example/main.cpp @@ -69,17 +69,17 @@ static void ImImpl_RenderDrawLists(ImDrawList** const cmd_lists, int cmd_lists_c glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(ImDrawVert), (void*)(vtx_buffer + offsetof(ImDrawVert, col))); int vtx_offset = 0; - for (size_t cmd_i = 0; cmd_i < cmd_list->commands.size(); cmd_i++) + for (size_t cmd_i = 0; cmd_i < cmd_list->commands.size(); cmd_i++) { - const ImDrawCmd* pcmd = &cmd_list->commands[cmd_i]; + const ImDrawCmd* pcmd = &cmd_list->commands[cmd_i]; glScissor((int)pcmd->clip_rect.x, (int)(height - pcmd->clip_rect.w), (int)(pcmd->clip_rect.z - pcmd->clip_rect.x), (int)(pcmd->clip_rect.w - pcmd->clip_rect.y)); glDrawArrays(GL_TRIANGLES, vtx_offset, pcmd->vtx_count); vtx_offset += pcmd->vtx_count; } } - // Restore modified state - glDisableClientState(GL_COLOR_ARRAY); + // Restore modified state + glDisableClientState(GL_COLOR_ARRAY); glDisableClientState(GL_TEXTURE_COORD_ARRAY); glDisableClientState(GL_VERTEX_ARRAY); glMatrixMode(GL_MODELVIEW); diff --git a/imgui.cpp b/imgui.cpp index 7c08b7a7..3a37af2a 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -4331,7 +4331,7 @@ void ImGuiTextEditCallbackData::InsertChars(int pos, const char* new_text, const if (new_text_len + text_len + 1 >= BufSize) return; - size_t upos = (size_t)pos; + size_t upos = (size_t)pos; if (text_len != upos) memmove(Buf + upos + new_text_len, Buf + upos, text_len - upos); memcpy(Buf + upos, new_text, new_text_len * sizeof(char)); @@ -5798,7 +5798,7 @@ bool ImFont::LoadFromMemory(const void* data, size_t data_size) IM_ASSERT(Kerning == NULL && KerningCount == 0); Kerning = (FntKerning*)p; KerningCount = block_size / sizeof(FntKerning); - break; + break; default: break; } From 0f29cd7a14ff87d9b00f1b87fd979f23df400780 Mon Sep 17 00:00:00 2001 From: ocornut Date: Sun, 30 Nov 2014 15:54:58 +0000 Subject: [PATCH 012/108] Removed Microsoft IME handler in examples, too confusing. Moved to imgui.cpp instruction block. --- examples/directx11_example/main.cpp | 15 ----------- examples/directx9_example/main.cpp | 15 ----------- examples/opengl_example/main.cpp | 20 --------------- imgui.cpp | 39 +++++++++++++++++++++-------- 4 files changed, 29 insertions(+), 60 deletions(-) diff --git a/examples/directx11_example/main.cpp b/examples/directx11_example/main.cpp index bb5be23c..dd16f834 100644 --- a/examples/directx11_example/main.cpp +++ b/examples/directx11_example/main.cpp @@ -1,5 +1,4 @@ #include -#include #define STB_IMAGE_IMPLEMENTATION #include "../shared/stb_image.h" // for .png loading #include "../../imgui.h" @@ -344,19 +343,6 @@ LRESULT WINAPI MsgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) return DefWindowProc(hWnd, msg, wParam, lParam); } -// Notify OS Input Method Editor of text input position (e.g. when using Japanese/Chinese inputs, otherwise this isn't needed) -static void ImImpl_ImeSetInputScreenPosFn(int x, int y) -{ - if (HIMC himc = ImmGetContext(hWnd)) - { - COMPOSITIONFORM cf; - cf.ptCurrentPos.x = x; - cf.ptCurrentPos.y = y; - cf.dwStyle = CFS_FORCE_POSITION; - ImmSetCompositionWindow(himc, &cf); - } -} - void InitImGui() { RECT rect; @@ -385,7 +371,6 @@ void InitImGui() io.KeyMap[ImGuiKey_Z] = 'Z'; io.RenderDrawListsFn = ImImpl_RenderDrawLists; - io.ImeSetInputScreenPosFn = ImImpl_ImeSetInputScreenPosFn; // Create the vertex buffer { diff --git a/examples/directx9_example/main.cpp b/examples/directx9_example/main.cpp index 94249de9..ac8c2105 100644 --- a/examples/directx9_example/main.cpp +++ b/examples/directx9_example/main.cpp @@ -1,5 +1,4 @@ #include -#include #include "../../imgui.h" // DirectX @@ -175,19 +174,6 @@ LRESULT WINAPI MsgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) return DefWindowProc(hWnd, msg, wParam, lParam); } -// Notify OS Input Method Editor of text input position (e.g. when using Japanese/Chinese inputs, otherwise this isn't needed) -static void ImImpl_ImeSetInputScreenPosFn(int x, int y) -{ - if (HIMC himc = ImmGetContext(hWnd)) - { - COMPOSITIONFORM cf; - cf.ptCurrentPos.x = x; - cf.ptCurrentPos.y = y; - cf.dwStyle = CFS_FORCE_POSITION; - ImmSetCompositionWindow(himc, &cf); - } -} - void InitImGui() { RECT rect; @@ -216,7 +202,6 @@ void InitImGui() io.KeyMap[ImGuiKey_Z] = 'Z'; io.RenderDrawListsFn = ImImpl_RenderDrawLists; - io.ImeSetInputScreenPosFn = ImImpl_ImeSetInputScreenPosFn; // Create the vertex buffer if (g_pd3dDevice->CreateVertexBuffer(10000 * sizeof(CUSTOMVERTEX), D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY, D3DFVF_CUSTOMVERTEX, D3DPOOL_DEFAULT, &g_pVB, NULL) < 0) diff --git a/examples/opengl_example/main.cpp b/examples/opengl_example/main.cpp index dbf29e26..2fce58f0 100644 --- a/examples/opengl_example/main.cpp +++ b/examples/opengl_example/main.cpp @@ -1,7 +1,6 @@ #ifdef _MSC_VER #pragma warning (disable: 4996) // 'This function or variable may be unsafe': strcpy, strdup, sprintf, vsnprintf, sscanf, fopen #include -#include #endif #define STB_IMAGE_IMPLEMENTATION #include "../shared/stb_image.h" // for .png loading @@ -100,22 +99,6 @@ static void ImImpl_SetClipboardTextFn(const char* text) glfwSetClipboardString(window, text); } -#ifdef _MSC_VER -// Notify OS Input Method Editor of text input position (e.g. when using Japanese/Chinese inputs, otherwise this isn't needed) -static void ImImpl_ImeSetInputScreenPosFn(int x, int y) -{ - HWND hwnd = glfwGetWin32Window(window); - if (HIMC himc = ImmGetContext(hwnd)) - { - COMPOSITIONFORM cf; - cf.ptCurrentPos.x = x; - cf.ptCurrentPos.y = y; - cf.dwStyle = CFS_FORCE_POSITION; - ImmSetCompositionWindow(himc, &cf); - } -} -#endif - // GLFW callbacks to get events static void glfw_error_callback(int error, const char* description) { @@ -204,9 +187,6 @@ void InitImGui() io.RenderDrawListsFn = ImImpl_RenderDrawLists; io.SetClipboardTextFn = ImImpl_SetClipboardTextFn; io.GetClipboardTextFn = ImImpl_GetClipboardTextFn; -#ifdef _MSC_VER - io.ImeSetInputScreenPosFn = ImImpl_ImeSetInputScreenPosFn; -#endif // Load font texture glGenTextures(1, &fontTex); diff --git a/imgui.cpp b/imgui.cpp index 3a37af2a..059c36cf 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -125,19 +125,11 @@ TROUBLESHOOTING & FREQUENTLY ASKED QUESTIONS ============================================ - - if text or lines are blurry when integrating ImGui in your engine: + If text or lines are blurry when integrating ImGui in your engine: - in your Render function, try translating your projection matrix by (0.5f,0.5f) or (0.375f,0.375f) - try adjusting ImGui::GetIO().PixelCenterOffset to 0.5f or 0.375f - - if you want to use a different font than the default: - - create bitmap font data using BMFont, make sure that BMFont is exporting the .fnt file in Binary mode. - io.Font = new ImBitmapFont(); - io.Font->LoadFromFile("path_to_your_fnt_file.fnt"); - - load your texture yourself. texture *MUST* have white pixel at UV coordinate io.Font->TexUvForWhite. This is used to draw all solid shapes. - - the extra_fonts/ folder provides examples of using external fonts. - - if you can only see text but no solid shapes or lines, make sure io.Font->TexUvForWhite is set to the texture coordinates of a pure white pixel in your texture! - - - if you are confused about the meaning or use of ID in ImGui: + If you are confused about the meaning or use of ID in ImGui: - some widgets requires state to be carried over multiple frames (most typically ImGui often wants remember what is the "active" widget). to do so they need an unique ID. unique ID are typically derived from a string label, an indice or a pointer. when you call Button("OK") the button shows "OK" and also use "OK" as an ID. @@ -155,6 +147,33 @@ e.g. "##Foobar" display an empty label and uses "##Foobar" as ID - read articles about the imgui principles (see web links) to understand the requirement and use of ID. + If you want to use a different font than the default: + - read extra_fonts/README.txt for instructions. Examples fonts are also provided. + - if you can only see text but no solid shapes or lines, make sure io.Font->TexUvForWhite is set to the texture coordinates of a pure white pixel in your texture! + + If you want to input Japanese/Chinese/Korean in the text input widget: + - make sure you are using a font that can display the glyphs you want (see above paragraph about fonts) + - to have the Microsoft IME cursor appears at the right location in the screen, setup a handler for the io.ImeSetInputScreenPosFn function: + + #include + #include + static void ImImpl_ImeSetInputScreenPosFn(int x, int y) + { + // Notify OS Input Method Editor of text input position + HWND hwnd = glfwGetWin32Window(window); + if (HIMC himc = ImmGetContext(hwnd)) + { + COMPOSITIONFORM cf; + cf.ptCurrentPos.x = x; + cf.ptCurrentPos.y = y; + cf.dwStyle = CFS_FORCE_POSITION; + ImmSetCompositionWindow(himc, &cf); + } + } + + // Set pointer to handler in ImGuiIO structure + io.ImeSetInputScreenPosFn = ImImpl_ImeSetInputScreenPosFn; + - tip: the construct 'IMGUI_ONCE_UPON_A_FRAME { ... }' will evaluate to a block of code only once a frame. You can use it to quickly add custom UI in the middle of a deep nested inner loop in your code. - tip: you can call Render() multiple times (e.g for VR renders), up to you to communicate the extra state to your RenderDrawListFn function. - tip: you can create widgets without a Begin()/End() block, they will go in an implicit window called "Debug" From de44af5227e9d47a258628823f3479bdde020399 Mon Sep 17 00:00:00 2001 From: ocornut Date: Sun, 30 Nov 2014 16:53:33 +0000 Subject: [PATCH 013/108] DirectX11 example: closing all handler/resources in Cleanup. --- examples/directx11_example/main.cpp | 62 +++++++++++++++++------------ 1 file changed, 36 insertions(+), 26 deletions(-) diff --git a/examples/directx11_example/main.cpp b/examples/directx11_example/main.cpp index dd16f834..cf8ac106 100644 --- a/examples/directx11_example/main.cpp +++ b/examples/directx11_example/main.cpp @@ -157,15 +157,10 @@ static void ImImpl_RenderDrawLists(ImDrawList** const cmd_lists, int cmd_lists_c HRESULT InitD3D(HWND hWnd) { - IDXGIFactory1* pFactory = NULL; - CreateDXGIFactory1(__uuidof(IDXGIFactory1), (void**)&pFactory); - + // Setup swap chain DXGI_SWAP_CHAIN_DESC sd; - // Setup the swap chain { - // Setup swap chain ZeroMemory(&sd, sizeof(sd)); - sd.BufferCount = 2; sd.BufferDesc.Width = (UINT)ImGui::GetIO().DisplaySize.x; sd.BufferDesc.Height = (UINT)ImGui::GetIO().DisplaySize.y; @@ -208,41 +203,37 @@ HRESULT InitD3D(HWND hWnd) else RSDesc.MultisampleEnable = FALSE; - ID3D11RasterizerState* g_pRState = NULL; - g_pd3dDevice->CreateRasterizerState(&RSDesc, &g_pRState); - g_pd3dDeviceImmediateContext->RSSetState(g_pRState); + ID3D11RasterizerState* pRState = NULL; + g_pd3dDevice->CreateRasterizerState(&RSDesc, &pRState); + g_pd3dDeviceImmediateContext->RSSetState(pRState); + pRState->Release(); } // Create the render target { - ID3D11Texture2D* g_pBackBuffer; + ID3D11Texture2D* pBackBuffer; D3D11_RENDER_TARGET_VIEW_DESC render_target_view_desc; ZeroMemory(&render_target_view_desc, sizeof(render_target_view_desc)); render_target_view_desc.Format = sd.BufferDesc.Format; render_target_view_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D; - - g_pSwapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), (LPVOID*)&g_pBackBuffer); - g_pd3dDevice->CreateRenderTargetView(g_pBackBuffer, &render_target_view_desc, &g_mainRenderTargetView); - + g_pSwapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), (LPVOID*)&pBackBuffer); + g_pd3dDevice->CreateRenderTargetView(pBackBuffer, &render_target_view_desc, &g_mainRenderTargetView); g_pd3dDeviceImmediateContext->OMSetRenderTargets(1, &g_mainRenderTargetView, NULL); + pBackBuffer->Release(); } - // Create the vertex shader { - ID3D10Blob * pErrorBlob; + ID3D10Blob * pErrorBlob = NULL; D3DCompile(vertexShader, strlen(vertexShader), NULL, NULL, NULL, "main", "vs_5_0", 0, 0, &g_pVertexShaderBlob, &pErrorBlob); - if (g_pVertexShaderBlob == NULL) { - const char* pError = (const char*)pErrorBlob->GetBufferPointer(); + //const char* pError = (const char*)pErrorBlob->GetBufferPointer(); pErrorBlob->Release(); return E_FAIL; } - if (g_pd3dDevice->CreateVertexShader((DWORD*)g_pVertexShaderBlob->GetBufferPointer(), g_pVertexShaderBlob->GetBufferSize(), NULL, &g_pVertexShader) != S_OK) return E_FAIL; - if (pErrorBlob) pErrorBlob->Release(); @@ -272,17 +263,14 @@ HRESULT InitD3D(HWND hWnd) { ID3D10Blob * pErrorBlob; D3DCompile(pixelShader, strlen(pixelShader), NULL, NULL, NULL, "main", "ps_5_0", 0, 0, &g_pPixelShaderBlob, &pErrorBlob); - if (g_pPixelShaderBlob == NULL) { - const char* pError = (const char*)pErrorBlob->GetBufferPointer(); + //const char* pError = (const char*)pErrorBlob->GetBufferPointer(); pErrorBlob->Release(); return E_FAIL; } - if (g_pd3dDevice->CreatePixelShader((DWORD*)g_pPixelShaderBlob->GetBufferPointer(), g_pPixelShaderBlob->GetBufferSize(), NULL, &g_pPixelShader) != S_OK) return E_FAIL; - if (pErrorBlob) pErrorBlob->Release(); } @@ -306,6 +294,27 @@ HRESULT InitD3D(HWND hWnd) return S_OK; } +void Cleanup() +{ + if (g_pd3dDeviceImmediateContext) g_pd3dDeviceImmediateContext->ClearState(); + + if (g_pFontSampler) g_pFontSampler->Release(); + if (g_pFontTextureView) g_pFontTextureView->Release(); + if (g_pVB) g_pVB->Release(); + + if (g_blendState) g_blendState->Release(); + if (g_pPixelShader) g_pPixelShader->Release(); + if (g_pPixelShaderBlob) g_pPixelShaderBlob->Release(); + if (g_pVertexConstantBuffer) g_pVertexConstantBuffer->Release(); + if (g_pInputLayout) g_pInputLayout->Release(); + if (g_pVertexShader) g_pVertexShader->Release(); + if (g_pVertexShaderBlob) g_pVertexShaderBlob->Release(); + if (g_mainRenderTargetView) g_mainRenderTargetView->Release(); + if (g_pSwapChain) g_pSwapChain->Release(); + if (g_pd3dDeviceImmediateContext) g_pd3dDeviceImmediateContext->Release(); + if (g_pd3dDevice) g_pd3dDevice->Release(); +} + LRESULT WINAPI MsgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { ImGuiIO& io = ImGui::GetIO(); @@ -337,6 +346,7 @@ LRESULT WINAPI MsgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) io.AddInputCharacter((unsigned short)wParam); return true; case WM_DESTROY: + Cleanup(); PostQuitMessage(0); return 0; } @@ -369,7 +379,6 @@ void InitImGui() io.KeyMap[ImGuiKey_X] = 'X'; io.KeyMap[ImGuiKey_Y] = 'Y'; io.KeyMap[ImGuiKey_Z] = 'Z'; - io.RenderDrawListsFn = ImImpl_RenderDrawLists; // Create the vertex buffer @@ -427,6 +436,7 @@ void InitImGui() srvDesc.Texture2D.MipLevels = desc.MipLevels; srvDesc.Texture2D.MostDetailedMip = 0; g_pd3dDevice->CreateShaderResourceView(pTexture, &srvDesc, &g_pFontTextureView); + pTexture->Release(); } // create texture sampler @@ -562,8 +572,8 @@ int WINAPI wWinMain(HINSTANCE hInst, HINSTANCE, LPWSTR, int) } ImGui::Shutdown(); - UnregisterClass("ImGui Example", wc.hInstance); + return 0; } From 7f804d3d6451707a98a94b8bb7f66e9acdbcc799 Mon Sep 17 00:00:00 2001 From: ocornut Date: Sun, 30 Nov 2014 16:56:35 +0000 Subject: [PATCH 014/108] Tab->Spaces :( visual studio can't even be trusted for that, oh thanks. --- examples/directx11_example/main.cpp | 44 ++++++++++++++--------------- imgui.cpp | 22 +++++++-------- imgui.h | 22 +++++++-------- 3 files changed, 44 insertions(+), 44 deletions(-) diff --git a/examples/directx11_example/main.cpp b/examples/directx11_example/main.cpp index cf8ac106..1923f644 100644 --- a/examples/directx11_example/main.cpp +++ b/examples/directx11_example/main.cpp @@ -14,24 +14,24 @@ extern const char* vertexShader; // Implemented at the bottom extern const char* pixelShader; -static HWND hWnd; -static ID3D11Device* g_pd3dDevice = NULL; -static ID3D11DeviceContext* g_pd3dDeviceImmediateContext = NULL; -static IDXGISwapChain* g_pSwapChain = NULL; -static ID3D11Buffer* g_pVB = NULL; -static ID3D11RenderTargetView* g_mainRenderTargetView; +static HWND hWnd; +static ID3D11Device* g_pd3dDevice = NULL; +static ID3D11DeviceContext* g_pd3dDeviceImmediateContext = NULL; +static IDXGISwapChain* g_pSwapChain = NULL; +static ID3D11Buffer* g_pVB = NULL; +static ID3D11RenderTargetView* g_mainRenderTargetView; -static ID3D10Blob * g_pVertexShaderBlob = NULL; -static ID3D11VertexShader* g_pVertexShader = NULL; -static ID3D11InputLayout* g_pInputLayout = NULL; -static ID3D11Buffer* g_pVertexConstantBuffer = NULL; +static ID3D10Blob * g_pVertexShaderBlob = NULL; +static ID3D11VertexShader* g_pVertexShader = NULL; +static ID3D11InputLayout* g_pInputLayout = NULL; +static ID3D11Buffer* g_pVertexConstantBuffer = NULL; -static ID3D10Blob * g_pPixelShaderBlob = NULL; -static ID3D11PixelShader* g_pPixelShader = NULL; +static ID3D10Blob * g_pPixelShaderBlob = NULL; +static ID3D11PixelShader* g_pPixelShader = NULL; static ID3D11ShaderResourceView*g_pFontTextureView = NULL; -static ID3D11SamplerState* g_pFontSampler = NULL; -static ID3D11BlendState* g_blendState = NULL; +static ID3D11SamplerState* g_pFontSampler = NULL; +static ID3D11BlendState* g_blendState = NULL; struct CUSTOMVERTEX { @@ -92,10 +92,10 @@ static void ImImpl_RenderDrawLists(ImDrawList** const cmd_lists, int cmd_lists_c const float T = 0.5f; const float mvp[4][4] = { - { 2.0f/(R-L), 0.0f, 0.0f, 0.0f}, - { 0.0f, 2.0f/(T-B), 0.0f, 0.0f,}, - { 0.0f, 0.0f, 0.5f, 0.0f }, // -1.0f - { (R+L)/(L-R), (T+B)/(B-T), 0.5f, 1.0f }, // 0.0f + { 2.0f/(R-L), 0.0f, 0.0f, 0.0f}, + { 0.0f, 2.0f/(T-B), 0.0f, 0.0f,}, + { 0.0f, 0.0f, 0.5f, 0.0f }, + { (R+L)/(L-R), (T+B)/(B-T), 0.5f, 1.0f }, }; memcpy(&pConstantBuffer->mvp, mvp, sizeof(mvp)); g_pd3dDeviceImmediateContext->Unmap(g_pVertexConstantBuffer, 0); @@ -143,7 +143,7 @@ static void ImImpl_RenderDrawLists(ImDrawList** const cmd_lists, int cmd_lists_c { const ImDrawCmd* pcmd = &cmd_list->commands[cmd_i]; const D3D11_RECT r = { (LONG)pcmd->clip_rect.x, (LONG)pcmd->clip_rect.y, (LONG)pcmd->clip_rect.z, (LONG)pcmd->clip_rect.w }; - g_pd3dDeviceImmediateContext->RSSetScissorRects(1, &r); + g_pd3dDeviceImmediateContext->RSSetScissorRects(1, &r); g_pd3dDeviceImmediateContext->Draw(pcmd->vtx_count, vtx_offset); vtx_offset += pcmd->vtx_count; } @@ -203,15 +203,15 @@ HRESULT InitD3D(HWND hWnd) else RSDesc.MultisampleEnable = FALSE; - ID3D11RasterizerState* pRState = NULL; + ID3D11RasterizerState* pRState = NULL; g_pd3dDevice->CreateRasterizerState(&RSDesc, &pRState); g_pd3dDeviceImmediateContext->RSSetState(pRState); - pRState->Release(); + pRState->Release(); } // Create the render target { - ID3D11Texture2D* pBackBuffer; + ID3D11Texture2D* pBackBuffer; D3D11_RENDER_TARGET_VIEW_DESC render_target_view_desc; ZeroMemory(&render_target_view_desc, sizeof(render_target_view_desc)); render_target_view_desc.Format = sd.BufferDesc.Format; diff --git a/imgui.cpp b/imgui.cpp index 059c36cf..08787b2c 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -4143,7 +4143,7 @@ static void STB_TEXTEDIT_LAYOUTROW(StbTexteditRow* r, STB_TEXTEDIT_STRING* ob static bool is_white(unsigned int c) { return c==0 || c==' ' || c=='\t' || c=='\r' || c=='\n'; } static bool is_separator(unsigned int c) { return c==',' || c==';' || c=='(' || c==')' || c=='{' || c=='}' || c=='[' || c==']' || c=='|'; } -#define STB_TEXTEDIT_IS_SPACE(CH) ( is_white((unsigned int)CH) || is_separator((unsigned int)CH) ) +#define STB_TEXTEDIT_IS_SPACE(CH) ( is_white((unsigned int)CH) || is_separator((unsigned int)CH) ) static void STB_TEXTEDIT_DELETECHARS(STB_TEXTEDIT_STRING* obj, int pos, int n) { ImWchar* dst = obj->Text+pos; const ImWchar* src = obj->Text+pos+n; while (ImWchar c = *src++) *dst++ = c; *dst = '\0'; } static bool STB_TEXTEDIT_INSERTCHARS(STB_TEXTEDIT_STRING* obj, int pos, const ImWchar* new_text, int new_text_len) { @@ -4389,7 +4389,7 @@ bool ImGui::InputText(const char* label, char* buf, size_t buf_size, ImGuiInputT const bool is_ctrl_down = io.KeyCtrl; const bool is_shift_down = io.KeyShift; - const bool tab_focus_requested = window->FocusItemRegister(g.ActiveId == id, (flags & ImGuiInputTextFlags_CallbackCompletion) == 0); // Using completion callback disable keyboard tabbing + const bool tab_focus_requested = window->FocusItemRegister(g.ActiveId == id, (flags & ImGuiInputTextFlags_CallbackCompletion) == 0); // Using completion callback disable keyboard tabbing //const bool align_center = (bool)(flags & ImGuiInputTextFlags_AlignCenter); // FIXME: Unsupported const bool hovered = (g.HoveredWindow == window) && (g.HoveredId == 0) && IsMouseHoveringBox(frame_bb); @@ -6727,10 +6727,10 @@ void ImGui::ShowTestWindow(bool* open) // Testing IMGUI_ONCE_UPON_A_FRAME macro //for (int i = 0; i < 5; i++) //{ - // IMGUI_ONCE_UPON_A_FRAME - // { - // ImGui::Text("This will be displayed only once."); - // } + // IMGUI_ONCE_UPON_A_FRAME + // { + // ImGui::Text("This will be displayed only once."); + // } //} ImGui::Separator(); @@ -7118,9 +7118,9 @@ static void ShowExampleAppAutoResize(bool* open) struct ExampleAppConsole { ImVector Items; - bool NewItems; + bool NewItems; - void Clear() + void Clear() { for (size_t i = 0; i < Items.size(); i++) ImGui::MemFree(Items[i]); @@ -7128,7 +7128,7 @@ struct ExampleAppConsole NewItems = true; } - void AddLog(const char* fmt, ...) + void AddLog(const char* fmt, ...) { char buf[512]; va_list args; @@ -7139,7 +7139,7 @@ struct ExampleAppConsole NewItems = true; } - void TextEditCallback(ImGuiTextEditCallbackData* data) + void TextEditCallback(ImGuiTextEditCallbackData* data) { //AddLog("cursor: %d, selection: %d-%d", data->CursorPos, data->SelectionStart, data->SelectionEnd); switch (data->EventKey) @@ -7290,7 +7290,7 @@ static void ShowExampleAppConsole(bool* open) if (input_trimmed_end > input) { console.AddLog("# %s\n", input); - console.AddLog("Unknown command: '%.*s'\n", input_trimmed_end-input, input); // NB: we don't actually handle any command in this sample code + console.AddLog("Unknown command: '%.*s'\n", input_trimmed_end-input, input); // NB: we don't actually handle any command in this sample code } strcpy(input, ""); } diff --git a/imgui.h b/imgui.h index f1592161..6a61bcc0 100644 --- a/imgui.h +++ b/imgui.h @@ -537,7 +537,7 @@ struct ImGuiOnceUponAFrame { ImGuiOnceUponAFrame() { RefFrame = -1; } mutable int RefFrame; - operator bool() const { const int current_frame = ImGui::GetFrameCount(); if (RefFrame == current_frame) return false; RefFrame = current_frame; return true; } + operator bool() const { const int current_frame = ImGui::GetFrameCount(); if (RefFrame == current_frame) return false; RefFrame = current_frame; return true; } }; // Helper: Parse and apply text filters. In format "aaaaa[,bbbb][,ccccc]" @@ -608,15 +608,15 @@ struct ImGuiStorage // Shared state of InputText(), passed to callback when a ImGuiInputTextFlags_Callback* flag is used. struct ImGuiTextEditCallbackData { - ImGuiKey EventKey; // Key pressed (Up/Down/TAB) // Read-only - char* Buf; // Current text // Read-write (pointed data only) - size_t BufSize; // // Read-only - bool BufDirty; // Set if you modify Buf directly // Write - ImGuiInputTextFlags Flags; // What user passed to InputText() // Read-only - int CursorPos; // // Read-write - int SelectionStart; // // Read-write (== to SelectionEnd when no selection) - int SelectionEnd; // // Read-write - void* UserData; // What user passed to InputText() + ImGuiKey EventKey; // Key pressed (Up/Down/TAB) // Read-only + char* Buf; // Current text // Read-write (pointed data only) + size_t BufSize; // // Read-only + bool BufDirty; // Set if you modify Buf directly // Write + ImGuiInputTextFlags Flags; // What user passed to InputText() // Read-only + int CursorPos; // // Read-write + int SelectionStart; // // Read-write (== to SelectionEnd when no selection) + int SelectionEnd; // // Read-write + void* UserData; // What user passed to InputText() // NB: calling those function loses selection. void DeleteChars(int pos, int bytes_count); @@ -722,7 +722,7 @@ struct ImFont IMGUI_API ImFont(); IMGUI_API ~ImFont() { Clear(); } - IMGUI_API bool LoadFromMemory(const void* data, size_t data_size); + IMGUI_API bool LoadFromMemory(const void* data, size_t data_size); IMGUI_API bool LoadFromFile(const char* filename); IMGUI_API void Clear(); IMGUI_API void BuildLookupTable(); From 0e6f288a2f64d923d32442813aa86244670fb255 Mon Sep 17 00:00:00 2001 From: ocornut Date: Sun, 30 Nov 2014 17:26:44 +0000 Subject: [PATCH 015/108] DirectX11 example: further tweaks/massaging (-15 lines). Syncing example. --- examples/directx11_example/main.cpp | 73 ++++++++++++----------------- examples/directx9_example/main.cpp | 49 +++++++++---------- examples/opengl_example/main.cpp | 18 +++---- 3 files changed, 61 insertions(+), 79 deletions(-) diff --git a/examples/directx11_example/main.cpp b/examples/directx11_example/main.cpp index 1923f644..ea9a3411 100644 --- a/examples/directx11_example/main.cpp +++ b/examples/directx11_example/main.cpp @@ -3,7 +3,7 @@ #include "../shared/stb_image.h" // for .png loading #include "../../imgui.h" -// DirectX +// DirectX 11 #include #include #define DIRECTINPUT_VERSION 0x0800 @@ -115,12 +115,12 @@ static void ImImpl_RenderDrawLists(ImDrawList** const cmd_lists, int cmd_lists_c } // Bind shader and vertex buffers - g_pd3dDeviceImmediateContext->IASetInputLayout(g_pInputLayout); unsigned int stride = sizeof(CUSTOMVERTEX); unsigned int offset = 0; + g_pd3dDeviceImmediateContext->IASetInputLayout(g_pInputLayout); g_pd3dDeviceImmediateContext->IASetVertexBuffers(0, 1, &g_pVB, &stride, &offset); g_pd3dDeviceImmediateContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST); - + g_pd3dDeviceImmediateContext->VSSetShader(g_pVertexShader, NULL, 0); g_pd3dDeviceImmediateContext->VSSetConstantBuffers(0, 1, &g_pVertexConstantBuffer); @@ -130,8 +130,7 @@ static void ImImpl_RenderDrawLists(ImDrawList** const cmd_lists, int cmd_lists_c // Setup render state const float blendFactor[4] = { 0.f, 0.f, 0.f, 0.f }; - const UINT sampleMask = 0xffffffff; - g_pd3dDeviceImmediateContext->OMSetBlendState(g_blendState, blendFactor, sampleMask); + g_pd3dDeviceImmediateContext->OMSetBlendState(g_blendState, blendFactor, 0xffffffff); // Render command lists int vtx_offset = 0; @@ -155,7 +154,7 @@ static void ImImpl_RenderDrawLists(ImDrawList** const cmd_lists, int cmd_lists_c g_pd3dDeviceImmediateContext->VSSetShader(NULL, NULL, 0); } -HRESULT InitD3D(HWND hWnd) +HRESULT InitDeviceD3D(HWND hWnd) { // Setup swap chain DXGI_SWAP_CHAIN_DESC sd; @@ -198,10 +197,7 @@ HRESULT InitD3D(HWND hWnd) RSDesc.DepthClipEnable = TRUE; RSDesc.ScissorEnable = TRUE; RSDesc.AntialiasedLineEnable = FALSE; - if (sd.SampleDesc.Count > 1) - RSDesc.MultisampleEnable = TRUE; - else - RSDesc.MultisampleEnable = FALSE; + RSDesc.MultisampleEnable = (sd.SampleDesc.Count > 1) ? TRUE : FALSE; ID3D11RasterizerState* pRState = NULL; g_pd3dDevice->CreateRasterizerState(&RSDesc, &pRState); @@ -224,18 +220,11 @@ HRESULT InitD3D(HWND hWnd) // Create the vertex shader { - ID3D10Blob * pErrorBlob = NULL; - D3DCompile(vertexShader, strlen(vertexShader), NULL, NULL, NULL, "main", "vs_5_0", 0, 0, &g_pVertexShaderBlob, &pErrorBlob); - if (g_pVertexShaderBlob == NULL) - { - //const char* pError = (const char*)pErrorBlob->GetBufferPointer(); - pErrorBlob->Release(); + D3DCompile(vertexShader, strlen(vertexShader), NULL, NULL, NULL, "main", "vs_5_0", 0, 0, &g_pVertexShaderBlob, NULL); + if (g_pVertexShaderBlob == NULL) // NB: Pass ID3D10Blob* pErrorBlob to D3DCompile() to get error showing in (const char*)pErrorBlob->GetBufferPointer(). Make sure to Release() the blob! return E_FAIL; - } if (g_pd3dDevice->CreateVertexShader((DWORD*)g_pVertexShaderBlob->GetBufferPointer(), g_pVertexShaderBlob->GetBufferSize(), NULL, &g_pVertexShader) != S_OK) return E_FAIL; - if (pErrorBlob) - pErrorBlob->Release(); // Create the input layout D3D11_INPUT_ELEMENT_DESC localLayout[] = { @@ -261,18 +250,11 @@ HRESULT InitD3D(HWND hWnd) // Create the pixel shader { - ID3D10Blob * pErrorBlob; - D3DCompile(pixelShader, strlen(pixelShader), NULL, NULL, NULL, "main", "ps_5_0", 0, 0, &g_pPixelShaderBlob, &pErrorBlob); - if (g_pPixelShaderBlob == NULL) - { - //const char* pError = (const char*)pErrorBlob->GetBufferPointer(); - pErrorBlob->Release(); + D3DCompile(pixelShader, strlen(pixelShader), NULL, NULL, NULL, "main", "ps_5_0", 0, 0, &g_pPixelShaderBlob, NULL); + if (g_pPixelShaderBlob == NULL) // NB: Pass ID3D10Blob* pErrorBlob to D3DCompile() to get error showing in (const char*)pErrorBlob->GetBufferPointer(). Make sure to Release() the blob! return E_FAIL; - } if (g_pd3dDevice->CreatePixelShader((DWORD*)g_pPixelShaderBlob->GetBufferPointer(), g_pPixelShaderBlob->GetBufferSize(), NULL, &g_pPixelShader) != S_OK) return E_FAIL; - if (pErrorBlob) - pErrorBlob->Release(); } // Create the blending setup @@ -294,14 +276,16 @@ HRESULT InitD3D(HWND hWnd) return S_OK; } -void Cleanup() +void CleanupDevice() { if (g_pd3dDeviceImmediateContext) g_pd3dDeviceImmediateContext->ClearState(); + // InitImGui if (g_pFontSampler) g_pFontSampler->Release(); if (g_pFontTextureView) g_pFontTextureView->Release(); if (g_pVB) g_pVB->Release(); + // InitDeviceD3D if (g_blendState) g_blendState->Release(); if (g_pPixelShader) g_pPixelShader->Release(); if (g_pPixelShaderBlob) g_pPixelShaderBlob->Release(); @@ -346,7 +330,7 @@ LRESULT WINAPI MsgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) io.AddInputCharacter((unsigned short)wParam); return true; case WM_DESTROY: - Cleanup(); + CleanupDevice(); PostQuitMessage(0); return 0; } @@ -357,12 +341,14 @@ void InitImGui() { RECT rect; GetClientRect(hWnd, &rect); + int display_w = (int)(rect.right - rect.left); + int display_h = (int)(rect.bottom - rect.top); ImGuiIO& io = ImGui::GetIO(); - io.DisplaySize = ImVec2((float)(rect.right - rect.left), (float)(rect.bottom - rect.top)); // Display size, in pixels. For clamping windows positions. - io.DeltaTime = 1.0f/60.0f; // Time elapsed since last frame, in seconds (in this sample app we'll override this every frame because our timestep is variable) - io.PixelCenterOffset = 0.0f; // Align Direct3D Texels - io.KeyMap[ImGuiKey_Tab] = VK_TAB; // Keyboard mapping. ImGui will use those indices to peek into the io.KeyDown[] array that we will update during the application lifetime. + io.DisplaySize = ImVec2((float)display_w, (float)display_h); // Display size, in pixels. For clamping windows positions. + io.DeltaTime = 1.0f/60.0f; // Time elapsed since last frame, in seconds (in this sample app we'll override this every frame because our time step is variable) + io.PixelCenterOffset = 0.0f; // Align Direct3D Texels + io.KeyMap[ImGuiKey_Tab] = VK_TAB; // Keyboard mapping. ImGui will use those indices to peek into the io.KeyDown[] array that we will update during the application lifetime. io.KeyMap[ImGuiKey_LeftArrow] = VK_LEFT; io.KeyMap[ImGuiKey_RightArrow] = VK_RIGHT; io.KeyMap[ImGuiKey_UpArrow] = VK_UP; @@ -385,13 +371,11 @@ void InitImGui() { D3D11_BUFFER_DESC bufferDesc; memset(&bufferDesc, 0, sizeof(D3D11_BUFFER_DESC)); - bufferDesc.Usage = D3D11_USAGE_DYNAMIC; bufferDesc.ByteWidth = 10000 * sizeof(CUSTOMVERTEX); bufferDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER; bufferDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; bufferDesc.MiscFlags = 0; - if (g_pd3dDevice->CreateBuffer(&bufferDesc, NULL, &g_pVB) < 0) { IM_ASSERT(0); @@ -428,7 +412,7 @@ void InitImGui() subResource.SysMemSlicePitch = 0; g_pd3dDevice->CreateTexture2D(&desc, &subResource, &pTexture); - // create texture view + // Create texture view D3D11_SHADER_RESOURCE_VIEW_DESC srvDesc; ZeroMemory(&srvDesc, sizeof(srvDesc)); srvDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; @@ -439,7 +423,7 @@ void InitImGui() pTexture->Release(); } - // create texture sampler + // Create texture sampler { D3D11_SAMPLER_DESC desc; ZeroMemory(&desc, sizeof(desc)); @@ -456,17 +440,17 @@ void InitImGui() } INT64 ticks_per_second = 0; -INT64 time = 0; +INT64 last_time = 0; void UpdateImGui() { ImGuiIO& io = ImGui::GetIO(); - // Setup timestep + // Setup time step INT64 current_time; QueryPerformanceCounter((LARGE_INTEGER *)¤t_time); - io.DeltaTime = (float)(current_time - time) / ticks_per_second; - time = current_time; + io.DeltaTime = (float)(current_time - last_time) / ticks_per_second; + last_time = current_time; // Setup inputs // (we already got mouse position, buttons, wheel from the window message callback) @@ -495,12 +479,13 @@ int WINAPI wWinMain(HINSTANCE hInst, HINSTANCE, LPWSTR, int) if (!QueryPerformanceFrequency((LARGE_INTEGER *)&ticks_per_second)) return 1; - if (!QueryPerformanceCounter((LARGE_INTEGER *)&time)) + if (!QueryPerformanceCounter((LARGE_INTEGER *)&last_time)) return 1; // Initialize Direct3D - if (InitD3D(hWnd) < 0) + if (InitDeviceD3D(hWnd) < 0) { + CleanupDevice(); UnregisterClass("ImGui Example", wc.hInstance); return 1; } diff --git a/examples/directx9_example/main.cpp b/examples/directx9_example/main.cpp index ac8c2105..adb2bf30 100644 --- a/examples/directx9_example/main.cpp +++ b/examples/directx9_example/main.cpp @@ -1,7 +1,7 @@ #include #include "../../imgui.h" -// DirectX +// DirectX 9 #include #define DIRECTINPUT_VERSION 0x0800 #include @@ -103,7 +103,7 @@ static void ImImpl_RenderDrawLists(ImDrawList** const cmd_lists, int cmd_lists_c } } -HRESULT InitD3D(HWND hWnd) +HRESULT InitDeviceD3D(HWND hWnd) { if (NULL == (g_pD3D = Direct3DCreate9(D3D_SDK_VERSION))) return E_FAIL; @@ -124,16 +124,15 @@ HRESULT InitD3D(HWND hWnd) return S_OK; } -void Cleanup() +void CleanupDevice() { - if (g_pTexture != NULL) - g_pTexture->Release(); + // InitImGui + if (g_pVB) g_pVB->Release(); - if (g_pd3dDevice != NULL) - g_pd3dDevice->Release(); - - if (g_pD3D != NULL) - g_pD3D->Release(); + // InitDeviceD3D + if (g_pTexture) g_pTexture->Release(); + if (g_pd3dDevice) g_pd3dDevice->Release(); + if (g_pD3D) g_pD3D->Release(); } LRESULT WINAPI MsgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) @@ -167,7 +166,7 @@ LRESULT WINAPI MsgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) io.AddInputCharacter((unsigned short)wParam); return true; case WM_DESTROY: - Cleanup(); + CleanupDevice(); PostQuitMessage(0); return 0; } @@ -178,12 +177,14 @@ void InitImGui() { RECT rect; GetClientRect(hWnd, &rect); + int display_w = (int)(rect.right - rect.left); + int display_h = (int)(rect.bottom - rect.top); ImGuiIO& io = ImGui::GetIO(); - io.DisplaySize = ImVec2((float)(rect.right - rect.left), (float)(rect.bottom - rect.top)); // Display size, in pixels. For clamping windows positions. - io.DeltaTime = 1.0f/60.0f; // Time elapsed since last frame, in seconds (in this sample app we'll override this every frame because our timestep is variable) - io.PixelCenterOffset = 0.0f; // Align Direct3D Texels - io.KeyMap[ImGuiKey_Tab] = VK_TAB; // Keyboard mapping. ImGui will use those indices to peek into the io.KeyDown[] array that we will update during the application lifetime. + io.DisplaySize = ImVec2((float)display_w, (float)display_h); // Display size, in pixels. For clamping windows positions. + io.DeltaTime = 1.0f/60.0f; // Time elapsed since last frame, in seconds (in this sample app we'll override this every frame because our time step is variable) + io.PixelCenterOffset = 0.0f; // Align Direct3D Texels + io.KeyMap[ImGuiKey_Tab] = VK_TAB; // Keyboard mapping. ImGui will use those indices to peek into the io.KeyDown[] array that we will update during the application lifetime. io.KeyMap[ImGuiKey_LeftArrow] = VK_LEFT; io.KeyMap[ImGuiKey_RightArrow] = VK_RIGHT; io.KeyMap[ImGuiKey_UpArrow] = VK_UP; @@ -222,17 +223,17 @@ void InitImGui() } INT64 ticks_per_second = 0; -INT64 time = 0; +INT64 last_time = 0; void UpdateImGui() { ImGuiIO& io = ImGui::GetIO(); - // Setup timestep + // Setup time step INT64 current_time; QueryPerformanceCounter((LARGE_INTEGER *)¤t_time); - io.DeltaTime = (float)(current_time - time) / ticks_per_second; - time = current_time; + io.DeltaTime = (float)(current_time - last_time) / ticks_per_second; + last_time = current_time; // Setup inputs // (we already got mouse position, buttons, wheel from the window message callback) @@ -261,14 +262,13 @@ int WINAPI wWinMain(HINSTANCE hInst, HINSTANCE, LPWSTR, int) if (!QueryPerformanceFrequency((LARGE_INTEGER *)&ticks_per_second)) return 1; - if (!QueryPerformanceCounter((LARGE_INTEGER *)&time)) + if (!QueryPerformanceCounter((LARGE_INTEGER *)&last_time)) return 1; // Initialize Direct3D - if (InitD3D(hWnd) < 0) + if (InitDeviceD3D(hWnd) < 0) { - if (g_pVB) - g_pVB->Release(); + CleanupDevice(); UnregisterClass(L"ImGui Example", wc.hInstance); return 1; } @@ -347,9 +347,6 @@ int WINAPI wWinMain(HINSTANCE hInst, HINSTANCE, LPWSTR, int) ImGui::Shutdown(); - if (g_pVB) - g_pVB->Release(); - UnregisterClass(L"ImGui Example", wc.hInstance); return 0; } diff --git a/examples/opengl_example/main.cpp b/examples/opengl_example/main.cpp index 2fce58f0..22e2b1b0 100644 --- a/examples/opengl_example/main.cpp +++ b/examples/opengl_example/main.cpp @@ -156,17 +156,17 @@ void InitGL() void InitImGui() { int w, h; - int fb_w, fb_h; + int display_w, display_h; glfwGetWindowSize(window, &w, &h); - glfwGetFramebufferSize(window, &fb_w, &fb_h); - mousePosScale.x = (float)fb_w / w; // Some screens e.g. Retina display have framebuffer size != from window size, and mouse inputs are given in window/screen coordinates. - mousePosScale.y = (float)fb_h / h; + glfwGetFramebufferSize(window, &display_w, &display_h); + mousePosScale.x = (float)display_w / w; // Some screens e.g. Retina display have framebuffer size != from window size, and mouse inputs are given in window/screen coordinates. + mousePosScale.y = (float)display_h / h; ImGuiIO& io = ImGui::GetIO(); - io.DisplaySize = ImVec2((float)fb_w, (float)fb_h); // Display size, in pixels. For clamping windows positions. - io.DeltaTime = 1.0f/60.0f; // Time elapsed since last frame, in seconds (in this sample app we'll override this every frame because our timestep is variable) - io.PixelCenterOffset = 0.0f; // Align OpenGL texels - io.KeyMap[ImGuiKey_Tab] = GLFW_KEY_TAB; // Keyboard mapping. ImGui will use those indices to peek into the io.KeyDown[] array. + io.DisplaySize = ImVec2((float)display_w, (float)display_h); // Display size, in pixels. For clamping windows positions. + io.DeltaTime = 1.0f/60.0f; // Time elapsed since last frame, in seconds (in this sample app we'll override this every frame because our time step is variable) + io.PixelCenterOffset = 0.0f; // Align OpenGL texels + io.KeyMap[ImGuiKey_Tab] = GLFW_KEY_TAB; // Keyboard mapping. ImGui will use those indices to peek into the io.KeyDown[] array. io.KeyMap[ImGuiKey_LeftArrow] = GLFW_KEY_LEFT; io.KeyMap[ImGuiKey_RightArrow] = GLFW_KEY_RIGHT; io.KeyMap[ImGuiKey_UpArrow] = GLFW_KEY_UP; @@ -230,7 +230,7 @@ void UpdateImGui() { ImGuiIO& io = ImGui::GetIO(); - // Setup timestep + // Setup time step static double time = 0.0f; const double current_time = glfwGetTime(); io.DeltaTime = (float)(current_time - time); From 0730ec7577d84bb4e54ccb5657a7115f49e1e1af Mon Sep 17 00:00:00 2001 From: ocornut Date: Sun, 30 Nov 2014 17:41:08 +0000 Subject: [PATCH 016/108] Example apps: accumulate mouse wheel to accodomate for slow framerate. --- examples/directx11_example/main.cpp | 2 +- examples/directx9_example/main.cpp | 2 +- examples/opengl_example/main.cpp | 3 +-- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/examples/directx11_example/main.cpp b/examples/directx11_example/main.cpp index ea9a3411..84d86739 100644 --- a/examples/directx11_example/main.cpp +++ b/examples/directx11_example/main.cpp @@ -317,7 +317,7 @@ LRESULT WINAPI MsgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) io.MouseDown[1] = false; return true; case WM_MOUSEWHEEL: - io.MouseWheel = GET_WHEEL_DELTA_WPARAM(wParam) > 0 ? +1.0f : -1.0f; + io.MouseWheel += GET_WHEEL_DELTA_WPARAM(wParam) > 0 ? +1.0f : -1.0f; return true; case WM_MOUSEMOVE: // Mouse position, in pixels (set to -1,-1 if no mouse / on another screen, etc.) diff --git a/examples/directx9_example/main.cpp b/examples/directx9_example/main.cpp index adb2bf30..047874c4 100644 --- a/examples/directx9_example/main.cpp +++ b/examples/directx9_example/main.cpp @@ -153,7 +153,7 @@ LRESULT WINAPI MsgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) io.MouseDown[1] = false; return true; case WM_MOUSEWHEEL: - io.MouseWheel = GET_WHEEL_DELTA_WPARAM(wParam) > 0 ? +1.0f : -1.0f; + io.MouseWheel += GET_WHEEL_DELTA_WPARAM(wParam) > 0 ? +1.0f : -1.0f; return true; case WM_MOUSEMOVE: // Mouse position, in pixels (set to -1,-1 if no mouse / on another screen, etc.) diff --git a/examples/opengl_example/main.cpp b/examples/opengl_example/main.cpp index 22e2b1b0..61a9f369 100644 --- a/examples/opengl_example/main.cpp +++ b/examples/opengl_example/main.cpp @@ -114,7 +114,7 @@ static void glfw_mouse_button_callback(GLFWwindow* window, int button, int actio static void glfw_scroll_callback(GLFWwindow* window, double xoffset, double yoffset) { ImGuiIO& io = ImGui::GetIO(); - io.MouseWheel = (float)yoffset; // Use fractional mouse wheel, 1.0 unit 5 lines. + io.MouseWheel += (float)yoffset; // Use fractional mouse wheel, 1.0 unit 5 lines. } static void glfw_key_callback(GLFWwindow* window, int key, int scancode, int action, int mods) @@ -258,7 +258,6 @@ int main(int argc, char** argv) { ImGuiIO& io = ImGui::GetIO(); mousePressed[0] = mousePressed[1] = false; - io.MouseWheel = 0; glfwPollEvents(); UpdateImGui(); From b4fd216bd203da625083301d4af600025a29d2bf Mon Sep 17 00:00:00 2001 From: ocornut Date: Sun, 30 Nov 2014 18:02:08 +0000 Subject: [PATCH 017/108] DirectX9/DirectX11 example: fixed window initially showing an hourglass cursor. --- examples/directx11_example/main.cpp | 4 ++-- examples/directx9_example/main.cpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/directx11_example/main.cpp b/examples/directx11_example/main.cpp index 84d86739..0d4cec29 100644 --- a/examples/directx11_example/main.cpp +++ b/examples/directx11_example/main.cpp @@ -299,7 +299,7 @@ void CleanupDevice() if (g_pd3dDevice) g_pd3dDevice->Release(); } -LRESULT WINAPI MsgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) +LRESULT WINAPI WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { ImGuiIO& io = ImGui::GetIO(); switch (msg) @@ -471,7 +471,7 @@ void UpdateImGui() int WINAPI wWinMain(HINSTANCE hInst, HINSTANCE, LPWSTR, int) { // Register the window class - WNDCLASSEX wc = { sizeof(WNDCLASSEX), CS_CLASSDC, MsgProc, 0L, 0L, GetModuleHandle(NULL), NULL, NULL, NULL, NULL, "ImGui Example", NULL }; + WNDCLASSEX wc = { sizeof(WNDCLASSEX), CS_CLASSDC, WndProc, 0L, 0L, GetModuleHandle(NULL), NULL, LoadCursor(NULL, IDC_ARROW), NULL, NULL, "ImGui Example", NULL }; RegisterClassEx(&wc); // Create the application's window diff --git a/examples/directx9_example/main.cpp b/examples/directx9_example/main.cpp index 047874c4..dc86c3c0 100644 --- a/examples/directx9_example/main.cpp +++ b/examples/directx9_example/main.cpp @@ -135,7 +135,7 @@ void CleanupDevice() if (g_pD3D) g_pD3D->Release(); } -LRESULT WINAPI MsgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) +LRESULT WINAPI WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { ImGuiIO& io = ImGui::GetIO(); switch (msg) @@ -254,7 +254,7 @@ void UpdateImGui() int WINAPI wWinMain(HINSTANCE hInst, HINSTANCE, LPWSTR, int) { // Register the window class - WNDCLASSEX wc = { sizeof(WNDCLASSEX), CS_CLASSDC, MsgProc, 0L, 0L, GetModuleHandle(NULL), NULL, NULL, NULL, NULL, L"ImGui Example", NULL }; + WNDCLASSEX wc = { sizeof(WNDCLASSEX), CS_CLASSDC, WndProc, 0L, 0L, GetModuleHandle(NULL), NULL, LoadCursor(NULL, IDC_ARROW), NULL, NULL, L"ImGui Example", NULL }; RegisterClassEx(&wc); // Create the application's window From e6b9950645c271ad2ae07cc3c5890035a131900a Mon Sep 17 00:00:00 2001 From: omar Date: Sun, 30 Nov 2014 18:06:52 +0000 Subject: [PATCH 018/108] Update README.md Credits+link for stb_textedit.h --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 9774ccdc..433f0a6d 100644 --- a/README.md +++ b/README.md @@ -93,6 +93,7 @@ Developed by [Omar Cornut](http://www.miracleworld.net). The library was develop Embeds [proggy_clean](http://upperbounds.net) font by Tristan Grimmer (MIT license). Embeds [M+ fonts](http://mplus-fonts.sourceforge.jp/mplus-outline-fonts/index-en.html) font by Coji Morishita (free software license). +Embeds [stb_textedit.h](https://github.com/nothings/stb/) by Sean Barrett. Inspiration, feedback, and testing: Casey Muratori, Atman Binstock, Mikko Mononen, Emmanuel Briney, Stefan Kamoda, Anton Mikhailov, Matt Willis. Thanks! From bd762b559cada530f33d77e29bbb2c7b47b22dab Mon Sep 17 00:00:00 2001 From: ocornut Date: Mon, 1 Dec 2014 09:34:17 +0000 Subject: [PATCH 019/108] DirectX11 example: fixed projection matrix offset. --- examples/directx11_example/main.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/directx11_example/main.cpp b/examples/directx11_example/main.cpp index 0d4cec29..bb24c73b 100644 --- a/examples/directx11_example/main.cpp +++ b/examples/directx11_example/main.cpp @@ -86,10 +86,10 @@ static void ImImpl_RenderDrawLists(ImDrawList** const cmd_lists, int cmd_lists_c return; VERTEX_CONSTANT_BUFFER* pConstantBuffer = (VERTEX_CONSTANT_BUFFER*)mappedResource.pData; - const float L = 0.5f; - const float R = ImGui::GetIO().DisplaySize.x + 0.5f; - const float B = ImGui::GetIO().DisplaySize.y + 0.5f; - const float T = 0.5f; + const float L = 0.0f; + const float R = ImGui::GetIO().DisplaySize.x; + const float B = ImGui::GetIO().DisplaySize.y; + const float T = 0.0f; const float mvp[4][4] = { { 2.0f/(R-L), 0.0f, 0.0f, 0.0f}, From d31623061fde9fc9932002357570b0761beff788 Mon Sep 17 00:00:00 2001 From: omar Date: Wed, 3 Dec 2014 11:56:33 +0000 Subject: [PATCH 020/108] ImVector: private -> protected --- imgui.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/imgui.h b/imgui.h index 6a61bcc0..f749a189 100644 --- a/imgui.h +++ b/imgui.h @@ -77,7 +77,7 @@ namespace ImGui template class ImVector { -private: +protected: size_t Size; size_t Capacity; T* Data; From 63ff0ad0ff7be8da20691cdd917e8a61ddb1164c Mon Sep 17 00:00:00 2001 From: omar Date: Wed, 3 Dec 2014 12:00:03 +0000 Subject: [PATCH 021/108] Examples: OpenGL: fix accessing libraries via ProjectDir instead of SolutionDir --- examples/opengl_example/opengl_example.vcxproj | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/opengl_example/opengl_example.vcxproj b/examples/opengl_example/opengl_example.vcxproj index e53123c0..4dc74d37 100644 --- a/examples/opengl_example/opengl_example.vcxproj +++ b/examples/opengl_example/opengl_example.vcxproj @@ -41,11 +41,11 @@ Level3 Disabled - $(SolutionDir)\glfw\include;$(SolutionDir)\glew\include;%(AdditionalIncludeDirectories) + $(ProjectDir)\glfw\include;$(ProjectDir)\glew\include;%(AdditionalIncludeDirectories) true - $(SolutionDir)\glfw\lib-msvc100;$(SolutionDir)\glew\lib\Release\Win32;%(AdditionalLibraryDirectories) + $(ProjectDir)\glfw\lib-msvc100;$(ProjectDir)\glew\lib\Release\Win32;%(AdditionalLibraryDirectories) opengl32.lib;imm32.lib;glfw3.lib;glew32s.lib;%(AdditionalDependencies) NotSet @@ -56,13 +56,13 @@ MaxSpeed true true - $(SolutionDir)\glfw\include;$(SolutionDir)\glew\include;%(AdditionalIncludeDirectories) + $(ProjectDir)\glfw\include;$(ProjectDir)\glew\include;%(AdditionalIncludeDirectories) true true true - $(SolutionDir)\glfw\lib-msvc100;$(SolutionDir)\glew\lib\Release\Win32;%(AdditionalLibraryDirectories) + $(ProjectDir)\glfw\lib-msvc100;$(ProjectDir)\glew\lib\Release\Win32;%(AdditionalLibraryDirectories) opengl32.lib;imm32.lib;glfw3.lib;glew32s.lib;%(AdditionalDependencies) NotSet From a8d2bc69ed3bb9664e764d5f1addbf4b5c2ea07e Mon Sep 17 00:00:00 2001 From: Olivier Chatry Date: Wed, 3 Dec 2014 18:37:07 +0100 Subject: [PATCH 022/108] added opengl3 sample, mix from @ocornut and @thelinked --- examples/imgui_examples_msvc2010.sln | 6 + examples/opengl3_example/Makefile | 53 +++ examples/opengl3_example/main.cpp | 407 ++++++++++++++++++ .../opengl3_example/opengl3_example.vcxproj | 85 ++++ .../opengl3_example.vcxproj.filters | 36 ++ 5 files changed, 587 insertions(+) create mode 100644 examples/opengl3_example/Makefile create mode 100644 examples/opengl3_example/main.cpp create mode 100644 examples/opengl3_example/opengl3_example.vcxproj create mode 100644 examples/opengl3_example/opengl3_example.vcxproj.filters diff --git a/examples/imgui_examples_msvc2010.sln b/examples/imgui_examples_msvc2010.sln index 05c018d2..1ff20521 100644 --- a/examples/imgui_examples_msvc2010.sln +++ b/examples/imgui_examples_msvc2010.sln @@ -7,6 +7,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "directx9_example", "directx EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "directx11_example", "directx11_example\directx11_example.vcxproj", "{9F316E83-5AE5-4939-A723-305A94F48005}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "opengl3_example", "opengl3_example\opengl3_example.vcxproj", "{4A1FB5EA-22F5-42A8-AB92-1D2DF5D47FB9}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Win32 = Debug|Win32 @@ -25,6 +27,10 @@ Global {9F316E83-5AE5-4939-A723-305A94F48005}.Debug|Win32.Build.0 = Debug|Win32 {9F316E83-5AE5-4939-A723-305A94F48005}.Release|Win32.ActiveCfg = Release|Win32 {9F316E83-5AE5-4939-A723-305A94F48005}.Release|Win32.Build.0 = Release|Win32 + {4A1FB5EA-22F5-42A8-AB92-1D2DF5D47FB9}.Debug|Win32.ActiveCfg = Debug|Win32 + {4A1FB5EA-22F5-42A8-AB92-1D2DF5D47FB9}.Debug|Win32.Build.0 = Debug|Win32 + {4A1FB5EA-22F5-42A8-AB92-1D2DF5D47FB9}.Release|Win32.ActiveCfg = Release|Win32 + {4A1FB5EA-22F5-42A8-AB92-1D2DF5D47FB9}.Release|Win32.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/examples/opengl3_example/Makefile b/examples/opengl3_example/Makefile new file mode 100644 index 00000000..027fc151 --- /dev/null +++ b/examples/opengl3_example/Makefile @@ -0,0 +1,53 @@ +# +# Cross Platform Make file +# +# Compatible with Ubuntu 14.04.1 and Mac OS X +# +# +# if you using Mac OS X: +# You should install glew via homebrew +# brew install glew +# Also you'll need glfw +# http://www.glfw.org +# + +CXX = g++ + +OBJS = main.o +OBJS += ../../imgui.o + +UNAME_S := $(shell uname -s) + + +ifeq ($(UNAME_S), Linux) #LINUX + ECHO_MESSAGE = "Linux" + CXXFLAGS = -I../../ `pkg-config --cflags glfw3` + LIBS = `pkg-config --static --libs glfw3` -lGLEW +endif + +ifeq ($(UNAME_S), Darwin) #APPLE + ECHO_MESSAGE = "Mac OS X" + + LIBS = -framework OpenGL -framework Cocoa -framework IOKit -framework CoreVideo + LIBS += -L/usr/local/Cellar/glew/1.10.0/lib -L/usr/local/lib + LIBS += -lglew -lglfw3 + + CXXFLAGS = -I/usr/local/Cellar/glew/1.10.0/include -I/usr/local/include + CXXFLAGS += -I../../ + +# CXXFLAGS += -D__APPLE__ + +endif + +.cpp.o: + $(CXX) $(CXXFLAGS) -c -o $@ $< + +all:imgui_example + @echo Build complete for $(ECHO_MESSAGE) + +imgui_example:$(OBJS) + $(CXX) -o imgui_example $(OBJS) $(CXXFLAGS) $(LIBS) + +clean: + rm $(OBJS) + diff --git a/examples/opengl3_example/main.cpp b/examples/opengl3_example/main.cpp new file mode 100644 index 00000000..2be8a24f --- /dev/null +++ b/examples/opengl3_example/main.cpp @@ -0,0 +1,407 @@ +#define GLEW_STATIC +#include +#include +#define STB_IMAGE_IMPLEMENTATION +#include "../shared/stb_image.h" // for .png loading +#include "../../imgui.h" +#ifdef _MSC_VER +#pragma warning (disable: 4996) // 'This function or variable may be unsafe': strcpy, strdup, sprintf, vsnprintf, sscanf, fopen +#endif + +static GLFWwindow* window; +static GLuint fontTex; +//Shader variables +static int shader_handle, vert_handle, frag_handle; + +static int texture_location, ortho_location; +static int position_location, uv_location, colour_location; +//streaming vbo +//we are going to use the same vertex buffer for all rendering of imgui +//so we need to use a large enough buffer as default. +//the buffer will be resized if needed in the rendering code, but it is not a "free" operation. +static size_t vbo_max_size = 1000000; +static unsigned int vbo_handle, vao_handle; + + +template +unsigned int stream(GLenum target, unsigned int vbo, unsigned int *vbo_cursor, unsigned int *vbo_size, T *start, int elementCount) +{ + unsigned int bytes = sizeof(T) *elementCount; + unsigned int aligned = bytes + bytes % 64; //align memory + + glBindBuffer(target, vbo); + //If there's not enough space left, orphan the buffer object, create a new one and start writing + if (vbo_cursor[0] + aligned > vbo_size[0]) + { + assert(aligned < vbo_size[0]); + glBufferData(target, vbo_size[0], NULL, GL_DYNAMIC_DRAW); + vbo_cursor[0] = 0; + } + + void* mapped = glMapBufferRange(target, vbo_cursor[0], aligned, GL_MAP_WRITE_BIT | GL_MAP_UNSYNCHRONIZED_BIT); + + memcpy(mapped, start, bytes); + vbo_cursor[0] += aligned; + + glUnmapBuffer(target); + return vbo_cursor[0] - aligned; //return the offset we use for glVertexAttribPointer call +} + +// This is the main rendering function that you have to implement and provide to ImGui (via setting up 'RenderDrawListsFn' in the ImGuiIO structure) +// If text or lines are blurry when integrating ImGui in your engine: +// - try adjusting ImGui::GetIO().PixelCenterOffset to 0.0f or 0.5f +// - in your Render function, try translating your projection matrix by (0.5f,0.5f) or (0.375f,0.375f) +static void ImImpl_RenderDrawLists(ImDrawList** const cmd_lists, int cmd_lists_count) +{ + if (cmd_lists_count == 0) + return; + + // Setup render state: alpha-blending enabled, no face culling, no depth testing, scissor enabled + glEnable(GL_BLEND); + glBlendEquation(GL_FUNC_ADD); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glDisable(GL_CULL_FACE); + glDisable(GL_DEPTH_TEST); + glEnable(GL_SCISSOR_TEST); + + // Setup texture + glActiveTexture(GL_TEXTURE0); + glBindTexture(GL_TEXTURE_2D, fontTex); + + // Setup orthographic projection matrix + const float width = ImGui::GetIO().DisplaySize.x; + const float height = ImGui::GetIO().DisplaySize.y; + const float ortho_projection[4][4] = + { + { 2.0f/width, 0.0f, 0.0f, 0.0f }, + { 0.0f, 2.0f/-height, 0.0f, 0.0f }, + { 0.0f, 0.0f, -1.0f, 0.0f }, + { -1.0f, 1.0f, 0.0f, 1.0f }, + }; + glUseProgram(shader_handle); + glUniform1i(texture_location, 0); + glUniformMatrix4fv(ortho_location, 1, GL_FALSE, &ortho_projection[0][0]); + + // we will update the buffer in full, so we need to compute the total size of the buffer. + size_t total_vtx_count = 0; + for (int n = 0; n < cmd_lists_count; n++) + total_vtx_count += cmd_lists[n]->vtx_buffer.size(); + + glBindBuffer(GL_ARRAY_BUFFER, vbo_handle); + size_t neededBufferSize = total_vtx_count * sizeof(ImDrawVert); + if (neededBufferSize > vbo_max_size) + { + vbo_max_size = neededBufferSize; + glBufferData(GL_ARRAY_BUFFER, total_vtx_count * sizeof(ImDrawVert), NULL, GL_STREAM_DRAW); + } + + unsigned char* buffer_data = (unsigned char*)glMapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY); + if (!buffer_data) + return; + for (int n = 0; n < cmd_lists_count; n++) + { + const ImDrawList* cmd_list = cmd_lists[n]; + memcpy(buffer_data, &cmd_list->vtx_buffer[0], cmd_list->vtx_buffer.size() * sizeof(ImDrawVert)); + buffer_data += cmd_list->vtx_buffer.size() * sizeof(ImDrawVert); + } + glUnmapBuffer(GL_ARRAY_BUFFER); + glBindBuffer(GL_ARRAY_BUFFER, 0); + + glBindVertexArray(vao_handle); + + int cmd_offset = 0; + for (int n = 0; n < cmd_lists_count; n++) + { + const ImDrawList* cmd_list = cmd_lists[n]; + int vtx_offset = cmd_offset; + const ImDrawCmd* pcmd_end = cmd_list->commands.end(); + for (const ImDrawCmd* pcmd = cmd_list->commands.begin(); pcmd != pcmd_end; pcmd++) + { + glScissor((int)pcmd->clip_rect.x, (int)(height - pcmd->clip_rect.w), (int)(pcmd->clip_rect.z - pcmd->clip_rect.x), (int)(pcmd->clip_rect.w - pcmd->clip_rect.y)); + glDrawArrays(GL_TRIANGLES, vtx_offset, pcmd->vtx_count); + vtx_offset += pcmd->vtx_count; + } + cmd_offset = vtx_offset; + } + + glBindVertexArray(0); + glUseProgram(0); + glDisable(GL_SCISSOR_TEST); + glBindTexture(GL_TEXTURE_2D, 0); + +} + +static const char* ImImpl_GetClipboardTextFn() +{ + return glfwGetClipboardString(window); +} + +static void ImImpl_SetClipboardTextFn(const char* text) +{ + glfwSetClipboardString(window, text); +} + +// GLFW callbacks to get events +static void glfw_error_callback(int error, const char* description) +{ + fputs(description, stderr); +} + +static void glfw_scroll_callback(GLFWwindow* window, double xoffset, double yoffset) +{ + ImGuiIO& io = ImGui::GetIO(); + io.MouseWheel = (yoffset != 0.0f) ? yoffset > 0.0f ? 1.0f : -1.0f : 0.0f; // Mouse wheel: -1,0,+1 +} + +static void glfw_key_callback(GLFWwindow* window, int key, int scancode, int action, int mods) +{ + ImGuiIO& io = ImGui::GetIO(); + if (action == GLFW_PRESS) + io.KeysDown[key] = true; + if (action == GLFW_RELEASE) + io.KeysDown[key] = false; + io.KeyCtrl = (mods & GLFW_MOD_CONTROL) != 0; + io.KeyShift = (mods & GLFW_MOD_SHIFT) != 0; +} + +static void glfw_char_callback(GLFWwindow* window, unsigned int c) +{ + if (c > 0 && c <= 255) + ImGui::GetIO().AddInputCharacter((char)c); +} + + +// OpenGL code based on http://open.gl tutorials +void InitGL() +{ + glfwSetErrorCallback(glfw_error_callback); + + if (!glfwInit()) + exit(1); + + glfwWindowHint(GLFW_RESIZABLE, GL_FALSE); + glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); + glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); + glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); + + window = glfwCreateWindow(1280, 720, "ImGui OpenGL example", NULL, NULL); + glfwMakeContextCurrent(window); + glfwSetKeyCallback(window, glfw_key_callback); + glfwSetScrollCallback(window, glfw_scroll_callback); + glfwSetCharCallback(window, glfw_char_callback); + + glewExperimental = GL_TRUE; + + GLenum err = glewInit(); + if (GLEW_OK != err) + { + fprintf(stderr, "Error: %s\n", glewGetErrorString(err)); + } + + const GLchar *vertex_shader = \ + "#version 330\n" + "uniform mat4 ortho;\n" + + "in vec2 Position;\n" + "in vec2 UV;\n" + "in vec4 Colour;\n" + + "out vec2 Frag_UV;\n" + "out vec4 Frag_Colour;\n" + + "void main()\n" + "{\n" + " Frag_UV = UV;\n" + " Frag_Colour = Colour;\n" + "\n" + " gl_Position = ortho*vec4(Position.xy,0,1);\n" + "}\n"; + + const GLchar* fragment_shader = \ + "#version 330\n" + "uniform sampler2D Texture;\n" + + "in vec2 Frag_UV;\n" + "in vec4 Frag_Colour;\n" + + "out vec4 FragColor;\n" + + "void main()\n" + "{\n" + " FragColor = Frag_Colour * texture( Texture, Frag_UV.st);\n" + "}\n"; + + shader_handle = glCreateProgram(); + vert_handle = glCreateShader(GL_VERTEX_SHADER); + frag_handle = glCreateShader(GL_FRAGMENT_SHADER); + glShaderSource(vert_handle, 1, &vertex_shader, 0); + glShaderSource(frag_handle, 1, &fragment_shader, 0); + glCompileShader(vert_handle); + glCompileShader(frag_handle); + glAttachShader(shader_handle, vert_handle); + glAttachShader(shader_handle, frag_handle); + glLinkProgram(shader_handle); + + texture_location = glGetUniformLocation(shader_handle, "Texture"); + ortho_location = glGetUniformLocation(shader_handle, "ortho"); + position_location = glGetAttribLocation(shader_handle, "Position"); + uv_location = glGetAttribLocation(shader_handle, "UV"); + colour_location = glGetAttribLocation(shader_handle, "Colour"); + + glGenBuffers(1, &vbo_handle); + glBindBuffer(GL_ARRAY_BUFFER, vbo_handle); + glBufferData(GL_ARRAY_BUFFER, vbo_max_size, NULL, GL_DYNAMIC_DRAW); + + glGenVertexArrays(1, &vao_handle); + glBindVertexArray(vao_handle); + glBindBuffer(GL_ARRAY_BUFFER, vbo_handle); + glEnableVertexAttribArray(position_location); + glEnableVertexAttribArray(uv_location); + glEnableVertexAttribArray(colour_location); + + glVertexAttribPointer(position_location, 2, GL_FLOAT, GL_FALSE, sizeof(ImDrawVert), (GLvoid*) offsetof(ImDrawVert, pos)); + glVertexAttribPointer(uv_location, 2, GL_FLOAT, GL_FALSE, sizeof(ImDrawVert), (GLvoid*) offsetof(ImDrawVert, uv)); + glVertexAttribPointer(colour_location, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(ImDrawVert), (GLvoid*) offsetof(ImDrawVert, col)); + glBindVertexArray(0); + glBindBuffer(GL_ARRAY_BUFFER, 0); + + +} + +void InitImGui() +{ + int w, h; + glfwGetWindowSize(window, &w, &h); + + ImGuiIO& io = ImGui::GetIO(); + io.DisplaySize = ImVec2((float)w, (float)h); // Display size, in pixels. For clamping windows positions. + io.DeltaTime = 1.0f / 60.0f; // Time elapsed since last frame, in seconds (in this sample app we'll override this every frame because our timestep is variable) + io.PixelCenterOffset = 0.5f; // Align OpenGL texels + io.KeyMap[ImGuiKey_Tab] = GLFW_KEY_TAB; // Keyboard mapping. ImGui will use those indices to peek into the io.KeyDown[] array. + io.KeyMap[ImGuiKey_LeftArrow] = GLFW_KEY_LEFT; + io.KeyMap[ImGuiKey_RightArrow] = GLFW_KEY_RIGHT; + io.KeyMap[ImGuiKey_UpArrow] = GLFW_KEY_UP; + io.KeyMap[ImGuiKey_DownArrow] = GLFW_KEY_DOWN; + io.KeyMap[ImGuiKey_Home] = GLFW_KEY_HOME; + io.KeyMap[ImGuiKey_End] = GLFW_KEY_END; + io.KeyMap[ImGuiKey_Delete] = GLFW_KEY_DELETE; + io.KeyMap[ImGuiKey_Backspace] = GLFW_KEY_BACKSPACE; + io.KeyMap[ImGuiKey_Enter] = GLFW_KEY_ENTER; + io.KeyMap[ImGuiKey_Escape] = GLFW_KEY_ESCAPE; + io.KeyMap[ImGuiKey_A] = GLFW_KEY_A; + io.KeyMap[ImGuiKey_C] = GLFW_KEY_C; + io.KeyMap[ImGuiKey_V] = GLFW_KEY_V; + io.KeyMap[ImGuiKey_X] = GLFW_KEY_X; + io.KeyMap[ImGuiKey_Y] = GLFW_KEY_Y; + io.KeyMap[ImGuiKey_Z] = GLFW_KEY_Z; + + io.RenderDrawListsFn = ImImpl_RenderDrawLists; + io.SetClipboardTextFn = ImImpl_SetClipboardTextFn; + io.GetClipboardTextFn = ImImpl_GetClipboardTextFn; + + // Load font texture + glGenTextures(1, &fontTex); + glBindTexture(GL_TEXTURE_2D, fontTex); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + const void* png_data; + unsigned int png_size; + ImGui::GetDefaultFontData(NULL, NULL, &png_data, &png_size); + int tex_x, tex_y, tex_comp; + void* tex_data = stbi_load_from_memory((const unsigned char*)png_data, (int)png_size, &tex_x, &tex_y, &tex_comp, 0); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tex_x, tex_y, 0, GL_RGBA, GL_UNSIGNED_BYTE, tex_data); + stbi_image_free(tex_data); +} + +void UpdateImGui() +{ + ImGuiIO& io = ImGui::GetIO(); + + // Setup timestep + static double time = 0.0f; + const double current_time = glfwGetTime(); + io.DeltaTime = (float)(current_time - time); + time = current_time; + + // Setup inputs + // (we already got mouse wheel, keyboard keys & characters from glfw callbacks polled in glfwPollEvents()) + double mouse_x, mouse_y; + glfwGetCursorPos(window, &mouse_x, &mouse_y); + io.MousePos = ImVec2((float)mouse_x, (float)mouse_y); // Mouse position, in pixels (set to -1,-1 if no mouse / on another screen, etc.) + io.MouseDown[0] = glfwGetMouseButton(window, GLFW_MOUSE_BUTTON_LEFT) != 0; + io.MouseDown[1] = glfwGetMouseButton(window, GLFW_MOUSE_BUTTON_RIGHT) != 0; + + // Start the frame + ImGui::NewFrame(); +} + +// Application code +int main(int argc, char** argv) +{ + InitGL(); + InitImGui(); + + while (!glfwWindowShouldClose(window)) + { + ImGuiIO& io = ImGui::GetIO(); + io.MouseWheel = 0; + glfwPollEvents(); + UpdateImGui(); + + // Create a simple window + // Tip: if we don't call ImGui::Begin()/ImGui::End() the widgets appears in a window automatically called "Debug" + static bool show_test_window = true; + static bool show_another_window = false; + static float f; + ImGui::Text("Hello, world!"); + ImGui::SliderFloat("float", &f, 0.0f, 1.0f); + show_test_window ^= ImGui::Button("Test Window"); + show_another_window ^= ImGui::Button("Another Window"); + + // Calculate and show framerate + static float ms_per_frame[120] = { 0 }; + static int ms_per_frame_idx = 0; + static float ms_per_frame_accum = 0.0f; + ms_per_frame_accum -= ms_per_frame[ms_per_frame_idx]; + ms_per_frame[ms_per_frame_idx] = ImGui::GetIO().DeltaTime * 1000.0f; + ms_per_frame_accum += ms_per_frame[ms_per_frame_idx]; + ms_per_frame_idx = (ms_per_frame_idx + 1) % 120; + const float ms_per_frame_avg = ms_per_frame_accum / 120; + ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", ms_per_frame_avg, 1000.0f / ms_per_frame_avg); + + // Show the ImGui test window + // Most of user example code is in ImGui::ShowTestWindow() + if (show_test_window) + { + ImGui::SetNewWindowDefaultPos(ImVec2(650, 20)); // Normally user code doesn't need/want to call it because positions are saved in .ini file anyway. Here we just want to make the demo initial state a bit more friendly! + ImGui::ShowTestWindow(&show_test_window); + } + + // Show another simple window + if (show_another_window) + { + ImGui::Begin("Another Window", &show_another_window, ImVec2(200,100)); + ImGui::Text("Hello"); + ImGui::End(); + } + + // Rendering + glViewport(0, 0, (int)io.DisplaySize.x, (int)io.DisplaySize.y); + glClearColor(0.8f, 0.6f, 0.6f, 1.0f); + glClear(GL_COLOR_BUFFER_BIT); + ImGui::Render(); + glfwSwapBuffers(window); + } + if (vao_handle) glDeleteVertexArrays(1, &vao_handle); + if (vbo_handle) glDeleteBuffers(1, &vbo_handle); + glDetachShader(shader_handle, vert_handle); + glDetachShader(shader_handle, frag_handle); + glDeleteShader(vert_handle); + glDeleteShader(frag_handle); + glDeleteProgram(shader_handle); + + ImGui::Shutdown(); + glfwTerminate(); + + return 0; +} \ No newline at end of file diff --git a/examples/opengl3_example/opengl3_example.vcxproj b/examples/opengl3_example/opengl3_example.vcxproj new file mode 100644 index 00000000..8ffd778a --- /dev/null +++ b/examples/opengl3_example/opengl3_example.vcxproj @@ -0,0 +1,85 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + + {4a1fb5ea-22f5-42a8-ab92-1d2df5d47fb9} + opengl3_example + + + + Application + true + MultiByte + + + Application + false + true + MultiByte + + + + + + + + + + + + + + + Level3 + Disabled + $(ProjectDir)..\opengl_example\glfw\include;$(ProjectDir)..\opengl_example\glew\include;%(AdditionalIncludeDirectories) + + + true + $(ProjectDir)..\opengl_example\glfw\lib-msvc100;$(ProjectDir)..\opengl_example\glew\lib\Release\Win32;%(AdditionalLibraryDirectories) + opengl32.lib;imm32.lib;glfw3.lib;glew32s.lib;%(AdditionalDependencies) + NotSet + + + + + Level3 + MaxSpeed + true + true + $(ProjectDir)..\opengl_example\glfw\include;$(ProjectDir)..\opengl_example\glew\include;%(AdditionalIncludeDirectories) + + + true + true + true + $(ProjectDir)..\opengl_example\glfw\lib-msvc100;$(ProjectDir)..\opengl_example\glew\lib\Release\Win32;%(AdditionalLibraryDirectories) + opengl32.lib;imm32.lib;glfw3.lib;glew32s.lib;%(AdditionalDependencies) + NotSet + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/examples/opengl3_example/opengl3_example.vcxproj.filters b/examples/opengl3_example/opengl3_example.vcxproj.filters new file mode 100644 index 00000000..d04ee241 --- /dev/null +++ b/examples/opengl3_example/opengl3_example.vcxproj.filters @@ -0,0 +1,36 @@ + + + + + {20b90ce4-7fcb-4731-b9a0-075f875de82d} + + + {f18ab499-84e1-499f-8eff-9754361e0e52} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + + + sources + + + imgui + + + + + imgui + + + imgui + + + imgui + + + + + imgui + + + \ No newline at end of file From 2f176033c65d8ce295e123ad08e400c25e382da4 Mon Sep 17 00:00:00 2001 From: Olivier Chatry Date: Wed, 3 Dec 2014 19:11:23 +0100 Subject: [PATCH 023/108] fixed indentation mix, removed some unused code, updated different callback using the example_opengl code. --- examples/opengl3_example/main.cpp | 214 ++++++++++++++---------------- 1 file changed, 96 insertions(+), 118 deletions(-) diff --git a/examples/opengl3_example/main.cpp b/examples/opengl3_example/main.cpp index 2be8a24f..6d5304fe 100644 --- a/examples/opengl3_example/main.cpp +++ b/examples/opengl3_example/main.cpp @@ -10,6 +10,9 @@ static GLFWwindow* window; static GLuint fontTex; +static bool mousePressed[2] = { false, false }; +static ImVec2 mousePosScale(1.0f, 1.0f); + //Shader variables static int shader_handle, vert_handle, frag_handle; @@ -19,34 +22,10 @@ static int position_location, uv_location, colour_location; //we are going to use the same vertex buffer for all rendering of imgui //so we need to use a large enough buffer as default. //the buffer will be resized if needed in the rendering code, but it is not a "free" operation. -static size_t vbo_max_size = 1000000; +static size_t vbo_max_size = 1000000; static unsigned int vbo_handle, vao_handle; -template -unsigned int stream(GLenum target, unsigned int vbo, unsigned int *vbo_cursor, unsigned int *vbo_size, T *start, int elementCount) -{ - unsigned int bytes = sizeof(T) *elementCount; - unsigned int aligned = bytes + bytes % 64; //align memory - - glBindBuffer(target, vbo); - //If there's not enough space left, orphan the buffer object, create a new one and start writing - if (vbo_cursor[0] + aligned > vbo_size[0]) - { - assert(aligned < vbo_size[0]); - glBufferData(target, vbo_size[0], NULL, GL_DYNAMIC_DRAW); - vbo_cursor[0] = 0; - } - - void* mapped = glMapBufferRange(target, vbo_cursor[0], aligned, GL_MAP_WRITE_BIT | GL_MAP_UNSYNCHRONIZED_BIT); - - memcpy(mapped, start, bytes); - vbo_cursor[0] += aligned; - - glUnmapBuffer(target); - return vbo_cursor[0] - aligned; //return the offset we use for glVertexAttribPointer call -} - // This is the main rendering function that you have to implement and provide to ImGui (via setting up 'RenderDrawListsFn' in the ImGuiIO structure) // If text or lines are blurry when integrating ImGui in your engine: // - try adjusting ImGui::GetIO().PixelCenterOffset to 0.0f or 0.5f @@ -58,9 +37,9 @@ static void ImImpl_RenderDrawLists(ImDrawList** const cmd_lists, int cmd_lists_c // Setup render state: alpha-blending enabled, no face culling, no depth testing, scissor enabled glEnable(GL_BLEND); - glBlendEquation(GL_FUNC_ADD); + glBlendEquation(GL_FUNC_ADD); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - glDisable(GL_CULL_FACE); + glDisable(GL_CULL_FACE); glDisable(GL_DEPTH_TEST); glEnable(GL_SCISSOR_TEST); @@ -71,46 +50,46 @@ static void ImImpl_RenderDrawLists(ImDrawList** const cmd_lists, int cmd_lists_c // Setup orthographic projection matrix const float width = ImGui::GetIO().DisplaySize.x; const float height = ImGui::GetIO().DisplaySize.y; - const float ortho_projection[4][4] = - { - { 2.0f/width, 0.0f, 0.0f, 0.0f }, - { 0.0f, 2.0f/-height, 0.0f, 0.0f }, - { 0.0f, 0.0f, -1.0f, 0.0f }, - { -1.0f, 1.0f, 0.0f, 1.0f }, - }; + const float ortho_projection[4][4] = + { + { 2.0f/width, 0.0f, 0.0f, 0.0f }, + { 0.0f, 2.0f/-height, 0.0f, 0.0f }, + { 0.0f, 0.0f, -1.0f, 0.0f }, + { -1.0f, 1.0f, 0.0f, 1.0f }, + }; glUseProgram(shader_handle); glUniform1i(texture_location, 0); glUniformMatrix4fv(ortho_location, 1, GL_FALSE, &ortho_projection[0][0]); - // we will update the buffer in full, so we need to compute the total size of the buffer. - size_t total_vtx_count = 0; - for (int n = 0; n < cmd_lists_count; n++) - total_vtx_count += cmd_lists[n]->vtx_buffer.size(); - - glBindBuffer(GL_ARRAY_BUFFER, vbo_handle); - size_t neededBufferSize = total_vtx_count * sizeof(ImDrawVert); - if (neededBufferSize > vbo_max_size) - { - vbo_max_size = neededBufferSize; - glBufferData(GL_ARRAY_BUFFER, total_vtx_count * sizeof(ImDrawVert), NULL, GL_STREAM_DRAW); - } + // we will update the buffer in full, so we need to compute the total size of the buffer. + size_t total_vtx_count = 0; + for (int n = 0; n < cmd_lists_count; n++) + total_vtx_count += cmd_lists[n]->vtx_buffer.size(); - unsigned char* buffer_data = (unsigned char*)glMapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY); - if (!buffer_data) - return; - for (int n = 0; n < cmd_lists_count; n++) - { - const ImDrawList* cmd_list = cmd_lists[n]; - memcpy(buffer_data, &cmd_list->vtx_buffer[0], cmd_list->vtx_buffer.size() * sizeof(ImDrawVert)); - buffer_data += cmd_list->vtx_buffer.size() * sizeof(ImDrawVert); - } - glUnmapBuffer(GL_ARRAY_BUFFER); - glBindBuffer(GL_ARRAY_BUFFER, 0); + glBindBuffer(GL_ARRAY_BUFFER, vbo_handle); + size_t neededBufferSize = total_vtx_count * sizeof(ImDrawVert); + if (neededBufferSize > vbo_max_size) + { + vbo_max_size = neededBufferSize; + glBufferData(GL_ARRAY_BUFFER, total_vtx_count * sizeof(ImDrawVert), NULL, GL_STREAM_DRAW); + } - glBindVertexArray(vao_handle); - - int cmd_offset = 0; - for (int n = 0; n < cmd_lists_count; n++) + unsigned char* buffer_data = (unsigned char*)glMapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY); + if (!buffer_data) + return; + for (int n = 0; n < cmd_lists_count; n++) + { + const ImDrawList* cmd_list = cmd_lists[n]; + memcpy(buffer_data, &cmd_list->vtx_buffer[0], cmd_list->vtx_buffer.size() * sizeof(ImDrawVert)); + buffer_data += cmd_list->vtx_buffer.size() * sizeof(ImDrawVert); + } + glUnmapBuffer(GL_ARRAY_BUFFER); + glBindBuffer(GL_ARRAY_BUFFER, 0); + + glBindVertexArray(vao_handle); + + int cmd_offset = 0; + for (int n = 0; n < cmd_lists_count; n++) { const ImDrawList* cmd_list = cmd_lists[n]; int vtx_offset = cmd_offset; @@ -121,13 +100,13 @@ static void ImImpl_RenderDrawLists(ImDrawList** const cmd_lists, int cmd_lists_c glDrawArrays(GL_TRIANGLES, vtx_offset, pcmd->vtx_count); vtx_offset += pcmd->vtx_count; } - cmd_offset = vtx_offset; + cmd_offset = vtx_offset; } - glBindVertexArray(0); - glUseProgram(0); + glBindVertexArray(0); + glUseProgram(0); glDisable(GL_SCISSOR_TEST); - glBindTexture(GL_TEXTURE_2D, 0); + glBindTexture(GL_TEXTURE_2D, 0); } @@ -147,10 +126,16 @@ static void glfw_error_callback(int error, const char* description) fputs(description, stderr); } +static void glfw_mouse_button_callback(GLFWwindow* window, int button, int action, int mods) +{ + if (action == GLFW_PRESS && button >= 0 && button < 2) + mousePressed[button] = true; +} + static void glfw_scroll_callback(GLFWwindow* window, double xoffset, double yoffset) { ImGuiIO& io = ImGui::GetIO(); - io.MouseWheel = (yoffset != 0.0f) ? yoffset > 0.0f ? 1.0f : -1.0f : 0.0f; // Mouse wheel: -1,0,+1 + io.MouseWheel += (float)yoffset; // Use fractional mouse wheel, 1.0 unit 5 lines. } static void glfw_key_callback(GLFWwindow* window, int key, int scancode, int action, int mods) @@ -166,8 +151,8 @@ static void glfw_key_callback(GLFWwindow* window, int key, int scancode, int act static void glfw_char_callback(GLFWwindow* window, unsigned int c) { - if (c > 0 && c <= 255) - ImGui::GetIO().AddInputCharacter((char)c); + if (c > 0 && c < 0x10000) + ImGui::GetIO().AddInputCharacter((unsigned short)c); } @@ -182,7 +167,7 @@ void InitGL() glfwWindowHint(GLFW_RESIZABLE, GL_FALSE); glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); - glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); + glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); window = glfwCreateWindow(1280, 720, "ImGui OpenGL example", NULL, NULL); glfwMakeContextCurrent(window); @@ -190,49 +175,42 @@ void InitGL() glfwSetScrollCallback(window, glfw_scroll_callback); glfwSetCharCallback(window, glfw_char_callback); - glewExperimental = GL_TRUE; - - GLenum err = glewInit(); - if (GLEW_OK != err) - { - fprintf(stderr, "Error: %s\n", glewGetErrorString(err)); - } + glewExperimental = GL_TRUE; - const GLchar *vertex_shader = \ - "#version 330\n" - "uniform mat4 ortho;\n" + GLenum err = glewInit(); + if (GLEW_OK != err) + { + fprintf(stderr, "Error: %s\n", glewGetErrorString(err)); + } - "in vec2 Position;\n" - "in vec2 UV;\n" - "in vec4 Colour;\n" + const GLchar *vertex_shader = \ + "#version 330\n" + "uniform mat4 ortho;\n" + "in vec2 Position;\n" + "in vec2 UV;\n" + "in vec4 Colour;\n" + "out vec2 Frag_UV;\n" + "out vec4 Frag_Colour;\n" + "void main()\n" + "{\n" + " Frag_UV = UV;\n" + " Frag_Colour = Colour;\n" + " gl_Position = ortho*vec4(Position.xy,0,1);\n" + "}\n"; - "out vec2 Frag_UV;\n" - "out vec4 Frag_Colour;\n" + const GLchar* fragment_shader = \ + "#version 330\n" + "uniform sampler2D Texture;\n" + "in vec2 Frag_UV;\n" + "in vec4 Frag_Colour;\n" + "out vec4 FragColor;\n" + "void main()\n" + "{\n" + " FragColor = Frag_Colour * texture( Texture, Frag_UV.st);\n" + "}\n"; - "void main()\n" - "{\n" - " Frag_UV = UV;\n" - " Frag_Colour = Colour;\n" - "\n" - " gl_Position = ortho*vec4(Position.xy,0,1);\n" - "}\n"; - - const GLchar* fragment_shader = \ - "#version 330\n" - "uniform sampler2D Texture;\n" - - "in vec2 Frag_UV;\n" - "in vec4 Frag_Colour;\n" - - "out vec4 FragColor;\n" - - "void main()\n" - "{\n" - " FragColor = Frag_Colour * texture( Texture, Frag_UV.st);\n" - "}\n"; - - shader_handle = glCreateProgram(); - vert_handle = glCreateShader(GL_VERTEX_SHADER); + shader_handle = glCreateProgram(); + vert_handle = glCreateShader(GL_VERTEX_SHADER); frag_handle = glCreateShader(GL_FRAGMENT_SHADER); glShaderSource(vert_handle, 1, &vertex_shader, 0); glShaderSource(frag_handle, 1, &fragment_shader, 0); @@ -252,19 +230,19 @@ void InitGL() glBindBuffer(GL_ARRAY_BUFFER, vbo_handle); glBufferData(GL_ARRAY_BUFFER, vbo_max_size, NULL, GL_DYNAMIC_DRAW); - glGenVertexArrays(1, &vao_handle); - glBindVertexArray(vao_handle); - glBindBuffer(GL_ARRAY_BUFFER, vbo_handle); + glGenVertexArrays(1, &vao_handle); + glBindVertexArray(vao_handle); + glBindBuffer(GL_ARRAY_BUFFER, vbo_handle); glEnableVertexAttribArray(position_location); glEnableVertexAttribArray(uv_location); glEnableVertexAttribArray(colour_location); - glVertexAttribPointer(position_location, 2, GL_FLOAT, GL_FALSE, sizeof(ImDrawVert), (GLvoid*) offsetof(ImDrawVert, pos)); - glVertexAttribPointer(uv_location, 2, GL_FLOAT, GL_FALSE, sizeof(ImDrawVert), (GLvoid*) offsetof(ImDrawVert, uv)); - glVertexAttribPointer(colour_location, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(ImDrawVert), (GLvoid*) offsetof(ImDrawVert, col)); - glBindVertexArray(0); - glBindBuffer(GL_ARRAY_BUFFER, 0); - + glVertexAttribPointer(position_location, 2, GL_FLOAT, GL_FALSE, sizeof(ImDrawVert), (GLvoid*) offsetof(ImDrawVert, pos)); + glVertexAttribPointer(uv_location, 2, GL_FLOAT, GL_FALSE, sizeof(ImDrawVert), (GLvoid*) offsetof(ImDrawVert, uv)); + glVertexAttribPointer(colour_location, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(ImDrawVert), (GLvoid*) offsetof(ImDrawVert, col)); + glBindVertexArray(0); + glBindBuffer(GL_ARRAY_BUFFER, 0); + } @@ -392,7 +370,7 @@ int main(int argc, char** argv) ImGui::Render(); glfwSwapBuffers(window); } - if (vao_handle) glDeleteVertexArrays(1, &vao_handle); + if (vao_handle) glDeleteVertexArrays(1, &vao_handle); if (vbo_handle) glDeleteBuffers(1, &vbo_handle); glDetachShader(shader_handle, vert_handle); glDetachShader(shader_handle, frag_handle); From 860cf578f502cc566572b2a45207a0e5626a58bb Mon Sep 17 00:00:00 2001 From: omar Date: Wed, 3 Dec 2014 16:54:04 +0000 Subject: [PATCH 024/108] Added ImGuiWindowFlags_NoScrollWithMouse flag. ButtonBehaviour test hovering of CurrentRootWindow (vs CurrentWindow, different for child-windows). This is intentionally meant to fix grabbing the lower-right resize grip when lower-right corner has a child-window, but may be the overall right-er test. Testing out. --- imgui.cpp | 39 +++++++++++++++++++++++++++------------ imgui.h | 15 ++++++++------- 2 files changed, 35 insertions(+), 19 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 08787b2c..8d46c4ca 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -1,4 +1,4 @@ -// ImGui library v1.17 wip +// ImGui library v1.18 wip // See ImGui::ShowTestWindow() for sample code. // Read 'Programmer guide' below for notes on how to setup ImGui in your codebase. // Get latest version at https://github.com/ocornut/imgui @@ -757,7 +757,7 @@ struct ImGuiState ImVector CurrentWindowStack; ImGuiWindow* FocusedWindow; // Will catch keyboard inputs ImGuiWindow* HoveredWindow; // Will catch mouse inputs - ImGuiWindow* HoveredWindowExcludingChilds; // Will catch mouse inputs (for focus/move only) + ImGuiWindow* HoveredRootWindow; // Will catch mouse inputs (for focus/move only) ImGuiID HoveredId; ImGuiID ActiveId; ImGuiID ActiveIdPreviousFrame; @@ -794,7 +794,7 @@ struct ImGuiState CurrentWindow = NULL; FocusedWindow = NULL; HoveredWindow = NULL; - HoveredWindowExcludingChilds = NULL; + HoveredRootWindow = NULL; ActiveIdIsAlive = false; SettingsDirtyTimer = 0.0f; NewWindowDefaultPos = ImVec2(60, 60); @@ -837,8 +837,9 @@ struct ImGuiWindow int LastFrameDrawn; float ItemWidthDefault; ImGuiStorage StateStorage; - float FontWindowScale; // Scale multipler per-window + float FontWindowScale; // Scale multiplier per-window ImDrawList* DrawList; + ImGuiWindow* RootWindow; // Focus int FocusIdxAllCounter; // Start at -1 and increase as assigned via FocusItemRegister() @@ -1445,7 +1446,7 @@ void ImGui::NewFrame() } g.HoveredWindow = FindHoveredWindow(g.IO.MousePos, false); - g.HoveredWindowExcludingChilds = FindHoveredWindow(g.IO.MousePos, true); + g.HoveredRootWindow = FindHoveredWindow(g.IO.MousePos, true); // Are we using inputs? Tell user so they can capture/discard them. g.IO.WantCaptureMouse = (g.HoveredWindow != NULL) || (g.ActiveId != 0); @@ -1474,8 +1475,11 @@ void ImGui::NewFrame() else { // Scroll - const int scroll_lines = (window->Flags & ImGuiWindowFlags_ComboBox) ? 3 : 5; - window->NextScrollY -= g.IO.MouseWheel * window->FontSize() * scroll_lines; + if (!(window->Flags & ImGuiWindowFlags_NoScrollWithMouse)) + { + const int scroll_lines = (window->Flags & ImGuiWindowFlags_ComboBox) ? 3 : 5; + window->NextScrollY -= g.IO.MouseWheel * window->FontSize() * scroll_lines; + } } } @@ -1521,7 +1525,7 @@ void ImGui::Shutdown() g.RenderDrawLists.clear(); g.FocusedWindow = NULL; g.HoveredWindow = NULL; - g.HoveredWindowExcludingChilds = NULL; + g.HoveredRootWindow = NULL; for (size_t i = 0; i < g.Settings.size(); i++) { g.Settings[i]->~ImGuiIniData(); @@ -2128,6 +2132,16 @@ bool ImGui::Begin(const char* name, bool* open, ImVec2 size, float fill_alpha, I g.CurrentWindowStack.push_back(window); g.CurrentWindow = window; + // Find root + size_t root_idx = g.CurrentWindowStack.size() - 1; + while (root_idx > 0) + { + if ((g.CurrentWindowStack[root_idx]->Flags & ImGuiWindowFlags_ChildWindow) == 0) + break; + root_idx--; + } + window->RootWindow = g.CurrentWindowStack[root_idx]; + // Default alpha if (fill_alpha < 0.0f) fill_alpha = style.WindowFillAlphaDefault; @@ -2282,7 +2296,7 @@ bool ImGui::Begin(const char* name, bool* open, ImVec2 size, float fill_alpha, I const ImVec2 size_auto_fit = ImClamp(window->SizeContentsFit + style.AutoFitPadding, style.WindowMinSize, g.IO.DisplaySize - style.AutoFitPadding); if ((window->Flags & ImGuiWindowFlags_AlwaysAutoResize) != 0) { - // Don't continously mark settings as dirty, the size of the window doesn't need to be stored. + // Don't continuously mark settings as dirty, the size of the window doesn't need to be stored. window->SizeFull = size_auto_fit; } else if (window->AutoFitFrames > 0) @@ -2298,7 +2312,7 @@ bool ImGui::Begin(const char* name, bool* open, ImVec2 size, float fill_alpha, I { // Resize grip const ImGuiAabb resize_aabb(window->Aabb().GetBR()-ImVec2(18,18), window->Aabb().GetBR()); - const ImGuiID resize_id = window->GetID("#RESIZE"); + const ImGuiID resize_id = window->GetID("##RESIZE"); bool hovered, held; ButtonBehaviour(resize_aabb, resize_id, &hovered, &held, true); resize_col = window->Color(held ? ImGuiCol_ResizeGripActive : hovered ? ImGuiCol_ResizeGripHovered : ImGuiCol_ResizeGrip); @@ -2506,7 +2520,7 @@ void ImGui::End() // Select window for move/focus when we're done with all our widgets (we only consider non-childs windows here) const ImGuiAabb bb(window->Pos, window->Pos+window->Size); - if (g.ActiveId == 0 && g.HoveredId == 0 && g.HoveredWindowExcludingChilds == window && IsMouseHoveringBox(bb) && g.IO.MouseClicked[0]) + if (g.ActiveId == 0 && g.HoveredId == 0 && g.HoveredRootWindow == window && IsMouseHoveringBox(bb) && g.IO.MouseClicked[0]) g.ActiveId = window->GetID("#MOVE"); // Stop logging @@ -2532,6 +2546,7 @@ void ImGui::End() } // Pop + window->RootWindow = NULL; g.CurrentWindowStack.pop_back(); g.CurrentWindow = g.CurrentWindowStack.empty() ? NULL : g.CurrentWindowStack.back(); } @@ -3113,7 +3128,7 @@ static bool ButtonBehaviour(const ImGuiAabb& bb, const ImGuiID& id, bool* out_ho ImGuiState& g = GImGui; ImGuiWindow* window = GetCurrentWindow(); - const bool hovered = (g.HoveredWindow == window) && (g.HoveredId == 0) && IsMouseHoveringBox(bb); + const bool hovered = (g.HoveredRootWindow == window->RootWindow) && (g.HoveredId == 0) && IsMouseHoveringBox(bb); bool pressed = false; if (hovered) { diff --git a/imgui.h b/imgui.h index f749a189..84f3532e 100644 --- a/imgui.h +++ b/imgui.h @@ -1,4 +1,4 @@ -// ImGui library v1.17 wip +// ImGui library v1.18 wip // See .cpp file for commentary. // See ImGui::ShowTestWindow() for sample code. // Read 'Programmer guide' in .cpp for notes on how to setup ImGui in your codebase. @@ -308,12 +308,13 @@ enum ImGuiWindowFlags_ ImGuiWindowFlags_NoResize = 1 << 2, ImGuiWindowFlags_NoMove = 1 << 3, ImGuiWindowFlags_NoScrollbar = 1 << 4, - ImGuiWindowFlags_AlwaysAutoResize = 1 << 5, - ImGuiWindowFlags_ChildWindow = 1 << 6, // For internal use by BeginChild() - ImGuiWindowFlags_ChildWindowAutoFitX = 1 << 7, // For internal use by BeginChild() - ImGuiWindowFlags_ChildWindowAutoFitY = 1 << 8, // For internal use by BeginChild() - ImGuiWindowFlags_ComboBox = 1 << 9, // For internal use by ComboBox() - ImGuiWindowFlags_Tooltip = 1 << 10 // For internal use by Render() when using Tooltip + ImGuiWindowFlags_NoScrollWithMouse = 1 << 5, + ImGuiWindowFlags_AlwaysAutoResize = 1 << 6, + ImGuiWindowFlags_ChildWindow = 1 << 7, // For internal use by BeginChild() + ImGuiWindowFlags_ChildWindowAutoFitX = 1 << 8, // For internal use by BeginChild() + ImGuiWindowFlags_ChildWindowAutoFitY = 1 << 9, // For internal use by BeginChild() + ImGuiWindowFlags_ComboBox = 1 << 10, // For internal use by ComboBox() + ImGuiWindowFlags_Tooltip = 1 << 11 // For internal use by Render() when using Tooltip }; // Flags for ImGui::InputText() From 6c9edb6db08c311ac640f6eb33333625f412ada8 Mon Sep 17 00:00:00 2001 From: omar Date: Wed, 3 Dec 2014 18:19:05 +0000 Subject: [PATCH 025/108] Examples: removed LICENSE file from MSVC project. --- .../directx11_example.vcxproj | 3 --- .../directx11_example.vcxproj.filters | 5 ----- .../directx9_example/directx9_example.vcxproj | 9 -------- .../directx9_example.vcxproj.filters | 22 ------------------- .../opengl3_example/opengl3_example.vcxproj | 3 --- .../opengl3_example.vcxproj.filters | 5 ----- .../opengl_example/opengl_example.vcxproj | 3 --- .../opengl_example.vcxproj.filters | 5 ----- 8 files changed, 55 deletions(-) diff --git a/examples/directx11_example/directx11_example.vcxproj b/examples/directx11_example/directx11_example.vcxproj index 324a14e4..06114202 100644 --- a/examples/directx11_example/directx11_example.vcxproj +++ b/examples/directx11_example/directx11_example.vcxproj @@ -75,9 +75,6 @@ - - - diff --git a/examples/directx11_example/directx11_example.vcxproj.filters b/examples/directx11_example/directx11_example.vcxproj.filters index 19429f4c..8fc7b4d5 100644 --- a/examples/directx11_example/directx11_example.vcxproj.filters +++ b/examples/directx11_example/directx11_example.vcxproj.filters @@ -30,9 +30,4 @@ sources - - - imgui - - \ No newline at end of file diff --git a/examples/directx9_example/directx9_example.vcxproj b/examples/directx9_example/directx9_example.vcxproj index 60b70700..512d86e1 100644 --- a/examples/directx9_example/directx9_example.vcxproj +++ b/examples/directx9_example/directx9_example.vcxproj @@ -70,17 +70,8 @@ - - - - - - - - - diff --git a/examples/directx9_example/directx9_example.vcxproj.filters b/examples/directx9_example/directx9_example.vcxproj.filters index e400dde2..f18cb00d 100644 --- a/examples/directx9_example/directx9_example.vcxproj.filters +++ b/examples/directx9_example/directx9_example.vcxproj.filters @@ -1,9 +1,6 @@  - - {ac86c4ce-1d96-47a9-9ace-f8970c3bd485} - {4FC737F1-C7A5-4376-A066-2A32D752A2FF} cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx @@ -13,24 +10,5 @@ sources - - imgui - - - - - imgui - - - imgui - - - imgui - - - - - imgui - \ No newline at end of file diff --git a/examples/opengl3_example/opengl3_example.vcxproj b/examples/opengl3_example/opengl3_example.vcxproj index 8ffd778a..657b9e1b 100644 --- a/examples/opengl3_example/opengl3_example.vcxproj +++ b/examples/opengl3_example/opengl3_example.vcxproj @@ -76,9 +76,6 @@ - - - diff --git a/examples/opengl3_example/opengl3_example.vcxproj.filters b/examples/opengl3_example/opengl3_example.vcxproj.filters index d04ee241..f5668ce5 100644 --- a/examples/opengl3_example/opengl3_example.vcxproj.filters +++ b/examples/opengl3_example/opengl3_example.vcxproj.filters @@ -28,9 +28,4 @@ imgui - - - imgui - - \ No newline at end of file diff --git a/examples/opengl_example/opengl_example.vcxproj b/examples/opengl_example/opengl_example.vcxproj index 4dc74d37..8c1898d6 100644 --- a/examples/opengl_example/opengl_example.vcxproj +++ b/examples/opengl_example/opengl_example.vcxproj @@ -77,9 +77,6 @@ - - - diff --git a/examples/opengl_example/opengl_example.vcxproj.filters b/examples/opengl_example/opengl_example.vcxproj.filters index baab0575..69a481e2 100644 --- a/examples/opengl_example/opengl_example.vcxproj.filters +++ b/examples/opengl_example/opengl_example.vcxproj.filters @@ -31,9 +31,4 @@ sources - - - imgui - - \ No newline at end of file From 90b4ff13fb4780ef116007f6f01c08623682611c Mon Sep 17 00:00:00 2001 From: omar Date: Wed, 3 Dec 2014 18:19:48 +0000 Subject: [PATCH 026/108] Ignore list. --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index 9c09a7cb..cc09676f 100644 --- a/.gitignore +++ b/.gitignore @@ -11,6 +11,9 @@ examples/directx11_example/ipch/* examples/opengl_example/Debug/* examples/opengl_example/Release/* examples/opengl_example/ipch/* +examples/opengl3_example/Debug/* +examples/opengl3_example/Release/* +examples/opengl3_example/ipch/* *.opensdf *.sdf *.suo From b02eed3e4963c6ba337fd286dc3a2e2496dd8678 Mon Sep 17 00:00:00 2001 From: omar Date: Wed, 3 Dec 2014 18:29:46 +0000 Subject: [PATCH 027/108] Examples: adding title to the top of each examples. Cleaning up file headers. --- examples/directx11_example/main.cpp | 2 ++ .../directx9_example/directx9_example.vcxproj | 6 ++++++ .../directx9_example.vcxproj.filters | 17 ++++++++++++++++ examples/directx9_example/main.cpp | 2 ++ examples/opengl3_example/main.cpp | 20 +++++++++++-------- examples/opengl_example/main.cpp | 17 +++++++--------- 6 files changed, 46 insertions(+), 18 deletions(-) diff --git a/examples/directx11_example/main.cpp b/examples/directx11_example/main.cpp index bb24c73b..95b02920 100644 --- a/examples/directx11_example/main.cpp +++ b/examples/directx11_example/main.cpp @@ -1,3 +1,5 @@ +// ImGui - standalone example application for DirectX 11 + #include #define STB_IMAGE_IMPLEMENTATION #include "../shared/stb_image.h" // for .png loading diff --git a/examples/directx9_example/directx9_example.vcxproj b/examples/directx9_example/directx9_example.vcxproj index 512d86e1..5609b756 100644 --- a/examples/directx9_example/directx9_example.vcxproj +++ b/examples/directx9_example/directx9_example.vcxproj @@ -70,8 +70,14 @@ + + + + + + diff --git a/examples/directx9_example/directx9_example.vcxproj.filters b/examples/directx9_example/directx9_example.vcxproj.filters index f18cb00d..f39e1589 100644 --- a/examples/directx9_example/directx9_example.vcxproj.filters +++ b/examples/directx9_example/directx9_example.vcxproj.filters @@ -5,10 +5,27 @@ {4FC737F1-C7A5-4376-A066-2A32D752A2FF} cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + {a82cba23-9de0-45c2-b1e3-2eb1666702de} + sources + + imgui + + + + + imgui + + + imgui + + + imgui + \ No newline at end of file diff --git a/examples/directx9_example/main.cpp b/examples/directx9_example/main.cpp index dc86c3c0..9da31d2f 100644 --- a/examples/directx9_example/main.cpp +++ b/examples/directx9_example/main.cpp @@ -1,3 +1,5 @@ +// ImGui - standalone example application for DirectX 9 + #include #include "../../imgui.h" diff --git a/examples/opengl3_example/main.cpp b/examples/opengl3_example/main.cpp index 6d5304fe..e2f2442e 100644 --- a/examples/opengl3_example/main.cpp +++ b/examples/opengl3_example/main.cpp @@ -1,19 +1,24 @@ -#define GLEW_STATIC -#include -#include -#define STB_IMAGE_IMPLEMENTATION -#include "../shared/stb_image.h" // for .png loading -#include "../../imgui.h" +// ImGui - standalone example application for OpenGL 3, using programmable pipeline + #ifdef _MSC_VER #pragma warning (disable: 4996) // 'This function or variable may be unsafe': strcpy, strdup, sprintf, vsnprintf, sscanf, fopen #endif +#include "../../imgui.h" +#define STB_IMAGE_IMPLEMENTATION +#include "../shared/stb_image.h" // stb_image.h for PNG loading + +// Glfw/Glew +#define GLEW_STATIC +#include +#include + static GLFWwindow* window; static GLuint fontTex; static bool mousePressed[2] = { false, false }; static ImVec2 mousePosScale(1.0f, 1.0f); -//Shader variables +// Shader variables static int shader_handle, vert_handle, frag_handle; static int texture_location, ortho_location; @@ -25,7 +30,6 @@ static int position_location, uv_location, colour_location; static size_t vbo_max_size = 1000000; static unsigned int vbo_handle, vao_handle; - // This is the main rendering function that you have to implement and provide to ImGui (via setting up 'RenderDrawListsFn' in the ImGuiIO structure) // If text or lines are blurry when integrating ImGui in your engine: // - try adjusting ImGui::GetIO().PixelCenterOffset to 0.0f or 0.5f diff --git a/examples/opengl_example/main.cpp b/examples/opengl_example/main.cpp index 61a9f369..32ca0b9f 100644 --- a/examples/opengl_example/main.cpp +++ b/examples/opengl_example/main.cpp @@ -1,20 +1,17 @@ +// ImGui - standalone example application for OpenGL 2, using fixed pipeline + #ifdef _MSC_VER #pragma warning (disable: 4996) // 'This function or variable may be unsafe': strcpy, strdup, sprintf, vsnprintf, sscanf, fopen -#include #endif -#define STB_IMAGE_IMPLEMENTATION -#include "../shared/stb_image.h" // for .png loading -#include "../../imgui.h" -// glew & glfw +#include "../../imgui.h" +#define STB_IMAGE_IMPLEMENTATION +#include "../shared/stb_image.h" // stb_image.h for PNG loading + +// Glfw/Glew #define GLEW_STATIC #include #include -#ifdef _MSC_VER -#define GLFW_EXPOSE_NATIVE_WIN32 -#define GLFW_EXPOSE_NATIVE_WGL -#include -#endif static GLFWwindow* window; static GLuint fontTex; From 52b5376d9ba3b05b7bf6922404fc9065890ea4d6 Mon Sep 17 00:00:00 2001 From: omar Date: Wed, 3 Dec 2014 18:40:28 +0000 Subject: [PATCH 028/108] Examples: OpenGL3: cleaned up to match features of OpenGL2 example --- examples/opengl3_example/main.cpp | 165 +++++++++++++++--------------- examples/opengl_example/main.cpp | 4 +- 2 files changed, 84 insertions(+), 85 deletions(-) diff --git a/examples/opengl3_example/main.cpp b/examples/opengl3_example/main.cpp index e2f2442e..21e959ac 100644 --- a/examples/opengl3_example/main.cpp +++ b/examples/opengl3_example/main.cpp @@ -20,14 +20,9 @@ static ImVec2 mousePosScale(1.0f, 1.0f); // Shader variables static int shader_handle, vert_handle, frag_handle; - static int texture_location, ortho_location; static int position_location, uv_location, colour_location; -//streaming vbo -//we are going to use the same vertex buffer for all rendering of imgui -//so we need to use a large enough buffer as default. -//the buffer will be resized if needed in the rendering code, but it is not a "free" operation. -static size_t vbo_max_size = 1000000; +static size_t vbo_max_size = 20000; static unsigned int vbo_handle, vao_handle; // This is the main rendering function that you have to implement and provide to ImGui (via setting up 'RenderDrawListsFn' in the ImGuiIO structure) @@ -65,19 +60,19 @@ static void ImImpl_RenderDrawLists(ImDrawList** const cmd_lists, int cmd_lists_c glUniform1i(texture_location, 0); glUniformMatrix4fv(ortho_location, 1, GL_FALSE, &ortho_projection[0][0]); - // we will update the buffer in full, so we need to compute the total size of the buffer. + // Grow our buffer according to what we need size_t total_vtx_count = 0; for (int n = 0; n < cmd_lists_count; n++) total_vtx_count += cmd_lists[n]->vtx_buffer.size(); - glBindBuffer(GL_ARRAY_BUFFER, vbo_handle); size_t neededBufferSize = total_vtx_count * sizeof(ImDrawVert); if (neededBufferSize > vbo_max_size) { - vbo_max_size = neededBufferSize; - glBufferData(GL_ARRAY_BUFFER, total_vtx_count * sizeof(ImDrawVert), NULL, GL_STREAM_DRAW); + vbo_max_size = neededBufferSize + 5000; // Grow buffer + glBufferData(GL_ARRAY_BUFFER, neededBufferSize, NULL, GL_STREAM_DRAW); } + // Copy and convert all vertices into a single contiguous buffer unsigned char* buffer_data = (unsigned char*)glMapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY); if (!buffer_data) return; @@ -89,7 +84,6 @@ static void ImImpl_RenderDrawLists(ImDrawList** const cmd_lists, int cmd_lists_c } glUnmapBuffer(GL_ARRAY_BUFFER); glBindBuffer(GL_ARRAY_BUFFER, 0); - glBindVertexArray(vao_handle); int cmd_offset = 0; @@ -107,11 +101,11 @@ static void ImImpl_RenderDrawLists(ImDrawList** const cmd_lists, int cmd_lists_c cmd_offset = vtx_offset; } + // Restore modified state glBindVertexArray(0); glUseProgram(0); glDisable(GL_SCISSOR_TEST); glBindTexture(GL_TEXTURE_2D, 0); - } static const char* ImImpl_GetClipboardTextFn() @@ -159,7 +153,6 @@ static void glfw_char_callback(GLFWwindow* window, unsigned int c) ImGui::GetIO().AddInputCharacter((unsigned short)c); } - // OpenGL code based on http://open.gl tutorials void InitGL() { @@ -183,35 +176,33 @@ void InitGL() GLenum err = glewInit(); if (GLEW_OK != err) - { fprintf(stderr, "Error: %s\n", glewGetErrorString(err)); - } - const GLchar *vertex_shader = \ - "#version 330\n" - "uniform mat4 ortho;\n" - "in vec2 Position;\n" - "in vec2 UV;\n" - "in vec4 Colour;\n" - "out vec2 Frag_UV;\n" - "out vec4 Frag_Colour;\n" - "void main()\n" - "{\n" - " Frag_UV = UV;\n" - " Frag_Colour = Colour;\n" - " gl_Position = ortho*vec4(Position.xy,0,1);\n" - "}\n"; + const GLchar *vertex_shader = + "#version 330\n" + "uniform mat4 ortho;\n" + "in vec2 Position;\n" + "in vec2 UV;\n" + "in vec4 Colour;\n" + "out vec2 Frag_UV;\n" + "out vec4 Frag_Colour;\n" + "void main()\n" + "{\n" + " Frag_UV = UV;\n" + " Frag_Colour = Colour;\n" + " gl_Position = ortho*vec4(Position.xy,0,1);\n" + "}\n"; - const GLchar* fragment_shader = \ - "#version 330\n" - "uniform sampler2D Texture;\n" - "in vec2 Frag_UV;\n" - "in vec4 Frag_Colour;\n" - "out vec4 FragColor;\n" - "void main()\n" - "{\n" - " FragColor = Frag_Colour * texture( Texture, Frag_UV.st);\n" - "}\n"; + const GLchar* fragment_shader = + "#version 330\n" + "uniform sampler2D Texture;\n" + "in vec2 Frag_UV;\n" + "in vec4 Frag_Colour;\n" + "out vec4 FragColor;\n" + "void main()\n" + "{\n" + " FragColor = Frag_Colour * texture( Texture, Frag_UV.st);\n" + "}\n"; shader_handle = glCreateProgram(); vert_handle = glCreateShader(GL_VERTEX_SHADER); @@ -246,20 +237,22 @@ void InitGL() glVertexAttribPointer(colour_location, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(ImDrawVert), (GLvoid*) offsetof(ImDrawVert, col)); glBindVertexArray(0); glBindBuffer(GL_ARRAY_BUFFER, 0); - - } void InitImGui() { - int w, h; - glfwGetWindowSize(window, &w, &h); + int w, h; + int display_w, display_h; + glfwGetWindowSize(window, &w, &h); + glfwGetFramebufferSize(window, &display_w, &display_h); + mousePosScale.x = (float)display_w / w; // Some screens e.g. Retina display have framebuffer size != from window size, and mouse inputs are given in window/screen coordinates. + mousePosScale.y = (float)display_h / h; ImGuiIO& io = ImGui::GetIO(); - io.DisplaySize = ImVec2((float)w, (float)h); // Display size, in pixels. For clamping windows positions. - io.DeltaTime = 1.0f / 60.0f; // Time elapsed since last frame, in seconds (in this sample app we'll override this every frame because our timestep is variable) - io.PixelCenterOffset = 0.5f; // Align OpenGL texels - io.KeyMap[ImGuiKey_Tab] = GLFW_KEY_TAB; // Keyboard mapping. ImGui will use those indices to peek into the io.KeyDown[] array. + io.DisplaySize = ImVec2((float)display_w, (float)display_h); // Display size, in pixels. For clamping windows positions. + io.DeltaTime = 1.0f / 60.0f; // Time elapsed since last frame, in seconds (in this sample app we'll override this every frame because our timestep is variable) + io.PixelCenterOffset = 0.5f; // Align OpenGL texels + io.KeyMap[ImGuiKey_Tab] = GLFW_KEY_TAB; // Keyboard mapping. ImGui will use those indices to peek into the io.KeyDown[] array. io.KeyMap[ImGuiKey_LeftArrow] = GLFW_KEY_LEFT; io.KeyMap[ImGuiKey_RightArrow] = GLFW_KEY_RIGHT; io.KeyMap[ImGuiKey_UpArrow] = GLFW_KEY_UP; @@ -309,9 +302,9 @@ void UpdateImGui() // (we already got mouse wheel, keyboard keys & characters from glfw callbacks polled in glfwPollEvents()) double mouse_x, mouse_y; glfwGetCursorPos(window, &mouse_x, &mouse_y); - io.MousePos = ImVec2((float)mouse_x, (float)mouse_y); // Mouse position, in pixels (set to -1,-1 if no mouse / on another screen, etc.) - io.MouseDown[0] = glfwGetMouseButton(window, GLFW_MOUSE_BUTTON_LEFT) != 0; - io.MouseDown[1] = glfwGetMouseButton(window, GLFW_MOUSE_BUTTON_RIGHT) != 0; + io.MousePos = ImVec2((float)mouse_x * mousePosScale.x, (float)mouse_y * mousePosScale.y); // Mouse position, in pixels (set to -1,-1 if no mouse / on another screen, etc.) + io.MouseDown[0] = mousePressed[0] || glfwGetMouseButton(window, GLFW_MOUSE_BUTTON_LEFT) != 0; // If a mouse press event came, always pass it as "mouse held this frame", so we don't miss click-release events that are shorter than 1 frame. + io.MouseDown[1] = mousePressed[1] || glfwGetMouseButton(window, GLFW_MOUSE_BUTTON_RIGHT) != 0; // Start the frame ImGui::NewFrame(); @@ -330,50 +323,54 @@ int main(int argc, char** argv) glfwPollEvents(); UpdateImGui(); - // Create a simple window - // Tip: if we don't call ImGui::Begin()/ImGui::End() the widgets appears in a window automatically called "Debug" - static bool show_test_window = true; - static bool show_another_window = false; - static float f; - ImGui::Text("Hello, world!"); - ImGui::SliderFloat("float", &f, 0.0f, 1.0f); - show_test_window ^= ImGui::Button("Test Window"); - show_another_window ^= ImGui::Button("Another Window"); + static bool show_test_window = true; + static bool show_another_window = false; - // Calculate and show framerate - static float ms_per_frame[120] = { 0 }; - static int ms_per_frame_idx = 0; - static float ms_per_frame_accum = 0.0f; - ms_per_frame_accum -= ms_per_frame[ms_per_frame_idx]; - ms_per_frame[ms_per_frame_idx] = ImGui::GetIO().DeltaTime * 1000.0f; - ms_per_frame_accum += ms_per_frame[ms_per_frame_idx]; - ms_per_frame_idx = (ms_per_frame_idx + 1) % 120; - const float ms_per_frame_avg = ms_per_frame_accum / 120; - ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", ms_per_frame_avg, 1000.0f / ms_per_frame_avg); + // 1. Show a simple window + // Tip: if we don't call ImGui::Begin()/ImGui::End() the widgets appears in a window automatically called "Debug" + { + static float f; + ImGui::Text("Hello, world!"); + ImGui::SliderFloat("float", &f, 0.0f, 1.0f); + show_test_window ^= ImGui::Button("Test Window"); + show_another_window ^= ImGui::Button("Another Window"); - // Show the ImGui test window - // Most of user example code is in ImGui::ShowTestWindow() - if (show_test_window) - { - ImGui::SetNewWindowDefaultPos(ImVec2(650, 20)); // Normally user code doesn't need/want to call it because positions are saved in .ini file anyway. Here we just want to make the demo initial state a bit more friendly! - ImGui::ShowTestWindow(&show_test_window); - } + // Calculate and show frame rate + static float ms_per_frame[120] = { 0 }; + static int ms_per_frame_idx = 0; + static float ms_per_frame_accum = 0.0f; + ms_per_frame_accum -= ms_per_frame[ms_per_frame_idx]; + ms_per_frame[ms_per_frame_idx] = ImGui::GetIO().DeltaTime * 1000.0f; + ms_per_frame_accum += ms_per_frame[ms_per_frame_idx]; + ms_per_frame_idx = (ms_per_frame_idx + 1) % 120; + const float ms_per_frame_avg = ms_per_frame_accum / 120; + ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", ms_per_frame_avg, 1000.0f / ms_per_frame_avg); + } - // Show another simple window - if (show_another_window) - { - ImGui::Begin("Another Window", &show_another_window, ImVec2(200,100)); - ImGui::Text("Hello"); - ImGui::End(); - } + // 2. Show another simple window, this time using an explicit Begin/End pair + if (show_another_window) + { + ImGui::Begin("Another Window", &show_another_window, ImVec2(200,100)); + ImGui::Text("Hello"); + ImGui::End(); + } - // Rendering + // 3. Show the ImGui test window. Most of the sample code is in ImGui::ShowTestWindow() + if (show_test_window) + { + ImGui::SetNewWindowDefaultPos(ImVec2(650, 20)); // Normally user code doesn't need/want to call this, because positions are saved in .ini file. Here we just want to make the demo initial state a bit more friendly! + ImGui::ShowTestWindow(&show_test_window); + } + + // Rendering glViewport(0, 0, (int)io.DisplaySize.x, (int)io.DisplaySize.y); glClearColor(0.8f, 0.6f, 0.6f, 1.0f); glClear(GL_COLOR_BUFFER_BIT); ImGui::Render(); glfwSwapBuffers(window); } + + // Cleanup if (vao_handle) glDeleteVertexArrays(1, &vao_handle); if (vbo_handle) glDeleteBuffers(1, &vbo_handle); glDetachShader(shader_handle, vert_handle); diff --git a/examples/opengl_example/main.cpp b/examples/opengl_example/main.cpp index 32ca0b9f..6247f893 100644 --- a/examples/opengl_example/main.cpp +++ b/examples/opengl_example/main.cpp @@ -305,7 +305,9 @@ int main(int argc, char** argv) glfwSwapBuffers(window); } + // Cleanup ImGui::Shutdown(); glfwTerminate(); - return 0; + + return 0; } From 2e5b81627f3de9791d483240d3f8bc1599afc7bb Mon Sep 17 00:00:00 2001 From: omar Date: Wed, 3 Dec 2014 18:46:13 +0000 Subject: [PATCH 029/108] Examples: DirectX11: moved shader to be close to its usage location, --- examples/directx11_example/main.cpp | 91 +++++++++--------- examples/opengl3_example/main.cpp | 144 ++++++++++++++-------------- examples/opengl_example/main.cpp | 4 +- 3 files changed, 118 insertions(+), 121 deletions(-) diff --git a/examples/directx11_example/main.cpp b/examples/directx11_example/main.cpp index 95b02920..c6ec87f8 100644 --- a/examples/directx11_example/main.cpp +++ b/examples/directx11_example/main.cpp @@ -13,9 +13,6 @@ #pragma warning (disable: 4996) // 'This function or variable may be unsafe': strdup -extern const char* vertexShader; // Implemented at the bottom -extern const char* pixelShader; - static HWND hWnd; static ID3D11Device* g_pd3dDevice = NULL; static ID3D11DeviceContext* g_pd3dDeviceImmediateContext = NULL; @@ -222,6 +219,34 @@ HRESULT InitDeviceD3D(HWND hWnd) // Create the vertex shader { + static const char* vertexShader = + "cbuffer vertexBuffer : register(c0) \ + {\ + float4x4 ProjectionMatrix; \ + };\ + struct VS_INPUT\ + {\ + float2 pos : POSITION;\ + float4 col : COLOR0;\ + float2 uv : TEXCOORD0;\ + };\ + \ + struct PS_INPUT\ + {\ + float4 pos : SV_POSITION;\ + float4 col : COLOR0;\ + float2 uv : TEXCOORD0;\ + };\ + \ + PS_INPUT main(VS_INPUT input)\ + {\ + PS_INPUT output;\ + output.pos = mul( ProjectionMatrix, float4(input.pos.xy, 0.f, 1.f));\ + output.col = input.col;\ + output.uv = input.uv;\ + return output;\ + }"; + D3DCompile(vertexShader, strlen(vertexShader), NULL, NULL, NULL, "main", "vs_5_0", 0, 0, &g_pVertexShaderBlob, NULL); if (g_pVertexShaderBlob == NULL) // NB: Pass ID3D10Blob* pErrorBlob to D3DCompile() to get error showing in (const char*)pErrorBlob->GetBufferPointer(). Make sure to Release() the blob! return E_FAIL; @@ -252,6 +277,22 @@ HRESULT InitDeviceD3D(HWND hWnd) // Create the pixel shader { + static const char* pixelShader = + "struct PS_INPUT\ + {\ + float4 pos : SV_POSITION;\ + float4 col : COLOR0;\ + float2 uv : TEXCOORD0;\ + };\ + sampler sampler0;\ + Texture2D texture0;\ + \ + float4 main(PS_INPUT input) : SV_Target\ + {\ + float4 out_col = texture0.Sample(sampler0, input.uv);\ + return input.col * out_col;\ + }"; + D3DCompile(pixelShader, strlen(pixelShader), NULL, NULL, NULL, "main", "ps_5_0", 0, 0, &g_pPixelShaderBlob, NULL); if (g_pPixelShaderBlob == NULL) // NB: Pass ID3D10Blob* pErrorBlob to D3DCompile() to get error showing in (const char*)pErrorBlob->GetBufferPointer(). Make sure to Release() the blob! return E_FAIL; @@ -563,47 +604,3 @@ int WINAPI wWinMain(HINSTANCE hInst, HINSTANCE, LPWSTR, int) return 0; } - -static const char* vertexShader = "\ -cbuffer vertexBuffer : register(c0) \ -{\ - float4x4 ProjectionMatrix; \ -};\ -struct VS_INPUT\ -{\ - float2 pos : POSITION;\ - float4 col : COLOR0;\ - float2 uv : TEXCOORD0;\ -};\ -\ -struct PS_INPUT\ -{\ - float4 pos : SV_POSITION;\ - float4 col : COLOR0;\ - float2 uv : TEXCOORD0;\ -};\ -\ -PS_INPUT main(VS_INPUT input)\ -{\ - PS_INPUT output;\ - output.pos = mul( ProjectionMatrix, float4(input.pos.xy, 0.f, 1.f));\ - output.col = input.col;\ - output.uv = input.uv;\ - return output;\ -}"; - -static const char* pixelShader = "\ -struct PS_INPUT\ -{\ - float4 pos : SV_POSITION;\ - float4 col : COLOR0;\ - float2 uv : TEXCOORD0;\ -};\ -sampler sampler0;\ -Texture2D texture0;\ -\ -float4 main(PS_INPUT input) : SV_Target\ -{\ - float4 out_col = texture0.Sample(sampler0, input.uv);\ - return input.col * out_col;\ -}"; diff --git a/examples/opengl3_example/main.cpp b/examples/opengl3_example/main.cpp index 21e959ac..d1adae7b 100644 --- a/examples/opengl3_example/main.cpp +++ b/examples/opengl3_example/main.cpp @@ -60,7 +60,7 @@ static void ImImpl_RenderDrawLists(ImDrawList** const cmd_lists, int cmd_lists_c glUniform1i(texture_location, 0); glUniformMatrix4fv(ortho_location, 1, GL_FALSE, &ortho_projection[0][0]); - // Grow our buffer according to what we need + // Grow our buffer according to what we need size_t total_vtx_count = 0; for (int n = 0; n < cmd_lists_count; n++) total_vtx_count += cmd_lists[n]->vtx_buffer.size(); @@ -72,7 +72,7 @@ static void ImImpl_RenderDrawLists(ImDrawList** const cmd_lists, int cmd_lists_c glBufferData(GL_ARRAY_BUFFER, neededBufferSize, NULL, GL_STREAM_DRAW); } - // Copy and convert all vertices into a single contiguous buffer + // Copy and convert all vertices into a single contiguous buffer unsigned char* buffer_data = (unsigned char*)glMapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY); if (!buffer_data) return; @@ -101,7 +101,7 @@ static void ImImpl_RenderDrawLists(ImDrawList** const cmd_lists, int cmd_lists_c cmd_offset = vtx_offset; } - // Restore modified state + // Restore modified state glBindVertexArray(0); glUseProgram(0); glDisable(GL_SCISSOR_TEST); @@ -179,30 +179,30 @@ void InitGL() fprintf(stderr, "Error: %s\n", glewGetErrorString(err)); const GLchar *vertex_shader = - "#version 330\n" - "uniform mat4 ortho;\n" - "in vec2 Position;\n" - "in vec2 UV;\n" - "in vec4 Colour;\n" - "out vec2 Frag_UV;\n" - "out vec4 Frag_Colour;\n" - "void main()\n" - "{\n" - " Frag_UV = UV;\n" - " Frag_Colour = Colour;\n" - " gl_Position = ortho*vec4(Position.xy,0,1);\n" - "}\n"; + "#version 330\n" + "uniform mat4 ortho;\n" + "in vec2 Position;\n" + "in vec2 UV;\n" + "in vec4 Colour;\n" + "out vec2 Frag_UV;\n" + "out vec4 Frag_Colour;\n" + "void main()\n" + "{\n" + " Frag_UV = UV;\n" + " Frag_Colour = Colour;\n" + " gl_Position = ortho*vec4(Position.xy,0,1);\n" + "}\n"; const GLchar* fragment_shader = - "#version 330\n" - "uniform sampler2D Texture;\n" - "in vec2 Frag_UV;\n" - "in vec4 Frag_Colour;\n" - "out vec4 FragColor;\n" - "void main()\n" - "{\n" - " FragColor = Frag_Colour * texture( Texture, Frag_UV.st);\n" - "}\n"; + "#version 330\n" + "uniform sampler2D Texture;\n" + "in vec2 Frag_UV;\n" + "in vec4 Frag_Colour;\n" + "out vec4 FragColor;\n" + "void main()\n" + "{\n" + " FragColor = Frag_Colour * texture( Texture, Frag_UV.st);\n" + "}\n"; shader_handle = glCreateProgram(); vert_handle = glCreateShader(GL_VERTEX_SHADER); @@ -241,12 +241,12 @@ void InitGL() void InitImGui() { - int w, h; - int display_w, display_h; - glfwGetWindowSize(window, &w, &h); - glfwGetFramebufferSize(window, &display_w, &display_h); - mousePosScale.x = (float)display_w / w; // Some screens e.g. Retina display have framebuffer size != from window size, and mouse inputs are given in window/screen coordinates. - mousePosScale.y = (float)display_h / h; + int w, h; + int display_w, display_h; + glfwGetWindowSize(window, &w, &h); + glfwGetFramebufferSize(window, &display_w, &display_h); + mousePosScale.x = (float)display_w / w; // Some screens e.g. Retina display have framebuffer size != from window size, and mouse inputs are given in window/screen coordinates. + mousePosScale.y = (float)display_h / h; ImGuiIO& io = ImGui::GetIO(); io.DisplaySize = ImVec2((float)display_w, (float)display_h); // Display size, in pixels. For clamping windows positions. @@ -302,9 +302,9 @@ void UpdateImGui() // (we already got mouse wheel, keyboard keys & characters from glfw callbacks polled in glfwPollEvents()) double mouse_x, mouse_y; glfwGetCursorPos(window, &mouse_x, &mouse_y); - io.MousePos = ImVec2((float)mouse_x * mousePosScale.x, (float)mouse_y * mousePosScale.y); // Mouse position, in pixels (set to -1,-1 if no mouse / on another screen, etc.) - io.MouseDown[0] = mousePressed[0] || glfwGetMouseButton(window, GLFW_MOUSE_BUTTON_LEFT) != 0; // If a mouse press event came, always pass it as "mouse held this frame", so we don't miss click-release events that are shorter than 1 frame. - io.MouseDown[1] = mousePressed[1] || glfwGetMouseButton(window, GLFW_MOUSE_BUTTON_RIGHT) != 0; + io.MousePos = ImVec2((float)mouse_x * mousePosScale.x, (float)mouse_y * mousePosScale.y); // Mouse position, in pixels (set to -1,-1 if no mouse / on another screen, etc.) + io.MouseDown[0] = mousePressed[0] || glfwGetMouseButton(window, GLFW_MOUSE_BUTTON_LEFT) != 0; // If a mouse press event came, always pass it as "mouse held this frame", so we don't miss click-release events that are shorter than 1 frame. + io.MouseDown[1] = mousePressed[1] || glfwGetMouseButton(window, GLFW_MOUSE_BUTTON_RIGHT) != 0; // Start the frame ImGui::NewFrame(); @@ -323,46 +323,46 @@ int main(int argc, char** argv) glfwPollEvents(); UpdateImGui(); - static bool show_test_window = true; - static bool show_another_window = false; + static bool show_test_window = true; + static bool show_another_window = false; - // 1. Show a simple window - // Tip: if we don't call ImGui::Begin()/ImGui::End() the widgets appears in a window automatically called "Debug" - { - static float f; - ImGui::Text("Hello, world!"); - ImGui::SliderFloat("float", &f, 0.0f, 1.0f); - show_test_window ^= ImGui::Button("Test Window"); - show_another_window ^= ImGui::Button("Another Window"); + // 1. Show a simple window + // Tip: if we don't call ImGui::Begin()/ImGui::End() the widgets appears in a window automatically called "Debug" + { + static float f; + ImGui::Text("Hello, world!"); + ImGui::SliderFloat("float", &f, 0.0f, 1.0f); + show_test_window ^= ImGui::Button("Test Window"); + show_another_window ^= ImGui::Button("Another Window"); - // Calculate and show frame rate - static float ms_per_frame[120] = { 0 }; - static int ms_per_frame_idx = 0; - static float ms_per_frame_accum = 0.0f; - ms_per_frame_accum -= ms_per_frame[ms_per_frame_idx]; - ms_per_frame[ms_per_frame_idx] = ImGui::GetIO().DeltaTime * 1000.0f; - ms_per_frame_accum += ms_per_frame[ms_per_frame_idx]; - ms_per_frame_idx = (ms_per_frame_idx + 1) % 120; - const float ms_per_frame_avg = ms_per_frame_accum / 120; - ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", ms_per_frame_avg, 1000.0f / ms_per_frame_avg); - } + // Calculate and show frame rate + static float ms_per_frame[120] = { 0 }; + static int ms_per_frame_idx = 0; + static float ms_per_frame_accum = 0.0f; + ms_per_frame_accum -= ms_per_frame[ms_per_frame_idx]; + ms_per_frame[ms_per_frame_idx] = ImGui::GetIO().DeltaTime * 1000.0f; + ms_per_frame_accum += ms_per_frame[ms_per_frame_idx]; + ms_per_frame_idx = (ms_per_frame_idx + 1) % 120; + const float ms_per_frame_avg = ms_per_frame_accum / 120; + ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", ms_per_frame_avg, 1000.0f / ms_per_frame_avg); + } - // 2. Show another simple window, this time using an explicit Begin/End pair - if (show_another_window) - { - ImGui::Begin("Another Window", &show_another_window, ImVec2(200,100)); - ImGui::Text("Hello"); - ImGui::End(); - } + // 2. Show another simple window, this time using an explicit Begin/End pair + if (show_another_window) + { + ImGui::Begin("Another Window", &show_another_window, ImVec2(200,100)); + ImGui::Text("Hello"); + ImGui::End(); + } - // 3. Show the ImGui test window. Most of the sample code is in ImGui::ShowTestWindow() - if (show_test_window) - { - ImGui::SetNewWindowDefaultPos(ImVec2(650, 20)); // Normally user code doesn't need/want to call this, because positions are saved in .ini file. Here we just want to make the demo initial state a bit more friendly! - ImGui::ShowTestWindow(&show_test_window); - } - - // Rendering + // 3. Show the ImGui test window. Most of the sample code is in ImGui::ShowTestWindow() + if (show_test_window) + { + ImGui::SetNewWindowDefaultPos(ImVec2(650, 20)); // Normally user code doesn't need/want to call this, because positions are saved in .ini file. Here we just want to make the demo initial state a bit more friendly! + ImGui::ShowTestWindow(&show_test_window); + } + + // Rendering glViewport(0, 0, (int)io.DisplaySize.x, (int)io.DisplaySize.y); glClearColor(0.8f, 0.6f, 0.6f, 1.0f); glClear(GL_COLOR_BUFFER_BIT); @@ -370,7 +370,7 @@ int main(int argc, char** argv) glfwSwapBuffers(window); } - // Cleanup + // Cleanup if (vao_handle) glDeleteVertexArrays(1, &vao_handle); if (vbo_handle) glDeleteBuffers(1, &vbo_handle); glDetachShader(shader_handle, vert_handle); @@ -383,4 +383,4 @@ int main(int argc, char** argv) glfwTerminate(); return 0; -} \ No newline at end of file +} diff --git a/examples/opengl_example/main.cpp b/examples/opengl_example/main.cpp index 6247f893..db116123 100644 --- a/examples/opengl_example/main.cpp +++ b/examples/opengl_example/main.cpp @@ -305,9 +305,9 @@ int main(int argc, char** argv) glfwSwapBuffers(window); } - // Cleanup + // Cleanup ImGui::Shutdown(); glfwTerminate(); - return 0; + return 0; } From d13383190927fd2b8123cd57ab293df5dd479978 Mon Sep 17 00:00:00 2001 From: omar Date: Thu, 4 Dec 2014 11:42:13 +0000 Subject: [PATCH 030/108] In-code FAQ: added comment about reading WantCaptureMouse / WantCaptureKeyboard --- imgui.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/imgui.cpp b/imgui.cpp index 8d46c4ca..4d200bb8 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -36,6 +36,7 @@ - limited layout features, intricate layouts are typically crafted in code - occasionally use statically sized buffers for string manipulations - won't crash, but some long text may be clipped + END-USER GUIDE ============== @@ -58,6 +59,7 @@ - ESCAPE to revert text to its original value - You can apply arithmetic operators +,*,/ on numerical values. Use +- to subtract (because - would set a negative value!) + PROGRAMMER GUIDE ================ @@ -105,6 +107,10 @@ // swap video buffer, etc. } + - after calling ImGui::NewFrame() you can read back 'ImGui::GetIO().WantCaptureMouse' and 'ImGui::GetIO().WantCaptureKeyboard' to tell + if ImGui wants to use your inputs. so typically can hide the mouse inputs from the rest of your application if ImGui is using it. + + API BREAKING CHANGES ==================== @@ -122,6 +128,7 @@ - 2014/08/30 (1.09) moved IMGUI_FONT_TEX_UV_FOR_WHITE preprocessor define to IO.FontTexUvForWhite - 2014/08/28 (1.09) changed the behavior of IO.PixelCenterOffset following various rendering fixes + TROUBLESHOOTING & FREQUENTLY ASKED QUESTIONS ============================================ @@ -179,6 +186,7 @@ - tip: you can create widgets without a Begin()/End() block, they will go in an implicit window called "Debug" - tip: read the ShowTestWindow() code for more example of how to use ImGui! + ISSUES & TODO-LIST ================== From 6b16424faf74afc6d533f801fa3a87babc0cdccb Mon Sep 17 00:00:00 2001 From: omar Date: Thu, 4 Dec 2014 11:54:49 +0000 Subject: [PATCH 031/108] Comments. --- imgui.h | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/imgui.h b/imgui.h index 84f3532e..4281e55a 100644 --- a/imgui.h +++ b/imgui.h @@ -261,8 +261,7 @@ namespace ImGui IMGUI_API void TreePop(); IMGUI_API void OpenNextNode(bool open); // force open/close the next TreeNode or CollapsingHeader - // Value helper output "name: value" - // Freely declare your own in the ImGui namespace. + // Value helper output "name: value". tip: freely declare your own within the ImGui namespace! IMGUI_API void Value(const char* prefix, bool b); IMGUI_API void Value(const char* prefix, int v); IMGUI_API void Value(const char* prefix, unsigned int v); @@ -327,7 +326,7 @@ enum ImGuiInputTextFlags_ ImGuiInputTextFlags_EnterReturnsTrue = 1 << 3, // Return 'true' when Enter is pressed (as opposed to when the value was modified) ImGuiInputTextFlags_CallbackCompletion = 1 << 4, // Call user function on pressing TAB (for completion handling) ImGuiInputTextFlags_CallbackHistory = 1 << 5, // Call user function on pressing Up/Down arrows (for history handling) - ImGuiInputTextFlags_CallbackAlways = 1 << 6 // Call user function every frame + ImGuiInputTextFlags_CallbackAlways = 1 << 6 // Call user function every time //ImGuiInputTextFlags_AlignCenter = 1 << 6, }; @@ -450,8 +449,8 @@ struct ImGuiIO ImVec2 DisplaySize; // // Display size, in pixels. For clamping windows positions. float DeltaTime; // = 1.0f/60.0f // Time elapsed since last frame, in seconds. float IniSavingRate; // = 5.0f // Maximum time between saving .ini file, in seconds. Set to a negative value to disable .ini saving. - const char* IniFilename; // = "imgui.ini" // Absolute path to .ini file. - const char* LogFilename; // = "imgui_log.txt" // Absolute path to .log file. + const char* IniFilename; // = "imgui.ini" // Path to .ini file. + const char* LogFilename; // = "imgui_log.txt" // Path to .log file. float MouseDoubleClickTime; // = 0.30f // Time for a double-click, in seconds. float MouseDoubleClickMaxDist; // = 6.0f // Distance threshold to stay in to validate a double-click, in pixels. int KeyMap[ImGuiKey_COUNT]; // // Map of indices into the KeysDown[512] entries array @@ -480,7 +479,7 @@ struct ImGuiIO void* (*MemReallocFn)(void* ptr, size_t sz); void (*MemFreeFn)(void* ptr); - // Optional: notify OS Input Method Editor of text input position (e.g. when using Japanese/Chinese inputs, otherwise this isn't needed) + // Optional: notify OS Input Method Editor of the screen position of your cursor for text input position (e.g. when using Japanese/Chinese inputs in Windows) void (*ImeSetInputScreenPosFn)(int x, int y); //------------------------------------------------------------------ @@ -651,8 +650,8 @@ IMGUI_OVERRIDE_DRAWVERT_STRUCT_LAYOUT; #endif // Draw command list -// This is the low-level list of polygon that ImGui:: functions are filling. At the end of the frame, all command lists are passed to your ImGuiIO::RenderDrawListFn function for rendering. -// Each ImGui window contains its own ImDrawList. +// This is the low-level list of polygon that ImGui:: functions are creating. At the end of the frame, all command lists are passed to your ImGuiIO::RenderDrawListFn function for rendering. +// At the moment, each ImGui window contains its own ImDrawList but they could potentially be merged. // If you want to add custom rendering within a window, you can use ImGui::GetWindowDrawList() to access the current draw list and add your own primitives. // You can interleave normal ImGui:: calls and adding primitives to the current draw list. // Note that this only gives you access to rendering polygons. If your intent is to create custom widgets and the publicly exposed functions/data aren't sufficient, you can add code in imgui_user.inl @@ -686,7 +685,7 @@ struct ImDrawList IMGUI_API void AddText(ImFont* font, float font_size, const ImVec2& pos, ImU32 col, const char* text_begin, const char* text_end = NULL, float wrap_width = 0.0f); }; -// Optional bitmap font data loader & renderer into vertices +// Bitmap font data loader & renderer into vertices // Using the .fnt format exported by BMFont // - tool: http://www.angelcode.com/products/bmfont // - file-format: http://www.angelcode.com/products/bmfont/doc/file_format.html From a5cc2e4161e79b36823c44791c266a322ef471cc Mon Sep 17 00:00:00 2001 From: omar Date: Fri, 5 Dec 2014 12:34:14 +0000 Subject: [PATCH 032/108] Fixed InputInt() writing to output when it doesn't need to, which break with large int due to int<>float conversions. Added todo note. --- imgui.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 4d200bb8..63bc6619 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -201,7 +201,8 @@ - main: make IsHovered() info stored in a stack? so that 'if TreeNode() { Text; TreePop; } if IsHovered' return the hover state of the TreeNode? - scrollbar: use relative mouse movement when first-clicking inside of scroll grab box. - scrollbar: make the grab visible and a minimum size for long scroll regions - - input number: optional range min/max +!- input number: very large int not reliably supported because of int<>float conversions. + - input number: optional range min/max for Input*() functions - input number: holding [-]/[+] buttons should increase the step non-linearly - input number: use mouse wheel to step up/down - layout: clean up the InputFloatN/SliderFloatN/ColorEdit4 horrible layout code. item width should include frame padding, then we can have a generic horizontal layout helper. @@ -4341,7 +4342,8 @@ bool ImGui::InputInt(const char* label, int *v, int step, int step_fast, ImGuiIn { float f = (float)*v; const bool value_changed = ImGui::InputFloat(label, &f, (float)step, (float)step_fast, 0, extra_flags); - *v = (int)f; + if (value_changed) + *v = (int)f; return value_changed; } From e43cd6e97fccb9d8a21902f0bee4b67f2e11b039 Mon Sep 17 00:00:00 2001 From: ocornut Date: Fri, 5 Dec 2014 23:09:43 +0000 Subject: [PATCH 033/108] Added IMGUI_INCLUDE_IMGUI_USER_H --- imconfig.h | 3 +++ imgui.cpp | 3 ++- imgui.h | 7 +++++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/imconfig.h b/imconfig.h index e38c59cd..02e70da9 100644 --- a/imconfig.h +++ b/imconfig.h @@ -20,6 +20,9 @@ //---- Include imgui_user.inl at the end of imgui.cpp so you can include code that extends ImGui using its private data/functions. //#define IMGUI_INCLUDE_IMGUI_USER_INL +//---- Include imgui_user.h at the end of imgui.h +//#define IMGUI_INCLUDE_IMGUI_USER_H + //---- Define implicit cast operators to convert back<>forth from your math types and ImVec2/ImVec4. /* #define IM_VEC2_CLASS_EXTRA \ diff --git a/imgui.cpp b/imgui.cpp index 63bc6619..4db1a5b6 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -7559,7 +7559,8 @@ void ImGui::GetDefaultFontData(const void** fnt_data, unsigned int* fnt_size, co //----------------------------------------------------------------------------- -//---- Include imgui_user.inl at the end of imgui.cpp so you can include code that extends ImGui using its private data/functions. +//---- Include imgui_user.inl at the end of imgui.cpp +//---- So you can include code that extends ImGui using its private data/functions. #ifdef IMGUI_INCLUDE_IMGUI_USER_INL #include "imgui_user.inl" #endif diff --git a/imgui.h b/imgui.h index 4281e55a..6d050a3c 100644 --- a/imgui.h +++ b/imgui.h @@ -777,3 +777,10 @@ struct ImFont }; #pragma pack(pop) }; + +//---- Include imgui_user.h at the end of imgui.h +//---- So you can include code that extends ImGui using any of the types declared above. +//---- (also convenient for user to only explicitly include vanilla imgui.h) +#ifdef IMGUI_INCLUDE_IMGUI_USER_H +#include "imgui_user.h" +#endif From 317dab5269bc5c4fba2c68fc970d49e420009536 Mon Sep 17 00:00:00 2001 From: Daniel Collin Date: Sat, 6 Dec 2014 13:49:46 +0100 Subject: [PATCH 034/108] Clang warning fixes --- imgui.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 4db1a5b6..13c4de75 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -7188,7 +7188,7 @@ struct ExampleAppConsole const char* commands[] = { "HELP", "CLEAR", "CLASSIFY" }; ImVector candidates; for (size_t i = 0; i < IM_ARRAYSIZE(commands); i++) - if (ImStrnicmp(commands[i], word_start, word_end-word_start) == 0) + if (ImStrnicmp(commands[i], word_start, (int)(word_end-word_start)) == 0) candidates.push_back(commands[i]); if (candidates.size() == 0) @@ -7199,14 +7199,14 @@ struct ExampleAppConsole else if (candidates.size() == 1) { // Single match. Delete the beginning of the word and replace it entirely so we've got nice casing - data->DeleteChars(word_start-data->Buf, word_end-word_start); + data->DeleteChars((int)(word_start-data->Buf), (int)(word_end-word_start)); data->InsertChars(data->CursorPos, candidates[0]); data->InsertChars(data->CursorPos, " "); } else { // Multiple matches. Complete as much as we can, so inputing "C" will complete to "CL" and display "CLEAR" and "CLASSIFY" - int match_len = word_end - word_start; + int match_len = (int)(word_end - word_start); while (true) { int c = 0; @@ -7225,7 +7225,7 @@ struct ExampleAppConsole if (match_len > 0) { - data->DeleteChars(word_start - data->Buf, word_end-word_start); + data->DeleteChars((int)(word_start - data->Buf), (int)(word_end-word_start)); data->InsertChars(data->CursorPos, candidates[0], candidates[0] + match_len); } From 036ed3ea93583f5fd292fa155a9453e2d83867e5 Mon Sep 17 00:00:00 2001 From: ocornut Date: Sat, 6 Dec 2014 20:43:08 +0000 Subject: [PATCH 035/108] OpenGL3 example: unregistered mouse callback for mouse click-release faster than frame interval. --- examples/opengl3_example/main.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/opengl3_example/main.cpp b/examples/opengl3_example/main.cpp index d1adae7b..9ccc8ab6 100644 --- a/examples/opengl3_example/main.cpp +++ b/examples/opengl3_example/main.cpp @@ -169,6 +169,7 @@ void InitGL() window = glfwCreateWindow(1280, 720, "ImGui OpenGL example", NULL, NULL); glfwMakeContextCurrent(window); glfwSetKeyCallback(window, glfw_key_callback); + glfwSetMouseButtonCallback(window, glfw_mouse_button_callback); glfwSetScrollCallback(window, glfw_scroll_callback); glfwSetCharCallback(window, glfw_char_callback); From d553cd96b0b6a7f11cdda9c1396ec67726ee1732 Mon Sep 17 00:00:00 2001 From: ocornut Date: Sat, 6 Dec 2014 20:50:27 +0000 Subject: [PATCH 036/108] Setup Travis CI integration Testing. --- .travis.yml | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 00000000..90d0c9df --- /dev/null +++ b/.travis.yml @@ -0,0 +1,7 @@ +language: cpp +compiler: + - gcc + - clang +# Change this to your needs +script: cd examples/opengl_example && make + From 2b0d8447e33028a2b30a7d3901f39bcdd943942a Mon Sep 17 00:00:00 2001 From: ocornut Date: Sat, 6 Dec 2014 20:56:34 +0000 Subject: [PATCH 037/108] Setup Travis CI integration Testing --- .travis.yml | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 90d0c9df..e80c9fb9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,12 @@ language: cpp + compiler: - gcc - - clang -# Change this to your needs -script: cd examples/opengl_example && make + +before_install: + - apt-get update && apt-get install -y --no-install-recommends build-essential libglfw3-dev libglew-dev pkg-config libxrandr-dev libxi-dev + +script: + - cd examples/opengl_example && make + - cd examples/opengl3_example && make From 3e83de58b5f78841400be5abf30b06331c00d272 Mon Sep 17 00:00:00 2001 From: ocornut Date: Sat, 6 Dec 2014 20:59:14 +0000 Subject: [PATCH 038/108] Setup Travis CI integration --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index e80c9fb9..80cf9cc9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,7 +4,7 @@ compiler: - gcc before_install: - - apt-get update && apt-get install -y --no-install-recommends build-essential libglfw3-dev libglew-dev pkg-config libxrandr-dev libxi-dev + - if [ $TRAVIS_OS_NAME == linux ]; then sudo apt-get update && apt-get install -y --no-install-recommends libglfw3-dev libglew-dev; fi script: - cd examples/opengl_example && make From 83575a464fc821e42531cc446b680fff10448807 Mon Sep 17 00:00:00 2001 From: ocornut Date: Sat, 6 Dec 2014 21:01:00 +0000 Subject: [PATCH 039/108] Setup Travis CI integration Forgot sudo. Removing apt-get update, probably works without. --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 80cf9cc9..c9818933 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,7 +4,7 @@ compiler: - gcc before_install: - - if [ $TRAVIS_OS_NAME == linux ]; then sudo apt-get update && apt-get install -y --no-install-recommends libglfw3-dev libglew-dev; fi + - if [ $TRAVIS_OS_NAME == linux ]; then sudo apt-get install -y --no-install-recommends libglfw3-dev libglew-dev; fi script: - cd examples/opengl_example && make From 1bfb59174a83f1e91f4cb9d2607fa8af85cf60c8 Mon Sep 17 00:00:00 2001 From: ocornut Date: Sat, 6 Dec 2014 21:04:25 +0000 Subject: [PATCH 040/108] Setup Travis CI integration Apt-get update needed.. --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index c9818933..adf5c49c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,7 +4,7 @@ compiler: - gcc before_install: - - if [ $TRAVIS_OS_NAME == linux ]; then sudo apt-get install -y --no-install-recommends libglfw3-dev libglew-dev; fi + - if [ $TRAVIS_OS_NAME == linux ]; then sudo apt-get update -qq && apt-get install -y --no-install-recommends libglfw3-dev libglew-dev; fi script: - cd examples/opengl_example && make From 1d454786371160e0f25fd0562d54aeb3d156617f Mon Sep 17 00:00:00 2001 From: ocornut Date: Sat, 6 Dec 2014 21:06:00 +0000 Subject: [PATCH 041/108] Setup Travis CI integration Argh. --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index adf5c49c..180e7492 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,7 +4,7 @@ compiler: - gcc before_install: - - if [ $TRAVIS_OS_NAME == linux ]; then sudo apt-get update -qq && apt-get install -y --no-install-recommends libglfw3-dev libglew-dev; fi + - if [ $TRAVIS_OS_NAME == linux ]; then sudo apt-get update -qq && sudo apt-get install -y --no-install-recommends libglfw3-dev libglew-dev; fi script: - cd examples/opengl_example && make From 0687af2ce53ceeecc22332f8fbf0d013b834fd25 Mon Sep 17 00:00:00 2001 From: ocornut Date: Sat, 6 Dec 2014 23:01:41 +0000 Subject: [PATCH 042/108] Setup Travis CI integration Failing to get glfw3 for ubuntu, trying osx/gcc --- .travis.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.travis.yml b/.travis.yml index 180e7492..7fa9138c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,10 +1,14 @@ language: cpp +os: + - osx + compiler: - gcc before_install: - if [ $TRAVIS_OS_NAME == linux ]; then sudo apt-get update -qq && sudo apt-get install -y --no-install-recommends libglfw3-dev libglew-dev; fi + - if [ $TRAVIS_OS_NAME == osx ]; then brew update && brew install glew && brew install glfw3; fi script: - cd examples/opengl_example && make From da1b8f7e468750336b5366906eb4f15dcd67cc39 Mon Sep 17 00:00:00 2001 From: ocornut Date: Sat, 6 Dec 2014 23:06:04 +0000 Subject: [PATCH 043/108] Setup Travis CI integration Argh. --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 7fa9138c..3c7037f6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,6 +2,7 @@ language: cpp os: - osx +osx_image: xcode61 compiler: - gcc From 2599849e9c70e9a856f9d93bbf6e8bc2a28ca71c Mon Sep 17 00:00:00 2001 From: ocornut Date: Sat, 6 Dec 2014 23:17:30 +0000 Subject: [PATCH 044/108] Setup Travis CI integration Trying again with a PPA for glfw3-dev --- .travis.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 3c7037f6..6f7f1596 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,14 +1,13 @@ language: cpp os: - - osx -osx_image: xcode61 + - linux compiler: - gcc before_install: - - if [ $TRAVIS_OS_NAME == linux ]; then sudo apt-get update -qq && sudo apt-get install -y --no-install-recommends libglfw3-dev libglew-dev; fi + - if [ $TRAVIS_OS_NAME == linux ]; then sudo add-apt-repository ppa:keithw/glfw3 && sudo apt-get update -qq && sudo apt-get install -y --no-install-recommends libglfw3-dev libglew-dev; fi - if [ $TRAVIS_OS_NAME == osx ]; then brew update && brew install glew && brew install glfw3; fi script: From 857a4e364c786b2cfa73e0235f0293053f9e11bf Mon Sep 17 00:00:00 2001 From: ocornut Date: Sat, 6 Dec 2014 23:21:05 +0000 Subject: [PATCH 045/108] Setup Travis CI integration Yes please --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 6f7f1596..0a263dd5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,7 +7,7 @@ compiler: - gcc before_install: - - if [ $TRAVIS_OS_NAME == linux ]; then sudo add-apt-repository ppa:keithw/glfw3 && sudo apt-get update -qq && sudo apt-get install -y --no-install-recommends libglfw3-dev libglew-dev; fi + - if [ $TRAVIS_OS_NAME == linux ]; then sudo add-apt-repository -y ppa:keithw/glfw3 && sudo apt-get update -qq && sudo apt-get install -y --no-install-recommends libglfw3-dev libglew-dev; fi - if [ $TRAVIS_OS_NAME == osx ]; then brew update && brew install glew && brew install glfw3; fi script: From 2eb837ea8614d05d485aa072f0bbba0416dc54e9 Mon Sep 17 00:00:00 2001 From: ocornut Date: Sat, 6 Dec 2014 23:23:57 +0000 Subject: [PATCH 046/108] Setup Travis CI integration Different PPA source --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 0a263dd5..dc90688a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,7 +7,7 @@ compiler: - gcc before_install: - - if [ $TRAVIS_OS_NAME == linux ]; then sudo add-apt-repository -y ppa:keithw/glfw3 && sudo apt-get update -qq && sudo apt-get install -y --no-install-recommends libglfw3-dev libglew-dev; fi + - if [ $TRAVIS_OS_NAME == linux ]; then sudo add-apt-repository -y ppa:pyglfw/pyglfw && sudo apt-get update -qq && sudo apt-get install -y --no-install-recommends libglfw3-dev libglew-dev; fi - if [ $TRAVIS_OS_NAME == osx ]; then brew update && brew install glew && brew install glfw3; fi script: From fec067d033c3bd101f8d06eec85e3d1cf5aa3f96 Mon Sep 17 00:00:00 2001 From: ocornut Date: Sat, 6 Dec 2014 23:27:40 +0000 Subject: [PATCH 047/108] Setup Travis CI integration More libs needed --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index dc90688a..7f9f60de 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,7 +7,7 @@ compiler: - gcc before_install: - - if [ $TRAVIS_OS_NAME == linux ]; then sudo add-apt-repository -y ppa:pyglfw/pyglfw && sudo apt-get update -qq && sudo apt-get install -y --no-install-recommends libglfw3-dev libglew-dev; fi + - if [ $TRAVIS_OS_NAME == linux ]; then sudo add-apt-repository -y ppa:pyglfw/pyglfw && sudo apt-get update -qq && sudo apt-get install -y --no-install-recommends libglfw3-dev libglew-dev libxrandr-dev libxi-dev libxxf86vm-dev; fi - if [ $TRAVIS_OS_NAME == osx ]; then brew update && brew install glew && brew install glfw3; fi script: From bb20065be0c94a1bbd17873302ee662fad0a7228 Mon Sep 17 00:00:00 2001 From: ocornut Date: Sat, 6 Dec 2014 23:30:38 +0000 Subject: [PATCH 048/108] Setup Travis CI integration Getting there! --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 7f9f60de..eea77555 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,6 +11,6 @@ before_install: - if [ $TRAVIS_OS_NAME == osx ]; then brew update && brew install glew && brew install glfw3; fi script: - - cd examples/opengl_example && make - - cd examples/opengl3_example && make + - make -C examples/opengl_example + - make -C examples/opengl3_example From 71e20680dbe7686c9bb306399c50d73def316c1f Mon Sep 17 00:00:00 2001 From: ocornut Date: Sun, 7 Dec 2014 09:48:01 +0000 Subject: [PATCH 049/108] Setup Travis CI integration with Clang + -Wall in Makefiles --- .travis.yml | 1 + examples/opengl_example/Makefile | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index eea77555..cb1aba20 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,6 +5,7 @@ os: compiler: - gcc + - clang before_install: - if [ $TRAVIS_OS_NAME == linux ]; then sudo add-apt-repository -y ppa:pyglfw/pyglfw && sudo apt-get update -qq && sudo apt-get install -y --no-install-recommends libglfw3-dev libglew-dev libxrandr-dev libxi-dev libxxf86vm-dev; fi diff --git a/examples/opengl_example/Makefile b/examples/opengl_example/Makefile index 027fc151..df0e4ece 100644 --- a/examples/opengl_example/Makefile +++ b/examples/opengl_example/Makefile @@ -11,7 +11,7 @@ # http://www.glfw.org # -CXX = g++ +#CXX = g++ OBJS = main.o OBJS += ../../imgui.o @@ -22,6 +22,7 @@ UNAME_S := $(shell uname -s) ifeq ($(UNAME_S), Linux) #LINUX ECHO_MESSAGE = "Linux" CXXFLAGS = -I../../ `pkg-config --cflags glfw3` + CXXFLAGS += -Wall LIBS = `pkg-config --static --libs glfw3` -lGLEW endif @@ -32,11 +33,10 @@ ifeq ($(UNAME_S), Darwin) #APPLE LIBS += -L/usr/local/Cellar/glew/1.10.0/lib -L/usr/local/lib LIBS += -lglew -lglfw3 - CXXFLAGS = -I/usr/local/Cellar/glew/1.10.0/include -I/usr/local/include - CXXFLAGS += -I../../ + CXXFLAGS = -I../../ -I/usr/local/Cellar/glew/1.10.0/include -I/usr/local/include + CXXFLAGS += -Wall # CXXFLAGS += -D__APPLE__ - endif .cpp.o: From 987188d437efb14e65e5b90b467aac5c23940d05 Mon Sep 17 00:00:00 2001 From: ocornut Date: Sun, 7 Dec 2014 09:58:45 +0000 Subject: [PATCH 050/108] Fix Clang warning with offsetof() macro? Added -Wall in OpenGL 3 example. --- examples/opengl3_example/Makefile | 9 ++++----- examples/opengl3_example/main.cpp | 7 ++++--- examples/opengl_example/Makefile | 1 - examples/opengl_example/main.cpp | 7 ++++--- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/examples/opengl3_example/Makefile b/examples/opengl3_example/Makefile index 027fc151..ae08a231 100644 --- a/examples/opengl3_example/Makefile +++ b/examples/opengl3_example/Makefile @@ -11,7 +11,7 @@ # http://www.glfw.org # -CXX = g++ +#CXX = g++ OBJS = main.o OBJS += ../../imgui.o @@ -22,6 +22,7 @@ UNAME_S := $(shell uname -s) ifeq ($(UNAME_S), Linux) #LINUX ECHO_MESSAGE = "Linux" CXXFLAGS = -I../../ `pkg-config --cflags glfw3` + CXXFLAGS += -Wall LIBS = `pkg-config --static --libs glfw3` -lGLEW endif @@ -32,11 +33,9 @@ ifeq ($(UNAME_S), Darwin) #APPLE LIBS += -L/usr/local/Cellar/glew/1.10.0/lib -L/usr/local/lib LIBS += -lglew -lglfw3 - CXXFLAGS = -I/usr/local/Cellar/glew/1.10.0/include -I/usr/local/include - CXXFLAGS += -I../../ - + CXXFLAGS = -I../../ -I/usr/local/Cellar/glew/1.10.0/include -I/usr/local/include + CXXFLAGS += -Wall # CXXFLAGS += -D__APPLE__ - endif .cpp.o: diff --git a/examples/opengl3_example/main.cpp b/examples/opengl3_example/main.cpp index 9ccc8ab6..2ab11b08 100644 --- a/examples/opengl3_example/main.cpp +++ b/examples/opengl3_example/main.cpp @@ -12,6 +12,7 @@ #define GLEW_STATIC #include #include +#define OFFSETOF(TYPE, ELEMENT) ((size_t)&(((TYPE *)0)->ELEMENT)) static GLFWwindow* window; static GLuint fontTex; @@ -233,9 +234,9 @@ void InitGL() glEnableVertexAttribArray(uv_location); glEnableVertexAttribArray(colour_location); - glVertexAttribPointer(position_location, 2, GL_FLOAT, GL_FALSE, sizeof(ImDrawVert), (GLvoid*) offsetof(ImDrawVert, pos)); - glVertexAttribPointer(uv_location, 2, GL_FLOAT, GL_FALSE, sizeof(ImDrawVert), (GLvoid*) offsetof(ImDrawVert, uv)); - glVertexAttribPointer(colour_location, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(ImDrawVert), (GLvoid*) offsetof(ImDrawVert, col)); + glVertexAttribPointer(position_location, 2, GL_FLOAT, GL_FALSE, sizeof(ImDrawVert), (GLvoid*)OFFSETOF(ImDrawVert, pos)); + glVertexAttribPointer(uv_location, 2, GL_FLOAT, GL_FALSE, sizeof(ImDrawVert), (GLvoid*)OFFSETOF(ImDrawVert, uv)); + glVertexAttribPointer(colour_location, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(ImDrawVert), (GLvoid*)OFFSETOF(ImDrawVert, col)); glBindVertexArray(0); glBindBuffer(GL_ARRAY_BUFFER, 0); } diff --git a/examples/opengl_example/Makefile b/examples/opengl_example/Makefile index df0e4ece..ae08a231 100644 --- a/examples/opengl_example/Makefile +++ b/examples/opengl_example/Makefile @@ -35,7 +35,6 @@ ifeq ($(UNAME_S), Darwin) #APPLE CXXFLAGS = -I../../ -I/usr/local/Cellar/glew/1.10.0/include -I/usr/local/include CXXFLAGS += -Wall - # CXXFLAGS += -D__APPLE__ endif diff --git a/examples/opengl_example/main.cpp b/examples/opengl_example/main.cpp index db116123..eea14791 100644 --- a/examples/opengl_example/main.cpp +++ b/examples/opengl_example/main.cpp @@ -12,6 +12,7 @@ #define GLEW_STATIC #include #include +#define OFFSETOF(TYPE, ELEMENT) ((size_t)&(((TYPE *)0)->ELEMENT)) static GLFWwindow* window; static GLuint fontTex; @@ -60,9 +61,9 @@ static void ImImpl_RenderDrawLists(ImDrawList** const cmd_lists, int cmd_lists_c { const ImDrawList* cmd_list = cmd_lists[n]; const unsigned char* vtx_buffer = (const unsigned char*)&cmd_list->vtx_buffer.front(); - glVertexPointer(2, GL_FLOAT, sizeof(ImDrawVert), (void*)(vtx_buffer + offsetof(ImDrawVert, pos))); - glTexCoordPointer(2, GL_FLOAT, sizeof(ImDrawVert), (void*)(vtx_buffer + offsetof(ImDrawVert, uv))); - glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(ImDrawVert), (void*)(vtx_buffer + offsetof(ImDrawVert, col))); + glVertexPointer(2, GL_FLOAT, sizeof(ImDrawVert), (void*)(vtx_buffer + OFFSETOF(ImDrawVert, pos))); + glTexCoordPointer(2, GL_FLOAT, sizeof(ImDrawVert), (void*)(vtx_buffer + OFFSETOF(ImDrawVert, uv))); + glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(ImDrawVert), (void*)(vtx_buffer + OFFSETOF(ImDrawVert, col))); int vtx_offset = 0; for (size_t cmd_i = 0; cmd_i < cmd_list->commands.size(); cmd_i++) From 6252b26af26621a240076865acf3cf5a59ddf648 Mon Sep 17 00:00:00 2001 From: omar Date: Sun, 7 Dec 2014 10:15:34 +0000 Subject: [PATCH 051/108] Update README.md --- README.md | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 433f0a6d..0e9d800e 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,21 @@ ImGui ===== -ImGui is a bloat-free graphical user interface library for C++. It outputs vertex buffers that you can render in your 3D-pipeline enabled application. It is portable, renderer agnostic and carries minimal amount of dependencies (only 3 files are needed). It is based on an "immediate" graphical user interface paradigm which allows you to build user interfaces with ease. +ImGui is a bloat-free graphical user interface library for C++. It outputs vertex buffers that you can render in your 3D-pipeline enabled application. It is portable, renderer agnostic and carries minimal amount of dependencies. It is based on an "immediate" graphical user interface paradigm which allows you to build user interfaces with ease. ImGui is designed to enable fast iteration and allow programmers to create "content creation" or "debug" tools (as opposed to UI for the average end-user). It favors simplicity and productivity toward this goal, and thus lacks certain features normally found in more high-level libraries. ImGui is particularly suited to integration in 3D applications, fullscreen applications, embedded applications, games, or any applications on consoles platforms where operating system features are non-standard. -After ImGui is setup in your engine, you can use it like in this example: + +ImGui is self-contained within 4 files that you can easily copy and compile into your application/engine: + + - imgui.cpp + - imgui.h + - imconfig.h (empty by default, user-editable) + - stb_textedit.h + +Your code passes mouse/keyboard inputs and settings to ImGui (see example applications for more details). After ImGui is setup, you can use it like in this example: ![screenshot of sample code alongside its output with ImGui](/web/code_sample_01.png?raw=true) From 0a0769227d7c317cc35a51badbf0f6fd65f59954 Mon Sep 17 00:00:00 2001 From: omar Date: Sun, 7 Dec 2014 10:17:39 +0000 Subject: [PATCH 052/108] Added Travis CI build banner. --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 0e9d800e..3cdf22df 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,6 @@ ImGui ===== +[![Build Status](https://travis-ci.org/ocornut/imgui.svg?branch=master)](https://travis-ci.org/ocornut/imgui) ImGui is a bloat-free graphical user interface library for C++. It outputs vertex buffers that you can render in your 3D-pipeline enabled application. It is portable, renderer agnostic and carries minimal amount of dependencies. It is based on an "immediate" graphical user interface paradigm which allows you to build user interfaces with ease. From bdb2344db0587e65c03d220dfc907157369060b4 Mon Sep 17 00:00:00 2001 From: omar Date: Mon, 8 Dec 2014 17:14:54 +0000 Subject: [PATCH 053/108] ImGuiStorage helper can store float + added functions to get pointer to data. Exposed ImGui::GetId() - may be misleading? --- imgui.cpp | 72 +++++++++++++++++++++++++++++++++++++++---------------- imgui.h | 43 +++++++++++++++++++++++---------- 2 files changed, 83 insertions(+), 32 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 13c4de75..b08febe3 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -924,46 +924,66 @@ static ImVector::iterator LowerBound(ImVector::iterator it = LowerBound(const_cast&>(Data), key); + if (it == Data.end() || it->key != key) + return default_val; + return it->val_i; +} + +float ImGuiStorage::GetFloat(ImU32 key, float default_val) const +{ + ImVector::iterator it = LowerBound(const_cast&>(Data), key); + if (it == Data.end() || it->key != key) + return default_val; + return it->val_f; +} + +int* ImGuiStorage::GetIntPtr(ImGuiID key, int default_val) { ImVector::iterator it = LowerBound(Data, key); - if (it == Data.end()) - return NULL; - if (it->key != key) - return NULL; - return &it->val; + if (it == Data.end() || it->key != key) + it = Data.insert(it, Pair(key, default_val)); + return &it->val_i; } -int ImGuiStorage::GetInt(ImU32 key, int default_val) +float* ImGuiStorage::GetFloatPtr(ImGuiID key, float default_val) { - int* pval = Find(key); - if (!pval) - return default_val; - return *pval; + ImVector::iterator it = LowerBound(Data, key); + if (it == Data.end() || it->key != key) + it = Data.insert(it, Pair(key, default_val)); + return &it->val_f; } -// FIXME-OPT: We are wasting time because all SetInt() are preceeded by GetInt() calls so we should have the result from lower_bound already in place. +// FIXME-OPT: Wasting CPU because all SetInt() are preceeded by GetInt() calls so we should have the result from lower_bound already in place. // However we only use SetInt() on explicit user action (so that's maximum once a frame) so the optimisation isn't much needed. void ImGuiStorage::SetInt(ImU32 key, int val) { ImVector::iterator it = LowerBound(Data, key); - if (it != Data.end() && it->key == key) + if (it == Data.end() || it->key != key) { - it->val = val; + Data.insert(it, Pair(key, val)); + return; } - else + it->val_i = val; +} + +void ImGuiStorage::SetFloat(ImU32 key, float val) +{ + ImVector::iterator it = LowerBound(Data, key); + if (it == Data.end() || it->key != key) { - Pair pair_key; - pair_key.key = key; - pair_key.val = val; - Data.insert(it, pair_key); + Data.insert(it, Pair(key, val)); + return; } + it->val_f = val; } void ImGuiStorage::SetAllInt(int v) { for (size_t i = 0; i < Data.size(); i++) - Data[i].val = v; + Data[i].val_i = v; } //----------------------------------------------------------------------------- @@ -3550,6 +3570,18 @@ void ImGui::PopID() window->IDStack.pop_back(); } +ImGuiID ImGui::GetID(const char* str_id) +{ + ImGuiWindow* window = GetCurrentWindow(); + return window->GetID(str_id); +} + +ImGuiID ImGui::GetID(const void* ptr_id) +{ + ImGuiWindow* window = GetCurrentWindow(); + return window->GetID(ptr_id); +} + // User can input math operators (e.g. +100) to edit a numerical values. // NB: only call right after InputText because we are using its InitialValue storage static void ApplyNumericalTextInput(const char* buf, float *v) diff --git a/imgui.h b/imgui.h index 6d050a3c..df38958e 100644 --- a/imgui.h +++ b/imgui.h @@ -117,7 +117,7 @@ public: inline void pop_back() { IM_ASSERT(Size > 0); Size--; } inline iterator erase(const_iterator it) { IM_ASSERT(it >= begin() && it < end()); const ptrdiff_t off = it - begin(); memmove(Data + off, Data + off + 1, (Size - (size_t)off - 1) * sizeof(value_type)); Size--; return Data + off; } - inline void insert(const_iterator it, const value_type& v) { IM_ASSERT(it >= begin() && it <= end()); const ptrdiff_t off = it - begin(); if (Size == Capacity) reserve(Capacity ? Capacity * 2 : 4); if (off < (int)Size) memmove(Data + off + 1, Data + off, (Size - (size_t)off) * sizeof(value_type)); Data[off] = v; Size++; } + inline iterator insert(const_iterator it, const value_type& v) { IM_ASSERT(it >= begin() && it <= end()); const ptrdiff_t off = it - begin(); if (Size == Capacity) reserve(Capacity ? Capacity * 2 : 4); if (off < (int)Size) memmove(Data + off + 1, Data + off, (Size - (size_t)off) * sizeof(value_type)); Data[off] = v; Size++; return Data + off; } }; #endif // #ifndef ImVector @@ -204,10 +204,13 @@ namespace ImGui IMGUI_API float GetTextLineHeight(); // ID scopes - IMGUI_API void PushID(const char* str_id); + // If you are creating repeated widgets in a loop you most likely want to push a unique identifier so ImGui can differentiate them. + IMGUI_API void PushID(const char* str_id); // push identifier into the ID stack. IDs are hash of the *entire* stack! IMGUI_API void PushID(const void* ptr_id); IMGUI_API void PushID(const int int_id); IMGUI_API void PopID(); + IMGUI_API ImGuiID GetID(const char* str_id); // calculate unique ID (hash of whole ID stack + given parameter). useful if you want to query into ImGuiStorage yourself. otherwise rarely needed. + IMGUI_API ImGuiID GetID(const void* ptr_id); // Widgets IMGUI_API void Text(const char* fmt, ...); @@ -587,22 +590,38 @@ struct ImGuiTextBuffer }; // Helper: Key->value storage -// - Store collapse state for a tree -// - Store color edit options, etc. +// - Store collapse state for a tree (Int 0/1) +// - Store color edit options (Int using values in ImGuiColorEditMode enum). +// - Custom user storage for temporary values. // Typically you don't have to worry about this since a storage is held within each Window. -// Declare your own storage if you want to manipulate the open/close state of a particular sub-tree in your interface. +// Declare your own storage if: +// - You want to manipulate the open/close state of a particular sub-tree in your interface (tree node uses Int 0/1 to store their state). +// - You want to store custom debug data easily without adding or editing structures in your code. struct ImGuiStorage { - struct Pair { ImU32 key; int val; }; + struct Pair + { + ImGuiID key; + union { int val_i; float val_f; }; + Pair(ImGuiID _key, int _val_i) { key = _key; val_i = _val_i; } + Pair(ImGuiID _key, float _val_f) { key = _key; val_f = _val_f; } + }; ImVector Data; + // - Get***() functions find pair, never add/allocate. Pairs are sorted so a query is O(log N) + // - Set***() functions find pair, insertion on demand if missing. + // - Get***Ptr() functions find pair, insertion on demand if missing, return pointer. Useful if you intend to do Get+Set. + // A typical use case where this is very convenient: + // ImGui::SliderInt("tmp adjustment", GetIntPtr(key), 0, 100); some_var += *GetIntPtr(key); + // - Sorted insertion is costly but should amortize. A typical frame shouldn't need to insert any new pair. IMGUI_API void Clear(); - IMGUI_API int GetInt(ImU32 key, int default_val = 0); - IMGUI_API void SetInt(ImU32 key, int val); - IMGUI_API void SetAllInt(int val); - - IMGUI_API int* Find(ImU32 key); - IMGUI_API void Insert(ImU32 key, int val); + IMGUI_API int GetInt(ImGuiID key, int default_val = 0) const; + IMGUI_API void SetInt(ImGuiID key, int val); + IMGUI_API int* GetIntPtr(ImGuiID key, int default_val = 0); + IMGUI_API float GetFloat(ImGuiID key, float default_val = 0.0f) const; + IMGUI_API void SetFloat(ImGuiID key, float val); + IMGUI_API float* GetFloatPtr(ImGuiID key, float default_val = 0); + IMGUI_API void SetAllInt(int val); // Use on your own storage if you know only integer are being stored. }; // Shared state of InputText(), passed to callback when a ImGuiInputTextFlags_Callback* flag is used. From 6523fb263dae6368372a1bd905047750198f30aa Mon Sep 17 00:00:00 2001 From: omar Date: Mon, 8 Dec 2014 17:15:08 +0000 Subject: [PATCH 054/108] OpenGL3 example: fixed mouse handling. --- examples/opengl3_example/main.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/opengl3_example/main.cpp b/examples/opengl3_example/main.cpp index 2ab11b08..234940ba 100644 --- a/examples/opengl3_example/main.cpp +++ b/examples/opengl3_example/main.cpp @@ -322,6 +322,7 @@ int main(int argc, char** argv) { ImGuiIO& io = ImGui::GetIO(); io.MouseWheel = 0; + mousePressed[0] = mousePressed[1] = false; glfwPollEvents(); UpdateImGui(); From cca5f473ca6bd296b40d8150c55a1a0ae5d49396 Mon Sep 17 00:00:00 2001 From: omar Date: Mon, 8 Dec 2014 17:18:20 +0000 Subject: [PATCH 055/108] Clarified comment --- imgui.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/imgui.h b/imgui.h index df38958e..eec7d8c1 100644 --- a/imgui.h +++ b/imgui.h @@ -612,7 +612,7 @@ struct ImGuiStorage // - Set***() functions find pair, insertion on demand if missing. // - Get***Ptr() functions find pair, insertion on demand if missing, return pointer. Useful if you intend to do Get+Set. // A typical use case where this is very convenient: - // ImGui::SliderInt("tmp adjustment", GetIntPtr(key), 0, 100); some_var += *GetIntPtr(key); + // float* pvar = ImGui::GetIntPtr(key); ImGui::SliderInt("var", pvar, 0, 100); some_var += *pvar; // - Sorted insertion is costly but should amortize. A typical frame shouldn't need to insert any new pair. IMGUI_API void Clear(); IMGUI_API int GetInt(ImGuiID key, int default_val = 0) const; From 09bacfbe18700d9dea00fbd4218aefa5e9a16d56 Mon Sep 17 00:00:00 2001 From: omar Date: Wed, 10 Dec 2014 15:27:40 +0000 Subject: [PATCH 056/108] OpenGL example: allow resizing window. --- examples/opengl3_example/main.cpp | 23 +++++++++++------------ examples/opengl_example/main.cpp | 21 ++++++++++----------- 2 files changed, 21 insertions(+), 23 deletions(-) diff --git a/examples/opengl3_example/main.cpp b/examples/opengl3_example/main.cpp index 234940ba..41ef5221 100644 --- a/examples/opengl3_example/main.cpp +++ b/examples/opengl3_example/main.cpp @@ -17,7 +17,6 @@ static GLFWwindow* window; static GLuint fontTex; static bool mousePressed[2] = { false, false }; -static ImVec2 mousePosScale(1.0f, 1.0f); // Shader variables static int shader_handle, vert_handle, frag_handle; @@ -162,7 +161,6 @@ void InitGL() if (!glfwInit()) exit(1); - glfwWindowHint(GLFW_RESIZABLE, GL_FALSE); glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); @@ -243,15 +241,7 @@ void InitGL() void InitImGui() { - int w, h; - int display_w, display_h; - glfwGetWindowSize(window, &w, &h); - glfwGetFramebufferSize(window, &display_w, &display_h); - mousePosScale.x = (float)display_w / w; // Some screens e.g. Retina display have framebuffer size != from window size, and mouse inputs are given in window/screen coordinates. - mousePosScale.y = (float)display_h / h; - ImGuiIO& io = ImGui::GetIO(); - io.DisplaySize = ImVec2((float)display_w, (float)display_h); // Display size, in pixels. For clamping windows positions. io.DeltaTime = 1.0f / 60.0f; // Time elapsed since last frame, in seconds (in this sample app we'll override this every frame because our timestep is variable) io.PixelCenterOffset = 0.5f; // Align OpenGL texels io.KeyMap[ImGuiKey_Tab] = GLFW_KEY_TAB; // Keyboard mapping. ImGui will use those indices to peek into the io.KeyDown[] array. @@ -294,7 +284,14 @@ void UpdateImGui() { ImGuiIO& io = ImGui::GetIO(); - // Setup timestep + // Setup resolution (every frame to accommodate for window resizing) + int w, h; + int display_w, display_h; + glfwGetWindowSize(window, &w, &h); + glfwGetFramebufferSize(window, &display_w, &display_h); + io.DisplaySize = ImVec2((float)display_w, (float)display_h); // Display size, in pixels. For clamping windows positions. + + // Setup time step static double time = 0.0f; const double current_time = glfwGetTime(); io.DeltaTime = (float)(current_time - time); @@ -304,7 +301,9 @@ void UpdateImGui() // (we already got mouse wheel, keyboard keys & characters from glfw callbacks polled in glfwPollEvents()) double mouse_x, mouse_y; glfwGetCursorPos(window, &mouse_x, &mouse_y); - io.MousePos = ImVec2((float)mouse_x * mousePosScale.x, (float)mouse_y * mousePosScale.y); // Mouse position, in pixels (set to -1,-1 if no mouse / on another screen, etc.) + mouse_x *= (float)display_w / w; // Convert mouse coordinates to pixels + mouse_y *= (float)display_h / h; + io.MousePos = ImVec2((float)mouse_x, (float)mouse_y); // Mouse position, in pixels (set to -1,-1 if no mouse / on another screen, etc.) io.MouseDown[0] = mousePressed[0] || glfwGetMouseButton(window, GLFW_MOUSE_BUTTON_LEFT) != 0; // If a mouse press event came, always pass it as "mouse held this frame", so we don't miss click-release events that are shorter than 1 frame. io.MouseDown[1] = mousePressed[1] || glfwGetMouseButton(window, GLFW_MOUSE_BUTTON_RIGHT) != 0; diff --git a/examples/opengl_example/main.cpp b/examples/opengl_example/main.cpp index eea14791..069fc870 100644 --- a/examples/opengl_example/main.cpp +++ b/examples/opengl_example/main.cpp @@ -17,7 +17,6 @@ static GLFWwindow* window; static GLuint fontTex; static bool mousePressed[2] = { false, false }; -static ImVec2 mousePosScale(1.0f, 1.0f); // This is the main rendering function that you have to implement and provide to ImGui (via setting up 'RenderDrawListsFn' in the ImGuiIO structure) // If text or lines are blurry when integrating ImGui in your engine: @@ -140,7 +139,6 @@ void InitGL() if (!glfwInit()) exit(1); - glfwWindowHint(GLFW_RESIZABLE, GL_FALSE); window = glfwCreateWindow(1280, 720, "ImGui OpenGL example", NULL, NULL); glfwMakeContextCurrent(window); glfwSetKeyCallback(window, glfw_key_callback); @@ -153,15 +151,7 @@ void InitGL() void InitImGui() { - int w, h; - int display_w, display_h; - glfwGetWindowSize(window, &w, &h); - glfwGetFramebufferSize(window, &display_w, &display_h); - mousePosScale.x = (float)display_w / w; // Some screens e.g. Retina display have framebuffer size != from window size, and mouse inputs are given in window/screen coordinates. - mousePosScale.y = (float)display_h / h; - ImGuiIO& io = ImGui::GetIO(); - io.DisplaySize = ImVec2((float)display_w, (float)display_h); // Display size, in pixels. For clamping windows positions. io.DeltaTime = 1.0f/60.0f; // Time elapsed since last frame, in seconds (in this sample app we'll override this every frame because our time step is variable) io.PixelCenterOffset = 0.0f; // Align OpenGL texels io.KeyMap[ImGuiKey_Tab] = GLFW_KEY_TAB; // Keyboard mapping. ImGui will use those indices to peek into the io.KeyDown[] array. @@ -228,6 +218,13 @@ void UpdateImGui() { ImGuiIO& io = ImGui::GetIO(); + // Setup resolution (every frame to accommodate for window resizing) + int w, h; + int display_w, display_h; + glfwGetWindowSize(window, &w, &h); + glfwGetFramebufferSize(window, &display_w, &display_h); + io.DisplaySize = ImVec2((float)display_w, (float)display_h); // Display size, in pixels. For clamping windows positions. + // Setup time step static double time = 0.0f; const double current_time = glfwGetTime(); @@ -238,7 +235,9 @@ void UpdateImGui() // (we already got mouse wheel, keyboard keys & characters from glfw callbacks polled in glfwPollEvents()) double mouse_x, mouse_y; glfwGetCursorPos(window, &mouse_x, &mouse_y); - io.MousePos = ImVec2((float)mouse_x * mousePosScale.x, (float)mouse_y * mousePosScale.y); // Mouse position, in pixels (set to -1,-1 if no mouse / on another screen, etc.) + mouse_x *= (float)display_w / w; // Convert mouse coordinates to pixels + mouse_y *= (float)display_h / h; + io.MousePos = ImVec2((float)mouse_x, (float)mouse_y); // Mouse position, in pixels (set to -1,-1 if no mouse / on another screen, etc.) io.MouseDown[0] = mousePressed[0] || glfwGetMouseButton(window, GLFW_MOUSE_BUTTON_LEFT) != 0; // If a mouse press event came, always pass it as "mouse held this frame", so we don't miss click-release events that are shorter than 1 frame. io.MouseDown[1] = mousePressed[1] || glfwGetMouseButton(window, GLFW_MOUSE_BUTTON_RIGHT) != 0; From 2a3bff9a828185c3d37bb0de0a5b311c73c596c1 Mon Sep 17 00:00:00 2001 From: omar Date: Wed, 10 Dec 2014 16:56:11 +0000 Subject: [PATCH 057/108] Comments --- imgui.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/imgui.h b/imgui.h index eec7d8c1..42ad488f 100644 --- a/imgui.h +++ b/imgui.h @@ -451,9 +451,9 @@ struct ImGuiIO ImVec2 DisplaySize; // // Display size, in pixels. For clamping windows positions. float DeltaTime; // = 1.0f/60.0f // Time elapsed since last frame, in seconds. - float IniSavingRate; // = 5.0f // Maximum time between saving .ini file, in seconds. Set to a negative value to disable .ini saving. - const char* IniFilename; // = "imgui.ini" // Path to .ini file. - const char* LogFilename; // = "imgui_log.txt" // Path to .log file. + float IniSavingRate; // = 5.0f // Maximum time between saving .ini file, in seconds. + const char* IniFilename; // = "imgui.ini" // Path to .ini file. NULL to disable .ini saving. + const char* LogFilename; // = "imgui_log.txt" // Path to .log file (default parameter to ImGui::LogToFile when no file is specified). float MouseDoubleClickTime; // = 0.30f // Time for a double-click, in seconds. float MouseDoubleClickMaxDist; // = 6.0f // Distance threshold to stay in to validate a double-click, in pixels. int KeyMap[ImGuiKey_COUNT]; // // Map of indices into the KeysDown[512] entries array From 3399890a8499813162454c2d86706bb93c854892 Mon Sep 17 00:00:00 2001 From: omar Date: Wed, 10 Dec 2014 17:13:45 +0000 Subject: [PATCH 058/108] Added ImGuiWindowFlags_NoSavedSettings flag + Fixed overlay example app. --- imgui.cpp | 32 +++++++++++++++++++++++++++----- imgui.h | 11 ++++++----- 2 files changed, 33 insertions(+), 10 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index b08febe3..13303a27 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -1340,7 +1340,7 @@ static void SaveSettings() for (size_t i = 0; i != g.Windows.size(); i++) { ImGuiWindow* window = g.Windows[i]; - if (window->Flags & (ImGuiWindowFlags_ChildWindow | ImGuiWindowFlags_Tooltip)) + if (window->Flags & ImGuiWindowFlags_NoSavedSettings) continue; ImGuiIniData* settings = FindWindowSettings(window->Name); settings->Pos = window->Pos; @@ -2054,7 +2054,7 @@ static ImGuiWindow* FindWindow(const char* name) void ImGui::BeginTooltip() { - ImGui::Begin("##Tooltip", NULL, ImVec2(0,0), 0.9f, ImGuiWindowFlags_NoTitleBar|ImGuiWindowFlags_NoMove|ImGuiWindowFlags_NoResize|ImGuiWindowFlags_Tooltip); + ImGui::Begin("##Tooltip", NULL, ImVec2(0,0), 0.9f, ImGuiWindowFlags_NoTitleBar|ImGuiWindowFlags_NoMove|ImGuiWindowFlags_NoResize|ImGuiWindowFlags_NoSavedSettings|ImGuiWindowFlags_Tooltip); } void ImGui::EndTooltip() @@ -2068,7 +2068,7 @@ void ImGui::BeginChild(const char* str_id, ImVec2 size, bool border, ImGuiWindow ImGuiState& g = GImGui; ImGuiWindow* window = GetCurrentWindow(); - ImGuiWindowFlags flags = ImGuiWindowFlags_NoTitleBar|ImGuiWindowFlags_NoMove|ImGuiWindowFlags_NoResize|ImGuiWindowFlags_ChildWindow; + ImGuiWindowFlags flags = ImGuiWindowFlags_NoTitleBar|ImGuiWindowFlags_NoMove|ImGuiWindowFlags_NoResize|ImGuiWindowFlags_NoSavedSettings|ImGuiWindowFlags_ChildWindow; const ImVec2 content_max = window->Pos + ImGui::GetContentRegionMax(); const ImVec2 cursor_pos = window->Pos + ImGui::GetCursorPos(); @@ -2102,6 +2102,7 @@ void ImGui::EndChild() { ImGuiWindow* window = GetCurrentWindow(); + IM_ASSERT(window->Flags & ImGuiWindowFlags_ChildWindow); if (window->Flags & ImGuiWindowFlags_ComboBox) { ImGui::End(); @@ -2130,8 +2131,8 @@ bool ImGui::Begin(const char* name, bool* open, ImVec2 size, float fill_alpha, I ImGuiWindow* window = FindWindow(name); if (!window) { - // Create window the first time, and load settings - if (flags & (ImGuiWindowFlags_ChildWindow | ImGuiWindowFlags_Tooltip)) + // Create window the first time + if (flags & ImGuiWindowFlags_NoSavedSettings) { // Tooltip and child windows don't store settings window = (ImGuiWindow*)ImGui::MemAlloc(sizeof(ImGuiWindow)); @@ -6628,6 +6629,7 @@ void ImGui::ShowStyleEditor(ImGuiStyle* ref) static void ShowExampleAppConsole(bool* open); static void ShowExampleAppLongText(bool* open); static void ShowExampleAppAutoResize(bool* open); +static void ShowExampleAppFixedOverlay(bool* open); // Demonstrate ImGui features (unfortunately this makes this function a little bloated!) void ImGui::ShowTestWindow(bool* open) @@ -7139,11 +7141,13 @@ void ImGui::ShowTestWindow(bool* open) static bool show_app_console = false; static bool show_app_long_text = false; static bool show_app_auto_resize = false; + static bool show_app_fixed_overlay = false; if (ImGui::CollapsingHeader("App Examples")) { ImGui::Checkbox("Console", &show_app_console); ImGui::Checkbox("Long text display", &show_app_long_text); ImGui::Checkbox("Auto-resizing window", &show_app_auto_resize); + ImGui::Checkbox("Simple overlay", &show_app_fixed_overlay); } if (show_app_console) ShowExampleAppConsole(&show_app_console); @@ -7151,6 +7155,8 @@ void ImGui::ShowTestWindow(bool* open) ShowExampleAppLongText(&show_app_long_text); if (show_app_auto_resize) ShowExampleAppAutoResize(&show_app_auto_resize); + if (show_app_fixed_overlay) + ShowExampleAppFixedOverlay(&show_app_fixed_overlay); ImGui::End(); } @@ -7172,6 +7178,22 @@ static void ShowExampleAppAutoResize(bool* open) ImGui::End(); } +static void ShowExampleAppFixedOverlay(bool* open) +{ + if (!ImGui::Begin("Example: Fixed Overlay", open, ImVec2(0,0), 0.3f, ImGuiWindowFlags_NoTitleBar|ImGuiWindowFlags_NoResize|ImGuiWindowFlags_NoMove|ImGuiWindowFlags_NoSavedSettings)) + { + ImGui::End(); + return; + } + + ImGui::SetWindowPos(ImVec2(10,10)); + ImGui::Text("Simple overlay\non the top-left side of the screen."); + ImGui::Separator(); + ImGui::Text("Mouse Position: (%.1f,%.1f)", ImGui::GetIO().MousePos.x, ImGui::GetIO().MousePos.y); + + ImGui::End(); +} + struct ExampleAppConsole { ImVector Items; diff --git a/imgui.h b/imgui.h index 42ad488f..8ce585e3 100644 --- a/imgui.h +++ b/imgui.h @@ -312,11 +312,12 @@ enum ImGuiWindowFlags_ ImGuiWindowFlags_NoScrollbar = 1 << 4, ImGuiWindowFlags_NoScrollWithMouse = 1 << 5, ImGuiWindowFlags_AlwaysAutoResize = 1 << 6, - ImGuiWindowFlags_ChildWindow = 1 << 7, // For internal use by BeginChild() - ImGuiWindowFlags_ChildWindowAutoFitX = 1 << 8, // For internal use by BeginChild() - ImGuiWindowFlags_ChildWindowAutoFitY = 1 << 9, // For internal use by BeginChild() - ImGuiWindowFlags_ComboBox = 1 << 10, // For internal use by ComboBox() - ImGuiWindowFlags_Tooltip = 1 << 11 // For internal use by Render() when using Tooltip + ImGuiWindowFlags_NoSavedSettings = 1 << 7, // Never load/save settings in .ini file + ImGuiWindowFlags_ChildWindow = 1 << 8, // For internal use by BeginChild() + ImGuiWindowFlags_ChildWindowAutoFitX = 1 << 9, // For internal use by BeginChild() + ImGuiWindowFlags_ChildWindowAutoFitY = 1 << 10, // For internal use by BeginChild() + ImGuiWindowFlags_ComboBox = 1 << 11, // For internal use by ComboBox() + ImGuiWindowFlags_Tooltip = 1 << 12 // For internal use by Render() when using Tooltip }; // Flags for ImGui::InputText() From e9e0e36f988a12e0719b1e3b109dafac9fb4471f Mon Sep 17 00:00:00 2001 From: omar Date: Wed, 10 Dec 2014 19:22:30 +0000 Subject: [PATCH 059/108] New and better Set[Next]Window(Pos|Size|Collapsed) API. Removed rarely useful SetNewWindowDefaultPos() in favor of new API. --- examples/directx11_example/main.cpp | 2 +- examples/directx9_example/main.cpp | 2 +- examples/opengl3_example/main.cpp | 2 +- examples/opengl_example/main.cpp | 2 +- imgui.cpp | 160 ++++++++++++++++++++++------ imgui.h | 33 ++++-- 6 files changed, 158 insertions(+), 43 deletions(-) diff --git a/examples/directx11_example/main.cpp b/examples/directx11_example/main.cpp index c6ec87f8..252b8b69 100644 --- a/examples/directx11_example/main.cpp +++ b/examples/directx11_example/main.cpp @@ -588,7 +588,7 @@ int WINAPI wWinMain(HINSTANCE hInst, HINSTANCE, LPWSTR, int) // 3. Show the ImGui test window. Most of the sample code is in ImGui::ShowTestWindow() if (show_test_window) { - ImGui::SetNewWindowDefaultPos(ImVec2(650, 20)); // Normally user code doesn't need/want to call it because positions are saved in .ini file anyway. Here we just want to make the demo initial state a bit more friendly! + ImGui::SetNextWindowPos(ImVec2(650, 20), ImGuiSetCondition_FirstUseEver); // Normally user code doesn't need/want to call it because positions are saved in .ini file anyway. Here we just want to make the demo initial state a bit more friendly! ImGui::ShowTestWindow(&show_test_window); } diff --git a/examples/directx9_example/main.cpp b/examples/directx9_example/main.cpp index 9da31d2f..fe4f15d7 100644 --- a/examples/directx9_example/main.cpp +++ b/examples/directx9_example/main.cpp @@ -330,7 +330,7 @@ int WINAPI wWinMain(HINSTANCE hInst, HINSTANCE, LPWSTR, int) // 3. Show the ImGui test window. Most of the sample code is in ImGui::ShowTestWindow() if (show_test_window) { - ImGui::SetNewWindowDefaultPos(ImVec2(650, 20)); // Normally user code doesn't need/want to call it because positions are saved in .ini file anyway. Here we just want to make the demo initial state a bit more friendly! + ImGui::SetNextWindowPos(ImVec2(650, 20), ImGuiSetCondition_FirstUseEver); ImGui::ShowTestWindow(&show_test_window); } diff --git a/examples/opengl3_example/main.cpp b/examples/opengl3_example/main.cpp index 41ef5221..2687da9d 100644 --- a/examples/opengl3_example/main.cpp +++ b/examples/opengl3_example/main.cpp @@ -360,7 +360,7 @@ int main(int argc, char** argv) // 3. Show the ImGui test window. Most of the sample code is in ImGui::ShowTestWindow() if (show_test_window) { - ImGui::SetNewWindowDefaultPos(ImVec2(650, 20)); // Normally user code doesn't need/want to call this, because positions are saved in .ini file. Here we just want to make the demo initial state a bit more friendly! + ImGui::SetNextWindowPos(ImVec2(650, 20), ImGuiSetCondition_FirstUseEver); ImGui::ShowTestWindow(&show_test_window); } diff --git a/examples/opengl_example/main.cpp b/examples/opengl_example/main.cpp index 069fc870..34dd1da9 100644 --- a/examples/opengl_example/main.cpp +++ b/examples/opengl_example/main.cpp @@ -293,7 +293,7 @@ int main(int argc, char** argv) // 3. Show the ImGui test window. Most of the sample code is in ImGui::ShowTestWindow() if (show_test_window) { - ImGui::SetNewWindowDefaultPos(ImVec2(650, 20)); // Normally user code doesn't need/want to call this, because positions are saved in .ini file. Here we just want to make the demo initial state a bit more friendly! + ImGui::SetNextWindowPos(ImVec2(650, 20), ImGuiSetCondition_FirstUseEver); ImGui::ShowTestWindow(&show_test_window); } diff --git a/imgui.cpp b/imgui.cpp index 13303a27..c890a55d 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -117,6 +117,7 @@ Occasionally introducing changes that are breaking the API. The breakage are generally minor and easy to fix. Here is a change-log of API breaking changes, if you are using one of the functions listed, expect to have to fix some code. + - 2014/12/10 (1.18) removed SetNewWindowDefaultPos() in favor of new generic API SetNextWindowPos(pos, ImGuiSetCondition_FirstUseEver) - 2014/11/28 (1.17) moved IO.Font*** options to inside the IO.Font-> structure. - 2014/11/26 (1.17) reworked syntax of IMGUI_ONCE_UPON_A_FRAME helper macro to increase compiler compatibility - 2014/11/07 (1.15) renamed IsHovered() to IsItemHovered() @@ -773,9 +774,14 @@ struct ImGuiState bool ActiveIdIsAlive; float SettingsDirtyTimer; ImVector Settings; - ImVec2 NewWindowDefaultPos; ImVector ColorModifiers; ImVector StyleModifiers; + ImVec2 SetNextWindowPosVal; + ImGuiSetCondition SetNextWindowPosCond; + ImVec2 SetNextWindowSizeVal; + ImGuiSetCondition SetNextWindowSizeCond; + bool SetNextWindowCollapsedVal; + ImGuiSetCondition SetNextWindowCollapsedCond; // Render ImVector RenderDrawLists; @@ -806,7 +812,12 @@ struct ImGuiState HoveredRootWindow = NULL; ActiveIdIsAlive = false; SettingsDirtyTimer = 0.0f; - NewWindowDefaultPos = ImVec2(60, 60); + SetNextWindowPosVal = ImVec2(0.0f, 0.0f); + SetNextWindowPosCond = 0; + SetNextWindowSizeVal = ImVec2(0.0f, 0.0f); + SetNextWindowSizeCond = 0; + SetNextWindowCollapsedVal = false; + SetNextWindowCollapsedCond = 0; SliderAsInputTextId = 0; ActiveComboID = 0; memset(Tooltip, 0, sizeof(Tooltip)); @@ -839,6 +850,9 @@ struct ImGuiWindow bool SkipItems; // == Visible && !Collapsed int AutoFitFrames; bool AutoFitOnlyGrows; + int SetWindowPosAllowFlags; // bit ImGuiSetCondition_*** specify if SetWindowPos() call is allowed with this particular flag. + int SetWindowSizeAllowFlags; // bit ImGuiSetCondition_*** specify if SetWindowSize() call is allowed with this particular flag. + int SetWindowCollapsedAllowFlags; // bit ImGuiSetCondition_*** specify if SetWindowCollapsed() call is allowed with this particular flag. ImGuiDrawContext DC; ImVector IDStack; @@ -859,7 +873,7 @@ struct ImGuiWindow int FocusIdxTabRequestNext; // " public: - ImGuiWindow(const char* name, ImVec2 default_pos, ImVec2 default_size); + ImGuiWindow(const char* name); ~ImGuiWindow(); ImGuiID GetID(const char* str); @@ -1103,15 +1117,14 @@ void ImGuiTextBuffer::append(const char* fmt, ...) //----------------------------------------------------------------------------- -ImGuiWindow::ImGuiWindow(const char* name, ImVec2 default_pos, ImVec2 default_size) +ImGuiWindow::ImGuiWindow(const char* name) { Name = ImStrdup(name); ID = GetID(name); IDStack.push_back(ID); - PosFloat = default_pos; - Pos = ImVec2((float)(int)PosFloat.x, (float)(int)PosFloat.y); - Size = SizeFull = default_size; + PosFloat = Pos = ImVec2(0.0f, 0.0f); + Size = SizeFull = ImVec2(0.0f, 0.0f); SizeContentsFit = ImVec2(0.0f, 0.0f); ScrollY = 0.0f; NextScrollY = 0.0f; @@ -1122,6 +1135,8 @@ ImGuiWindow::ImGuiWindow(const char* name, ImVec2 default_pos, ImVec2 default_si SkipItems = false; AutoFitFrames = -1; AutoFitOnlyGrows = false; + SetWindowPosAllowFlags = SetWindowSizeAllowFlags = SetWindowCollapsedAllowFlags = ImGuiSetCondition_Always | ImGuiSetCondition_FirstUseThisSession | ImGuiSetCondition_FirstUseEver; + LastFrameDrawn = -1; ItemWidthDefault = 0.0f; FontWindowScale = 1.0f; @@ -1240,20 +1255,24 @@ void* ImGui::MemRealloc(void* ptr, size_t sz) static ImGuiIniData* FindWindowSettings(const char* name) { ImGuiState& g = GImGui; - for (size_t i = 0; i != g.Settings.size(); i++) { ImGuiIniData* ini = g.Settings[i]; if (ImStricmp(ini->Name, name) == 0) return ini; } + return NULL; +} + +static ImGuiIniData* AddWindowSettings(const char* name) +{ ImGuiIniData* ini = (ImGuiIniData*)ImGui::MemAlloc(sizeof(ImGuiIniData)); new(ini) ImGuiIniData(); ini->Name = ImStrdup(name); ini->Collapsed = false; ini->Pos = ImVec2(FLT_MAX,FLT_MAX); ini->Size = ImVec2(0,0); - g.Settings.push_back(ini); + GImGui.Settings.push_back(ini); return ini; } @@ -1310,6 +1329,8 @@ static void LoadSettings() char name[64]; ImFormatString(name, IM_ARRAYSIZE(name), "%.*s", line_end-line_start-2, line_start+1); settings = FindWindowSettings(name); + if (!settings) + settings = AddWindowSettings(name); } else if (settings) { @@ -2026,13 +2047,6 @@ void ImGui::SetTooltip(const char* fmt, ...) va_end(args); } -// Position new window if they don't have position setting in the .ini file. Rarely useful (used by the sample applications). -void ImGui::SetNewWindowDefaultPos(const ImVec2& pos) -{ - ImGuiState& g = GImGui; - g.NewWindowDefaultPos = pos; -} - float ImGui::GetTime() { return GImGui.Time; @@ -2121,7 +2135,10 @@ void ImGui::EndChild() } } -// Push a new ImGui window to add widgets to. This can be called multiple times with the same window to append contents +// Push a new ImGui window to add widgets to. +// A default window called "Debug" is automatically stacked at the beginning of every frame. +// This can be called multiple times with the same window name to append content to the same window. +// Passing non-zero 'size' is roughly equivalent to calling SetNextWindowSize(size, ImGuiSetCondition_FirstUseEver) prior to calling Begin(). bool ImGui::Begin(const char* name, bool* open, ImVec2 size, float fill_alpha, ImGuiWindowFlags flags) { ImGuiState& g = GImGui; @@ -2136,17 +2153,30 @@ bool ImGui::Begin(const char* name, bool* open, ImVec2 size, float fill_alpha, I { // Tooltip and child windows don't store settings window = (ImGuiWindow*)ImGui::MemAlloc(sizeof(ImGuiWindow)); - new(window) ImGuiWindow(name, ImVec2(0,0), size); + new(window) ImGuiWindow(name); + + window->Size = window->SizeFull = size; } else { // Normal windows store settings in .ini file - ImGuiIniData* settings = FindWindowSettings(name); - if (settings && ImLength(settings->Size) > 0.0f && !(flags & ImGuiWindowFlags_NoResize))// && ImLengthsize) == 0.0f) - size = settings->Size; - window = (ImGuiWindow*)ImGui::MemAlloc(sizeof(ImGuiWindow)); - new(window) ImGuiWindow(name, g.NewWindowDefaultPos, size); + new(window) ImGuiWindow(name); + + window->PosFloat = ImVec2(60, 60); + window->Pos = ImVec2((float)(int)window->PosFloat.x, (float)(int)window->PosFloat.y); + + ImGuiIniData* settings = FindWindowSettings(name); + if (!settings) + { + settings = AddWindowSettings(name); + } + else + { + window->SetWindowPosAllowFlags &= ~ImGuiSetCondition_FirstUseEver; + window->SetWindowSizeAllowFlags &= ~ImGuiSetCondition_FirstUseEver; + window->SetWindowCollapsedAllowFlags &= ~ImGuiSetCondition_FirstUseEver; + } if (settings->Pos.x != FLT_MAX) { @@ -2154,6 +2184,10 @@ bool ImGui::Begin(const char* name, bool* open, ImVec2 size, float fill_alpha, I window->Pos = ImVec2((float)(int)window->PosFloat.x, (float)(int)window->PosFloat.y); window->Collapsed = settings->Collapsed; } + + if (ImLength(settings->Size) > 0.0f && !(flags & ImGuiWindowFlags_NoResize)) + size = settings->Size; + window->Size = window->SizeFull = size; } g.Windows.push_back(window); } @@ -2162,6 +2196,25 @@ bool ImGui::Begin(const char* name, bool* open, ImVec2 size, float fill_alpha, I g.CurrentWindowStack.push_back(window); g.CurrentWindow = window; + // Process SetNextWindow***() calls + if (g.SetNextWindowPosCond) + { + const ImVec2 backup_cursor_pos = window->DC.CursorPos; + ImGui::SetWindowPos(g.SetNextWindowPosVal, g.SetNextWindowPosCond); + window->DC.CursorPos = backup_cursor_pos; + g.SetNextWindowPosCond = 0; + } + if (g.SetNextWindowSizeCond) + { + ImGui::SetWindowSize(g.SetNextWindowSizeVal, g.SetNextWindowSizeCond); + g.SetNextWindowSizeCond = 0; + } + if (g.SetNextWindowCollapsedCond) + { + ImGui::SetWindowCollapsed(g.SetNextWindowCollapsedVal, g.SetNextWindowCollapsedCond); + g.SetNextWindowCollapsedCond = 0; + } + // Find root size_t root_idx = g.CurrentWindowStack.size() - 1; while (root_idx > 0) @@ -2797,15 +2850,20 @@ ImVec2 ImGui::GetWindowPos() return window->Pos; } -void ImGui::SetWindowPos(const ImVec2& pos) +void ImGui::SetWindowPos(const ImVec2& pos, ImGuiSetCondition cond) { ImGuiWindow* window = GetCurrentWindow(); + + // Test condition (NB: bit 0 is always true) and clear flags for next time + if (cond && (window->SetWindowPosAllowFlags & cond) == 0) + return; + window->SetWindowPosAllowFlags &= ~(ImGuiSetCondition_FirstUseThisSession | ImGuiSetCondition_FirstUseEver); + + // Set const ImVec2 old_pos = window->Pos; window->PosFloat = pos; window->Pos = ImVec2((float)(int)window->PosFloat.x, (float)(int)window->PosFloat.y); - - // If we happen to move the window while it is being appended to (which is a bad idea - will smear) let's at least offset the cursor - window->DC.CursorPos += (window->Pos - old_pos); + window->DC.CursorPos += (window->Pos - old_pos); // As we happen to move the window while it is being appended to (which is a bad idea - will smear) let's at least offset the cursor } ImVec2 ImGui::GetWindowSize() @@ -2814,9 +2872,16 @@ ImVec2 ImGui::GetWindowSize() return window->Size; } -void ImGui::SetWindowSize(const ImVec2& size) +void ImGui::SetWindowSize(const ImVec2& size, ImGuiSetCondition cond) { ImGuiWindow* window = GetCurrentWindow(); + + // Test condition (NB: bit 0 is always true) and clear flags for next time + if (cond && (window->SetWindowSizeAllowFlags & cond) == 0) + return; + window->SetWindowSizeAllowFlags &= ~(ImGuiSetCondition_FirstUseThisSession | ImGuiSetCondition_FirstUseEver); + + // Set if (ImLength(size) < 0.001f) { window->AutoFitFrames = 2; @@ -2825,9 +2890,44 @@ void ImGui::SetWindowSize(const ImVec2& size) else { window->SizeFull = size; + window->AutoFitFrames = 0; } } +void ImGui::SetWindowCollapsed(bool collapsed, ImGuiSetCondition cond) +{ + ImGuiWindow* window = GetCurrentWindow(); + + // Test condition (NB: bit 0 is always true) and clear flags for next time + if (cond && (window->SetWindowCollapsedAllowFlags & cond) == 0) + return; + window->SetWindowCollapsedAllowFlags &= ~(ImGuiSetCondition_FirstUseThisSession | ImGuiSetCondition_FirstUseEver); + + // Set + window->Collapsed = collapsed; +} + +void ImGui::SetNextWindowPos(const ImVec2& pos, ImGuiSetCondition cond) +{ + ImGuiState& g = GImGui; + g.SetNextWindowPosVal = pos; + g.SetNextWindowPosCond = cond ? cond : ImGuiSetCondition_Always; +} + +void ImGui::SetNextWindowSize(const ImVec2& size, ImGuiSetCondition cond) +{ + ImGuiState& g = GImGui; + g.SetNextWindowSizeVal = size; + g.SetNextWindowSizeCond = cond ? cond : ImGuiSetCondition_Always; +} + +void ImGui::SetNextWindowCollapsed(bool collapsed, ImGuiSetCondition cond) +{ + ImGuiState& g = GImGui; + g.SetNextWindowCollapsedVal = collapsed; + g.SetNextWindowCollapsedCond = cond ? cond : ImGuiSetCondition_Always; +} + ImVec2 ImGui::GetContentRegionMax() { ImGuiWindow* window = GetCurrentWindow(); @@ -6555,7 +6655,7 @@ void ImGui::ShowStyleEditor(ImGuiStyle* ref) *ref = g.Style; } - ImGui::PushItemWidth(ImGui::GetWindowWidth()*0.55f); + ImGui::PushItemWidth(ImGui::GetWindowWidth() * 0.55f); if (ImGui::TreeNode("Sizes")) { @@ -6943,7 +7043,7 @@ void ImGui::ShowTestWindow(bool* open) ImGui::PushItemWidth(100); goto_line |= ImGui::InputInt("##Line", &line, 0, 0, ImGuiInputTextFlags_EnterReturnsTrue); ImGui::PopItemWidth(); - ImGui::BeginChild("Sub1", ImVec2(ImGui::GetWindowWidth()*0.5f,300)); + ImGui::BeginChild("Sub1", ImVec2(ImGui::GetWindowWidth() * 0.5f,300)); for (int i = 0; i < 100; i++) { ImGui::Text("%04d: scrollable region", i); diff --git a/imgui.h b/imgui.h index 8ce585e3..2d82d1e1 100644 --- a/imgui.h +++ b/imgui.h @@ -37,6 +37,7 @@ typedef int ImGuiStyleVar; // enum ImGuiStyleVar_ typedef int ImGuiKey; // enum ImGuiKey_ typedef int ImGuiColorEditMode; // enum ImGuiColorEditMode_ typedef int ImGuiWindowFlags; // enum ImGuiWindowFlags_ +typedef int ImGuiSetCondition; // enum ImGuiSetCondition_ typedef int ImGuiInputTextFlags; // enum ImGuiInputTextFlags_ struct ImGuiTextEditCallbackData; @@ -127,7 +128,7 @@ public: // - struct ImGuiTextBuffer // Text buffer for logging/accumulating text // - struct ImGuiStorage // Custom key value storage (if you need to alter open/close states manually) // - struct ImDrawList // Draw command list -// - struct ImBitmapFont // Bitmap font loader +// - struct ImFont // Bitmap font loader // ImGui End-user API // In a namespace so that user can add extra functions (e.g. Value() helpers for your vector or common types) @@ -149,11 +150,6 @@ namespace ImGui IMGUI_API void BeginChild(const char* str_id, ImVec2 size = ImVec2(0,0), bool border = false, ImGuiWindowFlags extra_flags = 0); // size==0.0f: use remaining window size, size<0.0f: use remaining window size minus abs(size). on each axis. IMGUI_API void EndChild(); IMGUI_API bool GetWindowIsFocused(); - IMGUI_API ImVec2 GetWindowSize(); - IMGUI_API float GetWindowWidth(); - IMGUI_API void SetWindowSize(const ImVec2& size); // set to ImVec2(0,0) to force an auto-fit - IMGUI_API ImVec2 GetWindowPos(); // you should rarely need/care about the window position, but it can be useful if you want to use your own drawing. - IMGUI_API void SetWindowPos(const ImVec2& pos); // set current window pos. IMGUI_API ImVec2 GetContentRegionMax(); // window or current column boundaries IMGUI_API ImVec2 GetWindowContentRegionMin(); // window boundaries IMGUI_API ImVec2 GetWindowContentRegionMax(); @@ -161,11 +157,22 @@ namespace ImGui IMGUI_API ImFont* GetWindowFont(); IMGUI_API float GetWindowFontSize(); IMGUI_API void SetWindowFontScale(float scale); // per-window font scale. Adjust IO.FontGlobalScale if you want to scale all windows. + IMGUI_API ImVec2 GetWindowPos(); // you should rarely need/care about the window position, but it can be useful if you want to do your own drawing. + IMGUI_API ImVec2 GetWindowSize(); // get current window position. + IMGUI_API float GetWindowWidth(); + IMGUI_API bool GetWindowCollapsed(); + IMGUI_API void SetWindowPos(const ImVec2& pos, ImGuiSetCondition cond = 0); // set current window position. + IMGUI_API void SetWindowSize(const ImVec2& size, ImGuiSetCondition cond = 0); // set current window size. set to ImVec2(0,0) to force an auto-fit + IMGUI_API void SetWindowCollapsed(bool collapsed, ImGuiSetCondition cond = 0); // set current window collapsed state. + IMGUI_API void SetNextWindowPos(const ImVec2& pos, ImGuiSetCondition cond = 0); // set next window position. + IMGUI_API void SetNextWindowSize(const ImVec2& size, ImGuiSetCondition cond = 0); // set next window size. set to ImVec2(0,0) to force an auto-fit + IMGUI_API void SetNextWindowCollapsed(bool collapsed, ImGuiSetCondition cond = 0); // set next window collapsed state. + IMGUI_API void SetScrollPosHere(); // adjust scrolling position to center into the current cursor position. - IMGUI_API void SetKeyboardFocusHere(int offset = 0); // focus keyboard on the next widget. Use 'offset' to access sub components of a multiple component widget. + IMGUI_API void SetKeyboardFocusHere(int offset = 0); // focus keyboard on the next widget. Use positive 'offset' to access sub components of a multiple component widget. IMGUI_API void SetTreeStateStorage(ImGuiStorage* tree); // replace tree state storage with our own (if you want to manipulate it yourself, typically clear subsection of it). IMGUI_API ImGuiStorage* GetTreeStateStorage(); - + IMGUI_API void PushItemWidth(float item_width); // width of items for the common item+label case. default to ~2/3 of windows width. IMGUI_API void PopItemWidth(); IMGUI_API float GetItemWidth(); @@ -279,7 +286,6 @@ namespace ImGui IMGUI_API void LogToClipboard(int max_depth = -1); // Utilities - IMGUI_API void SetNewWindowDefaultPos(const ImVec2& pos); // set position of window that do IMGUI_API bool IsItemHovered(); // was the last item active area hovered by mouse? IMGUI_API bool IsItemFocused(); // was the last item focused for keyboard input? IMGUI_API ImVec2 GetItemBoxMin(); // get bounding box of last item @@ -422,6 +428,15 @@ enum ImGuiColorEditMode_ ImGuiColorEditMode_HEX = 2 }; +// Condition flags for ImGui::SetWindow***() and SetNextWindow***() functions +// Those functions treat 0 as a shortcut to ImGuiSetCondition_Always +enum ImGuiSetCondition_ +{ + ImGuiSetCondition_Always = 1 << 0, // Set the variable + ImGuiSetCondition_FirstUseThisSession = 1 << 1, // Only set the variable on the first call for this window (once per session) + ImGuiSetCondition_FirstUseEver = 1 << 2, // Only set the variable if the window doesn't exist in the .ini file +}; + struct ImGuiStyle { float Alpha; // Global alpha applies to everything in ImGui From 486506e37fa755141f1b52c06d8cb7ba836c8a1c Mon Sep 17 00:00:00 2001 From: omar Date: Wed, 10 Dec 2014 23:39:48 +0000 Subject: [PATCH 060/108] Update README.md --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 3cdf22df..c552c890 100644 --- a/README.md +++ b/README.md @@ -48,6 +48,10 @@ The Immediate Mode GUI paradigm may at first appear unusual to some users. This Frequently Asked Question ------------------------- +Where is example code? + +The bulk of actual ImGui usage code is contained within the ImGui::ShowTestWindow() function. It covers most featurse of ImGui so you can read its source code and call the function itself to see its output. Ready-to-go example applications covering different versions of OpenGL/DirectX are provided in the examples/ folder. + How do you use ImGui on a platform that may not have a mouse or keyboard? I recommend using [Synergy](http://synergy-project.org). With the uSynergy.c micro client running you can seamlessly use your PC input devices from a video game console or a tablet. ImGui was also designed to function with touch inputs if you increase the padding of widgets to compensate for the lack of precision of touch devices, but it is recommended you use a mouse to allow optimising for screen real-estate. From 0056ccce262dd5429b836f095c3249f58d04eb00 Mon Sep 17 00:00:00 2001 From: omar Date: Wed, 10 Dec 2014 23:40:20 +0000 Subject: [PATCH 061/108] Version number --- imgui.cpp | 2 +- imgui.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index c890a55d..99658690 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -1,4 +1,4 @@ -// ImGui library v1.18 wip +// ImGui library v1.18 // See ImGui::ShowTestWindow() for sample code. // Read 'Programmer guide' below for notes on how to setup ImGui in your codebase. // Get latest version at https://github.com/ocornut/imgui diff --git a/imgui.h b/imgui.h index 2d82d1e1..b33a6454 100644 --- a/imgui.h +++ b/imgui.h @@ -1,4 +1,4 @@ -// ImGui library v1.18 wip +// ImGui library v1.18 // See .cpp file for commentary. // See ImGui::ShowTestWindow() for sample code. // Read 'Programmer guide' in .cpp for notes on how to setup ImGui in your codebase. From 7e868e28424d212b1e990365d69101df0940b803 Mon Sep 17 00:00:00 2001 From: omar Date: Thu, 11 Dec 2014 10:12:52 +0000 Subject: [PATCH 062/108] Cleanup todo list, removed 3 done items + added 1 new --- imgui.cpp | 8 +++----- imgui.h | 2 +- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 99658690..5a620c51 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -1,4 +1,4 @@ -// ImGui library v1.18 +// ImGui library v1.19 wip // See ImGui::ShowTestWindow() for sample code. // Read 'Programmer guide' below for notes on how to setup ImGui in your codebase. // Get latest version at https://github.com/ocornut/imgui @@ -195,7 +195,7 @@ - window: autofit is losing its purpose when user relies on any dynamic layout (window width multiplier, column). maybe just clearly discard autofit? - window: add horizontal scroll - window: fix resize grip rendering scaling along with Rounding style setting - - window: better helpers to set pos/size/collapsed with different options (first-run, session only, current value) (github issue #89) + - window: add a way for very transient windows (non-saved, temporary overlay over hundreds of objects) to "clean" up from the global window list. - widgets: switching from "widget-label" to "label-widget" would make it more convenient to integrate widgets in trees - widgets: clip text? hover clipped text shows it in a tooltip or in-place overlay - main: make IsHovered() more consistent for various type of widgets, widgets with multiple components, etc. also effectively IsHovered() region sometimes differs from hot region, e.g tree nodes @@ -244,9 +244,7 @@ - misc: double-clicking on title bar to minimize isn't consistent, perhaps move to single-click on left-most collapse icon? - misc: CalcTextSize() could benefit from having 'hide_text_after_double_hash' false by default for external use? - style editor: add a button to output C code. - - examples: integrate dx11 example. - - examples: integrate opengl 3/4 programmable pipeline example. - - optimization/render: use indexed rendering + - optimization/render: use indexed rendering to reduce vertex data cost (for remote/networked imgui) - optimization/render: move clip-rect to vertex data? would allow merging all commands - optimization/render: merge command-lists with same clip-rect into one even if they aren't sequential? (as long as in-between clip rectangle don't overlap)? - optimization/render: font exported by bmfont is not tight fit on vertical axis, incur unneeded pixel-shading cost. diff --git a/imgui.h b/imgui.h index b33a6454..68f37e66 100644 --- a/imgui.h +++ b/imgui.h @@ -1,4 +1,4 @@ -// ImGui library v1.18 +// ImGui library v1.19 wip // See .cpp file for commentary. // See ImGui::ShowTestWindow() for sample code. // Read 'Programmer guide' in .cpp for notes on how to setup ImGui in your codebase. From b09c49180ffad008479e045fa6dd74a2e945b1de Mon Sep 17 00:00:00 2001 From: omar Date: Sun, 14 Dec 2014 10:44:43 +0000 Subject: [PATCH 063/108] Update README.md minor fixes --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c552c890..7d122222 100644 --- a/README.md +++ b/README.md @@ -50,7 +50,7 @@ Frequently Asked Question Where is example code? -The bulk of actual ImGui usage code is contained within the ImGui::ShowTestWindow() function. It covers most featurse of ImGui so you can read its source code and call the function itself to see its output. Ready-to-go example applications covering different versions of OpenGL/DirectX are provided in the examples/ folder. +The bulk of example user code is contained within the ImGui::ShowTestWindow() function. It covers most features of ImGui so you can read the code and call the function itself to see its output. Ready-to-go example applications covering different versions of OpenGL/DirectX are provided in the examples/ folder. How do you use ImGui on a platform that may not have a mouse or keyboard? From a3af51fd4eec1405457c602b10d8c03f2b90d366 Mon Sep 17 00:00:00 2001 From: ocornut Date: Fri, 19 Dec 2014 12:56:00 +0000 Subject: [PATCH 064/108] Added ImGuiStyleVar_WindowRounding enum for PushStyleVar() API --- imgui.cpp | 1 + imgui.h | 1 + 2 files changed, 2 insertions(+) diff --git a/imgui.cpp b/imgui.cpp index 5a620c51..241213f7 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -2720,6 +2720,7 @@ static float* GetStyleVarFloatAddr(ImGuiStyleVar idx) switch (idx) { case ImGuiStyleVar_Alpha: return &g.Style.Alpha; + case ImGuiStyleVar_WindowRounding: return &g.Style.WindowRounding; case ImGuiStyleVar_TreeNodeSpacing: return &g.Style.TreeNodeSpacing; case ImGuiStyleVar_ColumnsMinSpacing: return &g.Style.ColumnsMinSpacing; } diff --git a/imgui.h b/imgui.h index 68f37e66..7ff4471a 100644 --- a/imgui.h +++ b/imgui.h @@ -412,6 +412,7 @@ enum ImGuiStyleVar_ { ImGuiStyleVar_Alpha, // float ImGuiStyleVar_WindowPadding, // ImVec2 + ImGuiStyleVar_WindowRounding, // float ImGuiStyleVar_FramePadding, // ImVec2 ImGuiStyleVar_ItemSpacing, // ImVec2 ImGuiStyleVar_ItemInnerSpacing, // ImVec2 From ac29859f70ce747b8d8d92b839051b7d3c779dff Mon Sep 17 00:00:00 2001 From: ocornut Date: Mon, 22 Dec 2014 01:45:13 +0000 Subject: [PATCH 065/108] Support zero-sized display, now sets default as -1,-1 and assert if display size is negative. --- imgui.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/imgui.cpp b/imgui.cpp index 241213f7..f47fffaa 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -371,6 +371,7 @@ ImGuiStyle::ImGuiStyle() ImGuiIO::ImGuiIO() { memset(this, 0, sizeof(*this)); + DisplaySize = ImVec2(-1.0f, -1.0f); DeltaTime = 1.0f/60.0f; IniSavingRate = 5.0f; IniFilename = "imgui.ini"; @@ -1411,7 +1412,7 @@ void ImGui::NewFrame() // Check user inputs IM_ASSERT(g.IO.DeltaTime > 0.0f); - IM_ASSERT(g.IO.DisplaySize.x > 0.0f && g.IO.DisplaySize.y > 0.0f); + IM_ASSERT(g.IO.DisplaySize.x >= 0.0f && g.IO.DisplaySize.y >= 0.0f); IM_ASSERT(g.IO.RenderDrawListsFn != NULL); // Must be implemented if (!g.Initialized) From b3febabc30fe0333efa185bba5aeabb3965f77c6 Mon Sep 17 00:00:00 2001 From: ocornut Date: Mon, 22 Dec 2014 01:47:34 +0000 Subject: [PATCH 066/108] OpenGL3 example: fix growing of VBO --- examples/opengl3_example/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/opengl3_example/main.cpp b/examples/opengl3_example/main.cpp index 2687da9d..6617b4ca 100644 --- a/examples/opengl3_example/main.cpp +++ b/examples/opengl3_example/main.cpp @@ -69,7 +69,7 @@ static void ImImpl_RenderDrawLists(ImDrawList** const cmd_lists, int cmd_lists_c if (neededBufferSize > vbo_max_size) { vbo_max_size = neededBufferSize + 5000; // Grow buffer - glBufferData(GL_ARRAY_BUFFER, neededBufferSize, NULL, GL_STREAM_DRAW); + glBufferData(GL_ARRAY_BUFFER, vbo_max_size, NULL, GL_STREAM_DRAW); } // Copy and convert all vertices into a single contiguous buffer From d6c13128b95101a4eec5b0881415ea90bb88a827 Mon Sep 17 00:00:00 2001 From: omar Date: Mon, 22 Dec 2014 02:07:02 +0000 Subject: [PATCH 067/108] Update README.md - tweaks --- README.md | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 7d122222..66b13464 100644 --- a/README.md +++ b/README.md @@ -48,9 +48,9 @@ The Immediate Mode GUI paradigm may at first appear unusual to some users. This Frequently Asked Question ------------------------- -Where is example code? +Where are samples? -The bulk of example user code is contained within the ImGui::ShowTestWindow() function. It covers most features of ImGui so you can read the code and call the function itself to see its output. Ready-to-go example applications covering different versions of OpenGL/DirectX are provided in the examples/ folder. +The bulk of example user code is contained within the ImGui::ShowTestWindow() function. It covers most features of ImGui so you can read the code and call the function itself to see its output. Ready-to-go example applications covering different versions of OpenGL/DirectX are provided in the examples/ folder. How do you use ImGui on a platform that may not have a mouse or keyboard? @@ -93,11 +93,14 @@ Support Can you develop features xxxx for ImGui? -Please use GitHub 'Issues' facilities to suggest and discuss improvements. Your questions are often helpul to the community of users. If you represent an organization and would like specific non-trivial features to be implemented, I am available for hire to work on or with ImGui. +Please use GitHub 'Issues' facilities to suggest and discuss improvements. Your questions are often helpul to the community of users. + +Donate +------ Can I donate to support the development of ImGui? -If you have the mean to help, I have setup a [**Patreon page**](http://www.patreon.com/imgui) to enable me to spend more time on the development of the library. One-off donations are also greatly appreciated. Thanks! +Yes please! I have setup an [**ImGui Patreon page**](http://www.patreon.com/imgui) if you want to donate and enable me to spend more time improving the library. If your company uses ImGui on a commercial project please consider making a small contribution. One-off donations are also greatly appreciated. I am also available for hire to work on or with ImGui. Thanks! Credits ------- From 69f3d67d184d412a76754f3912c50222631d2c3f Mon Sep 17 00:00:00 2001 From: ocornut Date: Mon, 22 Dec 2014 02:14:25 +0000 Subject: [PATCH 068/108] Preserve windows position on zero-sized display (minimized). --- imgui.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index f47fffaa..ed743eaa 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -2300,8 +2300,11 @@ bool ImGui::Begin(const char* name, bool* open, ImVec2 size, float fill_alpha, I if (!(window->Flags & ImGuiWindowFlags_ChildWindow)) { const ImVec2 pad = ImVec2(window->FontSize()*2.0f, window->FontSize()*2.0f); - window->PosFloat = ImMax(window->PosFloat + window->Size, pad) - window->Size; - window->PosFloat = ImMin(window->PosFloat, ImVec2(g.IO.DisplaySize.x, g.IO.DisplaySize.y) - pad); + if (g.IO.DisplaySize.x > 0.0f && g.IO.DisplaySize.y > 0.0f) // Ignore zero-sized display explicitly to avoid losing positions if a window manager reports zero-sized window when initializing or minimizing. + { + window->PosFloat = ImMax(window->PosFloat + window->Size, pad) - window->Size; + window->PosFloat = ImMin(window->PosFloat, ImVec2(g.IO.DisplaySize.x, g.IO.DisplaySize.y) - pad); + } window->SizeFull = ImMax(window->SizeFull, pad); } window->Pos = ImVec2((float)(int)window->PosFloat.x, (float)(int)window->PosFloat.y); @@ -2375,7 +2378,7 @@ bool ImGui::Begin(const char* name, bool* open, ImVec2 size, float fill_alpha, I } else { - const ImVec2 size_auto_fit = ImClamp(window->SizeContentsFit + style.AutoFitPadding, style.WindowMinSize, g.IO.DisplaySize - style.AutoFitPadding); + const ImVec2 size_auto_fit = ImClamp(window->SizeContentsFit + style.AutoFitPadding, style.WindowMinSize, ImMax(style.WindowMinSize, g.IO.DisplaySize - style.AutoFitPadding)); if ((window->Flags & ImGuiWindowFlags_AlwaysAutoResize) != 0) { // Don't continuously mark settings as dirty, the size of the window doesn't need to be stored. From 90351298d164814a49c1ae8c9aeaa2fa65c8a59f Mon Sep 17 00:00:00 2001 From: ocornut Date: Mon, 22 Dec 2014 13:29:39 +0000 Subject: [PATCH 069/108] Renamed second parameter to Begin() to 'bool* p_opened' to be more self-explanatory. Added more comments on the use of Begin(). --- imgui.cpp | 62 +++++++++++++++++++++++++++++-------------------------- imgui.h | 2 +- 2 files changed, 34 insertions(+), 30 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index ed743eaa..35592acf 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -41,7 +41,7 @@ ============== - double-click title bar to collapse window - - click upper right corner to close a window, available when 'bool* open' is passed to ImGui::Begin() + - click upper right corner to close a window, available when 'bool* p_opened' is passed to ImGui::Begin() - click and drag on lower right corner to resize window - click and drag on any empty space to move window - double-click/double-tap on lower right corner grip to auto-fit to content @@ -286,7 +286,7 @@ static void LogText(const ImVec2& ref_pos, const char* text, const char* static void RenderText(ImVec2 pos, const char* text, const char* text_end = NULL, bool hide_text_after_hash = true, float wrap_width = 0.0f); static void RenderFrame(ImVec2 p_min, ImVec2 p_max, ImU32 fill_col, bool border = true, float rounding = 0.0f); -static void RenderCollapseTriangle(ImVec2 p_min, bool open, float scale = 1.0f, bool shadow = false); +static void RenderCollapseTriangle(ImVec2 p_min, bool opened, float scale = 1.0f, bool shadow = false); static void ItemSize(ImVec2 size, ImVec2* adjust_start_offset = NULL); static void ItemSize(const ImGuiAabb& aabb, ImVec2* adjust_start_offset = NULL); @@ -297,7 +297,7 @@ static bool ClipAdvance(const ImGuiAabb& aabb); static bool IsMouseHoveringBox(const ImGuiAabb& box); static bool IsKeyPressedMap(ImGuiKey key, bool repeat = true); -static bool CloseWindowButton(bool* open = NULL); +static bool CloseWindowButton(bool* p_opened = NULL); static void FocusWindow(ImGuiWindow* window); static ImGuiWindow* FindWindow(const char* name); static ImGuiWindow* FindHoveredWindow(ImVec2 pos, bool excluding_childs); @@ -1846,7 +1846,7 @@ static void RenderFrame(ImVec2 p_min, ImVec2 p_max, ImU32 fill_col, bool border, } // Render a triangle to denote expanded/collapsed state -static void RenderCollapseTriangle(ImVec2 p_min, bool open, float scale, bool shadow) +static void RenderCollapseTriangle(ImVec2 p_min, bool opened, float scale, bool shadow) { ImGuiWindow* window = GetCurrentWindow(); @@ -1855,7 +1855,7 @@ static void RenderCollapseTriangle(ImVec2 p_min, bool open, float scale, bool sh ImVec2 center = p_min + ImVec2(h*0.50f, h*0.50f*scale); ImVec2 a, b, c; - if (open) + if (opened) { center.y -= r*0.25f; a = center + ImVec2(0,1)*r; @@ -2135,14 +2135,18 @@ void ImGui::EndChild() } // Push a new ImGui window to add widgets to. -// A default window called "Debug" is automatically stacked at the beginning of every frame. -// This can be called multiple times with the same window name to append content to the same window. -// Passing non-zero 'size' is roughly equivalent to calling SetNextWindowSize(size, ImGuiSetCondition_FirstUseEver) prior to calling Begin(). -bool ImGui::Begin(const char* name, bool* open, ImVec2 size, float fill_alpha, ImGuiWindowFlags flags) +// - A default window called "Debug" is automatically stacked at the beginning of every frame. +// - This can be called multiple times during the frame with the same window name to append content to the same window. +// - The window name is used as a unique identifier to preserve window information across frames (and save rudimentary information to the .ini file). Note that you can use ## to append unique data that isn't displayed, e.g. "My window##1" will use "My window##1" as unique window ID but display "My window" to the user. +// - Return false when window is collapsed, so you can early out in your code. You always need to call ImGui::End() even if false is returned. +// - Passing 'bool* p_opened' displays a Close button on the upper-right corner of the window, the pointed value will be set to false when the button is pressed. +// - Passing non-zero 'size' is roughly equivalent to calling SetNextWindowSize(size, ImGuiSetCondition_FirstUseEver) prior to calling Begin(). +bool ImGui::Begin(const char* name, bool* p_opened, ImVec2 size, float fill_alpha, ImGuiWindowFlags flags) { ImGuiState& g = GImGui; const ImGuiStyle& style = g.Style; IM_ASSERT(g.Initialized); // Forgot to call ImGui::NewFrame() + IM_ASSERT(name != NULL); // Must pass a name ImGuiWindow* window = FindWindow(name); if (!window) @@ -2533,12 +2537,12 @@ bool ImGui::Begin(const char* name, bool* open, ImVec2 size, float fill_alpha, I if (!(window->Flags & ImGuiWindowFlags_NoTitleBar)) { RenderCollapseTriangle(window->Pos + style.FramePadding, !window->Collapsed, 1.0f, true); - if (open) - CloseWindowButton(open); + if (p_opened != NULL) + CloseWindowButton(p_opened); const ImVec2 text_size = CalcTextSize(name); const ImVec2 text_min = window->Pos + style.FramePadding + ImVec2(window->FontSize() + style.ItemInnerSpacing.x, 0.0f); - const ImVec2 text_max = window->Pos + ImVec2(window->Size.x - (open ? (title_bar_aabb.GetHeight()-3) : style.FramePadding.x), style.FramePadding.y + text_size.y); + const ImVec2 text_max = window->Pos + ImVec2(window->Size.x - (p_opened ? (title_bar_aabb.GetHeight()-3) : style.FramePadding.x), style.FramePadding.y + text_size.y); const bool clip_title = text_size.x > (text_max.x - text_min.x); // only push a clip rectangle if we need to, because it may turn into a separate draw call if (clip_title) PushClipRect(ImVec4(text_min.x, text_min.y, text_max.x, text_max.y)); @@ -3368,7 +3372,7 @@ bool ImGui::SmallButton(const char* label) } // Upper-right button to close a window. -static bool CloseWindowButton(bool* open) +static bool CloseWindowButton(bool* p_opened) { ImGuiWindow* window = GetCurrentWindow(); @@ -3391,8 +3395,8 @@ static bool CloseWindowButton(bool* open) window->DrawList->AddLine(center + ImVec2(+cross_extent,-cross_extent), center + ImVec2(-cross_extent,+cross_extent), window->Color(ImGuiCol_Text)); } - if (open != NULL && pressed) - *open = !*open; + if (p_opened != NULL && pressed) + *p_opened = !*p_opened; return pressed; } @@ -6729,13 +6733,13 @@ void ImGui::ShowStyleEditor(ImGuiStyle* ref) // SAMPLE CODE //----------------------------------------------------------------------------- -static void ShowExampleAppConsole(bool* open); -static void ShowExampleAppLongText(bool* open); -static void ShowExampleAppAutoResize(bool* open); -static void ShowExampleAppFixedOverlay(bool* open); +static void ShowExampleAppConsole(bool* opened); +static void ShowExampleAppLongText(bool* opened); +static void ShowExampleAppAutoResize(bool* opened); +static void ShowExampleAppFixedOverlay(bool* opened); // Demonstrate ImGui features (unfortunately this makes this function a little bloated!) -void ImGui::ShowTestWindow(bool* open) +void ImGui::ShowTestWindow(bool* opened) { static bool no_titlebar = false; static bool no_border = true; @@ -6745,7 +6749,7 @@ void ImGui::ShowTestWindow(bool* open) static float fill_alpha = 0.65f; const ImGuiWindowFlags layout_flags = (no_titlebar ? ImGuiWindowFlags_NoTitleBar : 0) | (no_border ? 0 : ImGuiWindowFlags_ShowBorders) | (no_resize ? ImGuiWindowFlags_NoResize : 0) | (no_move ? ImGuiWindowFlags_NoMove : 0) | (no_scrollbar ? ImGuiWindowFlags_NoScrollbar : 0); - ImGui::Begin("ImGui Test", open, ImVec2(550,680), fill_alpha, layout_flags); + ImGui::Begin("ImGui Test", opened, ImVec2(550,680), fill_alpha, layout_flags); ImGui::PushItemWidth(ImGui::GetWindowWidth() * 0.65f); ImGui::Text("ImGui says hello."); @@ -7264,9 +7268,9 @@ void ImGui::ShowTestWindow(bool* open) ImGui::End(); } -static void ShowExampleAppAutoResize(bool* open) +static void ShowExampleAppAutoResize(bool* opened) { - if (!ImGui::Begin("Example: Auto-Resizing Window", open, ImVec2(0,0), -1.0f, ImGuiWindowFlags_AlwaysAutoResize)) + if (!ImGui::Begin("Example: Auto-Resizing Window", opened, ImVec2(0,0), -1.0f, ImGuiWindowFlags_AlwaysAutoResize)) { ImGui::End(); return; @@ -7281,9 +7285,9 @@ static void ShowExampleAppAutoResize(bool* open) ImGui::End(); } -static void ShowExampleAppFixedOverlay(bool* open) +static void ShowExampleAppFixedOverlay(bool* opened) { - if (!ImGui::Begin("Example: Fixed Overlay", open, ImVec2(0,0), 0.3f, ImGuiWindowFlags_NoTitleBar|ImGuiWindowFlags_NoResize|ImGuiWindowFlags_NoMove|ImGuiWindowFlags_NoSavedSettings)) + if (!ImGui::Begin("Example: Fixed Overlay", opened, ImVec2(0,0), 0.3f, ImGuiWindowFlags_NoTitleBar|ImGuiWindowFlags_NoResize|ImGuiWindowFlags_NoMove|ImGuiWindowFlags_NoSavedSettings)) { ImGui::End(); return; @@ -7404,9 +7408,9 @@ static void ShowExampleAppConsole_TextEditCallback(ImGuiTextEditCallbackData* da console->TextEditCallback(data); } -static void ShowExampleAppConsole(bool* open) +static void ShowExampleAppConsole(bool* opened) { - if (!ImGui::Begin("Example: Console", open, ImVec2(520,600))) + if (!ImGui::Begin("Example: Console", opened, ImVec2(520,600))) { ImGui::End(); return; @@ -7481,9 +7485,9 @@ static void ShowExampleAppConsole(bool* open) ImGui::End(); } -static void ShowExampleAppLongText(bool* open) +static void ShowExampleAppLongText(bool* opened) { - if (!ImGui::Begin("Example: Long text display", open, ImVec2(520,600))) + if (!ImGui::Begin("Example: Long text display", opened, ImVec2(520,600))) { ImGui::End(); return; diff --git a/imgui.h b/imgui.h index 7ff4471a..a37d128c 100644 --- a/imgui.h +++ b/imgui.h @@ -145,7 +145,7 @@ namespace ImGui IMGUI_API void ShowTestWindow(bool* open = NULL); // Window - IMGUI_API bool Begin(const char* name = "Debug", bool* open = NULL, ImVec2 size = ImVec2(0,0), float fill_alpha = -1.0f, ImGuiWindowFlags flags = 0); // return false when window is collapsed, so you can early out in your code. + IMGUI_API bool Begin(const char* name = "Debug", bool* p_opened = NULL, ImVec2 size = ImVec2(0,0), float fill_alpha = -1.0f, ImGuiWindowFlags flags = 0);// return false when window is collapsed, so you can early out in your code. passing 'bool* p_opened' displays a Close button on the upper-right corner of the window, the pointed value will be set to false when the button is pressed. IMGUI_API void End(); IMGUI_API void BeginChild(const char* str_id, ImVec2 size = ImVec2(0,0), bool border = false, ImGuiWindowFlags extra_flags = 0); // size==0.0f: use remaining window size, size<0.0f: use remaining window size minus abs(size). on each axis. IMGUI_API void EndChild(); From 34728394ec9b5b38f08fef9157da4787c23e74f0 Mon Sep 17 00:00:00 2001 From: ocornut Date: Fri, 26 Dec 2014 12:38:13 +0000 Subject: [PATCH 070/108] Fixed clipped ImGui::Combo not registering its size properly (was flickering when scrolling with combo on the edge of clipping region) --- imgui.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 35592acf..16951ecf 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -4935,17 +4935,17 @@ bool ImGui::Combo(const char* label, int* current_item, bool (*items_getter)(voi const ImGuiID id = window->GetID(label); const ImVec2 text_size = CalcTextSize(label); - const float arrow_size = (window->FontSize() + style.FramePadding.x * 2.0f); const ImGuiAabb frame_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(window->DC.ItemWidth.back(), text_size.y) + style.FramePadding*2.0f); - const ImGuiAabb bb(frame_bb.Min, frame_bb.Max + ImVec2(style.ItemInnerSpacing.x + text_size.x,0)); + ItemSize(frame_bb); if (ClipAdvance(frame_bb)) return false; + const ImGuiAabb bb(frame_bb.Min, frame_bb.Max + ImVec2(style.ItemInnerSpacing.x + text_size.x,0)); + const float arrow_size = (window->FontSize() + style.FramePadding.x * 2.0f); const bool hovered = (g.HoveredWindow == window) && (g.HoveredId == 0) && IsMouseHoveringBox(bb); bool value_changed = false; - ItemSize(frame_bb); RenderFrame(frame_bb.Min, frame_bb.Max, window->Color(ImGuiCol_FrameBg)); RenderFrame(ImVec2(frame_bb.Max.x-arrow_size, frame_bb.Min.y), frame_bb.Max, window->Color(hovered ? ImGuiCol_ButtonHovered : ImGuiCol_Button)); RenderCollapseTriangle(ImVec2(frame_bb.Max.x-arrow_size, frame_bb.Min.y) + style.FramePadding, true); From bf3212c681e3926ca579233d6e1040b26346842f Mon Sep 17 00:00:00 2001 From: ocornut Date: Sun, 28 Dec 2014 16:09:19 +0000 Subject: [PATCH 071/108] Taking notes of issues/todo --- imgui.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 16951ecf..2ca4bde3 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -192,24 +192,29 @@ ================== - misc: merge or clarify ImVec4 / ImGuiAabb, they are essentially duplicate containers - - window: autofit is losing its purpose when user relies on any dynamic layout (window width multiplier, column). maybe just clearly discard autofit? - window: add horizontal scroll - window: fix resize grip rendering scaling along with Rounding style setting + - window: autofit feedback loop when user relies on any dynamic layout (window width multiplier, column). maybe just clearly drop manual autofit? - window: add a way for very transient windows (non-saved, temporary overlay over hundreds of objects) to "clean" up from the global window list. - widgets: switching from "widget-label" to "label-widget" would make it more convenient to integrate widgets in trees - widgets: clip text? hover clipped text shows it in a tooltip or in-place overlay + - widgets: widget-label types of function calls don't play nicely with SameLine (github issue #100) because of how they intentionally not declare the label extent. separate extent for auto-size vs extent for cursor. - main: make IsHovered() more consistent for various type of widgets, widgets with multiple components, etc. also effectively IsHovered() region sometimes differs from hot region, e.g tree nodes - main: make IsHovered() info stored in a stack? so that 'if TreeNode() { Text; TreePop; } if IsHovered' return the hover state of the TreeNode? - scrollbar: use relative mouse movement when first-clicking inside of scroll grab box. - scrollbar: make the grab visible and a minimum size for long scroll regions !- input number: very large int not reliably supported because of int<>float conversions. - input number: optional range min/max for Input*() functions - - input number: holding [-]/[+] buttons should increase the step non-linearly + - input number: holding [-]/[+] buttons could increase the step speed non-linearly (or user-controlled) - input number: use mouse wheel to step up/down - - layout: clean up the InputFloatN/SliderFloatN/ColorEdit4 horrible layout code. item width should include frame padding, then we can have a generic horizontal layout helper. + - layout: horizontal layout helper (github issue #97) + - layout: clean up the InputFloatN/SliderFloatN/ColorEdit4 horrible layout code. item width should include frame padding. + - columns: separator function or parameter that works within the column (currently Separator() bypass all columns) - columns: declare column set (each column: fixed size, %, fill, distribute default size among fills) - columns: columns header to act as button (~sort op) and allow resize/reorder - columns: user specify columns size + - combo: overlap test beyond parent window bounding box is broken (used to work) + - combo: broken visual ordering when window B is focused then click on window A:combo - combo: turn child handling code into pop up helper - list selection, concept of a selectable "block" (that can be multiple widgets) - menubar, menus @@ -239,8 +244,8 @@ - tooltip: move to fit within screen (e.g. when mouse cursor is right of the screen). - clipboard: automatically transform \n into \n\r or equivalent for higher compatibility on windows - portability: big-endian test/support (github issue #81) - - misc: provide a way to compile out the entire implementation while providing a dummy API (e.g. #define IMGUI_DUMMY_IMPL - - misc: not thread-safe + - examples: add History support in the demo console application (pertinent to github issue #68). + - misc: provide a way to compile out the entire implementation while providing a dummy API (e.g. #define IMGUI_DUMMY_IMPL) - misc: double-clicking on title bar to minimize isn't consistent, perhaps move to single-click on left-most collapse icon? - misc: CalcTextSize() could benefit from having 'hide_text_after_double_hash' false by default for external use? - style editor: add a button to output C code. From 5b7ed5432e3b7b059e7e1e9e4577971cc8f26b4e Mon Sep 17 00:00:00 2001 From: ocornut Date: Sun, 28 Dec 2014 16:17:08 +0000 Subject: [PATCH 072/108] CalcTextSize() default third parameter to false because it almost never makes sense to use it from the outside (may obsolete it) --- imgui.cpp | 34 +++++++++++++++++----------------- imgui.h | 2 +- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 2ca4bde3..e180c722 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -247,7 +247,6 @@ - examples: add History support in the demo console application (pertinent to github issue #68). - misc: provide a way to compile out the entire implementation while providing a dummy API (e.g. #define IMGUI_DUMMY_IMPL) - misc: double-clicking on title bar to minimize isn't consistent, perhaps move to single-click on left-most collapse icon? - - misc: CalcTextSize() could benefit from having 'hide_text_after_double_hash' false by default for external use? - style editor: add a button to output C code. - optimization/render: use indexed rendering to reduce vertex data cost (for remote/networked imgui) - optimization/render: move clip-rect to vertex data? would allow merging all commands @@ -1018,7 +1017,7 @@ void ImGuiTextFilter::Draw(const char* label, float width) ImGuiWindow* window = GetCurrentWindow(); if (width < 0.0f) { - ImVec2 label_size = ImGui::CalcTextSize(label, NULL); + ImVec2 label_size = ImGui::CalcTextSize(label, NULL, true); width = ImMax(window->Pos.x + ImGui::GetContentRegionMax().x - window->DC.CursorPos.x - (label_size.x + GImGui.Style.ItemSpacing.x*4), 10.0f); } ImGui::PushItemWidth(width); @@ -2545,7 +2544,7 @@ bool ImGui::Begin(const char* name, bool* p_opened, ImVec2 size, float fill_alph if (p_opened != NULL) CloseWindowButton(p_opened); - const ImVec2 text_size = CalcTextSize(name); + const ImVec2 text_size = CalcTextSize(name, NULL, true); const ImVec2 text_min = window->Pos + style.FramePadding + ImVec2(window->FontSize() + style.ItemInnerSpacing.x, 0.0f); const ImVec2 text_max = window->Pos + ImVec2(window->Size.x - (p_opened ? (title_bar_aabb.GetHeight()-3) : style.FramePadding.x), style.FramePadding.y + text_size.y); const bool clip_title = text_size.x > (text_max.x - text_min.x); // only push a clip rectangle if we need to, because it may turn into a separate draw call @@ -3244,7 +3243,7 @@ void ImGui::LabelTextV(const char* label, const char* fmt, va_list args) const char* text_begin = &buf[0]; const char* text_end = text_begin + ImFormatStringV(buf, IM_ARRAYSIZE(buf), fmt, args); - const ImVec2 text_size = CalcTextSize(label); + const ImVec2 text_size = CalcTextSize(label, NULL, true); const ImGuiAabb value_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(w + style.FramePadding.x*2, text_size.y)); const ImGuiAabb bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(w + style.FramePadding.x*2 + style.ItemInnerSpacing.x, 0.0f) + text_size); ItemSize(bb); @@ -3319,7 +3318,7 @@ bool ImGui::Button(const char* label, ImVec2 size, bool repeat_when_held) const ImGuiStyle& style = g.Style; const ImGuiID id = window->GetID(label); - const ImVec2 text_size = CalcTextSize(label); + const ImVec2 text_size = CalcTextSize(label, NULL, true); if (size.x == 0.0f) size.x = text_size.x; if (size.y == 0.0f) @@ -3359,7 +3358,8 @@ bool ImGui::SmallButton(const char* label) const ImGuiStyle& style = g.Style; const ImGuiID id = window->GetID(label); - const ImGuiAabb bb(window->DC.CursorPos, window->DC.CursorPos+CalcTextSize(label) + ImVec2(style.FramePadding.x*2,0)); + const ImVec2 text_size = CalcTextSize(label, NULL, true); + const ImGuiAabb bb(window->DC.CursorPos, window->DC.CursorPos + text_size + ImVec2(style.FramePadding.x*2,0)); ItemSize(bb); if (ClipAdvance(bb)) @@ -3505,7 +3505,7 @@ bool ImGui::CollapsingHeader(const char* label, const char* str_id, const bool d // Framed header expand a little outside the default padding const ImVec2 window_padding = window->WindowPadding(); - const ImVec2 text_size = CalcTextSize(label); + const ImVec2 text_size = CalcTextSize(label, NULL, true); const ImVec2 pos_min = window->DC.CursorPos; const ImVec2 pos_max = window->Pos + GetContentRegionMax(); ImGuiAabb bb = ImGuiAabb(pos_min, ImVec2(pos_max.x, pos_min.y + text_size.y)); @@ -3570,7 +3570,7 @@ void ImGui::BulletTextV(const char* fmt, va_list args) const char* text_end = text_begin + ImFormatStringV(buf, IM_ARRAYSIZE(buf), fmt, args); const float line_height = window->FontSize(); - const ImVec2 text_size = CalcTextSize(text_begin, text_end); + const ImVec2 text_size = CalcTextSize(text_begin, text_end, true); const ImGuiAabb bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(line_height + (text_size.x > 0.0f ? (g.Style.FramePadding.x*2) : 0.0f),0) + text_size); // Empty text doesn't add padding ItemSize(bb); @@ -3772,7 +3772,7 @@ bool ImGui::SliderFloat(const char* label, float* v, float v_min, float v_max, c } } - const ImVec2 text_size = CalcTextSize(label); + const ImVec2 text_size = CalcTextSize(label, NULL, true); const ImGuiAabb frame_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(w, text_size.y) + style.FramePadding*2.0f); const ImGuiAabb slider_bb(frame_bb.Min+g.Style.FramePadding, frame_bb.Max-g.Style.FramePadding); const ImGuiAabb bb(frame_bb.Min, frame_bb.Max + ImVec2(style.ItemInnerSpacing.x + text_size.x, 0.0f)); @@ -3953,7 +3953,7 @@ bool ImGui::SliderFloat(const char* label, float* v, float v_min, float v_max, c // Draw value using user-provided display format so user can add prefix/suffix/decorations to the value. char value_buf[64]; ImFormatString(value_buf, IM_ARRAYSIZE(value_buf), display_format, *v); - RenderText(ImVec2(slider_bb.GetCenter().x-CalcTextSize(value_buf).x*0.5f, frame_bb.Min.y + style.FramePadding.y), value_buf); + RenderText(ImVec2(slider_bb.GetCenter().x-CalcTextSize(value_buf, NULL, true).x*0.5f, frame_bb.Min.y + style.FramePadding.y), value_buf); RenderText(ImVec2(frame_bb.Max.x + style.ItemInnerSpacing.x, slider_bb.Min.y), label); @@ -4044,7 +4044,7 @@ static void Plot(ImGuiPlotType plot_type, const char* label, float (*values_gett const ImGuiStyle& style = g.Style; - const ImVec2 text_size = ImGui::CalcTextSize(label); + const ImVec2 text_size = ImGui::CalcTextSize(label, NULL, true); if (graph_size.x == 0.0f) graph_size.x = window->DC.ItemWidth.back(); if (graph_size.y == 0.0f) @@ -4127,7 +4127,7 @@ static void Plot(ImGuiPlotType plot_type, const char* label, float (*values_gett // Text overlay if (overlay_text) - RenderText(ImVec2(graph_bb.GetCenter().x - ImGui::CalcTextSize(overlay_text).x*0.5f, frame_bb.Min.y + style.FramePadding.y), overlay_text); + RenderText(ImVec2(graph_bb.GetCenter().x - ImGui::CalcTextSize(overlay_text, NULL, true).x*0.5f, frame_bb.Min.y + style.FramePadding.y), overlay_text); RenderText(ImVec2(frame_bb.Max.x + style.ItemInnerSpacing.x, graph_bb.Min.y), label); } @@ -4179,7 +4179,7 @@ bool ImGui::Checkbox(const char* label, bool* v) const ImGuiStyle& style = g.Style; const ImGuiID id = window->GetID(label); - const ImVec2 text_size = CalcTextSize(label); + const ImVec2 text_size = CalcTextSize(label, NULL, true); const ImGuiAabb check_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(text_size.y + style.FramePadding.y*2, text_size.y + style.FramePadding.y*2)); ItemSize(check_bb); @@ -4238,7 +4238,7 @@ bool ImGui::RadioButton(const char* label, bool active) const ImGuiStyle& style = g.Style; const ImGuiID id = window->GetID(label); - const ImVec2 text_size = CalcTextSize(label); + const ImVec2 text_size = CalcTextSize(label, NULL, true); const ImGuiAabb check_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(text_size.y + style.FramePadding.y*2-1, text_size.y + style.FramePadding.y*2-1)); ItemSize(check_bb); @@ -4437,7 +4437,7 @@ bool ImGui::InputFloat(const char* label, float *v, float step, float step_fast, const ImGuiStyle& style = g.Style; const float w = window->DC.ItemWidth.back(); - const ImVec2 text_size = CalcTextSize(label); + const ImVec2 text_size = CalcTextSize(label, NULL, true); const ImGuiAabb frame_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(w, text_size.y) + style.FramePadding*2.0f); ImGui::PushID(label); @@ -4546,7 +4546,7 @@ bool ImGui::InputText(const char* label, char* buf, size_t buf_size, ImGuiInputT const ImGuiID id = window->GetID(label); const float w = window->DC.ItemWidth.back(); - const ImVec2 text_size = CalcTextSize(label); + const ImVec2 text_size = CalcTextSize(label, NULL, true); const ImGuiAabb frame_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(w, text_size.y) + style.FramePadding*2.0f); const ImGuiAabb bb(frame_bb.Min, frame_bb.Max + ImVec2(style.ItemInnerSpacing.x + text_size.x, 0.0f)); ItemSize(bb); @@ -4939,7 +4939,7 @@ bool ImGui::Combo(const char* label, int* current_item, bool (*items_getter)(voi const ImGuiStyle& style = g.Style; const ImGuiID id = window->GetID(label); - const ImVec2 text_size = CalcTextSize(label); + const ImVec2 text_size = CalcTextSize(label, NULL, true); const ImGuiAabb frame_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(window->DC.ItemWidth.back(), text_size.y) + style.FramePadding*2.0f); ItemSize(frame_bb); diff --git a/imgui.h b/imgui.h index a37d128c..1cf9e730 100644 --- a/imgui.h +++ b/imgui.h @@ -303,7 +303,7 @@ namespace ImGui IMGUI_API int GetFrameCount(); IMGUI_API const char* GetStyleColorName(ImGuiCol idx); IMGUI_API void GetDefaultFontData(const void** fnt_data, unsigned int* fnt_size, const void** png_data, unsigned int* png_size); - IMGUI_API ImVec2 CalcTextSize(const char* text, const char* text_end = NULL, bool hide_text_after_double_hash = true, float wrap_width = -1.0f); + IMGUI_API ImVec2 CalcTextSize(const char* text, const char* text_end = NULL, bool hide_text_after_double_hash = false, float wrap_width = -1.0f); } // namespace ImGui From e2fbbe02744a8974d03e80341f8faba3ad6b2fdc Mon Sep 17 00:00:00 2001 From: ocornut Date: Sun, 28 Dec 2014 17:54:02 +0000 Subject: [PATCH 073/108] Factoring bits out of Begin() into a private CreateNewWindow() funciton (Hopefully to ease a bit the merging work for ProDBG) --- imgui.cpp | 123 +++++++++++++++++++++++++++++------------------------- imgui.h | 4 +- 2 files changed, 67 insertions(+), 60 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index e180c722..bdd78183 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -303,7 +303,6 @@ static bool IsKeyPressedMap(ImGuiKey key, bool repeat = true); static bool CloseWindowButton(bool* p_opened = NULL); static void FocusWindow(ImGuiWindow* window); -static ImGuiWindow* FindWindow(const char* name); static ImGuiWindow* FindHoveredWindow(ImVec2 pos, bool excluding_childs); //----------------------------------------------------------------------------- @@ -2060,15 +2059,6 @@ int ImGui::GetFrameCount() return GImGui.FrameCount; } -static ImGuiWindow* FindWindow(const char* name) -{ - ImGuiState& g = GImGui; - for (size_t i = 0; i != g.Windows.size(); i++) - if (strcmp(g.Windows[i]->Name, name) == 0) - return g.Windows[i]; - return NULL; -} - void ImGui::BeginTooltip() { ImGui::Begin("##Tooltip", NULL, ImVec2(0,0), 0.9f, ImGuiWindowFlags_NoTitleBar|ImGuiWindowFlags_NoMove|ImGuiWindowFlags_NoResize|ImGuiWindowFlags_NoSavedSettings|ImGuiWindowFlags_Tooltip); @@ -2138,6 +2128,64 @@ void ImGui::EndChild() } } +static ImGuiWindow* FindWindowByName(const char* name) +{ + // FIXME-OPT: Consider optimizing this (e.g. sorted hashes to window pointers) + ImGuiState& g = GImGui; + for (size_t i = 0; i != g.Windows.size(); i++) + if (strcmp(g.Windows[i]->Name, name) == 0) + return g.Windows[i]; + return NULL; +} + +static ImGuiWindow* CreateNewWindow(const char* name, ImVec2 size, ImGuiWindowFlags flags) +{ + ImGuiState& g = GImGui; + + // Create window the first time + ImGuiWindow* window = (ImGuiWindow*)ImGui::MemAlloc(sizeof(ImGuiWindow)); + new(window) ImGuiWindow(name); + window->Flags = flags; + + if (flags & ImGuiWindowFlags_NoSavedSettings) + { + // User can disable loading and saving of settings. Tooltip and child windows also don't store settings. + window->Size = window->SizeFull = size; + } + else + { + // Retrieve settings from .ini file + // Use SetWindowPos() or SetNextWindowPos() with the appropriate condition flag to change the initial position of a window. + window->PosFloat = ImVec2(60, 60); + window->Pos = ImVec2((float)(int)window->PosFloat.x, (float)(int)window->PosFloat.y); + + ImGuiIniData* settings = FindWindowSettings(name); + if (!settings) + { + settings = AddWindowSettings(name); + } + else + { + window->SetWindowPosAllowFlags &= ~ImGuiSetCondition_FirstUseEver; + window->SetWindowSizeAllowFlags &= ~ImGuiSetCondition_FirstUseEver; + window->SetWindowCollapsedAllowFlags &= ~ImGuiSetCondition_FirstUseEver; + } + + if (settings->Pos.x != FLT_MAX) + { + window->PosFloat = settings->Pos; + window->Pos = ImVec2((float)(int)window->PosFloat.x, (float)(int)window->PosFloat.y); + window->Collapsed = settings->Collapsed; + } + + if (ImLength(settings->Size) > 0.0f && !(flags & ImGuiWindowFlags_NoResize)) + size = settings->Size; + window->Size = window->SizeFull = size; + } + g.Windows.push_back(window); + return window; +} + // Push a new ImGui window to add widgets to. // - A default window called "Debug" is automatically stacked at the beginning of every frame. // - This can be called multiple times during the frame with the same window name to append content to the same window. @@ -2152,54 +2200,13 @@ bool ImGui::Begin(const char* name, bool* p_opened, ImVec2 size, float fill_alph IM_ASSERT(g.Initialized); // Forgot to call ImGui::NewFrame() IM_ASSERT(name != NULL); // Must pass a name - ImGuiWindow* window = FindWindow(name); + // Find or create + ImGuiWindow* window = FindWindowByName(name); if (!window) - { - // Create window the first time - if (flags & ImGuiWindowFlags_NoSavedSettings) - { - // Tooltip and child windows don't store settings - window = (ImGuiWindow*)ImGui::MemAlloc(sizeof(ImGuiWindow)); - new(window) ImGuiWindow(name); - - window->Size = window->SizeFull = size; - } - else - { - // Normal windows store settings in .ini file - window = (ImGuiWindow*)ImGui::MemAlloc(sizeof(ImGuiWindow)); - new(window) ImGuiWindow(name); - - window->PosFloat = ImVec2(60, 60); - window->Pos = ImVec2((float)(int)window->PosFloat.x, (float)(int)window->PosFloat.y); - - ImGuiIniData* settings = FindWindowSettings(name); - if (!settings) - { - settings = AddWindowSettings(name); - } - else - { - window->SetWindowPosAllowFlags &= ~ImGuiSetCondition_FirstUseEver; - window->SetWindowSizeAllowFlags &= ~ImGuiSetCondition_FirstUseEver; - window->SetWindowCollapsedAllowFlags &= ~ImGuiSetCondition_FirstUseEver; - } - - if (settings->Pos.x != FLT_MAX) - { - window->PosFloat = settings->Pos; - window->Pos = ImVec2((float)(int)window->PosFloat.x, (float)(int)window->PosFloat.y); - window->Collapsed = settings->Collapsed; - } - - if (ImLength(settings->Size) > 0.0f && !(flags & ImGuiWindowFlags_NoResize)) - size = settings->Size; - window->Size = window->SizeFull = size; - } - g.Windows.push_back(window); - } + window = CreateNewWindow(name, size, flags); window->Flags = (ImGuiWindowFlags)flags; + // Add to stack g.CurrentWindowStack.push_back(window); g.CurrentWindow = window; @@ -2222,7 +2229,7 @@ bool ImGui::Begin(const char* name, bool* p_opened, ImVec2 size, float fill_alph g.SetNextWindowCollapsedCond = 0; } - // Find root + // Find root (if we are a child window) size_t root_idx = g.CurrentWindowStack.size() - 1; while (root_idx > 0) { @@ -3358,7 +3365,7 @@ bool ImGui::SmallButton(const char* label) const ImGuiStyle& style = g.Style; const ImGuiID id = window->GetID(label); - const ImVec2 text_size = CalcTextSize(label, NULL, true); + const ImVec2 text_size = CalcTextSize(label, NULL, true); const ImGuiAabb bb(window->DC.CursorPos, window->DC.CursorPos + text_size + ImVec2(style.FramePadding.x*2,0)); ItemSize(bb); @@ -4947,7 +4954,7 @@ bool ImGui::Combo(const char* label, int* current_item, bool (*items_getter)(voi return false; const ImGuiAabb bb(frame_bb.Min, frame_bb.Max + ImVec2(style.ItemInnerSpacing.x + text_size.x,0)); - const float arrow_size = (window->FontSize() + style.FramePadding.x * 2.0f); + const float arrow_size = (window->FontSize() + style.FramePadding.x * 2.0f); const bool hovered = (g.HoveredWindow == window) && (g.HoveredId == 0) && IsMouseHoveringBox(bb); bool value_changed = false; diff --git a/imgui.h b/imgui.h index 1cf9e730..1272704d 100644 --- a/imgui.h +++ b/imgui.h @@ -161,10 +161,10 @@ namespace ImGui IMGUI_API ImVec2 GetWindowSize(); // get current window position. IMGUI_API float GetWindowWidth(); IMGUI_API bool GetWindowCollapsed(); - IMGUI_API void SetWindowPos(const ImVec2& pos, ImGuiSetCondition cond = 0); // set current window position. + IMGUI_API void SetWindowPos(const ImVec2& pos, ImGuiSetCondition cond = 0); // set current window position - call within Begin()/End(). IMGUI_API void SetWindowSize(const ImVec2& size, ImGuiSetCondition cond = 0); // set current window size. set to ImVec2(0,0) to force an auto-fit IMGUI_API void SetWindowCollapsed(bool collapsed, ImGuiSetCondition cond = 0); // set current window collapsed state. - IMGUI_API void SetNextWindowPos(const ImVec2& pos, ImGuiSetCondition cond = 0); // set next window position. + IMGUI_API void SetNextWindowPos(const ImVec2& pos, ImGuiSetCondition cond = 0); // set next window position - call before Begin(). IMGUI_API void SetNextWindowSize(const ImVec2& size, ImGuiSetCondition cond = 0); // set next window size. set to ImVec2(0,0) to force an auto-fit IMGUI_API void SetNextWindowCollapsed(bool collapsed, ImGuiSetCondition cond = 0); // set next window collapsed state. From 8994f2f1e4d1b20366c98e8088f639c429025412 Mon Sep 17 00:00:00 2001 From: ocornut Date: Mon, 29 Dec 2014 11:23:03 +0000 Subject: [PATCH 074/108] Cleanup. Removed unnecessary calls to sqrtf(). Factoring bits into ImLoadFileToMemory(). Added index of static helpers. --- imgui.cpp | 191 +++++++++++++++++++++++++++--------------------------- 1 file changed, 97 insertions(+), 94 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index bdd78183..13b5c86a 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -273,10 +273,11 @@ #pragma warning (disable: 4996) // 'This function or variable may be unsafe': strcpy, strdup, sprintf, vsnprintf, sscanf, fopen #endif +// Clang warnings with -Weverything #ifdef __clang__ -#pragma clang diagnostic ignored "-Wold-style-cast" // warning : use of old-style cast // yes, they are more terse and not scary looking. +#pragma clang diagnostic ignored "-Wold-style-cast" // warning : use of old-style cast // yes, they are more terse. #pragma clang diagnostic ignored "-Wfloat-equal" // warning : comparing floating point with == or != is unsafe // storing and comparing against same constants ok. -#pragma clang diagnostic ignored "-Wformat-nonliteral" // warning : format string is not a string literal // passing non-literal to vsnformat(). yes, user passing incorrect format strings can crash the code, thank you. +#pragma clang diagnostic ignored "-Wformat-nonliteral" // warning : format string is not a string literal // passing non-literal to vsnformat(). yes, user passing incorrect format strings can crash the code. #pragma clang diagnostic ignored "-Wexit-time-destructors" // warning : declaration requires an exit-time destructor // exit-time destruction order is undefined. if MemFree() leads to users code that has been disabled before exit it might cause problems. ImGui coding style welcomes static/globals. #pragma clang diagnostic ignored "-Wglobal-constructors" // warning : declaration requires a global destructor // similar to above, not sure what the exact difference it. #endif @@ -305,6 +306,32 @@ static bool CloseWindowButton(bool* p_opened = NULL); static void FocusWindow(ImGuiWindow* window); static ImGuiWindow* FindHoveredWindow(ImVec2 pos, bool excluding_childs); +// Helpers: String +static int ImStricmp(const char* str1, const char* str2); +static int ImStrnicmp(const char* str1, const char* str2, int count); +static char* ImStrdup(const char *str); +static size_t ImStrlenW(const ImWchar* str); +static const char* ImStristr(const char* haystack, const char* needle, const char* needle_end); +static size_t ImFormatString(char* buf, size_t buf_size, const char* fmt, ...); +static size_t ImFormatStringV(char* buf, size_t buf_size, const char* fmt, va_list args); + +// Helpers: Data +static ImU32 ImCrc32(const void* data, size_t data_size, ImU32 seed); +static bool ImLoadFileToMemory(const char* filename, const char* file_open_mode, void** out_file_data, size_t* out_file_size); + +// Helpers: Color Conversion +static ImU32 ImConvertColorFloat4ToU32(const ImVec4& in); +static void ImConvertColorRGBtoHSV(float r, float g, float b, float& out_h, float& out_s, float& out_v); +static void ImConvertColorHSVtoRGB(float h, float s, float v, float& out_r, float& out_g, float& out_b); + +// Helpers: UTF-8 <> wchar +static int ImTextCharToUtf8(char* buf, size_t buf_size, unsigned int in_char); // return output UTF-8 bytes count +static ptrdiff_t ImTextStrToUtf8(char* buf, size_t buf_size, const ImWchar* in_text, const ImWchar* in_text_end); // return output UTF-8 bytes count +static int ImTextCharFromUtf8(unsigned int* out_char, const char* in_text, const char* in_text_end); // return input UTF-8 bytes count +static ptrdiff_t ImTextStrFromUtf8(ImWchar* buf, size_t buf_size, const char* in_text, const char* in_text_end); // return input UTF-8 bytes count +static int ImTextCountCharsFromUtf8(const char* in_text, const char* in_text_end); // return number of UTF-8 code-points (NOT bytes count) +static int ImTextCountUtf8BytesFromWchar(const ImWchar* in_text, const ImWchar* in_text_end); // return number of bytes to express string as UTF-8 code-points + //----------------------------------------------------------------------------- // Platform dependent default implementations //----------------------------------------------------------------------------- @@ -394,7 +421,7 @@ ImGuiIO::ImGuiIO() MemAllocFn = malloc; MemReallocFn = realloc; MemFreeFn = free; - GetClipboardTextFn = GetClipboardTextFn_DefaultImpl; // Platform dependant default implementations + GetClipboardTextFn = GetClipboardTextFn_DefaultImpl; // Platform dependent default implementations SetClipboardTextFn = SetClipboardTextFn_DefaultImpl; ImeSetInputScreenPosFn = NULL; } @@ -402,7 +429,6 @@ ImGuiIO::ImGuiIO() // Pass in translated ASCII characters for text input. // - with glfw you can get those from the callback set in glfwSetCharCallback() // - on Windows you can get those using ToAscii+keyboard state, or via the VM_CHAR message -static size_t ImStrlenW(const ImWchar* str); void ImGuiIO::AddInputCharacter(ImWchar c) { const size_t n = ImStrlenW(InputCharacters); @@ -451,16 +477,8 @@ static inline float ImClamp(float f, float mn, float mx) static inline ImVec2 ImClamp(const ImVec2& f, const ImVec2& mn, ImVec2 mx) { return ImVec2(ImClamp(f.x,mn.x,mx.x), ImClamp(f.y,mn.y,mx.y)); } static inline float ImSaturate(float f) { return (f < 0.0f) ? 0.0f : (f > 1.0f) ? 1.0f : f; } static inline float ImLerp(float a, float b, float t) { return a + (b - a) * t; } -//static inline ImVec2 ImLerp(const ImVec2& a, const ImVec2& b, float t) { return a + (b - a) * t; } static inline ImVec2 ImLerp(const ImVec2& a, const ImVec2& b, const ImVec2& t) { return ImVec2(a.x + (b.x - a.x) * t.x, a.y + (b.y - a.y) * t.y); } -static inline float ImLength(const ImVec2& lhs) { return sqrtf(lhs.x*lhs.x + lhs.y*lhs.y); } - -static int ImTextCharToUtf8(char* buf, size_t buf_size, unsigned int in_char); // return output UTF-8 bytes count -static ptrdiff_t ImTextStrToUtf8(char* buf, size_t buf_size, const ImWchar* in_text, const ImWchar* in_text_end); // return output UTF-8 bytes count -static int ImTextCharFromUtf8(unsigned int* out_char, const char* in_text, const char* in_text_end); // return input UTF-8 bytes count -static ptrdiff_t ImTextStrFromUtf8(ImWchar* buf, size_t buf_size, const char* in_text, const char* in_text_end); // return input UTF-8 bytes count -static int ImTextCountCharsFromUtf8(const char* in_text, const char* in_text_end); // return number of UTF-8 code-points (NOT bytes count) -static int ImTextCountUtf8BytesFromWchar(const ImWchar* in_text, const ImWchar* in_text_end); // return number of bytes to express string as UTF-8 code-points +static inline float ImLengthSqr(const ImVec2& lhs) { return lhs.x*lhs.x + lhs.y*lhs.y; } static int ImStricmp(const char* str1, const char* str2) { @@ -514,7 +532,7 @@ static const char* ImStristr(const char* haystack, const char* needle, const cha return NULL; } -static ImU32 crc32(const void* data, size_t data_size, ImU32 seed = 0) +static ImU32 ImCrc32(const void* data, size_t data_size, ImU32 seed = 0) { static ImU32 crc32_lut[256] = { 0 }; if (!crc32_lut[1]) @@ -612,6 +630,46 @@ static void ImConvertColorHSVtoRGB(float h, float s, float v, float& out_r, floa } } +// Load file content into memory +// Memory allocated with ImGui::MemAlloc(), must be freed by user using ImGui::MemFree() +static bool ImLoadFileToMemory(const char* filename, const char* file_open_mode, void** out_file_data, size_t* out_file_size) +{ + IM_ASSERT(filename && file_open_mode && out_file_data && out_file_size); + *out_file_data = NULL; + *out_file_size = 0; + + FILE* f; + if ((f = fopen(filename, file_open_mode)) == NULL) + return false; + + long file_size_signed; + if (fseek(f, 0, SEEK_END) || (file_size_signed = ftell(f)) == -1 || fseek(f, 0, SEEK_SET)) + { + fclose(f); + return false; + } + + size_t file_size = (size_t)file_size_signed; + void* file_data = ImGui::MemAlloc(file_size); + if (file_data == NULL) + { + fclose(f); + return false; + } + if (fread(file_data, 1, file_size, f) != file_size) + { + fclose(f); + ImGui::MemFree(file_data); + return false; + } + + fclose(f); + *out_file_data = file_data; + *out_file_size = file_size; + + return true; +} + //----------------------------------------------------------------------------- struct ImGuiColMod // Color modifier, backup of modified data so we can restore it @@ -1143,7 +1201,7 @@ ImGuiWindow::ImGuiWindow(const char* name) ItemWidthDefault = 0.0f; FontWindowScale = 1.0f; - if (ImLength(Size) < 0.001f) + if (ImLengthSqr(Size) < 0.00001f) { AutoFitFrames = 2; AutoFitOnlyGrows = true; @@ -1169,7 +1227,7 @@ ImGuiWindow::~ImGuiWindow() ImGuiID ImGuiWindow::GetID(const char* str) { const ImGuiID seed = IDStack.empty() ? 0 : IDStack.back(); - const ImGuiID id = crc32(str, strlen(str), seed); // FIXME-OPT: crc32 function/variant should handle zero-terminated strings + const ImGuiID id = ImCrc32(str, strlen(str), seed); // FIXME-OPT: crc32 function/variant should handle zero-terminated strings RegisterAliveId(id); return id; } @@ -1177,7 +1235,7 @@ ImGuiID ImGuiWindow::GetID(const char* str) ImGuiID ImGuiWindow::GetID(const void* ptr) { const ImGuiID seed = IDStack.empty() ? 0 : IDStack.back(); - const ImGuiID id = crc32(&ptr, sizeof(void*), seed); + const ImGuiID id = ImCrc32(&ptr, sizeof(void*), seed); RegisterAliveId(id); return id; } @@ -1287,40 +1345,14 @@ static void LoadSettings() if (!filename) return; - // Load file - FILE* f; - if ((f = fopen(filename, "rt")) == NULL) + char* file_data; + size_t file_size; + if (!ImLoadFileToMemory(filename, "rb", (void**)&file_data, &file_size)) return; - if (fseek(f, 0, SEEK_END)) - { - fclose(f); - return; - } - const long f_size_signed = ftell(f); - if (f_size_signed == -1) - { - fclose(f); - return; - } - size_t f_size = (size_t)f_size_signed; - if (fseek(f, 0, SEEK_SET)) - { - fclose(f); - return; - } - char* f_data = (char*)ImGui::MemAlloc(f_size+1); - f_size = fread(f_data, 1, f_size, f); // Text conversion alter read size so let's not be fussy about return value - fclose(f); - if (f_size == 0) - { - ImGui::MemFree(f_data); - return; - } - f_data[f_size] = 0; ImGuiIniData* settings = NULL; - const char* buf_end = f_data + f_size; - for (const char* line_start = f_data; line_start < buf_end; ) + const char* buf_end = file_data + file_size; + for (const char* line_start = file_data; line_start < buf_end; ) { const char* line_end = line_start; while (line_end < buf_end && *line_end != '\n' && *line_end != '\r') @@ -1349,7 +1381,7 @@ static void LoadSettings() line_start = line_end+1; } - ImGui::MemFree(f_data); + ImGui::MemFree(file_data); } static void SaveSettings() @@ -1468,7 +1500,7 @@ void ImGui::NewFrame() { if (g.Time - g.IO.MouseClickedTime[i] < g.IO.MouseDoubleClickTime) { - if (ImLength(g.IO.MousePos - g.IO.MouseClickedPos[i]) < g.IO.MouseDoubleClickMaxDist) + if (ImLengthSqr(g.IO.MousePos - g.IO.MouseClickedPos[i]) < g.IO.MouseDoubleClickMaxDist * g.IO.MouseDoubleClickMaxDist) g.IO.MouseDoubleClicked[i] = true; g.IO.MouseClickedTime[i] = -FLT_MAX; // so the third click isn't turned into a double-click } @@ -2149,13 +2181,13 @@ static ImGuiWindow* CreateNewWindow(const char* name, ImVec2 size, ImGuiWindowFl if (flags & ImGuiWindowFlags_NoSavedSettings) { - // User can disable loading and saving of settings. Tooltip and child windows also don't store settings. + // User can disable loading and saving of settings. Tooltip and child windows also don't store settings. window->Size = window->SizeFull = size; } else { // Retrieve settings from .ini file - // Use SetWindowPos() or SetNextWindowPos() with the appropriate condition flag to change the initial position of a window. + // Use SetWindowPos() or SetNextWindowPos() with the appropriate condition flag to change the initial position of a window. window->PosFloat = ImVec2(60, 60); window->Pos = ImVec2((float)(int)window->PosFloat.x, (float)(int)window->PosFloat.y); @@ -2178,7 +2210,7 @@ static ImGuiWindow* CreateNewWindow(const char* name, ImVec2 size, ImGuiWindowFl window->Collapsed = settings->Collapsed; } - if (ImLength(settings->Size) > 0.0f && !(flags & ImGuiWindowFlags_NoResize)) + if (ImLengthSqr(settings->Size) > 0.00001f && !(flags & ImGuiWindowFlags_NoResize)) size = settings->Size; window->Size = window->SizeFull = size; } @@ -2900,16 +2932,17 @@ void ImGui::SetWindowSize(const ImVec2& size, ImGuiSetCondition cond) window->SetWindowSizeAllowFlags &= ~(ImGuiSetCondition_FirstUseThisSession | ImGuiSetCondition_FirstUseEver); // Set - if (ImLength(size) < 0.001f) - { - window->AutoFitFrames = 2; - window->AutoFitOnlyGrows = false; - } - else + if (ImLengthSqr(size) > 0.00001f) { window->SizeFull = size; window->AutoFitFrames = 0; } + else + { + // Autofit + window->AutoFitFrames = 2; + window->AutoFitOnlyGrows = false; + } } void ImGui::SetWindowCollapsed(bool collapsed, ImGuiSetCondition cond) @@ -4822,7 +4855,7 @@ bool ImGui::InputText(const char* label, char* buf, size_t buf_size, ImGuiInputT window->DrawList->AddRect(cursor_pos - font_off_up + ImVec2(0,2), cursor_pos + font_off_dn - ImVec2(0,3), window->Color(ImGuiCol_Text)); // Notify OS of text input position - if (io.ImeSetInputScreenPosFn && ImLength(edit_state.LastCursorPos - cursor_pos) > 0.01f) + if (io.ImeSetInputScreenPosFn && ImLengthSqr(edit_state.LastCursorPos - cursor_pos) > 0.0001f) io.ImeSetInputScreenPosFn((int)cursor_pos.x - 1, (int)(cursor_pos.y - window->FontSize())); // -1 x offset so that Windows IME can cover our cursor. Bit of an extra nicety. edit_state.LastCursorPos = cursor_pos; @@ -5657,7 +5690,8 @@ void ImDrawList::AddVtx(const ImVec2& pos, ImU32 col) void ImDrawList::AddVtxLine(const ImVec2& a, const ImVec2& b, ImU32 col) { const float offset = GImGui.IO.PixelCenterOffset; - const ImVec2 hn = (b - a) * (0.50f / ImLength(b - a)); // half normal + const float length = sqrtf(ImLengthSqr(b - a)); + const ImVec2 hn = (b - a) * (0.50f / length); // half normal const ImVec2 hp0 = ImVec2(offset + hn.y, offset - hn.x); // half perpendiculars + user offset const ImVec2 hp1 = ImVec2(offset - hn.y, offset + hn.x); @@ -5916,46 +5950,15 @@ bool ImFont::LoadFromFile(const char* filename) { IM_ASSERT(!IsLoaded()); // Call Clear() - // Load file - FILE* f; - if ((f = fopen(filename, "rb")) == NULL) + if (!ImLoadFileToMemory(filename, "rb", (void**)&Data, &DataSize)) return false; - if (fseek(f, 0, SEEK_END)) - { - fclose(f); - return false; - } - const long f_size = ftell(f); - if (f_size == -1) - { - fclose(f); - return false; - } - DataSize = (size_t)f_size; - if (fseek(f, 0, SEEK_SET)) - { - fclose(f); - return false; - } - if ((Data = (unsigned char*)ImGui::MemAlloc(DataSize)) == NULL) - { - fclose(f); - return false; - } - if (fread(Data, 1, DataSize, f) != DataSize) - { - fclose(f); - ImGui::MemFree(Data); - return false; - } - fclose(f); DataOwned = true; return LoadFromMemory(Data, DataSize); } bool ImFont::LoadFromMemory(const void* data, size_t data_size) { - IM_ASSERT(!IsLoaded()); // Call Clear() + IM_ASSERT(!IsLoaded()); // Call Clear() Data = (unsigned char*)data; DataSize = data_size; From 0796dc0dc1577fc97097e5827ba96c5d1da82d43 Mon Sep 17 00:00:00 2001 From: ocornut Date: Mon, 29 Dec 2014 18:05:22 +0000 Subject: [PATCH 075/108] Minor fix for cases of malformed .ini file (zero-terminating text file like it was before previous commit). --- imgui.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 13b5c86a..c086968d 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -317,7 +317,7 @@ static size_t ImFormatStringV(char* buf, size_t buf_size, const char* fmt, // Helpers: Data static ImU32 ImCrc32(const void* data, size_t data_size, ImU32 seed); -static bool ImLoadFileToMemory(const char* filename, const char* file_open_mode, void** out_file_data, size_t* out_file_size); +static bool ImLoadFileToMemory(const char* filename, const char* file_open_mode, void** out_file_data, size_t* out_file_size, size_t padding_bytes = 0); // Helpers: Color Conversion static ImU32 ImConvertColorFloat4ToU32(const ImVec4& in); @@ -632,9 +632,10 @@ static void ImConvertColorHSVtoRGB(float h, float s, float v, float& out_r, floa // Load file content into memory // Memory allocated with ImGui::MemAlloc(), must be freed by user using ImGui::MemFree() -static bool ImLoadFileToMemory(const char* filename, const char* file_open_mode, void** out_file_data, size_t* out_file_size) +static bool ImLoadFileToMemory(const char* filename, const char* file_open_mode, void** out_file_data, size_t* out_file_size, size_t padding_bytes) { IM_ASSERT(filename && file_open_mode && out_file_data && out_file_size); + IM_ASSERT(padding_bytes >= 0); *out_file_data = NULL; *out_file_size = 0; @@ -650,7 +651,7 @@ static bool ImLoadFileToMemory(const char* filename, const char* file_open_mode, } size_t file_size = (size_t)file_size_signed; - void* file_data = ImGui::MemAlloc(file_size); + void* file_data = ImGui::MemAlloc(file_size + padding_bytes); if (file_data == NULL) { fclose(f); @@ -662,6 +663,8 @@ static bool ImLoadFileToMemory(const char* filename, const char* file_open_mode, ImGui::MemFree(file_data); return false; } + if (padding_bytes > 0) + memset((void *)(((char*)file_data) + file_size), 0, padding_bytes); fclose(f); *out_file_data = file_data; @@ -1347,7 +1350,7 @@ static void LoadSettings() char* file_data; size_t file_size; - if (!ImLoadFileToMemory(filename, "rb", (void**)&file_data, &file_size)) + if (!ImLoadFileToMemory(filename, "rb", (void**)&file_data, &file_size, 1)) return; ImGuiIniData* settings = NULL; From 1b25fa8169e3aee023ba9fbc3b0dc82bffc36119 Mon Sep 17 00:00:00 2001 From: ocornut Date: Mon, 29 Dec 2014 18:13:41 +0000 Subject: [PATCH 076/108] Added LogFinish() to stop logging at an arbitrary point. --- imgui.cpp | 50 ++++++++++++++++++++++++++++---------------------- imgui.h | 14 ++++++++------ 2 files changed, 36 insertions(+), 28 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index c086968d..6bc176dc 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -635,7 +635,7 @@ static void ImConvertColorHSVtoRGB(float h, float s, float v, float& out_r, floa static bool ImLoadFileToMemory(const char* filename, const char* file_open_mode, void** out_file_data, size_t* out_file_size, size_t padding_bytes) { IM_ASSERT(filename && file_open_mode && out_file_data && out_file_size); - IM_ASSERT(padding_bytes >= 0); + IM_ASSERT(padding_bytes >= 0); *out_file_data = NULL; *out_file_size = 0; @@ -663,8 +663,8 @@ static bool ImLoadFileToMemory(const char* filename, const char* file_open_mode, ImGui::MemFree(file_data); return false; } - if (padding_bytes > 0) - memset((void *)(((char*)file_data) + file_size), 0, padding_bytes); + if (padding_bytes > 0) + memset((void *)(((char*)file_data) + file_size), 0, padding_bytes); fclose(f); *out_file_data = file_data; @@ -2660,25 +2660,7 @@ void ImGui::End() // Stop logging if (!(window->Flags & ImGuiWindowFlags_ChildWindow)) // FIXME: add more options for scope of logging - { - g.LogEnabled = false; - if (g.LogFile != NULL) - { - fprintf(g.LogFile, "\n"); - if (g.LogFile == stdout) - fflush(g.LogFile); - else - fclose(g.LogFile); - g.LogFile = NULL; - } - if (g.LogClipboard->size() > 1) - { - g.LogClipboard->append("\n"); - if (g.IO.SetClipboardTextFn) - g.IO.SetClipboardTextFn(g.LogClipboard->begin()); - g.LogClipboard->clear(); - } - } + ImGui::LogFinish(); // Pop window->RootWindow = NULL; @@ -3487,6 +3469,30 @@ void ImGui::LogToClipboard(int max_depth) g.LogAutoExpandMaxDepth = max_depth; } +void ImGui::LogFinish() +{ + ImGuiState& g = GImGui; + if (!g.LogEnabled) + return; + g.LogEnabled = false; + if (g.LogFile != NULL) + { + fprintf(g.LogFile, "\n"); + if (g.LogFile == stdout) + fflush(g.LogFile); + else + fclose(g.LogFile); + g.LogFile = NULL; + } + if (g.LogClipboard->size() > 1) + { + g.LogClipboard->append("\n"); + if (g.IO.SetClipboardTextFn) + g.IO.SetClipboardTextFn(g.LogClipboard->begin()); + g.LogClipboard->clear(); + } +} + // Helper to display logging buttons void ImGui::LogButtons() { diff --git a/imgui.h b/imgui.h index 1272704d..6082baf8 100644 --- a/imgui.h +++ b/imgui.h @@ -212,6 +212,7 @@ namespace ImGui // ID scopes // If you are creating repeated widgets in a loop you most likely want to push a unique identifier so ImGui can differentiate them. + // You can also use ## within your widget name to distinguish them from each others (see 'Programmer Guide') IMGUI_API void PushID(const char* str_id); // push identifier into the ID stack. IDs are hash of the *entire* stack! IMGUI_API void PushID(const void* ptr_id); IMGUI_API void PushID(const int int_id); @@ -271,7 +272,7 @@ namespace ImGui IMGUI_API void TreePop(); IMGUI_API void OpenNextNode(bool open); // force open/close the next TreeNode or CollapsingHeader - // Value helper output "name: value". tip: freely declare your own within the ImGui namespace! + // Value() Helpers: output single value in "name: value" format. Tip: freely declare your own within the ImGui namespace! IMGUI_API void Value(const char* prefix, bool b); IMGUI_API void Value(const char* prefix, int v); IMGUI_API void Value(const char* prefix, unsigned int v); @@ -279,11 +280,12 @@ namespace ImGui IMGUI_API void Color(const char* prefix, const ImVec4& v); IMGUI_API void Color(const char* prefix, unsigned int v); - // Logging - IMGUI_API void LogButtons(); - IMGUI_API void LogToTTY(int max_depth = -1); - IMGUI_API void LogToFile(int max_depth = -1, const char* filename = NULL); - IMGUI_API void LogToClipboard(int max_depth = -1); + // Logging: All text output can be redirected to tty/file/clipboard. Tree nodes are automatically opened. + IMGUI_API void LogToTTY(int max_depth = -1); // start logging to tty + IMGUI_API void LogToFile(int max_depth = -1, const char* filename = NULL); // start logging to file + IMGUI_API void LogToClipboard(int max_depth = -1); // start logging to OS clipboard + IMGUI_API void LogFinish(); // stop logging (close file, etc.) + IMGUI_API void LogButtons(); // helper to display buttons for logging to tty/file/clipboard // Utilities IMGUI_API bool IsItemHovered(); // was the last item active area hovered by mouse? From 39952d2362591421b3ed9a07b7f6417c858095de Mon Sep 17 00:00:00 2001 From: ocornut Date: Mon, 29 Dec 2014 18:17:54 +0000 Subject: [PATCH 077/108] Renamed GetTreeStateStorage() to GetStateStorage(). Columns storing floats instead of fixed point integers --- imgui.cpp | 16 ++++++++-------- imgui.h | 4 ++-- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 6bc176dc..94f4e864 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -3078,13 +3078,13 @@ void ImGui::SetKeyboardFocusHere(int offset) window->FocusIdxTabRequestNext = IM_INT_MAX; } -void ImGui::SetTreeStateStorage(ImGuiStorage* tree) +void ImGui::SetStateStorage(ImGuiStorage* tree) { ImGuiWindow* window = GetCurrentWindow(); window->DC.StateStorage = tree ? tree : &window->StateStorage; } -ImGuiStorage* ImGui::GetTreeStateStorage() +ImGuiStorage* ImGui::GetStateStorage() { ImGuiWindow* window = GetCurrentWindow(); return window->DC.StateStorage; @@ -3539,17 +3539,17 @@ bool ImGui::CollapsingHeader(const char* label, const char* str_id, const bool d const ImGuiID id = window->GetID(str_id); // We only write to the tree storage if the user clicks - ImGuiStorage* tree = window->DC.StateStorage; + ImGuiStorage* storage = window->DC.StateStorage; bool opened; if (window->DC.OpenNextNode != -1) { opened = window->DC.OpenNextNode > 0; - tree->SetInt(id, opened); + storage->SetInt(id, opened); window->DC.OpenNextNode = -1; } else { - opened = tree->GetInt(id, default_open) != 0; + opened = storage->GetInt(id, default_open) != 0; } // Framed header expand a little outside the default padding @@ -3582,7 +3582,7 @@ bool ImGui::CollapsingHeader(const char* label, const char* str_id, const bool d if (pressed) { opened = !opened; - tree->SetInt(id, opened); + storage->SetInt(id, opened); } // Render @@ -5444,7 +5444,7 @@ float ImGui::GetColumnOffset(int column_index) const ImGuiID column_id = window->DC.ColumnsSetID + ImGuiID(column_index); RegisterAliveId(column_id); const float default_t = column_index / (float)window->DC.ColumnsCount; - const float t = (float)window->StateStorage.GetInt(column_id, (int)(default_t * 8192)) / 8192; // Cheaply store our floating point value inside the integer (could store an union into the map?) + const float t = window->StateStorage.GetFloat(column_id, default_t); // Cheaply store our floating point value inside the integer (could store an union into the map?) const float offset = window->DC.ColumnsStartX + t * (window->Size.x - g.Style.ScrollBarWidth - window->DC.ColumnsStartX); return offset; @@ -5459,7 +5459,7 @@ void ImGui::SetColumnOffset(int column_index, float offset) const ImGuiID column_id = window->DC.ColumnsSetID + ImGuiID(column_index); const float t = (offset - window->DC.ColumnsStartX) / (window->Size.x - g.Style.ScrollBarWidth - window->DC.ColumnsStartX); - window->StateStorage.SetInt(column_id, (int)(t*8192)); + window->StateStorage.SetFloat(column_id, t); } float ImGui::GetColumnWidth(int column_index) diff --git a/imgui.h b/imgui.h index 6082baf8..14a0e4c0 100644 --- a/imgui.h +++ b/imgui.h @@ -170,8 +170,8 @@ namespace ImGui IMGUI_API void SetScrollPosHere(); // adjust scrolling position to center into the current cursor position. IMGUI_API void SetKeyboardFocusHere(int offset = 0); // focus keyboard on the next widget. Use positive 'offset' to access sub components of a multiple component widget. - IMGUI_API void SetTreeStateStorage(ImGuiStorage* tree); // replace tree state storage with our own (if you want to manipulate it yourself, typically clear subsection of it). - IMGUI_API ImGuiStorage* GetTreeStateStorage(); + IMGUI_API void SetStateStorage(ImGuiStorage* tree); // replace tree state storage with our own (if you want to manipulate it yourself, typically clear subsection of it). + IMGUI_API ImGuiStorage* GetStateStorage(); IMGUI_API void PushItemWidth(float item_width); // width of items for the common item+label case. default to ~2/3 of windows width. IMGUI_API void PopItemWidth(); From 886d954e3df5041e0cf96cc0ae6835bd21d7ea06 Mon Sep 17 00:00:00 2001 From: ocornut Date: Mon, 29 Dec 2014 19:56:01 +0000 Subject: [PATCH 078/108] GetStyleColorName -> GetStyleColName for consistency with type name. Removed ImGuiStyleVar_ColumnsMinSpacing --- imgui.cpp | 7 +++---- imgui.h | 9 ++++----- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 94f4e864..24c8cd34 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -348,13 +348,13 @@ ImGuiStyle::ImGuiStyle() Alpha = 1.0f; // Global alpha applies to everything in ImGui WindowPadding = ImVec2(8,8); // Padding within a window WindowMinSize = ImVec2(48,48); // Minimum window size + WindowRounding = 10.0f; // Radius of window corners rounding. Set to 0.0f to have rectangular windows FramePadding = ImVec2(5,4); // Padding within a framed rectangle (used by most widgets) ItemSpacing = ImVec2(10,5); // Horizontal and vertical spacing between widgets/lines ItemInnerSpacing = ImVec2(5,5); // Horizontal and vertical spacing between within elements of a composed widget (e.g. a slider and its label) TouchExtraPadding = ImVec2(0,0); // Expand bounding box for touch-based system where touch position is not accurate enough (unnecessary for mouse inputs). Unfortunately we don't sort widgets so priority on overlap will always be given to the first widget running. So dont grow this too much! AutoFitPadding = ImVec2(8,8); // Extra space after auto-fit (double-clicking on resize grip) WindowFillAlphaDefault = 0.70f; // Default alpha of window background, if not specified in ImGui::Begin() - WindowRounding = 10.0f; // Radius of window corners rounding. Set to 0.0f to have rectangular windows TreeNodeSpacing = 22.0f; // Horizontal spacing when entering a tree node ColumnsMinSpacing = 6.0f; // Minimum horizontal spacing between two columns ScrollBarWidth = 16.0f; // Width of the vertical scroll bar @@ -2758,7 +2758,6 @@ static float* GetStyleVarFloatAddr(ImGuiStyleVar idx) case ImGuiStyleVar_Alpha: return &g.Style.Alpha; case ImGuiStyleVar_WindowRounding: return &g.Style.WindowRounding; case ImGuiStyleVar_TreeNodeSpacing: return &g.Style.TreeNodeSpacing; - case ImGuiStyleVar_ColumnsMinSpacing: return &g.Style.ColumnsMinSpacing; } return NULL; } @@ -2819,7 +2818,7 @@ void ImGui::PopStyleVar(int count) } } -const char* ImGui::GetStyleColorName(ImGuiCol idx) +const char* ImGui::GetStyleColName(ImGuiCol idx) { // Create switch-case from enum with regexp: ImGuiCol_{.*}, --> case ImGuiCol_\1: return "\1"; switch (idx) @@ -6719,7 +6718,7 @@ void ImGui::ShowStyleEditor(ImGuiStyle* ref) ImGui::ColorEditMode(edit_mode); for (int i = 0; i < ImGuiCol_COUNT; i++) { - const char* name = GetStyleColorName(i); + const char* name = ImGui::GetStyleColName(i); if (!filter.PassFilter(name)) continue; ImGui::PushID(i); diff --git a/imgui.h b/imgui.h index 14a0e4c0..4499f9f2 100644 --- a/imgui.h +++ b/imgui.h @@ -280,11 +280,11 @@ namespace ImGui IMGUI_API void Color(const char* prefix, const ImVec4& v); IMGUI_API void Color(const char* prefix, unsigned int v); - // Logging: All text output can be redirected to tty/file/clipboard. Tree nodes are automatically opened. + // Logging: All text output from your interface are redirected to tty/file/clipboard. Tree nodes are automatically opened. IMGUI_API void LogToTTY(int max_depth = -1); // start logging to tty IMGUI_API void LogToFile(int max_depth = -1, const char* filename = NULL); // start logging to file IMGUI_API void LogToClipboard(int max_depth = -1); // start logging to OS clipboard - IMGUI_API void LogFinish(); // stop logging (close file, etc.) + IMGUI_API void LogFinish(); // stop logging (close file, etc.) IMGUI_API void LogButtons(); // helper to display buttons for logging to tty/file/clipboard // Utilities @@ -303,7 +303,7 @@ namespace ImGui IMGUI_API ImVec2 GetMousePos(); // shortcut to ImGui::GetIO().MousePos provided by user, to be consistent with other calls IMGUI_API float GetTime(); IMGUI_API int GetFrameCount(); - IMGUI_API const char* GetStyleColorName(ImGuiCol idx); + IMGUI_API const char* GetStyleColName(ImGuiCol idx); IMGUI_API void GetDefaultFontData(const void** fnt_data, unsigned int* fnt_size, const void** png_data, unsigned int* png_size); IMGUI_API ImVec2 CalcTextSize(const char* text, const char* text_end = NULL, bool hide_text_after_double_hash = false, float wrap_width = -1.0f); @@ -419,7 +419,6 @@ enum ImGuiStyleVar_ ImGuiStyleVar_ItemSpacing, // ImVec2 ImGuiStyleVar_ItemInnerSpacing, // ImVec2 ImGuiStyleVar_TreeNodeSpacing, // float - ImGuiStyleVar_ColumnsMinSpacing // float }; // Enumeration for ColorEditMode() @@ -445,13 +444,13 @@ struct ImGuiStyle float Alpha; // Global alpha applies to everything in ImGui ImVec2 WindowPadding; // Padding within a window ImVec2 WindowMinSize; // Minimum window size + float WindowRounding; // Radius of window corners rounding. Set to 0.0f to have rectangular windows ImVec2 FramePadding; // Padding within a framed rectangle (used by most widgets) ImVec2 ItemSpacing; // Horizontal and vertical spacing between widgets/lines ImVec2 ItemInnerSpacing; // Horizontal and vertical spacing between within elements of a composed widget (e.g. a slider and its label) ImVec2 TouchExtraPadding; // Expand bounding box for touch-based system where touch position is not accurate enough (unnecessary for mouse inputs). Unfortunately we don't sort widgets so priority on overlap will always be given to the first widget running. So dont grow this too much! ImVec2 AutoFitPadding; // Extra space after auto-fit (double-clicking on resize grip) float WindowFillAlphaDefault; // Default alpha of window background, if not specified in ImGui::Begin() - float WindowRounding; // Radius of window corners rounding. Set to 0.0f to have rectangular windows float TreeNodeSpacing; // Horizontal spacing when entering a tree node float ColumnsMinSpacing; // Minimum horizontal spacing between two columns float ScrollBarWidth; // Width of the vertical scroll bar From 036a153cf4e4628792c1e156e64accda4a2dabb8 Mon Sep 17 00:00:00 2001 From: ocornut Date: Mon, 29 Dec 2014 20:18:52 +0000 Subject: [PATCH 079/108] Log depth padding relative to start depth. Tree node and headers looking better when logged to text. Added LogText(). --- imgui.cpp | 87 +++++++++++++++++++++++++++++++++++++++---------------- imgui.h | 2 ++ 2 files changed, 64 insertions(+), 25 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 24c8cd34..814e2e7d 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -861,6 +861,7 @@ struct ImGuiState bool LogEnabled; FILE* LogFile; ImGuiTextBuffer* LogClipboard; // pointer so our GImGui static constructor doesn't call heap allocators. + int LogStartDepth; int LogAutoExpandMaxDepth; ImGuiState() @@ -887,6 +888,7 @@ struct ImGuiState PrivateClipboard = NULL; LogEnabled = false; LogFile = NULL; + LogStartDepth = 0; LogAutoExpandMaxDepth = 2; LogClipboard = NULL; } @@ -1158,23 +1160,24 @@ bool ImGuiTextFilter::PassFilter(const char* val) const //----------------------------------------------------------------------------- // Helper: Text buffer for logging/accumulating text -void ImGuiTextBuffer::append(const char* fmt, ...) +void ImGuiTextBuffer::appendv(const char* fmt, va_list args) { - va_list args; - va_start(args, fmt); - int len = vsnprintf(NULL, 0, fmt, args); - va_end(args); + int len = vsnprintf(NULL, 0, fmt, args); // FIXME-OPT: could do a first pass write attempt, likely successful on first pass. if (len <= 0) return; - const size_t write_off = Buf.size(); if (write_off + (size_t)len >= Buf.capacity()) Buf.reserve(Buf.capacity() * 2); Buf.resize(write_off + (size_t)len); - - va_start(args, fmt); ImFormatStringV(&Buf[write_off] - 1, (size_t)len+1, fmt, args); +} + +void ImGuiTextBuffer::append(const char* fmt, ...) +{ + va_list args; + va_start(args, fmt); + appendv(fmt, args); va_end(args); } @@ -1764,7 +1767,27 @@ static const char* FindTextDisplayEnd(const char* text, const char* text_end = return text_display_end; } -// Log ImGui display into text output (tty or file or clipboard) +// Pass text data straight to log (without being displayed) +void ImGui::LogText(const char* fmt, ...) +{ + ImGuiState& g = GImGui; + if (!g.LogEnabled) + return; + + va_list args; + va_start(args, fmt); + if (g.LogFile) + { + vfprintf(g.LogFile, fmt, args); + } + else + { + g.LogClipboard->appendv(fmt, args); + } + va_end(args); +} + +// Internal version that takes a position to decide on newline placement and pad items according to their depth. static void LogText(const ImVec2& ref_pos, const char* text, const char* text_end) { ImGuiState& g = GImGui; @@ -1777,7 +1800,9 @@ static void LogText(const ImVec2& ref_pos, const char* text, const char* text_en window->DC.LogLineHeight = ref_pos.y; const char* text_remaining = text; - const int tree_depth = window->DC.TreeDepth; + if (g.LogStartDepth > window->DC.TreeDepth) // Re-adjust padding if we have popped out of our starting depth + g.LogStartDepth = window->DC.TreeDepth; + const int tree_depth = (window->DC.TreeDepth - g.LogStartDepth); while (true) { const char* line_end = text_remaining; @@ -1799,20 +1824,10 @@ static void LogText(const ImVec2& ref_pos, const char* text, const char* text_en if (line_end != NULL && !(is_last_line && (line_end - text_remaining)==0)) { const int char_count = (int)(line_end - text_remaining); - if (g.LogFile) - { - if (log_new_line || !is_first_line) - fprintf(g.LogFile, "\n%*s%.*s", tree_depth*4, "", char_count, text_remaining); - else - fprintf(g.LogFile, " %.*s", char_count, text_remaining); - } + if (log_new_line || !is_first_line) + ImGui::LogText("\n%*s%.*s", tree_depth*4, "", char_count, text_remaining); else - { - if (log_new_line || !is_first_line) - g.LogClipboard->append("\n%*s%.*s", tree_depth*4, "", char_count, text_remaining); - else - g.LogClipboard->append(" %.*s", char_count, text_remaining); - } + ImGui::LogText(" %.*s", char_count, text_remaining); } if (is_last_line) @@ -3434,10 +3449,13 @@ static bool CloseWindowButton(bool* p_opened) void ImGui::LogToTTY(int max_depth) { ImGuiState& g = GImGui; + ImGuiWindow* window = GetCurrentWindow(); if (g.LogEnabled) return; + g.LogEnabled = true; g.LogFile = stdout; + g.LogStartDepth = window->DC.TreeDepth; if (max_depth >= 0) g.LogAutoExpandMaxDepth = max_depth; } @@ -3446,12 +3464,15 @@ void ImGui::LogToTTY(int max_depth) void ImGui::LogToFile(int max_depth, const char* filename) { ImGuiState& g = GImGui; + ImGuiWindow* window = GetCurrentWindow(); if (g.LogEnabled) return; if (!filename) filename = g.IO.LogFilename; + g.LogEnabled = true; g.LogFile = fopen(filename, "at"); + g.LogStartDepth = window->DC.TreeDepth; if (max_depth >= 0) g.LogAutoExpandMaxDepth = max_depth; } @@ -3459,11 +3480,14 @@ void ImGui::LogToFile(int max_depth, const char* filename) // Start logging ImGui output to clipboard void ImGui::LogToClipboard(int max_depth) { + ImGuiWindow* window = GetCurrentWindow(); ImGuiState& g = GImGui; if (g.LogEnabled) return; + g.LogEnabled = true; g.LogFile = NULL; + g.LogStartDepth = window->DC.TreeDepth; if (max_depth >= 0) g.LogAutoExpandMaxDepth = max_depth; } @@ -3473,10 +3497,11 @@ void ImGui::LogFinish() ImGuiState& g = GImGui; if (!g.LogEnabled) return; + + ImGui::LogText("\n"); g.LogEnabled = false; if (g.LogFile != NULL) { - fprintf(g.LogFile, "\n"); if (g.LogFile == stdout) fflush(g.LogFile); else @@ -3485,7 +3510,6 @@ void ImGui::LogFinish() } if (g.LogClipboard->size() > 1) { - g.LogClipboard->append("\n"); if (g.IO.SetClipboardTextFn) g.IO.SetClipboardTextFn(g.LogClipboard->begin()); g.LogClipboard->clear(); @@ -3591,7 +3615,18 @@ bool ImGui::CollapsingHeader(const char* label, const char* str_id, const bool d // Framed type RenderFrame(bb.Min, bb.Max, col, true); RenderCollapseTriangle(bb.Min + style.FramePadding, opened, 1.0f, true); + if (g.LogEnabled) + { + // NB: '##' is normally used to hide text (as a library-wide feature), so we need to specify the text range to make sure the ## aren't stripped out here. + const char log_prefix[] = "\n##"; + LogText(bb.Min + style.FramePadding, log_prefix, log_prefix+3); + } RenderText(bb.Min + style.FramePadding + ImVec2(window->FontSize() + style.FramePadding.x*2,0), label); + if (g.LogEnabled) + { + const char log_suffix[] = "##"; + LogText(bb.Min + style.FramePadding, log_suffix, log_suffix+2); + } } else { @@ -3599,6 +3634,8 @@ bool ImGui::CollapsingHeader(const char* label, const char* str_id, const bool d if ((held && hovered) || hovered) RenderFrame(bb.Min, bb.Max, col, false); RenderCollapseTriangle(bb.Min + ImVec2(style.FramePadding.x, window->FontSize()*0.15f), opened, 0.70f, false); + if (g.LogEnabled) + LogText(bb.Min, ">"); RenderText(bb.Min + ImVec2(window->FontSize() + style.FramePadding.x*2,0), label); } diff --git a/imgui.h b/imgui.h index 4499f9f2..2912b6b6 100644 --- a/imgui.h +++ b/imgui.h @@ -286,6 +286,7 @@ namespace ImGui IMGUI_API void LogToClipboard(int max_depth = -1); // start logging to OS clipboard IMGUI_API void LogFinish(); // stop logging (close file, etc.) IMGUI_API void LogButtons(); // helper to display buttons for logging to tty/file/clipboard + IMGUI_API void LogText(const char* fmt, ...); // pass text data straight to log (without being displayed) // Utilities IMGUI_API bool IsItemHovered(); // was the last item active area hovered by mouse? @@ -605,6 +606,7 @@ struct ImGuiTextBuffer bool empty() { return Buf.empty(); } void clear() { Buf.clear(); Buf.push_back(0); } IMGUI_API void append(const char* fmt, ...); + IMGUI_API void appendv(const char* fmt, va_list args); }; // Helper: Key->value storage From 409b1ac6b5d256e0114dcb5fc062910eb445994c Mon Sep 17 00:00:00 2001 From: ocornut Date: Mon, 29 Dec 2014 20:41:27 +0000 Subject: [PATCH 080/108] Log output \r\n under Windows so files are readable with Notepad --- imgui.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 814e2e7d..b53ed414 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -454,6 +454,13 @@ const float PI = 3.14159265358979323846f; #define IM_INT_MAX 2147483647 #endif +// Play it nice with Windows users. Notepad in 2014 still doesn't display text data with Unix-style \n. +#ifdef _MSC_VER +#define STR_NEW_LINE "\r\n" +#else +#define STR_NEW_LINE "\n" +#endif + // Math bits // We are keeping those static in the .cpp file so as not to leak them outside, in the case the user has implicit cast operators between ImVec2 and its own types. static inline ImVec2 operator*(const ImVec2& lhs, const float rhs) { return ImVec2(lhs.x*rhs, lhs.y*rhs); } @@ -1825,7 +1832,7 @@ static void LogText(const ImVec2& ref_pos, const char* text, const char* text_en { const int char_count = (int)(line_end - text_remaining); if (log_new_line || !is_first_line) - ImGui::LogText("\n%*s%.*s", tree_depth*4, "", char_count, text_remaining); + ImGui::LogText(STR_NEW_LINE "%*s%.*s", tree_depth*4, "", char_count, text_remaining); else ImGui::LogText(" %.*s", char_count, text_remaining); } @@ -3471,7 +3478,7 @@ void ImGui::LogToFile(int max_depth, const char* filename) filename = g.IO.LogFilename; g.LogEnabled = true; - g.LogFile = fopen(filename, "at"); + g.LogFile = fopen(filename, "ab"); g.LogStartDepth = window->DC.TreeDepth; if (max_depth >= 0) g.LogAutoExpandMaxDepth = max_depth; @@ -3498,7 +3505,7 @@ void ImGui::LogFinish() if (!g.LogEnabled) return; - ImGui::LogText("\n"); + ImGui::LogText(STR_NEW_LINE); g.LogEnabled = false; if (g.LogFile != NULL) { From a950df6655b5d1eb49b98e7de4dca2d678a1447e Mon Sep 17 00:00:00 2001 From: ocornut Date: Tue, 30 Dec 2014 10:00:00 +0000 Subject: [PATCH 081/108] Tightening default style (saving -2 pixels on each axis per widget) --- imgui.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index b53ed414..32eed5b8 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -66,6 +66,7 @@ - your code creates the UI, if your code doesn't run the UI is gone! == dynamic UI, no construction step, less data retention on your side, no state duplication, less sync, less errors. - see ImGui::ShowTestWindow() for user-side sample code - see examples/ folder for standalone sample applications. + - customization: use the style editor to tweak the look of the interface (e.g. if you want a more compact UI or a different color scheme), and report values in your code. - getting started: - initialisation: call ImGui::GetIO() and fill the 'Settings' data. @@ -348,10 +349,10 @@ ImGuiStyle::ImGuiStyle() Alpha = 1.0f; // Global alpha applies to everything in ImGui WindowPadding = ImVec2(8,8); // Padding within a window WindowMinSize = ImVec2(48,48); // Minimum window size - WindowRounding = 10.0f; // Radius of window corners rounding. Set to 0.0f to have rectangular windows - FramePadding = ImVec2(5,4); // Padding within a framed rectangle (used by most widgets) - ItemSpacing = ImVec2(10,5); // Horizontal and vertical spacing between widgets/lines - ItemInnerSpacing = ImVec2(5,5); // Horizontal and vertical spacing between within elements of a composed widget (e.g. a slider and its label) + WindowRounding = 9.0f; // Radius of window corners rounding. Set to 0.0f to have rectangular windows + FramePadding = ImVec2(4,3); // Padding within a framed rectangle (used by most widgets) + ItemSpacing = ImVec2(8,4); // Horizontal and vertical spacing between widgets/lines + ItemInnerSpacing = ImVec2(4,4); // Horizontal and vertical spacing between within elements of a composed widget (e.g. a slider and its label) TouchExtraPadding = ImVec2(0,0); // Expand bounding box for touch-based system where touch position is not accurate enough (unnecessary for mouse inputs). Unfortunately we don't sort widgets so priority on overlap will always be given to the first widget running. So dont grow this too much! AutoFitPadding = ImVec2(8,8); // Extra space after auto-fit (double-clicking on resize grip) WindowFillAlphaDefault = 0.70f; // Default alpha of window background, if not specified in ImGui::Begin() @@ -6739,7 +6740,7 @@ void ImGui::ShowStyleEditor(ImGuiStyle* ref) ImGui::SliderFloat2("FramePadding", (float*)&style.FramePadding, 0.0f, 20.0f, "%.0f"); ImGui::SliderFloat2("ItemSpacing", (float*)&style.ItemSpacing, 0.0f, 20.0f, "%.0f"); ImGui::SliderFloat2("ItemInnerSpacing", (float*)&style.ItemInnerSpacing, 0.0f, 20.0f, "%.0f"); - ImGui::SliderFloat2("TouchExtraPadding", (float*)&style.TouchExtraPadding, 0.0f, 20.0f, "%.0f"); + ImGui::SliderFloat2("TouchExtraPadding", (float*)&style.TouchExtraPadding, 0.0f, 10.0f, "%.0f"); ImGui::SliderFloat("TreeNodeSpacing", &style.TreeNodeSpacing, 0.0f, 20.0f, "%.0f"); ImGui::SliderFloat("ScrollBarWidth", &style.ScrollBarWidth, 0.0f, 20.0f, "%.0f"); ImGui::TreePop(); From 60b4389ac170697e0fa8024178b8e1e0e4c31916 Mon Sep 17 00:00:00 2001 From: ocornut Date: Tue, 30 Dec 2014 11:41:46 +0000 Subject: [PATCH 082/108] Empty label consistently remove the inner-padding normally preceeding the label. --- imgui.cpp | 79 +++++++++++++++++++++++++++++++++---------------------- 1 file changed, 48 insertions(+), 31 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 32eed5b8..eecc497e 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -713,10 +713,12 @@ struct ImGuiAabb // 2D axis aligned bounding-box ImVec2 GetTR() const { return ImVec2(Max.x,Min.y); } ImVec2 GetBL() const { return ImVec2(Min.x,Max.y); } ImVec2 GetBR() const { return Max; } - bool Contains(ImVec2 p) const { return p.x >= Min.x && p.y >= Min.y && p.x <= Max.x && p.y <= Max.y; } + bool Contains(const ImVec2& p) const { return p.x >= Min.x && p.y >= Min.y && p.x <= Max.x && p.y <= Max.y; } bool Contains(const ImGuiAabb& r) const { return r.Min.x >= Min.x && r.Min.y >= Min.y && r.Max.x <= Max.x && r.Max.y <= Max.y; } bool Overlaps(const ImGuiAabb& r) const { return r.Min.y <= Max.y && r.Max.y >= Min.y && r.Min.x <= Max.x && r.Max.x >= Min.x; } - void Expand(ImVec2 sz) { Min -= sz; Max += sz; } + void Add(const ImVec2& rhs) { Min.x = ImMin(Min.x, rhs.x); Min.y = ImMin(Min.y, rhs.y); Max.x = ImMax(Max.x, rhs.x); Max.y = ImMax(Max.x, rhs.x); } + void Add(const ImGuiAabb& rhs) { Min.x = ImMin(Min.x, rhs.Min.x); Min.y = ImMin(Min.y, rhs.Min.y); Max.x = ImMax(Max.x, rhs.Max.x); Max.y = ImMax(Max.y, rhs.Max.y); } + void Expand(const ImVec2& sz) { Min -= sz; Max += sz; } void Clip(const ImGuiAabb& clip) { Min.x = ImMax(Min.x, clip.Min.x); Min.y = ImMax(Min.y, clip.Min.y); Max.x = ImMin(Max.x, clip.Max.x); Max.y = ImMin(Max.y, clip.Max.y); } }; @@ -3292,7 +3294,7 @@ void ImGui::LabelTextV(const char* label, const char* fmt, va_list args) const ImVec2 text_size = CalcTextSize(label, NULL, true); const ImGuiAabb value_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(w + style.FramePadding.x*2, text_size.y)); - const ImGuiAabb bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(w + style.FramePadding.x*2 + style.ItemInnerSpacing.x, 0.0f) + text_size); + const ImGuiAabb bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(w + style.FramePadding.x*2 + (text_size.x > 0.0f ? style.ItemInnerSpacing.x : 0.0f), 0.0f) + text_size); ItemSize(bb); if (ClipAdvance(value_bb)) @@ -3371,7 +3373,7 @@ bool ImGui::Button(const char* label, ImVec2 size, bool repeat_when_held) if (size.y == 0.0f) size.y = text_size.y; - const ImGuiAabb bb(window->DC.CursorPos, window->DC.CursorPos+size + style.FramePadding*2.0f); + const ImGuiAabb bb(window->DC.CursorPos, window->DC.CursorPos + size + style.FramePadding*2.0f); ItemSize(bb); if (ClipAdvance(bb)) @@ -3868,7 +3870,7 @@ bool ImGui::SliderFloat(const char* label, float* v, float v_min, float v_max, c const ImVec2 text_size = CalcTextSize(label, NULL, true); const ImGuiAabb frame_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(w, text_size.y) + style.FramePadding*2.0f); const ImGuiAabb slider_bb(frame_bb.Min+g.Style.FramePadding, frame_bb.Max-g.Style.FramePadding); - const ImGuiAabb bb(frame_bb.Min, frame_bb.Max + ImVec2(style.ItemInnerSpacing.x + text_size.x, 0.0f)); + const ImGuiAabb bb(frame_bb.Min, frame_bb.Max + ImVec2(text_size.x > 0.0f ? style.ItemInnerSpacing.x + text_size.x : 0.0f, 0.0f)); if (IsClipped(slider_bb)) { @@ -4081,8 +4083,8 @@ static bool SliderFloatN(const char* label, float v[3], int components, float v_ const ImGuiStyle& style = g.Style; const float w_full = window->DC.ItemWidth.back(); - const float w_item_one = ImMax(1.0f, (float)(int)((w_full - (style.FramePadding.x*2.0f+style.ItemInnerSpacing.x)*(components-1)) / (float)components)); - const float w_item_last = ImMax(1.0f, (float)(int)(w_full - (w_item_one+style.FramePadding.x*2.0f+style.ItemInnerSpacing.x)*(components-1))); + const float w_item_one = ImMax(1.0f, (float)(int)((w_full - (style.FramePadding.x*2.0f + style.ItemInnerSpacing.x)*(components-1)) / (float)components)); + const float w_item_last = ImMax(1.0f, (float)(int)(w_full - (w_item_one + style.FramePadding.x*2.0f + style.ItemInnerSpacing.x)*(components-1))); bool value_changed = false; ImGui::PushID(label); @@ -4096,7 +4098,7 @@ static bool SliderFloatN(const char* label, float v[3], int components, float v_ ImGui::PushItemWidth(w_item_last); } value_changed |= ImGui::SliderFloat("##v", &v[i], v_min, v_max, display_format, power); - ImGui::SameLine(0, 0); + ImGui::SameLine(0, (int)style.ItemInnerSpacing.x); ImGui::PopID(); } ImGui::PopItemWidth(); @@ -4145,7 +4147,7 @@ static void Plot(ImGuiPlotType plot_type, const char* label, float (*values_gett const ImGuiAabb frame_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(graph_size.x, graph_size.y) + style.FramePadding*2.0f); const ImGuiAabb graph_bb(frame_bb.Min + style.FramePadding, frame_bb.Max - style.FramePadding); - const ImGuiAabb bb(frame_bb.Min, frame_bb.Max + ImVec2(style.ItemInnerSpacing.x + text_size.x,0)); + const ImGuiAabb bb(frame_bb.Min, frame_bb.Max + ImVec2(text_size.x > 0.0f ? style.ItemInnerSpacing.x + text_size.x : 0.0f, 0)); ItemSize(bb); if (ClipAdvance(bb)) @@ -4276,11 +4278,16 @@ bool ImGui::Checkbox(const char* label, bool* v) const ImGuiAabb check_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(text_size.y + style.FramePadding.y*2, text_size.y + style.FramePadding.y*2)); ItemSize(check_bb); - SameLine(0, (int)g.Style.ItemInnerSpacing.x); + ImGuiAabb total_bb = check_bb; + if (text_size.x > 0) + SameLine(0, (int)g.Style.ItemInnerSpacing.x); const ImGuiAabb text_bb(window->DC.CursorPos + ImVec2(0,style.FramePadding.y), window->DC.CursorPos + ImVec2(0,style.FramePadding.y) + text_size); - ItemSize(ImVec2(text_bb.GetWidth(), check_bb.GetHeight())); - const ImGuiAabb total_bb(ImMin(check_bb.Min, text_bb.Min), ImMax(check_bb.Max, text_bb.Max)); + if (text_size.x > 0) + { + ItemSize(ImVec2(text_bb.GetWidth(), check_bb.GetHeight())); + total_bb = ImGuiAabb(ImMin(check_bb.Min, text_bb.Min), ImMax(check_bb.Max, text_bb.Max)); + } if (ClipAdvance(total_bb)) return false; @@ -4335,11 +4342,16 @@ bool ImGui::RadioButton(const char* label, bool active) const ImGuiAabb check_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(text_size.y + style.FramePadding.y*2-1, text_size.y + style.FramePadding.y*2-1)); ItemSize(check_bb); - SameLine(0, (int)style.ItemInnerSpacing.x); + ImGuiAabb total_bb = check_bb; + if (text_size.x > 0) + SameLine(0, (int)style.ItemInnerSpacing.x); const ImGuiAabb text_bb(window->DC.CursorPos + ImVec2(0, style.FramePadding.y), window->DC.CursorPos + ImVec2(0, style.FramePadding.y) + text_size); - ItemSize(ImVec2(text_bb.GetWidth(), check_bb.GetHeight())); - const ImGuiAabb total_bb(ImMin(check_bb.Min, text_bb.Min), ImMax(check_bb.Max, text_bb.Max)); + if (text_size.x > 0) + { + ItemSize(ImVec2(text_bb.GetWidth(), check_bb.GetHeight())); + total_bb.Add(text_bb); + } if (ClipAdvance(total_bb)) return false; @@ -4536,7 +4548,7 @@ bool ImGui::InputFloat(const char* label, float *v, float step, float step_fast, ImGui::PushID(label); const float button_sz = window->FontSize(); if (step > 0.0f) - ImGui::PushItemWidth(ImMax(1.0f, window->DC.ItemWidth.back() - (button_sz+g.Style.FramePadding.x*2.0f+g.Style.ItemInnerSpacing.x)*2)); + ImGui::PushItemWidth(ImMax(1.0f, window->DC.ItemWidth.back() - (button_sz + g.Style.FramePadding.x*2.0f + g.Style.ItemInnerSpacing.x)*2)); char buf[64]; if (decimal_precision < 0) @@ -4555,13 +4567,13 @@ bool ImGui::InputFloat(const char* label, float *v, float step, float step_fast, if (step > 0.0f) { ImGui::PopItemWidth(); - ImGui::SameLine(0, 0); + ImGui::SameLine(0, (int)style.ItemInnerSpacing.x); if (ImGui::Button("-", ImVec2(button_sz,button_sz), true)) { *v -= g.IO.KeyCtrl && step_fast > 0.0f ? step_fast : step; value_changed = true; } - ImGui::SameLine(0, (int)g.Style.ItemInnerSpacing.x); + ImGui::SameLine(0, (int)style.ItemInnerSpacing.x); if (ImGui::Button("+", ImVec2(button_sz,button_sz), true)) { *v += g.IO.KeyCtrl && step_fast > 0.0f ? step_fast : step; @@ -4641,7 +4653,7 @@ bool ImGui::InputText(const char* label, char* buf, size_t buf_size, ImGuiInputT const ImVec2 text_size = CalcTextSize(label, NULL, true); const ImGuiAabb frame_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(w, text_size.y) + style.FramePadding*2.0f); - const ImGuiAabb bb(frame_bb.Min, frame_bb.Max + ImVec2(style.ItemInnerSpacing.x + text_size.x, 0.0f)); + const ImGuiAabb bb(frame_bb.Min, frame_bb.Max + ImVec2(text_size.x > 0.0f ? (style.ItemInnerSpacing.x + text_size.x) : 0.0f, 0.0f)); ItemSize(bb); if (ClipAdvance(frame_bb)) @@ -4931,8 +4943,8 @@ static bool InputFloatN(const char* label, float* v, int components, int decimal const ImGuiStyle& style = g.Style; const float w_full = window->DC.ItemWidth.back(); - const float w_item_one = ImMax(1.0f, (float)(int)((w_full - (style.FramePadding.x*2.0f+style.ItemInnerSpacing.x) * (components-1)) / (float)components)); - const float w_item_last = ImMax(1.0f, (float)(int)(w_full - (w_item_one+style.FramePadding.x*2.0f+style.ItemInnerSpacing.x) * (components-1))); + const float w_item_one = ImMax(1.0f, (float)(int)((w_full - (style.FramePadding.x*2.0f + style.ItemInnerSpacing.x) * (components-1)) / (float)components)); + const float w_item_last = ImMax(1.0f, (float)(int)(w_full - (w_item_one + style.FramePadding.x*2.0f + style.ItemInnerSpacing.x) * (components-1))); bool value_changed = false; ImGui::PushID(label); @@ -4946,7 +4958,7 @@ static bool InputFloatN(const char* label, float* v, int components, int decimal ImGui::PushItemWidth(w_item_last); } value_changed |= ImGui::InputFloat("##v", &v[i], 0, 0, decimal_precision); - ImGui::SameLine(0, 0); + ImGui::SameLine(0, (int)style.ItemInnerSpacing.x); ImGui::PopID(); } ImGui::PopItemWidth(); @@ -5031,9 +5043,10 @@ bool ImGui::Combo(const char* label, int* current_item, bool (*items_getter)(voi const ImGuiStyle& style = g.Style; const ImGuiID id = window->GetID(label); + const float w = window->DC.ItemWidth.back(); const ImVec2 text_size = CalcTextSize(label, NULL, true); - const ImGuiAabb frame_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(window->DC.ItemWidth.back(), text_size.y) + style.FramePadding*2.0f); + const ImGuiAabb frame_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(w, text_size.y) + style.FramePadding*2.0f); ItemSize(frame_bb); if (ClipAdvance(frame_bb)) @@ -5055,8 +5068,12 @@ bool ImGui::Combo(const char* label, int* current_item, bool (*items_getter)(voi RenderText(frame_bb.Min + style.FramePadding, item_text, NULL, false); } - ImGui::SameLine(0, (int)g.Style.ItemInnerSpacing.x); - ImGui::TextUnformatted(label, FindTextDisplayEnd(label)); + // Empty text doesn't add padding + if (text_size.x > 0) + { + ImGui::SameLine(0, (int)g.Style.ItemInnerSpacing.x); + ImGui::TextUnformatted(label, FindTextDisplayEnd(label)); + } ImGui::PushID((int)id); bool menu_toggled = false; @@ -5229,18 +5246,18 @@ bool ImGui::ColorEdit4(const char* label, float col[4], bool alpha) // 0: RGB 0..255 // 1: HSV 0.255 Sliders const float w_items_all = w_full - (square_sz + style.ItemInnerSpacing.x); - const float w_item_one = ImMax(1.0f, (float)(int)((w_items_all - (style.FramePadding.x*2.0f+style.ItemInnerSpacing.x) * (components-1)) / (float)components)); - const float w_item_last = ImMax(1.0f, (float)(int)(w_items_all - (w_item_one+style.FramePadding.x*2.0f+style.ItemInnerSpacing.x) * (components-1))); + const float w_item_one = ImMax(1.0f, (float)(int)((w_items_all - (style.FramePadding.x*2.0f + style.ItemInnerSpacing.x) * (components-1)) / (float)components)); + const float w_item_last = ImMax(1.0f, (float)(int)(w_items_all - (w_item_one + style.FramePadding.x*2.0f + style.ItemInnerSpacing.x) * (components-1))); ImGui::PushItemWidth(w_item_one); value_changed |= ImGui::SliderInt("##X", &ix, 0, 255, hsv ? "H:%3.0f" : "R:%3.0f"); - ImGui::SameLine(0, 0); + ImGui::SameLine(0, (int)style.ItemInnerSpacing.x); value_changed |= ImGui::SliderInt("##Y", &iy, 0, 255, hsv ? "S:%3.0f" : "G:%3.0f"); - ImGui::SameLine(0, 0); + ImGui::SameLine(0, (int)style.ItemInnerSpacing.x); if (alpha) { value_changed |= ImGui::SliderInt("##Z", &iz, 0, 255, hsv ? "V:%3.0f" : "B:%3.0f"); - ImGui::SameLine(0, 0); + ImGui::SameLine(0, (int)style.ItemInnerSpacing.x); ImGui::PushItemWidth(w_item_last); value_changed |= ImGui::SliderInt("##W", &iw, 0, 255, "A:%3.0f"); } @@ -5279,7 +5296,7 @@ bool ImGui::ColorEdit4(const char* label, float col[4], bool alpha) break; } - ImGui::SameLine(0, 0); + ImGui::SameLine(0, (int)style.ItemInnerSpacing.x); ImGui::ColorButton(col_display); if (window->DC.ColorEditMode == ImGuiColorEditMode_UserSelect) From 929f127d065cc34a4c1906272d188137b2340ab5 Mon Sep 17 00:00:00 2001 From: ocornut Date: Tue, 30 Dec 2014 11:54:04 +0000 Subject: [PATCH 083/108] Added SliderInt2(), SliderInt3(), SliderInt4() for consistency --- imgui.cpp | 69 +++++++++++++++++++++++++++++++++++++++++++++++-------- imgui.h | 3 +++ 2 files changed, 63 insertions(+), 9 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index eecc497e..3d42f71d 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -4124,6 +4124,56 @@ bool ImGui::SliderFloat4(const char* label, float v[4], float v_min, float v_max return SliderFloatN(label, v, 4, v_min, v_max, display_format, power); } +static bool SliderIntN(const char* label, int v[3], int components, int v_min, int v_max, const char* display_format) +{ + ImGuiState& g = GImGui; + ImGuiWindow* window = GetCurrentWindow(); + if (window->SkipItems) + return false; + + const ImGuiStyle& style = g.Style; + const float w_full = window->DC.ItemWidth.back(); + const float w_item_one = ImMax(1.0f, (float)(int)((w_full - (style.FramePadding.x*2.0f + style.ItemInnerSpacing.x)*(components-1)) / (float)components)); + const float w_item_last = ImMax(1.0f, (float)(int)(w_full - (w_item_one + style.FramePadding.x*2.0f + style.ItemInnerSpacing.x)*(components-1))); + + bool value_changed = false; + ImGui::PushID(label); + ImGui::PushItemWidth(w_item_one); + for (int i = 0; i < components; i++) + { + ImGui::PushID(i); + if (i + 1 == components) + { + ImGui::PopItemWidth(); + ImGui::PushItemWidth(w_item_last); + } + value_changed |= ImGui::SliderInt("##v", &v[i], v_min, v_max, display_format); + ImGui::SameLine(0, (int)style.ItemInnerSpacing.x); + ImGui::PopID(); + } + ImGui::PopItemWidth(); + ImGui::PopID(); + + ImGui::TextUnformatted(label, FindTextDisplayEnd(label)); + + return value_changed; +} + +bool ImGui::SliderInt2(const char* label, int v[2], int v_min, int v_max, const char* display_format) +{ + return SliderIntN(label, v, 2, v_min, v_max, display_format); +} + +bool ImGui::SliderInt3(const char* label, int v[3], int v_min, int v_max, const char* display_format) +{ + return SliderIntN(label, v, 3, v_min, v_max, display_format); +} + +bool ImGui::SliderInt4(const char* label, int v[4], int v_min, int v_max, const char* display_format) +{ + return SliderIntN(label, v, 4, v_min, v_max, display_format); +} + enum ImGuiPlotType { ImGuiPlotType_Lines, @@ -5243,8 +5293,8 @@ bool ImGui::ColorEdit4(const char* label, float col[4], bool alpha) case ImGuiColorEditMode_RGB: case ImGuiColorEditMode_HSV: { - // 0: RGB 0..255 - // 1: HSV 0.255 Sliders + // 0: RGB 0..255 Sliders + // 1: HSV 0..255 Sliders const float w_items_all = w_full - (square_sz + style.ItemInnerSpacing.x); const float w_item_one = ImMax(1.0f, (float)(int)((w_items_all - (style.FramePadding.x*2.0f + style.ItemInnerSpacing.x) * (components-1)) / (float)components)); const float w_item_last = ImMax(1.0f, (float)(int)(w_items_all - (w_item_one + style.FramePadding.x*2.0f + style.ItemInnerSpacing.x) * (components-1))); @@ -7025,15 +7075,16 @@ void ImGui::ShowTestWindow(bool* opened) static float angle = 0.0f; ImGui::SliderAngle("angle", &angle); - //static float vec2b[3] = { 0.10f, 0.20f }; - //ImGui::SliderFloat2("slider float2", vec2b, 0.0f, 1.0f); - - static float vec3b[3] = { 0.10f, 0.20f, 0.30f }; - ImGui::SliderFloat3("slider float3", vec3b, 0.0f, 1.0f); - - //static float vec4b[4] = { 0.10f, 0.20f, 0.30f, 0.40f }; + static float vec4b[4] = { 0.10f, 0.20f, 0.30f, 0.40f }; + //ImGui::SliderFloat2("slider float2", vec4b, 0.0f, 1.0f); + ImGui::SliderFloat3("slider float3", vec4b, 0.0f, 1.0f); //ImGui::SliderFloat4("slider float4", vec4b, 0.0f, 1.0f); + //static int vec4i[4] = { 1, 5, 100, 255 }; + //ImGui::SliderInt2("slider int2", vec4i, 0, 255); + //ImGui::SliderInt3("slider int3", vec4i, 0, 255); + //ImGui::SliderInt4("slider int4", vec4i, 0, 255); + static float col1[3] = { 1.0f,0.0f,0.2f }; static float col2[4] = { 0.4f,0.7f,0.0f,0.5f }; ImGui::ColorEdit3("color 1", col1); diff --git a/imgui.h b/imgui.h index 2912b6b6..f4f3e6b7 100644 --- a/imgui.h +++ b/imgui.h @@ -241,6 +241,9 @@ namespace ImGui IMGUI_API bool SliderFloat4(const char* label, float v[4], float v_min, float v_max, const char* display_format = "%.3f", float power = 1.0f); IMGUI_API bool SliderAngle(const char* label, float* v, float v_degrees_min = -360.0f, float v_degrees_max = +360.0f); // *v in radians IMGUI_API bool SliderInt(const char* label, int* v, int v_min, int v_max, const char* display_format = "%.0f"); + IMGUI_API bool SliderInt2(const char* label, int v[2], int v_min, int v_max, const char* display_format = "%.0f"); + IMGUI_API bool SliderInt3(const char* label, int v[3], int v_min, int v_max, const char* display_format = "%.0f"); + IMGUI_API bool SliderInt4(const char* label, int v[4], int v_min, int v_max, const char* display_format = "%.0f"); IMGUI_API void PlotLines(const char* label, const float* values, int values_count, int values_offset = 0, const char* overlay_text = NULL, float scale_min = FLT_MAX, float scale_max = FLT_MAX, ImVec2 graph_size = ImVec2(0,0), size_t stride = sizeof(float)); IMGUI_API void PlotLines(const char* label, float (*values_getter)(void* data, int idx), void* data, int values_count, int values_offset = 0, const char* overlay_text = NULL, float scale_min = FLT_MAX, float scale_max = FLT_MAX, ImVec2 graph_size = ImVec2(0,0)); IMGUI_API void PlotHistogram(const char* label, const float* values, int values_count, int values_offset = 0, const char* overlay_text = NULL, float scale_min = FLT_MAX, float scale_max = FLT_MAX, ImVec2 graph_size = ImVec2(0,0), size_t stride = sizeof(float)); From aa750d538d0b26c5afc60da57142db3f01c5826f Mon Sep 17 00:00:00 2001 From: ocornut Date: Tue, 30 Dec 2014 12:08:33 +0000 Subject: [PATCH 084/108] Style editor: added an Output button to output colors to clipboard/tty --- imgui.cpp | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 3d42f71d..07f3f129 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -457,9 +457,9 @@ const float PI = 3.14159265358979323846f; // Play it nice with Windows users. Notepad in 2014 still doesn't display text data with Unix-style \n. #ifdef _MSC_VER -#define STR_NEW_LINE "\r\n" +#define STR_NEWLINE "\r\n" #else -#define STR_NEW_LINE "\n" +#define STR_NEWLINE "\n" #endif // Math bits @@ -1835,7 +1835,7 @@ static void LogText(const ImVec2& ref_pos, const char* text, const char* text_en { const int char_count = (int)(line_end - text_remaining); if (log_new_line || !is_first_line) - ImGui::LogText(STR_NEW_LINE "%*s%.*s", tree_depth*4, "", char_count, text_remaining); + ImGui::LogText(STR_NEWLINE "%*s%.*s", tree_depth*4, "", char_count, text_remaining); else ImGui::LogText(" %.*s", char_count, text_remaining); } @@ -3508,7 +3508,7 @@ void ImGui::LogFinish() if (!g.LogEnabled) return; - ImGui::LogText(STR_NEW_LINE); + ImGui::LogText(STR_NEWLINE); g.LogEnabled = false; if (g.LogFile != NULL) { @@ -6786,7 +6786,7 @@ void ImGui::ShowStyleEditor(ImGuiStyle* ref) ImGuiState& g = GImGui; ImGuiStyle& style = g.Style; - const ImGuiStyle def; + const ImGuiStyle def; // Default style if (ImGui::Button("Revert Style")) g.Style = ref ? *ref : def; @@ -6815,6 +6815,27 @@ void ImGui::ShowStyleEditor(ImGuiStyle* ref) if (ImGui::TreeNode("Colors")) { + static int output_dest = 0; + static bool output_only_modified = false; + if (ImGui::Button("Output Colors")) + { + if (output_dest == 0) + ImGui::LogToClipboard(); + else + ImGui::LogToTTY(); + ImGui::LogText("ImGuiStyle& style = ImGui::GetStyle();" STR_NEWLINE); + for (int i = 0; i < ImGuiCol_COUNT; i++) + { + const ImVec4& col = style.Colors[i]; + const char* name = ImGui::GetStyleColName(i); + if (!output_only_modified || memcmp(&col, (ref ? &ref->Colors[i] : &def.Colors[i]), sizeof(ImVec4)) != 0) + ImGui::LogText("style.Colors[ImGuiCol_%s]%*s= ImVec4(%.2ff, %.2ff, %.2ff, %.2ff);" STR_NEWLINE, name, 22 - strlen(name), "", col.x, col.y, col.z, col.w); + } + ImGui::LogFinish(); + } + ImGui::SameLine(); ImGui::PushItemWidth(150); ImGui::Combo("##output_type", &output_dest, "To Clipboard\0To TTY"); ImGui::PopItemWidth(); + ImGui::SameLine(); ImGui::Checkbox("Only Modified Fields", &output_only_modified); + static ImGuiColorEditMode edit_mode = ImGuiColorEditMode_RGB; ImGui::RadioButton("RGB", &edit_mode, ImGuiColorEditMode_RGB); ImGui::SameLine(); From 209be54e499aae2ad031d83293280582017b57f1 Mon Sep 17 00:00:00 2001 From: ocornut Date: Tue, 30 Dec 2014 12:21:57 +0000 Subject: [PATCH 085/108] Version number --- imgui.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/imgui.cpp b/imgui.cpp index 07f3f129..aa737868 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -1,4 +1,4 @@ -// ImGui library v1.19 wip +// ImGui library v1.19 // See ImGui::ShowTestWindow() for sample code. // Read 'Programmer guide' below for notes on how to setup ImGui in your codebase. // Get latest version at https://github.com/ocornut/imgui From 691ca4697828eaa71766a69556af40f13a41ebf5 Mon Sep 17 00:00:00 2001 From: ocornut Date: Tue, 30 Dec 2014 15:10:55 +0000 Subject: [PATCH 086/108] Version number --- imgui.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/imgui.h b/imgui.h index f4f3e6b7..8bd52230 100644 --- a/imgui.h +++ b/imgui.h @@ -1,4 +1,4 @@ -// ImGui library v1.19 wip +// ImGui library v1.19 // See .cpp file for commentary. // See ImGui::ShowTestWindow() for sample code. // Read 'Programmer guide' in .cpp for notes on how to setup ImGui in your codebase. From 2d111ccb555e038c3149d571691b6bcf6a8ed542 Mon Sep 17 00:00:00 2001 From: ocornut Date: Tue, 30 Dec 2014 15:18:21 +0000 Subject: [PATCH 087/108] crc32 on strings is performed in one pass - removed the strlen() call. --- imgui.cpp | 32 ++++++++++++++++++++------------ imgui.h | 2 +- 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index aa737868..6df37ab6 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -1,4 +1,4 @@ -// ImGui library v1.19 +// ImGui library v1.19 wip // See ImGui::ShowTestWindow() for sample code. // Read 'Programmer guide' below for notes on how to setup ImGui in your codebase. // Get latest version at https://github.com/ocornut/imgui @@ -540,6 +540,7 @@ static const char* ImStristr(const char* haystack, const char* needle, const cha return NULL; } +// Pass data_size==0 for zero-terminated string static ImU32 ImCrc32(const void* data, size_t data_size, ImU32 seed = 0) { static ImU32 crc32_lut[256] = { 0 }; @@ -555,9 +556,20 @@ static ImU32 ImCrc32(const void* data, size_t data_size, ImU32 seed = 0) } } ImU32 crc = ~seed; - const unsigned char* current = (const unsigned char*)data; - while (data_size--) - crc = (crc >> 8) ^ crc32_lut[(crc & 0xFF) ^ *current++]; + const unsigned char* current = (const unsigned char*)data; + + if (data_size > 0) + { + // Known size + while (data_size--) + crc = (crc >> 8) ^ crc32_lut[(crc & 0xFF) ^ *current++]; + } + else + { + // Zero-terminated string + while (unsigned char c = *current++) + crc = (crc >> 8) ^ crc32_lut[(crc & 0xFF) ^ c]; + } return ~crc; } @@ -1243,7 +1255,7 @@ ImGuiWindow::~ImGuiWindow() ImGuiID ImGuiWindow::GetID(const char* str) { const ImGuiID seed = IDStack.empty() ? 0 : IDStack.back(); - const ImGuiID id = ImCrc32(str, strlen(str), seed); // FIXME-OPT: crc32 function/variant should handle zero-terminated strings + const ImGuiID id = ImCrc32(str, 0, seed); RegisterAliveId(id); return id; } @@ -7071,13 +7083,9 @@ void ImGui::ShowTestWindow(bool* opened) ImGui::InputInt("input int", &i0); ImGui::InputFloat("input float", &f0, 0.01f, 1.0f); - //static float vec2a[3] = { 0.10f, 0.20f }; - //ImGui::InputFloat2("input float2", vec2a); - - static float vec3a[3] = { 0.10f, 0.20f, 0.30f }; - ImGui::InputFloat3("input float3", vec3a); - - //static float vec4a[4] = { 0.10f, 0.20f, 0.30f, 0.44f }; + static float vec4a[4] = { 0.10f, 0.20f, 0.30f, 0.44f }; + //ImGui::InputFloat2("input float2", vec4a); + ImGui::InputFloat3("input float3", vec4a); //ImGui::InputFloat4("input float4", vec4a); static int i1=0; diff --git a/imgui.h b/imgui.h index 8bd52230..f4f3e6b7 100644 --- a/imgui.h +++ b/imgui.h @@ -1,4 +1,4 @@ -// ImGui library v1.19 +// ImGui library v1.19 wip // See .cpp file for commentary. // See ImGui::ShowTestWindow() for sample code. // Read 'Programmer guide' in .cpp for notes on how to setup ImGui in your codebase. From 3b028c7ebf302c105e7a2c1eb50135fdec56cf04 Mon Sep 17 00:00:00 2001 From: ocornut Date: Tue, 30 Dec 2014 15:38:28 +0000 Subject: [PATCH 088/108] Fixed InputInt() InputFloat() label not declaring their width, breaking SameLine (bug #100) + shallow cleanups --- imgui.cpp | 88 +++++++++++++++++++++++++++++-------------------------- 1 file changed, 47 insertions(+), 41 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 6df37ab6..90ad8062 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -558,18 +558,18 @@ static ImU32 ImCrc32(const void* data, size_t data_size, ImU32 seed = 0) ImU32 crc = ~seed; const unsigned char* current = (const unsigned char*)data; - if (data_size > 0) - { - // Known size - while (data_size--) - crc = (crc >> 8) ^ crc32_lut[(crc & 0xFF) ^ *current++]; - } - else - { - // Zero-terminated string - while (unsigned char c = *current++) - crc = (crc >> 8) ^ crc32_lut[(crc & 0xFF) ^ c]; - } + if (data_size > 0) + { + // Known size + while (data_size--) + crc = (crc >> 8) ^ crc32_lut[(crc & 0xFF) ^ *current++]; + } + else + { + // Zero-terminated string + while (unsigned char c = *current++) + crc = (crc >> 8) ^ crc32_lut[(crc & 0xFF) ^ c]; + } return ~crc; } @@ -2380,7 +2380,7 @@ bool ImGui::Begin(const char* name, bool* p_opened, ImVec2 size, float fill_alph // Tooltips always follow mouse if ((window->Flags & ImGuiWindowFlags_Tooltip) != 0) { - window->PosFloat = g.IO.MousePos + ImVec2(32,16) - g.Style.FramePadding*2; + window->PosFloat = g.IO.MousePos + ImVec2(32,16) - style.FramePadding*2; } // Clamp into view @@ -2443,11 +2443,11 @@ bool ImGui::Begin(const char* name, bool* p_opened, ImVec2 size, float fill_alph { // Draw title bar only window->Size = title_bar_aabb.GetSize(); - window->DrawList->AddRectFilled(title_bar_aabb.GetTL(), title_bar_aabb.GetBR(), window->Color(ImGuiCol_TitleBgCollapsed), g.Style.WindowRounding); + window->DrawList->AddRectFilled(title_bar_aabb.GetTL(), title_bar_aabb.GetBR(), window->Color(ImGuiCol_TitleBgCollapsed), style.WindowRounding); if (window->Flags & ImGuiWindowFlags_ShowBorders) { - window->DrawList->AddRect(title_bar_aabb.GetTL()+ImVec2(1,1), title_bar_aabb.GetBR()+ImVec2(1,1), window->Color(ImGuiCol_BorderShadow), g.Style.WindowRounding); - window->DrawList->AddRect(title_bar_aabb.GetTL(), title_bar_aabb.GetBR(), window->Color(ImGuiCol_Border), g.Style.WindowRounding); + window->DrawList->AddRect(title_bar_aabb.GetTL()+ImVec2(1,1), title_bar_aabb.GetBR()+ImVec2(1,1), window->Color(ImGuiCol_BorderShadow), style.WindowRounding); + window->DrawList->AddRect(title_bar_aabb.GetTL(), title_bar_aabb.GetBR(), window->Color(ImGuiCol_Border), style.WindowRounding); } } else @@ -2460,7 +2460,7 @@ bool ImGui::Begin(const char* name, bool* p_opened, ImVec2 size, float fill_alph // Tooltip always resize if (window->AutoFitFrames > 0) { - window->SizeFull = window->SizeContentsFit + g.Style.WindowPadding - ImVec2(0.0f, g.Style.ItemSpacing.y); + window->SizeFull = window->SizeContentsFit + style.WindowPadding - ImVec2(0.0f, style.ItemSpacing.y); } } else @@ -2515,16 +2515,16 @@ bool ImGui::Begin(const char* name, bool* p_opened, ImVec2 size, float fill_alph if ((window->Flags & ImGuiWindowFlags_ComboBox) != 0) window->DrawList->AddRectFilled(window->Pos, window->Pos+window->Size, window->Color(ImGuiCol_ComboBg, fill_alpha), 0); else - window->DrawList->AddRectFilled(window->Pos, window->Pos+window->Size, window->Color(ImGuiCol_WindowBg, fill_alpha), g.Style.WindowRounding); + window->DrawList->AddRectFilled(window->Pos, window->Pos+window->Size, window->Color(ImGuiCol_WindowBg, fill_alpha), style.WindowRounding); } if (!(window->Flags & ImGuiWindowFlags_NoTitleBar)) - window->DrawList->AddRectFilled(title_bar_aabb.GetTL(), title_bar_aabb.GetBR(), window->Color(ImGuiCol_TitleBg), g.Style.WindowRounding, 1|2); + window->DrawList->AddRectFilled(title_bar_aabb.GetTL(), title_bar_aabb.GetBR(), window->Color(ImGuiCol_TitleBg), style.WindowRounding, 1|2); // Borders if (window->Flags & ImGuiWindowFlags_ShowBorders) { - const float rounding = (window->Flags & ImGuiWindowFlags_ComboBox) ? 0.0f : g.Style.WindowRounding; + const float rounding = (window->Flags & ImGuiWindowFlags_ComboBox) ? 0.0f : style.WindowRounding; window->DrawList->AddRect(window->Pos+ImVec2(1,1), window->Pos+window->Size+ImVec2(1,1), window->Color(ImGuiCol_BorderShadow), rounding); window->DrawList->AddRect(window->Pos, window->Pos+window->Size, window->Color(ImGuiCol_Border), rounding); if (!(window->Flags & ImGuiWindowFlags_NoTitleBar)) @@ -2653,7 +2653,7 @@ bool ImGui::Begin(const char* name, bool* p_opened, ImVec2 size, float fill_alph const ImGuiAabb title_bar_aabb = window->TitleBarAabb(); ImVec4 clip_rect(title_bar_aabb.Min.x+0.5f+window->WindowPadding().x*0.5f, title_bar_aabb.Max.y+0.5f, window->Aabb().Max.x+0.5f-window->WindowPadding().x*0.5f, window->Aabb().Max.y-1.5f); if (window->ScrollbarY) - clip_rect.z -= g.Style.ScrollBarWidth; + clip_rect.z -= style.ScrollBarWidth; PushClipRect(clip_rect); // Clear 'accessed' flag last thing @@ -2673,10 +2673,10 @@ bool ImGui::Begin(const char* name, bool* p_opened, ImVec2 size, float fill_alph if (window->Collapsed) window->Visible = false; } - if (g.Style.Alpha <= 0.0f) + if (style.Alpha <= 0.0f) window->Visible = false; - // Return false if we don't intend to display anything to allow user to perform an early out optimisation + // Return false if we don't intend to display anything to allow user to perform an early out optimization window->SkipItems = window->Collapsed || (!window->Visible && window->AutoFitFrames == 0); return !window->SkipItems; } @@ -3378,8 +3378,8 @@ bool ImGui::Button(const char* label, ImVec2 size, bool repeat_when_held) const ImGuiStyle& style = g.Style; const ImGuiID id = window->GetID(label); - const ImVec2 text_size = CalcTextSize(label, NULL, true); + if (size.x == 0.0f) size.x = text_size.x; if (size.y == 0.0f) @@ -3418,8 +3418,8 @@ bool ImGui::SmallButton(const char* label) const ImGuiStyle& style = g.Style; const ImGuiID id = window->GetID(label); - const ImVec2 text_size = CalcTextSize(label, NULL, true); + const ImGuiAabb bb(window->DC.CursorPos, window->DC.CursorPos + text_size + ImVec2(style.FramePadding.x*2,0)); ItemSize(bb); @@ -3671,6 +3671,8 @@ void ImGui::BulletTextV(const char* fmt, va_list args) ImGuiWindow* window = GetCurrentWindow(); if (window->SkipItems) return; + + const ImGuiStyle& style = g.Style; static char buf[1024]; const char* text_begin = buf; @@ -3678,7 +3680,7 @@ void ImGui::BulletTextV(const char* fmt, va_list args) const float line_height = window->FontSize(); const ImVec2 text_size = CalcTextSize(text_begin, text_end, true); - const ImGuiAabb bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(line_height + (text_size.x > 0.0f ? (g.Style.FramePadding.x*2) : 0.0f),0) + text_size); // Empty text doesn't add padding + const ImGuiAabb bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(line_height + (text_size.x > 0.0f ? (style.FramePadding.x*2) : 0.0f),0) + text_size); // Empty text doesn't add padding ItemSize(bb); if (ClipAdvance(bb)) @@ -3686,8 +3688,8 @@ void ImGui::BulletTextV(const char* fmt, va_list args) // Render const float bullet_size = line_height*0.15f; - window->DrawList->AddCircleFilled(bb.Min + ImVec2(g.Style.FramePadding.x + line_height*0.5f, line_height*0.5f), bullet_size, window->Color(ImGuiCol_Text)); - RenderText(bb.Min+ImVec2(window->FontSize()+g.Style.FramePadding.x*2,0), text_begin, text_end); + window->DrawList->AddCircleFilled(bb.Min + ImVec2(style.FramePadding.x + line_height*0.5f, line_height*0.5f), bullet_size, window->Color(ImGuiCol_Text)); + RenderText(bb.Min+ImVec2(window->FontSize() + style.FramePadding.x*2,0), text_begin, text_end); } void ImGui::BulletText(const char* fmt, ...) @@ -3881,7 +3883,7 @@ bool ImGui::SliderFloat(const char* label, float* v, float v_min, float v_max, c const ImVec2 text_size = CalcTextSize(label, NULL, true); const ImGuiAabb frame_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(w, text_size.y) + style.FramePadding*2.0f); - const ImGuiAabb slider_bb(frame_bb.Min+g.Style.FramePadding, frame_bb.Max-g.Style.FramePadding); + const ImGuiAabb slider_bb(frame_bb.Min + style.FramePadding, frame_bb.Max - style.FramePadding); const ImGuiAabb bb(frame_bb.Min, frame_bb.Max + ImVec2(text_size.x > 0.0f ? style.ItemInnerSpacing.x + text_size.x : 0.0f, 0.0f)); if (IsClipped(slider_bb)) @@ -4335,7 +4337,6 @@ bool ImGui::Checkbox(const char* label, bool* v) const ImGuiStyle& style = g.Style; const ImGuiID id = window->GetID(label); - const ImVec2 text_size = CalcTextSize(label, NULL, true); const ImGuiAabb check_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(text_size.y + style.FramePadding.y*2, text_size.y + style.FramePadding.y*2)); @@ -4343,7 +4344,7 @@ bool ImGui::Checkbox(const char* label, bool* v) ImGuiAabb total_bb = check_bb; if (text_size.x > 0) - SameLine(0, (int)g.Style.ItemInnerSpacing.x); + SameLine(0, (int)style.ItemInnerSpacing.x); const ImGuiAabb text_bb(window->DC.CursorPos + ImVec2(0,style.FramePadding.y), window->DC.CursorPos + ImVec2(0,style.FramePadding.y) + text_size); if (text_size.x > 0) { @@ -4610,7 +4611,7 @@ bool ImGui::InputFloat(const char* label, float *v, float step, float step_fast, ImGui::PushID(label); const float button_sz = window->FontSize(); if (step > 0.0f) - ImGui::PushItemWidth(ImMax(1.0f, window->DC.ItemWidth.back() - (button_sz + g.Style.FramePadding.x*2.0f + g.Style.ItemInnerSpacing.x)*2)); + ImGui::PushItemWidth(ImMax(1.0f, w - (button_sz + style.FramePadding.x*2.0f + style.ItemInnerSpacing.x)*2)); char buf[64]; if (decimal_precision < 0) @@ -4645,7 +4646,12 @@ bool ImGui::InputFloat(const char* label, float *v, float step, float step_fast, ImGui::PopID(); - RenderText(ImVec2(frame_bb.Max.x + style.ItemInnerSpacing.x, frame_bb.Min.y + g.Style.FramePadding.y), label); + if (text_size.x > 0) + { + ImGui::SameLine(0, (int)style.ItemInnerSpacing.x); + ItemSize(text_size); + RenderText(ImVec2(frame_bb.Max.x + style.ItemInnerSpacing.x, frame_bb.Min.y + style.FramePadding.y), label); + } return value_changed; } @@ -4721,7 +4727,7 @@ bool ImGui::InputText(const char* label, char* buf, size_t buf_size, ImGuiInputT if (ClipAdvance(frame_bb)) return false; - // NB: we are only allowed to access it if we are the active widget. + // NB: we are only allowed to access 'edit_state' if we are the active widget. ImGuiTextEditState& edit_state = g.InputTextState; const bool is_ctrl_down = io.KeyCtrl; @@ -5133,7 +5139,7 @@ bool ImGui::Combo(const char* label, int* current_item, bool (*items_getter)(voi // Empty text doesn't add padding if (text_size.x > 0) { - ImGui::SameLine(0, (int)g.Style.ItemInnerSpacing.x); + ImGui::SameLine(0, (int)style.ItemInnerSpacing.x); ImGui::TextUnformatted(label, FindTextDisplayEnd(label)); } @@ -5152,8 +5158,8 @@ bool ImGui::Combo(const char* label, int* current_item, bool (*items_getter)(voi if (g.ActiveComboID == id) { const ImVec2 backup_pos = ImGui::GetCursorPos(); - const float popup_off_x = 0.0f;//g.Style.ItemInnerSpacing.x; - const float popup_height = (text_size.y + g.Style.ItemSpacing.y) * ImMin(items_count, popup_height_items) + g.Style.WindowPadding.y; + const float popup_off_x = 0.0f;//style.ItemInnerSpacing.x; + const float popup_height = (text_size.y + style.ItemSpacing.y) * ImMin(items_count, popup_height_items) + style.WindowPadding.y; const ImGuiAabb popup_aabb(ImVec2(frame_bb.Min.x+popup_off_x, frame_bb.Max.y), ImVec2(frame_bb.Max.x+popup_off_x, frame_bb.Max.y + popup_height)); ImGui::SetCursorPos(popup_aabb.Min - window->Pos); @@ -5169,8 +5175,8 @@ bool ImGui::Combo(const char* label, int* current_item, bool (*items_getter)(voi for (int item_idx = 0; item_idx < items_count; item_idx++) { const float item_h = child_window->FontSize(); - const float spacing_up = (float)(int)(g.Style.ItemSpacing.y/2); - const float spacing_dn = g.Style.ItemSpacing.y - spacing_up; + const float spacing_up = (float)(int)(style.ItemSpacing.y/2); + const float spacing_dn = style.ItemSpacing.y - spacing_up; const ImGuiAabb item_aabb(ImVec2(popup_aabb.Min.x, child_window->DC.CursorPos.y - spacing_up), ImVec2(popup_aabb.Max.x, child_window->DC.CursorPos.y + item_h + spacing_dn)); const ImGuiID item_id = child_window->GetID((void*)(intptr_t)item_idx); @@ -5341,7 +5347,7 @@ bool ImGui::ColorEdit4(const char* label, float col[4], bool alpha) sprintf(buf, "#%02X%02X%02X%02X", ix, iy, iz, iw); else sprintf(buf, "#%02X%02X%02X", ix, iy, iz); - ImGui::PushItemWidth(w_slider_all - g.Style.ItemInnerSpacing.x); + ImGui::PushItemWidth(w_slider_all - style.ItemInnerSpacing.x); value_changed |= ImGui::InputText("##Text", buf, IM_ARRAYSIZE(buf), ImGuiInputTextFlags_CharsHexadecimal); ImGui::PopItemWidth(); char* p = buf; @@ -7083,7 +7089,7 @@ void ImGui::ShowTestWindow(bool* opened) ImGui::InputInt("input int", &i0); ImGui::InputFloat("input float", &f0, 0.01f, 1.0f); - static float vec4a[4] = { 0.10f, 0.20f, 0.30f, 0.44f }; + static float vec4a[4] = { 0.10f, 0.20f, 0.30f, 0.44f }; //ImGui::InputFloat2("input float2", vec4a); ImGui::InputFloat3("input float3", vec4a); //ImGui::InputFloat4("input float4", vec4a); From da5227fa28ef394ccea7779596cfe96a601779f4 Mon Sep 17 00:00:00 2001 From: ocornut Date: Tue, 30 Dec 2014 15:44:19 +0000 Subject: [PATCH 089/108] Added comment about defining IMGUI_OVERRIDE_DRAWVERT_STRUCT_LAYOUT in imconfig.h --- imgui.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/imgui.h b/imgui.h index f4f3e6b7..ca5233c5 100644 --- a/imgui.h +++ b/imgui.h @@ -685,7 +685,7 @@ struct ImDrawVert ImU32 col; }; #else -// You can change the vertex format layout by defining IMGUI_OVERRIDE_DRAWVERT_STRUCT_LAYOUT. +// You can change the vertex format layout by defining IMGUI_OVERRIDE_DRAWVERT_STRUCT_LAYOUT in imconfig.h // The code expect ImVec2 pos (8 bytes), ImVec2 uv (8 bytes), ImU32 col (4 bytes), but you can re-order them or add other fields as needed to simplify integration in your engine. // The type has to be described by the #define (you can either declare the struct or use a typedef) IMGUI_OVERRIDE_DRAWVERT_STRUCT_LAYOUT; From 74ab55555869541fec1f7ca79dc73d9de25fa02f Mon Sep 17 00:00:00 2001 From: ocornut Date: Tue, 30 Dec 2014 16:49:39 +0000 Subject: [PATCH 090/108] Examples: Console:: added support for History callbacks + cleanup to be self contained. --- imgui.cpp | 255 +++++++++++++++++++++++++++++++++++------------------- 1 file changed, 165 insertions(+), 90 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 90ad8062..cbb697dc 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -7474,26 +7474,154 @@ static void ShowExampleAppFixedOverlay(bool* opened) struct ExampleAppConsole { - ImVector Items; - bool NewItems; + char InputBuf[256]; + ImVector Items; + bool ScrollToBottom; + ImVector History; + int HistoryPos; // -1: new line, 0..History.size()-1 browsing history. + ImVector Commands; - void Clear() + ExampleAppConsole() + { + ClearLog(); + HistoryPos = -1; + Commands.push_back("HELP"); + Commands.push_back("HISTORY"); + Commands.push_back("CLEAR"); + Commands.push_back("CLASSIFY"); // "classify" is here to provide an example of "C"+[tab] completing to "CL" and displaying matches. + } + ~ExampleAppConsole() + { + ClearLog(); + for (size_t i = 0; i < Items.size(); i++) + ImGui::MemFree(History[i]); + } + + void ClearLog() { for (size_t i = 0; i < Items.size(); i++) ImGui::MemFree(Items[i]); Items.clear(); - NewItems = true; + ScrollToBottom = true; } void AddLog(const char* fmt, ...) { - char buf[512]; + char buf[1024]; va_list args; va_start(args, fmt); ImFormatStringV(buf, IM_ARRAYSIZE(buf), fmt, args); va_end(args); Items.push_back(ImStrdup(buf)); - NewItems = true; + ScrollToBottom = true; + } + + void Run(const char* title, bool* opened) + { + if (!ImGui::Begin(title, opened, ImVec2(520,600))) + { + ImGui::End(); + return; + } + + ImGui::TextWrapped("This example implement a console with basic coloring, completion and history. A more elaborate implementation may want to store entries along with extra data such as timestamp, emitter, etc."); + ImGui::TextWrapped("Enter 'HELP' for help, press TAB to use text completion."); + + // TODO: display from bottom + // TODO: clip manually + + if (ImGui::SmallButton("Add Dummy Text")) AddLog("some text\nsome more text\ndisplay very important message here!\n"); ImGui::SameLine(); + if (ImGui::SmallButton("Add Dummy Error")) AddLog("[error] something went wrong"); ImGui::SameLine(); + if (ImGui::SmallButton("Clear")) ClearLog(); + ImGui::Separator(); + + ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(0,0)); + static ImGuiTextFilter filter; + filter.Draw("Filter (\"incl,-excl\") (\"error\")", 180); + if (ImGui::IsItemHovered()) ImGui::SetKeyboardFocusHere(-1); // Auto focus on hover + ImGui::PopStyleVar(); + ImGui::Separator(); + + // Display every line as a separate entry so we can change their color or add custom widgets. If you only want raw text you can use ImGui::TextUnformatted(log.begin(), log.end()); + // NB- if you have lots of text this approach may be too inefficient. You can seek and display only the lines that are on display using a technique similar to what TextUnformatted() does, + // or faster if your entries are already stored into a table. + ImGui::BeginChild("ScrollingRegion", ImVec2(0,-ImGui::GetTextLineSpacing()*2)); + ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(4,1)); // Tighten spacing + for (size_t i = 0; i < Items.size(); i++) + { + const char* item = Items[i]; + if (!filter.PassFilter(item)) + continue; + ImVec4 col(1,1,1,1); // A better implement may store a type per-item. For the sample let's just parse the text. + if (strstr(item, "[error]")) col = ImVec4(1.0f,0.4f,0.4f,1.0f); + else if (strncmp(item, "# ", 2) == 0) col = ImVec4(1.0f,0.8f,0.6f,1.0f); + ImGui::PushStyleColor(ImGuiCol_Text, col); + ImGui::TextUnformatted(item); + ImGui::PopStyleColor(); + } + if (ScrollToBottom) + ImGui::SetScrollPosHere(); + ScrollToBottom = false; + ImGui::PopStyleVar(); + ImGui::EndChild(); + ImGui::Separator(); + + // Command-line + if (ImGui::InputText("Input", InputBuf, IM_ARRAYSIZE(InputBuf), ImGuiInputTextFlags_EnterReturnsTrue|ImGuiInputTextFlags_CallbackCompletion|ImGuiInputTextFlags_CallbackHistory, &TextEditCallbackStub, (void*)this)) + { + char* input_end = InputBuf+strlen(InputBuf); + while (input_end > InputBuf && input_end[-1] == ' ') input_end--; *input_end = 0; + if (InputBuf[0]) + ExecCommand(InputBuf); + strcpy(InputBuf, ""); + } + + if (ImGui::IsItemHovered()) ImGui::SetKeyboardFocusHere(-1); // Auto focus on hover + + ImGui::End(); + } + + void ExecCommand(const char* command_line) + { + AddLog("# %s\n", command_line); + + // Insert into history. First find match and delete it so it can be pushed to the back. This isn't trying to be smart or optimal. + HistoryPos = -1; + for (int i = (int)History.size()-1; i >= 0; i--) + if (ImStricmp(History[i], command_line) == 0) + { + ImGui::MemFree(History[i]); + History.erase(History.begin() + i); + break; + } + History.push_back(ImStrdup(command_line)); + + // Process command + if (ImStricmp(command_line, "CLEAR") == 0) + { + ClearLog(); + } + else if (ImStricmp(command_line, "HELP") == 0) + { + AddLog("Commands:"); + for (size_t i = 0; i < Commands.size(); i++) + AddLog("- %s", Commands[i]); + } + else if (ImStricmp(command_line, "HISTORY") == 0) + { + for (size_t i = History.size() >= 10 ? History.size() - 10 : 0; i < History.size(); i++) + AddLog("%3d: %s\n", i, History[i]); + } + else + { + AddLog("Unknown command: '%s'\n", command_line); + } + } + + static void TextEditCallbackStub(ImGuiTextEditCallbackData* data) + { + ExampleAppConsole* console = (ExampleAppConsole*)data->UserData; + console->TextEditCallback(data); } void TextEditCallback(ImGuiTextEditCallbackData* data) @@ -7517,11 +7645,10 @@ struct ExampleAppConsole } // Build a list of candidates - const char* commands[] = { "HELP", "CLEAR", "CLASSIFY" }; ImVector candidates; - for (size_t i = 0; i < IM_ARRAYSIZE(commands); i++) - if (ImStrnicmp(commands[i], word_start, (int)(word_end-word_start)) == 0) - candidates.push_back(commands[i]); + for (size_t i = 0; i < Commands.size(); i++) + if (ImStrnicmp(Commands[i], word_start, (int)(word_end-word_start)) == 0) + candidates.push_back(Commands[i]); if (candidates.size() == 0) { @@ -7544,12 +7671,10 @@ struct ExampleAppConsole int c = 0; bool all_candidates_matches = true; for (size_t i = 0; i < candidates.size() && all_candidates_matches; i++) - { if (i == 0) c = toupper(candidates[i][match_len]); else if (c != toupper(candidates[i][match_len])) all_candidates_matches = false; - } if (!all_candidates_matches) break; match_len++; @@ -7569,91 +7694,41 @@ struct ExampleAppConsole break; } + case ImGuiKey_UpArrow: + case ImGuiKey_DownArrow: + { + // Example of HISTORY + const int prev_history_pos = HistoryPos; + if (data->EventKey == ImGuiKey_UpArrow) + { + if (HistoryPos == -1) + HistoryPos = History.size() - 1; + else if (HistoryPos > 0) + HistoryPos--; + } + else if (data->EventKey == ImGuiKey_DownArrow) + { + if (HistoryPos != -1) + if (++HistoryPos >= (int)History.size()) + HistoryPos = -1; + } + + // A better implementation would preserve the data on the current input line along with cursor position. + if (prev_history_pos != HistoryPos) + { + ImFormatString(data->Buf, data->BufSize, "%s", (HistoryPos >= 0) ? History[HistoryPos] : ""); + data->BufDirty = true; + data->CursorPos = data->SelectionStart = data->SelectionEnd = strlen(data->Buf); + } + } } } }; -static void ShowExampleAppConsole_TextEditCallback(ImGuiTextEditCallbackData* data) -{ - ExampleAppConsole* console = (ExampleAppConsole*)data->UserData; - console->TextEditCallback(data); -} - static void ShowExampleAppConsole(bool* opened) { - if (!ImGui::Begin("Example: Console", opened, ImVec2(520,600))) - { - ImGui::End(); - return; - } - - ImGui::TextWrapped("This example implement a simple console. A more elaborate implementation may want to store individual entries along with extra data such as timestamp, emitter, etc."); - ImGui::TextWrapped("Press TAB to use text completion."); - - // TODO: display from bottom - // TODO: clip manually - // TODO: history - static ExampleAppConsole console; - static char input[256] = ""; - - if (ImGui::SmallButton("Add Dummy Text")) console.AddLog("some text\nsome more text"); - ImGui::SameLine(); - if (ImGui::SmallButton("Add Dummy Error")) console.AddLog("[error] something went wrong"); - ImGui::SameLine(); - if (ImGui::SmallButton("Clear all")) console.Clear(); - ImGui::Separator(); - - ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(0,0)); - static ImGuiTextFilter filter; - filter.Draw("Filter (\"incl,-excl\") (\"error\")", 180); - if (ImGui::IsItemHovered()) ImGui::SetKeyboardFocusHere(-1); // Auto focus on hover - ImGui::PopStyleVar(); - ImGui::Separator(); - - ImGui::BeginChild("ScrollingRegion", ImVec2(0,-ImGui::GetTextLineSpacing()*2)); - - // Display every line as a separate entry so we can change their color or add custom widgets. If you only want raw text you can use ImGui::TextUnformatted(log.begin(), log.end()); - // NB- if you have lots of text this approach may be too inefficient. You can seek and display only the lines that are on display using a technique similar to what TextUnformatted() does, - // or faster if your entries are already stored into a table. - ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(4,1)); // tighten spacing - ImGui::GetStyle().ItemSpacing.y = 1; // tighten spacing - for (size_t i = 0; i < console.Items.size(); i++) - { - const char* item = console.Items[i]; - if (!filter.PassFilter(item)) - continue; - ImVec4 col(1,1,1,1); - if (strstr(item, "[error]")) col = ImVec4(1.0f,0.4f,0.4f,1.0f); - else if (strncmp(item, "# ", 2) == 0) col = ImVec4(1.0f,0.8f,0.6f,1.0f); - ImGui::PushStyleColor(ImGuiCol_Text, col); - ImGui::TextUnformatted(item); - ImGui::PopStyleColor(); - } - ImGui::PopStyleVar(); - if (console.NewItems) - { - ImGui::SetScrollPosHere(); - console.NewItems = false; - } - ImGui::EndChild(); - - ImGui::Separator(); - if (ImGui::InputText("Input", input, IM_ARRAYSIZE(input), ImGuiInputTextFlags_EnterReturnsTrue|ImGuiInputTextFlags_CallbackCompletion, &ShowExampleAppConsole_TextEditCallback, (void*)&console)) - { - const char* input_trimmed_end = input+strlen(input); - while (input_trimmed_end > input && input_trimmed_end[-1] == ' ') - input_trimmed_end--; - if (input_trimmed_end > input) - { - console.AddLog("# %s\n", input); - console.AddLog("Unknown command: '%.*s'\n", input_trimmed_end-input, input); // NB: we don't actually handle any command in this sample code - } - strcpy(input, ""); - } - if (ImGui::IsItemHovered()) ImGui::SetKeyboardFocusHere(-1); // Auto focus on hover - - ImGui::End(); + console.Run("Example: Console", opened); } static void ShowExampleAppLongText(bool* opened) From f8c58fe3286feb2ca006804c91d9bd0bbc736885 Mon Sep 17 00:00:00 2001 From: ocornut Date: Tue, 30 Dec 2014 16:55:32 +0000 Subject: [PATCH 091/108] Fix for Clang --- imgui.cpp | 1 - imgui.h | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/imgui.cpp b/imgui.cpp index cbb697dc..d8e80ddd 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -267,7 +267,6 @@ #include // sqrtf #include // intptr_t #include // vsnprintf -#include // memset #include // new (ptr) #ifdef _MSC_VER diff --git a/imgui.h b/imgui.h index ca5233c5..f9b41ed9 100644 --- a/imgui.h +++ b/imgui.h @@ -19,6 +19,7 @@ struct ImGuiWindow; #include // va_list #include // ptrdiff_t #include // NULL, malloc +#include // memset, memmove #ifndef IM_ASSERT #include From c9002620c66f0b857b6201317a3586314aa4d31e Mon Sep 17 00:00:00 2001 From: omar Date: Tue, 30 Dec 2014 17:13:04 +0000 Subject: [PATCH 092/108] Update README.md --- README.md | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 66b13464..6922f913 100644 --- a/README.md +++ b/README.md @@ -88,13 +88,6 @@ ImGui takes advantage of a few C++ features for convenience but nothing in the r Shall someone wants to use ImGui from another language, it should be possible to wrap ImGui to be used from a raw C API in the future. -Support -------- - -Can you develop features xxxx for ImGui? - -Please use GitHub 'Issues' facilities to suggest and discuss improvements. Your questions are often helpul to the community of users. - Donate ------ @@ -105,13 +98,23 @@ Yes please! I have setup an [**ImGui Patreon page**](http://www.patreon.com/imgu Credits ------- -Developed by [Omar Cornut](http://www.miracleworld.net). The library was developed with the support of [Media Molecule](http://www.mediamolecule.com) and first used internally on the game [Tearaway](http://tearaway.mediamolecule.com). +Developed by [Omar Cornut](http://www.miracleworld.net) and every direct or indirect contributors to the GitHub. The early version of this library was developed with the support of [Media Molecule](http://www.mediamolecule.com) and first used internally on the game [Tearaway](http://tearaway.mediamolecule.com). Embeds [proggy_clean](http://upperbounds.net) font by Tristan Grimmer (MIT license). Embeds [M+ fonts](http://mplus-fonts.sourceforge.jp/mplus-outline-fonts/index-en.html) font by Coji Morishita (free software license). -Embeds [stb_textedit.h](https://github.com/nothings/stb/) by Sean Barrett. +Embeds [stb_textedit.h](https://github.com/nothings/stb/) by Sean Barrett (public domain). -Inspiration, feedback, and testing: Casey Muratori, Atman Binstock, Mikko Mononen, Emmanuel Briney, Stefan Kamoda, Anton Mikhailov, Matt Willis. Thanks! +Inspiration, feedback, and testing for early versions: Casey Muratori, Atman Binstock, Mikko Mononen, Emmanuel Briney, Stefan Kamoda, Anton Mikhailov, Matt Willis. And everybody posting feedback, questions and patches on the GitHub. + +ImGui is financially supported on [**Patreon**](http://www.patreon.com/imgui). + +Special supporters +- Jetha Chan + +Supporters +- Michel Courtine + +And other supporters; thanks! License ------- From 505bd1a66dec39aae7e27ddb55ced4376f1a1769 Mon Sep 17 00:00:00 2001 From: ocornut Date: Wed, 31 Dec 2014 09:49:47 +0000 Subject: [PATCH 093/108] Fixed text input filtering for character in the 128-255 range. --- imgui.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index d8e80ddd..1fe974c4 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -208,6 +208,7 @@ - input number: optional range min/max for Input*() functions - input number: holding [-]/[+] buttons could increase the step speed non-linearly (or user-controlled) - input number: use mouse wheel to step up/down + - input number: non-decimal input. - layout: horizontal layout helper (github issue #97) - layout: clean up the InputFloatN/SliderFloatN/ColorEdit4 horrible layout code. item width should include frame padding. - columns: separator function or parameter that works within the column (currently Separator() bypass all columns) @@ -215,7 +216,6 @@ - columns: columns header to act as button (~sort op) and allow resize/reorder - columns: user specify columns size - combo: overlap test beyond parent window bounding box is broken (used to work) - - combo: broken visual ordering when window B is focused then click on window A:combo - combo: turn child handling code into pop up helper - list selection, concept of a selectable "block" (that can be multiple widgets) - menubar, menus @@ -4870,7 +4870,7 @@ bool ImGui::InputText(const char* label, char* buf, size_t buf_size, ImGuiInputT if (c) { // Filter - if (c < 256 && !isprint((char)(c & 0xFF)) && c != ' ') + if (c < 128 && c != ' ' && !isprint((int)(c & 0xFF))) continue; if (flags & ImGuiInputTextFlags_CharsDecimal) if (!(c >= '0' && c <= '9') && (c != '.') && (c != '-') && (c != '+') && (c != '*') && (c != '/')) From 12225abfe22eef70476f4be681bc22f9228d304b Mon Sep 17 00:00:00 2001 From: ocornut Date: Wed, 31 Dec 2014 10:38:36 +0000 Subject: [PATCH 094/108] Version number (fix) --- imgui.cpp | 2 +- imgui.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 1fe974c4..71cb7ab5 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -1,4 +1,4 @@ -// ImGui library v1.19 wip +// ImGui library v1.20 wip // See ImGui::ShowTestWindow() for sample code. // Read 'Programmer guide' below for notes on how to setup ImGui in your codebase. // Get latest version at https://github.com/ocornut/imgui diff --git a/imgui.h b/imgui.h index f9b41ed9..2334860f 100644 --- a/imgui.h +++ b/imgui.h @@ -1,4 +1,4 @@ -// ImGui library v1.19 wip +// ImGui library v1.20 wip // See .cpp file for commentary. // See ImGui::ShowTestWindow() for sample code. // Read 'Programmer guide' in .cpp for notes on how to setup ImGui in your codebase. From e4f96147de71f786c74c2b8b28879c2cd3c3605f Mon Sep 17 00:00:00 2001 From: omar Date: Wed, 31 Dec 2014 15:55:34 +0000 Subject: [PATCH 095/108] Update README.md --- README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/README.md b/README.md index 6922f913..a1171181 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,6 @@ ImGui is designed to enable fast iteration and allow programmers to create "cont ImGui is particularly suited to integration in 3D applications, fullscreen applications, embedded applications, games, or any applications on consoles platforms where operating system features are non-standard. - ImGui is self-contained within 4 files that you can easily copy and compile into your application/engine: - imgui.cpp @@ -54,7 +53,7 @@ The bulk of example user code is contained within the ImGui::ShowTestWindow() fu How do you use ImGui on a platform that may not have a mouse or keyboard? -I recommend using [Synergy](http://synergy-project.org). With the uSynergy.c micro client running you can seamlessly use your PC input devices from a video game console or a tablet. ImGui was also designed to function with touch inputs if you increase the padding of widgets to compensate for the lack of precision of touch devices, but it is recommended you use a mouse to allow optimising for screen real-estate. +I recommend using [Synergy](http://synergy-project.org). With the uSynergy.c micro client running on your platform and connecting to your PC, you can seamlessly use your PC input devices from a video game console or a tablet. ImGui allows to increase the hit box of widgets (via the _TouchPadding_ setting) to accomodate a little for the lack of precision of touch inputs, but it is recommended you use a mouse to allow optimising for screen real-estate. I integrated ImGui in my engine and the text or lines are blurry.. From 34664dc28ca9b8c9c6602cd498b58cba0a8fa1e5 Mon Sep 17 00:00:00 2001 From: ocornut Date: Sat, 3 Jan 2015 17:37:39 +0000 Subject: [PATCH 096/108] InputText() consume input characters immediately (fixes #105) --- imgui.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/imgui.cpp b/imgui.cpp index 71cb7ab5..13005d77 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -4883,6 +4883,9 @@ bool ImGui::InputText(const char* label, char* buf, size_t buf_size, ImGuiInputT edit_state.OnKeyPressed(c); } } + + // Consume characters + memset(g.IO.InputCharacters, 0, sizeof(g.IO.InputCharacters)); } edit_state.CursorAnim += g.IO.DeltaTime; From ee49c2288d532f55115cd6a8b5a2e606836e1cbb Mon Sep 17 00:00:00 2001 From: ocornut Date: Sat, 3 Jan 2015 17:38:10 +0000 Subject: [PATCH 097/108] Todo items. --- imgui.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/imgui.cpp b/imgui.cpp index 13005d77..0e36cc6a 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -233,8 +233,10 @@ - text edit: add multi-line text edit - settings: write more decent code to allow saving/loading new fields - settings: api for per-tool simple persistent data (bool,int,float) in .ini file + - log: LogButtons() options for specifying depth and/orhiding depth slider + - log: LogTofile() error handling - log: have more control over the log scope (e.g. stop logging when leaving current tree node scope) - - log: be able to right-click and log a window or tree-node into tty/file/clipboard? + - log: be able to right-click and log a window or tree-node into tty/file/clipboard / generalized context menu? - filters: set a current filter that tree node can automatically query to hide themselves - filters: handle wildcards (with implicit leading/trailing *), regexps - shortcuts: add a shortcut api, e.g. parse "&Save" and/or "Save (CTRL+S)", pass in to widgets or provide simple ways to use (button=activate, input=focus) From 4bccc06933c75d1dc30ef7e5039f86637541888c Mon Sep 17 00:00:00 2001 From: ocornut Date: Sun, 4 Jan 2015 18:12:30 +0000 Subject: [PATCH 098/108] Dragging outside area of a widget while it is active doesn't trigger hover on other widgets. --- imgui.cpp | 61 ++++++++++++++++++++++++++----------------------------- 1 file changed, 29 insertions(+), 32 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 0e36cc6a..6f5b1cb8 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -199,7 +199,9 @@ - window: add a way for very transient windows (non-saved, temporary overlay over hundreds of objects) to "clean" up from the global window list. - widgets: switching from "widget-label" to "label-widget" would make it more convenient to integrate widgets in trees - widgets: clip text? hover clipped text shows it in a tooltip or in-place overlay + - widgets: checkbox/radio active on press, is that standard/correct ? - widgets: widget-label types of function calls don't play nicely with SameLine (github issue #100) because of how they intentionally not declare the label extent. separate extent for auto-size vs extent for cursor. + - widgets: IsItemHovered() returns true even if mouse is active on another widget (e.g. dragging outside of sliders). Maybe not a sensible default? Add parameter or alternate function? - main: make IsHovered() more consistent for various type of widgets, widgets with multiple components, etc. also effectively IsHovered() region sometimes differs from hot region, e.g tree nodes - main: make IsHovered() info stored in a stack? so that 'if TreeNode() { Text; TreePop; } if IsHovered' return the hover state of the TreeNode? - scrollbar: use relative mouse movement when first-clicking inside of scroll grab box. @@ -217,6 +219,7 @@ - columns: user specify columns size - combo: overlap test beyond parent window bounding box is broken (used to work) - combo: turn child handling code into pop up helper + - combo: clicking on e.g. checkbox or radio outside combo doesn't close combo because checkbox/radio doesn't set ActiveID (activate on-click) - list selection, concept of a selectable "block" (that can be multiple widgets) - menubar, menus - plot: make it easier for user to draw into the graph (e.g: draw basis, highlight certain points, 2d plots, multiple plots) @@ -3326,12 +3329,24 @@ void ImGui::LabelText(const char* label, const char* fmt, ...) va_end(args); } +static bool IsHovered(const ImGuiAabb& bb, const ImGuiID& id) +{ + ImGuiState& g = GImGui; + if (g.HoveredId == 0) + { + ImGuiWindow* window = GetCurrentWindow(); + const bool hovered = (g.HoveredRootWindow == window->RootWindow) && (g.ActiveId == 0 || g.ActiveId == id) && IsMouseHoveringBox(bb); + return hovered; + } + return false; +} + static bool ButtonBehaviour(const ImGuiAabb& bb, const ImGuiID& id, bool* out_hovered, bool* out_held, bool allow_key_modifiers, bool repeat) { ImGuiState& g = GImGui; ImGuiWindow* window = GetCurrentWindow(); - const bool hovered = (g.HoveredRootWindow == window->RootWindow) && (g.HoveredId == 0) && IsMouseHoveringBox(bb); + const bool hovered = IsHovered(bb, id); bool pressed = false; if (hovered) { @@ -3926,7 +3941,7 @@ bool ImGui::SliderFloat(const char* label, float* v, float v_min, float v_max, c } } - const bool hovered = (g.HoveredWindow == window) && (g.HoveredId == 0) && IsMouseHoveringBox(slider_bb); + const bool hovered = IsHovered(slider_bb, id); if (hovered) g.HoveredId = id; @@ -4356,7 +4371,7 @@ bool ImGui::Checkbox(const char* label, bool* v) if (ClipAdvance(total_bb)) return false; - const bool hovered = (g.HoveredWindow == window) && (g.HoveredId == 0) && IsMouseHoveringBox(total_bb); + const bool hovered = IsHovered(total_bb, id); const bool pressed = hovered && g.IO.MouseClicked[0]; if (hovered) g.HoveredId = id; @@ -4425,7 +4440,7 @@ bool ImGui::RadioButton(const char* label, bool active) center.y = (float)(int)center.y + 0.5f; const float radius = check_bb.GetHeight() * 0.5f; - const bool hovered = (g.HoveredWindow == window) && (g.HoveredId == 0) && IsMouseHoveringBox(total_bb); + const bool hovered = IsHovered(total_bb, id); const bool pressed = hovered && g.IO.MouseClicked[0]; if (hovered) g.HoveredId = id; @@ -4736,7 +4751,7 @@ bool ImGui::InputText(const char* label, char* buf, size_t buf_size, ImGuiInputT const bool tab_focus_requested = window->FocusItemRegister(g.ActiveId == id, (flags & ImGuiInputTextFlags_CallbackCompletion) == 0); // Using completion callback disable keyboard tabbing //const bool align_center = (bool)(flags & ImGuiInputTextFlags_AlignCenter); // FIXME: Unsupported - const bool hovered = (g.HoveredWindow == window) && (g.HoveredId == 0) && IsMouseHoveringBox(frame_bb); + const bool hovered = IsHovered(frame_bb, id); if (hovered) g.HoveredId = id; @@ -5126,7 +5141,7 @@ bool ImGui::Combo(const char* label, int* current_item, bool (*items_getter)(voi const ImGuiAabb bb(frame_bb.Min, frame_bb.Max + ImVec2(style.ItemInnerSpacing.x + text_size.x,0)); const float arrow_size = (window->FontSize() + style.FramePadding.x * 2.0f); - const bool hovered = (g.HoveredWindow == window) && (g.HoveredId == 0) && IsMouseHoveringBox(bb); + const bool hovered = IsHovered(bb, id); bool value_changed = false; RenderFrame(frame_bb.Min, frame_bb.Max, window->Color(ImGuiCol_FrameBg)); @@ -5242,7 +5257,7 @@ bool ImGui::ColorButton(const ImVec4& col, bool small_height, bool outline_borde if (ClipAdvance(bb)) return false; - const bool hovered = (g.HoveredWindow == window) && (g.HoveredId == 0) && IsMouseHoveringBox(bb); + const bool hovered = IsHovered(bb, 0); const bool pressed = hovered && g.IO.MouseClicked[0]; RenderFrame(bb.Min, bb.Max, window->Color(col), outline_border); @@ -7157,7 +7172,7 @@ void ImGui::ShowTestWindow(bool* opened) ImGui::PlotHistogram("Histogram", arr, IM_ARRAYSIZE(arr), 0, NULL, 0.0f, 1.0f, ImVec2(0,70)); } - if (ImGui::CollapsingHeader("Widgets on same line")) + if (ImGui::CollapsingHeader("Horizontal Layout")) { // Text ImGui::Text("Hello"); @@ -7172,13 +7187,11 @@ void ImGui::ShowTestWindow(bool* opened) ImGui::Button("Corniflower"); // Button - ImGui::SmallButton("Banana"); + ImGui::Text("Small buttons"); ImGui::SameLine(); - ImGui::SmallButton("Apple"); + ImGui::SmallButton("Like this one"); ImGui::SameLine(); - ImGui::SmallButton("Corniflower"); - ImGui::SameLine(); - ImGui::Text("Small buttons fit in a text block"); + ImGui::Text("can fit within a text block."); // Checkbox static bool c1=false,c2=false,c3=false,c4=false; @@ -7193,27 +7206,11 @@ void ImGui::ShowTestWindow(bool* opened) // SliderFloat static float f0=1.0f, f1=2.0f, f2=3.0f; ImGui::PushItemWidth(80); - ImGui::SliderFloat("f0", &f0, 0.0f,5.0f); + ImGui::SliderFloat("X", &f0, 0.0f,5.0f); ImGui::SameLine(); - ImGui::SliderFloat("f1", &f1, 0.0f,5.0f); + ImGui::SliderFloat("Y", &f1, 0.0f,5.0f); ImGui::SameLine(); - ImGui::SliderFloat("f2", &f2, 0.0f,5.0f); - - // InputText - static char s0[128] = "one", s1[128] = "two", s2[128] = "three"; - ImGui::InputText("s0", s0, 128); - ImGui::SameLine(); - ImGui::InputText("s1", s1, 128); - ImGui::SameLine(); - ImGui::InputText("s2", s2, 128); - - // LabelText - ImGui::LabelText("l0", "one"); - ImGui::SameLine(); - ImGui::LabelText("l0", "two"); - ImGui::SameLine(); - ImGui::LabelText("l0", "three"); - ImGui::PopItemWidth(); + ImGui::SliderFloat("Z", &f2, 0.0f,5.0f); } if (ImGui::CollapsingHeader("Child regions")) From 2268b098e031a0a71fede76ed37c67b8185a931f Mon Sep 17 00:00:00 2001 From: ocornut Date: Sun, 4 Jan 2015 18:23:30 +0000 Subject: [PATCH 099/108] Avoid marking settings as dirty when window is marked unsaved + minor FocusWindow() optimisation --- imgui.cpp | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 6f5b1cb8..362cb28e 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -202,6 +202,7 @@ - widgets: checkbox/radio active on press, is that standard/correct ? - widgets: widget-label types of function calls don't play nicely with SameLine (github issue #100) because of how they intentionally not declare the label extent. separate extent for auto-size vs extent for cursor. - widgets: IsItemHovered() returns true even if mouse is active on another widget (e.g. dragging outside of sliders). Maybe not a sensible default? Add parameter or alternate function? + - widgets: activating widget doesn't move parent to front - main: make IsHovered() more consistent for various type of widgets, widgets with multiple components, etc. also effectively IsHovered() region sometimes differs from hot region, e.g tree nodes - main: make IsHovered() info stored in a stack? so that 'if TreeNode() { Text; TreePop; } if IsHovered' return the hover state of the TreeNode? - scrollbar: use relative mouse movement when first-clicking inside of scroll grab box. @@ -2361,7 +2362,7 @@ bool ImGui::Begin(const char* name, bool* p_opened, ImVec2 size, float fill_alph window->IDStack.resize(0); ImGui::PushID(window); - // Move window (at the beginning of the frame to avoid lag) + // Move window (at the beginning of the frame to avoid input lag or sheering) const ImGuiID move_id = window->GetID("#MOVE"); RegisterAliveId(move_id); if (g.ActiveId == move_id) @@ -2371,7 +2372,8 @@ bool ImGui::Begin(const char* name, bool* p_opened, ImVec2 size, float fill_alph if (!(window->Flags & ImGuiWindowFlags_NoMove)) { window->PosFloat += g.IO.MouseDelta; - MarkSettingsDirty(); + if (!(window->Flags & ImGuiWindowFlags_NoSavedSettings)) + MarkSettingsDirty(); } FocusWindow(window); } @@ -2434,7 +2436,8 @@ bool ImGui::Begin(const char* name, bool* p_opened, ImVec2 size, float fill_alph if (g.HoveredWindow == window && IsMouseHoveringBox(title_bar_aabb) && g.IO.MouseDoubleClicked[0]) { window->Collapsed = !window->Collapsed; - MarkSettingsDirty(); + if (!(window->Flags & ImGuiWindowFlags_NoSavedSettings)) + MarkSettingsDirty(); FocusWindow(window); } } @@ -2482,7 +2485,8 @@ bool ImGui::Begin(const char* name, bool* p_opened, ImVec2 size, float fill_alph window->SizeFull = ImMax(window->SizeFull, size_auto_fit); else window->SizeFull = size_auto_fit; - MarkSettingsDirty(); + if (!(window->Flags & ImGuiWindowFlags_NoSavedSettings)) + MarkSettingsDirty(); } else if (!(window->Flags & ImGuiWindowFlags_NoResize)) { @@ -2498,14 +2502,16 @@ bool ImGui::Begin(const char* name, bool* p_opened, ImVec2 size, float fill_alph // Manual auto-fit window->SizeFull = size_auto_fit; window->Size = window->SizeFull; - MarkSettingsDirty(); + if (!(window->Flags & ImGuiWindowFlags_NoSavedSettings)) + MarkSettingsDirty(); } else if (held) { // Resize window->SizeFull = ImMax(window->SizeFull + g.IO.MouseDelta, style.WindowMinSize); window->Size = window->SizeFull; - MarkSettingsDirty(); + if (!(window->Flags & ImGuiWindowFlags_NoSavedSettings)) + MarkSettingsDirty(); } } @@ -2709,12 +2715,15 @@ void ImGui::End() g.CurrentWindow = g.CurrentWindowStack.empty() ? NULL : g.CurrentWindowStack.back(); } -// Moving window to front +// Moving window to front of display (which happens to be back of our sorted list) static void FocusWindow(ImGuiWindow* window) { ImGuiState& g = GImGui; g.FocusedWindow = window; + if (g.Windows.back() == window) + return; + for (size_t i = 0; i < g.Windows.size(); i++) if (g.Windows[i] == window) { From 3674d30e90ad9a8cd7c0a967d5b163d145c3e678 Mon Sep 17 00:00:00 2001 From: ocornut Date: Sun, 4 Jan 2015 18:32:15 +0000 Subject: [PATCH 100/108] Fixed clicking on Combo box label. --- imgui.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/imgui.cpp b/imgui.cpp index 362cb28e..4c9e4edb 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -5150,7 +5150,7 @@ bool ImGui::Combo(const char* label, int* current_item, bool (*items_getter)(voi const ImGuiAabb bb(frame_bb.Min, frame_bb.Max + ImVec2(style.ItemInnerSpacing.x + text_size.x,0)); const float arrow_size = (window->FontSize() + style.FramePadding.x * 2.0f); - const bool hovered = IsHovered(bb, id); + const bool hovered = IsHovered(frame_bb, id); bool value_changed = false; RenderFrame(frame_bb.Min, frame_bb.Max, window->Color(ImGuiCol_FrameBg)); From a5f4108781cb937f89549ff7560b68f39916990f Mon Sep 17 00:00:00 2001 From: ocornut Date: Sun, 4 Jan 2015 18:36:33 +0000 Subject: [PATCH 101/108] Activating widget bring parent window to front --- imgui.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 4c9e4edb..3e253eaa 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -200,9 +200,7 @@ - widgets: switching from "widget-label" to "label-widget" would make it more convenient to integrate widgets in trees - widgets: clip text? hover clipped text shows it in a tooltip or in-place overlay - widgets: checkbox/radio active on press, is that standard/correct ? - - widgets: widget-label types of function calls don't play nicely with SameLine (github issue #100) because of how they intentionally not declare the label extent. separate extent for auto-size vs extent for cursor. - widgets: IsItemHovered() returns true even if mouse is active on another widget (e.g. dragging outside of sliders). Maybe not a sensible default? Add parameter or alternate function? - - widgets: activating widget doesn't move parent to front - main: make IsHovered() more consistent for various type of widgets, widgets with multiple components, etc. also effectively IsHovered() region sometimes differs from hot region, e.g tree nodes - main: make IsHovered() info stored in a stack? so that 'if TreeNode() { Text; TreePop; } if IsHovered' return the hover state of the TreeNode? - scrollbar: use relative mouse movement when first-clicking inside of scroll grab box. @@ -3365,6 +3363,7 @@ static bool ButtonBehaviour(const ImGuiAabb& bb, const ImGuiID& id, bool* out_ho if (g.IO.MouseClicked[0]) { g.ActiveId = id; + FocusWindow(window); } else if (repeat && g.ActiveId && ImGui::IsMouseClicked(0, true)) { @@ -3958,6 +3957,7 @@ bool ImGui::SliderFloat(const char* label, float* v, float v_min, float v_max, c if (tab_focus_requested || (hovered && g.IO.MouseClicked[0])) { g.ActiveId = id; + FocusWindow(window); const bool is_ctrl_down = g.IO.KeyCtrl; if (tab_focus_requested || is_ctrl_down || is_unbound) @@ -4783,6 +4783,7 @@ bool ImGui::InputText(const char* label, char* buf, size_t buf_size, ImGuiInputT select_all = true; } g.ActiveId = id; + FocusWindow(window); } else if (io.MouseClicked[0]) { @@ -5180,6 +5181,8 @@ bool ImGui::Combo(const char* label, int* current_item, bool (*items_getter)(voi { menu_toggled = true; g.ActiveComboID = (g.ActiveComboID == id) ? 0 : id; + if (g.ActiveComboID) + FocusWindow(window); } } @@ -5221,7 +5224,7 @@ bool ImGui::Combo(const char* label, int* current_item, bool (*items_getter)(voi const char* item_text; if (!items_getter(data, item_idx, &item_text)) item_text = "*Unknown item*"; - ImGui::Text("%s", item_text); + ImGui::TextUnformatted(item_text); if (item_selected) { From 97d34271f8da8f0ec9af2c74ecce10209db287e0 Mon Sep 17 00:00:00 2001 From: ocornut Date: Sun, 4 Jan 2015 18:47:08 +0000 Subject: [PATCH 102/108] Fix clipboard pasting into an InputText box not filtering the characters according to input box semantic (number, etc.) --- imgui.cpp | 40 ++++++++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 3e253eaa..8a411c83 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -231,7 +231,6 @@ - text edit: centered text for slider or input text to it matches typical positioning. - text edit: flag to disable live update of the user buffer. - text edit: field resize behavior - field could stretch when being edited? hover tooltip shows more text? - - text edit: pasting text into a number box should filter the characters the same way direct input does - text edit: add multi-line text edit - settings: write more decent code to allow saving/loading new fields - settings: api for per-tool simple persistent data (bool,int,float) in .ini file @@ -4730,6 +4729,22 @@ void ImGuiTextEditCallbackData::InsertChars(int pos, const char* new_text, const SelectionStart = SelectionEnd = CursorPos; } +static bool InputTextFilterCharacter(ImWchar c, ImGuiInputTextFlags flags) +{ + if (c < 128 && c != ' ' && !isprint((int)(c & 0xFF))) + return true; + + if (flags & ImGuiInputTextFlags_CharsDecimal) + if (!(c >= '0' && c <= '9') && (c != '.') && (c != '-') && (c != '+') && (c != '*') && (c != '/')) + return true; + + if (flags & ImGuiInputTextFlags_CharsHexadecimal) + if (!(c >= '0' && c <= '9') && !(c >= 'a' && c <= 'f') && !(c >= 'A' && c <= 'F')) + return true; + + return false; +} + // Edit a string of text bool ImGui::InputText(const char* label, char* buf, size_t buf_size, ImGuiInputTextFlags flags, void (*callback)(ImGuiTextEditCallbackData*), void* user_data) { @@ -4876,14 +4891,15 @@ bool ImGui::InputText(const char* label, char* buf, size_t buf_size, ImGuiInputT if (bytes_count <= 0) break; s += bytes_count; - if (c == '\n' || c == '\r') - continue; if (c >= 0x10000) continue; - clipboard_filtered[clipboard_filtered_len++] = (ImWchar)c; + if (InputTextFilterCharacter((ImWchar)c, flags)) + continue; + clipboard_filtered[clipboard_filtered_len++] = (ImWchar)c; } clipboard_filtered[clipboard_filtered_len] = 0; - stb_textedit_paste(&edit_state, &edit_state.StbState, clipboard_filtered, clipboard_filtered_len); + if (clipboard_filtered_len > 0) // If everything was filtered, ignore the pasting operation + stb_textedit_paste(&edit_state, &edit_state.StbState, clipboard_filtered, clipboard_filtered_len); ImGui::MemFree(clipboard_filtered); } } @@ -4896,17 +4912,9 @@ bool ImGui::InputText(const char* label, char* buf, size_t buf_size, ImGuiInputT const ImWchar c = g.IO.InputCharacters[n]; if (c) { - // Filter - if (c < 128 && c != ' ' && !isprint((int)(c & 0xFF))) - continue; - if (flags & ImGuiInputTextFlags_CharsDecimal) - if (!(c >= '0' && c <= '9') && (c != '.') && (c != '-') && (c != '+') && (c != '*') && (c != '/')) - continue; - if (flags & ImGuiInputTextFlags_CharsHexadecimal) - if (!(c >= '0' && c <= '9') && !(c >= 'a' && c <= 'f') && !(c >= 'A' && c <= 'F')) - continue; - - // Insert character! + // Insert character if they pass filtering + if (InputTextFilterCharacter(c, flags)) + continue; edit_state.OnKeyPressed(c); } } From 39373b563b1fdc3ef957bedce6c4dc5068481f78 Mon Sep 17 00:00:00 2001 From: ocornut Date: Sun, 4 Jan 2015 19:23:36 +0000 Subject: [PATCH 103/108] Checkbox and Radio buttons activate on click-release to be consistent with other widgets and most UI --- imgui.cpp | 67 +++++++++++++++++++++++++------------------------------ imgui.h | 5 +++-- 2 files changed, 33 insertions(+), 39 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 8a411c83..135ef077 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -199,7 +199,6 @@ - window: add a way for very transient windows (non-saved, temporary overlay over hundreds of objects) to "clean" up from the global window list. - widgets: switching from "widget-label" to "label-widget" would make it more convenient to integrate widgets in trees - widgets: clip text? hover clipped text shows it in a tooltip or in-place overlay - - widgets: checkbox/radio active on press, is that standard/correct ? - widgets: IsItemHovered() returns true even if mouse is active on another widget (e.g. dragging outside of sliders). Maybe not a sensible default? Add parameter or alternate function? - main: make IsHovered() more consistent for various type of widgets, widgets with multiple components, etc. also effectively IsHovered() region sometimes differs from hot region, e.g tree nodes - main: make IsHovered() info stored in a stack? so that 'if TreeNode() { Text; TreePop; } if IsHovered' return the hover state of the TreeNode? @@ -218,7 +217,6 @@ - columns: user specify columns size - combo: overlap test beyond parent window bounding box is broken (used to work) - combo: turn child handling code into pop up helper - - combo: clicking on e.g. checkbox or radio outside combo doesn't close combo because checkbox/radio doesn't set ActiveID (activate on-click) - list selection, concept of a selectable "block" (that can be multiple widgets) - menubar, menus - plot: make it easier for user to draw into the graph (e.g: draw basis, highlight certain points, 2d plots, multiple plots) @@ -374,8 +372,9 @@ ImGuiStyle::ImGuiStyle() Colors[ImGuiCol_ScrollbarGrabHovered] = ImVec4(0.40f, 0.40f, 0.80f, 0.40f); Colors[ImGuiCol_ScrollbarGrabActive] = ImVec4(0.80f, 0.50f, 0.50f, 0.40f); Colors[ImGuiCol_ComboBg] = ImVec4(0.20f, 0.20f, 0.20f, 0.99f); - Colors[ImGuiCol_CheckHovered] = ImVec4(0.60f, 0.40f, 0.40f, 0.45f); - Colors[ImGuiCol_CheckActive] = ImVec4(0.90f, 0.90f, 0.90f, 0.50f); + Colors[ImGuiCol_CheckBgHovered] = ImVec4(0.60f, 0.40f, 0.40f, 0.45f); + Colors[ImGuiCol_CheckBgActive] = ImVec4(0.65f, 0.50f, 0.50f, 0.55f); + Colors[ImGuiCol_CheckSelected] = ImVec4(0.90f, 0.90f, 0.90f, 0.50f); Colors[ImGuiCol_SliderGrab] = ImVec4(1.00f, 1.00f, 1.00f, 0.30f); Colors[ImGuiCol_SliderGrabActive] = ImVec4(0.80f, 0.50f, 0.50f, 1.00f); Colors[ImGuiCol_Button] = ImVec4(0.67f, 0.40f, 0.40f, 0.60f); @@ -2882,8 +2881,9 @@ const char* ImGui::GetStyleColName(ImGuiCol idx) case ImGuiCol_ScrollbarGrabHovered: return "ScrollbarGrabHovered"; case ImGuiCol_ScrollbarGrabActive: return "ScrollbarGrabActive"; case ImGuiCol_ComboBg: return "ComboBg"; - case ImGuiCol_CheckHovered: return "CheckHovered"; - case ImGuiCol_CheckActive: return "CheckActive"; + case ImGuiCol_CheckBgHovered: return "CheckBgHovered"; + case ImGuiCol_CheckBgActive: return "CheckBgActive"; + case ImGuiCol_CheckSelected: return "CheckSelected"; case ImGuiCol_SliderGrab: return "SliderGrab"; case ImGuiCol_SliderGrabActive: return "SliderGrabActive"; case ImGuiCol_Button: return "Button"; @@ -4379,22 +4379,17 @@ bool ImGui::Checkbox(const char* label, bool* v) if (ClipAdvance(total_bb)) return false; - const bool hovered = IsHovered(total_bb, id); - const bool pressed = hovered && g.IO.MouseClicked[0]; - if (hovered) - g.HoveredId = id; + bool hovered, held; + bool pressed = ButtonBehaviour(total_bb, id, &hovered, &held, true); if (pressed) - { *v = !(*v); - g.ActiveId = 0; // Clear focus - } - RenderFrame(check_bb.Min, check_bb.Max, window->Color(hovered ? ImGuiCol_CheckHovered : ImGuiCol_FrameBg)); + RenderFrame(check_bb.Min, check_bb.Max, window->Color((held && hovered) ? ImGuiCol_CheckBgActive : hovered ? ImGuiCol_CheckBgHovered : ImGuiCol_FrameBg)); if (*v) { const float check_sz = ImMin(check_bb.GetWidth(), check_bb.GetHeight()); const float pad = check_sz < 8.0f ? 1.0f : check_sz < 13.0f ? 2.0f : 3.0f; - window->DrawList->AddRectFilled(check_bb.Min+ImVec2(pad,pad), check_bb.Max-ImVec2(pad,pad), window->Color(ImGuiCol_CheckActive)); + window->DrawList->AddRectFilled(check_bb.Min+ImVec2(pad,pad), check_bb.Max-ImVec2(pad,pad), window->Color(ImGuiCol_CheckSelected)); } if (g.LogEnabled) @@ -4448,17 +4443,15 @@ bool ImGui::RadioButton(const char* label, bool active) center.y = (float)(int)center.y + 0.5f; const float radius = check_bb.GetHeight() * 0.5f; - const bool hovered = IsHovered(total_bb, id); - const bool pressed = hovered && g.IO.MouseClicked[0]; - if (hovered) - g.HoveredId = id; + bool hovered, held; + bool pressed = ButtonBehaviour(total_bb, id, &hovered, &held, true); - window->DrawList->AddCircleFilled(center, radius, window->Color(hovered ? ImGuiCol_CheckHovered : ImGuiCol_FrameBg), 16); + window->DrawList->AddCircleFilled(center, radius, window->Color((held && hovered) ? ImGuiCol_CheckBgActive : hovered ? ImGuiCol_CheckBgHovered : ImGuiCol_FrameBg), 16); if (active) { const float check_sz = ImMin(check_bb.GetWidth(), check_bb.GetHeight()); const float pad = check_sz < 8.0f ? 1.0f : check_sz < 13.0f ? 2.0f : 3.0f; - window->DrawList->AddCircleFilled(center, radius-pad, window->Color(ImGuiCol_CheckActive), 16); + window->DrawList->AddCircleFilled(center, radius-pad, window->Color(ImGuiCol_CheckSelected), 16); } if (window->Flags & ImGuiWindowFlags_ShowBorders) @@ -4731,18 +4724,18 @@ void ImGuiTextEditCallbackData::InsertChars(int pos, const char* new_text, const static bool InputTextFilterCharacter(ImWchar c, ImGuiInputTextFlags flags) { - if (c < 128 && c != ' ' && !isprint((int)(c & 0xFF))) - return true; + if (c < 128 && c != ' ' && !isprint((int)(c & 0xFF))) + return true; - if (flags & ImGuiInputTextFlags_CharsDecimal) - if (!(c >= '0' && c <= '9') && (c != '.') && (c != '-') && (c != '+') && (c != '*') && (c != '/')) - return true; + if (flags & ImGuiInputTextFlags_CharsDecimal) + if (!(c >= '0' && c <= '9') && (c != '.') && (c != '-') && (c != '+') && (c != '*') && (c != '/')) + return true; - if (flags & ImGuiInputTextFlags_CharsHexadecimal) - if (!(c >= '0' && c <= '9') && !(c >= 'a' && c <= 'f') && !(c >= 'A' && c <= 'F')) - return true; + if (flags & ImGuiInputTextFlags_CharsHexadecimal) + if (!(c >= '0' && c <= '9') && !(c >= 'a' && c <= 'f') && !(c >= 'A' && c <= 'F')) + return true; - return false; + return false; } // Edit a string of text @@ -4893,13 +4886,13 @@ bool ImGui::InputText(const char* label, char* buf, size_t buf_size, ImGuiInputT s += bytes_count; if (c >= 0x10000) continue; - if (InputTextFilterCharacter((ImWchar)c, flags)) - continue; - clipboard_filtered[clipboard_filtered_len++] = (ImWchar)c; + if (InputTextFilterCharacter((ImWchar)c, flags)) + continue; + clipboard_filtered[clipboard_filtered_len++] = (ImWchar)c; } clipboard_filtered[clipboard_filtered_len] = 0; if (clipboard_filtered_len > 0) // If everything was filtered, ignore the pasting operation - stb_textedit_paste(&edit_state, &edit_state.StbState, clipboard_filtered, clipboard_filtered_len); + stb_textedit_paste(&edit_state, &edit_state.StbState, clipboard_filtered, clipboard_filtered_len); ImGui::MemFree(clipboard_filtered); } } @@ -4912,9 +4905,9 @@ bool ImGui::InputText(const char* label, char* buf, size_t buf_size, ImGuiInputT const ImWchar c = g.IO.InputCharacters[n]; if (c) { - // Insert character if they pass filtering - if (InputTextFilterCharacter(c, flags)) - continue; + // Insert character if they pass filtering + if (InputTextFilterCharacter(c, flags)) + continue; edit_state.OnKeyPressed(c); } } diff --git a/imgui.h b/imgui.h index 2334860f..1a2e5bf3 100644 --- a/imgui.h +++ b/imgui.h @@ -385,8 +385,9 @@ enum ImGuiCol_ ImGuiCol_ScrollbarGrabHovered, ImGuiCol_ScrollbarGrabActive, ImGuiCol_ComboBg, - ImGuiCol_CheckHovered, - ImGuiCol_CheckActive, + ImGuiCol_CheckBgHovered, + ImGuiCol_CheckBgActive, + ImGuiCol_CheckSelected, ImGuiCol_SliderGrab, ImGuiCol_SliderGrabActive, ImGuiCol_Button, From 22c1d7ededb8662f54a494f129ac75214da09457 Mon Sep 17 00:00:00 2001 From: ocornut Date: Sun, 4 Jan 2015 19:37:24 +0000 Subject: [PATCH 104/108] Renamed some color enums --- imgui.cpp | 20 ++++++++++---------- imgui.h | 6 +++--- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 135ef077..1bd32dd0 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -372,9 +372,9 @@ ImGuiStyle::ImGuiStyle() Colors[ImGuiCol_ScrollbarGrabHovered] = ImVec4(0.40f, 0.40f, 0.80f, 0.40f); Colors[ImGuiCol_ScrollbarGrabActive] = ImVec4(0.80f, 0.50f, 0.50f, 0.40f); Colors[ImGuiCol_ComboBg] = ImVec4(0.20f, 0.20f, 0.20f, 0.99f); - Colors[ImGuiCol_CheckBgHovered] = ImVec4(0.60f, 0.40f, 0.40f, 0.45f); - Colors[ImGuiCol_CheckBgActive] = ImVec4(0.65f, 0.50f, 0.50f, 0.55f); - Colors[ImGuiCol_CheckSelected] = ImVec4(0.90f, 0.90f, 0.90f, 0.50f); + Colors[ImGuiCol_CheckHovered] = ImVec4(0.60f, 0.40f, 0.40f, 0.45f); + Colors[ImGuiCol_CheckActive] = ImVec4(0.65f, 0.50f, 0.50f, 0.55f); + Colors[ImGuiCol_CheckMark] = ImVec4(0.90f, 0.90f, 0.90f, 0.50f); Colors[ImGuiCol_SliderGrab] = ImVec4(1.00f, 1.00f, 1.00f, 0.30f); Colors[ImGuiCol_SliderGrabActive] = ImVec4(0.80f, 0.50f, 0.50f, 1.00f); Colors[ImGuiCol_Button] = ImVec4(0.67f, 0.40f, 0.40f, 0.60f); @@ -2881,9 +2881,9 @@ const char* ImGui::GetStyleColName(ImGuiCol idx) case ImGuiCol_ScrollbarGrabHovered: return "ScrollbarGrabHovered"; case ImGuiCol_ScrollbarGrabActive: return "ScrollbarGrabActive"; case ImGuiCol_ComboBg: return "ComboBg"; - case ImGuiCol_CheckBgHovered: return "CheckBgHovered"; - case ImGuiCol_CheckBgActive: return "CheckBgActive"; - case ImGuiCol_CheckSelected: return "CheckSelected"; + case ImGuiCol_CheckHovered: return "CheckBgHovered"; + case ImGuiCol_CheckActive: return "CheckBgActive"; + case ImGuiCol_CheckMark: return "CheckSelected"; case ImGuiCol_SliderGrab: return "SliderGrab"; case ImGuiCol_SliderGrabActive: return "SliderGrabActive"; case ImGuiCol_Button: return "Button"; @@ -4384,12 +4384,12 @@ bool ImGui::Checkbox(const char* label, bool* v) if (pressed) *v = !(*v); - RenderFrame(check_bb.Min, check_bb.Max, window->Color((held && hovered) ? ImGuiCol_CheckBgActive : hovered ? ImGuiCol_CheckBgHovered : ImGuiCol_FrameBg)); + RenderFrame(check_bb.Min, check_bb.Max, window->Color((held && hovered) ? ImGuiCol_CheckActive : hovered ? ImGuiCol_CheckHovered : ImGuiCol_FrameBg)); if (*v) { const float check_sz = ImMin(check_bb.GetWidth(), check_bb.GetHeight()); const float pad = check_sz < 8.0f ? 1.0f : check_sz < 13.0f ? 2.0f : 3.0f; - window->DrawList->AddRectFilled(check_bb.Min+ImVec2(pad,pad), check_bb.Max-ImVec2(pad,pad), window->Color(ImGuiCol_CheckSelected)); + window->DrawList->AddRectFilled(check_bb.Min+ImVec2(pad,pad), check_bb.Max-ImVec2(pad,pad), window->Color(ImGuiCol_CheckMark)); } if (g.LogEnabled) @@ -4446,12 +4446,12 @@ bool ImGui::RadioButton(const char* label, bool active) bool hovered, held; bool pressed = ButtonBehaviour(total_bb, id, &hovered, &held, true); - window->DrawList->AddCircleFilled(center, radius, window->Color((held && hovered) ? ImGuiCol_CheckBgActive : hovered ? ImGuiCol_CheckBgHovered : ImGuiCol_FrameBg), 16); + window->DrawList->AddCircleFilled(center, radius, window->Color((held && hovered) ? ImGuiCol_CheckActive : hovered ? ImGuiCol_CheckHovered : ImGuiCol_FrameBg), 16); if (active) { const float check_sz = ImMin(check_bb.GetWidth(), check_bb.GetHeight()); const float pad = check_sz < 8.0f ? 1.0f : check_sz < 13.0f ? 2.0f : 3.0f; - window->DrawList->AddCircleFilled(center, radius-pad, window->Color(ImGuiCol_CheckSelected), 16); + window->DrawList->AddCircleFilled(center, radius-pad, window->Color(ImGuiCol_CheckMark), 16); } if (window->Flags & ImGuiWindowFlags_ShowBorders) diff --git a/imgui.h b/imgui.h index 1a2e5bf3..ddf94b11 100644 --- a/imgui.h +++ b/imgui.h @@ -385,9 +385,9 @@ enum ImGuiCol_ ImGuiCol_ScrollbarGrabHovered, ImGuiCol_ScrollbarGrabActive, ImGuiCol_ComboBg, - ImGuiCol_CheckBgHovered, - ImGuiCol_CheckBgActive, - ImGuiCol_CheckSelected, + ImGuiCol_CheckHovered, + ImGuiCol_CheckActive, + ImGuiCol_CheckMark, ImGuiCol_SliderGrab, ImGuiCol_SliderGrabActive, ImGuiCol_Button, From 3fe669f547f9af4cb972510eae9c68772b094ea6 Mon Sep 17 00:00:00 2001 From: ocornut Date: Sun, 4 Jan 2015 21:37:49 +0000 Subject: [PATCH 105/108] Failure in LogToFile() treated at an error (assert) in the absence of another type of error handling. --- imgui.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 1bd32dd0..fe4a27f2 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -233,7 +233,6 @@ - settings: write more decent code to allow saving/loading new fields - settings: api for per-tool simple persistent data (bool,int,float) in .ini file - log: LogButtons() options for specifying depth and/orhiding depth slider - - log: LogTofile() error handling - log: have more control over the log scope (e.g. stop logging when leaving current tree node scope) - log: be able to right-click and log a window or tree-node into tty/file/clipboard / generalized context menu? - filters: set a current filter that tree node can automatically query to hide themselves @@ -3515,8 +3514,13 @@ void ImGui::LogToFile(int max_depth, const char* filename) if (!filename) filename = g.IO.LogFilename; - g.LogEnabled = true; g.LogFile = fopen(filename, "ab"); + if (!g.LogFile) + { + IM_ASSERT(g.LogFile != NULL); // Consider this an error + return; + } + g.LogEnabled = true; g.LogStartDepth = window->DC.TreeDepth; if (max_depth >= 0) g.LogAutoExpandMaxDepth = max_depth; From 4905ec46f17c36d01761050c19a1a3f896762e5f Mon Sep 17 00:00:00 2001 From: ocornut Date: Sun, 4 Jan 2015 22:07:37 +0000 Subject: [PATCH 106/108] Fixed hovering of child windows / combo boxes that extend beyond the root window limits. --- imgui.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index fe4a27f2..75a35b4a 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -215,7 +215,6 @@ - columns: declare column set (each column: fixed size, %, fill, distribute default size among fills) - columns: columns header to act as button (~sort op) and allow resize/reorder - columns: user specify columns size - - combo: overlap test beyond parent window bounding box is broken (used to work) - combo: turn child handling code into pop up helper - list selection, concept of a selectable "block" (that can be multiple widgets) - menubar, menus @@ -1557,8 +1556,12 @@ void ImGui::NewFrame() SaveSettings(); } + // Find the window we are hovering. Child windows can extend beyond the limit of their parent so we need to derive HoveredRootWindow from HoveredWindow g.HoveredWindow = FindHoveredWindow(g.IO.MousePos, false); - g.HoveredRootWindow = FindHoveredWindow(g.IO.MousePos, true); + if (g.HoveredWindow && (g.HoveredWindow->Flags & ImGuiWindowFlags_ChildWindow)) + g.HoveredRootWindow = g.HoveredWindow->RootWindow; + else + g.HoveredRootWindow = FindHoveredWindow(g.IO.MousePos, true); // Are we using inputs? Tell user so they can capture/discard them. g.IO.WantCaptureMouse = (g.HoveredWindow != NULL) || (g.ActiveId != 0); @@ -1603,11 +1606,13 @@ void ImGui::NewFrame() } // Mark all windows as not visible + // Clear root windows at this point. for (size_t i = 0; i != g.Windows.size(); i++) { ImGuiWindow* window = g.Windows[i]; window->Visible = false; window->Accessed = false; + window->RootWindow = NULL; } // No window should be open at the beginning of the frame. @@ -2705,7 +2710,7 @@ void ImGui::End() ImGui::LogFinish(); // Pop - window->RootWindow = NULL; + // NB: we don't clear 'window->RootWindow' yet, it will be used then cleared in NewFrame() g.CurrentWindowStack.pop_back(); g.CurrentWindow = g.CurrentWindowStack.empty() ? NULL : g.CurrentWindowStack.back(); } From 0505995193dcf25ce7521d5223f6d82d690dec44 Mon Sep 17 00:00:00 2001 From: ocornut Date: Sun, 4 Jan 2015 22:29:53 +0000 Subject: [PATCH 107/108] Very minor code/comments tweaks. --- imgui.cpp | 8 ++++---- imgui.h | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 75a35b4a..55931b61 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -6625,10 +6625,10 @@ void ImFont::RenderText(float size, ImVec2 pos, ImU32 col, const ImVec4& clip_re if (!text_end) text_end = text_begin + strlen(text_begin); - const float line_height = (float)Info->FontSize; const float scale = size / (float)Info->FontSize; + const float line_height = (float)Info->FontSize * scale; const float tex_scale_x = 1.0f / (float)Common->ScaleW; - const float tex_scale_y = 1.0f / (float)(Common->ScaleH); + const float tex_scale_y = 1.0f / (float)Common->ScaleH; const float outline = (float)Info->Outline; // Align to be pixel perfect @@ -6658,7 +6658,7 @@ void ImFont::RenderText(float size, ImVec2 pos, ImU32 col, const ImVec4& clip_re if (s >= word_wrap_eol) { x = pos.x; - y += line_height * scale; + y += line_height; word_wrap_eol = NULL; // Wrapping skips upcoming blanks @@ -6679,7 +6679,7 @@ void ImFont::RenderText(float size, ImVec2 pos, ImU32 col, const ImVec4& clip_re if (c == '\n') { x = pos.x; - y += line_height * scale; + y += line_height; continue; } diff --git a/imgui.h b/imgui.h index ddf94b11..fdd17971 100644 --- a/imgui.h +++ b/imgui.h @@ -745,7 +745,7 @@ struct ImFont // Settings float Scale; // = 1.0f // Base font scale, multiplied by the per-window font scale which you can adjust with SetFontScale() - ImVec2 DisplayOffset; // = (0.0f,0.0f // Offset font rendering by xx pixels + ImVec2 DisplayOffset; // = (0.0f,0.0f) // Offset font rendering by xx pixels ImVec2 TexUvForWhite; // = (0.0f,0.0f) // Font texture must have a white pixel at this UV coordinate. Adjust if you are using custom texture. ImWchar FallbackChar; // = '?' // Replacement glyph is one isn't found. From 98a38e24ab7036522a28964cd6983bd0c683742b Mon Sep 17 00:00:00 2001 From: ocornut Date: Mon, 5 Jan 2015 11:13:02 +0000 Subject: [PATCH 108/108] Reexported proggy_clean_13 in a 256x64 texture (instead of 256x128) and documented exact export parameters --- extra_fonts/proggy_clean_13.fnt | Bin 4647 -> 4647 bytes extra_fonts/proggy_clean_13.png | Bin 1557 -> 1271 bytes imgui.cpp | 265 ++++++++++++++++---------------- 3 files changed, 132 insertions(+), 133 deletions(-) diff --git a/extra_fonts/proggy_clean_13.fnt b/extra_fonts/proggy_clean_13.fnt index 126ff7f01d681e29958d2844fbc73e2c70e0919b..f90bd09a42d6e9f36208491590ceefe5b5b7835e 100644 GIT binary patch literal 4647 zcmZ9Q2XIwI6o&WZHA)PMlu!-5g_ekd1tMJ#3@Q*63>YAwm_!r>QIHvCaC8_MnQ=tN zA(n`OMi3EH5EVfwN>Pdw5eq07qXHtL;&<-8d*8m3%$?lxy?^(dJ$tsi^c^-Z9BOQg zxya<12`0pw3587lw9?|@nf<0t9A9G6>Uba5;)6U-5Q#*>4Pa%SsIW*>h23)tyLBlm zDK?Rvmq;h}Cr-ce6E~)g^gYeAGf{p+CgQO)SPk#N~03G1cWGHCLW>Z3O75N*8?@GkwO z^Y>W5Vjhzb9Zj$>QHm}Dwl83|t)%y29yeEF@8gLYiNMAzY28FyiPNL=tmDSS{uw?8K4@Yicr6 z{5FD}=MkNsXQ{01@gaE+Cw#PrUBeTmPv36`>^#LfV$W0SqZ4d~V%e~D_(-D$WPCD5onh6UPF9Sq zwJxwKFBX{%tLy6NY+dVS69h#bcfAVEC)7Uv0T_9#V&`%O{JpsEaR88E_t~cR*7F3zrW|mTojV47_I$v zbS-Zi$d$AV!KH0)SONWs&TrcX*3M+5_|1dmtJ=5@woBDUUzkyO=?BSG{q=`sDBS>9 zFE!qQus(_nf-O~k2g52AyB@ZTyoAY%zgCC9&ZCPs^Dz{*TD83aHbD6u1{?Xz6&PnKZ4dD@7>t5RNJYr9;)p9x`ekZZUZ)d zHkMLYj_HuX%3!5|539QuR;1W8Shi|=AFQWh_rofPMb?qOwx+{s1aoP9JOFE~*n=?f z;*Mhmq%G&0JC2#K1uDLWVD(ggvtVs_qG{Zkq_Bms5_QHu58JHH^K#fcrF#Lkiafh# z{EM*B!CqqTIWNJ+qI1uWmtpI@dSO&#LB>|WTLICz`^GCU*~i>mEyZ3O|M)`OXb~e}} z>>YCjtTO1&#=H`?&C5&jp7<8*=^#F*0e+M>_T)F%B z8rW{y$_*(kQCDkW2fY4-+I{U^*fRWvyeNRmi;}BPJW~gHt@Gd)ys!48K2wVN7&-WWglb9e&@1{*z&mS6YSyYd&MT0tV36~ z8T+vyr}iBD6xQ6+$(pw8Gwh#v?3rT6u?72k#bo@472AeAUDfk;SVrQ`FRNej@;QI& zD)t2|rq~WxX5zbnzZQ1FR;%^43numJj(0byLb7oVNdY5u^hmjr`SPk*~?wsA?zIGSMr|E3xfXa9`P?MlP5~A{$1cdY+31c&aLhOq&ttj3t09)?)W`u literal 4647 zcmZA43s6*59LMp)Log#K3Zo*X!mPF;$U-Y$VG&lM6q1oqtNbK{=ysR8DfQoTS9k z;zASJZ~?#ZNi>lroObOe+?Xg^FU9mRT`+rZEtu=e5*OnAEzX2FaiLg@3A8R)f>;=q zEJhyFLEaGBv-xb^u3R&vFXv!Gq%MOtm15^&<4l?fb;cHfO%$^uf5m5=V=_^ZSiYE@ z-V~XG^RX;n|G4$`*-mS&STxo`dv%XMqhi}dixT~ zwO(>uf^GJhf1d5mnj-C8hD{TT!|W%9ahy8and5TG%f;d;-yn7c{Va?{BwFWwnXB3V#hIepI(E7N#1L*m6G>5tVYa(&6K>?W3$BU z_zzMy*je)%vAGhLh=uz4;$M%Ou!RzrgjI2rTtchk`Lh4+#b#snx#r*Z z_hGeC_kL`=h+&de}ug0%MlW+d-}NTk?9-l)L$LMB!qeHo5< zr0xi;SmGYWCW$?QrAggKu?mUH!ZIZ;8=EWh{1{d)<9!_4BXJ|KsS=liZIryZ*cs~D z=Yjv6=V8;O?kMavvC-IDVq>t`V)@uSu>x$7SRuAl>cZ3ASFW6x$^B6t-2Y4BH_#0oyG$5v%Zx!@nL+V|yiT61Gol zGPX{}F$Fs;apl-Cv1hP0v1c*+L~x(k&v`BI-S|8fCUF&5cj?Pi%$^7LJ^i9LF3@IR z_O!ZjZz3D{x;B%tT_@M(QJy9?pYk5D1(dtV^L`-~A>&wtMT;%QX35yz!$yiN!MaM0 z_pw-MuM%6vn!A5vF2zPjdmmskWRHJ{#Y=n3u+!9a&%#GoDqnZ5swnrD9MxD)vE^8a z?N@p>@a4}UnnZ!21^zD7E2e~f@O%+V~b^twqnc0wqccG z-(el}&t2aJY@5vU_t+L0$98PH*bZ#B*iOtN>-z(CK;m{`tzti76*AsN?1aSa#%vaM z5B-FMi~Wp6igiA#0_*-l+%B1eCahBWvKMQTxMr+I;(o_041>@1cg_CK=fRpbBw diff --git a/extra_fonts/proggy_clean_13.png b/extra_fonts/proggy_clean_13.png index 19922df338881788d0fcbbb9e7054c2c7ac8c81e..9fb1ca8121c6cd1622525465e4b710f91c5b795a 100644 GIT binary patch delta 1264 zcmVoz+m`n@}?;YQiw6ap$nTp{SWzVis0A&I3( zY%mR|Pyy=o7!|1s{R8b;jNZkg^S;s@RILKsy{(4F?@3~$2QFttUngi&9a|n;DQGZb1d^+4{aDmD}58FlMxalZy$6NVd zeaJz8H$2Z{w?S2C%JJWD!Jg|y9P2xu%1ksG>;*B#0c@qYX`;FyshSSsD>&dcq;yeK zXaNqSM^6ydz2P0ztZ<+sv(X^E04y_#Ya5H}I(rUs@P9+BZ+@5q-XLXeN3V?EL$62@ zzGx0DOY8N;31CLla}z@ABUusryMv9lKx;rAoGfi*B^@AE*=-0N5-l<6Q{glqo>mEv zIf+{134OzyDQddVfe_YE^OJ4!{|i6Md$q`!ChOk}B~EsaO&2O`L_oo^aI zD}~|-gMY|TqHmI46M@eO!+(pRy3~?uouAtOaa$<@|pvMQ}mBO|EB0IPl?}x*^I#yu1lWq6wl9yv!RU2Wz^~ zdJ9&H(M7&uHpq`$DMfe#1hcfOT{;M8)jZ%J(|;VT=ayx$u5^0v80p?W)>;3ZY@0<{ z4#W%JGIA|qf#q0CwXBH(Vc$8Oc^?Th@~!q?TaDzK``J}6f|Z+X@m!HuwgnV)gCV z5`R#LLT!dQM0KiZP>;Yz_Sq_5UKp676F!*qVR3xZ!|0wFVA%83 zufN@PfrilV!>$NLT1%-Hut&tSdtnB9w14E=N(0o;Vo?_{TNG2ZTPD$?trG)s_xvyi z&lGg@`gs%u;K10IGdlKy^1inQ`<#u9hP@#L@w~*5lkZKA9d~H_?`4nuS2M!aa%rYGnOfIuNC>A()<6F2czDnb+CBV+pe1d&^JN6R zjAa+gwjBn$T)2c*i(_XRVC{0?1X>;Bb&`(<>gZLe<|!!z(W`T$ph!0Qm#`DtZ1f+= a|M?3g)SL%u(7a9n0000HRVAz)n~>&KhWI4id_yC|VqeirK|3U_BZ` z06a2ip1k%f);hiqCSX050M>#B$G_mw@tgasX9B+uCIA+|DSr|MgTVj*SS%Jd{D`36 z1Xq3DfV=#6@x$dv__)|}0(h^)tr4LddhG!K@1yN@06vYk19BXIvA`7qM6eJ9)BsVa z$9`f5s6Y4&A{qdc@kev`!Oyka%z!u?$~55AosE+EF@6@XaK&6QOIW>2bY)Jxgy6bx ziU7dy+Z|v(YJX6=3xWWOrEZi)Tg^-gayjj)-$H=gCG-R2e#xBHDhV)4Z0$FYLUs6) z0`1&s8khkRtB4)IVcbJ5&+h;{{BWX4z=EZ|+W{t74c(~8!$Z*%P`i7i8QoKo_}l@R z3e66XIM>PEvM>_4!fz1ZxXT1&m-EAeUHyiDZU?ZMTz~dd1N8zR=jY0B$V+c?Nvq(- zH^K97s;Mte_`e`-K4;*^$`zA4$cMaDQ<(x9udKQ z{{360$fv8rYpf-_rE(lBVV_>WjyG4a0&;>{o_G$tR#KJ;kjn)TauDD=f&lwjt7(KF z$2lc?=1Xy|S1n!-VdE!=l7J|mRk=2LG!D>(b#KMjw(BhI_5g0`d&l59kg- z6`4VKu0*JGftV4L{J^}+anxg?X#za~_@MS@&~!vTwG8FaU=ICOO#Q&b|0xEP7J7=| z4>O?5w@~f4i+43?k;gSRl`$NJeYYJNP@YSgO z3H*#-Qgiu?qb>_UyfPvRrj#qBVjnaBDPNJQz6U_dj2`*0))&baprR0_c}yi`-hZK= z0(I$MSYzP3&qiWIt*it%QK05Dggwv`0F}v}fJ|L2lP3MF6Owc9*kIxpMi%6%VEh*6 zAqyR}1W-g-8~qam_^?(wYLlwLSyVHsjDNEOj(vyD#{h#Wd32T=dAcA?0*Fmi zb9C=MXC6hG{My9PoIB+j0kkp?EPrr4KnuJHeJ2ef33%&A0A-Yly~HSbnGfKW+GRt) zM$hd9CoJxLe+vTU-_D*D{{Y*|x)-h2}(!)hYEGUiNS>9 zCQkKTd29EkzH+hD>s*aK?2s*k=V${MO>#^%5)_LX>3iUf{+Zz@&iH+mi{H6!?=E z0tSP@U@#aA27|$1Fc=I5gTY`h7z_r3!C){L4E_O?whZ6dKziK(015yANkvXXu0mjf DPwC5F diff --git a/imgui.cpp b/imgui.cpp index 55931b61..cd2baca2 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -7815,6 +7815,7 @@ static void ShowExampleAppLongText(bool* opened) // PNG further compressed with pngout.exe http://advsys.net/ken/utils.htm // Manually converted to C++ array using the following program: /* +#include static void binary_to_c(const char* name_in, const char* symbol) { FILE* fi = fopen(name_in, "rb"); fseek(fi, 0, SEEK_END); long sz = ftell(fi); fseek(fi, 0, SEEK_SET); @@ -7832,151 +7833,149 @@ static void binary_to_c(const char* name_in, const char* symbol) int main(int argc, char** argv) { - binary_to_c("proggy_clean_13.fnt", "proggy_clean_13_fnt"); binary_to_c("proggy_clean_13.png", "proggy_clean_13_png"); + binary_to_c("proggy_clean_13.fnt", "proggy_clean_13_fnt"); return 1; } */ //----------------------------------------------------------------------------- -static const unsigned int proggy_clean_13_png_size = 1557; -static const unsigned int proggy_clean_13_png_data[1560/4] = +// ProggyClean.fon, size 13, disable "Render from TrueType outline", disable "Font Smoothing", disable "ClearType", disable "Super sampling" +// Character sets: 0000..00FF, 0100..017F +// Export options: 256x64, but depth: 32, white text with alpha, Binary, PNG +// PNG further compressed with pngout.exe +static const unsigned int proggy_clean_13_png_size = 1271; +static const unsigned int proggy_clean_13_png_data[1272/4] = { - 0x474e5089, 0x0a1a0a0d, 0x0d000000, 0x52444849, 0x00010000, 0x80000000, 0x00000308, 0x476bd300, 0x00000038, 0x544c5006, 0x00000045, 0xa5ffffff, - 0x00dd9fd9, 0x74010000, 0x00534e52, 0x66d8e640, 0xbd050000, 0x54414449, 0x9bed5e78, 0x30e36e51, 0xeef5440c, 0x31fde97f, 0x584ec0f0, 0x681ace39, - 0xca120e6b, 0x1c5a28a6, 0xc5d98a89, 0x1a3d602e, 0x323c0043, 0xf6bc9e68, 0xbe3ad62c, 0x3d60260f, 0x82d60096, 0xe0bfc707, 0xfb9bf1d1, 0xbf0267ac, - 0x1600260f, 0x061229c0, 0x0000c183, 0x37162c58, 0xdfa088fc, 0xde7d5704, 0x77fcbb80, 0x48e5c3f1, 0x73d8b8f8, 0xc4af7802, 0x1ca111ad, 0x0001ed7a, - 0x76eda3ef, 0xb78d3e00, 0x801c7203, 0x0215c0b1, 0x0410b044, 0xa85100d4, 0x07627ec7, 0x0cf83fa8, 0x94001a22, 0xf87347f1, 0xdcb5cfc1, 0x1c3880cc, - 0xd4e034ca, 0xfa928d9d, 0xb0167e31, 0x325cc570, 0x4bbd584b, 0xbd4e6574, 0x70bae084, 0xf0c0008a, 0x3f601ddb, 0x0bba506a, 0xa58a0082, 0x5b46946e, - 0x720a4ccd, 0xdfaaed39, 0x25dc8042, 0x7ee403f4, 0x2ad69cc9, 0x6c4b3009, 0x429037ed, 0x0293f875, 0x1a69dced, 0xab120198, 0x61c01d88, 0xcf2e43dc, - 0xfc3c00ef, 0xc049a270, 0xdbbea582, 0x0d592601, 0xc3c9a8dd, 0x5013d143, 0x19a47bbb, 0xf89253dd, 0x0a9901dc, 0x38900ecd, 0xb2dec9d7, 0xc2b91230, - 0xb8e0106f, 0x976404cb, 0x5d83c3f3, 0x6e8086fd, 0x5c9ab007, 0xf50354f6, 0xe7e72002, 0x4bc870ca, 0xab49736f, 0xc137c6e0, 0xa9aa6ff3, 0xbff84f2f, - 0x673e6e20, 0xf6e3c7e0, 0x618fe05a, 0x39ca2a00, 0x93ca03b4, 0x3a9d2728, 0xbbebba41, 0xce0e3681, 0x6e29ec05, 0x111eca83, 0xfdfe7ec1, 0xa7c8a75b, - 0xac6bc3ab, 0x72a5bc25, 0x9f612c1c, 0x378ec05e, 0x7202b157, 0x789e5a82, 0x5256bc0e, 0xcb900996, 0x10721105, 0x00823ce0, 0x69ab59fb, 0x39c72084, - 0xf5e37b25, 0xd1794700, 0x538d0637, 0x9a2bff4f, 0xce0d43a4, 0xa6da7ed2, 0xd7095132, 0xf5ad6232, 0x9aaa8e9c, 0xd8d1d3ed, 0x058940a1, 0x21f00d64, - 0x89a5c9de, 0x021b3f24, 0x77a97aac, 0x714be65a, 0x5e2d57ae, 0x27e3610f, 0x28809288, 0x36b9559f, 0xd00e347a, 0x0094e385, 0x565d034d, 0x7f52d5f2, - 0x9aea81de, 0x5e804909, 0x010d7f0a, 0x8f0d3fb1, 0xbbce23bc, 0x375e85ac, 0x01fa03b9, 0xc0526c3a, 0xf7866870, 0x9d46d804, 0x158ebf64, 0x7bd534c5, - 0xd80cf202, 0x410ee80f, 0x79419915, 0x74a844ae, 0x94119881, 0xcbbcc0fc, 0xa263d471, 0x013d0269, 0x67f6a0f8, 0x3e4474d0, 0xd1e50cb5, 0x56fd0e60, - 0xc4c0fd4c, 0x940629ff, 0xe18a7a16, 0xcca0330f, 0xb8ed50b7, 0x6935778b, 0x3735c791, 0x3909eb94, 0x0be36620, 0x0ac0d7aa, 0xefe942c9, 0xf0092727, - 0x5c020ee2, 0x0246da53, 0xa24be8bc, 0xa891ab94, 0xd012c7e2, 0x9c115954, 0xde0dac8e, 0x555dc022, 0x59e84f77, 0xbed2cf80, 0xe9af2cda, 0x4b600716, - 0x8955bd80, 0x7098c3f3, 0x25a8466a, 0x4ddbf26a, 0x5f554753, 0xf4890f28, 0x886a27ab, 0x54a00413, 0x0a157ca9, 0x52909a80, 0x7122a312, 0x0024a75c, - 0xe6d72935, 0xecde29cf, 0x025de009, 0x7995a6aa, 0x4a180491, 0x013df0d8, 0xe009edba, 0xd40019dc, 0x45b36b2a, 0x0122eb0d, 0x6e80a79f, 0x746590f5, - 0xd1a6dd49, 0xc05954b6, 0x83d4b957, 0xa00fe5b1, 0x59695ad7, 0xcff8433d, 0x44a0f340, 0xdd226c73, 0x5537f08c, 0xe1e89c32, 0x431056af, 0x233eb000, - 0x60773f40, 0xed7e490a, 0xc160091f, 0x12829db5, 0x43fbe6cf, 0x0a6b26c2, 0xd5f0f35a, 0xfc09fda8, 0x73525f8c, 0x2ea38cf9, 0x32bc410b, 0x94a60a22, - 0x1f62a42b, 0x5f290034, 0x07beaa91, 0x1e8ccb40, 0x17d6b0f9, 0xa2a017c9, 0x4c79a610, 0xa1de6525, 0xe975029f, 0xe063585f, 0x6246cfbb, 0x04acad44, - 0xe6a05138, 0xd03d8434, 0xc9950013, 0x5d4c809e, 0xfd26932d, 0x739213ac, 0xe260d8ef, 0xe4164617, 0x16fc60aa, 0x1d0b21e7, 0x445004b4, 0x13fd1b59, - 0x56b0f804, 0xaa936a3a, 0x335459c1, 0xb37f8caa, 0x06b68e03, 0x14d5eb01, 0x8300c78c, 0x9674792a, 0x20ba791b, 0x4d88024d, 0xef747354, 0x451e673e, - 0xc4dafc9a, 0xe53b9cd1, 0x32b4011a, 0x3d702c0f, 0x09bc0b40, 0x220d277d, 0x47eb7809, 0x8a946500, 0x7a28c4bd, 0x96e00f99, 0xc04365da, 0x05edcf46, - 0x7dee2c27, 0xe6020b7f, 0x159ecedf, 0xcbdb00ff, 0x516bb9e3, 0xd0716161, 0xeba75956, 0xf17fc22b, 0x5c578beb, 0xfe474a09, 0xc1750a87, 0xe384c189, - 0x5df54e26, 0xa6f76b79, 0xd4b172be, 0x3e8d5ceb, 0x832d90ec, 0x180368e7, 0x354c724d, 0x1a8b1412, 0x8de07be9, 0xaf009efe, 0x4616c621, 0x2860eb01, - 0x244f1404, 0xc3de724b, 0x6497a802, 0xab2f4419, 0x4e02910d, 0xe3ecf410, 0x7a6404a8, 0x8c72b112, 0xde5bc706, 0xd4f8ffe9, 0x50176344, 0x7b49fe7d, - 0x02c1d88c, 0x25634a40, 0x194804f7, 0x03b76d84, 0x392bde58, 0xdeebad27, 0xc160c021, 0xa97a72db, 0xa8040b83, 0x78804f3e, 0x046b9433, 0x178cc824, - 0x62800897, 0x7010370b, 0x21cfe7e4, 0x8053ec40, 0xf9d60526, 0xae9d353f, 0x069b40c7, 0x80496f14, 0x57e682b3, 0x6e0273e0, 0x974e2e28, 0x60ab7c3d, - 0x2025ba33, 0x507b3a8c, 0x12b70173, 0xd095c400, 0xee012d96, 0x6e194c9a, 0xe5933f89, 0x43b70102, 0xf30306aa, 0xc5802189, 0x53c077c3, 0x86029009, - 0xa0c1e780, 0xa4c04c1f, 0x93dbd580, 0xf8149809, 0x06021893, 0x3060c183, 0x83060c18, 0x183060c1, 0xc183060c, 0x0c183060, 0x60c18306, 0xfe0c1830, - 0x0cb69501, 0x7a40d9df, 0x000000dd, 0x4e454900, 0x6042ae44, 0x00000082, + 0x474e5089, 0x0a1a0a0d, 0x0d000000, 0x52444849, 0x00010000, 0x40000000, 0x00000301, 0x3b93cf00, 0x000000fd, 0x544c5006, 0xffffff45, 0x55ffffff, + 0x006cf57c, 0x74010000, 0x00534e52, 0x66d8e640, 0x9f040000, 0x54414449, 0xd2ed5e78, 0x57136f4d, 0xebe00518, 0x0c4c98c9, 0xdf1def0d, 0x52b2b494, + 0xe18a99db, 0x5d412243, 0x66adc8d8, 0x831a772e, 0x8c1c74aa, 0x534a9540, 0x2c162568, 0x50e1650a, 0x4e27b2a7, 0x8e289b19, 0x08555047, 0x5572c4a1, + 0x45d465e4, 0x23e2a2c5, 0x410d3602, 0x484a82ea, 0x48a58921, 0xa80d306c, 0xf5ea0150, 0x0aa91518, 0x59ed03fd, 0xa3c5de8c, 0x1dd2bef3, 0xdc02ad54, + 0xc786adbd, 0xa46249ef, 0x45672e07, 0x5368275f, 0xba00af1e, 0x50802410, 0x44584212, 0x0cc02d22, 0x54c385db, 0xa4304a20, 0x4ab0be59, 0x5581c073, + 0x3223c105, 0x3cca900e, 0x2f434141, 0xc31f00a2, 0x8381436e, 0x7582e1c3, 0xc61bd538, 0xd9d639b6, 0xac8f0873, 0x7cdf5051, 0x7068dc3a, 0x0f41ca81, + 0xb8e545db, 0xc77128e9, 0xc2357961, 0x0d9bd340, 0xb0385a6b, 0x378d1cd9, 0xf51d14c0, 0x7deed071, 0x378041c8, 0xb763cf3c, 0xca685541, 0xc170dff1, + 0x1c45eb9e, 0xca9f3beb, 0xec1a344c, 0x01c63105, 0x69b9a56c, 0xa920baa2, 0x2be30e9a, 0xa437e038, 0x68545174, 0x47a40e01, 0xbdd5104f, 0xacd51de1, + 0xb323a070, 0x00bd20d1, 0x6b8a332c, 0x3aeb8b1b, 0xf0720e7b, 0x7e6fac43, 0x20de0398, 0xaf476e65, 0xaf43df8c, 0x68be1248, 0xeb4b2d0e, 0x6009c5f5, + 0x1373d446, 0x5923eb42, 0x83bbfc11, 0x6b40b78d, 0x2c9c1e40, 0x1d25646d, 0x6dd95620, 0x2d121d08, 0xe153ea31, 0x569e2034, 0x89399009, 0x7d09e35a, + 0x6a299cc3, 0x1081d0ba, 0x93f350d6, 0x24e5f36d, 0x83939908, 0x2189e357, 0xbfa41382, 0x644cf977, 0x8d2da4a9, 0x2207ea47, 0x6f9db2c8, 0x852b401a, + 0xc88309e2, 0x926fa251, 0xcf81135f, 0x8b7fc309, 0x92d4baa1, 0xda9f9d6b, 0x285b71ff, 0x7cb1a1fe, 0xf37fc3ba, 0x5b1bd90d, 0x63fd19b9, 0x4e861b9e, + 0x5b98ba9d, 0xada921a0, 0x0d65816d, 0x0901d031, 0x8835ecaf, 0x4170458e, 0x67ae4dbe, 0xe1f03847, 0xca21ba9d, 0x09bcbc43, 0xa209a248, 0x1bccbc10, + 0xba6b0724, 0x560b7ad1, 0xbe45d18a, 0x8fc83662, 0x7845295c, 0xb4b30403, 0x083a5dab, 0xe03cd568, 0xad1cd320, 0xb16596e7, 0xf07a74ae, 0x3fdee918, + 0x9dff59d6, 0x59459b6c, 0xdf0bc40e, 0x622d7232, 0x4c58e581, 0x0289acb5, 0x9d39df61, 0x52091f79, 0x27ea7234, 0x2f862fd4, 0x018c6b90, 0xcf531873, + 0x9204974e, 0x79294e4f, 0xc42cd641, 0xe120a953, 0xb3d5d7c2, 0xcaaab02a, 0x3f57283e, 0xc6d4796f, 0x67057d81, 0xa9150405, 0xda65fc5d, 0x81abf954, + 0x52cf855a, 0x3b33e9e5, 0xa606f836, 0xd8edf562, 0x42885012, 0x4439866d, 0x5069aa75, 0xf647c08f, 0x5e5f2ad9, 0x13a29818, 0x8809993e, 0x6ce63187, + 0x039cea7e, 0x6d9a0600, 0xb23f3659, 0x54ee50e4, 0x51bd1d01, 0x69698176, 0xa78cc82e, 0x918fc7d3, 0xe68c782d, 0xddb6d41e, 0x05d50541, 0x6862b4cc, + 0x9fa0b8b5, 0x93d18d39, 0x61fb26d3, 0xc3d37c71, 0x60199ee8, 0xafd5f3d8, 0x8176ddbf, 0xc3f0d086, 0x5a4508ae, 0xb017a94b, 0x7bb4c447, 0xb47b0661, + 0x034adbe4, 0x5162d0d4, 0x145b3117, 0x265bb553, 0x13ada3d1, 0xfcf77203, 0x14cf0730, 0x79faf474, 0xc0e00514, 0x3a3397d8, 0xbef282f6, 0x9cfb06b7, + 0xbd868d8d, 0xbcf10521, 0x4313fcc5, 0xa9506c35, 0x231e9801, 0x80b83798, 0x2ffba8af, 0xea629967, 0x14bbd762, 0x404f5e86, 0x741c674e, 0xe1e4bddf, + 0xc8289e2b, 0x22161ede, 0x08ba737d, 0xfdd624de, 0x0c262c25, 0xf033fd82, 0x2d7df0c9, 0x01edfbc9, 0x1c063022, 0x5ab3cb48, 0x65787dad, 0xd174b636, + 0xcf3c6e44, 0xcec7a29e, 0xcd131c86, 0x1eb9d6e1, 0xf18cbd0d, 0xc7e3b3c4, 0x51a3855a, 0xb3b63099, 0x73791a88, 0x28bdd4b3, 0x0877396d, 0xdcb4af9f, + 0xda2678bf, 0x3f8388f1, 0xe1c23c49, 0x4bb1c0c9, 0x60811a9f, 0x32526321, 0x0de7bf4d, 0x272bb715, 0x36b4712b, 0xbecbb290, 0xf3f58cde, 0x4def93e3, + 0x68771d8e, 0x8f65effc, 0xc23357fd, 0x38a672d6, 0x6cd75a99, 0x4ba70848, 0xecfe3fd6, 0x0ed07878, 0x86fc3dda, 0xb96d25a0, 0xbd0465f3, 0xcb17658c, + 0xbb061db6, 0x5684b85c, 0x1a67638b, 0xe072ed60, 0xe41d5a04, 0x078f9275, 0xa955e8ea, 0x042929e6, 0xa473abd1, 0xfa3648a0, 0xdb13b097, 0xc91ff46c, + 0x250bf9ff, 0x6a079cd4, 0x004ebcd0, 0x49000000, 0xae444e45, 0x00826042, }; static const unsigned int proggy_clean_13_fnt_size = 4647; static const unsigned int proggy_clean_13_fnt_data[4648/4] = { - 0x03464d42, 0x00001a01, 0x40000d00, 0x01006400, 0x00000000, 0x50000101, 0x67676f72, 0x656c4379, 0x02006e61, 0x0000000f, 0x000a000d, 0x00800100, - 0x01000001, 0x03000000, 0x00000016, 0x676f7270, 0x635f7967, 0x6e61656c, 0x5f33315f, 0x6e702e30, 0xd0040067, 0x00000011, 0x2e000000, 0x07000e00, - 0x00000d00, 0x07000000, 0x010f0000, 0x36000000, 0x05003800, 0x01000d00, 0x07000000, 0x020f0000, 0x86000000, 0x07000e00, 0x00000d00, 0x07000000, - 0x030f0000, 0x07000000, 0x06001c00, 0x01000d00, 0x07000000, 0x040f0000, 0x15000000, 0x06001c00, 0x01000d00, 0x07000000, 0x050f0000, 0x23000000, - 0x06001c00, 0x01000d00, 0x07000000, 0x060f0000, 0x31000000, 0x06001c00, 0x01000d00, 0x07000000, 0x070f0000, 0xfc000000, 0x03003800, 0x02000d00, - 0x07000000, 0x080f0000, 0x54000000, 0x05003800, 0x01000d00, 0x07000000, 0x090f0000, 0x4d000000, 0x06001c00, 0x01000d00, 0x07000000, 0x0a0f0000, - 0xa8000000, 0x06001c00, 0x01000d00, 0x07000000, 0x0b0f0000, 0x6a000000, 0x04004600, 0x00000d00, 0x07000000, 0x0c0f0000, 0x74000000, 0x04004600, - 0x00000d00, 0x07000000, 0x0d0f0000, 0x88000000, 0x04004600, 0x03000d00, 0x07000000, 0x0e0f0000, 0x65000000, 0x04004600, 0x03000d00, 0x07000000, - 0x0f0f0000, 0x36000000, 0x07000e00, 0x00000d00, 0x07000000, 0x100f0000, 0x5a000000, 0x05003800, 0x00000d00, 0x07000000, 0x110f0000, 0x60000000, - 0x05003800, 0x00000d00, 0x07000000, 0x120f0000, 0xe4000000, 0x03004600, 0x01000d00, 0x07000000, 0x130f0000, 0xe0000000, 0x03004600, 0x01000d00, - 0x07000000, 0x140f0000, 0x66000000, 0x05003800, 0x00000d00, 0x07000000, 0x150f0000, 0x6c000000, 0x05003800, 0x00000d00, 0x07000000, 0x160f0000, - 0x72000000, 0x05003800, 0x00000d00, 0x07000000, 0x170f0000, 0xd8000000, 0x03004600, 0x00000d00, 0x07000000, 0x180f0000, 0xcc000000, 0x03004600, - 0x01000d00, 0x07000000, 0x190f0000, 0xc8000000, 0x03004600, 0x02000d00, 0x07000000, 0x1a0f0000, 0x78000000, 0x05003800, 0x00000d00, 0x07000000, - 0x1b0f0000, 0x84000000, 0x05003800, 0x00000d00, 0x07000000, 0x1c0f0000, 0x00000000, 0x15000000, 0xf9000d00, 0x070000ff, 0x1d0f0000, 0xb0000000, - 0x15000000, 0xf9000d00, 0x070000ff, 0x1e0f0000, 0x2c000000, 0x15000000, 0xf9000d00, 0x070000ff, 0x200f0000, 0x9a000000, 0x15000000, 0xf9000d00, - 0x070000ff, 0x210f0000, 0x0c000000, 0x01005400, 0x03000d00, 0x07000000, 0x220f0000, 0xbc000000, 0x03004600, 0x02000d00, 0x07000000, 0x230f0000, - 0x4e000000, 0x07000e00, 0x00000d00, 0x07000000, 0x240f0000, 0x8a000000, 0x05003800, 0x01000d00, 0x07000000, 0x250f0000, 0xa6000000, 0x07000e00, - 0x00000d00, 0x07000000, 0x260f0000, 0xf4000000, 0x06000e00, 0x01000d00, 0x07000000, 0x270f0000, 0x06000000, 0x01005400, 0x03000d00, 0x07000000, - 0x280f0000, 0xb8000000, 0x03004600, 0x02000d00, 0x07000000, 0x290f0000, 0xb4000000, 0x03004600, 0x02000d00, 0x07000000, 0x2a0f0000, 0x90000000, - 0x05003800, 0x01000d00, 0x07000000, 0x2b0f0000, 0x96000000, 0x05003800, 0x01000d00, 0x07000000, 0x2c0f0000, 0xe8000000, 0x02004600, 0x01000d00, - 0x07000000, 0x2d0f0000, 0x9c000000, 0x05003800, 0x01000d00, 0x07000000, 0x2e0f0000, 0x04000000, 0x01005400, 0x02000d00, 0x07000000, 0x2f0f0000, - 0xa2000000, 0x05003800, 0x01000d00, 0x07000000, 0x300f0000, 0xae000000, 0x05003800, 0x01000d00, 0x07000000, 0x310f0000, 0xd8000000, 0x05003800, - 0x01000d00, 0x07000000, 0x320f0000, 0xfa000000, 0x05000000, 0x01000d00, 0x07000000, 0x330f0000, 0x31000000, 0x05002a00, 0x01000d00, 0x07000000, - 0x340f0000, 0x3f000000, 0x06001c00, 0x01000d00, 0x07000000, 0x350f0000, 0x37000000, 0x05002a00, 0x01000d00, 0x07000000, 0x360f0000, 0x3d000000, - 0x05002a00, 0x01000d00, 0x07000000, 0x370f0000, 0x43000000, 0x05002a00, 0x01000d00, 0x07000000, 0x380f0000, 0x49000000, 0x05002a00, 0x01000d00, - 0x07000000, 0x390f0000, 0x4f000000, 0x05002a00, 0x01000d00, 0x07000000, 0x3a0f0000, 0x02000000, 0x01005400, 0x03000d00, 0x07000000, 0x3b0f0000, - 0xfa000000, 0x02004600, 0x01000d00, 0x07000000, 0x3c0f0000, 0x77000000, 0x06001c00, 0x00000d00, 0x07000000, 0x3d0f0000, 0x7e000000, 0x06001c00, - 0x01000d00, 0x07000000, 0x3e0f0000, 0x85000000, 0x06001c00, 0x01000d00, 0x07000000, 0x3f0f0000, 0x55000000, 0x05002a00, 0x01000d00, 0x07000000, - 0x400f0000, 0xae000000, 0x07000e00, 0x00000d00, 0x07000000, 0x410f0000, 0xe0000000, 0x06001c00, 0x01000d00, 0x07000000, 0x420f0000, 0xa1000000, - 0x06001c00, 0x01000d00, 0x07000000, 0x430f0000, 0x5b000000, 0x05002a00, 0x01000d00, 0x07000000, 0x440f0000, 0xaf000000, 0x06001c00, 0x01000d00, - 0x07000000, 0x450f0000, 0x61000000, 0x05002a00, 0x01000d00, 0x07000000, 0x460f0000, 0x67000000, 0x05002a00, 0x01000d00, 0x07000000, 0x470f0000, - 0x38000000, 0x06001c00, 0x01000d00, 0x07000000, 0x480f0000, 0x8c000000, 0x06001c00, 0x01000d00, 0x07000000, 0x490f0000, 0xa0000000, 0x03004600, - 0x02000d00, 0x07000000, 0x4a0f0000, 0x97000000, 0x04004600, 0x01000d00, 0x07000000, 0x4b0f0000, 0xb6000000, 0x06001c00, 0x01000d00, 0x07000000, - 0x4c0f0000, 0x6d000000, 0x05002a00, 0x01000d00, 0x07000000, 0x4d0f0000, 0x1e000000, 0x07000e00, 0x00000d00, 0x07000000, 0x4e0f0000, 0x23000000, - 0x06002a00, 0x01000d00, 0x07000000, 0x4f0f0000, 0xed000000, 0x06000e00, 0x01000d00, 0x07000000, 0x500f0000, 0x73000000, 0x05002a00, 0x01000d00, - 0x07000000, 0x510f0000, 0x00000000, 0x06001c00, 0x01000d00, 0x07000000, 0x520f0000, 0x0e000000, 0x06001c00, 0x01000d00, 0x07000000, 0x530f0000, - 0x1c000000, 0x06001c00, 0x01000d00, 0x07000000, 0x540f0000, 0x66000000, 0x07000e00, 0x00000d00, 0x07000000, 0x550f0000, 0x2a000000, 0x06001c00, - 0x01000d00, 0x07000000, 0x560f0000, 0x6e000000, 0x07000e00, 0x00000d00, 0x07000000, 0x570f0000, 0x76000000, 0x07000e00, 0x00000d00, 0x07000000, - 0x580f0000, 0x46000000, 0x06001c00, 0x01000d00, 0x07000000, 0x590f0000, 0x7e000000, 0x07000e00, 0x00000d00, 0x07000000, 0x5a0f0000, 0x54000000, - 0x06001c00, 0x01000d00, 0x07000000, 0x5b0f0000, 0x9c000000, 0x03004600, 0x02000d00, 0x07000000, 0x5c0f0000, 0x79000000, 0x05002a00, 0x01000d00, - 0x07000000, 0x5d0f0000, 0xdc000000, 0x03004600, 0x02000d00, 0x07000000, 0x5e0f0000, 0x7f000000, 0x05002a00, 0x01000d00, 0x07000000, 0x5f0f0000, - 0xc6000000, 0x07000e00, 0x00000d00, 0x07000000, 0x600f0000, 0xfd000000, 0x02004600, 0x02000d00, 0x07000000, 0x610f0000, 0x85000000, 0x05002a00, - 0x01000d00, 0x07000000, 0x620f0000, 0x8b000000, 0x05002a00, 0x01000d00, 0x07000000, 0x630f0000, 0x91000000, 0x05002a00, 0x01000d00, 0x07000000, - 0x640f0000, 0x97000000, 0x05002a00, 0x01000d00, 0x07000000, 0x650f0000, 0x9d000000, 0x05002a00, 0x01000d00, 0x07000000, 0x660f0000, 0xa3000000, - 0x05002a00, 0x01000d00, 0x07000000, 0x670f0000, 0xa9000000, 0x05002a00, 0x01000d00, 0x07000000, 0x680f0000, 0xaf000000, 0x05002a00, 0x01000d00, - 0x07000000, 0x690f0000, 0xee000000, 0x02004600, 0x02000d00, 0x07000000, 0x6a0f0000, 0x92000000, 0x04004600, 0x01000d00, 0x07000000, 0x6b0f0000, - 0xb5000000, 0x05002a00, 0x01000d00, 0x07000000, 0x6c0f0000, 0xfd000000, 0x02002a00, 0x02000d00, 0x07000000, 0x6d0f0000, 0x8e000000, 0x07000e00, - 0x00000d00, 0x07000000, 0x6e0f0000, 0xbb000000, 0x05002a00, 0x01000d00, 0x07000000, 0x6f0f0000, 0xc1000000, 0x05002a00, 0x01000d00, 0x07000000, - 0x700f0000, 0xc7000000, 0x05002a00, 0x01000d00, 0x07000000, 0x710f0000, 0xcd000000, 0x05002a00, 0x01000d00, 0x07000000, 0x720f0000, 0xd3000000, - 0x05002a00, 0x01000d00, 0x07000000, 0x730f0000, 0xd9000000, 0x05002a00, 0x01000d00, 0x07000000, 0x740f0000, 0x7e000000, 0x04004600, 0x02000d00, - 0x07000000, 0x750f0000, 0xdf000000, 0x05002a00, 0x01000d00, 0x07000000, 0x760f0000, 0xe5000000, 0x05002a00, 0x01000d00, 0x07000000, 0x770f0000, - 0xbe000000, 0x07000e00, 0x00000d00, 0x07000000, 0x780f0000, 0xeb000000, 0x05002a00, 0x01000d00, 0x07000000, 0x790f0000, 0xf1000000, 0x05002a00, - 0x01000d00, 0x07000000, 0x7a0f0000, 0xf7000000, 0x05002a00, 0x01000d00, 0x07000000, 0x7b0f0000, 0x00000000, 0x05003800, 0x01000d00, 0x07000000, - 0x7c0f0000, 0x00000000, 0x01005400, 0x03000d00, 0x07000000, 0x7d0f0000, 0x06000000, 0x05003800, 0x01000d00, 0x07000000, 0x7e0f0000, 0x16000000, - 0x07000e00, 0x00000d00, 0x07000000, 0x7f0f0000, 0x58000000, 0x15000000, 0xf9000d00, 0x070000ff, 0x810f0000, 0x16000000, 0x15000000, 0xf9000d00, - 0x070000ff, 0x8d0f0000, 0x00000000, 0x15000e00, 0xf9000d00, 0x070000ff, 0x8f0f0000, 0xc6000000, 0x15000000, 0xf9000d00, 0x070000ff, 0x900f0000, - 0x6e000000, 0x15000000, 0xf9000d00, 0x070000ff, 0x9d0f0000, 0x84000000, 0x15000000, 0xf9000d00, 0x070000ff, 0xa00f0000, 0xdc000000, 0x15000000, - 0xf9000d00, 0x070000ff, 0xa10f0000, 0x0a000000, 0x01005400, 0x03000d00, 0x07000000, 0xa20f0000, 0x0c000000, 0x05003800, 0x01000d00, 0x07000000, - 0xa30f0000, 0x12000000, 0x05003800, 0x01000d00, 0x07000000, 0xa40f0000, 0x96000000, 0x07000e00, 0x00000d00, 0x07000000, 0xa50f0000, 0x5e000000, - 0x07000e00, 0x00000d00, 0x07000000, 0xa60f0000, 0x08000000, 0x01005400, 0x03000d00, 0x07000000, 0xa70f0000, 0x18000000, 0x05003800, 0x01000d00, - 0x07000000, 0xa80f0000, 0xac000000, 0x03004600, 0x02000d00, 0x07000000, 0xa90f0000, 0x56000000, 0x07000e00, 0x00000d00, 0x07000000, 0xaa0f0000, - 0x8d000000, 0x04004600, 0x01000d00, 0x07000000, 0xab0f0000, 0x1e000000, 0x05003800, 0x01000d00, 0x07000000, 0xac0f0000, 0xfb000000, 0x04000e00, - 0x01000d00, 0x07000000, 0xad0f0000, 0x42000000, 0x15000000, 0xf9000d00, 0x070000ff, 0xae0f0000, 0x3e000000, 0x07000e00, 0x00000d00, 0x07000000, - 0xaf0f0000, 0x26000000, 0x07000e00, 0x00000d00, 0x07000000, 0xb00f0000, 0x6f000000, 0x04004600, 0x01000d00, 0x07000000, 0xb10f0000, 0x24000000, - 0x05003800, 0x01000d00, 0x07000000, 0xb20f0000, 0x79000000, 0x04004600, 0x01000d00, 0x07000000, 0xb30f0000, 0x83000000, 0x04004600, 0x01000d00, - 0x07000000, 0xb40f0000, 0xeb000000, 0x02004600, 0x03000d00, 0x07000000, 0xb50f0000, 0x46000000, 0x07000e00, 0x00000d00, 0x07000000, 0xb60f0000, - 0xe6000000, 0x06000e00, 0x01000d00, 0x07000000, 0xb70f0000, 0xc0000000, 0x03004600, 0x02000d00, 0x07000000, 0xb80f0000, 0xf7000000, 0x02004600, - 0x03000d00, 0x07000000, 0xb90f0000, 0xc4000000, 0x03004600, 0x01000d00, 0x07000000, 0xba0f0000, 0x60000000, 0x04004600, 0x01000d00, 0x07000000, - 0xbb0f0000, 0x2a000000, 0x05003800, 0x01000d00, 0x07000000, 0xbc0f0000, 0x1c000000, 0x06002a00, 0x01000d00, 0x07000000, 0xbd0f0000, 0xc4000000, - 0x06001c00, 0x01000d00, 0x07000000, 0xbe0f0000, 0x9e000000, 0x07000e00, 0x00000d00, 0x07000000, 0xbf0f0000, 0x30000000, 0x05003800, 0x01000d00, - 0x07000000, 0xc00f0000, 0x9a000000, 0x06001c00, 0x01000d00, 0x07000000, 0xc10f0000, 0x93000000, 0x06001c00, 0x01000d00, 0x07000000, 0xc20f0000, - 0x70000000, 0x06001c00, 0x01000d00, 0x07000000, 0xc30f0000, 0x69000000, 0x06001c00, 0x01000d00, 0x07000000, 0xc40f0000, 0x62000000, 0x06001c00, - 0x01000d00, 0x07000000, 0xc50f0000, 0x5b000000, 0x06001c00, 0x01000d00, 0x07000000, 0xc60f0000, 0xf2000000, 0x07000000, 0x00000d00, 0x07000000, - 0xc70f0000, 0xbd000000, 0x06001c00, 0x01000d00, 0x07000000, 0xc80f0000, 0x3c000000, 0x05003800, 0x01000d00, 0x07000000, 0xc90f0000, 0x42000000, - 0x05003800, 0x01000d00, 0x07000000, 0xca0f0000, 0x48000000, 0x05003800, 0x01000d00, 0x07000000, 0xcb0f0000, 0x4e000000, 0x05003800, 0x01000d00, - 0x07000000, 0xcc0f0000, 0xa4000000, 0x03004600, 0x02000d00, 0x07000000, 0xcd0f0000, 0xb0000000, 0x03004600, 0x02000d00, 0x07000000, 0xce0f0000, - 0xa8000000, 0x03004600, 0x02000d00, 0x07000000, 0xcf0f0000, 0xfc000000, 0x03001c00, 0x02000d00, 0x07000000, 0xd00f0000, 0xce000000, 0x07000e00, - 0x00000d00, 0x07000000, 0xd10f0000, 0xcb000000, 0x06001c00, 0x01000d00, 0x07000000, 0xd20f0000, 0xd2000000, 0x06001c00, 0x01000d00, 0x07000000, - 0xd30f0000, 0xd9000000, 0x06001c00, 0x01000d00, 0x07000000, 0xd40f0000, 0x2a000000, 0x06002a00, 0x01000d00, 0x07000000, 0xd50f0000, 0xe7000000, - 0x06001c00, 0x01000d00, 0x07000000, 0xd60f0000, 0xee000000, 0x06001c00, 0x01000d00, 0x07000000, 0xd70f0000, 0x7e000000, 0x05003800, 0x01000d00, - 0x07000000, 0xd80f0000, 0xf5000000, 0x06001c00, 0x01000d00, 0x07000000, 0xd90f0000, 0x00000000, 0x06002a00, 0x01000d00, 0x07000000, 0xda0f0000, - 0x07000000, 0x06002a00, 0x01000d00, 0x07000000, 0xdb0f0000, 0x0e000000, 0x06002a00, 0x01000d00, 0x07000000, 0xdc0f0000, 0x15000000, 0x06002a00, - 0x01000d00, 0x07000000, 0xdd0f0000, 0xd6000000, 0x07000e00, 0x00000d00, 0x07000000, 0xde0f0000, 0xa8000000, 0x05003800, 0x01000d00, 0x07000000, - 0xdf0f0000, 0xde000000, 0x07000e00, 0x00000d00, 0x07000000, 0xe00f0000, 0xb4000000, 0x05003800, 0x01000d00, 0x07000000, 0xe10f0000, 0xba000000, - 0x05003800, 0x01000d00, 0x07000000, 0xe20f0000, 0xc0000000, 0x05003800, 0x01000d00, 0x07000000, 0xe30f0000, 0xc6000000, 0x05003800, 0x01000d00, - 0x07000000, 0xe40f0000, 0xcc000000, 0x05003800, 0x01000d00, 0x07000000, 0xe50f0000, 0xd2000000, 0x05003800, 0x01000d00, 0x07000000, 0xe60f0000, - 0xb6000000, 0x07000e00, 0x00000d00, 0x07000000, 0xe70f0000, 0xde000000, 0x05003800, 0x01000d00, 0x07000000, 0xe80f0000, 0xe4000000, 0x05003800, - 0x01000d00, 0x07000000, 0xe90f0000, 0xea000000, 0x05003800, 0x01000d00, 0x07000000, 0xea0f0000, 0xf0000000, 0x05003800, 0x01000d00, 0x07000000, - 0xeb0f0000, 0xf6000000, 0x05003800, 0x01000d00, 0x07000000, 0xec0f0000, 0xf1000000, 0x02004600, 0x02000d00, 0x07000000, 0xed0f0000, 0xf4000000, - 0x02004600, 0x02000d00, 0x07000000, 0xee0f0000, 0xd0000000, 0x03004600, 0x02000d00, 0x07000000, 0xef0f0000, 0xd4000000, 0x03004600, 0x02000d00, - 0x07000000, 0xf00f0000, 0x00000000, 0x05004600, 0x01000d00, 0x07000000, 0xf10f0000, 0x06000000, 0x05004600, 0x01000d00, 0x07000000, 0xf20f0000, - 0x0c000000, 0x05004600, 0x01000d00, 0x07000000, 0xf30f0000, 0x12000000, 0x05004600, 0x01000d00, 0x07000000, 0xf40f0000, 0x18000000, 0x05004600, - 0x01000d00, 0x07000000, 0xf50f0000, 0x1e000000, 0x05004600, 0x01000d00, 0x07000000, 0xf60f0000, 0x24000000, 0x05004600, 0x01000d00, 0x07000000, - 0xf70f0000, 0x2a000000, 0x05004600, 0x01000d00, 0x07000000, 0xf80f0000, 0x30000000, 0x05004600, 0x01000d00, 0x07000000, 0xf90f0000, 0x36000000, - 0x05004600, 0x01000d00, 0x07000000, 0xfa0f0000, 0x3c000000, 0x05004600, 0x01000d00, 0x07000000, 0xfb0f0000, 0x42000000, 0x05004600, 0x01000d00, - 0x07000000, 0xfc0f0000, 0x48000000, 0x05004600, 0x01000d00, 0x07000000, 0xfd0f0000, 0x4e000000, 0x05004600, 0x01000d00, 0x07000000, 0xfe0f0000, - 0x54000000, 0x05004600, 0x01000d00, 0x07000000, 0xff0f0000, 0x5a000000, 0x05004600, 0x01000d00, 0x07000000, 0x000f0000, + 0x03464d42, 0x00001a01, 0x40000d00, 0x01006400, 0x00000000, 0x50000101, 0x67676f72, 0x656c4379, 0x02006e61, 0x0000000f, 0x000a000d, 0x00400100, + 0x00000001, 0x03040404, 0x00000016, 0x676f7270, 0x635f7967, 0x6e61656c, 0x5f33315f, 0x6e702e30, 0xd0040067, 0x00000011, 0x00000000, 0x07000000, + 0x00000d00, 0x07000000, 0x010f0000, 0x72000000, 0x05002700, 0x01000500, 0x07000400, 0x020f0000, 0x08000000, 0x07000000, 0x00000d00, 0x07000000, + 0x030f0000, 0x16000000, 0x06000e00, 0x01000900, 0x07000100, 0x040f0000, 0x1d000000, 0x06000d00, 0x01000900, 0x07000100, 0x050f0000, 0x24000000, + 0x06000c00, 0x01000900, 0x07000100, 0x060f0000, 0x2b000000, 0x06000c00, 0x01000900, 0x07000100, 0x070f0000, 0xb8000000, 0x03002600, 0x02000400, + 0x07000200, 0x080f0000, 0xd1000000, 0x05001e00, 0x01000700, 0x07000300, 0x090f0000, 0x39000000, 0x06000c00, 0x01000900, 0x07000100, 0x0a0f0000, + 0x40000000, 0x06000c00, 0x01000900, 0x07000100, 0x0b0f0000, 0xdc000000, 0x04001e00, 0x00000700, 0x07000000, 0x0c0f0000, 0xe6000000, 0x04001e00, + 0x00000700, 0x07000600, 0x0d0f0000, 0xe1000000, 0x04001e00, 0x03000700, 0x07000600, 0x0e0f0000, 0xd7000000, 0x04001e00, 0x03000700, 0x07000000, + 0x0f0f0000, 0x10000000, 0x07000000, 0x00000d00, 0x07000000, 0x100f0000, 0xd7000000, 0x05000000, 0x00000a00, 0x07000200, 0x110f0000, 0xc5000000, + 0x05001e00, 0x00000700, 0x07000400, 0x120f0000, 0x24000000, 0x03001600, 0x01000900, 0x07000300, 0x130f0000, 0xeb000000, 0x03001e00, 0x01000700, + 0x07000300, 0x140f0000, 0xab000000, 0x05000b00, 0x00000900, 0x07000300, 0x150f0000, 0x3e000000, 0x05002800, 0x00000600, 0x07000200, 0x160f0000, + 0x7e000000, 0x05002700, 0x00000500, 0x07000700, 0x170f0000, 0x0a000000, 0x03000e00, 0x00000a00, 0x07000200, 0x180f0000, 0x1c000000, 0x03001800, + 0x01000900, 0x07000300, 0x190f0000, 0xfb000000, 0x03000000, 0x02000a00, 0x07000200, 0x1a0f0000, 0xcc000000, 0x05002600, 0x00000300, 0x07000600, + 0x1b0f0000, 0xc6000000, 0x05002600, 0x00000300, 0x07000600, 0x1c0f0000, 0x00000000, 0x15003300, 0xf9000100, 0x07000cff, 0x1d0f0000, 0x9a000000, + 0x15002d00, 0xf9000100, 0x07000cff, 0x1e0f0000, 0xb0000000, 0x15002c00, 0xf9000100, 0x07000cff, 0x200f0000, 0xdc000000, 0x15002a00, 0xf9000100, + 0x07000cff, 0x210f0000, 0xb1000000, 0x01001e00, 0x03000800, 0x07000200, 0x220f0000, 0xd6000000, 0x03002600, 0x02000300, 0x07000100, 0x230f0000, + 0x40000000, 0x07001600, 0x00000800, 0x07000200, 0x240f0000, 0x81000000, 0x05000b00, 0x01000900, 0x07000200, 0x250f0000, 0x38000000, 0x07001600, + 0x00000800, 0x07000200, 0x260f0000, 0xa0000000, 0x06001500, 0x01000800, 0x07000200, 0x270f0000, 0xdd000000, 0x01002600, 0x03000300, 0x07000100, + 0x280f0000, 0x3c000000, 0x03000000, 0x02000b00, 0x07000100, 0x290f0000, 0x40000000, 0x03000000, 0x02000b00, 0x07000100, 0x2a0f0000, 0x84000000, + 0x05002700, 0x01000500, 0x07000400, 0x2b0f0000, 0x78000000, 0x05002700, 0x01000500, 0x07000400, 0x2c0f0000, 0xbc000000, 0x02002600, 0x01000400, + 0x07000800, 0x2d0f0000, 0xef000000, 0x05002700, 0x01000100, 0x07000600, 0x2e0f0000, 0xed000000, 0x01002600, 0x02000200, 0x07000800, 0x2f0f0000, + 0xef000000, 0x05000000, 0x01000a00, 0x07000100, 0x300f0000, 0x7b000000, 0x05001e00, 0x01000800, 0x07000200, 0x310f0000, 0x81000000, 0x05001e00, + 0x01000800, 0x07000200, 0x320f0000, 0x87000000, 0x05001e00, 0x01000800, 0x07000200, 0x330f0000, 0x93000000, 0x05001e00, 0x01000800, 0x07000200, + 0x340f0000, 0x07000000, 0x06002300, 0x01000800, 0x07000200, 0x350f0000, 0x9f000000, 0x05001e00, 0x01000800, 0x07000200, 0x360f0000, 0x15000000, + 0x05002300, 0x01000800, 0x07000200, 0x370f0000, 0x1b000000, 0x05002200, 0x01000800, 0x07000200, 0x380f0000, 0x21000000, 0x05002100, 0x01000800, + 0x07000200, 0x390f0000, 0x51000000, 0x05001f00, 0x01000800, 0x07000200, 0x3a0f0000, 0x56000000, 0x01002800, 0x03000600, 0x07000400, 0x3b0f0000, + 0xae000000, 0x02001e00, 0x01000800, 0x07000400, 0x3c0f0000, 0x5f000000, 0x06002700, 0x00000500, 0x07000400, 0x3d0f0000, 0xbf000000, 0x06002600, + 0x01000300, 0x07000500, 0x3e0f0000, 0x58000000, 0x06002800, 0x01000500, 0x07000400, 0x3f0f0000, 0x27000000, 0x05002000, 0x01000800, 0x07000200, + 0x400f0000, 0x50000000, 0x07001600, 0x00000800, 0x07000200, 0x410f0000, 0xd1000000, 0x06001500, 0x01000800, 0x07000200, 0x420f0000, 0x00000000, + 0x06002300, 0x01000800, 0x07000200, 0x430f0000, 0x33000000, 0x05002000, 0x01000800, 0x07000200, 0x440f0000, 0x0e000000, 0x06002300, 0x01000800, + 0x07000200, 0x450f0000, 0x39000000, 0x05001f00, 0x01000800, 0x07000200, 0x460f0000, 0x3f000000, 0x05001f00, 0x01000800, 0x07000200, 0x470f0000, + 0xa7000000, 0x06001500, 0x01000800, 0x07000200, 0x480f0000, 0xae000000, 0x06001500, 0x01000800, 0x07000200, 0x490f0000, 0xaa000000, 0x03001e00, + 0x02000800, 0x07000200, 0x4a0f0000, 0xfb000000, 0x04001500, 0x01000800, 0x07000200, 0x4b0f0000, 0xb5000000, 0x06001500, 0x01000800, 0x07000200, + 0x4c0f0000, 0x45000000, 0x05001f00, 0x01000800, 0x07000200, 0x4d0f0000, 0x48000000, 0x07001600, 0x00000800, 0x07000200, 0x4e0f0000, 0xc3000000, + 0x06001500, 0x01000800, 0x07000200, 0x4f0f0000, 0xca000000, 0x06001500, 0x01000800, 0x07000200, 0x500f0000, 0x4b000000, 0x05001f00, 0x01000800, + 0x07000200, 0x510f0000, 0x5c000000, 0x06000b00, 0x01000900, 0x07000200, 0x520f0000, 0xd8000000, 0x06001500, 0x01000800, 0x07000200, 0x530f0000, + 0xdf000000, 0x06001500, 0x01000800, 0x07000200, 0x540f0000, 0x60000000, 0x07001500, 0x00000800, 0x07000200, 0x550f0000, 0xe6000000, 0x06001500, + 0x01000800, 0x07000200, 0x560f0000, 0x68000000, 0x07001500, 0x00000800, 0x07000200, 0x570f0000, 0x70000000, 0x07001500, 0x00000800, 0x07000200, + 0x580f0000, 0xed000000, 0x06001500, 0x01000800, 0x07000200, 0x590f0000, 0x78000000, 0x07001500, 0x00000800, 0x07000200, 0x5a0f0000, 0xf4000000, + 0x06001500, 0x01000800, 0x07000200, 0x5b0f0000, 0x48000000, 0x03000000, 0x02000b00, 0x07000100, 0x5c0f0000, 0xf5000000, 0x05000000, 0x01000a00, + 0x07000100, 0x5d0f0000, 0x44000000, 0x03000000, 0x02000b00, 0x07000100, 0x5e0f0000, 0x0e000000, 0x05002c00, 0x01000600, 0x07000100, 0x5f0f0000, + 0xef000000, 0x07002500, 0x00000100, 0x07000a00, 0x600f0000, 0xea000000, 0x02002600, 0x02000200, 0x07000100, 0x610f0000, 0x50000000, 0x05002800, + 0x01000600, 0x07000400, 0x620f0000, 0x9f000000, 0x05000b00, 0x01000900, 0x07000100, 0x630f0000, 0x4a000000, 0x05002800, 0x01000600, 0x07000400, + 0x640f0000, 0xe7000000, 0x05000b00, 0x01000900, 0x07000100, 0x650f0000, 0x44000000, 0x05002800, 0x01000600, 0x07000400, 0x660f0000, 0xa5000000, + 0x05000b00, 0x01000900, 0x07000100, 0x670f0000, 0xc3000000, 0x05000b00, 0x01000900, 0x07000400, 0x680f0000, 0x69000000, 0x05000b00, 0x01000900, + 0x07000100, 0x690f0000, 0x2f000000, 0x02001600, 0x02000900, 0x07000100, 0x6a0f0000, 0x37000000, 0x04000000, 0x01000b00, 0x07000100, 0x6b0f0000, + 0x7b000000, 0x05000b00, 0x01000900, 0x07000100, 0x6c0f0000, 0x35000000, 0x02001600, 0x02000900, 0x07000100, 0x6d0f0000, 0xf7000000, 0x07001e00, + 0x00000600, 0x07000400, 0x6e0f0000, 0x20000000, 0x05002b00, 0x01000600, 0x07000400, 0x6f0f0000, 0x32000000, 0x05002900, 0x01000600, 0x07000400, + 0x700f0000, 0x6f000000, 0x05000b00, 0x01000900, 0x07000400, 0x710f0000, 0x63000000, 0x05000b00, 0x01000900, 0x07000400, 0x720f0000, 0x2c000000, + 0x05002900, 0x01000600, 0x07000400, 0x730f0000, 0x38000000, 0x05002900, 0x01000600, 0x07000400, 0x740f0000, 0xa5000000, 0x04001e00, 0x02000800, + 0x07000200, 0x750f0000, 0x08000000, 0x05002c00, 0x01000600, 0x07000400, 0x760f0000, 0x1a000000, 0x05002c00, 0x01000600, 0x07000400, 0x770f0000, + 0x00000000, 0x07002c00, 0x00000600, 0x07000400, 0x780f0000, 0x26000000, 0x05002a00, 0x01000600, 0x07000400, 0x790f0000, 0x8d000000, 0x05000b00, + 0x01000900, 0x07000400, 0x7a0f0000, 0x14000000, 0x05002c00, 0x01000600, 0x07000400, 0x7b0f0000, 0x25000000, 0x05000000, 0x01000b00, 0x07000100, + 0x7c0f0000, 0x4c000000, 0x01000000, 0x03000b00, 0x07000100, 0x7d0f0000, 0x2b000000, 0x05000000, 0x01000b00, 0x07000100, 0x7e0f0000, 0xdf000000, + 0x07002600, 0x00000200, 0x07000500, 0x7f0f0000, 0x16000000, 0x15003300, 0xf9000100, 0x07000cff, 0x810f0000, 0x2c000000, 0x15003000, 0xf9000100, + 0x07000cff, 0x8d0f0000, 0x42000000, 0x15002f00, 0xf9000100, 0x07000cff, 0x8f0f0000, 0x58000000, 0x15002e00, 0xf9000100, 0x07000cff, 0x900f0000, + 0x6e000000, 0x15002d00, 0xf9000100, 0x07000cff, 0x9d0f0000, 0xc6000000, 0x15002a00, 0xf9000100, 0x07000cff, 0xa00f0000, 0x84000000, 0x15002d00, + 0xf9000100, 0x07000cff, 0xa10f0000, 0xb3000000, 0x01001e00, 0x03000800, 0x07000200, 0xa20f0000, 0x57000000, 0x05001f00, 0x01000800, 0x07000300, + 0xa30f0000, 0x5d000000, 0x05001e00, 0x01000800, 0x07000200, 0xa40f0000, 0xbd000000, 0x07001e00, 0x00000700, 0x07000300, 0xa50f0000, 0x58000000, + 0x07001500, 0x00000800, 0x07000200, 0xa60f0000, 0x4e000000, 0x01000000, 0x03000b00, 0x07000100, 0xa70f0000, 0x99000000, 0x05000b00, 0x01000900, + 0x07000100, 0xa80f0000, 0xf5000000, 0x03002700, 0x02000100, 0x07000100, 0xa90f0000, 0x90000000, 0x07001500, 0x00000800, 0x07000200, 0xaa0f0000, + 0xa0000000, 0x04002700, 0x01000500, 0x07000200, 0xab0f0000, 0x90000000, 0x05002700, 0x01000500, 0x07000400, 0xac0f0000, 0xb3000000, 0x04002700, + 0x01000400, 0x07000600, 0xad0f0000, 0x2c000000, 0x15003200, 0xf9000100, 0x07000cff, 0xae0f0000, 0x98000000, 0x07001500, 0x00000800, 0x07000200, + 0xaf0f0000, 0xf7000000, 0x07002500, 0x00000100, 0x07000000, 0xb00f0000, 0xae000000, 0x04002700, 0x01000400, 0x07000100, 0xb10f0000, 0xcb000000, + 0x05001e00, 0x01000700, 0x07000300, 0xb20f0000, 0x96000000, 0x04002700, 0x01000500, 0x07000100, 0xb30f0000, 0x9b000000, 0x04002700, 0x01000500, + 0x07000100, 0xb40f0000, 0xe7000000, 0x02002600, 0x03000200, 0x07000100, 0xb50f0000, 0x80000000, 0x07001500, 0x00000800, 0x07000400, 0xb60f0000, + 0x55000000, 0x06000b00, 0x01000900, 0x07000200, 0xb70f0000, 0xd2000000, 0x03002600, 0x02000300, 0x07000500, 0xb80f0000, 0xda000000, 0x02002600, + 0x03000300, 0x07000a00, 0xb90f0000, 0xaa000000, 0x03002700, 0x01000500, 0x07000100, 0xba0f0000, 0xa5000000, 0x04002700, 0x01000500, 0x07000100, + 0xbb0f0000, 0x6c000000, 0x05002700, 0x01000500, 0x07000400, 0xbc0f0000, 0x6f000000, 0x06000000, 0x01000a00, 0x07000000, 0xbd0f0000, 0xca000000, + 0x06000000, 0x01000a00, 0x07000000, 0xbe0f0000, 0x58000000, 0x07000000, 0x00000a00, 0x07000000, 0xbf0f0000, 0x63000000, 0x05001e00, 0x01000800, + 0x07000200, 0xc00f0000, 0xb5000000, 0x06000000, 0x01000a00, 0x07000000, 0xc10f0000, 0xbc000000, 0x06000000, 0x01000a00, 0x07000000, 0xc20f0000, + 0x68000000, 0x06000000, 0x01000a00, 0x07000000, 0xc30f0000, 0xc3000000, 0x06000000, 0x01000a00, 0x07000000, 0xc40f0000, 0x4e000000, 0x06000c00, + 0x01000900, 0x07000100, 0xc50f0000, 0x7d000000, 0x06000000, 0x01000a00, 0x07000000, 0xc60f0000, 0x88000000, 0x07001500, 0x00000800, 0x07000200, + 0xc70f0000, 0x1e000000, 0x06000000, 0x01000b00, 0x07000200, 0xc80f0000, 0xe9000000, 0x05000000, 0x01000a00, 0x07000000, 0xc90f0000, 0xe3000000, + 0x05000000, 0x01000a00, 0x07000000, 0xca0f0000, 0xdd000000, 0x05000000, 0x01000a00, 0x07000000, 0xcb0f0000, 0x75000000, 0x05000b00, 0x01000900, + 0x07000100, 0xcc0f0000, 0x0e000000, 0x03000e00, 0x02000a00, 0x07000000, 0xcd0f0000, 0x12000000, 0x03000e00, 0x02000a00, 0x07000000, 0xce0f0000, + 0x06000000, 0x03000e00, 0x02000a00, 0x07000000, 0xcf0f0000, 0x18000000, 0x03001800, 0x02000900, 0x07000100, 0xd00f0000, 0xb5000000, 0x07001e00, + 0x00000700, 0x07000300, 0xd10f0000, 0xae000000, 0x06000000, 0x01000a00, 0x07000000, 0xd20f0000, 0xa7000000, 0x06000000, 0x01000a00, 0x07000000, + 0xd30f0000, 0xa0000000, 0x06000000, 0x01000a00, 0x07000000, 0xd40f0000, 0x99000000, 0x06000000, 0x01000a00, 0x07000000, 0xd50f0000, 0x92000000, + 0x06000000, 0x01000a00, 0x07000000, 0xd60f0000, 0x47000000, 0x06000c00, 0x01000900, 0x07000100, 0xd70f0000, 0x66000000, 0x05002700, 0x01000500, + 0x07000400, 0xd80f0000, 0xbc000000, 0x06001500, 0x01000800, 0x07000200, 0xd90f0000, 0x8b000000, 0x06000000, 0x01000a00, 0x07000000, 0xda0f0000, + 0x84000000, 0x06000000, 0x01000a00, 0x07000000, 0xdb0f0000, 0x76000000, 0x06000000, 0x01000a00, 0x07000000, 0xdc0f0000, 0x32000000, 0x06000c00, + 0x01000900, 0x07000100, 0xdd0f0000, 0x50000000, 0x07000000, 0x00000a00, 0x07000000, 0xde0f0000, 0x69000000, 0x05001e00, 0x01000800, 0x07000200, + 0xdf0f0000, 0x60000000, 0x07000000, 0x00000a00, 0x07000100, 0xe00f0000, 0xb1000000, 0x05000b00, 0x01000900, 0x07000100, 0xe10f0000, 0xb7000000, + 0x05000b00, 0x01000900, 0x07000100, 0xe20f0000, 0xbd000000, 0x05000b00, 0x01000900, 0x07000100, 0xe30f0000, 0x93000000, 0x05000b00, 0x01000900, + 0x07000100, 0xe40f0000, 0x99000000, 0x05001e00, 0x01000800, 0x07000200, 0xe50f0000, 0xd1000000, 0x05000000, 0x01000a00, 0x07000000, 0xe60f0000, + 0xef000000, 0x07001e00, 0x00000600, 0x07000400, 0xe70f0000, 0xc9000000, 0x05000b00, 0x01000900, 0x07000400, 0xe80f0000, 0xcf000000, 0x05000b00, + 0x01000900, 0x07000100, 0xe90f0000, 0xd5000000, 0x05000b00, 0x01000900, 0x07000100, 0xea0f0000, 0xdb000000, 0x05000b00, 0x01000900, 0x07000100, + 0xeb0f0000, 0x2d000000, 0x05002000, 0x01000800, 0x07000200, 0xec0f0000, 0x2c000000, 0x02001600, 0x02000900, 0x07000100, 0xed0f0000, 0x32000000, + 0x02001600, 0x02000900, 0x07000100, 0xee0f0000, 0x20000000, 0x03001700, 0x02000900, 0x07000100, 0xef0f0000, 0x28000000, 0x03001600, 0x02000900, + 0x07000100, 0xf00f0000, 0xed000000, 0x05000b00, 0x01000900, 0x07000100, 0xf10f0000, 0xf3000000, 0x05000b00, 0x01000900, 0x07000100, 0xf20f0000, + 0xf9000000, 0x05000b00, 0x01000900, 0x07000100, 0xf30f0000, 0x00000000, 0x05001900, 0x01000900, 0x07000100, 0xf40f0000, 0xe1000000, 0x05000b00, + 0x01000900, 0x07000100, 0xf50f0000, 0x06000000, 0x05001900, 0x01000900, 0x07000100, 0xf60f0000, 0x6f000000, 0x05001e00, 0x01000800, 0x07000200, + 0xf70f0000, 0x8a000000, 0x05002700, 0x01000500, 0x07000400, 0xf80f0000, 0x75000000, 0x05001e00, 0x01000800, 0x07000300, 0xf90f0000, 0x0c000000, + 0x05001900, 0x01000900, 0x07000100, 0xfa0f0000, 0x12000000, 0x05001900, 0x01000900, 0x07000100, 0xfb0f0000, 0x87000000, 0x05000b00, 0x01000900, + 0x07000100, 0xfc0f0000, 0x8d000000, 0x05001e00, 0x01000800, 0x07000200, 0xfd0f0000, 0x18000000, 0x05000000, 0x01000c00, 0x07000100, 0xfe0f0000, + 0x00000000, 0x05000e00, 0x01000a00, 0x07000200, 0xff0f0000, 0x31000000, 0x05000000, 0x01000b00, 0x07000200, 0x000f0000, }; void ImGui::GetDefaultFontData(const void** fnt_data, unsigned int* fnt_size, const void** png_data, unsigned int* png_size)