diff --git a/Source/.clang-format b/Source/.clang-format index 2403752f3a8..d30f4466e5e 100644 --- a/Source/.clang-format +++ b/Source/.clang-format @@ -1,7 +1,8 @@ BasedOnStyle: webkit AlignTrailingComments: true AllowShortBlocksOnASingleLine: true -AllowShortFunctionsOnASingleLine: None +AllowShortFunctionsOnASingleLine: All +AllowShortIfStatementsOnASingleLine: WithoutElse PointerAlignment: Right TabWidth: 4 UseTab: ForIndentation diff --git a/Source/control.cpp b/Source/control.cpp index 9a40e7f3a61..0a0beaba9c5 100644 --- a/Source/control.cpp +++ b/Source/control.cpp @@ -255,7 +255,7 @@ void PrintInfo(const Surface &out) return; const int space[] = { 18, 12, 6, 3, 0 }; - Rectangle infoArea { GetMainPanel().position + Displacement { 177, 46 }, { 288, 60 } }; + Rectangle infoArea { GetMainPanel().position + InfoBoxTopLeft, InfoBoxSize }; const int newLineCount = std::count(InfoString.str().begin(), InfoString.str().end(), '\n'); const int spaceIndex = std::min(4, newLineCount); @@ -1161,7 +1161,7 @@ void FreeControlPan() void DrawInfoBox(const Surface &out) { - DrawPanelBox(out, { 177, 62, 288, 63 }, GetMainPanel().position + Displacement { 177, 46 }); + DrawPanelBox(out, { 177, 62, InfoBoxSize.width, InfoBoxSize.height }, GetMainPanel().position + InfoBoxTopLeft); if (!panelflag && !trigflag && pcursinvitem == -1 && pcursstashitem == StashStruct::EmptyCell && !spselflag) { InfoString = {}; InfoColor = UiFlags::ColorWhite; diff --git a/Source/control.h b/Source/control.h index eae004760f7..08f6f264c26 100644 --- a/Source/control.h +++ b/Source/control.h @@ -16,9 +16,11 @@ #include "DiabloUI/ui_flags.hpp" #include "engine.h" +#include "engine/displacement.hpp" #include "engine/point.hpp" #include "engine/rectangle.hpp" #include "engine/render/text_render.hpp" +#include "engine/size.hpp" #include "panels/ui_panels.hpp" #include "spelldat.h" #include "spells.h" @@ -32,6 +34,10 @@ namespace devilution { constexpr Size SidePanelSize { 320, 352 }; +// Info box displacement of the top-left corner relative to GetMainPanel().position. +constexpr Displacement InfoBoxTopLeft { 177, 46 }; +constexpr Size InfoBoxSize { 288, 64 }; + extern bool dropGoldFlag; extern bool chrbtn[4]; extern bool lvlbtndown; diff --git a/Source/engine/render/scrollrt.cpp b/Source/engine/render/scrollrt.cpp index 847b90696ce..758bc46ca38 100644 --- a/Source/engine/render/scrollrt.cpp +++ b/Source/engine/render/scrollrt.cpp @@ -1343,7 +1343,8 @@ void DrawMain(const Surface &out, int dwHgt, bool drawDesc, bool drawHp, bool dr // When chat input is displayed, the belt is hidden and the chat moves up. DoBlitScreen(mainPanelPosition.x + 171, mainPanelPosition.y + 6, 298, 116); } else { - DoBlitScreen(mainPanelPosition.x + 176, mainPanelPosition.y + 46, 288, 63); + DoBlitScreen(mainPanelPosition.x + InfoBoxTopLeft.deltaX, mainPanelPosition.y + InfoBoxTopLeft.deltaY, + InfoBoxSize.width, InfoBoxSize.height); } } if (drawMana) { diff --git a/Source/qol/itemlabels.cpp b/Source/qol/itemlabels.cpp index b409eab5151..100fca48482 100644 --- a/Source/qol/itemlabels.cpp +++ b/Source/qol/itemlabels.cpp @@ -36,11 +36,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. @@ -121,7 +126,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) }); } @@ -151,6 +156,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(); @@ -161,7 +168,7 @@ void DrawItemNameLabels(const Surface &out) for (unsigned j = 0; j < i; ++j) { ItemLabel &a = labelQueue[i]; ItemLabel &b = labelQueue[j]; - if (abs(b.pos.y - a.pos.y) < Height + BorderY) { + if (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; @@ -186,7 +193,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 @@ -199,10 +207,11 @@ 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 } }, item.getTextColor()); + 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 } }, + item.getTextColor()); } labelQueue.clear(); } diff --git a/test/.clang-format b/test/.clang-format index 2403752f3a8..d30f4466e5e 100644 --- a/test/.clang-format +++ b/test/.clang-format @@ -1,7 +1,8 @@ BasedOnStyle: webkit AlignTrailingComments: true AllowShortBlocksOnASingleLine: true -AllowShortFunctionsOnASingleLine: None +AllowShortFunctionsOnASingleLine: All +AllowShortIfStatementsOnASingleLine: WithoutElse PointerAlignment: Right TabWidth: 4 UseTab: ForIndentation