aboutsummaryrefslogtreecommitdiff
path: root/src/engine/graphics/string_matrix.cpp
blob: ae06755cac367c47e5f88aebb877a324571c5264 (plain)
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
#include "string_matrix.hpp"

StringMatrix::StringMatrix(const Bounds &bounds) noexcept
	: _rows(bounds.get_height()), _columns(bounds.get_width())
{
	_matrix.reserve(bounds.get_height());
	_matrix.assign(_matrix.capacity(), std::vector<std::string_view>(bounds.get_width()));
};

void StringMatrix::fill(std::string_view element) noexcept
{
	for (uint32_t row = 0U; row < _matrix.capacity(); row++)
	{
		std::vector<std::string_view> row_vector = _matrix[row];

		for (uint32_t column = 0U; column < row_vector.capacity(); column++)
		{
			_matrix[row][column] = element;
		}
	}
}

std::string_view StringMatrix::get(const Vector2 &pos) const noexcept
{
	auto x = static_cast<std::size_t>(pos.get_x());
	auto y = static_cast<std::size_t>(pos.get_y());

	return _matrix[y][x];
}

void StringMatrix::set(const Vector2 &pos, std::string_view element) noexcept
{
	auto x = static_cast<std::size_t>(pos.get_x());
	auto y = static_cast<std::size_t>(pos.get_y());

	_matrix[y][x] = element;
}

uint32_t StringMatrix::rows() const noexcept
{
	return _rows;
}

uint32_t StringMatrix::columns() const noexcept
{
	return _columns;
}