diff --git a/docs/FAQ.md b/docs/FAQ.md index 6dfdb436..6430f678 100644 --- a/docs/FAQ.md +++ b/docs/FAQ.md @@ -13,7 +13,7 @@ or view this file with any Markdown viewer. :---------------------------------------------------------- | | [Where is the documentation?](#q-where-is-the-documentation) | | [Which version should I get?](#q-which-version-should-i-get) | -| [Why the names "Dear ImGui" vs "ImGui"?](#q-why-names-dear-imgui-vs-imgui) | +| [Why the names "Dear ImGui" vs "ImGui"?](#q-why-the-names-dear-imgui-vs-imgui) | | **Q&A: Concerns** | | [Who uses Dear ImGui?](#q-who-uses-dear-imgui) | | [Can you create elaborate/serious tools with Dear ImGui?](#q-can-you-create-elaborateserious-tools-with-dear-imgui) | @@ -29,7 +29,7 @@ or view this file with any Markdown viewer. | [How can I display an image? What is ImTextureID, how does it work?](#q-how-can-i-display-an-image-what-is-imtextureid-how-does-it-work)| | [How can I use my own math types instead of ImVec2/ImVec4?](#q-how-can-i-use-my-own-math-types-instead-of-imvec2imvec4) | | [How can I interact with standard C++ types (such as std::string and std::vector)?](#q-how-can-i-interact-with-standard-c-types-such-as-stdstring-and-stdvector) | -| [How can I use low-level drawing facilities? (using ImDrawList API)](#q-how-can-i-use-low-level-drawing-facilities-using-imdrawlist-api) | +| [How can I display custom shapes? (using low-level ImDrawList API)](#q-how-can-i-display-custom-shapes-using-low-level-imdrawlist-api) | | **Q&A: Fonts, Text** | | [How can I load a different font than the default?](#q-how-can-i-load-a-different-font-than-the-default) | | [How can I easily use icons in my application?](#q-how-can-i-easily-use-icons-in-my-application) | @@ -386,13 +386,37 @@ provide similar or better string helpers. --- -### Q: How can I use low-level drawing facilities? (using ImDrawList API) -- You can create a dummy window. Call Begin() with the NoBackground | NoDecoration | NoSavedSettings | NoInputs flags. -(The `ImGuiWindowFlags_NoDecoration` flag itself is a shortcut for NoTitleBar | NoResize | NoScrollbar | NoCollapse) -Then you can retrieve the ImDrawList* via GetWindowDrawList() and draw to it in any way you like. -- You can call `ImGui::GetBackgroundDrawList()` or `ImGui::GetForegroundDrawList()` and use those draw list to display -contents behind or over every other imgui windows (one bg/fg drawlist per viewport). -- You can create your own ImDrawList instance. You'll need to initialize them with ImGui::GetDrawListSharedData(), or create your own instancing ImDrawListSharedData, and then call your rendered code with your own ImDrawList or ImDrawData data. +### Q: How can I display custom shapes? (using low-level ImDrawList API) + +- You can use the low-level `ImDrawList` api to render shapes within a window. + +``` +ImGui::Begin("My shapes"); + +ImDrawList* draw_list = ImGui::GetWindowDrawList(); + +// Get the current ImGui cursor position +ImVec2 p = ImGui::GetCursorScreenPos(); + +// Draw a red circle +draw_list->AddCircleFilled(ImVec2(p.x + 50, p.y + 50), 30.0f, IM_COL32(255, 0, 0, 255), 16); + +// Draw a 3 pixel thick yellow line +draw_list->AddLine(ImVec2(p.x, p.y), ImVec2(p.x + 100.0f, p.y + 100.0f), IM_COL32(255, 255, 0, 255), 3.0f); + +// Advance the ImGui cursor to claim space in the window (otherwise the window will appears small and needs to be resized) +ImGui::Dummy(ImVec2(200, 200)); + +ImGui::End(); +``` +![ImDrawList usage](https://raw.githubusercontent.com/wiki/ocornut/imgui/tutorials/CustomRendering01.png) + +- Refer to "Demo > Examples > Custom Rendering" in the demo window and read the code of `ShowExampleAppCustomRendering()` in `imgui_demo.cpp` from more examples. +- To generate colors: you can use the macro `IM_COL32(255,255,255,255)` to generate them at compile time, or use `ImGui::GetColorU32(IM_COL32(255,255,255,255))` or `ImGui::GetColorU32(ImVec4(1.0f,1.0f,1.0f,1.0f))` to generate a color that is multiplied by the current value of `style.Alpha`. +- Math operators: if you have setup `IM_VEC2_CLASS_EXTRA` in `imconfig.h` to bind your own math types, you can use your own math types and their natural operators instead of ImVec2. ImVec2 by default doesn't export any math operators in the public API. You may use `#define IMGUI_DEFINE_MATH_OPERATORS` `#include "imgui_internal.h"` to use the internally defined math operators, but instead prefer using your own math library and set it up in `imconfig.h`. +- You can use `ImGui::GetBackgroundDrawList()` or `ImGui::GetForegroundDrawList()` to access draw lists which will be displayed behind and over every other dear imgui windows (one bg/fg drawlist per viewport). This is very convenient if you need to quickly display something on the screen that is not associated to a dear imgui window. +- You can also create your own dummy window and draw inside it. Call Begin() with the NoBackground | NoDecoration | NoSavedSettings | NoInputs flags (The `ImGuiWindowFlags_NoDecoration` flag itself is a shortcut for NoTitleBar | NoResize | NoScrollbar | NoCollapse). Then you can retrieve the ImDrawList* via GetWindowDrawList() and draw to it in any way you like. +- You can create your own ImDrawList instance. You'll need to initialize them with `ImGui::GetDrawListSharedData()`, or create your own instancing ImDrawListSharedData, and then call your renderer function with your own ImDrawList or ImDrawData data. ##### [Return to Index](#index) diff --git a/docs/README.md b/docs/README.md index aaca0316..a99ffe67 100644 --- a/docs/README.md +++ b/docs/README.md @@ -184,7 +184,7 @@ Most common questions will be answered by the [Frequently Asked Questions (FAQ)] - "How can I display an image? What is ImTextureID, how does it work?" - "How can I use my own math types instead of ImVec2/ImVec4?" - "How can I interact with standard C++ types (such as std::string and std::vector)?" -- "How can I use low-level drawing facilities? (using ImDrawList API)" +- "How can I display custom shapes? (using low-level ImDrawList API)" **Fonts, Text** - "How can I load a different font than the default?" @@ -247,7 +247,7 @@ Ongoing Dear ImGui development is financially supported by users and private spo - Media Molecule, Mobigame, Aras Pranckevičius, Greggman, DotEmu, Nadeo, Supercell, Runner, Aiden Koss, Kylotonn. *Salty caramel supporters* -- Remedy Entertainment, Recognition Robotics, ikrima, Geoffrey Evans, Mercury Labs, Singularity Demo Group, Lionel Landwerlin, Ron Gilbert, Brandon Townsend, G3DVu, Cort Stratton, drudru, Harfang 3D, Jeff Roberts, Rainway inc, Ondra Voves, Mesh Consultants, Unit 2 Games, Neil Bickford, Bill Six, Graham Manders. +- Remedy Entertainment, Next Level Games, Recognition Robotics, ikrima, Geoffrey Evans, Mercury Labs, Singularity Demo Group, Lionel Landwerlin, Ron Gilbert, Brandon Townsend, G3DVu, Cort Stratton, drudru, Harfang 3D, Jeff Roberts, Rainway inc, Ondra Voves, Mesh Consultants, Unit 2 Games, Neil Bickford, Bill Six, Graham Manders. *Caramel supporters* - Jerome Lanquetot, Daniel Collin, Ctrl Alt Ninja, Neil Henning, Neil Blakey-Milner, Aleksei, NeiloGD, Eric, Game Atelier, Vincent Hamm, Morten Skaaning, Colin Riley, Sergio Gonzales, Andrew Berridge, Roy Eltham, Game Preservation Society, Josh Faust, Martin Donlon, Codecat, Doug McNabb, Emmanuel Julien, Guillaume Chereau, Jeffrey Slutter, Jeremiah Deckard, r-lyeh, Nekith, Joshua Fisher, Malte Hoffmann, Mustafa Karaalioglu, Merlyn Morgan-Graham, Per Vognsen, Fabian Giesen, Jan Staubach, Matt Hargett, John Shearer, Jesse Chounard, kingcoopa, Jonas Bernemann, Johan Andersson, Michael Labbe, Tomasz Golebiowski, Louis Schnellbach, Jimmy Andrews, Bojan Endrovski, Robin Berg Pettersen, Rachel Crawford, Andrew Johnson, Sean Hunter, Jordan Mellow, Nefarius Software Solutions, Laura Wieme, Robert Nix, Mick Honey, Steven Kah Hien Wong, Bartosz Bielecki, Oscar Penas, A M, Liam Moynihan, Artometa, Mark Lee, Dimitri Diakopoulos, Pete Goodwin, Johnathan Roatch, nyu lea, Oswald Hurlem, Semyon Smelyanskiy, Le Bach, Jeong MyeongSoo, Chris Matthews, Astrofra, Frederik De Bleser, Anticrisis, Matt Reyer. diff --git a/docs/TODO.txt b/docs/TODO.txt index 7ca24ca8..b9fcecee 100644 --- a/docs/TODO.txt +++ b/docs/TODO.txt @@ -363,6 +363,7 @@ It's mostly a bunch of personal notes, probably incomplete. Feel free to query i - demo: add vertical separator demo - demo: add virtual scrolling example? - demo: demonstrate Plot offset + - demo: window size constraint: square demo is broken when resizing from edges (#1975), would need to rework the callback system to solve this - examples: window minimize, maximize (#583) - examples: provide a zero frame-rate/idle example. - examples: apple: example_apple should be using modern GL3. diff --git a/examples/imgui_impl_glfw.cpp b/examples/imgui_impl_glfw.cpp index a9e72c6c..dbf1188d 100644 --- a/examples/imgui_impl_glfw.cpp +++ b/examples/imgui_impl_glfw.cpp @@ -61,7 +61,7 @@ static GLFWwindow* g_Window = NULL; // Main window static GlfwClientApi g_ClientApi = GlfwClientApi_Unknown; static double g_Time = 0.0; static bool g_MouseJustPressed[5] = { false, false, false, false, false }; -static GLFWcursor* g_MouseCursors[ImGuiMouseCursor_COUNT] = { 0 }; +static GLFWcursor* g_MouseCursors[ImGuiMouseCursor_COUNT] = {}; // Chain GLFW callbacks: our callbacks will call the user's previously installed callbacks, if any. static GLFWmousebuttonfun g_PrevUserCallbackMousebutton = NULL; diff --git a/examples/imgui_impl_osx.mm b/examples/imgui_impl_osx.mm index a491616a..4f4e9753 100644 --- a/examples/imgui_impl_osx.mm +++ b/examples/imgui_impl_osx.mm @@ -24,7 +24,7 @@ // Data static CFAbsoluteTime g_Time = 0.0; -static NSCursor* g_MouseCursors[ImGuiMouseCursor_COUNT] = { 0 }; +static NSCursor* g_MouseCursors[ImGuiMouseCursor_COUNT] = {}; static bool g_MouseCursorHidden = false; // Undocumented methods for creating cursors. diff --git a/examples/imgui_impl_sdl.cpp b/examples/imgui_impl_sdl.cpp index 42677581..06d27b21 100644 --- a/examples/imgui_impl_sdl.cpp +++ b/examples/imgui_impl_sdl.cpp @@ -57,7 +57,7 @@ static SDL_Window* g_Window = NULL; static Uint64 g_Time = 0; static bool g_MousePressed[3] = { false, false, false }; -static SDL_Cursor* g_MouseCursors[ImGuiMouseCursor_COUNT] = { 0 }; +static SDL_Cursor* g_MouseCursors[ImGuiMouseCursor_COUNT] = {}; static char* g_ClipboardTextData = NULL; static const char* ImGui_ImplSDL2_GetClipboardText(void*) diff --git a/imgui.cpp b/imgui.cpp index 597e681c..700138f4 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -735,7 +735,7 @@ CODE Q: How can I use my own math types instead of ImVec2/ImVec4? Q: How can I interact with standard C++ types (such as std::string and std::vector)? - Q: How can I use low-level drawing facilities? (using ImDrawList API) + Q: How can I display custom shapes? (using low-level ImDrawList API) >> See https://www.dearimgui.org/faq Q&A: Fonts, Text @@ -5522,7 +5522,7 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags) // Handle manual resize: Resize Grips, Borders, Gamepad int border_held = -1; - ImU32 resize_grip_col[4] = { 0 }; + ImU32 resize_grip_col[4] = {}; const int resize_grip_count = g.IO.ConfigWindowsResizeFromEdges ? 2 : 1; // 4 const float resize_grip_draw_size = (float)(int)ImMax(g.FontSize * 1.35f, window->WindowRounding + 1.0f + g.FontSize * 0.2f); if (!window->Collapsed) diff --git a/imgui_demo.cpp b/imgui_demo.cpp index 0eeec980..8e765863 100644 --- a/imgui_demo.cpp +++ b/imgui_demo.cpp @@ -923,7 +923,7 @@ static void ShowDemoWindowWidgets() if (ImGui::TreeNode("In columns")) { ImGui::Columns(3, NULL, false); - static bool selected[16] = { 0 }; + static bool selected[16] = {}; for (int i = 0; i < 16; i++) { char label[32]; sprintf(label, "Item %d", i); @@ -1075,7 +1075,7 @@ static void ShowDemoWindowWidgets() // Create a dummy array of contiguous float values to plot // Tip: If your float aren't contiguous but part of a structure, you can pass a pointer to your first float and the sizeof() of your structure in the Stride parameter. - static float values[90] = { 0 }; + static float values[90] = {}; static int values_offset = 0; static double refresh_time = 0.0; if (!animate || refresh_time == 0.0) @@ -1176,7 +1176,7 @@ static void ShowDemoWindowWidgets() // Generate a dummy default palette. The palette will persist and can be edited. static bool saved_palette_init = true; - static ImVec4 saved_palette[32] = { }; + static ImVec4 saved_palette[32] = {}; if (saved_palette_init) { for (int n = 0; n < IM_ARRAYSIZE(saved_palette); n++)