Browse Source

Remove PANEL_ defines and replace them with GetMainPanel()

pull/4615/head
obligaron 4 years ago committed by Anders Jenbo
parent
commit
bc15bdf3a9
  1. 6
      Source/automap.cpp
  2. 94
      Source/control.cpp
  3. 10
      Source/control.h
  4. 10
      Source/controls/modifier_hints.cpp
  5. 7
      Source/cursor.cpp
  6. 10
      Source/diablo.cpp
  7. 8
      Source/inv.cpp
  8. 4
      Source/panels/mainpanel.cpp
  9. 32
      Source/panels/spell_list.cpp
  10. 2
      Source/plrmsg.cpp
  11. 8
      Source/qol/xpbar.cpp
  12. 32
      Source/scrollrt.cpp
  13. 4
      test/scrollrt_test.cpp

6
Source/automap.cpp

@ -370,7 +370,7 @@ void SearchAutomapItem(const Surface &out, const Displacement &myPlayerOffset)
Point screen = {
(myPlayerOffset.deltaX * AutoMapScale / 100 / 2) + (px - py) * AmLine16 + gnScreenWidth / 2,
(myPlayerOffset.deltaY * AutoMapScale / 100 / 2) + (px + py) * AmLine8 + (gnScreenHeight - PANEL_HEIGHT) / 2
(myPlayerOffset.deltaY * AutoMapScale / 100 / 2) + (px + py) * AmLine8 + (gnScreenHeight - GetMainPanel().size.height) / 2
};
if (CanPanelsCoverView()) {
@ -407,7 +407,7 @@ void DrawAutomapPlr(const Surface &out, const Displacement &myPlayerOffset, int
Point base = {
((playerOffset.deltaX + myPlayerOffset.deltaX) * AutoMapScale / 100 / 2) + (px - py) * AmLine16 + gnScreenWidth / 2,
((playerOffset.deltaY + myPlayerOffset.deltaY) * AutoMapScale / 100 / 2) + (px + py) * AmLine8 + (gnScreenHeight - PANEL_HEIGHT) / 2
((playerOffset.deltaY + myPlayerOffset.deltaY) * AutoMapScale / 100 / 2) + (px + py) * AmLine8 + (gnScreenHeight - GetMainPanel().size.height) / 2
};
if (CanPanelsCoverView()) {
@ -681,7 +681,7 @@ void DrawAutomap(const Surface &out)
Point screen {
gnScreenWidth / 2,
(gnScreenHeight - PANEL_HEIGHT) / 2
(gnScreenHeight - GetMainPanel().size.height) / 2
};
if ((cells & 1) != 0) {
screen.x -= AmLine64 * ((cells - 1) / 2);

94
Source/control.cpp

@ -218,10 +218,10 @@ void DrawFlaskUpper(const Surface &out, const Surface &sourceBuffer, int offset,
int emptyPortion = clamp(80 - fillPer, 0, 11) + 2; // +2 to account for the frame being included in the sprite
// Draw the empty part of the flask
DrawFlask(out, sourceBuffer, { 13, 3 }, { PANEL_LEFT + offset, PANEL_TOP - 13 }, emptyPortion);
DrawFlask(out, sourceBuffer, { 13, 3 }, GetMainPanel().position + Displacement { offset, -13 }, emptyPortion);
if (emptyPortion < 13)
// Draw the filled part of the flask
DrawFlask(out, *pBtmBuff, { offset, emptyPortion + 3 }, { PANEL_LEFT + offset, PANEL_TOP - 13 + emptyPortion }, 13 - emptyPortion);
DrawFlask(out, *pBtmBuff, { offset, emptyPortion + 3 }, GetMainPanel().position + Displacement { offset, -13 + emptyPortion }, 13 - emptyPortion);
}
/**
@ -237,12 +237,12 @@ void DrawFlaskLower(const Surface &out, const Surface &sourceBuffer, int offset,
int filled = clamp(fillPer, 0, 69);
if (filled < 69)
DrawFlaskTop(out, { PANEL_X + offset, PANEL_Y }, sourceBuffer, 16, 85 - filled);
DrawFlaskTop(out, GetMainPanel().position + Displacement { offset, 0 }, sourceBuffer, 16, 85 - filled);
// It appears that the panel defaults to having a filled flask and DrawFlaskTop only overlays the appropriate amount of empty space.
// This draw might not be necessary?
if (filled > 0)
DrawPanelBox(out, MakeSdlRect(offset, 85 - filled, 88, filled), { PANEL_X + offset, PANEL_Y + 69 - filled });
DrawPanelBox(out, MakeSdlRect(offset, 85 - filled, 88, filled), GetMainPanel().position + Displacement { offset, 69 - filled });
}
void SetButtonStateDown(int btnId)
@ -260,7 +260,7 @@ void PrintInfo(const Surface &out)
const int LineStart[] = { 70, 58, 52, 48, 46 };
const int LineHeights[] = { 30, 24, 18, 15, 12 };
Rectangle line { { PANEL_X + 177, PANEL_Y + LineStart[pnumlines] }, { 288, 12 } };
Rectangle line { GetMainPanel().position + Displacement { 177, LineStart[pnumlines] }, { 288, 12 } };
if (!InfoString.empty()) {
DrawString(out, InfoString, line, InfoColor | UiFlags::AlignCenter | UiFlags::KerningFitSpacing, 2);
@ -311,7 +311,7 @@ int DrawDurIcon4Item(const Surface &out, Item &pItem, int x, int c)
}
if (pItem._iDurability > 2)
c += 8;
CelDrawTo(out, { x, -17 + PANEL_Y }, *pDurIcons, c);
CelDrawTo(out, { x, -17 + GetMainPanel().position.y }, *pDurIcons, c);
return x - 32 - 8;
}
@ -408,9 +408,12 @@ bool IsLevelUpButtonVisible()
void CalculatePanelAreas()
{
constexpr uint16_t PanelWidth = 640;
constexpr uint16_t PanelHeight = 128;
MainPanel = {
{ (gnScreenWidth - PANEL_WIDTH) / 2, gnScreenHeight - PANEL_HEIGHT },
{ PANEL_WIDTH, PANEL_HEIGHT }
{ (gnScreenWidth - PanelWidth) / 2, gnScreenHeight - PanelHeight },
{ PanelWidth, PanelHeight }
};
LeftPanel = {
{ 0, 0 },
@ -424,11 +427,11 @@ void CalculatePanelAreas()
if (ControlMode == ControlTypes::VirtualGamepad) {
LeftPanel.position.x = gnScreenWidth / 2 - LeftPanel.size.width;
} else {
if (gnScreenWidth - LeftPanel.size.width - RightPanel.size.width > PANEL_WIDTH) {
LeftPanel.position.x = (gnScreenWidth - LeftPanel.size.width - RightPanel.size.width - PANEL_WIDTH) / 2;
if (gnScreenWidth - LeftPanel.size.width - RightPanel.size.width > MainPanel.size.width) {
LeftPanel.position.x = (gnScreenWidth - LeftPanel.size.width - RightPanel.size.width - MainPanel.size.width) / 2;
}
}
LeftPanel.position.y = (gnScreenHeight - LeftPanel.size.height - PANEL_HEIGHT) / 2;
LeftPanel.position.y = (gnScreenHeight - LeftPanel.size.height - MainPanel.size.height) / 2;
if (ControlMode == ControlTypes::VirtualGamepad) {
RightPanel.position.x = gnScreenWidth / 2;
@ -438,9 +441,9 @@ void CalculatePanelAreas()
RightPanel.position.y = LeftPanel.position.y;
gnViewportHeight = gnScreenHeight;
if (gnScreenWidth <= PANEL_WIDTH) {
if (gnScreenWidth <= MainPanel.size.width) {
// Part of the screen is fully obscured by the UI
gnViewportHeight -= PANEL_HEIGHT;
gnViewportHeight -= MainPanel.size.height;
}
}
@ -537,13 +540,13 @@ void control_update_life_mana()
void InitControlPan()
{
pBtmBuff.emplace(PANEL_WIDTH, (PANEL_HEIGHT + 16) * (IsChatAvailable() ? 2 : 1));
pBtmBuff.emplace(GetMainPanel().size.width, (GetMainPanel().size.height + 16) * (IsChatAvailable() ? 2 : 1));
pManaBuff.emplace(88, 88);
pLifeBuff.emplace(88, 88);
LoadCharPanel();
LoadSpellIcons();
CelDrawUnsafeTo(*pBtmBuff, { 0, (PANEL_HEIGHT + 16) - 1 }, LoadCel("CtrlPan\\Panel8.CEL", PANEL_WIDTH), 0);
CelDrawUnsafeTo(*pBtmBuff, { 0, (GetMainPanel().size.height + 16) - 1 }, LoadCel("CtrlPan\\Panel8.CEL", GetMainPanel().size.width), 0);
{
const Point bulbsPosition { 0, 87 };
const OwnedCelSprite statusPanel = LoadCel("CtrlPan\\P8Bulbs.CEL", 88);
@ -552,7 +555,7 @@ void InitControlPan()
}
talkflag = false;
if (IsChatAvailable()) {
CelDrawUnsafeTo(*pBtmBuff, { 0, (PANEL_HEIGHT + 16) * 2 - 1 }, LoadCel("CtrlPan\\TalkPanl.CEL", PANEL_WIDTH), 0);
CelDrawUnsafeTo(*pBtmBuff, { 0, (GetMainPanel().size.height + 16) * 2 - 1 }, LoadCel("CtrlPan\\TalkPanl.CEL", GetMainPanel().size.width), 0);
multiButtons = LoadCel("CtrlPan\\P8But2.CEL", 33);
talkButtons = LoadCel("CtrlPan\\TalkButt.CEL", 61);
sgbPlrTalkTbl = 0;
@ -600,28 +603,29 @@ void InitControlPan()
void DrawCtrlPan(const Surface &out)
{
DrawPanelBox(out, MakeSdlRect(0, sgbPlrTalkTbl + 16, PANEL_WIDTH, PANEL_HEIGHT), { PANEL_X, PANEL_Y });
DrawPanelBox(out, MakeSdlRect(0, sgbPlrTalkTbl + 16, GetMainPanel().size.width, GetMainPanel().size.height), GetMainPanel().position);
DrawInfoBox(out);
}
void DrawCtrlBtns(const Surface &out)
{
const Point mainPanelPosition = GetMainPanel().position;
for (int i = 0; i < 6; i++) {
if (!PanelButtons[i]) {
DrawPanelBox(out, MakeSdlRect(PanBtnPos[i].x, PanBtnPos[i].y + 16, 71, 20), { PanBtnPos[i].x + PANEL_X, PanBtnPos[i].y + PANEL_Y });
DrawPanelBox(out, MakeSdlRect(PanBtnPos[i].x, PanBtnPos[i].y + 16, 71, 20), mainPanelPosition + Displacement { PanBtnPos[i].x, PanBtnPos[i].y });
} else {
Point position { PanBtnPos[i].x + PANEL_X, PanBtnPos[i].y + PANEL_Y + 18 };
Point position = mainPanelPosition + Displacement { PanBtnPos[i].x, PanBtnPos[i].y + 18 };
CelDrawTo(out, position, *pPanelButtons, i);
DrawArt(out, position + Displacement { 4, -18 }, &PanelButtonDown, i);
}
}
if (PanelButtonIndex == 8) {
CelDrawTo(out, { 87 + PANEL_X, 122 + PANEL_Y }, *multiButtons, PanelButtons[6] ? 1 : 0);
CelDrawTo(out, mainPanelPosition + Displacement { 87, 122 }, *multiButtons, PanelButtons[6] ? 1 : 0);
auto &myPlayer = Players[MyPlayerId];
if (myPlayer.friendlyMode)
CelDrawTo(out, { 527 + PANEL_X, 122 + PANEL_Y }, *multiButtons, PanelButtons[7] ? 3 : 2);
CelDrawTo(out, mainPanelPosition + Displacement { 527, 122 }, *multiButtons, PanelButtons[7] ? 3 : 2);
else
CelDrawTo(out, { 527 + PANEL_X, 122 + PANEL_Y }, *multiButtons, PanelButtons[7] ? 5 : 4);
CelDrawTo(out, mainPanelPosition + Displacement { 527, 122 }, *multiButtons, PanelButtons[7] ? 5 : 4);
}
}
@ -635,7 +639,7 @@ void ClearPanBtn()
void DoPanBtn()
{
auto &mainPanelPosition = GetMainPanel().position;
const Point mainPanelPosition = GetMainPanel().position;
for (int i = 0; i < PanelButtonIndex; i++) {
int x = PanBtnPos[i].x + mainPanelPosition.x + PanBtnPos[i].w;
@ -663,7 +667,7 @@ void DoPanBtn()
void control_check_btn_press()
{
auto &mainPanelPosition = GetMainPanel().position;
const Point mainPanelPosition = GetMainPanel().position;
int x = PanBtnPos[3].x + mainPanelPosition.x + PanBtnPos[3].w;
int y = PanBtnPos[3].y + mainPanelPosition.y + PanBtnPos[3].h;
if (MousePosition.x >= PanBtnPos[3].x + mainPanelPosition.x
@ -697,7 +701,7 @@ void DoAutoMap()
void CheckPanelInfo()
{
panelflag = false;
auto &mainPanelPosition = GetMainPanel().position;
const Point mainPanelPosition = GetMainPanel().position;
ClearPanel();
for (int i = 0; i < PanelButtonIndex; i++) {
int xend = PanBtnPos[i].x + mainPanelPosition.x + PanBtnPos[i].w;
@ -764,7 +768,7 @@ void CheckPanelInfo()
void CheckBtnUp()
{
bool gamemenuOff = true;
auto &mainPanelPosition = GetMainPanel().position;
const Point mainPanelPosition = GetMainPanel().position;
drawbtnflag = true;
panbtndown = false;
@ -863,7 +867,7 @@ void FreeControlPan()
void DrawInfoBox(const Surface &out)
{
DrawPanelBox(out, { 177, 62, 288, 63 }, { PANEL_X + 177, PANEL_Y + 46 });
DrawPanelBox(out, { 177, 62, 288, 63 }, GetMainPanel().position + Displacement { 177, 46 });
if (!panelflag && !trigflag && pcursinvitem == -1 && pcursstashitem == uint16_t(-1) && !spselflag) {
InfoString.clear();
InfoColor = UiFlags::ColorWhite;
@ -925,14 +929,14 @@ void CheckLvlBtn()
return;
}
auto &mainPanelPosition = GetMainPanel().position;
const Point mainPanelPosition = GetMainPanel().position;
if (!lvlbtndown && MousePosition.x >= 40 + mainPanelPosition.x && MousePosition.x <= 81 + mainPanelPosition.x && MousePosition.y >= -39 + mainPanelPosition.y && MousePosition.y <= -17 + mainPanelPosition.y)
lvlbtndown = true;
}
void ReleaseLvlBtn()
{
auto &mainPanelPosition = GetMainPanel().position;
const Point mainPanelPosition = GetMainPanel().position;
if (MousePosition.x >= 40 + mainPanelPosition.x && MousePosition.x <= 81 + mainPanelPosition.x && MousePosition.y >= -39 + mainPanelPosition.y && MousePosition.y <= -17 + mainPanelPosition.y) {
QuestLogIsOpen = false;
CloseGoldWithdraw();
@ -946,8 +950,8 @@ void DrawLevelUpIcon(const Surface &out)
{
if (IsLevelUpButtonVisible()) {
int nCel = lvlbtndown ? 2 : 1;
DrawString(out, _("Level Up"), { { PANEL_LEFT + 0, PANEL_TOP - 62 }, { 120, 0 } }, UiFlags::ColorWhite | UiFlags::AlignCenter);
CelDrawTo(out, { 40 + PANEL_X, -17 + PANEL_Y }, *pChrButtons, nCel);
DrawString(out, _("Level Up"), { GetMainPanel().position + Displacement { 0, -62 }, { 120, 0 } }, UiFlags::ColorWhite | UiFlags::AlignCenter);
CelDrawTo(out, GetMainPanel().position + Displacement { 40, -17 }, *pChrButtons, nCel);
}
}
@ -1105,20 +1109,22 @@ void DrawTalkPan(const Surface &out)
force_redraw = 255;
DrawPanelBox(out, MakeSdlRect(175, sgbPlrTalkTbl + 20, 294, 5), { PANEL_X + 175, PANEL_Y + 4 });
const Point mainPanelPosition = GetMainPanel().position;
DrawPanelBox(out, MakeSdlRect(175, sgbPlrTalkTbl + 20, 294, 5), mainPanelPosition + Displacement { 175, 4 });
int off = 0;
for (int i = 293; i > 283; off++, i--) {
DrawPanelBox(out, MakeSdlRect((off / 2) + 175, sgbPlrTalkTbl + off + 25, i, 1), { (off / 2) + PANEL_X + 175, off + PANEL_Y + 9 });
DrawPanelBox(out, MakeSdlRect((off / 2) + 175, sgbPlrTalkTbl + off + 25, i, 1), mainPanelPosition + Displacement { (off / 2) + 175, off + 9 });
}
DrawPanelBox(out, MakeSdlRect(185, sgbPlrTalkTbl + 35, 274, 30), { PANEL_X + 185, PANEL_Y + 19 });
DrawPanelBox(out, MakeSdlRect(180, sgbPlrTalkTbl + 65, 284, 5), { PANEL_X + 180, PANEL_Y + 49 });
DrawPanelBox(out, MakeSdlRect(185, sgbPlrTalkTbl + 35, 274, 30), mainPanelPosition + Displacement { 185, 19 });
DrawPanelBox(out, MakeSdlRect(180, sgbPlrTalkTbl + 65, 284, 5), mainPanelPosition + Displacement { 180, 49 });
for (int i = 0; i < 10; i++) {
DrawPanelBox(out, MakeSdlRect(180, sgbPlrTalkTbl + i + 70, i + 284, 1), { PANEL_X + 180, i + PANEL_Y + 54 });
DrawPanelBox(out, MakeSdlRect(180, sgbPlrTalkTbl + i + 70, i + 284, 1), mainPanelPosition + Displacement { 180, i + 54 });
}
DrawPanelBox(out, MakeSdlRect(170, sgbPlrTalkTbl + 80, 310, 55), { PANEL_X + 170, PANEL_Y + 64 });
DrawPanelBox(out, MakeSdlRect(170, sgbPlrTalkTbl + 80, 310, 55), mainPanelPosition + Displacement { 170, 64 });
int x = PANEL_LEFT + 200;
int y = PANEL_Y + 10;
int x = mainPanelPosition.x + 200;
int y = mainPanelPosition.y + 10;
uint32_t idx = DrawString(out, TalkMessage, { { x, y }, { 250, 27 } }, UiFlags::ColorWhite | UiFlags::PentaCursor, 1, 13);
if (idx < sizeof(TalkMessage))
@ -1132,7 +1138,7 @@ void DrawTalkPan(const Surface &out)
auto &player = Players[i];
UiFlags color = player.friendlyMode ? UiFlags::ColorWhitegold : UiFlags::ColorRed;
const Point talkPanPosition { 172 + PANEL_X, 84 + 18 * talkBtn + PANEL_Y };
const Point talkPanPosition = mainPanelPosition + Displacement { 172, 84 + 18 * talkBtn };
if (WhisperList[i]) {
if (TalkButtonsDown[talkBtn]) {
int nCel = talkBtn != 0 ? 4 : 3;
@ -1159,7 +1165,7 @@ bool control_check_talk_btn()
if (!talkflag)
return false;
auto &mainPanelPosition = GetMainPanel().position;
const Point mainPanelPosition = GetMainPanel().position;
if (MousePosition.x < 172 + mainPanelPosition.x)
return false;
@ -1187,7 +1193,7 @@ void control_release_talk_btn()
for (bool &talkButtonDown : TalkButtonsDown)
talkButtonDown = false;
auto &mainPanelPosition = GetMainPanel().position;
const Point mainPanelPosition = GetMainPanel().position;
if (MousePosition.x < 172 + mainPanelPosition.x || MousePosition.y < 69 + mainPanelPosition.y || MousePosition.x > 233 + mainPanelPosition.x || MousePosition.y > 123 + mainPanelPosition.y)
return;
@ -1209,13 +1215,13 @@ void control_type_message()
return;
talkflag = true;
SDL_Rect rect = MakeSdlRect(PANEL_LEFT + 200, PANEL_Y + 22, 250, 39);
SDL_Rect rect = MakeSdlRect(GetMainPanel().position.x + 200, GetMainPanel().position.y + 22, 250, 39);
SDL_SetTextInputRect(&rect);
TalkMessage[0] = '\0';
for (bool &talkButtonDown : TalkButtonsDown) {
talkButtonDown = false;
}
sgbPlrTalkTbl = PANEL_HEIGHT + 16;
sgbPlrTalkTbl = GetMainPanel().size.height + 16;
force_redraw = 255;
TalkSaveIndex = NextTalkSave;
SDL_StartTextInput();

10
Source/control.h

@ -23,13 +23,6 @@
namespace devilution {
#define PANEL_WIDTH 640
#define PANEL_HEIGHT 128
#define PANEL_TOP (gnScreenHeight - PANEL_HEIGHT)
#define PANEL_LEFT (gnScreenWidth - PANEL_WIDTH) / 2
#define PANEL_X PANEL_LEFT
#define PANEL_Y PANEL_TOP
#define SPANEL_WIDTH 320
#define SPANEL_HEIGHT 352
@ -69,7 +62,8 @@ bool IsChatAvailable();
*/
inline bool CanPanelsCoverView()
{
return GetScreenWidth() <= PANEL_WIDTH && GetScreenHeight() <= SPANEL_HEIGHT + PANEL_HEIGHT;
const Rectangle &mainPanel = GetMainPanel();
return GetScreenWidth() <= mainPanel.size.width && GetScreenHeight() <= SPANEL_HEIGHT + mainPanel.size.height;
}
void DrawSpellList(const Surface &out);
void SetSpell();

10
Source/controls/modifier_hints.cpp

@ -150,8 +150,9 @@ void DrawStartModifierMenu(const Surface &out)
return;
static const CircleMenuHint DPad(/*top=*/HintIcon::IconMenu, /*right=*/HintIcon::IconInv, /*bottom=*/HintIcon::IconMap, /*left=*/HintIcon::IconChar);
static const CircleMenuHint Buttons(/*top=*/HintIcon::IconNull, /*right=*/HintIcon::IconNull, /*bottom=*/HintIcon::IconSpells, /*left=*/HintIcon::IconQuests);
DrawCircleMenuHint(out, DPad, { PANEL_LEFT + CircleMarginX, PANEL_TOP - CircleTop });
DrawCircleMenuHint(out, Buttons, { PANEL_LEFT + PANEL_WIDTH - HintBoxSize * 3 - CircleMarginX - HintBoxMargin * 2, PANEL_TOP - CircleTop });
const Rectangle &mainPanel = GetMainPanel();
DrawCircleMenuHint(out, DPad, { mainPanel.position.x + CircleMarginX, mainPanel.position.y - CircleTop });
DrawCircleMenuHint(out, Buttons, { mainPanel.position.x + mainPanel.size.width - HintBoxSize * 3 - CircleMarginX - HintBoxMargin * 2, mainPanel.position.y - CircleTop });
}
void DrawSelectModifierMenu(const Surface &out)
@ -159,10 +160,11 @@ void DrawSelectModifierMenu(const Surface &out)
if (!select_modifier_active || SimulatingMouseWithSelectAndDPad)
return;
const Rectangle &mainPanel = GetMainPanel();
if (sgOptions.Controller.bDpadHotkeys) {
DrawSpellsCircleMenuHint(out, { PANEL_LEFT + CircleMarginX, PANEL_TOP - CircleTop });
DrawSpellsCircleMenuHint(out, { mainPanel.position.x + CircleMarginX, mainPanel.position.y - CircleTop });
}
DrawSpellsCircleMenuHint(out, { PANEL_LEFT + PANEL_WIDTH - HintBoxSize * 3 - CircleMarginX - HintBoxMargin * 2, PANEL_TOP - CircleTop });
DrawSpellsCircleMenuHint(out, { mainPanel.position.x + mainPanel.size.width - HintBoxSize * 3 - CircleMarginX - HintBoxMargin * 2, mainPanel.position.y - CircleTop });
}
} // namespace

7
Source/cursor.cpp

@ -264,8 +264,9 @@ void CheckCursMove()
sx += GetScreenWidth() / 4;
}
}
if (sy > GetMainPanel().position.y - 1 && MousePosition.x >= GetMainPanel().position.x && MousePosition.x < GetMainPanel().position.x + PANEL_WIDTH && track_isscrolling()) {
sy = GetMainPanel().position.y - 1;
const Rectangle &mainPanel = GetMainPanel();
if (mainPanel.Contains(MousePosition) && track_isscrolling()) {
sy = mainPanel.position.y - 1;
}
if (!zoomflag) {
@ -378,7 +379,7 @@ void CheckCursMove()
cursPosition = { mx, my };
return;
}
if (GetMainPanel().Contains(MousePosition)) {
if (mainPanel.Contains(MousePosition)) {
CheckPanelInfo();
return;
}

10
Source/diablo.cpp

@ -218,7 +218,7 @@ void LeftMouseCmd(bool bShift)
{
bool bNear;
assert(MousePosition.y < GetMainPanel().position.y || MousePosition.x < GetMainPanel().position.x || MousePosition.x >= GetMainPanel().position.x + PANEL_WIDTH);
assert(!GetMainPanel().Contains(MousePosition));
if (leveltype == DTYPE_TOWN) {
CloseGoldWithdraw();
@ -429,9 +429,9 @@ void ReleaseKey(int vkey)
void ClosePanels()
{
if (CanPanelsCoverView()) {
if (!IsLeftPanelOpen() && IsRightPanelOpen() && MousePosition.x < 480 && MousePosition.y < PANEL_TOP) {
if (!IsLeftPanelOpen() && IsRightPanelOpen() && MousePosition.x < 480 && MousePosition.y < GetMainPanel().position.y) {
SetCursorPos(MousePosition + Displacement { 160, 0 });
} else if (!IsRightPanelOpen() && IsLeftPanelOpen() && MousePosition.x > 160 && MousePosition.y < PANEL_TOP) {
} else if (!IsRightPanelOpen() && IsLeftPanelOpen() && MousePosition.x > 160 && MousePosition.y < GetMainPanel().position.y) {
SetCursorPos(MousePosition - Displacement { 160, 0 });
}
}
@ -1392,11 +1392,11 @@ void QuestLogKeyPressed()
}
if (!IsRightPanelOpen() && CanPanelsCoverView()) {
if (!QuestLogIsOpen) { // We closed the quest log
if (MousePosition.x > 160 && MousePosition.y < PANEL_TOP) {
if (MousePosition.x > 160 && MousePosition.y < GetMainPanel().position.y) {
SetCursorPos(MousePosition - Displacement { 160, 0 });
}
} else if (!chrflag) { // We opened the character quest log
if (MousePosition.x < 480 && MousePosition.y < PANEL_TOP) {
if (MousePosition.x < 480 && MousePosition.y < GetMainPanel().position.y) {
SetCursorPos(MousePosition + Displacement { 160, 0 });
}
}

8
Source/inv.cpp

@ -1245,7 +1245,9 @@ void DrawInvBelt(const Surface &out)
return;
}
DrawPanelBox(out, { 205, 21, 232, 28 }, { PANEL_X + 205, PANEL_Y + 5 });
const Point mainPanelPosition = GetMainPanel().position;
DrawPanelBox(out, { 205, 21, 232, 28 }, mainPanelPosition + Displacement { 205, 5 });
auto &myPlayer = Players[MyPlayerId];
@ -1254,7 +1256,7 @@ void DrawInvBelt(const Surface &out)
continue;
}
const Point position { InvRect[i + SLOTXY_BELT_FIRST].x + PANEL_X, InvRect[i + SLOTXY_BELT_FIRST].y + PANEL_Y - 1 };
const Point position { InvRect[i + SLOTXY_BELT_FIRST].x + mainPanelPosition.x, InvRect[i + SLOTXY_BELT_FIRST].y + mainPanelPosition.y - 1 };
InvDrawSlotBack(out, position, InventorySlotSizeInPixels);
const int cursId = myPlayer.SpdList[i]._iCurs + CURSOR_FIRSTITEM;
@ -1569,7 +1571,7 @@ void CheckInvItem(bool isShiftHeld, bool isCtrlHeld)
void CheckInvScrn(bool isShiftHeld, bool isCtrlHeld)
{
auto &mainPanelPosition = GetMainPanel().position;
const Point mainPanelPosition = GetMainPanel().position;
if (MousePosition.x > 190 + mainPanelPosition.x && MousePosition.x < 437 + mainPanelPosition.x
&& MousePosition.y > mainPanelPosition.y && MousePosition.y < 33 + mainPanelPosition.y) {
CheckInvItem(isShiftHeld, isCtrlHeld);

4
Source/panels/mainpanel.cpp

@ -43,7 +43,7 @@ void RenderMainButton(int buttonId, string_view text, int frame)
Point panelPosition { PanBtnPos[buttonId].x + 4, PanBtnPos[buttonId].y + 17 };
DrawButtonOnPanel(panelPosition, text, frame);
if (IsChatAvailable())
DrawButtonOnPanel(panelPosition + Displacement { 0, PANEL_HEIGHT + 16 }, text, frame);
DrawButtonOnPanel(panelPosition + Displacement { 0, GetMainPanel().size.height + 16 }, text, frame);
const Surface out(PanelButtonDown.surface.get());
Point position { 0, 19 * buttonId };
@ -60,7 +60,7 @@ void RenderMainButton(int buttonId, string_view text, int frame)
void DrawTalkButton(int buttonId)
{
string_view text = _("voice");
Point position { 176, PANEL_HEIGHT + 101 + 18 * buttonId };
Point position { 176, GetMainPanel().size.height + 101 + 18 * buttonId };
DrawArt(*pBtmBuff, position, &TalkButton);
int width = std::min(GetLineWidth(text, GameFont12, 1), PanelButton.w());
DrawArt(*pBtmBuff, position + Displacement { (TalkButton.w() - width) / 2, 6 }, &PanelButtonGrime, 1, width, 9);

32
Source/panels/spell_list.cpp

@ -114,7 +114,7 @@ void DrawSpell(const Surface &out)
st = RSPLTYPE_INVALID;
SetSpellTrans(st);
const int nCel = (spl != SPL_INVALID) ? SpellITbl[spl] : 26;
const Point position { PANEL_X + 565, PANEL_Y + 119 };
const Point position = GetMainPanel().position + Displacement { 565, 119 };
DrawSpellCel(out, position, nCel);
std::optional<string_view> hotkeyName = GetHotkeyName(spl, myPlayer._pRSplType);
@ -211,9 +211,10 @@ std::vector<SpellListItem> GetSpellListItems()
std::vector<SpellListItem> spellListItems;
uint64_t mask;
const Point mainPanelPosition = GetMainPanel().position;
int x = PANEL_X + 12 + SPLICONLENGTH * SPLROWICONLS;
int y = PANEL_Y - 17;
int x = mainPanelPosition.x + 12 + SPLICONLENGTH * SPLROWICONLS;
int y = mainPanelPosition.y - 17;
for (int i = RSPLTYPE_SKILL; i < RSPLTYPE_INVALID; i++) {
auto &myPlayer = Players[MyPlayerId];
@ -242,15 +243,15 @@ std::vector<SpellListItem> GetSpellListItems()
bool isSelected = (MousePosition.x >= lx && MousePosition.x < lx + SPLICONLENGTH && MousePosition.y >= ly && MousePosition.y < ly + SPLICONLENGTH);
spellListItems.emplace_back(SpellListItem { { x, y }, (spell_type)i, (spell_id)j, isSelected });
x -= SPLICONLENGTH;
if (x == PANEL_X + 12 - SPLICONLENGTH) {
x = PANEL_X + 12 + SPLICONLENGTH * SPLROWICONLS;
if (x == mainPanelPosition.x + 12 - SPLICONLENGTH) {
x = mainPanelPosition.x + 12 + SPLICONLENGTH * SPLROWICONLS;
y -= SPLICONLENGTH;
}
}
if (mask != 0 && x != PANEL_X + 12 + SPLICONLENGTH * SPLROWICONLS)
if (mask != 0 && x != mainPanelPosition.x + 12 + SPLICONLENGTH * SPLROWICONLS)
x -= SPLICONLENGTH;
if (x == PANEL_X + 12 - SPLICONLENGTH) {
x = PANEL_X + 12 + SPLICONLENGTH * SPLROWICONLS;
if (x == mainPanelPosition.x + 12 - SPLICONLENGTH) {
x = mainPanelPosition.x + 12 + SPLICONLENGTH * SPLROWICONLS;
y -= SPLICONLENGTH;
}
}
@ -332,8 +333,9 @@ void ToggleSpell(size_t slot)
void DoSpeedBook()
{
spselflag = true;
int xo = PANEL_X + 12 + SPLICONLENGTH * 10;
int yo = PANEL_Y - 17;
const Point mainPanelPosition = GetMainPanel().position;
int xo = mainPanelPosition.x + 12 + SPLICONLENGTH * 10;
int yo = mainPanelPosition.y - 17;
int x = xo + SPLICONLENGTH / 2;
int y = yo - SPLICONLENGTH / 2;
@ -364,17 +366,17 @@ void DoSpeedBook()
y = yo - SPLICONLENGTH / 2;
}
xo -= SPLICONLENGTH;
if (xo == PANEL_X + 12 - SPLICONLENGTH) {
xo = PANEL_X + 12 + SPLICONLENGTH * SPLROWICONLS;
if (xo == mainPanelPosition.x + 12 - SPLICONLENGTH) {
xo = mainPanelPosition.x + 12 + SPLICONLENGTH * SPLROWICONLS;
yo -= SPLICONLENGTH;
}
}
spell <<= 1ULL;
}
if (spells != 0 && xo != PANEL_X + 12 + SPLICONLENGTH * SPLROWICONLS)
if (spells != 0 && xo != mainPanelPosition.x + 12 + SPLICONLENGTH * SPLROWICONLS)
xo -= SPLICONLENGTH;
if (xo == PANEL_X + 12 - SPLICONLENGTH) {
xo = PANEL_X + 12 + SPLICONLENGTH * SPLROWICONLS;
if (xo == mainPanelPosition.x + 12 - SPLICONLENGTH) {
xo = mainPanelPosition.x + 12 + SPLICONLENGTH * SPLROWICONLS;
yo -= SPLICONLENGTH;
}
}

2
Source/plrmsg.cpp

@ -101,7 +101,7 @@ void DrawPlrMsg(const Surface &out)
return;
int x = 10;
int y = PANEL_TOP - 13;
int y = GetMainPanel().position.y - 13;
int width = gnScreenWidth - 20;
if (!talkflag && IsLeftPanelOpen()) {

8
Source/qol/xpbar.cpp

@ -92,8 +92,9 @@ void DrawXPBar(const Surface &out)
return;
const auto &player = Players[MyPlayerId];
const Rectangle &mainPanel = GetMainPanel();
const Point back = { PANEL_LEFT + PANEL_WIDTH / 2 - 155, PANEL_TOP + PANEL_HEIGHT - 11 };
const Point back = { mainPanel.position.x + mainPanel.size.width / 2 - 155, mainPanel.position.y + mainPanel.size.height - 11 };
const Point position = back + Displacement { 3, 2 };
DrawArt(out, back, &xpbarArt);
@ -132,9 +133,10 @@ bool CheckXPBarInfo()
{
if (!*sgOptions.Gameplay.experienceBar)
return false;
const Rectangle &mainPanel = GetMainPanel();
const int backX = PANEL_LEFT + PANEL_WIDTH / 2 - 155;
const int backY = PANEL_TOP + PANEL_HEIGHT - 11;
const int backX = mainPanel.position.x + mainPanel.size.width / 2 - 155;
const int backY = mainPanel.position.y + mainPanel.size.height - 11;
if (MousePosition.x < backX || MousePosition.x >= backX + BackWidth || MousePosition.y < backY || MousePosition.y >= backY + BackHeight)
return false;

32
Source/scrollrt.cpp

@ -1386,25 +1386,26 @@ void DrawMain(int dwHgt, bool drawDesc, bool drawHp, bool drawMana, bool drawSba
DoBlitScreen(0, 0, gnScreenWidth, dwHgt);
}
if (dwHgt < gnScreenHeight) {
const Point mainPanelPosition = GetMainPanel().position;
if (drawSbar) {
DoBlitScreen(PANEL_LEFT + 204, PANEL_TOP + 5, 232, 28);
DoBlitScreen(mainPanelPosition.x + 204, mainPanelPosition.y + 5, 232, 28);
}
if (drawDesc) {
DoBlitScreen(PANEL_LEFT + 176, PANEL_TOP + 46, 288, 63);
DoBlitScreen(mainPanelPosition.x + 176, mainPanelPosition.y + 46, 288, 63);
}
if (drawMana) {
DoBlitScreen(PANEL_LEFT + 460, PANEL_TOP, 88, 72);
DoBlitScreen(PANEL_LEFT + 564, PANEL_TOP + 64, 56, 56);
DoBlitScreen(mainPanelPosition.x + 460, mainPanelPosition.y, 88, 72);
DoBlitScreen(mainPanelPosition.x + 564, mainPanelPosition.y + 64, 56, 56);
}
if (drawHp) {
DoBlitScreen(PANEL_LEFT + 96, PANEL_TOP, 88, 72);
DoBlitScreen(mainPanelPosition.x + 96, mainPanelPosition.y, 88, 72);
}
if (drawBtn) {
DoBlitScreen(PANEL_LEFT + 8, PANEL_TOP + 5, 72, 119);
DoBlitScreen(PANEL_LEFT + 556, PANEL_TOP + 5, 72, 48);
DoBlitScreen(mainPanelPosition.x + 8, mainPanelPosition.y + 5, 72, 119);
DoBlitScreen(mainPanelPosition.x + 556, mainPanelPosition.y + 5, 72, 48);
if (gbIsMultiplayer) {
DoBlitScreen(PANEL_LEFT + 84, PANEL_TOP + 91, 36, 32);
DoBlitScreen(PANEL_LEFT + 524, PANEL_TOP + 91, 36, 32);
DoBlitScreen(mainPanelPosition.x + 84, mainPanelPosition.y + 91, 36, 32);
DoBlitScreen(mainPanelPosition.x + 524, mainPanelPosition.y + 91, 36, 32);
}
}
if (sgdwCursWdtOld != 0) {
@ -1453,11 +1454,12 @@ void ShiftGrid(int *x, int *y, int horizontal, int vertical)
int RowsCoveredByPanel()
{
if (GetScreenWidth() <= PANEL_WIDTH) {
auto &mainPanelSize = GetMainPanel().size;
if (GetScreenWidth() <= mainPanelSize.width) {
return 0;
}
int rows = PANEL_HEIGHT / TILE_HEIGHT;
int rows = mainPanelSize.height / TILE_HEIGHT;
if (!zoomflag) {
rows /= 2;
}
@ -1692,7 +1694,9 @@ void DrawAndBlit()
bool ddsdesc = false;
bool ctrlPan = false;
if (gnScreenWidth > PANEL_WIDTH || force_redraw == 255 || IsHighlightingLabelsEnabled()) {
const Rectangle &mainPanel = GetMainPanel();
if (gnScreenWidth > mainPanel.size.width || force_redraw == 255 || IsHighlightingLabelsEnabled()) {
drawhpflag = true;
drawmanaflag = true;
drawbtnflag = true;
@ -1737,9 +1741,9 @@ void DrawAndBlit()
}
DrawXPBar(out);
if (*sgOptions.Graphics.showHealthValues)
DrawFlaskValues(out, { PANEL_X + 134, PANEL_Y + 28 }, MyPlayer->_pHitPoints >> 6, MyPlayer->_pMaxHP >> 6);
DrawFlaskValues(out, { mainPanel.position.x + 134, mainPanel.position.y + 28 }, MyPlayer->_pHitPoints >> 6, MyPlayer->_pMaxHP >> 6);
if (*sgOptions.Graphics.showManaValues)
DrawFlaskValues(out, { PANEL_X + PANEL_WIDTH - 138, PANEL_Y + 28 }, MyPlayer->_pMana >> 6, MyPlayer->_pMaxMana >> 6);
DrawFlaskValues(out, { mainPanel.position.x + mainPanel.size.width - 138, mainPanel.position.y + 28 }, MyPlayer->_pMana >> 6, MyPlayer->_pMaxMana >> 6);
if (IsHardwareCursor()) {
SetHardwareCursorVisible(ShouldShowCursor());

4
test/scrollrt_test.cpp

@ -1,5 +1,6 @@
#include <gtest/gtest.h>
#include "control.h"
#include "diablo.h"
#include "scrollrt.h"
#include "utils/ui_fwd.h"
@ -146,6 +147,7 @@ TEST(Scroll_rt, calc_tiles_covered_by_panel_original)
{
gnScreenWidth = 640;
zoomflag = true;
CalculatePanelAreas();
EXPECT_EQ(RowsCoveredByPanel(), 0);
}
@ -153,6 +155,7 @@ TEST(Scroll_rt, calc_tiles_covered_by_panel_960)
{
gnScreenWidth = 960;
zoomflag = true;
CalculatePanelAreas();
EXPECT_EQ(RowsCoveredByPanel(), 4);
}
@ -160,5 +163,6 @@ TEST(Scroll_rt, calc_tiles_covered_by_panel_960_zoom)
{
gnScreenWidth = 960;
zoomflag = false;
CalculatePanelAreas();
EXPECT_EQ(RowsCoveredByPanel(), 2);
}

Loading…
Cancel
Save