diff options
Diffstat (limited to 'Menu.cpp')
-rw-r--r-- | Menu.cpp | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/Menu.cpp b/Menu.cpp new file mode 100644 index 0000000..7fa2448 --- /dev/null +++ b/Menu.cpp @@ -0,0 +1,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); + } +} |