diff --git a/Source/qol/itemlabels.cpp b/Source/qol/itemlabels.cpp index c6f4d4dbc..7a485129e 100644 --- a/Source/qol/itemlabels.cpp +++ b/Source/qol/itemlabels.cpp @@ -38,11 +38,16 @@ bool highlightKeyPressed = false; bool isLabelHighlighted = false; std::array, ITEMTYPES> labelCenterOffsets; -const int BorderX = 4; // minimal horizontal space between labels -const int BorderY = 2; // minimal vertical space between labels -const int MarginX = 2; // horizontal margins between text and edges of the label -const int MarginY = 1; // vertical margins between text and edges of the label -const int Height = 11 + MarginY * 2; // going above 13 scatters labels of items that are next to each other +const int BorderX = 4; // minimal horizontal space between labels +const int BorderY = 2; // minimal vertical space between labels +const int MarginX = 2; // horizontal margins between text and edges of the label + +// Vertical space between the text and the edges of the label. +int TextMarginTop() { return IsSmallFontTall() ? 1 : -1; } +int TextMarginBottom() { return IsSmallFontTall() ? 1 : 3; } + +// The total height of the label box. +int LabelHeight() { return (IsSmallFontTall() ? 16 : 11) + TextMarginBottom() + TextMarginTop(); } /** * @brief The set of used X coordinates for a certain Y coordinate. @@ -123,7 +128,7 @@ void AddItemToLabelQueue(int id, Point position) position *= 2; } position.x -= nameWidth / 2; - position.y -= Height; + position.y -= LabelHeight(); labelQueue.push_back(ItemLabel { id, nameWidth, position, std::move(textOnGround) }); } @@ -146,6 +151,8 @@ void DrawItemNameLabels(const Surface &out) if (labelQueue.empty()) return; UsedX usedX; + const int labelHeight = LabelHeight(); + const int labelMarginTop = TextMarginTop(); for (unsigned i = 0; i < labelQueue.size(); ++i) { usedX.clear(); @@ -156,7 +163,7 @@ void DrawItemNameLabels(const Surface &out) for (unsigned j = 0; j < i; ++j) { ItemLabel &a = labelQueue[i]; ItemLabel &b = labelQueue[j]; - if (std::abs(b.pos.y - a.pos.y) < Height + BorderY) { + if (std::abs(b.pos.y - a.pos.y) < labelHeight + BorderY) { const int widthA = a.width + BorderX + MarginX * 2; const int widthB = b.width + BorderX + MarginX * 2; int newpos = b.pos.x; @@ -181,7 +188,8 @@ void DrawItemNameLabels(const Surface &out) for (const ItemLabel &label : labelQueue) { Item &item = Items[label.id]; - if (MousePosition.x >= label.pos.x && MousePosition.x < label.pos.x + label.width && MousePosition.y >= label.pos.y + MarginY && MousePosition.y < label.pos.y + MarginY + Height) { + if (MousePosition.x >= label.pos.x && MousePosition.x < label.pos.x + label.width + && MousePosition.y >= label.pos.y && MousePosition.y < label.pos.y + labelHeight) { if (!gmenu_is_active() && PauseMode == 0 && !MyPlayerIsDead @@ -194,10 +202,10 @@ void DrawItemNameLabels(const Surface &out) } } if (pcursitem == label.id && stextflag == TalkID::None) - FillRect(clippedOut, label.pos.x, label.pos.y + MarginY, label.width, Height, PAL8_BLUE + 6); + FillRect(clippedOut, label.pos.x, label.pos.y, label.width, labelHeight, PAL8_BLUE + 6); else - DrawHalfTransparentRectTo(clippedOut, label.pos.x, label.pos.y + MarginY, label.width, Height); - DrawString(clippedOut, label.text, { { label.pos.x + MarginX, label.pos.y }, { label.width, Height } }, + DrawHalfTransparentRectTo(clippedOut, label.pos.x, label.pos.y, label.width, labelHeight); + DrawString(clippedOut, label.text, { { label.pos.x + MarginX, label.pos.y + labelMarginTop }, { label.width, labelHeight } }, { .flags = item.getTextColor() }); } labelQueue.clear();