Skip to content

Commit

Permalink
Some static analysis fixes in MenuItem class.
Browse files Browse the repository at this point in the history
  • Loading branch information
przemek83 committed Sep 14, 2024
1 parent d80a078 commit 41ee4d5
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/MenuItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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}
{
Expand All @@ -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)
{
Expand All @@ -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));
}

Expand Down

0 comments on commit 41ee4d5

Please sign in to comment.