Compare commits

..

32 Commits
v1.07 ... v1.09

Author SHA1 Message Date
cd3d027df0 Delete obsolete comments in imconfig.h 2014-08-28 14:54:22 +01:00
7adad71042 Moved IMGUI_FONT_TEX_UV_FOR_WHITE define to a variable so font can be changed at runtime 2014-08-28 14:53:41 +01:00
88c33ecc29 Fixes to allow clean 1-pixel thick lines in more use cases. PixelCenterOffset not the same as previously! 2014-08-28 14:52:10 +01:00
1f63e01cc6 Minor fixes to scrollbar rendering, close button and made checkbox/radio button padding more consistent. 2014-08-27 22:16:55 +01:00
bd26de0628 Collapse triangle don't have a shadow unless borders are enabled.
Fixed cross that appears when hovering window close button to be perfectly 45 degrees.
2014-08-27 17:54:11 +01:00
5a9639b423 Fixed collapsing header border (if borders are enabled) being off the clip rectangle.
Tweak demo window.
2014-08-27 11:38:26 +01:00
b90d0c558d Minor text alignment 2014-08-26 19:22:09 +01:00
51f8e33eb4 Added FAQ entry 2014-08-26 18:29:58 +01:00
80dd1e1065 Added comments 2014-08-26 18:27:10 +01:00
5f6b261c9b Fixed uninitialised fields in ImBitmapFont (were unused when uninitialised, but still dodgy) 2014-08-26 18:14:04 +01:00
681ac5f777 Fixed size/padding of slider grab box for vertical symetry (was 1 pixel too high) 2014-08-26 16:56:20 +01:00
0d344e1f03 Merge pull request #34 from orbitcowboy/master
Do not update a variable, which is not used.
2014-08-26 14:28:40 +01:00
d2b43f31e3 Updated URL to new ProggyFonts site 2014-08-25 17:27:42 +01:00
d17a586738 Fixed ImGuiTextFilter triming of leading/trailing blanks. Documented "Filtering" section of demo better. 2014-08-25 17:19:04 +01:00
710b9b68b1 Merge pull request #29 from Roflraging/master
Disable client state in OpenGL example after rendering.
2014-08-25 16:58:54 +01:00
29ba288ea0 Merge pull request #31 from orbitcowboy/master
Fixed file descriptor leak on LoadSettings() failure
2014-08-25 16:56:45 +01:00
addfa75eb0 Do not update a variable, which is not used. 2014-08-24 07:32:27 +02:00
882072cf30 Fixed resource leaks 2014-08-24 03:51:00 +02:00
7bd507d266 Disable client state in OpenGL example after rendering.
Using the example code in another application that has other rendering
code can cause rendering bugs or memory access errors if client state
is not disabled.
2014-08-22 16:00:38 -05:00
1ff104641a Web FAQ 2014-08-20 18:12:08 +01:00
3b8d1ec207 Update README.md - skinning 2014-08-20 17:56:23 +01:00
e9e1fd2b3c Added screenshot for web 2014-08-20 17:46:49 +01:00
6062d18cf9 Added basic sizes edition in the style editor 2014-08-20 17:42:53 +01:00
05f0993616 stb_textedit 1.4 fix signed/unsigned warnings 2014-08-20 10:43:08 +01:00
6dd2b13220 Merge branch 'Dadeos-compilation_warnings' 2014-08-20 10:41:06 +01:00
5864c45fe3 Fix type conversion compiler warnings (from dadeos) 2014-08-20 10:40:31 +01:00
4bc3642bdb Todo list 2014-08-20 10:19:05 +01:00
a3f32381c4 Fix mismatched static declaration warning 2014-08-19 12:51:13 +01:00
67f17a644c Converted all Tabs to Spaces
Argh
2014-08-19 12:45:34 +01:00
e807d97089 Exposed CalcTextSize(), GetCursorScreenPos() for more advanced fiddling 2014-08-19 12:39:30 +01:00
23d156908d Added an assertion 2014-08-19 12:27:34 +01:00
42d4b4be6a Converted all Tabs to Spaces (git diff -w shows an empty diff) 2014-08-19 12:09:13 +01:00
8 changed files with 5213 additions and 5121 deletions

View File

@ -30,13 +30,34 @@ The Immediate Mode GUI paradigm may at first appear unusual to some users. This
- [Jari Komppa's tutorial on building an ImGui library](http://iki.fi/sol/imgui/).
- [Casey Muratori's original video that popularized the concept](https://mollyrocket.com/861).
Frequently Asked Question
-------------------------
<b>How do you use ImGui on a platform that may not have a mouse and keyboard?</b>
I recommend using [Synergy](http://synergy-project.org) and the uSynergy.c micro client to share your mouse and keyboard. This way you can seemingly use your PC input devices on a video game console or a tablet. ImGui was also designed to function with touch inputs if you increase the padding of widgets to compensate for the lack of precision of touch devices, but it is recommended you use a mouse to allow optimising for screen real-estate.
<b>I integrated ImGui in my engine and the text or lines are blurry..</b>
- Try adjusting ImGui::GetIO().PixelCenterOffset to 0.0f or 0.5f.
- In your Render function, try translating your projection matrix by (0.5f,0.5f) or (0.375f,0.375f).
<b>Can you create elaborate/serious tools with ImGui?</b>
Yes. I have written data browsers, debuggers, profilers and all sort of non-trivial tools with the library. There's no reason you cannot, and in my experience the simplicity of the API is very empowering. However note that ImGui is programmer centric and the immediate-mode GUI paradigm might requires a bit of adaptation before you can realize its full potential.
<b>Can you reskin the look of ImGui?</b>
Yes, you can alter the look of the interface to some degree: changing colors, sizes and padding, font. However, as ImGui is designed and optimised to create debug tools, the amount of skinning you can apply is limited. There is only so much you can stray away from the default look and feel of the interface. The example below uses modified settings to create a more compact UI with different colors:
![skinning screenshot 1](/web/skinning_sample_01.png?raw=true)
Credits
-------
Developed by [Omar Cornut](http://www.miracleworld.net). The library was developed with the support of [Media Molecule](http://www.mediamolecule.com) and first used internally on the game [Tearaway](http://tearaway.mediamolecule.com).
Embeds [proggy_clean](http://www.proggyfonts.net/) font by Tristan Grimmer (also MIT license).
Embeds [proggy_clean](http://upperbounds.net) font by Tristan Grimmer (also MIT license).
Inspiration, feedback, and testing: Casey Muratori, Atman Binstock, Mikko Mononen, Emmanuel Briney, Stefan Kamoda, Anton Mikhailov, Matt Willis. Thanks!

View File

@ -20,7 +20,10 @@ struct CUSTOMVERTEX
};
#define D3DFVF_CUSTOMVERTEX (D3DFVF_XYZ|D3DFVF_DIFFUSE|D3DFVF_TEX1)
// This is the main rendering function that you have to implement and provide to ImGui (via setting up 'RenderDrawListsFn' in the ImGuiIO structuer)
// This is the main rendering function that you have to implement and provide to ImGui (via setting up 'RenderDrawListsFn' in the ImGuiIO structure)
// If text or lines are blurry when integrating ImGui in your engine:
// - in your Render function, try translating your projection matrix by (0.5f,0.5f) or (0.375f,0.375f)
// - try adjusting ImGui::GetIO().PixelCenterOffset to 0.5f or 0.375f
static void ImImpl_RenderDrawLists(ImDrawList** const cmd_lists, int cmd_lists_count)
{
size_t total_vtx_count = 0;
@ -79,7 +82,7 @@ static void ImImpl_RenderDrawLists(ImDrawList** const cmd_lists, int cmd_lists_c
D3DXMatrixIdentity(&mat);
g_pd3dDevice->SetTransform(D3DTS_WORLD, &mat);
g_pd3dDevice->SetTransform(D3DTS_VIEW, &mat);
D3DXMatrixOrthoOffCenterLH(&mat, 0.0f, ImGui::GetIO().DisplaySize.x, ImGui::GetIO().DisplaySize.y, 0.0f, -1.0f, +1.0f);
D3DXMatrixOrthoOffCenterLH(&mat, 0.5f, ImGui::GetIO().DisplaySize.x+0.5f, ImGui::GetIO().DisplaySize.y+0.5f, 0.5f, -1.0f, +1.0f);
g_pd3dDevice->SetTransform(D3DTS_PROJECTION, &mat);
// Render command lists

View File

@ -11,14 +11,17 @@
static GLFWwindow* window;
static GLuint fontTex;
// This is the main rendering function that you have to implement and provide to ImGui (via setting up 'RenderDrawListsFn' in the ImGuiIO structuer)
// We are using the fixed pipeline.
// A faster way would be to collate all vertices from all cmd_lists into a single vertex buffer
// This is the main rendering function that you have to implement and provide to ImGui (via setting up 'RenderDrawListsFn' in the ImGuiIO structure)
// If text or lines are blurry when integrating ImGui in your engine:
// - in your Render function, try translating your projection matrix by (0.5f,0.5f) or (0.375f,0.375f)
// - try adjusting ImGui::GetIO().PixelCenterOffset to 0.5f or 0.375f
static void ImImpl_RenderDrawLists(ImDrawList** const cmd_lists, int cmd_lists_count)
{
if (cmd_lists_count == 0)
return;
// We are using the OpenGL fixed pipeline to make the example code simpler to read!
// A probable faster way to render would be to collate all vertices from all cmd_lists into a single vertex buffer.
// Setup render state: alpha-blending enabled, no face culling, no depth testing, scissor enabled, vertex/texcoord/color pointers.
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
@ -61,6 +64,9 @@ static void ImImpl_RenderDrawLists(ImDrawList** const cmd_lists, int cmd_lists_c
}
}
glDisable(GL_SCISSOR_TEST);
glDisableClientState(GL_COLOR_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glDisableClientState(GL_VERTEX_ARRAY);
}
static const char* ImImpl_GetClipboardTextFn()
@ -145,7 +151,7 @@ void InitImGui()
ImGuiIO& io = ImGui::GetIO();
io.DisplaySize = ImVec2((float)w, (float)h); // Display size, in pixels. For clamping windows positions.
io.DeltaTime = 1.0f/60.0f; // Time elapsed since last frame, in seconds (in this sample app we'll override this every frame because our timestep is variable)
io.PixelCenterOffset = 0.5f; // Align OpenGL texels
io.PixelCenterOffset = 0.0f; // Align OpenGL texels
io.KeyMap[ImGuiKey_Tab] = GLFW_KEY_TAB; // Keyboard mapping. ImGui will use those indices to peek into the io.KeyDown[] array.
io.KeyMap[ImGuiKey_LeftArrow] = GLFW_KEY_LEFT;
io.KeyMap[ImGuiKey_RightArrow] = GLFW_KEY_RIGHT;

View File

@ -15,10 +15,6 @@
//---- Don't implement default clipboard handlers for Windows (so as not to link with OpenClipboard(), etc.)
//#define IMGUI_DISABLE_WIN32_DEFAULT_CLIPBOARD_FUNCS
//---- If you are loading a custom font, ImGui expect to find a pure white pixel at (0,0)
// Change it's UV coordinate here if you can't have a white pixel at (0,0)
//#define IMGUI_FONT_TEX_UV_FOR_WHITE ImVec2(0.f/256.f,0.f/256.f)
//---- Define implicit cast operators to convert back<>forth from your math types and ImVec2/ImVec4.
/*
#define IM_VEC2_CLASS_EXTRA \

266
imgui.cpp
View File

@ -53,7 +53,7 @@
- every frame:
1/ in your mainloop or right after you got your keyboard/mouse info, call ImGui::GetIO() and fill the 'Input' data, then call ImGui::NewFrame().
2/ use any ImGui function you want between NewFrame() and Render()
3/ ImGui::Render() to render all the accumulated command-lists. it will cack your RenderDrawListFn handler set in the IO structure.
3/ ImGui::Render() to render all the accumulated command-lists. it will call your RenderDrawListFn handler that you set in the IO structure.
- all rendering information are stored into command-lists until ImGui::Render() is called.
- effectively it means you can create widgets at any time in your code, regardless of "update" vs "render" considerations.
- a typical application skeleton may be:
@ -87,6 +87,10 @@
// swap video buffer, etc.
}
- if text or lines are blurry when integrating ImGui in your engine:
- in your Render function, try translating your projection matrix by (0.5f,0.5f) or (0.375f,0.375f)
- try adjusting ImGui::GetIO().PixelCenterOffset to 0.5f or 0.375f
- some widgets carry state and requires an unique ID to do so.
- unique ID are typically derived from a string label, an indice or a pointer.
- use PushID/PopID to easily create scopes and avoid ID conflicts. A Window is also an implicit scope.
@ -101,7 +105,7 @@
- if you want to use a different font than the default
- create bitmap font data using BMFont. allocate ImGui::GetIO().Font and use ->LoadFromFile()/LoadFromMemory(), set ImGui::GetIO().FontHeight
- load your texture yourself. texture *MUST* have white pixel at UV coordinate 'IMGUI_FONT_TEX_UV_FOR_WHITE' (you can #define it in imconfig.h), this is used by solid objects.
- load your texture yourself. texture *MUST* have white pixel at UV coordinate Imgui::GetIO().FontTexUvForWhite. This is used to draw all solid shapes.
- tip: the construct 'if (IMGUI_ONCE_UPON_A_FRAME)' will evaluate to true only once a frame, you can use it to add custom UI in the middle of a deep nested inner loop in your code.
- tip: you can call Render() multiple times (e.g for VR renders), up to you to communicate the extra state to your RenderDrawListFn function.
@ -141,6 +145,7 @@
- text edit: pasting text into a number box should filter the characters the same way direct input does
- text edit: allow code to catch user pressing Return (perhaps through disable live edit? so only Return apply the final value, also allow catching Return if value didn't changed)
- settings: write more decent code to allow saving/loading new fields
- settings: api for per-tool simple persistant data (bool,int,float) in .ini file
- log: be able to right-click and log a window or tree-node into tty/file/clipboard?
- filters: set a current filter that tree node can automatically query to hide themselves
- filters: handle wildcards (with implicit leading/trailing *), regexps
@ -149,6 +154,7 @@
- input: support trackpad style scrolling & slider edit.
- misc: not thread-safe
- misc: double-clicking on title bar to minimize isn't consistent, perhaps move to single-click on left-most collapse icon?
- style editor: add a button to print C code.
- optimisation/render: use indexed rendering
- optimisation/render: move clip-rect to vertex data? would allow merging all commands
- optimisation/render: merge command-list of all windows into one command-list?
@ -177,11 +183,12 @@ namespace ImGui
{
static bool ButtonBehaviour(const ImGuiAabb& bb, const ImGuiID& id, bool* out_hovered, bool* out_held, bool allow_key_modifiers, bool repeat = false);
static void RenderFrame(ImVec2 p_min, ImVec2 p_max, ImU32 fill_col, bool border = true, float rounding = 0.0f);
static void RenderText(ImVec2 pos, const char* text, const char* text_end = NULL, const bool hide_text_after_hash = true);
static ImVec2 CalcTextSize(const char* text, const char* text_end = NULL, const bool hide_text_after_hash = true);
static void LogText(const ImVec2& ref_pos, const char* text, const char* text_end = NULL);
static void RenderText(ImVec2 pos, const char* text, const char* text_end = NULL, const bool hide_text_after_hash = true);
static void RenderFrame(ImVec2 p_min, ImVec2 p_max, ImU32 fill_col, bool border = true, float rounding = 0.0f);
static void RenderCollapseTriangle(ImVec2 p_min, bool open, float scale = 1.0f, bool shadow = false);
static void ItemSize(ImVec2 size, ImVec2* adjust_start_offset = NULL);
static void ItemSize(const ImGuiAabb& aabb, ImVec2* adjust_start_offset = NULL);
static void PushColumnClipRect(int column_index = -1);
@ -272,8 +279,9 @@ ImGuiIO::ImGuiIO()
IniFilename = "imgui.ini";
LogFilename = "imgui_log.txt";
Font = NULL;
FontTexUvForWhite = ImVec2(0.0f,0.0f);
FontAllowScaling = false;
PixelCenterOffset = 0.5f;
PixelCenterOffset = 0.0f;
MousePos = ImVec2(-1,-1);
MousePosPrev = ImVec2(-1,-1);
MouseDoubleClickTime = 0.30f;
@ -378,7 +386,7 @@ static ImU32 crc32(const void* data, size_t data_size, ImU32 seed = 0)
{
ImU32 crc = i;
for (ImU32 j = 0; j < 8; j++)
crc = (crc >> 1) ^ (-int(crc & 1) & polynomial);
crc = (crc >> 1) ^ (ImU32(-int(crc & 1)) & polynomial);
crc32_lut[i] = crc;
}
}
@ -396,16 +404,14 @@ static size_t ImFormatString(char* buf, size_t buf_size, const char* fmt, ...)
int w = vsnprintf(buf, buf_size, fmt, args);
va_end(args);
buf[buf_size-1] = 0;
if (w == -1) w = (int)buf_size;
return w;
return (w == -1) ? buf_size : (size_t)w;
}
static size_t ImFormatStringV(char* buf, size_t buf_size, const char* fmt, va_list args)
{
int w = vsnprintf(buf, buf_size, fmt, args);
buf[buf_size-1] = 0;
if (w == -1) w = (int)buf_size;
return w;
return (w == -1) ? buf_size : (size_t)w;
}
static ImU32 ImConvertColorFloat4ToU32(const ImVec4& in)
@ -727,6 +733,7 @@ static void RegisterAliveId(const ImGuiID& id)
//-----------------------------------------------------------------------------
// Helper: Key->value storage
void ImGuiStorage::Clear()
{
Data.clear();
@ -799,6 +806,7 @@ void ImGuiStorage::SetAllInt(int v)
//-----------------------------------------------------------------------------
// Helper: Parse and apply text filters. In format "aaaaa[,bbbb][,ccccc]"
ImGuiTextFilter::ImGuiTextFilter()
{
InputBuf[0] = 0;
@ -890,6 +898,7 @@ bool ImGuiTextFilter::PassFilter(const char* val) const
//-----------------------------------------------------------------------------
// Helper: Text buffer for logging/accumulating text
void ImGuiTextBuffer::append(const char* fmt, ...)
{
va_list args;
@ -900,13 +909,13 @@ void ImGuiTextBuffer::append(const char* fmt, ...)
return;
const size_t write_off = Buf.size();
if (write_off + len >= Buf.capacity())
if (write_off + (size_t)len >= Buf.capacity())
Buf.reserve(Buf.capacity() * 2);
Buf.resize(write_off + (size_t)len);
va_start(args, fmt);
ImFormatStringV(&Buf[write_off] - 1, len+1, fmt, args);
ImFormatStringV(&Buf[write_off] - 1, (size_t)len+1, fmt, args);
va_end(args);
}
@ -1051,14 +1060,24 @@ static void LoadSettings()
if ((f = fopen(filename, "rt")) == NULL)
return;
if (fseek(f, 0, SEEK_END))
{
fclose(f);
return;
long f_size = ftell(f);
if (f_size == -1)
}
const long f_size_signed = ftell(f);
if (f_size_signed == -1)
{
fclose(f);
return;
}
size_t f_size = (size_t)f_size_signed;
if (fseek(f, 0, SEEK_SET))
{
fclose(f);
return;
}
char* f_data = new char[f_size+1];
f_size = (long)fread(f_data, 1, f_size, f); // Text conversion alter read size so let's not be fussy about return value
f_size = fread(f_data, 1, f_size, f); // Text conversion alter read size so let's not be fussy about return value
fclose(f);
if (f_size == 0)
{
@ -1542,12 +1561,14 @@ static void RenderFrame(ImVec2 p_min, ImVec2 p_max, ImU32 fill_col, bool border,
window->DrawList->AddRectFilled(p_min, p_max, fill_col, rounding);
if (border && (window->Flags & ImGuiWindowFlags_ShowBorders))
{
window->DrawList->AddRect(p_min+ImVec2(1,1), p_max+ImVec2(1,1), window->Color(ImGuiCol_BorderShadow), rounding);
window->DrawList->AddRect(p_min, p_max, window->Color(ImGuiCol_Border), rounding);
// FIXME: I have no idea how this is working correctly but it is the best I've found that works on multiple rendering
const float offset = GImGui.IO.PixelCenterOffset;
window->DrawList->AddRect(p_min+ImVec2(1.5f-offset,1.5f-offset), p_max+ImVec2(1.0f-offset*2,1.0f-offset*2), window->Color(ImGuiCol_BorderShadow), rounding);
window->DrawList->AddRect(p_min+ImVec2(0.5f-offset,0.5f-offset), p_max+ImVec2(0.0f-offset*2,0.0f-offset*2), window->Color(ImGuiCol_Border), rounding);
}
}
static void RenderCollapseTriangle(ImVec2 p_min, bool open, float scale = 1.0f, bool shadow = false)
static void RenderCollapseTriangle(ImVec2 p_min, bool open, float scale, bool shadow)
{
ImGuiWindow* window = GetCurrentWindow();
@ -1570,12 +1591,12 @@ static void RenderCollapseTriangle(ImVec2 p_min, bool open, float scale = 1.0f,
c = center + ImVec2(-0.500f,-0.866f)*r;
}
if (shadow)
if (shadow && (window->Flags & ImGuiWindowFlags_ShowBorders) != 0)
window->DrawList->AddTriangleFilled(a+ImVec2(2,2), b+ImVec2(2,2), c+ImVec2(2,2), window->Color(ImGuiCol_BorderShadow));
window->DrawList->AddTriangleFilled(a, b, c, window->Color(ImGuiCol_Border));
}
static ImVec2 CalcTextSize(const char* text, const char* text_end, const bool hide_text_after_hash)
ImVec2 CalcTextSize(const char* text, const char* text_end, const bool hide_text_after_hash)
{
ImGuiWindow* window = GetCurrentWindow();
@ -2055,8 +2076,7 @@ bool Begin(const char* name, bool* open, ImVec2 size, float fill_alpha, ImGuiWin
ImGuiAabb scrollbar_bb(window->Aabb().Max.x - style.ScrollBarWidth, title_bar_aabb.Max.y+1, window->Aabb().Max.x, window->Aabb().Max.y-1);
//window->DrawList->AddLine(scrollbar_bb.GetTL(), scrollbar_bb.GetBL(), g.Colors[ImGuiCol_Border]);
window->DrawList->AddRectFilled(scrollbar_bb.Min, scrollbar_bb.Max, window->Color(ImGuiCol_ScrollbarBg));
scrollbar_bb.Max.x -= 3;
scrollbar_bb.Expand(ImVec2(0,-3));
scrollbar_bb.Expand(ImVec2(-3,-3));
const float grab_size_y_norm = ImSaturate(window->Size.y / ImMax(window->SizeContentsFit.y, window->Size.y));
const float grab_size_y = scrollbar_bb.GetHeight() * grab_size_y_norm;
@ -2345,7 +2365,7 @@ const char* GetStyleColorName(ImGuiCol idx)
case ImGuiCol_PlotLines: return "PlotLines";
case ImGuiCol_PlotLinesHovered: return "PlotLinesHovered";
case ImGuiCol_PlotHistogram: return "PlotHistogram";
case ImGuiCol_PlotHistogramHovered: return "ImGuiCol_PlotHistogramHovered";
case ImGuiCol_PlotHistogramHovered: return "PlotHistogramHovered";
case ImGuiCol_TextSelectedBg: return "TextSelectedBg";
case ImGuiCol_TooltipBg: return "TooltipBg";
}
@ -2441,6 +2461,12 @@ void SetCursorPos(const ImVec2& pos)
window->DC.CursorPos = window->Pos + pos;
}
ImVec2 GetCursorScreenPos()
{
ImGuiWindow* window = GetCurrentWindow();
return window->DC.CursorPos;
}
void SetScrollPosHere()
{
ImGuiWindow* window = GetCurrentWindow();
@ -2495,6 +2521,7 @@ void TextUnformatted(const char* text, const char* text_end)
if (window->SkipItems)
return;
IM_ASSERT(text != NULL);
const char* text_begin = text;
if (text_end == NULL)
text_end = text + strlen(text);
@ -2743,21 +2770,22 @@ static bool CloseWindowButton(bool* open)
ImGuiWindow* window = GetCurrentWindow();
const ImGuiID id = window->GetID("##CLOSE");
const float title_bar_height = window->TitleBarHeight();
const ImGuiAabb bb(window->Aabb().GetTR() + ImVec2(-title_bar_height+3.0f,2.0f), window->Aabb().GetTR() + ImVec2(-2.0f,+title_bar_height-2.0f));
const float size = window->TitleBarHeight() - 4.0f;
const ImGuiAabb bb(window->Aabb().GetTR() + ImVec2(-3.0f-size,2.0f), window->Aabb().GetTR() + ImVec2(-3.0f,2.0f+size));
bool hovered, held;
bool pressed = ButtonBehaviour(bb, id, &hovered, &held, true);
// Render
const ImU32 col = window->Color((held && hovered) ? ImGuiCol_CloseButtonActive : hovered ? ImGuiCol_CloseButtonHovered : ImGuiCol_CloseButton);
window->DrawList->AddCircleFilled(bb.GetCenter(), ImMax(2.0f,title_bar_height*0.5f-4), col, 16);
const ImVec2 center = bb.GetCenter();
window->DrawList->AddCircleFilled(center, ImMax(2.0f,size*0.5f), col, 16);
const float cross_padding = 4;
if (hovered && bb.GetWidth() >= (cross_padding+1)*2 && bb.GetHeight() >= (cross_padding+1)*2)
const float cross_extent = (size * 0.5f * 0.7071f) - 1.0f;
if (hovered)
{
window->DrawList->AddLine(bb.GetTL()+ImVec2(+cross_padding,+cross_padding), bb.GetBR()+ImVec2(-cross_padding,-cross_padding), window->Color(ImGuiCol_Text));
window->DrawList->AddLine(bb.GetBL()+ImVec2(+cross_padding,-cross_padding), bb.GetTR()+ImVec2(-cross_padding,+cross_padding), window->Color(ImGuiCol_Text));
window->DrawList->AddLine(center + ImVec2(+cross_extent,+cross_extent), center + ImVec2(-cross_extent,-cross_extent), window->Color(ImGuiCol_Text));
window->DrawList->AddLine(center + ImVec2(+cross_extent,-cross_extent), center + ImVec2(-cross_extent,+cross_extent), window->Color(ImGuiCol_Text));
}
if (open != NULL && pressed)
@ -2865,8 +2893,8 @@ bool CollapsingHeader(const char* label, const char* str_id, const bool display_
ImGuiAabb bb = ImGuiAabb(pos_min, ImVec2(pos_max.x, pos_min.y + text_size.y));
if (display_frame)
{
bb.Min.x -= window_padding.x*0.5f;
bb.Max.x += window_padding.x*0.5f;
bb.Min.x -= window_padding.x*0.5f - 1;
bb.Max.x += window_padding.x*0.5f - 1;
bb.Max.y += style.FramePadding.y * 2;
}
@ -2902,7 +2930,7 @@ bool CollapsingHeader(const char* label, const char* str_id, const bool display_
{
if ((held && hovered) || hovered)
RenderFrame(bb.Min, bb.Max, col, false);
RenderCollapseTriangle(bb.Min + ImVec2(style.FramePadding.x, window->FontSize()*0.15f), opened, 0.70f);
RenderCollapseTriangle(bb.Min + ImVec2(style.FramePadding.x, window->FontSize()*0.15f), opened, 0.70f, false);
RenderText(bb.Min + ImVec2(window->FontSize() + style.FramePadding.x*2,0), label);
}
@ -3002,7 +3030,7 @@ void PushID(const void* ptr_id)
window->IDStack.push_back(window->GetID(ptr_id));
}
void PushID(int int_id)
void PushID(const int int_id)
{
const void* ptr_id = (void*)(intptr_t)int_id;
ImGuiWindow* window = GetCurrentWindow();
@ -3266,7 +3294,7 @@ bool SliderFloat(const char* label, float* v, float v_min, float v_max, const ch
// Draw
const float grab_x = ImLerp(slider_effective_x1, slider_effective_x2, grab_t);
const ImGuiAabb grab_bb(ImVec2(grab_x-grab_size_in_pixels*0.5f,frame_bb.Min.y+2.0f), ImVec2(grab_x+grab_size_in_pixels*0.5f,frame_bb.Max.y-1.0f));
const ImGuiAabb grab_bb(ImVec2(grab_x-grab_size_in_pixels*0.5f,frame_bb.Min.y+2.0f), ImVec2(grab_x+grab_size_in_pixels*0.5f,frame_bb.Max.y-2.0f));
window->DrawList->AddRectFilled(grab_bb.Min, grab_bb.Max, window->Color(g.ActiveId == id ? ImGuiCol_SliderGrabActive : ImGuiCol_SliderGrab));
}
@ -3356,7 +3384,7 @@ enum ImGuiPlotType
static float PlotGetValue(const float* values, size_t stride, int idx)
{
float v = *(float*)((unsigned char*)values + idx * stride);
const float v = *(float*)((unsigned char*)values + (size_t)idx * stride);
return v;
}
@ -3446,7 +3474,6 @@ static void Plot(ImGuiPlotType plot_type, const char* label, const float* values
else if (plot_type == ImGuiPlotType_Histogram)
window->DrawList->AddRectFilled(ImLerp(graph_bb.Min, graph_bb.Max, p0), ImLerp(graph_bb.Min, graph_bb.Max, ImVec2(p1.x, 1.0f))+ImVec2(-1,0), v_hovered == v_idx ? col_hovered : col_base);
v0 = v1;
t0 = t1;
p0 = p1;
}
@ -3504,7 +3531,7 @@ void Checkbox(const char* label, bool* v)
RenderFrame(check_bb.Min, check_bb.Max, window->Color(hovered ? ImGuiCol_CheckHovered : ImGuiCol_FrameBg));
if (*v)
{
window->DrawList->AddRectFilled(check_bb.Min+ImVec2(4,4), check_bb.Max-ImVec2(4,4), window->Color(ImGuiCol_CheckActive));
window->DrawList->AddRectFilled(check_bb.Min+ImVec2(3,3), check_bb.Max-ImVec2(3,3), window->Color(ImGuiCol_CheckActive));
}
if (g.LogEnabled)
@ -3557,7 +3584,7 @@ bool RadioButton(const char* label, bool active)
window->DrawList->AddCircleFilled(center, radius, window->Color(hovered ? ImGuiCol_CheckHovered : ImGuiCol_FrameBg), 16);
if (active)
window->DrawList->AddCircleFilled(center, radius-2, window->Color(ImGuiCol_CheckActive), 16);
window->DrawList->AddCircleFilled(center, radius-3.0f, window->Color(ImGuiCol_CheckActive), 16);
if (window->Flags & ImGuiWindowFlags_ShowBorders)
{
@ -3609,14 +3636,14 @@ void STB_TEXTEDIT_DELETECHARS(STB_TEXTEDIT_STRING* obj, int idx, int n) { c
bool STB_TEXTEDIT_INSERTCHARS(STB_TEXTEDIT_STRING* obj, int idx, const char* new_text, int new_text_len)
{
char* buf_end = obj->Text + obj->BufSize;
const int text_len = (int)strlen(obj->Text);
const size_t text_len = strlen(obj->Text);
if (new_text_len > buf_end - (obj->Text + text_len + 1))
return false;
memmove(obj->Text + idx + new_text_len, obj->Text + idx, text_len - idx);
memcpy(obj->Text + idx, new_text, new_text_len);
obj->Text[text_len + new_text_len] = 0;
memmove(obj->Text + (size_t)idx + new_text_len, obj->Text + (size_t)idx, text_len - (size_t)idx);
memcpy(obj->Text + (size_t)idx, new_text, (size_t)new_text_len);
obj->Text[text_len + (size_t)new_text_len] = 0;
return true;
}
@ -4059,7 +4086,7 @@ static bool Combo_ArrayGetter(void* data, int idx, const char** out_text)
bool Combo(const char* label, int* current_item, const char** items, int items_count, int popup_height_items)
{
bool value_changed = Combo(label, current_item, Combo_ArrayGetter, (void*)items, items_count, popup_height_items);
const bool value_changed = Combo(label, current_item, Combo_ArrayGetter, (void*)items, items_count, popup_height_items);
return value_changed;
}
@ -4132,7 +4159,7 @@ bool Combo(const char* label, int* current_item, bool (*items_getter)(void*, int
ImGui::SameLine(0, (int)g.Style.ItemInnerSpacing.x);
ImGui::TextUnformatted(label, FindTextDisplayEnd(label));
ImGui::PushID(id);
ImGui::PushID((int)id);
bool menu_toggled = false;
if (hovered)
{
@ -4540,7 +4567,7 @@ float GetColumnOffset(int column_index)
if (column_index < 0)
column_index = window->DC.ColumnCurrent;
const ImGuiID column_id = ImGuiID(window->DC.ColumnsSetID + column_index);
const ImGuiID column_id = window->DC.ColumnsSetID + ImGuiID(column_index);
RegisterAliveId(column_id);
const float default_t = column_index / (float)window->DC.ColumnsCount;
const float t = (float)window->StateStorage.GetInt(column_id, (int)(default_t * 8096)) / 8096; // Cheaply store our floating point value inside the integer (could store an union into the map?)
@ -4556,7 +4583,7 @@ void SetColumnOffset(int column_index, float offset)
if (column_index < 0)
column_index = window->DC.ColumnCurrent;
const ImGuiID column_id = ImGuiID(window->DC.ColumnsSetID + column_index);
const ImGuiID column_id = window->DC.ColumnsSetID + ImGuiID(column_index);
const float t = (offset - window->DC.ColumnStartX) / (window->Size.x - g.Style.ScrollBarWidth - window->DC.ColumnStartX);
window->StateStorage.SetInt(column_id, (int)(t*8096));
}
@ -4606,7 +4633,7 @@ void Columns(int columns_count, const char* id, bool border)
{
float x = window->Pos.x + GetColumnOffset(i);
const ImGuiID column_id = ImGuiID(window->DC.ColumnsSetID + i);
const ImGuiID column_id = window->DC.ColumnsSetID + ImGuiID(i);
const ImGuiAabb column_aabb(ImVec2(x-4,y1),ImVec2(x+4,y2));
if (IsClipped(column_aabb))
@ -4786,22 +4813,24 @@ void ImDrawList::AddVtx(const ImVec2& pos, ImU32 col)
{
vtx_write->pos = pos;
vtx_write->col = col;
vtx_write->uv = IMGUI_FONT_TEX_UV_FOR_WHITE;
vtx_write->uv = GImGui.IO.FontTexUvForWhite;
vtx_write++;
}
void ImDrawList::AddVtxLine(const ImVec2& a, const ImVec2& b, ImU32 col)
{
const ImVec2 n = (b - a) / ImLength(b - a);
const ImVec2 hn = ImVec2(n.y, -n.x) * 0.5f;
const float offset = GImGui.IO.PixelCenterOffset;
const ImVec2 hn = (b - a) * (0.50f / ImLength(b - a)); // half normal
const ImVec2 hp0 = ImVec2(offset - hn.y, offset + hn.x); // half perpendiculars + user offset
const ImVec2 hp1 = ImVec2(offset + hn.y, offset - hn.x);
AddVtx(a - hn, col);
AddVtx(b - hn, col);
AddVtx(a + hn, col);
AddVtx(b - hn, col);
AddVtx(b + hn, col);
AddVtx(a + hn, col);
// Two triangles makes up one line. Using triangles allows us to make draw calls.
AddVtx(a + hp0, col);
AddVtx(b + hp0, col);
AddVtx(a + hp1, col);
AddVtx(b + hp0, col);
AddVtx(b + hp1, col);
AddVtx(a + hp1, col);
}
void ImDrawList::AddLine(const ImVec2& a, const ImVec2& b, ImU32 col)
@ -4833,7 +4862,7 @@ void ImDrawList::AddArc(const ImVec2& center, float rad, ImU32 col, int a_min, i
if (tris)
{
ReserveVertices((a_max-a_min) * 3);
ReserveVertices((unsigned int)(a_max-a_min) * 3);
for (int a = a_min; a < a_max; a++)
{
AddVtx(center + circle_vtx[a % IM_ARRAYSIZE(circle_vtx)] * rad, col);
@ -4843,7 +4872,7 @@ void ImDrawList::AddArc(const ImVec2& center, float rad, ImU32 col, int a_min, i
}
else
{
ReserveVertices((a_max-a_min) * 6);
ReserveVertices((unsigned int)(a_max-a_min) * 6);
for (int a = a_min; a < a_max; a++)
AddVtxLine(center + circle_vtx[a % IM_ARRAYSIZE(circle_vtx)] * rad, center + circle_vtx[(a+1) % IM_ARRAYSIZE(circle_vtx)] * rad, col);
}
@ -4943,10 +4972,12 @@ void ImDrawList::AddTriangleFilled(const ImVec2& a, const ImVec2& b, const ImVec
if ((col >> 24) == 0)
return;
const ImVec2 offset(GImGui.IO.PixelCenterOffset,GImGui.IO.PixelCenterOffset);
ReserveVertices(3);
AddVtx(a, col);
AddVtx(b, col);
AddVtx(c, col);
AddVtx(a + offset, col);
AddVtx(b + offset, col);
AddVtx(c + offset, col);
}
void ImDrawList::AddCircle(const ImVec2& centre, float radius, ImU32 col, int num_segments)
@ -4954,13 +4985,15 @@ void ImDrawList::AddCircle(const ImVec2& centre, float radius, ImU32 col, int nu
if ((col >> 24) == 0)
return;
ReserveVertices(num_segments*6);
const ImVec2 offset(GImGui.IO.PixelCenterOffset,GImGui.IO.PixelCenterOffset);
ReserveVertices((unsigned int)num_segments*6);
const float a_step = 2*PI/(float)num_segments;
float a0 = 0.0f;
for (int i = 0; i < num_segments; i++)
{
const float a1 = (i + 1) == num_segments ? 0.0f : a0 + a_step;
AddVtxLine(centre + ImVec2(cos(a0),sin(a0))*radius, centre + ImVec2(cos(a1),sin(a1))*radius, col);
AddVtxLine(centre + offset + ImVec2(cos(a0),sin(a0))*radius, centre + ImVec2(cos(a1),sin(a1))*radius, col);
a0 = a1;
}
}
@ -4970,15 +5003,17 @@ void ImDrawList::AddCircleFilled(const ImVec2& centre, float radius, ImU32 col,
if ((col >> 24) == 0)
return;
ReserveVertices(num_segments*3);
const ImVec2 offset(GImGui.IO.PixelCenterOffset,GImGui.IO.PixelCenterOffset);
ReserveVertices((unsigned int)num_segments*3);
const float a_step = 2*PI/(float)num_segments;
float a0 = 0.0f;
for (int i = 0; i < num_segments; i++)
{
const float a1 = (i + 1) == num_segments ? 0.0f : a0 + a_step;
AddVtx(centre + ImVec2(cos(a0),sin(a0))*radius, col);
AddVtx(centre + ImVec2(cos(a1),sin(a1))*radius, col);
AddVtx(centre, col);
AddVtx(centre + offset + ImVec2(cos(a0),sin(a0))*radius, col);
AddVtx(centre + offset + ImVec2(cos(a1),sin(a1))*radius, col);
AddVtx(centre + offset, col);
a0 = a1;
}
}
@ -4992,17 +5027,17 @@ void ImDrawList::AddText(ImFont font, float font_size, const ImVec2& pos, ImU32
text_end = text_begin + strlen(text_begin);
// reserve vertices for worse case
const int char_count = (int)(text_end - text_begin);
const int vtx_count_max = char_count * 6;
const unsigned int char_count = (unsigned int)(text_end - text_begin);
const unsigned int vtx_count_max = char_count * 6;
const size_t vtx_begin = vtx_buffer.size();
ReserveVertices(vtx_count_max);
font->RenderText(font_size, pos, col, clip_rect_stack.back(), text_begin, text_end, vtx_write);
// give unused vertices
vtx_buffer.resize(vtx_write - &vtx_buffer.front());
const int vtx_count = (int)(vtx_buffer.size() - vtx_begin);
commands.back().vtx_count -= (vtx_count_max - vtx_count);
// give back unused vertices
vtx_buffer.resize((size_t)(vtx_write - &vtx_buffer.front()));
const size_t vtx_count = vtx_buffer.size() - vtx_begin;
commands.back().vtx_count -= (unsigned int)(vtx_count_max - vtx_count);
vtx_write -= (vtx_count_max - vtx_count);
}
@ -5013,11 +5048,14 @@ void ImDrawList::AddText(ImFont font, float font_size, const ImVec2& pos, ImU32
ImBitmapFont::ImBitmapFont()
{
Data = NULL;
DataSize = 0;
DataOwned = false;
Info = NULL;
Common = NULL;
Glyphs = NULL;
GlyphsCount = 0;
Kerning = NULL;
KerningCount = 0;
TabCount = 4;
}
@ -5043,8 +5081,10 @@ bool ImBitmapFont::LoadFromFile(const char* filename)
return false;
if (fseek(f, 0, SEEK_END))
return false;
if ((DataSize = (int)ftell(f)) == -1)
const long f_size = ftell(f);
if (f_size == -1)
return false;
DataSize = (size_t)f_size;
if (fseek(f, 0, SEEK_SET))
return false;
if ((Data = (unsigned char*)malloc(DataSize)) == NULL)
@ -5052,7 +5092,7 @@ bool ImBitmapFont::LoadFromFile(const char* filename)
fclose(f);
return false;
}
if ((int)fread(Data, 1, DataSize, f) != DataSize)
if (fread(Data, 1, DataSize, f) != DataSize)
{
fclose(f);
free(Data);
@ -5063,7 +5103,7 @@ bool ImBitmapFont::LoadFromFile(const char* filename)
return LoadFromMemory(Data, DataSize);
}
bool ImBitmapFont::LoadFromMemory(const void* data, int data_size)
bool ImBitmapFont::LoadFromMemory(const void* data, size_t data_size)
{
Data = (unsigned char*)data;
DataSize = data_size;
@ -5203,13 +5243,11 @@ void ImBitmapFont::RenderText(float size, ImVec2 pos, ImU32 col, const ImVec4& c
const float outline = (float)Info->Outline;
// Align to be pixel perfect
pos.x = (float)(int)pos.x + 0.5f;
pos.y = (float)(int)pos.y + 0.5f;
pos.x = (float)(int)pos.x;
pos.y = (float)(int)pos.y;
const ImVec4 clip_rect = clip_rect_ref;
const float uv_offset = GImGui.IO.PixelCenterOffset;
float x = pos.x;
float y = pos.y;
for (const char* s = text_begin; s < text_end; s++)
@ -5246,10 +5284,10 @@ void ImBitmapFont::RenderText(float size, ImVec2 pos, ImU32 col, const ImVec4& c
continue;
}
const float s1 = (uv_offset + glyph->X) * tex_scale_x;
const float t1 = (uv_offset + glyph->Y) * tex_scale_y;
const float s2 = (uv_offset + glyph->X + glyph->Width) * tex_scale_x;
const float t2 = (uv_offset + glyph->Y + glyph->Height) * tex_scale_y;
const float s1 = (glyph->X) * tex_scale_x;
const float t1 = (glyph->Y) * tex_scale_y;
const float s2 = (glyph->X + glyph->Width) * tex_scale_x;
const float t2 = (glyph->Y + glyph->Height) * tex_scale_y;
out_vertices[0].pos = ImVec2(x1, y1);
out_vertices[0].uv = ImVec2(s1, t1);
@ -5351,9 +5389,9 @@ static void SetClipboardTextFn_DefaultImpl(const char* text, const char* text_en
}
if (!text_end)
text_end = text + strlen(text);
GImGui.PrivateClipboard = (char*)malloc(text_end - text + 1);
memcpy(GImGui.PrivateClipboard, text, text_end - text);
GImGui.PrivateClipboard[text_end - text] = 0;
GImGui.PrivateClipboard = (char*)malloc((size_t)(text_end - text) + 1);
memcpy(GImGui.PrivateClipboard, text, (size_t)(text_end - text));
GImGui.PrivateClipboard[(size_t)(text_end - text)] = 0;
}
#endif
@ -5405,9 +5443,24 @@ void ShowStyleEditor(ImGuiStyle* ref)
*ref = g.Style;
}
ImGui::SliderFloat("Alpha", &style.Alpha, 0.20f, 1.0f, "%.2f"); // Not exposing zero here so user doesn't "lose" the UI. But application code could have a toggle to switch between zero and non-zero.
ImGui::SliderFloat("Rounding", &style.WindowRounding, 0.0f, 16.0f, "%.0f");
ImGui::PushItemWidth(ImGui::GetWindowWidth()*0.55f);
if (ImGui::TreeNode("Sizes"))
{
ImGui::SliderFloat("Alpha", &style.Alpha, 0.20f, 1.0f, "%.2f"); // Not exposing zero here so user doesn't "lose" the UI. But application code could have a toggle to switch between zero and non-zero.
ImGui::SliderFloat2("WindowPadding", (float*)&style.WindowPadding, 0.0f, 20.0f, "%.0f");
ImGui::SliderFloat("WindowRounding", &style.WindowRounding, 0.0f, 16.0f, "%.0f");
ImGui::SliderFloat2("FramePadding", (float*)&style.FramePadding, 0.0f, 20.0f, "%.0f");
ImGui::SliderFloat2("ItemSpacing", (float*)&style.ItemSpacing, 0.0f, 20.0f, "%.0f");
ImGui::SliderFloat2("ItemInnerSpacing", (float*)&style.ItemInnerSpacing, 0.0f, 20.0f, "%.0f");
ImGui::SliderFloat2("TouchExtraPadding", (float*)&style.TouchExtraPadding, 0.0f, 20.0f, "%.0f");
ImGui::SliderFloat("TreeNodeSpacing", &style.TreeNodeSpacing, 0.0f, 20.0f, "%.0f");
ImGui::SliderFloat("ScrollBarWidth", &style.ScrollBarWidth, 0.0f, 20.0f, "%.0f");
ImGui::TreePop();
}
if (ImGui::TreeNode("Colors"))
{
static ImGuiColorEditMode edit_mode = ImGuiColorEditMode_RGB;
ImGui::RadioButton("RGB", &edit_mode, ImGuiColorEditMode_RGB);
ImGui::SameLine();
@ -5433,6 +5486,10 @@ void ShowStyleEditor(ImGuiStyle* ref)
}
ImGui::PopID();
}
ImGui::TreePop();
}
ImGui::PopItemWidth();
}
//-----------------------------------------------------------------------------
@ -5449,7 +5506,7 @@ void ShowTestWindow(bool* open)
static bool no_scrollbar = false;
static float fill_alpha = 0.65f;
const ImU32 layout_flags = (no_titlebar ? ImGuiWindowFlags_NoTitleBar : 0) | (no_border ? 0 : ImGuiWindowFlags_ShowBorders) | (no_resize ? ImGuiWindowFlags_NoResize : 0) | (no_move ? ImGuiWindowFlags_NoMove : 0) | (no_scrollbar ? ImGuiWindowFlags_NoScrollbar : 0);
const ImGuiWindowFlags layout_flags = (no_titlebar ? ImGuiWindowFlags_NoTitleBar : 0) | (no_border ? 0 : ImGuiWindowFlags_ShowBorders) | (no_resize ? ImGuiWindowFlags_NoResize : 0) | (no_move ? ImGuiWindowFlags_NoMove : 0) | (no_scrollbar ? ImGuiWindowFlags_NoScrollbar : 0);
ImGui::Begin("ImGui Test", open, ImVec2(550,680), fill_alpha, layout_flags);
ImGui::PushItemWidth(ImGui::GetWindowWidth() * 0.65f);
@ -5465,10 +5522,10 @@ void ShowTestWindow(bool* open)
if (ImGui::CollapsingHeader("Window options"))
{
ImGui::Checkbox("no titlebar", &no_titlebar); ImGui::SameLine(200);
ImGui::Checkbox("no border", &no_border); ImGui::SameLine(400);
ImGui::Checkbox("no titlebar", &no_titlebar); ImGui::SameLine(150);
ImGui::Checkbox("no border", &no_border); ImGui::SameLine(300);
ImGui::Checkbox("no resize", &no_resize);
ImGui::Checkbox("no move", &no_move); ImGui::SameLine(200);
ImGui::Checkbox("no move", &no_move); ImGui::SameLine(150);
ImGui::Checkbox("no scrollbar", &no_scrollbar);
ImGui::SliderFloat("fill alpha", &fill_alpha, 0.0f, 1.0f);
if (ImGui::TreeNode("Style Editor"))
@ -5551,6 +5608,9 @@ void ShowTestWindow(bool* open)
ImGui::EndTooltip();
}
ImGui::Separator();
ImGui::Text("^ Horizontal separator");
static int item = 1;
ImGui::Combo("combo", &item, "aaaa\0bbbb\0cccc\0dddd\0eeee\0\0");
@ -5614,7 +5674,7 @@ void ShowTestWindow(bool* open)
static bool pause;
static ImVector<float> values; if (values.empty()) { values.resize(100); memset(&values.front(), 0, values.size()*sizeof(float)); }
static int values_offset = 0;
static size_t values_offset = 0;
if (!pause)
{
// create dummy data at 60 hz
@ -5628,7 +5688,7 @@ void ShowTestWindow(bool* open)
phase += 0.10f*values_offset;
}
}
ImGui::PlotLines("Frame Times", &values.front(), (int)values.size(), values_offset, "avg 0.0", -1.0f, 1.0f, ImVec2(0,70));
ImGui::PlotLines("Frame Times", &values.front(), (int)values.size(), (int)values_offset, "avg 0.0", -1.0f, 1.0f, ImVec2(0,70));
ImGui::SameLine(); ImGui::Checkbox("pause", &pause);
ImGui::PlotHistogram("Histogram", arr, IM_ARRAYSIZE(arr), 0, NULL, 0.0f, 1.0f, ImVec2(0,70));
@ -5818,6 +5878,11 @@ void ShowTestWindow(bool* open)
if (ImGui::CollapsingHeader("Filtering"))
{
static ImGuiTextFilter filter;
ImGui::Text("Filter usage:\n"
" \"\" display all lines\n"
" \"xxx\" display lines containing \"xxx\"\n"
" \"xxx,yyy\" display lines containing \"xxx\" or \"yyy\"\n"
" \"-xxx\" hide lines containing \"xxx\"");
filter.Draw();
const char* lines[] = { "aaa1.c", "bbb1.c", "ccc1.c", "aaa2.cpp", "bbb2.cpp", "ccc2.cpp", "abc.h", "hello, world" };
for (size_t i = 0; i < IM_ARRAYSIZE(lines); i++)
@ -5835,7 +5900,7 @@ void ShowTestWindow(bool* open)
ImGui::SameLine();
if (ImGui::Button("Add 1000 lines"))
{
for (size_t i = 0; i < 1000; i++)
for (int i = 0; i < 1000; i++)
log.append("%i The quick brown fox jumps over the lazy dog\n", lines+i);
lines += 1000;
}
@ -5852,7 +5917,8 @@ void ShowTestWindow(bool* open)
//-----------------------------------------------------------------------------
// Font data
// Bitmap exported from proggy_clean.fon (c) by Tristan Grimmer http://www.proggyfonts.net
// Bitmap exported from proggy_clean.fon (c) by Tristan Grimmer http://upperbounds.net/
// Also available on unofficial ProggyFonts mirror http://www.proggyfonts.net
//-----------------------------------------------------------------------------
/*
// Copyright (c) 2004, 2005 Tristan Grimmer

21
imgui.h
View File

@ -107,7 +107,7 @@ public:
// Helpers at bottom of the file:
// - if (IMGUI_ONCE_UPON_A_FRAME) // Execute a block of code once per frame only
// - struct ImGuiTextFilter // Parse and apply text filter. In format "aaaaa[,bbbb][,ccccc]"
// - struct ImGuiTextFilter // Parse and apply text filters. In format "aaaaa[,bbbb][,ccccc]"
// - struct ImGuiTextBuffer // Text buffer for logging/accumulating text
// - struct ImGuiStorage // Custom key value storage (if you need to alter open/close states manually)
// - struct ImDrawList // Draw command list
@ -166,8 +166,9 @@ namespace ImGui
float GetColumnOffset(int column_index = -1);
void SetColumnOffset(int column_index, float offset);
float GetColumnWidth(int column_index = -1);
ImVec2 GetCursorPos(); // cursor position is relative to window position
ImVec2 GetCursorPos(); // cursor position relative to window position
void SetCursorPos(const ImVec2& pos); // "
ImVec2 GetCursorScreenPos(); // cursor position in screen space
void AlignFirstTextHeightToWidgets(); // call once if the first item on the line is a Text() item and you want to vertically lower it to match higher widgets.
float GetTextLineSpacing();
float GetTextLineHeight();
@ -251,6 +252,7 @@ namespace ImGui
int GetFrameCount();
const char* GetStyleColorName(ImGuiCol idx);
void GetDefaultFontData(const void** fnt_data, unsigned int* fnt_size, const void** png_data, unsigned int* png_size);
ImVec2 CalcTextSize(const char* text, const char* text_end = NULL, const bool hide_text_after_hash = true);
}; // namespace ImGui
@ -388,8 +390,9 @@ struct ImGuiIO
int KeyMap[ImGuiKey_COUNT]; // <unset> // Map of indices into the KeysDown[512] entries array
ImFont Font; // <auto> // Gets passed to text functions. Typedef ImFont to the type you want (ImBitmapFont* or your own font).
float FontHeight; // <auto> // Default font height, must be the vertical distance between two lines of text, aka == CalcTextSize(" ").y
ImVec2 FontTexUvForWhite; // = (0.0f,0.0f) // Font texture must have a white pixel at this UV coordinate. Adjust if you are using custom texture.
bool FontAllowScaling; // = false // Set to allow scaling text with CTRL+Wheel.
float PixelCenterOffset; // = 0.5f // Set to 0.0f for DirectX <= 9, 0.5f for Direct3D >= 10 and OpenGL.
float PixelCenterOffset; // = 0.0f // Try to set to 0.5f or 0.375f if rendering is blurry
// Settings - Rendering function (REQUIRED)
// See example code if you are unsure of how to implement this.
@ -447,7 +450,7 @@ private:
bool TryIsNewFrame() const { const int current_frame = ImGui::GetFrameCount(); if (LastFrame == current_frame) return false; LastFrame = current_frame; return true; }
};
// Helper: Parse and apply text filter. In format "aaaaa[,bbbb][,ccccc]"
// Helper: Parse and apply text filters. In format "aaaaa[,bbbb][,ccccc]"
struct ImGuiTextFilter
{
struct TextRange
@ -461,7 +464,7 @@ struct ImGuiTextFilter
const char* end() const { return e; }
bool empty() const { return b == e; }
char front() const { return *b; }
static bool isblank(char c) { return c == ' ' && c == '\t'; }
static bool isblank(char c) { return c == ' ' || c == '\t'; }
void trim_blanks() { while (b < e && isblank(*b)) b++; while (e > b && isblank(*(e-1))) e--; }
void split(char separator, ImVector<TextRange>& out);
};
@ -522,10 +525,6 @@ struct ImDrawCmd
ImVec4 clip_rect;
};
#ifndef IMGUI_FONT_TEX_UV_FOR_WHITE
#define IMGUI_FONT_TEX_UV_FOR_WHITE ImVec2(0.f,0.f)
#endif
// sizeof() == 20
struct ImDrawVert
{
@ -620,7 +619,7 @@ struct ImBitmapFont
#pragma pack(pop)
unsigned char* Data; // Raw data, content of .fnt file
int DataSize; //
size_t DataSize; //
bool DataOwned; //
const FntInfo* Info; // (point into raw data)
const FntCommon* Common; // (point into raw data)
@ -635,7 +634,7 @@ struct ImBitmapFont
ImBitmapFont();
~ImBitmapFont() { Clear(); }
bool LoadFromMemory(const void* data, int data_size);
bool LoadFromMemory(const void* data, size_t data_size);
bool LoadFromFile(const char* filename);
void Clear();
void BuildLookupTable();

View File

@ -1,4 +1,4 @@
// stb_textedit.h - v1.3 - public domain - Sean Barrett
// stb_textedit.h - v1.4 - public domain - Sean Barrett
// Development of this library was sponsored by RAD Game Tools
//
// This C header file implements the guts of a multi-line text-editing
@ -30,8 +30,9 @@
//
// VERSION HISTORY
//
// 1.3 (2013-06-19) fix mouse clicking to round to nearest char boundary
// 1.2 (2013-05-27) fix some RAD types that had crept into the new code
// 1.4 (2014-08-17) fix signed/unsigned warnings
// 1.3 (2014-06-19) fix mouse clicking to round to nearest char boundary
// 1.2 (2014-05-27) fix some RAD types that had crept into the new code
// 1.1 (2013-12-15) move-by-word (requires STB_TEXTEDIT_IS_SPACE )
// 1.0 (2012-07-26) improve documentation, initial public release
// 0.3 (2012-02-24) bugfixes, single-line mode; insert mode
@ -41,7 +42,7 @@
// ADDITIONAL CONTRIBUTORS
//
// Ulf Winklemann: move-by-word in 1.1
// Scott Graham: mouse selectiom bugfix in 1.3
// Scott Graham: mouse selection bugfix in 1.3
//
// USAGE
//
@ -445,7 +446,7 @@ static void stb_textedit_drag(STB_TEXTEDIT_STRING *str, STB_TexteditState *state
static void stb_text_undo(STB_TEXTEDIT_STRING *str, STB_TexteditState *state);
static void stb_text_redo(STB_TEXTEDIT_STRING *str, STB_TexteditState *state);
static void stb_text_makeundo_delete(STB_TEXTEDIT_STRING *str, STB_TexteditState *state, int where, int length);
static void stb_text_makeundo_insert(STB_TEXTEDIT_STRING *str, STB_TexteditState *state, int where, int length);
static void stb_text_makeundo_insert(STB_TexteditState *state, int where, int length);
static void stb_text_makeundo_replace(STB_TEXTEDIT_STRING *str, STB_TexteditState *state, int where, int old_length, int new_length);
typedef struct
@ -649,7 +650,7 @@ static int stb_textedit_paste(STB_TEXTEDIT_STRING *str, STB_TexteditState *state
stb_textedit_delete_selection(str,state);
// try to insert the characters
if (STB_TEXTEDIT_INSERTCHARS(str, state->cursor, text, len)) {
stb_text_makeundo_insert(str, state, state->cursor, len);
stb_text_makeundo_insert(state, state->cursor, len);
state->cursor += len;
state->has_preferred_x = 0;
return 1;
@ -684,7 +685,7 @@ retry:
} else {
stb_textedit_delete_selection(str,state); // implicity clamps
if (STB_TEXTEDIT_INSERTCHARS(str, state->cursor, &ch, 1)) {
stb_text_makeundo_insert(str, state, state->cursor, 1);
stb_text_makeundo_insert(state, state->cursor, 1);
++state->cursor;
state->has_preferred_x = 0;
}
@ -1007,13 +1008,13 @@ static void stb_textedit_discard_undo(StbUndoState *state)
int n = state->undo_rec[0].insert_length, i;
// delete n characters from all other records
state->undo_char_point = state->undo_char_point - (short) n; // vsnet05
memmove(state->undo_char, state->undo_char + n, state->undo_char_point*sizeof(STB_TEXTEDIT_CHARTYPE));
memmove(state->undo_char, state->undo_char + n, (size_t) (state->undo_char_point*sizeof(STB_TEXTEDIT_CHARTYPE)));
for (i=0; i < state->undo_point; ++i)
if (state->undo_rec[i].char_storage >= 0)
state->undo_rec[i].char_storage = state->undo_rec[i].char_storage - (short) n; // vsnet05 // @OPTIMIZE: get rid of char_storage and infer it
}
--state->undo_point;
memmove(state->undo_rec, state->undo_rec+1, state->undo_point*sizeof(state->undo_rec[0]));
memmove(state->undo_rec, state->undo_rec+1, (size_t) (state->undo_point*sizeof(state->undo_rec[0])));
}
}
@ -1031,13 +1032,13 @@ static void stb_textedit_discard_redo(StbUndoState *state)
int n = state->undo_rec[k].insert_length, i;
// delete n characters from all other records
state->redo_char_point = state->redo_char_point + (short) n; // vsnet05
memmove(state->undo_char + state->redo_char_point, state->undo_char + state->redo_char_point-n, (STB_TEXTEDIT_UNDOSTATECOUNT - state->redo_char_point)*sizeof(STB_TEXTEDIT_CHARTYPE));
memmove(state->undo_char + state->redo_char_point, state->undo_char + state->redo_char_point-n, (size_t) ((STB_TEXTEDIT_UNDOSTATECOUNT - state->redo_char_point)*sizeof(STB_TEXTEDIT_CHARTYPE)));
for (i=state->redo_point; i < k; ++i)
if (state->undo_rec[i].char_storage >= 0)
state->undo_rec[i].char_storage = state->undo_rec[i].char_storage + (short) n; // vsnet05
}
++state->redo_point;
memmove(state->undo_rec + state->redo_point-1, state->undo_rec + state->redo_point, (STB_TEXTEDIT_UNDOSTATECOUNT - state->redo_point)*sizeof(state->undo_rec[0]));
memmove(state->undo_rec + state->redo_point-1, state->undo_rec + state->redo_point, (size_t) ((STB_TEXTEDIT_UNDOSTATECOUNT - state->redo_point)*sizeof(state->undo_rec[0])));
}
}
@ -1203,7 +1204,7 @@ static void stb_text_redo(STB_TEXTEDIT_STRING *str, STB_TexteditState *state)
s->redo_point++;
}
static void stb_text_makeundo_insert(STB_TEXTEDIT_STRING *str, STB_TexteditState *state, int where, int length)
static void stb_text_makeundo_insert(STB_TexteditState *state, int where, int length)
{
stb_text_createundo(&state->undostate, where, 0, length);
}

BIN
web/skinning_sample_01.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB