Merge branch 'master' into 2016-02-colorpicker

This commit is contained in:
ocornut 2016-03-23 10:50:37 +01:00
commit baabe3b62c
9 changed files with 194 additions and 140 deletions

View File

@ -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) // - 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) 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 // Backup GL state
GLint last_program; glGetIntegerv(GL_CURRENT_PROGRAM, &last_program); GLint last_program; glGetIntegerv(GL_CURRENT_PROGRAM, &last_program);
GLint last_texture; glGetIntegerv(GL_TEXTURE_BINDING_2D, &last_texture); 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); glEnable(GL_SCISSOR_TEST);
glActiveTexture(GL_TEXTURE0); 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 // Setup viewport, orthographic projection matrix
glViewport(0, 0, (GLsizei)fb_width, (GLsizei)fb_height); glViewport(0, 0, (GLsizei)fb_width, (GLsizei)fb_height);
const float ortho_projection[4][4] = const float ortho_projection[4][4] =

View File

@ -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) // - 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) 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! // 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. // 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); 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); glEnable(GL_TEXTURE_2D);
//glUseProgram(0); // You may want this if using this code in an OpenGL 3+ context //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 // Setup viewport, orthographic projection matrix
glViewport(0, 0, (GLsizei)fb_width, (GLsizei)fb_height); glViewport(0, 0, (GLsizei)fb_width, (GLsizei)fb_height);
glMatrixMode(GL_PROJECTION); glMatrixMode(GL_PROJECTION);

View File

@ -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) // - 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) 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 // Backup GL state
GLint last_program; glGetIntegerv(GL_CURRENT_PROGRAM, &last_program); GLint last_program; glGetIntegerv(GL_CURRENT_PROGRAM, &last_program);
GLint last_texture; glGetIntegerv(GL_TEXTURE_BINDING_2D, &last_texture); 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); glEnable(GL_SCISSOR_TEST);
glActiveTexture(GL_TEXTURE0); 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 // Setup orthographic projection matrix
glViewport(0, 0, (GLsizei)fb_width, (GLsizei)fb_height); glViewport(0, 0, (GLsizei)fb_width, (GLsizei)fb_height);
const float ortho_projection[4][4] = const float ortho_projection[4][4] =

View File

@ -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) // - 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) 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! // 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. // 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); 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); glEnable(GL_TEXTURE_2D);
//glUseProgram(0); // You may want this if using this code in an OpenGL 3+ context //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 // Setup viewport, orthographic projection matrix
glViewport(0, 0, (GLsizei)fb_width, (GLsizei)fb_height); glViewport(0, 0, (GLsizei)fb_width, (GLsizei)fb_height);
glMatrixMode(GL_PROJECTION); glMatrixMode(GL_PROJECTION);

140
imgui.cpp
View File

@ -19,7 +19,7 @@
- FREQUENTLY ASKED QUESTIONS (FAQ), TIPS - FREQUENTLY ASKED QUESTIONS (FAQ), TIPS
- How can I help? - How can I help?
- How do I update to a newer version of ImGui? - 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 the text or lines are blurry..
- I integrated ImGui in my engine and some elements are disappearing when I move windows around.. - 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? - How can I load a different font than the default?
@ -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. 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. 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/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/02/21 (1.48) - removed ColorEditMode() and ImGuiColorEditMode in favor of ImGuiColorEditFlags and parameters to ColorEdit*() functions - 2016/02/21 (1.48) - removed ColorEditMode() and ImGuiColorEditMode in favor of ImGuiColorEditFlags and parameters to ColorEdit*() functions
- replaced ColorEdit4() third parameter 'bool show_alpha=true' to 'ImGuiColorEditFlags flags=0x01' where ImGuiColorEditFlags_Alpha=0x01 for dodgy compatibility - replaced ColorEdit4() third parameter 'bool show_alpha=true' to 'ImGuiColorEditFlags flags=0x01' where ImGuiColorEditFlags_Alpha=0x01 for dodgy compatibility
@ -426,8 +427,8 @@
- window: get size/pos helpers given names (see discussion in #249) - window: get size/pos helpers given names (see discussion in #249)
- window: a collapsed window can be stuck behind the main menu bar? - 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: 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/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). - 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 !- 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) - splitter/separator: formalize the splitter idiom into an official api (we want to handle n-way split) (#319)
@ -439,7 +440,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() 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? - 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: 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: 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: 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) - input text multi-line: line numbers? status bar? (follow up on #200)
@ -447,6 +448,7 @@
- input number: holding [-]/[+] buttons could increase the step speed non-linearly (or user-controlled) - 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: use mouse wheel to step up/down
- input number: applying arithmetics ops (+,-,*,/) messes up with text edit undo stack. - input number: applying arithmetics ops (+,-,*,/) messes up with text edit undo stack.
- button: provide a button that looks framed.
- text: proper alignment options - text: proper alignment options
- image/image button: misalignment on padded/bordered button? - 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? - 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?
@ -454,6 +456,7 @@
- layout: horizontal flow until no space left (#404) - layout: horizontal flow until no space left (#404)
- layout: more generic alignment state (left/right/centered) for single items? - 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: 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: 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: add a conditional parameter to SetColumnOffset() (#513, #125)
- columns: separator function or parameter that works within the column (currently Separator() bypass all columns) (#125) - columns: separator function or parameter that works within the column (currently Separator() bypass all columns) (#125)
@ -471,9 +474,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/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: add variant using global identifier similar to Begin/End (#402)
- popups: border options. richer api like BeginChild() perhaps? (#197) - 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: local shortcuts, global shortcuts (#456, #126)
- menus: icons - menus: icons
- menus: menubars: some sort of priority / effect of main menu-bar on desktop size? - 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. - statusbar: add a per-window status bar helper similar to what menubar does.
- tabs (#261, #351) - tabs (#261, #351)
- separator: separator on the initial position of a window is not visible (cursorpos.y <= clippos.y) - separator: separator on the initial position of a window is not visible (cursorpos.y <= clippos.y)
@ -497,6 +502,7 @@
- text edit: flag to disable live update of the user buffer. - 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: field resize behavior - field could stretch when being edited? hover tooltip shows more text?
- tree node / optimization: avoid formatting when clipped. - 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: 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: 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) - tree node / selectable render mismatch which is visible if you use them both next to each other (e.g. cf. property viewer)
@ -527,6 +533,7 @@
- input: support track pad style scrolling & slider edit. - 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: 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: 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: 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. - style editor: color child window height expressed in multiple of line height.
- remote: make a system like RemoteImGui first-class citizen/project (#75) - remote: make a system like RemoteImGui first-class citizen/project (#75)
@ -586,7 +593,6 @@
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
static void LogRenderedText(const ImVec2& ref_pos, const char* text, const char* text_end = NULL); 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 void PushMultiItemsWidths(int components, float w_full = 0.0f);
static float GetDraggedColumnOffset(int column_index); static float GetDraggedColumnOffset(int column_index);
@ -2504,8 +2510,7 @@ void ImGui::Render()
} }
} }
// Find the optional ## from which we stop displaying text. const char* ImGui::FindRenderedTextEnd(const char* text, const char* text_end)
static const char* FindTextDisplayEnd(const char* text, const char* text_end)
{ {
const char* text_display_end = text; const char* text_display_end = text;
if (!text_end) if (!text_end)
@ -2544,7 +2549,7 @@ static void LogRenderedText(const ImVec2& ref_pos, const char* text, const char*
ImGuiWindow* window = ImGui::GetCurrentWindowRead(); ImGuiWindow* window = ImGui::GetCurrentWindowRead();
if (!text_end) if (!text_end)
text_end = FindTextDisplayEnd(text, text_end); text_end = ImGui::FindRenderedTextEnd(text, text_end);
const bool log_new_line = ref_pos.y > window->DC.LogLinePosY+1; const bool log_new_line = ref_pos.y > window->DC.LogLinePosY+1;
window->DC.LogLinePosY = ref_pos.y; window->DC.LogLinePosY = ref_pos.y;
@ -2598,7 +2603,7 @@ void ImGui::RenderText(ImVec2 pos, const char* text, const char* text_end, bool
const char* text_display_end; const char* text_display_end;
if (hide_text_after_hash) if (hide_text_after_hash)
{ {
text_display_end = FindTextDisplayEnd(text, text_end); text_display_end = FindRenderedTextEnd(text, text_end);
} }
else else
{ {
@ -2637,7 +2642,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) 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 // Hide anything after a '##' string
const char* text_display_end = FindTextDisplayEnd(text, text_end); const char* text_display_end = FindRenderedTextEnd(text, text_end);
const int text_len = (int)(text_display_end - text); const int text_len = (int)(text_display_end - text);
if (text_len == 0) if (text_len == 0)
return; return;
@ -2744,7 +2749,7 @@ ImVec2 ImGui::CalcTextSize(const char* text, const char* text_end, bool hide_tex
const char* text_display_end; const char* text_display_end;
if (hide_text_after_double_hash) if (hide_text_after_double_hash)
text_display_end = FindTextDisplayEnd(text, text_end); // Hide anything after a '##' string text_display_end = FindRenderedTextEnd(text, text_end); // Hide anything after a '##' string
else else
text_display_end = text_end; text_display_end = text_end;
@ -2823,13 +2828,13 @@ static ImGuiWindow* FindHoveredWindow(ImVec2 pos, bool excluding_childs)
// Test if mouse cursor is hovering given rectangle // Test if mouse cursor is hovering given rectangle
// NB- Rectangle is clipped by our current clip setting // NB- Rectangle is clipped by our current clip setting
// NB- Expand the rectangle to be generous on imprecise inputs systems (g.Style.TouchExtraPadding) // 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; ImGuiState& g = *GImGui;
ImGuiWindow* window = GetCurrentWindowRead(); ImGuiWindow* window = GetCurrentWindowRead();
// Clip // Clip
ImRect rect_clipped(pos_min, pos_max); ImRect rect_clipped(r_min, r_max);
if (clip) if (clip)
rect_clipped.Clip(window->ClipRect); rect_clipped.Clip(window->ClipRect);
@ -4824,16 +4829,19 @@ ImDrawList* ImGui::GetWindowDrawList()
return window->DrawList; return window->DrawList;
} }
ImFont* ImGui::GetWindowFont() ImFont* ImGui::GetFont()
{ {
ImGuiState& g = *GImGui; return GImGui->Font;
return g.Font;
} }
float ImGui::GetWindowFontSize() float ImGui::GetFontSize()
{ {
ImGuiState& g = *GImGui; return GImGui->FontSize;
return g.FontSize; }
ImVec2 ImGui::GetFontTexUvWhitePixel()
{
return GImGui->FontTexUvWhitePixel;
} }
void ImGui::SetWindowFontScale(float scale) void ImGui::SetWindowFontScale(float scale)
@ -6328,7 +6336,7 @@ bool ImGui::SliderFloatN(const char* label, float* v, int components, float v_mi
} }
ImGui::PopID(); ImGui::PopID();
ImGui::TextUnformatted(label, FindTextDisplayEnd(label)); ImGui::TextUnformatted(label, FindRenderedTextEnd(label));
ImGui::EndGroup(); ImGui::EndGroup();
return value_changed; return value_changed;
@ -6370,7 +6378,7 @@ bool ImGui::SliderIntN(const char* label, int* v, int components, int v_min, int
} }
ImGui::PopID(); ImGui::PopID();
ImGui::TextUnformatted(label, FindTextDisplayEnd(label)); ImGui::TextUnformatted(label, FindRenderedTextEnd(label));
ImGui::EndGroup(); ImGui::EndGroup();
return value_changed; return value_changed;
@ -6414,6 +6422,7 @@ bool ImGui::DragBehavior(const ImRect& frame_bb, ImGuiID id, float* v, float v_s
g.DragLastMouseDelta = ImVec2(0.f, 0.f); g.DragLastMouseDelta = ImVec2(0.f, 0.f);
} }
float v_cur = g.DragCurrentValue;
const ImVec2 mouse_drag_delta = ImGui::GetMouseDragDelta(0, 1.0f); const ImVec2 mouse_drag_delta = ImGui::GetMouseDragDelta(0, 1.0f);
if (fabsf(mouse_drag_delta.x - g.DragLastMouseDelta.x) > 0.0f) if (fabsf(mouse_drag_delta.x - g.DragLastMouseDelta.x) > 0.0f)
{ {
@ -6425,7 +6434,6 @@ bool ImGui::DragBehavior(const ImRect& frame_bb, ImGuiID id, float* v, float v_s
if (g.IO.KeyAlt && g.DragSpeedScaleSlow >= 0.0f) if (g.IO.KeyAlt && g.DragSpeedScaleSlow >= 0.0f)
speed = speed * g.DragSpeedScaleSlow; speed = speed * g.DragSpeedScaleSlow;
float v_cur = g.DragCurrentValue;
float delta = (mouse_drag_delta.x - g.DragLastMouseDelta.x) * speed; float delta = (mouse_drag_delta.x - g.DragLastMouseDelta.x) * speed;
if (fabsf(power - 1.0f) > 0.001f) if (fabsf(power - 1.0f) > 0.001f)
{ {
@ -6447,14 +6455,14 @@ bool ImGui::DragBehavior(const ImRect& frame_bb, ImGuiID id, float* v, float v_s
if (v_min < v_max) if (v_min < v_max)
v_cur = ImClamp(v_cur, v_min, v_max); v_cur = ImClamp(v_cur, v_min, v_max);
g.DragCurrentValue = v_cur; g.DragCurrentValue = v_cur;
}
// Round to user desired precision, then apply // Round to user desired precision, then apply
v_cur = RoundScalar(v_cur, decimal_precision); v_cur = RoundScalar(v_cur, decimal_precision);
if (*v != v_cur) if (*v != v_cur)
{ {
*v = v_cur; *v = v_cur;
value_changed = true; value_changed = true;
}
} }
} }
else else
@ -6550,7 +6558,7 @@ bool ImGui::DragFloatN(const char* label, float* v, int components, float v_spee
} }
ImGui::PopID(); ImGui::PopID();
ImGui::TextUnformatted(label, FindTextDisplayEnd(label)); ImGui::TextUnformatted(label, FindRenderedTextEnd(label));
ImGui::EndGroup(); ImGui::EndGroup();
return value_changed; return value_changed;
@ -6589,7 +6597,7 @@ bool ImGui::DragFloatRange2(const char* label, float* v_current_min, float* v_cu
ImGui::PopItemWidth(); ImGui::PopItemWidth();
ImGui::SameLine(0, g.Style.ItemInnerSpacing.x); ImGui::SameLine(0, g.Style.ItemInnerSpacing.x);
ImGui::TextUnformatted(label, FindTextDisplayEnd(label)); ImGui::TextUnformatted(label, FindRenderedTextEnd(label));
ImGui::EndGroup(); ImGui::EndGroup();
ImGui::PopID(); ImGui::PopID();
@ -6628,7 +6636,7 @@ bool ImGui::DragIntN(const char* label, int* v, int components, float v_speed, i
} }
ImGui::PopID(); ImGui::PopID();
ImGui::TextUnformatted(label, FindTextDisplayEnd(label)); ImGui::TextUnformatted(label, FindRenderedTextEnd(label));
ImGui::EndGroup(); ImGui::EndGroup();
return value_changed; return value_changed;
@ -6667,7 +6675,7 @@ bool ImGui::DragIntRange2(const char* label, int* v_current_min, int* v_current_
ImGui::PopItemWidth(); ImGui::PopItemWidth();
ImGui::SameLine(0, g.Style.ItemInnerSpacing.x); ImGui::SameLine(0, g.Style.ItemInnerSpacing.x);
ImGui::TextUnformatted(label, FindTextDisplayEnd(label)); ImGui::TextUnformatted(label, FindRenderedTextEnd(label));
ImGui::EndGroup(); ImGui::EndGroup();
ImGui::PopID(); ImGui::PopID();
@ -6901,12 +6909,16 @@ bool ImGui::Checkbox(const char* label, bool* v)
bool ImGui::CheckboxFlags(const char* label, unsigned int* flags, unsigned int flags_value) 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); bool pressed = ImGui::Checkbox(label, &v);
if (v) if (pressed)
*flags |= flags_value; {
else if (v)
*flags &= ~flags_value; *flags |= flags_value;
else
*flags &= ~flags_value;
}
return pressed; return pressed;
} }
@ -7887,7 +7899,7 @@ bool ImGui::InputFloatN(const char* label, float* v, int components, int decimal
ImGui::PopID(); ImGui::PopID();
window->DC.CurrentLineTextBaseOffset = ImMax(window->DC.CurrentLineTextBaseOffset, g.Style.FramePadding.y); window->DC.CurrentLineTextBaseOffset = ImMax(window->DC.CurrentLineTextBaseOffset, g.Style.FramePadding.y);
ImGui::TextUnformatted(label, FindTextDisplayEnd(label)); ImGui::TextUnformatted(label, FindRenderedTextEnd(label));
ImGui::EndGroup(); ImGui::EndGroup();
return value_changed; return value_changed;
@ -7930,7 +7942,7 @@ bool ImGui::InputIntN(const char* label, int* v, int components, ImGuiInputTextF
ImGui::PopID(); ImGui::PopID();
window->DC.CurrentLineTextBaseOffset = ImMax(window->DC.CurrentLineTextBaseOffset, g.Style.FramePadding.y); window->DC.CurrentLineTextBaseOffset = ImMax(window->DC.CurrentLineTextBaseOffset, g.Style.FramePadding.y);
ImGui::TextUnformatted(label, FindTextDisplayEnd(label)); ImGui::TextUnformatted(label, FindRenderedTextEnd(label));
ImGui::EndGroup(); ImGui::EndGroup();
return value_changed; return value_changed;
@ -8760,7 +8772,7 @@ bool ImGui::ColorPicker4(const char* label, float col[4], ImGuiColorEditFlags fl
} }
} }
const char* label_display_end = FindTextDisplayEnd(label); const char* label_display_end = FindRenderedTextEnd(label);
if (label != label_display_end) if (label != label_display_end)
{ {
ImGui::SameLine(0, style.ItemInnerSpacing.x); ImGui::SameLine(0, style.ItemInnerSpacing.x);
@ -8956,33 +8968,31 @@ void ImGui::EndGroup()
} }
// Gets back to previous line and continue with horizontal layout // Gets back to previous line and continue with horizontal layout
// local_pos_x == 0 : follow on previous item // pos_x == 0 : follow on previous item
// local_pos_x != 0 : align to specified column // 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 : use default spacing if column_x==0, no spacing if column_x!=0
// spacing_w >= 0 : enforce spacing // 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(); ImGuiWindow* window = GetCurrentWindow();
if (window->SkipItems) if (window->SkipItems)
return; return;
ImGuiState& g = *GImGui; ImGuiState& g = *GImGui;
float x, y; if (pos_x != 0.0f)
if (local_pos_x != 0.0f)
{ {
if (spacing_w < 0.0f) spacing_w = 0.0f; if (spacing_w < 0.0f) spacing_w = 0.0f;
x = window->Pos.x - window->Scroll.x + local_pos_x + spacing_w; window->DC.CursorPos.x = window->Pos.x - window->Scroll.x + pos_x + spacing_w;
y = window->DC.CursorPosPrevLine.y; window->DC.CursorPos.y = window->DC.CursorPosPrevLine.y;
} }
else else
{ {
if (spacing_w < 0.0f) spacing_w = g.Style.ItemSpacing.x; if (spacing_w < 0.0f) spacing_w = g.Style.ItemSpacing.x;
x = window->DC.CursorPosPrevLine.x + spacing_w; window->DC.CursorPos.x = window->DC.CursorPosPrevLine.x + spacing_w;
y = window->DC.CursorPosPrevLine.y; window->DC.CursorPos.y = window->DC.CursorPosPrevLine.y;
} }
window->DC.CurrentLineHeight = window->DC.PrevLineHeight; window->DC.CurrentLineHeight = window->DC.PrevLineHeight;
window->DC.CurrentLineTextBaseOffset = window->DC.PrevLineTextBaseOffset; window->DC.CurrentLineTextBaseOffset = window->DC.PrevLineTextBaseOffset;
window->DC.CursorPos = ImVec2(x, y);
} }
void ImGui::NextColumn() void ImGui::NextColumn()
@ -9422,10 +9432,14 @@ void ImGui::ShowMetricsWindow(bool* opened)
{ {
ImGui::SameLine(); 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) 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) if (!node_opened)
return; return;
ImDrawList* overlay_draw_list = &GImGui->OverlayDrawList; // Render additional visuals into the top-most draw list
overlay_draw_list->PushClipRectFullScreen();
int elem_offset = 0; int elem_offset = 0;
for (const ImDrawCmd* pcmd = draw_list->CmdBuffer.begin(); pcmd < draw_list->CmdBuffer.end(); elem_offset += pcmd->ElemCount, pcmd++) for (const ImDrawCmd* pcmd = draw_list->CmdBuffer.begin(); pcmd < draw_list->CmdBuffer.end(); elem_offset += pcmd->ElemCount, pcmd++)
{ {
@ -9434,7 +9448,7 @@ void ImGui::ShowMetricsWindow(bool* opened)
ImGui::BulletText("Callback %p, user_data %p", pcmd->UserCallback, pcmd->UserCallbackData); ImGui::BulletText("Callback %p, user_data %p", pcmd->UserCallback, pcmd->UserCallbackData);
continue; 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()) if (show_clip_rects && ImGui::IsItemHovered())
{ {
ImRect clip_rect = pcmd->ClipRect; ImRect clip_rect = pcmd->ClipRect;
@ -9442,12 +9456,28 @@ void ImGui::ShowMetricsWindow(bool* opened)
ImDrawIdx* idx_buffer = (draw_list->IdxBuffer.Size > 0) ? draw_list->IdxBuffer.Data : NULL; 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++) 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); vtxs_rect.Add(draw_list->VtxBuffer[idx_buffer ? idx_buffer[i] : i].pos);
GImGui->OverlayDrawList.PushClipRectFullScreen(); clip_rect.Round(); overlay_draw_list->AddRect(clip_rect.Min, clip_rect.Max, ImColor(255,255,0));
clip_rect.Round(); GImGui->OverlayDrawList.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));
vtxs_rect.Round(); GImGui->OverlayDrawList.AddRect(vtxs_rect.Min, vtxs_rect.Max, ImColor(255,0,255));
GImGui->OverlayDrawList.PopClipRect();
} }
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(); ImGui::TreePop();
} }

55
imgui.h
View File

@ -103,9 +103,9 @@ namespace ImGui
// Main // Main
IMGUI_API ImGuiIO& GetIO(); IMGUI_API ImGuiIO& GetIO();
IMGUI_API ImGuiStyle& GetStyle(); 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 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 Shutdown();
IMGUI_API void ShowUserGuide(); // help block IMGUI_API void ShowUserGuide(); // help block
IMGUI_API void ShowStyleEditor(ImGuiStyle* ref = NULL); // style editor block IMGUI_API void ShowStyleEditor(ImGuiStyle* ref = NULL); // style editor block
@ -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 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 float GetWindowContentRegionWidth(); //
IMGUI_API ImDrawList* GetWindowDrawList(); // get rendering command-list if you want to append your own draw primitives 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 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 ImVec2 GetWindowSize(); // get current window size
IMGUI_API float GetWindowWidth(); IMGUI_API float GetWindowWidth();
IMGUI_API float GetWindowHeight(); IMGUI_API float GetWindowHeight();
IMGUI_API bool IsWindowCollapsed(); 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 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() IMGUI_API void SetNextWindowPosCenter(ImGuiSetCond cond = 0); // set next window position to be centered on screen. call before Begin()
@ -171,6 +169,9 @@ namespace ImGui
IMGUI_API void PushStyleVar(ImGuiStyleVar idx, float val); IMGUI_API void PushStyleVar(ImGuiStyleVar idx, float val);
IMGUI_API void PushStyleVar(ImGuiStyleVar idx, const ImVec2& val); IMGUI_API void PushStyleVar(ImGuiStyleVar idx, const ImVec2& val);
IMGUI_API void PopStyleVar(int count = 1); 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(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 IMGUI_API ImU32 GetColorU32(const ImVec4& col); // retrieve given color with style alpha applied
@ -189,18 +190,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 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 EndGroup();
IMGUI_API void Separator(); // horizontal line 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 Spacing(); // add spacing
IMGUI_API void Dummy(const ImVec2& size); // add a dummy item of given size 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 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 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 ImVec2 GetCursorPos(); // cursor position is relative to window position
IMGUI_API float GetCursorPosX(); // " IMGUI_API float GetCursorPosX(); // "
IMGUI_API float GetCursorPosY(); // " IMGUI_API float GetCursorPosY(); // "
@ -215,6 +209,16 @@ namespace ImGui
IMGUI_API float GetTextLineHeightWithSpacing(); // distance (in pixels) between 2 consecutive lines of text == GetWindowFontSize() + GetStyle().ItemSpacing.y 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 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 // ID scopes
// If you are creating widgets in a loop you most likely want to push a unique identifier so ImGui can differentiate them. // 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. // 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.
@ -239,7 +243,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 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 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 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 BulletText(const char* fmt, ...) IM_PRINTFARGS(1);
IMGUI_API void BulletTextV(const char* fmt, va_list args); IMGUI_API void BulletTextV(const char* fmt, va_list args);
IMGUI_API bool Button(const char* label, const ImVec2& size = ImVec2(0,0)); IMGUI_API bool Button(const char* label, const ImVec2& size = ImVec2(0,0));
@ -304,8 +308,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"); 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 // 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_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_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 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 char* str_id, const char* fmt, va_list args); // "
IMGUI_API bool TreeNodeV(const void* ptr_id, const char* fmt, va_list args); // " IMGUI_API bool TreeNodeV(const void* ptr_id, const char* fmt, va_list args); // "
@ -331,7 +335,7 @@ namespace ImGui
IMGUI_API void ValueColor(const char* prefix, const ImVec4& v); IMGUI_API void ValueColor(const char* prefix, const ImVec4& v);
IMGUI_API void ValueColor(const char* prefix, unsigned int 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 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 SetTooltipV(const char* fmt, va_list args);
IMGUI_API void BeginTooltip(); // use to create full-featured tooltip windows that aren't just text IMGUI_API void BeginTooltip(); // use to create full-featured tooltip windows that aren't just text
@ -347,7 +351,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 = 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 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 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 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) IMGUI_API bool BeginPopupModal(const char* name, bool* p_opened = NULL, ImGuiWindowFlags extra_flags = 0); // modal dialog (can't close them by clicking outside)
@ -408,7 +412,7 @@ namespace ImGui
IMGUI_API bool IsMouseReleased(int button); // did mouse button released (went from Down to !Down) 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 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 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 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 GetMousePos(); // shortcut to ImGui::GetIO().MousePos provided by user, to be consistent with other calls
IMGUI_API ImVec2 GetMousePosOnOpeningCurrentPopup(); // retrieve backup of mouse positioning at the time of opening popup we have BeginPopup() into IMGUI_API ImVec2 GetMousePosOnOpeningCurrentPopup(); // retrieve backup of mouse positioning at the time of opening popup we have BeginPopup() into
@ -433,6 +437,8 @@ namespace ImGui
// Obsolete (will be removed) // Obsolete (will be removed)
#ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS #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 void OpenNextNode(bool open) { ImGui::SetNextTreeNodeOpened(open, 0); } // OBSOLETE 1.34+
static inline bool GetWindowIsFocused() { return ImGui::IsWindowFocused(); } // OBSOLETE 1.36+ static inline bool GetWindowIsFocused() { return ImGui::IsWindowFocused(); } // OBSOLETE 1.36+
static inline bool GetWindowCollapsed() { return ImGui::IsWindowCollapsed(); } // OBSOLETE 1.39+ static inline bool GetWindowCollapsed() { return ImGui::IsWindowCollapsed(); } // OBSOLETE 1.39+
@ -1126,11 +1132,12 @@ struct ImDrawList
// Primitives // Primitives
IMGUI_API void AddLine(const ImVec2& a, const ImVec2& b, ImU32 col, float thickness = 1.0f); 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 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 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 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 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 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 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); 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);
@ -1260,8 +1267,8 @@ struct ImFontAtlas
int TexWidth; // Texture width calculated during Build(). int TexWidth; // Texture width calculated during Build().
int TexHeight; // Texture height 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. 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<ImFont*> Fonts; ImVector<ImFont*> 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 // Private
ImVector<ImFontConfig> ConfigData; // Internal data ImVector<ImFontConfig> ConfigData; // Internal data

View File

@ -1108,7 +1108,7 @@ void ImGui::ShowTestWindow(bool* p_opened)
ImGui::InvisibleButton("##dummy", size); ImGui::InvisibleButton("##dummy", size);
if (ImGui::IsItemActive() && ImGui::IsMouseDragging()) { offset.x += ImGui::GetIO().MouseDelta.x; offset.y += ImGui::GetIO().MouseDelta.y; } 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()->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(); ImGui::TreePop();
} }
} }
@ -1803,24 +1803,26 @@ static void ShowExampleAppCustomRendering(bool* opened)
const ImVec2 p = ImGui::GetCursorScreenPos(); const ImVec2 p = ImGui::GetCursorScreenPos();
const ImU32 col32 = ImColor(col); const ImU32 col32 = ImColor(col);
float x = p.x + 4.0f, y = p.y + 4.0f, spacing = 8.0f; 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; for (int n = 0; n < 2; n++)
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; float thickness = (n == 0) ? 1.0f : 4.0f;
draw_list->AddLine(ImVec2(x, y), ImVec2(x+sz, y ), col32); x += sz+spacing; draw_list->AddCircle(ImVec2(x+sz*0.5f, y+sz*0.5f), sz*0.5f, col32, 20, thickness); x += sz+spacing;
draw_list->AddLine(ImVec2(x, y), ImVec2(x+sz, y+sz), col32); x += sz+spacing; draw_list->AddRect(ImVec2(x, y), ImVec2(x+sz, y+sz), col32, 0.0f, ~0, thickness); x += sz+spacing;
draw_list->AddLine(ImVec2(x, y), ImVec2(x, y+sz), col32); x += spacing; draw_list->AddRect(ImVec2(x, y), ImVec2(x+sz, y+sz), col32, 10.0f, ~0, thickness); x += sz+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); 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;
x = p.x + 4; draw_list->AddLine(ImVec2(x, y), ImVec2(x+sz, y ), col32, thickness); x += sz+spacing;
y += 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->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); x += sz+spacing;
draw_list->AddRectFilled(ImVec2(x, y), ImVec2(x+sz, y+sz), col32, 10.0f); 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->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->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)); 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(); ImGui::Separator();
{ {

View File

@ -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. // 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) if ((col >> 24) == 0)
return; return;
PathRect(a + ImVec2(0.5f,0.5f), b - ImVec2(0.5f,0.5f), rounding, rounding_corners); 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) void ImDrawList::AddRectFilled(const ImVec2& a, const ImVec2& b, ImU32 col, float rounding, int rounding_corners)
@ -823,6 +823,17 @@ void ImDrawList::AddRectFilledMultiColor(const ImVec2& a, const ImVec2& c, ImU32
PrimWriteVtx(ImVec2(a.x, c.y), uv, col_bot_left); 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) void ImDrawList::AddTriangleFilled(const ImVec2& a, const ImVec2& b, const ImVec2& c, ImU32 col)
{ {
if ((col >> 24) == 0) if ((col >> 24) == 0)
@ -834,14 +845,14 @@ void ImDrawList::AddTriangleFilled(const ImVec2& a, const ImVec2& b, const ImVec
PathFill(col); 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) if ((col >> 24) == 0)
return; return;
const float a_max = IM_PI*2.0f * ((float)num_segments - 1.0f) / (float)num_segments; 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); 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) void ImDrawList::AddCircleFilled(const ImVec2& centre, float radius, ImU32 col, int num_segments)
@ -874,6 +885,13 @@ void ImDrawList::AddText(const ImFont* font, float font_size, const ImVec2& pos,
if (text_begin == text_end) if (text_begin == text_end)
return; 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. 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) // reserve vertices for worse case (over-reserving is useful and easily amortized)
@ -906,12 +924,8 @@ void ImDrawList::AddText(const ImFont* font, float font_size, const ImVec2& pos,
_VtxCurrentIdx = (unsigned int)VtxBuffer.Size; _VtxCurrentIdx = (unsigned int)VtxBuffer.Size;
} }
// 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) 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); AddText(GImGui->Font, GImGui->FontSize, pos, col, text_begin, text_end);
} }
@ -1992,10 +2006,10 @@ void ImFont::RenderText(float size, ImVec2 pos, ImU32 col, const ImVec4& clip_re
{ {
char_width = glyph->XAdvance * scale; 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') 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 y1 = (float)(y + glyph->Y0 * scale);
float y2 = (float)(y + glyph->Y1 * scale); float y2 = (float)(y + glyph->Y1 * scale);
@ -2039,8 +2053,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. // We are NOT calling PrimRectUV() here because non-inlined causes too much overhead in a debug build.
// inlined: // 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[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); idx_write[3] = (ImDrawIdx)(vtx_current_idx); idx_write[4] = (ImDrawIdx)(vtx_current_idx+2); idx_write[5] = (ImDrawIdx)(vtx_current_idx+3);

View File

@ -357,7 +357,7 @@ struct ImGuiState
ImFont* Font; // (Shortcut) == FontStack.empty() ? IO.Font : FontStack.back() ImFont* Font; // (Shortcut) == FontStack.empty() ? IO.Font : FontStack.back()
float FontSize; // (Shortcut) == FontBaseSize * g.CurrentWindow->FontWindowScale == window->FontSize() float FontSize; // (Shortcut) == FontBaseSize * g.CurrentWindow->FontWindowScale == window->FontSize()
float FontBaseSize; // (Shortcut) == IO.FontGlobalScale * Font->Scale * Font->FontSize. Size of characters. float FontBaseSize; // (Shortcut) == IO.FontGlobalScale * Font->Scale * Font->FontSize. Size of characters.
ImVec2 FontTexUvWhitePixel; // (Shortcut) == Font->TexUvForWhite ImVec2 FontTexUvWhitePixel; // (Shortcut) == Font->TexUvWhitePixel
float Time; float Time;
int FrameCount; int FrameCount;
@ -706,7 +706,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 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 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 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 PushClipRect(const ImVec2& clip_rect_min, const ImVec2& clip_rect_max, bool intersect_with_existing_clip_rect = true);
IMGUI_API void PopClipRect(); IMGUI_API void PopClipRect();