From 41ee4d5c8a425da326b89bbf5f1252790963116a Mon Sep 17 00:00:00 2001 From: przemek83 <4788832+przemek83@users.noreply.github.com> Date: Sat, 14 Sep 2024 21:13:35 +0200 Subject: [PATCH] Some static analysis fixes in MenuItem class. --- src/MenuItem.cpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/MenuItem.cpp b/src/MenuItem.cpp index 1951d25..d046ff2 100644 --- a/src/MenuItem.cpp +++ b/src/MenuItem.cpp @@ -6,6 +6,11 @@ #include "ResourceType.h" #include "Screen.h" +namespace +{ +int getMidpoint(int value) { return value / 2; } +} // namespace + MenuItem::MenuItem(UserChoice userChoice) : Drawable({}), userChoice_{userChoice} { @@ -20,7 +25,10 @@ void MenuItem::draw(const Screen& screen) const ResourceType MenuItem::getResourceType() const { return resourceType_; } -Point MenuItem::getCenter() const { return {width_ / 2, height_ / 2}; } +Point MenuItem::getCenter() const +{ + return {getMidpoint(width_), getMidpoint(height_)}; +} void MenuItem::setSelected(bool selected) { @@ -37,9 +45,10 @@ void MenuItem::init(const Display& display, int position, int count) height_ = std::max(display.getHeight() / 10, display.getResourceHeight(ResourceType::MENU_ITEM)); - setX(display.getCenterX() - width_ / 2); + setX(display.getCenterX() - getMidpoint(width_)); - const int locationOfFirstItem{display.getCenterY() - (count * height_ / 2)}; + const int locationOfFirstItem{display.getCenterY() - + getMidpoint(count * height_)}; setY(locationOfFirstItem + (height_ * position)); }