summaryrefslogtreecommitdiff
path: root/Menu.cpp
blob: 7fa2448381937305f805b498a2b1822673acf21d (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
#include "Menu.hpp"
#include "lzr.h"
#include "cfg.hpp"
#include <stdlib.h>

Menu::Menu() : _hovered(-1)
{
}

void Menu::update(const Cursor &cursor)
{
	if (cursor.x < 0 || cursor.x >= CFG_DWIDTH ||
	    cursor.y < _ybegin || cursor.y > _yend) {
		_hovered = -1;
		return;
	}
	int x = cursor.x / _wentry;
	if (x > _entries)
		x = _entries;
	_hovered = x;
}

void Menu::draw() const
{
	LZR_DrawSetColor(0, 0, 0, 1);
	LZR_DrawRectangle(true, 0, _ybegin, CFG_DWIDTH, _yend - _ybegin);
	if (_hovered > -1) {
		LZR_DrawSetColor(rand() & 1, rand() & 1, rand() & 1, 1);
		LZR_DrawRectangle(true, _hovered * _wentry, _ybegin,
		                  _wentry, _yend - _ybegin + 1);
	}
}