From c68fcf3cb1c5063e46cfdbbd83ad926db670be44 Mon Sep 17 00:00:00 2001 From: ephphatha Date: Sat, 18 Jun 2022 17:19:13 +1000 Subject: [PATCH] Apply MethodCase config to Rectangle::Contains Also included Circle and VirtualButton classes due to the shared use. --- Source/control.cpp | 6 +++--- Source/controls/plrctrls.cpp | 6 +++--- Source/controls/touch/event_handlers.cpp | 12 ++++++------ Source/controls/touch/gamepad.cpp | 2 +- Source/controls/touch/gamepad.h | 10 +++++----- Source/controls/touch/renderers.cpp | 2 +- Source/cursor.cpp | 12 ++++++------ Source/diablo.cpp | 16 ++++++++-------- Source/engine/circle.hpp | 2 +- Source/engine/rectangle.hpp | 2 +- Source/items.cpp | 2 +- Source/levels/drlg_l2.cpp | 4 ++-- Source/levels/gendung.cpp | 4 ++-- Source/levels/trigs.cpp | 2 +- Source/panels/spell_book.cpp | 4 ++-- Source/player.cpp | 6 +++--- Source/qol/itemlabels.cpp | 6 +++--- Source/qol/stash.cpp | 10 +++++----- Source/quests.cpp | 2 +- 19 files changed, 55 insertions(+), 55 deletions(-) diff --git a/Source/control.cpp b/Source/control.cpp index 79cc170c1..6f98167c0 100644 --- a/Source/control.cpp +++ b/Source/control.cpp @@ -400,7 +400,7 @@ bool IsLevelUpButtonVisible() if (stextflag != STORE_NONE || IsStashOpen) { return false; } - if (QuestLogIsOpen && GetLeftPanel().Contains(GetMainPanel().position + Displacement { 0, -74 })) { + if (QuestLogIsOpen && GetLeftPanel().contains(GetMainPanel().position + Displacement { 0, -74 })) { return false; } @@ -975,7 +975,7 @@ void CheckChrBtns() auto buttonId = static_cast(attribute); Rectangle button = ChrBtnsRect[buttonId]; button.position = GetPanelPosition(UiPanels::Character, button.position); - if (button.Contains(MousePosition)) { + if (button.contains(MousePosition)) { chrbtn[buttonId] = true; chrbtnactive = true; } @@ -993,7 +993,7 @@ void ReleaseChrBtns(bool addAllStatPoints) chrbtn[buttonId] = false; Rectangle button = ChrBtnsRect[buttonId]; button.position = GetPanelPosition(UiPanels::Character, button.position); - if (button.Contains(MousePosition)) { + if (button.contains(MousePosition)) { Player &myPlayer = *MyPlayer; int statPointsToAdd = 1; if (addAllStatPoints) diff --git a/Source/controls/plrctrls.cpp b/Source/controls/plrctrls.cpp index 744c6f28b..2714f6cc1 100644 --- a/Source/controls/plrctrls.cpp +++ b/Source/controls/plrctrls.cpp @@ -542,7 +542,7 @@ void AttrIncBtnSnap(AxisDirection dir) for (int i = 0; i < 4; i++) { button = ChrBtnsRect[i]; button.position = GetPanelPosition(UiPanels::Character, button.position); - if (button.Contains(MousePosition)) { + if (button.contains(MousePosition)) { slot = i; break; } @@ -1689,7 +1689,7 @@ void PerformPrimaryAction() if (pcurs > CURSOR_HAND && pcurs < CURSOR_FIRSTITEM) { TryIconCurs(); NewCursor(CURSOR_HAND); - } else if (GetRightPanel().Contains(MousePosition) || GetMainPanel().Contains(MousePosition)) { + } else if (GetRightPanel().contains(MousePosition) || GetMainPanel().contains(MousePosition)) { int inventorySlot = (Slot >= 0) ? Slot : FindClosestInventorySlot(MousePosition); const Size cursorSizeInCells = MyPlayer->HoldItem.isEmpty() ? Size { 1, 1 } : GetInventorySize(MyPlayer->HoldItem); @@ -1725,7 +1725,7 @@ void PerformPrimaryAction() Slot = jumpSlot; SetCursorPos(mousePos); } - } else if (IsStashOpen && GetLeftPanel().Contains(MousePosition)) { + } else if (IsStashOpen && GetLeftPanel().contains(MousePosition)) { Point stashSlot = (ActiveStashSlot != InvalidStashPoint) ? ActiveStashSlot : FindClosestStashSlot(MousePosition); const Size cursorSizeInCells = MyPlayer->HoldItem.isEmpty() ? Size { 1, 1 } : GetInventorySize(MyPlayer->HoldItem); diff --git a/Source/controls/touch/event_handlers.cpp b/Source/controls/touch/event_handlers.cpp index 7244f1bb6..7f6a1adbe 100644 --- a/Source/controls/touch/event_handlers.cpp +++ b/Source/controls/touch/event_handlers.cpp @@ -31,9 +31,9 @@ void SimulateMouseMovement(const SDL_Event &event) { Point position = ScaleToScreenCoordinates(event.tfinger.x, event.tfinger.y); - bool isInMainPanel = GetMainPanel().Contains(position); - bool isInLeftPanel = GetLeftPanel().Contains(position); - bool isInRightPanel = GetRightPanel().Contains(position); + bool isInMainPanel = GetMainPanel().contains(position); + bool isInLeftPanel = GetLeftPanel().contains(position); + bool isInRightPanel = GetRightPanel().contains(position); if (IsStashOpen) { if (!spselflag && !isInMainPanel && !isInLeftPanel && !isInRightPanel) return; @@ -234,7 +234,7 @@ bool VirtualDirectionPadEventHandler::HandleFingerDown(const SDL_TouchFingerEven float y = event.y; Point touchCoordinates = ScaleToScreenCoordinates(x, y); - if (!virtualDirectionPad->area.Contains(touchCoordinates)) + if (!virtualDirectionPad->area.contains(touchCoordinates)) return false; virtualDirectionPad->UpdatePosition(touchCoordinates); @@ -301,7 +301,7 @@ bool VirtualButtonEventHandler::HandleFingerDown(const SDL_TouchFingerEvent &eve float y = event.y; Point touchCoordinates = ScaleToScreenCoordinates(x, y); - if (!virtualButton->Contains(touchCoordinates)) + if (!virtualButton->contains(touchCoordinates)) return false; if (toggles) @@ -343,7 +343,7 @@ bool VirtualButtonEventHandler::HandleFingerMotion(const SDL_TouchFingerEvent &e Point touchCoordinates = ScaleToScreenCoordinates(x, y); bool wasHeld = virtualButton->isHeld; - virtualButton->isHeld = virtualButton->Contains(touchCoordinates); + virtualButton->isHeld = virtualButton->contains(touchCoordinates); virtualButton->didStateChange = virtualButton->isHeld != wasHeld; return true; diff --git a/Source/controls/touch/gamepad.cpp b/Source/controls/touch/gamepad.cpp index 5fa8932c9..8110dc73f 100644 --- a/Source/controls/touch/gamepad.cpp +++ b/Source/controls/touch/gamepad.cpp @@ -219,7 +219,7 @@ void VirtualDirectionPad::UpdatePosition(Point touchCoordinates) return; } - if (!area.Contains(position)) { + if (!area.contains(position)) { int x = diff.deltaX; int y = diff.deltaY; double dist = sqrt(x * x + y * y); diff --git a/Source/controls/touch/gamepad.h b/Source/controls/touch/gamepad.h index 6e288bcda..3b9d5932a 100644 --- a/Source/controls/touch/gamepad.h +++ b/Source/controls/touch/gamepad.h @@ -37,7 +37,7 @@ struct VirtualButton { { } - virtual bool Contains(Point point) = 0; + virtual bool contains(Point point) = 0; void Deactivate(); }; @@ -49,9 +49,9 @@ struct VirtualMenuButton : VirtualButton { { } - bool Contains(Point point) override + bool contains(Point point) override { - return area.Contains(point); + return area.contains(point); } }; @@ -63,9 +63,9 @@ struct VirtualPadButton : VirtualButton { { } - bool Contains(Point point) override + bool contains(Point point) override { - return area.Contains(point); + return area.contains(point); } }; diff --git a/Source/controls/touch/renderers.cpp b/Source/controls/touch/renderers.cpp index 13b6c30be..3e0a8e8f5 100644 --- a/Source/controls/touch/renderers.cpp +++ b/Source/controls/touch/renderers.cpp @@ -169,7 +169,7 @@ bool InteractsWithCharButton(Point point) auto buttonId = static_cast(attribute); Rectangle button = ChrBtnsRect[buttonId]; button.position = GetPanelPosition(UiPanels::Character, button.position); - if (button.Contains(point)) { + if (button.contains(point)) { return true; } } diff --git a/Source/cursor.cpp b/Source/cursor.cpp index 7964fba65..b5fdb17ed 100644 --- a/Source/cursor.cpp +++ b/Source/cursor.cpp @@ -265,7 +265,7 @@ void CheckCursMove() } } const Rectangle &mainPanel = GetMainPanel(); - if (mainPanel.Contains(MousePosition) && track_isscrolling()) { + if (mainPanel.contains(MousePosition) && track_isscrolling()) { sy = mainPanel.position.y - 1; } @@ -379,24 +379,24 @@ void CheckCursMove() cursPosition = { mx, my }; return; } - if (mainPanel.Contains(MousePosition)) { + if (mainPanel.contains(MousePosition)) { CheckPanelInfo(); return; } if (DoomFlag) { return; } - if (invflag && GetRightPanel().Contains(MousePosition)) { + if (invflag && GetRightPanel().contains(MousePosition)) { pcursinvitem = CheckInvHLight(); return; } - if (IsStashOpen && GetLeftPanel().Contains(MousePosition)) { + if (IsStashOpen && GetLeftPanel().contains(MousePosition)) { pcursstashitem = CheckStashHLight(MousePosition); } - if (sbookflag && GetRightPanel().Contains(MousePosition)) { + if (sbookflag && GetRightPanel().contains(MousePosition)) { return; } - if (IsLeftPanelOpen() && GetLeftPanel().Contains(MousePosition)) { + if (IsLeftPanelOpen() && GetLeftPanel().contains(MousePosition)) { return; } diff --git a/Source/diablo.cpp b/Source/diablo.cpp index da085fb69..240424fc2 100644 --- a/Source/diablo.cpp +++ b/Source/diablo.cpp @@ -218,7 +218,7 @@ void LeftMouseCmd(bool bShift) { bool bNear; - assert(!GetMainPanel().Contains(MousePosition)); + assert(!GetMainPanel().contains(MousePosition)); if (leveltype == DTYPE_TOWN) { CloseGoldWithdraw(); @@ -322,23 +322,23 @@ void LeftMouseDown(int wParam) bool isShiftHeld = (wParam & DVL_MK_SHIFT) != 0; bool isCtrlHeld = (wParam & DVL_MK_CTRL) != 0; - if (!GetMainPanel().Contains(MousePosition)) { + if (!GetMainPanel().contains(MousePosition)) { if (!gmenu_is_active() && !TryIconCurs()) { - if (QuestLogIsOpen && GetLeftPanel().Contains(MousePosition)) { + if (QuestLogIsOpen && GetLeftPanel().contains(MousePosition)) { QuestlogESC(); } else if (qtextflag) { qtextflag = false; stream_stop(); - } else if (chrflag && GetLeftPanel().Contains(MousePosition)) { + } else if (chrflag && GetLeftPanel().contains(MousePosition)) { CheckChrBtns(); - } else if (invflag && GetRightPanel().Contains(MousePosition)) { + } else if (invflag && GetRightPanel().contains(MousePosition)) { if (!dropGoldFlag) CheckInvItem(isShiftHeld, isCtrlHeld); - } else if (IsStashOpen && GetLeftPanel().Contains(MousePosition)) { + } else if (IsStashOpen && GetLeftPanel().contains(MousePosition)) { if (!IsWithdrawGoldOpen) CheckStashItem(MousePosition, isShiftHeld, isCtrlHeld); CheckStashButtonPress(MousePosition); - } else if (sbookflag && GetRightPanel().Contains(MousePosition)) { + } else if (sbookflag && GetRightPanel().contains(MousePosition)) { CheckSBook(); } else if (!MyPlayer->HoldItem.isEmpty()) { Point currentPosition = MyPlayer->position.tile; @@ -396,7 +396,7 @@ void RightMouseDown(bool isShiftHeld) SetSpell(); return; } - if (sbookflag && GetRightPanel().Contains(MousePosition)) + if (sbookflag && GetRightPanel().contains(MousePosition)) return; if (TryIconCurs()) return; diff --git a/Source/engine/circle.hpp b/Source/engine/circle.hpp index 4e3a5bd59..499fe7350 100644 --- a/Source/engine/circle.hpp +++ b/Source/engine/circle.hpp @@ -9,7 +9,7 @@ struct Circle { Point position; int radius; - constexpr bool Contains(Point point) const + constexpr bool contains(Point point) const { Displacement diff = point - position; int x = diff.deltaX; diff --git a/Source/engine/rectangle.hpp b/Source/engine/rectangle.hpp index 606303966..22b9e907a 100644 --- a/Source/engine/rectangle.hpp +++ b/Source/engine/rectangle.hpp @@ -31,7 +31,7 @@ struct Rectangle { { } - constexpr bool Contains(Point point) const + constexpr bool contains(Point point) const { return point.x >= this->position.x && point.x < (this->position.x + this->size.width) diff --git a/Source/items.cpp b/Source/items.cpp index 672bbbc77..15cc4494d 100644 --- a/Source/items.cpp +++ b/Source/items.cpp @@ -3740,7 +3740,7 @@ bool DoOil(Player &player, int cii) void DrawUniqueInfo(const Surface &out) { const Point position = GetRightPanel().position - Displacement { SidePanelSize.width, 0 }; - if (IsLeftPanelOpen() && GetLeftPanel().Contains(position)) { + if (IsLeftPanelOpen() && GetLeftPanel().contains(position)) { return; } diff --git a/Source/levels/drlg_l2.cpp b/Source/levels/drlg_l2.cpp index 6ddec0035..c340a48ec 100644 --- a/Source/levels/drlg_l2.cpp +++ b/Source/levels/drlg_l2.cpp @@ -1575,7 +1575,7 @@ void PlaceMiniSetRandom(const Miniset &miniset, int rndper) for (int sy = 0; sy < DMAXY - sh; sy++) { for (int sx = 0; sx < DMAXX - sw; sx++) { - if (SetPieceRoom.Contains({ sx, sy })) + if (SetPieceRoom.contains({ sx, sy })) continue; if (!miniset.matches({ sx, sy })) continue; @@ -2099,7 +2099,7 @@ void Substitution() { for (int y = 0; y < DMAXY; y++) { for (int x = 0; x < DMAXX; x++) { - if (SetPieceRoom.Contains({ x, y })) + if (SetPieceRoom.contains({ x, y })) continue; if (GenerateRnd(4) != 0) continue; diff --git a/Source/levels/gendung.cpp b/Source/levels/gendung.cpp index 67f92e37a..e2df47488 100644 --- a/Source/levels/gendung.cpp +++ b/Source/levels/gendung.cpp @@ -613,7 +613,7 @@ std::optional PlaceMiniSet(const Miniset &miniset, int tries, bool drlg1Q } } - if (SetPieceRoom.Contains(position)) + if (SetPieceRoom.contains(position)) continue; if (!miniset.matches(position)) continue; @@ -748,7 +748,7 @@ void DRLG_LPass3(int lv) bool IsNearThemeRoom(Point testPosition) { for (int i = 0; i < themeCount; i++) { - if (Rectangle(themeLoc[i].room.position - Displacement { 2 }, themeLoc[i].room.size + 5).Contains(testPosition)) + if (Rectangle(themeLoc[i].room.position - Displacement { 2 }, themeLoc[i].room.size + 5).contains(testPosition)) return true; } diff --git a/Source/levels/trigs.cpp b/Source/levels/trigs.cpp index ccbbeee52..d1ab41519 100644 --- a/Source/levels/trigs.cpp +++ b/Source/levels/trigs.cpp @@ -762,7 +762,7 @@ void CheckTrigForce() { trigflag = false; - if (ControlMode == ControlTypes::KeyboardAndMouse && GetMainPanel().Contains(MousePosition)) { + if (ControlMode == ControlTypes::KeyboardAndMouse && GetMainPanel().contains(MousePosition)) { return; } diff --git a/Source/panels/spell_book.cpp b/Source/panels/spell_book.cpp index 706db9b89..3166cecfa 100644 --- a/Source/panels/spell_book.cpp +++ b/Source/panels/spell_book.cpp @@ -194,7 +194,7 @@ void CheckSBook() // enough to the height of the space given to spell descriptions that we can reuse that value and subtract the // padding from the end of the area. Rectangle iconArea = { GetPanelPosition(UiPanels::Spell, { 11, 18 }), Size { 37, SpellBookDescription.height * 7 - 5 } }; - if (iconArea.Contains(MousePosition)) { + if (iconArea.contains(MousePosition)) { spell_id sn = SpellPages[sbooktab][(MousePosition.y - iconArea.position.y) / SpellBookDescription.height]; Player &player = *MyPlayer; uint64_t spl = player._pMemSpells | player._pISpells | player._pAblSpells; @@ -219,7 +219,7 @@ void CheckSBook() const int TabWidth = gbIsHellfire ? 61 : 76; // Tabs are drawn in a row near the bottom of the panel Rectangle tabArea = { GetPanelPosition(UiPanels::Spell, { 7, 320 }), Size { 305, 29 } }; - if (tabArea.Contains(MousePosition)) { + if (tabArea.contains(MousePosition)) { int hitColumn = MousePosition.x - tabArea.position.x; // Clicking on the gutter currently activates tab 3. Could make it do nothing by checking for == here and return early. if (!gbIsHellfire && hitColumn > TabWidth * 2) { diff --git a/Source/player.cpp b/Source/player.cpp index b5c71b42b..d36eed719 100644 --- a/Source/player.cpp +++ b/Source/player.cpp @@ -3528,12 +3528,12 @@ void CheckPlrSpell(bool isShiftHeld, spell_id spellID, spell_type spellType) if (pcurs != CURSOR_HAND) return; - if (GetMainPanel().Contains(MousePosition)) // inside main panel + if (GetMainPanel().contains(MousePosition)) // inside main panel return; if ( - (IsLeftPanelOpen() && GetLeftPanel().Contains(MousePosition)) // inside left panel - || (IsRightPanelOpen() && GetRightPanel().Contains(MousePosition)) // inside right panel + (IsLeftPanelOpen() && GetLeftPanel().contains(MousePosition)) // inside left panel + || (IsRightPanelOpen() && GetRightPanel().contains(MousePosition)) // inside right panel ) { if (spellID != SPL_HEAL && spellID != SPL_IDENTIFY diff --git a/Source/qol/itemlabels.cpp b/Source/qol/itemlabels.cpp index ba79d7630..16f52914d 100644 --- a/Source/qol/itemlabels.cpp +++ b/Source/qol/itemlabels.cpp @@ -96,11 +96,11 @@ void AddItemToLabelQueue(int id, int x, int y) bool IsMouseOverGameArea() { - if ((IsRightPanelOpen()) && GetRightPanel().Contains(MousePosition)) + if ((IsRightPanelOpen()) && GetRightPanel().contains(MousePosition)) return false; - if ((IsLeftPanelOpen()) && GetLeftPanel().Contains(MousePosition)) + if ((IsLeftPanelOpen()) && GetLeftPanel().contains(MousePosition)) return false; - if (GetMainPanel().Contains(MousePosition)) + if (GetMainPanel().contains(MousePosition)) return false; return true; diff --git a/Source/qol/stash.cpp b/Source/qol/stash.cpp index 1c8faa6e5..9f2f2d00b 100644 --- a/Source/qol/stash.cpp +++ b/Source/qol/stash.cpp @@ -70,7 +70,7 @@ Point FindSlotUnderCursor(Point cursorPosition) InventorySlotSizeInPixels + 1 }; - if (cell.Contains(cursorPosition)) { + if (cell.contains(cursorPosition)) { return point; } } @@ -174,7 +174,7 @@ void CheckStashCut(Point cursorPosition, bool automaticMove) }; // check which inventory rectangle the mouse is in, if any - if (cell.Contains(cursorPosition)) { + if (cell.contains(cursorPosition)) { slot = point; break; } @@ -296,7 +296,7 @@ void CheckStashButtonRelease(Point mousePosition) Rectangle stashButton = StashButtonRect[StashButtonPressed]; stashButton.position = GetPanelPosition(UiPanels::Stash, stashButton.position); - if (stashButton.Contains(mousePosition)) { + if (stashButton.contains(mousePosition)) { switch (StashButtonPressed) { case 0: Stash.PreviousPage(10); @@ -326,7 +326,7 @@ void CheckStashButtonPress(Point mousePosition) for (int i = 0; i < 5; i++) { stashButton = StashButtonRect[i]; stashButton.position = GetPanelPosition(UiPanels::Stash, stashButton.position); - if (stashButton.Contains(mousePosition)) { + if (stashButton.contains(mousePosition)) { StashButtonPressed = i; return; } @@ -404,7 +404,7 @@ uint16_t CheckStashHLight(Point mousePosition) InventorySlotSizeInPixels + 1 }; - if (cell.Contains({ mousePosition })) { + if (cell.contains(mousePosition)) { slot = point; break; } diff --git a/Source/quests.cpp b/Source/quests.cpp index 32b977fa1..3da623bda 100644 --- a/Source/quests.cpp +++ b/Source/quests.cpp @@ -198,7 +198,7 @@ int QuestLogMouseToEntry() { Rectangle innerArea = InnerPanel; innerArea.position += Displacement(GetLeftPanel().position.x, GetLeftPanel().position.y); - if (!innerArea.Contains(MousePosition) || (EncounteredQuestCount == 0)) + if (!innerArea.contains(MousePosition) || (EncounteredQuestCount == 0)) return -1; int y = MousePosition.y - innerArea.position.y; for (int i = 0; i < FirstFinishedQuest; i++) {