summaryrefslogtreecommitdiff
path: root/Menu.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Menu.cpp')
-rw-r--r--Menu.cpp15
1 files changed, 14 insertions, 1 deletions
diff --git a/Menu.cpp b/Menu.cpp
index 7fa2448..688f7e0 100644
--- a/Menu.cpp
+++ b/Menu.cpp
@@ -3,7 +3,7 @@
#include "cfg.hpp"
#include <stdlib.h>
-Menu::Menu() : _hovered(-1)
+Menu::Menu() : _was_down(false), _hovered(-1), _selected(1)
{
}
@@ -12,21 +12,34 @@ void Menu::update(const Cursor &cursor)
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;
+}