Compare commits
151 Commits
Author | SHA1 | Date | |
---|---|---|---|
618a42acf8 | |||
3cd1b8a37b | |||
746951691a | |||
8eafb373f7 | |||
fec4232c79 | |||
85672fec2e | |||
d5ed586d70 | |||
d58a029285 | |||
6e039c8b7d | |||
05a42ba3a6 | |||
da2ccf0a78 | |||
3e647d86aa | |||
0e0cd5e705 | |||
8d32fcb7d4 | |||
4ea2af7ea5 | |||
3773fb4117 | |||
24028911e3 | |||
3fd68c3a31 | |||
1cf4b313e2 | |||
2e85dce1ee | |||
62d233aaab | |||
3cdb4fa456 | |||
7439df0ba1 | |||
ad42787543 | |||
91059da1a5 | |||
b420a51541 | |||
c07ab1b56a | |||
22a9555a99 | |||
25080d53e5 | |||
43448d9c89 | |||
e20077fbd0 | |||
2c677c45c7 | |||
3b339efeb2 | |||
8fc50f5ed3 | |||
dd5d251273 | |||
2fb63b6068 | |||
cd3d027df0 | |||
7adad71042 | |||
88c33ecc29 | |||
1f63e01cc6 | |||
bd26de0628 | |||
5a9639b423 | |||
b90d0c558d | |||
51f8e33eb4 | |||
80dd1e1065 | |||
5f6b261c9b | |||
681ac5f777 | |||
0d344e1f03 | |||
d2b43f31e3 | |||
d17a586738 | |||
710b9b68b1 | |||
29ba288ea0 | |||
addfa75eb0 | |||
882072cf30 | |||
7bd507d266 | |||
1ff104641a | |||
3b8d1ec207 | |||
e9e1fd2b3c | |||
6062d18cf9 | |||
05f0993616 | |||
6dd2b13220 | |||
5864c45fe3 | |||
4bc3642bdb | |||
a3f32381c4 | |||
67f17a644c | |||
e807d97089 | |||
23d156908d | |||
42d4b4be6a | |||
efc473df98 | |||
bbda899801 | |||
a17885f470 | |||
7de89e0da3 | |||
7c61822d26 | |||
ca027e1754 | |||
c5dacee3a7 | |||
d6f6afabb3 | |||
76a39ad224 | |||
aa7fc37b37 | |||
c13c2449bb | |||
c2cb727ac9 | |||
47fd8431c1 | |||
926f7bfcc5 | |||
f6414f2011 | |||
931a4c5b49 | |||
c32221fa20 | |||
a165954a69 | |||
ddf8b280e9 | |||
969b1e0563 | |||
6e15b71663 | |||
ef628a0a9d | |||
df5a06f119 | |||
e9b697698a | |||
5240013c90 | |||
1956703c42 | |||
f5dbb0a973 | |||
ade21a1ad5 | |||
868ba05a13 | |||
152878571e | |||
fa0aa5ace6 | |||
6267905a17 | |||
1509b8f634 | |||
2bc6346b48 | |||
9169b2911c | |||
a4b96445e8 | |||
6c11d7623e | |||
6d6ee4e1f1 | |||
f33eb89018 | |||
e9b0a61f48 | |||
a8d3b045b7 | |||
a830037eab | |||
309ff44579 | |||
f30d23a502 | |||
a905505cca | |||
46eee0cee4 | |||
29863b55ef | |||
530f103dfe | |||
7a3e6aa38d | |||
cda3aecc6a | |||
b6d1d85d86 | |||
9a426faf4f | |||
b0d5600ffb | |||
c52a54ef43 | |||
cc9d63b46a | |||
d3ad5ce475 | |||
cb3d503941 | |||
ddc7f8b0b0 | |||
57ac561ecb | |||
2573ffb6fc | |||
c938affcac | |||
a1e176fb07 | |||
901e9890d4 | |||
f4ee74b312 | |||
64e5c2f127 | |||
e2655d104e | |||
8825545653 | |||
150ad95bd6 | |||
ab8561e6fc | |||
2a1ba33263 | |||
4fa623c43b | |||
080eb69e68 | |||
1b330f420e | |||
28df6f39d9 | |||
98a000055e | |||
e3001fb986 | |||
4020ef7b58 | |||
86d2c9d232 | |||
8ab2942716 | |||
680a5a9b54 | |||
900dd3bd0f | |||
678f6d3a3d | |||
42419b59c0 |
14
.gitignore
vendored
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
## Visual Studio files
|
||||||
|
examples/directx9_example/Debug/*
|
||||||
|
examples/directx9_example/Release/*
|
||||||
|
examples/directx9_example/ipch/*
|
||||||
|
examples/opengl_example/Debug/*
|
||||||
|
examples/opengl_example/Release/*
|
||||||
|
examples/opengl_example/ipch/*
|
||||||
|
*.opensdf
|
||||||
|
*.sdf
|
||||||
|
*.suo
|
||||||
|
*.vcxproj.user
|
||||||
|
|
||||||
|
## Ini files
|
||||||
|
imgui.ini
|
48
README.md
@ -1,16 +1,19 @@
|
|||||||
ImGui
|
ImGui
|
||||||
=====
|
=====
|
||||||
|
|
||||||
ImGui is a bloat-free graphical user interface library for C/C++. It is portable, renderer agnostic and carries minimal amount of dependencies (only 3 files are needed). It is based on an "immediate" graphical user interface paradigm which allows you to build simple user interfaces with ease.
|
ImGui is a bloat-free graphical user interface library for C++. It outputs vertex buffers that you can render in your 3D-pipeline enabled application. It is portable, renderer agnostic and carries minimal amount of dependencies (only 3 files are needed). It is based on an "immediate" graphical user interface paradigm which allows you to build simple user interfaces with ease.
|
||||||
|
|
||||||
ImGui is designed to allow programmers to create "content creation" or "debug" tools (as opposed to tools for the average end-user). It favors simplicity and thus lacks certain features normally found in more high-level libraries, such as string localisation.
|
ImGui is designed to enable fast iteration and allow programmers to create "content creation" or "debug" tools (as opposed to tools for the average end-user). It favors simplicity and thus lacks certain features normally found in more high-level libraries, such as string localisation.
|
||||||
|
|
||||||
Usage example:
|
ImGui is particularly suited to integration in 3D applications, fullscreen applications, embedded applications, games, or any applications on consoles platforms where operating system features are non-standard.
|
||||||
|
|
||||||
|
After ImGui is setup in your engine, you can use it like in this example:
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
ImGui outputs vertex buffers and simple command-lists that you can render in your application. Because it doesn't know or touch graphics state directly, you can call ImGui commands anywhere in your code (e.g. in the middle of a running algorithm, or in the middle of your own rendering process). Refer to the sample applications in the examples/ folder for instructions on how to integrate ImGui with your existing codebase.
|
ImGui outputs vertex buffers and simple command-lists that you can render in your application. Because it doesn't know or touch graphics state directly, you can call ImGui commands anywhere in your code (e.g. in the middle of a running algorithm, or in the middle of your own rendering process). Refer to the sample applications in the examples/ folder for instructions on how to integrate ImGui with your existing codebase.
|
||||||
|
|
||||||
|
ImGui allows you create elaborate tools as well as very short-lived ones. On the extreme side of short-liveness: using the Edit&Continue feature of compilers you can add a few widgets to tweaks variables while your application is running, and remove the code a minute later! ImGui is not just for tweaking values. You can use it to trace a running algorithm by just emitting text commands. You can use it along with your own reflection data to browse your dataset live. You can use it to expose the internals of a subsystem in your engine, to create a logger, an inspection tool, a profiler, a debugger, etc.
|
||||||
|
|
||||||
Gallery
|
Gallery
|
||||||
-------
|
-------
|
||||||
@ -20,14 +23,49 @@ Gallery
|
|||||||

|

|
||||||

|

|
||||||
|
|
||||||
|
References
|
||||||
|
----------
|
||||||
|
|
||||||
|
The Immediate Mode GUI paradigm may at first appear unusual to some users. This is mainly because "Retained Mode" GUIs have been so widespread and predominant. The following links can give you a better understanding about how Immediate Mode GUIs works.
|
||||||
|
- [Johannes 'johno' Norneby's article](http://www.johno.se/book/imgui.html).
|
||||||
|
- [A presentation by Rickard Gustafsson and Johannes Algelind](http://www.cse.chalmers.se/edu/year/2011/course/TDA361/Advanced%20Computer%20Graphics/IMGUI.pdf).
|
||||||
|
- [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). With the uSynergy.c micro client running you can seamlessly use your PC input devices from a video game console or a tablet. ImGui was also designed to function with touch inputs if you increase the padding of widgets to compensate for the lack of precision of touch devices, but it is recommended you use a mouse to allow optimising for screen real-estate.
|
||||||
|
|
||||||
|
<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:
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
<b>Can you develop features xxxx for ImGui?</b>
|
||||||
|
|
||||||
|
Please use GitHub 'Issues' facilities to suggest and discuss improvements. If you are company and would like specific non-trivial features to be implemented, I am available for hire to work on or with ImGui. Donations are also welcome to support further work on the library.
|
||||||
|
|
||||||
|
|
||||||
Credits
|
Credits
|
||||||
-------
|
-------
|
||||||
|
|
||||||
Developed by [Omar Cornut](http://www.miracleworld.net). The library was developed with the support of [Media Molecule](http://www.mediamolecule.com) and first used internally on the game [Tearaway](http://tearaway.mediamolecule.com).
|
Developed by [Omar Cornut](http://www.miracleworld.net). 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, Matt Willis. Thanks!
|
Inspiration, feedback, and testing: Casey Muratori, Atman Binstock, Mikko Mononen, Emmanuel Briney, Stefan Kamoda, Anton Mikhailov, Matt Willis. Thanks!
|
||||||
|
|
||||||
License
|
License
|
||||||
-------
|
-------
|
||||||
|
@ -12,16 +12,18 @@ static LPDIRECT3D9 g_pD3D = NULL; // Used to create the D3DDevice
|
|||||||
static LPDIRECT3DDEVICE9 g_pd3dDevice = NULL; // Our rendering device
|
static LPDIRECT3DDEVICE9 g_pd3dDevice = NULL; // Our rendering device
|
||||||
static LPDIRECT3DVERTEXBUFFER9 g_pVB = NULL; // Buffer to hold vertices
|
static LPDIRECT3DVERTEXBUFFER9 g_pVB = NULL; // Buffer to hold vertices
|
||||||
static LPDIRECT3DTEXTURE9 g_pTexture = NULL; // Our texture
|
static LPDIRECT3DTEXTURE9 g_pTexture = NULL; // Our texture
|
||||||
|
|
||||||
struct CUSTOMVERTEX
|
struct CUSTOMVERTEX
|
||||||
{
|
{
|
||||||
D3DXVECTOR3 position;
|
D3DXVECTOR3 position;
|
||||||
D3DCOLOR color;
|
D3DCOLOR color;
|
||||||
float tu, tv;
|
float tu, tv;
|
||||||
};
|
};
|
||||||
|
|
||||||
#define D3DFVF_CUSTOMVERTEX (D3DFVF_XYZ|D3DFVF_DIFFUSE|D3DFVF_TEX1)
|
#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 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)
|
static void ImImpl_RenderDrawLists(ImDrawList** const cmd_lists, int cmd_lists_count)
|
||||||
{
|
{
|
||||||
size_t total_vtx_count = 0;
|
size_t total_vtx_count = 0;
|
||||||
@ -30,31 +32,13 @@ static void ImImpl_RenderDrawLists(ImDrawList** const cmd_lists, int cmd_lists_c
|
|||||||
if (total_vtx_count == 0)
|
if (total_vtx_count == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
ImVector<ImVec4> clip_rect_stack;
|
// Copy and convert all vertices into a single contiguous buffer
|
||||||
clip_rect_stack.push_back(ImVec4(-9999,-9999,+9999,+9999));
|
|
||||||
|
|
||||||
// Setup orthographic projection
|
|
||||||
// Set up world matrix
|
|
||||||
D3DXMATRIXA16 mat;
|
|
||||||
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);
|
|
||||||
g_pd3dDevice->SetTransform(D3DTS_PROJECTION, &mat);
|
|
||||||
|
|
||||||
D3DSURFACE_DESC texture_desc;
|
|
||||||
g_pTexture->GetLevelDesc(0, &texture_desc);
|
|
||||||
|
|
||||||
// Fill the vertex buffer
|
|
||||||
CUSTOMVERTEX* vtx_dst;
|
CUSTOMVERTEX* vtx_dst;
|
||||||
if (g_pVB->Lock(0, total_vtx_count, (void**)&vtx_dst, D3DLOCK_DISCARD) < 0)
|
if (g_pVB->Lock(0, total_vtx_count, (void**)&vtx_dst, D3DLOCK_DISCARD) < 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
for (int n = 0; n < cmd_lists_count; n++)
|
for (int n = 0; n < cmd_lists_count; n++)
|
||||||
{
|
{
|
||||||
const ImDrawList* cmd_list = cmd_lists[n];
|
const ImDrawList* cmd_list = cmd_lists[n];
|
||||||
if (cmd_list->commands.empty() || cmd_list->vtx_buffer.empty())
|
|
||||||
continue;
|
|
||||||
const ImDrawVert* vtx_src = &cmd_list->vtx_buffer[0];
|
const ImDrawVert* vtx_src = &cmd_list->vtx_buffer[0];
|
||||||
for (size_t i = 0; i < cmd_list->vtx_buffer.size(); i++)
|
for (size_t i = 0; i < cmd_list->vtx_buffer.size(); i++)
|
||||||
{
|
{
|
||||||
@ -73,11 +57,10 @@ static void ImImpl_RenderDrawLists(ImDrawList** const cmd_lists, int cmd_lists_c
|
|||||||
g_pd3dDevice->SetStreamSource( 0, g_pVB, 0, sizeof( CUSTOMVERTEX ) );
|
g_pd3dDevice->SetStreamSource( 0, g_pVB, 0, sizeof( CUSTOMVERTEX ) );
|
||||||
g_pd3dDevice->SetFVF( D3DFVF_CUSTOMVERTEX );
|
g_pd3dDevice->SetFVF( D3DFVF_CUSTOMVERTEX );
|
||||||
|
|
||||||
// Setup render state: alpha-blending enabled, no face culling, no depth testing
|
// Setup render state: alpha-blending, no face culling, no depth testing
|
||||||
g_pd3dDevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_NONE );
|
g_pd3dDevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_NONE );
|
||||||
g_pd3dDevice->SetRenderState( D3DRS_LIGHTING, false );
|
g_pd3dDevice->SetRenderState( D3DRS_LIGHTING, false );
|
||||||
g_pd3dDevice->SetRenderState( D3DRS_ZENABLE, false );
|
g_pd3dDevice->SetRenderState( D3DRS_ZENABLE, false );
|
||||||
|
|
||||||
g_pd3dDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, true );
|
g_pd3dDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, true );
|
||||||
g_pd3dDevice->SetRenderState( D3DRS_BLENDOP, D3DBLENDOP_ADD );
|
g_pd3dDevice->SetRenderState( D3DRS_BLENDOP, D3DBLENDOP_ADD );
|
||||||
g_pd3dDevice->SetRenderState( D3DRS_ALPHATESTENABLE, false );
|
g_pd3dDevice->SetRenderState( D3DRS_ALPHATESTENABLE, false );
|
||||||
@ -94,95 +77,29 @@ static void ImImpl_RenderDrawLists(ImDrawList** const cmd_lists, int cmd_lists_c
|
|||||||
g_pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE );
|
g_pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE );
|
||||||
g_pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE );
|
g_pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE );
|
||||||
|
|
||||||
int vtx_consumed = 0; // offset in vertex buffer. each command consume ImDrawCmd::vtx_count of those
|
// Setup orthographic projection matrix
|
||||||
bool clip_rect_dirty = true;
|
D3DXMATRIXA16 mat;
|
||||||
|
D3DXMatrixIdentity(&mat);
|
||||||
|
g_pd3dDevice->SetTransform(D3DTS_WORLD, &mat);
|
||||||
|
g_pd3dDevice->SetTransform(D3DTS_VIEW, &mat);
|
||||||
|
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
|
||||||
|
int vtx_offset = 0;
|
||||||
for (int n = 0; n < cmd_lists_count; n++)
|
for (int n = 0; n < cmd_lists_count; n++)
|
||||||
{
|
{
|
||||||
|
// Render command list
|
||||||
const ImDrawList* cmd_list = cmd_lists[n];
|
const ImDrawList* cmd_list = cmd_lists[n];
|
||||||
if (cmd_list->commands.empty() || cmd_list->vtx_buffer.empty())
|
const ImDrawCmd* pcmd_end = cmd_list->commands.end();
|
||||||
continue;
|
for (const ImDrawCmd* pcmd = cmd_list->commands.begin(); pcmd != pcmd_end; pcmd++)
|
||||||
const ImDrawCmd* pcmd = &cmd_list->commands.front();
|
|
||||||
const ImDrawCmd* pcmd_end = &cmd_list->commands.back();
|
|
||||||
int clip_rect_buf_consumed = 0; // offset in cmd_list->clip_rect_buffer. each PushClipRect command consume 1 of those.
|
|
||||||
while (pcmd <= pcmd_end)
|
|
||||||
{
|
{
|
||||||
const ImDrawCmd& cmd = *pcmd++;
|
const RECT r = { (LONG)pcmd->clip_rect.x, (LONG)pcmd->clip_rect.y, (LONG)pcmd->clip_rect.z, (LONG)pcmd->clip_rect.w };
|
||||||
switch (cmd.cmd_type)
|
|
||||||
{
|
|
||||||
case ImDrawCmdType_DrawTriangleList:
|
|
||||||
if (clip_rect_dirty)
|
|
||||||
{
|
|
||||||
const ImVec4& clip_rect = clip_rect_stack.back();
|
|
||||||
const RECT r = { (LONG)clip_rect.x, (LONG)clip_rect.y, (LONG)clip_rect.z, (LONG)clip_rect.w };
|
|
||||||
g_pd3dDevice->SetScissorRect(&r);
|
g_pd3dDevice->SetScissorRect(&r);
|
||||||
clip_rect_dirty = false;
|
g_pd3dDevice->DrawPrimitive(D3DPT_TRIANGLELIST, vtx_offset, pcmd->vtx_count/3);
|
||||||
}
|
vtx_offset += pcmd->vtx_count;
|
||||||
g_pd3dDevice->DrawPrimitive(D3DPT_TRIANGLELIST, vtx_consumed, cmd.vtx_count/3);
|
|
||||||
vtx_consumed += cmd.vtx_count;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case ImDrawCmdType_PushClipRect:
|
|
||||||
clip_rect_stack.push_back(cmd_list->clip_rect_buffer[clip_rect_buf_consumed++]);
|
|
||||||
clip_rect_dirty = true;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case ImDrawCmdType_PopClipRect:
|
|
||||||
clip_rect_stack.pop_back();
|
|
||||||
clip_rect_dirty = true;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get text data in Win32 clipboard
|
|
||||||
static const char* ImImpl_GetClipboardTextFn()
|
|
||||||
{
|
|
||||||
static char* buf_local = NULL;
|
|
||||||
if (buf_local)
|
|
||||||
{
|
|
||||||
free(buf_local);
|
|
||||||
buf_local = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!OpenClipboard(NULL))
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
HANDLE buf_handle = GetClipboardData(CF_TEXT);
|
|
||||||
if (buf_handle == NULL)
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
if (char* buf_global = (char*)GlobalLock(buf_handle))
|
|
||||||
buf_local = strdup(buf_global);
|
|
||||||
GlobalUnlock(buf_handle);
|
|
||||||
CloseClipboard();
|
|
||||||
|
|
||||||
return buf_local;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set text data in Win32 clipboard
|
|
||||||
static void ImImpl_SetClipboardTextFn(const char* text, const char* text_end)
|
|
||||||
{
|
|
||||||
if (!OpenClipboard(NULL))
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (!text_end)
|
|
||||||
text_end = text + strlen(text);
|
|
||||||
|
|
||||||
const int buf_length = (text_end - text) + 1;
|
|
||||||
HGLOBAL buf_handle = GlobalAlloc(GMEM_MOVEABLE, buf_length * sizeof(char));
|
|
||||||
if (buf_handle == NULL)
|
|
||||||
return;
|
|
||||||
|
|
||||||
char* buf_global = (char *)GlobalLock(buf_handle);
|
|
||||||
memcpy(buf_global, text, text_end - text);
|
|
||||||
buf_global[text_end - text] = 0;
|
|
||||||
GlobalUnlock(buf_handle);
|
|
||||||
|
|
||||||
EmptyClipboard();
|
|
||||||
SetClipboardData(CF_TEXT, buf_handle);
|
|
||||||
CloseClipboard();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
HRESULT InitD3D(HWND hWnd)
|
HRESULT InitD3D(HWND hWnd)
|
||||||
@ -203,17 +120,6 @@ HRESULT InitD3D(HWND hWnd)
|
|||||||
if (g_pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, D3DCREATE_HARDWARE_VERTEXPROCESSING, &d3dpp, &g_pd3dDevice) < 0)
|
if (g_pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, D3DCREATE_HARDWARE_VERTEXPROCESSING, &d3dpp, &g_pd3dDevice) < 0)
|
||||||
return E_FAIL;
|
return E_FAIL;
|
||||||
|
|
||||||
// Create the vertex buffer.
|
|
||||||
if (g_pd3dDevice->CreateVertexBuffer(10000 * sizeof(CUSTOMVERTEX), D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY, D3DFVF_CUSTOMVERTEX, D3DPOOL_DEFAULT, &g_pVB, NULL) < 0)
|
|
||||||
return E_FAIL;
|
|
||||||
|
|
||||||
// Load font texture
|
|
||||||
const void* png_data;
|
|
||||||
unsigned int png_size;
|
|
||||||
ImGui::GetDefaultFontData(NULL, NULL, &png_data, &png_size);
|
|
||||||
if (D3DXCreateTextureFromFileInMemory(g_pd3dDevice, png_data, png_size, &g_pTexture) < 0)
|
|
||||||
return E_FAIL;
|
|
||||||
|
|
||||||
return S_OK;
|
return S_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -247,9 +153,11 @@ LRESULT WINAPI MsgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
|||||||
io.MouseDown[1] = false;
|
io.MouseDown[1] = false;
|
||||||
return true;
|
return true;
|
||||||
case WM_MOUSEWHEEL:
|
case WM_MOUSEWHEEL:
|
||||||
|
// Mouse wheel: -1,0,+1
|
||||||
io.MouseWheel = GET_WHEEL_DELTA_WPARAM(wParam) > 0 ? +1 : -1;
|
io.MouseWheel = GET_WHEEL_DELTA_WPARAM(wParam) > 0 ? +1 : -1;
|
||||||
return true;
|
return true;
|
||||||
case WM_MOUSEMOVE:
|
case WM_MOUSEMOVE:
|
||||||
|
// Mouse position, in pixels (set to -1,-1 if no mouse / on another screen, etc.)
|
||||||
io.MousePos.x = (signed short)(lParam);
|
io.MousePos.x = (signed short)(lParam);
|
||||||
io.MousePos.y = (signed short)(lParam >> 16);
|
io.MousePos.y = (signed short)(lParam >> 16);
|
||||||
return true;
|
return true;
|
||||||
@ -274,9 +182,10 @@ void InitImGui()
|
|||||||
GetClientRect(hWnd, &rect);
|
GetClientRect(hWnd, &rect);
|
||||||
|
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
io.DisplaySize = ImVec2((float)(rect.right - rect.left), (float)(rect.bottom - rect.top));
|
io.DisplaySize = ImVec2((float)(rect.right - rect.left), (float)(rect.bottom - rect.top)); // Display size, in pixels. For clamping windows positions.
|
||||||
io.DeltaTime = 1.0f/60.0f;
|
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.KeyMap[ImGuiKey_Tab] = VK_TAB;
|
io.PixelCenterOffset = 0.0f; // Align Direct3D Texels
|
||||||
|
io.KeyMap[ImGuiKey_Tab] = VK_TAB; // Keyboard mapping. ImGui will use those indices to peek into the io.KeyDown[] array that we will update during the application lifetime.
|
||||||
io.KeyMap[ImGuiKey_LeftArrow] = VK_LEFT;
|
io.KeyMap[ImGuiKey_LeftArrow] = VK_LEFT;
|
||||||
io.KeyMap[ImGuiKey_RightArrow] = VK_RIGHT;
|
io.KeyMap[ImGuiKey_RightArrow] = VK_RIGHT;
|
||||||
io.KeyMap[ImGuiKey_UpArrow] = VK_UP;
|
io.KeyMap[ImGuiKey_UpArrow] = VK_UP;
|
||||||
@ -295,8 +204,52 @@ void InitImGui()
|
|||||||
io.KeyMap[ImGuiKey_Z] = 'Z';
|
io.KeyMap[ImGuiKey_Z] = 'Z';
|
||||||
|
|
||||||
io.RenderDrawListsFn = ImImpl_RenderDrawLists;
|
io.RenderDrawListsFn = ImImpl_RenderDrawLists;
|
||||||
io.SetClipboardTextFn = ImImpl_SetClipboardTextFn;
|
|
||||||
io.GetClipboardTextFn = ImImpl_GetClipboardTextFn;
|
// Create the vertex buffer
|
||||||
|
if (g_pd3dDevice->CreateVertexBuffer(10000 * sizeof(CUSTOMVERTEX), D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY, D3DFVF_CUSTOMVERTEX, D3DPOOL_DEFAULT, &g_pVB, NULL) < 0)
|
||||||
|
{
|
||||||
|
IM_ASSERT(0);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Load font texture
|
||||||
|
const void* png_data;
|
||||||
|
unsigned int png_size;
|
||||||
|
ImGui::GetDefaultFontData(NULL, NULL, &png_data, &png_size);
|
||||||
|
if (D3DXCreateTextureFromFileInMemory(g_pd3dDevice, png_data, png_size, &g_pTexture) < 0)
|
||||||
|
{
|
||||||
|
IM_ASSERT(0);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
INT64 ticks_per_second = 0;
|
||||||
|
INT64 time = 0;
|
||||||
|
|
||||||
|
void UpdateImGui()
|
||||||
|
{
|
||||||
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
|
|
||||||
|
// Setup timestep
|
||||||
|
INT64 current_time;
|
||||||
|
QueryPerformanceCounter((LARGE_INTEGER *)¤t_time);
|
||||||
|
io.DeltaTime = (float)(current_time - time) / ticks_per_second;
|
||||||
|
time = current_time;
|
||||||
|
|
||||||
|
// Setup inputs
|
||||||
|
// (we already got mouse position, buttons, wheel from the window message callback)
|
||||||
|
BYTE keystate[256];
|
||||||
|
GetKeyboardState(keystate);
|
||||||
|
for (int i = 0; i < 256; i++)
|
||||||
|
io.KeysDown[i] = (keystate[i] & 0x80) != 0;
|
||||||
|
io.KeyCtrl = (keystate[VK_CONTROL] & 0x80) != 0;
|
||||||
|
io.KeyShift = (keystate[VK_SHIFT] & 0x80) != 0;
|
||||||
|
// io.MousePos : filled by WM_MOUSEMOVE event
|
||||||
|
// io.MouseDown : filled by WM_*BUTTON* events
|
||||||
|
// io.MouseWheel : filled by WM_MOUSEWHEEL events
|
||||||
|
|
||||||
|
// Start the frame
|
||||||
|
ImGui::NewFrame();
|
||||||
}
|
}
|
||||||
|
|
||||||
int WINAPI wWinMain(HINSTANCE hInst, HINSTANCE, LPWSTR, int)
|
int WINAPI wWinMain(HINSTANCE hInst, HINSTANCE, LPWSTR, int)
|
||||||
@ -308,15 +261,20 @@ int WINAPI wWinMain(HINSTANCE hInst, HINSTANCE, LPWSTR, int)
|
|||||||
// Create the application's window
|
// Create the application's window
|
||||||
hWnd = CreateWindow(L"ImGui Example", L"ImGui DirectX9 Example", WS_OVERLAPPEDWINDOW, 100, 100, 1280, 800, NULL, NULL, wc.hInstance, NULL);
|
hWnd = CreateWindow(L"ImGui Example", L"ImGui DirectX9 Example", WS_OVERLAPPEDWINDOW, 100, 100, 1280, 800, NULL, NULL, wc.hInstance, NULL);
|
||||||
|
|
||||||
INT64 ticks_per_second, time;
|
|
||||||
if (!QueryPerformanceFrequency((LARGE_INTEGER *)&ticks_per_second))
|
if (!QueryPerformanceFrequency((LARGE_INTEGER *)&ticks_per_second))
|
||||||
return 1;
|
return 1;
|
||||||
if (!QueryPerformanceCounter((LARGE_INTEGER *)&time))
|
if (!QueryPerformanceCounter((LARGE_INTEGER *)&time))
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
// Initialize Direct3D
|
// Initialize Direct3D
|
||||||
if (InitD3D(hWnd) >= 0)
|
if (InitD3D(hWnd) < 0)
|
||||||
{
|
{
|
||||||
|
if (g_pVB)
|
||||||
|
g_pVB->Release();
|
||||||
|
UnregisterClass(L"ImGui Example", wc.hInstance);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
// Show the window
|
// Show the window
|
||||||
ShowWindow(hWnd, SW_SHOWDEFAULT);
|
ShowWindow(hWnd, SW_SHOWDEFAULT);
|
||||||
UpdateWindow(hWnd);
|
UpdateWindow(hWnd);
|
||||||
@ -335,24 +293,10 @@ int WINAPI wWinMain(HINSTANCE hInst, HINSTANCE, LPWSTR, int)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 1) ImGui start frame, setup time delta & inputs
|
UpdateImGui();
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
|
||||||
INT64 current_time;
|
|
||||||
QueryPerformanceCounter((LARGE_INTEGER *)¤t_time);
|
|
||||||
io.DeltaTime = (float)(current_time - time) / ticks_per_second;
|
|
||||||
time = current_time;
|
|
||||||
BYTE keystate[256];
|
|
||||||
GetKeyboardState(keystate);
|
|
||||||
for (int i = 0; i < 256; i++)
|
|
||||||
io.KeysDown[i] = (keystate[i] & 0x80) != 0;
|
|
||||||
io.KeyCtrl = (keystate[VK_CONTROL] & 0x80) != 0;
|
|
||||||
io.KeyShift = (keystate[VK_SHIFT] & 0x80) != 0;
|
|
||||||
// io.MousePos : filled by WM_MOUSEMOVE event
|
|
||||||
// io.MouseDown : filled by WM_*BUTTON* events
|
|
||||||
// io.MouseWheel : filled by WM_MOUSEWHEEL events
|
|
||||||
ImGui::NewFrame();
|
|
||||||
|
|
||||||
// 2) ImGui usage
|
// Create a simple window
|
||||||
|
// Tip: if we don't call ImGui::Begin()/ImGui::End() the widgets appears in a window automatically called "Debug"
|
||||||
static bool show_test_window = true;
|
static bool show_test_window = true;
|
||||||
static bool show_another_window = false;
|
static bool show_another_window = false;
|
||||||
static float f;
|
static float f;
|
||||||
@ -366,19 +310,21 @@ int WINAPI wWinMain(HINSTANCE hInst, HINSTANCE, LPWSTR, int)
|
|||||||
static int ms_per_frame_idx = 0;
|
static int ms_per_frame_idx = 0;
|
||||||
static float ms_per_frame_accum = 0.0f;
|
static float ms_per_frame_accum = 0.0f;
|
||||||
ms_per_frame_accum -= ms_per_frame[ms_per_frame_idx];
|
ms_per_frame_accum -= ms_per_frame[ms_per_frame_idx];
|
||||||
ms_per_frame[ms_per_frame_idx] = io.DeltaTime * 1000.0f;
|
ms_per_frame[ms_per_frame_idx] = ImGui::GetIO().DeltaTime * 1000.0f;
|
||||||
ms_per_frame_accum += ms_per_frame[ms_per_frame_idx];
|
ms_per_frame_accum += ms_per_frame[ms_per_frame_idx];
|
||||||
ms_per_frame_idx = (ms_per_frame_idx + 1) % 120;
|
ms_per_frame_idx = (ms_per_frame_idx + 1) % 120;
|
||||||
const float ms_per_frame_avg = ms_per_frame_accum / 120;
|
const float ms_per_frame_avg = ms_per_frame_accum / 120;
|
||||||
ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", ms_per_frame_avg, 1000.0f / ms_per_frame_avg);
|
ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", ms_per_frame_avg, 1000.0f / ms_per_frame_avg);
|
||||||
|
|
||||||
|
// Show the ImGui test window
|
||||||
|
// Most of user example code is in ImGui::ShowTestWindow()
|
||||||
if (show_test_window)
|
if (show_test_window)
|
||||||
{
|
{
|
||||||
// More example code in ShowTestWindow()
|
|
||||||
ImGui::SetNewWindowDefaultPos(ImVec2(650, 20)); // Normally user code doesn't need/want to call it because positions are saved in .ini file anyway. Here we just want to make the demo initial state a bit more friendly!
|
ImGui::SetNewWindowDefaultPos(ImVec2(650, 20)); // Normally user code doesn't need/want to call it because positions are saved in .ini file anyway. Here we just want to make the demo initial state a bit more friendly!
|
||||||
ImGui::ShowTestWindow(&show_test_window);
|
ImGui::ShowTestWindow(&show_test_window);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Show another simple window
|
||||||
if (show_another_window)
|
if (show_another_window)
|
||||||
{
|
{
|
||||||
ImGui::Begin("Another Window", &show_another_window, ImVec2(200,100));
|
ImGui::Begin("Another Window", &show_another_window, ImVec2(200,100));
|
||||||
@ -386,11 +332,11 @@ int WINAPI wWinMain(HINSTANCE hInst, HINSTANCE, LPWSTR, int)
|
|||||||
ImGui::End();
|
ImGui::End();
|
||||||
}
|
}
|
||||||
|
|
||||||
// 3) Render
|
// Rendering
|
||||||
g_pd3dDevice->SetRenderState(D3DRS_ZENABLE, false);
|
g_pd3dDevice->SetRenderState(D3DRS_ZENABLE, false);
|
||||||
g_pd3dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, false);
|
g_pd3dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, false);
|
||||||
g_pd3dDevice->SetRenderState(D3DRS_SCISSORTESTENABLE, false);
|
g_pd3dDevice->SetRenderState(D3DRS_SCISSORTESTENABLE, false);
|
||||||
g_pd3dDevice->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(204, 153, 153), 1.0f, 0); // Clear the backbuffer and the zbuffer
|
g_pd3dDevice->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(204, 153, 153), 1.0f, 0);
|
||||||
if (g_pd3dDevice->BeginScene() >= 0)
|
if (g_pd3dDevice->BeginScene() >= 0)
|
||||||
{
|
{
|
||||||
ImGui::Render();
|
ImGui::Render();
|
||||||
@ -400,7 +346,6 @@ int WINAPI wWinMain(HINSTANCE hInst, HINSTANCE, LPWSTR, int)
|
|||||||
}
|
}
|
||||||
|
|
||||||
ImGui::Shutdown();
|
ImGui::Shutdown();
|
||||||
}
|
|
||||||
|
|
||||||
if (g_pVB)
|
if (g_pVB)
|
||||||
g_pVB->Release();
|
g_pVB->Release();
|
||||||
|
18
examples/opengl_example/Makefile.Linux
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
#
|
||||||
|
# Quick and dirty makefile to build on Linux
|
||||||
|
# tested on Ubuntu 14.04.1 32bit
|
||||||
|
#
|
||||||
|
|
||||||
|
SRC = main.cpp ../../imgui.cpp
|
||||||
|
|
||||||
|
OBJ = $(SRC:.cpp=.o)
|
||||||
|
|
||||||
|
CXXFLAGS = -I../../ `pkg-config --cflags glfw3`
|
||||||
|
|
||||||
|
LIBS = `pkg-config --static --libs glfw3` -lGLEW
|
||||||
|
|
||||||
|
all: $(OBJ)
|
||||||
|
$(CXX) $(OBJ) $(LIBS)
|
||||||
|
|
||||||
|
clean:
|
||||||
|
$(RM) -f $(OBJ)
|
18
examples/opengl_example/Makefile.Macosx
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
# This makefile currently only works for mac os
|
||||||
|
# You should install via homebrew:
|
||||||
|
# brew install glew
|
||||||
|
# brew install glfw3
|
||||||
|
#
|
||||||
|
|
||||||
|
CXXFLAGS=-framework OpenGL -framework Cocoa -framework IOKit -framework CoreVideo
|
||||||
|
CXXFLAGS+=-I/usr/local/Cellar/glew/1.10.0/include -I/usr/local/Cellar/glfw3/3.0.4/include
|
||||||
|
CXXFLAGS+=-L/usr/local/Cellar/glew/1.10.0/lib -L/usr/local/Cellar/glfw3/3.0.4/lib
|
||||||
|
CXXFLAGS+=-lglew -lglfw3
|
||||||
|
CXXFLAGS+=-I../../
|
||||||
|
CXXFLAGS+= -D__APPLE__
|
||||||
|
|
||||||
|
main: main.cpp ../../imgui.cpp
|
||||||
|
$(CXX) $(CXXFLAGS) -o $@ $^
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm main
|
@ -9,109 +9,65 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
static GLFWwindow* window;
|
static GLFWwindow* window;
|
||||||
static GLuint vbo;
|
|
||||||
static GLuint vao;
|
|
||||||
static GLuint vertexShader;
|
|
||||||
static GLuint fragmentShader;
|
|
||||||
static GLuint shaderProgram;
|
|
||||||
static GLuint fontTex;
|
static GLuint fontTex;
|
||||||
static GLint uniMVP;
|
static ImVec2 mousePosScale(1.0f, 1.0f);
|
||||||
static GLint uniClipRect;
|
|
||||||
|
|
||||||
|
// 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)
|
static void ImImpl_RenderDrawLists(ImDrawList** const cmd_lists, int cmd_lists_count)
|
||||||
{
|
{
|
||||||
size_t total_vtx_count = 0;
|
if (cmd_lists_count == 0)
|
||||||
for (int n = 0; n < cmd_lists_count; n++)
|
|
||||||
total_vtx_count += cmd_lists[n]->vtx_buffer.size();
|
|
||||||
if (total_vtx_count == 0)
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
int read_pos_clip_rect_buf = 0; // offset in 'clip_rect_buffer'. each PushClipRect command consume 1 of those.
|
// 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.
|
||||||
ImVector<ImVec4> clip_rect_stack;
|
// Setup render state: alpha-blending enabled, no face culling, no depth testing, scissor enabled, vertex/texcoord/color pointers.
|
||||||
clip_rect_stack.push_back(ImVec4(-9999,-9999,+9999,+9999));
|
|
||||||
|
|
||||||
// Setup orthographic projection
|
|
||||||
const float L = 0.0f;
|
|
||||||
const float R = ImGui::GetIO().DisplaySize.x;
|
|
||||||
const float B = ImGui::GetIO().DisplaySize.y;
|
|
||||||
const float T = 0.0f;
|
|
||||||
const float mvp[4][4] =
|
|
||||||
{
|
|
||||||
{ 2.0f/(R-L), 0.0f, 0.0f, 0.0f },
|
|
||||||
{ 0.0f, 2.0f/(T-B), 0.0f, 0.0f },
|
|
||||||
{ 0.0f, 0.0f, -1.0f, 0.0f },
|
|
||||||
{ -(R+L)/(R-L), -(T+B)/(T-B), 0.0f, 1.0f },
|
|
||||||
};
|
|
||||||
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, vbo);
|
|
||||||
glBindVertexArray(vao);
|
|
||||||
glBufferData(GL_ARRAY_BUFFER, total_vtx_count * sizeof(ImDrawVert), NULL, GL_STREAM_DRAW);
|
|
||||||
unsigned char* buffer_data = (unsigned char*)glMapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY);
|
|
||||||
if (!buffer_data)
|
|
||||||
return;
|
|
||||||
int vtx_consumed = 0;
|
|
||||||
for (int n = 0; n < cmd_lists_count; n++)
|
|
||||||
{
|
|
||||||
const ImDrawList* cmd_list = cmd_lists[n];
|
|
||||||
if (!cmd_list->vtx_buffer.empty())
|
|
||||||
{
|
|
||||||
memcpy(buffer_data, &cmd_list->vtx_buffer[0], cmd_list->vtx_buffer.size() * sizeof(ImDrawVert));
|
|
||||||
buffer_data += cmd_list->vtx_buffer.size() * sizeof(ImDrawVert);
|
|
||||||
vtx_consumed += cmd_list->vtx_buffer.size();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
glUnmapBuffer(GL_ARRAY_BUFFER);
|
|
||||||
|
|
||||||
glUseProgram(shaderProgram);
|
|
||||||
glUniformMatrix4fv(uniMVP, 1, GL_FALSE, &mvp[0][0]);
|
|
||||||
|
|
||||||
// Setup render state: alpha-blending enabled, no face culling, no depth testing
|
|
||||||
glEnable(GL_BLEND);
|
glEnable(GL_BLEND);
|
||||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||||
glDisable(GL_CULL_FACE);
|
glDisable(GL_CULL_FACE);
|
||||||
glDisable(GL_DEPTH_TEST);
|
glDisable(GL_DEPTH_TEST);
|
||||||
|
glEnable(GL_SCISSOR_TEST);
|
||||||
|
glEnableClientState(GL_VERTEX_ARRAY);
|
||||||
|
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||||
|
glEnableClientState(GL_COLOR_ARRAY);
|
||||||
|
|
||||||
|
// Setup texture
|
||||||
glBindTexture(GL_TEXTURE_2D, fontTex);
|
glBindTexture(GL_TEXTURE_2D, fontTex);
|
||||||
|
glEnable(GL_TEXTURE_2D);
|
||||||
|
|
||||||
vtx_consumed = 0; // offset in vertex buffer. each command consume ImDrawCmd::vtx_count of those
|
// Setup orthographic projection matrix
|
||||||
bool clip_rect_dirty = true;
|
const float width = ImGui::GetIO().DisplaySize.x;
|
||||||
|
const float height = ImGui::GetIO().DisplaySize.y;
|
||||||
|
glMatrixMode(GL_PROJECTION);
|
||||||
|
glLoadIdentity();
|
||||||
|
glOrtho(0.0f, width, height, 0.0f, -1.0f, +1.0f);
|
||||||
|
glMatrixMode(GL_MODELVIEW);
|
||||||
|
glLoadIdentity();
|
||||||
|
|
||||||
|
// Render command lists
|
||||||
for (int n = 0; n < cmd_lists_count; n++)
|
for (int n = 0; n < cmd_lists_count; n++)
|
||||||
{
|
{
|
||||||
const ImDrawList* cmd_list = cmd_lists[n];
|
const ImDrawList* cmd_list = cmd_lists[n];
|
||||||
if (cmd_list->commands.empty() || cmd_list->vtx_buffer.empty())
|
const unsigned char* vtx_buffer = (const unsigned char*)cmd_list->vtx_buffer.begin();
|
||||||
continue;
|
glVertexPointer(2, GL_FLOAT, sizeof(ImDrawVert), (void*)(vtx_buffer));
|
||||||
const ImDrawCmd* pcmd = &cmd_list->commands.front();
|
glTexCoordPointer(2, GL_FLOAT, sizeof(ImDrawVert), (void*)(vtx_buffer+8));
|
||||||
const ImDrawCmd* pcmd_end = &cmd_list->commands.back();
|
glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(ImDrawVert), (void*)(vtx_buffer+16));
|
||||||
int clip_rect_buf_consumed = 0; // offset in cmd_list->clip_rect_buffer. each PushClipRect command consume 1 of those.
|
|
||||||
while (pcmd <= pcmd_end)
|
|
||||||
{
|
|
||||||
const ImDrawCmd& cmd = *pcmd++;
|
|
||||||
switch (cmd.cmd_type)
|
|
||||||
{
|
|
||||||
case ImDrawCmdType_DrawTriangleList:
|
|
||||||
if (clip_rect_dirty)
|
|
||||||
{
|
|
||||||
glUniform4fv(uniClipRect, 1, (float*)&clip_rect_stack.back());
|
|
||||||
clip_rect_dirty = false;
|
|
||||||
}
|
|
||||||
glDrawArrays(GL_TRIANGLES, vtx_consumed, cmd.vtx_count);
|
|
||||||
vtx_consumed += cmd.vtx_count;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case ImDrawCmdType_PushClipRect:
|
int vtx_offset = 0;
|
||||||
clip_rect_stack.push_back(cmd_list->clip_rect_buffer[clip_rect_buf_consumed++]);
|
const ImDrawCmd* pcmd_end = cmd_list->commands.end();
|
||||||
clip_rect_dirty = true;
|
for (const ImDrawCmd* pcmd = cmd_list->commands.begin(); pcmd != pcmd_end; pcmd++)
|
||||||
break;
|
{
|
||||||
|
glScissor((int)pcmd->clip_rect.x, (int)(height - pcmd->clip_rect.w), (int)(pcmd->clip_rect.z - pcmd->clip_rect.x), (int)(pcmd->clip_rect.w - pcmd->clip_rect.y));
|
||||||
case ImDrawCmdType_PopClipRect:
|
glDrawArrays(GL_TRIANGLES, vtx_offset, pcmd->vtx_count);
|
||||||
clip_rect_stack.pop_back();
|
vtx_offset += pcmd->vtx_count;
|
||||||
clip_rect_dirty = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
glDisable(GL_SCISSOR_TEST);
|
||||||
|
glDisableClientState(GL_COLOR_ARRAY);
|
||||||
|
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||||
|
glDisableClientState(GL_VERTEX_ARRAY);
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char* ImImpl_GetClipboardTextFn()
|
static const char* ImImpl_GetClipboardTextFn()
|
||||||
@ -124,55 +80,33 @@ static void ImImpl_SetClipboardTextFn(const char* text, const char* text_end)
|
|||||||
if (!text_end)
|
if (!text_end)
|
||||||
text_end = text + strlen(text);
|
text_end = text + strlen(text);
|
||||||
|
|
||||||
|
if (*text_end == 0)
|
||||||
|
{
|
||||||
|
// Already got a zero-terminator at 'text_end', we don't need to add one
|
||||||
|
glfwSetClipboardString(window, text);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Add a zero-terminator because glfw function doesn't take a size
|
||||||
char* buf = (char*)malloc(text_end - text + 1);
|
char* buf = (char*)malloc(text_end - text + 1);
|
||||||
memcpy(buf, text, text_end-text);
|
memcpy(buf, text, text_end-text);
|
||||||
buf[text_end-text] = '\0';
|
buf[text_end-text] = '\0';
|
||||||
glfwSetClipboardString(window, buf);
|
glfwSetClipboardString(window, buf);
|
||||||
free(buf);
|
free(buf);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Shader sources
|
|
||||||
// FIXME-OPT: clip at vertex level
|
|
||||||
const GLchar* vertexSource =
|
|
||||||
"#version 150 core\n"
|
|
||||||
"uniform mat4 MVP;"
|
|
||||||
"in vec2 i_pos;"
|
|
||||||
"in vec2 i_uv;"
|
|
||||||
"in vec4 i_col;"
|
|
||||||
"out vec4 col;"
|
|
||||||
"out vec2 pixel_pos;"
|
|
||||||
"out vec2 uv;"
|
|
||||||
"void main() {"
|
|
||||||
" col = i_col;"
|
|
||||||
" pixel_pos = i_pos;"
|
|
||||||
" uv = i_uv;"
|
|
||||||
" gl_Position = MVP * vec4(i_pos.x, i_pos.y, 0.0f, 1.0f);"
|
|
||||||
"}";
|
|
||||||
|
|
||||||
const GLchar* fragmentSource =
|
|
||||||
"#version 150 core\n"
|
|
||||||
"uniform sampler2D Tex;"
|
|
||||||
"uniform vec4 ClipRect;"
|
|
||||||
"in vec4 col;"
|
|
||||||
"in vec2 pixel_pos;"
|
|
||||||
"in vec2 uv;"
|
|
||||||
"out vec4 o_col;"
|
|
||||||
"void main() {"
|
|
||||||
" o_col = texture(Tex, uv) * col;"
|
|
||||||
//" if (pixel_pos.x < ClipRect.x || pixel_pos.y < ClipRect.y || pixel_pos.x > ClipRect.z || pixel_pos.y > ClipRect.w) discard;" // Clipping: using discard
|
|
||||||
//" if (step(ClipRect.x,pixel_pos.x) * step(ClipRect.y,pixel_pos.y) * step(pixel_pos.x,ClipRect.z) * step(pixel_pos.y,ClipRect.w) < 1.0f) discard;" // Clipping: using discard and step
|
|
||||||
" o_col.w *= (step(ClipRect.x,pixel_pos.x) * step(ClipRect.y,pixel_pos.y) * step(pixel_pos.x,ClipRect.z) * step(pixel_pos.y,ClipRect.w));" // Clipping: branch-less, set alpha 0.0f
|
|
||||||
"}";
|
|
||||||
|
|
||||||
|
// GLFW callbacks to get events
|
||||||
static void glfw_error_callback(int error, const char* description)
|
static void glfw_error_callback(int error, const char* description)
|
||||||
{
|
{
|
||||||
fputs(description, stderr);
|
fputs(description, stderr);
|
||||||
}
|
}
|
||||||
|
|
||||||
static float mouse_wheel = 0.0f;
|
|
||||||
static void glfw_scroll_callback(GLFWwindow* window, double xoffset, double yoffset)
|
static void glfw_scroll_callback(GLFWwindow* window, double xoffset, double yoffset)
|
||||||
{
|
{
|
||||||
mouse_wheel = (float)yoffset;
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
|
io.MouseWheel = (yoffset != 0.0f) ? yoffset > 0.0f ? 1 : - 1 : 0; // Mouse wheel: -1,0,+1
|
||||||
}
|
}
|
||||||
|
|
||||||
static void glfw_key_callback(GLFWwindow* window, int key, int scancode, int action, int mods)
|
static void glfw_key_callback(GLFWwindow* window, int key, int scancode, int action, int mods)
|
||||||
@ -200,87 +134,30 @@ void InitGL()
|
|||||||
if (!glfwInit())
|
if (!glfwInit())
|
||||||
exit(1);
|
exit(1);
|
||||||
|
|
||||||
//glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
|
|
||||||
//glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0);
|
|
||||||
//glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
|
|
||||||
//glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
|
|
||||||
glfwWindowHint(GLFW_REFRESH_RATE, 60);
|
|
||||||
glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);
|
glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);
|
||||||
window = glfwCreateWindow(1280, 720, "ImGui OpenGL example", nullptr, nullptr);
|
window = glfwCreateWindow(1280, 720, "ImGui OpenGL example", NULL, NULL);
|
||||||
glfwMakeContextCurrent(window);
|
glfwMakeContextCurrent(window);
|
||||||
|
|
||||||
glfwSetKeyCallback(window, glfw_key_callback);
|
glfwSetKeyCallback(window, glfw_key_callback);
|
||||||
glfwSetScrollCallback(window, glfw_scroll_callback);
|
glfwSetScrollCallback(window, glfw_scroll_callback);
|
||||||
glfwSetCharCallback(window, glfw_char_callback);
|
glfwSetCharCallback(window, glfw_char_callback);
|
||||||
|
|
||||||
glewExperimental = GL_TRUE;
|
|
||||||
glewInit();
|
glewInit();
|
||||||
|
|
||||||
GLenum err = GL_NO_ERROR;
|
|
||||||
GLint status = GL_TRUE;
|
|
||||||
err = glGetError(); IM_ASSERT(err == GL_NO_ERROR);
|
|
||||||
|
|
||||||
// Create and compile the vertex shader
|
|
||||||
vertexShader = glCreateShader(GL_VERTEX_SHADER);
|
|
||||||
glShaderSource(vertexShader, 1, &vertexSource, NULL);
|
|
||||||
glCompileShader(vertexShader);
|
|
||||||
glGetShaderiv(vertexShader, GL_COMPILE_STATUS, &status);
|
|
||||||
if (status != GL_TRUE)
|
|
||||||
{
|
|
||||||
char buffer[512];
|
|
||||||
glGetShaderInfoLog(vertexShader, 1024, NULL, buffer);
|
|
||||||
printf("%s", buffer);
|
|
||||||
IM_ASSERT(status == GL_TRUE);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create and compile the fragment shader
|
|
||||||
fragmentShader = glCreateShader(GL_FRAGMENT_SHADER);
|
|
||||||
glShaderSource(fragmentShader, 1, &fragmentSource, NULL);
|
|
||||||
glCompileShader(fragmentShader);
|
|
||||||
glGetShaderiv(vertexShader, GL_COMPILE_STATUS, &status);
|
|
||||||
IM_ASSERT(status == GL_TRUE);
|
|
||||||
|
|
||||||
// Link the vertex and fragment shader into a shader program
|
|
||||||
shaderProgram = glCreateProgram();
|
|
||||||
glAttachShader(shaderProgram, vertexShader);
|
|
||||||
glAttachShader(shaderProgram, fragmentShader);
|
|
||||||
glBindFragDataLocation(shaderProgram, 0, "o_col");
|
|
||||||
glLinkProgram(shaderProgram);
|
|
||||||
glGetProgramiv(shaderProgram, GL_LINK_STATUS, &status);
|
|
||||||
IM_ASSERT(status == GL_TRUE);
|
|
||||||
|
|
||||||
uniMVP = glGetUniformLocation(shaderProgram, "MVP");
|
|
||||||
uniClipRect = glGetUniformLocation(shaderProgram, "ClipRect");
|
|
||||||
|
|
||||||
// Create Vertex Buffer Objects & Vertex Array Objects
|
|
||||||
glGenBuffers(1, &vbo);
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, vbo);
|
|
||||||
glGenVertexArrays(1, &vao);
|
|
||||||
glBindVertexArray(vao);
|
|
||||||
|
|
||||||
GLint posAttrib = glGetAttribLocation(shaderProgram, "i_pos");
|
|
||||||
glVertexAttribPointer(posAttrib, 2, GL_FLOAT, GL_FALSE, sizeof(ImDrawVert), 0);
|
|
||||||
glEnableVertexAttribArray(posAttrib);
|
|
||||||
|
|
||||||
GLint uvAttrib = glGetAttribLocation(shaderProgram, "i_uv");
|
|
||||||
glEnableVertexAttribArray(uvAttrib);
|
|
||||||
glVertexAttribPointer(uvAttrib, 2, GL_FLOAT, GL_FALSE, sizeof(ImDrawVert), (void*)(2*sizeof(float)));
|
|
||||||
|
|
||||||
GLint colAttrib = glGetAttribLocation(shaderProgram, "i_col");
|
|
||||||
glVertexAttribPointer(colAttrib, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(ImDrawVert), (void*)(4*sizeof(float)));
|
|
||||||
glEnableVertexAttribArray(colAttrib);
|
|
||||||
err = glGetError(); IM_ASSERT(err == GL_NO_ERROR);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void InitImGui()
|
void InitImGui()
|
||||||
{
|
{
|
||||||
int w, h;
|
int w, h;
|
||||||
|
int fb_w, fb_h;
|
||||||
glfwGetWindowSize(window, &w, &h);
|
glfwGetWindowSize(window, &w, &h);
|
||||||
|
glfwGetFramebufferSize(window, &fb_w, &fb_h);
|
||||||
|
mousePosScale.x = (float)fb_w / w; // Some screens e.g. Retina display have framebuffer size != from window size, and mouse inputs are given in window/screen coordinates.
|
||||||
|
mousePosScale.y = (float)fb_h / h;
|
||||||
|
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
io.DisplaySize = ImVec2((float)w, (float)h);
|
io.DisplaySize = ImVec2((float)fb_w, (float)fb_h); // Display size, in pixels. For clamping windows positions.
|
||||||
io.DeltaTime = 1.0f/60.0f;
|
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.KeyMap[ImGuiKey_Tab] = GLFW_KEY_TAB;
|
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_LeftArrow] = GLFW_KEY_LEFT;
|
||||||
io.KeyMap[ImGuiKey_RightArrow] = GLFW_KEY_RIGHT;
|
io.KeyMap[ImGuiKey_RightArrow] = GLFW_KEY_RIGHT;
|
||||||
io.KeyMap[ImGuiKey_UpArrow] = GLFW_KEY_UP;
|
io.KeyMap[ImGuiKey_UpArrow] = GLFW_KEY_UP;
|
||||||
@ -307,7 +184,6 @@ void InitImGui()
|
|||||||
glBindTexture(GL_TEXTURE_2D, fontTex);
|
glBindTexture(GL_TEXTURE_2D, fontTex);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||||
|
|
||||||
const void* png_data;
|
const void* png_data;
|
||||||
unsigned int png_size;
|
unsigned int png_size;
|
||||||
ImGui::GetDefaultFontData(NULL, NULL, &png_data, &png_size);
|
ImGui::GetDefaultFontData(NULL, NULL, &png_data, &png_size);
|
||||||
@ -317,44 +193,43 @@ void InitImGui()
|
|||||||
stbi_image_free(tex_data);
|
stbi_image_free(tex_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Shutdown()
|
void UpdateImGui()
|
||||||
{
|
{
|
||||||
ImGui::Shutdown();
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
|
|
||||||
glDeleteProgram(shaderProgram);
|
// Setup timestep
|
||||||
glDeleteShader(fragmentShader);
|
static double time = 0.0f;
|
||||||
glDeleteShader(vertexShader);
|
const double current_time = glfwGetTime();
|
||||||
glDeleteBuffers(1, &vbo);
|
io.DeltaTime = (float)(current_time - time);
|
||||||
glDeleteVertexArrays(1, &vao);
|
time = current_time;
|
||||||
|
|
||||||
glfwTerminate();
|
// Setup inputs
|
||||||
|
// (we already got mouse wheel, keyboard keys & characters from glfw callbacks polled in glfwPollEvents())
|
||||||
|
double mouse_x, mouse_y;
|
||||||
|
glfwGetCursorPos(window, &mouse_x, &mouse_y);
|
||||||
|
io.MousePos = ImVec2((float)mouse_x * mousePosScale.x, (float)mouse_y * mousePosScale.y); // Mouse position, in pixels (set to -1,-1 if no mouse / on another screen, etc.)
|
||||||
|
io.MouseDown[0] = glfwGetMouseButton(window, GLFW_MOUSE_BUTTON_LEFT) != 0;
|
||||||
|
io.MouseDown[1] = glfwGetMouseButton(window, GLFW_MOUSE_BUTTON_RIGHT) != 0;
|
||||||
|
|
||||||
|
// Start the frame
|
||||||
|
ImGui::NewFrame();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Application code
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
InitGL();
|
InitGL();
|
||||||
InitImGui();
|
InitImGui();
|
||||||
|
|
||||||
double time = glfwGetTime();
|
|
||||||
while (!glfwWindowShouldClose(window))
|
while (!glfwWindowShouldClose(window))
|
||||||
{
|
{
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
|
io.MouseWheel = 0;
|
||||||
glfwPollEvents();
|
glfwPollEvents();
|
||||||
|
UpdateImGui();
|
||||||
|
|
||||||
// 1) ImGui start frame, setup time delta & inputs
|
// Create a simple window
|
||||||
const double current_time = glfwGetTime();
|
// Tip: if we don't call ImGui::Begin()/ImGui::End() the widgets appears in a window automatically called "Debug"
|
||||||
io.DeltaTime = (float)(current_time - time);
|
|
||||||
time = current_time;
|
|
||||||
double mouse_x, mouse_y;
|
|
||||||
glfwGetCursorPos(window, &mouse_x, &mouse_y);
|
|
||||||
io.MousePos = ImVec2((float)mouse_x, (float)mouse_y);
|
|
||||||
io.MouseDown[0] = glfwGetMouseButton(window, GLFW_MOUSE_BUTTON_LEFT) != 0;
|
|
||||||
io.MouseDown[1] = glfwGetMouseButton(window, GLFW_MOUSE_BUTTON_RIGHT) != 0;
|
|
||||||
io.MouseWheel = (mouse_wheel != 0) ? mouse_wheel > 0.0f ? 1 : - 1 : 0;
|
|
||||||
mouse_wheel = 0.0f;
|
|
||||||
ImGui::NewFrame();
|
|
||||||
|
|
||||||
// 2) ImGui usage
|
|
||||||
static bool show_test_window = true;
|
static bool show_test_window = true;
|
||||||
static bool show_another_window = false;
|
static bool show_another_window = false;
|
||||||
static float f;
|
static float f;
|
||||||
@ -368,19 +243,21 @@ int main(int argc, char** argv)
|
|||||||
static int ms_per_frame_idx = 0;
|
static int ms_per_frame_idx = 0;
|
||||||
static float ms_per_frame_accum = 0.0f;
|
static float ms_per_frame_accum = 0.0f;
|
||||||
ms_per_frame_accum -= ms_per_frame[ms_per_frame_idx];
|
ms_per_frame_accum -= ms_per_frame[ms_per_frame_idx];
|
||||||
ms_per_frame[ms_per_frame_idx] = io.DeltaTime * 1000.0f;
|
ms_per_frame[ms_per_frame_idx] = ImGui::GetIO().DeltaTime * 1000.0f;
|
||||||
ms_per_frame_accum += ms_per_frame[ms_per_frame_idx];
|
ms_per_frame_accum += ms_per_frame[ms_per_frame_idx];
|
||||||
ms_per_frame_idx = (ms_per_frame_idx + 1) % 120;
|
ms_per_frame_idx = (ms_per_frame_idx + 1) % 120;
|
||||||
const float ms_per_frame_avg = ms_per_frame_accum / 120;
|
const float ms_per_frame_avg = ms_per_frame_accum / 120;
|
||||||
ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", ms_per_frame_avg, 1000.0f / ms_per_frame_avg);
|
ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", ms_per_frame_avg, 1000.0f / ms_per_frame_avg);
|
||||||
|
|
||||||
|
// Show the ImGui test window
|
||||||
|
// Most of user example code is in ImGui::ShowTestWindow()
|
||||||
if (show_test_window)
|
if (show_test_window)
|
||||||
{
|
{
|
||||||
// More example code in ShowTestWindow()
|
|
||||||
ImGui::SetNewWindowDefaultPos(ImVec2(650, 20)); // Normally user code doesn't need/want to call it because positions are saved in .ini file anyway. Here we just want to make the demo initial state a bit more friendly!
|
ImGui::SetNewWindowDefaultPos(ImVec2(650, 20)); // Normally user code doesn't need/want to call it because positions are saved in .ini file anyway. Here we just want to make the demo initial state a bit more friendly!
|
||||||
ImGui::ShowTestWindow(&show_test_window);
|
ImGui::ShowTestWindow(&show_test_window);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Show another simple window
|
||||||
if (show_another_window)
|
if (show_another_window)
|
||||||
{
|
{
|
||||||
ImGui::Begin("Another Window", &show_another_window, ImVec2(200,100));
|
ImGui::Begin("Another Window", &show_another_window, ImVec2(200,100));
|
||||||
@ -388,15 +265,15 @@ int main(int argc, char** argv)
|
|||||||
ImGui::End();
|
ImGui::End();
|
||||||
}
|
}
|
||||||
|
|
||||||
// 3) Render
|
// Rendering
|
||||||
|
glViewport(0, 0, (int)io.DisplaySize.x, (int)io.DisplaySize.y);
|
||||||
glClearColor(0.8f, 0.6f, 0.6f, 1.0f);
|
glClearColor(0.8f, 0.6f, 0.6f, 1.0f);
|
||||||
glClear(GL_COLOR_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
ImGui::Render();
|
ImGui::Render();
|
||||||
|
|
||||||
glfwSwapBuffers(window);
|
glfwSwapBuffers(window);
|
||||||
}
|
}
|
||||||
|
|
||||||
Shutdown();
|
ImGui::Shutdown();
|
||||||
|
glfwTerminate();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
BIN
extra_fonts/ProggyClean.zip
Normal file
BIN
extra_fonts/ProggySmall.zip
Normal file
71
extra_fonts/README.txt
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
|
||||||
|
Extra fonts for ImGui.
|
||||||
|
THOSE FONTS ARE OPTIONAL.
|
||||||
|
|
||||||
|
ImGui embeds a copy of 'proggy_clean' that you can use without any external files.
|
||||||
|
Export your own font with bmfont (www.angelcode.com/products/bmfont).
|
||||||
|
|
||||||
|
bmfont reads fonts (.ttf, .fon, etc.) and output a .fnt file and a texture file, e.g:
|
||||||
|
|
||||||
|
proggy_clean.fon --> [bmfont] ---> proggy_clean_13.fnt
|
||||||
|
proggy_clean_13.png
|
||||||
|
|
||||||
|
Configure bmfont:
|
||||||
|
|
||||||
|
- Export .fnt as Binary
|
||||||
|
- Tip: uncheck "Render from TrueType outline" and "Font Smoothing" for best result with non-anti-aliased type fonts.
|
||||||
|
But you can experiment with other settings if you want anti-aliased fonts.
|
||||||
|
|
||||||
|
|
||||||
|
(A) Use font data embedded in ImGui
|
||||||
|
|
||||||
|
// Access embedded font data
|
||||||
|
const void* fnt_data; // pointer to FNT data
|
||||||
|
unsigned fnt_size; // size of FNT data
|
||||||
|
const void* png_data; // pointer to PNG data
|
||||||
|
unsigned int png_size; // size of PNG data
|
||||||
|
ImGui::GetDefaultFontData(&fnt_data, &fnt_size, &png_data, &png_size);
|
||||||
|
|
||||||
|
1. Load the .FNT data from 'fnt_data' (NB: this is done for you by default if you don't do anything)
|
||||||
|
|
||||||
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
|
io.Font = new ImBitmapFont();
|
||||||
|
io.Font->LoadFromMemory(fnt_data, fnt_size);
|
||||||
|
|
||||||
|
2. Load the .PNG data from 'png_data' into a texture
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
(B) Use fonts from external files
|
||||||
|
|
||||||
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
|
|
||||||
|
1. Load the .FNT data, e.g.
|
||||||
|
|
||||||
|
// proggy_clean_13 [default]
|
||||||
|
io.Font->LoadFromFile("proggy_clean_13.fnt");
|
||||||
|
io.FontTexUvForWhite = ImVec2(0.0f/256.0f,0.0f/128);
|
||||||
|
io.FontYOffset = +1;
|
||||||
|
|
||||||
|
// proggy_small_12
|
||||||
|
io.Font = new ImBitmapFont();
|
||||||
|
io.Font->LoadFromFile("proggy_small_12.fnt");
|
||||||
|
io.FontTexUvForWhite = ImVec2(84.0f/256.0f,20.0f/64);
|
||||||
|
io.FontYOffset = +2;
|
||||||
|
|
||||||
|
// proggy_small_14
|
||||||
|
io.Font = new ImBitmapFont();
|
||||||
|
io.Font->LoadFromFile("proggy_small_14.fnt");
|
||||||
|
io.FontTexUvForWhite = ImVec2(84.0f/256.0f,20.0f/64);
|
||||||
|
io.FontYOffset = +3;
|
||||||
|
|
||||||
|
// courier_new_16
|
||||||
|
io.Font->LoadFromFile("courier_new_16.fnt");
|
||||||
|
io.FontTexUvForWhite = ImVec2(1.0f/256.0f,4.0f/128);
|
||||||
|
|
||||||
|
// courier_new_18
|
||||||
|
io.Font->LoadFromFile("courier_new_18.fnt");
|
||||||
|
io.FontTexUvForWhite = ImVec2(4.0f/256.0f,5.0f/256);
|
||||||
|
|
||||||
|
2. Load the matching .PNG data into a texture
|
||||||
|
|
BIN
extra_fonts/courier_new_16.fnt
Normal file
After Width: | Height: | Size: 3.8 KiB |
BIN
extra_fonts/courier_new_16.png
Normal file
After Width: | Height: | Size: 1.4 KiB |
BIN
extra_fonts/courier_new_18.fnt
Normal file
After Width: | Height: | Size: 3.8 KiB |
BIN
extra_fonts/courier_new_18.png
Normal file
After Width: | Height: | Size: 2.6 KiB |
BIN
extra_fonts/proggy_clean_13.fnt
Normal file
After Width: | Height: | Size: 4.5 KiB |
BIN
extra_fonts/proggy_clean_13.png
Normal file
After Width: | Height: | Size: 1.5 KiB |
BIN
extra_fonts/proggy_small_12.fnt
Normal file
After Width: | Height: | Size: 4.5 KiB |
BIN
extra_fonts/proggy_small_12.png
Normal file
After Width: | Height: | Size: 949 B |
BIN
extra_fonts/proggy_small_14.fnt
Normal file
After Width: | Height: | Size: 4.5 KiB |
BIN
extra_fonts/proggy_small_14.png
Normal file
After Width: | Height: | Size: 949 B |
26
imconfig.h
@ -1,18 +1,26 @@
|
|||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// USER IMPLEMENTATION
|
// USER IMPLEMENTATION
|
||||||
|
// This file contains compile-time options for ImGui.
|
||||||
|
// Other options (memory allocation overrides, callbacks, etc.) can be set at runtime via the ImGuiIO structure - ImGui::GetIO().
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
//----- Define your own ImVector<> type if you don't want to use the provided implementation defined in imgui.h
|
//---- Define your own ImVector<> type if you don't want to use the provided implementation defined in imgui.h
|
||||||
//#include <vector>
|
//#include <vector>
|
||||||
//#define ImVector std::vector
|
//#define ImVector std::vector
|
||||||
//#define ImVector MyVector
|
//#define ImVector MyVector
|
||||||
|
|
||||||
//----- Define assertion handler. Default to calling assert().
|
//---- Define assertion handler. Defaults to calling assert().
|
||||||
// #define IM_ASSERT(_EXPR) MyAssert(_EXPR)
|
//#define IM_ASSERT(_EXPR) MyAssert(_EXPR)
|
||||||
|
|
||||||
//----- Define implicit cast operators to convert back<>forth from your math types and ImVec2/ImVec4.
|
//---- Don't implement default clipboard handlers for Windows (so as not to link with OpenClipboard() and others Win32 functions)
|
||||||
|
//#define IMGUI_DISABLE_WIN32_DEFAULT_CLIPBOARD_FUNCS
|
||||||
|
|
||||||
|
//---- Include imgui_user.cpp at the end of imgui.cpp so you can include code that extends ImGui using its private data/functions.
|
||||||
|
//#define IMGUI_INCLUDE_IMGUI_USER_CPP
|
||||||
|
|
||||||
|
//---- Define implicit cast operators to convert back<>forth from your math types and ImVec2/ImVec4.
|
||||||
/*
|
/*
|
||||||
#define IM_VEC2_CLASS_EXTRA \
|
#define IM_VEC2_CLASS_EXTRA \
|
||||||
ImVec2(const MyVec2& f) { x = f.x; y = f.y; } \
|
ImVec2(const MyVec2& f) { x = f.x; y = f.y; } \
|
||||||
@ -23,12 +31,14 @@
|
|||||||
operator MyVec4() const { return MyVec4(x,y,z,w); }
|
operator MyVec4() const { return MyVec4(x,y,z,w); }
|
||||||
*/
|
*/
|
||||||
|
|
||||||
//----- Freely implement extra functions within the ImGui:: namespace.
|
//---- Freely implement extra functions within the ImGui:: namespace.
|
||||||
//----- e.g. you can create variants of the ImGui::Value() helper for your low-level math types.
|
//---- Declare helpers or widgets implemented in imgui_user.cpp or elsewhere, so end-user doesn't need to include multiple files.
|
||||||
|
//---- e.g. you can create variants of the ImGui::Value() helper for your low-level math types.
|
||||||
/*
|
/*
|
||||||
namespace ImGui
|
namespace ImGui
|
||||||
{
|
{
|
||||||
void Value(const char* prefix, cosnt MyVec2& v, const char* float_format = NULL);
|
void Value(const char* prefix, const MyVec2& v, const char* float_format = NULL);
|
||||||
void Value(const char* prefix, cosnt MyVec4& v, const char* float_format = NULL);
|
void Value(const char* prefix, const MyVec4& v, const char* float_format = NULL);
|
||||||
};
|
};
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
284
imgui.h
@ -1,4 +1,4 @@
|
|||||||
// ImGui library
|
// ImGui library v1.12
|
||||||
// See .cpp file for commentary.
|
// See .cpp file for commentary.
|
||||||
// See ImGui::ShowTestWindow() for sample code.
|
// See ImGui::ShowTestWindow() for sample code.
|
||||||
// Read 'Programmer guide' in .cpp for notes on how to setup ImGui in your codebase.
|
// Read 'Programmer guide' in .cpp for notes on how to setup ImGui in your codebase.
|
||||||
@ -17,7 +17,7 @@ struct ImGuiWindow;
|
|||||||
#include "imconfig.h"
|
#include "imconfig.h"
|
||||||
#include <float.h> // FLT_MAX
|
#include <float.h> // FLT_MAX
|
||||||
#include <stdarg.h> // va_list
|
#include <stdarg.h> // va_list
|
||||||
#include <stdlib.h> // NULL
|
#include <stdlib.h> // NULL, malloc
|
||||||
|
|
||||||
#ifndef IM_ASSERT
|
#ifndef IM_ASSERT
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
@ -29,8 +29,8 @@ typedef ImU32 ImGuiID;
|
|||||||
typedef int ImGuiCol; // enum ImGuiCol_
|
typedef int ImGuiCol; // enum ImGuiCol_
|
||||||
typedef int ImGuiKey; // enum ImGuiKey_
|
typedef int ImGuiKey; // enum ImGuiKey_
|
||||||
typedef int ImGuiColorEditMode; // enum ImGuiColorEditMode_
|
typedef int ImGuiColorEditMode; // enum ImGuiColorEditMode_
|
||||||
typedef ImU32 ImGuiWindowFlags; // enum ImGuiWindowFlags_
|
typedef int ImGuiWindowFlags; // enum ImGuiWindowFlags_
|
||||||
typedef ImU32 ImGuiInputTextFlags; // enum ImGuiInputTextFlags_
|
typedef int ImGuiInputTextFlags; // enum ImGuiInputTextFlags_
|
||||||
typedef ImBitmapFont* ImFont;
|
typedef ImBitmapFont* ImFont;
|
||||||
|
|
||||||
struct ImVec2
|
struct ImVec2
|
||||||
@ -55,59 +55,68 @@ struct ImVec4
|
|||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
|
namespace ImGui
|
||||||
|
{
|
||||||
|
// Proxy functions to access the MemAllocFn/MemFreeFn/MemReallocFn pointers in ImGui::GetIO(). The only reason they exist here is to allow ImVector<> to compile inline.
|
||||||
|
void* MemAlloc(size_t sz);
|
||||||
|
void MemFree(void* ptr);
|
||||||
|
void* MemRealloc(void* ptr, size_t sz);
|
||||||
|
};
|
||||||
|
|
||||||
// std::vector<> like class to avoid dragging dependencies (also: windows implementation of STL with debug enabled is absurdly slow, so let's bypass it so our code runs fast in debug).
|
// std::vector<> like class to avoid dragging dependencies (also: windows implementation of STL with debug enabled is absurdly slow, so let's bypass it so our code runs fast in debug).
|
||||||
// this implementation does NOT call c++ constructors! we don't need them! also only provide the minimum functionalities we need.
|
// Use '#define ImVector std::vector' if you want to use the STL type or your own type.
|
||||||
|
// Our implementation does NOT call c++ constructors! because the data types we use don't need them (but that could be added as well). Only provide the minimum functionalities we need.
|
||||||
#ifndef ImVector
|
#ifndef ImVector
|
||||||
template<typename T>
|
template<typename T>
|
||||||
class ImVector
|
class ImVector
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
size_t _size;
|
size_t Size;
|
||||||
size_t _capacity;
|
size_t Capacity;
|
||||||
T* _data;
|
T* Data;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
typedef T value_type;
|
typedef T value_type;
|
||||||
typedef value_type* iterator;
|
typedef value_type* iterator;
|
||||||
typedef const value_type* const_iterator;
|
typedef const value_type* const_iterator;
|
||||||
|
|
||||||
ImVector() { _size = _capacity = 0; _data = NULL; }
|
ImVector() { Size = Capacity = 0; Data = NULL; }
|
||||||
~ImVector() { if (_data) free(_data); }
|
~ImVector() { if (Data) ImGui::MemFree(Data); }
|
||||||
|
|
||||||
inline bool empty() const { return _size == 0; }
|
inline bool empty() const { return Size == 0; }
|
||||||
inline size_t size() const { return _size; }
|
inline size_t size() const { return Size; }
|
||||||
inline size_t capacity() const { return _capacity; }
|
inline size_t capacity() const { return Capacity; }
|
||||||
|
|
||||||
inline value_type& at(size_t i) { IM_ASSERT(i < _size); return _data[i]; }
|
inline value_type& at(size_t i) { IM_ASSERT(i < Size); return Data[i]; }
|
||||||
inline const value_type& at(size_t i) const { IM_ASSERT(i < _size); return _data[i]; }
|
inline const value_type& at(size_t i) const { IM_ASSERT(i < Size); return Data[i]; }
|
||||||
inline value_type& operator[](size_t i) { IM_ASSERT(i < _size); return _data[i]; }
|
inline value_type& operator[](size_t i) { IM_ASSERT(i < Size); return Data[i]; }
|
||||||
inline const value_type& operator[](size_t i) const { IM_ASSERT(i < _size); return _data[i]; }
|
inline const value_type& operator[](size_t i) const { IM_ASSERT(i < Size); return Data[i]; }
|
||||||
|
|
||||||
inline void clear() { if (_data) { _size = _capacity = 0; free(_data); _data = NULL; } }
|
inline void clear() { if (Data) { Size = Capacity = 0; ImGui::MemFree(Data); Data = NULL; } }
|
||||||
inline iterator begin() { return _data; }
|
inline iterator begin() { return Data; }
|
||||||
inline const iterator begin() const { return _data; }
|
inline const_iterator begin() const { return Data; }
|
||||||
inline iterator end() { return _data + _size; }
|
inline iterator end() { return Data + Size; }
|
||||||
inline const iterator end() const { return _data + _size; }
|
inline const_iterator end() const { return Data + Size; }
|
||||||
inline value_type& front() { return at(0); }
|
inline value_type& front() { return at(0); }
|
||||||
inline const value_type& front() const { return at(0); }
|
inline const value_type& front() const { return at(0); }
|
||||||
inline value_type& back() { IM_ASSERT(_size > 0); return at(_size-1); }
|
inline value_type& back() { IM_ASSERT(Size > 0); return at(Size-1); }
|
||||||
inline const value_type& back() const { IM_ASSERT(_size > 0); return at(_size-1); }
|
inline const value_type& back() const { IM_ASSERT(Size > 0); return at(Size-1); }
|
||||||
inline void swap(ImVector<T>& rhs) { const size_t rhs_size = rhs._size; rhs._size = _size; _size = rhs_size; const size_t rhs_cap = rhs._capacity; rhs._capacity = _capacity; _capacity = rhs_cap; value_type* rhs_data = rhs._data; rhs._data = _data; _data = rhs_data; }
|
inline void swap(ImVector<T>& rhs) { const size_t rhs_size = rhs.Size; rhs.Size = Size; Size = rhs_size; const size_t rhs_cap = rhs.Capacity; rhs.Capacity = Capacity; Capacity = rhs_cap; value_type* rhs_data = rhs.Data; rhs.Data = Data; Data = rhs_data; }
|
||||||
|
|
||||||
inline void reserve(size_t new_capacity) { _data = (value_type*)realloc(_data, new_capacity * sizeof(value_type)); _capacity = new_capacity; }
|
inline void reserve(size_t new_capacity) { Data = (value_type*)ImGui::MemRealloc(Data, new_capacity * sizeof(value_type)); Capacity = new_capacity; }
|
||||||
inline void resize(size_t new_size) { if (new_size > _capacity) reserve(new_size); _size = new_size; }
|
inline void resize(size_t new_size) { if (new_size > Capacity) reserve(new_size); Size = new_size; }
|
||||||
|
|
||||||
inline void push_back(const value_type& v) { if (_size == _capacity) reserve(_capacity ? _capacity * 2 : 4); _data[_size++] = v; }
|
inline void push_back(const value_type& v) { if (Size == Capacity) reserve(Capacity ? Capacity * 2 : 4); Data[Size++] = v; }
|
||||||
inline void pop_back() { IM_ASSERT(_size > 0); _size--; }
|
inline void pop_back() { IM_ASSERT(Size > 0); Size--; }
|
||||||
|
|
||||||
inline iterator erase(const_iterator it) { IM_ASSERT(it >= begin() && it < end()); const int off = it - begin(); memmove(_data + off, _data + off + 1, (_size - off - 1) * sizeof(value_type)); _size--; return _data + off; }
|
inline iterator erase(const_iterator it) { IM_ASSERT(it >= begin() && it < end()); const ptrdiff_t off = it - begin(); memmove(Data + off, Data + off + 1, (Size - off - 1) * sizeof(value_type)); Size--; return Data + off; }
|
||||||
inline void insert(const_iterator it, const value_type& v) { IM_ASSERT(it >= begin() && it <= end()); const int off = it - begin(); if (_size == _capacity) reserve(_capacity ? _capacity * 2 : 4); if (off < (int)_size) memmove(_data + off + 1, _data + off, (_size - off) * sizeof(value_type)); _data[off] = v; _size++; }
|
inline void insert(const_iterator it, const value_type& v) { IM_ASSERT(it >= begin() && it <= end()); const ptrdiff_t off = it - begin(); if (Size == Capacity) reserve(Capacity ? Capacity * 2 : 4); if (off < (int)Size) memmove(Data + off + 1, Data + off, (Size - off) * sizeof(value_type)); Data[off] = v; Size++; }
|
||||||
};
|
};
|
||||||
#endif // #ifndef ImVector
|
#endif // #ifndef ImVector
|
||||||
|
|
||||||
// Helpers at bottom of the file:
|
// Helpers at bottom of the file:
|
||||||
// - if (IMGUI_ONCE_UPON_A_FRAME) // Execute a block of code once per frame only
|
// - 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 ImGuiTextBuffer // Text buffer for logging/accumulating text
|
||||||
// - struct ImGuiStorage // Custom key value storage (if you need to alter open/close states manually)
|
// - struct ImGuiStorage // Custom key value storage (if you need to alter open/close states manually)
|
||||||
// - struct ImDrawList // Draw command list
|
// - struct ImDrawList // Draw command list
|
||||||
@ -133,23 +142,31 @@ namespace ImGui
|
|||||||
void BeginChild(const char* str_id, ImVec2 size = ImVec2(0,0), bool border = false, ImGuiWindowFlags extra_flags = 0);
|
void BeginChild(const char* str_id, ImVec2 size = ImVec2(0,0), bool border = false, ImGuiWindowFlags extra_flags = 0);
|
||||||
void EndChild();
|
void EndChild();
|
||||||
bool GetWindowIsFocused();
|
bool GetWindowIsFocused();
|
||||||
float GetWindowWidth();
|
|
||||||
ImVec2 GetWindowPos(); // you should rarely need/care about the window position, but it can be useful if you want to use your own drawing
|
|
||||||
void SetWindowPos(ImVec2 pos); // unchecked
|
|
||||||
ImVec2 GetWindowSize();
|
ImVec2 GetWindowSize();
|
||||||
|
float GetWindowWidth();
|
||||||
|
ImVec2 GetWindowPos(); // you should rarely need/care about the window position, but it can be useful if you want to use your own drawing.
|
||||||
|
void SetWindowPos(const ImVec2& pos); // set current window pos.
|
||||||
ImVec2 GetWindowContentRegionMin();
|
ImVec2 GetWindowContentRegionMin();
|
||||||
ImVec2 GetWindowContentRegionMax();
|
ImVec2 GetWindowContentRegionMax();
|
||||||
ImDrawList* GetWindowDrawList();
|
ImDrawList* GetWindowDrawList(); // get rendering command-list if you want to append your own draw primitives.
|
||||||
void SetFontScale(float scale);
|
void SetWindowFontScale(float scale); // per-window font scale. Adjust IO.FontBaseScale if you want to scale all windows together.
|
||||||
void SetScrollPosHere();
|
void SetScrollPosHere(); // adjust scrolling position to center into the current cursor position.
|
||||||
void SetTreeStateStorage(ImGuiStorage* tree);
|
void SetTreeStateStorage(ImGuiStorage* tree); // replace tree state storage with our own (if you want to manipulate it yourself, typically clear subsection of it).
|
||||||
|
ImGuiStorage* GetTreeStateStorage();
|
||||||
void PushItemWidth(float item_width);
|
void PushItemWidth(float item_width);
|
||||||
void PopItemWidth();
|
void PopItemWidth();
|
||||||
|
float GetItemWidth();
|
||||||
void PushAllowKeyboardFocus(bool v);
|
void PushAllowKeyboardFocus(bool v);
|
||||||
void PopAllowKeyboardFocus();
|
void PopAllowKeyboardFocus();
|
||||||
void PushStyleColor(ImGuiCol idx, ImVec4 col);
|
void PushStyleColor(ImGuiCol idx, const ImVec4& col);
|
||||||
void PopStyleColor();
|
void PopStyleColor();
|
||||||
|
|
||||||
|
// Tooltip
|
||||||
|
void SetTooltip(const char* fmt, ...); // set tooltip under mouse-cursor, typically use with ImGui::IsHovered(). last call wins.
|
||||||
|
void SetTooltipV(const char* fmt, va_list args);
|
||||||
|
void BeginTooltip(); // use to create full-featured tooltip windows that aren't just text.
|
||||||
|
void EndTooltip();
|
||||||
|
|
||||||
// Layout
|
// Layout
|
||||||
void Separator(); // horizontal line
|
void Separator(); // horizontal line
|
||||||
void SameLine(int column_x = 0, int spacing_w = -1); // call between widgets to layout them horizontally
|
void SameLine(int column_x = 0, int spacing_w = -1); // call between widgets to layout them horizontally
|
||||||
@ -159,9 +176,12 @@ namespace ImGui
|
|||||||
float GetColumnOffset(int column_index = -1);
|
float GetColumnOffset(int column_index = -1);
|
||||||
void SetColumnOffset(int column_index, float offset);
|
void SetColumnOffset(int column_index, float offset);
|
||||||
float GetColumnWidth(int column_index = -1);
|
float GetColumnWidth(int column_index = -1);
|
||||||
ImVec2 GetCursorPos(); // cursor position relative to window position
|
ImVec2 GetCursorPos(); // cursor position is relative to window position
|
||||||
void SetCursorPos(ImVec2 p);
|
void SetCursorPos(const ImVec2& pos); // "
|
||||||
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.
|
void SetCursorPosX(float x); // "
|
||||||
|
void SetCursorPosY(float y); // "
|
||||||
|
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 subsequent (bigger) widgets.
|
||||||
float GetTextLineSpacing();
|
float GetTextLineSpacing();
|
||||||
float GetTextLineHeight();
|
float GetTextLineHeight();
|
||||||
|
|
||||||
@ -174,26 +194,34 @@ namespace ImGui
|
|||||||
// Widgets
|
// Widgets
|
||||||
void Text(const char* fmt, ...);
|
void Text(const char* fmt, ...);
|
||||||
void TextV(const char* fmt, va_list args);
|
void TextV(const char* fmt, va_list args);
|
||||||
|
void TextColored(const ImVec4& col, const char* fmt, ...); // shortcut to doing PushStyleColor(ImGuiCol_Text, col); Text(fmt, ...); PopStyleColor();
|
||||||
|
void TextColoredV(const ImVec4& col, const char* fmt, va_list args);
|
||||||
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, better for long chunks of text.
|
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, better for long chunks of text.
|
||||||
void LabelText(const char* label, const char* fmt, ...);
|
void LabelText(const char* label, const char* fmt, ...);
|
||||||
|
void LabelTextV(const char* label, const char* fmt, va_list args);
|
||||||
void BulletText(const char* fmt, ...);
|
void BulletText(const char* fmt, ...);
|
||||||
|
void BulletTextV(const char* fmt, va_list args);
|
||||||
bool Button(const char* label, ImVec2 size = ImVec2(0,0), bool repeat_when_held = false);
|
bool Button(const char* label, ImVec2 size = ImVec2(0,0), bool repeat_when_held = false);
|
||||||
bool SmallButton(const char* label);
|
bool SmallButton(const char* label);
|
||||||
bool CollapsingHeader(const char* label, const char* str_id = NULL, const bool display_frame = true, const bool default_open = false);
|
bool CollapsingHeader(const char* label, const char* str_id = NULL, const bool display_frame = true, const bool default_open = false);
|
||||||
bool SliderFloat(const char* label, float* v, float v_min, float v_max, const char* display_format = "%.3f", float power = 1.0f);
|
bool SliderFloat(const char* label, float* v, float v_min, float v_max, const char* display_format = "%.3f", float power = 1.0f); // adjust display_format to decorate the value with a prefix or a suffix. Use power!=1.0 for logarithmic sliders.
|
||||||
|
bool SliderFloat2(const char* label, float v[2], float v_min, float v_max, const char* display_format = "%.3f", float power = 1.0f);
|
||||||
bool SliderFloat3(const char* label, float v[3], float v_min, float v_max, const char* display_format = "%.3f", float power = 1.0f);
|
bool SliderFloat3(const char* label, float v[3], float v_min, float v_max, const char* display_format = "%.3f", float power = 1.0f);
|
||||||
|
bool SliderFloat4(const char* label, float v[4], float v_min, float v_max, const char* display_format = "%.3f", float power = 1.0f);
|
||||||
bool SliderAngle(const char* label, float* v, float v_degrees_min = -360.0f, float v_degrees_max = +360.0f); // *v in radians
|
bool SliderAngle(const char* label, float* v, float v_degrees_min = -360.0f, float v_degrees_max = +360.0f); // *v in radians
|
||||||
bool SliderInt(const char* label, int* v, int v_min, int v_max, const char* display_format = "%.0f");
|
bool SliderInt(const char* label, int* v, int v_min, int v_max, const char* display_format = "%.0f");
|
||||||
void PlotLines(const char* label, const float* values, int values_count, int values_offset = 0, const char* overlay_text = NULL, float scale_min = FLT_MAX, float scale_max = FLT_MAX, ImVec2 graph_size = ImVec2(0,0));
|
void PlotLines(const char* label, const float* values, int values_count, int values_offset = 0, const char* overlay_text = NULL, float scale_min = FLT_MAX, float scale_max = FLT_MAX, ImVec2 graph_size = ImVec2(0,0), size_t stride = sizeof(float));
|
||||||
void PlotHistogram(const char* label, const float* values, int values_count, int values_offset = 0, const char* overlay_text = NULL, float scale_min = FLT_MAX, float scale_max = FLT_MAX, ImVec2 graph_size = ImVec2(0,0));
|
void PlotHistogram(const char* label, const float* values, int values_count, int values_offset = 0, const char* overlay_text = NULL, float scale_min = FLT_MAX, float scale_max = FLT_MAX, ImVec2 graph_size = ImVec2(0,0), size_t stride = sizeof(float));
|
||||||
void Checkbox(const char* label, bool* v);
|
bool Checkbox(const char* label, bool* v);
|
||||||
void CheckboxFlags(const char* label, unsigned int* flags, unsigned int flags_value);
|
bool CheckboxFlags(const char* label, unsigned int* flags, unsigned int flags_value);
|
||||||
bool RadioButton(const char* label, bool active);
|
bool RadioButton(const char* label, bool active);
|
||||||
bool RadioButton(const char* label, int* v, int v_button);
|
bool RadioButton(const char* label, int* v, int v_button);
|
||||||
bool InputFloat(const char* label, float* v, float step = 0.0f, float step_fast = 0.0f, int decimal_precision = -1);
|
|
||||||
bool InputFloat3(const char* label, float v[3], int decimal_precision = -1);
|
|
||||||
bool InputInt(const char* label, int* v, int step = 1, int step_fast = 100);
|
|
||||||
bool InputText(const char* label, char* buf, size_t buf_size, ImGuiInputTextFlags flags = 0);
|
bool InputText(const char* label, char* buf, size_t buf_size, ImGuiInputTextFlags flags = 0);
|
||||||
|
bool InputFloat(const char* label, float* v, float step = 0.0f, float step_fast = 0.0f, int decimal_precision = -1, ImGuiInputTextFlags extra_flags = 0);
|
||||||
|
bool InputFloat2(const char* label, float v[2], int decimal_precision = -1);
|
||||||
|
bool InputFloat3(const char* label, float v[3], int decimal_precision = -1);
|
||||||
|
bool InputFloat4(const char* label, float v[4], int decimal_precision = -1);
|
||||||
|
bool InputInt(const char* label, int* v, int step = 1, int step_fast = 100, ImGuiInputTextFlags extra_flags = 0);
|
||||||
bool Combo(const char* label, int* current_item, const char** items, int items_count, int popup_height_items = 7);
|
bool Combo(const char* label, int* current_item, const char** items, int items_count, int popup_height_items = 7);
|
||||||
bool Combo(const char* label, int* current_item, const char* items_separated_by_zeros, int popup_height_items = 7); // Separate items with \0, end item-list with \0\0
|
bool Combo(const char* label, int* current_item, const char* items_separated_by_zeros, int popup_height_items = 7); // Separate items with \0, end item-list with \0\0
|
||||||
bool Combo(const char* label, int* current_item, bool (*items_getter)(void* data, int idx, const char** out_text), void* data, int items_count, int popup_height_items = 7);
|
bool Combo(const char* label, int* current_item, bool (*items_getter)(void* data, int idx, const char** out_text), void* data, int items_count, int popup_height_items = 7);
|
||||||
@ -201,10 +229,12 @@ namespace ImGui
|
|||||||
bool ColorEdit3(const char* label, float col[3]);
|
bool ColorEdit3(const char* label, float col[3]);
|
||||||
bool ColorEdit4(const char* label, float col[4], bool show_alpha = true);
|
bool ColorEdit4(const char* label, float col[4], bool show_alpha = true);
|
||||||
void ColorEditMode(ImGuiColorEditMode mode);
|
void ColorEditMode(ImGuiColorEditMode mode);
|
||||||
bool TreeNode(const char* str_label_id); // if returning 'true' the user is responsible for calling TreePop
|
bool TreeNode(const char* str_label_id); // if returning 'true' the node is open and the user is responsible for calling TreePop
|
||||||
bool TreeNode(const char* str_id, const char* fmt, ...); // "
|
bool TreeNode(const char* str_id, const char* fmt, ...); // "
|
||||||
bool TreeNode(const void* ptr_id, const char* fmt, ...); // "
|
bool TreeNode(const void* ptr_id, const char* fmt, ...); // "
|
||||||
void TreePush(const char* str_id = NULL); // already called by TreeNode(), but you can call Push/Pop yourself for layout purpose
|
bool TreeNodeV(const char* str_id, const char* fmt, va_list args); // "
|
||||||
|
bool TreeNodeV(const void* ptr_id, const char* fmt, va_list args); // "
|
||||||
|
void TreePush(const char* str_id = NULL); // already called by TreeNode(), but you can call Push/Pop yourself for layouting purpose
|
||||||
void TreePush(const void* ptr_id = NULL); // "
|
void TreePush(const void* ptr_id = NULL); // "
|
||||||
void TreePop();
|
void TreePop();
|
||||||
void OpenNextNode(bool open); // force open/close the next TreeNode or CollapsingHeader
|
void OpenNextNode(bool open); // force open/close the next TreeNode or CollapsingHeader
|
||||||
@ -220,22 +250,29 @@ namespace ImGui
|
|||||||
|
|
||||||
// Logging
|
// Logging
|
||||||
void LogButtons();
|
void LogButtons();
|
||||||
void LogToTTY(int max_depth);
|
void LogToTTY(int max_depth = -1);
|
||||||
void LogToFile(int max_depth, const char* filename);
|
void LogToFile(int max_depth = -1, const char* filename = NULL);
|
||||||
void LogToClipboard(int max_depth);
|
void LogToClipboard(int max_depth = -1);
|
||||||
|
|
||||||
// Utilities
|
// Utilities
|
||||||
void SetTooltip(const char* fmt, ...); // set tooltip under mouse-cursor, typically use with ImGui::IsHovered(). (currently no contention handling, last call win)
|
void SetNewWindowDefaultPos(const ImVec2& pos); // set position of window that do
|
||||||
void SetNewWindowDefaultPos(ImVec2 pos); // set position of window that do
|
|
||||||
bool IsHovered(); // was the last item active area hovered by mouse?
|
bool IsHovered(); // was the last item active area hovered by mouse?
|
||||||
bool IsClipped(ImVec2 item_size); // to perform coarse clipping on user's side (as an optimisation)
|
ImVec2 GetItemBoxMin(); // get bounding box of last item
|
||||||
|
ImVec2 GetItemBoxMax(); // get bounding box of last item
|
||||||
|
bool IsClipped(const ImVec2& item_size); // to perform coarse clipping on user's side (as an optimisation)
|
||||||
bool IsKeyPressed(int key_index, bool repeat = true); // key_index into the keys_down[512] array, imgui doesn't know the semantic of each entry
|
bool IsKeyPressed(int key_index, bool repeat = true); // key_index into the keys_down[512] array, imgui doesn't know the semantic of each entry
|
||||||
bool IsMouseClicked(int button, bool repeat = false);
|
bool IsMouseClicked(int button, bool repeat = false);
|
||||||
ImVec2 GetMousePos();
|
bool IsMouseDoubleClicked(int button);
|
||||||
|
bool IsMouseHoveringWindow(); // is mouse hovering current window ("window" in API names always refer to current window)
|
||||||
|
bool IsMouseHoveringAnyWindow(); // is mouse hovering any active imgui window
|
||||||
|
bool IsMouseHoveringBox(const ImVec2& box_min, const ImVec2& box_max); // is mouse hovering given bounding box
|
||||||
|
bool IsPosHoveringAnyWindow(const ImVec2& pos); // is given position hovering any active imgui window
|
||||||
|
ImVec2 GetMousePos(); // shortcut to ImGui::GetIO().MousePos provided by user, to be consistent with other calls
|
||||||
float GetTime();
|
float GetTime();
|
||||||
int GetFrameCount();
|
int GetFrameCount();
|
||||||
const char* GetStyleColorName(ImGuiCol idx);
|
const char* GetStyleColorName(ImGuiCol idx);
|
||||||
void GetDefaultFontData(const void** fnt_data, unsigned int* fnt_size, const void** png_data, unsigned int* png_size);
|
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
|
}; // namespace ImGui
|
||||||
|
|
||||||
@ -259,10 +296,11 @@ enum ImGuiWindowFlags_
|
|||||||
enum ImGuiInputTextFlags_
|
enum ImGuiInputTextFlags_
|
||||||
{
|
{
|
||||||
// Default: 0
|
// Default: 0
|
||||||
ImGuiInputTextFlags_CharsDecimal = 1 << 0,
|
ImGuiInputTextFlags_CharsDecimal = 1 << 0, // Allow 0123456789.+-*/
|
||||||
ImGuiInputTextFlags_CharsHexadecimal = 1 << 1,
|
ImGuiInputTextFlags_CharsHexadecimal = 1 << 1, // Allow 0123456789ABCDEFabcdef
|
||||||
ImGuiInputTextFlags_AutoSelectAll = 1 << 2,
|
ImGuiInputTextFlags_AutoSelectAll = 1 << 2, // Select entire text when first taking focus
|
||||||
ImGuiInputTextFlags_AlignCenter = 1 << 3,
|
ImGuiInputTextFlags_EnterReturnsTrue = 1 << 3, // Return 'true' when Enter is pressed (as opposed to when the value was modified)
|
||||||
|
//ImGuiInputTextFlags_AlignCenter = 1 << 3,
|
||||||
};
|
};
|
||||||
|
|
||||||
// User fill ImGuiIO.KeyMap[] array with indices into the ImGuiIO.KeysDown[512] array
|
// User fill ImGuiIO.KeyMap[] array with indices into the ImGuiIO.KeysDown[512] array
|
||||||
@ -302,6 +340,7 @@ enum ImGuiCol_
|
|||||||
ImGuiCol_ScrollbarGrabHovered,
|
ImGuiCol_ScrollbarGrabHovered,
|
||||||
ImGuiCol_ScrollbarGrabActive,
|
ImGuiCol_ScrollbarGrabActive,
|
||||||
ImGuiCol_ComboBg,
|
ImGuiCol_ComboBg,
|
||||||
|
ImGuiCol_CheckHovered,
|
||||||
ImGuiCol_CheckActive,
|
ImGuiCol_CheckActive,
|
||||||
ImGuiCol_SliderGrab,
|
ImGuiCol_SliderGrab,
|
||||||
ImGuiCol_SliderGrabActive,
|
ImGuiCol_SliderGrabActive,
|
||||||
@ -337,21 +376,21 @@ enum ImGuiColorEditMode_
|
|||||||
ImGuiColorEditMode_HEX = 2,
|
ImGuiColorEditMode_HEX = 2,
|
||||||
};
|
};
|
||||||
|
|
||||||
// See constructor for comments of individual fields.
|
|
||||||
struct ImGuiStyle
|
struct ImGuiStyle
|
||||||
{
|
{
|
||||||
ImVec2 WindowPadding;
|
float Alpha; // Global alpha applies to everything in ImGui
|
||||||
ImVec2 WindowMinSize;
|
ImVec2 WindowPadding; // Padding within a window
|
||||||
ImVec2 FramePadding;
|
ImVec2 WindowMinSize; // Minimum window size
|
||||||
ImVec2 ItemSpacing;
|
ImVec2 FramePadding; // Padding within a framed rectangle (used by most widgets)
|
||||||
ImVec2 ItemInnerSpacing;
|
ImVec2 ItemSpacing; // Horizontal and vertical spacing between widgets/lines
|
||||||
ImVec2 TouchExtraPadding;
|
ImVec2 ItemInnerSpacing; // Horizontal and vertical spacing between within elements of a composed widget (e.g. a slider and its label)
|
||||||
ImVec2 AutoFitPadding;
|
ImVec2 TouchExtraPadding; // Expand bounding box for touch-based system where touch position is not accurate enough (unnecessary for mouse inputs). Unfortunately we don't sort widgets so priority on overlap will always be given to the first widget running. So dont grow this too much!
|
||||||
float WindowFillAlphaDefault;
|
ImVec2 AutoFitPadding; // Extra space after auto-fit (double-clicking on resize grip)
|
||||||
float WindowRounding;
|
float WindowFillAlphaDefault; // Default alpha of window background, if not specified in ImGui::Begin()
|
||||||
float TreeNodeSpacing;
|
float WindowRounding; // Radius of window corners rounding. Set to 0.0f to have rectangular windows
|
||||||
float ColumnsMinSpacing;
|
float TreeNodeSpacing; // Horizontal spacing when entering a tree node
|
||||||
float ScrollBarWidth;
|
float ColumnsMinSpacing; // Minimum horizontal spacing between two columns
|
||||||
|
float ScrollBarWidth; // Width of the vertical scroll bar
|
||||||
ImVec4 Colors[ImGuiCol_COUNT];
|
ImVec4 Colors[ImGuiCol_COUNT];
|
||||||
|
|
||||||
ImGuiStyle();
|
ImGuiStyle();
|
||||||
@ -371,39 +410,56 @@ struct ImGuiIO
|
|||||||
float MouseDoubleClickMaxDist; // = 6.0f // Distance threshold to stay in to validate a double-click, in pixels.
|
float MouseDoubleClickMaxDist; // = 6.0f // Distance threshold to stay in to validate a double-click, in pixels.
|
||||||
int KeyMap[ImGuiKey_COUNT]; // <unset> // Map of indices into the KeysDown[512] entries array
|
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).
|
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
|
float FontYOffset; // = 0.0f // Offset font rendering by xx pixels in Y axis.
|
||||||
bool FontAllowScaling; // = false // Set to allow scaling text with CTRL+Wheel.
|
ImVec2 FontTexUvForWhite; // = (0.0f,0.0f) // Font texture must have a white pixel at this UV coordinate. Adjust if you are using custom texture.
|
||||||
|
float FontBaseScale; // = 1.0f // Base font scale, multiplied by the per-window font scale which you can adjust with SetFontScale()
|
||||||
|
bool FontAllowUserScaling; // = false // Set to allow scaling text with CTRL+Wheel.
|
||||||
|
float PixelCenterOffset; // = 0.0f // Try to set to 0.5f or 0.375f if rendering is blurry
|
||||||
|
|
||||||
// Settings - Functions (fill once)
|
// Settings - Rendering function (REQUIRED)
|
||||||
void (*RenderDrawListsFn)(ImDrawList** const draw_lists, int count); // Required
|
// See example code if you are unsure of how to implement this.
|
||||||
const char* (*GetClipboardTextFn)(); // Required for clipboard support
|
void (*RenderDrawListsFn)(ImDrawList** const draw_lists, int count);
|
||||||
void (*SetClipboardTextFn)(const char* text, const char* text_end); // Required for clipboard support (nb- the string is *NOT* zero-terminated at 'text_end')
|
|
||||||
|
// Settings - Clipboard Support
|
||||||
|
// Override to provide your clipboard handlers.
|
||||||
|
// On Windows architecture, defaults to use the native Win32 clipboard, otherwise default to use a ImGui private clipboard.
|
||||||
|
// NB- for SetClipboardTextFn, the string is *NOT* zero-terminated at 'text_end'
|
||||||
|
const char* (*GetClipboardTextFn)();
|
||||||
|
void (*SetClipboardTextFn)(const char* text, const char* text_end);
|
||||||
|
|
||||||
|
// Settings - Memory allocation
|
||||||
|
// Default to posix malloc/realloc/free functions.
|
||||||
|
void* (*MemAllocFn)(size_t sz);
|
||||||
|
void* (*MemReallocFn)(void* ptr, size_t sz);
|
||||||
|
void (*MemFreeFn)(void* ptr);
|
||||||
|
|
||||||
// Input - Fill before calling NewFrame()
|
// Input - Fill before calling NewFrame()
|
||||||
ImVec2 MousePos; // Mouse position (set to -1,-1 if no mouse / on another screen, etc.)
|
ImVec2 MousePos; // Mouse position, in pixels (set to -1,-1 if no mouse / on another screen, etc.)
|
||||||
bool MouseDown[2]; // Mouse buttons
|
bool MouseDown[5]; // Mouse buttons. ImGui itself only uses button 0 (left button) but you can use others as storage for convenience.
|
||||||
int MouseWheel; // Mouse wheel: -1,0,+1
|
int MouseWheel; // Mouse wheel: -1,0,+1
|
||||||
bool KeyCtrl; // Keyboard modifier pressed: Control
|
bool KeyCtrl; // Keyboard modifier pressed: Control
|
||||||
bool KeyShift; // Keyboard modifier pressed: Shift
|
bool KeyShift; // Keyboard modifier pressed: Shift
|
||||||
bool KeysDown[512]; // Keyboard keys that are pressed (in whatever order user naturally has access to keyboard data)
|
bool KeysDown[512]; // Keyboard keys that are pressed (in whatever order user naturally has access to keyboard data)
|
||||||
char InputCharacters[16]; // List of characters input (translated by user from keypress+keyboard state). Fill using AddInputCharacter() helper.
|
char InputCharacters[16]; // List of characters input (translated by user from keypress+keyboard state). Fill using AddInputCharacter() helper.
|
||||||
|
|
||||||
// Output - Retrieve after calling NewFrame(), you can use them to discard inputs for the rest of your application
|
// Output - Retrieve after calling NewFrame(), you can use them to discard inputs or hide them from the rest of your application
|
||||||
bool WantCaptureMouse; // ImGui is using your mouse input (= window is being hovered or widget is active).
|
bool WantCaptureMouse; // Mouse is hovering a window or widget is active (= ImGui will use your mouse input)
|
||||||
bool WantCaptureKeyboard; // imGui is using your keyboard input (= widget is active).
|
bool WantCaptureKeyboard; // Widget is active (= ImGui will use your keyboard input)
|
||||||
|
|
||||||
|
// Function
|
||||||
|
void AddInputCharacter(char c); // Helper to add a new character into InputCharacters[]
|
||||||
|
|
||||||
// [Internal] ImGui will maintain those fields for you
|
// [Internal] ImGui will maintain those fields for you
|
||||||
ImVec2 MousePosPrev;
|
ImVec2 MousePosPrev;
|
||||||
ImVec2 MouseDelta;
|
ImVec2 MouseDelta;
|
||||||
bool MouseClicked[2];
|
bool MouseClicked[5];
|
||||||
ImVec2 MouseClickedPos[2];
|
ImVec2 MouseClickedPos[5];
|
||||||
float MouseClickedTime[2];
|
float MouseClickedTime[5];
|
||||||
bool MouseDoubleClicked[2];
|
bool MouseDoubleClicked[5];
|
||||||
float MouseDownTime[2];
|
float MouseDownTime[5];
|
||||||
float KeysDownTime[512];
|
float KeysDownTime[512];
|
||||||
|
|
||||||
ImGuiIO();
|
ImGuiIO();
|
||||||
void AddInputCharacter(char c); // Helper to add a new character into InputCharacters[]
|
|
||||||
};
|
};
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
@ -422,7 +478,7 @@ private:
|
|||||||
bool TryIsNewFrame() const { const int current_frame = ImGui::GetFrameCount(); if (LastFrame == current_frame) return false; LastFrame = current_frame; return true; }
|
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 ImGuiTextFilter
|
||||||
{
|
{
|
||||||
struct TextRange
|
struct TextRange
|
||||||
@ -436,7 +492,7 @@ struct ImGuiTextFilter
|
|||||||
const char* end() const { return e; }
|
const char* end() const { return e; }
|
||||||
bool empty() const { return b == e; }
|
bool empty() const { return b == e; }
|
||||||
char front() const { return *b; }
|
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 trim_blanks() { while (b < e && isblank(*b)) b++; while (e > b && isblank(*(e-1))) e--; }
|
||||||
void split(char separator, ImVector<TextRange>& out);
|
void split(char separator, ImVector<TextRange>& out);
|
||||||
};
|
};
|
||||||
@ -464,7 +520,7 @@ struct ImGuiTextBuffer
|
|||||||
size_t size() const { return Buf.size()-1; }
|
size_t size() const { return Buf.size()-1; }
|
||||||
bool empty() { return Buf.empty(); }
|
bool empty() { return Buf.empty(); }
|
||||||
void clear() { Buf.clear(); Buf.push_back(0); }
|
void clear() { Buf.clear(); Buf.push_back(0); }
|
||||||
void Append(const char* fmt, ...);
|
void append(const char* fmt, ...);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Helper: Key->value storage
|
// Helper: Key->value storage
|
||||||
@ -491,25 +547,12 @@ struct ImGuiStorage
|
|||||||
// Hold a series of drawing commands. The user provide a renderer for ImDrawList
|
// Hold a series of drawing commands. The user provide a renderer for ImDrawList
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
enum ImDrawCmdType
|
|
||||||
{
|
|
||||||
ImDrawCmdType_DrawTriangleList,
|
|
||||||
ImDrawCmdType_PushClipRect,
|
|
||||||
ImDrawCmdType_PopClipRect,
|
|
||||||
};
|
|
||||||
|
|
||||||
// sizeof() == 4
|
|
||||||
struct ImDrawCmd
|
struct ImDrawCmd
|
||||||
{
|
{
|
||||||
ImDrawCmdType cmd_type : 16;
|
unsigned int vtx_count;
|
||||||
unsigned int vtx_count : 16;
|
ImVec4 clip_rect;
|
||||||
ImDrawCmd(ImDrawCmdType _cmd_type = ImDrawCmdType_DrawTriangleList, unsigned int _vtx_count = 0) { cmd_type = _cmd_type; vtx_count = _vtx_count; }
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifndef IMDRAW_TEX_UV_FOR_WHITE
|
|
||||||
#define IMDRAW_TEX_UV_FOR_WHITE ImVec2(0,0)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// sizeof() == 20
|
// sizeof() == 20
|
||||||
struct ImDrawVert
|
struct ImDrawVert
|
||||||
{
|
{
|
||||||
@ -522,18 +565,20 @@ struct ImDrawVert
|
|||||||
// User is responsible for providing a renderer for this in ImGuiIO::RenderDrawListFn
|
// User is responsible for providing a renderer for this in ImGuiIO::RenderDrawListFn
|
||||||
struct ImDrawList
|
struct ImDrawList
|
||||||
{
|
{
|
||||||
ImVector<ImDrawCmd> commands;
|
// This is what you have to render
|
||||||
|
ImVector<ImDrawCmd> commands; // commands
|
||||||
ImVector<ImDrawVert> vtx_buffer; // each command consume ImDrawCmd::vtx_count of those
|
ImVector<ImDrawVert> vtx_buffer; // each command consume ImDrawCmd::vtx_count of those
|
||||||
ImVector<ImVec4> clip_rect_buffer; // each PushClipRect command consume 1 of those
|
|
||||||
ImVector<ImVec4> clip_rect_stack_; // [internal] clip rect stack while building the command-list (so text command can perform clipping early on)
|
// [Internal to ImGui]
|
||||||
ImDrawVert* vtx_write_; // [internal] point within vtx_buffer after each add command. allow us to use less [] and .resize on the vector (often slow on windows/debug)
|
ImVector<ImVec4> clip_rect_stack; // [internal] clip rect stack while building the command-list (so text command can perform clipping early on)
|
||||||
|
ImDrawVert* vtx_write; // [internal] point within vtx_buffer after each add command (to avoid using the ImVector<> operators too much)
|
||||||
|
|
||||||
ImDrawList() { Clear(); }
|
ImDrawList() { Clear(); }
|
||||||
|
|
||||||
void Clear();
|
void Clear();
|
||||||
void PushClipRect(const ImVec4& clip_rect);
|
void PushClipRect(const ImVec4& clip_rect);
|
||||||
void PopClipRect();
|
void PopClipRect();
|
||||||
void AddCommand(ImDrawCmdType cmd_type, int vtx_count);
|
void ReserveVertices(unsigned int vtx_count);
|
||||||
void AddVtx(const ImVec2& pos, ImU32 col);
|
void AddVtx(const ImVec2& pos, ImU32 col);
|
||||||
void AddVtxLine(const ImVec2& a, const ImVec2& b, ImU32 col);
|
void AddVtxLine(const ImVec2& a, const ImVec2& b, ImU32 col);
|
||||||
|
|
||||||
@ -602,7 +647,7 @@ struct ImBitmapFont
|
|||||||
#pragma pack(pop)
|
#pragma pack(pop)
|
||||||
|
|
||||||
unsigned char* Data; // Raw data, content of .fnt file
|
unsigned char* Data; // Raw data, content of .fnt file
|
||||||
int DataSize; //
|
size_t DataSize; //
|
||||||
bool DataOwned; //
|
bool DataOwned; //
|
||||||
const FntInfo* Info; // (point into raw data)
|
const FntInfo* Info; // (point into raw data)
|
||||||
const FntCommon* Common; // (point into raw data)
|
const FntCommon* Common; // (point into raw data)
|
||||||
@ -617,12 +662,13 @@ struct ImBitmapFont
|
|||||||
ImBitmapFont();
|
ImBitmapFont();
|
||||||
~ImBitmapFont() { Clear(); }
|
~ImBitmapFont() { Clear(); }
|
||||||
|
|
||||||
bool LoadFromMemory(const void* data, int data_size);
|
bool LoadFromMemory(const void* data, size_t data_size);
|
||||||
bool LoadFromFile(const char* filename);
|
bool LoadFromFile(const char* filename);
|
||||||
void Clear();
|
void Clear();
|
||||||
void BuildLookupTable();
|
void BuildLookupTable();
|
||||||
const FntGlyph * FindGlyph(unsigned short c) const;
|
const FntGlyph * FindGlyph(unsigned short c) const;
|
||||||
float GetFontSize() const { return (float)Info->FontSize; }
|
float GetFontSize() const { return (float)Info->FontSize; }
|
||||||
|
bool IsLoaded() const { return Info != NULL && Common != NULL && Glyphs != NULL; }
|
||||||
|
|
||||||
ImVec2 CalcTextSize(float size, float max_width, const char* text_begin, const char* text_end, const char** remaining = NULL) const;
|
ImVec2 CalcTextSize(float size, float max_width, const char* text_begin, const char* text_end, const char** remaining = NULL) const;
|
||||||
void RenderText(float size, ImVec2 pos, ImU32 col, const ImVec4& clip_rect, const char* text_begin, const char* text_end, ImDrawVert*& out_vertices) const;
|
void RenderText(float size, ImVec2 pos, ImU32 col, const ImVec4& clip_rect, const char* text_begin, const char* text_end, ImDrawVert*& out_vertices) const;
|
||||||
|
@ -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
|
// Development of this library was sponsored by RAD Game Tools
|
||||||
//
|
//
|
||||||
// This C header file implements the guts of a multi-line text-editing
|
// This C header file implements the guts of a multi-line text-editing
|
||||||
@ -30,8 +30,9 @@
|
|||||||
//
|
//
|
||||||
// VERSION HISTORY
|
// VERSION HISTORY
|
||||||
//
|
//
|
||||||
// 1.3 (2013-06-19) fix mouse clicking to round to nearest char boundary
|
// 1.4 (2014-08-17) fix signed/unsigned warnings
|
||||||
// 1.2 (2013-05-27) fix some RAD types that had crept into the new code
|
// 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.1 (2013-12-15) move-by-word (requires STB_TEXTEDIT_IS_SPACE )
|
||||||
// 1.0 (2012-07-26) improve documentation, initial public release
|
// 1.0 (2012-07-26) improve documentation, initial public release
|
||||||
// 0.3 (2012-02-24) bugfixes, single-line mode; insert mode
|
// 0.3 (2012-02-24) bugfixes, single-line mode; insert mode
|
||||||
@ -41,7 +42,7 @@
|
|||||||
// ADDITIONAL CONTRIBUTORS
|
// ADDITIONAL CONTRIBUTORS
|
||||||
//
|
//
|
||||||
// Ulf Winklemann: move-by-word in 1.1
|
// 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
|
// 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_undo(STB_TEXTEDIT_STRING *str, STB_TexteditState *state);
|
||||||
static void stb_text_redo(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_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);
|
static void stb_text_makeundo_replace(STB_TEXTEDIT_STRING *str, STB_TexteditState *state, int where, int old_length, int new_length);
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
@ -649,7 +650,7 @@ static int stb_textedit_paste(STB_TEXTEDIT_STRING *str, STB_TexteditState *state
|
|||||||
stb_textedit_delete_selection(str,state);
|
stb_textedit_delete_selection(str,state);
|
||||||
// try to insert the characters
|
// try to insert the characters
|
||||||
if (STB_TEXTEDIT_INSERTCHARS(str, state->cursor, text, len)) {
|
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->cursor += len;
|
||||||
state->has_preferred_x = 0;
|
state->has_preferred_x = 0;
|
||||||
return 1;
|
return 1;
|
||||||
@ -684,7 +685,7 @@ retry:
|
|||||||
} else {
|
} else {
|
||||||
stb_textedit_delete_selection(str,state); // implicity clamps
|
stb_textedit_delete_selection(str,state); // implicity clamps
|
||||||
if (STB_TEXTEDIT_INSERTCHARS(str, state->cursor, &ch, 1)) {
|
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->cursor;
|
||||||
state->has_preferred_x = 0;
|
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;
|
int n = state->undo_rec[0].insert_length, i;
|
||||||
// delete n characters from all other records
|
// delete n characters from all other records
|
||||||
state->undo_char_point = state->undo_char_point - (short) n; // vsnet05
|
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)
|
for (i=0; i < state->undo_point; ++i)
|
||||||
if (state->undo_rec[i].char_storage >= 0)
|
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_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;
|
--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;
|
int n = state->undo_rec[k].insert_length, i;
|
||||||
// delete n characters from all other records
|
// delete n characters from all other records
|
||||||
state->redo_char_point = state->redo_char_point + (short) n; // vsnet05
|
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)
|
for (i=state->redo_point; i < k; ++i)
|
||||||
if (state->undo_rec[i].char_storage >= 0)
|
if (state->undo_rec[i].char_storage >= 0)
|
||||||
state->undo_rec[i].char_storage = state->undo_rec[i].char_storage + (short) n; // vsnet05
|
state->undo_rec[i].char_storage = state->undo_rec[i].char_storage + (short) n; // vsnet05
|
||||||
}
|
}
|
||||||
++state->redo_point;
|
++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++;
|
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);
|
stb_text_createundo(&state->undostate, where, 0, length);
|
||||||
}
|
}
|
||||||
|
Before Width: | Height: | Size: 11 KiB After Width: | Height: | Size: 7.8 KiB |
BIN
web/skinning_sample_01.png
Normal file
After Width: | Height: | Size: 18 KiB |