---
# System prepended metadata

title: GUI.cpp

---

# Overview
GUI contains the main function and integrates SFML for rendering and event handling.

---

## Configuration
```
struct GameRendererConfig
{
    static constexpr int kFPS = 30;
    static constexpr int kCellSize = 20;
    static constexpr int kBoardLeft = 20;
    static constexpr int kBoardTop = 60;
    static constexpr int kBorderSize = 1;
};
```
* <font color="#3398FF">Frames per second:</font>
    kFPS = 30
* <font color="#3398FF">Size of each cell:</font>
    kCellSize = 20
* <font color="#3398FF">Position offsets:</font>
    kBoardLeft = 20; kBoardTop = 60
* <font color="#3398FF">Size of the border:</font>
    kBorderSize = 1

---

## Get Mouse
```
CellPosition GetMouseCellPosition(const sf::RenderWindow &window) {
    const sf::Vector2i mousePosition = sf::Mouse::getPosition(window);
    const sf::Vector2i relatedMousePosition =
        mousePosition - sf::Vector2i(GameRendererConfig::kBoardLeft, GameRendererConfig::kBoardTop);
    return {relatedMousePosition.y / GameRendererConfig::kCellSize,
            relatedMousePosition.x / GameRendererConfig::kCellSize};
}
```
* <font color="#3398FF">GetMouseCellPosition:</font>
    Calculates the mouse cursor relative to the game grid.
### Steps:
1. <font color="#3398FF">mousePosition:</font>
    Gets the mouse's position in the window.
2. <font color="#3398FF">relatedMousePosition:</font>
    Adjust the mouse position based on the board's top-left offset.
3. Finally returns the cell position by dividing the adjusted coordinates by the cell size.