aboutsummaryrefslogtreecommitdiff
path: root/src/engine/graphics/scene.cpp
blob: 73c1292af9ac89c046fe1201091b5dcb73eea7c9 (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
48
49
50
51
52
53
#include "scene.hpp"

#include "engine/escape.hpp"
#include "util/color.hpp"

#include <fmt/color.h>
#include <fmt/core.h>
#include <iostream>
#include <utility>

Scene::Scene(
	IMatrixFactory<std::string_view> matrix_factory,
	std::shared_ptr<ICursorController> cursor_controller,
	std::shared_ptr<IWindow> window) noexcept
	: _is_shown(false),
	  _matrix(matrix_factory(window->size() - Bounds({.width = 0U, .height = 1U}))),
	  _cursor_controller(std::move(cursor_controller)),
	  _window(std::move(window))
{
	_matrix->fill(" ");
}

void Scene::enter() noexcept
{
	if (_is_shown)
	{
		return;
	}

	fmt::print(ENABLE_ALT_BUFFER, fmt::arg("esc", ESC));
	std::cout.flush();

	_is_shown = true;
}

void Scene::leave() noexcept
{
	if (!_is_shown)
	{
		return;
	}

	fmt::print(DISABLE_ALT_BUFFER, fmt::arg("esc", ESC));
	std::cout.flush();

	_is_shown = false;
}

auto Scene::get_matrix() const noexcept
	-> const std::shared_ptr<IMatrix<std::string_view>> &
{
	return _matrix;
}