-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgridCell.cpp
More file actions
52 lines (42 loc) · 1.53 KB
/
gridCell.cpp
File metadata and controls
52 lines (42 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include "gridCell.h"
#include <iostream>
GridCell::GridCell(int index, int boxSize, sf::Font& font)
: textOffset(sf::Vector2f(0, 17)), isSelected(false)
{
UpdateGridCell(index, boxSize, font);
}
void GridCell::SetFillColor(sf::Color color)
{
shape.setFillColor(color);
}
// sets up the cell number
void GridCell::UpdateCellNum(int num, int boxSize, sf::Font& font)
{
cellNum.setFont(font);
cellNum.setString(sf::String(std::to_string(num)));
cellNum.setCharacterSize(30);
cellNum.setFillColor(isSelected ? sf::Color::Red : sf::Color::Green);
// get the coords of the bottom middle edge of the shape
sf::Vector2f gridBottomMiddlePos = shape.getPosition() + sf::Vector2f(boxSize/2, boxSize);
cellNum.setPosition(gridBottomMiddlePos + textOffset);
}
void GridCell::UpdateCellNumColor()
{
cellNum.setFillColor(isSelected ? sf::Color::Red : sf::Color::Green);
}
void GridCell::UpdateGridCell(int index, int boxSize, sf::Font& font)
{
UpdateCellShape(index, boxSize, font);
int num = index + 1;
UpdateCellNum(num, boxSize, font);
}
void GridCell::UpdateCellShape(int index, int boxSize, sf::Font& font)
{
sf::Color grey(128, 128, 128, 255);
//static casting to convert the position to an exact integer (to solve rendering issues)
shape.setPosition(sf::Vector2f(static_cast<int>(index * boxSize), 0));
shape.setSize(sf::Vector2f(boxSize, boxSize));
shape.setOutlineThickness(10.0f);
shape.setOutlineColor(grey);
shape.setFillColor(sf::Color::White);
}