Menu::Menu() :
pos(),
- menuaction(),
delete_character(),
mn_input_char(),
menu_repeat_time(),
arrange_left(),
active_item()
{
- menuaction = MENU_ACTION_NONE;
delete_character = 0;
mn_input_char = '\0';
active_item = -1;
}
-/* Process actions done on the menu */
void
Menu::process_input()
{
pos.y = SCREEN_HEIGHT/2 - scroll_offset * ((float(active_item) / (items.size()-1)) - 0.5f) * 2.0f;
}
+ MenuAction menuaction = MENU_ACTION_NONE;
Controller* controller = g_input_manager->get_controller();
/** check main input controller... */
if(controller->pressed(Controller::UP)) {
if(items.size() == 0)
return;
+ // The menu_action() call can pop() the menu from the stack and thus
+ // delete it, so it's important that no further member variables are
+ // accessed after this call
+ process_action(menuaction);
+}
+
+void
+Menu::process_action(MenuAction menuaction)
+{
int last_active_item = active_item;
switch(menuaction) {
case MENU_ACTION_UP:
case MENU_ACTION_NONE:
break;
}
- menuaction = MENU_ACTION_NONE;
-
- assert(active_item < int(items.size()));
}
void
-Menu::menu_action(MenuItem* )
-{}
-
-void
Menu::draw_item(DrawingContext& context, int index)
{
float menu_height = get_height();
get_item_by_id(id).toggled = toggled;
}
-/* Check for menu event */
void
Menu::event(const SDL_Event& event)
{
y > pos.y - get_height()/2 &&
y < pos.y + get_height()/2)
{
- menuaction = MENU_ACTION_HIT;
+ process_action(MENU_ACTION_HIT);
}
}
break;
class DrawingContext;
class MenuItem;
-bool confirm_dialog(Surface* background, std::string text);
-
class Menu
{
static Color default_color;
MenuItem* add_item(std::unique_ptr<MenuItem> menu_item);
private:
+ void process_action(MenuAction menuaction);
void check_controlfield_change_event(const SDL_Event& event);
void draw_item(DrawingContext& context, int index);
// position of the menu (ie. center of the menu, not top/left)
Vector pos;
- /** input event for the menu (up, down, left, right, etc.) */
- MenuAction menuaction;
-
/* input implementation variables */
int delete_character;
char mn_input_char;