#include "Menu.hpp" #include "lzr.h" #include "cfg.hpp" #include "input.h" #include Menu::Menu() : _was_down(false), _hovered(-1), _selected(1) { } void Menu::update(const Cursor &cursor) { if (input_pressed(K_O)) { _selected += 1; _selected %= _entries; } if (cursor.x < 0 || cursor.x >= CFG_DWIDTH || cursor.y < _ybegin || cursor.y > _yend) { _hovered = -1; _was_down = cursor.down; return; } int x = cursor.x / _wentry; if (x > _entries) x = _entries; _hovered = x; if (cursor.down && !_was_down) _selected = _hovered; _was_down = cursor.down; } void Menu::draw() const { LZR_DrawSetColor(0, 0, 0, 1); LZR_DrawRectangle(true, 0, _ybegin, CFG_DWIDTH, _yend - _ybegin); LZR_DrawSetColor(rand() & 1, rand() & 1, rand() & 1, rand() & 1); if ((rand() & 31) == 0) LZR_DrawRectangle(true, _selected * _wentry, _ybegin, _wentry, _yend - _ybegin + 1); if (_hovered > -1) { LZR_DrawSetColor(rand() & 1, rand() & 1, rand() & 1, 1); LZR_DrawRectangle(true, _hovered * _wentry, _ybegin, _wentry, _yend - _ybegin + 1); } } int Menu::get_selection() const { return _selected; }