From 63466909629570ec7067eca4ddf8c1c54cf9fd7b Mon Sep 17 00:00:00 2001 From: ocornut Date: Fri, 4 Mar 2016 14:09:08 +0100 Subject: [PATCH 01/19] Comment (#544) --- imgui.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/imgui.h b/imgui.h index 43e6ab3b..2c111949 100644 --- a/imgui.h +++ b/imgui.h @@ -1256,7 +1256,7 @@ struct ImFontAtlas int TexHeight; // Texture height calculated during Build(). int TexDesiredWidth; // Texture width desired by user before Build(). Must be a power-of-two. If have many glyphs your graphics API have texture size restrictions you may want to increase texture width to decrease height. ImVec2 TexUvWhitePixel; // Texture coordinates to a white pixel (part of the TexExtraData block) - ImVector Fonts; + ImVector Fonts; // Hold all the fonts returned by AddFont*. Fonts[0] is the default font upon calling ImGui::NewFrame(), use ImGui::PushFont()/PopFont() to change the current font. // Private ImVector ConfigData; // Internal data From 1dcb9c877d2a591587bc581130d9f95c36e374ca Mon Sep 17 00:00:00 2001 From: ocornut Date: Sun, 6 Mar 2016 10:46:57 +0100 Subject: [PATCH 02/19] Examples: OpenGL: Fix early return on zero-sized framebuffer breaking GL state (#486, #547) --- examples/opengl3_example/imgui_impl_glfw_gl3.cpp | 16 ++++++++-------- examples/opengl_example/imgui_impl_glfw.cpp | 16 ++++++++-------- .../sdl_opengl3_example/imgui_impl_sdl_gl3.cpp | 16 ++++++++-------- examples/sdl_opengl_example/imgui_impl_sdl.cpp | 16 ++++++++-------- 4 files changed, 32 insertions(+), 32 deletions(-) diff --git a/examples/opengl3_example/imgui_impl_glfw_gl3.cpp b/examples/opengl3_example/imgui_impl_glfw_gl3.cpp index e62f1a64..fe895fb0 100644 --- a/examples/opengl3_example/imgui_impl_glfw_gl3.cpp +++ b/examples/opengl3_example/imgui_impl_glfw_gl3.cpp @@ -33,6 +33,14 @@ static unsigned int g_VboHandle = 0, g_VaoHandle = 0, g_ElementsHandle = 0; // - in your Render function, try translating your projection matrix by (0.5f,0.5f) or (0.375f,0.375f) void ImGui_ImplGlfwGL3_RenderDrawLists(ImDrawData* draw_data) { + // Avoid rendering when minimized, scale coordinates for retina displays (screen coordinates != framebuffer coordinates) + ImGuiIO& io = ImGui::GetIO(); + int fb_width = (int)(io.DisplaySize.x * io.DisplayFramebufferScale.x); + int fb_height = (int)(io.DisplaySize.y * io.DisplayFramebufferScale.y); + if (fb_width == 0 || fb_height == 0) + return; + draw_data->ScaleClipRects(io.DisplayFramebufferScale); + // Backup GL state GLint last_program; glGetIntegerv(GL_CURRENT_PROGRAM, &last_program); GLint last_texture; glGetIntegerv(GL_TEXTURE_BINDING_2D, &last_texture); @@ -58,14 +66,6 @@ void ImGui_ImplGlfwGL3_RenderDrawLists(ImDrawData* draw_data) glEnable(GL_SCISSOR_TEST); glActiveTexture(GL_TEXTURE0); - // Handle cases of screen coordinates != from framebuffer coordinates (e.g. retina displays) - ImGuiIO& io = ImGui::GetIO(); - int fb_width = (int)(io.DisplaySize.x * io.DisplayFramebufferScale.x); - int fb_height = (int)(io.DisplaySize.y * io.DisplayFramebufferScale.y); - if (fb_width == 0 || fb_height == 0) - return; - draw_data->ScaleClipRects(io.DisplayFramebufferScale); - // Setup viewport, orthographic projection matrix glViewport(0, 0, (GLsizei)fb_width, (GLsizei)fb_height); const float ortho_projection[4][4] = diff --git a/examples/opengl_example/imgui_impl_glfw.cpp b/examples/opengl_example/imgui_impl_glfw.cpp index 267b6803..54943e1d 100644 --- a/examples/opengl_example/imgui_impl_glfw.cpp +++ b/examples/opengl_example/imgui_impl_glfw.cpp @@ -28,6 +28,14 @@ static GLuint g_FontTexture = 0; // - in your Render function, try translating your projection matrix by (0.5f,0.5f) or (0.375f,0.375f) void ImGui_ImplGlfw_RenderDrawLists(ImDrawData* draw_data) { + // Avoid rendering when minimized, scale coordinates for retina displays (screen coordinates != framebuffer coordinates) + ImGuiIO& io = ImGui::GetIO(); + int fb_width = (int)(io.DisplaySize.x * io.DisplayFramebufferScale.x); + int fb_height = (int)(io.DisplaySize.y * io.DisplayFramebufferScale.y); + if (fb_width == 0 || fb_height == 0) + return; + draw_data->ScaleClipRects(io.DisplayFramebufferScale); + // We are using the OpenGL fixed pipeline to make the example code simpler to read! // Setup render state: alpha-blending enabled, no face culling, no depth testing, scissor enabled, vertex/texcoord/color pointers. GLint last_texture; glGetIntegerv(GL_TEXTURE_BINDING_2D, &last_texture); @@ -44,14 +52,6 @@ void ImGui_ImplGlfw_RenderDrawLists(ImDrawData* draw_data) glEnable(GL_TEXTURE_2D); //glUseProgram(0); // You may want this if using this code in an OpenGL 3+ context - // Handle cases of screen coordinates != from framebuffer coordinates (e.g. retina displays) - ImGuiIO& io = ImGui::GetIO(); - int fb_width = (int)(io.DisplaySize.x * io.DisplayFramebufferScale.x); - int fb_height = (int)(io.DisplaySize.y * io.DisplayFramebufferScale.y); - if (fb_width == 0 || fb_height == 0) - return; - draw_data->ScaleClipRects(io.DisplayFramebufferScale); - // Setup viewport, orthographic projection matrix glViewport(0, 0, (GLsizei)fb_width, (GLsizei)fb_height); glMatrixMode(GL_PROJECTION); diff --git a/examples/sdl_opengl3_example/imgui_impl_sdl_gl3.cpp b/examples/sdl_opengl3_example/imgui_impl_sdl_gl3.cpp index d4cecb13..accaa60a 100644 --- a/examples/sdl_opengl3_example/imgui_impl_sdl_gl3.cpp +++ b/examples/sdl_opengl3_example/imgui_impl_sdl_gl3.cpp @@ -28,6 +28,14 @@ static unsigned int g_VboHandle = 0, g_VaoHandle = 0, g_ElementsHandle = 0; // - in your Render function, try translating your projection matrix by (0.5f,0.5f) or (0.375f,0.375f) void ImGui_ImplSdlGL3_RenderDrawLists(ImDrawData* draw_data) { + // Avoid rendering when minimized, scale coordinates for retina displays (screen coordinates != framebuffer coordinates) + ImGuiIO& io = ImGui::GetIO(); + int fb_width = (int)(io.DisplaySize.x * io.DisplayFramebufferScale.x); + int fb_height = (int)(io.DisplaySize.y * io.DisplayFramebufferScale.y); + if (fb_width == 0 || fb_height == 0) + return; + draw_data->ScaleClipRects(io.DisplayFramebufferScale); + // Backup GL state GLint last_program; glGetIntegerv(GL_CURRENT_PROGRAM, &last_program); GLint last_texture; glGetIntegerv(GL_TEXTURE_BINDING_2D, &last_texture); @@ -53,14 +61,6 @@ void ImGui_ImplSdlGL3_RenderDrawLists(ImDrawData* draw_data) glEnable(GL_SCISSOR_TEST); glActiveTexture(GL_TEXTURE0); - // Handle cases of screen coordinates != from framebuffer coordinates (e.g. retina displays) - ImGuiIO& io = ImGui::GetIO(); - int fb_width = (int)(io.DisplaySize.x * io.DisplayFramebufferScale.x); - int fb_height = (int)(io.DisplaySize.y * io.DisplayFramebufferScale.y); - if (fb_width == 0 || fb_height == 0) - return; - draw_data->ScaleClipRects(io.DisplayFramebufferScale); - // Setup orthographic projection matrix glViewport(0, 0, (GLsizei)fb_width, (GLsizei)fb_height); const float ortho_projection[4][4] = diff --git a/examples/sdl_opengl_example/imgui_impl_sdl.cpp b/examples/sdl_opengl_example/imgui_impl_sdl.cpp index 6ace60a0..a8429a25 100644 --- a/examples/sdl_opengl_example/imgui_impl_sdl.cpp +++ b/examples/sdl_opengl_example/imgui_impl_sdl.cpp @@ -21,6 +21,14 @@ static GLuint g_FontTexture = 0; // - in your Render function, try translating your projection matrix by (0.5f,0.5f) or (0.375f,0.375f) void ImGui_ImplSdl_RenderDrawLists(ImDrawData* draw_data) { + // Avoid rendering when minimized, scale coordinates for retina displays (screen coordinates != framebuffer coordinates) + ImGuiIO& io = ImGui::GetIO(); + int fb_width = (int)(io.DisplaySize.x * io.DisplayFramebufferScale.x); + int fb_height = (int)(io.DisplaySize.y * io.DisplayFramebufferScale.y); + if (fb_width == 0 || fb_height == 0) + return; + draw_data->ScaleClipRects(io.DisplayFramebufferScale); + // We are using the OpenGL fixed pipeline to make the example code simpler to read! // Setup render state: alpha-blending enabled, no face culling, no depth testing, scissor enabled, vertex/texcoord/color pointers. GLint last_texture; glGetIntegerv(GL_TEXTURE_BINDING_2D, &last_texture); @@ -37,14 +45,6 @@ void ImGui_ImplSdl_RenderDrawLists(ImDrawData* draw_data) glEnable(GL_TEXTURE_2D); //glUseProgram(0); // You may want this if using this code in an OpenGL 3+ context - // Handle cases of screen coordinates != from framebuffer coordinates (e.g. retina displays) - ImGuiIO& io = ImGui::GetIO(); - int fb_width = (int)(io.DisplaySize.x * io.DisplayFramebufferScale.x); - int fb_height = (int)(io.DisplaySize.y * io.DisplayFramebufferScale.y); - if (fb_width == 0 || fb_height == 0) - return; - draw_data->ScaleClipRects(io.DisplayFramebufferScale); - // Setup viewport, orthographic projection matrix glViewport(0, 0, (GLsizei)fb_width, (GLsizei)fb_height); glMatrixMode(GL_PROJECTION); From 9ea093ddd0c0ef9523d0918099f1a3a59eb6a42b Mon Sep 17 00:00:00 2001 From: ocornut Date: Mon, 7 Mar 2016 13:12:15 +0100 Subject: [PATCH 03/19] DragFloat(): always apply value when mouse is held/widget active, so that can use a drag over an always-reseting value --- imgui.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 746ff749..91abb338 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -6413,6 +6413,7 @@ bool ImGui::DragBehavior(const ImRect& frame_bb, ImGuiID id, float* v, float v_s g.DragLastMouseDelta = ImVec2(0.f, 0.f); } + float v_cur = g.DragCurrentValue; const ImVec2 mouse_drag_delta = ImGui::GetMouseDragDelta(0, 1.0f); if (fabsf(mouse_drag_delta.x - g.DragLastMouseDelta.x) > 0.0f) { @@ -6424,7 +6425,6 @@ bool ImGui::DragBehavior(const ImRect& frame_bb, ImGuiID id, float* v, float v_s if (g.IO.KeyAlt && g.DragSpeedScaleSlow >= 0.0f) speed = speed * g.DragSpeedScaleSlow; - float v_cur = g.DragCurrentValue; float delta = (mouse_drag_delta.x - g.DragLastMouseDelta.x) * speed; if (fabsf(power - 1.0f) > 0.001f) { @@ -6446,14 +6446,14 @@ bool ImGui::DragBehavior(const ImRect& frame_bb, ImGuiID id, float* v, float v_s if (v_min < v_max) v_cur = ImClamp(v_cur, v_min, v_max); g.DragCurrentValue = v_cur; + } - // Round to user desired precision, then apply - v_cur = RoundScalar(v_cur, decimal_precision); - if (*v != v_cur) - { - *v = v_cur; - value_changed = true; - } + // Round to user desired precision, then apply + v_cur = RoundScalar(v_cur, decimal_precision); + if (*v != v_cur) + { + *v = v_cur; + value_changed = true; } } else From 4b7edffe8a67dc30d22bdc284b208aa01b4f3461 Mon Sep 17 00:00:00 2001 From: ocornut Date: Tue, 8 Mar 2016 20:54:21 +0100 Subject: [PATCH 04/19] Comments --- imgui.cpp | 11 +++++++++-- imgui.h | 6 +++--- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 91abb338..c50a894e 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -19,7 +19,7 @@ - FREQUENTLY ASKED QUESTIONS (FAQ), TIPS - How can I help? - How do I update to a newer version of ImGui? - - Can I have multiple widgets with the same label? Can I have widget without a label? (Yes) + - Can I have multiple widgets with the same label? Can I have widget without a label? (Yes) / A primer on the use of labels/IDs in ImGui. - I integrated ImGui in my engine and the text or lines are blurry.. - I integrated ImGui in my engine and some elements are disappearing when I move windows around.. - How can I load a different font than the default? @@ -426,6 +426,7 @@ - window: detect extra End() call that pop the "Debug" window out and assert at call site instead of later. - window: consider renaming "GetWindowFont" which conflict with old Windows #define (#340) - window/tooltip: allow to set the width of a tooltip to allow TextWrapped() etc. while keeping the height automatic. + - window: increase minimum size of a window with menus or fix the menu rendering so that it doesn't look odd. - draw-list: maintaining bounding box per command would allow to merge draw command when clipping isn't relied on (typical non-scrolling window or non-overflowing column would merge with previous command). !- scrolling: allow immediately effective change of scroll if we haven't appended items yet - splitter/separator: formalize the splitter idiom into an official api (we want to handle n-way split) (#319) @@ -437,7 +438,7 @@ - main: IsItemHovered() make it 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: IsItemHovered() info stored in a stack? so that 'if TreeNode() { Text; TreePop; } if IsHovered' return the hover state of the TreeNode? - input text: add ImGuiInputTextFlags_EnterToApply? (off #218) - - input text: reorganise event handling, allow CharFilter to modify buffers, allow multiple events? (#541) + - input text: reorganize event handling, allow CharFilter to modify buffers, allow multiple events? (#541) - input text multi-line: don't directly call AddText() which does an unnecessary vertex reserve for character count prior to clipping. and/or more line-based clipping to AddText(). and/or reorganize TextUnformatted/RenderText for more efficiency for large text (e.g TextUnformatted could clip and log separately, etc). - input text multi-line: way to dynamically grow the buffer without forcing the user to initially allocate for worse case (follow up on #200) - input text multi-line: line numbers? status bar? (follow up on #200) @@ -445,6 +446,7 @@ - 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: applying arithmetics ops (+,-,*,/) messes up with text edit undo stack. + - button: provide a button that looks framed. - text: proper alignment options - image/image button: misalignment on padded/bordered button? - image/image button: parameters are confusing, image() has tint_col,border_col whereas imagebutton() has bg_col/tint_col. Even thou they are different parameters ordering could be more consistent. can we fix that? @@ -452,6 +454,7 @@ - layout: horizontal flow until no space left (#404) - layout: more generic alignment state (left/right/centered) for single items? - layout: clean up the InputFloatN/SliderFloatN/ColorEdit4 layout code. item width should include frame padding. + - layout: BeginGroup() needs a border option. - columns: declare column set (each column: fixed size, %, fill, distribute default size among fills) (#513, #125) - columns: add a conditional parameter to SetColumnOffset() (#513, #125) - columns: separator function or parameter that works within the column (currently Separator() bypass all columns) (#125) @@ -469,9 +472,11 @@ !- popups/menus: clarify usage of popups id, how MenuItem/Selectable closing parent popups affects the ID, etc. this is quite fishy needs improvement! (#331, #402) - popups: add variant using global identifier similar to Begin/End (#402) - popups: border options. richer api like BeginChild() perhaps? (#197) + - tooltip: tooltip that doesn't fit in entire screen seems to lose their "last prefered button" and may teleport when moving mouse - menus: local shortcuts, global shortcuts (#456, #126) - menus: icons - menus: menubars: some sort of priority / effect of main menu-bar on desktop size? + - menus: calling BeginMenu() twice with a same name doesn't seem to append nicely - statusbar: add a per-window status bar helper similar to what menubar does. - tabs (#261, #351) - separator: separator on the initial position of a window is not visible (cursorpos.y <= clippos.y) @@ -495,6 +500,7 @@ - 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? - tree node / optimization: avoid formatting when clipped. + - tree node: clarify spacing, perhaps provide API to query exact spacing. provide API to draw the primitive. same with Bullet(). - tree node: tree-node/header right-most side doesn't take account of horizontal scrolling. - tree node: add treenode/treepush int variants? because (void*) cast from int warns on some platforms/settings - tree node / selectable render mismatch which is visible if you use them both next to each other (e.g. cf. property viewer) @@ -525,6 +531,7 @@ - input: support track pad style scrolling & slider edit. - 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: provide HoveredTime and ActivatedTime to ease the creation of animations. - style editor: have a more global HSV setter (e.g. alter hue on all elements). consider replacing active/hovered by offset in HSV space? (#438) - style editor: color child window height expressed in multiple of line height. - remote: make a system like RemoteImGui first-class citizen/project (#75) diff --git a/imgui.h b/imgui.h index 2c111949..5259a789 100644 --- a/imgui.h +++ b/imgui.h @@ -239,7 +239,7 @@ namespace ImGui IMGUI_API void TextUnformatted(const char* text, const char* text_end = NULL); // doesn't require null terminated string if 'text_end' is specified. no copy done to any bounded stack buffer, recommended for long chunks of text IMGUI_API void LabelText(const char* label, const char* fmt, ...) IM_PRINTFARGS(2); // display text+label aligned the same way as value+label widgets IMGUI_API void LabelTextV(const char* label, const char* fmt, va_list args); - IMGUI_API void Bullet(); + IMGUI_API void Bullet(); // draw a small circle and keep the cursor on the same line. advance you by the same distance as an empty TreeNode() call. IMGUI_API void BulletText(const char* fmt, ...) IM_PRINTFARGS(1); IMGUI_API void BulletTextV(const char* fmt, va_list args); IMGUI_API bool Button(const char* label, const ImVec2& size = ImVec2(0,0)); @@ -303,8 +303,8 @@ namespace ImGui IMGUI_API bool VSliderInt(const char* label, const ImVec2& size, int* v, int v_min, int v_max, const char* display_format = "%.0f"); // Widgets: Trees - IMGUI_API bool TreeNode(const char* str_label_id); // if returning 'true' the node is open and the user is responsible for calling TreePop() - IMGUI_API bool TreeNode(const char* str_id, const char* fmt, ...) IM_PRINTFARGS(2); // " + IMGUI_API bool TreeNode(const char* str_label_id); // if returning 'true' the node is open and the user is responsible for calling TreePop(). + IMGUI_API bool TreeNode(const char* str_id, const char* fmt, ...) IM_PRINTFARGS(2); // read the FAQ about why and how to use ID. to align arbitrary text at the same level as a TreeNode() you can use Bullet(). IMGUI_API bool TreeNode(const void* ptr_id, const char* fmt, ...) IM_PRINTFARGS(2); // " IMGUI_API bool TreeNodeV(const char* str_id, const char* fmt, va_list args); // " IMGUI_API bool TreeNodeV(const void* ptr_id, const char* fmt, va_list args); // " From 5abb39cb1f2fde6a4988a46548cafdd8727892af Mon Sep 17 00:00:00 2001 From: Daniel Martinek Date: Fri, 18 Mar 2016 14:02:14 +0100 Subject: [PATCH 05/19] Added support for CheckboxFlags that can set multiple flags at the same time. --- imgui.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index c50a894e..62c5288c 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -6907,12 +6907,14 @@ bool ImGui::Checkbox(const char* label, bool* v) bool ImGui::CheckboxFlags(const char* label, unsigned int* flags, unsigned int flags_value) { - bool v = (*flags & flags_value) ? true : false; + bool v = ((*flags & flags_value) == flags_value); bool pressed = ImGui::Checkbox(label, &v); - if (v) - *flags |= flags_value; - else - *flags &= ~flags_value; + if(pressed) { + if (v) + *flags |= flags_value; + else + *flags &= ~flags_value; + } return pressed; } From 37716184b34c84d589913b87e94bf774a905054f Mon Sep 17 00:00:00 2001 From: Daniel Martinek Date: Fri, 18 Mar 2016 16:49:19 +0100 Subject: [PATCH 06/19] Fixed coding style. --- imgui.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/imgui.cpp b/imgui.cpp index 62c5288c..0baebacf 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -6909,12 +6909,14 @@ bool ImGui::CheckboxFlags(const char* label, unsigned int* flags, unsigned int f { bool v = ((*flags & flags_value) == flags_value); bool pressed = ImGui::Checkbox(label, &v); - if(pressed) { + if (pressed) + { if (v) *flags |= flags_value; else *flags &= ~flags_value; } + return pressed; } From 5bffc85ba64a5cb751f50345b01bab4ff9c0ab9d Mon Sep 17 00:00:00 2001 From: Kyle Rocha Date: Mon, 21 Mar 2016 12:07:13 -0700 Subject: [PATCH 07/19] Exposed FindTextDisplayEnd to imgui_internal.h --- imgui.cpp | 29 ++++++++++++++--------------- imgui_internal.h | 2 ++ 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index c50a894e..2bdb8590 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -591,7 +591,6 @@ //------------------------------------------------------------------------- static void LogRenderedText(const ImVec2& ref_pos, const char* text, const char* text_end = NULL); -static const char* FindTextDisplayEnd(const char* text, const char* text_end = NULL); static void PushMultiItemsWidths(int components, float w_full = 0.0f); static float GetDraggedColumnOffset(int column_index); @@ -2510,7 +2509,7 @@ void ImGui::Render() } // Find the optional ## from which we stop displaying text. -static const char* FindTextDisplayEnd(const char* text, const char* text_end) +const char* ImGui::FindTextDisplayEnd(const char* text, const char* text_end) { const char* text_display_end = text; if (!text_end) @@ -2549,7 +2548,7 @@ static void LogRenderedText(const ImVec2& ref_pos, const char* text, const char* ImGuiWindow* window = ImGui::GetCurrentWindowRead(); if (!text_end) - text_end = FindTextDisplayEnd(text, text_end); + text_end = ImGui::FindTextDisplayEnd(text, text_end); const bool log_new_line = ref_pos.y > window->DC.LogLinePosY+1; window->DC.LogLinePosY = ref_pos.y; @@ -2603,7 +2602,7 @@ void ImGui::RenderText(ImVec2 pos, const char* text, const char* text_end, bool const char* text_display_end; if (hide_text_after_hash) { - text_display_end = FindTextDisplayEnd(text, text_end); + text_display_end = ImGui::FindTextDisplayEnd(text, text_end); } else { @@ -2642,7 +2641,7 @@ void ImGui::RenderTextWrapped(ImVec2 pos, const char* text, const char* text_end void ImGui::RenderTextClipped(const ImVec2& pos_min, const ImVec2& pos_max, const char* text, const char* text_end, const ImVec2* text_size_if_known, ImGuiAlign align, const ImVec2* clip_min, const ImVec2* clip_max) { // Hide anything after a '##' string - const char* text_display_end = FindTextDisplayEnd(text, text_end); + const char* text_display_end = ImGui::FindTextDisplayEnd(text, text_end); const int text_len = (int)(text_display_end - text); if (text_len == 0) return; @@ -2749,7 +2748,7 @@ ImVec2 ImGui::CalcTextSize(const char* text, const char* text_end, bool hide_tex const char* text_display_end; if (hide_text_after_double_hash) - text_display_end = FindTextDisplayEnd(text, text_end); // Hide anything after a '##' string + text_display_end = ImGui::FindTextDisplayEnd(text, text_end); // Hide anything after a '##' string else text_display_end = text_end; @@ -6334,7 +6333,7 @@ bool ImGui::SliderFloatN(const char* label, float* v, int components, float v_mi } ImGui::PopID(); - ImGui::TextUnformatted(label, FindTextDisplayEnd(label)); + ImGui::TextUnformatted(label, ImGui::FindTextDisplayEnd(label)); ImGui::EndGroup(); return value_changed; @@ -6376,7 +6375,7 @@ bool ImGui::SliderIntN(const char* label, int* v, int components, int v_min, int } ImGui::PopID(); - ImGui::TextUnformatted(label, FindTextDisplayEnd(label)); + ImGui::TextUnformatted(label, ImGui::FindTextDisplayEnd(label)); ImGui::EndGroup(); return value_changed; @@ -6556,7 +6555,7 @@ bool ImGui::DragFloatN(const char* label, float* v, int components, float v_spee } ImGui::PopID(); - ImGui::TextUnformatted(label, FindTextDisplayEnd(label)); + ImGui::TextUnformatted(label, ImGui::FindTextDisplayEnd(label)); ImGui::EndGroup(); return value_changed; @@ -6595,7 +6594,7 @@ bool ImGui::DragFloatRange2(const char* label, float* v_current_min, float* v_cu ImGui::PopItemWidth(); ImGui::SameLine(0, g.Style.ItemInnerSpacing.x); - ImGui::TextUnformatted(label, FindTextDisplayEnd(label)); + ImGui::TextUnformatted(label, ImGui::FindTextDisplayEnd(label)); ImGui::EndGroup(); ImGui::PopID(); @@ -6634,7 +6633,7 @@ bool ImGui::DragIntN(const char* label, int* v, int components, float v_speed, i } ImGui::PopID(); - ImGui::TextUnformatted(label, FindTextDisplayEnd(label)); + ImGui::TextUnformatted(label, ImGui::FindTextDisplayEnd(label)); ImGui::EndGroup(); return value_changed; @@ -6673,7 +6672,7 @@ bool ImGui::DragIntRange2(const char* label, int* v_current_min, int* v_current_ ImGui::PopItemWidth(); ImGui::SameLine(0, g.Style.ItemInnerSpacing.x); - ImGui::TextUnformatted(label, FindTextDisplayEnd(label)); + ImGui::TextUnformatted(label, ImGui::FindTextDisplayEnd(label)); ImGui::EndGroup(); ImGui::PopID(); @@ -7893,7 +7892,7 @@ bool ImGui::InputFloatN(const char* label, float* v, int components, int decimal ImGui::PopID(); window->DC.CurrentLineTextBaseOffset = ImMax(window->DC.CurrentLineTextBaseOffset, g.Style.FramePadding.y); - ImGui::TextUnformatted(label, FindTextDisplayEnd(label)); + ImGui::TextUnformatted(label, ImGui::FindTextDisplayEnd(label)); ImGui::EndGroup(); return value_changed; @@ -7936,7 +7935,7 @@ bool ImGui::InputIntN(const char* label, int* v, int components, ImGuiInputTextF ImGui::PopID(); window->DC.CurrentLineTextBaseOffset = ImMax(window->DC.CurrentLineTextBaseOffset, g.Style.FramePadding.y); - ImGui::TextUnformatted(label, FindTextDisplayEnd(label)); + ImGui::TextUnformatted(label, ImGui::FindTextDisplayEnd(label)); ImGui::EndGroup(); return value_changed; @@ -8647,7 +8646,7 @@ bool ImGui::ColorEdit4(const char* label, float col[4], bool alpha) g.ColorEditModeStorage.SetInt(id, (edit_mode + 1) % 3); // Don't set local copy of 'edit_mode' right away! } - const char* label_display_end = FindTextDisplayEnd(label); + const char* label_display_end = ImGui::FindTextDisplayEnd(label); if (label != label_display_end) { ImGui::SameLine(0, (window->DC.ColorEditMode == ImGuiColorEditMode_UserSelectShowButton) ? -1.0f : style.ItemInnerSpacing.x); diff --git a/imgui_internal.h b/imgui_internal.h index f6300e74..d6fc78ae 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -683,6 +683,8 @@ namespace ImGui IMGUI_API void SetHoveredID(ImGuiID id); IMGUI_API void KeepAliveID(ImGuiID id); + const char* FindTextDisplayEnd(const char* text, const char* text_end = NULL); + IMGUI_API void EndFrame(); // Automatically called by Render() IMGUI_API void ItemSize(const ImVec2& size, float text_offset_y = 0.0f); From 3f46d9b9337e7ed0f5526f7f4c4dfda2e5c2820f Mon Sep 17 00:00:00 2001 From: Kyle Rocha Date: Mon, 21 Mar 2016 12:33:48 -0700 Subject: [PATCH 08/19] Renamed FindTextDisplayEnd to FindRenderedTextEnd --- imgui.cpp | 29 ++++++++++++++--------------- imgui_internal.h | 5 ++--- 2 files changed, 16 insertions(+), 18 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 2bdb8590..83fdc6e3 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -2508,8 +2508,7 @@ void ImGui::Render() } } -// Find the optional ## from which we stop displaying text. -const char* ImGui::FindTextDisplayEnd(const char* text, const char* text_end) +const char* ImGui::FindRenderedTextEnd(const char* text, const char* text_end) { const char* text_display_end = text; if (!text_end) @@ -2548,7 +2547,7 @@ static void LogRenderedText(const ImVec2& ref_pos, const char* text, const char* ImGuiWindow* window = ImGui::GetCurrentWindowRead(); if (!text_end) - text_end = ImGui::FindTextDisplayEnd(text, text_end); + text_end = ImGui::FindRenderedTextEnd(text, text_end); const bool log_new_line = ref_pos.y > window->DC.LogLinePosY+1; window->DC.LogLinePosY = ref_pos.y; @@ -2602,7 +2601,7 @@ void ImGui::RenderText(ImVec2 pos, const char* text, const char* text_end, bool const char* text_display_end; if (hide_text_after_hash) { - text_display_end = ImGui::FindTextDisplayEnd(text, text_end); + text_display_end = FindRenderedTextEnd(text, text_end); } else { @@ -2641,7 +2640,7 @@ void ImGui::RenderTextWrapped(ImVec2 pos, const char* text, const char* text_end void ImGui::RenderTextClipped(const ImVec2& pos_min, const ImVec2& pos_max, const char* text, const char* text_end, const ImVec2* text_size_if_known, ImGuiAlign align, const ImVec2* clip_min, const ImVec2* clip_max) { // Hide anything after a '##' string - const char* text_display_end = ImGui::FindTextDisplayEnd(text, text_end); + const char* text_display_end = FindRenderedTextEnd(text, text_end); const int text_len = (int)(text_display_end - text); if (text_len == 0) return; @@ -2748,7 +2747,7 @@ ImVec2 ImGui::CalcTextSize(const char* text, const char* text_end, bool hide_tex const char* text_display_end; if (hide_text_after_double_hash) - text_display_end = ImGui::FindTextDisplayEnd(text, text_end); // Hide anything after a '##' string + text_display_end = FindRenderedTextEnd(text, text_end); // Hide anything after a '##' string else text_display_end = text_end; @@ -6333,7 +6332,7 @@ bool ImGui::SliderFloatN(const char* label, float* v, int components, float v_mi } ImGui::PopID(); - ImGui::TextUnformatted(label, ImGui::FindTextDisplayEnd(label)); + ImGui::TextUnformatted(label, FindRenderedTextEnd(label)); ImGui::EndGroup(); return value_changed; @@ -6375,7 +6374,7 @@ bool ImGui::SliderIntN(const char* label, int* v, int components, int v_min, int } ImGui::PopID(); - ImGui::TextUnformatted(label, ImGui::FindTextDisplayEnd(label)); + ImGui::TextUnformatted(label, FindRenderedTextEnd(label)); ImGui::EndGroup(); return value_changed; @@ -6555,7 +6554,7 @@ bool ImGui::DragFloatN(const char* label, float* v, int components, float v_spee } ImGui::PopID(); - ImGui::TextUnformatted(label, ImGui::FindTextDisplayEnd(label)); + ImGui::TextUnformatted(label, FindRenderedTextEnd(label)); ImGui::EndGroup(); return value_changed; @@ -6594,7 +6593,7 @@ bool ImGui::DragFloatRange2(const char* label, float* v_current_min, float* v_cu ImGui::PopItemWidth(); ImGui::SameLine(0, g.Style.ItemInnerSpacing.x); - ImGui::TextUnformatted(label, ImGui::FindTextDisplayEnd(label)); + ImGui::TextUnformatted(label, FindRenderedTextEnd(label)); ImGui::EndGroup(); ImGui::PopID(); @@ -6633,7 +6632,7 @@ bool ImGui::DragIntN(const char* label, int* v, int components, float v_speed, i } ImGui::PopID(); - ImGui::TextUnformatted(label, ImGui::FindTextDisplayEnd(label)); + ImGui::TextUnformatted(label, FindRenderedTextEnd(label)); ImGui::EndGroup(); return value_changed; @@ -6672,7 +6671,7 @@ bool ImGui::DragIntRange2(const char* label, int* v_current_min, int* v_current_ ImGui::PopItemWidth(); ImGui::SameLine(0, g.Style.ItemInnerSpacing.x); - ImGui::TextUnformatted(label, ImGui::FindTextDisplayEnd(label)); + ImGui::TextUnformatted(label, FindRenderedTextEnd(label)); ImGui::EndGroup(); ImGui::PopID(); @@ -7892,7 +7891,7 @@ bool ImGui::InputFloatN(const char* label, float* v, int components, int decimal ImGui::PopID(); window->DC.CurrentLineTextBaseOffset = ImMax(window->DC.CurrentLineTextBaseOffset, g.Style.FramePadding.y); - ImGui::TextUnformatted(label, ImGui::FindTextDisplayEnd(label)); + ImGui::TextUnformatted(label, FindRenderedTextEnd(label)); ImGui::EndGroup(); return value_changed; @@ -7935,7 +7934,7 @@ bool ImGui::InputIntN(const char* label, int* v, int components, ImGuiInputTextF ImGui::PopID(); window->DC.CurrentLineTextBaseOffset = ImMax(window->DC.CurrentLineTextBaseOffset, g.Style.FramePadding.y); - ImGui::TextUnformatted(label, ImGui::FindTextDisplayEnd(label)); + ImGui::TextUnformatted(label, FindRenderedTextEnd(label)); ImGui::EndGroup(); return value_changed; @@ -8646,7 +8645,7 @@ bool ImGui::ColorEdit4(const char* label, float col[4], bool alpha) g.ColorEditModeStorage.SetInt(id, (edit_mode + 1) % 3); // Don't set local copy of 'edit_mode' right away! } - const char* label_display_end = ImGui::FindTextDisplayEnd(label); + const char* label_display_end = FindRenderedTextEnd(label); if (label != label_display_end) { ImGui::SameLine(0, (window->DC.ColorEditMode == ImGuiColorEditMode_UserSelectShowButton) ? -1.0f : style.ItemInnerSpacing.x); diff --git a/imgui_internal.h b/imgui_internal.h index d6fc78ae..d5f97c60 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -683,8 +683,6 @@ namespace ImGui IMGUI_API void SetHoveredID(ImGuiID id); IMGUI_API void KeepAliveID(ImGuiID id); - const char* FindTextDisplayEnd(const char* text, const char* text_end = NULL); - IMGUI_API void EndFrame(); // Automatically called by Render() IMGUI_API void ItemSize(const ImVec2& size, float text_offset_y = 0.0f); @@ -709,7 +707,8 @@ namespace ImGui IMGUI_API void RenderTextClipped(const ImVec2& pos_min, const ImVec2& pos_max, const char* text, const char* text_end, const ImVec2* text_size_if_known, ImGuiAlign align = ImGuiAlign_Default, const ImVec2* clip_min = NULL, const ImVec2* clip_max = NULL); IMGUI_API void RenderFrame(ImVec2 p_min, ImVec2 p_max, ImU32 fill_col, bool border = true, float rounding = 0.0f); IMGUI_API void RenderCollapseTriangle(ImVec2 p_min, bool opened, float scale = 1.0f, bool shadow = false); - IMGUI_API void RenderCheckMark(ImVec2 pos, ImU32 col); + IMGUI_API void RenderCheckMark(ImVec2 pos, ImU32 col); + IMGUI_API const char* FindRenderedTextEnd(const char* text, const char* text_end = NULL); // Find the optional ## from which we stop displaying text. IMGUI_API void PushClipRect(const ImVec2& clip_rect_min, const ImVec2& clip_rect_max, bool intersect_with_existing_clip_rect = true); IMGUI_API void PopClipRect(); From b8fcb4e7e450d536c2e881ae026a8f3227219865 Mon Sep 17 00:00:00 2001 From: Kyle Rocha Date: Mon, 21 Mar 2016 12:40:02 -0700 Subject: [PATCH 09/19] Converted tabs to spaces --- imgui_internal.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/imgui_internal.h b/imgui_internal.h index d5f97c60..4df5ca94 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -708,7 +708,7 @@ namespace ImGui IMGUI_API void RenderFrame(ImVec2 p_min, ImVec2 p_max, ImU32 fill_col, bool border = true, float rounding = 0.0f); IMGUI_API void RenderCollapseTriangle(ImVec2 p_min, bool opened, float scale = 1.0f, bool shadow = false); IMGUI_API void RenderCheckMark(ImVec2 pos, ImU32 col); - IMGUI_API const char* FindRenderedTextEnd(const char* text, const char* text_end = NULL); // Find the optional ## from which we stop displaying text. + IMGUI_API const char* FindRenderedTextEnd(const char* text, const char* text_end = NULL); // Find the optional ## from which we stop displaying text. IMGUI_API void PushClipRect(const ImVec2& clip_rect_min, const ImVec2& clip_rect_max, bool intersect_with_existing_clip_rect = true); IMGUI_API void PopClipRect(); From a9e303e0064d7a698e46383bdc8f8f5a069abf02 Mon Sep 17 00:00:00 2001 From: ocornut Date: Mon, 21 Mar 2016 12:56:56 -0700 Subject: [PATCH 10/19] Minor comments --- imgui.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/imgui.h b/imgui.h index 5259a789..9731e31e 100644 --- a/imgui.h +++ b/imgui.h @@ -103,9 +103,9 @@ namespace ImGui // Main IMGUI_API ImGuiIO& GetIO(); IMGUI_API ImGuiStyle& GetStyle(); - IMGUI_API ImDrawData* GetDrawData(); // same value as passed to your RenderDrawListsFn() function. valid after Render() and until the next call to NewFrame() + IMGUI_API ImDrawData* GetDrawData(); // same value as passed to your io.RenderDrawListsFn() function. valid after Render() and until the next call to NewFrame(). IMGUI_API void NewFrame(); - IMGUI_API void Render(); + IMGUI_API void Render(); // finalize rendering data, then call your io.RenderDrawListsFn() function if set. IMGUI_API void Shutdown(); IMGUI_API void ShowUserGuide(); // help block IMGUI_API void ShowStyleEditor(ImGuiStyle* ref = NULL); // style editor block From 86fb3a6a3c3c4a8ce2786bd1a937583a6b8acaef Mon Sep 17 00:00:00 2001 From: ocornut Date: Mon, 21 Mar 2016 21:48:05 +0100 Subject: [PATCH 11/19] ImDrawList: AddCircle() takes optional thickness parameter --- imgui.h | 2 +- imgui_draw.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/imgui.h b/imgui.h index 9731e31e..2764ff4b 100644 --- a/imgui.h +++ b/imgui.h @@ -1125,7 +1125,7 @@ struct ImDrawList IMGUI_API void AddRectFilled(const ImVec2& a, const ImVec2& b, ImU32 col, float rounding = 0.0f, int rounding_corners = 0x0F); // a: upper-left, b: lower-right IMGUI_API void AddRectFilledMultiColor(const ImVec2& a, const ImVec2& b, ImU32 col_upr_left, ImU32 col_upr_right, ImU32 col_bot_right, ImU32 col_bot_left); IMGUI_API void AddTriangleFilled(const ImVec2& a, const ImVec2& b, const ImVec2& c, ImU32 col); - IMGUI_API void AddCircle(const ImVec2& centre, float radius, ImU32 col, int num_segments = 12); + IMGUI_API void AddCircle(const ImVec2& centre, float radius, ImU32 col, int num_segments = 12, float thickness = 1.0f); IMGUI_API void AddCircleFilled(const ImVec2& centre, float radius, ImU32 col, int num_segments = 12); IMGUI_API void AddText(const ImVec2& pos, ImU32 col, const char* text_begin, const char* text_end = NULL); IMGUI_API void AddText(const ImFont* font, float font_size, const ImVec2& pos, ImU32 col, const char* text_begin, const char* text_end = NULL, float wrap_width = 0.0f, const ImVec4* cpu_fine_clip_rect = NULL); diff --git a/imgui_draw.cpp b/imgui_draw.cpp index 9fbda0c6..77d596cd 100644 --- a/imgui_draw.cpp +++ b/imgui_draw.cpp @@ -834,14 +834,14 @@ void ImDrawList::AddTriangleFilled(const ImVec2& a, const ImVec2& b, const ImVec PathFill(col); } -void ImDrawList::AddCircle(const ImVec2& centre, float radius, ImU32 col, int num_segments) +void ImDrawList::AddCircle(const ImVec2& centre, float radius, ImU32 col, int num_segments, float thickness) { if ((col >> 24) == 0) return; const float a_max = IM_PI*2.0f * ((float)num_segments - 1.0f) / (float)num_segments; PathArcTo(centre, radius-0.5f, 0.0f, a_max, num_segments); - PathStroke(col, true); + PathStroke(col, true, thickness); } void ImDrawList::AddCircleFilled(const ImVec2& centre, float radius, ImU32 col, int num_segments) From 9cbc6e196b5b88e11263917920b441ede48084eb Mon Sep 17 00:00:00 2001 From: ocornut Date: Mon, 21 Mar 2016 21:56:23 +0100 Subject: [PATCH 12/19] ImDrawList: AddRect() added optional thickness parameter + updated demo --- imgui.h | 4 ++-- imgui_demo.cpp | 28 ++++++++++++++-------------- imgui_draw.cpp | 4 ++-- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/imgui.h b/imgui.h index 2764ff4b..f484d6e3 100644 --- a/imgui.h +++ b/imgui.h @@ -1121,8 +1121,8 @@ struct ImDrawList // Primitives IMGUI_API void AddLine(const ImVec2& a, const ImVec2& b, ImU32 col, float thickness = 1.0f); - IMGUI_API void AddRect(const ImVec2& a, const ImVec2& b, ImU32 col, float rounding = 0.0f, int rounding_corners = 0x0F); // a: upper-left, b: lower-right - IMGUI_API void AddRectFilled(const ImVec2& a, const ImVec2& b, ImU32 col, float rounding = 0.0f, int rounding_corners = 0x0F); // a: upper-left, b: lower-right + IMGUI_API void AddRect(const ImVec2& a, const ImVec2& b, ImU32 col, float rounding = 0.0f, int rounding_corners = 0x0F, float thickness = 1.0f); // a: upper-left, b: lower-right + IMGUI_API void AddRectFilled(const ImVec2& a, const ImVec2& b, ImU32 col, float rounding = 0.0f, int rounding_corners = 0x0F); // a: upper-left, b: lower-right IMGUI_API void AddRectFilledMultiColor(const ImVec2& a, const ImVec2& b, ImU32 col_upr_left, ImU32 col_upr_right, ImU32 col_bot_right, ImU32 col_bot_left); IMGUI_API void AddTriangleFilled(const ImVec2& a, const ImVec2& b, const ImVec2& c, ImU32 col); IMGUI_API void AddCircle(const ImVec2& centre, float radius, ImU32 col, int num_segments = 12, float thickness = 1.0f); diff --git a/imgui_demo.cpp b/imgui_demo.cpp index b2e4e09e..4b51e2bb 100644 --- a/imgui_demo.cpp +++ b/imgui_demo.cpp @@ -1804,24 +1804,24 @@ static void ShowExampleAppCustomRendering(bool* opened) const ImVec2 p = ImGui::GetCursorScreenPos(); const ImU32 col32 = ImColor(col); float x = p.x + 4.0f, y = p.y + 4.0f, spacing = 8.0f; - draw_list->AddCircle(ImVec2(x+sz*0.5f, y+sz*0.5f), sz*0.5f, col32, 32); x += sz+spacing; - draw_list->AddRect(ImVec2(x, y), ImVec2(x+sz, y+sz), col32); x += sz+spacing; - draw_list->AddRect(ImVec2(x, y), ImVec2(x+sz, y+sz), col32, 10.0f); x += sz+spacing; - draw_list->AddLine(ImVec2(x, y), ImVec2(x+sz, y ), col32); x += sz+spacing; - draw_list->AddLine(ImVec2(x, y), ImVec2(x+sz, y+sz), col32); x += sz+spacing; - draw_list->AddLine(ImVec2(x, y), ImVec2(x, y+sz), col32); x += spacing; - draw_list->AddBezierCurve(ImVec2(x, y), ImVec2(x+sz*1.3f,y+sz*0.3f), ImVec2(x+sz-sz*1.3f,y+sz-sz*0.3f), ImVec2(x+sz, y+sz), col32, 1.0f); - x = p.x + 4; - y += sz+spacing; + for (int n = 0; n < 2; n++) + { + float thickness = (n == 0) ? 1.0f : 4.0f; + draw_list->AddCircle(ImVec2(x+sz*0.5f, y+sz*0.5f), sz*0.5f, col32, 20, thickness); x += sz+spacing; + draw_list->AddRect(ImVec2(x, y), ImVec2(x+sz, y+sz), col32, 0.0f, ~0, thickness); x += sz+spacing; + draw_list->AddRect(ImVec2(x, y), ImVec2(x+sz, y+sz), col32, 10.0f, ~0, thickness); x += sz+spacing; + draw_list->AddLine(ImVec2(x, y), ImVec2(x+sz, y ), col32, thickness); x += sz+spacing; + draw_list->AddLine(ImVec2(x, y), ImVec2(x+sz, y+sz), col32, thickness); x += sz+spacing; + draw_list->AddLine(ImVec2(x, y), ImVec2(x, y+sz), col32, thickness); x += spacing; + draw_list->AddBezierCurve(ImVec2(x, y), ImVec2(x+sz*1.3f,y+sz*0.3f), ImVec2(x+sz-sz*1.3f,y+sz-sz*0.3f), ImVec2(x+sz, y+sz), col32, thickness); + x = p.x + 4; + y += sz+spacing; + } draw_list->AddCircleFilled(ImVec2(x+sz*0.5f, y+sz*0.5f), sz*0.5f, col32, 32); x += sz+spacing; draw_list->AddRectFilled(ImVec2(x, y), ImVec2(x+sz, y+sz), col32); x += sz+spacing; draw_list->AddRectFilled(ImVec2(x, y), ImVec2(x+sz, y+sz), col32, 10.0f); x += sz+spacing; - draw_list->AddLine(ImVec2(x, y), ImVec2(x+sz, y ), col32, 4.0f); x += sz+spacing; - draw_list->AddLine(ImVec2(x, y), ImVec2(x+sz, y+sz), col32, 4.0f); x += sz+spacing; - draw_list->AddLine(ImVec2(x, y), ImVec2(x, y+sz), col32, 4.0f); x += spacing; - draw_list->AddBezierCurve(ImVec2(x, y), ImVec2(x+sz*1.3f,y+sz*0.3f), ImVec2(x+sz-sz*1.3f,y+sz-sz*0.3f), ImVec2(x+sz, y+sz), col32, 4.0f); x += sz+spacing; draw_list->AddRectFilledMultiColor(ImVec2(x, y), ImVec2(x+sz, y+sz), ImColor(0,0,0), ImColor(255,0,0), ImColor(255,255,0), ImColor(0,255,0)); - ImGui::Dummy(ImVec2((sz+spacing)*8, (sz+spacing)*2)); + ImGui::Dummy(ImVec2((sz+spacing)*8, (sz+spacing)*3)); } ImGui::Separator(); { diff --git a/imgui_draw.cpp b/imgui_draw.cpp index 77d596cd..5a8fe770 100644 --- a/imgui_draw.cpp +++ b/imgui_draw.cpp @@ -784,12 +784,12 @@ void ImDrawList::AddLine(const ImVec2& a, const ImVec2& b, ImU32 col, float thic } // a: upper-left, b: lower-right. we don't render 1 px sized rectangles properly. -void ImDrawList::AddRect(const ImVec2& a, const ImVec2& b, ImU32 col, float rounding, int rounding_corners) +void ImDrawList::AddRect(const ImVec2& a, const ImVec2& b, ImU32 col, float rounding, int rounding_corners, float thickness) { if ((col >> 24) == 0) return; PathRect(a + ImVec2(0.5f,0.5f), b - ImVec2(0.5f,0.5f), rounding, rounding_corners); - PathStroke(col, true); + PathStroke(col, true, thickness); } void ImDrawList::AddRectFilled(const ImVec2& a, const ImVec2& b, ImU32 col, float rounding, int rounding_corners) From 928832a5bc93eb4285f73ef3e181a233a3abbe71 Mon Sep 17 00:00:00 2001 From: ocornut Date: Mon, 21 Mar 2016 22:11:43 +0100 Subject: [PATCH 13/19] Various tidying up / comments, moved columns functions declarations, no functional changes --- imgui.cpp | 22 ++++++++++------------ imgui.h | 27 +++++++++++++++------------ imgui_draw.cpp | 2 +- imgui_internal.h | 2 +- 4 files changed, 27 insertions(+), 26 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 8fca8fae..9d2d1413 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -2826,13 +2826,13 @@ static ImGuiWindow* FindHoveredWindow(ImVec2 pos, bool excluding_childs) // Test if mouse cursor is hovering given rectangle // NB- Rectangle is clipped by our current clip setting // NB- Expand the rectangle to be generous on imprecise inputs systems (g.Style.TouchExtraPadding) -bool ImGui::IsMouseHoveringRect(const ImVec2& pos_min, const ImVec2& pos_max, bool clip) +bool ImGui::IsMouseHoveringRect(const ImVec2& r_min, const ImVec2& r_max, bool clip) { ImGuiState& g = *GImGui; ImGuiWindow* window = GetCurrentWindowRead(); // Clip - ImRect rect_clipped(pos_min, pos_max); + ImRect rect_clipped(r_min, r_max); if (clip) rect_clipped.Clip(window->ClipRect); @@ -8798,33 +8798,31 @@ void ImGui::EndGroup() } // Gets back to previous line and continue with horizontal layout -// local_pos_x == 0 : follow on previous item -// local_pos_x != 0 : align to specified column +// pos_x == 0 : follow on previous item +// pos_x != 0 : align to specified column // spacing_w < 0 : use default spacing if column_x==0, no spacing if column_x!=0 // spacing_w >= 0 : enforce spacing -void ImGui::SameLine(float local_pos_x, float spacing_w) +void ImGui::SameLine(float pos_x, float spacing_w) { ImGuiWindow* window = GetCurrentWindow(); if (window->SkipItems) return; ImGuiState& g = *GImGui; - float x, y; - if (local_pos_x != 0.0f) + if (pos_x != 0.0f) { if (spacing_w < 0.0f) spacing_w = 0.0f; - x = window->Pos.x - window->Scroll.x + local_pos_x + spacing_w; - y = window->DC.CursorPosPrevLine.y; + window->DC.CursorPos.x = window->Pos.x - window->Scroll.x + pos_x + spacing_w; + window->DC.CursorPos.y = window->DC.CursorPosPrevLine.y; } else { if (spacing_w < 0.0f) spacing_w = g.Style.ItemSpacing.x; - x = window->DC.CursorPosPrevLine.x + spacing_w; - y = window->DC.CursorPosPrevLine.y; + window->DC.CursorPos.x = window->DC.CursorPosPrevLine.x + spacing_w; + window->DC.CursorPos.y = window->DC.CursorPosPrevLine.y; } window->DC.CurrentLineHeight = window->DC.PrevLineHeight; window->DC.CurrentLineTextBaseOffset = window->DC.PrevLineTextBaseOffset; - window->DC.CursorPos = ImVec2(x, y); } void ImGui::NextColumn() diff --git a/imgui.h b/imgui.h index f484d6e3..7e4b5917 100644 --- a/imgui.h +++ b/imgui.h @@ -189,18 +189,11 @@ namespace ImGui IMGUI_API void BeginGroup(); // lock horizontal starting position. once closing a group it is seen as a single item (so you can use IsItemHovered() on a group, SameLine() between groups, etc. IMGUI_API void EndGroup(); IMGUI_API void Separator(); // horizontal line - IMGUI_API void SameLine(float local_pos_x = 0.0f, float spacing_w = -1.0f); // call between widgets or groups to layout them horizontally + IMGUI_API void SameLine(float pos_x = 0.0f, float spacing_w = -1.0f); // call between widgets or groups to layout them horizontally IMGUI_API void Spacing(); // add spacing IMGUI_API void Dummy(const ImVec2& size); // add a dummy item of given size IMGUI_API void Indent(); // move content position toward the right by style.IndentSpacing pixels IMGUI_API void Unindent(); // move content position back to the left (cancel Indent) - IMGUI_API void Columns(int count = 1, const char* id = NULL, bool border = true); // setup number of columns. use an identifier to distinguish multiple column sets. close with Columns(1). - IMGUI_API void NextColumn(); // next column - IMGUI_API int GetColumnIndex(); // get current column index - IMGUI_API float GetColumnOffset(int column_index = -1); // get position of column line (in pixels, from the left side of the contents region). pass -1 to use current column, otherwise 0..GetcolumnsCount() inclusive. column 0 is usually 0.0f and not resizable unless you call this - IMGUI_API void SetColumnOffset(int column_index, float offset_x); // set position of column line (in pixels, from the left side of the contents region). pass -1 to use current column - IMGUI_API float GetColumnWidth(int column_index = -1); // column width (== GetColumnOffset(GetColumnIndex()+1) - GetColumnOffset(GetColumnOffset()) - IMGUI_API int GetColumnsCount(); // number of columns (what was passed to Columns()) IMGUI_API ImVec2 GetCursorPos(); // cursor position is relative to window position IMGUI_API float GetCursorPosX(); // " IMGUI_API float GetCursorPosY(); // " @@ -215,6 +208,16 @@ namespace ImGui IMGUI_API float GetTextLineHeightWithSpacing(); // distance (in pixels) between 2 consecutive lines of text == GetWindowFontSize() + GetStyle().ItemSpacing.y IMGUI_API float GetItemsLineHeightWithSpacing(); // distance (in pixels) between 2 consecutive lines of standard height widgets == GetWindowFontSize() + GetStyle().FramePadding.y*2 + GetStyle().ItemSpacing.y + // Columns + // You can also use SameLine(pos_x) for simplified columning. The columns API is still work-in-progress. + IMGUI_API void Columns(int count = 1, const char* id = NULL, bool border = true); // setup number of columns. use an identifier to distinguish multiple column sets. close with Columns(1). + IMGUI_API void NextColumn(); // next column + IMGUI_API int GetColumnIndex(); // get current column index + IMGUI_API float GetColumnOffset(int column_index = -1); // get position of column line (in pixels, from the left side of the contents region). pass -1 to use current column, otherwise 0..GetcolumnsCount() inclusive. column 0 is usually 0.0f and not resizable unless you call this + IMGUI_API void SetColumnOffset(int column_index, float offset_x); // set position of column line (in pixels, from the left side of the contents region). pass -1 to use current column + IMGUI_API float GetColumnWidth(int column_index = -1); // column width (== GetColumnOffset(GetColumnIndex()+1) - GetColumnOffset(GetColumnOffset()) + IMGUI_API int GetColumnsCount(); // number of columns (what was passed to Columns()) + // ID scopes // If you are creating widgets in a loop you most likely want to push a unique identifier so ImGui can differentiate them. // You can also use the "##foobar" syntax within widget label to distinguish them from each others. Read "A primer on the use of labels/IDs" in the FAQ for more details. @@ -330,7 +333,7 @@ namespace ImGui IMGUI_API void ValueColor(const char* prefix, const ImVec4& v); IMGUI_API void ValueColor(const char* prefix, unsigned int v); - // Tooltip + // Tooltips IMGUI_API void SetTooltip(const char* fmt, ...) IM_PRINTFARGS(1); // set tooltip under mouse-cursor, typically use with ImGui::IsHovered(). last call wins IMGUI_API void SetTooltipV(const char* fmt, va_list args); IMGUI_API void BeginTooltip(); // use to create full-featured tooltip windows that aren't just text @@ -346,7 +349,7 @@ namespace ImGui IMGUI_API bool MenuItem(const char* label, const char* shortcut = NULL, bool selected = false, bool enabled = true); // return true when activated. shortcuts are displayed for convenience but not processed by ImGui at the moment IMGUI_API bool MenuItem(const char* label, const char* shortcut, bool* p_selected, bool enabled = true); // return true when activated + toggle (*p_selected) if p_selected != NULL - // Popup + // Popups IMGUI_API void OpenPopup(const char* str_id); // mark popup as open. popups are closed when user click outside, or activate a pressable item, or CloseCurrentPopup() is called within a BeginPopup()/EndPopup() block. popup identifiers are relative to the current ID-stack (so OpenPopup and BeginPopup needs to be at the same level). IMGUI_API bool BeginPopup(const char* str_id); // return true if popup if opened and start outputting to it. only call EndPopup() if BeginPopup() returned true! IMGUI_API bool BeginPopupModal(const char* name, bool* p_opened = NULL, ImGuiWindowFlags extra_flags = 0); // modal dialog (can't close them by clicking outside) @@ -407,7 +410,7 @@ namespace ImGui IMGUI_API bool IsMouseReleased(int button); // did mouse button released (went from Down to !Down) IMGUI_API bool IsMouseHoveringWindow(); // is mouse hovering current window ("window" in API names always refer to current window). disregarding of any consideration of being blocked by a popup. (unlike IsWindowHovered() this will return true even if the window is blocked because of a popup) IMGUI_API bool IsMouseHoveringAnyWindow(); // is mouse hovering any visible window - IMGUI_API bool IsMouseHoveringRect(const ImVec2& pos_min, const ImVec2& pos_max, bool clip = true); // is mouse hovering given bounding rect (in screen space). clipped by current clipping settings. disregarding of consideration of focus/window ordering/blocked by a popup. + IMGUI_API bool IsMouseHoveringRect(const ImVec2& r_min, const ImVec2& r_max, bool clip = true); // is mouse hovering given bounding rect (in screen space). clipped by current clipping settings. disregarding of consideration of focus/window ordering/blocked by a popup. IMGUI_API bool IsMouseDragging(int button = 0, float lock_threshold = -1.0f); // is mouse dragging. if lock_threshold < -1.0f uses io.MouseDraggingThreshold IMGUI_API ImVec2 GetMousePos(); // shortcut to ImGui::GetIO().MousePos provided by user, to be consistent with other calls IMGUI_API ImVec2 GetMousePosOnOpeningCurrentPopup(); // retrieve backup of mouse positioning at the time of opening popup we have BeginPopup() into @@ -1255,7 +1258,7 @@ struct ImFontAtlas int TexWidth; // Texture width calculated during Build(). int TexHeight; // Texture height calculated during Build(). int TexDesiredWidth; // Texture width desired by user before Build(). Must be a power-of-two. If have many glyphs your graphics API have texture size restrictions you may want to increase texture width to decrease height. - ImVec2 TexUvWhitePixel; // Texture coordinates to a white pixel (part of the TexExtraData block) + ImVec2 TexUvWhitePixel; // Texture coordinates to a white pixel ImVector Fonts; // Hold all the fonts returned by AddFont*. Fonts[0] is the default font upon calling ImGui::NewFrame(), use ImGui::PushFont()/PopFont() to change the current font. // Private diff --git a/imgui_draw.cpp b/imgui_draw.cpp index 5a8fe770..a401b771 100644 --- a/imgui_draw.cpp +++ b/imgui_draw.cpp @@ -906,7 +906,7 @@ void ImDrawList::AddText(const ImFont* font, float font_size, const ImVec2& pos, _VtxCurrentIdx = (unsigned int)VtxBuffer.Size; } -// This is one of the few function breaking the encapsulation of ImDrawLst, but it is just so useful. +// [Uses global ImGui state] This is one of the few function breaking the encapsulation of ImDrawLst, but it is just so useful. void ImDrawList::AddText(const ImVec2& pos, ImU32 col, const char* text_begin, const char* text_end) { if ((col >> 24) == 0) diff --git a/imgui_internal.h b/imgui_internal.h index 4df5ca94..554ef885 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -356,7 +356,7 @@ struct ImGuiState ImFont* Font; // (Shortcut) == FontStack.empty() ? IO.Font : FontStack.back() float FontSize; // (Shortcut) == FontBaseSize * g.CurrentWindow->FontWindowScale == window->FontSize() float FontBaseSize; // (Shortcut) == IO.FontGlobalScale * Font->Scale * Font->FontSize. Size of characters. - ImVec2 FontTexUvWhitePixel; // (Shortcut) == Font->TexUvForWhite + ImVec2 FontTexUvWhitePixel; // (Shortcut) == Font->TexUvWhitePixel float Time; int FrameCount; From a274a09955219c6cca2614b58605696942c4261a Mon Sep 17 00:00:00 2001 From: ocornut Date: Mon, 21 Mar 2016 22:29:11 +0100 Subject: [PATCH 14/19] Renamed GetWindowFont()->GetFont(), GetWindowFontSize()->GetFontSize() (related to #340) --- imgui.cpp | 12 +++++------- imgui.h | 8 +++++--- imgui_demo.cpp | 2 +- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 9d2d1413..7593bd47 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -149,6 +149,7 @@ 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. Also read releases logs https://github.com/ocornut/imgui/releases for more details. + - 2016/03/21 (1.48) - renamed GetWindowFont() to GetFont(), GetWindowFontSize() to GetFontSize(). Kept inline redirection function (will obsolete). - 2016/03/02 (1.48) - InputText() completion/history/always callbacks: if you modify the text buffer manually (without using DeleteChars()/InsertChars() helper) you need to maintain the BufTextLen field. added an assert. - 2016/01/23 (1.48) - fixed not honoring exact width passed to PushItemWidth(), previously it would add extra FramePadding.x*2 over that width. if you had manual pixel-perfect alignment in place it might affect you. - 2015/12/27 (1.48) - fixed ImDrawList::AddRect() which used to render a rectangle 1 px too large on each axis. @@ -424,7 +425,6 @@ - window: get size/pos helpers given names (see discussion in #249) - window: a collapsed window can be stuck behind the main menu bar? - window: detect extra End() call that pop the "Debug" window out and assert at call site instead of later. - - window: consider renaming "GetWindowFont" which conflict with old Windows #define (#340) - window/tooltip: allow to set the width of a tooltip to allow TextWrapped() etc. while keeping the height automatic. - window: increase minimum size of a window with menus or fix the menu rendering so that it doesn't look odd. - draw-list: maintaining bounding box per command would allow to merge draw command when clipping isn't relied on (typical non-scrolling window or non-overflowing column would merge with previous command). @@ -4828,16 +4828,14 @@ ImDrawList* ImGui::GetWindowDrawList() return window->DrawList; } -ImFont* ImGui::GetWindowFont() +ImFont* ImGui::GetFont() { - ImGuiState& g = *GImGui; - return g.Font; + return GImGui->Font; } -float ImGui::GetWindowFontSize() +float ImGui::GetFontSize() { - ImGuiState& g = *GImGui; - return g.FontSize; + return GImGui->FontSize; } void ImGui::SetWindowFontScale(float scale) diff --git a/imgui.h b/imgui.h index 7e4b5917..df23e7bd 100644 --- a/imgui.h +++ b/imgui.h @@ -126,14 +126,12 @@ namespace ImGui IMGUI_API ImVec2 GetWindowContentRegionMax(); // content boundaries max (roughly (0,0)+Size-Scroll) where Size can be override with SetNextWindowContentSize(), in window coordinates IMGUI_API float GetWindowContentRegionWidth(); // IMGUI_API ImDrawList* GetWindowDrawList(); // get rendering command-list if you want to append your own draw primitives - IMGUI_API ImFont* GetWindowFont(); - IMGUI_API float GetWindowFontSize(); // size (also height in pixels) of current font with current scale applied - IMGUI_API void SetWindowFontScale(float scale); // per-window font scale. Adjust IO.FontGlobalScale if you want to scale all windows IMGUI_API ImVec2 GetWindowPos(); // get current window position in screen space (useful if you want to do your own drawing via the DrawList api) IMGUI_API ImVec2 GetWindowSize(); // get current window size IMGUI_API float GetWindowWidth(); IMGUI_API float GetWindowHeight(); IMGUI_API bool IsWindowCollapsed(); + IMGUI_API void SetWindowFontScale(float scale); // per-window font scale. Adjust IO.FontGlobalScale if you want to scale all windows IMGUI_API void SetNextWindowPos(const ImVec2& pos, ImGuiSetCond cond = 0); // set next window position. call before Begin() IMGUI_API void SetNextWindowPosCenter(ImGuiSetCond cond = 0); // set next window position to be centered on screen. call before Begin() @@ -171,6 +169,8 @@ namespace ImGui IMGUI_API void PushStyleVar(ImGuiStyleVar idx, float val); IMGUI_API void PushStyleVar(ImGuiStyleVar idx, const ImVec2& val); IMGUI_API void PopStyleVar(int count = 1); + IMGUI_API ImFont* GetFont(); // get current font + IMGUI_API float GetFontSize(); // get current font size (= height in pixels) of current font with current scale applied IMGUI_API ImU32 GetColorU32(ImGuiCol idx, float alpha_mul = 1.0f); // retrieve given style color with style alpha applied and optional extra alpha multiplier IMGUI_API ImU32 GetColorU32(const ImVec4& col); // retrieve given color with style alpha applied @@ -435,6 +435,8 @@ namespace ImGui // Obsolete (will be removed) #ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS + static inline ImFont* GetWindowFont() { return GetFont(); } // OBSOLETE 1.48+ + static inline float GetWindowFontSize() { return GetFontSize(); } // OBSOLETE 1.48+ static inline void OpenNextNode(bool open) { ImGui::SetNextTreeNodeOpened(open, 0); } // OBSOLETE 1.34+ static inline bool GetWindowIsFocused() { return ImGui::IsWindowFocused(); } // OBSOLETE 1.36+ static inline bool GetWindowCollapsed() { return ImGui::IsWindowCollapsed(); } // OBSOLETE 1.39+ diff --git a/imgui_demo.cpp b/imgui_demo.cpp index 4b51e2bb..532a10c2 100644 --- a/imgui_demo.cpp +++ b/imgui_demo.cpp @@ -1108,7 +1108,7 @@ void ImGui::ShowTestWindow(bool* p_opened) ImGui::InvisibleButton("##dummy", size); if (ImGui::IsItemActive() && ImGui::IsMouseDragging()) { offset.x += ImGui::GetIO().MouseDelta.x; offset.y += ImGui::GetIO().MouseDelta.y; } ImGui::GetWindowDrawList()->AddRectFilled(pos, ImVec2(pos.x+size.x,pos.y+size.y), ImColor(90,90,120,255)); - ImGui::GetWindowDrawList()->AddText(ImGui::GetWindowFont(), ImGui::GetWindowFontSize()*2.0f, ImVec2(pos.x+offset.x,pos.y+offset.y), ImColor(255,255,255,255), "Line 1 hello\nLine 2 clip me!", NULL, 0.0f, &clip_rect); + ImGui::GetWindowDrawList()->AddText(ImGui::GetFont(), ImGui::GetFontSize()*2.0f, ImVec2(pos.x+offset.x,pos.y+offset.y), ImColor(255,255,255,255), "Line 1 hello\nLine 2 clip me!", NULL, 0.0f, &clip_rect); ImGui::TreePop(); } } From 37d50dccf92543fd6f042fa7127ef6f6ff05137f Mon Sep 17 00:00:00 2001 From: ocornut Date: Mon, 21 Mar 2016 22:30:32 +0100 Subject: [PATCH 15/19] Added GetFontTexUvWhitePixel() helper. --- imgui.cpp | 5 +++++ imgui.h | 1 + 2 files changed, 6 insertions(+) diff --git a/imgui.cpp b/imgui.cpp index 7593bd47..5bfa19d5 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -4838,6 +4838,11 @@ float ImGui::GetFontSize() return GImGui->FontSize; } +ImVec2 ImGui::GetFontTexUvWhitePixel() +{ + return GImGui->FontTexUvWhitePixel; +} + void ImGui::SetWindowFontScale(float scale) { ImGuiState& g = *GImGui; diff --git a/imgui.h b/imgui.h index df23e7bd..55f18692 100644 --- a/imgui.h +++ b/imgui.h @@ -171,6 +171,7 @@ namespace ImGui IMGUI_API void PopStyleVar(int count = 1); IMGUI_API ImFont* GetFont(); // get current font IMGUI_API float GetFontSize(); // get current font size (= height in pixels) of current font with current scale applied + IMGUI_API ImVec2 GetFontTexUvWhitePixel(); // get UV coordinate for a while pixel, useful to draw custom shapes via the ImDrawList API IMGUI_API ImU32 GetColorU32(ImGuiCol idx, float alpha_mul = 1.0f); // retrieve given style color with style alpha applied and optional extra alpha multiplier IMGUI_API ImU32 GetColorU32(const ImVec4& col); // retrieve given color with style alpha applied From b495a52fc0267a852e0eb1f74f48b5d603679704 Mon Sep 17 00:00:00 2001 From: ocornut Date: Mon, 21 Mar 2016 22:43:53 +0100 Subject: [PATCH 16/19] ImDrawList: Allow AddText(ImFont* font, float font_size, ...) to take NULL/0.0f as default --- imgui_draw.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/imgui_draw.cpp b/imgui_draw.cpp index a401b771..5faf91a2 100644 --- a/imgui_draw.cpp +++ b/imgui_draw.cpp @@ -874,6 +874,13 @@ void ImDrawList::AddText(const ImFont* font, float font_size, const ImVec2& pos, if (text_begin == text_end) return; + // Note: This is one of the few instance of breaking the encapsulation of ImDrawList, as we pull this from ImGui state, but it is just SO useful. + // Might just move Font/FontSize to ImDrawList? + if (font == NULL) + font = GImGui->Font; + if (font_size == 0.0f) + font_size = GImGui->FontSize; + IM_ASSERT(font->ContainerAtlas->TexID == _TextureIdStack.back()); // Use high-level ImGui::PushFont() or low-level ImDrawList::PushTextureId() to change font. // reserve vertices for worse case (over-reserving is useful and easily amortized) @@ -906,12 +913,8 @@ void ImDrawList::AddText(const ImFont* font, float font_size, const ImVec2& pos, _VtxCurrentIdx = (unsigned int)VtxBuffer.Size; } -// [Uses global ImGui state] This is one of the few function breaking the encapsulation of ImDrawLst, but it is just so useful. void ImDrawList::AddText(const ImVec2& pos, ImU32 col, const char* text_begin, const char* text_end) { - if ((col >> 24) == 0) - return; - AddText(GImGui->Font, GImGui->FontSize, pos, col, text_begin, text_end); } From 9260d46c2cc742d098726d3fea9d839d03460a4d Mon Sep 17 00:00:00 2001 From: ocornut Date: Mon, 21 Mar 2016 22:51:51 +0100 Subject: [PATCH 17/19] Comments --- imgui_draw.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/imgui_draw.cpp b/imgui_draw.cpp index 5faf91a2..08057b57 100644 --- a/imgui_draw.cpp +++ b/imgui_draw.cpp @@ -1995,10 +1995,10 @@ void ImFont::RenderText(float size, ImVec2 pos, ImU32 col, const ImVec4& clip_re { char_width = glyph->XAdvance * scale; - // Clipping on Y is more likely + // Arbitrarily assume that both space and tabs are empty glyphs as an optimization if (c != ' ' && c != '\t') { - // We don't do a second finer clipping test on the Y axis (TODO: do some measurement see if it is worth it, probably not) + // We don't do a second finer clipping test on the Y axis as we've already skipped anything before clip_rect.y and exit once we pass clip_rect.w float y1 = (float)(y + glyph->Y0 * scale); float y2 = (float)(y + glyph->Y1 * scale); @@ -2042,8 +2042,8 @@ void ImFont::RenderText(float size, ImVec2 pos, ImU32 col, const ImVec4& clip_re } } - // NB: we are not calling PrimRectUV() here because non-inlined causes too much overhead in a debug build. - // inlined: + // We are NOT calling PrimRectUV() here because non-inlined causes too much overhead in a debug build. + // Inlined here: { idx_write[0] = (ImDrawIdx)(vtx_current_idx); idx_write[1] = (ImDrawIdx)(vtx_current_idx+1); idx_write[2] = (ImDrawIdx)(vtx_current_idx+2); idx_write[3] = (ImDrawIdx)(vtx_current_idx); idx_write[4] = (ImDrawIdx)(vtx_current_idx+2); idx_write[5] = (ImDrawIdx)(vtx_current_idx+3); From 5bed7144fe5517c570162049b6b0ec935436931a Mon Sep 17 00:00:00 2001 From: ocornut Date: Tue, 22 Mar 2016 20:10:06 +0100 Subject: [PATCH 18/19] ImDrawList: Added AddTriangle() function --- imgui.h | 1 + imgui_demo.cpp | 2 ++ imgui_draw.cpp | 11 +++++++++++ 3 files changed, 14 insertions(+) diff --git a/imgui.h b/imgui.h index 55f18692..77ad8e07 100644 --- a/imgui.h +++ b/imgui.h @@ -1130,6 +1130,7 @@ struct ImDrawList IMGUI_API void AddRect(const ImVec2& a, const ImVec2& b, ImU32 col, float rounding = 0.0f, int rounding_corners = 0x0F, float thickness = 1.0f); // a: upper-left, b: lower-right IMGUI_API void AddRectFilled(const ImVec2& a, const ImVec2& b, ImU32 col, float rounding = 0.0f, int rounding_corners = 0x0F); // a: upper-left, b: lower-right IMGUI_API void AddRectFilledMultiColor(const ImVec2& a, const ImVec2& b, ImU32 col_upr_left, ImU32 col_upr_right, ImU32 col_bot_right, ImU32 col_bot_left); + IMGUI_API void AddTriangle(const ImVec2& a, const ImVec2& b, const ImVec2& c, ImU32 col, float thickness = 1.0f); IMGUI_API void AddTriangleFilled(const ImVec2& a, const ImVec2& b, const ImVec2& c, ImU32 col); IMGUI_API void AddCircle(const ImVec2& centre, float radius, ImU32 col, int num_segments = 12, float thickness = 1.0f); IMGUI_API void AddCircleFilled(const ImVec2& centre, float radius, ImU32 col, int num_segments = 12); diff --git a/imgui_demo.cpp b/imgui_demo.cpp index 532a10c2..a69374de 100644 --- a/imgui_demo.cpp +++ b/imgui_demo.cpp @@ -1810,6 +1810,7 @@ static void ShowExampleAppCustomRendering(bool* opened) draw_list->AddCircle(ImVec2(x+sz*0.5f, y+sz*0.5f), sz*0.5f, col32, 20, thickness); x += sz+spacing; draw_list->AddRect(ImVec2(x, y), ImVec2(x+sz, y+sz), col32, 0.0f, ~0, thickness); x += sz+spacing; draw_list->AddRect(ImVec2(x, y), ImVec2(x+sz, y+sz), col32, 10.0f, ~0, thickness); x += sz+spacing; + draw_list->AddTriangle(ImVec2(x+sz*0.5f, y), ImVec2(x+sz,y+sz-0.5f), ImVec2(x,y+sz-0.5f), col32, thickness); x += sz+spacing; draw_list->AddLine(ImVec2(x, y), ImVec2(x+sz, y ), col32, thickness); x += sz+spacing; draw_list->AddLine(ImVec2(x, y), ImVec2(x+sz, y+sz), col32, thickness); x += sz+spacing; draw_list->AddLine(ImVec2(x, y), ImVec2(x, y+sz), col32, thickness); x += spacing; @@ -1820,6 +1821,7 @@ static void ShowExampleAppCustomRendering(bool* opened) draw_list->AddCircleFilled(ImVec2(x+sz*0.5f, y+sz*0.5f), sz*0.5f, col32, 32); x += sz+spacing; draw_list->AddRectFilled(ImVec2(x, y), ImVec2(x+sz, y+sz), col32); x += sz+spacing; draw_list->AddRectFilled(ImVec2(x, y), ImVec2(x+sz, y+sz), col32, 10.0f); x += sz+spacing; + draw_list->AddTriangleFilled(ImVec2(x+sz*0.5f, y), ImVec2(x+sz,y+sz-0.5f), ImVec2(x,y+sz-0.5f), col32); x += sz+spacing; draw_list->AddRectFilledMultiColor(ImVec2(x, y), ImVec2(x+sz, y+sz), ImColor(0,0,0), ImColor(255,0,0), ImColor(255,255,0), ImColor(0,255,0)); ImGui::Dummy(ImVec2((sz+spacing)*8, (sz+spacing)*3)); } diff --git a/imgui_draw.cpp b/imgui_draw.cpp index 08057b57..b82327c0 100644 --- a/imgui_draw.cpp +++ b/imgui_draw.cpp @@ -823,6 +823,17 @@ void ImDrawList::AddRectFilledMultiColor(const ImVec2& a, const ImVec2& c, ImU32 PrimWriteVtx(ImVec2(a.x, c.y), uv, col_bot_left); } +void ImDrawList::AddTriangle(const ImVec2& a, const ImVec2& b, const ImVec2& c, ImU32 col, float thickness) +{ + if ((col >> 24) == 0) + return; + + PathLineTo(a); + PathLineTo(b); + PathLineTo(c); + PathStroke(col, true, thickness); +} + void ImDrawList::AddTriangleFilled(const ImVec2& a, const ImVec2& b, const ImVec2& c, ImU32 col) { if ((col >> 24) == 0) From 367c53967f859bc0473ab76a3e156f3532b9300f Mon Sep 17 00:00:00 2001 From: ocornut Date: Tue, 22 Mar 2016 21:17:24 +0100 Subject: [PATCH 19/19] Metrics: inspect individual triangles in drawcall --- imgui.cpp | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 5bfa19d5..5e047819 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -9265,10 +9265,14 @@ void ImGui::ShowMetricsWindow(bool* opened) { ImGui::SameLine(); ImGui::TextColored(ImColor(255,100,100), "CURRENTLY APPENDING"); // Can't display stats for active draw list! (we don't have the data double-buffered) + if (node_opened) ImGui::TreePop(); + return; } if (!node_opened) return; + ImDrawList* overlay_draw_list = &GImGui->OverlayDrawList; // Render additional visuals into the top-most draw list + overlay_draw_list->PushClipRectFullScreen(); int elem_offset = 0; for (const ImDrawCmd* pcmd = draw_list->CmdBuffer.begin(); pcmd < draw_list->CmdBuffer.end(); elem_offset += pcmd->ElemCount, pcmd++) { @@ -9277,7 +9281,7 @@ void ImGui::ShowMetricsWindow(bool* opened) ImGui::BulletText("Callback %p, user_data %p", pcmd->UserCallback, pcmd->UserCallbackData); continue; } - ImGui::BulletText("Draw %-4d %s vtx, tex = %p, clip_rect = (%.0f,%.0f)..(%.0f,%.0f)", pcmd->ElemCount, draw_list->IdxBuffer.Size > 0 ? "indexed" : "non-indexed", pcmd->TextureId, pcmd->ClipRect.x, pcmd->ClipRect.y, pcmd->ClipRect.z, pcmd->ClipRect.w); + bool draw_opened = ImGui::TreeNode((void*)(pcmd - draw_list->CmdBuffer.begin()), "Draw %-4d %s vtx, tex = %p, clip_rect = (%.0f,%.0f)..(%.0f,%.0f)", pcmd->ElemCount, draw_list->IdxBuffer.Size > 0 ? "indexed" : "non-indexed", pcmd->TextureId, pcmd->ClipRect.x, pcmd->ClipRect.y, pcmd->ClipRect.z, pcmd->ClipRect.w); if (show_clip_rects && ImGui::IsItemHovered()) { ImRect clip_rect = pcmd->ClipRect; @@ -9285,12 +9289,28 @@ void ImGui::ShowMetricsWindow(bool* opened) ImDrawIdx* idx_buffer = (draw_list->IdxBuffer.Size > 0) ? draw_list->IdxBuffer.Data : NULL; for (int i = elem_offset; i < elem_offset + (int)pcmd->ElemCount; i++) vtxs_rect.Add(draw_list->VtxBuffer[idx_buffer ? idx_buffer[i] : i].pos); - GImGui->OverlayDrawList.PushClipRectFullScreen(); - clip_rect.Round(); GImGui->OverlayDrawList.AddRect(clip_rect.Min, clip_rect.Max, ImColor(255,255,0)); - vtxs_rect.Round(); GImGui->OverlayDrawList.AddRect(vtxs_rect.Min, vtxs_rect.Max, ImColor(255,0,255)); - GImGui->OverlayDrawList.PopClipRect(); + clip_rect.Round(); overlay_draw_list->AddRect(clip_rect.Min, clip_rect.Max, ImColor(255,255,0)); + vtxs_rect.Round(); overlay_draw_list->AddRect(vtxs_rect.Min, vtxs_rect.Max, ImColor(255,0,255)); } + if (!draw_opened) + continue; + for (int i = elem_offset; i+2 < elem_offset + (int)pcmd->ElemCount; i += 3) + { + ImVec2 triangles_pos[3]; + char buf[300], *buf_p = buf; + for (int n = 0; n < 3; n++) + { + ImDrawVert& v = draw_list->VtxBuffer[(draw_list->IdxBuffer.Size > 0) ? draw_list->IdxBuffer.Data[i+n] : i+n]; + triangles_pos[n] = v.pos; + buf_p += sprintf(buf_p, "vtx %04d { pos = (%8.2f,%8.2f), uv = (%.6f,%.6f), col = %08X }\n", i+n, v.pos.x, v.pos.y, v.uv.x, v.uv.y, v.col); + } + ImGui::Selectable(buf, false); + if (ImGui::IsItemHovered()) + overlay_draw_list->AddPolyline(triangles_pos, 3, ImColor(255,255,0), true, 1.0f, false); // Add triangle without AA, more readable for large-thin triangle + } + ImGui::TreePop(); } + overlay_draw_list->PopClipRect(); ImGui::TreePop(); }