Skip to content

Commit

Permalink
ImDrawList: Uses IM_COL32_A_MASK macro instead of hardcoded zero alph…
Browse files Browse the repository at this point in the history
…a testing (#844)
  • Loading branch information
ocornut committed Oct 7, 2016
1 parent 7995cab commit e07d457
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
2 changes: 2 additions & 0 deletions imgui.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 14 additions & 14 deletions imgui_draw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -809,15 +809,15 @@ 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);
}

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)
{
Expand All @@ -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;
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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);
Expand All @@ -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)
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit e07d457

Please sign in to comment.