Improved ColorPicker hue wheel color interpolation

This commit is contained in:
Václav Patejdl 2017-09-05 16:31:54 +02:00
parent 2600b28f5d
commit e1a7aa41cb

View File

@ -9510,11 +9510,11 @@ static void RenderArrowsForVerticalBar(ImDrawList* draw_list, ImVec2 pos, ImVec2
static void PaintVertsLinearGradientKeepAlpha(ImDrawVert* vert_start, ImDrawVert* vert_end, ImVec2 gradient_p0, ImVec2 gradient_p1, ImU32 col0, ImU32 col1) static void PaintVertsLinearGradientKeepAlpha(ImDrawVert* vert_start, ImDrawVert* vert_end, ImVec2 gradient_p0, ImVec2 gradient_p1, ImU32 col0, ImU32 col1)
{ {
ImVec2 gradient_extent = gradient_p1 - gradient_p0; ImVec2 gradient_extent = gradient_p1 - gradient_p0;
float gradient_inv_length = ImInvLength(gradient_extent, 0.0f); float gradient_inv_length2 = 1.0f / ImLengthSqr(gradient_extent);
for (ImDrawVert* vert = vert_start; vert < vert_end; vert++) for (ImDrawVert* vert = vert_start; vert < vert_end; vert++)
{ {
float d = ImDot(vert->pos - gradient_p0, gradient_extent); float d = ImDot(vert->pos - gradient_p0, gradient_extent);
float t = ImMin(sqrtf(ImMax(d, 0.0f)) * gradient_inv_length, 1.0f); float t = ImClamp(d * gradient_inv_length2, 0.0f, 1.0f);
int r = ImLerp((int)(col0 >> IM_COL32_R_SHIFT) & 0xFF, (int)(col1 >> IM_COL32_R_SHIFT) & 0xFF, t); int r = ImLerp((int)(col0 >> IM_COL32_R_SHIFT) & 0xFF, (int)(col1 >> IM_COL32_R_SHIFT) & 0xFF, t);
int g = ImLerp((int)(col0 >> IM_COL32_G_SHIFT) & 0xFF, (int)(col1 >> IM_COL32_G_SHIFT) & 0xFF, t); int g = ImLerp((int)(col0 >> IM_COL32_G_SHIFT) & 0xFF, (int)(col1 >> IM_COL32_G_SHIFT) & 0xFF, t);
int b = ImLerp((int)(col0 >> IM_COL32_B_SHIFT) & 0xFF, (int)(col1 >> IM_COL32_B_SHIFT) & 0xFF, t); int b = ImLerp((int)(col0 >> IM_COL32_B_SHIFT) & 0xFF, (int)(col1 >> IM_COL32_B_SHIFT) & 0xFF, t);