From f9a19f243a7f22d338aac8c9f900b7b8f700c101 Mon Sep 17 00:00:00 2001 From: Sim Dietrich Date: Sun, 10 Aug 2014 19:47:14 -0700 Subject: [PATCH 1/2] Fix 0.5 pixel offset, only needed for d3d <= 9 Defaults to 0.0f, which is correct for d3d10+ and ogl --- examples/directx9_example/main.cpp | 2 ++ imgui.cpp | 5 +++-- imgui.h | 1 + 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/examples/directx9_example/main.cpp b/examples/directx9_example/main.cpp index fd25f0101..88faf74d6 100644 --- a/examples/directx9_example/main.cpp +++ b/examples/directx9_example/main.cpp @@ -297,6 +297,8 @@ void InitImGui() io.RenderDrawListsFn = ImImpl_RenderDrawLists; io.SetClipboardTextFn = ImImpl_SetClipboardTextFn; io.GetClipboardTextFn = ImImpl_GetClipboardTextFn; + + ImGui::GetStyle().PixelCenterOffset = 0.5f; // to make texels & pixels align } int WINAPI wWinMain(HINSTANCE hInst, HINSTANCE, LPWSTR, int) diff --git a/imgui.cpp b/imgui.cpp index e5aca50ca..540d826c0 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -211,6 +211,7 @@ ImGuiStyle::ImGuiStyle() TreeNodeSpacing = 22.0f; ColumnsMinSpacing = 6.0f; // Minimum space between two columns ScrollBarWidth = 16.0f; + PixelCenterOffset = 0.0f; // for <= d3d9, this should be 0.5f. for ogl & d3d10+, 0.0f is correct Colors[ImGuiCol_Text] = ImVec4(0.90f, 0.90f, 0.90f, 1.00f); Colors[ImGuiCol_WindowBg] = ImVec4(0.00f, 0.00f, 0.00f, 1.00f); @@ -3355,8 +3356,8 @@ bool RadioButton(const char* label, bool active) return false; ImVec2 center = check_bb.GetCenter(); - center.x = (float)(int)center.x + 0.5f; - center.y = (float)(int)center.y + 0.5f; + center.x = (float)(int)center.x + style.PixelCenterOffset; + center.y = (float)(int)center.y + style.PixelCenterOffset; const float radius = check_bb.GetHeight() * 0.5f; const bool hovered = (g.HoveredWindow == window) && (g.HoveredId == 0) && IsMouseHoveringBox(check_bb); diff --git a/imgui.h b/imgui.h index 3c7505771..29904e7ac 100644 --- a/imgui.h +++ b/imgui.h @@ -352,6 +352,7 @@ struct ImGuiStyle float TreeNodeSpacing; float ColumnsMinSpacing; float ScrollBarWidth; + float PixelCenterOffset; ImVec4 Colors[ImGuiCol_COUNT]; ImGuiStyle(); From a238a1dcc0ab6fd160f8895e6573363c62270e17 Mon Sep 17 00:00:00 2001 From: Sim Dietrich Date: Sun, 10 Aug 2014 19:47:14 -0700 Subject: [PATCH 2/2] Fix 0.5 pixel offset, only needed for d3d <= 9 Defaults to 0.0f, which is correct for d3d10+ and ogl --- examples/directx9_example/main.cpp | 2 ++ imgui.cpp | 5 +++-- imgui.h | 1 + 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/examples/directx9_example/main.cpp b/examples/directx9_example/main.cpp index fd25f0101..88faf74d6 100644 --- a/examples/directx9_example/main.cpp +++ b/examples/directx9_example/main.cpp @@ -297,6 +297,8 @@ void InitImGui() io.RenderDrawListsFn = ImImpl_RenderDrawLists; io.SetClipboardTextFn = ImImpl_SetClipboardTextFn; io.GetClipboardTextFn = ImImpl_GetClipboardTextFn; + + ImGui::GetStyle().PixelCenterOffset = 0.5f; // to make texels & pixels align } int WINAPI wWinMain(HINSTANCE hInst, HINSTANCE, LPWSTR, int) diff --git a/imgui.cpp b/imgui.cpp index e5aca50ca..6351f1dd2 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -211,6 +211,7 @@ ImGuiStyle::ImGuiStyle() TreeNodeSpacing = 22.0f; ColumnsMinSpacing = 6.0f; // Minimum space between two columns ScrollBarWidth = 16.0f; + PixelCenterOffset = 0.0f; // for <= d3d9, this should be 0.5f. for ogl & d3d10+, 0.0f is correct Colors[ImGuiCol_Text] = ImVec4(0.90f, 0.90f, 0.90f, 1.00f); Colors[ImGuiCol_WindowBg] = ImVec4(0.00f, 0.00f, 0.00f, 1.00f); @@ -4993,8 +4994,8 @@ void ImBitmapFont::RenderText(float size, ImVec2 pos, ImU32 col, const ImVec4& c const float outline = (float)Info->Outline; // Align to be pixel perfect - pos.x = (float)(int)pos.x + 0.5f; - pos.y = (float)(int)pos.y + 0.5f; + pos.x = (float)(int)pos.x + ImGui::GetStyle().PixelCenterOffset; + pos.y = (float)(int)pos.y + ImGui::GetStyle().PixelCenterOffset; ImVec2 text_size = ImVec2(0,0); float line_width = 0.0f; diff --git a/imgui.h b/imgui.h index 3c7505771..29904e7ac 100644 --- a/imgui.h +++ b/imgui.h @@ -352,6 +352,7 @@ struct ImGuiStyle float TreeNodeSpacing; float ColumnsMinSpacing; float ScrollBarWidth; + float PixelCenterOffset; ImVec4 Colors[ImGuiCol_COUNT]; ImGuiStyle();