From 0fc1f5b17ff271c4e0ef8a3e3330281558406fb4 Mon Sep 17 00:00:00 2001 From: ocornut Date: Thu, 9 Apr 2015 16:45:14 +0100 Subject: [PATCH] Revert AddArcFast()->AddArc(), removed modulo from function 200d3482dcb94e0cf886863fbb95770f35f9ba43 --- imgui.cpp | 43 ++++++++++++++++++++++++------------------- imgui.h | 2 +- 2 files changed, 25 insertions(+), 20 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 7171dd8b8..9fa96cad8 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -135,7 +135,7 @@ Occasionally introducing changes that are breaking the API. The breakage are generally minor and easy to fix. Here is a change-log of API breaking changes, if you are using one of the functions listed, expect to have to fix some code. - - 2015/04/09 (1.38) - renamed ImDrawList::AddArc() to ImDrawList::AddArcFast() for compatibility with future API, and changed 2*PI range from 0..12 to 0..16 + - 2015/04/09 (1.38) - renamed ImDrawList::AddArc() to ImDrawList::AddArcFast() for compatibility with future API - 2015/04/03 (1.38) - removed ImGuiCol_CheckHovered, ImGuiCol_CheckActive, replaced with the more general ImGuiCol_FrameBgHovered, ImGuiCol_FrameBgActive. - 2014/04/03 (1.38) - removed support for passing -FLT_MAX..+FLT_MAX as the range for a SliderFloat(). Use DragFloat() or Inputfloat() instead. - 2015/03/17 (1.36) - renamed GetItemRectMin()/GetItemRectMax()/IsMouseHoveringBox() to GetItemRectMin()/GetItemRectMax()/IsMouseHoveringRect(). Kept inline redirection function (will obsolete). @@ -3329,7 +3329,7 @@ bool ImGui::Begin(const char* name, bool* p_opened, const ImVec2& size_on_first_ else { // FIXME: We should draw 4 triangles and decide on a size that's not dependent on the rounding size (previously used 18) - window->DrawList->AddArcFast(br - ImVec2(r,r), r, resize_col, 8, 12, true); + window->DrawList->AddArcFast(br - ImVec2(r,r), r, resize_col, 6, 9, true); 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); } @@ -7751,18 +7751,19 @@ void ImDrawList::AddLine(const ImVec2& a, const ImVec2& b, ImU32 col, float thic AddVtxLine(a, b, col, thickness); } -void ImDrawList::AddArcFast(const ImVec2& center, float rad, ImU32 col, int a_min, int a_max, bool tris, const ImVec2& third_point_offset) +void ImDrawList::AddArcFast(const ImVec2& center, float radius, ImU32 col, int a_min, int a_max, bool tris, const ImVec2& third_point_offset) { if ((col >> 24) == 0) return; - static ImVec2 circle_vtx[16]; + const int SAMPLES = 12; + static ImVec2 circle_vtx[SAMPLES]; static bool circle_vtx_builds = false; if (!circle_vtx_builds) { - for (int i = 0; i < 16; i++) + for (int i = 0; i < SAMPLES; i++) { - const float a = ((float)i / (float)16.0f) * 2*PI; + const float a = ((float)i / (float)SAMPLES) * 2*PI; circle_vtx[i].x = cosf(a + PI); circle_vtx[i].y = sinf(a + PI); } @@ -7772,18 +7773,22 @@ void ImDrawList::AddArcFast(const ImVec2& center, float rad, ImU32 col, int a_mi if (tris) { ReserveVertices((unsigned int)(a_max-a_min) * 3); - for (int a = a_min; a < a_max; a++) + for (int a0 = a_min; a0 < a_max; a0++) { - AddVtx(center + circle_vtx[a & 15] * rad, col); - AddVtx(center + circle_vtx[(a+1) & 15] * rad, col); + int a1 = (a0 + 1 == SAMPLES) ? 0 : a0 + 1; + AddVtx(center + circle_vtx[a0] * radius, col); + AddVtx(center + circle_vtx[a1] * radius, col); AddVtx(center + third_point_offset, col); } } else { ReserveVertices((unsigned int)(a_max-a_min) * 6); - for (int a = a_min; a < a_max; a++) - AddVtxLine(center + circle_vtx[a & 15] * rad, center + circle_vtx[(a+1) & 15] * rad, col); + for (int a0 = a_min; a0 < a_max; a0++) + { + int a1 = (a0 + 1 == SAMPLES) ? 0 : a0 + 1; + AddVtxLine(center + circle_vtx[a0] * radius, center + circle_vtx[a1] * radius, col); + } } } @@ -7812,10 +7817,10 @@ void ImDrawList::AddRect(const ImVec2& a, const ImVec2& b, ImU32 col, float roun AddVtxLine(ImVec2(b.x - ((rounding_corners & 4)?r:0), b.y), ImVec2(a.x + ((rounding_corners & 8)?r:0), b.y), col); AddVtxLine(ImVec2(a.x, b.y - ((rounding_corners & 8)?r:0)), ImVec2(a.x, a.y + ((rounding_corners & 1)?r:0)), col); - if (rounding_corners & 1) AddArcFast(ImVec2(a.x+r,a.y+r), r, col, 0, 4); - if (rounding_corners & 2) AddArcFast(ImVec2(b.x-r,a.y+r), r, col, 4, 8); - if (rounding_corners & 4) AddArcFast(ImVec2(b.x-r,b.y-r), r, col, 8, 12); - if (rounding_corners & 8) AddArcFast(ImVec2(a.x+r,b.y-r), r, col, 12, 16); + if (rounding_corners & 1) AddArcFast(ImVec2(a.x+r,a.y+r), r, col, 0, 3); + if (rounding_corners & 2) AddArcFast(ImVec2(b.x-r,a.y+r), r, col, 3, 6); + if (rounding_corners & 4) AddArcFast(ImVec2(b.x-r,b.y-r), r, col, 6, 9); + if (rounding_corners & 8) AddArcFast(ImVec2(a.x+r,b.y-r), r, col, 9, 12); } } @@ -7867,10 +7872,10 @@ void ImDrawList::AddRectFilled(const ImVec2& a, const ImVec2& b, ImU32 col, floa AddVtx(ImVec2(b.x,bot_y), col); AddVtx(ImVec2(b.x-r,bot_y), col); - if (rounding_corners & 1) AddArcFast(ImVec2(a.x+r,a.y+r), r, col, 0, 4, true); - if (rounding_corners & 2) AddArcFast(ImVec2(b.x-r,a.y+r), r, col, 4, 8, true); - if (rounding_corners & 4) AddArcFast(ImVec2(b.x-r,b.y-r), r, col, 8, 12, true); - if (rounding_corners & 8) AddArcFast(ImVec2(a.x+r,b.y-r), r, col, 12, 16, true); + if (rounding_corners & 1) AddArcFast(ImVec2(a.x+r,a.y+r), r, col, 0, 3, true); + if (rounding_corners & 2) AddArcFast(ImVec2(b.x-r,a.y+r), r, col, 3, 6, true); + if (rounding_corners & 4) AddArcFast(ImVec2(b.x-r,b.y-r), r, col, 6, 8, true); + if (rounding_corners & 8) AddArcFast(ImVec2(a.x+r,b.y-r), r, col, 9, 12, true); } } diff --git a/imgui.h b/imgui.h index 96c374be5..0188146a1 100644 --- a/imgui.h +++ b/imgui.h @@ -913,7 +913,7 @@ struct ImDrawList IMGUI_API void AddTriangleFilled(const ImVec2& a, const ImVec2& b, const ImVec2& c, ImU32 col); IMGUI_API void AddCircle(const ImVec2& centre, float radius, ImU32 col, int num_segments = 12); IMGUI_API void AddCircleFilled(const ImVec2& centre, float radius, ImU32 col, int num_segments = 12); - IMGUI_API void AddArcFast(const ImVec2& center, float rad, ImU32 col, int a_min_of_16, int a_max_of_16, bool tris = false, const ImVec2& third_point_offset = ImVec2(0,0)); // Angles in 0..16 range + IMGUI_API void AddArcFast(const ImVec2& center, float radius, ImU32 col, int a_min_12, int a_max_12, bool tris = false, const ImVec2& third_point_offset = ImVec2(0,0)); // Angles in 0..12 range IMGUI_API void AddText(const ImFont* font, float font_size, const ImVec2& pos, ImU32 col, const char* text_begin, const char* text_end = NULL, float wrap_width = 0.0f, const ImVec2* cpu_clip_max = NULL); IMGUI_API void AddImage(ImTextureID user_texture_id, const ImVec2& a, const ImVec2& b, const ImVec2& uv0, const ImVec2& uv1, ImU32 col = 0xFFFFFFFF);