summaryrefslogtreecommitdiff
path: root/lib/nes/app/ui/screen-error.cc
blob: 67a3244473940195d193659c986447477bc933c1 (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
#include "nes/app/ui/screen-error.hh"
#include "nes/app/graphics/renderer.hh"
#include "nes/app/graphics/color.hh"
#include "nes/app/input/input-device-keyboard.hh"

namespace nes::app
{
	screen_error::screen_error(input_device_keyboard& keyboard)
		: keyboard_{ keyboard }
	{
	}

	auto screen_error::render(renderer& renderer) -> void
	{
		// TODO: Nicer box
		renderer.render_rect(2, 9, 28, 5, color::background_secondary);

		auto const attrs = text_attributes{}
			.set_alignment(text_alignment::center)
			.set_ellipsize_mode(ellipsize_mode::end)
			.set_max_width(26);
		renderer.render_text_format(16, 10, color::foreground_primary, attrs, "{}:", message_);
		renderer.render_text(16, 12, to_string(error_), color::foreground_primary, attrs);
	}

	auto screen_error::process_events() -> action
	{
		while (auto const event = keyboard_.poll_event())
		{
			if (event == input_event::key_down(key::enter))
			{
				return action::close_popup();
			}
		}

		return action{};
	}
} // namespace nes::app