ImDrawList: Uses IM_COL32_A_MASK macro instead of hardcoded zero alpha testing (#844)

This commit is contained in:
ocornut 2016-10-07 09:49:52 +02:00
parent 7995cabce5
commit e07d45709f
2 changed files with 16 additions and 14 deletions

View File

@ -1040,11 +1040,13 @@ struct ImGuiSizeConstraintCallbackData
#define IM_COL32_G_SHIFT 8
#define IM_COL32_B_SHIFT 0
#define IM_COL32_A_SHIFT 24
#define IM_COL32_A_MASK 0xFF000000
#else
#define IM_COL32_R_SHIFT 0
#define IM_COL32_G_SHIFT 8
#define IM_COL32_B_SHIFT 16
#define IM_COL32_A_SHIFT 24
#define IM_COL32_A_MASK 0xFF000000
#endif
#define IM_COL32(R,G,B,A) (((ImU32)(A)<<IM_COL32_A_SHIFT) | ((ImU32)(B)<<IM_COL32_B_SHIFT) | ((ImU32)(G)<<IM_COL32_G_SHIFT) | ((ImU32)(R)<<IM_COL32_R_SHIFT))
#define IM_COL32_WHITE IM_COL32(255,255,255,255) // Opaque white

View File

@ -799,7 +799,7 @@ void ImDrawList::PathRect(const ImVec2& a, const ImVec2& b, float rounding, int
void ImDrawList::AddLine(const ImVec2& a, const ImVec2& b, ImU32 col, float thickness)
{
if ((col >> 24) == 0)
if ((col & IM_COL32_A_MASK) == 0)
return;
PathLineTo(a + ImVec2(0.5f,0.5f));
PathLineTo(b + ImVec2(0.5f,0.5f));
@ -809,7 +809,7 @@ void ImDrawList::AddLine(const ImVec2& a, const ImVec2& b, ImU32 col, float thic
// a: upper-left, b: lower-right. we don't render 1 px sized rectangles properly.
void ImDrawList::AddRect(const ImVec2& a, const ImVec2& b, ImU32 col, float rounding, int rounding_corners, float thickness)
{
if ((col >> 24) == 0)
if ((col & IM_COL32_A_MASK) == 0)
return;
PathRect(a + ImVec2(0.5f,0.5f), b - ImVec2(0.5f,0.5f), rounding, rounding_corners);
PathStroke(col, true, thickness);
@ -817,7 +817,7 @@ void ImDrawList::AddRect(const ImVec2& a, const ImVec2& b, ImU32 col, float roun
void ImDrawList::AddRectFilled(const ImVec2& a, const ImVec2& b, ImU32 col, float rounding, int rounding_corners)
{
if ((col >> 24) == 0)
if ((col & IM_COL32_A_MASK) == 0)
return;
if (rounding > 0.0f)
{
@ -833,7 +833,7 @@ void ImDrawList::AddRectFilled(const ImVec2& a, const ImVec2& b, ImU32 col, floa
void ImDrawList::AddRectFilledMultiColor(const ImVec2& a, const ImVec2& c, ImU32 col_upr_left, ImU32 col_upr_right, ImU32 col_bot_right, ImU32 col_bot_left)
{
if (((col_upr_left | col_upr_right | col_bot_right | col_bot_left) >> 24) == 0)
if (((col_upr_left | col_upr_right | col_bot_right | col_bot_left) & IM_COL32_A_MASK) == 0)
return;
const ImVec2 uv = GImGui->FontTexUvWhitePixel;
@ -848,7 +848,7 @@ void ImDrawList::AddRectFilledMultiColor(const ImVec2& a, const ImVec2& c, ImU32
void ImDrawList::AddQuad(const ImVec2& a, const ImVec2& b, const ImVec2& c, const ImVec2& d, ImU32 col, float thickness)
{
if ((col >> 24) == 0)
if ((col & IM_COL32_A_MASK) == 0)
return;
PathLineTo(a);
@ -860,7 +860,7 @@ void ImDrawList::AddQuad(const ImVec2& a, const ImVec2& b, const ImVec2& c, cons
void ImDrawList::AddQuadFilled(const ImVec2& a, const ImVec2& b, const ImVec2& c, const ImVec2& d, ImU32 col)
{
if ((col >> 24) == 0)
if ((col & IM_COL32_A_MASK) == 0)
return;
PathLineTo(a);
@ -872,7 +872,7 @@ void ImDrawList::AddQuadFilled(const ImVec2& a, const ImVec2& b, const ImVec2& c
void ImDrawList::AddTriangle(const ImVec2& a, const ImVec2& b, const ImVec2& c, ImU32 col, float thickness)
{
if ((col >> 24) == 0)
if ((col & IM_COL32_A_MASK) == 0)
return;
PathLineTo(a);
@ -883,7 +883,7 @@ void ImDrawList::AddTriangle(const ImVec2& a, const ImVec2& b, const ImVec2& c,
void ImDrawList::AddTriangleFilled(const ImVec2& a, const ImVec2& b, const ImVec2& c, ImU32 col)
{
if ((col >> 24) == 0)
if ((col & IM_COL32_A_MASK) == 0)
return;
PathLineTo(a);
@ -894,7 +894,7 @@ void ImDrawList::AddTriangleFilled(const ImVec2& a, const ImVec2& b, const ImVec
void ImDrawList::AddCircle(const ImVec2& centre, float radius, ImU32 col, int num_segments, float thickness)
{
if ((col >> 24) == 0)
if ((col & IM_COL32_A_MASK) == 0)
return;
const float a_max = IM_PI*2.0f * ((float)num_segments - 1.0f) / (float)num_segments;
@ -904,7 +904,7 @@ void ImDrawList::AddCircle(const ImVec2& centre, float radius, ImU32 col, int nu
void ImDrawList::AddCircleFilled(const ImVec2& centre, float radius, ImU32 col, int num_segments)
{
if ((col >> 24) == 0)
if ((col & IM_COL32_A_MASK) == 0)
return;
const float a_max = IM_PI*2.0f * ((float)num_segments - 1.0f) / (float)num_segments;
@ -914,7 +914,7 @@ void ImDrawList::AddCircleFilled(const ImVec2& centre, float radius, ImU32 col,
void ImDrawList::AddBezierCurve(const ImVec2& pos0, const ImVec2& cp0, const ImVec2& cp1, const ImVec2& pos1, ImU32 col, float thickness, int num_segments)
{
if ((col >> 24) == 0)
if ((col & IM_COL32_A_MASK) == 0)
return;
PathLineTo(pos0);
@ -924,7 +924,7 @@ void ImDrawList::AddBezierCurve(const ImVec2& pos0, const ImVec2& cp0, const ImV
void ImDrawList::AddText(const ImFont* font, float font_size, const ImVec2& pos, ImU32 col, const char* text_begin, const char* text_end, float wrap_width, const ImVec4* cpu_fine_clip_rect)
{
if ((col >> 24) == 0)
if ((col & IM_COL32_A_MASK) == 0)
return;
if (text_end == NULL)
@ -959,7 +959,7 @@ void ImDrawList::AddText(const ImVec2& pos, ImU32 col, const char* text_begin, c
void ImDrawList::AddImage(ImTextureID user_texture_id, const ImVec2& a, const ImVec2& b, const ImVec2& uv0, const ImVec2& uv1, ImU32 col)
{
if ((col >> 24) == 0)
if ((col & IM_COL32_A_MASK) == 0)
return;
// FIXME-OPT: This is wasting draw calls.
@ -1169,7 +1169,7 @@ static void Decode85(const unsigned char* src, unsigned char* dst)
while (*src)
{
unsigned int tmp = Decode85Byte(src[0]) + 85*(Decode85Byte(src[1]) + 85*(Decode85Byte(src[2]) + 85*(Decode85Byte(src[3]) + 85*Decode85Byte(src[4]))));
dst[0] = ((tmp >> 0) & 0xFF); dst[1] = ((tmp >> 8) & 0xFF); dst[2] = ((tmp >> 16) & 0xFF); dst[3] = ((tmp >> 24) & 0xFF); // We can't assume little-endianess.
dst[0] = ((tmp >> 0) & 0xFF); dst[1] = ((tmp >> 8) & 0xFF); dst[2] = ((tmp >> 16) & 0xFF); dst[3] = ((tmp >> 24) & 0xFF); // We can't assume little-endianness.
src += 5;
dst += 4;
}