From cb9a3235bec264809089f1016e31424b21b251d3 Mon Sep 17 00:00:00 2001 From: ocornut Date: Sat, 17 Jan 2015 17:17:18 +0000 Subject: [PATCH] Removed PixelCenterOffset, uncesssary --- examples/directx11_example/main.cpp | 2 -- examples/directx9_example/main.cpp | 2 -- examples/opengl3_example/main.cpp | 2 -- examples/opengl_example/main.cpp | 2 -- imgui.cpp | 43 +++++++++++------------------ imgui.h | 1 - 6 files changed, 16 insertions(+), 36 deletions(-) diff --git a/examples/directx11_example/main.cpp b/examples/directx11_example/main.cpp index 5f18917a8..32ceb293d 100644 --- a/examples/directx11_example/main.cpp +++ b/examples/directx11_example/main.cpp @@ -44,7 +44,6 @@ struct VERTEX_CONSTANT_BUFFER // This is the main rendering function that you have to implement and provide to ImGui (via setting up 'RenderDrawListsFn' in the ImGuiIO structure) // If text or lines are blurry when integrating ImGui in your engine: // - in your Render function, try translating your projection matrix by (0.5f,0.5f) or (0.375f,0.375f) -// - try adjusting ImGui::GetIO().PixelCenterOffset to 0.5f or 0.375f static void ImImpl_RenderDrawLists(ImDrawList** const cmd_lists, int cmd_lists_count) { size_t total_vtx_count = 0; @@ -429,7 +428,6 @@ void InitImGui() ImGuiIO& io = ImGui::GetIO(); io.DisplaySize = ImVec2((float)display_w, (float)display_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 time step is variable) - 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_RightArrow] = VK_RIGHT; diff --git a/examples/directx9_example/main.cpp b/examples/directx9_example/main.cpp index 3752bafc2..1f312538b 100644 --- a/examples/directx9_example/main.cpp +++ b/examples/directx9_example/main.cpp @@ -25,7 +25,6 @@ struct CUSTOMVERTEX // This is the main rendering function that you have to implement and provide to ImGui (via setting up 'RenderDrawListsFn' in the ImGuiIO structure) // If text or lines are blurry when integrating ImGui in your engine: // - in your Render function, try translating your projection matrix by (0.5f,0.5f) or (0.375f,0.375f) -// - try adjusting ImGui::GetIO().PixelCenterOffset to 0.5f or 0.375f static void ImImpl_RenderDrawLists(ImDrawList** const cmd_lists, int cmd_lists_count) { size_t total_vtx_count = 0; @@ -212,7 +211,6 @@ void InitImGui() ImGuiIO& io = ImGui::GetIO(); io.DisplaySize = ImVec2((float)display_w, (float)display_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 time step is variable) - 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_RightArrow] = VK_RIGHT; diff --git a/examples/opengl3_example/main.cpp b/examples/opengl3_example/main.cpp index 9934bc887..0c0dfab63 100644 --- a/examples/opengl3_example/main.cpp +++ b/examples/opengl3_example/main.cpp @@ -28,7 +28,6 @@ static unsigned int vbo_handle, vao_handle; // 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: -// - 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) static void ImImpl_RenderDrawLists(ImDrawList** const cmd_lists, int cmd_lists_count) { @@ -256,7 +255,6 @@ void InitImGui() { ImGuiIO& io = ImGui::GetIO(); 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.KeyMap[ImGuiKey_Tab] = GLFW_KEY_TAB; // Keyboard mapping. ImGui will use those indices to peek into the io.KeyDown[] array. io.KeyMap[ImGuiKey_LeftArrow] = GLFW_KEY_LEFT; io.KeyMap[ImGuiKey_RightArrow] = GLFW_KEY_RIGHT; diff --git a/examples/opengl_example/main.cpp b/examples/opengl_example/main.cpp index 0119e7891..29e1c97b4 100644 --- a/examples/opengl_example/main.cpp +++ b/examples/opengl_example/main.cpp @@ -22,7 +22,6 @@ static bool mousePressed[2] = { false, false }; // This is the main rendering function that you have to implement and provide to ImGui (via setting up 'RenderDrawListsFn' in the ImGuiIO structure) // If text or lines are blurry when integrating ImGui in your engine: // - in your Render function, try translating your projection matrix by (0.5f,0.5f) or (0.375f,0.375f) -// - try adjusting ImGui::GetIO().PixelCenterOffset to 0.5f or 0.375f static void ImImpl_RenderDrawLists(ImDrawList** const cmd_lists, int cmd_lists_count) { if (cmd_lists_count == 0) @@ -166,7 +165,6 @@ void InitImGui() { ImGuiIO& io = ImGui::GetIO(); 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 time step is variable) - io.PixelCenterOffset = 0.0f; // Align OpenGL texels io.KeyMap[ImGuiKey_Tab] = GLFW_KEY_TAB; // Keyboard mapping. ImGui will use those indices to peek into the io.KeyDown[] array. io.KeyMap[ImGuiKey_LeftArrow] = GLFW_KEY_LEFT; io.KeyMap[ImGuiKey_RightArrow] = GLFW_KEY_RIGHT; diff --git a/imgui.cpp b/imgui.cpp index 6f56113dc..f9840bb8a 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -127,6 +127,7 @@ - 2015/01/11 (1.30) big font/image API change. now loads TTF file. allow for multiple fonts. no need for a PNG loader. removed GetDefaultFontData(). uses io.Font->GetTextureData*() API to retrieve uncompressed pixels. added texture identifier in ImDrawCmd passed to your render function. + removed IO.PixelCenterOffset (unnecessary, can be handled in user projection matrix) - 2014/12/10 (1.18) removed SetNewWindowDefaultPos() in favor of new generic API SetNextWindowPos(pos, ImGuiSetCondition_FirstUseEver) - 2014/11/28 (1.17) moved IO.Font*** options to inside the IO.Font-> structure. - 2014/11/26 (1.17) reworked syntax of IMGUI_ONCE_UPON_A_FRAME helper macro to increase compiler compatibility @@ -145,7 +146,6 @@ 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 If you are confused about the meaning or use of ID in ImGui: - some widgets requires state to be carried over multiple frames (most typically ImGui often wants remember what is the "active" widget). @@ -214,7 +214,6 @@ - main: IsItemHovered() returns true even if mouse is active on another widget (e.g. dragging outside of sliders). Maybe not a sensible default? Add parameter or alternate function? - main: IsItemHovered() make it more consistent for various type of widgets, widgets with multiple components, etc. also effectively IsHovered() region sometimes differs from hot region, e.g tree nodes - main: IsItemHovered() info stored in a stack? so that 'if TreeNode() { Text; TreePop; } if IsHovered' return the hover state of the TreeNode? -!- drawlist: handling of PixelCenterOffset is badly inconsistent (sometimes in callee, sometimes in caller). - scrollbar: use relative mouse movement when first-clicking inside of scroll grab box. - scrollbar: make the grab visible and a minimum size for long scroll regions !- input number: very large int not reliably supported because of int<>float conversions. @@ -450,7 +449,6 @@ ImGuiIO::ImGuiIO() Font = &GDefaultStaticFont; FontGlobalScale = 1.0f; FontAllowUserScaling = false; - PixelCenterOffset = 0.0f; MousePos = ImVec2(-1,-1); MousePosPrev = ImVec2(-1,-1); MouseDoubleClickTime = 0.30f; @@ -1963,10 +1961,9 @@ static void RenderFrame(ImVec2 p_min, ImVec2 p_max, ImU32 fill_col, bool border, window->DrawList->AddRectFilled(p_min, p_max, fill_col, rounding); if (border && (window->Flags & ImGuiWindowFlags_ShowBorders)) { - // FIXME: This is the best I've found that works on multiple renderer/back ends. Rather dodgy. - const float offset = GImGui.IO.PixelCenterOffset; - window->DrawList->AddRect(p_min+ImVec2(1.5f-offset,1.5f-offset), p_max+ImVec2(1.0f-offset*2,1.0f-offset*2), window->Color(ImGuiCol_BorderShadow), rounding); - window->DrawList->AddRect(p_min+ImVec2(0.5f-offset,0.5f-offset), p_max+ImVec2(0.0f-offset*2,0.0f-offset*2), window->Color(ImGuiCol_Border), rounding); + // FIXME: This is the best I've found that works on multiple renderer/back ends. Bit dodgy. + window->DrawList->AddRect(p_min+ImVec2(1.5f,1.5f), p_max+ImVec2(1,1), window->Color(ImGuiCol_BorderShadow), rounding); + window->DrawList->AddRect(p_min+ImVec2(0.5f,0.5f), p_max+ImVec2(0,0), window->Color(ImGuiCol_Border), rounding); } } @@ -2631,10 +2628,9 @@ bool ImGui::Begin(const char* name, bool* p_opened, ImVec2 size, float fill_alph else { // FIXME: We should draw 4 triangles and decide on a size that's not dependent on the rounding size (previously used 18) - const ImVec2 offset(GImGui.IO.PixelCenterOffset,GImGui.IO.PixelCenterOffset); window->DrawList->AddArc(br - ImVec2(r,r), r, resize_col, 6, 9, true); - window->DrawList->AddTriangleFilled(br-offset+ImVec2(0,-2*r),br-offset+ImVec2(0,-r),br-offset+ImVec2(-r,-r), resize_col); - window->DrawList->AddTriangleFilled(br-offset+ImVec2(-r,-r), br-offset+ImVec2(-r,0),br-offset+ImVec2(-2*r,0), resize_col); + window->DrawList->AddTriangleFilled(br+ImVec2(0,-2*r),br+ImVec2(0,-r),br+ImVec2(-r,-r), resize_col); + window->DrawList->AddTriangleFilled(br+ImVec2(-r,-r), br+ImVec2(-r,0),br+ImVec2(-2*r,0), resize_col); } } } @@ -6021,11 +6017,10 @@ void ImDrawList::AddVtxUV(const ImVec2& pos, ImU32 col, const ImVec2& uv) void ImDrawList::AddVtxLine(const ImVec2& a, const ImVec2& b, ImU32 col) { - const float offset = GImGui.IO.PixelCenterOffset; const float length = sqrtf(ImLengthSqr(b - a)); - const ImVec2 hn = (b - a) * (0.50f / length); // half normal - const ImVec2 hp0 = ImVec2(offset + hn.y, offset - hn.x); // half perpendiculars + user offset - const ImVec2 hp1 = ImVec2(offset - hn.y, offset + hn.x); + const ImVec2 hn = (b - a) * (0.50f / length); // half normal + const ImVec2 hp0 = ImVec2(+hn.y, -hn.x); // half perpendiculars + user offset + const ImVec2 hp1 = ImVec2(-hn.y, +hn.x); // Two triangles makes up one line. Using triangles allows us to reduce amount of draw calls. AddVtx(a + hp0, col); @@ -6173,12 +6168,10 @@ void ImDrawList::AddTriangleFilled(const ImVec2& a, const ImVec2& b, const ImVec if ((col >> 24) == 0) return; - const ImVec2 offset(GImGui.IO.PixelCenterOffset,GImGui.IO.PixelCenterOffset); - ReserveVertices(3); - AddVtx(a + offset, col); - AddVtx(b + offset, col); - AddVtx(c + offset, col); + AddVtx(a, col); + AddVtx(b, col); + AddVtx(c, col); } void ImDrawList::AddCircle(const ImVec2& centre, float radius, ImU32 col, int num_segments) @@ -6186,15 +6179,13 @@ void ImDrawList::AddCircle(const ImVec2& centre, float radius, ImU32 col, int nu if ((col >> 24) == 0) return; - const ImVec2 offset(GImGui.IO.PixelCenterOffset,GImGui.IO.PixelCenterOffset); - ReserveVertices((unsigned int)num_segments*6); const float a_step = 2*PI/(float)num_segments; float a0 = 0.0f; for (int i = 0; i < num_segments; i++) { const float a1 = (i + 1) == num_segments ? 0.0f : a0 + a_step; - AddVtxLine(centre + offset + ImVec2(cosf(a0), sinf(a0))*radius, centre + ImVec2(cosf(a1), sinf(a1))*radius, col); + AddVtxLine(centre + ImVec2(cosf(a0), sinf(a0))*radius, centre + ImVec2(cosf(a1), sinf(a1))*radius, col); a0 = a1; } } @@ -6204,17 +6195,15 @@ void ImDrawList::AddCircleFilled(const ImVec2& centre, float radius, ImU32 col, if ((col >> 24) == 0) return; - const ImVec2 offset(GImGui.IO.PixelCenterOffset,GImGui.IO.PixelCenterOffset); - ReserveVertices((unsigned int)num_segments*3); const float a_step = 2*PI/(float)num_segments; float a0 = 0.0f; for (int i = 0; i < num_segments; i++) { const float a1 = (i + 1) == num_segments ? 0.0f : a0 + a_step; - AddVtx(centre + offset + ImVec2(cosf(a0), sinf(a0))*radius, col); - AddVtx(centre + offset + ImVec2(cosf(a1), sinf(a1))*radius, col); - AddVtx(centre + offset, col); + AddVtx(centre + ImVec2(cosf(a0), sinf(a0))*radius, col); + AddVtx(centre + ImVec2(cosf(a1), sinf(a1))*radius, col); + AddVtx(centre, col); a0 = a1; } } diff --git a/imgui.h b/imgui.h index 216d5a42d..4353c5d2f 100644 --- a/imgui.h +++ b/imgui.h @@ -494,7 +494,6 @@ struct ImGuiIO ImFont* Font; // // Font (also see 'Settings' fields inside ImFont structure for details) float FontGlobalScale; // = 1.0f // Global scale all fonts bool FontAllowUserScaling; // = false // Allow user scaling text of individual window with CTRL+Wheel. - float PixelCenterOffset; // = 0.0f // Try to set to 0.5f or 0.375f if rendering is blurry void* UserData; // = NULL // Store your own data for retrieval by callbacks.