aboutsummaryrefslogtreecommitdiff
path: root/src/engine/graphics/statusline.hpp
blob: 6f0a4c2e9cf863f1488fcced00f7951f0427665c (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
#pragma once

#include "interfaces/cursor.hpp"
#include "interfaces/scene.hpp"
#include "interfaces/statusline.hpp"

#include "engine/data/vector2.hpp"

#include <fmt/core.h>

#include <memory>
#include <string_view>
#include <unordered_map>

constexpr uint32_t STATUSBAR_COLOR = 0x1A1A1AU;

class StatusLine : public IStatusLine
{
public:
	StatusLine(
		std::shared_ptr<ICursorController> cursor_controller,
		std::shared_ptr<IScene> scene) noexcept;

	void initialize_background() noexcept override;

	void set_status(
		const StatusLineSection &section,
		const std::string_view &status,
		std::size_t start) noexcept override;

	void set_section_length(const StatusLineSection &section, uint32_t length) noexcept
		override;

private:
	std::unordered_map<StatusLineSection, uint32_t> _sections_lengths;

	std::shared_ptr<ICursorController> _cursor_controller;
	std::shared_ptr<IScene> _scene;

	auto _move_to_statusline(int32_t x) noexcept -> Vector2;

	void _move_back(Vector2 previous_position) noexcept;

	[[nodiscard]] auto
	_get_section_start_x(const StatusLineSection &section) const noexcept -> int32_t;

	void _clear_section(const StatusLineSection &section, std::size_t start) noexcept;
};