Skip to content

Commit

Permalink
Replace operator&& with named function
Browse files Browse the repository at this point in the history
  • Loading branch information
ephphatha committed Jul 30, 2021
1 parent 9e29025 commit 47e930e
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 29 deletions.
2 changes: 1 addition & 1 deletion Source/DiabloUI/diabloui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -734,7 +734,7 @@ void Render(const UiArtText *uiArtText)
void Render(const UiImage *uiImage)
{
int x = uiImage->m_rect.x;
if ((uiImage->m_iFlags && UiFlags::UIS_CENTER) && uiImage->m_art != nullptr) {
if (HasAnyOf(uiImage->m_iFlags, UiFlags::UIS_CENTER) && uiImage->m_art != nullptr) {
const int xOffset = GetCenterOffset(uiImage->m_art->w(), uiImage->m_rect.w);
x += xOffset;
}
Expand Down
20 changes: 10 additions & 10 deletions Source/DiabloUI/text_draw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@ namespace {

TextAlignment XAlignmentFromFlags(UiFlags flags)
{
if (flags && UiFlags::UIS_CENTER)
if (HasAnyOf(flags, UiFlags::UIS_CENTER))
return TextAlignment_CENTER;
if (flags && UiFlags::UIS_RIGHT)
if (HasAnyOf(flags, UiFlags::UIS_RIGHT))
return TextAlignment_END;
return TextAlignment_BEGIN;
}

int AlignXOffset(UiFlags flags, const SDL_Rect &dest, int w)
{
if (flags && UiFlags::UIS_CENTER)
if (HasAnyOf(flags, UiFlags::UIS_CENTER))
return (dest.w - w) / 2;
if (flags && UiFlags::UIS_RIGHT)
if (HasAnyOf(flags, UiFlags::UIS_RIGHT))
return dest.w - w;
return 0;
}
Expand Down Expand Up @@ -54,7 +54,7 @@ void DrawTTF(const char *text, const SDL_Rect &rectIn, UiFlags flags,
SDL_Rect destRect = rect;
ScaleOutputRect(&destRect);
destRect.x += AlignXOffset(flags, destRect, textSurface->w);
destRect.y += (flags && UiFlags::UIS_VCENTER) ? (destRect.h - textSurface->h) / 2 : 0;
destRect.y += HasAnyOf(flags, UiFlags::UIS_VCENTER) ? (destRect.h - textSurface->h) / 2 : 0;

SDL_Rect shadowRect = destRect;
++shadowRect.x;
Expand All @@ -68,17 +68,17 @@ void DrawTTF(const char *text, const SDL_Rect &rectIn, UiFlags flags,
void DrawArtStr(const char *text, const SDL_Rect &rect, UiFlags flags, bool drawTextCursor)
{
_artFontTables size = AFT_SMALL;
_artFontColors color = (flags && UiFlags::UIS_GOLD) ? AFC_GOLD : AFC_SILVER;
_artFontColors color = HasAnyOf(flags, UiFlags::UIS_GOLD) ? AFC_GOLD : AFC_SILVER;

if (flags && UiFlags::UIS_MED)
if (HasAnyOf(flags, UiFlags::UIS_MED))
size = AFT_MED;
else if (flags && UiFlags::UIS_BIG)
else if (HasAnyOf(flags, UiFlags::UIS_BIG))
size = AFT_BIG;
else if (flags && UiFlags::UIS_HUGE)
else if (HasAnyOf(flags, UiFlags::UIS_HUGE))
size = AFT_HUGE;

const int x = rect.x + AlignXOffset(flags, rect, GetArtStrWidth(text, size));
const int y = rect.y + ((flags && UiFlags::UIS_VCENTER) ? (rect.h - ArtFonts[size][color].h()) / 2 : 0);
const int y = rect.y + (HasAnyOf(flags, UiFlags::UIS_VCENTER) ? (rect.h - ArtFonts[size][color].h()) / 2 : 0);

int sx = x;
int sy = y;
Expand Down
4 changes: 2 additions & 2 deletions Source/DiabloUI/ui_item.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ inline UiFlags operator~(UiFlags value)
return static_cast<UiFlags>(~static_cast<T>(value));
}

inline bool operator&&(UiFlags lhs, UiFlags test)
inline bool HasAnyOf(UiFlags lhs, UiFlags test)
{
return (lhs & test) != UiFlags::NONE;
}
Expand All @@ -96,7 +96,7 @@ class UiItemBase {

bool has_any_flag(UiFlags flags) const
{
return m_iFlags && flags;
return HasAnyOf(m_iFlags, flags);
}

void add_flag(UiFlags flag)
Expand Down
28 changes: 14 additions & 14 deletions Source/engine/render/text_render.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,36 +274,36 @@ void WordWrapGameString(char *text, size_t width, GameFontTables size, int spaci
uint16_t DrawString(const Surface &out, const char *text, const Rectangle &rect, UiFlags flags, int spacing, int lineHeight, bool drawTextCursor)
{
GameFontTables size = GameFontSmall;
if (flags && UiFlags::UIS_MED)
if (HasAnyOf(flags, UiFlags::UIS_MED))
size = GameFontMed;
else if (flags && UiFlags::UIS_HUGE)
else if (HasAnyOf(flags, UiFlags::UIS_HUGE))
size = GameFontBig;

text_color color = ColorGold;
if (flags && UiFlags::UIS_SILVER)
if (HasAnyOf(flags, UiFlags::UIS_SILVER))
color = ColorWhite;
else if (flags && UiFlags::UIS_BLUE)
else if (HasAnyOf(flags, UiFlags::UIS_BLUE))
color = ColorBlue;
else if (flags && UiFlags::UIS_RED)
else if (HasAnyOf(flags, UiFlags::UIS_RED))
color = ColorRed;
else if (flags && UiFlags::UIS_BLACK)
else if (HasAnyOf(flags, UiFlags::UIS_BLACK))
color = ColorBlack;

const size_t textLength = strlen(text);

int charactersInLine = 0;
int lineWidth = 0;
if (flags && (UiFlags::UIS_CENTER | UiFlags::UIS_RIGHT | UiFlags::UIS_FIT_SPACING))
if (HasAnyOf(flags, (UiFlags::UIS_CENTER | UiFlags::UIS_RIGHT | UiFlags::UIS_FIT_SPACING)))
lineWidth = GetLineWidth(text, size, spacing, &charactersInLine);

int maxSpacing = spacing;
if (flags && UiFlags::UIS_FIT_SPACING)
if (HasAnyOf(flags, UiFlags::UIS_FIT_SPACING))
spacing = AdjustSpacingToFitHorizontally(lineWidth, maxSpacing, charactersInLine, rect.size.width);

Point characterPosition = rect.position;
if (flags && UiFlags::UIS_CENTER)
if (HasAnyOf(flags, UiFlags::UIS_CENTER))
characterPosition.x += (rect.size.width - lineWidth) / 2;
else if (flags && UiFlags::UIS_RIGHT)
else if (HasAnyOf(flags, UiFlags::UIS_RIGHT))
characterPosition.x += rect.size.width - lineWidth;

int rightMargin = rect.position.x + rect.size.width;
Expand All @@ -321,16 +321,16 @@ uint16_t DrawString(const Surface &out, const char *text, const Rectangle &rect,
break;
characterPosition.y += lineHeight;

if (flags && (UiFlags::UIS_CENTER | UiFlags::UIS_RIGHT | UiFlags::UIS_FIT_SPACING))
if (HasAnyOf(flags, (UiFlags::UIS_CENTER | UiFlags::UIS_RIGHT | UiFlags::UIS_FIT_SPACING)))
lineWidth = GetLineWidth(&text[i + 1], size, spacing, &charactersInLine);

if (flags && UiFlags::UIS_FIT_SPACING)
if (HasAnyOf(flags, UiFlags::UIS_FIT_SPACING))
spacing = AdjustSpacingToFitHorizontally(lineWidth, maxSpacing, charactersInLine, rect.size.width);

characterPosition.x = rect.position.x;
if (flags && UiFlags::UIS_CENTER)
if (HasAnyOf(flags, UiFlags::UIS_CENTER))
characterPosition.x += (rect.size.width - lineWidth) / 2;
else if (flags && UiFlags::UIS_RIGHT)
else if (HasAnyOf(flags, UiFlags::UIS_RIGHT))
characterPosition.x += rect.size.width - lineWidth;
}
if (frame != 0) {
Expand Down
4 changes: 2 additions & 2 deletions Source/stores.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2166,13 +2166,13 @@ void DrawSelector(const Surface &out, const Rectangle &rect, const char *text, U
int lineWidth = GetLineWidth(text);

int x1 = rect.position.x - 20;
if (flags && UiFlags::UIS_CENTER)
if (HasAnyOf(flags, UiFlags::UIS_CENTER))
x1 += (rect.size.width - lineWidth) / 2;

CelDrawTo(out, { x1, rect.position.y + 1 }, *pSPentSpn2Cels, PentSpn2Spin());

int x2 = rect.position.x + rect.size.width + 5;
if (flags && UiFlags::UIS_CENTER)
if (HasAnyOf(flags, UiFlags::UIS_CENTER))
x2 = rect.position.x + (rect.size.width - lineWidth) / 2 + lineWidth + 5;

CelDrawTo(out, { x2, rect.position.y + 1 }, *pSPentSpn2Cels, PentSpn2Spin());
Expand Down

0 comments on commit 47e930e

Please sign in to comment.