Skip to content

Commit e07d457

Browse files
committed
ImDrawList: Uses IM_COL32_A_MASK macro instead of hardcoded zero alpha testing (ocornut#844)
1 parent 7995cab commit e07d457

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

imgui.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1040,11 +1040,13 @@ struct ImGuiSizeConstraintCallbackData
10401040
#define IM_COL32_G_SHIFT 8
10411041
#define IM_COL32_B_SHIFT 0
10421042
#define IM_COL32_A_SHIFT 24
1043+
#define IM_COL32_A_MASK 0xFF000000
10431044
#else
10441045
#define IM_COL32_R_SHIFT 0
10451046
#define IM_COL32_G_SHIFT 8
10461047
#define IM_COL32_B_SHIFT 16
10471048
#define IM_COL32_A_SHIFT 24
1049+
#define IM_COL32_A_MASK 0xFF000000
10481050
#endif
10491051
#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))
10501052
#define IM_COL32_WHITE IM_COL32(255,255,255,255) // Opaque white

imgui_draw.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -799,7 +799,7 @@ void ImDrawList::PathRect(const ImVec2& a, const ImVec2& b, float rounding, int
799799

800800
void ImDrawList::AddLine(const ImVec2& a, const ImVec2& b, ImU32 col, float thickness)
801801
{
802-
if ((col >> 24) == 0)
802+
if ((col & IM_COL32_A_MASK) == 0)
803803
return;
804804
PathLineTo(a + ImVec2(0.5f,0.5f));
805805
PathLineTo(b + ImVec2(0.5f,0.5f));
@@ -809,15 +809,15 @@ void ImDrawList::AddLine(const ImVec2& a, const ImVec2& b, ImU32 col, float thic
809809
// a: upper-left, b: lower-right. we don't render 1 px sized rectangles properly.
810810
void ImDrawList::AddRect(const ImVec2& a, const ImVec2& b, ImU32 col, float rounding, int rounding_corners, float thickness)
811811
{
812-
if ((col >> 24) == 0)
812+
if ((col & IM_COL32_A_MASK) == 0)
813813
return;
814814
PathRect(a + ImVec2(0.5f,0.5f), b - ImVec2(0.5f,0.5f), rounding, rounding_corners);
815815
PathStroke(col, true, thickness);
816816
}
817817

818818
void ImDrawList::AddRectFilled(const ImVec2& a, const ImVec2& b, ImU32 col, float rounding, int rounding_corners)
819819
{
820-
if ((col >> 24) == 0)
820+
if ((col & IM_COL32_A_MASK) == 0)
821821
return;
822822
if (rounding > 0.0f)
823823
{
@@ -833,7 +833,7 @@ void ImDrawList::AddRectFilled(const ImVec2& a, const ImVec2& b, ImU32 col, floa
833833

834834
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)
835835
{
836-
if (((col_upr_left | col_upr_right | col_bot_right | col_bot_left) >> 24) == 0)
836+
if (((col_upr_left | col_upr_right | col_bot_right | col_bot_left) & IM_COL32_A_MASK) == 0)
837837
return;
838838

839839
const ImVec2 uv = GImGui->FontTexUvWhitePixel;
@@ -848,7 +848,7 @@ void ImDrawList::AddRectFilledMultiColor(const ImVec2& a, const ImVec2& c, ImU32
848848

849849
void ImDrawList::AddQuad(const ImVec2& a, const ImVec2& b, const ImVec2& c, const ImVec2& d, ImU32 col, float thickness)
850850
{
851-
if ((col >> 24) == 0)
851+
if ((col & IM_COL32_A_MASK) == 0)
852852
return;
853853

854854
PathLineTo(a);
@@ -860,7 +860,7 @@ void ImDrawList::AddQuad(const ImVec2& a, const ImVec2& b, const ImVec2& c, cons
860860

861861
void ImDrawList::AddQuadFilled(const ImVec2& a, const ImVec2& b, const ImVec2& c, const ImVec2& d, ImU32 col)
862862
{
863-
if ((col >> 24) == 0)
863+
if ((col & IM_COL32_A_MASK) == 0)
864864
return;
865865

866866
PathLineTo(a);
@@ -872,7 +872,7 @@ void ImDrawList::AddQuadFilled(const ImVec2& a, const ImVec2& b, const ImVec2& c
872872

873873
void ImDrawList::AddTriangle(const ImVec2& a, const ImVec2& b, const ImVec2& c, ImU32 col, float thickness)
874874
{
875-
if ((col >> 24) == 0)
875+
if ((col & IM_COL32_A_MASK) == 0)
876876
return;
877877

878878
PathLineTo(a);
@@ -883,7 +883,7 @@ void ImDrawList::AddTriangle(const ImVec2& a, const ImVec2& b, const ImVec2& c,
883883

884884
void ImDrawList::AddTriangleFilled(const ImVec2& a, const ImVec2& b, const ImVec2& c, ImU32 col)
885885
{
886-
if ((col >> 24) == 0)
886+
if ((col & IM_COL32_A_MASK) == 0)
887887
return;
888888

889889
PathLineTo(a);
@@ -894,7 +894,7 @@ void ImDrawList::AddTriangleFilled(const ImVec2& a, const ImVec2& b, const ImVec
894894

895895
void ImDrawList::AddCircle(const ImVec2& centre, float radius, ImU32 col, int num_segments, float thickness)
896896
{
897-
if ((col >> 24) == 0)
897+
if ((col & IM_COL32_A_MASK) == 0)
898898
return;
899899

900900
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
904904

905905
void ImDrawList::AddCircleFilled(const ImVec2& centre, float radius, ImU32 col, int num_segments)
906906
{
907-
if ((col >> 24) == 0)
907+
if ((col & IM_COL32_A_MASK) == 0)
908908
return;
909909

910910
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,
914914

915915
void ImDrawList::AddBezierCurve(const ImVec2& pos0, const ImVec2& cp0, const ImVec2& cp1, const ImVec2& pos1, ImU32 col, float thickness, int num_segments)
916916
{
917-
if ((col >> 24) == 0)
917+
if ((col & IM_COL32_A_MASK) == 0)
918918
return;
919919

920920
PathLineTo(pos0);
@@ -924,7 +924,7 @@ void ImDrawList::AddBezierCurve(const ImVec2& pos0, const ImVec2& cp0, const ImV
924924

925925
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)
926926
{
927-
if ((col >> 24) == 0)
927+
if ((col & IM_COL32_A_MASK) == 0)
928928
return;
929929

930930
if (text_end == NULL)
@@ -959,7 +959,7 @@ void ImDrawList::AddText(const ImVec2& pos, ImU32 col, const char* text_begin, c
959959

960960
void ImDrawList::AddImage(ImTextureID user_texture_id, const ImVec2& a, const ImVec2& b, const ImVec2& uv0, const ImVec2& uv1, ImU32 col)
961961
{
962-
if ((col >> 24) == 0)
962+
if ((col & IM_COL32_A_MASK) == 0)
963963
return;
964964

965965
// FIXME-OPT: This is wasting draw calls.
@@ -1169,7 +1169,7 @@ static void Decode85(const unsigned char* src, unsigned char* dst)
11691169
while (*src)
11701170
{
11711171
unsigned int tmp = Decode85Byte(src[0]) + 85*(Decode85Byte(src[1]) + 85*(Decode85Byte(src[2]) + 85*(Decode85Byte(src[3]) + 85*Decode85Byte(src[4]))));
1172-
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.
1172+
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.
11731173
src += 5;
11741174
dst += 4;
11751175
}

0 commit comments

Comments
 (0)