mirror of
https://github.com/Drezil/imgui.git
synced 2025-07-13 16:29:54 +02:00
Compare commits
10 Commits
Author | SHA1 | Date | |
---|---|---|---|
cb3d503941 | |||
ddc7f8b0b0 | |||
57ac561ecb | |||
2573ffb6fc | |||
c938affcac | |||
a1e176fb07 | |||
901e9890d4 | |||
f4ee74b312 | |||
64e5c2f127 | |||
e2655d104e |
11
README.md
11
README.md
@ -11,7 +11,6 @@ After ImGui is setup in your application, 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.
|
||||||
|
|
||||||
|
|
||||||
Gallery
|
Gallery
|
||||||
-------
|
-------
|
||||||
|
|
||||||
@ -20,6 +19,16 @@ 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).
|
||||||
|
|
||||||
|
|
||||||
Credits
|
Credits
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
@ -86,36 +86,15 @@ static void ImImpl_RenderDrawLists(ImDrawList** const cmd_lists, int cmd_lists_c
|
|||||||
int vtx_offset = 0;
|
int vtx_offset = 0;
|
||||||
for (int n = 0; n < cmd_lists_count; n++)
|
for (int n = 0; n < cmd_lists_count; n++)
|
||||||
{
|
{
|
||||||
// Setup stack of clipping rectangles
|
|
||||||
int clip_rect_buf_offset = 0;
|
|
||||||
ImVector<ImVec4> clip_rect_stack;
|
|
||||||
clip_rect_stack.push_back(ImVec4(-9999,-9999,+9999,+9999));
|
|
||||||
|
|
||||||
// Render command list
|
// Render command list
|
||||||
const ImDrawList* cmd_list = cmd_lists[n];
|
const ImDrawList* cmd_list = cmd_lists[n];
|
||||||
const ImDrawCmd* pcmd_end = cmd_list->commands.end();
|
const ImDrawCmd* pcmd_end = cmd_list->commands.end();
|
||||||
for (const ImDrawCmd* pcmd = cmd_list->commands.begin(); pcmd != pcmd_end; pcmd++)
|
for (const ImDrawCmd* pcmd = cmd_list->commands.begin(); pcmd != pcmd_end; pcmd++)
|
||||||
{
|
{
|
||||||
switch (pcmd->cmd_type)
|
const RECT r = { (LONG)pcmd->clip_rect.x, (LONG)pcmd->clip_rect.y, (LONG)pcmd->clip_rect.z, (LONG)pcmd->clip_rect.w };
|
||||||
{
|
g_pd3dDevice->SetScissorRect(&r);
|
||||||
case ImDrawCmdType_DrawTriangleList:
|
g_pd3dDevice->DrawPrimitive(D3DPT_TRIANGLELIST, vtx_offset, pcmd->vtx_count/3);
|
||||||
{
|
vtx_offset += pcmd->vtx_count;
|
||||||
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->DrawPrimitive(D3DPT_TRIANGLELIST, vtx_offset, pcmd->vtx_count/3);
|
|
||||||
vtx_offset += pcmd->vtx_count;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case ImDrawCmdType_PushClipRect:
|
|
||||||
clip_rect_stack.push_back(cmd_list->clip_rect_buffer[clip_rect_buf_offset++]);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case ImDrawCmdType_PopClipRect:
|
|
||||||
clip_rect_stack.pop_back();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
18
examples/opengl_example/Makefile.Linux
Normal file
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)
|
17
examples/opengl_example/Makefile.Macosx
Normal file
17
examples/opengl_example/Makefile.Macosx
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
# 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
|
||||||
|
#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
|
@ -2,106 +2,63 @@
|
|||||||
#include <GL/glew.h>
|
#include <GL/glew.h>
|
||||||
#include <GLFW/glfw3.h>
|
#include <GLFW/glfw3.h>
|
||||||
#define STB_IMAGE_IMPLEMENTATION
|
#define STB_IMAGE_IMPLEMENTATION
|
||||||
#include "stb_image.h" // for .png loading
|
#include "stb_image.h" // for .png loading
|
||||||
#include "../../imgui.h"
|
#include "../../imgui.h"
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
#pragma warning (disable: 4996) // 'This function or variable may be unsafe': strcpy, strdup, sprintf, vsnprintf, sscanf, fopen
|
#pragma warning (disable: 4996) // 'This function or variable may be unsafe': strcpy, strdup, sprintf, vsnprintf, sscanf, fopen
|
||||||
#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;
|
||||||
|
|
||||||
// This is the main rendering function that you have to implement and provide to ImGui (via setting up 'RenderDrawListsFn' in the ImGuiIO structuer)
|
// This is the main rendering function that you have to implement and provide to ImGui (via setting up 'RenderDrawListsFn' in the ImGuiIO structuer)
|
||||||
|
// We are using the fixed pipeline.
|
||||||
|
// A faster way would be to collate all vertices from all cmd_lists into a single vertex buffer
|
||||||
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;
|
||||||
|
|
||||||
// Copy all vertices into a single contiguous GL buffer
|
|
||||||
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;
|
|
||||||
for (int n = 0; n < cmd_lists_count; n++)
|
|
||||||
{
|
|
||||||
const ImDrawList* cmd_list = cmd_lists[n];
|
|
||||||
memcpy(buffer_data, &cmd_list->vtx_buffer[0], cmd_list->vtx_buffer.size() * sizeof(ImDrawVert));
|
|
||||||
buffer_data += cmd_list->vtx_buffer.size() * sizeof(ImDrawVert);
|
|
||||||
}
|
|
||||||
glUnmapBuffer(GL_ARRAY_BUFFER);
|
|
||||||
|
|
||||||
// Setup render state: alpha-blending enabled, no face culling, no depth testing
|
// 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);
|
||||||
|
|
||||||
// Bind texture and enable our shader
|
// Bind texture
|
||||||
glBindTexture(GL_TEXTURE_2D, fontTex);
|
glBindTexture(GL_TEXTURE_2D, fontTex);
|
||||||
glUseProgram(shaderProgram);
|
glEnable(GL_TEXTURE_2D);
|
||||||
const GLint uniMVP = glGetUniformLocation(shaderProgram, "MVP");
|
|
||||||
const GLint uniClipRect = glGetUniformLocation(shaderProgram, "ClipRect");
|
|
||||||
|
|
||||||
// Setup orthographic projection matrix
|
// Setup matrices
|
||||||
const float width = ImGui::GetIO().DisplaySize.x;
|
glMatrixMode(GL_PROJECTION);
|
||||||
const float height = ImGui::GetIO().DisplaySize.y;
|
glLoadIdentity();
|
||||||
const float mvp[4][4] =
|
glOrtho(0.0f, ImGui::GetIO().DisplaySize.x, ImGui::GetIO().DisplaySize.y, 0.0f, -1.0f, +1.0f);
|
||||||
{
|
glMatrixMode(GL_MODELVIEW);
|
||||||
{ 2.0f/width, 0.0f, 0.0f, 0.0f },
|
glLoadIdentity();
|
||||||
{ 0.0f, 2.0f/-height, 0.0f, 0.0f },
|
|
||||||
{ 0.0f, 0.0f, -1.0f, 0.0f },
|
|
||||||
{ -1.0f, 1.0f, 0.0f, 1.0f },
|
|
||||||
};
|
|
||||||
glUniformMatrix4fv(uniMVP, 1, GL_FALSE, &mvp[0][0]);
|
|
||||||
|
|
||||||
// Render command lists
|
// 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++)
|
||||||
{
|
{
|
||||||
// Setup stack of clipping rectangles
|
|
||||||
int clip_rect_buf_offset = 0;
|
|
||||||
ImVector<ImVec4> clip_rect_stack;
|
|
||||||
clip_rect_stack.push_back(ImVec4(-9999,-9999,+9999,+9999));
|
|
||||||
|
|
||||||
// Render command list
|
|
||||||
const ImDrawList* cmd_list = cmd_lists[n];
|
const ImDrawList* cmd_list = cmd_lists[n];
|
||||||
|
const unsigned char* vtx_buffer = (const unsigned char*)cmd_list->vtx_buffer.begin();
|
||||||
|
glVertexPointer(2, GL_FLOAT, sizeof(ImDrawVert), (void*)(vtx_buffer));
|
||||||
|
glTexCoordPointer(2, GL_FLOAT, sizeof(ImDrawVert), (void*)(vtx_buffer+8));
|
||||||
|
glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(ImDrawVert), (void*)(vtx_buffer+16));
|
||||||
|
|
||||||
|
int vtx_offset = 0;
|
||||||
const ImDrawCmd* pcmd_end = cmd_list->commands.end();
|
const ImDrawCmd* pcmd_end = cmd_list->commands.end();
|
||||||
for (const ImDrawCmd* pcmd = cmd_list->commands.begin(); pcmd != pcmd_end; pcmd++)
|
for (const ImDrawCmd* pcmd = cmd_list->commands.begin(); pcmd != pcmd_end; pcmd++)
|
||||||
{
|
{
|
||||||
switch (pcmd->cmd_type)
|
glScissor((int)pcmd->clip_rect.x, (int)pcmd->clip_rect.y, (int)(pcmd->clip_rect.z - pcmd->clip_rect.x), (int)(pcmd->clip_rect.w - pcmd->clip_rect.y));
|
||||||
{
|
glDrawArrays(GL_TRIANGLES, vtx_offset, pcmd->vtx_count);
|
||||||
case ImDrawCmdType_DrawTriangleList:
|
vtx_offset += pcmd->vtx_count;
|
||||||
glUniform4fv(uniClipRect, 1, (float*)&clip_rect_stack.back());
|
|
||||||
glDrawArrays(GL_TRIANGLES, vtx_offset, pcmd->vtx_count);
|
|
||||||
vtx_offset += pcmd->vtx_count;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case ImDrawCmdType_PushClipRect:
|
|
||||||
clip_rect_stack.push_back(cmd_list->clip_rect_buffer[clip_rect_buf_offset++]);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case ImDrawCmdType_PopClipRect:
|
|
||||||
clip_rect_stack.pop_back();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
glDisable(GL_SCISSOR_TEST);
|
||||||
// Cleanup GL state
|
|
||||||
glBindTexture(GL_TEXTURE_2D, 0);
|
|
||||||
glBindVertexArray(0);
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
|
||||||
glUseProgram(0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char* ImImpl_GetClipboardTextFn()
|
static const char* ImImpl_GetClipboardTextFn()
|
||||||
@ -122,42 +79,10 @@ static void ImImpl_SetClipboardTextFn(const char* text, const char* text_end)
|
|||||||
free(buf);
|
free(buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Shader sources
|
|
||||||
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
|
// 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 float mouse_wheel = 0.0f;
|
||||||
@ -188,29 +113,17 @@ void InitGL()
|
|||||||
{
|
{
|
||||||
glfwSetErrorCallback(glfw_error_callback);
|
glfwSetErrorCallback(glfw_error_callback);
|
||||||
|
|
||||||
if (!glfwInit())
|
if (!glfwInit())
|
||||||
exit(1);
|
exit(1);
|
||||||
|
|
||||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
|
|
||||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
|
|
||||||
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", NULL, NULL);
|
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();
|
||||||
|
|
||||||
// After calling glewInit() our GL error state may be GL_INVALID_ENUM
|
|
||||||
const GLenum err = glGetError();
|
|
||||||
(void)err;
|
|
||||||
IM_ASSERT(err == GL_NO_ERROR || err == GL_INVALID_ENUM);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void InitImGui()
|
void InitImGui()
|
||||||
@ -219,10 +132,10 @@ void InitImGui()
|
|||||||
glfwGetWindowSize(window, &w, &h);
|
glfwGetWindowSize(window, &w, &h);
|
||||||
|
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
io.DisplaySize = ImVec2((float)w, (float)h); // Display size, in pixels. For clamping windows positions.
|
io.DisplaySize = ImVec2((float)w, (float)h); // Display size, in pixels. For clamping windows positions.
|
||||||
io.DeltaTime = 1.0f/60.0f; // Time elapsed since last frame, in seconds (in this sample app we'll override this every frame because our timestep is variable)
|
io.DeltaTime = 1.0f/60.0f; // Time elapsed since last frame, in seconds (in this sample app we'll override this every frame because our timestep is variable)
|
||||||
io.PixelCenterOffset = 0.5f; // Align OpenGL texels
|
io.PixelCenterOffset = 0.5f; // Align OpenGL texels
|
||||||
io.KeyMap[ImGuiKey_Tab] = GLFW_KEY_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_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;
|
||||||
@ -244,68 +157,11 @@ void InitImGui()
|
|||||||
io.SetClipboardTextFn = ImImpl_SetClipboardTextFn;
|
io.SetClipboardTextFn = ImImpl_SetClipboardTextFn;
|
||||||
io.GetClipboardTextFn = ImImpl_GetClipboardTextFn;
|
io.GetClipboardTextFn = ImImpl_GetClipboardTextFn;
|
||||||
|
|
||||||
// Setup graphics backend
|
|
||||||
GLint status = GL_TRUE;
|
|
||||||
GLenum err = GL_NO_ERROR;
|
|
||||||
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);
|
|
||||||
|
|
||||||
// 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);
|
|
||||||
|
|
||||||
glBindVertexArray(0);
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
|
||||||
|
|
||||||
// Load font texture
|
// Load font texture
|
||||||
glGenTextures(1, &fontTex);
|
glGenTextures(1, &fontTex);
|
||||||
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);
|
||||||
@ -318,13 +174,6 @@ void InitImGui()
|
|||||||
void Shutdown()
|
void Shutdown()
|
||||||
{
|
{
|
||||||
ImGui::Shutdown();
|
ImGui::Shutdown();
|
||||||
|
|
||||||
glDeleteProgram(shaderProgram);
|
|
||||||
glDeleteShader(fragmentShader);
|
|
||||||
glDeleteShader(vertexShader);
|
|
||||||
glDeleteBuffers(1, &vbo);
|
|
||||||
glDeleteVertexArrays(1, &vao);
|
|
||||||
|
|
||||||
glfwTerminate();
|
glfwTerminate();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -345,10 +194,10 @@ int main(int argc, char** argv)
|
|||||||
time = current_time;
|
time = current_time;
|
||||||
double mouse_x, mouse_y;
|
double mouse_x, mouse_y;
|
||||||
glfwGetCursorPos(window, &mouse_x, &mouse_y);
|
glfwGetCursorPos(window, &mouse_x, &mouse_y);
|
||||||
io.MousePos = ImVec2((float)mouse_x, (float)mouse_y); // Mouse position, in pixels (set to -1,-1 if no mouse / on another screen, etc.)
|
io.MousePos = ImVec2((float)mouse_x, (float)mouse_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[0] = glfwGetMouseButton(window, GLFW_MOUSE_BUTTON_LEFT) != 0;
|
||||||
io.MouseDown[1] = glfwGetMouseButton(window, GLFW_MOUSE_BUTTON_RIGHT) != 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: -1,0,+1
|
io.MouseWheel = (mouse_wheel != 0) ? mouse_wheel > 0.0f ? 1 : - 1 : 0; // Mouse wheel: -1,0,+1
|
||||||
mouse_wheel = 0.0f;
|
mouse_wheel = 0.0f;
|
||||||
ImGui::NewFrame();
|
ImGui::NewFrame();
|
||||||
|
|
||||||
@ -375,7 +224,7 @@ int main(int argc, char** argv)
|
|||||||
if (show_test_window)
|
if (show_test_window)
|
||||||
{
|
{
|
||||||
// More example code in ShowTestWindow()
|
// 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -386,9 +235,10 @@ int main(int argc, char** argv)
|
|||||||
ImGui::End();
|
ImGui::End();
|
||||||
}
|
}
|
||||||
|
|
||||||
// 3) Rendering
|
// 3) Rendering
|
||||||
glClearColor(0.8f, 0.6f, 0.6f, 1.0f);
|
glViewport(0, 0, (int)io.DisplaySize.x, (int)io.DisplaySize.y);
|
||||||
glClear(GL_COLOR_BUFFER_BIT);
|
glClearColor(0.8f, 0.6f, 0.6f, 1.0f);
|
||||||
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
ImGui::Render();
|
ImGui::Render();
|
||||||
|
|
||||||
glfwSwapBuffers(window);
|
glfwSwapBuffers(window);
|
||||||
|
@ -28,7 +28,7 @@
|
|||||||
/*
|
/*
|
||||||
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);
|
||||||
};
|
};
|
||||||
*/
|
*/
|
||||||
|
268
imgui.cpp
268
imgui.cpp
@ -184,7 +184,7 @@ static void ItemSize(ImVec2 size, ImVec2* adjust_start_offset = NULL);
|
|||||||
static void ItemSize(const ImGuiAabb& aabb, ImVec2* adjust_start_offset = NULL);
|
static void ItemSize(const ImGuiAabb& aabb, ImVec2* adjust_start_offset = NULL);
|
||||||
static void PushColumnClipRect(int column_index = -1);
|
static void PushColumnClipRect(int column_index = -1);
|
||||||
static bool IsClipped(const ImGuiAabb& aabb);
|
static bool IsClipped(const ImGuiAabb& aabb);
|
||||||
static bool ClipAdvance(const ImGuiAabb& aabb, bool skip_columns = false);
|
static bool ClipAdvance(const ImGuiAabb& aabb);
|
||||||
|
|
||||||
static bool IsMouseHoveringBox(const ImGuiAabb& box);
|
static bool IsMouseHoveringBox(const ImGuiAabb& box);
|
||||||
static bool IsKeyPressedMap(ImGuiKey key, bool repeat = true);
|
static bool IsKeyPressedMap(ImGuiKey key, bool repeat = true);
|
||||||
@ -274,7 +274,7 @@ ImGuiIO::ImGuiIO()
|
|||||||
// - on Windows you can get those using ToAscii+keyboard state, or via the VM_CHAR message
|
// - on Windows you can get those using ToAscii+keyboard state, or via the VM_CHAR message
|
||||||
void ImGuiIO::AddInputCharacter(char c)
|
void ImGuiIO::AddInputCharacter(char c)
|
||||||
{
|
{
|
||||||
const int n = strlen(InputCharacters);
|
const size_t n = strlen(InputCharacters);
|
||||||
if (n < sizeof(InputCharacters) / sizeof(InputCharacters[0]))
|
if (n < sizeof(InputCharacters) / sizeof(InputCharacters[0]))
|
||||||
{
|
{
|
||||||
InputCharacters[n] = c;
|
InputCharacters[n] = c;
|
||||||
@ -287,7 +287,7 @@ void ImGuiIO::AddInputCharacter(char c)
|
|||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
#undef ARRAYSIZE
|
#undef ARRAYSIZE
|
||||||
#define ARRAYSIZE(_ARR) (sizeof(_ARR)/sizeof(*_ARR))
|
#define ARRAYSIZE(_ARR) ((int)(sizeof(_ARR)/sizeof(*_ARR)))
|
||||||
|
|
||||||
#undef PI
|
#undef PI
|
||||||
const float PI = 3.14159265358979323846f;
|
const float PI = 3.14159265358979323846f;
|
||||||
@ -337,7 +337,7 @@ static const char* ImStristr(const char* haystack, const char* needle, const cha
|
|||||||
if (!needle_end)
|
if (!needle_end)
|
||||||
needle_end = needle + strlen(needle);
|
needle_end = needle + strlen(needle);
|
||||||
|
|
||||||
const char un0 = toupper(*needle);
|
const char un0 = (char)toupper(*needle);
|
||||||
while (*haystack)
|
while (*haystack)
|
||||||
{
|
{
|
||||||
if (toupper(*haystack) == un0)
|
if (toupper(*haystack) == un0)
|
||||||
@ -382,7 +382,7 @@ static size_t ImFormatString(char* buf, size_t buf_size, const char* fmt, ...)
|
|||||||
int w = vsnprintf(buf, buf_size, fmt, args);
|
int w = vsnprintf(buf, buf_size, fmt, args);
|
||||||
va_end(args);
|
va_end(args);
|
||||||
buf[buf_size-1] = 0;
|
buf[buf_size-1] = 0;
|
||||||
if (w == -1) w = buf_size;
|
if (w == -1) w = (int)buf_size;
|
||||||
return w;
|
return w;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -390,7 +390,7 @@ static size_t ImFormatStringV(char* buf, size_t buf_size, const char* fmt, va_li
|
|||||||
{
|
{
|
||||||
int w = vsnprintf(buf, buf_size, fmt, args);
|
int w = vsnprintf(buf, buf_size, fmt, args);
|
||||||
buf[buf_size-1] = 0;
|
buf[buf_size-1] = 0;
|
||||||
if (w == -1) w = buf_size;
|
if (w == -1) w = (int)buf_size;
|
||||||
return w;
|
return w;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -541,7 +541,7 @@ struct ImGuiTextEditState
|
|||||||
{
|
{
|
||||||
char Text[1024]; // edit buffer, we need to persist but can't guarantee the persistence of the user-provided buffer. so own buffer.
|
char Text[1024]; // edit buffer, we need to persist but can't guarantee the persistence of the user-provided buffer. so own buffer.
|
||||||
char InitialText[1024]; // backup of end-user buffer at focusing time, to ESC key can do a revert. Also used for arithmetic operations (but could use a pre-parsed float there).
|
char InitialText[1024]; // backup of end-user buffer at focusing time, to ESC key can do a revert. Also used for arithmetic operations (but could use a pre-parsed float there).
|
||||||
int MaxLength; // end-user buffer size <= 1024 (or increase above)
|
size_t BufSize; // end-user buffer size, <= 1024 (or increase above)
|
||||||
float Width; // widget width
|
float Width; // widget width
|
||||||
float ScrollX;
|
float ScrollX;
|
||||||
STB_TexteditState StbState;
|
STB_TexteditState StbState;
|
||||||
@ -555,7 +555,7 @@ struct ImGuiTextEditState
|
|||||||
void CursorAnimReset() { CursorAnim = -0.30f; } // After a user-input the cursor stays on for a while without blinking
|
void CursorAnimReset() { CursorAnim = -0.30f; } // After a user-input the cursor stays on for a while without blinking
|
||||||
bool CursorIsVisible() const { return CursorAnim <= 0.0f || fmodf(CursorAnim, 1.20f) <= 0.80f; } // Blinking
|
bool CursorIsVisible() const { return CursorAnim <= 0.0f || fmodf(CursorAnim, 1.20f) <= 0.80f; } // Blinking
|
||||||
bool HasSelection() const { return StbState.select_start != StbState.select_end; }
|
bool HasSelection() const { return StbState.select_start != StbState.select_end; }
|
||||||
void SelectAll() { StbState.select_start = 0; StbState.select_end = strlen(Text); StbState.cursor = StbState.select_end; StbState.has_preferred_x = false; }
|
void SelectAll() { StbState.select_start = 0; StbState.select_end = (int)strlen(Text); StbState.cursor = StbState.select_end; StbState.has_preferred_x = false; }
|
||||||
|
|
||||||
void OnKeyboardPressed(int key);
|
void OnKeyboardPressed(int key);
|
||||||
void UpdateScrollOffset();
|
void UpdateScrollOffset();
|
||||||
@ -717,7 +717,7 @@ static ImVector<ImGuiStorage::Pair>::iterator LowerBound(ImVector<ImGuiStorage::
|
|||||||
{
|
{
|
||||||
ImVector<ImGuiStorage::Pair>::iterator first = data.begin();
|
ImVector<ImGuiStorage::Pair>::iterator first = data.begin();
|
||||||
ImVector<ImGuiStorage::Pair>::iterator last = data.end();
|
ImVector<ImGuiStorage::Pair>::iterator last = data.end();
|
||||||
int count = last - first;
|
int count = (int)(last - first);
|
||||||
while (count > 0)
|
while (count > 0)
|
||||||
{
|
{
|
||||||
int count2 = count / 2;
|
int count2 = count / 2;
|
||||||
@ -870,18 +870,20 @@ bool ImGuiTextFilter::PassFilter(const char* val) const
|
|||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
void ImGuiTextBuffer::Append(const char* fmt, ...)
|
void ImGuiTextBuffer::append(const char* fmt, ...)
|
||||||
{
|
{
|
||||||
va_list args;
|
va_list args;
|
||||||
va_start(args, fmt);
|
va_start(args, fmt);
|
||||||
int len = vsnprintf(NULL, 0, fmt, args);
|
int len = vsnprintf(NULL, 0, fmt, args);
|
||||||
va_end(args);
|
va_end(args);
|
||||||
|
if (len <= 0)
|
||||||
|
return;
|
||||||
|
|
||||||
const size_t write_off = Buf.size();
|
const size_t write_off = Buf.size();
|
||||||
if (write_off + len >= Buf.capacity())
|
if (write_off + len >= Buf.capacity())
|
||||||
Buf.reserve(Buf.capacity() * 2);
|
Buf.reserve(Buf.capacity() * 2);
|
||||||
|
|
||||||
Buf.resize(write_off + len);
|
Buf.resize(write_off + (size_t)len);
|
||||||
|
|
||||||
va_start(args, fmt);
|
va_start(args, fmt);
|
||||||
ImFormatStringV(&Buf[write_off] - 1, len+1, fmt, args);
|
ImFormatStringV(&Buf[write_off] - 1, len+1, fmt, args);
|
||||||
@ -976,7 +978,11 @@ void ImGuiWindow::AddToRenderList()
|
|||||||
ImGuiState& g = GImGui;
|
ImGuiState& g = GImGui;
|
||||||
|
|
||||||
if (!DrawList->commands.empty() && !DrawList->vtx_buffer.empty())
|
if (!DrawList->commands.empty() && !DrawList->vtx_buffer.empty())
|
||||||
|
{
|
||||||
|
if (DrawList->commands.back().vtx_count == 0)
|
||||||
|
DrawList->commands.pop_back();
|
||||||
g.RenderDrawLists.push_back(DrawList);
|
g.RenderDrawLists.push_back(DrawList);
|
||||||
|
}
|
||||||
for (size_t i = 0; i < DC.ChildWindows.size(); i++)
|
for (size_t i = 0; i < DC.ChildWindows.size(); i++)
|
||||||
{
|
{
|
||||||
ImGuiWindow* child = DC.ChildWindows[i];
|
ImGuiWindow* child = DC.ChildWindows[i];
|
||||||
@ -1165,7 +1171,7 @@ void NewFrame()
|
|||||||
else
|
else
|
||||||
g.IO.MouseDelta = g.IO.MousePos - g.IO.MousePosPrev;
|
g.IO.MouseDelta = g.IO.MousePos - g.IO.MousePosPrev;
|
||||||
g.IO.MousePosPrev = g.IO.MousePos;
|
g.IO.MousePosPrev = g.IO.MousePos;
|
||||||
for (int i = 0; i < ARRAYSIZE(g.IO.MouseDown); i++)
|
for (size_t i = 0; i < ARRAYSIZE(g.IO.MouseDown); i++)
|
||||||
{
|
{
|
||||||
g.IO.MouseDownTime[i] = g.IO.MouseDown[i] ? (g.IO.MouseDownTime[i] < 0.0f ? 0.0f : g.IO.MouseDownTime[i] + g.IO.DeltaTime) : -1.0f;
|
g.IO.MouseDownTime[i] = g.IO.MouseDown[i] ? (g.IO.MouseDownTime[i] < 0.0f ? 0.0f : g.IO.MouseDownTime[i] + g.IO.DeltaTime) : -1.0f;
|
||||||
g.IO.MouseClicked[i] = (g.IO.MouseDownTime[i] == 0.0f);
|
g.IO.MouseClicked[i] = (g.IO.MouseDownTime[i] == 0.0f);
|
||||||
@ -1185,7 +1191,7 @@ void NewFrame()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (int i = 0; i < ARRAYSIZE(g.IO.KeysDown); i++)
|
for (size_t i = 0; i < ARRAYSIZE(g.IO.KeysDown); i++)
|
||||||
g.IO.KeysDownTime[i] = g.IO.KeysDown[i] ? (g.IO.KeysDownTime[i] < 0.0f ? 0.0f : g.IO.KeysDownTime[i] + g.IO.DeltaTime) : -1.0f;
|
g.IO.KeysDownTime[i] = g.IO.KeysDown[i] ? (g.IO.KeysDownTime[i] < 0.0f ? 0.0f : g.IO.KeysDownTime[i] + g.IO.DeltaTime) : -1.0f;
|
||||||
|
|
||||||
// Clear reference to active widget if the widget isn't alive anymore
|
// Clear reference to active widget if the widget isn't alive anymore
|
||||||
@ -1303,7 +1309,6 @@ static void AddWindowToSortedBuffer(ImGuiWindow* window, ImVector<ImGuiWindow*>&
|
|||||||
|
|
||||||
static void PushClipRect(const ImVec4& clip_rect, bool clipped = true)
|
static void PushClipRect(const ImVec4& clip_rect, bool clipped = true)
|
||||||
{
|
{
|
||||||
ImGuiState& g = GImGui;
|
|
||||||
ImGuiWindow* window = GetCurrentWindow();
|
ImGuiWindow* window = GetCurrentWindow();
|
||||||
|
|
||||||
ImVec4 cr = clip_rect;
|
ImVec4 cr = clip_rect;
|
||||||
@ -1320,7 +1325,6 @@ static void PushClipRect(const ImVec4& clip_rect, bool clipped = true)
|
|||||||
|
|
||||||
static void PopClipRect()
|
static void PopClipRect()
|
||||||
{
|
{
|
||||||
ImGuiState& g = GImGui;
|
|
||||||
ImGuiWindow* window = GetCurrentWindow();
|
ImGuiWindow* window = GetCurrentWindow();
|
||||||
window->ClipRectStack.pop_back();
|
window->ClipRectStack.pop_back();
|
||||||
window->DrawList->PopClipRect();
|
window->DrawList->PopClipRect();
|
||||||
@ -1451,9 +1455,9 @@ static void LogText(const ImVec2& ref_pos, const char* text, const char* text_en
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (log_new_line || !is_first_line)
|
if (log_new_line || !is_first_line)
|
||||||
g.LogClipboard.Append("\n%*s%.*s", tree_depth*4, "", char_count, text_remaining);
|
g.LogClipboard.append("\n%*s%.*s", tree_depth*4, "", char_count, text_remaining);
|
||||||
else
|
else
|
||||||
g.LogClipboard.Append(" %.*s", char_count, text_remaining);
|
g.LogClipboard.append(" %.*s", char_count, text_remaining);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1496,7 +1500,6 @@ static void RenderText(ImVec2 pos, const char* text, const char* text_end, const
|
|||||||
|
|
||||||
static void RenderFrame(ImVec2 p_min, ImVec2 p_max, ImU32 fill_col, bool border, float rounding)
|
static void RenderFrame(ImVec2 p_min, ImVec2 p_max, ImU32 fill_col, bool border, float rounding)
|
||||||
{
|
{
|
||||||
ImGuiState& g = GImGui;
|
|
||||||
ImGuiWindow* window = GetCurrentWindow();
|
ImGuiWindow* window = GetCurrentWindow();
|
||||||
|
|
||||||
window->DrawList->AddRectFilled(p_min, p_max, fill_col, rounding);
|
window->DrawList->AddRectFilled(p_min, p_max, fill_col, rounding);
|
||||||
@ -1509,7 +1512,6 @@ static void RenderFrame(ImVec2 p_min, ImVec2 p_max, ImU32 fill_col, bool border,
|
|||||||
|
|
||||||
static void RenderCollapseTriangle(ImVec2 p_min, bool open, float scale = 1.0f, bool shadow = false)
|
static void RenderCollapseTriangle(ImVec2 p_min, bool open, float scale = 1.0f, bool shadow = false)
|
||||||
{
|
{
|
||||||
ImGuiState& g = GImGui;
|
|
||||||
ImGuiWindow* window = GetCurrentWindow();
|
ImGuiWindow* window = GetCurrentWindow();
|
||||||
|
|
||||||
const float h = window->FontSize() * 1.00f;
|
const float h = window->FontSize() * 1.00f;
|
||||||
@ -1538,7 +1540,6 @@ static void RenderCollapseTriangle(ImVec2 p_min, bool open, float scale = 1.0f,
|
|||||||
|
|
||||||
static ImVec2 CalcTextSize(const char* text, const char* text_end, const bool hide_text_after_hash)
|
static ImVec2 CalcTextSize(const char* text, const char* text_end, const bool hide_text_after_hash)
|
||||||
{
|
{
|
||||||
ImGuiState& g = GImGui;
|
|
||||||
ImGuiWindow* window = GetCurrentWindow();
|
ImGuiWindow* window = GetCurrentWindow();
|
||||||
|
|
||||||
const char* text_display_end;
|
const char* text_display_end;
|
||||||
@ -1556,7 +1557,7 @@ static ImGuiWindow* FindHoveredWindow(ImVec2 pos, bool excluding_childs)
|
|||||||
ImGuiState& g = GImGui;
|
ImGuiState& g = GImGui;
|
||||||
for (int i = (int)g.Windows.size()-1; i >= 0; i--)
|
for (int i = (int)g.Windows.size()-1; i >= 0; i--)
|
||||||
{
|
{
|
||||||
ImGuiWindow* window = g.Windows[i];
|
ImGuiWindow* window = g.Windows[(size_t)i];
|
||||||
if (!window->Visible)
|
if (!window->Visible)
|
||||||
continue;
|
continue;
|
||||||
if (excluding_childs && (window->Flags & ImGuiWindowFlags_ChildWindow) != 0)
|
if (excluding_childs && (window->Flags & ImGuiWindowFlags_ChildWindow) != 0)
|
||||||
@ -1588,6 +1589,11 @@ static bool IsMouseHoveringBox(const ImGuiAabb& box)
|
|||||||
return box_for_touch.Contains(g.IO.MousePos);
|
return box_for_touch.Contains(g.IO.MousePos);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool IsMouseHoveringBox(const ImVec2& box_min, const ImVec2& box_max)
|
||||||
|
{
|
||||||
|
return IsMouseHoveringBox(ImGuiAabb(box_min, box_max));
|
||||||
|
}
|
||||||
|
|
||||||
static bool IsKeyPressedMap(ImGuiKey key, bool repeat)
|
static bool IsKeyPressedMap(ImGuiKey key, bool repeat)
|
||||||
{
|
{
|
||||||
ImGuiState& g = GImGui;
|
ImGuiState& g = GImGui;
|
||||||
@ -1631,6 +1637,13 @@ bool IsMouseClicked(int button, bool repeat)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool IsMouseDoubleClicked(int button)
|
||||||
|
{
|
||||||
|
ImGuiState& g = GImGui;
|
||||||
|
IM_ASSERT(button >= 0 && button < ARRAYSIZE(g.IO.MouseDown));
|
||||||
|
return g.IO.MouseDoubleClicked[button];
|
||||||
|
}
|
||||||
|
|
||||||
ImVec2 GetMousePos()
|
ImVec2 GetMousePos()
|
||||||
{
|
{
|
||||||
return GImGui.IO.MousePos;
|
return GImGui.IO.MousePos;
|
||||||
@ -1681,7 +1694,7 @@ void BeginChild(const char* str_id, ImVec2 size, bool border, ImGuiWindowFlags e
|
|||||||
ImGuiState& g = GImGui;
|
ImGuiState& g = GImGui;
|
||||||
ImGuiWindow* window = GetCurrentWindow();
|
ImGuiWindow* window = GetCurrentWindow();
|
||||||
|
|
||||||
ImU32 flags = ImGuiWindowFlags_NoTitleBar|ImGuiWindowFlags_NoMove|ImGuiWindowFlags_NoResize|ImGuiWindowFlags_ChildWindow;
|
ImGuiWindowFlags flags = ImGuiWindowFlags_NoTitleBar|ImGuiWindowFlags_NoMove|ImGuiWindowFlags_NoResize|ImGuiWindowFlags_ChildWindow;
|
||||||
|
|
||||||
const ImVec2 content_max = window->Pos + ImGui::GetWindowContentRegionMax();
|
const ImVec2 content_max = window->Pos + ImGui::GetWindowContentRegionMax();
|
||||||
const ImVec2 cursor_pos = window->Pos + ImGui::GetCursorPos();
|
const ImVec2 cursor_pos = window->Pos + ImGui::GetCursorPos();
|
||||||
@ -1792,6 +1805,10 @@ bool Begin(const char* name, bool* open, ImVec2 size, float fill_alpha, ImGuiWin
|
|||||||
if (!(flags & ImGuiWindowFlags_ComboBox))
|
if (!(flags & ImGuiWindowFlags_ComboBox))
|
||||||
ImGui::PushClipRect(parent_window->ClipRectStack.back());
|
ImGui::PushClipRect(parent_window->ClipRectStack.back());
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ImGui::PushClipRect(ImVec4(0.0f, 0.0f, g.IO.DisplaySize.x, g.IO.DisplaySize.y));
|
||||||
|
}
|
||||||
|
|
||||||
// ID stack
|
// ID stack
|
||||||
window->IDStack.resize(0);
|
window->IDStack.resize(0);
|
||||||
@ -2026,12 +2043,10 @@ bool Begin(const char* name, bool* open, ImVec2 size, float fill_alpha, ImGuiWin
|
|||||||
// Title bar
|
// Title bar
|
||||||
if (!(window->Flags & ImGuiWindowFlags_NoTitleBar))
|
if (!(window->Flags & ImGuiWindowFlags_NoTitleBar))
|
||||||
{
|
{
|
||||||
ImGui::PushClipRect(ImVec4(window->Pos.x-0.5f, window->Pos.y-0.5f, window->Pos.x+window->Size.x-1.5f, window->Pos.y+window->Size.y-1.5f), false);
|
|
||||||
RenderCollapseTriangle(window->Pos + style.FramePadding, !window->Collapsed, 1.0f, true);
|
RenderCollapseTriangle(window->Pos + style.FramePadding, !window->Collapsed, 1.0f, true);
|
||||||
RenderText(window->Pos + style.FramePadding + ImVec2(window->FontSize() + style.ItemInnerSpacing.x, 0), name);
|
RenderText(window->Pos + style.FramePadding + ImVec2(window->FontSize() + style.ItemInnerSpacing.x, 0), name);
|
||||||
if (open)
|
if (open)
|
||||||
ImGui::CloseWindowButton(open);
|
ImGui::CloseWindowButton(open);
|
||||||
ImGui::PopClipRect();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2061,8 +2076,14 @@ void End()
|
|||||||
ImGui::Columns(1, "#CloseColumns");
|
ImGui::Columns(1, "#CloseColumns");
|
||||||
ImGui::PopClipRect();
|
ImGui::PopClipRect();
|
||||||
if (window->Flags & ImGuiWindowFlags_ChildWindow)
|
if (window->Flags & ImGuiWindowFlags_ChildWindow)
|
||||||
|
{
|
||||||
if (!(window->Flags & ImGuiWindowFlags_ComboBox))
|
if (!(window->Flags & ImGuiWindowFlags_ComboBox))
|
||||||
ImGui::PopClipRect();
|
ImGui::PopClipRect();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ImGui::PopClipRect();
|
||||||
|
}
|
||||||
|
|
||||||
// Select window for move/focus when we're done with all our widgets
|
// Select window for move/focus when we're done with all our widgets
|
||||||
ImGuiAabb bb(window->Pos, window->Pos+window->Size);
|
ImGuiAabb bb(window->Pos, window->Pos+window->Size);
|
||||||
@ -2084,7 +2105,7 @@ void End()
|
|||||||
}
|
}
|
||||||
if (g.LogClipboard.size() > 1)
|
if (g.LogClipboard.size() > 1)
|
||||||
{
|
{
|
||||||
g.LogClipboard.Append("\n");
|
g.LogClipboard.append("\n");
|
||||||
if (g.IO.SetClipboardTextFn)
|
if (g.IO.SetClipboardTextFn)
|
||||||
g.IO.SetClipboardTextFn(g.LogClipboard.begin(), g.LogClipboard.end());
|
g.IO.SetClipboardTextFn(g.LogClipboard.begin(), g.LogClipboard.end());
|
||||||
g.LogClipboard.clear();
|
g.LogClipboard.clear();
|
||||||
@ -2296,21 +2317,24 @@ void SetCursorPos(ImVec2 p)
|
|||||||
|
|
||||||
void SetScrollPosHere()
|
void SetScrollPosHere()
|
||||||
{
|
{
|
||||||
ImGuiState& g = GImGui;
|
|
||||||
ImGuiWindow* window = GetCurrentWindow();
|
ImGuiWindow* window = GetCurrentWindow();
|
||||||
window->NextScrollY = (window->DC.CursorPos.y + window->ScrollY) - (window->Pos.y + window->SizeFull.y * 0.5f) - (window->TitleBarHeight() + window->WindowPadding().y);
|
window->NextScrollY = (window->DC.CursorPos.y + window->ScrollY) - (window->Pos.y + window->SizeFull.y * 0.5f) - (window->TitleBarHeight() + window->WindowPadding().y);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetTreeStateStorage(ImGuiStorage* tree)
|
void SetTreeStateStorage(ImGuiStorage* tree)
|
||||||
{
|
{
|
||||||
ImGuiState& g = GImGui;
|
|
||||||
ImGuiWindow* window = GetCurrentWindow();
|
ImGuiWindow* window = GetCurrentWindow();
|
||||||
window->DC.StateStorage = tree ? tree : &window->StateStorage;
|
window->DC.StateStorage = tree ? tree : &window->StateStorage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ImGuiStorage* GetTreeStateStorage()
|
||||||
|
{
|
||||||
|
ImGuiWindow* window = GetCurrentWindow();
|
||||||
|
return window->DC.StateStorage;
|
||||||
|
}
|
||||||
|
|
||||||
void TextV(const char* fmt, va_list args)
|
void TextV(const char* fmt, va_list args)
|
||||||
{
|
{
|
||||||
ImGuiState& g = GImGui;
|
|
||||||
ImGuiWindow* window = GetCurrentWindow();
|
ImGuiWindow* window = GetCurrentWindow();
|
||||||
if (window->Collapsed)
|
if (window->Collapsed)
|
||||||
return;
|
return;
|
||||||
@ -2370,10 +2394,6 @@ void TextUnformatted(const char* text, const char* text_end)
|
|||||||
pos.y += lines_skipped * line_height;
|
pos.y += lines_skipped * line_height;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
printf("");
|
|
||||||
}
|
|
||||||
|
|
||||||
// lines to render?
|
// lines to render?
|
||||||
if (line < text_end)
|
if (line < text_end)
|
||||||
@ -2581,7 +2601,6 @@ bool SmallButton(const char* label)
|
|||||||
|
|
||||||
static bool CloseWindowButton(bool* open)
|
static bool CloseWindowButton(bool* open)
|
||||||
{
|
{
|
||||||
ImGuiState& g = GImGui;
|
|
||||||
ImGuiWindow* window = GetCurrentWindow();
|
ImGuiWindow* window = GetCurrentWindow();
|
||||||
|
|
||||||
const ImGuiID id = window->GetID("##CLOSE");
|
const ImGuiID id = window->GetID("##CLOSE");
|
||||||
@ -2617,7 +2636,8 @@ void LogToTTY(int max_depth)
|
|||||||
return;
|
return;
|
||||||
g.LogEnabled = true;
|
g.LogEnabled = true;
|
||||||
g.LogFile = stdout;
|
g.LogFile = stdout;
|
||||||
g.LogAutoExpandMaxDepth = max_depth;
|
if (max_depth >= 0)
|
||||||
|
g.LogAutoExpandMaxDepth = max_depth;
|
||||||
}
|
}
|
||||||
|
|
||||||
void LogToFile(int max_depth, const char* filename)
|
void LogToFile(int max_depth, const char* filename)
|
||||||
@ -2625,10 +2645,12 @@ void LogToFile(int max_depth, const char* filename)
|
|||||||
ImGuiState& g = GImGui;
|
ImGuiState& g = GImGui;
|
||||||
if (g.LogEnabled)
|
if (g.LogEnabled)
|
||||||
return;
|
return;
|
||||||
IM_ASSERT(filename);
|
if (!filename)
|
||||||
|
filename = g.IO.LogFilename;
|
||||||
g.LogEnabled = true;
|
g.LogEnabled = true;
|
||||||
g.LogFile = fopen(filename, "at");
|
g.LogFile = fopen(filename, "at");
|
||||||
g.LogAutoExpandMaxDepth = max_depth;
|
if (max_depth >= 0)
|
||||||
|
g.LogAutoExpandMaxDepth = max_depth;
|
||||||
}
|
}
|
||||||
|
|
||||||
void LogToClipboard(int max_depth)
|
void LogToClipboard(int max_depth)
|
||||||
@ -2638,7 +2660,8 @@ void LogToClipboard(int max_depth)
|
|||||||
return;
|
return;
|
||||||
g.LogEnabled = true;
|
g.LogEnabled = true;
|
||||||
g.LogFile = NULL;
|
g.LogFile = NULL;
|
||||||
g.LogAutoExpandMaxDepth = max_depth;
|
if (max_depth >= 0)
|
||||||
|
g.LogAutoExpandMaxDepth = max_depth;
|
||||||
}
|
}
|
||||||
|
|
||||||
void LogButtons()
|
void LogButtons()
|
||||||
@ -2765,7 +2788,7 @@ void BulletText(const char* fmt, ...)
|
|||||||
|
|
||||||
const float line_height = window->FontSize();
|
const float line_height = window->FontSize();
|
||||||
const ImVec2 text_size = CalcTextSize(text_begin, text_end);
|
const ImVec2 text_size = CalcTextSize(text_begin, text_end);
|
||||||
const ImGuiAabb bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(line_height + (text_size.x ? (g.Style.FramePadding.x*2) : 0.0f),0) + text_size); // Empty text doesn't add padding
|
const ImGuiAabb bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(line_height + (text_size.x > 0.0f ? (g.Style.FramePadding.x*2) : 0.0f),0) + text_size); // Empty text doesn't add padding
|
||||||
ItemSize(bb);
|
ItemSize(bb);
|
||||||
|
|
||||||
if (ClipAdvance(bb))
|
if (ClipAdvance(bb))
|
||||||
@ -2779,10 +2802,6 @@ void BulletText(const char* fmt, ...)
|
|||||||
|
|
||||||
bool TreeNode(const char* str_id, const char* fmt, ...)
|
bool TreeNode(const char* str_id, const char* fmt, ...)
|
||||||
{
|
{
|
||||||
ImGuiState& g = GImGui;
|
|
||||||
ImGuiWindow* window = GetCurrentWindow();
|
|
||||||
ImGuiStorage* tree = window->DC.StateStorage;
|
|
||||||
|
|
||||||
static char buf[1024];
|
static char buf[1024];
|
||||||
va_list args;
|
va_list args;
|
||||||
va_start(args, fmt);
|
va_start(args, fmt);
|
||||||
@ -2804,10 +2823,6 @@ 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, ...)
|
||||||
{
|
{
|
||||||
ImGuiState& g = GImGui;
|
|
||||||
ImGuiWindow* window = GetCurrentWindow();
|
|
||||||
ImGuiStorage* tree = window->DC.StateStorage;
|
|
||||||
|
|
||||||
static char buf[1024];
|
static char buf[1024];
|
||||||
va_list args;
|
va_list args;
|
||||||
va_start(args, fmt);
|
va_start(args, fmt);
|
||||||
@ -3151,7 +3166,6 @@ bool SliderFloat3(const char* label, float v[3], float v_min, float v_max, const
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
const ImGuiStyle& style = g.Style;
|
const ImGuiStyle& style = g.Style;
|
||||||
const ImVec2 text_size = CalcTextSize(label);
|
|
||||||
|
|
||||||
bool value_changed = false;
|
bool value_changed = false;
|
||||||
|
|
||||||
@ -3196,7 +3210,6 @@ static void Plot(ImGuiPlotType plot_type, const char* label, const float* values
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
const ImGuiStyle& style = g.Style;
|
const ImGuiStyle& style = g.Style;
|
||||||
const ImGuiID id = window->GetID(label);
|
|
||||||
|
|
||||||
const ImVec2 text_size = CalcTextSize(label);
|
const ImVec2 text_size = CalcTextSize(label);
|
||||||
if (graph_size.x == 0)
|
if (graph_size.x == 0)
|
||||||
@ -3413,7 +3426,7 @@ bool RadioButton(const char* label, int* v, int v_button)
|
|||||||
// Wrapper for stb_textedit.h to edit text (our wrapper is for: statically sized buffer, single-line, ASCII, fixed-width font)
|
// Wrapper for stb_textedit.h to edit text (our wrapper is for: statically sized buffer, single-line, ASCII, fixed-width font)
|
||||||
int STB_TEXTEDIT_STRINGLEN(const STB_TEXTEDIT_STRING* obj) { return (int)strlen(obj->Text); }
|
int STB_TEXTEDIT_STRINGLEN(const STB_TEXTEDIT_STRING* obj) { return (int)strlen(obj->Text); }
|
||||||
char STB_TEXTEDIT_GETCHAR(const STB_TEXTEDIT_STRING* obj, int idx) { return (char)obj->Text[idx]; }
|
char STB_TEXTEDIT_GETCHAR(const STB_TEXTEDIT_STRING* obj, int idx) { return (char)obj->Text[idx]; }
|
||||||
float STB_TEXTEDIT_GETWIDTH(STB_TEXTEDIT_STRING* obj, int line_start_idx, int char_idx) { return obj->Font->CalcTextSize(obj->FontSize, 0, &obj->Text[char_idx], &obj->Text[char_idx]+1, NULL).x; }
|
float STB_TEXTEDIT_GETWIDTH(STB_TEXTEDIT_STRING* obj, int line_start_idx, int char_idx) { (void)line_start_idx; return obj->Font->CalcTextSize(obj->FontSize, 0, &obj->Text[char_idx], &obj->Text[char_idx]+1, NULL).x; }
|
||||||
char STB_TEXTEDIT_KEYTOTEXT(int key) { return key >= 0x10000 ? 0 : (char)key; }
|
char STB_TEXTEDIT_KEYTOTEXT(int key) { return key >= 0x10000 ? 0 : (char)key; }
|
||||||
char STB_TEXTEDIT_NEWLINE = '\n';
|
char STB_TEXTEDIT_NEWLINE = '\n';
|
||||||
void STB_TEXTEDIT_LAYOUTROW(StbTexteditRow* r, STB_TEXTEDIT_STRING* obj, int line_start_idx)
|
void STB_TEXTEDIT_LAYOUTROW(StbTexteditRow* r, STB_TEXTEDIT_STRING* obj, int line_start_idx)
|
||||||
@ -3434,17 +3447,17 @@ static bool is_separator(char c) { return c==',' || c==';' || c=='(' || c==')' |
|
|||||||
#define STB_TEXTEDIT_IS_SPACE(c) (is_white(c) || is_separator(c))
|
#define STB_TEXTEDIT_IS_SPACE(c) (is_white(c) || is_separator(c))
|
||||||
void STB_TEXTEDIT_DELETECHARS(STB_TEXTEDIT_STRING* obj, int idx, int n) { char* dst = obj->Text+idx; const char* src = obj->Text+idx+n; while (char c = *src++) *dst++ = c; *dst = '\0'; }
|
void STB_TEXTEDIT_DELETECHARS(STB_TEXTEDIT_STRING* obj, int idx, int n) { char* dst = obj->Text+idx; const char* src = obj->Text+idx+n; while (char c = *src++) *dst++ = c; *dst = '\0'; }
|
||||||
|
|
||||||
bool STB_TEXTEDIT_INSERTCHARS(STB_TEXTEDIT_STRING* obj, int idx, const char* new_text, int new_text_size)
|
bool STB_TEXTEDIT_INSERTCHARS(STB_TEXTEDIT_STRING* obj, int idx, const char* new_text, int new_text_len)
|
||||||
{
|
{
|
||||||
char* buf_end = obj->Text + obj->MaxLength;
|
char* buf_end = obj->Text + obj->BufSize;
|
||||||
int text_size = strlen(obj->Text);
|
const int text_len = (int)strlen(obj->Text);
|
||||||
|
|
||||||
if (new_text_size > buf_end - (obj->Text + text_size + 1))
|
if (new_text_len > buf_end - (obj->Text + text_len + 1))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
memmove(obj->Text + idx + new_text_size, obj->Text + idx, text_size - idx);
|
memmove(obj->Text + idx + new_text_len, obj->Text + idx, text_len - idx);
|
||||||
memcpy(obj->Text + idx, new_text, new_text_size);
|
memcpy(obj->Text + idx, new_text, new_text_len);
|
||||||
obj->Text[text_size + new_text_size] = 0;
|
obj->Text[text_len + new_text_len] = 0;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -3526,7 +3539,7 @@ void ImGuiTextEditState::RenderTextScrolledClipped(ImFont font, float font_size,
|
|||||||
const float clip_end = (text_end[0] != '\0' && text_end > text_start) ? symbol_w : 0.0f;
|
const float clip_end = (text_end[0] != '\0' && text_end > text_start) ? symbol_w : 0.0f;
|
||||||
|
|
||||||
// Draw text
|
// Draw text
|
||||||
ImGui::RenderText(pos+ImVec2(clip_begin,0), text_start+(clip_begin?1:0), text_end-(clip_end?1:0), false);//, &text_params_with_clipping);
|
ImGui::RenderText(pos+ImVec2(clip_begin,0), text_start+(clip_begin>0.0f?1:0), text_end-(clip_end>0.0f?1:0), false);//, &text_params_with_clipping);
|
||||||
|
|
||||||
// Draw the clip symbol
|
// Draw the clip symbol
|
||||||
const char s[2] = {symbol_c,'\0'};
|
const char s[2] = {symbol_c,'\0'};
|
||||||
@ -3553,7 +3566,7 @@ bool InputFloat(const char* label, float *v, float step, float step_fast, int de
|
|||||||
|
|
||||||
ImGui::PushID(label);
|
ImGui::PushID(label);
|
||||||
const float button_sz = window->FontSize();
|
const float button_sz = window->FontSize();
|
||||||
if (step)
|
if (step > 0.0f)
|
||||||
ImGui::PushItemWidth(ImMax(1.0f, window->DC.ItemWidth.back() - (button_sz+g.Style.FramePadding.x*2.0f+g.Style.ItemInnerSpacing.x)*2));
|
ImGui::PushItemWidth(ImMax(1.0f, window->DC.ItemWidth.back() - (button_sz+g.Style.FramePadding.x*2.0f+g.Style.ItemInnerSpacing.x)*2));
|
||||||
|
|
||||||
char buf[64];
|
char buf[64];
|
||||||
@ -3567,21 +3580,20 @@ bool InputFloat(const char* label, float *v, float step, float step_fast, int de
|
|||||||
ApplyNumericalTextInput(buf, v);
|
ApplyNumericalTextInput(buf, v);
|
||||||
value_changed = true;
|
value_changed = true;
|
||||||
}
|
}
|
||||||
if (step)
|
|
||||||
ImGui::PopItemWidth();
|
|
||||||
|
|
||||||
if (step)
|
if (step > 0.0f)
|
||||||
{
|
{
|
||||||
|
ImGui::PopItemWidth();
|
||||||
ImGui::SameLine(0, 0);
|
ImGui::SameLine(0, 0);
|
||||||
if (ImGui::Button("-", ImVec2(button_sz,button_sz), true))
|
if (ImGui::Button("-", ImVec2(button_sz,button_sz), true))
|
||||||
{
|
{
|
||||||
*v -= g.IO.KeyCtrl && step_fast ? step_fast : step;
|
*v -= g.IO.KeyCtrl && step_fast > 0.0f ? step_fast : step;
|
||||||
value_changed = true;
|
value_changed = true;
|
||||||
}
|
}
|
||||||
ImGui::SameLine(0, (int)g.Style.ItemInnerSpacing.x);
|
ImGui::SameLine(0, (int)g.Style.ItemInnerSpacing.x);
|
||||||
if (ImGui::Button("+", ImVec2(button_sz,button_sz), true))
|
if (ImGui::Button("+", ImVec2(button_sz,button_sz), true))
|
||||||
{
|
{
|
||||||
*v += g.IO.KeyCtrl && step_fast ? step_fast : step;
|
*v += g.IO.KeyCtrl && step_fast > 0.0f ? step_fast : step;
|
||||||
value_changed = true;
|
value_changed = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -3668,7 +3680,7 @@ bool InputText(const char* label, char* buf, size_t buf_size, ImGuiInputTextFlag
|
|||||||
bool cancel_edit = false;
|
bool cancel_edit = false;
|
||||||
if (g.ActiveId == id)
|
if (g.ActiveId == id)
|
||||||
{
|
{
|
||||||
edit_state.MaxLength = buf_size < ARRAYSIZE(edit_state.Text) ? buf_size : ARRAYSIZE(edit_state.Text);
|
edit_state.BufSize = buf_size < ARRAYSIZE(edit_state.Text) ? buf_size : ARRAYSIZE(edit_state.Text);
|
||||||
edit_state.Font = window->Font();
|
edit_state.Font = window->Font();
|
||||||
edit_state.FontSize = window->FontSize();
|
edit_state.FontSize = window->FontSize();
|
||||||
|
|
||||||
@ -3733,7 +3745,7 @@ bool InputText(const char* label, char* buf, size_t buf_size, ImGuiInputTextFlag
|
|||||||
if (const char* clipboard = g.IO.GetClipboardTextFn())
|
if (const char* clipboard = g.IO.GetClipboardTextFn())
|
||||||
{
|
{
|
||||||
// Remove new-line from pasted buffer
|
// Remove new-line from pasted buffer
|
||||||
int clipboard_len = strlen(clipboard);
|
size_t clipboard_len = strlen(clipboard);
|
||||||
char* clipboard_filtered = (char*)malloc(clipboard_len+1);
|
char* clipboard_filtered = (char*)malloc(clipboard_len+1);
|
||||||
int clipboard_filtered_len = 0;
|
int clipboard_filtered_len = 0;
|
||||||
for (int i = 0; clipboard[i]; i++)
|
for (int i = 0; clipboard[i]; i++)
|
||||||
@ -3836,7 +3848,6 @@ bool InputFloat3(const char* label, float v[3], int decimal_precision)
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
const ImGuiStyle& style = g.Style;
|
const ImGuiStyle& style = g.Style;
|
||||||
const ImVec2 text_size = CalcTextSize(label);
|
|
||||||
|
|
||||||
bool value_changed = false;
|
bool value_changed = false;
|
||||||
|
|
||||||
@ -4087,8 +4098,6 @@ bool ColorEdit4(const char* label, float col[4], bool alpha)
|
|||||||
const float w_full = window->DC.ItemWidth.back();
|
const float w_full = window->DC.ItemWidth.back();
|
||||||
const float square_sz = (window->FontSize() + style.FramePadding.x * 2.0f);
|
const float square_sz = (window->FontSize() + style.FramePadding.x * 2.0f);
|
||||||
|
|
||||||
const ImVec2 text_size = CalcTextSize(label);
|
|
||||||
|
|
||||||
ImGuiColorEditMode edit_mode = window->DC.ColorEditMode;
|
ImGuiColorEditMode edit_mode = window->DC.ColorEditMode;
|
||||||
if (edit_mode == ImGuiColorEditMode_UserSelect)
|
if (edit_mode == ImGuiColorEditMode_UserSelect)
|
||||||
edit_mode = g.ColorEditModeStorage.GetInt(id, 0) % 3;
|
edit_mode = g.ColorEditModeStorage.GetInt(id, 0) % 3;
|
||||||
@ -4210,15 +4219,12 @@ bool ColorEdit4(const char* label, float col[4], bool alpha)
|
|||||||
|
|
||||||
void ColorEditMode(ImGuiColorEditMode mode)
|
void ColorEditMode(ImGuiColorEditMode mode)
|
||||||
{
|
{
|
||||||
ImGuiState& g = GImGui;
|
|
||||||
ImGuiWindow* window = GetCurrentWindow();
|
ImGuiWindow* window = GetCurrentWindow();
|
||||||
|
|
||||||
window->DC.ColorEditMode = mode;
|
window->DC.ColorEditMode = mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Separator()
|
void Separator()
|
||||||
{
|
{
|
||||||
ImGuiState& g = GImGui;
|
|
||||||
ImGuiWindow* window = GetCurrentWindow();
|
ImGuiWindow* window = GetCurrentWindow();
|
||||||
if (window->Collapsed)
|
if (window->Collapsed)
|
||||||
return;
|
return;
|
||||||
@ -4229,7 +4235,7 @@ void Separator()
|
|||||||
const ImGuiAabb bb(ImVec2(window->Pos.x, window->DC.CursorPos.y), ImVec2(window->Pos.x + window->Size.x, window->DC.CursorPos.y));
|
const ImGuiAabb bb(ImVec2(window->Pos.x, window->DC.CursorPos.y), ImVec2(window->Pos.x + window->Size.x, window->DC.CursorPos.y));
|
||||||
ItemSize(ImVec2(0.0f, bb.GetSize().y)); // NB: we don't provide our width so that it doesn't get feed back into AutoFit
|
ItemSize(ImVec2(0.0f, bb.GetSize().y)); // NB: we don't provide our width so that it doesn't get feed back into AutoFit
|
||||||
|
|
||||||
if (ClipAdvance(bb, true))
|
if (ClipAdvance(bb))
|
||||||
{
|
{
|
||||||
if (window->DC.ColumnsCount > 1)
|
if (window->DC.ColumnsCount > 1)
|
||||||
ImGui::PushColumnClipRect();
|
ImGui::PushColumnClipRect();
|
||||||
@ -4244,7 +4250,6 @@ void Separator()
|
|||||||
|
|
||||||
void Spacing()
|
void Spacing()
|
||||||
{
|
{
|
||||||
ImGuiState& g = GImGui;
|
|
||||||
ImGuiWindow* window = GetCurrentWindow();
|
ImGuiWindow* window = GetCurrentWindow();
|
||||||
if (window->Collapsed)
|
if (window->Collapsed)
|
||||||
return;
|
return;
|
||||||
@ -4314,7 +4319,7 @@ bool IsClipped(ImVec2 item_size)
|
|||||||
return IsClipped(ImGuiAabb(window->DC.CursorPos, window->DC.CursorPos + item_size));
|
return IsClipped(ImGuiAabb(window->DC.CursorPos, window->DC.CursorPos + item_size));
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool ClipAdvance(const ImGuiAabb& bb, bool skip_columns)
|
static bool ClipAdvance(const ImGuiAabb& bb)
|
||||||
{
|
{
|
||||||
ImGuiWindow* window = GetCurrentWindow();
|
ImGuiWindow* window = GetCurrentWindow();
|
||||||
if (ImGui::IsClipped(bb))
|
if (ImGui::IsClipped(bb))
|
||||||
@ -4551,58 +4556,62 @@ void ImDrawList::Clear()
|
|||||||
{
|
{
|
||||||
commands.resize(0);
|
commands.resize(0);
|
||||||
vtx_buffer.resize(0);
|
vtx_buffer.resize(0);
|
||||||
clip_rect_buffer.resize(0);
|
vtx_write = NULL;
|
||||||
vtx_write_ = NULL;
|
clip_rect_stack.resize(0);
|
||||||
clip_rect_stack_.resize(0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ImDrawList::PushClipRect(const ImVec4& clip_rect)
|
void ImDrawList::PushClipRect(const ImVec4& clip_rect)
|
||||||
{
|
{
|
||||||
commands.push_back(ImDrawCmd(ImDrawCmdType_PushClipRect));
|
if (!commands.empty() && commands.back().vtx_count == 0)
|
||||||
clip_rect_buffer.push_back(clip_rect);
|
{
|
||||||
clip_rect_stack_.push_back(clip_rect);
|
// Reuse empty command because high-level clipping may have discarded the other vertices already
|
||||||
|
commands.back().clip_rect = clip_rect;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ImDrawCmd draw_cmd;
|
||||||
|
draw_cmd.vtx_count = 0;
|
||||||
|
draw_cmd.clip_rect = clip_rect;
|
||||||
|
commands.push_back(draw_cmd);
|
||||||
|
}
|
||||||
|
clip_rect_stack.push_back(clip_rect);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ImDrawList::PopClipRect()
|
void ImDrawList::PopClipRect()
|
||||||
{
|
{
|
||||||
if (!commands.empty() && commands.back().cmd_type == ImDrawCmdType_PushClipRect)
|
clip_rect_stack.pop_back();
|
||||||
|
const ImVec4 clip_rect = clip_rect_stack.empty() ? ImVec4(-9999.0f,-9999.0f, +9999.0f, +9999.0f) : clip_rect_stack.back();
|
||||||
|
if (!commands.empty() && commands.back().vtx_count == 0)
|
||||||
{
|
{
|
||||||
// Discard push/pop combo because high-level clipping may have discarded the other draw commands already
|
// Reuse empty command because high-level clipping may have discarded the other vertices already
|
||||||
commands.pop_back();
|
commands.back().clip_rect = clip_rect;
|
||||||
clip_rect_buffer.pop_back();
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
commands.push_back(ImDrawCmd(ImDrawCmdType_PopClipRect));
|
ImDrawCmd draw_cmd;
|
||||||
|
draw_cmd.vtx_count = 0;
|
||||||
|
draw_cmd.clip_rect = clip_rect;
|
||||||
|
commands.push_back(draw_cmd);
|
||||||
}
|
}
|
||||||
clip_rect_stack_.pop_back();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ImDrawList::AddCommand(ImDrawCmdType cmd_type, int vtx_count)
|
void ImDrawList::ReserveVertices(unsigned int vtx_count)
|
||||||
{
|
{
|
||||||
// Maximum value that can fit in our u16 vtx_count member
|
|
||||||
const int VTX_COUNT_MAX = (1<<16);
|
|
||||||
|
|
||||||
// Merge commands if we can, turning them into less draw calls
|
|
||||||
ImDrawCmd* prev = commands.empty() ? NULL : &commands.back();
|
|
||||||
if (vtx_count > 0 && prev && prev->cmd_type == (ImU32)cmd_type && prev->vtx_count + vtx_count < VTX_COUNT_MAX)
|
|
||||||
prev->vtx_count += vtx_count;
|
|
||||||
else
|
|
||||||
commands.push_back(ImDrawCmd(cmd_type, vtx_count));
|
|
||||||
|
|
||||||
if (vtx_count > 0)
|
if (vtx_count > 0)
|
||||||
{
|
{
|
||||||
|
ImDrawCmd& draw_cmd = commands.back();
|
||||||
|
draw_cmd.vtx_count += vtx_count;
|
||||||
vtx_buffer.resize(vtx_buffer.size() + vtx_count);
|
vtx_buffer.resize(vtx_buffer.size() + vtx_count);
|
||||||
vtx_write_ = &vtx_buffer[vtx_buffer.size() - vtx_count];
|
vtx_write = &vtx_buffer[vtx_buffer.size() - vtx_count];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ImDrawList::AddVtx(const ImVec2& pos, ImU32 col)
|
void ImDrawList::AddVtx(const ImVec2& pos, ImU32 col)
|
||||||
{
|
{
|
||||||
vtx_write_->pos = pos;
|
vtx_write->pos = pos;
|
||||||
vtx_write_->col = col;
|
vtx_write->col = col;
|
||||||
vtx_write_->uv = IMDRAW_TEX_UV_FOR_WHITE;
|
vtx_write->uv = IMDRAW_TEX_UV_FOR_WHITE;
|
||||||
vtx_write_++;
|
vtx_write++;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ImDrawList::AddVtxLine(const ImVec2& a, const ImVec2& b, ImU32 col)
|
void ImDrawList::AddVtxLine(const ImVec2& a, const ImVec2& b, ImU32 col)
|
||||||
@ -4624,7 +4633,7 @@ void ImDrawList::AddLine(const ImVec2& a, const ImVec2& b, ImU32 col)
|
|||||||
if ((col >> 24) == 0)
|
if ((col >> 24) == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
AddCommand(ImDrawCmdType_DrawTriangleList, 6);
|
ReserveVertices(6);
|
||||||
AddVtxLine(a, b, col);
|
AddVtxLine(a, b, col);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -4645,7 +4654,7 @@ void ImDrawList::AddArc(const ImVec2& center, float rad, ImU32 col, int a_min, i
|
|||||||
|
|
||||||
if (tris)
|
if (tris)
|
||||||
{
|
{
|
||||||
AddCommand(ImDrawCmdType_DrawTriangleList, (a_max-a_min) * 3);
|
ReserveVertices((a_max-a_min) * 3);
|
||||||
for (int a = a_min; a < a_max; a++)
|
for (int a = a_min; a < a_max; a++)
|
||||||
{
|
{
|
||||||
AddVtx(center + circle_vtx[a % ARRAYSIZE(circle_vtx)] * rad, col);
|
AddVtx(center + circle_vtx[a % ARRAYSIZE(circle_vtx)] * rad, col);
|
||||||
@ -4655,7 +4664,7 @@ void ImDrawList::AddArc(const ImVec2& center, float rad, ImU32 col, int a_min, i
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
AddCommand(ImDrawCmdType_DrawTriangleList, (a_max-a_min) * 6);
|
ReserveVertices((a_max-a_min) * 6);
|
||||||
for (int a = a_min; a < a_max; a++)
|
for (int a = a_min; a < a_max; a++)
|
||||||
AddVtxLine(center + circle_vtx[a % ARRAYSIZE(circle_vtx)] * rad, center + circle_vtx[(a+1) % ARRAYSIZE(circle_vtx)] * rad, col);
|
AddVtxLine(center + circle_vtx[a % ARRAYSIZE(circle_vtx)] * rad, center + circle_vtx[(a+1) % ARRAYSIZE(circle_vtx)] * rad, col);
|
||||||
}
|
}
|
||||||
@ -4673,7 +4682,7 @@ void ImDrawList::AddRect(const ImVec2& a, const ImVec2& b, ImU32 col, float roun
|
|||||||
|
|
||||||
if (r == 0.0f || rounding_corners == 0)
|
if (r == 0.0f || rounding_corners == 0)
|
||||||
{
|
{
|
||||||
AddCommand(ImDrawCmdType_DrawTriangleList, 4*6);
|
ReserveVertices(4*6);
|
||||||
AddVtxLine(ImVec2(a.x,a.y), ImVec2(b.x,a.y), col);
|
AddVtxLine(ImVec2(a.x,a.y), ImVec2(b.x,a.y), col);
|
||||||
AddVtxLine(ImVec2(b.x,a.y), ImVec2(b.x,b.y), col);
|
AddVtxLine(ImVec2(b.x,a.y), ImVec2(b.x,b.y), col);
|
||||||
AddVtxLine(ImVec2(b.x,b.y), ImVec2(a.x,b.y), col);
|
AddVtxLine(ImVec2(b.x,b.y), ImVec2(a.x,b.y), col);
|
||||||
@ -4681,7 +4690,7 @@ void ImDrawList::AddRect(const ImVec2& a, const ImVec2& b, ImU32 col, float roun
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
AddCommand(ImDrawCmdType_DrawTriangleList, 4*6);
|
ReserveVertices(4*6);
|
||||||
AddVtxLine(ImVec2(a.x + ((rounding_corners & 1)?r:0), a.y), ImVec2(b.x - ((rounding_corners & 2)?r:0), a.y), col);
|
AddVtxLine(ImVec2(a.x + ((rounding_corners & 1)?r:0), a.y), ImVec2(b.x - ((rounding_corners & 2)?r:0), a.y), col);
|
||||||
AddVtxLine(ImVec2(b.x, a.y + ((rounding_corners & 2)?r:0)), ImVec2(b.x, b.y - ((rounding_corners & 4)?r:0)), col);
|
AddVtxLine(ImVec2(b.x, a.y + ((rounding_corners & 2)?r:0)), ImVec2(b.x, b.y - ((rounding_corners & 4)?r:0)), col);
|
||||||
AddVtxLine(ImVec2(b.x - ((rounding_corners & 4)?r:0), b.y), ImVec2(a.x + ((rounding_corners & 8)?r:0), b.y), col);
|
AddVtxLine(ImVec2(b.x - ((rounding_corners & 4)?r:0), b.y), ImVec2(a.x + ((rounding_corners & 8)?r:0), b.y), col);
|
||||||
@ -4707,7 +4716,7 @@ void ImDrawList::AddRectFilled(const ImVec2& a, const ImVec2& b, ImU32 col, floa
|
|||||||
if (r == 0.0f || rounding_corners == 0)
|
if (r == 0.0f || rounding_corners == 0)
|
||||||
{
|
{
|
||||||
// Use triangle so we can merge more draw calls together (at the cost of extra vertices)
|
// Use triangle so we can merge more draw calls together (at the cost of extra vertices)
|
||||||
AddCommand(ImDrawCmdType_DrawTriangleList, 6);
|
ReserveVertices(6);
|
||||||
AddVtx(ImVec2(a.x,a.y), col);
|
AddVtx(ImVec2(a.x,a.y), col);
|
||||||
AddVtx(ImVec2(b.x,a.y), col);
|
AddVtx(ImVec2(b.x,a.y), col);
|
||||||
AddVtx(ImVec2(b.x,b.y), col);
|
AddVtx(ImVec2(b.x,b.y), col);
|
||||||
@ -4717,7 +4726,7 @@ void ImDrawList::AddRectFilled(const ImVec2& a, const ImVec2& b, ImU32 col, floa
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
AddCommand(ImDrawCmdType_DrawTriangleList, 6+6*2);
|
ReserveVertices(6+6*2);
|
||||||
AddVtx(ImVec2(a.x+r,a.y), col);
|
AddVtx(ImVec2(a.x+r,a.y), col);
|
||||||
AddVtx(ImVec2(b.x-r,a.y), col);
|
AddVtx(ImVec2(b.x-r,a.y), col);
|
||||||
AddVtx(ImVec2(b.x-r,b.y), col);
|
AddVtx(ImVec2(b.x-r,b.y), col);
|
||||||
@ -4755,7 +4764,7 @@ void ImDrawList::AddTriangleFilled(const ImVec2& a, const ImVec2& b, const ImVec
|
|||||||
if ((col >> 24) == 0)
|
if ((col >> 24) == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
AddCommand(ImDrawCmdType_DrawTriangleList, 3);
|
ReserveVertices(3);
|
||||||
AddVtx(a, col);
|
AddVtx(a, col);
|
||||||
AddVtx(b, col);
|
AddVtx(b, col);
|
||||||
AddVtx(c, col);
|
AddVtx(c, col);
|
||||||
@ -4766,7 +4775,7 @@ void ImDrawList::AddCircle(const ImVec2& centre, float radius, ImU32 col, int nu
|
|||||||
if ((col >> 24) == 0)
|
if ((col >> 24) == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
AddCommand(ImDrawCmdType_DrawTriangleList, num_segments*6);
|
ReserveVertices(num_segments*6);
|
||||||
const float a_step = 2*PI/(float)num_segments;
|
const float a_step = 2*PI/(float)num_segments;
|
||||||
float a0 = 0.0f;
|
float a0 = 0.0f;
|
||||||
for (int i = 0; i < num_segments; i++)
|
for (int i = 0; i < num_segments; i++)
|
||||||
@ -4782,7 +4791,7 @@ void ImDrawList::AddCircleFilled(const ImVec2& centre, float radius, ImU32 col,
|
|||||||
if ((col >> 24) == 0)
|
if ((col >> 24) == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
AddCommand(ImDrawCmdType_DrawTriangleList, num_segments*3);
|
ReserveVertices(num_segments*3);
|
||||||
const float a_step = 2*PI/(float)num_segments;
|
const float a_step = 2*PI/(float)num_segments;
|
||||||
float a0 = 0.0f;
|
float a0 = 0.0f;
|
||||||
for (int i = 0; i < num_segments; i++)
|
for (int i = 0; i < num_segments; i++)
|
||||||
@ -4803,17 +4812,19 @@ void ImDrawList::AddText(ImFont font, float font_size, const ImVec2& pos, ImU32
|
|||||||
if (text_end == NULL)
|
if (text_end == NULL)
|
||||||
text_end = text_begin + strlen(text_begin);
|
text_end = text_begin + strlen(text_begin);
|
||||||
|
|
||||||
int char_count = text_end - text_begin;
|
// reserve vertices for worse case
|
||||||
int vtx_count_max = char_count * 6;
|
const int char_count = (int)(text_end - text_begin);
|
||||||
int vtx_begin = vtx_buffer.size();
|
const int vtx_count_max = char_count * 6;
|
||||||
AddCommand(ImDrawCmdType_DrawTriangleList, vtx_count_max);
|
const size_t vtx_begin = vtx_buffer.size();
|
||||||
|
ReserveVertices(vtx_count_max);
|
||||||
|
|
||||||
font->RenderText(font_size, pos, col, clip_rect_stack_.back(), text_begin, text_end, vtx_write_);
|
font->RenderText(font_size, pos, col, clip_rect_stack.back(), text_begin, text_end, vtx_write);
|
||||||
vtx_buffer.resize(vtx_write_ - &vtx_buffer.front());
|
|
||||||
int vtx_count = vtx_buffer.size() - vtx_begin;
|
|
||||||
|
|
||||||
|
// give unused vertices
|
||||||
|
vtx_buffer.resize(vtx_write - &vtx_buffer.front());
|
||||||
|
const int vtx_count = (int)(vtx_buffer.size() - vtx_begin);
|
||||||
commands.back().vtx_count -= (vtx_count_max - vtx_count);
|
commands.back().vtx_count -= (vtx_count_max - vtx_count);
|
||||||
vtx_write_ -= (vtx_count_max - vtx_count);
|
vtx_write -= (vtx_count_max - vtx_count);
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
@ -4862,7 +4873,7 @@ bool ImBitmapFont::LoadFromFile(const char* filename)
|
|||||||
fclose(f);
|
fclose(f);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (fread(Data, 1, DataSize, f) != DataSize)
|
if ((int)fread(Data, 1, DataSize, f) != DataSize)
|
||||||
{
|
{
|
||||||
fclose(f);
|
fclose(f);
|
||||||
free(Data);
|
free(Data);
|
||||||
@ -4923,7 +4934,7 @@ bool ImBitmapFont::LoadFromMemory(const void* data, int data_size)
|
|||||||
void ImBitmapFont::BuildLookupTable()
|
void ImBitmapFont::BuildLookupTable()
|
||||||
{
|
{
|
||||||
ImU32 max_c = 0;
|
ImU32 max_c = 0;
|
||||||
for (int i = 0; i != GlyphsCount; i++)
|
for (size_t i = 0; i != GlyphsCount; i++)
|
||||||
if (max_c < Glyphs[i].Id)
|
if (max_c < Glyphs[i].Id)
|
||||||
max_c = Glyphs[i].Id;
|
max_c = Glyphs[i].Id;
|
||||||
|
|
||||||
@ -4973,7 +4984,8 @@ ImVec2 ImBitmapFont::CalcTextSize(float size, float max_width, const char* text_
|
|||||||
if (const FntGlyph* glyph = FindGlyph((unsigned short)c))
|
if (const FntGlyph* glyph = FindGlyph((unsigned short)c))
|
||||||
{
|
{
|
||||||
const float char_width = (glyph->XAdvance + Info->SpacingHoriz) * scale;
|
const float char_width = (glyph->XAdvance + Info->SpacingHoriz) * scale;
|
||||||
const float char_extend = (glyph->XOffset + glyph->Width * scale);
|
//const float char_extend = (glyph->XOffset + glyph->Width * scale);
|
||||||
|
|
||||||
if (line_width + char_width >= max_width)
|
if (line_width + char_width >= max_width)
|
||||||
break;
|
break;
|
||||||
line_width += char_width;
|
line_width += char_width;
|
||||||
@ -5015,8 +5027,6 @@ void ImBitmapFont::RenderText(float size, ImVec2 pos, ImU32 col, const ImVec4& c
|
|||||||
pos.x = (float)(int)pos.x + 0.5f;
|
pos.x = (float)(int)pos.x + 0.5f;
|
||||||
pos.y = (float)(int)pos.y + 0.5f;
|
pos.y = (float)(int)pos.y + 0.5f;
|
||||||
|
|
||||||
ImVec2 text_size = ImVec2(0,0);
|
|
||||||
float line_width = 0.0f;
|
|
||||||
const ImVec4 clip_rect = clip_rect_ref;
|
const ImVec4 clip_rect = clip_rect_ref;
|
||||||
|
|
||||||
const float uv_offset = GImGui.IO.PixelCenterOffset;
|
const float uv_offset = GImGui.IO.PixelCenterOffset;
|
||||||
@ -5036,7 +5046,7 @@ void ImBitmapFont::RenderText(float size, ImVec2 pos, ImU32 col, const ImVec4& c
|
|||||||
if (const FntGlyph* glyph = FindGlyph((unsigned short)c))
|
if (const FntGlyph* glyph = FindGlyph((unsigned short)c))
|
||||||
{
|
{
|
||||||
const float char_width = (glyph->XAdvance + Info->SpacingHoriz) * scale;
|
const float char_width = (glyph->XAdvance + Info->SpacingHoriz) * scale;
|
||||||
const float char_extend = (glyph->XOffset + glyph->Width * scale);
|
//const float char_extend = (glyph->XOffset + glyph->Width * scale);
|
||||||
|
|
||||||
if (c != ' ' && c != '\n')
|
if (c != ' ' && c != '\n')
|
||||||
{
|
{
|
||||||
@ -5154,7 +5164,7 @@ void ShowStyleEditor(ImGuiStyle* ref)
|
|||||||
filter.Draw("Filter colors", 200);
|
filter.Draw("Filter colors", 200);
|
||||||
|
|
||||||
ImGui::ColorEditMode(edit_mode);
|
ImGui::ColorEditMode(edit_mode);
|
||||||
for (size_t i = 0; i < ImGuiCol_COUNT; i++)
|
for (int i = 0; i < ImGuiCol_COUNT; i++)
|
||||||
{
|
{
|
||||||
const char* name = GetStyleColorName(i);
|
const char* name = GetStyleColorName(i);
|
||||||
if (!filter.PassFilter(name))
|
if (!filter.PassFilter(name))
|
||||||
@ -5480,7 +5490,7 @@ void ShowTestWindow(bool* open)
|
|||||||
static float foo = 1.0f;
|
static float foo = 1.0f;
|
||||||
ImGui::InputFloat("red", &foo, 0.05f, 0, 3); ImGui::NextColumn();
|
ImGui::InputFloat("red", &foo, 0.05f, 0, 3); ImGui::NextColumn();
|
||||||
static float bar = 1.0f;
|
static float bar = 1.0f;
|
||||||
ImGui::InputFloat("blue", &foo, 0.05f, 0, 3); ImGui::NextColumn();
|
ImGui::InputFloat("blue", &bar, 0.05f, 0, 3); ImGui::NextColumn();
|
||||||
ImGui::Columns(1);
|
ImGui::Columns(1);
|
||||||
|
|
||||||
ImGui::Separator();
|
ImGui::Separator();
|
||||||
@ -5540,7 +5550,7 @@ void ShowTestWindow(bool* open)
|
|||||||
if (ImGui::Button("Add 1000 lines"))
|
if (ImGui::Button("Add 1000 lines"))
|
||||||
{
|
{
|
||||||
for (size_t i = 0; i < 1000; i++)
|
for (size_t i = 0; i < 1000; i++)
|
||||||
log.Append("%i The quick brown fox jumps over the lazy dog\n", lines+i);
|
log.append("%i The quick brown fox jumps over the lazy dog\n", lines+i);
|
||||||
lines += 1000;
|
lines += 1000;
|
||||||
}
|
}
|
||||||
ImGui::BeginChild("Log");
|
ImGui::BeginChild("Log");
|
||||||
|
35
imgui.h
35
imgui.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
|
||||||
@ -143,6 +143,7 @@ namespace ImGui
|
|||||||
void SetFontScale(float scale);
|
void SetFontScale(float scale);
|
||||||
void SetScrollPosHere();
|
void SetScrollPosHere();
|
||||||
void SetTreeStateStorage(ImGuiStorage* tree);
|
void SetTreeStateStorage(ImGuiStorage* tree);
|
||||||
|
ImGuiStorage* GetTreeStateStorage();
|
||||||
void PushItemWidth(float item_width);
|
void PushItemWidth(float item_width);
|
||||||
void PopItemWidth();
|
void PopItemWidth();
|
||||||
float GetItemWidth();
|
float GetItemWidth();
|
||||||
@ -221,9 +222,9 @@ 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 SetTooltip(const char* fmt, ...); // set tooltip under mouse-cursor, typically use with ImGui::IsHovered(). (currently no contention handling, last call win)
|
||||||
@ -232,6 +233,8 @@ namespace ImGui
|
|||||||
bool IsClipped(ImVec2 item_size); // to perform coarse clipping on user's side (as an optimisation)
|
bool IsClipped(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);
|
||||||
|
bool IsMouseDoubleClicked(int button);
|
||||||
|
bool IsMouseHoveringBox(const ImVec2& box_min, const ImVec2& box_max);
|
||||||
ImVec2 GetMousePos();
|
ImVec2 GetMousePos();
|
||||||
float GetTime();
|
float GetTime();
|
||||||
int GetFrameCount();
|
int GetFrameCount();
|
||||||
@ -469,7 +472,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
|
||||||
@ -496,19 +499,10 @@ 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
|
#ifndef IMDRAW_TEX_UV_FOR_WHITE
|
||||||
@ -529,16 +523,15 @@ struct ImDrawList
|
|||||||
{
|
{
|
||||||
ImVector<ImDrawCmd> commands;
|
ImVector<ImDrawCmd> 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)
|
||||||
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)
|
||||||
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)
|
|
||||||
|
|
||||||
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);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user