Created
January 21, 2020 02:58
-
-
Save ShawnMcGrath/5f629c2d3a137e6df00104a2fccfbe8a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//this copies the logic of void ImDrawList::AddConvexPolyFilled() | |
static void imgui_fixQuadFilledVerts(ImDrawList *draw_list, int vert_offset, ImVec2 *points, mgColour opt_col) { | |
MG_ASSERT(draw_list->VtxBuffer.Size > vert_offset - 8); | |
const int points_count = 4; | |
ImDrawVert *vert_ptr = draw_list->VtxBuffer.Data + vert_offset; | |
if (draw_list->Flags & ImDrawListFlags_AntiAliasedFill) { | |
// Anti-aliased Fill | |
const float AA_SIZE = 1.0f; | |
// Compute normals | |
ImVec2 temp_normals[points_count]; | |
for (int i0 = points_count-1, i1 = 0; i1 < points_count; i0 = i1++) | |
{ | |
const ImVec2& p0 = points[i0]; | |
const ImVec2& p1 = points[i1]; | |
float dx = p1.x - p0.x; | |
float dy = p1.y - p0.y; | |
IM_NORMALIZE2F_OVER_ZERO___(dx, dy); | |
temp_normals[i0].x = dy; | |
temp_normals[i0].y = -dx; | |
} | |
for (int i0 = points_count-1, i1 = 0; i1 < points_count; i0 = i1++) | |
{ | |
// Average normals | |
const ImVec2& n0 = temp_normals[i0]; | |
const ImVec2& n1 = temp_normals[i1]; | |
float dm_x = (n0.x + n1.x) * 0.5f; | |
float dm_y = (n0.y + n1.y) * 0.5f; | |
IM_FIXNORMAL2F___(dm_x, dm_y); | |
dm_x *= AA_SIZE * 0.5f; | |
dm_y *= AA_SIZE * 0.5f; | |
// Add vertices | |
vert_ptr[0].pos.x = (points[i1].x - dm_x); vert_ptr[0].pos.y = (points[i1].y - dm_y);// vert_ptr[0].uv = uv; vert_ptr[0].col = col; // Inner | |
vert_ptr[1].pos.x = (points[i1].x + dm_x); vert_ptr[1].pos.y = (points[i1].y + dm_y);// vert_ptr[1].uv = uv; vert_ptr[1].col = col_trans; // Outer | |
if (opt_col.packed) { | |
vert_ptr[0].col = opt_col.packed; | |
} | |
vert_ptr += 2; | |
} | |
} else { | |
// Non Anti-aliased Fill | |
for (int i = 0; i < points_count; i++) { | |
vert_ptr[i].pos = points[i]; //_VtxWritePtr[0].uv = uv; _VtxWritePtr[0].col = col; | |
if (opt_col.packed) { | |
vert_ptr[i].col = opt_col.packed; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment